From: Francis Dupont Date: Thu, 2 Mar 2017 01:11:04 +0000 (+0100) Subject: [4501] Some attempts to improve coverage X-Git-Tag: trac5087_base~2^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=794ed2589a8c878cd3f237d7203477909638f96f;p=thirdparty%2Fkea.git [4501] Some attempts to improve coverage --- diff --git a/src/bin/d2/d2_queue_mgr.h b/src/bin/d2/d2_queue_mgr.h index 0a8d9c3a63..bea279cdc3 100644 --- a/src/bin/d2/d2_queue_mgr.h +++ b/src/bin/d2/d2_queue_mgr.h @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2013-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 @@ -33,6 +33,7 @@ public: /// @brief Thrown if the queue manager's receive handler is passed /// a failure result. +/// @todo use or remove it. class D2QueueMgrReceiveError : public isc::Exception { public: D2QueueMgrReceiveError(const char* file, size_t line, const char* what) : @@ -41,6 +42,7 @@ public: /// @brief Thrown if the request queue is full when an enqueue is attempted. +/// @todo use or remove it. class D2QueueMgrQueueFull : public isc::Exception { public: D2QueueMgrQueueFull(const char* file, size_t line, const char* what) : diff --git a/src/bin/d2/tests/d2_cfg_mgr_unittests.cc b/src/bin/d2/tests/d2_cfg_mgr_unittests.cc index 3f56dd578a..41406cd2b0 100644 --- a/src/bin/d2/tests/d2_cfg_mgr_unittests.cc +++ b/src/bin/d2/tests/d2_cfg_mgr_unittests.cc @@ -1337,6 +1337,7 @@ TEST_F(D2CfgMgrTest, fullConfig) { // Verify that the forward manager can be retrieved. DdnsDomainListMgrPtr mgr = context->getForwardMgr(); ASSERT_TRUE(mgr); + EXPECT_EQ("forward-ddns", mgr->getName()); // Verify that the forward manager has the correct number of domains. DdnsDomainMapPtr domains = mgr->getDomains(); @@ -1360,6 +1361,7 @@ TEST_F(D2CfgMgrTest, fullConfig) { // Verify that the reverse manager can be retrieved. mgr = context->getReverseMgr(); ASSERT_TRUE(mgr); + EXPECT_EQ("reverse-ddns", mgr->getName()); // Verify that the reverse manager has the correct number of domains. domains = mgr->getDomains(); diff --git a/src/bin/d2/tests/d2_zone_unittests.cc b/src/bin/d2/tests/d2_zone_unittests.cc index 794d965d43..486bed4798 100644 --- a/src/bin/d2/tests/d2_zone_unittests.cc +++ b/src/bin/d2/tests/d2_zone_unittests.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2013-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 @@ -7,6 +7,7 @@ #include #include #include +#include using namespace std; using namespace isc; @@ -41,6 +42,21 @@ TEST(D2ZoneTest, toText) { EXPECT_EQ("foo.example.com. IN SOA\n", zone2.toText()); } + // Same than for toText() but using the << operator. +TEST(D2ZoneTest, output) { + // Create first object. + D2Zone zone1(Name("example.com"), RRClass::ANY()); + ostringstream ss; + ss << zone1; + EXPECT_EQ("example.com. ANY SOA\n", ss.str()); + // Create another object with different parameters to make sure that the + // function's output changes accordingly. + D2Zone zone2(Name("foo.example.com"), RRClass::IN()); + ostringstream ss2; + ss2 << zone2; + EXPECT_EQ("foo.example.com. IN SOA\n", ss2.str()); +} + // This test verifies that the equality and inequality operators behave as // expected. TEST(D2ZoneTest, compare) { diff --git a/src/bin/lfc/lfc_controller.cc b/src/bin/lfc/lfc_controller.cc index dacf9e3154..1bc9ae8c29 100644 --- a/src/bin/lfc/lfc_controller.cc +++ b/src/bin/lfc/lfc_controller.cc @@ -150,7 +150,7 @@ LFCController::parseArgs(int argc, char* argv[]) { opterr = 0; optind = 1; - while ((ch = getopt(argc, argv, ":46dvVWp:x:i:o:c:f:")) != -1) { + while ((ch = getopt(argc, argv, ":46dhvVWp:x:i:o:c:f:")) != -1) { switch (ch) { case '4': // Process DHCPv4 lease files. @@ -236,6 +236,7 @@ LFCController::parseArgs(int argc, char* argv[]) { case '?': // Unknown argument + // note this will catch all the prevous ... name missing isc_throw(InvalidUsage, "Unknown argument"); case ':': diff --git a/src/bin/lfc/tests/lfc_controller_unittests.cc b/src/bin/lfc/tests/lfc_controller_unittests.cc index 76a80ddb38..d324780f30 100644 --- a/src/bin/lfc/tests/lfc_controller_unittests.cc +++ b/src/bin/lfc/tests/lfc_controller_unittests.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 @@ -145,6 +145,30 @@ TEST_F(LFCControllerTest, initialValues) { EXPECT_TRUE(lfc_controller.getPidFile().empty()); } +/// @brief Verify that parsing -v/V/W/h works well. +TEST_F(LFCControllerTest, version) { + LFCController lfc_controller; + + int argc = 2; + char *argv_v[] = { const_cast("progName"), + const_cast("-v") }; + char *argv_V[] = { const_cast("progName"), + const_cast("-V") }; + char *argv_W[] = { const_cast("progName"), + const_cast("-W") }; + char *argv_h[] = { const_cast("progName"), + const_cast("-h") }; + + ASSERT_EXIT(lfc_controller.parseArgs(argc, argv_v), + ::testing::ExitedWithCode(0), ""); + ASSERT_EXIT(lfc_controller.parseArgs(argc, argv_V), + ::testing::ExitedWithCode(0), ""); + ASSERT_EXIT(lfc_controller.parseArgs(argc, argv_W), + ::testing::ExitedWithCode(0), ""); + ASSERT_EXIT(lfc_controller.parseArgs(argc, argv_h), + ::testing::ExitedWithCode(0), "Usage"); +} + /// @brief Verify that parsing a full command line works. /// Parse a complete command line then verify the parsed /// and saved data matches our expectations. @@ -663,4 +687,6 @@ TEST_F(LFCControllerTest, launch6) { EXPECT_TRUE(noExistIOFP()); } +// @todo double launch (how to do that) + } // end of anonymous namespace diff --git a/src/lib/exceptions/tests/exceptions_unittest.cc b/src/lib/exceptions/tests/exceptions_unittest.cc index 381b84eb02..e2e632b91b 100644 --- a/src/lib/exceptions/tests/exceptions_unittest.cc +++ b/src/lib/exceptions/tests/exceptions_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2009-2015 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2009-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 @@ -36,6 +36,17 @@ TEST_F(ExceptionTest, basicMethods) { } } +// Same than basicMethods but using a string (vs char *) +TEST_F(ExceptionTest, string) { + try { + isc_throw(Exception, std::string(teststring)); + } catch (Exception& ex) { + EXPECT_EQ(ex.getMessage(), std::string(teststring)); + EXPECT_EQ(ex.getFile(), std::string(__FILE__)); + EXPECT_EQ(ex.getLine(), __LINE__ - 4); + } +} + // Test to see if it works as a proper derived class of std::exception. TEST_F(ExceptionTest, stdInheritance) { try { diff --git a/src/lib/log/interprocess/tests/interprocess_sync_file_unittest.cc b/src/lib/log/interprocess/tests/interprocess_sync_file_unittest.cc index 5118fa482e..d80f288be3 100644 --- a/src/lib/log/interprocess/tests/interprocess_sync_file_unittest.cc +++ b/src/lib/log/interprocess/tests/interprocess_sync_file_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2012-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 @@ -18,6 +18,14 @@ using namespace isc::log::interprocess; using isc::util::unittests::parentReadState; namespace { +TEST(InterprocessSyncFileTest, BadFile) { + InterprocessSyncFile sync("/no-such--dir/or--file"); + InterprocessSyncLocker locker(sync); + + EXPECT_FALSE(locker.isLocked()); + ASSERT_THROW(locker.lock(), InterprocessSyncFileError); +} + TEST(InterprocessSyncFileTest, TestLock) { InterprocessSyncFile sync("test"); InterprocessSyncLocker locker(sync);