source: molecuilder/src/unittests/stackclassunittest.cpp@ 36c5cf

Last change on this file since 36c5cf was 44becc, checked in by Frederik Heber <heber@…>, 16 years ago

Tests now work with Eclipse ECUT's TestRunner.

  • new switch in configure.ac: --enable-ecut
  • all tests are compiled as single test as before
  • and a new TestRunner test suite that combines all test into a single executable which can be run as CppUnit program in Eclipse (and then gives JUnit like output).
  • Property mode set to 100644
File size: 1.9 KB
Line 
1/*
2 * stackclassunittest.cpp
3 *
4 * Created on: Oct 27, 2009
5 * Author: heber
6 */
7
8using namespace std;
9
10#include <cppunit/CompilerOutputter.h>
11#include <cppunit/extensions/TestFactoryRegistry.h>
12#include <cppunit/ui/text/TestRunner.h>
13
14#include "stackclassunittest.hpp"
15#include "log.hpp"
16
17#ifdef HAVE_TESTRUNNER
18#include "UnitTestMain.hpp"
19#endif /*HAVE_TESTRUNNER*/
20
21enum { testdimension=3 };
22
23/********************************************** Test classes **************************************/
24
25// Registers the fixture into the 'registry'
26CPPUNIT_TEST_SUITE_REGISTRATION( StackClassTest );
27
28
29void StackClassTest::setUp()
30{
31 Stack = new StackClass<int *>(testdimension);
32};
33
34
35void StackClassTest::tearDown()
36{
37 Stack->ClearStack();
38 delete(Stack);
39};
40
41/** UnitTest for StackClass<T> implementation
42 *
43 */
44
45void StackClassTest::TestImplementation()
46{
47 int testfield[testdimension] = {0,1,2};
48 //Log() << Verbose(1) << "Testing the snake stack..." << endl;
49 for (int i=0;i<testdimension;i++) {
50 //Log() << Verbose(2) << "Filling " << i << "th element of stack." << endl;
51 Stack->Push(&testfield[i]);
52 }
53 //Log() << Verbose(0) << endl;
54 //Output(out);
55 CPPUNIT_ASSERT_EQUAL(true, Stack->IsFull());
56 CPPUNIT_ASSERT_EQUAL(false, Stack->IsEmpty());
57 CPPUNIT_ASSERT_EQUAL((testdimension) % (int)testdimension, Stack->ItemCount());
58
59 CPPUNIT_ASSERT_EQUAL( true, Stack->RemoveItem(&testfield[1]) );
60 CPPUNIT_ASSERT_EQUAL((testdimension-1) % (int)testdimension, Stack->ItemCount());
61
62 CPPUNIT_ASSERT_EQUAL( true, Stack->RemoveItem(&testfield[2]) );
63 CPPUNIT_ASSERT_EQUAL((testdimension-2) % (int)testdimension, Stack->ItemCount());
64
65 CPPUNIT_ASSERT_EQUAL( true, Stack->RemoveItem(&testfield[0]) );
66 CPPUNIT_ASSERT_EQUAL((testdimension-3) % (int)testdimension, Stack->ItemCount());
67
68 Stack->ClearStack();
69 CPPUNIT_ASSERT_EQUAL(false, Stack->IsFull());
70 CPPUNIT_ASSERT_EQUAL(true, Stack->IsEmpty());
71 CPPUNIT_ASSERT_EQUAL(0, Stack->ItemCount());
72};
Note: See TracBrowser for help on using the repository browser.