add unit test series for pipestream
[libi2ncommon] / test / test_pipestream.cpp
CommitLineData
3ed2cc9b
PG
1/*
2 * The software in this package is distributed under the GNU General
3 * Public License version 2 (with a special exception described below).
4 *
5 * A copy of GNU General Public License (GPL) is included in this distribution,
6 * in the file COPYING.GPL.
7 *
8 * As a special exception, if other files instantiate templates or use macros
9 * or inline functions from this file, or you compile this file and link it
10 * with other works to produce a work based on this file, this file
11 * does not by itself cause the resulting work to be covered
12 * by the GNU General Public License.
13 *
14 * However the source code for this file must still be made available
15 * in accordance with section (3) of the GNU General Public License.
16 *
17 * This exception does not invalidate any other reasons why a work based
18 * on this file might be covered by the GNU General Public License.
19 *
20 * @file
21 *
22 * unit tests for the module "pipestream"
23 *
24 * Copyright 2018 by Intra2net AG
25 */
26
27
28#define BOOST_TEST_DYN_LINK
29#include <boost/test/unit_test.hpp>
30#include <boost/algorithm/string/replace.hpp>
31
32#include "stringfunc.hxx"
33#include "pipestream.hxx"
34
35#define TO_CHARP_TOK(x) #x
36#define TO_CHARP(x) TO_CHARP_TOK(x)
37
38BOOST_AUTO_TEST_SUITE(pipestream)
39
40 BOOST_AUTO_TEST_SUITE(read)
41
42 # define ENOUGH_ZEROS 42
43 const char *const zero_bytes_argv [] =
44 { "/usr/bin/head", "-c", TO_CHARP(ENOUGH_ZEROS), "/dev/zero", NULL };
45
46 BOOST_AUTO_TEST_CASE(abspath_zeros_shell_ok)
47 {
48 const std::string result =
49 capture_exec (I2n::join_string (zero_bytes_argv, " "));
50
51 BOOST_CHECK_EQUAL(result.size (), ENOUGH_ZEROS);
52 }
53
54 BOOST_AUTO_TEST_CASE(abspath_zeros_noshell_ok)
55 {
56 const std::string result = capture_exec (zero_bytes_argv);
57
58 BOOST_CHECK_EQUAL(result.size (), ENOUGH_ZEROS);
59 }
60
61 BOOST_AUTO_TEST_SUITE_END() /* [pipestream->read] */
62
63BOOST_AUTO_TEST_SUITE_END() /* [pipestream] */
64