/* test_meow_repaint.c — M40 F5:解锁后「强制 App 整帧重画」请求文件的写/读/删除语义。 * * 编译(patch_v2/sdk 下): * gcc -Wall -Wextra -I. test_meow_repaint.c -o test_meow_repaint * 运行:./test_meow_repaint (exit 0=PASS) * * 语义:launcher 写文件 → SDK present 调 meow_ui_repaint_requested() 读到即删并返回 1 * (dirty_full 一次);文件不存在返回 0。路径可用 MEOW_APP_REPAINT_FILE 覆盖(测试隔离)。 */ #include #include #include #include #include #include "meow_ui_repaint.h" static int g_fail = 0; static void check(const char *name, int ok) { if (ok) { printf("ok %s\n", name); } else { printf("FAIL %s\n", name); g_fail = 1; } } static int write_file(const char *path) { int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (fd < 0) return -1; if (write(fd, "1", 1) != 1) { close(fd); return -1; } close(fd); return 0; } int main(void) { const char *tmp = getenv("TMPDIR"); char path[512]; snprintf(path, sizeof path, "%s/m40_repaint_XXXXXX", (tmp && tmp[0]) ? tmp : "/tmp"); int fd = mkstemp(path); if (fd < 0) { perror("mkstemp"); return 2; } close(fd); unlink(path); /* 先清空,测试从「无请求」开始 */ setenv("MEOW_APP_REPAINT_FILE", path, 1); check("path follows env", !strcmp(meow_ui_repaint_path(), path)); check("no request file -> 0", meow_ui_repaint_requested() == 0); check("write request", write_file(path) == 0); check("request present", access(path, F_OK) == 0); check("first check consumes -> 1", meow_ui_repaint_requested() == 1); check("file deleted after consume", access(path, F_OK) != 0); check("second check -> 0 (one-shot)", meow_ui_repaint_requested() == 0); /* 再写一次仍能消费(launcher 每次解锁/菜单关闭都会写) */ check("write again", write_file(path) == 0); check("consume again -> 1", meow_ui_repaint_requested() == 1); unlink(path); printf("\n%s\n", g_fail ? "SOME TESTS FAILED" : "ALL PASS"); return g_fail ? 1 : 0; }