]> git.saurik.com Git - apt.git/blob - test/libapt/assert.h
merged from the debian-sid branch
[apt.git] / test / libapt / assert.h
1 #include <iostream>
2
3 #define equals(x,y) assertEquals(y, x, __LINE__)
4 #define equalsNot(x,y) assertEqualsNot(y, x, __LINE__)
5
6 template < typename X, typename Y >
7 void OutputAssertEqual(X expect, char const* compare, Y get, unsigned long const &line) {
8 std::cerr << "Test FAILED: »" << expect << "« " << compare << " »" << get << "« at line " << line << std::endl;
9 }
10
11 template < typename X, typename Y >
12 void assertEquals(X expect, Y get, unsigned long const &line) {
13 if (expect == get)
14 return;
15 OutputAssertEqual(expect, "==", get, line);
16 }
17
18 template < typename X, typename Y >
19 void assertEqualsNot(X expect, Y get, unsigned long const &line) {
20 if (expect != get)
21 return;
22 OutputAssertEqual(expect, "!=", get, line);
23 }
24
25 void assertEquals(unsigned int const &expect, int const &get, unsigned long const &line) {
26 if (get < 0)
27 OutputAssertEqual(expect, "==", get, line);
28 assertEquals<unsigned int const&, unsigned int const&>(expect, get, line);
29 }
30
31 void assertEquals(int const &expect, unsigned int const &get, unsigned long const &line) {
32 if (expect < 0)
33 OutputAssertEqual(expect, "==", get, line);
34 assertEquals<unsigned int const&, unsigned int const&>(expect, get, line);
35 }
36
37 void assertEquals(unsigned long const &expect, int const &get, unsigned long const &line) {
38 if (get < 0)
39 OutputAssertEqual(expect, "==", get, line);
40 assertEquals<unsigned long const&, unsigned long const&>(expect, get, line);
41 }
42
43 void assertEquals(int const &expect, unsigned long const &get, unsigned long const &line) {
44 if (expect < 0)
45 OutputAssertEqual(expect, "==", get, line);
46 assertEquals<unsigned long const&, unsigned long const&>(expect, get, line);
47 }
48
49
50 #define equalsOr2(x,y,z) assertEqualsOr2(y, z, x, __LINE__)
51
52 template < typename X, typename Y >
53 void OutputAssertEqualOr2(X expect1, X expect2, char const* compare, Y get, unsigned long const &line) {
54 std::cerr << "Test FAILED: »" << expect1 << "« or »" << expect2 << "« " << compare << " »" << get << "« at line " << line << std::endl;
55 }
56
57 template < typename X, typename Y >
58 void assertEqualsOr2(X expect1, X expect2, Y get, unsigned long const &line) {
59 if (expect1 == get || expect2 == get)
60 return;
61 OutputAssertEqualOr2(expect1, expect2, "==", get, line);
62 }
63
64 void assertEqualsOr2(unsigned int const &expect1, unsigned int const &expect2, int const &get, unsigned long const &line) {
65 if (get < 0)
66 OutputAssertEqualOr2(expect1, expect2, "==", get, line);
67 assertEqualsOr2<unsigned int const&, unsigned int const&>(expect1, expect2, get, line);
68 }
69
70 void assertEqualsOr2(int const &expect1, int const &expect2, unsigned int const &get, unsigned long const &line) {
71 if (expect1 < 0 && expect2 < 0)
72 OutputAssertEqualOr2(expect1, expect2, "==", get, line);
73 assertEqualsOr2<unsigned int const&, unsigned int const&>(expect1, expect2, get, line);
74 }
75
76
77 #define equalsOr3(w,x,y,z) assertEqualsOr3(x, y, z, w, __LINE__)
78
79 template < typename X, typename Y >
80 void OutputAssertEqualOr3(X expect1, X expect2, X expect3, char const* compare, Y get, unsigned long const &line) {
81 std::cerr << "Test FAILED: »" << expect1 << "« or »" << expect2 << "« or »" << expect3 << "« " << compare << " »" << get << "« at line " << line << std::endl;
82 }
83
84 template < typename X, typename Y >
85 void assertEqualsOr3(X expect1, X expect2, X expect3, Y get, unsigned long const &line) {
86 if (expect1 == get || expect2 == get || expect3 == get)
87 return;
88 OutputAssertEqualOr3(expect1, expect2, expect3, "==", get, line);
89 }
90
91 #define equalsOr4(v,w,x,y,z) assertEqualsOr4(w, x, y, z, v, __LINE__)
92
93 template < typename X, typename Y >
94 void OutputAssertEqualOr4(X expect1, X expect2, X expect3, X expect4, char const* compare, Y get, unsigned long const &line) {
95 std::cerr << "Test FAILED: »" << expect1 << "« or »" << expect2 << "« or »" << expect3 << "« or »" << expect4 << "« " << compare << " »" << get << "« at line " << line << std::endl;
96 }
97
98 template < typename X, typename Y >
99 void assertEqualsOr4(X expect1, X expect2, X expect3, X expect4, Y get, unsigned long const &line) {
100 if (expect1 == get || expect2 == get || expect3 == get || expect4 == get)
101 return;
102 OutputAssertEqualOr4(expect1, expect2, expect3, expect4, "==", get, line);
103 }
104
105 // simple helper to quickly output a vectors
106 template < typename X >
107 void dumpVector(X vec) {
108 for (typename X::const_iterator v = vec.begin();
109 v != vec.end(); ++v)
110 std::cout << *v << std::endl;
111 }