Ignore:
Timestamp:
Jan 4, 2011, 5:15:14 PM (15 years ago)
Author:
Frederik Heber <heber@…>
Children:
1afcbe
Parents:
746ff1
git-author:
Frederik Heber <heber@…> (01/04/11 15:57:33)
git-committer:
Frederik Heber <heber@…> (01/04/11 17:15:14)
Message:

Factory know has an additional type table and stubs have been refactored.

  • CommonStub.?pp contains basic classes with a int counter inside.
  • Library version is now 2:1:0, API is 1.0.3.
Location:
src/Patterns/unittests
Files:
1 added
7 edited
1 moved

Legend:

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

    r746ff1 r724564  
    2525
    2626#include "Creator.hpp"
     27#include "stubs/CommonStub.hpp"
    2728#include "stubs/CreatorStub.hpp"
    2829
  • src/Patterns/unittests/FactoryUnitTest.cpp

    r746ff1 r724564  
    2222#include "FactoryUnitTest.hpp"
    2323
     24#include "stubs/CommonStub.hpp"
    2425#include "stubs/FactoryStub.hpp"
    2526
     
    6869void FactoryTest::setUp()
    6970{
    70   FactoryStub::getInstance();
     71  rndA =
     72      FactoryStub::getInstance().
     73      PrototypeTable[FactoryStub::Aclass]->create();
     74  rndB =
     75      FactoryStub::getInstance().
     76      PrototypeTable[FactoryStub::Bclass]->create();
    7177}
    7278
    7379void FactoryTest::tearDown()
    7480{
     81  delete rndA;
     82  delete rndB;
    7583  FactoryStub::purgeInstance();
    7684}
     
    93101  }
    94102
    95   // check one of the distributions in the table
    96   ICreatorStub * rnd =
    97       FactoryStub::getInstance().
    98       PrototypeTable[FactoryStub::Aclass]->create();
     103  // check distributions in the table
    99104  CPPUNIT_ASSERT_EQUAL(
    100105      std::string(typeid(teststubs::Aclass).name()),
    101       rnd->name()
     106      rndA->name()
    102107  );
    103   delete rnd;
     108  CPPUNIT_ASSERT_EQUAL(
     109      std::string(typeid(teststubs::Bclass).name()),
     110      rndB->name()
     111  );
    104112}
     113
     114
     115void FactoryTest::getProductEnumTest()
     116{
     117  ICreatorStub * rndA_1 =
     118      FactoryStub::getInstance().getProduct(FactoryStub::Aclass);
     119  CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
     120  delete rndA_1;
     121}
     122
     123void FactoryTest::getProductNameTest()
     124{
     125  ICreatorStub * rndA_1 =
     126      FactoryStub::getInstance().getProduct(std::string("Aclass"));
     127  CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
     128  delete rndA_1;
     129}
     130
     131void FactoryTest::getProductTypeTest()
     132{
     133  ICreatorStub * rndA_1 =
     134      FactoryStub::getInstance().getProduct( typeid(teststubs::Aclass) );
     135  CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
     136  delete rndA_1;
     137}
  • src/Patterns/unittests/FactoryUnitTest.hpp

    r746ff1 r724564  
    1414#endif
    1515
     16class ICreatorStub;
    1617
    1718#include <cppunit/extensions/HelperMacros.h>
     
    2122  CPPUNIT_TEST_SUITE( FactoryTest );
    2223  CPPUNIT_TEST ( DistributionTest );
     24  CPPUNIT_TEST ( getProductEnumTest );
     25  CPPUNIT_TEST ( getProductNameTest );
     26  CPPUNIT_TEST ( getProductTypeTest );
    2327  CPPUNIT_TEST_SUITE_END();
    2428
     
    2832
    2933  void DistributionTest();
     34  void getProductEnumTest();
     35  void getProductNameTest();
     36  void getProductTypeTest();
    3037
    3138private:
     39  ICreatorStub * rndA;
     40  ICreatorStub * rndB;
    3241};
    3342
  • src/Patterns/unittests/Makefile.am

    r746ff1 r724564  
    3737        CreatorUnitTest.hpp \
    3838        ../Creator.hpp \
    39         stubs/CreatorStub.hpp \
    40         stubs/CreatorStub.cpp
     39        stubs/CommonStub.cpp \
     40        stubs/CommonStub.hpp \
     41        stubs/CreatorStub.hpp
    4142CreatorUnitTest_LDADD = $(TESTLIBS)
    4243
     
    4445        FactoryUnitTest.cpp \
    4546        FactoryUnitTest.hpp \
     47        stubs/CommonStub.cpp \
     48        stubs/CommonStub.hpp \
    4649        stubs/CreatorStub.hpp \
    47         stubs/CreatorStub.cpp \
    4850        stubs/FactoryStub.hpp \
    4951        stubs/FactoryStub.cpp \
  • src/Patterns/unittests/stubs/CommonStub.cpp

    r746ff1 r724564  
    77
    88/*
    9  * CreatorStub.cpp
     9 * CommonStub.cpp
    1010 *
    1111 *  Created on: Jan 4, 2011
     
    1313 */
    1414
     15// include config.h
     16#ifdef HAVE_CONFIG_H
     17#include <config.h>
     18#endif
     19
     20#include "CommonStub.hpp"
     21
    1522namespace teststubs {
    16   class Aclass {};
    17   class Bclass {};
     23  Aclass::Aclass() :
     24    counter(0)
     25  {};
     26
     27  Aclass::~Aclass() {};
     28
     29  Bclass::Bclass() :
     30    counter(256)
     31  {};
     32
     33  Bclass::~Bclass() {};
    1834};
  • src/Patterns/unittests/stubs/CreatorStub.hpp

    r746ff1 r724564  
    88#ifndef CREATORSTUB_HPP_
    99#define CREATORSTUB_HPP_
     10
     11// include config.h
     12#ifdef HAVE_CONFIG_H
     13#include <config.h>
     14#endif
    1015
    1116#include <typeinfo>
     
    1924  virtual int getcount() = 0;
    2025  virtual std::string name() = 0;
    21 };
    22 
    23 namespace teststubs {
    24   class Aclass
    25   {
    26   public:
    27     Aclass() :
    28       counter(0)
    29     {};
    30     ~Aclass() {};
    31 
    32     int counter;
    33   };
    34 
    35   class Bclass
    36   {
    37   public:
    38     Bclass() :
    39       counter(256)
    40     {};
    41     ~Bclass() {};
    42 
    43     int counter;
    44   };
    4526};
    4627
  • src/Patterns/unittests/stubs/FactoryStub.cpp

    r746ff1 r724564  
    1313 */
    1414
     15// include config.h
     16#ifdef HAVE_CONFIG_H
     17#include <config.h>
     18#endif
     19
    1520#include "Singleton_impl.hpp"
    1621
     22#include "CommonStub.hpp"
    1723#include "FactoryStub.hpp"
    1824
  • src/Patterns/unittests/stubs/FactoryStub.hpp

    r746ff1 r724564  
    99#define FACTORYSTUB_HPP_
    1010
     11// include config.h
     12#ifdef HAVE_CONFIG_H
     13#include <config.h>
     14#endif
     15
    1116#include "CreatorStub.hpp"
    1217
    13 // has to be appear BEFORE Factory.hpp is included!
     18// triple has to be appear BEFORE Factory.hpp is included!
    1419#include "FactoryStub.def"
    1520#include "FactoryTypeList.hpp"
     21#include "FactoryStub.undef"
     22
    1623#include "Factory.hpp"
    1724
     
    2734  virtual ~FactoryStub();
    2835};
    29 #include "FactoryStub.undef"
    3036
    3137#endif /* FACTORYSTUB_HPP_ */
Note: See TracChangeset for help on using the changeset viewer.