tests: simplify use of testing framework

Also improve test results summary
This commit is contained in:
Hugues Delorme 2017-03-29 10:37:05 +02:00
parent 1293d3d1b9
commit 0d3a7e755c
5 changed files with 33 additions and 44 deletions

View File

@ -42,10 +42,8 @@ struct gmio_memblock gmio_memblock_for_tests()
return gmio_memblock_malloc(512 * 1024); /* 512KB */
}
const char* all_tests()
void all_tests()
{
UTEST_SUITE_START();
gmio_memblock_set_default_constructor(gmio_memblock_for_tests);
UTEST_RUN(test_amf_write_doc_null);
@ -54,7 +52,5 @@ const char* all_tests()
UTEST_RUN(test_amf_write_doc_1_zip64);
UTEST_RUN(test_amf_write_doc_1_zip64_file);
UTEST_RUN(test_amf_write_doc_1_task_iface);
return NULL;
}
UTEST_MAIN(all_tests)

View File

@ -34,10 +34,8 @@
#include "test_core_internal.c"
#include "test_core_platform.c"
const char* all_tests()
void all_tests()
{
UTEST_SUITE_START();
UTEST_RUN(test_core__buffer);
UTEST_RUN(test_core__endian);
UTEST_RUN(test_core__error);
@ -61,7 +59,5 @@ const char* all_tests()
UTEST_RUN(test_internal__zip_utils);
UTEST_RUN(test_internal__zlib_enumvalues);
UTEST_RUN(test_internal__file_utils);
return NULL;
}
UTEST_MAIN(all_tests)

View File

@ -44,10 +44,8 @@ struct gmio_memblock gmio_memblock_for_tests()
return gmio_memblock(buff, sizeof(buff), NULL);
}
const char* all_tests()
void all_tests()
{
UTEST_SUITE_START();
gmio_memblock_set_default_constructor(gmio_memblock_for_tests);
#if 0
@ -73,7 +71,5 @@ const char* all_tests()
UTEST_RUN(test_stlb_header_str);
UTEST_RUN(test_stlb_header_to_printable_str);
return NULL;
}
UTEST_MAIN(all_tests)

View File

@ -3,8 +3,7 @@
* http://c.learncodethehardway.org/book/ex30.html
*/
#ifndef UTEST_ASSERT_H
#define UTEST_ASSERT_H
#pragma once
#include <stdio.h>
@ -47,5 +46,3 @@
#define UTEST_COMPARE_CSTR(expected, actual) \
UTEST_COMPARE__INTERNAL(expected, actual, UTEST_EQUALS_STRCMP__INTERNAL, "%s", "C-string")
#endif /* UTEST_ASSERT_H */

View File

@ -3,38 +3,42 @@
* http://c.learncodethehardway.org/book/ex30.html
*/
#ifndef UTEST_LIB_H
#define UTEST_LIB_H
#pragma once
#include "utest_assert.h"
#include <stdlib.h>
#define UTEST_SUITE_START() const char* message = NULL
#define UTEST_RUN(func_run_utest) \
{\
printf("\n-----%s", " " #func_run_utest); \
++test_count;\
const char* str_error = func_run_utest();\
if (str_error == NULL)\
++test_ok_count;\
else\
printf(" FAILED: %s\n", str_error);\
}
#define UTEST_RUN(test) printf("\n-----%s", " " #test); \
message = test();\
tests_run++;\
if (message) return message;
#define UTEST_MAIN(name) \
#define UTEST_MAIN(func_run_utests) \
int main(int argc, char *argv[]) {\
const char *result = NULL; \
\
const char* prg_test_name = argv[0];\
(void)argc;\
printf("----\nRUNNING: %s\n", argv[0]);\
result = name();\
if (result != NULL) {\
printf("\n\nFAILED: %s\n", result);\
test_count = test_ok_count = 0;\
printf("----\nRUNNING: %s\n", prg_test_name);\
func_run_utests();\
printf("\n\nRESULT: %s\n"\
" tested: %d | passed: %d | failed: %d\n",\
prg_test_name,\
test_count, test_ok_count, test_count - test_ok_count);\
if (test_count > 0) {\
if (test_ok_count == test_count)\
printf(" ALL TESTS PASSED\n");\
else\
printf(" TEST FAILURE\n");\
}\
else {\
printf("\n\nALL TESTS PASSED\n");\
}\
printf("Tests run: %d\n", tests_run);\
exit(result != NULL);\
exit(test_ok_count != test_count);\
}
static int tests_run;
#endif /* UTEST_LIB_H */
static int test_count;
static int test_ok_count;