source: src/Patterns/unittests/RegistryUnitTest.cpp@ 17eaa5

Last change on this file since 17eaa5 was fe056c, checked in by Frederik Heber <heber@…>, 15 years ago

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.
  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * RegistryUnitTest.cpp
10 *
11 * Created on: Oct 27, 2010
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include <cppunit/CompilerOutputter.h>
21#include <cppunit/extensions/TestFactoryRegistry.h>
22#include <cppunit/ui/text/TestRunner.h>
23
24#include <typeinfo>
25
26#include "stubs/CommonNamedStub.hpp"
27#include "stubs/RegistryStub.hpp"
28
29#include "Assert.hpp"
30
31#include "RegistryUnitTest.hpp"
32
33#ifdef HAVE_TESTRUNNER
34#include "UnitTestMain.hpp"
35#endif /*HAVE_TESTRUNNER*/
36
37/********************************************** Test classes **************************************/
38
39// Registers the fixture into the 'registry'
40CPPUNIT_TEST_SUITE_REGISTRATION( RegistryTest );
41
42
43void RegistryTest::setUp()
44{
45 ASSERT_DO(Assert::Throw);
46 registry = new RegistryStub;
47};
48
49
50void RegistryTest::tearDown()
51{
52 delete registry;
53};
54
55void RegistryTest::InOutCheck()
56{
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;
100}
Note: See TracBrowser for help on using the repository browser.