]>
git.saurik.com Git - apt.git/blob - test/libapt/assert.h
4 #include <apt-pkg/macros.h>
7 #pragma GCC diagnostic push
8 #pragma GCC diagnostic ignored "-Wmissing-declarations"
11 #define equals(x,y) assertEquals(y, x, __LINE__)
12 #define equalsNot(x,y) assertEqualsNot(y, x, __LINE__)
14 template < typename X
, typename Y
>
15 APT_NORETURN
void OutputAssertEqual ( X expect
, char const * compare
, Y get
, unsigned long const & line
) {
16 std :: cerr
<< "Test FAILED: »" << expect
<< "« " << compare
<< " »" << get
<< "« at line " << line
<< std :: endl
;
17 std :: exit ( EXIT_FAILURE
);
20 template < typename X
, typename Y
>
21 void assertEquals ( X expect
, Y get
, unsigned long const & line
) {
24 OutputAssertEqual ( expect
, "==" , get
, line
);
27 template < typename X
, typename Y
>
28 void assertEqualsNot ( X expect
, Y get
, unsigned long const & line
) {
31 OutputAssertEqual ( expect
, "!=" , get
, line
);
34 void assertEquals ( unsigned int const & expect
, int const & get
, unsigned long const & line
) {
36 OutputAssertEqual ( expect
, "==" , get
, line
);
37 assertEquals
< unsigned int const &, unsigned int const &>( expect
, get
, line
);
40 void assertEquals ( int const & expect
, unsigned int const & get
, unsigned long const & line
) {
42 OutputAssertEqual ( expect
, "==" , get
, line
);
43 assertEquals
< unsigned int const &, unsigned int const &>( expect
, get
, line
);
46 void assertEquals ( unsigned long const & expect
, int const & get
, unsigned long const & line
) {
48 OutputAssertEqual ( expect
, "==" , get
, line
);
49 assertEquals
< unsigned long const &, unsigned long const &>( expect
, get
, line
);
52 void assertEquals ( int const & expect
, unsigned long const & get
, unsigned long const & line
) {
54 OutputAssertEqual ( expect
, "==" , get
, line
);
55 assertEquals
< unsigned long const &, unsigned long const &>( expect
, get
, line
);
59 #define equalsOr2(x,y,z) assertEqualsOr2(y, z, x, __LINE__)
61 template < typename X
, typename Y
>
62 void OutputAssertEqualOr2 ( X expect1
, X expect2
, char const * compare
, Y get
, unsigned long const & line
) {
63 std :: cerr
<< "Test FAILED: »" << expect1
<< "« or »" << expect2
<< "« " << compare
<< " »" << get
<< "« at line " << line
<< std :: endl
;
66 template < typename X
, typename Y
>
67 void assertEqualsOr2 ( X expect1
, X expect2
, Y get
, unsigned long const & line
) {
68 if ( expect1
== get
|| expect2
== get
)
70 OutputAssertEqualOr2 ( expect1
, expect2
, "==" , get
, line
);
73 void assertEqualsOr2 ( unsigned int const & expect1
, unsigned int const & expect2
, int const & get
, unsigned long const & line
) {
75 OutputAssertEqualOr2 ( expect1
, expect2
, "==" , get
, line
);
76 assertEqualsOr2
< unsigned int const &, unsigned int const &>( expect1
, expect2
, get
, line
);
79 void assertEqualsOr2 ( int const & expect1
, int const & expect2
, unsigned int const & get
, unsigned long const & line
) {
80 if ( expect1
< 0 && expect2
< 0 )
81 OutputAssertEqualOr2 ( expect1
, expect2
, "==" , get
, line
);
82 assertEqualsOr2
< unsigned int const &, unsigned int const &>( expect1
, expect2
, get
, line
);
86 #define equalsOr3(w,x,y,z) assertEqualsOr3(x, y, z, w, __LINE__)
88 template < typename X
, typename Y
>
89 void OutputAssertEqualOr3 ( X expect1
, X expect2
, X expect3
, char const * compare
, Y get
, unsigned long const & line
) {
90 std :: cerr
<< "Test FAILED: »" << expect1
<< "« or »" << expect2
<< "« or »" << expect3
<< "« " << compare
<< " »" << get
<< "« at line " << line
<< std :: endl
;
93 template < typename X
, typename Y
>
94 void assertEqualsOr3 ( X expect1
, X expect2
, X expect3
, Y get
, unsigned long const & line
) {
95 if ( expect1
== get
|| expect2
== get
|| expect3
== get
)
97 OutputAssertEqualOr3 ( expect1
, expect2
, expect3
, "==" , get
, line
);
100 #define equalsOr4(v,w,x,y,z) assertEqualsOr4(w, x, y, z, v, __LINE__)
102 template < typename X
, typename Y
>
103 void OutputAssertEqualOr4 ( X expect1
, X expect2
, X expect3
, X expect4
, char const * compare
, Y get
, unsigned long const & line
) {
104 std :: cerr
<< "Test FAILED: »" << expect1
<< "« or »" << expect2
<< "« or »" << expect3
<< "« or »" << expect4
<< "« " << compare
<< " »" << get
<< "« at line " << line
<< std :: endl
;
107 template < typename X
, typename Y
>
108 void assertEqualsOr4 ( X expect1
, X expect2
, X expect3
, X expect4
, Y get
, unsigned long const & line
) {
109 if ( expect1
== get
|| expect2
== get
|| expect3
== get
|| expect4
== get
)
111 OutputAssertEqualOr4 ( expect1
, expect2
, expect3
, expect4
, "==" , get
, line
);
114 // simple helper to quickly output a vectors
115 template < typename X
>
116 void dumpVector ( X vec
) {
117 for ( typename
X :: const_iterator v
= vec
. begin ();
119 std :: cout
<< * v
<< std :: endl
;
123 #pragma GCC diagnostic pop