]>
git.saurik.com Git - apt.git/blob - test/libapt/assert.h
3e45143a35ef1c43902581c13d8930e6e381af70
4 #include <apt-pkg/macros.h>
5 #include <apt-pkg/error.h>
8 #pragma GCC diagnostic push
9 #pragma GCC diagnostic ignored "-Wmissing-declarations"
12 #define equals(x,y) assertEquals(y, x, __LINE__)
13 #define equalsNot(x,y) assertEqualsNot(y, x, __LINE__)
15 template < typename X
, typename Y
>
16 APT_NORETURN
void OutputAssertEqual ( X expect
, char const * compare
, Y get
, unsigned long const & line
) {
17 std :: cerr
<< "Test FAILED: »" << expect
<< "« " << compare
<< " »" << get
<< "« at line " << line
<< std :: endl
;
18 _error
-> DumpErrors ( std :: cerr
);
19 std :: exit ( EXIT_FAILURE
);
22 template < typename X
, typename Y
>
23 void assertEquals ( X expect
, Y get
, unsigned long const & line
) {
26 OutputAssertEqual ( expect
, "==" , get
, line
);
29 template < typename X
, typename Y
>
30 void assertEqualsNot ( X expect
, Y get
, unsigned long const & line
) {
33 OutputAssertEqual ( expect
, "!=" , get
, line
);
36 void assertEquals ( unsigned int const & expect
, int const & get
, unsigned long const & line
) {
38 OutputAssertEqual ( expect
, "==" , get
, line
);
39 assertEquals
< unsigned int const &, unsigned int const &>( expect
, get
, line
);
42 void assertEquals ( int const & expect
, unsigned int const & get
, unsigned long const & line
) {
44 OutputAssertEqual ( expect
, "==" , get
, line
);
45 assertEquals
< unsigned int const &, unsigned int const &>( expect
, get
, line
);
48 void assertEquals ( unsigned long const & expect
, int const & get
, unsigned long const & line
) {
50 OutputAssertEqual ( expect
, "==" , get
, line
);
51 assertEquals
< unsigned long const &, unsigned long const &>( expect
, get
, line
);
54 void assertEquals ( int const & expect
, unsigned long const & get
, unsigned long const & line
) {
56 OutputAssertEqual ( expect
, "==" , get
, line
);
57 assertEquals
< unsigned long const &, unsigned long const &>( expect
, get
, line
);
61 #define equalsOr2(x,y,z) assertEqualsOr2(y, z, x, __LINE__)
63 template < typename X
, typename Y
>
64 void 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
;
68 template < typename X
, typename Y
>
69 void assertEqualsOr2 ( X expect1
, X expect2
, Y get
, unsigned long const & line
) {
70 if ( expect1
== get
|| expect2
== get
)
72 OutputAssertEqualOr2 ( expect1
, expect2
, "==" , get
, line
);
75 void assertEqualsOr2 ( unsigned int const & expect1
, unsigned int const & expect2
, int const & get
, unsigned long const & line
) {
77 OutputAssertEqualOr2 ( expect1
, expect2
, "==" , get
, line
);
78 assertEqualsOr2
< unsigned int const &, unsigned int const &>( expect1
, expect2
, get
, line
);
81 void 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
);
88 #define equalsOr3(w,x,y,z) assertEqualsOr3(x, y, z, w, __LINE__)
90 template < typename X
, typename Y
>
91 void 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
;
95 template < typename X
, typename Y
>
96 void assertEqualsOr3 ( X expect1
, X expect2
, X expect3
, Y get
, unsigned long const & line
) {
97 if ( expect1
== get
|| expect2
== get
|| expect3
== get
)
99 OutputAssertEqualOr3 ( expect1
, expect2
, expect3
, "==" , get
, line
);
102 #define equalsOr4(v,w,x,y,z) assertEqualsOr4(w, x, y, z, v, __LINE__)
104 template < typename X
, typename Y
>
105 void 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
;
109 template < typename X
, typename Y
>
110 void 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
)
113 OutputAssertEqualOr4 ( expect1
, expect2
, expect3
, expect4
, "==" , get
, line
);
116 // simple helper to quickly output a vectors
117 template < typename X
>
118 void dumpVector ( X vec
) {
119 for ( typename
X :: const_iterator v
= vec
. begin ();
121 std :: cout
<< * v
<< std :: endl
;
125 #pragma GCC diagnostic pop