Browse Source

[3929] Added basic unittests to src/lib/cfgrpt

Thomas Markwalder 9 years ago
parent
commit
37a9566461

+ 1 - 0
configure.ac

@@ -1442,6 +1442,7 @@ AC_CONFIG_FILES([compatcheck/Makefile
                  src/lib/cc/Makefile
                  src/lib/cc/tests/Makefile
                  src/lib/cfgrpt/Makefile
+                 src/lib/cfgrpt/tests/Makefile
                  src/lib/config/Makefile
                  src/lib/config/tests/Makefile
                  src/lib/config/tests/data_def_unittests_config.h

+ 1 - 0
src/lib/cfgrpt/Makefile.am

@@ -1,3 +1,4 @@
+SUBDIRS = . tests
 AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_builddir)/src/lib
 
 # Get rid of generated message files on a clean

+ 2 - 0
src/lib/cfgrpt/config_report.h

@@ -15,6 +15,8 @@
 #ifndef CONFIG_REPORT_H
 #define CONFIG_REPORT_H
 
+#include <string>
+
 namespace isc {
 namespace detail {
 

+ 31 - 0
src/lib/cfgrpt/tests/Makefile.am

@@ -0,0 +1,31 @@
+SUBDIRS = .
+
+AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
+AM_CPPFLAGS += $(BOOST_INCLUDES)
+AM_CPPFLAGS += -DTEST_DATA_DIR=\"$(abs_top_srcdir)/src/lib/testutils/testdata\"
+AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/lib/config/tests\"
+
+AM_CXXFLAGS = $(KEA_CXXFLAGS)
+
+if USE_STATIC_LINK
+AM_LDFLAGS = -static
+endif
+
+CLEANFILES = *.gcno *.gcda
+
+TESTS_ENVIRONMENT = \
+	$(LIBTOOL) --mode=execute $(VALGRIND_COMMAND)
+
+TESTS =
+if HAVE_GTEST
+TESTS += run_unittests
+run_unittests_SOURCES = config_report_unittests.cc run_unittests.cc
+
+run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
+run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
+run_unittests_LDADD =  $(GTEST_LDADD)
+run_unittests_LDADD += $(top_builddir)/src/lib/cfgrpt/libcfgrpt.la
+
+endif
+
+noinst_PROGRAMS = $(TESTS)

+ 34 - 0
src/lib/cfgrpt/tests/config_report_unittests.cc

@@ -0,0 +1,34 @@
+// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <config.h>
+#include <cfgrpt/config_report.h>
+
+#include <gtest/gtest.h>
+
+using namespace isc;
+using namespace std;
+
+// This test verifies that the getConfigReport() function
+// returns the actual config report.
+TEST(ConfigReportTest, getConfigReport) {
+
+    // Fetch the report string
+    std::string cfgReport = isc::detail::getConfigReport();
+
+    // Verify that it is not empty and does contain the
+    // extended version number
+    ASSERT_FALSE(cfgReport.empty());
+    EXPECT_NE(std::string::npos, cfgReport.find(EXTENDED_VERSION, 0));
+}

+ 24 - 0
src/lib/cfgrpt/tests/run_unittests.cc

@@ -0,0 +1,24 @@
+// Copyright (C) 2015  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <gtest/gtest.h>
+
+int
+main(int argc, char* argv[]) {
+    ::testing::InitGoogleTest(&argc, argv);
+
+    int result = RUN_ALL_TESTS();
+
+    return (result);
+}