Changeset 9f39db for src/Patterns
- Timestamp:
- Jan 6, 2011, 11:47:13 PM (15 years ago)
- Children:
- 8dd38e
- Parents:
- 567640
- Location:
- src/Patterns/unittests
- Files:
-
- 5 edited
-
CloneUnitTest.cpp (modified) (3 diffs)
-
CreatorUnitTest.cpp (modified) (4 diffs)
-
CreatorUnitTest.hpp (modified) (2 diffs)
-
FactoryUnitTest.cpp (modified) (3 diffs)
-
FactoryUnitTest.hpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/Patterns/unittests/CloneUnitTest.cpp
r567640 r9f39db 72 72 void CloneTest::setUp() 73 73 { 74 IPrototype *ip1 = &p1;74 ip1 = &p1; 75 75 CPPUNIT_ASSERT( ip1 == &p1 ); 76 IPrototype *ip2 = &p2;76 ip2 = &p2; 77 77 CPPUNIT_ASSERT( ip2 == &p2 ); 78 78 … … 95 95 { 96 96 // test that new instances have been created. 97 IPrototype *ip1_1 = p1.clone();98 IPrototype *ip1_2 = p1.clone();97 ip1_1 = p1.clone(); 98 ip1_2 = p1.clone(); 99 99 CPPUNIT_ASSERT( ip1 != ip1_1 ); 100 100 CPPUNIT_ASSERT( ip1 != ip1_2 ); 101 101 102 IPrototype *ip2_1 = p2.clone();103 IPrototype *ip2_2 = p2.clone();102 ip2_1 = p2.clone(); 103 ip2_2 = p2.clone(); 104 104 CPPUNIT_ASSERT( ip2 != ip2_1 ); 105 105 CPPUNIT_ASSERT( ip2 != ip2_2 ); … … 114 114 115 115 // make refs to interface 116 IPrototype *ip1 = &p1;116 ip1 = &p1; 117 117 CPPUNIT_ASSERT( ip1 == &p1 ); 118 IPrototype *ip2 = &p2;118 ip2 = &p2; 119 119 CPPUNIT_ASSERT( ip2 == &p2 ); 120 120 121 121 // clone (i.e. counter = p?.counter ), ... 122 IPrototype *ip1_1 = p1.clone();123 IPrototype *ip1_2 = p1.clone();124 IPrototype *ip2_1 = p2.clone();125 IPrototype *ip2_2 = p2.clone();122 ip1_1 = p1.clone(); 123 ip1_2 = p1.clone(); 124 ip2_1 = p2.clone(); 125 ip2_2 = p2.clone(); 126 126 127 127 // check that each is individual -
src/Patterns/unittests/CreatorUnitTest.cpp
r567640 r9f39db 23 23 24 24 #include "Assert.hpp" 25 26 #include "Creator.hpp"27 #include "stubs/CommonStub.hpp"28 #include "stubs/CreatorStub.hpp"29 25 30 26 #include <boost/nondet_random.hpp> … … 73 69 void CreatorTest::setUp() 74 70 { 71 testingA1 = NULL; 72 testingA2 = NULL; 73 testingB1 = NULL; 74 testingB2 = NULL; 75 75 } 76 76 77 77 void CreatorTest::tearDown() 78 78 { 79 delete testingA1; 80 delete testingA2; 81 delete testingB1; 82 delete testingB2; 79 83 } 80 84 81 85 void CreatorTest::CreationTest() 82 86 { 83 class CreatorStub<teststubs::Aclass> teststubA; 84 class CreatorStub<teststubs::Bclass> teststubB; 85 86 ICreatorStub* testingA1 = teststubA.create(); 87 ICreatorStub* testingA2 = teststubA.create(); 88 ICreatorStub* testingB = teststubB.create(); 87 testingA1 = teststubA.create(); 88 testingA2 = teststubA.create(); 89 testingB1 = teststubB.create(); 89 90 90 91 // instance is different … … 92 93 CPPUNIT_ASSERT( &teststubA != testingA2 ); 93 94 CPPUNIT_ASSERT( testingA1 != testingA2 ); 94 CPPUNIT_ASSERT( &teststubB != testingB );95 CPPUNIT_ASSERT( &teststubB != testingB1 ); 95 96 96 97 // type is the same ... 97 98 CPPUNIT_ASSERT_EQUAL( typeid(teststubA).name(), typeid(*testingA1).name() ); 98 99 CPPUNIT_ASSERT_EQUAL( typeid(*testingA1).name(), typeid(*testingA2).name() ); 99 CPPUNIT_ASSERT_EQUAL( typeid(teststubB).name(), typeid(*testingB ).name() );100 CPPUNIT_ASSERT_EQUAL( typeid(teststubB).name(), typeid(*testingB1).name() ); 100 101 101 102 // ... for the same particular type only! 102 103 // (RTTI knows about the true complex type!) 103 CPPUNIT_ASSERT( typeid(*testingB ).name() != typeid(*testingA1).name() );104 CPPUNIT_ASSERT( typeid(*testingB ).name() != typeid(*testingA2).name() );104 CPPUNIT_ASSERT( typeid(*testingB1).name() != typeid(*testingA1).name() ); 105 CPPUNIT_ASSERT( typeid(*testingB1).name() != typeid(*testingA2).name() ); 105 106 106 107 // but not for different encapsulated types 107 CPPUNIT_ASSERT( typeid(teststubA).name() != typeid(*testingB ).name() );108 CPPUNIT_ASSERT( typeid(teststubA).name() != typeid(*testingB1).name() ); 108 109 CPPUNIT_ASSERT( typeid(teststubB).name() != typeid(*testingA1).name() ); 109 110 CPPUNIT_ASSERT( typeid(teststubB).name() != typeid(*testingA2).name() ); 110 111 111 delete testingA1;112 delete testingA2;113 delete testingB;114 112 } 115 113 116 114 void CreatorTest::IndividualityTest() 117 115 { 118 class CreatorStub<teststubs::Aclass> teststubA;119 class CreatorStub<teststubs::Bclass> teststubB;120 116 teststubA.count(); 121 117 teststubB.count(); 122 118 teststubB.count(); 123 119 124 ICreatorStub*testingA1 = teststubA.create();125 ICreatorStub*testingA2 = teststubA.create();126 ICreatorStub*testingB1 = teststubB.create();127 ICreatorStub*testingB2 = teststubB.create();120 testingA1 = teststubA.create(); 121 testingA2 = teststubA.create(); 122 testingB1 = teststubB.create(); 123 testingB2 = teststubB.create(); 128 124 129 125 // content is the same (prototype has been copied) … … 140 136 testingB2->count(); 141 137 CPPUNIT_ASSERT( testingB1->getcount() != testingB2->getcount()); 142 143 delete testingA1;144 delete testingA2;145 delete testingB1;146 delete testingB2;147 138 } -
src/Patterns/unittests/CreatorUnitTest.hpp
r567640 r9f39db 14 14 #endif 15 15 16 #include <cppunit/extensions/HelperMacros.h> 16 17 17 #include <cppunit/extensions/HelperMacros.h> 18 #include "stubs/CreatorStub.hpp" 19 #include "stubs/CommonStub.hpp" 18 20 19 21 class CreatorTest : public CppUnit::TestFixture … … 32 34 33 35 private: 36 class CreatorStub<teststubs::Aclass> teststubA; 37 class CreatorStub<teststubs::Bclass> teststubB; 38 ICreatorStub* testingA1; 39 ICreatorStub* testingA2; 40 ICreatorStub* testingB1; 41 ICreatorStub* testingB2; 34 42 }; 35 43 -
src/Patterns/unittests/FactoryUnitTest.cpp
r567640 r9f39db 75 75 FactoryStub::getInstance(). 76 76 PrototypeTable[FactoryStub::Bclass]->create(); 77 rndA_1 = NULL; 77 78 } 78 79 … … 81 82 delete rndA; 82 83 delete rndB; 84 delete rndA_1; 83 85 FactoryStub::purgeInstance(); 84 86 } … … 115 117 void FactoryTest::getProductEnumTest() 116 118 { 117 ICreatorStub * rndA_1 = 118 FactoryStub::getInstance().getProduct(FactoryStub::Aclass); 119 rndA_1 = FactoryStub::getInstance().getProduct(FactoryStub::Aclass); 119 120 CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) ); 120 delete rndA_1;121 121 } 122 122 123 123 void FactoryTest::getProductNameTest() 124 124 { 125 ICreatorStub * rndA_1 = 126 FactoryStub::getInstance().getProduct(std::string("Aclass")); 125 rndA_1 = FactoryStub::getInstance().getProduct(std::string("Aclass")); 127 126 CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) ); 128 delete rndA_1;129 127 } 130 128 131 129 void FactoryTest::getProductTypeTest() 132 130 { 133 ICreatorStub * rndA_1 = 134 FactoryStub::getInstance().getProduct( typeid(teststubs::Aclass) ); 131 rndA_1 = FactoryStub::getInstance().getProduct( typeid(teststubs::Aclass) ); 135 132 CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) ); 136 delete rndA_1;137 133 } -
src/Patterns/unittests/FactoryUnitTest.hpp
r567640 r9f39db 39 39 ICreatorStub * rndA; 40 40 ICreatorStub * rndB; 41 ICreatorStub * rndA_1; 41 42 }; 42 43
Note:
See TracChangeset
for help on using the changeset viewer.
