0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-19 19:52:15 +02:00

unittests: Fix -Wsigned-compare errors

Seen with newer versions of GoogleTest.

Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
This commit is contained in:
Frank Lichtenheld 2023-02-14 14:52:41 +01:00
parent 71cf5f48fe
commit 330a91ef64
13 changed files with 56 additions and 56 deletions

View File

@ -10,7 +10,7 @@ TEST(buffer, const_buffer_ref_1)
static unsigned char hello[] = "hello world";
Buffer buf(hello, sizeof(hello) - 1, true);
ConstBuffer &cbuf = const_buffer_ref(buf);
EXPECT_EQ(cbuf.size(), 11);
EXPECT_EQ(cbuf.size(), 11u);
EXPECT_EQ(buf_to_string(buf), buf_to_string(cbuf));
}
@ -20,7 +20,7 @@ TEST(buffer, const_buffer_ref_2)
BufferAllocated buf(64, 0);
buf_append_string(buf, "hello world");
ConstBuffer &cbuf = const_buffer_ref(buf);
EXPECT_EQ(cbuf.size(), 11);
EXPECT_EQ(cbuf.size(), 11u);
EXPECT_EQ(buf_to_string(buf), buf_to_string(cbuf));
}
@ -30,7 +30,7 @@ TEST(buffer, my_const_buffer_1)
typedef ConstBufferType<const char> MyConstBuffer;
static const char hello[] = "hello world";
MyConstBuffer cbuf(hello, sizeof(hello) - 1, true);
EXPECT_EQ(cbuf.size(), 11);
EXPECT_EQ(cbuf.size(), 11u);
EXPECT_EQ(std::string(cbuf.c_data(), cbuf.size()), "hello world");
}

View File

@ -54,7 +54,7 @@ TEST(crypto, hmac)
uint8_t hash[20];
ASSERT_EQ(hmac.final(hash), 20);
ASSERT_EQ(hmac.final(hash), 20u);
/* Google test does not seem to have a good memory equality test macro */
ASSERT_EQ(std::memcmp(hash, goodhash, sizeof(goodhash)), 0);
@ -64,7 +64,7 @@ TEST(crypto, hmac)
/* Do this again to ensure that reset works */
hmac.update(ipsum, std::strlen(ipsumlorem));
hmac.update(ipsum, std::strlen(ipsumlorem));
ASSERT_EQ(hmac.final(hash), 20);
ASSERT_EQ(hmac.final(hash), 20u);
/* Google test does not seem to have a good memory equality test macro */
ASSERT_EQ(std::memcmp(hash, goodhash, sizeof(goodhash)), 0);
@ -78,7 +78,7 @@ TEST(crypto, hmac)
/* Do this again to ensure that reset works */
hmac.update(ipsum, std::strlen(ipsumlorem));
hmac.update(ipsum, std::strlen(ipsumlorem));
ASSERT_EQ(hmac.final(hash), 20);
ASSERT_EQ(hmac.final(hash), 20u);
/* Google test does not seem to have a good memory equality test macro */
ASSERT_EQ(std::memcmp(hash, goodhash, sizeof(goodhash)), 0);

View File

@ -48,12 +48,12 @@ TEST(Dns, Options)
DnsOptions dns(config);
ASSERT_EQ(dns.search_domains.size(), 3);
ASSERT_EQ(dns.search_domains.size(), 3u);
ASSERT_EQ(dns.search_domains[0], "domain0");
ASSERT_EQ(dns.search_domains[1], "domain1");
ASSERT_EQ(dns.search_domains[2], "domain2");
ASSERT_EQ(dns.servers.size(), 3);
ASSERT_EQ(dns.servers.size(), 3u);
int i = 1;
for (const auto &keyval : dns.servers)
@ -67,12 +67,12 @@ TEST(Dns, Options)
ASSERT_TRUE(server.address4.specified());
ASSERT_EQ(server.address4.to_string(), "2.2.2.2");
ASSERT_EQ(server.port4, 5353);
ASSERT_EQ(server.port4, 5353u);
ASSERT_TRUE(server.address6.unspecified());
ASSERT_EQ(server.port6, 0);
ASSERT_EQ(server.port6, 0u);
ASSERT_EQ(server.domains.size(), 2);
ASSERT_EQ(server.domains.size(), 2u);
ASSERT_EQ(server.domain_type, DnsServer::DomainType::Resolve);
ASSERT_EQ(server.domains[0], "rdom0");
ASSERT_EQ(server.domains[1], "rdom1");
@ -88,13 +88,13 @@ TEST(Dns, Options)
ASSERT_TRUE(server.address4.specified());
ASSERT_EQ(server.address4.to_string(), "1.1.1.1");
ASSERT_EQ(server.port4, 0);
ASSERT_EQ(server.port4, 0u);
ASSERT_TRUE(server.address6.specified());
ASSERT_EQ(server.address6.to_string(), "1::1");
ASSERT_EQ(server.port6, 5353);
ASSERT_EQ(server.port6, 5353u);
ASSERT_EQ(server.domains.size(), 1);
ASSERT_EQ(server.domains.size(), 1u);
ASSERT_EQ(server.domain_type, DnsServer::DomainType::Exclude);
ASSERT_EQ(server.domains[0], "xdom0");
@ -109,13 +109,13 @@ TEST(Dns, Options)
ASSERT_TRUE(server.address4.specified());
ASSERT_EQ(server.address4.to_string(), "3.2.1.0");
ASSERT_EQ(server.port4, 4242);
ASSERT_EQ(server.port4, 4242u);
ASSERT_TRUE(server.address6.specified());
ASSERT_EQ(server.address6.to_string(), "3::3");
ASSERT_EQ(server.port6, 0);
ASSERT_EQ(server.port6, 0u);
ASSERT_EQ(server.domains.size(), 0);
ASSERT_EQ(server.domains.size(), 0u);
ASSERT_EQ(server.domain_type, DnsServer::DomainType::Unset);
ASSERT_EQ(server.dnssec, DnsServer::Security::No);
@ -142,8 +142,8 @@ TEST(Dns, OptionsMerger)
config.update_map();
merger.merge(pushed, config);
ASSERT_EQ(config.size(), 2);
ASSERT_EQ(pushed.size(), 2);
ASSERT_EQ(config.size(), 2u);
ASSERT_EQ(pushed.size(), 2u);
ASSERT_EQ(pushed[0].ref(4), "::1");
ASSERT_EQ(pushed[1].ref(4), "2.2.2.2");
}

View File

@ -45,7 +45,7 @@ TEST(HttpProxyClient, Options)
ASSERT_EQ(po->password, "pazzword");
ASSERT_EQ(po->http_version, "1.1");
ASSERT_EQ(po->user_agent, "Mosaic/0.9");
ASSERT_EQ(po->headers.size(), 1);
ASSERT_EQ(po->headers.size(), 1u);
ASSERT_EQ(po->headers.at(0)->p1, "X-Greeting");
ASSERT_EQ(po->headers.at(0)->p2, "Hi mom!");

View File

@ -73,7 +73,7 @@ TEST(PushedOptionsFilter, RouteNopullEnabled)
dst.extend(src, &route_nopull_enabled);
std::string filter_output(testLog->stopCollecting());
ASSERT_EQ(1, dst.size())
ASSERT_EQ(1u, dst.size())
<< "Too few options have been filtered by --route-nopull" << std::endl
<< filter_output;
@ -168,7 +168,7 @@ TEST(PushedOptionsFilter, PullFilterIgnoreAll)
dst.extend(src, &filter_all);
std::string filter_output(testLog->stopCollecting());
ASSERT_EQ(0, dst.size())
ASSERT_EQ(0u, dst.size())
<< "Not all options have been ignored by --pull-filter" << std::endl
<< filter_output;
}
@ -209,7 +209,7 @@ TEST(PushedOptionsFilter, PullFilterAcceptWhitespace)
dst.extend(src, &accept_opt3);
std::string filter_output(testLog->stopCollecting());
ASSERT_EQ(2, dst.size())
ASSERT_EQ(2u, dst.size())
<< "Not all option3's have been accepted by --pull-filter" << std::endl
<< filter_output;
}
@ -233,7 +233,7 @@ TEST(PushedOptionsFilter, PullFilterIgnoreQuotedWhitespace)
dst.extend(src, &accept_opt2_single_space);
std::string filter_output(testLog->stopCollecting());
ASSERT_EQ(1, dst.size())
ASSERT_EQ(1u, dst.size())
<< "Too many options have been accepted by --pull-filter" << std::endl
<< filter_output;
@ -264,7 +264,7 @@ TEST(PushedOptionsFilter, PullFilterOverrideRouteNopull)
dst.extend(src, &override_route_nopull);
std::string filter_output(testLog->stopCollecting());
ASSERT_EQ(2, dst.size())
ASSERT_EQ(2u, dst.size())
<< "Expected two route option to be accepted" << std::endl
<< filter_output;
@ -275,10 +275,10 @@ TEST(PushedOptionsFilter, PullFilterOverrideRouteNopull)
ASSERT_EQ(dst[1].ref(0), "route")
<< dst[1].ref(0) << " instead of route option has been accepted" << std::endl
<< filter_output;
ASSERT_EQ(3, dst[0].size())
ASSERT_EQ(3u, dst[0].size())
<< "The host route option has been accepted, expected network route" << std::endl
<< filter_output;
ASSERT_EQ(3, dst[1].size())
ASSERT_EQ(3u, dst[1].size())
<< "The host route option has been accepted, expected network route" << std::endl
<< filter_output;
}

View File

@ -160,7 +160,7 @@ TEST(argv, parsetest)
extract_auth_token(opt);
extract_ifconfig(opt);
verify_topology(opt);
ASSERT_EQ(1066, limits.get_bytes());
ASSERT_EQ(1066u, limits.get_bytes());
}
static void csv_test(const std::string &str)

View File

@ -66,7 +66,7 @@ TEST(PeerFingerprint, parse_config)
};
TestPeerFingerprints fps(cfg, test_fingerprint.size());
ASSERT_EQ(fps.size(), 5);
ASSERT_EQ(fps.size(), 5u);
for (std::size_t i = 1; i <= fps.size(); ++i)
{

View File

@ -53,7 +53,7 @@ TEST(IPAddr, test32)
{
const IPv4::Addr::base_type mask = prefix_len_to_netmask(i);
const int pl = prefix_len(mask);
ASSERT_EQ(pl, i);
ASSERT_EQ(pl, (int)i);
// IPv4::Addr a = IPv4::Addr::from_uint32(mask);
// std::cout << i << ' ' << pl << ' ' << a << std::endl;
@ -82,4 +82,4 @@ void testbig() // exhaustive test of all 2^32 possible netmask values
if (++mask == 0)
break;
}
}
}

View File

@ -33,7 +33,7 @@ TEST(relack, test_size_1)
for (auto i = id_t(1); i <= ACK_CNT; ++i)
ra.push_back(i);
EXPECT_EQ(ra.size(), ACK_CNT);
EXPECT_EQ(ra.resend_size(), 0);
EXPECT_EQ(ra.resend_size(), size_t{0});
}
TEST(relack, test_prepend_1)
@ -55,12 +55,12 @@ TEST(relack, test_prepend_1)
// Add 4 packets to a CONTROL packet, should reduce number by 4
ra.prepend(buf, false);
EXPECT_EQ(ra.size(), ACK_CNT - 4);
EXPECT_EQ(ra.resend_size(), 4);
EXPECT_EQ(ra.resend_size(), size_t{4});
// Add packets to an ACK_V1 packet, should reduce number by up to 8
ra.prepend(buf, true);
EXPECT_EQ(ra.size(), 0);
EXPECT_EQ(ra.resend_size(), 8);
EXPECT_EQ(ra.size(), size_t{0});
EXPECT_EQ(ra.resend_size(), size_t{8});
}
{
@ -69,7 +69,7 @@ TEST(relack, test_prepend_1)
ra.prepend(buf, false); // resending should not change array sizes
EXPECT_EQ(ra.size(), size_t{0});
EXPECT_EQ(ra.resend_size(), 8);
EXPECT_EQ(ra.resend_size(), size_t{8});
}
{
@ -78,7 +78,7 @@ TEST(relack, test_prepend_1)
ra.prepend(buf, false);
EXPECT_EQ(ra.size(), size_t{0});
EXPECT_EQ(ra.resend_size(), 8);
EXPECT_EQ(ra.resend_size(), size_t{8});
}
}
@ -134,22 +134,22 @@ TEST(relack, test_ack_2)
auto buf = Buffer(storage, storageSize, false);
buf.init_headroom(storageSize / 2);
EXPECT_EQ(ra.size(), 9);
EXPECT_EQ(ra.resend_size(), 0);
EXPECT_EQ(ra.size(), size_t{9});
EXPECT_EQ(ra.resend_size(), size_t{0});
ra.prepend(buf, true);
EXPECT_EQ(ra.size(), 1);
EXPECT_EQ(ra.resend_size(), 8);
EXPECT_EQ(ra.size(), size_t{1});
EXPECT_EQ(ra.resend_size(), size_t{8});
RelSendMck send{};
auto num = ra.ack(send, buf, false);
EXPECT_EQ(send.mAcks.size(), size_t{0});
EXPECT_EQ(num, 8);
EXPECT_EQ(num, size_t{8});
RelSendMck send2;
ra.prepend(buf, true);
num = ra.ack(send2, buf, true);
EXPECT_EQ(num, 8);
EXPECT_EQ(num, size_t{8});
EXPECT_EQ(send2.mAcks.size(), size_t{8});
}
}

View File

@ -161,7 +161,7 @@ TEST_F(RouteEmulationTest, ExcludeOneSubnet)
doEmulate();
ASSERT_EQ(tb->routes.size(), 24);
ASSERT_EQ(tb->routes.size(), 24u);
}
TEST_F(RouteEmulationTest, ExcludeSubnetsNoDefault)
@ -175,7 +175,7 @@ TEST_F(RouteEmulationTest, ExcludeSubnetsNoDefault)
doEmulate();
ASSERT_EQ(tb->routes.size(), 1);
ASSERT_EQ(tb->routes.size(), 1u);
ASSERT_EQ(tb->routes.at(0), "10.20.128.0/17");
setup(true, false);
@ -186,7 +186,7 @@ TEST_F(RouteEmulationTest, ExcludeSubnetsNoDefault)
doEmulate();
ASSERT_EQ(tb->routes.size(), 1);
ASSERT_EQ(tb->routes.size(), 1u);
ASSERT_EQ(tb->routes.at(0), "2500:1000::/33");
}
@ -196,7 +196,7 @@ TEST_F(RouteEmulationTest, excludeServer)
emu->add_default_routes(true, true);
doEmulate("1.2.3.4");
ASSERT_EQ(tb->routes.size(), 32);
ASSERT_EQ(tb->routes.size(), 32u);
ASSERT_FALSE(tb->containsIP("1.2.3.4"));
ASSERT_TRUE(tb->containsIP("1.2.3.5"));
ASSERT_TRUE(tb->containsIP("1.2.3.3"));
@ -206,7 +206,7 @@ TEST_F(RouteEmulationTest, excludeServer)
emu->add_default_routes(true, true);
doEmulate("::1.2.3.4");
ASSERT_EQ(tb->routes.size(), 128);
ASSERT_EQ(tb->routes.size(), 128u);
ASSERT_FALSE(tb->containsIP("::1.2.3.4"));
ASSERT_TRUE(tb->containsIP("::1.2.3.5"));
ASSERT_TRUE(tb->containsIP("::1.2.3.3"));
@ -278,7 +278,7 @@ TEST_F(RouteEmulationTest, DefaultRoute)
doEmulate();
ASSERT_EQ(tb->routes.size(), 1);
ASSERT_EQ(tb->routes.size(), 1u);
ASSERT_EQ(tb->routes.at(0), "0.0.0.0/0");
// Now something more tricky add unnecessary extra route
@ -289,8 +289,8 @@ TEST_F(RouteEmulationTest, DefaultRoute)
doEmulate();
ASSERT_EQ(tb->routes.size(), 2);
ASSERT_EQ(tb->routes.size(), 2u);
ASSERT_EQ(tb->routes.at(0), "0.0.0.0/0");
}
} // namespace unittests
} // namespace unittests

View File

@ -119,9 +119,9 @@ static void sub(const Time &t1, const Time &t2, bool large)
const Time::Duration d = t1 - t2;
// std::cout << "T-T " << t1.raw() << " - " << t2.raw() << " = " << d.raw() << std::endl;
if (large)
ASSERT_GE(d.raw(), 100000);
ASSERT_GE(d.raw(), 100000u);
else
ASSERT_EQ(d.raw(), 0);
ASSERT_EQ(d.raw(), 0u);
}
static void sub(const Time::Duration &d1, const Time::Duration &d2)

View File

@ -143,7 +143,7 @@ TEST(typeindex, perf_test_fast)
i = 0;
}
OPENVPN_LOG("PERF " << n_strings << '/' << N);
ASSERT_EQ(n_strings, 28571428);
ASSERT_EQ(n_strings, 28571428u);
}
// as a control, test performance of dynamic_cast
@ -166,7 +166,7 @@ TEST(typeindex, perf_test_dynamic)
i = 0;
}
OPENVPN_LOG("PERF " << n_strings << '/' << N);
ASSERT_EQ(n_strings, 28571428);
ASSERT_EQ(n_strings, 28571428u);
}
#endif

View File

@ -196,7 +196,7 @@ void test()
obj->vec.emplace_back(new Ref("Three", obj));
// verify obj
ASSERT_EQ(obj->vec.size(), 3);
ASSERT_EQ(obj->vec.size(), 3u);
ASSERT_EQ(obj->vec.at(0)->to_string(), "I am One whose parent is Regular Joe");
ASSERT_EQ(obj->vec.at(1)->to_string(), "I am Two whose parent is Regular Joe");
ASSERT_EQ(obj->vec.at(2)->to_string(), "I am Three whose parent is Regular Joe");