source: src/unittests/memoryusageobserverunittest.cpp@ 13e3c3

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 13e3c3 was bf3817, checked in by Frederik Heber <heber@…>, 14 years ago

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

  • is now topmost in front of MemDebug.hpp (and any other).
  • Property mode set to 100644
File size: 5.2 KB
Line 
1/*
2 * memoryusageobserverunittest.cpp
3 */
4
5
6// include config.h
7#ifdef HAVE_CONFIG_H
8#include <config.h>
9#endif
10
11using namespace std;
12
13#include <cppunit/CompilerOutputter.h>
14#include <cppunit/extensions/TestFactoryRegistry.h>
15#include <cppunit/ui/text/TestRunner.h>
16
17#include "memoryallocator.hpp"
18#include "memoryusageobserver.hpp"
19#include "memoryusageobserverunittest.hpp"
20
21#ifdef HAVE_TESTRUNNER
22#include "UnitTestMain.hpp"
23#endif /*HAVE_TESTRUNNER*/
24
25/********************************************** Test classes **************************************/
26// Registers the fixture into the 'registry'
27CPPUNIT_TEST_SUITE_REGISTRATION( MemoryUsageObserverTest );
28
29
30void MemoryUsageObserverTest::setUp()
31{
32};
33
34
35void MemoryUsageObserverTest::tearDown()
36{
37 MemoryUsageObserver::purgeInstance();
38 logger::purgeInstance();
39 errorLogger::purgeInstance();
40};
41
42/**
43 * UnitTest for getInstance()
44 */
45void MemoryUsageObserverTest::getInstanceReturnsMemoryUsageObserverTest()
46{
47 CPPUNIT_ASSERT_EQUAL(true, MemoryUsageObserver::getInstance() != NULL);
48};
49
50/**
51 * UnitTest for getInstance()
52 */
53void MemoryUsageObserverTest::getInstanceTwiceReturnsSameInstanceTest()
54{
55 int* i = Malloc<int>(1, "MemoryUsageObserverTest::getInstanceTwiceReturnsSameInstanceTest - i");
56 MemoryUsageObserver::getInstance()->addMemory(i, sizeof(int));
57 CPPUNIT_ASSERT_EQUAL(sizeof(int), MemoryUsageObserver::getInstance()->getUsedMemorySize());
58 CPPUNIT_ASSERT_EQUAL(sizeof(int), MemoryUsageObserver::getInstance()->getUsedMemorySize());
59};
60
61/**
62 * UnitTest for getInstance()
63 */
64void MemoryUsageObserverTest::getInstanceAfterPurgeInstanceReturnsNewInstanceTest()
65{
66 int* i = Malloc<int>(1, "MemoryUsageObserverTest::getInstanceAfterPurgeInstanceReturnsNewInstanceTest - i");
67 MemoryUsageObserver::getInstance()->addMemory(i, sizeof(int));
68 CPPUNIT_ASSERT_EQUAL(sizeof(int), MemoryUsageObserver::getInstance()->getUsedMemorySize());
69 MemoryUsageObserver::purgeInstance();
70 CPPUNIT_ASSERT_EQUAL((size_t) 0, MemoryUsageObserver::getInstance()->getUsedMemorySize());
71};
72
73/**
74 * UnitTest for addMemory() and removeMemory()
75 */
76void MemoryUsageObserverTest::addAndRemoveMemoryTest()
77{
78 int* i = Malloc<int>(1, "MemoryUsageObserverTest::addAndRemoveMemoryTest - i");
79 MemoryUsageObserver::getInstance()->addMemory(i, sizeof(int));
80 CPPUNIT_ASSERT_EQUAL(sizeof(int), MemoryUsageObserver::getInstance()->getUsedMemorySize());
81 MemoryUsageObserver::getInstance()->removeMemory(i);
82 CPPUNIT_ASSERT_EQUAL((size_t) 0, MemoryUsageObserver::getInstance()->getUsedMemorySize());
83 Free(i);
84};
85
86/**
87 * UnitTest for addMemory() and removeMemory()
88 */
89void MemoryUsageObserverTest::removeNonTrackedMemoryDoesNotCauseACrashTest()
90{
91 int* i = Malloc<int>(1, "MemoryUsageObserverTest::removeNonTrackedMemoryDoesNotCauseACrashTest - i");
92 MemoryUsageObserver::getInstance()->removeMemory(i);
93 CPPUNIT_ASSERT_EQUAL((size_t) 0, MemoryUsageObserver::getInstance()->getUsedMemorySize());
94 Free(i);
95};
96
97/**
98 * UnitTest for addMemory() and removeMemory()
99 */
100void MemoryUsageObserverTest::addMemoryTwiceTest()
101{
102 int* i = Malloc<int>(1, "MemoryUsageObserverTest::addMemoryTwiceTest - i");
103 int* j = Malloc<int>(1, "MemoryUsageObserverTest::addMemoryTwiceTest - j");
104 MemoryUsageObserver::getInstance()->addMemory(i, sizeof(int));
105 MemoryUsageObserver::getInstance()->addMemory(j, sizeof(int));
106 CPPUNIT_ASSERT_EQUAL(2 * sizeof(int), MemoryUsageObserver::getInstance()->getUsedMemorySize());
107 Free(i);
108 Free(j);
109};
110
111/**
112 * UnitTest for addMemory() and removeMemory()
113 */
114void MemoryUsageObserverTest::addMemoryAndChangeSizeOfAddedMemoryTest()
115{
116 int* i = Malloc<int>(1, "MemoryUsageObserverTest::addMemoryAndChangeSizeOfAddedMemoryTest - i");
117 MemoryUsageObserver::getInstance()->addMemory(i, 2 * sizeof(int));
118 MemoryUsageObserver::getInstance()->addMemory(i, sizeof(int));
119 CPPUNIT_ASSERT_EQUAL(sizeof(int), MemoryUsageObserver::getInstance()->getUsedMemorySize());
120 Free(i);
121};
122
123/**
124 * UnitTest for getMaximumUsedMemory()
125 */
126void MemoryUsageObserverTest::addMemoryChangeSizeOfAddedMemoryAndGetMaximumSizeTest()
127{
128 int* i = Malloc<int>(1, "MemoryUsageObserverTest::addMemoryChangeSizeOfAddedMemoryAndGetMaximumSizeTest - i");
129 MemoryUsageObserver::getInstance()->addMemory(i, 2 * sizeof(int));
130 MemoryUsageObserver::getInstance()->addMemory(i, sizeof(int));
131 CPPUNIT_ASSERT_EQUAL(2 * sizeof(int), MemoryUsageObserver::getInstance()->getMaximumUsedMemory());
132 Free(i);
133};
134
135/**
136 * UnitTest for getMaximumUsedMemory()
137 */
138void MemoryUsageObserverTest::addMemoryRemoveMemoryAndGetMaximumSizeTest()
139{
140 int* i = Malloc<int>(1, "MemoryUsageObserverTest::addMemoryRemoveMemoryAndGetMaximumSizeTest - i");
141 MemoryUsageObserver::getInstance()->addMemory(i, sizeof(int));
142 MemoryUsageObserver::getInstance()->removeMemory(i);
143 CPPUNIT_ASSERT_EQUAL(sizeof(int), MemoryUsageObserver::getInstance()->getMaximumUsedMemory());
144 Free(i);
145};
146
147/**
148 * UnitTest for getPointersToAllocatedMemory()
149 */
150void MemoryUsageObserverTest::getPointersToAllocatedMemoryTest()
151{
152 int* i = Malloc<int>(1, "MemoryUsageObserverTest::getPointersToAllocatedMemoryTest - i");
153 MemoryUsageObserver::getInstance()->addMemory(i, sizeof(int));
154 CPPUNIT_ASSERT_EQUAL(i, (int*) MemoryUsageObserver::getInstance()->getPointersToAllocatedMemory().begin()->first);
155 Free(i);
156};
Note: See TracBrowser for help on using the repository browser.