diff --git a/include/LCUI.h b/include/LCUI.h index d68cfaf2..0f4e89f4 100644 --- a/include/LCUI.h +++ b/include/LCUI.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include diff --git a/lib/css/tests/test.c b/lib/css/tests/test.c index f4cf66ec..2714eead 100644 --- a/lib/css/tests/test.c +++ b/lib/css/tests/test.c @@ -1,13 +1,14 @@ +#include +#include #include "test.h" -#include "ctest.h" int main() { int ret = 0; logger_set_level(LOGGER_LEVEL_ALL); - describe("test_css_keywords", test_css_keywords); - describe("test_css_value", test_css_value); - describe("test_css_computed", test_css_computed); - return ret - print_test_result(); + ctest_describe("test_css_keywords", test_css_keywords); + ctest_describe("test_css_value", test_css_value); + ctest_describe("test_css_computed", test_css_computed); + return ret - ctest_finish(); } diff --git a/lib/css/tests/test_css_computed.c b/lib/css/tests/test_css_computed.c index ae349025..bd6e8e1c 100644 --- a/lib/css/tests/test_css_computed.c +++ b/lib/css/tests/test_css_computed.c @@ -6,7 +6,7 @@ static void check_length(const char *str, css_numeric_value_t actual, css_numeric_value_t expected) { - it_i(str, (int)actual, (int)expected); + ctest_euqal_int(str, (int)actual, (int)expected); } void test_css_computed(void) @@ -39,10 +39,10 @@ void test_css_computed(void) result = css_select_style(selector); css_cascade_style(result, &computed); - it_s("content", computed.content, "submit"); + ctest_euqal_str("content", computed.content, "submit"); check_length("font-size", computed.font_size, 16); check_length("min-width", computed.min_width, 80); - it_i("box-sizing", computed.type_bits.box_sizing, + ctest_euqal_int("box-sizing", computed.type_bits.box_sizing, CSS_BOX_SIZING_BORDER_BOX); check_length("padding-left", computed.padding_left, 8); @@ -55,15 +55,15 @@ void test_css_computed(void) check_length("border-bottom-width", computed.border_bottom_width, 1); check_length("border-left-width", computed.border_left_width, 1); - it_i("border-top-style", computed.type_bits.border_top_style, + ctest_euqal_int("border-top-style", computed.type_bits.border_top_style, CSS_BORDER_STYLE_SOLID); - it_i("border-right-style", computed.type_bits.border_right_style, + ctest_euqal_int("border-right-style", computed.type_bits.border_right_style, CSS_BORDER_STYLE_SOLID); - it_i("border-bottom-style", computed.type_bits.border_bottom_style, + ctest_euqal_int("border-bottom-style", computed.type_bits.border_bottom_style, CSS_BORDER_STYLE_SOLID); - it_i("border-left-style", computed.type_bits.border_left_style, + ctest_euqal_int("border-left-style", computed.type_bits.border_left_style, CSS_BORDER_STYLE_SOLID); - it_u("background-color", computed.background_color, css_color(255, 0, 0x50, 0xc9)); + ctest_euqal_uint("background-color", computed.background_color, css_color(255, 0, 0x50, 0xc9)); check_length("border-top-left-radius", computed.border_top_left_radius, 4); @@ -77,7 +77,7 @@ void test_css_computed(void) check_length("box-shadow-y", computed.box_shadow_y, 0); check_length("box-shadow-blur", computed.box_shadow_blur, 0); check_length("box-shadow-spread", computed.box_shadow_spread, 2); - it_u("box-shadow-color", computed.box_shadow_color, + ctest_euqal_uint("box-shadow-color", computed.box_shadow_color, css_color(127, 0, 0, 200)); css_style_decl_destroy(result); @@ -90,8 +90,8 @@ void test_css_computed(void) check_length("margin-top", computed.margin_top, 24); check_length("margin-bottom", computed.margin_top, 24); - it_i("margin-left", computed.type_bits.margin_left, CSS_MARGIN_AUTO); - it_i("margin-right", computed.type_bits.margin_right, CSS_MARGIN_AUTO); + ctest_euqal_int("margin-left", computed.type_bits.margin_left, CSS_MARGIN_AUTO); + ctest_euqal_int("margin-right", computed.type_bits.margin_right, CSS_MARGIN_AUTO); css_style_decl_destroy(result); css_selector_destroy(selector); diff --git a/lib/css/tests/test_css_keywords.c b/lib/css/tests/test_css_keywords.c index 28c8cacf..32ba2873 100644 --- a/lib/css/tests/test_css_keywords.c +++ b/lib/css/tests/test_css_keywords.c @@ -8,7 +8,7 @@ static void test_keyword_value(const char *name, int value) char str[256] = { 0 }; snprintf(str, 255, "keyword('%s').value", name); - it_i(str, css_get_keyword_key(name), value); + ctest_euqal_int(str, css_get_keyword_key(name), value); } static void test_keyword_register(const char *name) @@ -18,7 +18,7 @@ static void test_keyword_register(const char *name) int b = css_get_keyword_key(name); snprintf(str, 255, "keyword('%s')", name); - it_i(str, a, b); + ctest_euqal_int(str, a, b); } void test_css_keywords(void) diff --git a/lib/css/tests/test_css_value.c b/lib/css/tests/test_css_value.c index 9cd65626..05bd7d5c 100644 --- a/lib/css/tests/test_css_value.c +++ b/lib/css/tests/test_css_value.c @@ -14,8 +14,8 @@ static void test_css_valdef_string(const css_valdef_t *valdef) ret = val.array_value[0].type == CSS_STRING_VALUE; } css_style_value_destroy(&val); - it_b("match('\"abc\"')", ret, 1); - it_b("match('auto')", css_parse_value(valdef, "auto", &val) > 0, 1); + ctest_euqal_bool("match('\"abc\"')", ret, 1); + ctest_euqal_bool("match('auto')", css_parse_value(valdef, "auto", &val) > 0, 1); css_style_value_destroy(&val); } @@ -31,7 +31,7 @@ static void test_css_valdef_color(const css_valdef_t *valdef) } css_style_value_destroy(&val); - it_u("match('#fff')", (int)color, (int)css_color(255, 255, 255, 255)); + ctest_euqal_uint("match('#fff')", (int)color, (int)css_color(255, 255, 255, 255)); color = 0; if (css_parse_value(valdef, "#ffffff", &val) > 0 && @@ -40,7 +40,7 @@ static void test_css_valdef_color(const css_valdef_t *valdef) } css_style_value_destroy(&val); - it_u("match('#ffffff')", color, css_color(255, 255, 255, 255)); + ctest_euqal_uint("match('#ffffff')", color, css_color(255, 255, 255, 255)); color = 0; if (css_parse_value(valdef, "transparent", &val) > 0 && @@ -49,7 +49,7 @@ static void test_css_valdef_color(const css_valdef_t *valdef) } css_style_value_destroy(&val); - it_u("match('transparent')", color, CSS_COLOR_TRANSPARENT); + ctest_euqal_uint("match('transparent')", color, CSS_COLOR_TRANSPARENT); color = 0; if (css_parse_value(valdef, "rgb(100, 200, 255)", &val) > 0 && @@ -58,7 +58,7 @@ static void test_css_valdef_color(const css_valdef_t *valdef) } css_style_value_destroy(&val); - it_u("match('rgb(100, 200, 255)')", color, + ctest_euqal_uint("match('rgb(100, 200, 255)')", color, css_color(255, 100, 200, 255)); color = 0; @@ -68,7 +68,7 @@ static void test_css_valdef_color(const css_valdef_t *valdef) } css_style_value_destroy(&val); - it_u("match('rgba(100, 200, 255, 0.5)')", color, + ctest_euqal_uint("match('rgba(100, 200, 255, 0.5)')", color, css_color(127, 100, 200, 255)); } @@ -84,8 +84,8 @@ static void test_css_valdef_none(const css_valdef_t *valdef) css_get_keyword_key("none"); } css_style_value_destroy(&val); - it_b("match('none')", ret, 1); - it_b("notMatch('auto')", css_parse_value(valdef, "auto", &val) <= 0, 1); + ctest_euqal_bool("match('none')", ret, 1); + ctest_euqal_bool("notMatch('auto')", css_parse_value(valdef, "auto", &val) <= 0, 1); css_style_value_destroy(&val); } @@ -102,12 +102,12 @@ static void test_css_valdef_none_or_auto(const css_valdef_t *valdef) } css_style_value_destroy(&val); - it_b("match('none')", ret, 1); + ctest_euqal_bool("match('none')", ret, 1); ret = css_parse_value(valdef, "auto", &val) > 0 && val.type == CSS_ARRAY_VALUE; - it_b("match('auto')", ret, 1); - it_b("notMatch('normal')", css_parse_value(valdef, "normal", &val) <= 0, + ctest_euqal_bool("match('auto')", ret, 1); + ctest_euqal_bool("notMatch('normal')", css_parse_value(valdef, "normal", &val) <= 0, 1); css_style_value_destroy(&val); } @@ -117,15 +117,15 @@ static void test_css_valdef_border(const css_valdef_t *valdef) int ret; css_style_value_t val = { 0 }; - it_b("match('1px solid #eee')", + ctest_euqal_bool("match('1px solid #eee')", css_parse_value(valdef, "1px solid #eee", &val) > 0, 1); css_style_value_destroy(&val); - it_b("match('#eee 1px solid')", + ctest_euqal_bool("match('#eee 1px solid')", css_parse_value(valdef, "#eee 1px solid", &val) > 0, 1); css_style_value_destroy(&val); - it_b("match('solid #eee 1px')", + ctest_euqal_bool("match('solid #eee 1px')", css_parse_value(valdef, "solid #eee 1px", &val) > 0, 1); css_style_value_destroy(&val); @@ -135,7 +135,7 @@ static void test_css_valdef_border(const css_valdef_t *valdef) ret = val.array_value[0].type == CSS_UNIT_VALUE && val.array_value[0].unit_value.value == 1.; } - it_b("match('1px')", ret, 1); + ctest_euqal_bool("match('1px')", ret, 1); css_style_value_destroy(&val); ret = css_parse_value(valdef, "solid", &val) > 0 && @@ -145,13 +145,13 @@ static void test_css_valdef_border(const css_valdef_t *valdef) val.array_value[0].keyword_value == css_get_keyword_key("solid"); } - it_b("match('solid')", ret, 1); + ctest_euqal_bool("match('solid')", ret, 1); css_style_value_destroy(&val); ret = css_parse_value(valdef, "#eee", &val) > 0 && val.type == CSS_ARRAY_VALUE; ret = val.array_value[0].color_value == 0xffeeeeee; - it_b("match('#eee')", ret, 1); + ctest_euqal_bool("match('#eee')", ret, 1); css_style_value_destroy(&val); } @@ -160,31 +160,31 @@ static void test_css_valdef_border_2(const css_valdef_t *valdef) int ret; css_style_value_t val = { 0 }; - it_b("match('1px solid #eee')", + ctest_euqal_bool("match('1px solid #eee')", css_parse_value(valdef, "1px solid #eee", &val) > 0, 1); css_style_value_destroy(&val); - it_b("match('#eee 1px solid')", + ctest_euqal_bool("match('#eee 1px solid')", css_parse_value(valdef, "#eee 1px solid", &val) > 0, 1); css_style_value_destroy(&val); - it_b("match('solid #eee 1px')", + ctest_euqal_bool("match('solid #eee 1px')", css_parse_value(valdef, "solid #eee 1px", &val) > 0, 1); css_style_value_destroy(&val); ret = css_parse_value(valdef, "1px", &val) > 0 && val.type == CSS_ARRAY_VALUE; - it_b("notMatch('1px')", ret, 0); + ctest_euqal_bool("notMatch('1px')", ret, 0); css_style_value_destroy(&val); ret = css_parse_value(valdef, "solid", &val) > 0 && val.type == CSS_ARRAY_VALUE; - it_b("notMatch('solid')", ret, 0); + ctest_euqal_bool("notMatch('solid')", ret, 0); css_style_value_destroy(&val); ret = css_parse_value(valdef, "#eee", &val) > 0 && val.type == CSS_ARRAY_VALUE; - it_b("notMatch('#eee')", ret, 0); + ctest_euqal_bool("notMatch('#eee')", ret, 0); css_style_value_destroy(&val); } @@ -192,31 +192,31 @@ static void test_css_valdef_box_shadow(const css_valdef_t *valdef) { css_style_value_t val = { 0 }; - it_b("match('none')", + ctest_euqal_bool("match('none')", css_parse_value(valdef, "none", &val) > 0 && val.array_value[0].keyword_value == CSS_KEYWORD_NONE, 1); css_style_value_destroy(&val); - it_b("match('0 0')", + ctest_euqal_bool("match('0 0')", css_parse_value(valdef, "0 0", &val) > 0 && css_style_value_get_array_length(&val) == 2, 1); css_style_value_destroy(&val); - it_b("match('0 0 4px')", + ctest_euqal_bool("match('0 0 4px')", css_parse_value(valdef, "0 0 4px", &val) > 0 && css_style_value_get_array_length(&val) == 3, 1); css_style_value_destroy(&val); - it_b("match('0 0 4px #000')", + ctest_euqal_bool("match('0 0 4px #000')", css_parse_value(valdef, "0 0 4px #000", &val) > 0 && css_style_value_get_array_length(&val) == 4, 1); css_style_value_destroy(&val); - it_b( + ctest_euqal_bool( "match('0 0 6px rgba(33,150,243,0.4)')", css_parse_value(valdef, "0 0 6px rgba(33,150,243,0.4)", &val) > 0 && css_style_value_get_array_length(&val) == 4 && @@ -234,11 +234,11 @@ static void test_css_valdef_length_2(const css_valdef_t *valdef) ret = css_parse_value(valdef, "1px 2px", &val) > 0 && val.type == CSS_ARRAY_VALUE && css_style_value_get_array_length(&val) == 2; - it_b("match('1px 2px')", ret, 1); + ctest_euqal_bool("match('1px 2px')", ret, 1); css_style_value_destroy(&val); ret = css_parse_value(valdef, "1px", &val) != 0; - it_b("notMatch('1px')", ret, 1); + ctest_euqal_bool("notMatch('1px')", ret, 1); css_style_value_destroy(&val); } @@ -248,37 +248,37 @@ static void test_css_valdef_length_1_4(const css_valdef_t *valdef) css_style_value_t val = { 0 }; ret = css_parse_value(valdef, "", &val) <= 0; - it_b("notMatch('')", ret, 1); + ctest_euqal_bool("notMatch('')", ret, 1); css_style_value_destroy(&val); ret = css_parse_value(valdef, "1px", &val) > 0 && val.type == CSS_ARRAY_VALUE && css_style_value_get_array_length(&val) == 1; - it_b("match('1px')", ret, 1); + ctest_euqal_bool("match('1px')", ret, 1); css_style_value_destroy(&val); ret = css_parse_value(valdef, "1px 2px", &val) > 0 && val.type == CSS_ARRAY_VALUE && css_style_value_get_array_length(&val) == 2; - it_b("match('1px 2px')", ret, 1); + ctest_euqal_bool("match('1px 2px')", ret, 1); css_style_value_destroy(&val); ret = css_parse_value(valdef, "1px 2px 3px", &val) > 0 && val.type == CSS_ARRAY_VALUE && css_style_value_get_array_length(&val) == 3; - it_b("match('1px 2px 3px')", ret, 1); + ctest_euqal_bool("match('1px 2px 3px')", ret, 1); css_style_value_destroy(&val); ret = css_parse_value(valdef, "1px 2px 3px 4px", &val) > 0 && val.type == CSS_ARRAY_VALUE && css_style_value_get_array_length(&val) == 4; - it_b("match('1px 2px 3px 4px')", ret, 1); + ctest_euqal_bool("match('1px 2px 3px 4px')", ret, 1); css_style_value_destroy(&val); ret = css_parse_value(valdef, "1px 2px 3px 4px 5px", &val) > 0 && val.type == CSS_ARRAY_VALUE && css_style_value_get_array_length(&val) == 4; - it_b("Match('1px 2px 3px 4px 5px')", ret, 1); + ctest_euqal_bool("Match('1px 2px 3px 4px 5px')", ret, 1); css_style_value_destroy(&val); } @@ -288,61 +288,61 @@ static void test_css_valdef_length_percentage_1_4(const css_valdef_t *valdef) css_style_value_t val = { 0 }; ret = css_parse_value(valdef, "", &val) <= 0; - it_b("notMatch('')", ret, 1); + ctest_euqal_bool("notMatch('')", ret, 1); css_style_value_destroy(&val); ret = css_parse_value(valdef, "1px", &val) > 0 && val.type == CSS_ARRAY_VALUE && css_style_value_get_array_length(&val) == 1; - it_b("match('1px')", ret, 1); + ctest_euqal_bool("match('1px')", ret, 1); css_style_value_destroy(&val); ret = css_parse_value(valdef, "1px", &val) > 0 && val.type == CSS_ARRAY_VALUE && css_style_value_get_array_length(&val) == 1; - it_b("match('50%')", ret, 1); + ctest_euqal_bool("match('50%')", ret, 1); css_style_value_destroy(&val); ret = css_parse_value(valdef, "1px 2px", &val) > 0 && val.type == CSS_ARRAY_VALUE && css_style_value_get_array_length(&val) == 2; - it_b("match('1px 2px')", ret, 1); + ctest_euqal_bool("match('1px 2px')", ret, 1); css_style_value_destroy(&val); ret = css_parse_value(valdef, "1px 2px", &val) > 0 && val.type == CSS_ARRAY_VALUE && css_style_value_get_array_length(&val) == 2; - it_b("match('50% 50%')", ret, 1); + ctest_euqal_bool("match('50% 50%')", ret, 1); css_style_value_destroy(&val); ret = css_parse_value(valdef, "1px 2px 3px", &val) > 0 && val.type == CSS_ARRAY_VALUE && css_style_value_get_array_length(&val) == 3; - it_b("match('1px 2px 3px')", ret, 1); + ctest_euqal_bool("match('1px 2px 3px')", ret, 1); css_style_value_destroy(&val); ret = css_parse_value(valdef, "1px 2px 3px", &val) > 0 && val.type == CSS_ARRAY_VALUE && css_style_value_get_array_length(&val) == 3; - it_b("match('50% 50% 50%')", ret, 1); + ctest_euqal_bool("match('50% 50% 50%')", ret, 1); css_style_value_destroy(&val); ret = css_parse_value(valdef, "1px 2px 3px 4px", &val) > 0 && val.type == CSS_ARRAY_VALUE && css_style_value_get_array_length(&val) == 4; - it_b("match('1px 2px 3px 4px')", ret, 1); + ctest_euqal_bool("match('1px 2px 3px 4px')", ret, 1); css_style_value_destroy(&val); ret = css_parse_value(valdef, "1px 2px 3px 4px", &val) > 0 && val.type == CSS_ARRAY_VALUE && css_style_value_get_array_length(&val) == 4; - it_b("match('50% 50% 50% 50%')", ret, 1); + ctest_euqal_bool("match('50% 50% 50% 50%')", ret, 1); css_style_value_destroy(&val); ret = css_parse_value(valdef, "1px 2px 3px 4px 5px", &val) > 0 && val.type == CSS_ARRAY_VALUE && css_style_value_get_array_length(&val) == 4; - it_b("Match('1px 2px 3px 4px 5px')", ret, 1); + ctest_euqal_bool("Match('1px 2px 3px 4px 5px')", ret, 1); css_style_value_destroy(&val); } @@ -355,19 +355,19 @@ static void test_css_valdef_background_position(const css_valdef_t *valdef) ret = css_parse_value(valdef, "center", &val) > 0 && val.type == CSS_ARRAY_VALUE && css_style_value_get_array_length(&val) == 1; - it_b("match('center')", ret, 1); + ctest_euqal_bool("match('center')", ret, 1); css_style_value_destroy(&val); ret = css_parse_value(valdef, "10px", &val) > 0 && val.type == CSS_ARRAY_VALUE && css_style_value_get_array_length(&val) == 1; - it_b("match('10px')", ret, 1); + ctest_euqal_bool("match('10px')", ret, 1); css_style_value_destroy(&val); ret = css_parse_value(valdef, "50%", &val) > 0 && val.type == CSS_ARRAY_VALUE && css_style_value_get_array_length(&val) == 1; - it_b("match('50%')", ret, 1); + ctest_euqal_bool("match('50%')", ret, 1); css_style_value_destroy(&val); if (css_parse_value(valdef, "top center", &val) > 0) { @@ -376,13 +376,13 @@ static void test_css_valdef_background_position(const css_valdef_t *valdef) } else { ret = 0; } - it_b("match('top center')", ret, 1); + ctest_euqal_bool("match('top center')", ret, 1); css_style_value_destroy(&val); ret = css_parse_value(valdef, "bottom 10px right 20px", &val) > 0 && val.type == CSS_ARRAY_VALUE && css_style_value_get_array_length(&val) == 4; - it_b("match('bottom 10px right 20px')", ret, 1); + ctest_euqal_bool("match('bottom 10px right 20px')", ret, 1); css_style_value_destroy(&val); } @@ -393,16 +393,16 @@ static void test_css_valdef(const char *definition, css_valdef_t *valdef; snprintf(str, 255, "valdef('%s')", definition); - test_msg("%s\n", str); - test_begin(); + ctest_printf("%s\n", str); + ctest_group_begin(); valdef = css_compile_valdef(definition); if (valdef) { func(valdef); } else { - it_b("should be able to parse", 0, 1); + ctest_euqal_bool("should be able to parse", 0, 1); } - test_end(); - test_msg("\n"); + ctest_group_end(); + ctest_printf("\n"); css_valdef_destroy(valdef); } diff --git a/lib/ctest/include/ctest.h b/lib/ctest/include/ctest.h index 9589762b..5344bfd7 100644 --- a/lib/ctest/include/ctest.h +++ b/lib/ctest/include/ctest.h @@ -1,34 +1,26 @@ -#ifndef TEST_UTIL_H -#define TEST_UTIL_H +#ifndef LIB_CTEST_INCLUDE_CTEST_H +#define LIB_CTEST_INCLUDE_CTEST_H -#include -#include -#include +#include -void describe(const char *name, void (*func)()); - -int test_msg(const char *fmt, ...); - -void it_i(const char *name, int actual, int expected); - -void it_u(const char *name, unsigned actual, unsigned expected); - -void it_b(const char *name, int actual, int expected); - -void it_s(const char *name, const char *actual, const char *expected); - -void it_rectf(const char *name, const ui_rect_t *actual, - const ui_rect_t *expected); - -void it_rect(const char *name, const pd_rect_t *actual, - const pd_rect_t *expected); - -void test_begin(void); - -void test_end(void); - -int test_result(void); - -int print_test_result(void); +void ctest_describe(const char *name, void (*func)()); +int ctest_printf(const char *fmt, ...); +void ctest_group_begin(void); +void ctest_group_end(void); +void ctest_describe(const char *name, void (*func)()); +bool ctest_equal(const char *name, int (*to_str)(void *, char *, unsigned), + void *actual, void *expected); +int ctest_int_to_str(void *data, char *str, unsigned max_len); +int ctest_uint_to_str(void *data, char *str, unsigned max_len); +int ctest_float_to_str(void *data, char *str, unsigned max_len); +int ctest_str_to_str(void *data, char *str, unsigned max_len); +int ctest_bool_to_str(void *data, char *str, unsigned max_len); +bool ctest_euqal_int(const char *name, int actual, int expected); +bool ctest_euqal_bool(const char *name, bool actual, bool expected); +bool ctest_euqal_uint(const char *name, unsigned actual, unsigned expected); +bool ctest_euqal_float(const char *name, float actual, float expected); +bool ctest_euqal_str(const char *name, const char *actual, + const char *expected); +int ctest_finish(void); #endif diff --git a/lib/ctest/src/ctest.c b/lib/ctest/src/ctest.c index b6cccc49..43ae08b8 100644 --- a/lib/ctest/src/ctest.c +++ b/lib/ctest/src/ctest.c @@ -1,9 +1,8 @@ -#include "ctest.h" -#include +#include #include #include #include -#include +#include #ifdef _WIN32 #define COLOR_NONE @@ -30,7 +29,7 @@ static size_t tests_total = 0; static int test_msg_indent = 0; static int64_t test_start_time = 0; -int test_msg(const char *fmt, ...) +int ctest_printf(const char *fmt, ...) { int ret; char str[1024]; @@ -43,7 +42,7 @@ int test_msg(const char *fmt, ...) return ret; } -void test_begin(void) +void ctest_group_begin(void) { if (test_start_time == 0) { test_start_time = get_time_ms(); @@ -51,20 +50,91 @@ void test_begin(void) test_msg_indent++; } -void test_end(void) +void ctest_group_end(void) { test_msg_indent--; } -int test_result(void) +void ctest_describe(const char *name, void (*func)()) { - if (tests_total > tests_passed) { - return (int)(tests_total - tests_passed); - } - return 0; + ctest_printf("%s\n", name); + ctest_group_begin(); + func(); + ctest_group_end(); + ctest_printf("\n"); } -int print_test_result(void) +bool ctest_equal(const char *name, int (*to_str)(void *, char *, unsigned), + void *actual, void *expected) +{ + char actual_str[256] = { 0 }; + char expected_str[256] = { 0 }; + + to_str(actual, actual_str, 255); + to_str(expected, expected_str, 255); + if (strncmp(actual_str, expected_str, 255) == 0) { + ctest_printf(CHECK_MARK "%s\n", name); + tests_passed++; + return true; + } + ctest_printf(RED(ERROR_MARK "%s\n"), name); + ctest_printf(GREEN(" + expected ") RED("- actual\n\n")); + ctest_printf(RED(" - %s\n"), actual_str); + ctest_printf(GREEN(" + %s\n\n"), expected_str); + return false; +} + +int ctest_int_to_str(void *data, char *str, unsigned max_len) +{ + return snprintf(str, max_len, "%d", *(int *)data); +} + +int ctest_uint_to_str(void *data, char *str, unsigned max_len) +{ + return snprintf(str, max_len, "%u", *(unsigned *)data); +} + +int ctest_float_to_str(void *data, char *str, unsigned max_len) +{ + return snprintf(str, max_len, "%f", *(float *)data); +} + +int ctest_str_to_str(void *data, char *str, unsigned max_len) +{ + return snprintf(str, max_len, "\"%s\"", (char *)data); +} + +int ctest_bool_to_str(void *data, char *str, unsigned max_len) +{ + return snprintf(str, max_len, "\"%s\"", data ? "true" : "false"); +} + +bool ctest_euqal_int(const char *name, int actual, int expected) +{ + return ctest_equal(name, ctest_int_to_str, &actual, &expected); +} + +bool ctest_euqal_bool(const char *name, bool actual, bool expected) +{ + return ctest_equal(name, ctest_bool_to_str, &actual, &expected); +} + +bool ctest_euqal_uint(const char *name, unsigned actual, unsigned expected) +{ + return ctest_equal(name, ctest_uint_to_str, &actual, &expected); +} + +bool ctest_euqal_float(const char *name, float actual, float expected) +{ + return ctest_equal(name, ctest_float_to_str, &actual, &expected); +} + +bool ctest_euqal_str(const char *name, const char *actual, const char *expected) +{ + return ctest_equal(name, ctest_str_to_str, (void *)actual, (void *)expected); +} + +int ctest_finish(void) { printf(GREEN(" %zu passing") " (%ums)\n", tests_passed, (unsigned)get_time_delta(test_start_time)); @@ -75,131 +145,3 @@ int print_test_result(void) printf("\n"); return 0; } - -void describe(const char *name, void (*func)()) -{ - test_msg("%s\n", name); - test_begin(); - func(); - test_end(); - test_msg("\n"); -} - -void it_i(const char *name, int actual, int expected) -{ - tests_total++; - if (actual == expected) { - test_msg(CHECK_MARK "%s == %d\n", name, expected); - tests_passed++; - return; - } - test_msg(RED(ERROR_MARK "%s == %d\n"), name, expected); - test_msg(RED(" AssertionError: %d == %d\n"), actual, expected); - test_msg(GREEN(" + expected ") RED("- actual\n\n")); - test_msg(RED(" - %d\n"), actual); - test_msg(GREEN(" + %d\n\n"), expected); -} - -void it_u(const char *name, unsigned actual, unsigned expected) -{ - tests_total++; - if (actual == expected) { - test_msg(CHECK_MARK "%s == %u\n", name, expected); - tests_passed++; - return; - } - test_msg(RED(ERROR_MARK "%s == %u\n"), name, expected); - test_msg(RED(" AssertionError: %u == %u\n"), actual, expected); - test_msg(GREEN(" + expected ") RED("- actual\n\n")); - test_msg(RED(" - %u\n"), actual); - test_msg(GREEN(" + %u\n\n"), expected); -} - -void it_b(const char *name, int actual, int expected) -{ - const char *actual_str = actual ? "true" : "false"; - const char *expected_str = expected ? "true" : "false"; - - tests_total++; - if (!actual == !expected) { - test_msg(CHECK_MARK "%s\n", name); - tests_passed++; - return; - } - test_msg(RED(ERROR_MARK "%s\n"), name); - test_msg(RED(" AssertionError: %s == %s\n"), actual_str, expected_str); - test_msg(GREEN(" + expected ") RED("- actual\n\n")); - test_msg(RED(" - %s\n"), actual_str); - test_msg(GREEN(" + %s\n\n"), expected_str); -} - -void it_s(const char *name, const char *actual, const char *expected) -{ - tests_total++; - if ((actual && expected && strcmp(actual, expected) == 0) || - actual == expected) { - test_msg(CHECK_MARK "%s == '%s'\n", name, expected); - tests_passed++; - return; - } - test_msg(RED(ERROR_MARK "%s == '%s'\n"), name, expected); - if (expected) { - test_msg(RED(" AssertionError: '%s' == '%s'\n"), actual, - expected); - } else { - test_msg(RED(" AssertionError: '%s' == null\n"), actual); - } - test_msg(GREEN(" + expected ") RED("- actual\n\n")); - test_msg(RED(" - %s\n"), actual); - test_msg(GREEN(" + %s\n\n"), expected); -} - -// TODO: 取消对自定义类型的判断 - -void it_rectf(const char *name, const ui_rect_t *actual, - const ui_rect_t *expected) -{ - tests_total++; - if (ui_rect_is_equal(actual, expected)) { - test_msg(CHECK_MARK "%s == (%g, %g, %g, %g)\n", name, - expected->x, expected->y, expected->width, - expected->height); - tests_passed++; - return; - } - test_msg(RED(ERROR_MARK "%s == (%g, %g, %g, %g)\n"), name, expected->x, - expected->y, expected->width, expected->height); - test_msg( - RED(" AssertionError: (%g, %g, %g, %g) == (%g, %g, %g, %g)\n"), - actual->x, actual->y, actual->width, actual->height, expected->x, - expected->y, expected->width, expected->height); - test_msg(GREEN(" + expected ") RED("- actual\n\n")); - test_msg(RED(" - (%g, %g, %g, %g)\n"), actual->x, actual->y, - actual->width, actual->height); - test_msg(GREEN(" + (%g, %g, %g, %g)\n\n"), expected->x, expected->y, - expected->width, expected->height); -} - -void it_rect(const char *name, const pd_rect_t *actual, - const pd_rect_t *expected) -{ - tests_total++; - if (pd_rect_is_equal(actual, expected)) { - test_msg(CHECK_MARK "%s == (%d, %d, %d, %d)\n", name, - expected->x, expected->y, expected->width, - expected->height); - tests_passed++; - return; - } - test_msg(RED(ERROR_MARK "%s == (%d, %d, %d, %d)\n"), name, expected->x, - expected->y, expected->width, expected->height); - test_msg( - RED(" AssertionError: (%d, %d, %d, %d) == (%d, %d, %d, %d)\n"), - actual->x, actual->y, actual->width, actual->height, expected->x, - expected->y, expected->width, expected->height); - test_msg(GREEN(" + expected ") RED("- actual\n\n")); - test_msg(RED(" - (%d, %d, %d, %d)\n"), actual->x, actual->y, - actual->width, actual->height); - test_msg(GREEN(" + (%d, %d, %d, %d)\n\n"), expected->x, expected->y, - expected->width, expected->height); -} diff --git a/lib/ctest/xmake.lua b/lib/ctest/xmake.lua index 321a8c47..a2ec594b 100644 --- a/lib/ctest/xmake.lua +++ b/lib/ctest/xmake.lua @@ -4,5 +4,5 @@ add_includedirs("include") target("ctest") set_kind("static") add_files("src/*.c") + add_deps("yutil") add_headerfiles("include/ctest.h") - add_deps("pandagl") diff --git a/lib/pandagl/include/pandagl/rect.h b/lib/pandagl/include/pandagl/rect.h index 5f87f770..6057d5ce 100644 --- a/lib/pandagl/include/pandagl/rect.h +++ b/lib/pandagl/include/pandagl/rect.h @@ -52,6 +52,8 @@ PD_PUBLIC int pd_rects_remove(list_t *list, pd_rect_t *rect); PD_PUBLIC void pd_rects_clear(list_t *list); +PD_PUBLIC int pd_rect_to_str(pd_rect_t *rect, char *str, unsigned max_len); + PD_END_DECLS #endif diff --git a/lib/pandagl/src/rect.c b/lib/pandagl/src/rect.c index a20e34ca..2633cd82 100644 --- a/lib/pandagl/src/rect.c +++ b/lib/pandagl/src/rect.c @@ -29,328 +29,336 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include pd_rect_t pd_rect(int x, int y, int width, int height) { - pd_rect_t rect = { x, y, width, height }; - return rect; + pd_rect_t rect = { x, y, width, height }; + return rect; } -pd_rect_t pd_rect_crop(const pd_rect_t *rect, int container_width, int container_height) +pd_rect_t pd_rect_crop(const pd_rect_t *rect, int container_width, + int container_height) { - pd_rect_t cropped_rect = { 0, 0, rect->width, rect->height }; - if (rect->x < 0) { - cropped_rect.width += rect->x; - cropped_rect.x = 0 - rect->x; - } - if (rect->x + rect->width > container_width) { - cropped_rect.width -= (rect->x + rect->width - container_width); - } + pd_rect_t cropped_rect = { 0, 0, rect->width, rect->height }; + if (rect->x < 0) { + cropped_rect.width += rect->x; + cropped_rect.x = 0 - rect->x; + } + if (rect->x + rect->width > container_width) { + cropped_rect.width -= (rect->x + rect->width - container_width); + } - if (rect->y < 0) { - cropped_rect.height += rect->y; - cropped_rect.y = 0 - rect->y; - } - if (rect->y + rect->height > container_height) { - cropped_rect.height -= - (rect->y + rect->height - container_height); - } - return cropped_rect; + if (rect->y < 0) { + cropped_rect.height += rect->y; + cropped_rect.y = 0 - rect->y; + } + if (rect->y + rect->height > container_height) { + cropped_rect.height -= + (rect->y + rect->height - container_height); + } + return cropped_rect; } pd_bool_t pd_rect_correct(pd_rect_t *rect, int container_width, - int container_height) + int container_height) { - pd_bool_t overflow = PD_FALSE; + pd_bool_t overflow = PD_FALSE; - if (rect->x < 0) { - overflow = PD_TRUE; - rect->width += rect->x; - rect->x = 0; - } - if (rect->y < 0) { - overflow = PD_TRUE; - rect->height += rect->y; - rect->y = 0; - } + if (rect->x < 0) { + overflow = PD_TRUE; + rect->width += rect->x; + rect->x = 0; + } + if (rect->y < 0) { + overflow = PD_TRUE; + rect->height += rect->y; + rect->y = 0; + } - if (rect->x + rect->width > container_width) { - overflow = PD_TRUE; - if (rect->x < container_width) { - rect->width = container_width - rect->x; - } else { - rect->width = 0; - } - } - if (rect->y + rect->height > container_height) { - overflow = PD_TRUE; - if (rect->y < container_height) { - rect->height = container_height - rect->y; - } else { - rect->height = 0; - } - } - return overflow; + if (rect->x + rect->width > container_width) { + overflow = PD_TRUE; + if (rect->x < container_width) { + rect->width = container_width - rect->x; + } else { + rect->width = 0; + } + } + if (rect->y + rect->height > container_height) { + overflow = PD_TRUE; + if (rect->y < container_height) { + rect->height = container_height - rect->y; + } else { + rect->height = 0; + } + } + return overflow; } pd_bool_t pd_rect_is_cover(const pd_rect_t *a, const pd_rect_t *b) { - if (a->x > b->x) { - if (b->x + b->width <= a->x) { - return PD_FALSE; - } - } else { - if (a->x + a->width <= b->x) { - return PD_FALSE; - } - } - if (a->y > b->y) { - if (b->y + b->height <= a->y) { - return PD_FALSE; - } - } else { - if (a->y + a->height <= b->y) { - return PD_FALSE; - } - } - return PD_TRUE; + if (a->x > b->x) { + if (b->x + b->width <= a->x) { + return PD_FALSE; + } + } else { + if (a->x + a->width <= b->x) { + return PD_FALSE; + } + } + if (a->y > b->y) { + if (b->y + b->height <= a->y) { + return PD_FALSE; + } + } else { + if (a->y + a->height <= b->y) { + return PD_FALSE; + } + } + return PD_TRUE; } pd_bool_t pd_rect_overlap(const pd_rect_t *a, const pd_rect_t *b, - pd_rect_t *overlapping_rect) + pd_rect_t *overlapping_rect) { - if (a->x > b->x) { - if (b->x + b->width > a->x + a->width) { - overlapping_rect->width = a->width; - } else { - overlapping_rect->width = b->x + b->width - a->x; - } - overlapping_rect->x = a->x; - } else { - if (a->x + a->width > b->x + b->width) { - overlapping_rect->width = b->width; - } else { - overlapping_rect->width = a->x + a->width - b->x; - } - overlapping_rect->x = b->x; - } - if (a->y > b->y) { - if (b->y + b->height > a->y + a->height) { - overlapping_rect->height = a->height; - } else { - overlapping_rect->height = b->y + b->height - a->y; - } - overlapping_rect->y = a->y; - } else { - if (a->y + a->height > b->y + b->height) { - overlapping_rect->height = b->height; - } else { - overlapping_rect->height = a->y + a->height - b->y; - } - overlapping_rect->y = b->y; - } - if (overlapping_rect->width <= 0 || overlapping_rect->height <= 0) { - return PD_FALSE; - } - return PD_TRUE; + if (a->x > b->x) { + if (b->x + b->width > a->x + a->width) { + overlapping_rect->width = a->width; + } else { + overlapping_rect->width = b->x + b->width - a->x; + } + overlapping_rect->x = a->x; + } else { + if (a->x + a->width > b->x + b->width) { + overlapping_rect->width = b->width; + } else { + overlapping_rect->width = a->x + a->width - b->x; + } + overlapping_rect->x = b->x; + } + if (a->y > b->y) { + if (b->y + b->height > a->y + a->height) { + overlapping_rect->height = a->height; + } else { + overlapping_rect->height = b->y + b->height - a->y; + } + overlapping_rect->y = a->y; + } else { + if (a->y + a->height > b->y + b->height) { + overlapping_rect->height = b->height; + } else { + overlapping_rect->height = a->y + a->height - b->y; + } + overlapping_rect->y = b->y; + } + if (overlapping_rect->width <= 0 || overlapping_rect->height <= 0) { + return PD_FALSE; + } + return PD_TRUE; } void pd_rect_merge(pd_rect_t *merged_rect, const pd_rect_t *a, - const pd_rect_t *b) + const pd_rect_t *b) { - if (a->x + a->width < b->x + b->width) { - merged_rect->width = b->x + b->width; - } else { - merged_rect->width = a->x + a->width; - } - if (a->y + a->height < b->y + b->height) { - merged_rect->height = b->y + b->height; - } else { - merged_rect->height = a->y + a->height; - } - merged_rect->x = y_min(a->x, b->x); - merged_rect->y = y_min(a->y, b->y); - merged_rect->width -= merged_rect->x; - merged_rect->height -= merged_rect->y; + if (a->x + a->width < b->x + b->width) { + merged_rect->width = b->x + b->width; + } else { + merged_rect->width = a->x + a->width; + } + if (a->y + a->height < b->y + b->height) { + merged_rect->height = b->y + b->height; + } else { + merged_rect->height = a->y + a->height; + } + merged_rect->x = y_min(a->x, b->x); + merged_rect->y = y_min(a->y, b->y); + merged_rect->width -= merged_rect->x; + merged_rect->height -= merged_rect->y; } void pd_rect_split(pd_rect_t *base, pd_rect_t *target, pd_rect_t rects[4]) { - if (pd_rect_is_include(target, base)) { - rects[0].x = target->x; - rects[0].y = target->y; - rects[0].width = base->x - target->x; - rects[0].height = base->y + base->height - target->y; + if (pd_rect_is_include(target, base)) { + rects[0].x = target->x; + rects[0].y = target->y; + rects[0].width = base->x - target->x; + rects[0].height = base->y + base->height - target->y; - rects[1].x = target->x; - rects[1].y = base->y + base->height; - rects[1].width = base->x + base->width - target->x; - rects[1].height = target->y + target->height - rects[1].y; + rects[1].x = target->x; + rects[1].y = base->y + base->height; + rects[1].width = base->x + base->width - target->x; + rects[1].height = target->y + target->height - rects[1].y; - rects[2].x = base->x + base->width; - rects[2].y = base->y; - rects[2].width = target->width - rects[1].width; - rects[2].height = target->y + target->height - rects[2].y; + rects[2].x = base->x + base->width; + rects[2].y = base->y; + rects[2].width = target->width - rects[1].width; + rects[2].height = target->y + target->height - rects[2].y; - rects[3].x = base->x; - rects[3].y = target->y; - rects[3].width = target->x + target->width - rects[3].x; - rects[3].height = base->y - target->y; - return; - } - /* Right */ - if (target->x >= base->x) { - /* Top */ - if (target->y < base->y) { - rects[0].x = target->x; - rects[0].y = target->y; - rects[0].width = target->width; - rects[0].height = base->y - target->y; - rects[1].x = base->x + base->width; - rects[1].y = base->y; - rects[1].width = - target->x + target->width - base->x - base->width; - rects[1].height = target->y + target->height - base->y; - } else { - /* Bottom */ - rects[0].x = base->x + base->width; - rects[0].y = target->y; - rects[0].width = - target->x + target->width - base->x - base->width; - rects[0].height = target->height; - rects[1].x = target->x; - rects[1].y = base->y + base->height; - rects[1].width = base->x + base->width - target->x; - rects[1].height = - target->y + target->height - base->y - base->height; - } - } else { - /* Top */ - if (target->y < base->y) { - rects[0].x = target->x; - rects[0].y = target->y; - rects[0].width = target->width; - rects[0].height = base->y - target->y; - rects[1].x = target->x; - rects[1].y = base->y; - rects[1].width = base->x - target->x; - rects[1].height = target->y + target->height - base->y; - } else { - /* Bottom */ - rects[0].x = target->x; - rects[0].y = target->y; - rects[0].width = base->x - target->x; - rects[0].height = target->height; - rects[1].x = base->x; - rects[1].y = base->y + base->height; - rects[1].width = target->x + target->width - base->x; - rects[1].height = - target->y + target->height - base->y - base->height; - } - } - rects[2].x = 0; - rects[2].y = 0; - rects[2].width = 0; - rects[2].height = 0; - rects[3].x = 0; - rects[3].y = 0; - rects[3].width = 0; - rects[3].height = 0; + rects[3].x = base->x; + rects[3].y = target->y; + rects[3].width = target->x + target->width - rects[3].x; + rects[3].height = base->y - target->y; + return; + } + /* Right */ + if (target->x >= base->x) { + /* Top */ + if (target->y < base->y) { + rects[0].x = target->x; + rects[0].y = target->y; + rects[0].width = target->width; + rects[0].height = base->y - target->y; + rects[1].x = base->x + base->width; + rects[1].y = base->y; + rects[1].width = + target->x + target->width - base->x - base->width; + rects[1].height = target->y + target->height - base->y; + } else { + /* Bottom */ + rects[0].x = base->x + base->width; + rects[0].y = target->y; + rects[0].width = + target->x + target->width - base->x - base->width; + rects[0].height = target->height; + rects[1].x = target->x; + rects[1].y = base->y + base->height; + rects[1].width = base->x + base->width - target->x; + rects[1].height = + target->y + target->height - base->y - base->height; + } + } else { + /* Top */ + if (target->y < base->y) { + rects[0].x = target->x; + rects[0].y = target->y; + rects[0].width = target->width; + rects[0].height = base->y - target->y; + rects[1].x = target->x; + rects[1].y = base->y; + rects[1].width = base->x - target->x; + rects[1].height = target->y + target->height - base->y; + } else { + /* Bottom */ + rects[0].x = target->x; + rects[0].y = target->y; + rects[0].width = base->x - target->x; + rects[0].height = target->height; + rects[1].x = base->x; + rects[1].y = base->y + base->height; + rects[1].width = target->x + target->width - base->x; + rects[1].height = + target->y + target->height - base->y - base->height; + } + } + rects[2].x = 0; + rects[2].y = 0; + rects[2].width = 0; + rects[2].height = 0; + rects[3].x = 0; + rects[3].y = 0; + rects[3].width = 0; + rects[3].height = 0; } int pd_rects_add(list_t *list, pd_rect_t *rect) { - int x_distance, y_distance; + int x_distance, y_distance; - pd_rect_t *p, merged_rect; - list_node_t *node, *prev; + pd_rect_t *p, merged_rect; + list_node_t *node, *prev; - if (rect->width <= 0 || rect->height <= 0) { - return -1; - } - for (list_each(node, list)) { - p = node->data; - /* 如果被现有的矩形包含 */ - if (pd_rect_is_include(p, rect)) { - return -2; - } - /* 如果包含现有的矩形 */ - if (pd_rect_is_include(rect, p)) { - prev = node->prev; - free(node->data); - list_delete_node(list, node); - node = prev; - continue; - } - x_distance = p->x + p->width - rect->x - rect->width; - y_distance = p->y + p->height - rect->y - rect->height; - if ((x_distance <= 10 && x_distance >= -10) && - (y_distance <= 10 && y_distance >= -10)) { - pd_rect_merge(&merged_rect, p, rect); - free(node->data); - list_delete_node(list, node); - return pd_rects_add(list, &merged_rect); - } - } - p = malloc(sizeof(pd_rect_t)); - *p = *rect; - list_append(list, p); - return 0; + if (rect->width <= 0 || rect->height <= 0) { + return -1; + } + for (list_each(node, list)) { + p = node->data; + /* 如果被现有的矩形包含 */ + if (pd_rect_is_include(p, rect)) { + return -2; + } + /* 如果包含现有的矩形 */ + if (pd_rect_is_include(rect, p)) { + prev = node->prev; + free(node->data); + list_delete_node(list, node); + node = prev; + continue; + } + x_distance = p->x + p->width - rect->x - rect->width; + y_distance = p->y + p->height - rect->y - rect->height; + if ((x_distance <= 10 && x_distance >= -10) && + (y_distance <= 10 && y_distance >= -10)) { + pd_rect_merge(&merged_rect, p, rect); + free(node->data); + list_delete_node(list, node); + return pd_rects_add(list, &merged_rect); + } + } + p = malloc(sizeof(pd_rect_t)); + *p = *rect; + list_append(list, p); + return 0; } int pd_rects_remove(list_t *list, pd_rect_t *rect) { - int i; + int i; - pd_bool_t deletable; - pd_rect_t *p, child_rects[4]; + pd_bool_t deletable; + pd_rect_t *p, child_rects[4]; - list_t extra_list; - list_node_t *prev, *node; + list_t extra_list; + list_node_t *prev, *node; - if (rect->width <= 0 || rect->height <= 0) { - return -1; - } - list_create(&extra_list); - for (list_each(node, list)) { - p = node->data; - /* 如果包含现有的矩形 */ - if (pd_rect_is_include(rect, p)) { - prev = node->prev; - free(node->data); - list_delete_node(list, node); - node = prev; - continue; - } - if (!pd_rect_is_cover(p, rect)) { - continue; - } - deletable = PD_TRUE; - pd_rect_split(rect, p, child_rects); - for (i = 0; i < 4; ++i) { - if (child_rects[i].width <= 0 || - child_rects[i].height <= 0) { - continue; - } - if (deletable) { - prev = node->prev; - free(node->data); - list_delete_node(list, node); - node = prev; - deletable = PD_FALSE; - } - p = malloc(sizeof(pd_rect_t)); - *p = child_rects[i]; - list_append(&extra_list, p); - } - } - list_concat(list, &extra_list); - return 0; + if (rect->width <= 0 || rect->height <= 0) { + return -1; + } + list_create(&extra_list); + for (list_each(node, list)) { + p = node->data; + /* 如果包含现有的矩形 */ + if (pd_rect_is_include(rect, p)) { + prev = node->prev; + free(node->data); + list_delete_node(list, node); + node = prev; + continue; + } + if (!pd_rect_is_cover(p, rect)) { + continue; + } + deletable = PD_TRUE; + pd_rect_split(rect, p, child_rects); + for (i = 0; i < 4; ++i) { + if (child_rects[i].width <= 0 || + child_rects[i].height <= 0) { + continue; + } + if (deletable) { + prev = node->prev; + free(node->data); + list_delete_node(list, node); + node = prev; + deletable = PD_FALSE; + } + p = malloc(sizeof(pd_rect_t)); + *p = child_rects[i]; + list_append(&extra_list, p); + } + } + list_concat(list, &extra_list); + return 0; } void pd_rects_clear(list_t *rects) { - list_destroy(rects, free); + list_destroy(rects, free); +} + +int pd_rect_to_str(pd_rect_t *rect, char *str, unsigned max_len) +{ + return snprintf(str, max_len, "(%d, %d, %d, %d)", rect->x, rect->y, + rect->width, rect->height); } diff --git a/lib/pandagl/test/test.c b/lib/pandagl/test/test.c index a0ebc89f..8076de17 100644 --- a/lib/pandagl/test/test.c +++ b/lib/pandagl/test/test.c @@ -5,6 +5,6 @@ int main() { int ret = 0; - describe("test_canvas_mix", test_canvas_mix); - return ret - print_test_result(); + ctest_describe("test_canvas_mix", test_canvas_mix); + return ret - ctest_finish(); } diff --git a/lib/pandagl/test/test_canvas_mix.c b/lib/pandagl/test/test_canvas_mix.c index 71a676bd..8912d216 100644 --- a/lib/pandagl/test/test_canvas_mix.c +++ b/lib/pandagl/test/test_canvas_mix.c @@ -39,20 +39,20 @@ void test_canvas_mix(void) pd_canvas_mix(&red_layer, &blue_layer, 10, 10, PD_TRUE); pixel = pd_canvas_pixel_at(&red_layer, 15, 15); color2str(rgba_str, pixel); - it_s("red_layer(15, 15)", rgba_str, "rgba(50, 0, 204, 1)"); + ctest_euqal_str("red_layer(15, 15)", rgba_str, "rgba(50, 0, 204, 1)"); pd_canvas_mix(&white_layer, &red_layer, 10, 10, PD_TRUE); pixel = pd_canvas_pixel_at(&white_layer, 0, 0); color2str(rgba_str, pixel); - it_s("white_layer(0, 0)", rgba_str, "rgba(255, 255, 255, 1)"); + ctest_euqal_str("white_layer(0, 0)", rgba_str, "rgba(255, 255, 255, 1)"); pixel = pd_canvas_pixel_at(&white_layer, 15, 15); color2str(rgba_str, pixel); - it_s("white_layer(15, 15)", rgba_str, "rgba(255, 127, 127, 1)"); + ctest_euqal_str("white_layer(15, 15)", rgba_str, "rgba(255, 127, 127, 1)"); pixel = pd_canvas_pixel_at(&white_layer, 25, 25); color2str(rgba_str, pixel); - it_s("white_layer(25, 25)", rgba_str, "rgba(152, 127, 229, 1)"); + ctest_euqal_str("white_layer(25, 25)", rgba_str, "rgba(152, 127, 229, 1)"); pd_canvas_destroy(&white_layer); pd_canvas_destroy(&red_layer); diff --git a/lib/thread/include/thread.h b/lib/thread/include/thread.h index f2acd0da..8c534b92 100644 --- a/lib/thread/include/thread.h +++ b/lib/thread/include/thread.h @@ -31,11 +31,11 @@ #ifndef LIB_THREAD_INCLUDE_THREAD_H #define LIB_THREAD_INCLUDE_THREAD_H -#define LIBTHREAD_VERSION "3.0.0-a" -#define LIBTHREAD_VERSION_MAJOR 3 -#define LIBTHREAD_VERSION_MINOR 0 +#define LIBTHREAD_VERSION "0.1.0-a" +#define LIBTHREAD_VERSION_MAJOR 0 +#define LIBTHREAD_VERSION_MINOR 1 #define LIBTHREAD_VERSION_ALTER 0 -/* #undef LIBTHREAD_STATIC_BUILD */ +#define LIBTHREAD_STATIC_BUILD 1 #ifndef LIBTHREAD_PUBLIC #if defined(_MSC_VER) && !defined(LIBTHREAD_STATIC_BUILD) diff --git a/lib/thread/xmake.lua b/lib/thread/xmake.lua index da14327e..c8bd8b79 100644 --- a/lib/thread/xmake.lua +++ b/lib/thread/xmake.lua @@ -1,3 +1,5 @@ +set_version("0.1.0-a") + target("libthread") set_kind("$(kind)") add_files("src/*.c") diff --git a/lib/timer/include/timer.h b/lib/timer/include/timer.h index 9791bcb7..fb8b8c1e 100644 --- a/lib/timer/include/timer.h +++ b/lib/timer/include/timer.h @@ -6,7 +6,7 @@ #define LIBTIMER_VERSION_MAJOR 3 #define LIBTIMER_VERSION_MINOR 0 #define LIBTIMER_VERSION_ALTER 0 -/* #undef LIBTIMER_STATIC_BUILD */ +#define LIBTIMER_STATIC_BUILD 1 #include diff --git a/lib/ui/include/ui/rect.h b/lib/ui/include/ui/rect.h index f94a2ffa..5ac9ff1b 100644 --- a/lib/ui/include/ui/rect.h +++ b/lib/ui/include/ui/rect.h @@ -7,10 +7,10 @@ LIBUI_BEGIN_DECLS LIBUI_PUBLIC void ui_convert_rect(const pd_rect_t *rect, ui_rect_t *rectf, - float scale); + float scale); LIBUI_PUBLIC bool ui_rect_correct(ui_rect_t *rect, float container_width, - float container_height); + float container_height); LIBUI_INLINE bool ui_rect_has_point(ui_rect_t *rect, float x, float y) { @@ -35,10 +35,12 @@ LIBUI_INLINE bool ui_rect_is_include(ui_rect_t *a, ui_rect_t *b) } LIBUI_PUBLIC bool ui_rect_overlap(const ui_rect_t *a, const ui_rect_t *b, - ui_rect_t *overlapping_rect); + ui_rect_t *overlapping_rect); LIBUI_PUBLIC void ui_rect_merge(ui_rect_t *merged_rect, const ui_rect_t *a, - const ui_rect_t *b); + const ui_rect_t *b); + +LIBUI_PUBLIC int ui_rect_to_str(ui_rect_t *rect, char *str, unsigned max_len); LIBUI_END_DECLS diff --git a/lib/ui/src/ui_rect.c b/lib/ui/src/ui_rect.c index a8bfb29b..8709e638 100644 --- a/lib/ui/src/ui_rect.c +++ b/lib/ui/src/ui_rect.c @@ -1,125 +1,133 @@ -#include "../include/ui.h" +#include +#include #include void ui_convert_rect(const pd_rect_t *rect, ui_rect_t *ui_rect, float scale) { - ui_rect->x = rect->x * scale; - ui_rect->y = rect->y * scale; - ui_rect->width = rect->width * scale; - ui_rect->height = rect->height * scale; + ui_rect->x = rect->x * scale; + ui_rect->y = rect->y * scale; + ui_rect->width = rect->width * scale; + ui_rect->height = rect->height * scale; } bool ui_rect_correct(ui_rect_t *rect, float container_width, - float container_height) + float container_height) { - bool overflow = false; + bool overflow = false; - if (rect->x < 0) { - overflow = true; - rect->width += rect->x; - rect->x = 0; - } - if (rect->y < 0) { - overflow = true; - rect->height += rect->y; - rect->y = 0; - } + if (rect->x < 0) { + overflow = true; + rect->width += rect->x; + rect->x = 0; + } + if (rect->y < 0) { + overflow = true; + rect->height += rect->y; + rect->y = 0; + } - if (rect->x + rect->width - container_width > 0) { - overflow = true; - if (rect->x - container_width < 0) { - rect->width = container_width - rect->x; - } else { - rect->width = 0; - } - } - if (rect->y + rect->height - container_height > 0) { - overflow = true; - if (rect->y - container_height < 0) { - rect->height = container_height - rect->y; - } else { - rect->height = 0; - } - } - return overflow; + if (rect->x + rect->width - container_width > 0) { + overflow = true; + if (rect->x - container_width < 0) { + rect->width = container_width - rect->x; + } else { + rect->width = 0; + } + } + if (rect->y + rect->height - container_height > 0) { + overflow = true; + if (rect->y - container_height < 0) { + rect->height = container_height - rect->y; + } else { + rect->height = 0; + } + } + return overflow; } bool ui_rect_is_cover(const ui_rect_t *a, const ui_rect_t *b) { - if (a->x > b->x) { - if (b->x + b->width <= a->x) { - return false; - } - } else { - if (a->x + a->width <= b->x) { - return false; - } - } - if (a->y > b->y) { - if (b->y + b->height <= a->y) { - return false; - } - } else { - if (a->y + a->height <= b->y) { - return false; - } - } - return true; + if (a->x > b->x) { + if (b->x + b->width <= a->x) { + return false; + } + } else { + if (a->x + a->width <= b->x) { + return false; + } + } + if (a->y > b->y) { + if (b->y + b->height <= a->y) { + return false; + } + } else { + if (a->y + a->height <= b->y) { + return false; + } + } + return true; } bool ui_rect_overlap(const ui_rect_t *a, const ui_rect_t *b, - ui_rect_t *overlapping_rect) + ui_rect_t *overlapping_rect) { - if (a->x > b->x) { - if (b->x + b->width > a->x + a->width) { - overlapping_rect->width = a->width; - } else { - overlapping_rect->width = b->x + b->width - a->x; - } - overlapping_rect->x = a->x; - } else { - if (a->x + a->width > b->x + b->width) { - overlapping_rect->width = b->width; - } else { - overlapping_rect->width = a->x + a->width - b->x; - } - overlapping_rect->x = b->x; - } - if (a->y > b->y) { - if (b->y + b->height > a->y + a->height) { - overlapping_rect->height = a->height; - } else { - overlapping_rect->height = b->y + b->height - a->y; - } - overlapping_rect->y = a->y; - } else { - if (a->y + a->height > b->y + b->height) { - overlapping_rect->height = b->height; - } else { - overlapping_rect->height = a->y + a->height - b->y; - } - overlapping_rect->y = b->y; - } - if (overlapping_rect->width <= 0 || overlapping_rect->height <= 0) { - return false; - } - return true; + if (a->x > b->x) { + if (b->x + b->width > a->x + a->width) { + overlapping_rect->width = a->width; + } else { + overlapping_rect->width = b->x + b->width - a->x; + } + overlapping_rect->x = a->x; + } else { + if (a->x + a->width > b->x + b->width) { + overlapping_rect->width = b->width; + } else { + overlapping_rect->width = a->x + a->width - b->x; + } + overlapping_rect->x = b->x; + } + if (a->y > b->y) { + if (b->y + b->height > a->y + a->height) { + overlapping_rect->height = a->height; + } else { + overlapping_rect->height = b->y + b->height - a->y; + } + overlapping_rect->y = a->y; + } else { + if (a->y + a->height > b->y + b->height) { + overlapping_rect->height = b->height; + } else { + overlapping_rect->height = a->y + a->height - b->y; + } + overlapping_rect->y = b->y; + } + if (overlapping_rect->width <= 0 || overlapping_rect->height <= 0) { + return false; + } + return true; } -void ui_rect_merge(ui_rect_t *merged_rect, const ui_rect_t *a, const ui_rect_t *b) +void ui_rect_merge(ui_rect_t *merged_rect, const ui_rect_t *a, + const ui_rect_t *b) { - if (a->x + a->width < b->x + b->width) { - merged_rect->width = b->x + b->width; - } else { - merged_rect->width = a->x + a->width; - } - if (a->y + a->height < b->y + b->height) { - merged_rect->height = b->y + b->height; - } else { - merged_rect->height = a->y + a->height; - } - merged_rect->x = y_min(a->x, b->x); - merged_rect->y = y_min(a->y, b->y); - merged_rect->width -= merged_rect->x; - merged_rect->height -= merged_rect->y; + if (a->x + a->width < b->x + b->width) { + merged_rect->width = b->x + b->width; + } else { + merged_rect->width = a->x + a->width; + } + if (a->y + a->height < b->y + b->height) { + merged_rect->height = b->y + b->height; + } else { + merged_rect->height = a->y + a->height; + } + merged_rect->x = y_min(a->x, b->x); + merged_rect->y = y_min(a->y, b->y); + merged_rect->width -= merged_rect->x; + merged_rect->height -= merged_rect->y; +} + +int ui_rect_to_str(ui_rect_t *rect, char *str, unsigned max_len) +{ + return snprintf(str, max_len, "(%g, %g, %g, %g)", rect->x, rect->y, + rect->width, rect->height); } diff --git a/tests/cases/test_block_layout.c b/tests/cases/test_block_layout.c index 751ff81d..ee05dee6 100644 --- a/tests/cases/test_block_layout.c +++ b/tests/cases/test_block_layout.c @@ -1,7 +1,5 @@ -#include "ctest.h" -#include -#include -#include +#include +#include static void test_dropdown(void) { @@ -9,11 +7,11 @@ static void test_dropdown(void) int width, height; w = ui_get_widget("test-dropdown-menu"); - it_b("$('#test-dropdown-menu')[0].border_box.height < 200", + ctest_euqal_bool("$('#test-dropdown-menu')[0].border_box.height < 200", w->border_box.width < 200, TRUE); - it_b("$('#test-dropdown-menu')[0].border_box.width > 100", + ctest_euqal_bool("$('#test-dropdown-menu')[0].border_box.width > 100", w->border_box.width > 100, TRUE); - it_i("$('#test-dropdown-menu')[0].border_box.height", + ctest_euqal_int("$('#test-dropdown-menu')[0].border_box.height", (int)w->border_box.height, 142); w = ui_widget_get_child(w, 0); @@ -21,21 +19,21 @@ static void test_dropdown(void) height = (int)w->border_box.height; w = ui_widget_next(w); - it_i("$('#test-dropdown-menu .dropdown-item')[1].border_box.width", + ctest_euqal_int("$('#test-dropdown-menu .dropdown-item')[1].border_box.width", (int)w->border_box.width, width); - it_i("$('#test-dropdown-menu .dropdown-item')[1].border_box.height", + ctest_euqal_int("$('#test-dropdown-menu .dropdown-item')[1].border_box.height", (int)w->border_box.height, height); w = ui_widget_next(w); - it_i("$('#test-dropdown-menu .dropdown-item')[2].border_box.width", + ctest_euqal_int("$('#test-dropdown-menu .dropdown-item')[2].border_box.width", (int)w->border_box.width, width); - it_i("$('#test-dropdown-menu .dropdown-item')[2].border_box.height", + ctest_euqal_int("$('#test-dropdown-menu .dropdown-item')[2].border_box.height", (int)w->border_box.height, height); w = ui_widget_next(w); - it_i("$('#test-dropdown-menu .dropdown-item')[3].border_box.width", + ctest_euqal_int("$('#test-dropdown-menu .dropdown-item')[3].border_box.width", (int)w->border_box.width, width); - it_i("$('#test-dropdown-menu .dropdown-item')[3].border_box.height", + ctest_euqal_int("$('#test-dropdown-menu .dropdown-item')[3].border_box.height", (int)w->border_box.height, height); } @@ -56,18 +54,18 @@ static void test_auto_size(void) rect.y = 5; rect.width = 200; rect.height = 50; - it_rectf("$('#test-text-auto-height')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('#test-text-auto-height')[0].border_box", &w->border_box, &rect); w = ui_widget_next(w); - it_i("$('#test-text-auto-size')[0].border_box.y", (int)w->border_box.y, + ctest_euqal_int("$('#test-text-auto-size')[0].border_box.y", (int)w->border_box.y, 5 + 50); w = ui_widget_next(w); - it_i("$('#test-text-block-auto-height')[0].border_box.y", + ctest_euqal_int("$('#test-text-block-auto-height')[0].border_box.y", (int)w->border_box.y, 5 + 50 + 31); - it_i("$('.example')[2].border_box.height", + ctest_euqal_int("$('.example')[2].border_box.height", (int)example->border_box.height, 166); // Update #test-text-auto-size content @@ -79,20 +77,20 @@ static void test_auto_size(void) L"long long long long long long long long long long long long " L"long long text"); ui_update(); - it_i("$('#test-text-auto-size')[0].border_box.x", (int)w->border_box.x, + ctest_euqal_int("$('#test-text-auto-size')[0].border_box.x", (int)w->border_box.x, 5); - it_i("$('#test-text-auto-size')[0].border_box.y", (int)w->border_box.y, + ctest_euqal_int("$('#test-text-auto-size')[0].border_box.y", (int)w->border_box.y, 5 + 50); - it_b("$('#test-text-auto-size')[0].border_box.width <= 758", + ctest_euqal_bool("$('#test-text-auto-size')[0].border_box.width <= 758", w->border_box.width < 758.f, TRUE); - it_i("$('#test-text-auto-size')[0].border_box.height", + ctest_euqal_int("$('#test-text-auto-size')[0].border_box.height", (int)w->border_box.height, 50); w = ui_widget_next(w); - it_i("$('#test-text-block-auto-height')[0].border_box.y", + ctest_euqal_int("$('#test-text-block-auto-height')[0].border_box.y", (int)w->border_box.y, 5 + 50 + 50); - it_i("$('.example')[2].border_box.height", + ctest_euqal_int("$('.example')[2].border_box.height", (int)example->border_box.height, 185); // Update test-text-block-auto-height content @@ -108,7 +106,7 @@ static void test_auto_size(void) rect.y = 5 + 50 + 50; rect.width = 758; rect.height = 50; - it_rectf("$('#test-text-block-auto-height')[0].border_box", + ctest_euqal_ui_rect("$('#test-text-block-auto-height')[0].border_box", &w->border_box, &rect); } @@ -122,7 +120,7 @@ static void test_inline_block_nesting(void) rect.y = 5; rect.width = ui_widget_get_child(w, 0)->border_box.width * 2; rect.height = 31 * 3; - it_rectf("$('#example-inline-block-nesting__block-1')[0].border_box", + ctest_euqal_ui_rect("$('#example-inline-block-nesting__block-1')[0].border_box", &w->border_box, &rect); w = ui_widget_get_child(w, 1); @@ -130,7 +128,7 @@ static void test_inline_block_nesting(void) rect.height = 31; rect.x = rect.width; rect.y = 0; - it_rectf( + ctest_euqal_ui_rect( "$('#example-inline-block-nesting__block-1 .box')[1].border_box", &w->border_box, &rect); @@ -138,13 +136,13 @@ static void test_inline_block_nesting(void) rect.width = rect.width * 2; rect.x = 0; rect.y = 31; - it_rectf( + ctest_euqal_ui_rect( "$('#example-inline-block-nesting__block-1 .box')[2].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.y = 31 * 2; - it_rectf( + ctest_euqal_ui_rect( "$('#example-inline-block-nesting__block-1 .box')[3].border_box", &w->border_box, &rect); @@ -154,7 +152,7 @@ static void test_inline_block_nesting(void) rect.x = w->parent->computed_style.padding_left; rect.x += w->parent->content_box.width - rect.width; rect.y = 5; - it_rectf("$('#example-inline-block-nesting__block-2')[0].border_box", + ctest_euqal_ui_rect("$('#example-inline-block-nesting__block-2')[0].border_box", &w->border_box, &rect); } @@ -163,7 +161,7 @@ static void test_absolutely_positioned_progress_bar(void) ui_widget_t *w; w = ui_get_widget("example-progress-bar__bar"); - it_i("It should have the correct width", (int)w->border_box.width, + ctest_euqal_int("It should have the correct width", (int)w->border_box.width, (int)(w->parent->content_box.width * 0.5)); } @@ -184,42 +182,42 @@ static void test_block_layout_1280(void) rect.width = 780; rect.height = 404; w = ui_widget_get_child(container, 0); - it_rectf("$('.example')[0].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[0].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 304; w = ui_widget_get_child(container, 1); - it_rectf("$('.example')[1].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[1].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 147; w = ui_widget_get_child(container, 2); - it_rectf("$('.example')[2].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[2].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 550; w = ui_widget_get_child(container, 3); - it_rectf("$('.example')[3].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[3].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 354; w = ui_widget_get_child(container, 4); - it_rectf("$('.example')[4].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[4].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 254; w = ui_widget_get_child(container, 5); - it_rectf("$('.example')[5].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[5].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 354; w = ui_widget_get_child(container, 6); - it_rectf("$('.example')[6].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[6].border_box", &w->border_box, &rect); w = ui_get_widget("example-inline-block-nesting"); rect.y += rect.height + 10; rect.height = 147; - it_rectf("$('#example-inline-block-nesting')[0].border_box", + ctest_euqal_ui_rect("$('#example-inline-block-nesting')[0].border_box", &w->border_box, &rect); example = ui_widget_get_child(container, 0); @@ -229,21 +227,21 @@ static void test_block_layout_1280(void) rect.height = 50; rect.x = content->computed_style.padding_left; rect.y = 150 + content->computed_style.padding_top; - it_rectf("$('.example:eq(0) .box')[13].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(0) .box')[13].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x = content->content_box.width - 150.f; rect.x += content->computed_style.padding_left; rect.y += 50; - it_rectf("$('.example:eq(0) .box.ml-auto')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(0) .box.ml-auto')[0].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x = (content->content_box.width - 150.f) / 2.f; rect.x += content->computed_style.padding_left; rect.y += 50; - it_rectf("$('.example:eq(0) .box.ml-auto.mr-auto')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(0) .box.ml-auto.mr-auto')[0].border_box", &w->border_box, &rect); example = ui_widget_get_child(container, 1); @@ -253,51 +251,51 @@ static void test_block_layout_1280(void) rect.y = content->computed_style.padding_top; rect.width = content->content_box.width * 0.5f; rect.height = 50; - it_rectf("$('.example:eq(1) .box')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(1) .box')[0].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.y += 50; - it_rectf("$('.example:eq(1) .box')[1].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(1) .box')[1].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.y += 50; rect.width = content->content_box.width; - it_rectf("$('.example:eq(1) .box')[2].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(1) .box')[2].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.y += 50; rect.width = content->content_box.width * 0.5f; - it_rectf("$('.example:eq(1) .box')[3].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(1) .box')[3].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += rect.width; - it_rectf("$('.example:eq(1) .box')[4].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(1) .box')[4].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.y += 50; rect.x = content->computed_style.padding_left; rect.width = content->content_box.width * 0.25f; - it_rectf("$('.example:eq(1) .box')[5].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(1) .box')[5].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += rect.width; - it_rectf("$('.example:eq(1) .box')[6].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(1) .box')[6].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += rect.width; - it_rectf("$('.example:eq(1) .box')[7].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(1) .box')[7].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += rect.width; - it_rectf("$('.example:eq(1) .box')[8].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(1) .box')[8].border_box", &w->border_box, &rect); example = ui_widget_get_child(container, 3); @@ -311,7 +309,7 @@ static void test_block_layout_1280(void) rect.width -= w->computed_style.margin_left + w->computed_style.margin_right; rect.height = 50; - it_rectf("$('.example:eq(3) .box')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(3) .box')[0].border_box", &w->border_box, &rect); w = ui_widget_get_child(content, 5); @@ -319,21 +317,21 @@ static void test_block_layout_1280(void) rect.y = content->computed_style.padding_top + rect.height + 32; rect.width = 50; rect.height = 50; - it_rectf("$('.example:eq(3) .box')[5].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(3) .box')[5].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += rect.width - 8; rect.y += 8; rect.width = 150; - it_rectf("$('.example:eq(3) .box')[6].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(3) .box')[6].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += rect.width + w->computed_style.margin_left + 8; rect.y -= 8; rect.width = 100; - it_rectf("$('.example:eq(3 .box')[7].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(3 .box')[7].border_box", &w->border_box, &rect); w = ui_widget_next(w); @@ -342,7 +340,7 @@ static void test_block_layout_1280(void) (8 + 50 + 8) - 16; rect.width = content->content_box.width + 32; rect.height = 50; - it_rectf("$('.example:eq(3) .box')[8].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(3) .box')[8].border_box", &w->border_box, &rect); content = ui_widget_get_child(ui_widget_get_child(example, 1), 1); @@ -351,32 +349,32 @@ static void test_block_layout_1280(void) rect.y = content->computed_style.padding_top; rect.width = content->content_box.width; rect.height = 50; - it_rectf("$('.example:eq(3) .box')[9].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(3) .box')[9].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += w->computed_style.margin_left; rect.y += 50; rect.width -= w->computed_style.margin_left; - it_rectf("$('.example:eq(3) .box')[10].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(3) .box')[10].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.y += 50; rect.width = content->content_box.width + 16; - it_rectf("$('.example:eq(3) .box.ml--1.mr--1')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(3) .box.ml--1.mr--1')[0].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.y += 50; rect.width = 200; - it_rectf("$('.example:eq(3) .box.ml--1.mr--1')[1].border_box", + ctest_euqal_ui_rect("$('.example:eq(3) .box.ml--1.mr--1')[1].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.y += 50; rect.width = content->content_box.width; - it_rectf("$('.example:eq(3) .box.ml--1.mr--1')[2].border_box", + ctest_euqal_ui_rect("$('.example:eq(3) .box.ml--1.mr--1')[2].border_box", &w->border_box, &rect); example = ui_widget_get_child(container, 5); @@ -387,29 +385,29 @@ static void test_block_layout_1280(void) rect.y = 0; rect.width = 100; rect.height = 100; - it_rectf("$('#box-absolute-top-left')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('#box-absolute-top-left')[0].border_box", &w->border_box, &rect); w = ui_get_widget("box-absolute-top-right"); rect.x = content->padding_box.width - rect.width; - it_rectf("$('#box-absolute-top-right')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('#box-absolute-top-right')[0].border_box", &w->border_box, &rect); w = ui_get_widget("box-absolute-center"); rect.x = (content->padding_box.width - rect.width) * 0.5f; rect.y = (content->padding_box.height - rect.height) * 0.5f; - it_rectf("$('#box-absolute-center')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('#box-absolute-center')[0].border_box", &w->border_box, &rect); w = ui_get_widget("box-absolute-bottom-left"); rect.x = 0; rect.y = content->padding_box.height - rect.height; - it_rectf("$('#box-absolute-bottom-left')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('#box-absolute-bottom-left')[0].border_box", &w->border_box, &rect); w = ui_get_widget("box-absolute-bottom-right"); rect.x = content->padding_box.width - rect.width; - it_rectf("$('#box-absolute-bottom-right')[0].border_box", + ctest_euqal_ui_rect("$('#box-absolute-bottom-right')[0].border_box", &w->border_box, &rect); // (2) Auto size @@ -419,25 +417,25 @@ static void test_block_layout_1280(void) rect.y = 5; rect.width = 200; rect.height = 31; - it_rectf("$('#test-text-auto-height')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('#test-text-auto-height')[0].border_box", &w->border_box, &rect); w = ui_get_widget("test-text-auto-size"); - it_b("$('#test-text-auto-size')[0].width < 140px", + ctest_euqal_bool("$('#test-text-auto-size')[0].width < 140px", w->border_box.width < 170, TRUE); - it_i("$('#test-text-auto-size')[0].height", (int)w->border_box.height, + ctest_euqal_int("$('#test-text-auto-size')[0].height", (int)w->border_box.height, 31); w = ui_get_widget("test-text-block-auto-height"); - it_i("$('#test-text-block-auto-height')[0].width", + ctest_euqal_int("$('#test-text-block-auto-height')[0].width", (int)w->border_box.width, 758); - it_i("$('#test-text-block-auto-height')[0].height", + ctest_euqal_int("$('#test-text-block-auto-height')[0].height", (int)w->border_box.height, 31); - describe("test auto size", test_auto_size); - describe("test dropdown", test_dropdown); - describe("test inline block nesting", test_inline_block_nesting); - describe("test absolutely positioned progress bar", + ctest_describe("test auto size", test_auto_size); + ctest_describe("test dropdown", test_dropdown); + ctest_describe("test inline block nesting", test_inline_block_nesting); + ctest_describe("test absolutely positioned progress bar", test_absolutely_positioned_progress_bar); } @@ -458,32 +456,32 @@ static void test_block_layout_600(void) rect.width = 600 - 20 - 14; rect.height = 504; w = ui_widget_get_child(container, 0); - it_rectf("$('.example')[0].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[0].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 304; w = ui_widget_get_child(container, 1); - it_rectf("$('.example')[1].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[1].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 204; w = ui_widget_get_child(container, 2); - it_rectf("$('.example')[2].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[2].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 600; w = ui_widget_get_child(container, 3); - it_rectf("$('.example')[3].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[3].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 354; w = ui_widget_get_child(container, 4); - it_rectf("$('.example')[4].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[4].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 254; w = ui_widget_get_child(container, 5); - it_rectf("$('.example')[5].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[5].border_box", &w->border_box, &rect); example = ui_widget_get_child(container, 0); content = ui_widget_get_child(example, 1); @@ -492,7 +490,7 @@ static void test_block_layout_600(void) rect.height = 50; rect.x = content->computed_style.padding_left; rect.y = 100 + content->computed_style.padding_top; - it_rectf("$('.example:eq(0) .box')[11].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(0) .box')[11].border_box", &w->border_box, &rect); w = ui_widget_get_child(content, 14); @@ -500,14 +498,14 @@ static void test_block_layout_600(void) rect.x = content->computed_style.padding_left; rect.x += content->content_box.width - rect.width; rect.y = 250 + content->computed_style.padding_top; - it_rectf("$('.example:eq(0) .box')[14].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(0) .box')[14].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x = content->computed_style.padding_left; rect.x += (content->content_box.width - rect.width) / 2.f; rect.y += 50; - it_rectf("$('.example:eq(0) .box')[15].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(0) .box')[15].border_box", &w->border_box, &rect); w = ui_widget_get_child(content, 26); @@ -515,7 +513,7 @@ static void test_block_layout_600(void) rect.y = content->computed_style.padding_top + 400; rect.width = 50; rect.height = 50; - it_rectf("$('.example:eq(0) .box')[26].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(0) .box')[26].border_box", &w->border_box, &rect); example = ui_widget_get_child(container, 1); @@ -525,51 +523,51 @@ static void test_block_layout_600(void) rect.y = content->computed_style.padding_top; rect.width = content->content_box.width * 0.5f; rect.height = 50; - it_rectf("$('.example:eq(1) .box')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(1) .box')[0].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.y += 50; - it_rectf("$('.example:eq(1) .box')[1].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(1) .box')[1].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.y += 50; rect.width = content->content_box.width; - it_rectf("$('.example:eq(1) .box')[2].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(1) .box')[2].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.y += 50; rect.width = content->content_box.width * 0.5f; - it_rectf("$('.example:eq(1) .box')[3].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(1) .box')[3].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += rect.width; - it_rectf("$('.example:eq(1) .box')[4].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(1) .box')[4].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.y += 50; rect.x = content->computed_style.padding_left; rect.width = content->content_box.width * 0.25f; - it_rectf("$('.example:eq(1) .box')[5].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(1) .box')[5].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += rect.width; - it_rectf("$('.example:eq(1) .box')[6].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(1) .box')[6].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += rect.width; - it_rectf("$('.example:eq(1) .box')[7].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(1) .box')[7].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += rect.width; - it_rectf("$('.example:eq(1) .box')[8].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(1) .box')[8].border_box", &w->border_box, &rect); example = ui_widget_get_child(container, 3); @@ -581,7 +579,7 @@ static void test_block_layout_600(void) content->computed_style.padding_top + (16 + 50 + 16) + (8 + 50 + 8); rect.width = 100; rect.height = 50; - it_rectf("$('.example:eq(3) .box')[7].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(3) .box')[7].border_box", &w->border_box, &rect); content = ui_widget_get_child(ui_widget_get_child(example, 1), 1); @@ -590,7 +588,7 @@ static void test_block_layout_600(void) rect.y = content->computed_style.padding_top + 200; rect.width = content->content_box.width; rect.height = 50; - it_rectf("$('.example:eq(3) .box')[13].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(3) .box')[13].border_box", &w->border_box, &rect); example = ui_widget_get_child(container, 5); @@ -601,29 +599,29 @@ static void test_block_layout_600(void) rect.y = 0; rect.width = 100; rect.height = 100; - it_rectf("$('#box-absolute-top-left')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('#box-absolute-top-left')[0].border_box", &w->border_box, &rect); w = ui_get_widget("box-absolute-top-right"); rect.x = content->padding_box.width - rect.width; - it_rectf("$('#box-absolute-top-right')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('#box-absolute-top-right')[0].border_box", &w->border_box, &rect); w = ui_get_widget("box-absolute-center"); rect.x = (content->padding_box.width - rect.width) * 0.5f; rect.y = (content->padding_box.height - rect.height) * 0.5f; - it_rectf("$('#box-absolute-center')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('#box-absolute-center')[0].border_box", &w->border_box, &rect); w = ui_get_widget("box-absolute-bottom-left"); rect.x = 0; rect.y = content->padding_box.height - rect.height; - it_rectf("$('#box-absolute-bottom-left')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('#box-absolute-bottom-left')[0].border_box", &w->border_box, &rect); w = ui_get_widget("box-absolute-bottom-right"); rect.x = content->padding_box.width - rect.width; - it_rectf("$('#box-absolute-bottom-right')[0].border_box", + ctest_euqal_ui_rect("$('#box-absolute-bottom-right')[0].border_box", &w->border_box, &rect); } @@ -644,32 +642,32 @@ static void test_block_layout_320(void) rect.width = 320 - 20 - 14; rect.height = 604; w = ui_widget_get_child(container, 0); - it_rectf("$('.example')[0].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[0].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 304; w = ui_widget_get_child(container, 1); - it_rectf("$('.example')[1].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[1].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 280; w = ui_widget_get_child(container, 2); - it_rectf("$('.example')[2].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[2].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 732; w = ui_widget_get_child(container, 3); - it_rectf("$('.example')[3].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[3].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 504; w = ui_widget_get_child(container, 4); - it_rectf("$('.example')[4].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[4].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 254; w = ui_widget_get_child(container, 5); - it_rectf("$('.example')[5].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[5].border_box", &w->border_box, &rect); example = ui_widget_get_child(container, 0); content = ui_widget_get_child(example, 1); @@ -679,7 +677,7 @@ static void test_block_layout_320(void) rect.y = content->computed_style.padding_top + 150; rect.width = 50; rect.height = 50; - it_rectf("$('.example:eq(0) .box')[11].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(0) .box')[11].border_box", &w->border_box, &rect); w = ui_widget_get_child(content, 14); @@ -687,14 +685,14 @@ static void test_block_layout_320(void) rect.x = content->computed_style.padding_left; rect.x += content->content_box.width - rect.width; rect.y = content->computed_style.padding_top + 300; - it_rectf("$('.example:eq(0) .box')[14].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(0) .box')[14].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x = content->computed_style.padding_left; rect.x += (content->content_box.width - rect.width) / 2.f; rect.y += 50; - it_rectf("$('.example:eq(0) .box')[15].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(0) .box')[15].border_box", &w->border_box, &rect); w = ui_widget_get_child(content, 26); @@ -702,7 +700,7 @@ static void test_block_layout_320(void) rect.y = content->computed_style.padding_top + 500; rect.width = 50; rect.height = 50; - it_rectf("$('.example:eq(0) .box')[26].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(0) .box')[26].border_box", &w->border_box, &rect); example = ui_widget_get_child(container, 3); @@ -713,7 +711,7 @@ static void test_block_layout_320(void) 3 * (8 + 50 + 8); rect.width = 100; rect.height = 50; - it_rectf("$('.example:eq(3) .box')[7].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(3) .box')[7].border_box", &w->border_box, &rect); example = ui_widget_get_child(container, 5); @@ -724,29 +722,29 @@ static void test_block_layout_320(void) rect.y = 0; rect.width = 100; rect.height = 100; - it_rectf("$('#box-absolute-top-left')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('#box-absolute-top-left')[0].border_box", &w->border_box, &rect); w = ui_get_widget("box-absolute-top-right"); rect.x = content->padding_box.width - rect.width; - it_rectf("$('#box-absolute-top-right')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('#box-absolute-top-right')[0].border_box", &w->border_box, &rect); w = ui_get_widget("box-absolute-center"); rect.x = (content->padding_box.width - rect.width) * 0.5f; rect.y = (content->padding_box.height - rect.height) * 0.5f; - it_rectf("$('#box-absolute-center')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('#box-absolute-center')[0].border_box", &w->border_box, &rect); w = ui_get_widget("box-absolute-bottom-left"); rect.x = 0; rect.y = content->padding_box.height - rect.height; - it_rectf("$('#box-absolute-bottom-left')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('#box-absolute-bottom-left')[0].border_box", &w->border_box, &rect); w = ui_get_widget("box-absolute-bottom-right"); rect.x = content->padding_box.width - rect.width; - it_rectf("$('#box-absolute-bottom-right')[0].border_box", + ctest_euqal_ui_rect("$('#box-absolute-bottom-right')[0].border_box", &w->border_box, &rect); } @@ -762,9 +760,9 @@ void test_block_layout(void) ui_widget_unwrap(wrapper); ui_update(); - describe("root width 1280px", test_block_layout_1280); - describe("root width 600px", test_block_layout_600); - describe("root width 320px", test_block_layout_320); + ctest_describe("root width 1280px", test_block_layout_1280); + ctest_describe("root width 600px", test_block_layout_600); + ctest_describe("root width 320px", test_block_layout_320); #ifndef PREVIEW_MODE lcui_quit(); diff --git a/tests/cases/test_clipboard.c b/tests/cases/test_clipboard.c index a4c34314..649cea82 100644 --- a/tests/cases/test_clipboard.c +++ b/tests/cases/test_clipboard.c @@ -1,8 +1,6 @@ #include #include -#include -#include -#include "ctest.h" +#include static void paste_text(void *arg) { @@ -40,7 +38,7 @@ static void on_check_text(ui_widget_t *w, ui_event_t *e, void *arg) if (clipboard && clipboard->text) { encode_utf8(actual_text, clipboard->text, 31); } - it_s("check the pasted text", actual_text, "helloworld"); + ctest_euqal_str("check the pasted text", actual_text, "helloworld"); lcui_quit(); } diff --git a/tests/cases/test_flex_layout.c b/tests/cases/test_flex_layout.c index ebeb47cd..909726f1 100644 --- a/tests/cases/test_flex_layout.c +++ b/tests/cases/test_flex_layout.c @@ -1,7 +1,5 @@ -#include "ctest.h" #include -#include -#include +#include static void test_flex_layout_with_content_width(float width) { @@ -21,81 +19,81 @@ static void test_flex_layout_with_content_width(float width) rect.width = width; rect.height = 104; w = ui_widget_get_child(container, 0); - it_rectf("$('.example')[0].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[0].border_box", &w->border_box, &rect); rect.y += 114; w = ui_widget_get_child(container, 1); - it_rectf("$('.example')[1].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[1].border_box", &w->border_box, &rect); rect.y += 114; w = ui_widget_get_child(container, 2); - it_rectf("$('.example')[2].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[2].border_box", &w->border_box, &rect); rect.y += 114; w = ui_widget_get_child(container, 3); - it_rectf("$('.example')[3].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[3].border_box", &w->border_box, &rect); rect.y += 114; w = ui_widget_get_child(container, 4); - it_rectf("$('.example')[4].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[4].border_box", &w->border_box, &rect); rect.y += 114; w = ui_widget_get_child(container, 5); - it_rectf("$('.example')[5].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[5].border_box", &w->border_box, &rect); rect.y += 114; w = ui_widget_get_child(container, 6); - it_rectf("$('.example')[6].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[6].border_box", &w->border_box, &rect); rect.y += 114; rect.height = 344; w = ui_widget_get_child(container, 7); - it_rectf("$('.example')[7].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[7].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 204; w = ui_widget_get_child(container, 8); - it_rectf("$('.example')[8].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[8].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 354; w = ui_widget_get_child(container, 9); - it_rectf("$('.example')[9].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[9].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 354; w = ui_widget_get_child(container, 10); - it_rectf("$('.example')[10].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[10].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 354; w = ui_widget_get_child(container, 11); - it_rectf("$('.example')[11].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[11].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 354; w = ui_widget_get_child(container, 12); - it_rectf("$('.example')[12].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[12].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 354; w = ui_widget_get_child(container, 13); - it_rectf("$('.example')[13].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[13].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 254; w = ui_widget_get_child(container, 14); - it_rectf("$('.example')[14].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[14].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 185; w = ui_widget_get_child(container, 15); - it_rectf("$('.example')[15].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[15].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 354; w = ui_widget_get_child(container, 16); - it_rectf("$('.example')[16].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[16].border_box", &w->border_box, &rect); // (1) justify-content: center;; @@ -106,7 +104,7 @@ static void test_flex_layout_with_content_width(float width) rect.y = 5; rect.width = 50; rect.height = 50; - it_rectf("$('.example:eq(1) .box')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(1) .box')[0].border_box", &w->border_box, &rect); // (2) justify-content: flex-end; @@ -115,7 +113,7 @@ static void test_flex_layout_with_content_width(float width) content = ui_widget_get_child(example, 1); w = ui_widget_get_child(content, 0); rect.x = 5 + (content_width - 300); - it_rectf("$('.example:eq(2) .box')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(2) .box')[0].border_box", &w->border_box, &rect); // (3) justify-content: space-between; @@ -124,17 +122,17 @@ static void test_flex_layout_with_content_width(float width) content = ui_widget_get_child(example, 1); w = ui_widget_get_child(content, 0); rect.x = 5; - it_rectf("$('.example:eq(3) .box')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(3) .box')[0].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x = 5 + 50 + (content_width - 300) / 5.f; - it_rectf("$('.example:eq(3) .box')[1].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(3) .box')[1].border_box", &w->border_box, &rect); w = ui_widget_get_child(content, 5); rect.x = 5 + (content_width - 50); - it_rectf("$('.example:eq(3) .box')[5].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(3) .box')[5].border_box", &w->border_box, &rect); // (4) justify-content: space-around; @@ -143,17 +141,17 @@ static void test_flex_layout_with_content_width(float width) content = ui_widget_get_child(example, 1); w = ui_widget_get_child(content, 0); rect.x = 5 + (content_width - 300) / 6.f / 2.f; - it_rectf("$('.example:eq(4) .box')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(4) .box')[0].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += 50 + (content_width - 300) / 6.f; - it_rectf("$('.example:eq(4) .box')[1].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(4) .box')[1].border_box", &w->border_box, &rect); w = ui_widget_get_child(content, 5); rect.x = 5 + content_width - (content_width - 300) / 6.f / 2.f - 50; - it_rectf("$('.example:eq(4) .box')[5].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(4) .box')[5].border_box", &w->border_box, &rect); // (5) Auto margin @@ -162,22 +160,22 @@ static void test_flex_layout_with_content_width(float width) content = ui_widget_get_child(example, 1); w = ui_widget_get_child(content, 0); rect.x = 5; - it_rectf("$('.example:eq(5) .box')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(5) .box')[0].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += 50 + (content_width - 200) / 2.f; - it_rectf("$('.example:eq(5) .box')[1].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(5) .box')[1].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += 50; - it_rectf("$('.example:eq(5) .box')[2].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(5) .box')[2].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += 50 + (content_width - 200) / 2.f; - it_rectf("$('.example:eq(5) .box')[3].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(5) .box')[3].border_box", &w->border_box, &rect); // (7) flex-grow @@ -187,17 +185,17 @@ static void test_flex_layout_with_content_width(float width) w = ui_widget_get_child(content, 0); rect.x = 5; rect.width = content_width / 3.f; - it_rectf("$('.example:eq(7) .box')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(7) .box')[0].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += rect.width; - it_rectf("$('.example:eq(7) .box')[1].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(7) .box')[1].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += rect.width; - it_rectf("$('.example:eq(7) .box')[2].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(7) .box')[2].border_box", &w->border_box, &rect); // line 1 @@ -206,7 +204,7 @@ static void test_flex_layout_with_content_width(float width) w = ui_widget_get_child(content, 0); rect.x = 5; rect.width = content_width - 50 - 50; - it_rectf("$('.example:eq(7) .box')[3].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(7) .box')[3].border_box", &w->border_box, &rect); // line 2 @@ -215,12 +213,12 @@ static void test_flex_layout_with_content_width(float width) w = ui_widget_get_child(content, 0); rect.x = 5; rect.width = (content_width - 50) / 2.f; - it_rectf("$('.example:eq(7) .box')[6].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(7) .box')[6].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += rect.width; - it_rectf("$('.example:eq(7) .box')[7].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(7) .box')[7].border_box", &w->border_box, &rect); // line 3 @@ -228,12 +226,12 @@ static void test_flex_layout_with_content_width(float width) content = ui_widget_get_child(example, 4); w = ui_widget_get_child(content, 1); rect.x = 5 + 50; - it_rectf("$('.example:eq(7) .box')[10].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(7) .box')[10].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += rect.width; - it_rectf("$('.example:eq(7) .box')[11].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(7) .box')[11].border_box", &w->border_box, &rect); // line 4 @@ -242,19 +240,19 @@ static void test_flex_layout_with_content_width(float width) w = ui_widget_get_child(content, 0); rect.x = 5; rect.width = 12 + (content_width - 3 * 12) * 4.f / 7.f; - it_rectf("$('.example:eq(7) .box')[12].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(7) .box')[12].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += rect.width; rect.width = 12 + (content_width - 3 * 12) * 2.f / 7.f; - it_rectf("$('.example:eq(7) .box')[13].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(7) .box')[13].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += rect.width; rect.width = 12 + (content_width - 3 * 12) / 7.f; - it_rectf("$('.example:eq(7) .box')[14].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(7) .box')[14].border_box", &w->border_box, &rect); // (10) align-items: center; height: 300px; @@ -265,12 +263,12 @@ static void test_flex_layout_with_content_width(float width) rect.x = 5; rect.y = 5 + (300 / 3.f - 50) / 2.f; rect.width = 50; - it_rectf("$('.example:eq(10) .box')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(10) .box')[0].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += 50; - it_rectf("$('.example:eq(10) .box')[1].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(10) .box')[1].border_box", &w->border_box, &rect); // (11) align-items: end; height: 300px; @@ -281,12 +279,12 @@ static void test_flex_layout_with_content_width(float width) rect.x = 5; rect.y = 5 + (300 / 3.f - 50); rect.width = 50; - it_rectf("$('.example:eq(11) .box')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(11) .box')[0].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += 50; - it_rectf("$('.example:eq(11) .box')[1].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(11) .box')[1].border_box", &w->border_box, &rect); // (12) align-items: stretch; height: 300px; @@ -298,19 +296,19 @@ static void test_flex_layout_with_content_width(float width) rect.y = 5; rect.width = 50; rect.height = 100; - it_rectf("$('.example:eq(12) .box')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(12) .box')[0].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += 50; - it_rectf("$('.example:eq(12) .box')[1].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(12) .box')[1].border_box", &w->border_box, &rect); w = ui_widget_next(w); w = ui_widget_next(w); rect.x = 5 + 3 * 50; rect.height = 50; - it_rectf("$('.example:eq(12) .box')[3].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(12) .box')[3].border_box", &w->border_box, &rect); // (13) Vertically Centered Layout @@ -322,7 +320,7 @@ static void test_flex_layout_with_content_width(float width) rect.y = 5 + (300 - 50) / 2.f; rect.width = 50; rect.height = 50; - it_rectf("$('.example:eq(13) .box')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(13) .box')[0].border_box", &w->border_box, &rect); // (14) flex-direction: column; @@ -334,19 +332,19 @@ static void test_flex_layout_with_content_width(float width) rect.y = 5; rect.width = 50; rect.height = 50; - it_rectf("$('.example:eq(14) .box')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(14) .box')[0].border_box", &w->border_box, &rect); w = ui_widget_get_child(content, 4); rect.x = 5 + 50 + (content_width - 50 - 150 - 200 - 50 - 50) / 5.f; rect.width = 150; - it_rectf("$('.example:eq(14) .box')[4].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(14) .box')[4].border_box", &w->border_box, &rect); w = ui_widget_get_child(content, 8); rect.x += 150 + (content_width - 50 - 150 - 200 - 50 - 50) / 5.f; rect.width = 50; - it_rectf("$('.example:eq(14) .box')[8].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(14) .box')[8].border_box", &w->border_box, &rect); // (15) Holy Grail Layout @@ -358,12 +356,12 @@ static void test_flex_layout_with_content_width(float width) rect.y = 5; rect.width = content_width; rect.height = 50; - it_rectf("$('.example:eq(15) .layout__header')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(15) .layout__header')[0].border_box", &w->border_box, &rect); w = ui_widget_get_child(content, 2); rect.y = 5 + 50 + 31; - it_rectf("$('.example:eq(15) .layout__footer')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(15) .layout__footer')[0].border_box", &w->border_box, &rect); rect.x = 0; @@ -372,19 +370,19 @@ static void test_flex_layout_with_content_width(float width) rect.height = 31; w = ui_widget_get_child(content, 1); w = ui_widget_get_child(w, 0); - it_rectf("$('.example:eq(15) .layout__left')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(15) .layout__left')[0].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x = 100; rect.width = content_width - 100 - 100; - it_rectf("$('.example:eq(15) .layout__center')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(15) .layout__center')[0].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += rect.width; rect.width = 100; - it_rectf("$('.example:eq(15) .layout__right')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(15) .layout__right')[0].border_box", &w->border_box, &rect); // (16) Holy Grail Layout (height: 300px) @@ -396,12 +394,12 @@ static void test_flex_layout_with_content_width(float width) rect.y = 5; rect.width = content_width; rect.height = 50; - it_rectf("$('.example:eq(16) .layout__header')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(16) .layout__header')[0].border_box", &w->border_box, &rect); w = ui_widget_get_child(content, 2); rect.y = 5 + 50 + 200; - it_rectf("$('.example:eq(16) .layout__footer')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(16) .layout__footer')[0].border_box", &w->border_box, &rect); rect.x = 0; @@ -410,19 +408,19 @@ static void test_flex_layout_with_content_width(float width) rect.height = 200; w = ui_widget_get_child(content, 1); w = ui_widget_get_child(w, 0); - it_rectf("$('.example:eq(16) .layout__left')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(16) .layout__left')[0].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x = 100; rect.width = content_width - 100 - 100; - it_rectf("$('.example:eq(16) .layout__center')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(16) .layout__center')[0].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += rect.width; rect.width = 100; - it_rectf("$('.example:eq(16) .layout__right')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(16) .layout__right')[0].border_box", &w->border_box, &rect); } @@ -433,29 +431,29 @@ static void test_browser_layout(void) w = ui_get_widget("browser-tabbar"); w = ui_widget_get_child(w, 0); - it_i("$('#browser-tabbar .c-frame-tab')[0].width", + ctest_euqal_int("$('#browser-tabbar .c-frame-tab')[0].width", (int)w->border_box.width, 101); w = ui_widget_next(w); - it_i("$('#browser-tabbar .c-frame-tab')[1].width", + ctest_euqal_int("$('#browser-tabbar .c-frame-tab')[1].width", (int)w->border_box.width, 101); w = ui_widget_next(w); - it_i("$('#browser-tabbar .c-frame-tab')[2].width", + ctest_euqal_int("$('#browser-tabbar .c-frame-tab')[2].width", (int)w->border_box.width, 101); w = ui_widget_next(w); - it_i("$('#browser-tabbar .c-frame-tab')[3].width", + ctest_euqal_int("$('#browser-tabbar .c-frame-tab')[3].width", (int)w->border_box.width, 101); w = ui_widget_next(w); - it_i("$('#browser-tabbar .c-frame-tab')[4].width", + ctest_euqal_int("$('#browser-tabbar .c-frame-tab')[4].width", (int)w->border_box.width, 101); w = ui_get_widget("browser-frame-client"); - it_i("$('#browser-frame-client')[0].height", (int)w->border_box.height, + ctest_euqal_int("$('#browser-frame-client')[0].height", (int)w->border_box.height, 224); w = ui_get_widget("browser-frame-content"); - it_i("$('#browser-frame-content')[0].height", (int)w->border_box.height, + ctest_euqal_int("$('#browser-frame-content')[0].height", (int)w->border_box.height, 224); w = ui_get_widget("browser-page-home"); - it_i("$('#browser-page-home')[0].height", (int)w->border_box.height, + ctest_euqal_int("$('#browser-page-home')[0].height", (int)w->border_box.height, 224); w = ui_get_widget("browser-page-home-container"); rect.width = 256; @@ -464,7 +462,7 @@ static void test_browser_layout(void) (538.f - rect.width) / 2.f + w->parent->computed_style.padding_left; rect.y = (204.f - rect.height) / 2.f + w->parent->computed_style.padding_top; - it_rectf("$('#browser-page-home-container')[0].border_box", + ctest_euqal_ui_rect("$('#browser-page-home-container')[0].border_box", &w->border_box, &rect); } @@ -500,81 +498,81 @@ static void test_flex_layout_320(void) rect.width = width; rect.height = 104; w = ui_widget_get_child(container, 0); - it_rectf("$('.example')[0].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[0].border_box", &w->border_box, &rect); rect.y += 114; w = ui_widget_get_child(container, 1); - it_rectf("$('.example')[1].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[1].border_box", &w->border_box, &rect); rect.y += 114; w = ui_widget_get_child(container, 2); - it_rectf("$('.example')[2].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[2].border_box", &w->border_box, &rect); rect.y += 114; w = ui_widget_get_child(container, 3); - it_rectf("$('.example')[3].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[3].border_box", &w->border_box, &rect); rect.y += 114; w = ui_widget_get_child(container, 4); - it_rectf("$('.example')[4].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[4].border_box", &w->border_box, &rect); rect.y += 114; w = ui_widget_get_child(container, 5); - it_rectf("$('.example')[5].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[5].border_box", &w->border_box, &rect); rect.y += 114; w = ui_widget_get_child(container, 6); - it_rectf("$('.example')[6].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[6].border_box", &w->border_box, &rect); rect.y += 114; rect.height = 344; w = ui_widget_get_child(container, 7); - it_rectf("$('.example')[7].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[7].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 354; w = ui_widget_get_child(container, 8); - it_rectf("$('.example')[8].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[8].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 354; w = ui_widget_get_child(container, 9); - it_rectf("$('.example')[9].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[9].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 354; w = ui_widget_get_child(container, 10); - it_rectf("$('.example')[10].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[10].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 354; w = ui_widget_get_child(container, 11); - it_rectf("$('.example')[11].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[11].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 354; w = ui_widget_get_child(container, 12); - it_rectf("$('.example')[12].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[12].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 354; w = ui_widget_get_child(container, 13); - it_rectf("$('.example')[13].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[13].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 254; w = ui_widget_get_child(container, 14); - it_rectf("$('.example')[14].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[14].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 185; w = ui_widget_get_child(container, 15); - it_rectf("$('.example')[15].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[15].border_box", &w->border_box, &rect); rect.y += rect.height + 10; rect.height = 354; w = ui_widget_get_child(container, 16); - it_rectf("$('.example')[16].border_box", &w->border_box, &rect); + ctest_euqal_ui_rect("$('.example')[16].border_box", &w->border_box, &rect); // (1) justify-content: center;; @@ -585,7 +583,7 @@ static void test_flex_layout_320(void) rect.y = 5; rect.width = 50 + (content_width - 300) / 6.f; rect.height = 50; - it_rectf("$('.example:eq(1) .box')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(1) .box')[0].border_box", &w->border_box, &rect); // (2) justify-content: flex-end; @@ -593,7 +591,7 @@ static void test_flex_layout_320(void) example = ui_widget_get_child(container, 2); content = ui_widget_get_child(example, 1); w = ui_widget_get_child(content, 0); - it_rectf("$('.example:eq(2) .box')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(2) .box')[0].border_box", &w->border_box, &rect); // (3) justify-content: space-between; @@ -601,17 +599,17 @@ static void test_flex_layout_320(void) example = ui_widget_get_child(container, 3); content = ui_widget_get_child(example, 1); w = ui_widget_get_child(content, 0); - it_rectf("$('.example:eq(3) .box')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(3) .box')[0].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += rect.width; - it_rectf("$('.example:eq(3) .box')[1].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(3) .box')[1].border_box", &w->border_box, &rect); w = ui_widget_get_child(content, 5); rect.x = 5 + content_width - rect.width; - it_rectf("$('.example:eq(3) .box')[5].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(3) .box')[5].border_box", &w->border_box, &rect); // (5) Auto margin @@ -621,22 +619,22 @@ static void test_flex_layout_320(void) w = ui_widget_get_child(content, 0); rect.x = 5; rect.width = 50; - it_rectf("$('.example:eq(5) .box')[0].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(5) .box')[0].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += 50 + (content_width - 200) / 2.f; - it_rectf("$('.example:eq(5) .box')[1].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(5) .box')[1].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += 50; - it_rectf("$('.example:eq(5) .box')[2].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(5) .box')[2].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += 50 + (content_width - 200) / 2.f; - it_rectf("$('.example:eq(5) .box')[3].border_box", &w->border_box, + ctest_euqal_ui_rect("$('.example:eq(5) .box')[3].border_box", &w->border_box, &rect); // (15) Holy Grail Layout @@ -648,12 +646,12 @@ static void test_flex_layout_320(void) rect.y = 5; rect.width = content_width; rect.height = 50; - it_rectf("$('.example:eq(15) .layout__header')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(15) .layout__header')[0].border_box", &w->border_box, &rect); w = ui_widget_get_child(content, 2); rect.y = 5 + 50 + 31; - it_rectf("$('.example:eq(15) .layout__footer')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(15) .layout__footer')[0].border_box", &w->border_box, &rect); rect.x = 0; @@ -662,19 +660,19 @@ static void test_flex_layout_320(void) rect.height = 31; w = ui_widget_get_child(content, 1); w = ui_widget_get_child(w, 0); - it_rectf("$('.example:eq(15) .layout__left')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(15) .layout__left')[0].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x = 100; rect.width = content_width - 100 - 100; - it_rectf("$('.example:eq(15) .layout__center')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(15) .layout__center')[0].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += rect.width; rect.width = 100; - it_rectf("$('.example:eq(15) .layout__right')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(15) .layout__right')[0].border_box", &w->border_box, &rect); // (16) Holy Grail Layout (height: 300px) @@ -686,12 +684,12 @@ static void test_flex_layout_320(void) rect.y = 5; rect.width = content_width; rect.height = 50; - it_rectf("$('.example:eq(15) .layout__header')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(15) .layout__header')[0].border_box", &w->border_box, &rect); w = ui_widget_get_child(content, 2); rect.y = 5 + 50 + 200; - it_rectf("$('.example:eq(16) .layout__footer')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(16) .layout__footer')[0].border_box", &w->border_box, &rect); rect.x = 0; @@ -700,19 +698,19 @@ static void test_flex_layout_320(void) rect.height = 200; w = ui_widget_get_child(content, 1); w = ui_widget_get_child(w, 0); - it_rectf("$('.example:eq(16) .layout__left')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(16) .layout__left')[0].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x = 100; rect.width = content_width - 100 - 100; - it_rectf("$('.example:eq(16) .layout__center')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(16) .layout__center')[0].border_box", &w->border_box, &rect); w = ui_widget_next(w); rect.x += rect.width; rect.width = 100; - it_rectf("$('.example:eq(16) .layout__right')[0].border_box", + ctest_euqal_ui_rect("$('.example:eq(16) .layout__right')[0].border_box", &w->border_box, &rect); } @@ -729,10 +727,10 @@ void test_flex_layout(void) ui_widget_unwrap(wrapper); ui_update(); - describe("browser layout", test_browser_layout); - describe("root width 1280px", test_flex_layout_1280); - describe("root width 600px", test_flex_layout_600); - describe("root width 320px", test_flex_layout_320); + ctest_describe("browser layout", test_browser_layout); + ctest_describe("root width 1280px", test_flex_layout_1280); + ctest_describe("root width 600px", test_flex_layout_600); + ctest_describe("root width 320px", test_flex_layout_320); #ifndef PREVIEW_MODE lcui_quit(); diff --git a/tests/cases/test_font_load.c b/tests/cases/test_font_load.c index a63b2fdd..8fecf846 100644 --- a/tests/cases/test_font_load.c +++ b/tests/cases/test_font_load.c @@ -1,9 +1,6 @@ -#include -#include -#include -#include -#include "ctest.h" -#include +#include +#include +#include #define GetSegoeUIFont(S, W) pd_font_library_get_font_id("Segoe UI", S, W) #define GetArialFont(S, W) pd_font_library_get_font_id("Arial", S, W) @@ -15,62 +12,62 @@ void test_segoe_ui_font_load(void) if (pd_font_library_load_file("C:/windows/fonts/segoeui.ttf") != 0) { return; } - it_i("load segoeui.ttf", + ctest_euqal_int("load segoeui.ttf", pd_font_library_load_file("C:/windows/fonts/segoeui.ttf"), 0); - it_i("load segoeuib.ttf", + ctest_euqal_int("load segoeuib.ttf", pd_font_library_load_file("C:/windows/fonts/segoeuib.ttf"), 0); - it_i("load segoeuii.ttf", + ctest_euqal_int("load segoeuii.ttf", pd_font_library_load_file("C:/windows/fonts/segoeuii.ttf"), 0); - it_i("load segoeuil.ttf", + ctest_euqal_int("load segoeuil.ttf", pd_font_library_load_file("C:/windows/fonts/segoeuil.ttf"), 0); - it_i("load segoeuisl.ttf", + ctest_euqal_int("load segoeuisl.ttf", pd_font_library_load_file("C:/windows/fonts/segoeuisl.ttf"), 0); - it_i("load segoeuiz.ttf", + ctest_euqal_int("load segoeuiz.ttf", pd_font_library_load_file("C:/windows/fonts/segoeuiz.ttf"), 0); - it_i("load seguibl.ttf", + ctest_euqal_int("load seguibl.ttf", pd_font_library_load_file("C:/windows/fonts/seguibl.ttf"), 0); - it_i("load seguili.ttf", + ctest_euqal_int("load seguili.ttf", pd_font_library_load_file("C:/windows/fonts/seguili.ttf"), 0); - it_b("check get font (style: normal, weight: normal)", + ctest_euqal_bool("check get font (style: normal, weight: normal)", id = GetSegoeUIFont(PD_FONT_STYLE_NORMAL, PD_FONT_WEIGHT_NORMAL), TRUE); if (id > 0) { font = pd_font_library_get_font(id); - it_i("check font style", font->style, PD_FONT_STYLE_NORMAL); - it_i("check font weight", font->weight, PD_FONT_WEIGHT_NORMAL); + ctest_euqal_int("check font style", font->style, PD_FONT_STYLE_NORMAL); + ctest_euqal_int("check font weight", font->weight, PD_FONT_WEIGHT_NORMAL); } - it_b("check get font (style: italic, weight: normal)", + ctest_euqal_bool("check get font (style: italic, weight: normal)", id = GetSegoeUIFont(PD_FONT_STYLE_ITALIC, PD_FONT_WEIGHT_NORMAL), TRUE); if (id > 0) { font = pd_font_library_get_font(id); - it_i("check font style", font->style, PD_FONT_STYLE_ITALIC); - it_i("check font weight", font->weight, PD_FONT_WEIGHT_NORMAL); + ctest_euqal_int("check font style", font->style, PD_FONT_STYLE_ITALIC); + ctest_euqal_int("check font weight", font->weight, PD_FONT_WEIGHT_NORMAL); } - it_b("check get font (style: normal, weight: bold)", + ctest_euqal_bool("check get font (style: normal, weight: bold)", id = GetSegoeUIFont(PD_FONT_STYLE_NORMAL, PD_FONT_WEIGHT_BOLD), TRUE); if (id > 0) { font = pd_font_library_get_font(id); - it_i("check font style", font->style, PD_FONT_STYLE_NORMAL); - it_i("check font weight", font->weight, PD_FONT_WEIGHT_BOLD); + ctest_euqal_int("check font style", font->style, PD_FONT_STYLE_NORMAL); + ctest_euqal_int("check font weight", font->weight, PD_FONT_WEIGHT_BOLD); } - it_b("check get font (style: normal, weight: light)", + ctest_euqal_bool("check get font (style: normal, weight: light)", id = GetSegoeUIFont(PD_FONT_STYLE_NORMAL, PD_FONT_WEIGHT_LIGHT), TRUE); if (id > 0) { font = pd_font_library_get_font(id); - it_i("check font style", font->style, PD_FONT_STYLE_NORMAL); - it_i("check font weight", font->weight, PD_FONT_WEIGHT_LIGHT); + ctest_euqal_int("check font style", font->style, PD_FONT_STYLE_NORMAL); + ctest_euqal_int("check font weight", font->weight, PD_FONT_WEIGHT_LIGHT); } - it_b("check get font (style: italic, weight: extra light)", + ctest_euqal_bool("check get font (style: italic, weight: extra light)", id = GetSegoeUIFont(PD_FONT_STYLE_ITALIC, PD_FONT_WEIGHT_EXTRA_LIGHT), TRUE); if (id > 0) { font = pd_font_library_get_font(id); - it_i("check font style", font->style, PD_FONT_STYLE_ITALIC); - it_i("check font weight", font->weight, + ctest_euqal_int("check font style", font->style, PD_FONT_STYLE_ITALIC); + ctest_euqal_int("check font weight", font->weight, PD_FONT_WEIGHT_EXTRA_LIGHT); } } @@ -82,53 +79,53 @@ void test_arial_font_load(void) if (pd_font_library_load_file("C:/windows/fonts/arial.ttf") != 0) { return; } - it_i("load arialbd.ttf", + ctest_euqal_int("load arialbd.ttf", pd_font_library_load_file("C:/windows/fonts/arialbd.ttf"), 0); - it_i("load arialblk.ttf", + ctest_euqal_int("load arialblk.ttf", pd_font_library_load_file("C:/windows/fonts/ariblk.ttf"), 0); - it_i("load arialbi.ttf", + ctest_euqal_int("load arialbi.ttf", pd_font_library_load_file("C:/windows/fonts/arialbi.ttf"), 0); - it_i("load ariali.ttf", + ctest_euqal_int("load ariali.ttf", pd_font_library_load_file("C:/windows/fonts/ariali.ttf"), 0); - it_b("check get font (style: normal, weight: normal)", + ctest_euqal_bool("check get font (style: normal, weight: normal)", id = GetArialFont(PD_FONT_STYLE_NORMAL, PD_FONT_WEIGHT_NORMAL), TRUE); if (id > 0) { font = pd_font_library_get_font(id); - it_i("check font style", font->style, PD_FONT_STYLE_NORMAL); - it_i("check font weight", font->weight, PD_FONT_WEIGHT_NORMAL); + ctest_euqal_int("check font style", font->style, PD_FONT_STYLE_NORMAL); + ctest_euqal_int("check font weight", font->weight, PD_FONT_WEIGHT_NORMAL); } - it_b("check get font (style: italic, weight: normal)", + ctest_euqal_bool("check get font (style: italic, weight: normal)", id = GetArialFont(PD_FONT_STYLE_ITALIC, PD_FONT_WEIGHT_NORMAL), TRUE); if (id > 0) { font = pd_font_library_get_font(id); - it_i("check font style", font->style, PD_FONT_STYLE_ITALIC); - it_i("check font weight", font->weight, PD_FONT_WEIGHT_NORMAL); + ctest_euqal_int("check font style", font->style, PD_FONT_STYLE_ITALIC); + ctest_euqal_int("check font weight", font->weight, PD_FONT_WEIGHT_NORMAL); } - it_b("check get font (style: normal, weight: bold)", + ctest_euqal_bool("check get font (style: normal, weight: bold)", id = GetArialFont(PD_FONT_STYLE_NORMAL, PD_FONT_WEIGHT_BOLD), TRUE); if (id > 0) { font = pd_font_library_get_font(id); - it_i("check font style", font->style, PD_FONT_STYLE_NORMAL); - it_i("check font weight", font->weight, PD_FONT_WEIGHT_BOLD); + ctest_euqal_int("check font style", font->style, PD_FONT_STYLE_NORMAL); + ctest_euqal_int("check font weight", font->weight, PD_FONT_WEIGHT_BOLD); } - it_b("check get font (style: normal, weight: black)", + ctest_euqal_bool("check get font (style: normal, weight: black)", id = GetArialFont(PD_FONT_STYLE_NORMAL, PD_FONT_WEIGHT_BLACK), TRUE); if (id > 0) { font = pd_font_library_get_font(id); - it_i("check font style", font->style, PD_FONT_STYLE_NORMAL); - it_i("check font weight", font->weight, PD_FONT_WEIGHT_BLACK); + ctest_euqal_int("check font style", font->style, PD_FONT_STYLE_NORMAL); + ctest_euqal_int("check font weight", font->weight, PD_FONT_WEIGHT_BLACK); } - it_b("check get font (style: italic, weight: bold)", + ctest_euqal_bool("check get font (style: italic, weight: bold)", id = GetSegoeUIFont(PD_FONT_STYLE_ITALIC, PD_FONT_WEIGHT_BOLD), TRUE); if (id > 0) { font = pd_font_library_get_font(id); - it_i("check font style", font->style, PD_FONT_STYLE_ITALIC); - it_i("check font weight", font->weight, PD_FONT_WEIGHT_BOLD); + ctest_euqal_int("check font style", font->style, PD_FONT_STYLE_ITALIC); + ctest_euqal_int("check font weight", font->weight, PD_FONT_WEIGHT_BOLD); } } @@ -136,19 +133,19 @@ void test_font_load(void) { pd_font_library_init(); /* 测试是否能够从字体文件中载入字体 */ - it_i("check pd_font_library_load_file success", + ctest_euqal_int("check pd_font_library_load_file success", pd_font_library_load_file("test_font_load.ttf"), 0); #ifdef LIBPLAT_WIN32 - describe("test segoe ui font load", test_segoe_ui_font_load); - describe("test arial font load", test_arial_font_load); + ctest_describe("test segoe ui font load", test_segoe_ui_font_load); + ctest_describe("test arial font load", test_arial_font_load); #endif pd_font_library_destroy(); ui_init(); /* 测试是否能够根据 CSS 文件中定义的 @font-face 规则来载入字体 */ - it_i("check LCUIFont_LoadCSSFile success", + ctest_euqal_int("check LCUIFont_LoadCSSFile success", ui_load_css_file("test_font_load.css"), 0); - it_b("check pd_font_library_get_font_id success", + ctest_euqal_bool("check pd_font_library_get_font_id success", pd_font_library_get_font_id("icomoon", 0, 0) > 0, TRUE); ui_destroy(); } diff --git a/tests/cases/test_image_reader.c b/tests/cases/test_image_reader.c index 51b11767..d9bd68aa 100644 --- a/tests/cases/test_image_reader.c +++ b/tests/cases/test_image_reader.c @@ -1,8 +1,6 @@ #include #include -#include -#include -#include "ctest.h" +#include void test_image_reader(void) { @@ -15,15 +13,15 @@ void test_image_reader(void) pd_canvas_init(&img); snprintf(file, 255, "test_image_reader.%s", formats[i]); logger_debug("image file: %s\n", file); - it_i("check pd_read_image_from_file", pd_read_image_from_file(file, &img), + ctest_euqal_int("check pd_read_image_from_file", pd_read_image_from_file(file, &img), 0); - it_i("check image width with ReadImageFile", img.width, 91); - it_i("check image height with ReadImageFile", img.height, 69); - it_i("check pd_read_image_size_from_file", + ctest_euqal_int("check image width with ReadImageFile", img.width, 91); + ctest_euqal_int("check image height with ReadImageFile", img.height, 69); + ctest_euqal_int("check pd_read_image_size_from_file", pd_read_image_size_from_file(file, &width, &height), 0); logger_debug("image size: (%d, %d)\n", width, height); - it_i("check image width with GetImageSize", width, 91); - it_i("check image height with GetImageSize", height, 69); + ctest_euqal_int("check image width with GetImageSize", width, 91); + ctest_euqal_int("check image height with GetImageSize", height, 69); pd_canvas_destroy(&img); } } diff --git a/tests/cases/test_mainloop.c b/tests/cases/test_mainloop.c index e64d7bc6..90f3c8f7 100644 --- a/tests/cases/test_mainloop.c +++ b/tests/cases/test_mainloop.c @@ -1,10 +1,6 @@ #include #include -#include -#include -#include -#include -#include "ctest.h" +#include static void OnRefreshScreen(void *arg) { @@ -45,9 +41,9 @@ static void ObserverThread(void *arg) for (i = 0; i < 20 && !*exited; ++i) { sleep_ms(100); } - it_b("main loop should exit within 2000ms", *exited, TRUE); + ctest_euqal_bool("main loop should exit within 2000ms", *exited, TRUE); if (!*exited) { - exit(-print_test_result()); + exit(-ctest_finish()); return; } thread_exit(NULL); diff --git a/tests/cases/test_scrollbar.c b/tests/cases/test_scrollbar.c index cebdf83e..ba6ccd3b 100644 --- a/tests/cases/test_scrollbar.c +++ b/tests/cases/test_scrollbar.c @@ -1,10 +1,5 @@ #include -#include -#include -#include -#include -#include -#include "ctest.h" +#include /* clang-format off */ @@ -128,7 +123,7 @@ void test_scrollbar(void) ui_dispatch_event(&e); lcui_update_ui(); - it_b("content should be moved to the left", + ctest_euqal_bool("content should be moved to the left", content->computed_style.left < left && top == content->computed_style.top, TRUE); @@ -147,7 +142,7 @@ void test_scrollbar(void) ui_dispatch_event(&e); lcui_update_ui(); - it_b("content should be moved to the right", + ctest_euqal_bool("content should be moved to the right", content->computed_style.left > left && top == content->computed_style.top, TRUE); @@ -174,7 +169,7 @@ void test_scrollbar(void) ui_dispatch_event(&e); lcui_update_ui(); - it_b("content should be moved to the top", + ctest_euqal_bool("content should be moved to the top", content->computed_style.left == left && top > content->computed_style.top, TRUE); @@ -193,7 +188,7 @@ void test_scrollbar(void) ui_dispatch_event(&e); lcui_update_ui(); - it_b("the content should have scrolled to the bottom", + ctest_euqal_bool("the content should have scrolled to the bottom", content->computed_style.left == left && top < content->computed_style.top, TRUE); diff --git a/tests/cases/test_settings.c b/tests/cases/test_settings.c index b345adde..a96416eb 100644 --- a/tests/cases/test_settings.c +++ b/tests/cases/test_settings.c @@ -1,7 +1,6 @@ #include #include -#include -#include "ctest.h" +#include static void check_settings_frame_rate_cap(void *arg) { @@ -11,7 +10,7 @@ static void check_settings_frame_rate_cap(void *arg) sprintf(str, "should work when frame cap is %u (actual %u)", fps_limit, fps); - it_b(str, fps <= fps_limit + 2 && fps > fps_limit / 2, TRUE); + ctest_euqal_bool(str, fps <= fps_limit + 2 && fps > fps_limit / 2, TRUE); lcui_quit(); } @@ -23,12 +22,12 @@ static void test_default_settings(void) lcui_reset_settings(); lcui_get_settings(&settings); - it_i("check default frame rate cap", settings.frame_rate_cap, 120); - it_i("check default parallel rendering threads", + ctest_euqal_int("check default frame rate cap", settings.frame_rate_cap, 120); + ctest_euqal_int("check default parallel rendering threads", settings.parallel_rendering_threads, 4); - it_b("check default record profile", settings.record_profile, FALSE); - it_b("check default fps meter", settings.fps_meter, FALSE); - it_b("check default paint flashing", settings.paint_flashing, FALSE); + ctest_euqal_bool("check default record profile", settings.record_profile, FALSE); + ctest_euqal_bool("check default fps meter", settings.fps_meter, FALSE); + ctest_euqal_bool("check default paint flashing", settings.paint_flashing, FALSE); lcui_quit(); lcui_main(); } @@ -46,12 +45,12 @@ static void test_apply_settings(void) lcui_init(); lcui_apply_settings(&settings); lcui_get_settings(&settings); - it_i("check frame rate cap", settings.frame_rate_cap, 60); - it_i("check parallel rendering threads", + ctest_euqal_int("check frame rate cap", settings.frame_rate_cap, 60); + ctest_euqal_int("check parallel rendering threads", settings.parallel_rendering_threads, 2); - it_b("check record profile", settings.record_profile, TRUE); - it_b("check fps meter", settings.fps_meter, TRUE); - it_b("check paint flashing", settings.paint_flashing, TRUE); + ctest_euqal_bool("check record profile", settings.record_profile, TRUE); + ctest_euqal_bool("check fps meter", settings.fps_meter, TRUE); + ctest_euqal_bool("check paint flashing", settings.paint_flashing, TRUE); settings.frame_rate_cap = -1; settings.parallel_rendering_threads = -1; @@ -59,14 +58,14 @@ static void test_apply_settings(void) lcui_apply_settings(&settings); lcui_get_settings(&settings); - it_i("check frame rate cap minimum", settings.frame_rate_cap, 1); - it_i("check parallel rendering threads minimum", + ctest_euqal_int("check frame rate cap minimum", settings.frame_rate_cap, 1); + ctest_euqal_int("check parallel rendering threads minimum", settings.parallel_rendering_threads, 1); lcui_reset_settings(); lcui_get_settings(&settings); - it_i("check frame rate cap", settings.frame_rate_cap, LCUI_MAX_FRAMES_PER_SEC); + ctest_euqal_int("check frame rate cap", settings.frame_rate_cap, LCUI_MAX_FRAMES_PER_SEC); lcui_quit(); lcui_main(); } @@ -108,7 +107,7 @@ void test_settings_frame_rate_cap(void) void test_settings(void) { - describe("test default settings", test_default_settings); - describe("test apply settings", test_apply_settings); - describe("test settings.frame_rate_cap", test_settings_frame_rate_cap); + ctest_describe("test default settings", test_default_settings); + ctest_describe("test apply settings", test_apply_settings); + ctest_describe("test settings.frame_rate_cap", test_settings_frame_rate_cap); } diff --git a/tests/cases/test_textedit.c b/tests/cases/test_textedit.c index 6c0eaf21..d9e142bc 100644 --- a/tests/cases/test_textedit.c +++ b/tests/cases/test_textedit.c @@ -1,7 +1,5 @@ #include -#include -#include -#include "ctest.h" +#include void test_textedit(void) { @@ -14,29 +12,29 @@ void test_textedit(void) ui_textedit_set_text_w(w, L"hello"); ui_widget_update(w); - it_b("check TextEdit_GetLength after ui_textedit_set_text_w", + ctest_euqal_bool("check TextEdit_GetLength after ui_textedit_set_text_w", ui_textedit_get_text_length(w) == wcslen(L"hello"), TRUE); - it_b("check ui_textedit_get_text_w after ui_textedit_set_text_w", + ctest_euqal_bool("check ui_textedit_get_text_w after ui_textedit_set_text_w", ui_textedit_get_text_w(w, 0, 64, wcs) == wcslen(L"hello"), TRUE); - it_b("check string retrieved from ui_textedit_get_text_w", + ctest_euqal_bool("check string retrieved from ui_textedit_get_text_w", wcscmp(L"hello", wcs) == 0, TRUE); ui_widget_set_text(w, "hello"); ui_widget_update(w); - it_b("check TextEdit_GetLength after ui_textedit_set_text", + ctest_euqal_bool("check TextEdit_GetLength after ui_textedit_set_text", ui_textedit_get_text_length(w) == wcslen(L"hello"), TRUE); - it_b("check ui_textedit_get_text_w after ui_textedit_set_text", + ctest_euqal_bool("check ui_textedit_get_text_w after ui_textedit_set_text", ui_textedit_get_text_w(w, 0, 64, wcs) == wcslen(L"hello"), TRUE); - it_b("check string retrieved from ui_textedit_get_text_w", + ctest_euqal_bool("check string retrieved from ui_textedit_get_text_w", wcscmp(L"hello", wcs) == 0, TRUE); ui_textedit_append_text_w(w, L"world"); ui_widget_update(w); - it_b("check TextEdit_GetLength after ui_textedit_append_text_w", + ctest_euqal_bool("check TextEdit_GetLength after ui_textedit_append_text_w", ui_textedit_get_text_length(w) == wcslen(L"helloworld"), TRUE); - it_b("check ui_textedit_get_text_w after ui_textedit_append_text_w", + ctest_euqal_bool("check ui_textedit_get_text_w after ui_textedit_append_text_w", ui_textedit_get_text_w(w, 0, 64, wcs) == wcslen(L"helloworld"), TRUE); - it_b("check string retrieved from ui_textedit_get_text_w", + ctest_euqal_bool("check string retrieved from ui_textedit_get_text_w", wcscmp(L"helloworld", wcs) == 0, TRUE); ui_textedit_move_caret(w, 0, 5); @@ -45,12 +43,12 @@ void test_textedit(void) ui_textedit_move_caret(w, 0, 100); ui_textedit_insert_text_w(w, L"!"); ui_widget_update(w); - it_b("check TextEdit_GetLength after inserting text", + ctest_euqal_bool("check TextEdit_GetLength after inserting text", ui_textedit_get_text_length(w) == wcslen(L"hello, world!"), TRUE); - it_b("check ui_textedit_get_text_w after inserting text", + ctest_euqal_bool("check ui_textedit_get_text_w after inserting text", ui_textedit_get_text_w(w, 0, 64, wcs) == wcslen(L"hello, world!"), TRUE); - it_b("check string retrieved from ui_textedit_get_text_w", + ctest_euqal_bool("check string retrieved from ui_textedit_get_text_w", wcscmp(L"hello, world!", wcs) == 0, TRUE); ui_widget_destroy(w); lcui_quit(); diff --git a/tests/cases/test_textview_resize.c b/tests/cases/test_textview_resize.c index a878f9b2..ac508555 100644 --- a/tests/cases/test_textview_resize.c +++ b/tests/cases/test_textview_resize.c @@ -1,7 +1,5 @@ #include -#include -#include -#include "ctest.h" +#include /* clang-format off */ @@ -78,12 +76,12 @@ static void check_textview_set_text(void) { ui_update(); - it_b("check block width", self.block->border_box.width == 122.0f, TRUE); - it_b("check block height", self.block->border_box.height > 140.0f, + ctest_euqal_bool("check block width", self.block->border_box.width == 122.0f, TRUE); + ctest_euqal_bool("check block height", self.block->border_box.height > 140.0f, TRUE); - it_b("check inline block width", + ctest_euqal_bool("check inline block width", self.inline_block->border_box.width > 520.0f, TRUE); - it_b("check inline block height", + ctest_euqal_bool("check inline block height", self.inline_block->border_box.height < 45.0f, TRUE); } @@ -98,11 +96,11 @@ static void check_textview_set_short_content_css(void) { ui_update(); - it_b("check block width", self.block->border_box.width == 122.0f, TRUE); - it_b("check block height", self.block->border_box.height < 45.0f, TRUE); - it_b("check inline block width", + ctest_euqal_bool("check block width", self.block->border_box.width == 122.0f, TRUE); + ctest_euqal_bool("check block height", self.block->border_box.height < 45.0f, TRUE); + ctest_euqal_bool("check inline block width", self.inline_block->border_box.width < 70.0f, TRUE); - it_b("check inline block height", + ctest_euqal_bool("check inline block height", self.inline_block->border_box.height < 45.0f, TRUE); } @@ -119,11 +117,11 @@ static void check_textview_set_long_content_css(void) { ui_update(); - it_b("check block width", self.block->border_box.width == 122.0f, TRUE); - it_b("check block height", self.block->border_box.height > 60.0f, TRUE); - it_b("check inline block width", + ctest_euqal_bool("check block width", self.block->border_box.width == 122.0f, TRUE); + ctest_euqal_bool("check block height", self.block->border_box.height > 60.0f, TRUE); + ctest_euqal_bool("check inline block width", self.inline_block->border_box.width > 250.0f, TRUE); - it_b("check inline block height", + ctest_euqal_bool("check inline block height", self.inline_block->border_box.height < 45.0f, TRUE); } @@ -134,12 +132,12 @@ void test_textview_resize(void) build(); test_textview_set_text(NULL); - describe("check textview set text", check_textview_set_text); + ctest_describe("check textview set text", check_textview_set_text); test_textview_set_short_content_css(NULL); - describe("check textview set short content css", + ctest_describe("check textview set short content css", check_textview_set_short_content_css); test_textview_set_long_content_css(NULL); - describe("check textview set long content css", + ctest_describe("check textview set long content css", check_textview_set_long_content_css); lcui_quit(); diff --git a/tests/cases/test_thread.c b/tests/cases/test_thread.c index 6d8ab088..9c2741d3 100644 --- a/tests/cases/test_thread.c +++ b/tests/cases/test_thread.c @@ -1,8 +1,7 @@ #include #include #include -#include -#include "ctest.h" +#include typedef struct TestWorkerRec_ { char data[32]; @@ -79,6 +78,6 @@ void test_thread(void) TestWorker_Send(&worker, "bye!"); sleep_ms(100); TestWorker_Destroy(&worker); - it_i("check worker data count", worker.data_count, 7); - it_b("check worker is no longer active", worker.active, FALSE); + ctest_euqal_int("check worker data count", worker.data_count, 7); + ctest_euqal_bool("check worker is no longer active", worker.active, FALSE); } diff --git a/tests/cases/test_widget_event.c b/tests/cases/test_widget_event.c index c832bddb..07db4e6e 100644 --- a/tests/cases/test_widget_event.c +++ b/tests/cases/test_widget_event.c @@ -1,7 +1,7 @@ #include #include #include -#include "ctest.h" +#include void test_widget_mouse_event(void) { @@ -26,33 +26,33 @@ void test_widget_mouse_event(void) ev.mouse.y = 150; ui_dispatch_event(&ev); ui_update(); - it_b("mousemove(150, 150): root.hasStatus('hover') == true", + ctest_euqal_bool("mousemove(150, 150): root.hasStatus('hover') == true", ui_widget_has_status(root, "hover"), TRUE); - it_b("mousemove(150, 150): parent.hasStatus('hover') == false", + ctest_euqal_bool("mousemove(150, 150): parent.hasStatus('hover') == false", ui_widget_has_status(parent, "hover"), FALSE); - it_b("mousemove(150, 150): child.hasStatus('hover') == false", + ctest_euqal_bool("mousemove(150, 150): child.hasStatus('hover') == false", ui_widget_has_status(child, "hover"), FALSE); ev.mouse.x = 80; ev.mouse.y = 80; ui_dispatch_event(&ev); ui_update(); - it_b("mousemove(80, 80): root.hasStatus('hover') == true", + ctest_euqal_bool("mousemove(80, 80): root.hasStatus('hover') == true", ui_widget_has_status(root, "hover"), TRUE); - it_b("mousemove(80, 80): parent.hasStatus('hover') == true", + ctest_euqal_bool("mousemove(80, 80): parent.hasStatus('hover') == true", ui_widget_has_status(parent, "hover"), TRUE); - it_b("mousemove(80, 80): child.hasStatus('hover') == false", + ctest_euqal_bool("mousemove(80, 80): child.hasStatus('hover') == false", ui_widget_has_status(child, "hover"), FALSE); ev.mouse.x = 40; ev.mouse.y = 40; ui_dispatch_event(&ev); ui_update(); - it_b("mousemove(40, 40): root.hasStatus('hover') == true", + ctest_euqal_bool("mousemove(40, 40): root.hasStatus('hover') == true", ui_widget_has_status(root, "hover"), TRUE); - it_b("mousemove(40, 40): parent.hasStatus('hover') == true", + ctest_euqal_bool("mousemove(40, 40): parent.hasStatus('hover') == true", ui_widget_has_status(parent, "hover"), TRUE); - it_b("mousemove(40, 40): child.hasStatus('hover') == true", + ctest_euqal_bool("mousemove(40, 40): child.hasStatus('hover') == true", ui_widget_has_status(child, "hover"), TRUE); ev.type = UI_EVENT_MOUSEDOWN; @@ -61,21 +61,21 @@ void test_widget_mouse_event(void) ev.mouse.button = MOUSE_BUTTON_LEFT; ui_dispatch_event(&ev); ui_update(); - it_b("mousedown(40, 40): root.hasStatus('active') == true", + ctest_euqal_bool("mousedown(40, 40): root.hasStatus('active') == true", ui_widget_has_status(root, "active"), TRUE); - it_b("mousedown(40, 40): parent.hasStatus('active') == true", + ctest_euqal_bool("mousedown(40, 40): parent.hasStatus('active') == true", ui_widget_has_status(parent, "active"), TRUE); - it_b("mousedown(40, 40): child.hasStatus('active') == true", + ctest_euqal_bool("mousedown(40, 40): child.hasStatus('active') == true", ui_widget_has_status(child, "active"), TRUE); ev.type = UI_EVENT_MOUSEUP; ui_dispatch_event(&ev); ui_update(); - it_b("mouseup(40, 40): root.hasStatus('active') == false", + ctest_euqal_bool("mouseup(40, 40): root.hasStatus('active') == false", ui_widget_has_status(root, "active"), FALSE); - it_b("mouseup(40, 40): parent.hasStatus('active') == false", + ctest_euqal_bool("mouseup(40, 40): parent.hasStatus('active') == false", ui_widget_has_status(parent, "active"), FALSE); - it_b("mouseup(40, 40): child.hasStatus('active') == false", + ctest_euqal_bool("mouseup(40, 40): child.hasStatus('active') == false", ui_widget_has_status(child, "active"), FALSE); ev.type = UI_EVENT_MOUSEMOVE; @@ -83,22 +83,22 @@ void test_widget_mouse_event(void) ev.mouse.y = 80; ui_dispatch_event(&ev); ui_update(); - it_b("mousemove(80, 80): root.hasStatus('hover') == true", + ctest_euqal_bool("mousemove(80, 80): root.hasStatus('hover') == true", ui_widget_has_status(root, "hover"), TRUE); - it_b("mousemove(80, 80): parent.hasStatus('hover') == true", + ctest_euqal_bool("mousemove(80, 80): parent.hasStatus('hover') == true", ui_widget_has_status(parent, "hover"), TRUE); - it_b("mousemove(80, 80): child.hasStatus('hover') == false", + ctest_euqal_bool("mousemove(80, 80): child.hasStatus('hover') == false", ui_widget_has_status(child, "hover"), FALSE); ev.mouse.x = 150; ev.mouse.y = 150; ui_dispatch_event(&ev); ui_update(); - it_b("mousemove(150, 150): root.hasStatus('hover') == true", + ctest_euqal_bool("mousemove(150, 150): root.hasStatus('hover') == true", ui_widget_has_status(root, "hover"), TRUE); - it_b("mousemove(150, 150): parent.hasStatus('hover') == false", + ctest_euqal_bool("mousemove(150, 150): parent.hasStatus('hover') == false", ui_widget_has_status(parent, "hover"), FALSE); - it_b("mousemove(150, 150): child.hasStatus('hover') == false", + ctest_euqal_bool("mousemove(150, 150): child.hasStatus('hover') == false", ui_widget_has_status(child, "hover"), FALSE); lcui_quit(); @@ -107,5 +107,5 @@ void test_widget_mouse_event(void) void test_widget_event(void) { - describe("test widget mouse event", test_widget_mouse_event); + ctest_describe("test widget mouse event", test_widget_mouse_event); } diff --git a/tests/cases/test_widget_opacity.c b/tests/cases/test_widget_opacity.c index 55b5e257..86177973 100644 --- a/tests/cases/test_widget_opacity.c +++ b/tests/cases/test_widget_opacity.c @@ -1,7 +1,7 @@ #include #include #include -#include "ctest.h" +#include #define PARENT_OPACITY 0.8f #define CHILD_OPACITY 0.5f @@ -66,14 +66,14 @@ static void check_widget_opactiy(void) color = pd_canvas_get_pixel(&canvas, 10, 10); pd_blend_pixel(&expected_color, &parent_bcolor, (int)(PARENT_OPACITY * 255)); - it_b("check parent border color", check_color(expected_color, color), + ctest_euqal_bool("check parent border color", check_color(expected_color, color), TRUE); expected_color = bgcolor; color = pd_canvas_get_pixel(&canvas, 30, 30); pd_blend_pixel(&expected_color, &parent_bgcolor, (int)(PARENT_OPACITY * 255)); - it_b("check parent background color", + ctest_euqal_bool("check parent background color", check_color(expected_color, color), TRUE); tmp = parent_bgcolor; @@ -81,7 +81,7 @@ static void check_widget_opactiy(void) color = pd_canvas_get_pixel(&canvas, 60, 90); pd_blend_pixel(&tmp, &child_bgcolor, (int)(CHILD_OPACITY * 255)); pd_blend_pixel(&expected_color, &tmp, (int)(PARENT_OPACITY * 255)); - it_b("check child 1 background color", + ctest_euqal_bool("check child 1 background color", check_color(expected_color, color), TRUE); tmp = parent_bgcolor; @@ -89,18 +89,18 @@ static void check_widget_opactiy(void) color = pd_canvas_get_pixel(&canvas, 60, 120); pd_blend_pixel(&tmp, &child_footer_bgcolor, (int)(CHILD_OPACITY * 255)); pd_blend_pixel(&expected_color, &tmp, (int)(PARENT_OPACITY * 255)); - it_b("check child 1 footer background color", + ctest_euqal_bool("check child 1 footer background color", check_color(expected_color, color), TRUE); expected_color = bgcolor; color = pd_canvas_get_pixel(&canvas, 220, 90); pd_blend_pixel(&expected_color, &child_bgcolor, (int)(PARENT_OPACITY * 255)); - it_b("check child 2 background color", + ctest_euqal_bool("check child 2 background color", check_color(expected_color, color), TRUE); expected_color = child_footer_bgcolor; color = pd_canvas_get_pixel(&canvas, 220, 120); - it_b("check child 2 footer background color", + ctest_euqal_bool("check child 2 footer background color", check_color(expected_color, color), TRUE); pd_canvas_destroy(&canvas); @@ -111,7 +111,7 @@ void test_widget_opacity(void) lcui_init(); build(); - describe("check widget opacity", check_widget_opactiy); + ctest_describe("check widget opacity", check_widget_opactiy); lcui_quit(); lcui_main(); } diff --git a/tests/cases/test_widget_rect.c b/tests/cases/test_widget_rect.c index 88e76f38..649d27e4 100644 --- a/tests/cases/test_widget_rect.c +++ b/tests/cases/test_widget_rect.c @@ -3,7 +3,7 @@ #include #include #include -#include "ctest.h" +#include void test_widget_rect(void) { @@ -38,7 +38,7 @@ void test_widget_rect(void) ui_dispatch_event(&e); ui_update(); ui_widget_get_dirty_rects(root, &rects); - it_b("app.trigger({ type: 'mousemove', x: 150, y: 150}), " + ctest_euqal_bool("app.trigger({ type: 'mousemove', x: 150, y: 150}), " "root.getDirtyRects().length == 0", rects.length == 0, TRUE); @@ -47,7 +47,7 @@ void test_widget_rect(void) ui_dispatch_event(&e); ui_update(); ui_widget_get_dirty_rects(root, &rects); - it_b("app.trigger({ type: 'mousemove', x: 80, y: 80 }), " + ctest_euqal_bool("app.trigger({ type: 'mousemove', x: 80, y: 80 }), " "root.getDirtyRects().length == 1", rects.length == 1, TRUE); @@ -58,7 +58,7 @@ void test_widget_rect(void) if (rects.length == 1) { rect = *(pd_rect_t *)list_get(&rects, 0); } - it_rect("root.getDirtyRects()[0]", &rect, &expected_rect); + ctest_euqal_pd_rect("root.getDirtyRects()[0]", &rect, &expected_rect); list_destroy(&rects, free); e.mouse.x = 40; @@ -66,7 +66,7 @@ void test_widget_rect(void) ui_dispatch_event(&e); ui_update(); ui_widget_get_dirty_rects(root, &rects); - it_b("app.trigger({ type: 'mousemove', x: 40, y: 40 }), " + ctest_euqal_bool("app.trigger({ type: 'mousemove', x: 40, y: 40 }), " "root.getDirtyRects().length == 0", rects.length == 0, TRUE); @@ -77,26 +77,26 @@ void test_widget_rect(void) ui_dispatch_event(&e); ui_update(); ui_widget_get_dirty_rects(root, &rects); - it_b("app.trigger({ type: 'mousedown', x: 40, y: 40 }), " + ctest_euqal_bool("app.trigger({ type: 'mousedown', x: 40, y: 40 }), " "root.getDirtyRects().length == 1", rects.length == 1, TRUE); if (rects.length == 1) { rect = *(pd_rect_t *)list_get(&rects, 0); } - it_rect("root.getDirtyRects()[0]", &rect, &expected_rect); + ctest_euqal_pd_rect("root.getDirtyRects()[0]", &rect, &expected_rect); list_destroy(&rects, free); e.type = UI_EVENT_MOUSEUP; ui_dispatch_event(&e); ui_update(); ui_widget_get_dirty_rects(root, &rects); - it_b("app.trigger({ type: 'mouseup', x: 40, y: 40 }), " + ctest_euqal_bool("app.trigger({ type: 'mouseup', x: 40, y: 40 }), " "root.getDirtyRects().length == 1", rects.length == 1, TRUE); if (rects.length == 1) { rect = *(pd_rect_t *)list_get(&rects, 0); } - it_rect("root.getDirtyRects()[0]", &rect, &expected_rect); + ctest_euqal_pd_rect("root.getDirtyRects()[0]", &rect, &expected_rect); list_destroy(&rects, free); e.type = UI_EVENT_MOUSEMOVE; @@ -105,7 +105,7 @@ void test_widget_rect(void) ui_dispatch_event(&e); ui_update(); ui_widget_get_dirty_rects(root, &rects); - it_b("app.trigger({ type: 'mousemove', x: 80, y: 80 }), " + ctest_euqal_bool("app.trigger({ type: 'mousemove', x: 80, y: 80 }), " "root.getDirtyRects().length == 0", rects.length == 0, TRUE); @@ -115,13 +115,13 @@ void test_widget_rect(void) ui_update(); ui_widget_get_dirty_rects(root, &rects); - it_b("app.trigger({ type: 'mousemove', x: 150, y: 150 }), " + ctest_euqal_bool("app.trigger({ type: 'mousemove', x: 150, y: 150 }), " "root.getDirtyRects().length == 1", rects.length == 1, TRUE); if (rects.length == 1) { rect = *(pd_rect_t *)list_get(&rects, 0); } - it_rect("root.getDirtyRects()[0]", &rect, &expected_rect); + ctest_euqal_pd_rect("root.getDirtyRects()[0]", &rect, &expected_rect); list_destroy(&rects, free); expected_rect.x = 21; @@ -131,12 +131,12 @@ void test_widget_rect(void) ui_widget_remove(child); ui_update(); ui_widget_get_dirty_rects(root, &rects); - it_b("child.destroy(), root.getDirtyRects().length == 1", + ctest_euqal_bool("child.destroy(), root.getDirtyRects().length == 1", rects.length == 1, TRUE); if (rects.length == 1) { rect = *(pd_rect_t *)list_get(&rects, 0); } - it_rect("root.getDirtyRects()[0]", &rect, &expected_rect); + ctest_euqal_pd_rect("root.getDirtyRects()[0]", &rect, &expected_rect); list_destroy(&rects, free); expected_rect.x = 0; @@ -146,12 +146,12 @@ void test_widget_rect(void) ui_widget_remove(parent); ui_update(); ui_widget_get_dirty_rects(root, &rects); - it_b("parent.destroy(), root.getDirtyRects().length == 1", + ctest_euqal_bool("parent.destroy(), root.getDirtyRects().length == 1", rects.length == 1, TRUE); if (rects.length == 1) { rect = *(pd_rect_t *)list_get(&rects, 0); } - it_rect("root.getDirtyRects()[0]", &rect, &expected_rect); + ctest_euqal_pd_rect("root.getDirtyRects()[0]", &rect, &expected_rect); list_destroy(&rects, free); lcui_destroy(); diff --git a/tests/cases/test_xml_parser.c b/tests/cases/test_xml_parser.c index ac301ab1..7ad6565c 100644 --- a/tests/cases/test_xml_parser.c +++ b/tests/cases/test_xml_parser.c @@ -1,20 +1,18 @@ #include -#include -#include -#include "ctest.h" +#include static void check_widget_attribute(void) { ui_widget_t* w; w = ui_get_widget("test-attr-disabled-1"); - it_b("check element-1 is disabled", w->disabled, TRUE); + ctest_euqal_bool("check element-1 is disabled", w->disabled, TRUE); w = ui_get_widget("test-attr-disabled-2"); - it_b("check element-2 is disabled", w->disabled, TRUE); + ctest_euqal_bool("check element-2 is disabled", w->disabled, TRUE); w = ui_get_widget("test-attr-disabled-3"); - it_b("check element-3 is disabled", w->disabled, TRUE); + ctest_euqal_bool("check element-3 is disabled", w->disabled, TRUE); w = ui_get_widget("test-attr-disabled-4"); - it_b("check element-4 is normal", w->disabled, FALSE); + ctest_euqal_bool("check element-4 is normal", w->disabled, FALSE); } static void check_widget_loaded_from_nested_xml(void) @@ -22,13 +20,13 @@ static void check_widget_loaded_from_nested_xml(void) ui_widget_t* w; w = ui_get_widget("test-nested-1"); - it_b("check test-nested-1 should exist", w != NULL, TRUE); + ctest_euqal_bool("check test-nested-1 should exist", w != NULL, TRUE); w = ui_get_widget("test-nested-2"); - it_b("check test-nested-2 should exist", w != NULL, TRUE); + ctest_euqal_bool("check test-nested-2 should exist", w != NULL, TRUE); w = ui_get_widget("test-nested-3"); - it_b("check test-nested-3 should exist", w != NULL, TRUE); + ctest_euqal_bool("check test-nested-3 should exist", w != NULL, TRUE); w = ui_get_widget("test-nested-4"); - it_b("check test-nested-4 should exist", w != NULL, TRUE); + ctest_euqal_bool("check test-nested-4 should exist", w != NULL, TRUE); } void test_xml_parser(void) @@ -36,7 +34,7 @@ void test_xml_parser(void) ui_widget_t *pack; ui_init(); - it_b("load XML file", + ctest_euqal_bool("load XML file", (pack = ui_load_xml_file("test_xml_parser.xml")) != NULL, TRUE); if (!pack) { @@ -46,8 +44,8 @@ void test_xml_parser(void) ui_root_append(pack); ui_widget_unwrap(pack); ui_update(); - describe("check widget attribute", check_widget_attribute); - describe("check widget loaded from nested xml", + ctest_describe("check widget attribute", check_widget_attribute); + ctest_describe("check widget loaded from nested xml", check_widget_loaded_from_nested_xml); ui_destroy(); } diff --git a/tests/include/ctest-custom.h b/tests/include/ctest-custom.h new file mode 100644 index 00000000..e695cb7b --- /dev/null +++ b/tests/include/ctest-custom.h @@ -0,0 +1,16 @@ +#include +#include +#include +#include + +static inline bool ctest_euqal_pd_rect(const char *name, pd_rect_t *actual, + pd_rect_t *expected) +{ + return ctest_equal(name, pd_rect_to_str, actual, expected); +} + +static inline bool ctest_euqal_ui_rect(const char *name, pd_rect_t *actual, + pd_rect_t *expected) +{ + return ctest_equal(name, ui_rect_to_str, actual, expected); +} diff --git a/tests/run_tests.c b/tests/run_tests.c index 5bb57e59..a654ee72 100644 --- a/tests/run_tests.c +++ b/tests/run_tests.c @@ -2,27 +2,27 @@ #include #include #include -#include "ctest.h" +#include #include "run_tests.h" int main(int argc, char **argv) { int ret = 0; logger_set_level(LOGGER_LEVEL_ERROR); - describe("test settings", test_settings); - describe("test thread", test_thread); - describe("test font load", test_font_load); - describe("test image reader", test_image_reader); - describe("test xml parser", test_xml_parser); - describe("test mainloop", test_mainloop); - describe("test clipboard", test_clipboard); - describe("test widget event", test_widget_event); - describe("test widget opacity", test_widget_opacity); - describe("test textview resize", test_textview_resize); - describe("test textedit", test_textedit); - describe("test scrollbar", test_scrollbar); - describe("test widget rect", test_widget_rect); - describe("test block layout", test_block_layout); - describe("test flex layout", test_flex_layout); - return ret - print_test_result(); + ctest_describe("test settings", test_settings); + ctest_describe("test thread", test_thread); + ctest_describe("test font load", test_font_load); + ctest_describe("test image reader", test_image_reader); + ctest_describe("test xml parser", test_xml_parser); + ctest_describe("test mainloop", test_mainloop); + ctest_describe("test clipboard", test_clipboard); + ctest_describe("test widget event", test_widget_event); + ctest_describe("test widget opacity", test_widget_opacity); + ctest_describe("test textview resize", test_textview_resize); + ctest_describe("test textedit", test_textedit); + ctest_describe("test scrollbar", test_scrollbar); + ctest_describe("test widget rect", test_widget_rect); + ctest_describe("test block layout", test_block_layout); + ctest_describe("test flex layout", test_flex_layout); + return ret - ctest_finish(); } diff --git a/xmake.lua b/xmake.lua index d126c988..86ec0da3 100644 --- a/xmake.lua +++ b/xmake.lua @@ -42,6 +42,7 @@ end target("lcui_tests") set_kind("binary") set_rundir("tests") + add_includedirs("tests/include") add_files("tests/run_tests.c", "tests/cases/*.c") add_deps("ctest", "lcui") on_run(function (target)