Files
LCUI/tests/integration/test_text_resize.c
Liu faa7058837 test: reorganize test suite with xmake test integration
Restructure the test infrastructure with these changes:

* Extend libctest with ctest_suite_t, ctest_parse_args, ctest_run_suites and CTEST_MAIN macro to standardize test entry points; support --grep / --grep= / --list / --interactive flags; add ctest-tests for self-tests.

* Regroup tests by lib boundary: sink unit tests into lib/<name>/tests/ with <lib>_<topic> entry function names, move fixtures into lib/<name>/tests/fixtures/, rename top-level tests/cases/ to tests/integration/ for cross-lib integration tests.

* Add tests/scenes/ for reusable widget tree builders shared by integration cases and visual preview binaries; add tests/previews/ with 4 diagnostic binaries (flex_layout, block_layout, widget_opacity, scrollbar).

* Rewrite all describe/equal description strings using 'should ...' style or noun topic names; drop redundant lcui_quit/lcui_main calls from integration cases.

* Integrate xmake test via add_tests(\default\) and a shared tests.runnable rule defined in the root xmake.lua; the rule wraps the test binary with drmemory (Windows) or valgrind (Linux) when option memcheck=y.

* Drop the lcui-tests aggregation: lcui-tests now contains only integration cases and scenes, not the union of lib tests. Use xmake test to run everything across libs.

* Fix .clang-format: InsertNewlineAtEndOfFile -> InsertNewlineAtEOF (correct key for clang-format 16+).

* Update AGENTS.md with the new test layout, naming rules, description style and run commands.

* Update CI to use xmake test and xmake f --memcheck=y instead of per-lib runs.
2026-05-24 17:56:23 +08:00

155 lines
4.9 KiB
C

/*
* tests/cases/test_text_resize.c
*
* Copyright (c) 2023, Liu Chao <i@lc-soft.io> All rights reserved.
*
* SPDX-License-Identifier: MIT
*
* This file is part of LCUI, distributed under the MIT License found in the
* LICENSE.TXT file in the root directory of this source tree.
*/
#include <LCUI.h>
#include <ctest-custom.h>
/* clang-format off */
static struct {
ui_widget_t* block;
ui_widget_t* inline_block;
} self;
static const char *css = "\
.block {\
width: 100px;\
margin: 10px;\
padding: 10px;\
display: block;\
border: 1px solid #f00;\
line-height: 20px;\
}\
.inline-block {\
margin: 10px;\
padding: 10px;\
display: inline-block;\
border: 1px solid #f00;\
line-height: 20px;\
}\
.short-content {\
content: \"hello!\";\
}\
.long-content {\
content: \"this is long long long long long long long text\";\
}";
/* clang-format on */
static void build(void)
{
ui_widget_t *root;
ui_load_css_string(css, __FILE__);
self.block = ui_create_widget("text");
self.inline_block = ui_create_widget("text");
ui_widget_set_id(self.block, "debug-block");
ui_widget_set_id(self.inline_block, "debug-inline-block");
ui_text_set_content_w(self.block, L"block");
ui_text_set_content_w(self.inline_block, L"inline block");
ui_widget_add_class(self.block, "block");
ui_widget_add_class(self.inline_block, "inline-block");
root = ui_root();
ui_widget_append(root, self.block);
ui_widget_append(root, self.inline_block);
}
static void test_text_set_content(void *arg)
{
ui_text_set_content(self.inline_block,
"long long long long long long long "
"long long long long long long long "
"long long long long long long long text");
ui_text_set_content(self.block,
"long long long long long long long "
"long long long long long long long "
"long long long long long long long text");
}
static void check_text_set_content(void)
{
ui_update();
ctest_equal_float("should match block width",
self.block->border_box.width, 122.f);
ctest_equal_bool("should expand block height beyond 140px",
self.block->border_box.height > 140.f, true);
ctest_equal_float("should match inline block width",
self.inline_block->border_box.width, 580.f);
ctest_equal_float("should match inline block height",
self.inline_block->border_box.height, 62.f);
}
static void test_text_set_short_content_css(void *arg)
{
ui_widget_add_class(self.block, "short-content");
ui_widget_add_class(self.inline_block, "short-content");
}
static void check_text_set_short_content_css(void)
{
ui_update();
ctest_equal_float("should match block width with short content",
self.block->border_box.width, 122.f);
ctest_equal_float("should match block height with short content",
self.block->border_box.height, 42.f);
ctest_equal_bool("should shrink inline block width below 70px",
self.inline_block->border_box.width < 70.f, true);
ctest_equal_float("should match inline block height with short content",
self.inline_block->border_box.height, 42.f);
}
static void test_text_set_long_content_css(void *arg)
{
ui_widget_remove_class(self.block, "short-content");
ui_widget_remove_class(self.inline_block, "short-content");
ui_widget_add_class(self.block, "long-content");
ui_widget_add_class(self.inline_block, "long-content");
}
static void check_text_set_long_content_css(void)
{
ui_update();
ctest_equal_float("should match block width with long content",
self.block->border_box.width, 122.0f);
ctest_equal_bool("should expand block height beyond 60px",
self.block->border_box.height > 60.0f, true);
ctest_equal_bool("should expand inline block width beyond 250px",
self.inline_block->border_box.width > 250.0f, true);
ctest_equal_bool("should keep inline block height below 45px",
self.inline_block->border_box.height < 45.0f, true);
}
void test_text_resize(void)
{
lcui_init();
build();
ui_widget_resize(ui_root(), 600, 600);
test_text_set_content(NULL);
ctest_describe("text set content", check_text_set_content);
test_text_set_short_content_css(NULL);
ctest_describe("text set short content css",
check_text_set_short_content_css);
test_text_set_long_content_css(NULL);
ctest_describe("text set long content css",
check_text_set_long_content_css);
lcui_destroy();
}