2018-06-27 13:46:42 +08:00
|
|
|
|
#include "base/canvas.h"
|
2018-12-15 17:22:05 +08:00
|
|
|
|
#include "widgets/label.h"
|
2018-02-21 19:36:38 +08:00
|
|
|
|
#include "base/widget.h"
|
|
|
|
|
#include "font_dummy.h"
|
|
|
|
|
#include "lcd_log.h"
|
2018-02-22 08:36:54 +08:00
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
#include <stdlib.h>
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
|
|
|
|
TEST(Label, basic) {
|
|
|
|
|
value_t v1;
|
|
|
|
|
value_t v2;
|
2021-11-10 09:58:13 +08:00
|
|
|
|
widget_t* label = label_create(NULL, 10, 20, 30, 40);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
2021-11-10 09:58:13 +08:00
|
|
|
|
ASSERT_EQ(widget_set_text(label, L"OK"), RET_OK);
|
|
|
|
|
ASSERT_EQ(wcscmp(label->text.str, L"OK"), 0);
|
|
|
|
|
ASSERT_EQ(widget_set_text(label, L"Cancel"), RET_OK);
|
|
|
|
|
ASSERT_EQ(wcscmp(label->text.str, L"Cancel"), 0);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
|
|
|
|
value_set_wstr(&v1, L"label");
|
2021-11-10 09:58:13 +08:00
|
|
|
|
ASSERT_EQ(widget_set_prop(label, WIDGET_PROP_TEXT, &v1), RET_OK);
|
|
|
|
|
ASSERT_EQ(widget_get_prop(label, WIDGET_PROP_TEXT, &v2), RET_OK);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
ASSERT_EQ(wcscmp(v1.value.wstr, v2.value.wstr), 0);
|
|
|
|
|
|
2021-11-10 09:58:13 +08:00
|
|
|
|
widget_destroy(label);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|
2018-07-13 19:35:12 +08:00
|
|
|
|
|
2020-06-02 07:59:23 +08:00
|
|
|
|
TEST(Label, value) {
|
2021-11-10 09:58:13 +08:00
|
|
|
|
widget_t* label = label_create(NULL, 10, 20, 30, 40);
|
|
|
|
|
ASSERT_EQ(widget_set_value(label, 100), RET_OK);
|
|
|
|
|
ASSERT_EQ(widget_get_value(label), 100);
|
2020-06-05 17:16:19 +08:00
|
|
|
|
|
2021-11-10 09:58:13 +08:00
|
|
|
|
ASSERT_EQ(widget_add_value(label, 100), RET_OK);
|
|
|
|
|
ASSERT_EQ(widget_get_value(label), 200);
|
2020-06-02 07:59:23 +08:00
|
|
|
|
|
2021-11-10 09:58:13 +08:00
|
|
|
|
widget_destroy(label);
|
2020-06-02 07:59:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-13 19:35:12 +08:00
|
|
|
|
TEST(Label, clone) {
|
|
|
|
|
value_t v1;
|
|
|
|
|
widget_t* w1 = label_create(NULL, 10, 20, 30, 40);
|
|
|
|
|
|
|
|
|
|
widget_set_name(w1, "label");
|
|
|
|
|
value_set_wstr(&v1, L"label");
|
|
|
|
|
ASSERT_EQ(widget_set_prop(w1, WIDGET_PROP_TEXT, &v1), RET_OK);
|
|
|
|
|
|
|
|
|
|
widget_t* w2 = widget_clone(w1, NULL);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(widget_equal(w1, w2), TRUE);
|
|
|
|
|
|
|
|
|
|
widget_destroy(w1);
|
|
|
|
|
widget_destroy(w2);
|
|
|
|
|
}
|
2020-10-11 08:14:35 +08:00
|
|
|
|
|
|
|
|
|
TEST(Label, line_wrap) {
|
2021-11-10 09:58:13 +08:00
|
|
|
|
widget_t* label = label_create(NULL, 10, 20, 30, 40);
|
|
|
|
|
ASSERT_EQ(LABEL(label)->line_wrap, FALSE);
|
|
|
|
|
ASSERT_EQ(widget_set_prop_bool(label, WIDGET_PROP_LINE_WRAP, TRUE), RET_OK);
|
|
|
|
|
ASSERT_EQ(widget_get_prop_bool(label, WIDGET_PROP_LINE_WRAP, FALSE), TRUE);
|
|
|
|
|
ASSERT_EQ(LABEL(label)->line_wrap, TRUE);
|
2020-10-11 08:14:35 +08:00
|
|
|
|
|
2021-11-10 09:58:13 +08:00
|
|
|
|
widget_destroy(label);
|
2020-10-11 08:14:35 +08:00
|
|
|
|
}
|
2020-10-28 13:55:34 +08:00
|
|
|
|
|
|
|
|
|
TEST(Label, word_wrap) {
|
2021-11-10 09:58:13 +08:00
|
|
|
|
widget_t* label = label_create(NULL, 10, 20, 30, 40);
|
|
|
|
|
ASSERT_EQ(LABEL(label)->word_wrap, FALSE);
|
|
|
|
|
ASSERT_EQ(widget_set_prop_bool(label, WIDGET_PROP_WORD_WRAP, TRUE), RET_OK);
|
|
|
|
|
ASSERT_EQ(widget_get_prop_bool(label, WIDGET_PROP_WORD_WRAP, FALSE), TRUE);
|
|
|
|
|
ASSERT_EQ(LABEL(label)->word_wrap, TRUE);
|
2020-10-28 13:55:34 +08:00
|
|
|
|
|
2021-11-10 09:58:13 +08:00
|
|
|
|
widget_destroy(label);
|
2020-10-28 13:55:34 +08:00
|
|
|
|
}
|
2021-04-27 15:46:57 +08:00
|
|
|
|
|
|
|
|
|
TEST(Label, max_w) {
|
2021-11-10 09:58:13 +08:00
|
|
|
|
widget_t* label = label_create(NULL, 10, 20, 30, 40);
|
|
|
|
|
ASSERT_EQ(LABEL(label)->word_wrap, FALSE);
|
|
|
|
|
ASSERT_EQ(widget_set_prop_int(label, WIDGET_PROP_MAX_W, 123), RET_OK);
|
|
|
|
|
ASSERT_EQ(widget_get_prop_int(label, WIDGET_PROP_MAX_W, 0), 123);
|
|
|
|
|
ASSERT_EQ(LABEL(label)->max_w, 123);
|
2021-04-27 15:46:57 +08:00
|
|
|
|
|
2021-11-10 09:58:13 +08:00
|
|
|
|
widget_destroy(label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Label, add_value) {
|
|
|
|
|
widget_t* label = label_create(NULL, 10, 20, 30, 40);
|
|
|
|
|
|
|
|
|
|
widget_set_text_utf8(label, "10");
|
|
|
|
|
ASSERT_EQ((int)widget_get_value(label), 10);
|
|
|
|
|
ASSERT_EQ(widget_add_value(label, -1), RET_OK);
|
|
|
|
|
ASSERT_EQ((int)widget_get_value(label), 9);
|
2021-11-23 16:05:14 +08:00
|
|
|
|
|
2021-11-10 10:25:27 +08:00
|
|
|
|
ASSERT_EQ(widget_set_value(label, 100), RET_OK);
|
|
|
|
|
ASSERT_EQ((int)widget_get_value(label), 100);
|
|
|
|
|
|
|
|
|
|
widget_destroy(label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Label, add_value_int) {
|
|
|
|
|
widget_t* label = label_create(NULL, 10, 20, 30, 40);
|
|
|
|
|
|
|
|
|
|
widget_set_text_utf8(label, "10");
|
|
|
|
|
ASSERT_EQ(widget_get_value_int(label), 10);
|
|
|
|
|
ASSERT_EQ(widget_add_value_int(label, -1), RET_OK);
|
|
|
|
|
ASSERT_EQ(widget_get_value_int(label), 9);
|
2021-11-23 16:05:14 +08:00
|
|
|
|
|
2021-11-10 10:25:27 +08:00
|
|
|
|
ASSERT_EQ(widget_set_value_int(label, 100), RET_OK);
|
|
|
|
|
ASSERT_EQ(widget_get_value_int(label), 100);
|
2021-11-10 09:58:13 +08:00
|
|
|
|
|
|
|
|
|
widget_destroy(label);
|
2021-04-27 15:46:57 +08:00
|
|
|
|
}
|