]>
git.saurik.com Git - apt.git/blob - test/libapt/assert.h
5 #pragma GCC diagnostic push
6 #pragma GCC diagnostic ignored "-Wmissing-declarations"
9 #define equals(x,y) assertEquals(y, x, __LINE__)
10 #define equalsNot(x,y) assertEqualsNot(y, x, __LINE__)
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
);
18 template < typename X
, typename Y
>
19 void assertEquals ( X expect
, Y get
, unsigned long const & line
) {
22 OutputAssertEqual ( expect
, "==" , get
, line
);
25 template < typename X
, typename Y
>
26 void assertEqualsNot ( X expect
, Y get
, unsigned long const & line
) {
29 OutputAssertEqual ( expect
, "!=" , get
, line
);
32 void assertEquals ( unsigned int const & expect
, int const & get
, unsigned long const & line
) {
34 OutputAssertEqual ( expect
, "==" , get
, line
);
35 assertEquals
< unsigned int const &, unsigned int const &>( expect
, get
, line
);
38 void assertEquals ( int const & expect
, unsigned int const & get
, unsigned long const & line
) {
40 OutputAssertEqual ( expect
, "==" , get
, line
);
41 assertEquals
< unsigned int const &, unsigned int const &>( expect
, get
, line
);
44 void assertEquals ( unsigned long const & expect
, int const & get
, unsigned long const & line
) {
46 OutputAssertEqual ( expect
, "==" , get
, line
);
47 assertEquals
< unsigned long const &, unsigned long const &>( expect
, get
, line
);
50 void assertEquals ( int const & expect
, unsigned long const & get
, unsigned long const & line
) {
52 OutputAssertEqual ( expect
, "==" , get
, line
);
53 assertEquals
< unsigned long const &, unsigned long const &>( expect
, get
, line
);
57 #define equalsOr2(x,y,z) assertEqualsOr2(y, z, x, __LINE__)
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
;
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
)
68 OutputAssertEqualOr2 ( expect1
, expect2
, "==" , get
, line
);
71 void assertEqualsOr2 ( unsigned int const & expect1
, unsigned int const & expect2
, int const & get
, unsigned long const & line
) {
73 OutputAssertEqualOr2 ( expect1
, expect2
, "==" , get
, line
);
74 assertEqualsOr2
< unsigned int const &, unsigned int const &>( expect1
, expect2
, get
, line
);
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
);
84 #define equalsOr3(w,x,y,z) assertEqualsOr3(x, y, z, w, __LINE__)
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
;
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
)
95 OutputAssertEqualOr3 ( expect1
, expect2
, expect3
, "==" , get
, line
);
98 #define equalsOr4(v,w,x,y,z) assertEqualsOr4(w, x, y, z, v, __LINE__)
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
;
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
)
109 OutputAssertEqualOr4 ( expect1
, expect2
, expect3
, expect4
, "==" , get
, line
);
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 ();
117 std :: cout
<< * v
<< std :: endl
;
121 #pragma GCC diagnostic pop