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