source: src/Patterns/unittests/FactoryUnitTest.cpp@ 084729c

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 084729c was 084729c, checked in by Frederik Heber <heber@…>, 8 years ago

Squashed 'ThirdParty/CodePatterns/' content from commit c1e1041

git-subtree-dir: ThirdParty/CodePatterns
git-subtree-split: c1e10418c454f98be2f43d93167642b0008428fc

  • Property mode set to 100644
File size: 2.5 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 * FactoryUnitTest.cpp
9 *
10 * Created on: Jan 03, 2011
11 * Author: heber
12 */
13// include config.h
14#ifdef HAVE_CONFIG_H
15#include <config.h>
16#endif
17#include <cppunit/CompilerOutputter.h>
18#include <cppunit/extensions/TestFactoryRegistry.h>
19#include <cppunit/ui/text/TestRunner.h>
20#include "CodePatterns/Assert.hpp"
21
22#include "FactoryUnitTest.hpp"
23
24#include "stubs/CommonStub.hpp"
25#include "stubs/FactoryStub.hpp"
26
27#include <typeinfo>
28
29#ifdef HAVE_TESTRUNNER
30#include "UnitTestMain.hpp"
31#endif /*HAVE_TESTRUNNER*/
32
33/********************************************** Test classes **************************************/
34
35// Registers the fixture into the 'registry'
36CPPUNIT_TEST_SUITE_REGISTRATION( FactoryTest );
37
38void FactoryTest::setUp()
39{
40 rndA =
41 FactoryStub::getInstance().
42 PrototypeTable[FactoryStub::Aclass]->create();
43 rndB =
44 FactoryStub::getInstance().
45 PrototypeTable[FactoryStub::Bclass]->create();
46 rndA_1 = NULL;
47}
48
49void FactoryTest::tearDown()
50{
51 delete rndA;
52 delete rndB;
53 delete rndA_1;
54 FactoryStub::purgeInstance();
55}
56
57void FactoryTest::DistributionTest()
58{
59 // check the injectiveness of enum and string map
60 for (FactoryStub::NameMap::const_iterator
61 iter = FactoryStub::getInstance().names.begin();
62 iter != FactoryStub::getInstance().names.end();
63 ++iter) {
64 CPPUNIT_ASSERT_EQUAL(
65 iter->second,
66 FactoryStub::getInstance().getName(
67 FactoryStub::getInstance().getEnum(
68 iter->second
69 )
70 )
71 );
72 }
73
74 // check distributions in the table
75 CPPUNIT_ASSERT_EQUAL(
76 std::string(typeid(teststubs::Aclass).name()),
77 rndA->name()
78 );
79 CPPUNIT_ASSERT_EQUAL(
80 std::string(typeid(teststubs::Bclass).name()),
81 rndB->name()
82 );
83}
84
85
86void FactoryTest::getProductEnumTest()
87{
88 rndA_1 = FactoryStub::getInstance().getProduct(FactoryStub::Aclass);
89 CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
90}
91
92void FactoryTest::getProductNameTest()
93{
94 rndA_1 = FactoryStub::getInstance().getProduct(std::string("Aclass"));
95 CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
96}
97
98void FactoryTest::getProductTypeTest()
99{
100 rndA_1 = FactoryStub::getInstance().getProduct( typeid(teststubs::Aclass) );
101 CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) );
102}
Note: See TracBrowser for help on using the repository browser.