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