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
11{
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);
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);
28}
29
31{
34 for (
int i = 0; i < static_cast<int>(list.
rows.size()); ++i)
35 {
37 if (screen < 0) continue;
39 if (i >= 2) Check(screen >= 2, "body never overwrites headings");
40 }
41}
42
43static void CheckKeyRepeat()
44{
46 FillMammoth(list);
47 unsigned char keys[256] = {};
48 keys[208] = 0x80;
52 Check(list.
UpdateKeyRepeat(keys,
true, 0.375f) && list.
selected == 24,
"held key is consumed during initial delay");
54 Check(list.
selected == 27 && list.
offset == 3,
"half-second repeat scrolls from Bay 18 to Baggage");
55 CheckWindow(list);
57 Check(list.
selected == 27,
"wait for the Windows repeat interval");
59 Check(list.
selected == 29 && !list.
MoreBelow(),
"second repeat follows about 33 ms later");
61 Check(list.
selected == 29,
"repeat clamps at the end of the manifest");
62
63 keys[200] = 0x80;
66 Check(list.
selected == 27,
"direction change restarts the Windows delay");
68 Check(list.
selected == 24,
"up repeats after its own delay");
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
76 Check(list.
selected == 24,
"repress moves immediately");
78 Check(!list.
UpdateKeyRepeat(keys,
true, 5.0f),
"pressing Shift again cannot revive cancelled repeat");
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");
84 Check(!list.
UpdateKeyRepeat(keys,
true, 5.0f),
"changing pages cancels repeat");
87 Check(!list.
HandleNavigationKey(208,
false),
"unshifted arrows never arm navigation repeat");
88
89 for (short key : { short{80}, short{72} })
90 {
92 keys[key] = 0x80;
93 const int direction = key == 80 ? 1 : -1;
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 }
103 Check(list.
selected == 9,
"long frame produces at most one repeat");
105 Check(list.
selected == 9,
"no queued repeat burst after a stall");
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
115
116 for (int fps : { 30, 45, 60, 144 })
117 {
119 FillMammoth(list, 80);
122 for (int frame = 0; frame < 2 * fps; ++frame)
123 {
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
132 FillMammoth(list, 80);
136 Check(list.
selected == 28,
"shortest Windows delay waits before repeating");
138 Check(list.
selected == 29,
"shortest Windows delay is 250 ms");
141 Check(list.
selected == 30,
"longest Windows delay still waits one second");
143 Check(list.
selected == 31,
"longest Windows delay repeats at one second");
145 Check(list.
selected == 31,
"slowest Windows repeat waits 400 ms between moves");
147 Check(list.
selected == 32,
"slowest Windows repeat follows the configured rate");
148}
149
151{
152 CheckKeyRepeat();
153 CheckWindowsRepeatSettings();
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");
160 Check(list.
selected == 0,
"up at title stays at title");
162 Check(list.
rows[list.
selected].type ==
"Fuel",
"skip headings and empty weight");
165 "Bay 18 retains its real bay index");
166 Check(list.
offset == 0,
"Bay 18 fits without scrolling");
168 Check(list.
selected == 27 && list.
offset == 3,
"Bay 18 to Baggage scrolls exactly three rows");
170 "first three body rows disappear");
171 Check(list.
ScreenRow(5) == 2 && list.
ScreenRow(27) == 24,
"Baggage becomes the bottom row");
173 "Use, Swap and Transfer retain the personal inventory index");
174 CheckWindow(list);
177 "down past inventory reveals cash and total without an empty trailing page");
180 Check(list.
selected == last,
"down at total stays at total");
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 {
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);
201 list.
Add(L
"MANIFEST", 0);
202 list.
Add(L
"-------------", 0);
203 list.
Add(L
"Total Weight", 0);
205 Check(list.
offset == 0 && !list.
MoreBelow(),
"short manifests need no scrolling indicators");
206
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
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)