Repository navigation
Expand file tree
/
Copy pathtests.cs
More file actions
35 lines (28 loc) · 1.95 KB
/
Copy pathtests.cs
File metadata and controls
35 lines (28 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Run with test.cmd. Covers the logic that doesn't need a real monitor.
using System;
using System.Windows.Forms;
public static class Tests {
static void Check(bool ok, string name) {
Console.WriteLine((ok ? "ok " : "FAIL ") + name);
if (!ok) Environment.Exit(1);
}
static void Main() {
var normal = new Mode(1920, 1080, 165);
var stretched = new Mode(1720, 1080, 165);
Check(Mode.Next(normal, normal, stretched) == stretched, "normal goes to stretched");
Check(Mode.Next(stretched, normal, stretched) == normal, "stretched goes to normal");
Check(Mode.Next(new Mode(1280, 720, 60), normal, stretched) == stretched, "unknown resolution goes to stretched");
Check(Mode.Next(new Mode(1720, 1080, 60), normal, stretched) == normal, "stretched size at another refresh rate counts as stretched");
Check(Mode.Parse("1720x1080@165").Key == "1720x1080@165", "mode survives a round trip");
foreach (var bad in new[] { null, "", "abc", "1720x1080", "0x0@0", "-1x1080@60", "1x2@3@4" })
Check(Mode.Parse(bad) == null, "rejects mode '" + bad + "'");
Check(Hotkey.Text(Hotkey.CTRL | Hotkey.ALT, Keys.F11) == "Ctrl + Alt + F11", "hotkey text");
Check(Hotkey.Mods(true, false, true) == (Hotkey.CTRL | Hotkey.SHIFT), "hotkey modifiers");
var s = new Settings { Device = @"\\.\DISPLAY2", Normal = normal, Stretched = stretched, Mods = Hotkey.SHIFT, Key = Keys.F5 };
var r = Settings.FromLines(s.ToLines());
Check(r.Device == s.Device && r.Normal.Key == normal.Key && r.Stretched.Key == stretched.Key && r.Mods == s.Mods && r.Key == s.Key, "settings survive a round trip");
var d = Settings.FromLines(new[] { "garbage", "=x", "normal=nope", "mods=abc", "key=-5" });
Check(d.Normal == null && d.Mods == (Hotkey.CTRL | Hotkey.ALT) && d.Key == Keys.F11, "corrupt settings fall back to defaults");
Console.WriteLine("all passed");
}
}