You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
1.8 KiB
85 lines
1.8 KiB
#ifndef UTIL_TEST |
|
#define UTIL_TEST |
|
|
|
|
|
#include "munit/munit.h" |
|
|
|
#include "../src/util.h" |
|
|
|
|
|
|
|
|
|
MunitResult testStrPos(const MunitParameter params[], |
|
void* user_data_or_fixture){ |
|
munit_assert_int( strpos( "thisisatest", "test" ), ==, 7 ); |
|
munit_assert_int( strpos( "testthisisatest", "test" ), ==, 0 ); |
|
munit_assert_int( strpos( "blar", "test" ), ==, -1 ); |
|
return MUNIT_OK; |
|
} |
|
|
|
MunitResult testCountLines(const MunitParameter params[], |
|
void* user_data_or_fixture){ |
|
char filename[] = "/tmp/yaip-test-file"; |
|
FILE *fp = fopen(filename, "w"); |
|
if ( fp == NULL ){ |
|
printf("Cannot open file %s\n", filename); |
|
return MUNIT_ERROR; |
|
} |
|
fprintf( fp, "test\n" ); |
|
fclose(fp); |
|
|
|
munit_assert_int( 1, ==, countLines(filename) ); |
|
|
|
fp = fopen(filename, "w"); |
|
if ( fp == NULL ){ |
|
printf("Cannot open file %s\n", filename); |
|
return MUNIT_ERROR; |
|
} |
|
fprintf( fp, "test2\ntest3\n" ); |
|
fclose(fp); |
|
|
|
munit_assert_int( 2, ==, countLines(filename) ); |
|
|
|
remove(filename); |
|
|
|
return MUNIT_OK; |
|
} |
|
|
|
static MunitTest util_tests[] = { |
|
{ |
|
"/util/versions", /* name */ |
|
testStrPos, /* test */ |
|
NULL, /* setup */ |
|
NULL, /* tear_down */ |
|
MUNIT_TEST_OPTION_NONE, /* options */ |
|
NULL /* parameters */ |
|
}, { |
|
"/util/countLines", /* name */ |
|
testCountLines, /* test */ |
|
NULL, /* setup */ |
|
NULL, /* tear_down */ |
|
MUNIT_TEST_OPTION_NONE, /* options */ |
|
NULL /* parameters */ |
|
}, |
|
/* Mark the end of the array with an entry where the test |
|
* function is NULL */ |
|
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } |
|
}; |
|
|
|
MunitSuite util_test_suite = { |
|
"/request", /* name */ |
|
util_tests, /* tests */ |
|
NULL, /* suites */ |
|
1, /* iterations */ |
|
MUNIT_SUITE_OPTION_NONE /* options */ |
|
}; |
|
|
|
#ifndef MAINTEST |
|
#define MAINTEST |
|
|
|
int main (int argc, char* argv[]) { |
|
return munit_suite_main(&util_test_suite, NULL, argc, argv); |
|
} |
|
|
|
#endif /* ifndef MAINTEST */ |
|
#endif /* ifndef REQUEST_TEST */
|
|
|