forked from vieter-v/libvieter
test: started porting cron tests
This commit is contained in:
parent
c018d8d86c
commit
30e086ad6b
6 changed files with 97 additions and 119 deletions
|
|
@ -1,69 +1,38 @@
|
|||
#include "acutest.h"
|
||||
#include "vieter_cron.h"
|
||||
|
||||
void test_tutorial(void) {
|
||||
void *mem;
|
||||
void test_not_allowed() {
|
||||
char *expressions[] = {
|
||||
"4 *-7",
|
||||
"4 *-7/4",
|
||||
"4 7/*",
|
||||
"0 0 30 2",
|
||||
"0 /5",
|
||||
"0 ",
|
||||
"0",
|
||||
" 0",
|
||||
" 0 ",
|
||||
"1 2 3 4~9",
|
||||
"1 1-3-5",
|
||||
"0 5/2-5",
|
||||
"",
|
||||
"1 1/2/3",
|
||||
"*5 8",
|
||||
"x 8",
|
||||
NULL
|
||||
};
|
||||
|
||||
mem = malloc(10);
|
||||
TEST_CHECK(mem != NULL);
|
||||
int i = 0;
|
||||
|
||||
mem = realloc(mem, 20);
|
||||
TEST_CHECK(mem != NULL);
|
||||
while (expressions[i] != NULL) {
|
||||
vieter_cron_expression out;
|
||||
TEST_CHECK_(vieter_cron_parse_expression(&out, expressions[i]) != vieter_cron_parse_ok, "%s should error", expressions[i]);
|
||||
|
||||
free(mem);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void test_fail(void) {
|
||||
int a, b;
|
||||
|
||||
/* This condition is designed to fail so you can see what the failed test
|
||||
* output looks like. */
|
||||
a = 1;
|
||||
b = 2;
|
||||
TEST_CHECK(a + b == 5);
|
||||
|
||||
/* Here is TEST_CHECK_ in action. */
|
||||
TEST_CHECK_(a + b == 5, "%d + %d == 5", a, b);
|
||||
|
||||
/* We may also show more information about the failure. */
|
||||
if (!TEST_CHECK(a + b == 5)) {
|
||||
TEST_MSG("a: %d", a);
|
||||
TEST_MSG("b: %d", b);
|
||||
}
|
||||
|
||||
/* The macro TEST_MSG() only outputs something when the preceding
|
||||
* condition fails, so we can avoid the 'if' statement. */
|
||||
TEST_CHECK(a + b == 3);
|
||||
TEST_MSG("a: %d", a);
|
||||
TEST_MSG("b: %d", b);
|
||||
}
|
||||
|
||||
static void helper(void) {
|
||||
/* Kill the current test with a condition which is never true. */
|
||||
TEST_ASSERT(1 == 2);
|
||||
|
||||
/* This never happens because the test is aborted above. */
|
||||
TEST_CHECK(1 + 2 == 2 + 1);
|
||||
}
|
||||
|
||||
void test_abort(void) {
|
||||
helper();
|
||||
|
||||
/* This test never happens because the test is aborted inside the helper()
|
||||
* function. */
|
||||
TEST_CHECK(1 * 2 == 2 * 1);
|
||||
}
|
||||
|
||||
void test_crash(void) {
|
||||
int *invalid = ((int *)NULL) + 0xdeadbeef;
|
||||
|
||||
*invalid = 42;
|
||||
TEST_CHECK_(1 == 1, "This should never execute, due to a write into "
|
||||
"an invalid address.");
|
||||
}
|
||||
|
||||
TEST_LIST = {{"tutorial", test_tutorial},
|
||||
{"fail", test_fail},
|
||||
{"abort", test_abort},
|
||||
{"crash", test_crash},
|
||||
{NULL, NULL}};
|
||||
TEST_LIST = {
|
||||
{"not_allowed", test_not_allowed},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue