Files
MeowOS-SDK/sdk/test_pinyin.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

126 lines
5.5 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_pinyin.c — 中文拼音 IME 宿主验证(480x720 离屏,直接 handle_tap 确定语义)。
* ① 拼音组合:type "nihao" → 组合串="nihao"、字段=""(组合不上屏、on_change 不触发);
* 点候选(你好)→ 字段="你好"、组合清空、on_change="你好";
* ② 候选翻页:type "shi" → nc>6;点 ▶ 翻页末首候选变化、点 ◀ 回;
* ③ UTF-8 删字段:上屏"你好"后点退格 → 字段="你"(按 codepoint 回退,不出现乱码);
* ④ 中/英切换:拼音点 [拼/英] → ASCII;ASCII 点顶条「中」热区 → 拼音;
* ⑤ 空格/回车上屏首候选:type "ni" + 空格 → 字段="你"。
*
* 编译(宿主 gcc,同 test_ime_fix):
* gcc -Wall -Wextra -o test_pinyin test_pinyin.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_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
*/
#include "meow_ui.h"
#include "meow_ui_internal.h"
#include "meow_pinyin.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
/* 拼音键位(build_kb PINYIN:行 y=504/552/600/648,GCOL=48,行左缘 x=2;键 44×36):
* row1 y=504 "qwertyuiop";row2 y=552 "asdfghjkl"+[拼/英]@col9;
* row3 y=600 "zxcvbnm"+[←退格]@col7;row4 y=648 [?123]+[空格]+[OK]。 */
#define KEY_XY(col, y) (((2 + (col) * 48) + 22), ((y) + 18))
static void t(char ch) {
/* 按字符找其键中心坐标(行/列换算) */
int row = 0, col = 0;
const char *rows[3] = { "qwertyuiop", "asdfghjkl", "zxcvbnm" };
for (int r = 0; r < 3; r++) {
const char *p = strchr(rows[r], ch);
if (p) { row = r; col = (int)(p - rows[r]); break; }
}
int x = 2 + col * 48 + 22;
int y = 504 + row * 48 + 18;
meow_ime_handle_tap(x, y);
}
static char g_echo[128] = "";
static void ime_cb(const char *t, void *ctx) { (void)ctx; snprintf(g_echo, sizeof g_echo, "%s", t); }
static void tap(int x, int y) { meow_ime_handle_tap(x, y); }
static meow_ime_ctx g_c;
static void open_py(void) {
memset(&g_c, 0, sizeof g_c);
g_c.mode = MEOW_IME_PINYIN; g_c.maxlen = 64; g_c.on_change = ime_cb;
memset(g_echo, 0, sizeof g_echo);
meow_ui_text_input_async(&g_c);
assert(meow_ime_active() == 1);
}
static void close_py(void) { meow_ime_close(0); assert(meow_ime_active() == 0); }
int main(void) {
setenv("MEOW_UI_DUMP", "/tmp/pinyin.ppm", 1);
meow_ui_opts o = { 480, 720 };
assert(meow_ui_init(&o) == 0);
/* ① 拼音组合 + 点上屏 */
open_py();
t('n'); t('i'); t('h'); t('a'); t('o');
assert(strcmp(meow_ime_composition(), "nihao") == 0);
assert(meow_ime_text()[0] == 0); /* 组合不上屏 */
assert(g_echo[0] == 0); /* 未上屏不回调 */
/* 点候选 0(你好,x=44 起;宿主 stub width=strlen*6) */
tap(60, 480);
assert(strcmp(meow_ime_text(), "你好") == 0);
assert(strcmp(g_echo, "你好") == 0);
assert(meow_ime_composition()[0] == 0); /* 组合已清 */
close_py();
printf("PASS pinyin: nihao -> 你好 (compose+commit+on_change)\n"); fflush(stdout);
/* ② 候选翻页(shi 候选 >6) */
open_py();
t('s'); t('h'); t('i');
char all[32][64];
int n = py_predict("shi", all, 32);
assert(n > 6);
assert(strcmp(all[0], "是") == 0);
/* 点 ▶(下一页)→ 页内首候选应为 all[6](页 0 首候选是 all[0]) */
tap(457, 480); /* ▶:页 0 → 页 1 */
tap(60, 480); /* 点页 1 候选 0(x=44 起) */
assert(strcmp(meow_ime_text(), all[6]) == 0);
close_py();
printf("PASS pagination: shi page_next then commit page1[0] == all[6]\n"); fflush(stdout);
/* ③ UTF-8 删字段:上屏"你好"后点退格 → "你" */
open_py();
t('n'); t('i'); t('h'); t('a'); t('o');
tap(60, 480); /* 上屏"你好" */
assert(strcmp(meow_ime_text(), "你好") == 0);
tap(410, 618); /* ←退格(row3 col7 宽键中心) */
assert(strcmp(meow_ime_text(), "你") == 0);
assert(strcmp(g_echo, "你") == 0);
close_py();
printf("PASS utf8 field backspace: 你好 -> 你\n"); fflush(stdout);
/* ④ 中/英切换 */
open_py();
tap(456, 570); /* [拼/英] row2 col9 → ASCII */
assert(meow_ime_active() == 1);
/* 顶条「中」热区(430..474, KB_TOP..KB_TOP+42)→ 切回拼音;组合已被丢弃 */
tap(452, 438);
assert(meow_ime_active() == 1);
t('n'); t('i');
assert(strcmp(meow_ime_composition(), "ni") == 0);
tap(456, 570); /* 又回 ASCII */
assert(strcmp(meow_ime_composition(), "") == 0); /* 组合态已丢弃 */
close_py();
printf("PASS zh/en switch (pinyin->ascii->pinyin, combo dropped)\n"); fflush(stdout);
/* ⑤ 空格上屏首候选(ni → 你) */
open_py();
t('n'); t('i');
tap(194, 666); /* 空格 */
assert(strcmp(meow_ime_text(), "你") == 0);
assert(strcmp(g_echo, "你") == 0);
close_py();
printf("PASS space commits first candidate: ni -> 你\n"); fflush(stdout);
printf("ALL PASS\n");
meow_ui_shutdown();
return 0;
}