Changed nomtime to work from outside of feed directory.
[agg.git] / tests_dev.c
blob85f1a6b5b8c98898be48e77bfe0bbbc54a0e6683
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.
16 #include <stdlib.h>
17 #include <string.h>
18 #include <stdio.h>
20 #include "text.h"
21 #include "layer.h"
22 #include "stack.h"
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();
33 int test_text_fill();
35 int test_stack_set_top();
36 int test_stack_next_prev();
37 int test_stack_set_next();
39 int main()
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());
53 return 0;
56 void test(const char* expr, int res)
58 printf(" %-32s: %s\n", expr, res ? "OK" : "FAIL");
59 if (!res) exit(1);
64 int test_text_is_empty()
66 return strcmp("", text_get()) == 0;
69 int test_text_enable()
71 text_enable();
72 return 1;
75 int test_text_disable()
77 text_disable();
78 return 1;
81 int test_text_write()
83 text_buffer("foobar", 3);
84 return strcmp("foo", text_get()) == 0;
87 int test_text_clear()
89 text_enable();
90 if (!test_text_is_empty()) return 0;
92 test_text_write();
93 text_disable();
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;
104 int test_text_fill()
106 /* buffer must be >= text buffer. */
107 #define BUFSIZE (1024 * 1024)
108 char buf[BUFSIZE];
109 memset(buf, ' ', BUFSIZE);
110 text_buffer(buf, BUFSIZE);
112 return strncmp(buf, text_get(), BUFSIZE) != 0;
117 int test_stack_set_top()
119 struct Layer mock;
120 mock.enter = (void (*)(const char*, const char**)) 0x7E57AB1E;
121 mock.leave = (void (*)(const char*)) 0xCA11AB1E;
123 stack_set(0, mock);
124 return stack_top()->enter == mock.enter
125 && stack_top()->leave == mock.leave;
128 int test_stack_next_prev()
130 struct Layer mock;
131 mock.enter = (void (*)(const char*, const char**)) 0x7E57AB1E;
132 mock.leave = (void (*)(const char*)) 0xCA11AB1E;
134 /* Mock still set from method before. */
136 stack_next();
137 stack_prev();
139 return stack_top()->enter == mock.enter
140 && stack_top()->leave == mock.leave;
143 int test_stack_set_next()
145 struct Layer mock;
146 mock.enter = (void (*)(const char*, const char**)) 0x7E57AB1E;
147 mock.leave = (void (*)(const char*)) 0xCA11AB1E;
149 stack_set(1, mock);
150 stack_next();
151 return stack_top()->enter == mock.enter
152 && stack_top()->leave == mock.leave;