From: Francis Dupont Date: Wed, 1 Mar 2017 22:53:42 +0000 (+0100) Subject: [4501] Added unit tests for unused headers/classes/exceptions X-Git-Tag: trac5087_base~2^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb2d54a29140471d8053e2af99817ff0278d4ccb;p=thirdparty%2Fkea.git [4501] Added unit tests for unused headers/classes/exceptions --- diff --git a/src/lib/cc/tests/data_unittests.cc b/src/lib/cc/tests/data_unittests.cc index 1c8054a800..bc83927ffe 100644 --- a/src/lib/cc/tests/data_unittests.cc +++ b/src/lib/cc/tests/data_unittests.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2009-2016 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2009-2017 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -100,7 +100,7 @@ TEST(Element, from_and_to_json) { BOOST_FOREACH(const std::string& s, sv) { // Test two types of fromJSON(): with string and istream. - for (int i = 0; i < 2; ++i) { + for (unsigned i = 0; i < 2; ++i) { // test << operator, which uses Element::str() if (i == 0) { el = Element::fromJSON(s); @@ -555,6 +555,12 @@ TEST(Element, escape) { EXPECT_NO_THROW(Element::fromJSON("\"\\\"\\\"\"")); // A whitespace test EXPECT_NO_THROW(Element::fromJSON("\" \n \r \t \f \n \n \t\"")); + // Escape for forward slash is optional + ASSERT_NO_THROW(Element::fromJSON("\"foo\\/bar\"")); + EXPECT_EQ("foo/bar", Element::fromJSON("\"foo\\/bar\"")->stringValue()); + // Control characters + StringElement bell("foo\abar"); + EXPECT_EQ("\"foo\\u0007bar\"", bell.str()); } // This test verifies that a backslash can be used in element content @@ -655,6 +661,12 @@ TEST(Element, MapElement) { el->set(long_maptag, Element::create("bar")); EXPECT_EQ("bar", el->find(long_maptag)->stringValue()); + // Null pointer value + el.reset(new MapElement()); + ConstElementPtr null_ptr; + el->set("value", null_ptr); + EXPECT_FALSE(el->get("value")); + EXPECT_EQ("{ \"value\": None }", el->str()); } TEST(Element, to_and_from_wire) { @@ -857,8 +869,9 @@ TEST(Element, constRemoveIdentical) { c = Element::fromJSON("{ \"a\": 1 }"); EXPECT_EQ(*removeIdentical(a, b), *c); - EXPECT_THROW(removeIdentical(Element::create(1), Element::create(2)), - TypeError); + // removeIdentical() is overloaded so force the first argument to const + ConstElementPtr bad = Element::create(1); + EXPECT_THROW(removeIdentical(bad, Element::create(2)), TypeError); } TEST(Element, merge) { @@ -999,6 +1012,10 @@ TEST(Element, preprocessor) { EXPECT_THROW(Element::fromJSON(dbl_head_comment), JSONError); EXPECT_THROW(Element::fromJSON(dbl_mid_comment), JSONError); EXPECT_THROW(Element::fromJSON(dbl_tail_comment), JSONError); + + // For coverage + std::istringstream iss(no_comment); + EXPECT_TRUE(exp->equals(*Element::fromJSON(iss, true))); } TEST(Element, getPosition) { diff --git a/src/lib/dhcpsrv/tests/host_mgr_unittest.cc b/src/lib/dhcpsrv/tests/host_mgr_unittest.cc index 8e922d355d..71c432cf70 100644 --- a/src/lib/dhcpsrv/tests/host_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/host_mgr_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2016 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -388,6 +388,18 @@ TEST_F(HostMgrTest, get6ByPrefix) { testGet6ByPrefix(*getCfgHosts(), *getCfgHosts()); } +// This test verifies that without a host data source an exception is thrown. +TEST_F(HostMgrTest, addNoDataSource) { + // Remove all configuration. + CfgMgr::instance().clear(); + // Recreate HostMgr instance. + HostMgr::create(); + + HostPtr host(new Host(hwaddrs_[0]->toText(false), "hw-address", + SubnetID(1), SubnetID(0), IOAddress("192.0.2.5"))); + EXPECT_THROW(HostMgr::instance().add(host), NoHostDataSourceManager); +} + // The following tests require MySQL enabled. #if defined HAVE_MYSQL diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc index f52f2c1bd3..cb7ba0e36d 100644 --- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2016 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -375,6 +375,12 @@ TEST_F(MemfileLeaseMgrTest, constructor) { EXPECT_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)), isc::BadValue); } +// Checks if there is no lease manager NoLeaseManager is thrown. +TEST_F(MemfileLeaseMgrTest, noLeaseManager) { + LeaseMgrFactory::destroy(); + EXPECT_THROW(LeaseMgrFactory::instance(), NoLeaseManager); +} + // Checks if the getType() and getName() methods both return "memfile". TEST_F(MemfileLeaseMgrTest, getTypeAndName) { startBackend(V4); diff --git a/src/lib/dns/tests/dns_exceptions_unittest.cc b/src/lib/dns/tests/dns_exceptions_unittest.cc index bef41628e6..10ea1ef644 100644 --- a/src/lib/dns/tests/dns_exceptions_unittest.cc +++ b/src/lib/dns/tests/dns_exceptions_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2014-2015,2017 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -42,6 +42,7 @@ TEST(DNSExceptionsTest, checkExceptionsHierarchy) { const isc::dns::Exception& exception_cast2 = dynamic_cast(exception); // to avoid compiler warning + exception_cast.getRcode(); exception_cast.what(); exception_cast2.what(); }); @@ -53,6 +54,7 @@ TEST(DNSExceptionsTest, checkExceptionsHierarchy) { const isc::dns::Exception& exception_cast2 = dynamic_cast(exception); // to avoid compiler warning + exception_cast.getRcode(); exception_cast.what(); exception_cast2.what(); }); diff --git a/src/lib/hooks/tests/library_manager_unittest.cc b/src/lib/hooks/tests/library_manager_unittest.cc index 367ceb9430..1aa446d085 100644 --- a/src/lib/hooks/tests/library_manager_unittest.cc +++ b/src/lib/hooks/tests/library_manager_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -128,6 +128,13 @@ public: }; +// Check that LibraryManager constructor requires a not null manager + +TEST_F(LibraryManagerTest, NullManager) { + EXPECT_THROW(PublicLibraryManager(std::string("foo"), 0, 0), + NoCalloutManager); +} + // Check that openLibrary() reports an error when it can't find the specified // library. diff --git a/src/lib/util/tests/process_spawn_unittest.cc b/src/lib/util/tests/process_spawn_unittest.cc index 30533730f4..1dc894d202 100644 --- a/src/lib/util/tests/process_spawn_unittest.cc +++ b/src/lib/util/tests/process_spawn_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2015,2017 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -90,6 +90,21 @@ bool waitForProcessFast(const ProcessSpawn& process, const pid_t pid, return (true); } +// This test verifies that if the thread calling spawn has SIGCHLD +// already block ProcessSpawnError is thrown (@todo the second error +// case: fork() failling) +TEST(ProcessSpawn, sigchldBlocked) { + std::vector args; + ProcessSpawn process(getApp(), args); + sigset_t sset; + sigemptyset(&sset); + sigaddset(&sset, SIGCHLD); + sigset_t osset; + pthread_sigmask(SIG_BLOCK, &sset, &osset); + EXPECT_THROW(process.spawn(), ProcessSpawnError); + sigprocmask(SIG_SETMASK, &osset, 0); +} + // This test verifies that the external application can be ran with // arguments and that the exit code is gathered. TEST(ProcessSpawn, spawnWithArgs) {