-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_test.c
More file actions
48 lines (36 loc) · 1.22 KB
/
error_test.c
File metadata and controls
48 lines (36 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "tl_error.h"
#include "unity.h"
#include <stdlib.h>
#include <string.h>
void setUp(void) {
// Setup code if needed
}
void tearDown(void) {
// Teardown code if needed
}
static void test_tl_error_set_with_fixed_message(void) {
TLError error = {0};
tl_error_set(&error, TL_ERROR_INTERNAL, "fixed error message");
TEST_ASSERT_EQUAL(TL_ERROR_INTERNAL, error.code);
TEST_ASSERT_NOT_NULL(error.message);
TEST_ASSERT_EQUAL_STRING("fixed error message", error.message);
free((void *)error.message);
}
static void test_tl_error_set_with_formatted_message(void) {
TLError error = {0};
tl_error_set(&error, TL_ERROR_NOT_FOUND, "formatted error: %d", 42);
TEST_ASSERT_EQUAL(TL_ERROR_NOT_FOUND, error.code);
TEST_ASSERT_NOT_NULL(error.message);
TEST_ASSERT_EQUAL_STRING("formatted error: 42", error.message);
free((void *)error.message);
}
static void test_tl_error_set_with_null_error(void) {
tl_error_set(NULL, TL_ERROR_NOT_READY, "this should not crash");
}
int main(void) {
UNITY_BEGIN();
RUN_TEST(test_tl_error_set_with_fixed_message);
RUN_TEST(test_tl_error_set_with_formatted_message);
RUN_TEST(test_tl_error_set_with_null_error);
return UNITY_END();
}