source: trunk/debathena/third/schroot/test/sbuild-chroot-plain.cc @ 24167

Revision 24167, 4.1 KB checked in by broder, 15 years ago (diff)
Import schroot upstream into subversion.
Line 
1/* Copyright © 2006-2008  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 <config.h>
20
21#include <sbuild/sbuild-config.h>
22#include <sbuild/sbuild-chroot-plain.h>
23
24#include "test-helpers.h"
25#include "test-sbuild-chroot.h"
26
27#include <algorithm>
28#include <set>
29
30#include <cppunit/extensions/HelperMacros.h>
31
32using namespace CppUnit;
33
34class chroot_plain : public sbuild::chroot_plain
35{
36public:
37  chroot_plain():
38    sbuild::chroot_plain()
39  {}
40
41  virtual ~chroot_plain()
42  {}
43};
44
45class test_chroot_plain : public test_chroot_base<chroot_plain>
46{
47  CPPUNIT_TEST_SUITE(test_chroot_plain);
48  CPPUNIT_TEST(test_directory);
49  CPPUNIT_TEST(test_chroot_type);
50  CPPUNIT_TEST(test_setup_env);
51  CPPUNIT_TEST(test_setup_keyfile);
52  CPPUNIT_TEST(test_print_details);
53  CPPUNIT_TEST(test_print_config);
54  CPPUNIT_TEST(test_run_setup_scripts);
55  CPPUNIT_TEST_SUITE_END();
56
57public:
58  test_chroot_plain():
59    test_chroot_base<chroot_plain>()
60  {}
61
62  void setUp()
63  {
64    test_chroot_base<chroot_plain>::setUp();
65    CPPUNIT_ASSERT(!session);
66    CPPUNIT_ASSERT(!source);
67    CPPUNIT_ASSERT(!chroot_union);
68    CPPUNIT_ASSERT(!session_union);
69    CPPUNIT_ASSERT(!source_union);
70  }
71
72  virtual void setup_chroot_props (sbuild::chroot::ptr& chroot)
73  {
74    test_chroot_base<chroot_plain>::setup_chroot_props(chroot);
75
76    std::tr1::shared_ptr<sbuild::chroot_plain> c = std::tr1::dynamic_pointer_cast<sbuild::chroot_plain>(chroot);
77
78    c->set_mount_location("");
79    c->set_directory("/srv/chroot/example-chroot");
80  }
81
82  void
83  test_directory()
84  {
85    std::tr1::shared_ptr<sbuild::chroot_plain> c = std::tr1::dynamic_pointer_cast<sbuild::chroot_plain>(chroot);
86    CPPUNIT_ASSERT(c);
87    c->set_directory("/mnt/mount-location/example");
88    CPPUNIT_ASSERT(c->get_directory() == "/mnt/mount-location/example");
89    CPPUNIT_ASSERT(chroot->get_path() == "/mnt/mount-location/example");
90    CPPUNIT_ASSERT(chroot->get_mount_location() == "");
91  }
92
93  void test_chroot_type()
94  {
95    CPPUNIT_ASSERT(chroot->get_chroot_type() == "plain");
96  }
97
98  void test_setup_env()
99  {
100    sbuild::environment expected;
101    setup_env_chroot(expected);
102    expected.add("CHROOT_TYPE",           "plain");
103    expected.add("CHROOT_DIRECTORY",      "/srv/chroot/example-chroot");
104    expected.add("CHROOT_PATH",           "/srv/chroot/example-chroot");
105    expected.add("CHROOT_SESSION_CLONE",  "false");
106    expected.add("CHROOT_SESSION_CREATE", "false");
107    expected.add("CHROOT_SESSION_PURGE",  "false");
108
109    test_chroot_base<chroot_plain>::test_setup_env(chroot, expected);
110  }
111
112  void test_setup_keyfile()
113  {
114    sbuild::keyfile expected;
115    std::string group = chroot->get_name();
116    setup_keyfile_chroot(expected, group);
117    expected.set_value(group, "type", "plain");
118    expected.set_value(group, "directory", "/srv/chroot/example-chroot");
119
120    test_chroot_base<chroot_plain>::test_setup_keyfile
121      (chroot, expected, group);
122  }
123
124  void test_session_flags()
125  {
126    CPPUNIT_ASSERT(chroot->get_session_flags() ==
127                   sbuild::chroot::SESSION_NOFLAGS);
128  }
129
130  void test_print_details()
131  {
132    std::ostringstream os;
133    os << chroot;
134    // TODO: Compare output.
135    CPPUNIT_ASSERT(!os.str().empty());
136  }
137
138  void test_print_config()
139  {
140    std::ostringstream os;
141    sbuild::keyfile config;
142    config << chroot;
143    os << config;
144    // TODO: Compare output.
145    CPPUNIT_ASSERT(!os.str().empty());
146  }
147
148  void test_run_setup_scripts()
149  {
150    CPPUNIT_ASSERT(!chroot->get_run_setup_scripts());
151  }
152
153};
154
155CPPUNIT_TEST_SUITE_REGISTRATION(test_chroot_plain);
Note: See TracBrowser for help on using the repository browser.