1 /* agg - the news aggregator
2 * Copyright (C) 2011 Andreas Waidler <arandes@programmers.at>
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 #define TEST(expr) test(#expr, expr)
25 void test(const char* expr
, int res
);
27 int test_text_is_empty();
28 int test_text_enable();
29 int test_text_disable();
30 int test_text_write();
31 int test_text_clear();
32 int test_text_append();
35 int test_stack_set_top();
36 int test_stack_next_prev();
37 int test_stack_set_next();
41 TEST(test_text_is_empty());
42 TEST(test_text_enable());
43 TEST(test_text_disable());
44 TEST(test_text_write());
45 TEST(test_text_clear());
46 TEST(test_text_append());
47 TEST(test_text_fill());
49 TEST(test_stack_set_top());
50 TEST(test_stack_next_prev());
51 TEST(test_stack_set_next());
56 void test(const char* expr
, int res
)
58 printf(" %-32s: %s\n", expr
, res
? "OK" : "FAIL");
64 int test_text_is_empty()
66 return strcmp("", text_get()) == 0;
69 int test_text_enable()
75 int test_text_disable()
83 text_buffer("foobar", 3);
84 return strcmp("foo", text_get()) == 0;
90 if (!test_text_is_empty()) return 0;
94 return test_text_is_empty();
97 int test_text_append()
99 text_buffer("foobar", 3);
100 text_buffer("foobar", 3);
101 return strcmp("foofoo", text_get()) == 0;
106 /* buffer must be >= text buffer. */
107 #define BUFSIZE (1024 * 1024)
109 memset(buf
, ' ', BUFSIZE
);
110 text_buffer(buf
, BUFSIZE
);
112 return strncmp(buf
, text_get(), BUFSIZE
) != 0;
117 int test_stack_set_top()
120 mock
.enter
= (void (*)(const char*, const char**)) 0x7E57AB1E;
121 mock
.leave
= (void (*)(const char*)) 0xCA11AB1E;
124 return stack_top()->enter
== mock
.enter
125 && stack_top()->leave
== mock
.leave
;
128 int test_stack_next_prev()
131 mock
.enter
= (void (*)(const char*, const char**)) 0x7E57AB1E;
132 mock
.leave
= (void (*)(const char*)) 0xCA11AB1E;
134 /* Mock still set from method before. */
139 return stack_top()->enter
== mock
.enter
140 && stack_top()->leave
== mock
.leave
;
143 int test_stack_set_next()
146 mock
.enter
= (void (*)(const char*, const char**)) 0x7E57AB1E;
147 mock
.leave
= (void (*)(const char*)) 0xCA11AB1E;
151 return stack_top()->enter
== mock
.enter
152 && stack_top()->leave
== mock
.leave
;