Ignore:
Timestamp:
Jan 10, 2011, 8:06:49 PM (15 years ago)
Author:
Frederik Heber <heber@…>
Children:
192c04
Parents:
9f39db
git-author:
Frederik Heber <heber@…> (01/06/11 23:48:30)
git-committer:
Frederik Heber <heber@…> (01/10/11 20:06:49)
Message:

New patterns ManipulableClone and ManipulablePrototypeFactory, changed PrototypeFactory.

  • ManipulableClone is a Clone that can spawn a manipulated copy varied by given parameters.
  • prototypes in PrototypeFactory cannot be manipulated anymore.
  • PrototypeFactory::getPrototypeManipulator() -> getPrototype() and returned reference is const (and a ref, no pointer. Preventing its accidental deletion).
  • ManipulablePrototypeFactory then has non-const references returned by getProduct().
  • ManipulablePrototypeFactory::manipulatePrototype() allows direct manipulation of the prototype by a given parameter set.
  • Added unit tests for the new patterns.
  • Changed unit tests for PrototypeFactory.
  • Library version is now 4:0:0, API version is 1.0.7.
Location:
src/Patterns/unittests
Files:
11 added
5 edited

Legend:

Unmodified
Added
Removed
  • src/Patterns/unittests/Makefile.am

    r9f39db r8dd38e  
    1313  CreatorUnitTest \
    1414  FactoryUnitTest \
     15  ManipulableCloneUnitTest \
     16  ManipulablePrototypeFactoryUnitTest \
    1517  ObserverUnitTest \
    1618  PrototypeFactoryUnitTest \
     
    6769FactoryUnitTest_LDADD = $(TESTLIBS)
    6870
     71ManipulableCloneUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
     72        ManipulableCloneUnitTest.cpp \
     73        ManipulableCloneUnitTest.hpp \
     74        ../ManipulableClone.hpp \
     75        stubs/CommonStub.cpp \
     76        stubs/CommonStub.hpp \
     77        stubs/ManipulableCloneStub.cpp \
     78        stubs/ManipulableCloneStub.hpp
     79ManipulableCloneUnitTest_LDADD = $(TESTLIBS)
     80
     81ManipulablePrototypeFactoryUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
     82        ManipulablePrototypeFactoryUnitTest.cpp \
     83        ManipulablePrototypeFactoryUnitTest.hpp \
     84        stubs/ManipulableCloneStub.cpp \
     85        stubs/ManipulableCloneStub.hpp \
     86        stubs/CommonStub.cpp \
     87        stubs/CommonStub.hpp \
     88        stubs/ManipulablePrototypeFactoryStub.hpp \
     89        stubs/ManipulablePrototypeFactoryStub.cpp \
     90        ../ManipulablePrototypeFactory.hpp \
     91        ../FactoryTypeList.hpp \
     92        ../ManipulablePrototypeFactory_impl.hpp
     93ManipulablePrototypeFactoryUnitTest_LDADD = $(TESTLIBS)
     94
    6995ObserverUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
    7096        ObserverUnitTest.cpp \
  • src/Patterns/unittests/PrototypeFactoryUnitTest.cpp

    r9f39db r8dd38e  
    161161}
    162162
    163 void PrototypeFactoryTest::PrototypeManipulatortest()
     163void PrototypeFactoryTest::getPrototypetest()
    164164{
    165165  // this method is protected and only friends may access it.
    166   IPrototype *rndA_1 = PrototypeFactoryStub::getInstance().getPrototypeManipulator(std::string("Aclass"));
    167 
    168   // do something with the prototype.
    169   rndA_1->setcount(256);
     166  const IPrototype& rndA_1c = PrototypeFactoryStub::getInstance().getPrototype(std::string("Aclass"));
    170167
    171168  // clone the type and check whether new default values holds
    172169  rndA_2 = PrototypeFactoryStub::getInstance().getProduct(PrototypeFactoryStub::Aclass);
    173   CPPUNIT_ASSERT_EQUAL( 256, rndA_2->getcount() );
     170  CPPUNIT_ASSERT_EQUAL( rndA_1c.getcount(), rndA_2->getcount() );
     171  rndA_2->count();
     172  CPPUNIT_ASSERT( rndA_1c.getcount() != rndA_2->getcount() );
    174173
    175   // rndA has been cloned before we have manipulated the prototype
    176   CPPUNIT_ASSERT( rndA->getcount() != rndA_2->getcount() );
    177 
    178   // do something with the prototype.
    179   rndA_1->setcount(0);
     174  // the following is not possible
     175  //rndA_1c.count();
    180176
    181177  rndA_3 = PrototypeFactoryStub::getInstance().getProduct(PrototypeFactoryStub::Aclass);
     
    183179  CPPUNIT_ASSERT( rndA->getcount() == rndA_3->getcount() );
    184180}
    185 
    186 void PrototypeFactoryTest::installPrototypetest()
    187 {
    188   Prototype< teststubs::Aclass> *newprototype = new Prototype< teststubs::Aclass> ();
    189   newprototype->setcount(1);
    190   PrototypeFactoryStub::getInstance().installPrototype(newprototype, std::string("Aclass"));
    191   newprototype = NULL;
    192 
    193   IPrototype *rndA_1 = PrototypeFactoryStub::getInstance().getProduct(std::string("Aclass"));
    194   CPPUNIT_ASSERT( 1 == rndA_1->getcount() );
    195 
    196   rndA_1->count();
    197   CPPUNIT_ASSERT( 2 == rndA_1->getcount() );
    198 
    199   IPrototype *rndA_2 = PrototypeFactoryStub::getInstance().getProduct(std::string("Aclass"));
    200   CPPUNIT_ASSERT( 1 == rndA_2->getcount() );
    201   CPPUNIT_ASSERT( rndA_1->getcount() != rndA_2->getcount() );
    202 }
  • src/Patterns/unittests/PrototypeFactoryUnitTest.hpp

    r9f39db r8dd38e  
    2626  CPPUNIT_TEST ( getProductTypeTest );
    2727  CPPUNIT_TEST ( Individualitytest );
    28   CPPUNIT_TEST ( PrototypeManipulatortest );
    29   CPPUNIT_TEST ( installPrototypetest );
     28  CPPUNIT_TEST ( getPrototypetest );
    3029  CPPUNIT_TEST_SUITE_END();
    3130
     
    3938  void getProductTypeTest();
    4039  void Individualitytest();
    41   void PrototypeManipulatortest();
    42   void installPrototypetest();
     40  void getPrototypetest();
    4341
    4442private:
  • src/Patterns/unittests/stubs/PrototypeFactoryStub.def

    r9f39db r8dd38e  
    1 #ifndef ABSTRACTFACTORYSTUB_DEF_
    2 #define ABSTRACTFACTORYSTUB_DEF_
     1#ifndef PROTOTYPEFACTORYSTUB_DEF_
     2#define PROTOTYPEFACTORYSTUB_DEF_
    33
    44#define type_seq (Aclass)(Bclass)
     
    99#undef type_suffix
    1010
    11 #endif //ABSTRACTFACTORYSTUB_DEF_
     11#endif //PROTOTYPEFACTORYSTUB_DEF_
  • src/Patterns/unittests/stubs/PrototypeFactoryStub.undef

    r9f39db r8dd38e  
    1 #ifdef ABSTRACTFACTORYSTUB_DEF_
     1#ifdef PROTOTYPEFACTORYSTUB_DEF_
    22
    33#undef type_seq
     
    88#undef type_name_space
    99
    10 #undef ABSTRACTFACTORYSTUB_DEF_
     10#undef PROTOTYPEFACTORYSTUB_DEF_
    1111#endif
Note: See TracChangeset for help on using the changeset viewer.