source: ThirdParty/CodePatterns/src/Patterns/unittests/RegistryUnitTest.cpp

Candidate_v1.6.1
Last change on this file was 41e8e2, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '084729c5923f0123e695fbe2548b393288c1f13d' as 'ThirdParty/CodePatterns'

  • Property mode set to 100644
File size: 3.1 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 "CodePatterns/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 // re-register instanceA and check if this is admonished
71#ifndef NDEBUG
72 CPPUNIT_ASSERT_THROW(registry->registerInstance(instanceA),Assert::AssertionFailure);
73#endif
74
75 // unregister Aclass and see if there's no more match
76 registry->unregisterInstance(instanceA);
77 testinstance = NULL;
78#ifndef NDEBUG
79 CPPUNIT_ASSERT_THROW((testinstance = registry->getByName("ANamedclass")),Assert::AssertionFailure);
80#else
81 testinstance = registry->getByName("ANamedclass");
82#endif
83 CPPUNIT_ASSERT( testinstance == NULL );
84
85 // obtain Bclass and see if it matches
86 testinstance = registry->getByName("BNamedclass");
87 CPPUNIT_ASSERT( testinstance == instanceB );
88
89 // unregister Aclass and see if there's no more match
90 registry->unregisterInstance(instanceB);
91 testinstance = NULL;
92#ifndef NDEBUG
93 CPPUNIT_ASSERT_THROW((testinstance = registry->getByName("BNamedclass")),Assert::AssertionFailure);
94#else
95 testinstance = registry->getByName("BNamedclass");
96#endif
97 CPPUNIT_ASSERT( testinstance == NULL );
98 CPPUNIT_ASSERT( testinstance == NULL );
99
100 // check that registry is empty
101 CPPUNIT_ASSERT( registry->getBeginIter() == registry->getEndIter() );
102
103 delete instanceA;
104 delete instanceB;
105}
106
107void RegistryTest::cleanupCheck()
108{
109 // register two test instances
110 registry->registerInstance(new teststubs::ANamedclass);
111 registry->registerInstance(new teststubs::BNamedclass);
112 CPPUNIT_ASSERT( registry->getBeginIter() != registry->getEndIter() );
113
114 // cleanup and check
115 registry->cleanup();
116 CPPUNIT_ASSERT( registry->getBeginIter() == registry->getEndIter() );
117}
Note: See TracBrowser for help on using the repository browser.