]> git.saurik.com Git - apt.git/blame - test/libapt/assert.h
trigger the usage of the fallback code for kfreebsd also in the
[apt.git] / test / libapt / assert.h
CommitLineData
cefb7c1f
DK
1#include <iostream>
2
fce11533 3#define equals(x,y) assertEquals(y, x, __LINE__)
527df5a2 4#define equalsNot(x,y) assertEqualsNot(y, x, __LINE__)
cefb7c1f
DK
5
6template < typename X, typename Y >
fce11533 7void OutputAssertEqual(X expect, char const* compare, Y get, unsigned long const &line) {
cefb7c1f
DK
8 std::cerr << "Test FAILED: »" << expect << "« " << compare << " »" << get << "« at line " << line << std::endl;
9}
10
11template < typename X, typename Y >
12void assertEquals(X expect, Y get, unsigned long const &line) {
13 if (expect == get)
14 return;
fce11533 15 OutputAssertEqual(expect, "==", get, line);
cefb7c1f
DK
16}
17
527df5a2
DK
18template < typename X, typename Y >
19void assertEqualsNot(X expect, Y get, unsigned long const &line) {
20 if (expect != get)
21 return;
22 OutputAssertEqual(expect, "!=", get, line);
23}
24
cefb7c1f
DK
25void assertEquals(unsigned int const &expect, int const &get, unsigned long const &line) {
26 if (get < 0)
fce11533 27 OutputAssertEqual(expect, "==", get, line);
cefb7c1f
DK
28 assertEquals<unsigned int const&, unsigned int const&>(expect, get, line);
29}
fce11533
DK
30
31void 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);
fa4d3cdc
DK
35}
36
37void 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
43void 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);
fce11533
DK
47}
48
49
50#define equalsOr2(x,y,z) assertEqualsOr2(y, z, x, __LINE__)
51
52template < typename X, typename Y >
53void 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
57template < typename X, typename Y >
58void 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
64void 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
70void 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
f7f0d6c7 76
7cb28948
DK
77#define equalsOr3(w,x,y,z) assertEqualsOr3(x, y, z, w, __LINE__)
78
79template < typename X, typename Y >
80void 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
84template < typename X, typename Y >
85void 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
527df5a2
DK
91#define equalsOr4(v,w,x,y,z) assertEqualsOr4(w, x, y, z, v, __LINE__)
92
93template < typename X, typename Y >
94void 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
98template < typename X, typename Y >
99void 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}
7cb28948 104
f7f0d6c7
DK
105// simple helper to quickly output a vectors
106template < typename X >
107void dumpVector(X vec) {
108 for (typename X::const_iterator v = vec.begin();
109 v != vec.end(); ++v)
110 std::cout << *v << std::endl;
111}