/* * 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 #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_shell_ok_result) { ExecResult exres; const std::string result = capture_exec (I2n::join_string (zero_bytes_argv, " "), exres); BOOST_CHECK(exres.normal_exit); BOOST_CHECK_EQUAL(exres.return_code, 0); BOOST_CHECK(!exres.terminated_by_signal); 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_CASE(abspath_zeros_noshell_ok_strvec) { std::vector argvec; const char *const *argp = zero_bytes_argv; const char * cur = NULL; while ((cur = *argp++) != NULL) { argvec.push_back (std::string (cur)); } const std::string result = capture_exec (argvec); BOOST_CHECK_EQUAL(result.size (), ENOUGH_ZEROS); } BOOST_AUTO_TEST_CASE(abspath_zeros_noshell_ok_result) { ExecResult exres; const std::string result = capture_exec (zero_bytes_argv, exres); BOOST_CHECK(exres.normal_exit); BOOST_CHECK_EQUAL(exres.return_code, 0); BOOST_CHECK(!exres.terminated_by_signal); BOOST_CHECK_EQUAL(result.size (), ENOUGH_ZEROS); } BOOST_AUTO_TEST_SUITE_END() /* [pipestream->read] */ BOOST_AUTO_TEST_SUITE_END() /* [pipestream] */