2018-06-27 13:46:42 +08:00
|
|
|
|
#include "base/dialog.h"
|
2018-02-21 19:36:38 +08:00
|
|
|
|
#include "ui_loader/ui_builder_default.h"
|
2018-02-22 08:36:54 +08:00
|
|
|
|
#include "ui_loader/ui_builder_writer.h"
|
|
|
|
|
#include "ui_loader/ui_loader_default.h"
|
|
|
|
|
#include "gtest/gtest.h"
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
2018-03-10 19:11:37 +08:00
|
|
|
|
#define INIT_DESC(tt, xx, yy, ww, hh) \
|
|
|
|
|
desc.layout.x = xx; \
|
|
|
|
|
desc.layout.y = yy; \
|
|
|
|
|
desc.layout.w = ww; \
|
|
|
|
|
desc.layout.h = hh; \
|
2018-06-16 17:59:41 +08:00
|
|
|
|
strncpy(desc.type, tt, NAME_LEN);
|
2018-03-10 19:11:37 +08:00
|
|
|
|
|
2018-02-21 19:36:38 +08:00
|
|
|
|
TEST(UILoader, basic) {
|
|
|
|
|
uint8_t data[1024];
|
|
|
|
|
wbuffer_t wbuffer;
|
|
|
|
|
widget_t* ok = NULL;
|
|
|
|
|
widget_t* cancel = NULL;
|
2018-03-10 19:11:37 +08:00
|
|
|
|
widget_desc_t desc;
|
2018-02-21 19:36:38 +08:00
|
|
|
|
ui_loader_t* loader = default_ui_loader();
|
2018-06-15 19:12:34 +08:00
|
|
|
|
ui_builder_t* builder = ui_builder_default("");
|
2018-02-21 19:36:38 +08:00
|
|
|
|
ui_builder_t* writer = ui_builder_writer(wbuffer_init(&wbuffer, data, sizeof(data)));
|
|
|
|
|
|
2018-03-10 19:11:37 +08:00
|
|
|
|
memset(&desc, 0x00, sizeof(desc));
|
2018-06-16 17:59:41 +08:00
|
|
|
|
INIT_DESC("dialog", 0, 0, 400, 300);
|
2018-03-10 19:11:37 +08:00
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_start(writer, &desc), RET_OK);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_prop_end(writer), RET_OK);
|
|
|
|
|
|
2018-07-14 11:35:40 +08:00
|
|
|
|
INIT_DESC("dialog_title", 0, 0, 200, 300);
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_start(writer, &desc), RET_OK);
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_prop_end(writer), RET_OK);
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_end(writer), RET_OK);
|
|
|
|
|
|
|
|
|
|
INIT_DESC("dialog_client", 0, 0, 200, 300);
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_start(writer, &desc), RET_OK);
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_prop_end(writer), RET_OK);
|
|
|
|
|
|
2018-06-16 17:59:41 +08:00
|
|
|
|
INIT_DESC("button", 0, 0, 80, 30);
|
2018-03-10 19:11:37 +08:00
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_start(writer, &desc), RET_OK);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_prop(writer, "text", "ok"), RET_OK);
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_prop(writer, "name", "ok"), RET_OK);
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_prop_end(writer), RET_OK);
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_end(writer), RET_OK);
|
|
|
|
|
|
2018-06-16 17:59:41 +08:00
|
|
|
|
INIT_DESC("label", 128, 0, 80, 30);
|
2018-03-10 19:11:37 +08:00
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_start(writer, &desc), RET_OK);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_prop(writer, "text", "cancel"), RET_OK);
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_prop(writer, "name", "cancel"), RET_OK);
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_prop_end(writer), RET_OK);
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_end(writer), RET_OK);
|
2018-07-14 11:35:40 +08:00
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_end(writer), RET_OK);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_end(writer), RET_OK);
|
2018-07-14 11:35:40 +08:00
|
|
|
|
|
|
|
|
|
// ASSERT_EQ(wbuffer.cursor, 170);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
|
|
|
|
ASSERT_EQ(ui_loader_load(loader, wbuffer.data, wbuffer.cursor, builder), RET_OK);
|
|
|
|
|
ASSERT_EQ(builder->root->type == WIDGET_DIALOG, TRUE);
|
2018-03-31 13:48:18 +08:00
|
|
|
|
ASSERT_EQ(widget_count_children(builder->root), 2);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
2018-03-04 08:32:52 +08:00
|
|
|
|
ok = widget_lookup(builder->root, "ok", TRUE);
|
|
|
|
|
cancel = widget_lookup(builder->root, "cancel", TRUE);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
|
|
|
|
ASSERT_EQ(ok != NULL, true);
|
|
|
|
|
ASSERT_EQ(ok->type == WIDGET_BUTTON, true);
|
|
|
|
|
ASSERT_EQ(cancel != NULL, true);
|
|
|
|
|
ASSERT_EQ(cancel->type == WIDGET_LABEL, true);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(widget_get_child(DIALOG(builder->root)->client, 0)->type == WIDGET_BUTTON, true);
|
|
|
|
|
ASSERT_EQ(widget_get_child(DIALOG(builder->root)->client, 1)->type == WIDGET_LABEL, true);
|
2018-07-13 16:07:48 +08:00
|
|
|
|
ASSERT_EQ(strcmp(widget_get_child(DIALOG(builder->root)->client, 0)->name, "ok"), 0);
|
|
|
|
|
ASSERT_EQ(strcmp(widget_get_child(DIALOG(builder->root)->client, 1)->name, "cancel"), 0);
|
2018-02-21 19:36:38 +08:00
|
|
|
|
|
|
|
|
|
widget_destroy(builder->root);
|
|
|
|
|
}
|
2018-03-10 19:11:37 +08:00
|
|
|
|
|
|
|
|
|
TEST(UILoader, ext) {
|
|
|
|
|
uint8_t data[1024];
|
|
|
|
|
wbuffer_t wbuffer;
|
|
|
|
|
widget_t* ok = NULL;
|
|
|
|
|
widget_t* cancel = NULL;
|
|
|
|
|
widget_desc_t desc;
|
|
|
|
|
ui_loader_t* loader = default_ui_loader();
|
2018-06-15 19:12:34 +08:00
|
|
|
|
ui_builder_t* builder = ui_builder_default("");
|
2018-03-10 19:11:37 +08:00
|
|
|
|
ui_builder_t* writer = ui_builder_writer(wbuffer_init(&wbuffer, data, sizeof(data)));
|
|
|
|
|
|
|
|
|
|
memset(&desc, 0x00, sizeof(desc));
|
2018-06-16 17:59:41 +08:00
|
|
|
|
INIT_DESC("group_box", 0, 0, 100, 200);
|
2018-03-10 19:11:37 +08:00
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_start(writer, &desc), RET_OK);
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_prop_end(writer), RET_OK);
|
|
|
|
|
|
2018-06-16 17:59:41 +08:00
|
|
|
|
INIT_DESC("button", 10, 20, 30, 40);
|
2018-03-10 19:11:37 +08:00
|
|
|
|
desc.layout.x_attr = X_ATTR_PERCENT;
|
|
|
|
|
desc.layout.y_attr = Y_ATTR_PERCENT;
|
|
|
|
|
desc.layout.w_attr = W_ATTR_PERCENT;
|
|
|
|
|
desc.layout.h_attr = H_ATTR_PERCENT;
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_start(writer, &desc), RET_OK);
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_prop(writer, "text", "ok"), RET_OK);
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_prop(writer, "name", "ok"), RET_OK);
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_prop_end(writer), RET_OK);
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_end(writer), RET_OK);
|
|
|
|
|
|
2018-06-16 17:59:41 +08:00
|
|
|
|
INIT_DESC("label", 1, 2, 30, 40);
|
2018-03-10 19:11:37 +08:00
|
|
|
|
desc.layout.x_attr = X_ATTR_CENTER;
|
|
|
|
|
desc.layout.y_attr = Y_ATTR_MIDDLE;
|
|
|
|
|
desc.layout.w_attr = W_ATTR_PIXEL;
|
|
|
|
|
desc.layout.h_attr = H_ATTR_PIXEL;
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_start(writer, &desc), RET_OK);
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_prop(writer, "text", "cancel"), RET_OK);
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_prop(writer, "name", "cancel"), RET_OK);
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_prop_end(writer), RET_OK);
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_end(writer), RET_OK);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(ui_builder_on_widget_end(writer), RET_OK);
|
2018-06-16 17:59:41 +08:00
|
|
|
|
ASSERT_EQ(wbuffer.cursor, 170);
|
2018-03-10 19:11:37 +08:00
|
|
|
|
|
|
|
|
|
ASSERT_EQ(ui_loader_load(loader, wbuffer.data, wbuffer.cursor, builder), RET_OK);
|
|
|
|
|
ASSERT_EQ(builder->root->type == WIDGET_GROUP_BOX, TRUE);
|
|
|
|
|
ASSERT_EQ(widget_count_children(builder->root), 2);
|
|
|
|
|
|
|
|
|
|
ok = widget_lookup(builder->root, "ok", TRUE);
|
|
|
|
|
cancel = widget_lookup(builder->root, "cancel", TRUE);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(ok != NULL, true);
|
|
|
|
|
ASSERT_EQ(ok->type == WIDGET_BUTTON, true);
|
|
|
|
|
ASSERT_EQ(cancel != NULL, true);
|
|
|
|
|
ASSERT_EQ(cancel->type == WIDGET_LABEL, true);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(ok->x, 10);
|
|
|
|
|
ASSERT_EQ(ok->y, 40);
|
|
|
|
|
ASSERT_EQ(ok->w, 30);
|
|
|
|
|
ASSERT_EQ(ok->h, 80);
|
|
|
|
|
|
|
|
|
|
ASSERT_EQ(cancel->w, 30);
|
|
|
|
|
ASSERT_EQ(cancel->h, 40);
|
|
|
|
|
ASSERT_EQ(cancel->x, 36);
|
|
|
|
|
ASSERT_EQ(cancel->y, 82);
|
|
|
|
|
|
|
|
|
|
widget_destroy(builder->root);
|
|
|
|
|
}
|