Files
MeowOS-For-R3P2/patch_v2/sdk/test_meow_ui_swipe.c
T
AskaEth 38be5e78bc fix(sdk): 时钟 ABI 根因修复 — meow_ui_time 按 o32 time32 取时并链接期接管
真机 meow_ui_time_ms() 返回「低 32=秒×1000、高 32 随机」的根因不是 SDK 写法,
而是 zig 0.17 自带 musl 在 mipsel 上的 time64 ABI 自相矛盾:
- zig 头(mips-linux-musl/bits/alltypes.h)无条件 64 位 time_t、struct timespec 16 字节;
- zig 的 clang 给 32 位 mips 预定义 __ILP32__,musl 的 time64 回退分支
  `#if defined(SYS_x_time64) && !defined(__ILP32__)`(本意只排除 x32)被编译掉;
- 于是 libc 的 __clock_gettime64 实为 o32 time32 实现(SYS_clock_gettime 4263),
  只写 8 字节 {int32 sec; int32 nsec},与头的 16 字节布局错配。

修复(patch_v2/sdk/meow_ui_time.c):
- meow_ui_time_ms() 直接按内核 o32 ABI 取 8 字节 time32,再升 64 位毫秒;
- 同 TU 强定义 __clock_gettime/__clock_gettime64(归档先于 -lc,链接期接管,
  time()/gettimeofday()/pthread 定时等待的内部取时随之修正);
- 同源缺陷一并修:__nanosleep_time64/__clock_nanosleep(_time64) 转换 time32 后重发
  (修复前 usleep(16000) 等亚秒睡眠立即返回、变忙等空转);
- gfx/sys/input/cachegov 四处重复 now_ms 收敛到 meow_ui_time_ms;
- build_sdk.sh OBJS 增加 meow_ui_time;新增 test_meow_time 宿主单测、
  tools/clock_abi_probe.c 探针、CLOCK_ABI.md 根因/验证/影响面文档;
- 26 个宿主测试的编译注释补 meow_ui_time.c(cachegov 测试补时钟源)。

验证:宿主单测 PASS;anim(32)/view_event 宿主用例全过;build_sdk_host.sh --verify
76 成员全 MIPS32r2、0 warning;探针链接后无 libc cgt_init/__vdsosym,
__time64/__timedwait_cp 的取时指向本 TU,睡眠走 4166/4265 且用本地 8 字节结构。
2026-11-05 13:41:52 +08:00

211 lines
9.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_swipe.c — 宿主验证列表行左滑删除(§5.5,M7.3 缺口 #9):
* T1 滑动手势判定与冲突消解:begin 命中可滑行返回 1;横向小位移 = swipe(move 返回 1 消费);
* 纵向大位移 = 滚动手势优先(move 返回 0 并取消本行 swipe);非启用行 begin 返回 0。
* T2 左滑超阈值 → 删除动画(meow_anim 滑出),结束后 on_delete 回调恰一次 + swipe 状态复位。
* T3 未超阈值 → 回弹,on_delete 不触发,swipe_dx 回到 0。
* T4 点按(无位移):begin 后 end(未 started)返回 0(App 走 tap_at),不触发 on_delete。
* T5 右露删除区像素:滑动中重绘列表 → 右露区画主题 error 底 + 行内容左移。
*
* 编译(宿主 gcc):
* gcc -o test_meow_ui_swipe test_meow_ui_swipe.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 \
* -I. -I../meow_launcherd -DMEOW_UI_HOST_TEST -pthread -lm
* 运行:./test_meow_ui_swipe
*/
#include "meow_ui.h"
#include "meow_ui_internal.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static int g_pass = 0, g_fail = 0;
#define CHECK(cond, ...) do { \
if (cond) { g_pass++; } \
else { g_fail++; printf("FAIL %s:%d ", __FILE__, __LINE__); printf(__VA_ARGS__); printf("\n"); } \
} while (0)
static void rd_px(int x, int y, int *r, int *g, int *b)
{
unsigned char *bb = meow_ui_back_buf();
int line = meow_ui_back_buf_pitch(), bpp = meow_ui_back_buf_bpp();
if (!bb || x < 0 || y < 0) { *r = *g = *b = 0; return; }
if (bpp == 16) {
uint16_t px = *(uint16_t *)(bb + (size_t)y * line + (size_t)x * 2);
*r = (((px >> 11) & 0x1F) << 3) | ((px >> 11) & 0x1F) >> 2;
*g = (((px >> 5) & 0x3F) << 2) | ((px >> 5) & 0x3F) >> 4;
*b = ((px & 0x1F) << 3) | ((px & 0x1F) >> 2);
} else {
uint32_t px = *(uint32_t *)(bb + (size_t)y * line + (size_t)x * 4);
*r = (px >> 16) & 0xFF; *g = (px >> 8) & 0xFF; *b = px & 0xFF;
}
}
static int near2(int a, int b) { int d = a - b; if (d < 0) d = -d; return d <= 14; }
static int px_near(int x, int y, int r, int g, int b)
{
int rr, gg, bb; rd_px(x, y, &rr, &gg, &bb);
return near2(rr, r) && near2(gg, g) && near2(bb, b);
}
static int region_has(int x, int y, int w, int h, int r, int g, int b)
{
int cnt = 0;
for (int dy = 0; dy < h; dy++)
for (int dx = 0; dx < w; dx++)
if (px_near(x + dx, y + dy, r, g, b)) cnt++;
return cnt;
}
#define UNPK(c, rr, gg, bb) do { (rr) = ((c) >> 16) & 0xFF; (gg) = ((c) >> 8) & 0xFF; (bb) = (c) & 0xFF; } while (0)
#define LVX 20
#define LVY 50
#define LVW 440
#define LVH 300
#define ITEM 56
#define CNT 10
static int del_count; /* on_delete 回调次数 */
static int del_idx; /* 最后一次删除 idx */
static void on_delete(int idx, void *ctx) { (void)ctx; del_count++; del_idx = idx; }
static int scount(void *ctx) { (void)ctx; return CNT; }
static void sbind(int idx, meow_lv_item *it, void *ctx)
{
(void)ctx;
memset(it, 0, sizeof *it);
static char t[32];
snprintf(t, sizeof t, "notif %d", idx);
it->title = t; it->icon_kind = MEOW_LIST_ICON_NONE; it->right = MEOW_LIST_RIGHT_NONE;
it->enabled = 1;
}
static meow_widget *make_list(void)
{
meow_widget *lv = meow_listview_create(LVX, LVY, LVW, LVH, 0, NULL, NULL, MEOW_LIST_SEL_NONE);
meow_listview_set_item_h(lv, ITEM);
meow_listview_set_vsource(lv, scount, sbind, NULL);
meow_listview_set_item_renderer(lv, 2, 0, 0); /* 双行、无图标、无尾件 */
meow_listview_set_swipe_delete(lv, 1, on_delete, NULL);
return lv;
}
/* 推进 meow_anim 直到 swipe 动画结束(模拟 on_tick 节拍)。 */
static void pump_swipe(meow_widget *lv)
{
int guard = 0;
while (meow_listview_swipe_active(lv) && guard++ < 80) {
meow_anim_tick();
usleep(10000);
}
meow_anim_tick();
}
int main(void)
{
meow_ui_opts o = { 480, 720 };
if (meow_ui_init(&o) != 0) { printf("init failed\n"); return 1; }
const meow_theme *th = meow_theme_get();
int err_r, err_g, err_b; UNPK(th->error, err_r, err_g, err_b);
int row0y = LVY + ITEM / 2; /* 行 0 中心 y(scroll=0) */
/* ============ T1 手势判定 / 冲突消解 ============ */
{
meow_widget *lv = make_list();
/* begin 命中可滑行行 → 1 */
CHECK(meow_listview_swipe_begin(lv, 100, row0y) == 1, "T1 begin on swipe row = 1");
/* 横向小位移 → 裁定 swipe,move 返回 1(消费) */
CHECK(meow_listview_swipe_move(lv, 40, row0y) == 1, "T1 move horizontal = 1 (consumed)");
int dx = meow_listview_swipe_offset(lv);
CHECK(dx == -60, "T1 dx=-60 got %d", dx);
/* 又一小位移(不超容差也不改变方向) */
CHECK(meow_listview_swipe_move(lv, 30, row0y) == 1, "T1 move horizontal 2 = 1");
CHECK(meow_listview_swipe_end(lv, 30, row0y) == 1, "T1 end started swipe = 1 (bounce)");
pump_swipe(lv);
CHECK(meow_listview_swipe_offset(lv) == 0, "T1 bounce back dx=0 got %d", meow_listview_swipe_offset(lv));
CHECK(del_count == 0, "T1 no delete on bounce");
meow_widget_free(lv);
}
{
/* 纵向大位移 → 滚动手势优先(move 返回 0 + 取消) */
meow_widget *lv = make_list();
CHECK(meow_listview_swipe_begin(lv, 100, row0y) == 1, "T1 begin2 = 1");
CHECK(meow_listview_swipe_move(lv, 100, row0y + 80) == 0, "T1 vertical move = 0 (yield to scroll)");
CHECK(meow_listview_swipe_active(lv) == 0, "T1 vertical cancels swipe");
CHECK(meow_listview_swipe_offset(lv) == 0, "T1 vertical dx=0");
meow_widget_free(lv);
}
{
/* 非启用行 begin → 0 */
meow_widget *lv = make_list();
meow_listview_set_swipe_delete(lv, 0, NULL, NULL);
CHECK(meow_listview_swipe_begin(lv, 100, row0y) == 0, "T1 disabled begin = 0");
meow_widget_free(lv);
}
/* ============ T2 超阈值 → 删除动画 + on_delete ============ */
{
del_count = 0; del_idx = -1;
meow_widget *lv = make_list();
CHECK(meow_listview_swipe_begin(lv, 100, row0y) == 1, "T2 begin = 1");
/* 左滑 200px(阈值=LVW*2/5=176)→ 超阈值 */
CHECK(meow_listview_swipe_move(lv, 100 - 200, row0y) == 1, "T2 move big left = 1");
CHECK(meow_listview_swipe_end(lv, 100 - 200, row0y) == 1, "T2 end = 1 (delete anim)");
CHECK(meow_listview_swipe_active(lv) == 1, "T2 delete anim active");
pump_swipe(lv);
CHECK(del_count == 1, "T2 on_delete fired once got %d", del_count);
CHECK(del_idx == 0, "T2 on_delete idx0 got %d", del_idx);
CHECK(meow_listview_swipe_active(lv) == 0, "T2 state reset inactive");
CHECK(meow_listview_swipe_offset(lv) == 0, "T2 dx reset 0 got %d", meow_listview_swipe_offset(lv));
meow_widget_free(lv);
}
/* ============ T3 未超阈值 → 回弹,on_delete 不触发 ============ */
{
del_count = 0;
meow_widget *lv = make_list();
CHECK(meow_listview_swipe_begin(lv, 100, row0y) == 1, "T3 begin = 1");
CHECK(meow_listview_swipe_move(lv, 55, row0y) == 1, "T3 move left 45px = 1");
CHECK(meow_listview_swipe_offset(lv) == -45, "T3 dx=-45 got %d", meow_listview_swipe_offset(lv));
CHECK(meow_listview_swipe_end(lv, 55, row0y) == 1, "T3 end = 1 (bounce anim)");
CHECK(meow_listview_swipe_active(lv) == 1, "T3 bounce active");
pump_swipe(lv);
CHECK(del_count == 0, "T3 on_delete NOT fired got %d", del_count);
CHECK(meow_listview_swipe_offset(lv) == 0, "T3 bounce dx=0 got %d", meow_listview_swipe_offset(lv));
CHECK(meow_listview_swipe_active(lv) == 0, "T3 inactive after bounce");
meow_widget_free(lv);
}
/* ============ T4 点按(无位移)= 行点击,end 返回 0 ============ */
{
del_count = 0;
meow_widget *lv = make_list();
CHECK(meow_listview_swipe_begin(lv, 100, row0y) == 1, "T4 begin = 1");
CHECK(meow_listview_swipe_end(lv, 100, row0y) == 0, "T4 tap end = 0 (let App tap_at)");
CHECK(del_count == 0, "T4 no delete on tap");
CHECK(meow_listview_swipe_active(lv) == 0, "T4 inactive after tap");
meow_widget_free(lv);
}
/* ============ T5 右露删除区像素(默认 renderer) ============ */
{
meow_widget *lv = make_list();
CHECK(meow_listview_swipe_begin(lv, 100, row0y) == 1, "T5 begin = 1");
CHECK(meow_listview_swipe_move(lv, 100 - 200, row0y) == 1, "T5 move big left = 1");
meow_ui_clear(th->bg);
meow_widget_draw(lv);
/* 右露区 [LVX+LVW+dx, row0, -dx, ITEM] = [260,50,200,56] → error 底 */
CHECK(region_has(270, row0y - ITEM / 2 + 4, 180, ITEM - 8, err_r, err_g, err_b) > 50,
"T5 delete reveal error bg got %d", region_has(270, row0y - ITEM / 2 + 4, 180, ITEM - 8, err_r, err_g, err_b));
meow_listview_swipe_end(lv, 100 - 200, row0y);
pump_swipe(lv);
meow_widget_free(lv);
}
meow_ui_shutdown();
printf("swipe: %d pass / %d fail\n", g_pass, g_fail);
return g_fail ? 1 : 0;
}