]>
git.saurik.com Git - apt.git/blob - test/libapt/assert.h
4 #define equals(x,y) assertEquals(y, x, __LINE__)
5 #define equalsNot(x,y) assertEqualsNot(y, x, __LINE__)
7 template < typename X
, typename Y
>
8 void OutputAssertEqual ( X expect
, char const * compare
, Y get
, unsigned long const & line
) {
9 std :: cerr
<< "Test FAILED: »" << expect
<< "« " << compare
<< " »" << get
<< "« at line " << line
<< std :: endl
;
10 std :: exit ( EXIT_FAILURE
);
13 template < typename X
, typename Y
>
14 void assertEquals ( X expect
, Y get
, unsigned long const & line
) {
17 OutputAssertEqual ( expect
, "==" , get
, line
);
20 template < typename X
, typename Y
>
21 void assertEqualsNot ( X expect
, Y get
, unsigned long const & line
) {
24 OutputAssertEqual ( expect
, "!=" , get
, line
);
27 void assertEquals ( unsigned int const & expect
, int const & get
, unsigned long const & line
) {
29 OutputAssertEqual ( expect
, "==" , get
, line
);
30 assertEquals
< unsigned int const &, unsigned int const &>( expect
, get
, line
);
33 void assertEquals ( int const & expect
, unsigned int const & get
, unsigned long const & line
) {
35 OutputAssertEqual ( expect
, "==" , get
, line
);
36 assertEquals
< unsigned int const &, unsigned int const &>( expect
, get
, line
);
39 void assertEquals ( unsigned long const & expect
, int const & get
, unsigned long const & line
) {
41 OutputAssertEqual ( expect
, "==" , get
, line
);
42 assertEquals
< unsigned long const &, unsigned long const &>( expect
, get
, line
);
45 void assertEquals ( int const & expect
, unsigned long const & get
, unsigned long const & line
) {
47 OutputAssertEqual ( expect
, "==" , get
, line
);
48 assertEquals
< unsigned long const &, unsigned long const &>( expect
, get
, line
);
52 #define equalsOr2(x,y,z) assertEqualsOr2(y, z, x, __LINE__)
54 template < typename X
, typename Y
>
55 void OutputAssertEqualOr2 ( X expect1
, X expect2
, char const * compare
, Y get
, unsigned long const & line
) {
56 std :: cerr
<< "Test FAILED: »" << expect1
<< "« or »" << expect2
<< "« " << compare
<< " »" << get
<< "« at line " << line
<< std :: endl
;
59 template < typename X
, typename Y
>
60 void assertEqualsOr2 ( X expect1
, X expect2
, Y get
, unsigned long const & line
) {
61 if ( expect1
== get
|| expect2
== get
)
63 OutputAssertEqualOr2 ( expect1
, expect2
, "==" , get
, line
);
66 void assertEqualsOr2 ( unsigned int const & expect1
, unsigned int const & expect2
, int const & get
, unsigned long const & line
) {
68 OutputAssertEqualOr2 ( expect1
, expect2
, "==" , get
, line
);
69 assertEqualsOr2
< unsigned int const &, unsigned int const &>( expect1
, expect2
, get
, line
);
72 void assertEqualsOr2 ( int const & expect1
, int const & expect2
, unsigned int const & get
, unsigned long const & line
) {
73 if ( expect1
< 0 && expect2
< 0 )
74 OutputAssertEqualOr2 ( expect1
, expect2
, "==" , get
, line
);
75 assertEqualsOr2
< unsigned int const &, unsigned int const &>( expect1
, expect2
, get
, line
);
79 #define equalsOr3(w,x,y,z) assertEqualsOr3(x, y, z, w, __LINE__)
81 template < typename X
, typename Y
>
82 void OutputAssertEqualOr3 ( X expect1
, X expect2
, X expect3
, char const * compare
, Y get
, unsigned long const & line
) {
83 std :: cerr
<< "Test FAILED: »" << expect1
<< "« or »" << expect2
<< "« or »" << expect3
<< "« " << compare
<< " »" << get
<< "« at line " << line
<< std :: endl
;
86 template < typename X
, typename Y
>
87 void assertEqualsOr3 ( X expect1
, X expect2
, X expect3
, Y get
, unsigned long const & line
) {
88 if ( expect1
== get
|| expect2
== get
|| expect3
== get
)
90 OutputAssertEqualOr3 ( expect1
, expect2
, expect3
, "==" , get
, line
);
93 #define equalsOr4(v,w,x,y,z) assertEqualsOr4(w, x, y, z, v, __LINE__)
95 template < typename X
, typename Y
>
96 void OutputAssertEqualOr4 ( X expect1
, X expect2
, X expect3
, X expect4
, char const * compare
, Y get
, unsigned long const & line
) {
97 std :: cerr
<< "Test FAILED: »" << expect1
<< "« or »" << expect2
<< "« or »" << expect3
<< "« or »" << expect4
<< "« " << compare
<< " »" << get
<< "« at line " << line
<< std :: endl
;
100 template < typename X
, typename Y
>
101 void assertEqualsOr4 ( X expect1
, X expect2
, X expect3
, X expect4
, Y get
, unsigned long const & line
) {
102 if ( expect1
== get
|| expect2
== get
|| expect3
== get
|| expect4
== get
)
104 OutputAssertEqualOr4 ( expect1
, expect2
, expect3
, expect4
, "==" , get
, line
);
107 // simple helper to quickly output a vectors
108 template < typename X
>
109 void dumpVector ( X vec
) {
110 for ( typename
X :: const_iterator v
= vec
. begin ();
112 std :: cout
<< * v
<< std :: endl
;