forked from lc-soft/LCUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_textview_resize.c
166 lines (132 loc) · 3.93 KB
/
test_textview_resize.c
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include <LCUI_Build.h>
#include <LCUI/LCUI.h>
#include <LCUI/timer.h>
#include <LCUI/gui/widget.h>
#include <LCUI/gui/widget/textview.h>
#include <LCUI/gui/css_parser.h>
#include "test.h"
#include "libtest.h"
/* clang-format off */
static struct {
LCUI_Widget block;
LCUI_Widget inline_block;
} self;
static const char *css = CodeToString(
.block {
width: 100px;
margin: 10px;
padding: 10px;
display: block;
border: 1px solid #f00;
}
.inline-block {
margin: 10px;
padding: 10px;
display: inline-block;
border: 1px solid #f00;
}
.short-content {
content: "hello!";
}
.long-content {
content: "this is long long long long long long long text";
}
);
/* clang-format on */
static void build(void)
{
LCUI_Widget root;
LCUI_LoadCSSString(css, __FILE__);
self.block = LCUIWidget_New("textview");
self.inline_block = LCUIWidget_New("textview");
Widget_SetId(self.block, "debug-block");
Widget_SetId(self.inline_block, "debug-inline-block");
TextView_SetTextW(self.block, L"block");
TextView_SetTextW(self.inline_block, L"inline block");
Widget_AddClass(self.block, "block");
Widget_AddClass(self.inline_block, "inline-block");
root = LCUIWidget_GetRoot();
Widget_Append(root, self.block);
Widget_Append(root, self.inline_block);
}
static void test_textview_set_text(void *arg)
{
_DEBUG_MSG("set text\n");
TextView_SetText(self.inline_block,
"long long long long long long long "
"long long long long long long long "
"long long long long long long long text");
TextView_SetText(self.block, "long long long long long long long "
"long long long long long long long "
"long long long long long long long text");
}
static void check_textview_set_text(void)
{
LCUIWidget_Update();
it_b("check block width", self.block->width == 122.0f, TRUE);
it_b("check block height", self.block->height > 140.0f, TRUE);
it_b("check inline block width", self.inline_block->width > 520.0f,
TRUE);
it_b("check inline block height", self.inline_block->height < 45.0f,
TRUE);
}
static void test_textview_set_short_content_css(void *arg)
{
_DEBUG_MSG("set text\n");
Widget_AddClass(self.block, "short-content");
Widget_AddClass(self.inline_block, "short-content");
}
static void check_textview_set_short_content_css(void)
{
LCUIWidget_Update();
it_b("check block width", self.block->width == 122.0f, TRUE);
it_b("check block height", self.block->height < 45.0f, TRUE);
it_b("check inline block width", self.inline_block->width < 70.0f,
TRUE);
it_b("check inline block height", self.inline_block->height < 45.0f,
TRUE);
}
static void test_textview_set_long_content_css(void *arg)
{
_DEBUG_MSG("set text\n");
Widget_RemoveClass(self.block, "short-content");
Widget_RemoveClass(self.inline_block, "short-content");
Widget_AddClass(self.block, "long-content");
Widget_AddClass(self.inline_block, "long-content");
}
static void check_textview_set_long_content_css(void)
{
LCUIWidget_Update();
it_b("check block width", self.block->width == 122.0f, TRUE);
it_b("check block height", self.block->height > 60.0f, TRUE);
it_b("check inline block width", self.inline_block->width > 250.0f,
TRUE);
it_b("check inline block height", self.inline_block->height < 45.0f,
TRUE);
}
void test_textview_resize(void)
{
LCUI_Init();
build();
test_textview_set_text(NULL);
describe("check textview set text", check_textview_set_text);
test_textview_set_short_content_css(NULL);
describe("check textview set short content css",
check_textview_set_short_content_css);
test_textview_set_long_content_css(NULL);
describe("check textview set long content css",
check_textview_set_long_content_css);
LCUI_Destroy();
}
#ifdef PREVIEW_MODE
int tests_count = 0;
int main(void)
{
LCUI_Init();
build();
LCUI_SetTimeout(2000, test_textview_set_text, NULL);
LCUI_SetTimeout(4000, test_textview_set_short_content_css, NULL);
LCUI_SetTimeout(6000, test_textview_set_long_content_css, NULL);
return LCUI_Main();
}
#endif