2018-12-15 17:22:05 +08:00
|
|
|
|
#include "widgets/progress_bar.h"
|
2018-04-05 17:09:29 +08:00
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
|
|
TEST(progress_bar, basic) {
|
|
|
|
|
value_t v1;
|
|
|
|
|
value_t v2;
|
|
|
|
|
widget_t* s = progress_bar_create(NULL, 10, 20, 30, 40);
|
|
|
|
|
|
|
|
|
|
value_set_int(&v1, 10);
|
2018-04-20 21:49:47 +08:00
|
|
|
|
ASSERT_EQ(widget_set_prop(s, WIDGET_PROP_VALUE, &v1), RET_OK);
|
|
|
|
|
ASSERT_EQ(widget_get_prop(s, WIDGET_PROP_VALUE, &v2), RET_OK);
|
2018-04-05 17:09:29 +08:00
|
|
|
|
ASSERT_EQ(value_int(&v1), value_int(&v2));
|
|
|
|
|
|
|
|
|
|
value_set_bool(&v1, TRUE);
|
2018-04-20 21:49:47 +08:00
|
|
|
|
ASSERT_EQ(widget_set_prop(s, WIDGET_PROP_VERTICAL, &v1), RET_OK);
|
|
|
|
|
ASSERT_EQ(widget_get_prop(s, WIDGET_PROP_VERTICAL, &v2), RET_OK);
|
2018-04-05 17:09:29 +08:00
|
|
|
|
ASSERT_EQ(value_bool(&v1), value_bool(&v2));
|
|
|
|
|
|
|
|
|
|
widget_destroy(s);
|
|
|
|
|
}
|
2018-11-08 17:12:40 +08:00
|
|
|
|
|
2019-09-27 12:28:15 +08:00
|
|
|
|
TEST(progress_bar, max) {
|
|
|
|
|
value_t v1;
|
|
|
|
|
value_t v2;
|
|
|
|
|
widget_t* s = progress_bar_create(NULL, 10, 20, 30, 40);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(widget_get_prop_int(s, WIDGET_PROP_MAX, 0), 100);
|
|
|
|
|
|
|
|
|
|
value_set_int(&v1, 1000);
|
|
|
|
|
ASSERT_EQ(widget_set_prop(s, WIDGET_PROP_MAX, &v1), RET_OK);
|
|
|
|
|
ASSERT_EQ(widget_get_prop(s, WIDGET_PROP_MAX, &v2), RET_OK);
|
|
|
|
|
ASSERT_EQ(value_int(&v1), value_int(&v2));
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(progress_bar_set_value(s, 500), RET_OK);
|
|
|
|
|
ASSERT_EQ(progress_bar_get_percent(s), 50);
|
|
|
|
|
|
|
|
|
|
widget_destroy(s);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-08 17:12:40 +08:00
|
|
|
|
#include "log_change_events.inc"
|
|
|
|
|
|
|
|
|
|
TEST(ProgressBar, event) {
|
|
|
|
|
widget_t* w = progress_bar_create(NULL, 0, 0, 100, 100);
|
|
|
|
|
|
|
|
|
|
progress_bar_set_value(w, 10);
|
|
|
|
|
|
|
|
|
|
s_log = "";
|
|
|
|
|
widget_on(w, EVT_VALUE_WILL_CHANGE, on_change_events, NULL);
|
|
|
|
|
widget_on(w, EVT_VALUE_CHANGED, on_change_events, NULL);
|
|
|
|
|
|
|
|
|
|
progress_bar_set_value(w, 10);
|
|
|
|
|
ASSERT_EQ(s_log, "");
|
|
|
|
|
|
|
|
|
|
progress_bar_set_value(w, 20);
|
|
|
|
|
ASSERT_EQ(s_log, "will_change;change;");
|
|
|
|
|
|
|
|
|
|
widget_destroy(w);
|
|
|
|
|
}
|
2019-02-26 11:19:37 +08:00
|
|
|
|
|
|
|
|
|
TEST(ProgressBar, cast) {
|
|
|
|
|
widget_t* w = progress_bar_create(NULL, 0, 0, 100, 100);
|
2019-02-26 18:06:34 +08:00
|
|
|
|
|
2019-02-26 11:19:37 +08:00
|
|
|
|
ASSERT_EQ(w, progress_bar_cast(w));
|
|
|
|
|
|
|
|
|
|
widget_destroy(w);
|
|
|
|
|
}
|
2020-09-18 09:45:32 +08:00
|
|
|
|
|
|
|
|
|
TEST(ProgressBar, change_value) {
|
|
|
|
|
widget_t* w = progress_bar_create(NULL, 10, 20, 30, 40);
|
|
|
|
|
value_change_event_t evt;
|
|
|
|
|
memset(&evt, 0x00, sizeof(evt));
|
|
|
|
|
|
|
|
|
|
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_int(w, WIDGET_PROP_VALUE, 3), RET_OK);
|
|
|
|
|
ASSERT_EQ(widget_get_prop_int(w, WIDGET_PROP_VALUE, 0), 3);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(value_int(&(evt.old_value)), 0);
|
|
|
|
|
ASSERT_EQ(value_int(&(evt.new_value)), 3);
|
|
|
|
|
|
|
|
|
|
widget_destroy(w);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(ProgressBar, change_value_abort) {
|
|
|
|
|
widget_t* w = progress_bar_create(NULL, 10, 20, 30, 40);
|
|
|
|
|
value_change_event_t evt;
|
|
|
|
|
memset(&evt, 0x00, sizeof(evt));
|
|
|
|
|
|
|
|
|
|
widget_on(w, EVT_VALUE_WILL_CHANGE, on_value_will_changed_abort, NULL);
|
|
|
|
|
ASSERT_EQ(widget_set_prop_int(w, WIDGET_PROP_VALUE, 3), RET_OK);
|
|
|
|
|
ASSERT_EQ(widget_get_prop_int(w, WIDGET_PROP_VALUE, 3), 0);
|
|
|
|
|
|
|
|
|
|
widget_destroy(w);
|
|
|
|
|
}
|