]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[4501] Some attempts to improve coverage
authorFrancis Dupont <fdupont@isc.org>
Thu, 2 Mar 2017 01:11:04 +0000 (02:11 +0100)
committerFrancis Dupont <fdupont@isc.org>
Thu, 2 Mar 2017 01:11:04 +0000 (02:11 +0100)
src/bin/d2/d2_queue_mgr.h
src/bin/d2/tests/d2_cfg_mgr_unittests.cc
src/bin/d2/tests/d2_zone_unittests.cc
src/bin/lfc/lfc_controller.cc
src/bin/lfc/tests/lfc_controller_unittests.cc
src/lib/exceptions/tests/exceptions_unittest.cc
src/lib/log/interprocess/tests/interprocess_sync_file_unittest.cc

index 0a8d9c3a63e1a7a057a4318ff31cbfdf5426f192..bea279cdc35e50fdf28e0775a27c7ec543f6c4d6 100644 (file)
@@ -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) :
index 3f56dd578ad1be8be5ce6e29bf96882099a54c9f..41406cd2b00306cb4a170b7fe7265a8826b57812 100644 (file)
@@ -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();
index 794d965d43d2fc834f25af1a758c8f9292323f3e..486bed4798532b70550d3ffe8af8ffb0d8b52831 100644 (file)
@@ -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 <config.h>
 #include <d2/d2_zone.h>
 #include <gtest/gtest.h>
+#include <sstream>
 
 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) {
index dacf9e3154745a72d64fbb91869e0cb1a952a87e..1bc9ae8c29a2fcc72cb3cd9bc00a9ef08657c069 100644 (file)
@@ -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 ':':
index 76a80ddb388f02fa1acaf07a978c238288020048..d324780f3062d3891d44e85eda27a1e728093d2d 100644 (file)
@@ -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<char*>("progName"),
+                      const_cast<char*>("-v") };
+    char *argv_V[] = { const_cast<char*>("progName"),
+                      const_cast<char*>("-V") };
+    char *argv_W[] = { const_cast<char*>("progName"),
+                      const_cast<char*>("-W") };
+    char *argv_h[] = { const_cast<char*>("progName"),
+                      const_cast<char*>("-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
index 381b84eb028035caf3ca936ab3507a2995da9b45..e2e632b91bc4f63bf3e03be1c9cd660a45c57d22 100644 (file)
@@ -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 {
index 5118fa482ee05a655a691280a432c39fff24ba19..d80f288be36bb91afe13a4b85ba18b6926d0c333 100644 (file)
@@ -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);