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

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

1#include "../../RiseLauncher/RiseLauncher.h"
2#include <filesystem>
3#include <fstream>
4#include <iostream>
5#include <stdexcept>
6#include <string>
7
8namespace fs = std::filesystem;
9static fs::path programData;
10static int launches, errors;
11
12static void Require(bool condition, const char* message)
13{
14 if (!condition) throw std::runtime_error(message);
15}
16
17// Run the actual launcher entry point, redirecting its ProgramData lookup and
18// intercepting UI/process creation. File replacement uses the real Windows API.
19static HRESULT TestKnownFolder(REFKNOWNFOLDERID id, DWORD, HANDLE, PWSTR* result)
20{
21 Require(IsEqualGUID(id, FOLDERID_ProgramData), "unexpected known folder");
22 const auto text = programData.wstring();
23 *result = static_cast<PWSTR>(CoTaskMemAlloc((text.size() + 1) * sizeof(WCHAR)));
24 Require(*result != nullptr, "folder allocation failed");
25 wcscpy_s(*result, text.size() + 1, text.c_str());
26 return S_OK;
27}
28
29static int TestMessageBox(HWND, LPCSTR, LPCSTR, UINT)
30{
31 ++errors;
32 return IDOK;
33}
34
35static BOOL TestCreateProcess(LPCWSTR application, LPWSTR, LPSECURITY_ATTRIBUTES,
36 LPSECURITY_ATTRIBUTES, BOOL, DWORD, LPVOID, LPCWSTR directory,
37 LPSTARTUPINFOW, LPPROCESS_INFORMATION info)
38{
39 Require(fs::path(application) == programData / L"Rise" / L"Rise.exe", "wrong executable");
40 Require(fs::equivalent(directory, programData / L"Rise"), "wrong working directory");
41 ++launches;
42 info->hProcess = CreateEventW(nullptr, FALSE, FALSE, nullptr);
43 info->hThread = CreateEventW(nullptr, FALSE, FALSE, nullptr);
44 Require(info->hProcess && info->hThread, "test handle allocation failed");
45 return TRUE;
46}
47
48#define SHGetKnownFolderPath TestKnownFolder
49#define MessageBoxA TestMessageBox
50#define CreateProcessW TestCreateProcess
51#define WinMain LauncherEntry
52#include "../../RiseLauncher/RiseLauncher.cpp"
53#undef WinMain
54#undef CreateProcessW
55#undef MessageBoxA
56#undef SHGetKnownFolderPath
57
58static void Write(const fs::path& path, const char* data)
59{
60 std::ofstream output(path, std::ios::binary);
61 output << data;
62 Require(output.good(), "fixture write failed");
63}
64
65static std::string Read(const fs::path& path)
66{
67 std::ifstream input(path, std::ios::binary);
68 Require(input.good(), "fixture read failed");
69 return {std::istreambuf_iterator<char>(input), std::istreambuf_iterator<char>()};
70}
71
72static fs::path Prepare(const fs::path& root, const std::wstring& name)
73{
74 programData = root / name;
75 const auto runtime = programData / L"Rise";
76 fs::create_directories(runtime / L"Save");
77 Write(runtime / L"Rise.exe", "installed game");
78 Write(runtime / L"steam_api.dll", "legacy Steam must remain unchanged");
79 return runtime;
80}
81
82static void Run(int expected)
83{
84 const auto previousDirectory = fs::current_path();
85 // Prevent even the legacy Save migration from reading real user files.
86 fs::current_path(programData / L"Rise");
87 launches = errors = 0;
88 const int result = LauncherEntry(nullptr, nullptr, nullptr, 0);
89 fs::current_path(previousDirectory);
90 if (result != expected)
91 throw std::runtime_error("launcher fixture " + programData.filename().string() +
92 ": expected " + std::to_string(expected) + ", got " + std::to_string(result));
93 Require(launches == (expected == 0 ? 1 : 0), "game launch was not gated on updates");
94 Require(errors == (expected == 0 ? 0 : 1), "unexpected error reporting");
95}
96
97int wmain(int argc, wchar_t** argv)
98{
99 try
100 {
101 static_assert(sizeof(void*) == 8, "Run these tests as x64");
102 Require(argc == 2 || (argc == 3 && std::wstring(argv[2]) == L"--social-only"),
103 "specify an isolated fixture directory and optionally --social-only");
104 const bool socialOnly = argc == 3;
105 const auto root = fs::absolute(argv[1]) /
106 (L"run-" + std::to_wstring(GetCurrentProcessId()) + L"-" + std::to_wstring(GetTickCount64()));
107 int passed = 0;
108 auto runtime = Prepare(root, L"no-pending");
109 Run(0);
110 Require(Read(runtime / L"Rise.exe") == "installed game", "game changed without update");
111 ++passed;
112
113 runtime = Prepare(root, L"retired-game-sdk");
114 Write(runtime / L"discord_game_sdk.dll", "retired installed DLL");
115 Write(runtime / L"discord_game_sdk1.dll", "retired pending DLL");
116 Run(0);
117 Require(Read(runtime / L"discord_game_sdk.dll") == "retired installed DLL" &&
118 Read(runtime / L"discord_game_sdk1.dll") == "retired pending DLL",
119 "launcher still processes retired Game SDK patches");
120 ++passed;
121
122 for (const std::wstring dll : { L"steam_api64", L"discord_partner_sdk" })
123 {
124 if (socialOnly && dll != L"discord_partner_sdk") continue;
125 for (int scenario = 0; scenario < 5; ++scenario)
126 {
127 runtime = Prepare(root, dll + L"-" + std::to_wstring(scenario));
128 const auto installed = runtime / (dll + L".dll");
129 const auto staged = runtime / (dll + L"1.dll");
130 Write(staged, "new library");
131 if (scenario != 0) Write(installed, "old library");
132 HANDLE locked = INVALID_HANDLE_VALUE;
133 if (scenario == 2 || scenario == 3)
134 {
135 const auto& file = scenario == 2 ? installed : staged;
136 locked = CreateFileW(file.c_str(), GENERIC_READ, FILE_SHARE_READ,
137 nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
138 Require(locked != INVALID_HANDLE_VALUE, "cannot lock fixture");
139 }
140 if (scenario == 4)
141 Require(SetFileAttributesW(installed.c_str(), FILE_ATTRIBUTE_READONLY), "cannot protect fixture");
142
143 Run(scenario < 2 ? 0 : -4);
144 if (locked != INVALID_HANDLE_VALUE) CloseHandle(locked);
145 if (scenario == 4) SetFileAttributesW(installed.c_str(), FILE_ATTRIBUTE_NORMAL);
146 if (scenario < 2)
147 {
148 Require(Read(installed) == "new library", "pending DLL not installed");
149 Require(!fs::exists(staged), "pending DLL not renamed");
150 }
151 else
152 {
153 Require(Read(installed) == "old library", "failed replacement damaged installed DLL");
154 Require(Read(staged) == "new library", "failed replacement lost pending DLL");
155 Run(0);
156 Require(Read(installed) == "new library" && !fs::exists(staged), "retry failed");
157 }
158 Require(Read(runtime / L"steam_api.dll") == "legacy Steam must remain unchanged", "x64 update touched legacy Steam");
159 ++passed;
160 }
161 }
162
163 runtime = Prepare(root, L"combined");
164 if (!socialOnly)
165 {
166 Write(runtime / L"steam_api641.dll", "new Steam");
167 }
168 Write(runtime / L"discord_partner_sdk1.dll", "new Social SDK");
169 Write(runtime / L"Rise1.exe", "new game");
170 Run(0);
171 if (!socialOnly)
172 {
173 Require(Read(runtime / L"steam_api64.dll") == "new Steam", "combined Steam update failed");
174 }
175 Require(Read(runtime / L"discord_partner_sdk.dll") == "new Social SDK", "combined Social SDK update failed");
176 Require(Read(runtime / L"Rise.exe") == "new game", "game update regressed");
177 ++passed;
178
179 if (socialOnly)
180 {
181 std::cout << "PASS " << passed << " Social SDK launcher scenarios, including failed-update retries\n";
182 return 0;
183 }
184 runtime = Prepare(root, L"legacy-steam");
185 Write(runtime / L"steam_api1.dll", "legacy Steam update");
186 Run(0);
187 Require(Read(runtime / L"steam_api.dll") == "legacy Steam update", "legacy update regressed");
188 ++passed;
189 std::cout << "PASS " << passed << " launcher scenarios, including failed-update retries\n";
190 return 0;
191 }
192 catch (const std::exception& error)
193 {
194 std::cerr << "FAIL: " << error.what() << '\n';
195 return 1;
196 }
197}
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
SCRIPT_CONTROL SCRIPT_STATE const void SCRIPT_CONTROL SCRIPT_STATE const int SCRIPT_TABDEF const BYTE SCRIPT_STRING_ANALYSIS BOOL
SCRIPT_CONTROL SCRIPT_STATE const void DWORD