Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/CargoManifestTests.cpp

Source at documentation-generation time. See Test catalog for fixture associations.

1#include "../Instruments/MFD/CargoManifestList.h"
2#include <cstdlib>
3#include <iostream>
4
5static void Check(bool condition, const char* message)
6{
7 if (!condition) { std::cerr << "FAIL: " << message << '\n'; std::exit(1); }
8}
9
10static void FillMammoth(CargoManifestList& list, int baggage = 1, int cabin = 0)
11{
12 list.rows.clear();
13 list.Add(L"MANIFEST", 0);
14 list.Add(L"-------------", 0);
15 list.Add(L"Empty Weight", 0);
16 list.Add(L"Fuel", 0, "Fuel");
17 list.Add(L"VPT", 0, "Avionics", 6);
18 list.Add(L"40K-SRS", 0);
19 list.Add(L"JVC Radio", 0, "Avionics", 3);
20 for (int i = 0; i < 18; ++i) list.Add(L"Cargo Bay", 0, "Bay", i);
21 list.Add(L"Crew", 0);
22 list.Add(L"Stowage", 0);
23 for (int i = 0; i < baggage; ++i) list.Add(L"Baggage", 0, "Baggage", i);
24 list.Add(L"Cash (CR)", 0);
25 for (int i = 0; i < cabin; ++i) list.Add(L"Cabin", 0, "Cabin", i);
26 list.Add(L"Total Weight", 0);
27 list.UpdateView();
28}
29
30static void CheckWindow(const CargoManifestList& list)
31{
32 Check(list.ScreenRow(0) == 0 && list.ScreenRow(1) == 1, "headings remain pinned");
33 Check(list.ScreenRow(list.selected) >= 0, "selection stays visible");
34 for (int i = 0; i < static_cast<int>(list.rows.size()); ++i)
35 {
36 const int screen = list.ScreenRow(i);
37 if (screen < 0) continue;
38 Check(screen * CargoManifestList::LineHeight < list.controlsY, "rows stop above shortcuts");
39 if (i >= 2) Check(screen >= 2, "body never overwrites headings");
40 }
41}
42
43static void CheckKeyRepeat()
44{
45 CargoManifestList list(347);
46 FillMammoth(list);
47 unsigned char keys[256] = {};
48 keys[208] = 0x80;
49 list.selected = 23;
50 Check(list.HandleNavigationKey(208, true) && list.selected == 24, "press moves immediately to Bay 18");
51 Check(list.UpdateKeyRepeat(keys, true, 0.0f) && list.selected == 24, "press frame does not repeat");
52 Check(list.UpdateKeyRepeat(keys, true, 0.375f) && list.selected == 24, "held key is consumed during initial delay");
53 list.UpdateKeyRepeat(keys, true, 0.125f);
54 Check(list.selected == 27 && list.offset == 3, "half-second repeat scrolls from Bay 18 to Baggage");
55 CheckWindow(list);
56 list.UpdateKeyRepeat(keys, true, 0.02f);
57 Check(list.selected == 27, "wait for the Windows repeat interval");
58 list.UpdateKeyRepeat(keys, true, 0.02f);
59 Check(list.selected == 29 && !list.MoreBelow(), "second repeat follows about 33 ms later");
60 list.UpdateKeyRepeat(keys, true, 0.04f);
61 Check(list.selected == 29, "repeat clamps at the end of the manifest");
62
63 keys[200] = 0x80;
64 Check(list.HandleNavigationKey(200, true) && list.selected == 27, "opposite direction moves immediately");
65 list.UpdateKeyRepeat(keys, true, 0.375f);
66 Check(list.selected == 27, "direction change restarts the Windows delay");
67 list.UpdateKeyRepeat(keys, true, 0.125f);
68 Check(list.selected == 24, "up repeats after its own delay");
69 list.UpdateKeyRepeat(keys, true, 0.04f);
70 Check(list.selected == 23, "up uses the fast Windows repeat rate");
71 keys[200] = 0;
72 Check(!list.UpdateKeyRepeat(keys, true, 5.0f) && list.selected == 23, "releasing the active arrow cancels repeat");
73 Check(!list.UpdateKeyRepeat(keys, true, 5.0f), "older held arrow does not resume without a fresh press");
74
75 list.HandleNavigationKey(208, true);
76 Check(list.selected == 24, "repress moves immediately");
77 Check(!list.UpdateKeyRepeat(keys, false, 5.0f) && list.selected == 24, "releasing Shift cancels repeat");
78 Check(!list.UpdateKeyRepeat(keys, true, 5.0f), "pressing Shift again cannot revive cancelled repeat");
79 list.HandleNavigationKey(208, true);
80 Check(!list.UpdateKeyRepeat(nullptr, true, 5.0f) && list.selected == 27, "unavailable input cancels without moving");
81 Check(!list.UpdateKeyRepeat(keys, true, 5.0f), "restoring input requires a fresh navigation press");
82 list.HandleNavigationKey(208, true);
83 list.CancelKeyRepeat();
84 Check(!list.UpdateKeyRepeat(keys, true, 5.0f), "changing pages cancels repeat");
85 Check(!list.HandleNavigationKey(22, true), "Use never arms navigation repeat");
86 Check(!list.HandleNavigationKey(31, true), "Swap never arms navigation repeat");
87 Check(!list.HandleNavigationKey(208, false), "unshifted arrows never arm navigation repeat");
88
89 for (short key : { short{80}, short{72} })
90 {
91 list.selected = 10;
92 keys[key] = 0x80;
93 const int direction = key == 80 ? 1 : -1;
94 Check(list.HandleNavigationKey(key, true) && list.selected == 10 + direction, "keypad navigation moves immediately");
95 list.UpdateKeyRepeat(keys, true, 0.5f);
96 Check(list.selected == 10 + 2 * direction, "keypad navigation repeats");
97 keys[key] = 0;
98 Check(!list.UpdateKeyRepeat(keys, true, 1.0f), "keypad release cancels repeat");
99 }
100 list.selected = 7;
101 list.HandleNavigationKey(208, true);
102 list.UpdateKeyRepeat(keys, true, 10.0f);
103 Check(list.selected == 9, "long frame produces at most one repeat");
104 list.UpdateKeyRepeat(keys, true, 0.0f);
105 Check(list.selected == 9, "no queued repeat burst after a stall");
106 list.rows.clear();
107 Check(!list.UpdateKeyRepeat(keys, true, 1.0f), "empty manifest cancels repeat safely");
108}
109
110static void CheckWindowsRepeatSettings()
111{
112 unsigned char keys[256] = {};
113 keys[208] = 0x80;
114 // A two-second hold: the first repeat is at 0.5s, then about 30 per second.
115 // Fractional frame time must be retained, particularly at 45 and 144 FPS.
116 for (int fps : { 30, 45, 60, 144 })
117 {
118 CargoManifestList list(347);
119 FillMammoth(list, 80);
120 list.selected = 27;
121 list.HandleNavigationKey(208, true, 1, 31);
122 for (int frame = 0; frame < 2 * fps; ++frame)
123 {
124 list.UpdateKeyRepeat(keys, true, 1.0f / fps);
125 CheckWindow(list);
126 }
127 const int repeats = list.selected - 28;
128 Check(repeats >= 45 && repeats <= 46, "Windows fast repeat retains its rate across frame rates");
129 }
130
131 CargoManifestList list(347);
132 FillMammoth(list, 80);
133 list.selected = 27;
134 list.HandleNavigationKey(208, true, 0, 31);
135 list.UpdateKeyRepeat(keys, true, 0.125f);
136 Check(list.selected == 28, "shortest Windows delay waits before repeating");
137 list.UpdateKeyRepeat(keys, true, 0.125f);
138 Check(list.selected == 29, "shortest Windows delay is 250 ms");
139 list.HandleNavigationKey(208, true, 3, 0);
140 list.UpdateKeyRepeat(keys, true, 0.75f);
141 Check(list.selected == 30, "longest Windows delay still waits one second");
142 list.UpdateKeyRepeat(keys, true, 0.25f);
143 Check(list.selected == 31, "longest Windows delay repeats at one second");
144 list.UpdateKeyRepeat(keys, true, 0.25f);
145 Check(list.selected == 31, "slowest Windows repeat waits 400 ms between moves");
146 list.UpdateKeyRepeat(keys, true, 0.15625f);
147 Check(list.selected == 32, "slowest Windows repeat follows the configured rate");
148}
149
150int main()
151{
152 CheckKeyRepeat();
153 CheckWindowsRepeatSettings();
154 CargoManifestList list(347);
155 FillMammoth(list);
156 Check(list.controlsY == 300 && list.moreY == 324, "Mammoth footer matches the cockpit view");
157 Check(list.offset == 0 && list.MoreBelow(), "initial view indicates content below only");
158 Check(list.ScreenRow(24) == 24 && list.ScreenRow(25) == -1, "initial view ends at Bay 18");
159 list.MoveSelection(-1);
160 Check(list.selected == 0, "up at title stays at title");
161 list.MoveSelection(1);
162 Check(list.rows[list.selected].type == "Fuel", "skip headings and empty weight");
163 while (list.selected < 24) list.MoveSelection(1);
164 Check(list.rows[list.selected].type == "Bay" && list.rows[list.selected].value == 17,
165 "Bay 18 retains its real bay index");
166 Check(list.offset == 0, "Bay 18 fits without scrolling");
167 list.MoveSelection(1);
168 Check(list.selected == 27 && list.offset == 3, "Bay 18 to Baggage scrolls exactly three rows");
169 Check(list.ScreenRow(2) == -1 && list.ScreenRow(3) == -1 && list.ScreenRow(4) == -1,
170 "first three body rows disappear");
171 Check(list.ScreenRow(5) == 2 && list.ScreenRow(27) == 24, "Baggage becomes the bottom row");
172 Check(list.rows[list.selected].type == "Baggage" && list.rows[list.selected].value == 0,
173 "Use, Swap and Transfer retain the personal inventory index");
174 CheckWindow(list);
175 list.MoveSelection(1);
176 Check(list.rows[list.selected].text == L"Total Weight" && !list.MoreBelow(),
177 "down past inventory reveals cash and total without an empty trailing page");
178 const int last = list.selected;
179 list.MoveSelection(1);
180 Check(list.selected == last, "down at total stays at total");
181 while (list.selected > 0) { list.MoveSelection(-1); CheckWindow(list); }
182 Check(list.offset == 0, "returning to title restores MANIFEST and the first rows");
183
184 FillMammoth(list, 80, 90);
185 int baggageSeen = 0, cabinSeen = 0;
186 while (list.selected < static_cast<int>(list.rows.size()) - 1)
187 {
188 list.MoveSelection(1);
189 const auto& selected = list.rows[list.selected];
190 if (selected.type == "Baggage") Check(selected.value == baggageSeen++, "personal item order");
191 if (selected.type == "Cabin") Check(selected.value == cabinSeen++, "vehicle item order");
192 CheckWindow(list);
193 }
194 Check(baggageSeen == 80 && cabinSeen == 90 && !list.MoreBelow(), "inventory exceeds old 64-row limit");
195 FillMammoth(list, 0, 0);
196 Check(list.rows[list.selected].text == L"Total Weight" && !list.MoreBelow(), "shrinking list clamps selection and offset");
197 CheckWindow(list);
198 list.rows.clear();
199 list.MoveSelection(1);
200 Check(list.selected == 0 && list.offset == 0 && !list.MoreBelow(), "empty list is safe before first render");
201 list.Add(L"MANIFEST", 0);
202 list.Add(L"-------------", 0);
203 list.Add(L"Total Weight", 0);
204 list.UpdateView();
205 Check(list.offset == 0 && !list.MoreBelow(), "short manifests need no scrolling indicators");
206
207 CargoManifestList compact(320);
208 FillMammoth(compact);
209 Check(compact.controlsY + 22 <= compact.moreY && compact.moreY + 13 <= 320,
210 "shorter MFD fits both shortcuts and MORE below them");
211 while (compact.selected < static_cast<int>(compact.rows.size()) - 1)
212 {
213 compact.MoveSelection(1);
214 CheckWindow(compact);
215 }
216 std::cout << "PASS: manifest repeat timing/cancellation, Mammoth three-row scroll, pinned headings, footer, navigation, inventory identity, large/shrinking lists\n";
217}
void Add(const wchar_t *text, std::uint32_t color, const std::string &type="", int value=0)
void MoveSelection(int direction)
int ScreenRow(int row) const
std::vector< Row > rows
static constexpr int LineHeight
bool UpdateKeyRepeat(const unsigned char *keys, bool shift, float elapsed)
bool HandleNavigationKey(short key, bool shift, unsigned int keyboardDelay=1, unsigned int keyboardSpeed=31)