# -*- coding: utf-8 -*- """断言安卓端这次改造到位了。 用户要求: 1. 中转设置下面,删掉「设备诊断」,换成「输入配对码连接」 2. 局域网那套东西(搜索/手动填 IP)都删掉 3. 图标换成作者给的图 这个测试是源码级 + 产物级断言。 配合 verify_all 里的"手表 App 整体编译", 能挡住"删代码删坏了字段"这类事故。 """ from __future__ import annotations import re import sys import zipfile from pathlib import Path ROOT = Path(__file__).resolve().parent.parent WATCH = ROOT / "android" / "src" / "com" / "lanremote" / "watch" MAIN = WATCH / "MainActivity.java" passed = 0 failed = 0 def check(name, ok, detail=""): global passed, failed if ok: passed += 1 print(" [PASS] " + name) else: failed += 1 print(" [FAIL] " + name + " " + str(detail)) def main() -> int: src = MAIN.read_text(encoding="utf-8") # 去掉注释再查(注释里会提到这些名字) code = re.sub(r"//[^\n]*", "", src) code = re.sub(r"/\*.*?\*/", "", code, flags=re.S) print("一、设备诊断已移除") check("没有 openDiagPanel 的定义", "private void openDiagPanel" not in code) check("没有 openDiagPanel 的调用", "openDiagPanel(" not in code) check("首页没有「设备诊断」按钮", 'bigButton("连不上?点这里诊断"' not in code) check("没有「点这里诊断」字样", "点这里诊断" not in code) print() print("二、局域网入口按新设计存在(但不再是旧交互)") # 注意:早期这里断言的是"局域网那套已清掉", # 那是用户要求删除时的版本。后来用户又要求把局域网连接加回来 # (首页 -> 局域网连接页面 -> 搜索/直连),所以这些断言反过来了。 check("首页有局域网入口", 'bigButton("局域网连接(同一个 WiFi)"' in code) check("有独立的局域网页面", "private void buildLanPanel()" in code) check("页面里能广播搜索", "Discovery.search(" in code) check("用 DiscoveryCore 的结果类型", "DiscoveryCore.Found" in code) # 局域网页面里**本来就该有**搜索按钮,所以不能断言"全代码没有"。 # (我一开始就是这么写错的。) check("局域网页面里有搜索按钮", 'bigButton("自动搜索电脑"' in code) # 旧交互确实不该再有:手动输入地址那一套 check("没有旧的手动输入地址按钮", 'bigButton("手动输入地址"' not in code) check("没有 toggleManual(旧交互)", "toggleManual" not in code) check("首页没有裸的 hostInput", "hostInput" not in code) print() print("三、换成了「输入配对码连接」") check("有按钮", 'bigButton("输入配对码连接"' in code) check("有 promptPairingCode 定义", "private void promptPairingCode()" in code) check("有 connectByCode 定义", "private void connectByCode(" in code) check("点按钮会开输入框", "promptPairingCode();" in code) check("校验必须是 6 位数字", "\\\\d{6}" in code or "\\d{6}" in code) check("没填中转地址时会引导去设置", "请先在「中转设置」里填服务器地址" in code) print() print("四、关键字段还在(防删代码时误伤)") for field in ("busy", "mirrorStreaming", "incoming", "incomingName", "gridColumns", "cellHeightDp", "cellTextSp", "cellQueue", "logBuffer", "frameCount", "currentFps", "fpsWindowStart"): declared = bool(re.search( r"(private|volatile|final)[^;\n]*\b" + field + r"\b\s*(=|;|,)", code)) check(f"字段 {field} 有声明", declared) print() print("五、图标换成了作者给的图") ico = ROOT / "windows" / "app.ico" check("windows/app.ico 存在", ico.is_file()) if ico.is_file(): # 旧图标是 12KB 左右(自己画的),新图标带照片会大很多 check("图标是新的(不是原来那个自绘的)", ico.stat().st_size > 50000, f"{ico.stat().st_size} 字节") for folder in ("drawable-mdpi", "drawable-hdpi", "drawable-xhdpi", "drawable-xxhdpi", "drawable-xxxhdpi"): path = ROOT / "android" / "res" / folder / "ic_launcher.png" check(f"安卓图标 {folder} 存在", path.is_file()) old_xml = ROOT / "android" / "res" / "drawable" / "ic_launcher.xml" check("旧的矢量图标已删除", not old_xml.is_file()) print() print("六、APK 里带上了新图标") apks = sorted((ROOT / "dist").glob("*watch*.apk"), key=lambda p: p.stat().st_mtime, reverse=True) if apks: with zipfile.ZipFile(apks[0]) as archive: names = archive.namelist() icons = [n for n in names if "ic_launcher" in n] check(f"APK 里有图标资源({len(icons)} 个)", bool(icons), names[:6]) else: check("找到 APK", False, "dist 里没有 watch apk") print() print("=" * 62) print(f"通过 {passed} 项,失败 {failed} 项") return 0 if failed == 0 else 1 if __name__ == "__main__": raise SystemExit(main())