source: src/unittests/memoryallocatorunittest.cpp@ 1614174

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 1614174 was e138de, checked in by Frederik Heber <heber@…>, 15 years ago

Huge change from ofstream * (const) out --> Log().

  • first shift was done via regular expressions
  • then via error messages from the code
  • note that class atom, class element and class molecule kept in parts their output stream, was they print to file.
  • make check runs fine
  • MISSING: Verbosity is not fixed for everything (i.e. if no endl; is present and next has Verbose(0) ...)

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 * memoryallocatorunittest.cpp
3 */
4
5
6using namespace std;
7
8#include <cppunit/CompilerOutputter.h>
9#include <cppunit/extensions/TestFactoryRegistry.h>
10#include <cppunit/ui/text/TestRunner.h>
11
12#include "memoryallocator.hpp"
13#include "memoryallocatorunittest.hpp"
14#include "helpers.hpp"
15#include "defs.hpp"
16
17/********************************************** Test classes **************************************/
18
19// Registers the fixture into the 'registry'
20CPPUNIT_TEST_SUITE_REGISTRATION( MemoryAllocatorTest );
21
22
23void MemoryAllocatorTest::setUp()
24{
25};
26
27
28void MemoryAllocatorTest::tearDown()
29{
30 MemoryUsageObserver::getInstance()->purgeInstance();
31};
32
33/**
34 * UnitTest for Malloc()
35 */
36void MemoryAllocatorTest::MallocTest()
37{
38 int* buffer1 = NULL;
39 buffer1 = Malloc<int>(1, "");
40 Free(&buffer1);
41
42 long* buffer2 = NULL;
43 buffer2 = Malloc<long>(1, "");
44 Free(&buffer2);
45
46 char* buffer3 = NULL;
47 buffer3 = Malloc<char>(4, "");
48 Log() << Verbose(0) << buffer3 << endl;
49 Free(&buffer3);
50
51 char** buffer4 = NULL;
52 buffer4 = Malloc<char*>(10, "");
53 for (int i=0;i<10;i++)
54 buffer4[i] = NULL;
55 Free(&buffer4);
56};
57
58/**
59 * UnitTest for Calloc()
60 */
61void MemoryAllocatorTest::CallocTest()
62{
63 int* buffer1 = NULL;
64 buffer1 = Calloc<int>(10, "");
65 Free(&buffer1);
66
67 long* buffer2 = NULL;
68 buffer2 = Calloc<long>(10, "");
69 Free(&buffer2);
70
71 char** buffer3 = NULL;
72 buffer3 = Calloc<char *>(10, "");
73 for (int i=0;i<10;i++)
74 buffer3[i] = NULL;
75 Free(&buffer3);
76};
77
78/**
79 * UnitTest for ReAlloc()
80 */
81void MemoryAllocatorTest::ReAllocTest()
82{
83 int* buffer1 = NULL;
84 buffer1 = Malloc<int>(1, "");
85 buffer1 = ReAlloc<int>(buffer1, 2, "");
86 Free(&buffer1);
87
88 int* buffer2 = NULL;
89 buffer2 = ReAlloc<int>(buffer2, 2, "");
90 Free(&buffer2);
91};
92
93/**
94 * UnitTest for Free()
95 */
96void MemoryAllocatorTest::FreeTest()
97{
98 char** buffer1 = NULL;
99 Free(buffer1);
100
101 int** buffer2 = NULL;
102 Free(buffer2);
103};
104
105
106/********************************************** Main routine **************************************/
107
108int main(int argc, char **argv)
109{
110 // Get the top level suite from the registry
111 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
112
113 // Adds the test to the list of test to run
114 CppUnit::TextUi::TestRunner runner;
115 runner.addTest( suite );
116
117 // Change the default outputter to a compiler error format outputter
118 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
119 std::cerr ) );
120 // Run the tests.
121 bool wasSucessful = runner.run();
122
123 // Return error code 1 if the one of test failed.
124 return wasSucessful ? 0 : 1;
125};
Note: See TracBrowser for help on using the repository browser.