Changeset 9f39db for src/Patterns


Ignore:
Timestamp:
Jan 6, 2011, 11:47:13 PM (15 years ago)
Author:
Frederik Heber <heber@…>
Children:
8dd38e
Parents:
567640
Message:

FIX: some unittests declared variables anew although defined in header, NULL'd in setup, deleted in tearDown().

Location:
src/Patterns/unittests
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/Patterns/unittests/CloneUnitTest.cpp

    r567640 r9f39db  
    7272void CloneTest::setUp()
    7373{
    74   IPrototype *ip1 = &p1;
     74  ip1 = &p1;
    7575  CPPUNIT_ASSERT( ip1 == &p1 );
    76   IPrototype *ip2 = &p2;
     76  ip2 = &p2;
    7777  CPPUNIT_ASSERT( ip2 == &p2 );
    7878
     
    9595{
    9696  // 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();
    9999  CPPUNIT_ASSERT( ip1 != ip1_1 );
    100100  CPPUNIT_ASSERT( ip1 != ip1_2 );
    101101
    102   IPrototype *ip2_1 = p2.clone();
    103   IPrototype *ip2_2 = p2.clone();
     102  ip2_1 = p2.clone();
     103  ip2_2 = p2.clone();
    104104  CPPUNIT_ASSERT( ip2 != ip2_1 );
    105105  CPPUNIT_ASSERT( ip2 != ip2_2 );
     
    114114
    115115  // make refs to interface
    116   IPrototype *ip1 = &p1;
     116  ip1 = &p1;
    117117  CPPUNIT_ASSERT( ip1 == &p1 );
    118   IPrototype *ip2 = &p2;
     118  ip2 = &p2;
    119119  CPPUNIT_ASSERT( ip2 == &p2 );
    120120
    121121  // 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();
    126126
    127127  // check that each is individual
  • src/Patterns/unittests/CreatorUnitTest.cpp

    r567640 r9f39db  
    2323
    2424#include "Assert.hpp"
    25 
    26 #include "Creator.hpp"
    27 #include "stubs/CommonStub.hpp"
    28 #include "stubs/CreatorStub.hpp"
    2925
    3026#include <boost/nondet_random.hpp>
     
    7369void CreatorTest::setUp()
    7470{
     71  testingA1 = NULL;
     72  testingA2 = NULL;
     73  testingB1 = NULL;
     74  testingB2 = NULL;
    7575}
    7676
    7777void CreatorTest::tearDown()
    7878{
     79  delete testingA1;
     80  delete testingA2;
     81  delete testingB1;
     82  delete testingB2;
    7983}
    8084
    8185void CreatorTest::CreationTest()
    8286{
    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();
    8990
    9091  // instance is different
     
    9293  CPPUNIT_ASSERT( &teststubA != testingA2 );
    9394  CPPUNIT_ASSERT( testingA1 != testingA2 );
    94   CPPUNIT_ASSERT( &teststubB != testingB );
     95  CPPUNIT_ASSERT( &teststubB != testingB1 );
    9596
    9697  // type is the same ...
    9798  CPPUNIT_ASSERT_EQUAL( typeid(teststubA).name(), typeid(*testingA1).name() );
    9899  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() );
    100101
    101102  // ... for the same particular type only!
    102103  // (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() );
    105106
    106107  // but not for different encapsulated types
    107   CPPUNIT_ASSERT( typeid(teststubA).name() != typeid(*testingB).name() );
     108  CPPUNIT_ASSERT( typeid(teststubA).name() != typeid(*testingB1).name() );
    108109  CPPUNIT_ASSERT( typeid(teststubB).name() != typeid(*testingA1).name() );
    109110  CPPUNIT_ASSERT( typeid(teststubB).name() != typeid(*testingA2).name() );
    110111
    111   delete testingA1;
    112   delete testingA2;
    113   delete testingB;
    114112}
    115113
    116114void CreatorTest::IndividualityTest()
    117115{
    118   class CreatorStub<teststubs::Aclass> teststubA;
    119   class CreatorStub<teststubs::Bclass> teststubB;
    120116  teststubA.count();
    121117  teststubB.count();
    122118  teststubB.count();
    123119
    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();
    128124
    129125  // content is the same (prototype has been copied)
     
    140136  testingB2->count();
    141137  CPPUNIT_ASSERT( testingB1->getcount() != testingB2->getcount());
    142 
    143   delete testingA1;
    144   delete testingA2;
    145   delete testingB1;
    146   delete testingB2;
    147138}
  • src/Patterns/unittests/CreatorUnitTest.hpp

    r567640 r9f39db  
    1414#endif
    1515
     16#include <cppunit/extensions/HelperMacros.h>
    1617
    17 #include <cppunit/extensions/HelperMacros.h>
     18#include "stubs/CreatorStub.hpp"
     19#include "stubs/CommonStub.hpp"
    1820
    1921class CreatorTest : public CppUnit::TestFixture
     
    3234
    3335private:
     36  class CreatorStub<teststubs::Aclass> teststubA;
     37  class CreatorStub<teststubs::Bclass> teststubB;
     38  ICreatorStub* testingA1;
     39  ICreatorStub* testingA2;
     40  ICreatorStub* testingB1;
     41  ICreatorStub* testingB2;
    3442};
    3543
  • src/Patterns/unittests/FactoryUnitTest.cpp

    r567640 r9f39db  
    7575      FactoryStub::getInstance().
    7676      PrototypeTable[FactoryStub::Bclass]->create();
     77  rndA_1 = NULL;
    7778}
    7879
     
    8182  delete rndA;
    8283  delete rndB;
     84  delete rndA_1;
    8385  FactoryStub::purgeInstance();
    8486}
     
    115117void FactoryTest::getProductEnumTest()
    116118{
    117   ICreatorStub * rndA_1 =
    118       FactoryStub::getInstance().getProduct(FactoryStub::Aclass);
     119  rndA_1 = FactoryStub::getInstance().getProduct(FactoryStub::Aclass);
    119120  CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
    120   delete rndA_1;
    121121}
    122122
    123123void FactoryTest::getProductNameTest()
    124124{
    125   ICreatorStub * rndA_1 =
    126       FactoryStub::getInstance().getProduct(std::string("Aclass"));
     125  rndA_1 = FactoryStub::getInstance().getProduct(std::string("Aclass"));
    127126  CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
    128   delete rndA_1;
    129127}
    130128
    131129void FactoryTest::getProductTypeTest()
    132130{
    133   ICreatorStub * rndA_1 =
    134       FactoryStub::getInstance().getProduct( typeid(teststubs::Aclass) );
     131  rndA_1 = FactoryStub::getInstance().getProduct( typeid(teststubs::Aclass) );
    135132  CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
    136   delete rndA_1;
    137133}
  • src/Patterns/unittests/FactoryUnitTest.hpp

    r567640 r9f39db  
    3939  ICreatorStub * rndA;
    4040  ICreatorStub * rndB;
     41  ICreatorStub * rndA_1;
    4142};
    4243
Note: See TracChangeset for help on using the changeset viewer.