@@ -209,10 +209,47 @@ TEST(file, GetIniFileName_InProcessNamedProfileUnInitialized)
209
209
ASSERT_STREQ (path.c_str (), GetIniFileName ().c_str ());
210
210
}
211
211
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
+
212
249
/* !
213
250
* @brief iniファイルパスの取得
214
251
*/
215
- TEST (file , GetIniFileName_PrivateRoamingAppData)
252
+ TEST_F (CExeIniTest , GetIniFileName_PrivateRoamingAppData)
216
253
{
217
254
// コマンドラインのインスタンスを用意する
218
255
CCommandLine cCommandLine;
@@ -222,9 +259,6 @@ TEST(file, GetIniFileName_PrivateRoamingAppData)
222
259
// プロセスのインスタンスを用意する
223
260
CControlProcess dummy (nullptr , LR"( -PROF="profile1")" );
224
261
225
- // マルチユーザー構成設定ファイルのパス
226
- auto exeIniPath = GetExeFileName ().concat (L" .ini" );
227
-
228
262
// 設定を書き込む
229
263
::WritePrivateProfileString (L" Settings" , L" MultiUser" , L" 1" , exeIniPath.c_str());
230
264
::WritePrivateProfileString (L" Settings" , L" UserRootFolder" , L" 0" , exeIniPath.c_str());
@@ -241,18 +275,12 @@ TEST(file, GetIniFileName_PrivateRoamingAppData)
241
275
242
276
// テスト実施
243
277
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 ()));
250
278
}
251
279
252
280
/* !
253
281
* @brief iniファイルパスの取得
254
282
*/
255
- TEST (file , GetIniFileName_PrivateDesktop)
283
+ TEST_F (CExeIniTest , GetIniFileName_PrivateDesktop)
256
284
{
257
285
// コマンドラインのインスタンスを用意する
258
286
CCommandLine cCommandLine;
@@ -262,9 +290,6 @@ TEST(file, GetIniFileName_PrivateDesktop)
262
290
// プロセスのインスタンスを用意する
263
291
CControlProcess dummy (nullptr , LR"( -PROF="")" );
264
292
265
- // マルチユーザー構成設定ファイルのパス
266
- auto exeIniPath = GetExeFileName ().concat (L" .ini" );
267
-
268
293
// 設定を書き込む
269
294
::WritePrivateProfileString (L" Settings" , L" MultiUser" , L" 1" , exeIniPath.c_str());
270
295
::WritePrivateProfileString (L" Settings" , L" UserRootFolder" , L" 3" , exeIniPath.c_str());
@@ -281,18 +306,12 @@ TEST(file, GetIniFileName_PrivateDesktop)
281
306
282
307
// テスト実施
283
308
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 ()));
290
309
}
291
310
292
311
/* !
293
312
* @brief iniファイルパスの取得
294
313
*/
295
- TEST (file , GetIniFileName_PrivateProfile)
314
+ TEST_F (CExeIniTest , GetIniFileName_PrivateProfile)
296
315
{
297
316
// コマンドラインのインスタンスを用意する
298
317
CCommandLine cCommandLine;
@@ -302,9 +321,6 @@ TEST(file, GetIniFileName_PrivateProfile)
302
321
// プロセスのインスタンスを用意する
303
322
CControlProcess dummy (nullptr , LR"( -PROF="")" );
304
323
305
- // マルチユーザー構成設定ファイルのパス
306
- auto exeIniPath = GetExeFileName ().concat (L" .ini" );
307
-
308
324
// 設定を書き込む
309
325
::WritePrivateProfileString (L" Settings" , L" MultiUser" , L" 1" , exeIniPath.c_str());
310
326
::WritePrivateProfileString (L" Settings" , L" UserRootFolder" , L" 1" , exeIniPath.c_str());
@@ -321,18 +337,12 @@ TEST(file, GetIniFileName_PrivateProfile)
321
337
322
338
// テスト実施
323
339
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 ()));
330
340
}
331
341
332
342
/* !
333
343
* @brief iniファイルパスの取得
334
344
*/
335
- TEST (file , GetIniFileName_PrivateDocument)
345
+ TEST_F (CExeIniTest , GetIniFileName_PrivateDocument)
336
346
{
337
347
// コマンドラインのインスタンスを用意する
338
348
CCommandLine cCommandLine;
@@ -342,9 +352,6 @@ TEST(file, GetIniFileName_PrivateDocument)
342
352
// プロセスのインスタンスを用意する
343
353
CControlProcess dummy (nullptr , LR"( -PROF="")" );
344
354
345
- // マルチユーザー構成設定ファイルのパス
346
- auto exeIniPath = GetExeFileName ().concat (L" .ini" );
347
-
348
355
// 設定を書き込む
349
356
::WritePrivateProfileString (L" Settings" , L" MultiUser" , L" 1" , exeIniPath.c_str());
350
357
::WritePrivateProfileString (L" Settings" , L" UserRootFolder" , L" 2" , exeIniPath.c_str());
@@ -361,12 +368,6 @@ TEST(file, GetIniFileName_PrivateDocument)
361
368
362
369
// テスト実施
363
370
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 ()));
370
371
}
371
372
372
373
/* !
0 commit comments