2018-12-15 17:22:05 +08:00
|
|
|
|
#include "widgets/button.h"
|
2019-01-22 17:49:15 +08:00
|
|
|
|
#include "base/idle.h"
|
2018-02-21 19:36:38 +08:00
|
|
|
|
#include "base/canvas.h"
|
|
|
|
|
#include "base/widget.h"
|
2018-07-14 07:01:13 +08:00
|
|
|
|
#include "base/layout.h"
|
2019-01-22 17:49:15 +08:00
|
|
|
|
#include "base/window_manager.h"
|
|
|
|
|
#include "widgets/view.h"
|
|
|
|
|
#include "widgets/window.h"
|
2018-02-21 19:36:38 +08:00
|
|
|
|
#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(Button, basic) {
|
|
|
|
|
value_t v1;
|
|
|
|
|
value_t v2;
|
2018-07-09 07:32:38 +08:00
|
|
|
|
widget_t* w = button_create(NULL, 10, 20, 30, 40);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
2018-07-09 07:32:38 +08:00
|
|
|
|
ASSERT_EQ(widget_set_text(w, L"OK"), RET_OK);
|
|
|
|
|
ASSERT_EQ(wcscmp(w->text.str, L"OK"), 0);
|
|
|
|
|
ASSERT_EQ(widget_set_text(w, L"Cancel"), RET_OK);
|
|
|
|
|
ASSERT_EQ(wcscmp(w->text.str, L"Cancel"), 0);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
|
|
|
|
value_set_wstr(&v1, L"button");
|
2018-07-09 07:32:38 +08:00
|
|
|
|
ASSERT_EQ(widget_set_prop(w, WIDGET_PROP_TEXT, &v1), RET_OK);
|
|
|
|
|
ASSERT_EQ(widget_get_prop(w, WIDGET_PROP_TEXT, &v2), RET_OK);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
ASSERT_EQ(wcscmp(v1.value.wstr, v2.value.wstr), 0);
|
2018-07-09 07:42:35 +08:00
|
|
|
|
|
2018-07-09 07:32:38 +08:00
|
|
|
|
value_set_int(&v1, 200);
|
|
|
|
|
ASSERT_EQ(widget_set_prop(w, WIDGET_PROP_REPEAT, &v1), RET_OK);
|
|
|
|
|
ASSERT_EQ(widget_get_prop(w, WIDGET_PROP_REPEAT, &v2), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_int(&v1), value_int(&v2));
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
2018-07-09 07:32:38 +08:00
|
|
|
|
widget_destroy(w);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
}
|
2018-07-13 19:35:12 +08:00
|
|
|
|
|
|
|
|
|
TEST(Button, clone) {
|
|
|
|
|
value_t v1;
|
2018-07-14 07:01:13 +08:00
|
|
|
|
|
2018-07-13 19:35:12 +08:00
|
|
|
|
widget_t* w1 = button_create(NULL, 10, 20, 30, 40);
|
|
|
|
|
|
|
|
|
|
value_set_int(&v1, 200);
|
|
|
|
|
ASSERT_EQ(widget_set_prop(w1, WIDGET_PROP_REPEAT, &v1), RET_OK);
|
2018-07-14 07:01:13 +08:00
|
|
|
|
widget_set_self_layout_params(w1, "1", "2", "3", "4");
|
2018-12-20 11:01:37 +08:00
|
|
|
|
widget_set_children_layout(w1, "default(r=0,c=0,x=10,y=10,s=10)");
|
2018-12-20 16:18:49 +08:00
|
|
|
|
widget_set_sensitive(w1, FALSE);
|
|
|
|
|
widget_set_floating(w1, TRUE);
|
2018-08-08 17:58:03 +08:00
|
|
|
|
ASSERT_EQ(button_cast(w1), w1);
|
2018-07-13 19:35:12 +08:00
|
|
|
|
|
|
|
|
|
widget_t* w2 = widget_clone(w1, NULL);
|
|
|
|
|
ASSERT_EQ(widget_equal(w1, w2), TRUE);
|
|
|
|
|
widget_destroy(w1);
|
|
|
|
|
widget_destroy(w2);
|
|
|
|
|
}
|
2019-01-22 17:49:15 +08:00
|
|
|
|
|
|
|
|
|
static ret_t button_on_click_to_remove_parent(void* ctx, event_t* e) {
|
|
|
|
|
widget_t* target = WIDGET(e->target);
|
|
|
|
|
widget_destroy(target->parent);
|
|
|
|
|
|
|
|
|
|
return RET_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(Button, remove_parent) {
|
|
|
|
|
pointer_event_t e;
|
|
|
|
|
widget_t* w = window_create(NULL, 0, 0, 320, 240);
|
|
|
|
|
widget_t* group = view_create(w, 20, 20, 200, 200);
|
|
|
|
|
widget_t* b = button_create(group, 10, 10, 30, 40);
|
|
|
|
|
|
|
|
|
|
widget_resize(w, 320, 240);
|
|
|
|
|
widget_on(b, EVT_CLICK, button_on_click_to_remove_parent, NULL);
|
|
|
|
|
e.e = event_init(EVT_POINTER_DOWN, w);
|
|
|
|
|
e.x = 35;
|
|
|
|
|
e.y = 35;
|
|
|
|
|
window_manager_dispatch_input_event(w->parent, (event_t*)(&e));
|
|
|
|
|
|
|
|
|
|
e.e = event_init(EVT_POINTER_UP, w);
|
|
|
|
|
window_manager_dispatch_input_event(w->parent, (event_t*)(&e));
|
|
|
|
|
|
|
|
|
|
widget_destroy(w);
|
|
|
|
|
idle_dispatch();
|
|
|
|
|
}
|