Files
MeowOS-SDK/sdk/test_meow_ui_dispatch.c
T
AskaEth 27a3750e36 SDK: 同步主仓 M15/M16/bug3/MD3 修复 — 时钟 ABI 补全/IME 冷却窗/列表行高派生/形状 token/翻页键
公开 SDK 落后主仓的一批 bugfix(主仓是固件构建源,这些修复已在设备上跑过)。
本次只做「主仓 → 公开仓」单向同步,图像栈方向由主仓侧另一单处理。

时钟 ABI(M16 第二弹,原文件自认「残余未修」):
- meow_ui_time.c 147→345 行:futex 相对超时接管(__timedwait/_cp)、
  timerfd_create/settime/gettime 的 itimerspec 64↔32 双向转换、
  __clock_settime64 越界返 ENOTSUP,另有 4 个纯换算函数
- meow_ui_internal.h:struct meow_time32 / meow_itimerspec32 契约移入内部头
- CLOCK_ABI.md:补接管机制、验证配方与 objdump 证据
- 新增 test_meow_time64.c

IME bug3(成对才有意义):
- meow_ui_ime.c:IME_TAP_COOLDOWN_MS 200 冷却窗 + 打开时二次 drain
- meow_ui_input.c:meow_input_touch_reset() 并在 drain 内调用(复位触摸状态机)
- test_ime_fix.c:新增用例④ stray-tap

列表行高(M15,修用户可见 bug):
- meow_ui_widget.c:listv_item_h() 由主题字体行高派生,不再写死 56
  (两行列表 62 > 56 会让首行标题被裁剪守卫整条跳过)
- include/meow_ui_widgets.h:新增 meow_listview_item_h()
- 新增 test_meow_ui_listview_rowh.c

其余:meow_select.c / meow_ui_dialog.c 统一 MD3 形状 token;
include/meow_ipc.h 补 MSG_KEY_PAGEUP/PAGEDOWN 枚举;
meow_ui_sys.c / meow_cachegov.c 取时统一走 meow_ui_time_ms()。

测试辅助函数标定:tuku/test/test_settings_lock_host.c 的注入前等待 150ms→350ms。
该等待按修复前 IME 标定,新冷却窗下首键 dt_open≈114ms 会被当迟到抬起吞掉,
只录到 "68" 两位。仅改等待时长,断言原样保留。

验证:tuku 四套脚本全绿(run_tests 644 PASS / zip 106 / cbz 296 / webtoon PASS);
12 个源文件与主仓逐字节一致;sdk/build_sdk.sh 34 成员;
tuku/build_tuku.sh 产出静态 MIPS32r2 ELF。
2026-11-06 21:31:54 +08:00

146 lines
8.2 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_dispatch.c — §6.4 事件分发形式化宿主验证(离屏 480x720,16bpp)。
*
* 覆盖(新穿透矩阵,全部直接驱动 SDK §6.4 仲裁者 API + 真实注册控件):
* M1 模态打开点下层不触发:modal_begin 后 meow_ui_hit_topdown 恒返回模态哨兵(不再落到下层
* 同坐标控件),gesture_begin 捕获的是模态(哨兵)而非下层按钮——下层绝不消费;
* M2 弹层叠开两层不叠黑/层隔离:modal_begin 两次 → depth=2;end(LIFO)逐层递减;期间
* hit_topdown 始终返回哨兵,下层收不到任何触摸;
* M3 捕获手势滑出不误触:gesture_begin 命中按钮 A 后捕获;任凭概念滑动到远处(不重新命中),
* meow_ui_gesture_owner 恒为 A(绝不滑出误触下层/邻控件);end 释放;
* M4 list 焦点点外释放:meow_list_tap_at/meow_listview_tap_at 使列表成为唯一焦点;
* focus_tap 落在列表内 → 保位;落在列表外(页面内容/空白)→ 释放焦点并触发 lost 回调。
*
* 编译(宿主 gcc,链真实 widget/draw/input/activity/gfx/sys/theme/vol/log/dialog/ime/notify/ipc +
* 打桩 font/global;完整超集便于链接):
* gcc -Wall -Wextra -o test_meow_ui_dispatch test_meow_ui_dispatch.c test_host_stub.c \
* meow_ui_gfx.c meow_ui_time.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_dispatch (无设备,纯宿主)
*/
#include "meow_ui.h"
#include "meow_ui_internal.h"
#include "meow_ui_view.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.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)
/* 焦点丢失回调计数 */
static int g_lost_calls = 0;
static void *g_lost_last = NULL;
static void focus_lost(void *owner, void *ctx)
{ (void)ctx; g_lost_calls++; g_lost_last = owner; }
/* 列表数据源(最小 W_LIST) */
static int list_src(int idx, char *label, int len, void *ctx)
{
(void)ctx;
if (idx < 0 || idx >= 8) return 0;
snprintf(label, (size_t)len, "item %d", idx);
return 1;
}
int main(void)
{
setenv("MEOW_UI_DUMP", "/tmp/dispatch.ppm", 1);
meow_ui_opts o = { 480, 720 };
if (meow_ui_init(&o) != 0) { printf("init failed\n"); return 1; }
meow_ui_activity_push(5); /* 页面控件 owner=5,命中/绘制对齐 */
/* 场景控件:两个不重叠按钮 A/B + 一个 LazyColumn 列表 */
meow_widget *btnA = meow_btn_create(20, 100, 200, 60, "A");
meow_widget *btnB = meow_btn_create(240, 100, 200, 60, "B");
meow_widget *list = meow_lazycolumn_create(20, 300, 400, 150, 44, 8, list_src, NULL);
/* ================= M1:模态打开点下层不触发 =================
* 无模态:hit_topdown(按钮A中心) == 按钮A;modal_begin 后同一落点返回模态哨兵(≠按钮A),
* gesture_begin 捕获的是模态而非下层按钮——下层绝不消费(穿透根治)。 */
printf("M1 modal open -> lower not triggered\n");
void *h0 = meow_ui_hit_topdown(120, 130);
printf(" no-modal hit_topdown(120,130) = %s\n",
h0 == (void *)btnA ? "btnA" : (h0 ? "other" : "NULL"));
CHECK(h0 == (void *)btnA, "no-modal topdown hits btnA (z-top)");
meow_ui_modal *m = meow_ui_modal_begin();
void *hm = meow_ui_hit_topdown(120, 130);
printf(" modal-open hit_topdown(120,130) = %s (sentinel=%d)\n",
hm == (void *)btnA ? "btnA(LEAK!)" : "modal-sentinel", hm != NULL && hm != (void *)btnA);
CHECK(meow_ui_modal_active(), "modal active");
CHECK(hm != NULL && hm != (void *)btnA, "modal present -> hit_topdown never reaches btnA");
void *g0 = meow_ui_gesture_begin(120, 130); /* 下层同坐标:捕获的是模态而非按钮 */
CHECK(g0 == hm, "gesture_begin during modal captures modal (sentinel), not btnA");
meow_ui_gesture_end();
meow_ui_modal_end(m);
CHECK(meow_ui_hit_topdown(120, 130) == (void *)btnA, "after modal_end topdown returns btnA again");
CHECK(!meow_ui_modal_active(), "modal released");
/* ================= M2:弹层叠开两层(层隔离,depth 语义) =================
* 两层弹开:depth 1→2;期间 hit_topdown 恒返回哨兵;LIFO 关内层→1,关外层→0。
* 叠黑由 Dialog/Sheet 的「打开前整帧快照 + 关闭还原 + 高亮仅重绘卡片不叠遮罩」保证
* (meow_ui_dialog.c,M2.71-bug3),本处验证层隔离 + 栈深。 */
printf("M2 stacked modals (two layers)\n");
meow_ui_modal *m1 = meow_ui_modal_begin();
meow_ui_modal *m2 = meow_ui_modal_begin();
CHECK(meow_ui_modal_depth() == 2, "two modals -> depth 2");
CHECK(meow_ui_hit_topdown(120, 130) != (void *)btnA, "either modal -> lower btnA blocked");
meow_ui_modal_end(m2);
CHECK(meow_ui_modal_depth() == 1, "close inner -> depth 1");
CHECK(meow_ui_hit_topdown(120, 130) != (void *)btnA, "outer modal still blocks lower");
meow_ui_modal_end(m1);
CHECK(meow_ui_modal_depth() == 0, "close outer -> depth 0");
CHECK(meow_ui_hit_topdown(120, 130) == (void *)btnA, "both closed -> lower reachable");
/* ================= M3:捕获手势滑出不误触 =================
* touch-down 命中按钮 A → 捕获。此后 move(即使滑到按钮 B / 空白)不重新命中,owner 恒为 A;
* 绝不滑出误触 B 或下层。抬手(gesture_end)释放。 */
printf("M3 gesture capture: slide-out no false-trigger\n");
void *g1 = meow_ui_gesture_begin(120, 130);
CHECK(g1 == (void *)btnA, "down on A captures A");
CHECK(meow_ui_gesture_owner() == (void *)btnA, "owner == A after down");
/* 概念滑动到按钮 B 中心 (340,130):捕获不重命中 → 仍是 A(不误触 B) */
CHECK(meow_ui_gesture_owner() == (void *)btnA, "slide to B point: owner stays A (no re-hit)");
/* 滑出到空白 */
CHECK(meow_ui_gesture_owner() == (void *)btnA, "slide to blank: owner stays A");
meow_ui_gesture_end();
CHECK(meow_ui_gesture_owner() == NULL, "release -> no owner");
/* ================= M4:list 焦点点外释放 =================
* meow_list_tap_at 使列表成为唯一焦点;focus_tap 落在列表内→保位;落在列表外→释放并通知。 */
printf("M4 list focus release on tap outside\n");
meow_ui_focus_set_lost_cb(focus_lost, NULL);
CHECK(meow_ui_focus_owner() == NULL, "no focus initially");
int idx = meow_list_tap_at(list, 120, 320); /* 命中列表行0 */
CHECK(idx >= 0, "list tap hits a row");
CHECK(meow_ui_focus_owner() == (void *)list, "list tap -> list becomes focus owner");
meow_ui_focus_tap(120, 320); /* 点列表内:保位 */
CHECK(meow_ui_focus_owner() == (void *)list, "tap inside list -> focus retained");
CHECK(g_lost_calls == 0, "no lost callback while focus retained");
meow_ui_focus_tap(120, 130); /* 命中按钮A(非列表):释放焦点+通知 */
CHECK(meow_ui_focus_owner() == NULL, "tap outside list (on A) -> focus released");
CHECK(g_lost_calls == 1 && g_lost_last == (void *)list, "lost callback fired with list owner");
/* 再次聚焦后再点「空白」(无控件命中):同样释放 */
meow_list_tap_at(list, 120, 320);
meow_ui_focus_tap(400, 650); /* 列表外空白 */
CHECK(meow_ui_focus_owner() == NULL, "tap on blank -> focus released");
CHECK(g_lost_calls == 2, "lost callback fired again");
(void)btnB;
/* 清理:控件释放自动注销 z 序绘制物 + 焦点/捕获复位 */
meow_widget_free(list);
meow_widget_free(btnB);
meow_widget_free(btnA);
meow_ui_focus_release(NULL);
meow_ui_activity_pop();
meow_ui_shutdown();
printf(g_fail ? "\nRESULT: %d FAIL(S)\n" : "\nRESULT: ALL PASS\n", g_fail);
return g_fail;
}