awtk/tests/group_box_test.cc

72 lines
1.9 KiB
C++
Raw Normal View History

2019-02-26 10:17:02 +08:00
#include "widgets/group_box.h"
2023-11-19 08:47:08 +08:00
#include "widgets/check_button.h"
2019-02-26 10:17:02 +08:00
#include "gtest/gtest.h"
TEST(GroupBox, cast) {
widget_t* w = group_box_create(NULL, 10, 20, 30, 40);
ASSERT_EQ(w, group_box_cast(w));
widget_destroy(w);
2020-10-18 12:17:55 +08:00
idle_dispatch();
2019-02-26 10:17:02 +08:00
}
2023-11-19 08:47:08 +08:00
static ret_t on_value_changed(void* ctx, event_t* e) {
uint32_t* value = (uint32_t*)ctx;
value_change_event_t* evt = (value_change_event_t*)e;
*value = value_uint32(&(evt->new_value));
return RET_OK;
}
TEST(GroupBox, radio_button) {
uint32_t value1 = 0;
uint32_t value2 = 0;
widget_t* w = group_box_create(NULL, 10, 20, 30, 40);
widget_t* r0 = check_button_create_radio(w, 10, 20, 30, 40);
widget_t* r1 = check_button_create_radio(w, 10, 20, 30, 40);
widget_t* r2 = check_button_create_radio(w, 10, 30, 30, 40);
widget_t* r3 = check_button_create_radio(w, 10, 40, 30, 40);
group_box_t* group_box = GROUP_BOX(w);
widget_on(w, EVT_VALUE_WILL_CHANGE, on_value_changed, &value1);
widget_on(w, EVT_VALUE_CHANGED, on_value_changed, &value2);
widget_set_value_int(w, 0);
ASSERT_EQ(widget_get_value_int(r0), TRUE);
ASSERT_EQ(value1, 0);
ASSERT_EQ(value2, 0);
ASSERT_EQ(group_box->value, 0);
widget_set_value_int(w, 1);
ASSERT_EQ(widget_get_value_int(r1), TRUE);
ASSERT_EQ(value1, 1);
ASSERT_EQ(value2, 1);
ASSERT_EQ(group_box->value, 1);
widget_set_value_int(w, 2);
ASSERT_EQ(widget_get_value_int(r2), TRUE);
ASSERT_EQ(value1, 2);
ASSERT_EQ(value2, 2);
ASSERT_EQ(group_box->value, 2);
widget_set_value_int(w, 3);
ASSERT_EQ(widget_get_value_int(r3), TRUE);
ASSERT_EQ(value1, 3);
ASSERT_EQ(value2, 3);
ASSERT_EQ(group_box->value, 3);
widget_set_value_int(r0, 1);
ASSERT_EQ(value1, 0);
ASSERT_EQ(value2, 0);
ASSERT_EQ(group_box->value, 0);
2024-03-04 08:54:03 +08:00
2023-11-19 08:47:08 +08:00
widget_set_value_int(r3, 1);
ASSERT_EQ(value1, 3);
ASSERT_EQ(value2, 3);
ASSERT_EQ(group_box->value, 3);
widget_destroy(w);
idle_dispatch();
}