emberemu/tests/IntegrityData.cpp

61 lines
1.4 KiB
C++
Raw Permalink Normal View History

2024-03-04 02:24:21 +00:00
/*
2026-02-21 22:31:12 +00:00
* Copyright (c) 2024 - 2026 Ember
2024-03-04 02:24:21 +00:00
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <login/IntegrityData.h>
2024-12-30 23:45:04 +00:00
#include <shared/utility/FileMD5.h>
2026-02-21 22:31:12 +00:00
#include <shared/utility/HashDefines.h>
2024-03-04 02:24:21 +00:00
#include <gtest/gtest.h>
#include <array>
#include <cstdint>
using namespace ember;
TEST(IntegrityData, LoadData_MD5) {
2024-07-24 00:44:27 +01:00
const GameVersion version {
.major = 1,
.minor = 12,
.build = 5875,
2024-03-04 02:24:21 +00:00
};
2024-07-24 00:44:27 +01:00
IntegrityData data;
data.add_version(version, "test_data/");
const auto res = data.lookup(version, grunt::Platform::x86, grunt::System::Win);
2024-03-04 02:24:21 +00:00
ASSERT_TRUE(res);
ASSERT_EQ(res->size_bytes(), 320);
2026-02-18 21:38:07 +00:00
const auto md5 = utility::generate_md5(*res);
2026-02-21 22:31:12 +00:00
const std::array<std::uint8_t, hash_sizes::md5> expected_md5 {
2024-03-04 02:24:21 +00:00
0xd6, 0x4a, 0xd1, 0xb3, 0x86, 0x02, 0x08, 0x76,
0x2d, 0xfd, 0xd1, 0x0a, 0x9b, 0x85, 0x75, 0xbd
};
ASSERT_EQ(md5, expected_md5);
}
TEST(IntegrityData, LoadData_NotFound_BadDir) {
2024-07-24 00:44:27 +01:00
const GameVersion version {
.major = 1,
.minor = 12,
.build = 5875,
};
2024-07-24 00:44:27 +01:00
IntegrityData data;
ASSERT_ANY_THROW(data.add_version(version, "fake_dir/"));
}
TEST(IntegrityData, LoadData_NotFound_BadVers) {
2024-07-24 00:44:27 +01:00
const GameVersion version {
.major = 2,
.minor = 12,
.build = 1000,
};
2024-07-24 00:44:27 +01:00
IntegrityData data;
ASSERT_ANY_THROW(data.add_version(version, "test_data/"));
2024-03-04 02:24:21 +00:00
}