1#include <gtest/gtest.h>
2
3#include <engine/serverbrowser.h>
4#include <engine/shared/serverinfo.h>
5
6#include <engine/external/json-parser/json.h>
7
8TEST(ServerInfo, ParseLocation)
9{
10 int Result;
11 EXPECT_TRUE(CServerInfo::ParseLocation(&Result, "xx"));
12 EXPECT_FALSE(CServerInfo::ParseLocation(&Result, "an"));
13 EXPECT_EQ(Result, CServerInfo::LOC_UNKNOWN);
14 EXPECT_FALSE(CServerInfo::ParseLocation(&Result, "af"));
15 EXPECT_EQ(Result, CServerInfo::LOC_AFRICA);
16 EXPECT_FALSE(CServerInfo::ParseLocation(&Result, "eu-n"));
17 EXPECT_EQ(Result, CServerInfo::LOC_EUROPE);
18 EXPECT_FALSE(CServerInfo::ParseLocation(&Result, "na"));
19 EXPECT_EQ(Result, CServerInfo::LOC_NORTH_AMERICA);
20 EXPECT_FALSE(CServerInfo::ParseLocation(&Result, "sa"));
21 EXPECT_EQ(Result, CServerInfo::LOC_SOUTH_AMERICA);
22 EXPECT_FALSE(CServerInfo::ParseLocation(&Result, "as:e"));
23 EXPECT_EQ(Result, CServerInfo::LOC_ASIA);
24 EXPECT_FALSE(CServerInfo::ParseLocation(&Result, "as:cn"));
25 EXPECT_EQ(Result, CServerInfo::LOC_CHINA);
26 EXPECT_FALSE(CServerInfo::ParseLocation(&Result, "oc"));
27 EXPECT_EQ(Result, CServerInfo::LOC_AUSTRALIA);
28}
29
30static unsigned int ParseCrcOrDeadbeef(const char *pString)
31{
32 unsigned int Result;
33 if(ParseCrc(pResult: &Result, pString))
34 {
35 Result = 0xdeadbeef;
36 }
37 return Result;
38}
39
40TEST(ServerInfo, Crc)
41{
42 EXPECT_EQ(ParseCrcOrDeadbeef("00000000"), 0);
43 EXPECT_EQ(ParseCrcOrDeadbeef("00000001"), 1);
44 EXPECT_EQ(ParseCrcOrDeadbeef("12345678"), 0x12345678);
45 EXPECT_EQ(ParseCrcOrDeadbeef("9abcdef0"), 0x9abcdef0);
46
47 EXPECT_EQ(ParseCrcOrDeadbeef(""), 0xdeadbeef);
48 EXPECT_EQ(ParseCrcOrDeadbeef("a"), 0xdeadbeef);
49 EXPECT_EQ(ParseCrcOrDeadbeef("x"), 0xdeadbeef);
50 EXPECT_EQ(ParseCrcOrDeadbeef("ç"), 0xdeadbeef);
51 EXPECT_EQ(ParseCrcOrDeadbeef("😢"), 0xdeadbeef);
52 EXPECT_EQ(ParseCrcOrDeadbeef("0"), 0xdeadbeef);
53 EXPECT_EQ(ParseCrcOrDeadbeef("000000000"), 0xdeadbeef);
54 EXPECT_EQ(ParseCrcOrDeadbeef("00000000x"), 0xdeadbeef);
55}
56