diff --git a/test/draw.c b/test/draw.c index cc564cac5..616da2590 100644 --- a/test/draw.c +++ b/test/draw.c @@ -240,14 +240,16 @@ TEST test_layout_render_no_gaps(void) dim = calculate_dimensions(layouts); image_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1); - bool first = true; + enum corner_pos corners = C_TOP; for (GSList *iter = layouts; iter; iter = iter->next) { struct colored_layout *cl_this = iter->data; struct colored_layout *cl_next = iter->next ? iter->next->data : NULL; - dim = layout_render(image_surface, cl_this, cl_next, dim, first, !cl_next); + if (!cl_next) + corners |= C_BOT; + dim = layout_render(image_surface, cl_this, cl_next, dim, corners); - first = false; + corners &= ~C_TOP; } expected_y = get_expected_dimension_y_offset(layout_count); @@ -286,7 +288,7 @@ TEST test_layout_render_gaps(void) struct colored_layout *cl_this = iter->data; struct colored_layout *cl_next = iter->next ? iter->next->data : NULL; - dim = layout_render(image_surface, cl_this, cl_next, dim, true, true); + dim = layout_render(image_surface, cl_this, cl_next, dim, C_ALL); } expected_y = get_expected_dimension_y_offset(layout_count); diff --git a/test/option_parser.c b/test/option_parser.c index 8773fad10..116fb01b2 100644 --- a/test/option_parser.c +++ b/test/option_parser.c @@ -727,6 +727,82 @@ TEST test_string_to_length_invalid(void) PASS(); } +TEST test_string_to_corners(void) +{ + enum corner_pos corners = -1; + + struct setting s; + s.type = TYPE_CUSTOM; + s.value = &corners; + s.parser = string_parse_corners; + s.parser_data = corners_enum_data; + + char buf[50]; + + // do not go until last element, since it's ENUM_END (all 0) + for (int i = 0; i < G_N_ELEMENTS(ellipsize_enum_data)-1; i++) { + sprintf(buf, "Failed in round %i", i); + ASSERTm(buf, set_from_string(&corners, s, corners_enum_data[i].string)); + ASSERT_EQm(buf, corners, corners_enum_data[i].enum_value); + } + + const char* inputs[] = { + "bottom,right", + "top-left, top-right", + "all", + "right,left,top,bottom", + "bottom-left,top-right", + "all,all", // still accepted + "all,top-right", + }; + const enum corner_pos results[] = { + C_BOT | C_RIGHT, + C_TOP_LEFT | C_TOP_RIGHT, + C_ALL, + C_ALL, + C_BOT_LEFT | C_TOP_RIGHT, + C_ALL, + C_ALL, + }; + + ARRAY_SAME_LENGTH(inputs, results); + + for (int i = 0; i < G_N_ELEMENTS(inputs); i++) { + sprintf(buf, "Failed in round %i", i); + ASSERTm(buf, set_from_string(&corners, s, inputs[i])); + ASSERT_EQm(buf, corners, results[i]); + } + PASS(); +} + +TEST test_string_to_corners_invalid(void) +{ + enum corner_pos corners = -1; + + struct setting s; + s.type = TYPE_CUSTOM; + s.value = &corners; + s.name = "corners_test"; + s.parser = string_parse_corners; + s.parser_data = corners_enum_data; + + const char* invalid_inputs[] = { + "none", + "al l", + "right;right", + "bot-left", + "top right, bottom left" + }; + + char buf[50]; + for (int i = 0; i < G_N_ELEMENTS(invalid_inputs); i++) { + sprintf(buf, "Failed in round %i", i); + ASSERT_FALSEm(buf, set_from_string(&corners, s, invalid_inputs[i])); + } + ASSERT_EQm("Enum should not change from invalid values", corners, -1); + PASS(); +} + #define TEST_ENUM(t) { \ ASSERT_EQ(sizeof(t), sizeof(int)); \ } @@ -743,6 +819,7 @@ TEST test_enum_size(void) TEST_ENUM(enum follow_mode); TEST_ENUM(enum mouse_action ); TEST_ENUM(enum zwlr_layer_shell_v1_layer); + TEST_ENUM(enum corner_pos); PASS(); } @@ -791,6 +868,8 @@ SUITE(suite_option_parser) RUN_TEST(test_enum_size); RUN_TEST(test_string_to_length); RUN_TEST(test_string_to_length_invalid); + RUN_TEST(test_string_to_corners); + RUN_TEST(test_string_to_corners_invalid); g_strfreev(argv); }