test: add context to spinner capture and gallery resize assertions

Spinner tolerances scale with the reference ink size, and gallery resize assertions include the requested width and column index so repeated loop iterations are distinguishable.
This commit is contained in:
Liu
2026-11-21 14:45:31 +08:00
parent e26cd958a0
commit 03aef4fed3
2 changed files with 57 additions and 15 deletions
@@ -486,18 +486,30 @@ static void test_native_window_resize(void)
float root_width;
int i;
int j;
char desc[160];
for (i = 0; i < sizeof(widths) / sizeof(widths[0]); ++i) {
home_scene_native_resize(widths[i], 1000.0f);
root_width = ui_root()->content_box.width;
expected = home_scene_expected_column_width(root_width);
ctest_equal_bool("native resize should update the root width",
fabsf(root_width - widths[i]) < 2.0f, true);
ctest_equal_int("native resize should update the column count",
home_scene_visible_columns(), visible[i]);
snprintf(desc, sizeof(desc),
"native resize should update the root width "
"(requested=%.1f, actual=%.1f)",
widths[i], root_width);
ctest_equal_bool(desc, fabsf(root_width - widths[i]) < 2.0f,
true);
snprintf(desc, sizeof(desc),
"native resize should update the column count "
"(width=%.1f)",
widths[i]);
ctest_equal_int(desc, home_scene_visible_columns(), visible[i]);
snprintf(desc, sizeof(desc),
"native resize should shrink the gallery content "
"(width=%.1f, actual=%.1f, expected=%.1f)",
widths[i], scene->grid->content_box.width,
expected * visible[i] + HOME_GAP * (visible[i] - 1));
ctest_equal_float(
"native resize should shrink the gallery content",
scene->grid->content_box.width,
desc, scene->grid->content_box.width,
expected * visible[i] + HOME_GAP * (visible[i] - 1));
for (j = 0; j < HOME_GRID_COLUMNS; ++j) {
if (!scene->columns[j] ||
@@ -506,9 +518,13 @@ static void test_native_window_resize(void)
CSS_DISPLAY_NONE) {
continue;
}
ctest_equal_float(
"native resize should update the used column width",
scene->columns[j]->border_box.width, expected);
snprintf(desc, sizeof(desc),
"native resize should update the used column "
"width (width=%.1f, column=%d)",
widths[i], j);
ctest_equal_float(desc,
scene->columns[j]->border_box.width,
expected);
}
}
}
+32 -6
View File
@@ -1098,6 +1098,8 @@ static void check_text_capture_size(void)
ui_widget_t *sp, *content, *txt, *plain, *ptxt;
pd_canvas_t cap, ref;
int cx, cy, cw, ch, rx, ry, rw, rh;
int width_tolerance, height_tolerance, margin_tolerance;
char desc[160];
ui_metrics.dpi = 96;
ui_load_css_string(css, "t-cap-demo");
@@ -1134,14 +1136,38 @@ static void check_text_capture_size(void)
text_ink_bbox(&cap, 96, 32, &cx, &cy, &cw, &ch);
text_ink_bbox(&ref, 96, 32, &rx, &ry, &rw, &rh);
width_tolerance = rw / 16;
if (width_tolerance < 2) {
width_tolerance = 2;
}
height_tolerance = rh / 16;
if (height_tolerance < 2) {
height_tolerance = 2;
}
margin_tolerance = rw / 16;
if (margin_tolerance < 2) {
margin_tolerance = 2;
}
ctest_equal_bool("text capture: the captured text should be visible",
cw > 0 && ch > 0, true);
ctest_equal_bool("text capture: width should match a normal render",
cw > 0 && abs(cw - rw) <= 2, true);
ctest_equal_bool("text capture: height should match a normal render",
ch > 0 && abs(ch - rh) <= 2, true);
ctest_equal_bool("text capture: left margin should match",
cw > 0 && abs(cx - rx) <= 2, true);
snprintf(desc, sizeof(desc),
"text capture: width should match a normal render "
"(captured=%d, direct=%d, tolerance=%d)",
cw, rw, width_tolerance);
ctest_equal_bool(desc, cw > 0 && abs(cw - rw) <= width_tolerance, true);
snprintf(desc, sizeof(desc),
"text capture: height should match a normal render "
"(captured=%d, direct=%d, tolerance=%d)",
ch, rh, height_tolerance);
ctest_equal_bool(desc, ch > 0 && abs(ch - rh) <= height_tolerance,
true);
snprintf(desc, sizeof(desc),
"text capture: left margin should match "
"(captured=%d, direct=%d, tolerance=%d)",
cx, rx, margin_tolerance);
ctest_equal_bool(desc, cw > 0 && abs(cx - rx) <= margin_tolerance,
true);
pd_canvas_destroy(&cap);
pd_canvas_destroy(&ref);