Ignore:
Timestamp:
Jan 16, 2011, 6:38:25 PM (15 years ago)
Author:
Frederik Heber <heber@…>
Children:
d1a85d
Parents:
56d62f
git-author:
Frederik Heber <heber@…> (01/16/11 18:36:28)
git-committer:
Frederik Heber <heber@…> (01/16/11 18:38:25)
Message:

Implemented unit test for Registry pattern.

  • Library version is now 4:0:2, API version is still 1.0.7.
  • So far only empty test was present.
File:
1 edited

Legend:

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

    r56d62f rfe056c  
    2424#include <typeinfo>
    2525
     26#include "stubs/CommonNamedStub.hpp"
     27#include "stubs/RegistryStub.hpp"
     28
     29#include "Assert.hpp"
     30
    2631#include "RegistryUnitTest.hpp"
    2732
     
    3742
    3843void RegistryTest::setUp()
    39 {};
     44{
     45  ASSERT_DO(Assert::Throw);
     46  registry = new RegistryStub;
     47};
    4048
    4149
    4250void RegistryTest::tearDown()
    43 {};
     51{
     52  delete registry;
     53};
    4454
    4555void RegistryTest::InOutCheck()
    4656{
    47   CPPUNIT_ASSERT(true);
     57  // create two test instances to put into the registry
     58  teststubs::ANamedclass *instanceA = new teststubs::ANamedclass;
     59  teststubs::BNamedclass *instanceB = new teststubs::BNamedclass;
     60  teststubs::INamedclass *testinstance = NULL;
     61
     62  // register both instances
     63  registry->registerInstance(instanceA);
     64  registry->registerInstance(instanceB);
     65
     66  // obtain Aclass and see if it matches
     67  testinstance = registry->getByName("ANamedclass");
     68  CPPUNIT_ASSERT( testinstance == instanceA );
     69
     70  // unregister Aclass and see if there's no more match
     71  registry->unregisterInstance(instanceA);
     72  testinstance = NULL;
     73#ifndef NDEBUG
     74  CPPUNIT_ASSERT_THROW((testinstance = registry->getByName("ANamedclass")),Assert::AssertionFailure);
     75#else
     76  testinstance = registry->getByName("ANamedclass");
     77#endif
     78  CPPUNIT_ASSERT( testinstance == NULL );
     79
     80  // obtain Bclass and see if it matches
     81  testinstance = registry->getByName("BNamedclass");
     82  CPPUNIT_ASSERT( testinstance == instanceB );
     83
     84  // unregister Aclass and see if there's no more match
     85  registry->unregisterInstance(instanceB);
     86  testinstance = NULL;
     87#ifndef NDEBUG
     88  CPPUNIT_ASSERT_THROW((testinstance = registry->getByName("BNamedclass")),Assert::AssertionFailure);
     89#else
     90  testinstance = registry->getByName("BNamedclass");
     91#endif
     92  CPPUNIT_ASSERT( testinstance == NULL );
     93  CPPUNIT_ASSERT( testinstance == NULL );
     94
     95  // check that registry is empty
     96  CPPUNIT_ASSERT( registry->getBeginIter() == registry->getEndIter() );
     97
     98  delete instanceA;
     99  delete instanceB;
    48100}
Note: See TracChangeset for help on using the changeset viewer.