File: reporter.cpp

package info (click to toggle)
libtut 0.0.20070706-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, lenny, squeeze, stretch, wheezy
  • size: 1,020 kB
  • ctags: 607
  • sloc: cpp: 3,588; sh: 2,202; xml: 137; makefile: 59; ansic: 9
file content (132 lines) | stat: -rw-r--r-- 2,947 bytes parent folder | download | duplicates (4)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <tut/tut.hpp>
#include <tut/tut_reporter.hpp>
#include <sstream>

using std::stringstream;

namespace tut
{
    
/**
 * Testing reporter.
 */
struct reporter_test
{
    test_result tr1;
    test_result tr2;
    test_result tr3;
    test_result tr4;
    test_result tr5;

    reporter_test() 
        : tr1("foo", 1, "", test_result::ok),
          tr2("foo", 2, "", test_result::fail),
          tr3("foo", 3, "", test_result::ex),
          tr4("foo", 4, "", test_result::warn),
          tr5("foo", 5, "", test_result::term)
    {
    }
};

typedef test_group<reporter_test> tg;
typedef tg::object object;
tg reporter_test("default reporter");

template<>
template<>
void object::test<1>()
{
    stringstream ss;
    ss << tr1 << tr2 << tr3 << tr4 << tr5;
    ensure_equals("operator << formatter", ss.str(), ".[2=F][3=X][4=W][5=T]");
}

template<>
template<>
void object::test<2>()
{
    stringstream ss;
    reporter repo(ss);

    ensure_equals("ok count", repo.ok_count, 0);
    ensure_equals("fail count", repo.failures_count, 0);
    ensure_equals("ex count", repo.exceptions_count, 0);
    ensure_equals("warn count", repo.warnings_count, 0);
    ensure_equals("term count", repo.terminations_count, 0);

    repo.run_started();
    repo.test_completed(tr1);
    repo.test_completed(tr2);
    repo.test_completed(tr2);
    repo.test_completed(tr3);
    repo.test_completed(tr3);
    repo.test_completed(tr3);
    repo.test_completed(tr4);
    repo.test_completed(tr4);
    repo.test_completed(tr4);
    repo.test_completed(tr4);
    repo.test_completed(tr5);
    repo.test_completed(tr5);
    repo.test_completed(tr5);
    repo.test_completed(tr5);
    repo.test_completed(tr5);

    ensure_equals("ok count", repo.ok_count, 1);
    ensure_equals("fail count", repo.failures_count, 2);
    ensure_equals("ex count", repo.exceptions_count, 3);
    ensure_equals("warn count", repo.warnings_count, 4);
    ensure_equals("term count", repo.terminations_count, 5);
    ensure(!repo.all_ok());
}

template<>
template<>
void object::test<3>()
{
    std::stringstream ss;
    tut::reporter repo(ss);

    repo.run_started();
    repo.test_completed(tr1);

    ensure_equals("ok count",repo.ok_count,1);
    ensure(repo.all_ok());

    repo.run_started();
    ensure_equals("ok count",repo.ok_count,0);
}

template<>
template<>
void object::test<4>()
{
    stringstream ss;
    reporter repo(ss);

    repo.run_started();
    repo.test_completed(tr1);
    ensure(repo.all_ok());

    repo.run_started();
    repo.test_completed(tr1);
    repo.test_completed(tr2);
    ensure(!repo.all_ok());

    repo.run_started();
    repo.test_completed(tr3);
    repo.test_completed(tr1);
    ensure(!repo.all_ok());

    repo.run_started();
    repo.test_completed(tr1);
    repo.test_completed(tr4);
    ensure(!repo.all_ok());

    repo.run_started();
    repo.test_completed(tr5);
    repo.test_completed(tr1);
    ensure(!repo.all_ok());
}

}