awtk/tests/pages_test.cc

59 lines
1.4 KiB
C++
Raw Normal View History

#include "widgets/pages.h"
#include "widgets/view.h"
2018-06-18 07:18:37 +08:00
#include "gtest/gtest.h"
2018-10-20 11:15:41 +08:00
#include <string>
using std::string;
static ret_t pages_on_change(void* ctx, event_t* e) {
string& s = *(string*)ctx;
if (e->type == EVT_VALUE_CHANGED) {
s += "changed:";
2018-11-08 17:12:40 +08:00
} else if (e->type == EVT_VALUE_WILL_CHANGE) {
s += "will_change:";
2018-10-20 11:15:41 +08:00
}
return RET_OK;
}
2018-06-18 07:18:37 +08:00
TEST(Pages, basic) {
2018-10-20 11:15:41 +08:00
string str;
2018-06-18 07:18:37 +08:00
widget_t* pages = pages_create(NULL, 0, 0, 100, 100);
widget_t* p0 = view_create(pages, 0, 0, 100, 100);
widget_t* p1 = view_create(pages, 0, 0, 100, 100);
widget_t* p2 = view_create(pages, 0, 0, 100, 100);
widget_set_name(p0, "p0");
widget_set_name(p1, "p1");
widget_set_name(p2, "p2");
2018-10-20 11:15:41 +08:00
widget_on(pages, EVT_VALUE_CHANGED, pages_on_change, &str);
2018-11-08 17:12:40 +08:00
widget_on(pages, EVT_VALUE_WILL_CHANGE, pages_on_change, &str);
2018-10-20 11:15:41 +08:00
2021-06-09 13:57:48 +08:00
pages_set_active(pages, 0);
2021-09-16 16:06:55 +08:00
ASSERT_EQ(PAGES(pages)->active, 0u);
2021-06-09 15:18:18 +08:00
str = "";
2018-06-18 07:18:37 +08:00
pages_set_active(pages, 1);
2021-09-16 16:06:55 +08:00
ASSERT_EQ(PAGES(pages)->active, 1u);
2018-11-08 17:12:40 +08:00
ASSERT_EQ(str, "will_change:changed:");
2018-06-18 07:18:37 +08:00
pages_set_active_by_name(pages, "p2");
2021-09-16 16:06:55 +08:00
ASSERT_EQ(PAGES(pages)->active, 2u);
2018-11-08 17:12:40 +08:00
ASSERT_EQ(str, "will_change:changed:will_change:changed:");
2018-06-18 07:18:37 +08:00
pages_set_active_by_name(pages, "not found");
2021-09-16 16:06:55 +08:00
ASSERT_EQ(PAGES(pages)->active, 2u);
2018-06-18 07:18:37 +08:00
widget_destroy(pages);
}
2019-02-26 11:15:20 +08:00
TEST(Pages, cast) {
widget_t* pages = pages_create(NULL, 0, 0, 100, 100);
ASSERT_EQ(pages, pages_cast(pages));
widget_destroy(pages);
}