2 #include "../../src/utils.h"
4 static void test_int_to_str(const char *ref, int num) {
5 char *result = int_to_str(num);
6 assert_string_equal(ref, result);
10 static void test_int_to_str_return_expected(void **state) {
13 test_int_to_str("0", 0);
14 test_int_to_str("-1337", -1337);
15 test_int_to_str("65535", 65535);
18 static void test_is_decimal_fail_empty(void **state) {
21 assert_false(is_decimal(NULL));
22 assert_false(is_decimal(""));
25 static void test_is_decimal_fail_hex(void **state) {
28 assert_false(is_decimal("DEADBEEF"));
29 assert_false(is_decimal("0xCAFE"));
32 static void test_is_decimal_fail_junk_suffix(void **state) {
35 assert_false(is_decimal("123foobar"));
36 assert_false(is_decimal("777 "));
39 static void test_is_decimal_pass_simple(void **state) {
42 assert_true(is_decimal("0"));
43 assert_true(is_decimal("123"));
46 static void test_is_decimal_pass_signs(void **state) {
49 assert_true(is_decimal("-123"));
50 assert_true(is_decimal("+123"));
53 static void test_is_decimal_pass_whitespace_prefix(void **state) {
56 assert_true(is_decimal(" \r\n\t 777"));
59 static void test_string_eq(void **state) {
62 assert_true(string_eq(NULL, NULL));
63 assert_true(string_eq("", ""));
64 assert_true(string_eq("\tfoo 123", "\tfoo 123"));
66 assert_false(string_eq(NULL, ""));
67 assert_false(string_eq("", NULL));
68 assert_false(string_eq("foo", "FOO"));
69 assert_false(string_eq("foo", " foo"));
73 const struct CMUnitTest tests[] = {
74 cmocka_unit_test(test_int_to_str_return_expected),
75 cmocka_unit_test(test_is_decimal_fail_empty),
76 cmocka_unit_test(test_is_decimal_fail_hex),
77 cmocka_unit_test(test_is_decimal_fail_junk_suffix),
78 cmocka_unit_test(test_is_decimal_pass_simple),
79 cmocka_unit_test(test_is_decimal_pass_signs),
80 cmocka_unit_test(test_is_decimal_pass_whitespace_prefix),
81 cmocka_unit_test(test_string_eq),
85 cmocka_set_skip_filter("test_unix_*");
88 return cmocka_run_group_tests(tests, NULL, NULL);