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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
#if LV_BUILD_TEST
#include "../lvgl.h"
#include "unity/unity.h"
void test_txt_should_insert_string_into_another(void)
{
const char * msg = "Hello ";
const char * suffix = "World";
char target[20] = {0};
size_t msg_len = strlen(msg);
strcpy(target, msg);
_lv_text_ins(target, msg_len, suffix);
TEST_ASSERT_EQUAL_STRING("Hello World", target);
}
void test_txt_should_handle_null_pointers_when_inserting(void)
{
const char * msg = "Hello ";
char target[20] = {0};
size_t msg_len = strlen(msg);
strcpy(target, msg);
_lv_text_ins(target, msg_len, NULL);
TEST_ASSERT_EQUAL_STRING("Hello ", target);
}
void test_txt_cut_should_handle_null_pointer_to_txt(void)
{
_lv_text_cut(NULL, 0, 6);
}
void test_txt_cut_happy_path(void)
{
char msg[] = "Hello World";
_lv_text_cut(msg, 0, 6);
TEST_ASSERT_EQUAL_STRING("World", msg);
}
void test_txt_cut_should_handle_len_longer_than_string_length(void)
{
char msg[] = "Hello World";
_lv_text_cut(msg, 0, 30);
TEST_ASSERT_EQUAL_UINT8(msg[0], 0x00);
}
void test_txt_get_encoded_next_should_decode_valid_ascii(void)
{
char msg[] = "Hello World!";
uint32_t result = 0;
result = _lv_text_encoded_next(msg, NULL);
TEST_ASSERT_EQUAL_UINT32((uint32_t) 'H', result);
}
void test_txt_get_encoded_next_detect_valid_2_byte_input(void)
{
char msg[] = "\xc3\xb1";
uint32_t result = 0;
result = _lv_text_encoded_next(msg, NULL);
TEST_ASSERT_EQUAL_UINT32(241, result);
}
void test_txt_get_encoded_next_detect_invalid_2_byte_input(void)
{
char msg[] = "\xc3\x28";
uint32_t result = 0;
result = _lv_text_encoded_next(msg, NULL);
TEST_ASSERT_EQUAL_UINT32(0, result);
}
void test_txt_get_encoded_next_detect_valid_3_byte_input(void)
{
char msg[] = "\xe2\x82\xa1";
uint32_t result = 0;
result = _lv_text_encoded_next(msg, NULL);
TEST_ASSERT_EQUAL_UINT32(8353, result);
}
void test_txt_get_encoded_next_detect_invalid_3_byte_input(void)
{
char msg[] = "\xe2\x28\xa1";
uint32_t result = 0;
result = _lv_text_encoded_next(msg, NULL);
TEST_ASSERT_EQUAL_UINT32(0, result);
}
void test_txt_get_encoded_next_detect_valid_4_byte_input(void)
{
char msg[] = "\xf0\x90\x8c\xbc";
uint32_t result = 0;
result = _lv_text_encoded_next(msg, NULL);
TEST_ASSERT_EQUAL_UINT32(66364, result);
}
void test_txt_get_encoded_next_detect_invalid_4_byte_input(void)
{
char msg[] = "\xf0\x28\x8c\x28";
uint32_t result = 0;
result = _lv_text_encoded_next(msg, NULL);
TEST_ASSERT_EQUAL_UINT32(0, result);
}
/* See #2615 for more information */
void test_txt_next_line_should_handle_empty_string(void)
{
const lv_font_t * font_ptr = NULL;
int32_t letter_space = 0;
int32_t max_width = 0;
lv_text_flag_t flag = LV_TEXT_FLAG_NONE;
uint32_t next_line = _lv_text_get_next_line("", font_ptr, letter_space, max_width, NULL, flag);
TEST_ASSERT_EQUAL_UINT32(0, next_line);
}
#endif
|