awtk/tests/combo_box_test.cc

197 lines
5.4 KiB
C++
Raw Normal View History

2018-07-26 19:05:15 +08:00
#include "gtest/gtest.h"
#include "widgets/combo_box.h"
2018-07-26 19:05:15 +08:00
#include <string>
using std::string;
TEST(ComboBox, basic) {
value_t v1;
value_t v2;
widget_t* w = combo_box_create(NULL, 10, 20, 30, 40);
combo_box_t* combo_box = COMBO_BOX(w);
value_set_str(&v1, "window");
ASSERT_EQ(widget_set_prop(w, WIDGET_PROP_OPEN_WINDOW, &v1), RET_OK);
ASSERT_EQ(widget_get_prop(w, WIDGET_PROP_OPEN_WINDOW, &v2), RET_OK);
ASSERT_EQ(strcmp(v1.value.str, v2.value.str), 0);
ASSERT_EQ(strcmp(v1.value.str, combo_box->open_window), 0);
value_set_int(&v1, 1);
ASSERT_EQ(widget_set_prop(w, WIDGET_PROP_SELECTED_INDEX, &v1), RET_OK);
ASSERT_EQ(widget_get_prop(w, WIDGET_PROP_SELECTED_INDEX, &v2), RET_OK);
ASSERT_EQ(value_int(&v1), value_int(&v2));
ASSERT_EQ(value_int(&v1), combo_box->selected_index);
widget_destroy(w);
}
2019-10-09 13:57:33 +08:00
TEST(ComboBox, item_height) {
value_t v1;
value_t v2;
widget_t* w = combo_box_create(NULL, 10, 20, 30, 40);
combo_box_t* combo_box = COMBO_BOX(w);
value_set_int(&v1, 32);
ASSERT_EQ(widget_set_prop(w, WIDGET_PROP_ITEM_HEIGHT, &v1), RET_OK);
ASSERT_EQ(widget_get_prop(w, WIDGET_PROP_ITEM_HEIGHT, &v2), RET_OK);
ASSERT_EQ(value_int(&v1), value_int(&v2));
ASSERT_EQ(value_int(&v1), combo_box->item_height);
widget_destroy(w);
}
2019-09-27 06:46:38 +08:00
TEST(ComboBox, localize) {
value_t v1;
value_t v2;
widget_t* w = combo_box_create(NULL, 10, 20, 30, 40);
combo_box_t* combo_box = COMBO_BOX(w);
ASSERT_EQ(TRUE, combo_box->localize_options);
value_set_bool(&v1, TRUE);
ASSERT_EQ(widget_set_prop(w, WIDGET_PROP_LOCALIZE_OPTIONS, &v1), RET_OK);
ASSERT_EQ(widget_get_prop(w, WIDGET_PROP_LOCALIZE_OPTIONS, &v2), RET_OK);
ASSERT_EQ(value_bool(&v1), value_bool(&v2));
ASSERT_EQ(value_bool(&v1), combo_box->localize_options);
value_set_bool(&v1, FALSE);
ASSERT_EQ(widget_set_prop(w, WIDGET_PROP_LOCALIZE_OPTIONS, &v1), RET_OK);
ASSERT_EQ(widget_get_prop(w, WIDGET_PROP_LOCALIZE_OPTIONS, &v2), RET_OK);
ASSERT_EQ(value_bool(&v1), value_bool(&v2));
ASSERT_EQ(value_bool(&v1), combo_box->localize_options);
widget_destroy(w);
}
2018-07-26 19:05:15 +08:00
TEST(ComboBox, options) {
widget_t* w = combo_box_create(NULL, 10, 20, 30, 40);
ASSERT_EQ(combo_box_count_options(w), 0);
ASSERT_EQ(combo_box_append_option(w, 1, "red"), RET_OK);
ASSERT_EQ(combo_box_count_options(w), 1);
ASSERT_EQ(combo_box_append_option(w, 2, "green"), RET_OK);
ASSERT_EQ(combo_box_count_options(w), 2);
ASSERT_EQ(combo_box_append_option(w, 3, "blue"), RET_OK);
ASSERT_EQ(combo_box_count_options(w), 3);
combo_box_set_selected_index(w, 0);
ASSERT_EQ(combo_box_get_value(w), 1);
ASSERT_EQ(string(combo_box_get_text(w)), string("red"));
combo_box_set_selected_index(w, 1);
ASSERT_EQ(combo_box_get_value(w), 2);
ASSERT_EQ(string(combo_box_get_text(w)), string("green"));
combo_box_reset_options(w);
ASSERT_EQ(combo_box_count_options(w), 0);
widget_destroy(w);
}
TEST(ComboBox, parse_options) {
widget_t* w = combo_box_create(NULL, 10, 20, 30, 40);
combo_box_parse_options(w, "1:red;2:green;3:blue");
ASSERT_EQ(combo_box_count_options(w), 3);
combo_box_set_selected_index(w, 0);
ASSERT_EQ(combo_box_get_value(w), 1);
ASSERT_EQ(string(combo_box_get_text(w)), string("red"));
combo_box_set_selected_index(w, 1);
ASSERT_EQ(combo_box_get_value(w), 2);
ASSERT_EQ(string(combo_box_get_text(w)), string("green"));
combo_box_reset_options(w);
ASSERT_EQ(combo_box_count_options(w), 0);
widget_destroy(w);
}
2018-08-02 17:48:21 +08:00
TEST(ComboBox, props) {
value_t v1;
value_t v2;
const char* str = "1:red;2:green;3:blue";
widget_t* w = combo_box_create(NULL, 10, 20, 30, 40);
value_set_str(&v1, str);
2018-08-08 17:58:03 +08:00
ASSERT_EQ(combo_box_cast(w), w);
2018-08-02 17:48:21 +08:00
ASSERT_EQ(widget_set_prop(w, WIDGET_PROP_OPTIONS, &v1), RET_OK);
ASSERT_EQ(widget_get_prop(w, WIDGET_PROP_OPTIONS, &v2), RET_OK);
ASSERT_EQ(string(value_str(&v2)), string(str));
ASSERT_EQ(combo_box_count_options(w), 3);
widget_destroy(w);
}
2018-11-08 17:12:40 +08:00
#include "log_change_events.inc"
TEST(ComboBox, event) {
const char* str = "1:red;2:green;3:blue";
widget_t* w = combo_box_create(NULL, 0, 0, 100, 100);
combo_box_set_options(w, str);
combo_box_set_selected_index(w, 0);
widget_on(w, EVT_VALUE_WILL_CHANGE, on_change_events, NULL);
widget_on(w, EVT_VALUE_CHANGED, on_change_events, NULL);
s_log = "";
2018-11-08 17:12:40 +08:00
combo_box_set_selected_index(w, 0);
ASSERT_EQ(s_log, "");
s_log = "";
2018-11-08 17:12:40 +08:00
combo_box_set_selected_index(w, 1);
ASSERT_EQ(s_log, "will_change;change;");
widget_destroy(w);
}
2019-02-26 09:50:06 +08:00
TEST(ComboBox, cast) {
widget_t* w = combo_box_create(NULL, 0, 0, 100, 100);
2019-02-26 10:11:52 +08:00
ASSERT_EQ(w, edit_cast(w));
2019-02-26 09:50:06 +08:00
ASSERT_EQ(w, combo_box_cast(w));
widget_destroy(w);
}
2019-08-20 11:51:23 +08:00
TEST(ComboBox, resize) {
widget_t* w = combo_box_create(NULL, 0, 0, 100, 100);
edit_t* edit = EDIT(w);
widget_resize(w, 200, 30);
ASSERT_EQ(edit->right_margin, 30);
widget_destroy(w);
}
TEST(ComboBox, move_resize) {
widget_t* w = combo_box_create(NULL, 0, 0, 100, 100);
edit_t* edit = EDIT(w);
widget_move_resize(w, 10, 10, 200, 50);
ASSERT_EQ(edit->right_margin, 50);
widget_destroy(w);
}
2019-10-23 11:20:08 +08:00
TEST(ComboBox, clone) {
widget_t* w2 = NULL;
widget_t* w1 = combo_box_create(NULL, 0, 0, 100, 100);
const char* str = "1:red;2:green;3:blue";
ASSERT_EQ(combo_box_set_options(w1, str), RET_OK);
ASSERT_EQ(combo_box_set_selected_index(w1, 0), RET_OK);
ASSERT_STREQ(COMBO_BOX(w1)->options, str);
w2 = widget_clone(w1, NULL);
ASSERT_EQ(widget_equal(w1, w2), TRUE);
widget_destroy(w1);
widget_destroy(w2);
}