Repository navigation
Expand file tree
/
Copy pathSaveDataDialogTests.cpp
More file actions
166 lines (151 loc) · 5.25 KB
/
Copy pathSaveDataDialogTests.cpp
File metadata and controls
166 lines (151 loc) · 5.25 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include "libs/dialog.h"
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstring>
namespace Loader::Timer {
double GetTimeMs() {
return 0.0;
}
} // namespace Loader::Timer
namespace {
namespace Save = Libs::Dialog::SaveDataDialog;
struct BaseParam {
uint64_t size;
uint8_t reserved[36];
uint32_t magic;
};
struct Items {
int32_t user_id;
uint32_t pad0;
const void* title_id;
const void* dir_names;
uint32_t dir_names_num;
uint32_t pad1;
const void* new_item;
int32_t focus_pos;
uint32_t pad2;
const void* focus_dir_name;
int32_t item_style;
uint8_t reserved[36];
};
struct UserMessage {
int32_t button_type;
int32_t message_type;
const char* message;
uint8_t reserved[32];
};
struct Param {
BaseParam base;
int32_t size;
int32_t mode;
int32_t display_type;
uint32_t pad0;
void* animation;
Items* items;
UserMessage* user_message;
void* system_message;
void* error_code;
void* progress_bar;
void* user_data;
void* option;
void* wizard;
uint8_t reserved[16];
};
static_assert(sizeof(BaseParam) == 48);
static_assert(sizeof(Items) == 96);
static_assert(sizeof(Param) == 152);
static_assert(offsetof(Param, items) == 72);
static_assert(offsetof(Param, user_data) == 112);
bool CheckLatestStatus(const char* stage) {
const int updated = Save::SaveDataDialogUpdateStatus();
const int current = Save::SaveDataDialogGetStatus();
if (updated != current) {
std::fprintf(stderr,
"SaveDataDialogTests: %s: UpdateStatus returned %d but the current "
"status is %d\n",
stage, updated, current);
return false;
}
return true;
}
bool CheckStatus(int actual, int expected, const char* stage) {
if (actual != expected) {
std::fprintf(stderr, "SaveDataDialogTests: %s: expected %d, got %d\n", stage, expected,
actual);
return false;
}
return true;
}
bool TestRunningThenFinished(Param& param) {
bool passed = CheckStatus(Save::SaveDataDialogOpen(¶m), 0, "Open");
for (int poll = 0; poll < 3; ++poll) {
passed =
CheckStatus(Save::SaveDataDialogGetStatus(), 2, "peek before first update") && passed;
}
passed = CheckStatus(Save::SaveDataDialogUpdateStatus(), 2, "first update") && passed;
for (int poll = 0; poll < 3; ++poll) {
passed =
CheckStatus(Save::SaveDataDialogGetStatus(), 2, "peek after first update") && passed;
}
passed = CheckStatus(Save::SaveDataDialogUpdateStatus(), 3, "second update") && passed;
passed = CheckStatus(Save::SaveDataDialogGetStatus(), 3, "finished peek") && passed;
passed = CheckStatus(Save::SaveDataDialogUpdateStatus(), 3, "finished update") && passed;
return passed;
}
bool TestCloseAndReset(Param& param) {
bool passed = CheckStatus(Save::SaveDataDialogOpen(¶m), 0, "Open before Close");
passed =
CheckStatus(Save::SaveDataDialogClose(nullptr), 0, "Close before first poll") && passed;
passed = CheckStatus(Save::SaveDataDialogUpdateStatus(), 3, "poll after Close") && passed;
passed = CheckStatus(Save::SaveDataDialogGetStatus(), 3, "peek after Close") && passed;
passed = TestRunningThenFinished(param) && passed;
passed = CheckStatus(Save::SaveDataDialogOpen(¶m), 0, "Open before Terminate") && passed;
passed = CheckStatus(Save::SaveDataDialogUpdateStatus(), 2, "poll before Terminate") && passed;
passed = CheckStatus(Save::SaveDataDialogTerminate(), 0, "Terminate while running") && passed;
passed = CheckStatus(Save::SaveDataDialogGetStatus(), 0, "peek after Terminate") && passed;
passed = CheckStatus(Save::SaveDataDialogUpdateStatus(), 0, "poll after Terminate") && passed;
passed = CheckStatus(Save::SaveDataDialogInitialize(), 0, "reinitialize") && passed;
passed = CheckStatus(Save::SaveDataDialogUpdateStatus(), 1, "initialized update") && passed;
passed = TestRunningThenFinished(param) && passed;
return passed;
}
} // namespace
int main(int argc, char** argv) {
const bool consistency_only = argc == 2 && std::strcmp(argv[1], "--consistency-only") == 0;
if (argc != 1 && !consistency_only) {
std::fprintf(stderr, "usage: SaveDataDialogTests [--consistency-only]\n");
return 2;
}
Items items {};
items.user_id = 1000;
items.dir_names_num = 1; // No save-data information is displayed with a null dir_names.
UserMessage message {};
message.message = "Status polling";
Param param {};
param.base.size = sizeof(BaseParam);
param.base.magic =
static_cast<uint32_t>(0xc0d1a109u + reinterpret_cast<uintptr_t>(¶m.base));
param.size = sizeof(Param);
param.mode = 2; // USER_MSG
param.display_type = 1; // SAVE
param.items = &items;
param.user_message = &message;
if (Libs::Dialog::CommonDialog::CommonDialogInitialize() != 0 ||
Save::SaveDataDialogInitialize() != 0) {
return 2;
}
bool passed = CheckLatestStatus("initialized");
if (Save::SaveDataDialogOpen(¶m) != 0) {
return 2;
}
passed = CheckLatestStatus("first poll after Open") && passed;
passed = CheckLatestStatus("second poll after Open") && passed;
if (!consistency_only) {
passed = TestRunningThenFinished(param) && passed;
passed = TestCloseAndReset(param) && passed;
}
Save::SaveDataDialogTerminate();
passed = CheckLatestStatus("terminated") && passed;
return passed ? 0 : 1;
}