]>
git.saurik.com Git - apt.git/blob - test/libapt/assert.h
3 #define equals(x,y) assertEquals(y, x, __LINE__)
4 #define equalsNot(x,y) assertEqualsNot(y, x, __LINE__)
6 template < typename X
, typename Y
>
7 void OutputAssertEqual ( X expect
, char const * compare
, Y get
, unsigned long const & line
) {
8 std :: cerr
<< "Test FAILED: »" << expect
<< "« " << compare
<< " »" << get
<< "« at line " << line
<< std :: endl
;
11 template < typename X
, typename Y
>
12 void assertEquals ( X expect
, Y get
, unsigned long const & line
) {
15 OutputAssertEqual ( expect
, "==" , get
, line
);
18 template < typename X
, typename Y
>
19 void assertEqualsNot ( X expect
, Y get
, unsigned long const & line
) {
22 OutputAssertEqual ( expect
, "!=" , get
, line
);
25 void assertEquals ( unsigned int const & expect
, int const & get
, unsigned long const & line
) {
27 OutputAssertEqual ( expect
, "==" , get
, line
);
28 assertEquals
< unsigned int const &, unsigned int const &>( expect
, get
, line
);
31 void assertEquals ( int const & expect
, unsigned int const & get
, unsigned long const & line
) {
33 OutputAssertEqual ( expect
, "==" , get
, line
);
34 assertEquals
< unsigned int const &, unsigned int const &>( expect
, get
, line
);
37 void assertEquals ( unsigned long const & expect
, int const & get
, unsigned long const & line
) {
39 OutputAssertEqual ( expect
, "==" , get
, line
);
40 assertEquals
< unsigned long const &, unsigned long const &>( expect
, get
, line
);
43 void assertEquals ( int const & expect
, unsigned long const & get
, unsigned long const & line
) {
45 OutputAssertEqual ( expect
, "==" , get
, line
);
46 assertEquals
< unsigned long const &, unsigned long const &>( expect
, get
, line
);
50 #define equalsOr2(x,y,z) assertEqualsOr2(y, z, x, __LINE__)
52 template < typename X
, typename Y
>
53 void OutputAssertEqualOr2 ( X expect1
, X expect2
, char const * compare
, Y get
, unsigned long const & line
) {
54 std :: cerr
<< "Test FAILED: »" << expect1
<< "« or »" << expect2
<< "« " << compare
<< " »" << get
<< "« at line " << line
<< std :: endl
;
57 template < typename X
, typename Y
>
58 void assertEqualsOr2 ( X expect1
, X expect2
, Y get
, unsigned long const & line
) {
59 if ( expect1
== get
|| expect2
== get
)
61 OutputAssertEqualOr2 ( expect1
, expect2
, "==" , get
, line
);
64 void assertEqualsOr2 ( unsigned int const & expect1
, unsigned int const & expect2
, int const & get
, unsigned long const & line
) {
66 OutputAssertEqualOr2 ( expect1
, expect2
, "==" , get
, line
);
67 assertEqualsOr2
< unsigned int const &, unsigned int const &>( expect1
, expect2
, get
, line
);
70 void assertEqualsOr2 ( int const & expect1
, int const & expect2
, unsigned int const & get
, unsigned long const & line
) {
71 if ( expect1
< 0 && expect2
< 0 )
72 OutputAssertEqualOr2 ( expect1
, expect2
, "==" , get
, line
);
73 assertEqualsOr2
< unsigned int const &, unsigned int const &>( expect1
, expect2
, get
, line
);
77 #define equalsOr3(w,x,y,z) assertEqualsOr3(x, y, z, w, __LINE__)
79 template < typename X
, typename Y
>
80 void OutputAssertEqualOr3 ( X expect1
, X expect2
, X expect3
, char const * compare
, Y get
, unsigned long const & line
) {
81 std :: cerr
<< "Test FAILED: »" << expect1
<< "« or »" << expect2
<< "« or »" << expect3
<< "« " << compare
<< " »" << get
<< "« at line " << line
<< std :: endl
;
84 template < typename X
, typename Y
>
85 void assertEqualsOr3 ( X expect1
, X expect2
, X expect3
, Y get
, unsigned long const & line
) {
86 if ( expect1
== get
|| expect2
== get
|| expect3
== get
)
88 OutputAssertEqualOr3 ( expect1
, expect2
, expect3
, "==" , get
, line
);
91 #define equalsOr4(v,w,x,y,z) assertEqualsOr4(w, x, y, z, v, __LINE__)
93 template < typename X
, typename Y
>
94 void OutputAssertEqualOr4 ( X expect1
, X expect2
, X expect3
, X expect4
, char const * compare
, Y get
, unsigned long const & line
) {
95 std :: cerr
<< "Test FAILED: »" << expect1
<< "« or »" << expect2
<< "« or »" << expect3
<< "« or »" << expect4
<< "« " << compare
<< " »" << get
<< "« at line " << line
<< std :: endl
;
98 template < typename X
, typename Y
>
99 void assertEqualsOr4 ( X expect1
, X expect2
, X expect3
, X expect4
, Y get
, unsigned long const & line
) {
100 if ( expect1
== get
|| expect2
== get
|| expect3
== get
|| expect4
== get
)
102 OutputAssertEqualOr4 ( expect1
, expect2
, expect3
, expect4
, "==" , get
, line
);
105 // simple helper to quickly output a vectors
106 template < typename X
>
107 void dumpVector ( X vec
) {
108 for ( typename
X :: const_iterator v
= vec
. begin ();
110 std :: cout
<< * v
<< std :: endl
;