source: molecuilder/src/unittests/memoryallocatorunittest.cpp@ eda56a

Last change on this file since eda56a was 543ce4, checked in by Frederik Heber <heber@…>, 16 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.