testNetDb.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9#include "squid.h"
10#include "compat/cppunit.h"
11#include "icmp/net_db.h"
12#include "unitTestMain.h"
13
14class TestNetDb : public CPPUNIT_NS::TestFixture
15{
17 /* note the statement here and then the actual prototype below */
20
21public:
22protected:
23 void testConstruct();
24};
25
27
28void
30{
31 // default construct and destruct
32 {
33 netdbEntry T;
34 CPPUNIT_ASSERT_EQUAL(T.network[0], '\0');
35 CPPUNIT_ASSERT_EQUAL(0, T.pings_sent);
36 CPPUNIT_ASSERT_EQUAL(0, T.pings_recv);
37 CPPUNIT_ASSERT_EQUAL(0.0, T.hops);
38 CPPUNIT_ASSERT_EQUAL(1.0, T.rtt);
39 CPPUNIT_ASSERT_EQUAL(static_cast<time_t>(0), T.next_ping_time);
40 CPPUNIT_ASSERT_EQUAL(static_cast<time_t>(0), T.last_use_time);
41 CPPUNIT_ASSERT_EQUAL(0, T.link_count);
42 CPPUNIT_ASSERT_EQUAL(static_cast<net_db_name*>(nullptr), T.hosts);
43 CPPUNIT_ASSERT_EQUAL(static_cast<net_db_peer*>(nullptr), T.peers);
44 CPPUNIT_ASSERT_EQUAL(0, T.n_peers_alloc);
45 CPPUNIT_ASSERT_EQUAL(0, T.n_peers);
46 }
47
48 // new and delete operations
49 {
50 netdbEntry *T = new netdbEntry;
51 CPPUNIT_ASSERT_EQUAL(T->network[0], '\0');
52 CPPUNIT_ASSERT_EQUAL(0, T->pings_sent);
53 CPPUNIT_ASSERT_EQUAL(0, T->pings_recv);
54 CPPUNIT_ASSERT_EQUAL(0.0, T->hops);
55 CPPUNIT_ASSERT_EQUAL(1.0, T->rtt);
56 CPPUNIT_ASSERT_EQUAL(static_cast<time_t>(0), T->next_ping_time);
57 CPPUNIT_ASSERT_EQUAL(static_cast<time_t>(0), T->last_use_time);
58 CPPUNIT_ASSERT_EQUAL(0, T->link_count);
59 CPPUNIT_ASSERT_EQUAL(static_cast<net_db_name*>(nullptr), T->hosts);
60 CPPUNIT_ASSERT_EQUAL(static_cast<net_db_peer*>(nullptr), T->peers);
61 CPPUNIT_ASSERT_EQUAL(0, T->n_peers_alloc);
62 CPPUNIT_ASSERT_EQUAL(0, T->n_peers);
63 delete T;
64 }
65}
66
67int
68main(int argc, char *argv[])
69{
70 return TestProgram().run(argc, argv);
71}
72
CPPUNIT_TEST_SUITE_END()
CPPUNIT_TEST(testConstruct)
void testConstruct()
Definition: testNetDb.cc:29
CPPUNIT_TEST_SUITE(TestNetDb)
implements test program's main() function while enabling customization
Definition: unitTestMain.h:26
int run(int argc, char *argv[])
Definition: unitTestMain.h:44
int link_count
Definition: net_db.h:63
char network[MAX_IPSTRLEN]
Definition: net_db.h:56
double hops
Definition: net_db.h:59
int pings_recv
Definition: net_db.h:58
int n_peers_alloc
Definition: net_db.h:66
net_db_peer * peers
Definition: net_db.h:65
int pings_sent
Definition: net_db.h:57
time_t next_ping_time
Definition: net_db.h:61
time_t last_use_time
Definition: net_db.h:62
net_db_name * hosts
Definition: net_db.h:64
int n_peers
Definition: net_db.h:67
double rtt
Definition: net_db.h:60
int main(int argc, char *argv[])
Definition: testNetDb.cc:68
CPPUNIT_TEST_SUITE_REGISTRATION(TestNetDb)

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors