| 358 | } |
| 359 | |
| 360 | TEST(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 |
nothing calls this directly
no test coverage detected