~ubuntu-branches/ubuntu/intrepid/schroot/intrepid

« back to all changes in this revision

Viewing changes to test/sbuild-run-parts.cc

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2006-07-08 18:33:28 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060708183328-rlo4mpldmyoda55q
Tags: 0.99.2-2ubuntu1
* remerge ubuntu changes:
  + debian/control: libpam-dev (>> 0.79-3ubuntu6)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright © 2006  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 2 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, write to the Free Software
 
15
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 
16
 * MA  02111-1307  USA
 
17
 *
 
18
 *********************************************************************/
 
19
 
 
20
#include <sbuild/sbuild-dirstream.h>
 
21
#include <sbuild/sbuild-nostream.h>
 
22
#include <sbuild/sbuild-run-parts.h>
 
23
#include <sbuild/sbuild-util.h>
 
24
 
 
25
#include <iostream>
 
26
#include <sstream>
 
27
 
 
28
#include <cppunit/extensions/HelperMacros.h>
 
29
 
 
30
using namespace CppUnit;
 
31
 
 
32
class 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, sbuild::dirstream::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
 
 
45
public:
 
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
 
 
132
CPPUNIT_TEST_SUITE_REGISTRATION(test_run_parts);
 
133
 
 
134
/*
 
135
 * Local Variables:
 
136
 * mode:C++
 
137
 * End:
 
138
 */