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
140
141
142
143
144
145
146
147
|
#if LV_BUILD_TEST
#include "../lvgl.h"
#include "unity/unity.h"
#include "lv_test_indev.h"
/* This function runs before each test */
void setUp(void);
/* This function runs after every test */
void tearDown(void);
void test_msgbox_creation_successful_with_close_button(void);
void test_msgbox_creation_successful_no_close_button(void);
void test_msgbox_creation_successful_modal(void);
void test_msgbox_get_title(void);
void test_msgbox_get_content(void);
void test_msgbox_close(void);
void test_msgbox_close_modal(void);
void test_msgbox_close_async(void);
void test_msgbox_close_async_modal(void);
static lv_obj_t * active_screen = NULL;
static lv_obj_t * msgbox = NULL;
void setUp(void)
{
active_screen = lv_screen_active();
}
void tearDown(void)
{
lv_obj_clean(active_screen);
}
void test_msgbox_creation_successful_with_close_button(void)
{
msgbox = lv_msgbox_create(active_screen);
lv_msgbox_add_title(msgbox, "The title");
lv_msgbox_add_text(msgbox, "The text");
lv_msgbox_add_footer_button(msgbox, "Apply");
lv_msgbox_add_footer_button(msgbox, "Close");
lv_msgbox_add_header_button(msgbox, LV_SYMBOL_AUDIO);
lv_msgbox_add_close_button(msgbox);
TEST_ASSERT_NOT_NULL(msgbox);
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/msgbox_ok_with_close_btn.png");
}
void test_msgbox_creation_successful_no_close_button(void)
{
msgbox = lv_msgbox_create(NULL);
lv_msgbox_add_title(msgbox, "The title");
lv_msgbox_add_text(msgbox, "The text");
lv_msgbox_add_footer_button(msgbox, "Apply");
lv_msgbox_add_footer_button(msgbox, "Close");
lv_msgbox_add_header_button(msgbox, LV_SYMBOL_AUDIO);
TEST_ASSERT_NOT_NULL(msgbox);
TEST_ASSERT_EQUAL_SCREENSHOT("widgets/msgbox_ok_no_close_btn.png");
}
void test_msgbox_creation_successful_modal(void)
{
// If parent is NULL the message box will be modal
msgbox = lv_msgbox_create(NULL);
lv_msgbox_add_title(msgbox, "The title");
lv_msgbox_add_text(msgbox, "The text");
lv_msgbox_add_footer_button(msgbox, "Apply");
lv_msgbox_add_footer_button(msgbox, "Close");
lv_msgbox_add_header_button(msgbox, LV_SYMBOL_AUDIO);
lv_msgbox_add_close_button(msgbox);
TEST_ASSERT_NOT_NULL(msgbox);
// Since msgbox has no parent, it won´t be clean up at tearDown()
lv_obj_clean(msgbox);
}
void test_msgbox_get_title(void)
{
const char * txt_title = "The title";
lv_obj_t * lbl_title = NULL;
msgbox = lv_msgbox_create(active_screen);
lv_msgbox_add_title(msgbox, "The title");
lv_msgbox_add_text(msgbox, "The text");
lv_msgbox_add_footer_button(msgbox, "Apply");
lv_msgbox_add_footer_button(msgbox, "Close");
lv_msgbox_add_header_button(msgbox, LV_SYMBOL_AUDIO);
lv_msgbox_add_close_button(msgbox);
// Msgbox title is a lv_label widget
lbl_title = lv_msgbox_get_title(msgbox);
TEST_ASSERT_EQUAL_STRING(txt_title, lv_label_get_text(lbl_title));
}
void test_msgbox_get_content(void)
{
msgbox = lv_msgbox_create(active_screen);
TEST_ASSERT_NOT_NULL(lv_msgbox_get_content(msgbox));
}
void test_msgbox_close(void)
{
msgbox = lv_msgbox_create(active_screen);
lv_msgbox_add_text(msgbox, "The text");
lv_msgbox_close(msgbox);
// lv_msgbox_close deletes the message box
TEST_ASSERT_NOT_NULL(msgbox);
}
void test_msgbox_close_modal(void)
{
msgbox = lv_msgbox_create(NULL);
lv_msgbox_add_text(msgbox, "The text");
lv_msgbox_close(msgbox);
// lv_msgbox_close deletes the message box
TEST_ASSERT_NOT_NULL(msgbox);
}
void test_msgbox_close_async(void)
{
msgbox = lv_msgbox_create(active_screen);
lv_msgbox_add_text(msgbox, "The text");
// lv_msgbox_close deletes the message box
TEST_ASSERT_NOT_NULL(msgbox);
}
void test_msgbox_close_async_modal(void)
{
msgbox = lv_msgbox_create(NULL);
lv_msgbox_add_text(msgbox, "The text");
// lv_msgbox_close deletes the message box
TEST_ASSERT_NOT_NULL(msgbox);
}
#endif
|