xref: /minix3/external/bsd/bind/dist/unit/atf-src/atf-c++/utils.hpp (revision 00b67f09dd46474d133c95011a48590a8e8f94c7)
1*00b67f09SDavid van Moolenbroek //
2*00b67f09SDavid van Moolenbroek // Automated Testing Framework (atf)
3*00b67f09SDavid van Moolenbroek //
4*00b67f09SDavid van Moolenbroek // Copyright (c) 2007 The NetBSD Foundation, Inc.
5*00b67f09SDavid van Moolenbroek // All rights reserved.
6*00b67f09SDavid van Moolenbroek //
7*00b67f09SDavid van Moolenbroek // Redistribution and use in source and binary forms, with or without
8*00b67f09SDavid van Moolenbroek // modification, are permitted provided that the following conditions
9*00b67f09SDavid van Moolenbroek // are met:
10*00b67f09SDavid van Moolenbroek // 1. Redistributions of source code must retain the above copyright
11*00b67f09SDavid van Moolenbroek //    notice, this list of conditions and the following disclaimer.
12*00b67f09SDavid van Moolenbroek // 2. Redistributions in binary form must reproduce the above copyright
13*00b67f09SDavid van Moolenbroek //    notice, this list of conditions and the following disclaimer in the
14*00b67f09SDavid van Moolenbroek //    documentation and/or other materials provided with the distribution.
15*00b67f09SDavid van Moolenbroek //
16*00b67f09SDavid van Moolenbroek // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17*00b67f09SDavid van Moolenbroek // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18*00b67f09SDavid van Moolenbroek // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19*00b67f09SDavid van Moolenbroek // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20*00b67f09SDavid van Moolenbroek // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21*00b67f09SDavid van Moolenbroek // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*00b67f09SDavid van Moolenbroek // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23*00b67f09SDavid van Moolenbroek // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*00b67f09SDavid van Moolenbroek // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25*00b67f09SDavid van Moolenbroek // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26*00b67f09SDavid van Moolenbroek // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27*00b67f09SDavid van Moolenbroek // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*00b67f09SDavid van Moolenbroek //
29*00b67f09SDavid van Moolenbroek 
30*00b67f09SDavid van Moolenbroek #if !defined(_ATF_CXX_UTILS_HPP_)
31*00b67f09SDavid van Moolenbroek #define _ATF_CXX_UTILS_HPP_
32*00b67f09SDavid van Moolenbroek 
33*00b67f09SDavid van Moolenbroek extern "C" {
34*00b67f09SDavid van Moolenbroek #include <unistd.h>
35*00b67f09SDavid van Moolenbroek }
36*00b67f09SDavid van Moolenbroek 
37*00b67f09SDavid van Moolenbroek #include <string>
38*00b67f09SDavid van Moolenbroek 
39*00b67f09SDavid van Moolenbroek namespace atf {
40*00b67f09SDavid van Moolenbroek namespace utils {
41*00b67f09SDavid van Moolenbroek 
42*00b67f09SDavid van Moolenbroek void cat_file(const std::string&, const std::string&);
43*00b67f09SDavid van Moolenbroek bool compare_file(const std::string&, const std::string&);
44*00b67f09SDavid van Moolenbroek void copy_file(const std::string&, const std::string&);
45*00b67f09SDavid van Moolenbroek void create_file(const std::string&, const std::string&);
46*00b67f09SDavid van Moolenbroek bool file_exists(const std::string&);
47*00b67f09SDavid van Moolenbroek pid_t fork(void);
48*00b67f09SDavid van Moolenbroek bool grep_file(const std::string&, const std::string&);
49*00b67f09SDavid van Moolenbroek bool grep_string(const std::string&, const std::string&);
50*00b67f09SDavid van Moolenbroek void redirect(const int, const std::string&);
51*00b67f09SDavid van Moolenbroek void wait(const pid_t, const int, const std::string&, const std::string&);
52*00b67f09SDavid van Moolenbroek 
53*00b67f09SDavid van Moolenbroek template< typename Collection >
54*00b67f09SDavid van Moolenbroek bool
grep_collection(const std::string & regexp,const Collection & collection)55*00b67f09SDavid van Moolenbroek grep_collection(const std::string& regexp, const Collection& collection)
56*00b67f09SDavid van Moolenbroek {
57*00b67f09SDavid van Moolenbroek     for (typename Collection::const_iterator iter = collection.begin();
58*00b67f09SDavid van Moolenbroek          iter != collection.end(); ++iter) {
59*00b67f09SDavid van Moolenbroek         if (grep_string(regexp, *iter))
60*00b67f09SDavid van Moolenbroek             return true;
61*00b67f09SDavid van Moolenbroek     }
62*00b67f09SDavid van Moolenbroek     return false;
63*00b67f09SDavid van Moolenbroek }
64*00b67f09SDavid van Moolenbroek 
65*00b67f09SDavid van Moolenbroek } // namespace utils
66*00b67f09SDavid van Moolenbroek } // namespace atf
67*00b67f09SDavid van Moolenbroek 
68*00b67f09SDavid van Moolenbroek #endif // !defined(_ATF_CXX_UTILS_HPP_)
69