| 1 | #include <base/system.h> |
| 2 | |
| 3 | #include <game/mapbugs.h> |
| 4 | |
| 5 | #include <gtest/gtest.h> |
| 6 | |
| 7 | static const char *BINARY_SHA256 = "65b410e197fd2298ec270e89a84b762f6739d1d18089529f8ef6cf2104d3d600" ; |
| 8 | static const char *DM1_SHA256 = "0b0c481d77519c32fbe85624ef16ec0fa9991aec7367ad538bd280f28d8c26cf" ; |
| 9 | |
| 10 | static CMapBugs GetMapBugsImpl(const char *pName, int Size, const char *pSha256) |
| 11 | { |
| 12 | SHA256_DIGEST Sha256 = {.data: {0}}; |
| 13 | dbg_assert(sha256_from_str(&Sha256, pSha256) == 0, "invalid sha256 in tests" ); |
| 14 | return CMapBugs::Create(pName, Size, Sha256); |
| 15 | } |
| 16 | |
| 17 | TEST(MapBugs, Contains) |
| 18 | { |
| 19 | EXPECT_TRUE(GetMapBugsImpl("Binary" , 2022597, BINARY_SHA256).Contains(BUG_GRENADE_DOUBLEEXPLOSION)); |
| 20 | EXPECT_FALSE(GetMapBugsImpl("Binarx" , 2022597, BINARY_SHA256).Contains(BUG_GRENADE_DOUBLEEXPLOSION)); |
| 21 | EXPECT_FALSE(GetMapBugsImpl("Binary" , 2022598, BINARY_SHA256).Contains(BUG_GRENADE_DOUBLEEXPLOSION)); |
| 22 | EXPECT_FALSE(GetMapBugsImpl("dm1" , 5805, DM1_SHA256).Contains(BUG_GRENADE_DOUBLEEXPLOSION)); |
| 23 | } |
| 24 | |
| 25 | TEST(MapBugs, Update) |
| 26 | { |
| 27 | { |
| 28 | CMapBugs Binary = GetMapBugsImpl(pName: "Binary" , Size: 2022597, pSha256: BINARY_SHA256); |
| 29 | EXPECT_EQ(Binary.Update("grenade-doubleexplosion@ddnet.tw" ), EMapBugUpdate::OVERRIDDEN); |
| 30 | EXPECT_EQ(Binary.Update("doesntexist@invalid" ), EMapBugUpdate::NOTFOUND); |
| 31 | EXPECT_TRUE(Binary.Contains(BUG_GRENADE_DOUBLEEXPLOSION)); |
| 32 | } |
| 33 | { |
| 34 | CMapBugs Dm1 = GetMapBugsImpl(pName: "dm1" , Size: 5805, pSha256: DM1_SHA256); |
| 35 | EXPECT_FALSE(Dm1.Contains(BUG_GRENADE_DOUBLEEXPLOSION)); |
| 36 | EXPECT_EQ(Dm1.Update("doesntexist@invalid" ), EMapBugUpdate::NOTFOUND); |
| 37 | EXPECT_FALSE(Dm1.Contains(BUG_GRENADE_DOUBLEEXPLOSION)); |
| 38 | EXPECT_EQ(Dm1.Update("grenade-doubleexplosion@ddnet.tw" ), EMapBugUpdate::OK); |
| 39 | EXPECT_TRUE(Dm1.Contains(BUG_GRENADE_DOUBLEEXPLOSION)); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | TEST(MapBugs, Dump) |
| 44 | { |
| 45 | GetMapBugsImpl(pName: "Binary" , Size: 2022597, pSha256: BINARY_SHA256).Dump(); |
| 46 | GetMapBugsImpl(pName: "dm1" , Size: 5805, pSha256: DM1_SHA256).Dump(); |
| 47 | } |
| 48 | |