source: trunk/debathena/third/schroot/test/sbuild-run-parts.cc @ 24314

Revision 24314, 3.0 KB checked in by geofft, 14 years ago (diff)
In schroot: * Merge with Debian unstable; remaining changes: - Backport to Karmic, and adjust build-deps.
Line 
1/* Copyright © 2006-2007  Roger Leigh <rleigh@debian.org>
2 *
3 * schroot is free software: you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * schroot is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program.  If not, see
15 * <http://www.gnu.org/licenses/>.
16 *
17 *********************************************************************/
18
19#include <sbuild/sbuild-nostream.h>
20#include <sbuild/sbuild-run-parts.h>
21#include <sbuild/sbuild-util.h>
22
23#include <iostream>
24#include <sstream>
25
26#include <boost/filesystem/operations.hpp>
27
28#include <cppunit/extensions/HelperMacros.h>
29
30using namespace CppUnit;
31
32class test_run_parts : public TestFixture
33{
34  CPPUNIT_TEST_SUITE(test_run_parts);
35  CPPUNIT_TEST(test_construction);
36  CPPUNIT_TEST_EXCEPTION(test_construction_fail, boost::filesystem::filesystem_error);
37  CPPUNIT_TEST(test_run);
38  CPPUNIT_TEST(test_run2);
39  CPPUNIT_TEST(test_run3);
40  CPPUNIT_TEST_SUITE_END();
41
42  std::streambuf           *saved;
43  sbuild::basic_nbuf<char> *monitor;
44
45public:
46  test_run_parts():
47    TestFixture()
48  {}
49
50  void setUp()
51  {
52    this->monitor = new sbuild::basic_nbuf<char>();
53    this->saved = std::cerr.std::ios::rdbuf(this->monitor);
54  }
55
56  void tearDown()
57  {
58    std::cerr.std::ios::rdbuf(this->saved);
59    delete this->monitor;
60  }
61
62
63  virtual ~test_run_parts()
64  {}
65
66  void
67  test_construction()
68  {
69    sbuild::run_parts rp(TESTDATADIR "/run-parts.ex1");
70  }
71
72  void
73  test_construction_fail()
74  {
75    sbuild::run_parts rp(TESTDATADIR "/invalid_dir");
76  }
77
78  void test_run()
79  {
80    sbuild::run_parts rp(TESTDATADIR "/run-parts.ex1");
81
82    int status;
83
84    sbuild::string_list command;
85    sbuild::environment env(environ);
86
87    command.push_back("ok");
88    status = rp.run(command, env);
89    CPPUNIT_ASSERT(status == EXIT_SUCCESS);
90
91    command.clear();
92    command.push_back("fail");
93    status = rp.run(command, env);
94    CPPUNIT_ASSERT(status == EXIT_FAILURE);
95
96    command.clear();
97    command.push_back("fail2");
98    status = rp.run(command, env);
99    CPPUNIT_ASSERT(status == EXIT_FAILURE);
100  }
101
102  void test_run2()
103  {
104    sbuild::run_parts rp(TESTDATADIR "/run-parts.ex2");
105
106    int status;
107
108    sbuild::string_list command;
109    sbuild::environment env(environ);
110
111    command.push_back("ok");
112    status = rp.run(command, env);
113    CPPUNIT_ASSERT(status == EXIT_SUCCESS);
114  }
115
116  void test_run3()
117  {
118    sbuild::run_parts rp(TESTDATADIR "/run-parts.ex3");
119
120    int status;
121
122    sbuild::string_list command;
123    sbuild::environment env(environ);
124
125    command.push_back("ok");
126    status = rp.run(command, env);
127    CPPUNIT_ASSERT(status == EXIT_FAILURE);
128  }
129
130};
131
132CPPUNIT_TEST_SUITE_REGISTRATION(test_run_parts);
Note: See TracBrowser for help on using the repository browser.