Files
MeowOS-SDK/sdk/test_meow_ui_theme_export.c
T
AskaEth 432875d4e6 sdk: 宿主测试头注释按实测修订 + select T1 探针修正
- test_meow_ui_select: T1 选中高亮探针移到容器卡内(x=12),
  适配 M6.37 起的 listview 默认容器模式;6/6 PASS
- 各 test_*.c 头注释补 -Iinclude、meow_ui_nav.c 及精简源列表最小补集
  (theme/widgets/notif_gesture/overlay/suppress/sdk_fixes/pinyin/ime_fix)
- test_sb_statusbar 头注释给出可链接命令(--allow-multiple-definition)
- notify_post/ui_audio_host/p1p2p3 标注需主仓组件,公开仓跳过
- docs/APP_DEV_GUIDE.md: 去掉叠字与过强表述,改为 34/38 实测口径
2026-11-04 20:26:35 +08:00

123 lines
6.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* test_meow_ui_theme_export.c — M7.0a 主题收口前置(缺口#6 SDK 半)宿主验证:
* §8.1.5 色板导出/注入——meow_theme_export 拷当前权威主题;meow_theme_inject 覆写当前生效主题。
*
* 覆盖:
* T1 导出一致性:export 后关键字段 == meow_theme_get()(当前 style×mode 权威板);
* T2 注入:inject 一份自定义板 → meow_theme_get()/export 都返回注入板(单一权威反映);
* 注入恢复内建:inject(NULL) 后回到目标 style×mode 的内建板;
* T3 launcher 薄壳映射契约:导出板能映射出 meow_ui_theme_t 的 9 个角色字段(surface/
* surface_variant/surface_container/primary/on_surface/on_surface_variant/outline/error/
* surface_tint),值与 SDK meow_theme 对应字段一致。
*
* 编译(宿主 gcc,链真实 gfx/sys/theme/vol/log/widget/input/activity/dialog/ime + 打桩 font/global):
* gcc -Wall -Wextra -o test_meow_ui_theme_export test_meow_ui_theme_export.c test_host_stub.c \
* meow_ui_gfx.c meow_ui_sys.c meow_ui_theme.c meow_ui_vol.c meow_ui_log.c \
* meow_ui_widget.c meow_ui_input.c meow_ui_activity.c meow_ui_dialog.c meow_ui_ime.c meow_ui_str.c \
* meow_pinyin.c meow_ui_draw.c meow_ui_view.c meow_ui_box.c meow_ui_anim.c meow_ui_scroll.c \
* meow_ui_img.c meow_ui_media.c meow_notify_ipc.c stb_image.c meow_ui_nav.c \
* -I. -Iinclude -DMEOW_UI_HOST_TEST -pthread -lm
* 运行:./test_meow_ui_theme_export
*/
#include "meow_ui.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
static int g_fail = 0;
#define CHECK(cond, name) do { \
if (cond) printf(" PASS %s\n", name); \
else { printf(" FAIL %s\n", name); g_fail++; } } while (0)
/* launcher meow_ui_theme_t 的 9 字段形状(测试内复刻字段名,不依赖 launcher 内部头)。 */
typedef struct {
uint32_t surface, surface_variant, surface_container;
uint32_t primary, on_surface, on_surface_variant;
uint32_t outline, error, surface_tint;
} shell_theme;
static shell_theme export_shell(const meow_theme *t)
{
shell_theme s;
s.surface = t->surface;
s.surface_variant = t->surfaceVariant;
s.surface_container = t->surfaceContainer;
s.primary = t->primary;
s.on_surface = t->onSurface;
s.on_surface_variant= t->onSurfaceVariant;
s.outline = t->outline;
s.error = t->error;
s.surface_tint = t->surfaceTint;
return s;
}
int main(void)
{
setenv("MEOW_UI_DUMP", "/tmp/theme_export.ppm", 1);
meow_ui_opts o = { 480, 720 };
assert(meow_ui_init(&o) == 0);
/* ---- T1 导出一致性(MD3 dark) ---- */
printf("T1 export consistency\n");
meow_theme_set_mode(MEOW_THEME_DARK);
meow_ui_set_style(MEOW_STYLE_MD3);
const meow_theme *t0 = meow_theme_get();
meow_theme e0; meow_theme_export(&e0);
CHECK(e0.surface == t0->surface, "export.surface == get.surface");
CHECK(e0.primary == t0->primary, "export.primary == get.primary");
CHECK(e0.surfaceVariant== t0->surfaceVariant,"export.surfaceVariant == get.surfaceVariant");
CHECK(e0.onSurface == t0->onSurface, "export.onSurface == get.onSurface");
CHECK(e0.radius == t0->radius, "export.radius == get.radius");
CHECK(e0.bg == t0->bg, "export.bg == get.bg (background override applied)");
/* MIUIx light:确认导出随 style×mode 切换(不是固定板) */
meow_ui_set_style(MEOW_STYLE_MIUIX);
meow_theme_set_mode(MEOW_THEME_LIGHT);
const meow_theme *t1 = meow_theme_get();
meow_theme e1; meow_theme_export(&e1);
CHECK(e1.primary == 0xF57200 && t1->primary == 0xF57200, "MIUIx light primary exported");
CHECK(e1.bg == t1->bg && e1.surface == t1->surface, "MIUIx light bg/surface exported");
CHECK(e1.surface == (uint32_t)0xF7F3EE, "MIUIx light surface == warm default");
/* ---- T2 注入覆写 + 恢复内建 ---- */
printf("T2 inject override + restore\n");
meow_theme custom; memset(&custom, 0, sizeof custom);
custom.surface = 0x112233; custom.primary = 0xABCDEF; custom.onSurface = 0x0F0F0F;
custom.radius = 99; custom.radius_card = 100;
meow_theme_inject(&custom);
const meow_theme *ti = meow_theme_get();
meow_theme ei; meow_theme_export(&ei);
CHECK(ti->primary == 0xABCDEF && ti->surface == 0x112233 && ti->radius == 99,
"inject -> get() reads injected palette");
CHECK(ei.primary == 0xABCDEF && ei.surface == 0x112233, "inject -> export reads injected palette");
/* meow_theme_export == meow_theme_get even when injected(单一权威) */
CHECK(ei.onSurface == ti->onSurface && ei.radius_card == ti->radius_card,
"export == get while injected");
/* 注入恢复内建 */
meow_theme_inject(NULL);
const meow_theme *tr = meow_theme_get();
CHECK(tr->primary == 0xF57200 && tr->surface == 0xF7F3EE,
"inject(NULL) restores builtin (MIUIx light)");
/* ---- T3 launcher 薄壳映射契约(9 角色字段) ---- */
printf("T3 shell mapping contract\n");
meow_theme_export(&e1);
shell_theme sh = export_shell(&e1);
CHECK(sh.surface == e1.surface, "shell.surface == surface");
CHECK(sh.surface_variant == e1.surfaceVariant, "shell.surface_variant == surfaceVariant");
CHECK(sh.surface_container == e1.surfaceContainer, "shell.surface_container == surfaceContainer");
CHECK(sh.primary == e1.primary, "shell.primary == primary");
CHECK(sh.on_surface == e1.onSurface, "shell.on_surface == onSurface");
CHECK(sh.on_surface_variant == e1.onSurfaceVariant, "shell.on_surface_variant == onSurfaceVariant");
CHECK(sh.outline == e1.outline, "shell.outline == outline");
CHECK(sh.error == e1.error, "shell.error == error");
CHECK(sh.surface_tint == e1.surfaceTint, "shell.surface_tint == surfaceTint");
/* 关键角色字段值与 MIUIx light 内建一致(证明读的是 SDK 单一权威,而非 launcher 自持 4 套) */
CHECK(sh.surface == 0xF7F3EE && sh.primary == 0xF57200 && sh.error == 0xB3261E,
"shell roles match SDK builtin (single authority)");
meow_ui_shutdown();
printf(g_fail ? "\nRESULT: %d FAIL(S)\n" : "\nRESULT: ALL PASS\n", g_fail);
return g_fail;
}