awtk/tests/grid_test.cc

217 lines
5.0 KiB
C++
Raw Normal View History

2019-02-26 10:09:27 +08:00
#include "widgets/grid.h"
2022-06-19 11:15:42 +08:00
#include "widgets/button.h"
2019-02-26 10:09:27 +08:00
#include "gtest/gtest.h"
2022-06-19 11:15:42 +08:00
TEST(Grid, basic1) {
widget_t* w = grid_create(NULL, 10, 20, 300, 120);
grid_t* g = GRID(w);
2019-02-26 10:09:27 +08:00
2022-06-19 11:15:42 +08:00
ASSERT_EQ(grid_set_show_grid(w, TRUE), RET_OK);
ASSERT_EQ(g->show_grid, TRUE);
2022-07-06 06:36:58 +08:00
2022-06-19 11:15:42 +08:00
ASSERT_EQ(grid_set_show_grid(w, FALSE), RET_OK);
ASSERT_EQ(g->show_grid, FALSE);
2022-07-06 06:36:58 +08:00
2022-06-19 11:15:42 +08:00
ASSERT_EQ(grid_set_rows(w, 2), RET_OK);
ASSERT_EQ(g->rows, 2);
ASSERT_EQ(grid_set_columns_definition(w, "col(w=100,margin=2)"), RET_OK);
ASSERT_STREQ(g->columns_definition, "col(w=100,margin=2)");
ASSERT_EQ(g->cols_definition.size, 1);
2022-07-06 06:36:58 +08:00
2022-06-19 11:15:42 +08:00
widget_destroy(w);
idle_dispatch();
}
TEST(Grid, layout) {
widget_t* w = grid_create(NULL, 10, 20, 200, 80);
widget_t* b1 = button_create(w, 0, 0, 0, 0);
widget_t* b2 = button_create(w, 0, 0, 0, 0);
widget_t* b3 = button_create(w, 0, 0, 0, 0);
widget_t* b4 = button_create(w, 0, 0, 0, 0);
grid_t* g = GRID(w);
grid_set_rows(w, 2);
ASSERT_EQ(grid_set_columns_definition(w, "col(w=0.4,margin=2);col(w=0.6,margin=2);"), RET_OK);
ASSERT_EQ(g->cols_definition.size, 2);
widget_layout(w);
ASSERT_EQ(b1->x, 2);
ASSERT_EQ(b1->y, 2);
ASSERT_EQ(b1->w, 76);
ASSERT_EQ(b1->h, 36);
2022-07-06 06:36:58 +08:00
2022-06-19 11:15:42 +08:00
ASSERT_EQ(b2->x, 82);
ASSERT_EQ(b2->y, 2);
ASSERT_EQ(b2->w, 116);
ASSERT_EQ(b2->h, 36);
2022-07-06 06:36:58 +08:00
2022-06-19 11:15:42 +08:00
ASSERT_EQ(b3->x, 2);
ASSERT_EQ(b3->y, 42);
ASSERT_EQ(b3->w, 76);
ASSERT_EQ(b3->h, 36);
2022-07-06 06:36:58 +08:00
2022-06-19 11:15:42 +08:00
ASSERT_EQ(b4->x, 82);
ASSERT_EQ(b4->y, 42);
ASSERT_EQ(b4->w, 116);
ASSERT_EQ(b4->h, 36);
widget_destroy(w);
idle_dispatch();
}
TEST(Grid, layout2) {
widget_t* w = grid_create(NULL, 10, 20, 200, 80);
widget_t* b1 = button_create(w, 0, 0, 0, 0);
widget_t* b2 = button_create(w, 0, 0, 0, 0);
widget_t* b3 = button_create(w, 0, 0, 0, 0);
widget_t* b4 = button_create(w, 0, 0, 0, 0);
grid_t* g = GRID(w);
grid_set_rows(w, 2);
ASSERT_EQ(grid_set_columns_definition(w, "col(w=80,margin=2);col(w=120,margin=2);"), RET_OK);
ASSERT_EQ(g->cols_definition.size, 2);
widget_layout(w);
ASSERT_EQ(b1->x, 2);
ASSERT_EQ(b1->y, 2);
ASSERT_EQ(b1->w, 76);
ASSERT_EQ(b1->h, 36);
2022-07-06 06:36:58 +08:00
2022-06-19 11:15:42 +08:00
ASSERT_EQ(b2->x, 82);
ASSERT_EQ(b2->y, 2);
ASSERT_EQ(b2->w, 116);
ASSERT_EQ(b2->h, 36);
2022-07-06 06:36:58 +08:00
2022-06-19 11:15:42 +08:00
ASSERT_EQ(b3->x, 2);
ASSERT_EQ(b3->y, 42);
ASSERT_EQ(b3->w, 76);
ASSERT_EQ(b3->h, 36);
2022-07-06 06:36:58 +08:00
2022-06-19 11:15:42 +08:00
ASSERT_EQ(b4->x, 82);
ASSERT_EQ(b4->y, 42);
ASSERT_EQ(b4->w, 116);
ASSERT_EQ(b4->h, 36);
2019-02-26 10:09:27 +08:00
widget_destroy(w);
2020-10-18 12:17:55 +08:00
idle_dispatch();
2019-02-26 10:09:27 +08:00
}
2022-06-20 07:45:27 +08:00
TEST(Grid, layout3) {
widget_t* w = grid_create(NULL, 10, 20, 200, 80);
widget_t* b1 = button_create(w, 0, 0, 0, 0);
widget_t* b2 = button_create(w, 0, 0, 0, 0);
widget_t* b3 = button_create(w, 0, 0, 0, 0);
widget_t* b4 = button_create(w, 0, 0, 0, 0);
grid_t* g = GRID(w);
grid_set_rows(w, 2);
ASSERT_EQ(grid_set_columns_definition(w, "col(w=80,margin=2);col(w=-80,margin=2);"), RET_OK);
ASSERT_EQ(g->cols_definition.size, 2);
widget_layout(w);
ASSERT_EQ(b1->x, 2);
ASSERT_EQ(b1->y, 2);
ASSERT_EQ(b1->w, 76);
ASSERT_EQ(b1->h, 36);
2022-07-06 06:36:58 +08:00
2022-06-20 07:45:27 +08:00
ASSERT_EQ(b2->x, 82);
ASSERT_EQ(b2->y, 2);
ASSERT_EQ(b2->w, 116);
ASSERT_EQ(b2->h, 36);
2022-07-06 06:36:58 +08:00
2022-06-20 07:45:27 +08:00
ASSERT_EQ(b3->x, 2);
ASSERT_EQ(b3->y, 42);
ASSERT_EQ(b3->w, 76);
ASSERT_EQ(b3->h, 36);
2022-07-06 06:36:58 +08:00
2022-06-20 07:45:27 +08:00
ASSERT_EQ(b4->x, 82);
ASSERT_EQ(b4->y, 42);
ASSERT_EQ(b4->w, 116);
ASSERT_EQ(b4->h, 36);
widget_destroy(w);
idle_dispatch();
}
TEST(Grid, layout4) {
widget_t* w = grid_create(NULL, 10, 20, 200, 80);
widget_t* b1 = button_create(w, 0, 0, 0, 0);
widget_t* b2 = button_create(w, 0, 0, 0, 0);
widget_t* b3 = button_create(w, 0, 0, 0, 0);
widget_t* b4 = button_create(w, 0, 0, 0, 0);
grid_t* g = GRID(w);
grid_set_rows(w, 2);
ASSERT_EQ(grid_set_columns_definition(w, "col(w=0.4,margin=2);col(w=-0.4,margin=2);"), RET_OK);
ASSERT_EQ(g->cols_definition.size, 2);
widget_layout(w);
ASSERT_EQ(b1->x, 2);
ASSERT_EQ(b1->y, 2);
ASSERT_EQ(b1->w, 76);
ASSERT_EQ(b1->h, 36);
2022-07-06 06:36:58 +08:00
2022-06-20 07:45:27 +08:00
ASSERT_EQ(b2->x, 82);
ASSERT_EQ(b2->y, 2);
ASSERT_EQ(b2->w, 116);
ASSERT_EQ(b2->h, 36);
2022-07-06 06:36:58 +08:00
2022-06-20 07:45:27 +08:00
ASSERT_EQ(b3->x, 2);
ASSERT_EQ(b3->y, 42);
ASSERT_EQ(b3->w, 76);
ASSERT_EQ(b3->h, 36);
2022-07-06 06:36:58 +08:00
2022-06-20 07:45:27 +08:00
ASSERT_EQ(b4->x, 82);
ASSERT_EQ(b4->y, 42);
ASSERT_EQ(b4->w, 116);
ASSERT_EQ(b4->h, 36);
widget_destroy(w);
idle_dispatch();
}
2022-07-11 06:20:13 +08:00
TEST(Grid, layout5) {
widget_t* w = grid_create(NULL, 10, 20, 200, 80);
widget_t* b1 = button_create(w, 0, 0, 0, 0);
widget_t* b2 = button_create(w, 0, 0, 0, 0);
widget_t* b3 = button_create(w, 0, 0, 0, 0);
widget_t* b4 = button_create(w, 0, 0, 0, 0);
grid_t* g = GRID(w);
grid_set_rows(w, 2);
ASSERT_EQ(
grid_set_columns_definition(w, "col(w=0.4,margin=2);col(w=0,fill_available=true,margin=2);"),
RET_OK);
ASSERT_EQ(g->cols_definition.size, 2);
widget_layout(w);
ASSERT_EQ(b1->x, 2);
ASSERT_EQ(b1->y, 2);
ASSERT_EQ(b1->w, 76);
ASSERT_EQ(b1->h, 36);
ASSERT_EQ(b2->x, 82);
ASSERT_EQ(b2->y, 2);
ASSERT_EQ(b2->w, 116);
ASSERT_EQ(b2->h, 36);
ASSERT_EQ(b3->x, 2);
ASSERT_EQ(b3->y, 42);
ASSERT_EQ(b3->w, 76);
ASSERT_EQ(b3->h, 36);
ASSERT_EQ(b4->x, 82);
ASSERT_EQ(b4->y, 42);
ASSERT_EQ(b4->w, 116);
ASSERT_EQ(b4->h, 36);
widget_destroy(w);
idle_dispatch();
}