awtk/tests/check_button_test.cc

52 lines
1.4 KiB
C++
Raw Normal View History

2018-06-27 13:46:42 +08:00
#include "gtest/gtest.h"
2018-03-26 12:16:52 +08:00
#include "base/check_button.h"
static ret_t on_changed(void* ctx, event_t* e) {
int* count = (int*)ctx;
2018-03-30 22:15:45 +08:00
if (e->type == EVT_VALUE_CHANGED) {
2018-03-26 12:16:52 +08:00
*count += 1;
}
return RET_OK;
}
TEST(CheckButton, basic) {
uint32_t id = 0;
int count = 0;
widget_t* button = check_button_create(NULL, 0, 0, 100, 100);
ASSERT_EQ(CHECK_BUTTON(button)->radio, FALSE);
ASSERT_EQ(CHECK_BUTTON(button)->value, FALSE);
id = widget_on(button, EVT_VALUE_CHANGED, on_changed, &count);
ASSERT_EQ(id > 0, TRUE);
ASSERT_EQ(check_button_set_value(button, TRUE), RET_OK);
ASSERT_EQ(CHECK_BUTTON(button)->value, TRUE);
2018-03-30 22:15:45 +08:00
ASSERT_EQ(count, 1);
2018-03-26 12:16:52 +08:00
ASSERT_EQ(check_button_set_value(button, FALSE), RET_OK);
ASSERT_EQ(CHECK_BUTTON(button)->value, FALSE);
2018-03-30 22:15:45 +08:00
ASSERT_EQ(count, 2);
2018-03-26 12:16:52 +08:00
ASSERT_EQ(widget_off(button, id), RET_OK);
ASSERT_EQ(check_button_set_value(button, TRUE), RET_OK);
ASSERT_EQ(CHECK_BUTTON(button)->value, TRUE);
2018-03-30 22:15:45 +08:00
ASSERT_EQ(count, 2);
2018-03-26 12:16:52 +08:00
ASSERT_EQ(check_button_set_value(button, FALSE), RET_OK);
ASSERT_EQ(CHECK_BUTTON(button)->value, FALSE);
2018-03-30 22:15:45 +08:00
ASSERT_EQ(count, 2);
2018-07-14 07:01:13 +08:00
widget_destroy(button);
2018-03-26 12:16:52 +08:00
}
TEST(CheckButton, radio) {
widget_t* button = check_button_create_radio(NULL, 0, 0, 100, 100);
2018-08-08 17:58:03 +08:00
ASSERT_EQ(check_button_cast(button), button);
2018-03-26 12:16:52 +08:00
ASSERT_EQ(CHECK_BUTTON(button)->radio, TRUE);
ASSERT_EQ(CHECK_BUTTON(button)->value, FALSE);
2018-07-14 11:35:40 +08:00
2018-07-14 07:01:13 +08:00
widget_destroy(button);
2018-03-26 12:16:52 +08:00
}