File: NDCTest.hh

package info (click to toggle)
log4cpp 1.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,444 kB
  • sloc: cpp: 6,715; sh: 3,670; ansic: 1,049; makefile: 295
file content (83 lines) | stat: -rw-r--r-- 2,131 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef _NDCTEST_HH
#define _NDCTEST_HH

#include <string>
#include "cppunit/TestCaller.h"
#include "cppunit/TestCase.h"
#include "cppunit/TestSuite.h"
#include <iostream>

template<class NDCCLASS> class NDCTest : public CppUnit::TestCase {
    protected:
    NDCCLASS* _nDC;

    public:
    NDCTest() {
    }

    NDCTest(std::string name) : CppUnit::TestCase(name) {
    }

    virtual void registerTests(CppUnit::TestSuite* suite) {
       suite->addTest(new CppUnit::TestCaller<NDCTest>("testEmpty", 
           &NDCTest<NDCCLASS>::testEmpty));
       suite->addTest(new CppUnit::TestCaller<NDCTest>("testPush", 
           &NDCTest<NDCCLASS>::testPush));
       suite->addTest(new CppUnit::TestCaller<NDCTest>("testPush2", 
           &NDCTest<NDCCLASS>::testPush2));
       suite->addTest(new CppUnit::TestCaller<NDCTest>("testPop", 
           &NDCTest<NDCCLASS>::testPop));
       suite->addTest(new CppUnit::TestCaller<NDCTest>("testClear", 
           &NDCTest<NDCCLASS>::testClear));
     }

    int countTestCases() const {
        return 5;
    }

    void setUp() {
        _nDC = new NDCCLASS();
    }

    void tearDown() {
        delete _nDC;
    }

    void testEmpty() {
        assert(_nDC->_get() == "");
        assert(_nDC->_getDepth() == 0);
    }

    void testPush() {
        _nDC->_push("push context 1");
        assert(_nDC->_get() == "push context 1");
        assert(_nDC->_getDepth() == 1);
        
    }

    void testPush2() {
        _nDC->_push("push context 1");
        _nDC->_push("push context 2");
        assert(_nDC->_get() == "push context 1 push context 2");
        assert(_nDC->_getDepth() == 2);
        
    }

    void testPop() {
        _nDC->_push("push context 1");
        _nDC->_push("push context 2");
        _nDC->_pop();
        assert(_nDC->_get() == "push context 1");
        assert(_nDC->_getDepth() == 1);        
    }

    void testClear() {
        _nDC->_push("push context 1");
        _nDC->_push("push context 2");
        _nDC->_clear();
        assert(_nDC->_get() == "");
        assert(_nDC->_getDepth() == 0);        
    }
};

#endif // _NDCTEST_HH