2018-11-08 17:12:40 +08:00
|
|
|
|
#include <string>
|
|
|
|
|
#include "gtest/gtest.h"
|
2018-12-15 17:22:05 +08:00
|
|
|
|
#include "widgets/tab_button.h"
|
|
|
|
|
#include "widgets/tab_button_group.h"
|
2018-11-08 17:12:40 +08:00
|
|
|
|
|
|
|
|
|
TEST(TabButton, basic) {
|
|
|
|
|
value_t v1;
|
|
|
|
|
value_t v2;
|
|
|
|
|
widget_t* g = tab_button_group_create(NULL, 0, 0, 100, 100);
|
|
|
|
|
widget_t* w = tab_button_create(g, 0, 0, 100, 100);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(tab_button_set_value(w, TRUE), RET_OK);
|
|
|
|
|
ASSERT_EQ(TAB_BUTTON(w)->value, TRUE);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(tab_button_set_value(w, FALSE), RET_OK);
|
|
|
|
|
ASSERT_EQ(TAB_BUTTON(w)->value, FALSE);
|
|
|
|
|
|
|
|
|
|
value_set_str(&v1, "icon");
|
|
|
|
|
ASSERT_EQ(widget_set_prop(w, WIDGET_PROP_ICON, &v1), RET_OK);
|
|
|
|
|
ASSERT_EQ(widget_get_prop(w, WIDGET_PROP_ICON, &v2), RET_OK);
|
|
|
|
|
ASSERT_EQ(strcmp(v1.value.str, v2.value.str), 0);
|
|
|
|
|
|
|
|
|
|
value_set_str(&v1, "active_icon");
|
|
|
|
|
ASSERT_EQ(widget_set_prop(w, WIDGET_PROP_ACTIVE_ICON, &v1), RET_OK);
|
|
|
|
|
ASSERT_EQ(widget_get_prop(w, WIDGET_PROP_ACTIVE_ICON, &v2), RET_OK);
|
|
|
|
|
ASSERT_EQ(strcmp(v1.value.str, v2.value.str), 0);
|
|
|
|
|
|
2019-12-18 15:39:12 +08:00
|
|
|
|
value_set_str(&v1, "tab_button_view_page1");
|
|
|
|
|
ASSERT_EQ(widget_set_prop(w, WIDGET_PROP_LOAD_UI, &v1), RET_OK);
|
|
|
|
|
ASSERT_EQ(widget_get_prop(w, WIDGET_PROP_LOAD_UI, &v2), RET_OK);
|
|
|
|
|
ASSERT_EQ(strcmp(v1.value.str, v2.value.str), 0);
|
|
|
|
|
|
2018-11-08 17:12:40 +08:00
|
|
|
|
widget_destroy(g);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include "log_change_events.inc"
|
|
|
|
|
|
|
|
|
|
TEST(TabButton, event) {
|
|
|
|
|
widget_t* g = tab_button_group_create(NULL, 0, 0, 100, 100);
|
|
|
|
|
widget_t* w = tab_button_create(g, 0, 0, 100, 100);
|
|
|
|
|
|
|
|
|
|
tab_button_set_value(w, TRUE);
|
|
|
|
|
|
|
|
|
|
s_log = "";
|
|
|
|
|
widget_on(w, EVT_VALUE_WILL_CHANGE, on_change_events, NULL);
|
|
|
|
|
widget_on(w, EVT_VALUE_CHANGED, on_change_events, NULL);
|
|
|
|
|
|
|
|
|
|
tab_button_set_value(w, TRUE);
|
|
|
|
|
ASSERT_EQ(s_log, "");
|
|
|
|
|
|
|
|
|
|
tab_button_set_value(w, FALSE);
|
|
|
|
|
ASSERT_EQ(s_log, "will_change;change;");
|
|
|
|
|
|
|
|
|
|
widget_destroy(g);
|
|
|
|
|
}
|
2019-02-26 11:36:12 +08:00
|
|
|
|
|
|
|
|
|
TEST(TabButton, cast) {
|
|
|
|
|
widget_t* g = tab_button_group_create(NULL, 0, 0, 100, 100);
|
|
|
|
|
widget_t* w = tab_button_create(g, 0, 0, 100, 100);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(w, tab_button_cast(w));
|
|
|
|
|
ASSERT_NE(w, tab_button_group_cast(w));
|
|
|
|
|
|
|
|
|
|
widget_destroy(g);
|
|
|
|
|
}
|
2020-09-18 09:45:32 +08:00
|
|
|
|
|
|
|
|
|
TEST(TabButton, change_value) {
|
|
|
|
|
widget_t* g = tab_button_group_create(NULL, 0, 0, 100, 100);
|
|
|
|
|
widget_t* w = tab_button_create(g, 0, 0, 100, 100);
|
|
|
|
|
value_change_event_t evt;
|
|
|
|
|
memset(&evt, 0x00, sizeof(evt));
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(widget_set_prop_bool(w, WIDGET_PROP_VALUE, FALSE), RET_OK);
|
|
|
|
|
widget_on(w, EVT_VALUE_WILL_CHANGE, on_value_will_changed_accept, NULL);
|
|
|
|
|
widget_on(w, EVT_VALUE_CHANGED, on_value_changed, &evt);
|
|
|
|
|
ASSERT_EQ(widget_set_prop_bool(w, WIDGET_PROP_VALUE, TRUE), RET_OK);
|
|
|
|
|
ASSERT_EQ(widget_get_prop_bool(w, WIDGET_PROP_VALUE, FALSE), TRUE);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_bool(&(evt.old_value)), FALSE);
|
|
|
|
|
ASSERT_EQ(value_bool(&(evt.new_value)), TRUE);
|
|
|
|
|
|
2020-12-01 10:30:44 +08:00
|
|
|
|
widget_destroy(g);
|
2020-10-18 12:17:55 +08:00
|
|
|
|
idle_dispatch();
|
2020-09-18 09:45:32 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(TabButton, change_value_abort) {
|
|
|
|
|
widget_t* g = tab_button_group_create(NULL, 0, 0, 100, 100);
|
|
|
|
|
widget_t* w = tab_button_create(g, 0, 0, 100, 100);
|
|
|
|
|
value_change_event_t evt;
|
|
|
|
|
memset(&evt, 0x00, sizeof(evt));
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(widget_set_prop_bool(w, WIDGET_PROP_VALUE, FALSE), RET_OK);
|
|
|
|
|
widget_on(w, EVT_VALUE_WILL_CHANGE, on_value_will_changed_abort, NULL);
|
|
|
|
|
ASSERT_EQ(widget_set_prop_bool(w, WIDGET_PROP_VALUE, TRUE), RET_OK);
|
|
|
|
|
ASSERT_EQ(widget_get_prop_bool(w, WIDGET_PROP_VALUE, TRUE), FALSE);
|
|
|
|
|
|
2020-12-01 10:30:44 +08:00
|
|
|
|
widget_destroy(g);
|
2020-10-18 12:17:55 +08:00
|
|
|
|
idle_dispatch();
|
2020-09-18 09:45:32 +08:00
|
|
|
|
}
|