tests: simplify use of testing framework
Also improve test results summary
This commit is contained in:
parent
1293d3d1b9
commit
0d3a7e755c
@ -42,10 +42,8 @@ struct gmio_memblock gmio_memblock_for_tests()
|
|||||||
return gmio_memblock_malloc(512 * 1024); /* 512KB */
|
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);
|
gmio_memblock_set_default_constructor(gmio_memblock_for_tests);
|
||||||
|
|
||||||
UTEST_RUN(test_amf_write_doc_null);
|
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);
|
||||||
UTEST_RUN(test_amf_write_doc_1_zip64_file);
|
UTEST_RUN(test_amf_write_doc_1_zip64_file);
|
||||||
UTEST_RUN(test_amf_write_doc_1_task_iface);
|
UTEST_RUN(test_amf_write_doc_1_task_iface);
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
UTEST_MAIN(all_tests)
|
UTEST_MAIN(all_tests)
|
||||||
|
@ -34,10 +34,8 @@
|
|||||||
#include "test_core_internal.c"
|
#include "test_core_internal.c"
|
||||||
#include "test_core_platform.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__buffer);
|
||||||
UTEST_RUN(test_core__endian);
|
UTEST_RUN(test_core__endian);
|
||||||
UTEST_RUN(test_core__error);
|
UTEST_RUN(test_core__error);
|
||||||
@ -61,7 +59,5 @@ const char* all_tests()
|
|||||||
UTEST_RUN(test_internal__zip_utils);
|
UTEST_RUN(test_internal__zip_utils);
|
||||||
UTEST_RUN(test_internal__zlib_enumvalues);
|
UTEST_RUN(test_internal__zlib_enumvalues);
|
||||||
UTEST_RUN(test_internal__file_utils);
|
UTEST_RUN(test_internal__file_utils);
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
UTEST_MAIN(all_tests)
|
UTEST_MAIN(all_tests)
|
||||||
|
@ -44,10 +44,8 @@ struct gmio_memblock gmio_memblock_for_tests()
|
|||||||
return gmio_memblock(buff, sizeof(buff), NULL);
|
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);
|
gmio_memblock_set_default_constructor(gmio_memblock_for_tests);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -73,7 +71,5 @@ const char* all_tests()
|
|||||||
|
|
||||||
UTEST_RUN(test_stlb_header_str);
|
UTEST_RUN(test_stlb_header_str);
|
||||||
UTEST_RUN(test_stlb_header_to_printable_str);
|
UTEST_RUN(test_stlb_header_to_printable_str);
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
UTEST_MAIN(all_tests)
|
UTEST_MAIN(all_tests)
|
||||||
|
@ -3,8 +3,7 @@
|
|||||||
* http://c.learncodethehardway.org/book/ex30.html
|
* http://c.learncodethehardway.org/book/ex30.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef UTEST_ASSERT_H
|
#pragma once
|
||||||
#define UTEST_ASSERT_H
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@ -47,5 +46,3 @@
|
|||||||
|
|
||||||
#define UTEST_COMPARE_CSTR(expected, actual) \
|
#define UTEST_COMPARE_CSTR(expected, actual) \
|
||||||
UTEST_COMPARE__INTERNAL(expected, actual, UTEST_EQUALS_STRCMP__INTERNAL, "%s", "C-string")
|
UTEST_COMPARE__INTERNAL(expected, actual, UTEST_EQUALS_STRCMP__INTERNAL, "%s", "C-string")
|
||||||
|
|
||||||
#endif /* UTEST_ASSERT_H */
|
|
||||||
|
@ -3,38 +3,42 @@
|
|||||||
* http://c.learncodethehardway.org/book/ex30.html
|
* http://c.learncodethehardway.org/book/ex30.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef UTEST_LIB_H
|
#pragma once
|
||||||
#define UTEST_LIB_H
|
|
||||||
|
|
||||||
#include "utest_assert.h"
|
#include "utest_assert.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define UTEST_SUITE_START() const char* message = NULL
|
#define UTEST_RUN(func_run_utest) \
|
||||||
|
{\
|
||||||
#define UTEST_RUN(test) printf("\n-----%s", " " #test); \
|
printf("\n-----%s", " " #func_run_utest); \
|
||||||
message = test();\
|
++test_count;\
|
||||||
tests_run++;\
|
const char* str_error = func_run_utest();\
|
||||||
if (message) return message;
|
if (str_error == NULL)\
|
||||||
|
++test_ok_count;\
|
||||||
|
else\
|
||||||
|
printf(" FAILED: %s\n", str_error);\
|
||||||
|
}
|
||||||
|
|
||||||
#define UTEST_MAIN(name) \
|
#define UTEST_MAIN(func_run_utests) \
|
||||||
int main(int argc, char *argv[]) {\
|
int main(int argc, char *argv[]) {\
|
||||||
const char *result = NULL; \
|
const char* prg_test_name = argv[0];\
|
||||||
\
|
(void)argc;\
|
||||||
(void)argc; \
|
test_count = test_ok_count = 0;\
|
||||||
printf("----\nRUNNING: %s\n", argv[0]);\
|
printf("----\nRUNNING: %s\n", prg_test_name);\
|
||||||
result = name();\
|
func_run_utests();\
|
||||||
if (result != NULL) {\
|
printf("\n\nRESULT: %s\n"\
|
||||||
printf("\n\nFAILED: %s\n", result);\
|
" 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 {\
|
exit(test_ok_count != test_count);\
|
||||||
printf("\n\nALL TESTS PASSED\n");\
|
|
||||||
}\
|
|
||||||
printf("Tests run: %d\n", tests_run);\
|
|
||||||
exit(result != NULL);\
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int tests_run;
|
static int test_count;
|
||||||
|
static int test_ok_count;
|
||||||
#endif /* UTEST_LIB_H */
|
|
||||||
|
Loading…
Reference in New Issue
Block a user