mirror of
https://github.com/lc-soft/LCUI.git
synced 2026-11-30 16:48:21 +01:00
Introduce ctest_suite_t, ctest_parse_args, ctest_run_suites and CTEST_MAIN macro to standardize test binary entry points. Support --grep / --grep= / --list / --interactive / --help. Add lib/ctest/tests/ for self-tests covering str converters and grep filter logic.
60 lines
1.3 KiB
C
60 lines
1.3 KiB
C
#include <assert.h>
|
|
#include <string.h>
|
|
#include <ctest.h>
|
|
|
|
static void test_int_to_str(void)
|
|
{
|
|
char buf[256];
|
|
int val = 42;
|
|
ctest_int_to_str(&val, buf, 255);
|
|
assert(strcmp(buf, "42") == 0);
|
|
|
|
val = -1;
|
|
ctest_int_to_str(&val, buf, 255);
|
|
assert(strcmp(buf, "-1") == 0);
|
|
}
|
|
|
|
static void test_uint_to_str(void)
|
|
{
|
|
char buf[256];
|
|
unsigned val = 123u;
|
|
ctest_uint_to_str(&val, buf, 255);
|
|
assert(strcmp(buf, "123") == 0);
|
|
}
|
|
|
|
static void test_float_to_str(void)
|
|
{
|
|
char buf[256];
|
|
float val = 3.14f;
|
|
ctest_float_to_str(&val, buf, 255);
|
|
assert(strncmp(buf, "3.14", 4) == 0);
|
|
}
|
|
|
|
static void test_str_to_str(void)
|
|
{
|
|
char buf[256];
|
|
const char *val = "hello";
|
|
ctest_str_to_str((void *)val, buf, 255);
|
|
assert(strcmp(buf, "\"hello\"") == 0);
|
|
}
|
|
|
|
static void test_bool_to_str(void)
|
|
{
|
|
char buf[256];
|
|
bool val_true = true;
|
|
bool val_false = false;
|
|
ctest_bool_to_str(&val_true, buf, 255);
|
|
assert(strcmp(buf, "true") == 0);
|
|
ctest_bool_to_str(&val_false, buf, 255);
|
|
assert(strcmp(buf, "false") == 0);
|
|
}
|
|
|
|
void test_str_funcs(void)
|
|
{
|
|
test_int_to_str();
|
|
test_uint_to_str();
|
|
test_float_to_str();
|
|
test_str_to_str();
|
|
test_bool_to_str();
|
|
}
|