Changeset 10975 for code/branches/cpp11_v2/test/core
- Timestamp:
- Dec 23, 2015, 7:16:33 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/cpp11_v2/test/core/command/FunctorTest.cc
r10922 r10975 19 19 }; 20 20 21 class DestroyableClass : public Destroyable 22 { 23 public: 24 void method() {}; 25 }; 26 21 27 void f1(int, double) 22 28 { … … 31 37 return 0; 32 38 } 39 40 struct CallableStruct 41 { 42 public: 43 int operator()() 44 { 45 return 1; 46 } 47 }; 33 48 } 34 49 … … 38 53 FunctorPtr fp2 = createFunctor(&f2); 39 54 FunctorPtr fp3 = createFunctor(&f3); 40 ASSERT_ TRUE(fp1->getHeaderIdentifier(1) == fp2->getHeaderIdentifier(1));41 ASSERT_ TRUE(fp1->getHeaderIdentifier(2) == fp2->getHeaderIdentifier(2));42 ASSERT_ FALSE(fp1->getHeaderIdentifier(1) == fp2->getHeaderIdentifier(2));43 ASSERT_ FALSE(fp1->getHeaderIdentifier(10) == fp2->getHeaderIdentifier(10));44 ASSERT_ FALSE(fp2->getHeaderIdentifier(2) == fp3->getHeaderIdentifier(2));45 ASSERT_ FALSE(fp1->getHeaderIdentifier() == fp2->getHeaderIdentifier());46 ASSERT_ FALSE(fp2->getHeaderIdentifier() == fp3->getHeaderIdentifier());55 ASSERT_STREQ(fp1->getHeaderIdentifier(1).name(), fp2->getHeaderIdentifier(1).name()); 56 ASSERT_STREQ(fp1->getHeaderIdentifier(2).name(), fp2->getHeaderIdentifier(2).name()); 57 ASSERT_STRNE(fp1->getHeaderIdentifier(1).name(), fp2->getHeaderIdentifier(2).name()); 58 ASSERT_STRNE(fp1->getHeaderIdentifier(10).name(), fp2->getHeaderIdentifier(10).name()); 59 ASSERT_STRNE(fp2->getHeaderIdentifier(2).name(), fp3->getHeaderIdentifier(2).name()); 60 ASSERT_STRNE(fp1->getHeaderIdentifier().name(), fp2->getHeaderIdentifier().name()); 61 ASSERT_STRNE(fp2->getHeaderIdentifier().name(), fp3->getHeaderIdentifier().name()); 47 62 } 48 63 … … 52 67 FunctorPtr fp2 = createFunctor(&f2); 53 68 FunctorPtr fp3 = createFunctor(&f3); 54 ASSERT_ TRUE(fp1->getTypenameReturnvalue() ==fp2->getTypenameReturnvalue());55 ASSERT_ TRUE(fp1->getTypenameParam(0) ==fp3->getTypenameParam(0));69 ASSERT_EQ(fp1->getTypenameReturnvalue(), fp2->getTypenameReturnvalue()); 70 ASSERT_EQ(fp1->getTypenameParam(0), fp3->getTypenameParam(0)); 56 71 ASSERT_EQ("void", fp1->getTypenameReturnvalue()); 57 72 ASSERT_EQ("int", fp3->getTypenameReturnvalue()); … … 67 82 FunctorPtr fp3 = createFunctor(&f3); 68 83 ASSERT_EQ(3, fp2->getParamCount()); 69 ASSERT_ FALSE(fp1->getParamCount() ==fp3->getParamCount());84 ASSERT_NE(fp1->getParamCount(), fp3->getParamCount()); 70 85 ASSERT_FALSE(fp2->hasReturnvalue()); 71 86 ASSERT_TRUE(fp3->hasReturnvalue()); … … 86 101 ASSERT_TRUE(mttype.null()); 87 102 } 103 104 TEST_F(FunctorTest, canUseCallables) 105 { 106 int a = 0; 107 FunctorPtr fp1 = createFunctor(CallableStruct{}); 108 FunctorPtr fp2 = createFunctor([](bool val) { return val; }); 109 FunctorPtr fp3 = createFunctor([&a]() {return a++; }); 110 FunctorPtr fp4 = createFunctor([a]() {return a; }); 111 ASSERT_EQ(1, (*fp1)().get<int>()); 112 ASSERT_EQ(true, (*fp2)(true).get<bool>()); 113 ASSERT_EQ(0, (*fp3)().get<int>()); 114 ASSERT_EQ(1, a); 115 ASSERT_EQ(0, (*fp4)().get<int>()); 116 ASSERT_STREQ(fp1->getHeaderIdentifier().name(), fp3->getHeaderIdentifier().name()); 117 } 118 119 TEST_F(FunctorTest, SafeModeWorks) 120 { 121 DestroyableClass* testclass = new DestroyableClass(); 122 DestroyableClass* testclass2 = new DestroyableClass(); 123 FunctorPtr fp1 = createFunctor(&DestroyableClass::method, testclass); 124 fp1->setSafeMode(true); 125 FunctorPtr fp2 = createFunctor(&DestroyableClass::method, testclass); 126 fp2->setSafeMode(true); 127 FunctorPtr fp3 = createFunctor(&DestroyableClass::method, testclass); 128 fp2->setRawObjectPointer(testclass2); 129 130 ASSERT_NE(nullptr, fp1->getRawObjectPointer()); 131 ASSERT_NE(nullptr, fp2->getRawObjectPointer()); 132 ASSERT_NE(nullptr, fp3->getRawObjectPointer()); 133 testclass->destroy(); 134 ASSERT_EQ(nullptr, fp1->getRawObjectPointer()); 135 ASSERT_NE(nullptr, fp2->getRawObjectPointer()); 136 ASSERT_NE(nullptr, fp3->getRawObjectPointer()); 137 138 fp3->setRawObjectPointer(testclass2); 139 fp3->setSafeMode(true); 140 fp2->setSafeMode(false); 141 testclass2->destroy(); 142 ASSERT_NE(nullptr, fp2->getRawObjectPointer()); 143 ASSERT_EQ(nullptr, fp3->getRawObjectPointer()); 144 } 88 145 }
Note: See TracChangeset
for help on using the changeset viewer.