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