add unit test series for pipestream
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Tue, 2 Jan 2018 15:13:30 +0000 (16:13 +0100)
committerPhilipp Gesang <philipp.gesang@intra2net.com>
Mon, 13 Aug 2018 13:14:33 +0000 (15:14 +0200)
Setup skeleton unit test file with some simple functionality
tests and include it in a normal run. There haven't been any
pipestream tests so far.

test/CMakeLists.txt
test/test_pipestream.cpp [new file with mode: 0644]

index 2928716..ecd259b 100644 (file)
@@ -17,6 +17,7 @@ SET(cpp_sources
    test_logging.cpp
    test_pidfile.cpp
    test_restricted_html.cpp
+   test_pipestream.cpp
    test_timefunc.cpp
    test_tmpfstream.cpp
    test_tribool.cpp
diff --git a/test/test_pipestream.cpp b/test/test_pipestream.cpp
new file mode 100644 (file)
index 0000000..a58c89a
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ *  The software in this package is distributed under the GNU General
+ *  Public License version 2 (with a special exception described below).
+ *
+ *  A copy of GNU General Public License (GPL) is included in this distribution,
+ *  in the file COPYING.GPL.
+ *
+ *  As a special exception, if other files instantiate templates or use macros
+ *  or inline functions from this file, or you compile this file and link it
+ *  with other works to produce a work based on this file, this file
+ *  does not by itself cause the resulting work to be covered
+ *  by the GNU General Public License.
+ *
+ *  However the source code for this file must still be made available
+ *  in accordance with section (3) of the GNU General Public License.
+ *
+ *  This exception does not invalidate any other reasons why a work based
+ *  on this file might be covered by the GNU General Public License.
+ *
+ * @file
+ *
+ * unit tests for the module "pipestream"
+ *
+ * Copyright 2018 by Intra2net AG
+ */
+
+
+#define BOOST_TEST_DYN_LINK
+#include <boost/test/unit_test.hpp>
+#include <boost/algorithm/string/replace.hpp>
+
+#include "stringfunc.hxx"
+#include "pipestream.hxx"
+
+#define TO_CHARP_TOK(x) #x
+#define TO_CHARP(x) TO_CHARP_TOK(x)
+
+BOOST_AUTO_TEST_SUITE(pipestream)
+
+    BOOST_AUTO_TEST_SUITE(read)
+
+        # define ENOUGH_ZEROS 42
+        const char *const zero_bytes_argv [] =
+                { "/usr/bin/head", "-c", TO_CHARP(ENOUGH_ZEROS), "/dev/zero", NULL };
+
+        BOOST_AUTO_TEST_CASE(abspath_zeros_shell_ok)
+        {
+            const std::string result =
+                    capture_exec (I2n::join_string (zero_bytes_argv, " "));
+
+            BOOST_CHECK_EQUAL(result.size (), ENOUGH_ZEROS);
+        }
+
+        BOOST_AUTO_TEST_CASE(abspath_zeros_noshell_ok)
+        {
+            const std::string result = capture_exec (zero_bytes_argv);
+
+            BOOST_CHECK_EQUAL(result.size (), ENOUGH_ZEROS);
+        }
+
+    BOOST_AUTO_TEST_SUITE_END() /* [pipestream->read] */
+
+BOOST_AUTO_TEST_SUITE_END() /* [pipestream] */
+