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