MCPcopy Create free account
hub / github.com/ddnet/ddnet / TEST

Function TEST

src/test/serverbrowser_test.cpp:15–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13#include <memory>
14
15TEST(ServerBrowser, PingCache)
16{
17 CTestInfo Info;
18 Info.m_DeleteTestStorageFilesOnSuccess = true;
19
20 auto pConsole = CreateConsole(CFGFLAG_CLIENT);
21 std::unique_ptr<IStorage> pStorage = Info.CreateTestStorage();
22 ASSERT_NE(pStorage, nullptr) << "Error creating test storage";
23 auto pPingCache = std::unique_ptr<IServerBrowserPingCache>(CreateServerBrowserPingCache(pConsole.get(), pStorage.get()));
24
25 NETADDR Localhost4, Localhost6, OtherLocalhost4, OtherLocalhost6;
26 ASSERT_FALSE(net_addr_from_str(&Localhost4, "127.0.0.1:8303"));
27 ASSERT_FALSE(net_addr_from_str(&Localhost6, "[::1]:8304"));
28 ASSERT_FALSE(net_addr_from_str(&OtherLocalhost4, "127.0.0.1:8305"));
29 ASSERT_FALSE(net_addr_from_str(&OtherLocalhost6, "[::1]:8306"));
30 EXPECT_LT(net_addr_comp(&Localhost4, &Localhost6), 0);
31 NETADDR aLocalhostBoth[2] = {Localhost4, Localhost6};
32
33 EXPECT_EQ(pPingCache->NumEntries(), 0);
34 EXPECT_EQ(pPingCache->GetPing(&Localhost4, 1), -1);
35 EXPECT_EQ(pPingCache->GetPing(&Localhost6, 1), -1);
36 EXPECT_EQ(pPingCache->GetPing(aLocalhostBoth, 2), -1);
37 EXPECT_EQ(pPingCache->GetPing(&OtherLocalhost4, 1), -1);
38 EXPECT_EQ(pPingCache->GetPing(&OtherLocalhost6, 1), -1);
39
40 pPingCache->Load();
41
42 EXPECT_EQ(pPingCache->NumEntries(), 0);
43 EXPECT_EQ(pPingCache->GetPing(&Localhost4, 1), -1);
44 EXPECT_EQ(pPingCache->GetPing(&Localhost6, 1), -1);
45 EXPECT_EQ(pPingCache->GetPing(aLocalhostBoth, 2), -1);
46 EXPECT_EQ(pPingCache->GetPing(&OtherLocalhost4, 1), -1);
47 EXPECT_EQ(pPingCache->GetPing(&OtherLocalhost6, 1), -1);
48
49 // Newer pings overwrite older.
50 pPingCache->CachePing(Localhost4, 123);
51 pPingCache->CachePing(Localhost4, 234);
52 pPingCache->CachePing(Localhost4, 345);
53 pPingCache->CachePing(Localhost4, 456);
54 pPingCache->CachePing(Localhost4, 567);
55 pPingCache->CachePing(Localhost4, 678);
56 pPingCache->CachePing(Localhost4, 789);
57 pPingCache->CachePing(Localhost4, 890);
58 pPingCache->CachePing(Localhost4, 901);
59 pPingCache->CachePing(Localhost4, 135);
60 pPingCache->CachePing(Localhost4, 246);
61 pPingCache->CachePing(Localhost4, 357);
62 pPingCache->CachePing(Localhost4, 468);
63 pPingCache->CachePing(Localhost4, 579);
64 pPingCache->CachePing(Localhost4, 680);
65 pPingCache->CachePing(Localhost4, 791);
66 pPingCache->CachePing(Localhost4, 802);
67 pPingCache->CachePing(Localhost4, 913);
68
69 EXPECT_EQ(pPingCache->NumEntries(), 1);
70 EXPECT_EQ(pPingCache->GetPing(&Localhost4, 1), 913);
71 EXPECT_EQ(pPingCache->GetPing(&Localhost6, 1), -1);
72 EXPECT_EQ(pPingCache->GetPing(aLocalhostBoth, 2), 913);

Callers

nothing calls this directly

Calls 10

CreateConsoleFunction · 0.85
net_addr_from_strFunction · 0.85
net_addr_compFunction · 0.85
CreateTestStorageMethod · 0.80
getMethod · 0.80
NumEntriesMethod · 0.80
GetPingMethod · 0.80
CachePingMethod · 0.80
LoadMethod · 0.45

Tested by

no test coverage detected