Skip to content

Commit 64fb6f7

Browse files
authored
Merge pull request #1864 from berryzplus/feature/fix_test_for_exeini
マルチユーザー設定ファイル(sakura.exe.ini)のテストケース修正
2 parents 91a09d7 + b76c2e0 commit 64fb6f7

File tree

1 file changed

+41
-40
lines changed

1 file changed

+41
-40
lines changed

tests/unittests/test-file.cpp

+41-40
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,47 @@ TEST(file, GetIniFileName_InProcessNamedProfileUnInitialized)
209209
ASSERT_STREQ(path.c_str(), GetIniFileName().c_str());
210210
}
211211

212+
/*!
213+
* マルチユーザー設定ファイルを使うテストのためのフィクスチャクラス
214+
*
215+
* 設定ファイルを使うテストは「設定ファイルがない状態」からの始動を想定しているので
216+
* 始動前に設定ファイルを削除するようにしている。
217+
* テスト実行後に設定ファイルを残しておく意味はないので終了後も削除している。
218+
*/
219+
class CExeIniTest : public ::testing::Test {
220+
protected:
221+
/*!
222+
* マルチユーザー構成設定ファイルのパス
223+
*/
224+
std::filesystem::path exeIniPath;
225+
226+
/*!
227+
* テストが起動される直前に毎回呼ばれる関数
228+
*/
229+
void SetUp() override {
230+
// マルチユーザー構成設定ファイルのパス
231+
exeIniPath = GetExeFileName().concat(L".ini");
232+
}
233+
234+
/*!
235+
* テストが実行された直後に毎回呼ばれる関数
236+
*/
237+
void TearDown() override {
238+
// 存在チェック
239+
if (std::filesystem::exists(exeIniPath)) {
240+
// マルチユーザー構成設定ファイルを削除する
241+
std::filesystem::remove(exeIniPath);
242+
}
243+
244+
// 削除チェック
245+
ASSERT_FALSE(fexist(exeIniPath.c_str()));
246+
}
247+
};
248+
212249
/*!
213250
* @brief iniファイルパスの取得
214251
*/
215-
TEST(file, GetIniFileName_PrivateRoamingAppData)
252+
TEST_F(CExeIniTest, GetIniFileName_PrivateRoamingAppData)
216253
{
217254
// コマンドラインのインスタンスを用意する
218255
CCommandLine cCommandLine;
@@ -222,9 +259,6 @@ TEST(file, GetIniFileName_PrivateRoamingAppData)
222259
// プロセスのインスタンスを用意する
223260
CControlProcess dummy(nullptr, LR"(-PROF="profile1")");
224261

225-
// マルチユーザー構成設定ファイルのパス
226-
auto exeIniPath = GetExeFileName().concat(L".ini");
227-
228262
// 設定を書き込む
229263
::WritePrivateProfileString(L"Settings", L"MultiUser", L"1", exeIniPath.c_str());
230264
::WritePrivateProfileString(L"Settings", L"UserRootFolder", L"0", exeIniPath.c_str());
@@ -241,18 +275,12 @@ TEST(file, GetIniFileName_PrivateRoamingAppData)
241275

242276
// テスト実施
243277
ASSERT_STREQ(expected.c_str(), GetIniFileName().c_str());
244-
245-
// INIファイルを削除する
246-
std::filesystem::remove(exeIniPath);
247-
248-
// 削除チェック
249-
ASSERT_FALSE(fexist(exeIniPath.c_str()));
250278
}
251279

252280
/*!
253281
* @brief iniファイルパスの取得
254282
*/
255-
TEST(file, GetIniFileName_PrivateDesktop)
283+
TEST_F(CExeIniTest, GetIniFileName_PrivateDesktop)
256284
{
257285
// コマンドラインのインスタンスを用意する
258286
CCommandLine cCommandLine;
@@ -262,9 +290,6 @@ TEST(file, GetIniFileName_PrivateDesktop)
262290
// プロセスのインスタンスを用意する
263291
CControlProcess dummy(nullptr, LR"(-PROF="")");
264292

265-
// マルチユーザー構成設定ファイルのパス
266-
auto exeIniPath = GetExeFileName().concat(L".ini");
267-
268293
// 設定を書き込む
269294
::WritePrivateProfileString(L"Settings", L"MultiUser", L"1", exeIniPath.c_str());
270295
::WritePrivateProfileString(L"Settings", L"UserRootFolder", L"3", exeIniPath.c_str());
@@ -281,18 +306,12 @@ TEST(file, GetIniFileName_PrivateDesktop)
281306

282307
// テスト実施
283308
ASSERT_STREQ(expected.c_str(), GetIniFileName().c_str());
284-
285-
// INIファイルを削除する
286-
std::filesystem::remove(exeIniPath);
287-
288-
// 削除チェック
289-
ASSERT_FALSE(fexist(exeIniPath.c_str()));
290309
}
291310

292311
/*!
293312
* @brief iniファイルパスの取得
294313
*/
295-
TEST(file, GetIniFileName_PrivateProfile)
314+
TEST_F(CExeIniTest, GetIniFileName_PrivateProfile)
296315
{
297316
// コマンドラインのインスタンスを用意する
298317
CCommandLine cCommandLine;
@@ -302,9 +321,6 @@ TEST(file, GetIniFileName_PrivateProfile)
302321
// プロセスのインスタンスを用意する
303322
CControlProcess dummy(nullptr, LR"(-PROF="")");
304323

305-
// マルチユーザー構成設定ファイルのパス
306-
auto exeIniPath = GetExeFileName().concat(L".ini");
307-
308324
// 設定を書き込む
309325
::WritePrivateProfileString(L"Settings", L"MultiUser", L"1", exeIniPath.c_str());
310326
::WritePrivateProfileString(L"Settings", L"UserRootFolder", L"1", exeIniPath.c_str());
@@ -321,18 +337,12 @@ TEST(file, GetIniFileName_PrivateProfile)
321337

322338
// テスト実施
323339
ASSERT_STREQ(expected.c_str(), GetIniFileName().c_str());
324-
325-
// INIファイルを削除する
326-
std::filesystem::remove(exeIniPath);
327-
328-
// 削除チェック
329-
ASSERT_FALSE(fexist(exeIniPath.c_str()));
330340
}
331341

332342
/*!
333343
* @brief iniファイルパスの取得
334344
*/
335-
TEST(file, GetIniFileName_PrivateDocument)
345+
TEST_F(CExeIniTest, GetIniFileName_PrivateDocument)
336346
{
337347
// コマンドラインのインスタンスを用意する
338348
CCommandLine cCommandLine;
@@ -342,9 +352,6 @@ TEST(file, GetIniFileName_PrivateDocument)
342352
// プロセスのインスタンスを用意する
343353
CControlProcess dummy(nullptr, LR"(-PROF="")");
344354

345-
// マルチユーザー構成設定ファイルのパス
346-
auto exeIniPath = GetExeFileName().concat(L".ini");
347-
348355
// 設定を書き込む
349356
::WritePrivateProfileString(L"Settings", L"MultiUser", L"1", exeIniPath.c_str());
350357
::WritePrivateProfileString(L"Settings", L"UserRootFolder", L"2", exeIniPath.c_str());
@@ -361,12 +368,6 @@ TEST(file, GetIniFileName_PrivateDocument)
361368

362369
// テスト実施
363370
ASSERT_STREQ(expected.c_str(), GetIniFileName().c_str());
364-
365-
// INIファイルを削除する
366-
std::filesystem::remove(exeIniPath);
367-
368-
// 削除チェック
369-
ASSERT_FALSE(fexist(exeIniPath.c_str()));
370371
}
371372

372373
/*!

0 commit comments

Comments
 (0)