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