MCPcopy Create free account
hub / github.com/diasurgical/DevilutionX / TEST

Function TEST

test/writehero_test.cpp:360–399  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

358}
359
360TEST(Writehero, pfile_write_hero)
361{
362 const std::string savePath = paths::BasePath() + "multi_0.sv";
363 paths::SetPrefPath(paths::BasePath());
364 RemoveFile(savePath.c_str());
365
366 gbVanilla = true;
367 gbIsHellfire = false;
368 gbIsMultiplayer = true;
369 gbIsHellfireSaveGame = false;
370 leveltype = DTYPE_TOWN;
371 giNumberOfLevels = 17;
372
373 Players.resize(1);
374 MyPlayerId = 0;
375 MyPlayer = &Players[MyPlayerId];
376
377 _uiheroinfo info {};
378 info.heroclass = HeroClass::Rogue;
379 pfile_ui_save_create(&info);
380 PlayerPack pks;
381 PackPlayerTest(&pks);
382 UnPackPlayer(pks, *MyPlayer);
383 AssertPlayer(Players[0]);
384 pfile_write_hero();
385
386 uintmax_t fileSize;
387 ASSERT_TRUE(GetFileSize(savePath.c_str(), &fileSize));
388 size_t size = static_cast<size_t>(fileSize);
389 FILE *f = OpenFile(savePath.c_str(), "rb");
390 ASSERT_TRUE(f != nullptr);
391 std::unique_ptr<char[]> data { new char[size] };
392 ASSERT_EQ(std::fread(data.get(), size, 1, f), 1);
393 std::fclose(f);
394
395 std::vector<unsigned char> s(picosha2::k_digest_size);
396 picosha2::hash256(data.get(), data.get() + size, s.begin(), s.end());
397 EXPECT_EQ(picosha2::bytes_to_hex_string(s.begin(), s.end()),
398 "a79367caae6192d54703168d82e0316aa289b2a33251255fad8abe34889c1d3a");
399}
400
401} // namespace
402} // namespace devilution

Callers

nothing calls this directly

Calls 14

SetPrefPathFunction · 0.85
RemoveFileFunction · 0.85
pfile_ui_save_createFunction · 0.85
PackPlayerTestFunction · 0.85
UnPackPlayerFunction · 0.85
pfile_write_heroFunction · 0.85
GetFileSizeFunction · 0.85
OpenFileFunction · 0.85
hash256Function · 0.85
bytes_to_hex_stringFunction · 0.85
getMethod · 0.80
AssertPlayerFunction · 0.70

Tested by

no test coverage detected