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