Files
zerorigin 0b8b9b0775 迁移到 mygo 单进程架构并接入签名自更新
- 单进程:托盘常驻 + 原生设置窗口(internal/settings),移除 Wails 前端与 IPC
- 触发器(鼠标角落 / 边缘滚轮 / 热键)+ 规则引擎 + 动作注册表
- 调节提示条:截屏 + glass.Blur 三层毛玻璃、背景跟随屏幕变化、悬停光感与拖动
- 音量 Core Audio COM、亮度 DDC/CI(gamma 兜底)、多显示器求平均
- 配置热重载 + 版本迁移 v1→v5、便携模式、崩溃取证三件套
- updater/native 插件 + 托盘「检查更新…」,watchdog 识别更新重启
- 自建 Gitea 发布:scripts/publish-gitea.ps1(updates.url 指向 latest Release)
2026-11-16 10:31:44 +08:00

99 lines
2.6 KiB
Go
Raw Permalink 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.
package action
import "testing"
// TestVolumeMethodSelection 验证 method 参数归一化与校验:
// 默认("")→ media;hotkey 为 media 别名;com 保留为精确选项。
func TestVolumeMethodSelection(t *testing.T) {
cases := []struct {
in string
want string
}{
{"", "media"},
{"media", "media"},
{"hotkey", "media"},
{"com", "com"},
{"bogus", "media"}, // Validate 拦截前的兜底
}
for _, c := range cases {
if got := volumeMethod(c.in); got != c.want {
t.Errorf("volumeMethod(%q) = %q, want %q", c.in, got, c.want)
}
}
for _, id := range []string{"volume_up", "volume_down", "toggle_mute"} {
a, err := New(id)
if err != nil {
t.Fatalf("New(%q): %v", id, err)
}
for _, m := range []string{"", "media", "com", "hotkey"} {
if err := a.Validate(map[string]any{"method": m}); err != nil {
t.Errorf("%s method %q should pass: %v", id, m, err)
}
}
if err := a.Validate(map[string]any{"method": "cli"}); err == nil {
t.Errorf("%s invalid method should fail", id)
}
}
}
// TestVolumeUseCOM 验证奇数步进自动改用 COM,偶数步进仍走媒体键。
func TestVolumeUseCOM(t *testing.T) {
cases := []struct {
method string
steps int
want bool
}{
{"media", 1, true},
{"media", 3, true},
{"media", 5, true},
{"media", 2, false},
{"media", 4, false},
{"com", 1, true},
{"com", 2, true},
}
for _, c := range cases {
if got := volumeUseCOM(c.method, c.steps); got != c.want {
t.Errorf("volumeUseCOM(%q, %d) = %v, want %v", c.method, c.steps, got, c.want)
}
}
}
// TestMediaPressCount 验证百分比到媒体键次数的换算(每步约 2%,至少 1 次)。
func TestMediaPressCount(t *testing.T) {
cases := []struct {
delta int32
want int
}{
{4, 2},
{1, 1},
{2, 1},
{3, 2},
{10, 5},
{-4, 2},
{-7, 4},
{0, 1}, // 最小一次按键(Execute 里 steps<=0 会先归一化为 1)
}
for _, c := range cases {
if got := mediaPressCount(c.delta); got != c.want {
t.Errorf("mediaPressCount(%d) = %d, want %d", c.delta, got, c.want)
}
}
}
// TestVolumeSchemaDefaultMedia 回归:schema 默认值必须为 media(方案A的落点)。
func TestVolumeSchemaDefaultMedia(t *testing.T) {
up, _ := New("volume_up")
for _, p := range up.Schema().Params {
if p.Name == "method" && p.Default != "media" {
t.Errorf("volume_up method default = %v, want media", p.Default)
}
}
mu, _ := New("toggle_mute")
for _, p := range mu.Schema().Params {
if p.Name == "method" && p.Default != "media" {
t.Errorf("toggle_mute method default = %v, want media", p.Default)
}
}
}