[24167] | 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-chroot-config.h> |
---|
| 20 | #include <sbuild/sbuild-nostream.h> |
---|
| 21 | |
---|
| 22 | #include <fstream> |
---|
| 23 | #include <sstream> |
---|
| 24 | #include <vector> |
---|
| 25 | |
---|
| 26 | #include <cppunit/extensions/HelperMacros.h> |
---|
| 27 | |
---|
| 28 | using namespace CppUnit; |
---|
| 29 | |
---|
| 30 | class test_config : public TestFixture |
---|
| 31 | { |
---|
| 32 | CPPUNIT_TEST_SUITE(test_config); |
---|
| 33 | CPPUNIT_TEST(test_construction_file); |
---|
| 34 | CPPUNIT_TEST(test_construction_dir); |
---|
| 35 | CPPUNIT_TEST_EXCEPTION(test_construction_fail, sbuild::error_base); |
---|
| 36 | CPPUNIT_TEST(test_add_file); |
---|
| 37 | CPPUNIT_TEST(test_add_dir); |
---|
| 38 | CPPUNIT_TEST_EXCEPTION(test_add_fail, sbuild::error_base); |
---|
| 39 | CPPUNIT_TEST(test_get_chroots); |
---|
| 40 | CPPUNIT_TEST(test_find_chroot); |
---|
| 41 | CPPUNIT_TEST(test_find_alias); |
---|
| 42 | CPPUNIT_TEST(test_get_chroot_list); |
---|
| 43 | CPPUNIT_TEST(test_print_chroot_list); |
---|
| 44 | CPPUNIT_TEST(test_print_chroot_info); |
---|
| 45 | CPPUNIT_TEST(test_validate_chroots); |
---|
| 46 | CPPUNIT_TEST_EXCEPTION(test_config_fail, sbuild::error_base); |
---|
| 47 | CPPUNIT_TEST(test_config_deprecated); |
---|
| 48 | CPPUNIT_TEST(test_config_valid); |
---|
| 49 | CPPUNIT_TEST_SUITE_END(); |
---|
| 50 | |
---|
| 51 | protected: |
---|
| 52 | sbuild::chroot_config *cf; |
---|
| 53 | |
---|
| 54 | public: |
---|
| 55 | test_config(): |
---|
| 56 | TestFixture(), |
---|
| 57 | cf() |
---|
| 58 | {} |
---|
| 59 | |
---|
| 60 | virtual ~test_config() |
---|
| 61 | {} |
---|
| 62 | |
---|
| 63 | void setUp() |
---|
| 64 | { |
---|
| 65 | this->cf = new sbuild::chroot_config(TESTDATADIR "/config.ex1", false); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | void tearDown() |
---|
| 69 | { |
---|
| 70 | delete this->cf; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | void test_construction_file() |
---|
| 74 | { |
---|
| 75 | sbuild::chroot_config c(TESTDATADIR "/config.ex1", false); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | void test_construction_dir() |
---|
| 79 | { |
---|
| 80 | sbuild::chroot_config c(TESTDATADIR "/config.ex2", false); |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | void test_construction_fail() |
---|
| 84 | { |
---|
| 85 | sbuild::chroot_config c(TESTDATADIR "/config.nonexistent", false); |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | void test_construction_fail_wrong() |
---|
| 89 | { |
---|
| 90 | sbuild::chroot_config c(TESTDATADIR "/config.ex3", false); |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | void test_add_file() |
---|
| 94 | { |
---|
| 95 | sbuild::chroot_config c; |
---|
| 96 | c.add(TESTDATADIR "/config.ex1", false); |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | void test_add_dir() |
---|
| 100 | { |
---|
| 101 | sbuild::chroot_config c; |
---|
| 102 | c.add(TESTDATADIR "/config.ex2", false); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | void test_add_fail() |
---|
| 106 | { |
---|
| 107 | sbuild::chroot_config c; |
---|
| 108 | c.add(TESTDATADIR "/config.nonexistent", false); |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | void test_get_chroots() |
---|
| 112 | { |
---|
| 113 | CPPUNIT_ASSERT(this->cf->get_chroots().size() == 4); |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | void test_find_chroot() |
---|
| 117 | { |
---|
| 118 | sbuild::chroot::ptr chroot; |
---|
| 119 | |
---|
| 120 | chroot = this->cf->find_chroot("sid"); |
---|
| 121 | CPPUNIT_ASSERT((chroot)); |
---|
| 122 | CPPUNIT_ASSERT(chroot->get_name() == "sid"); |
---|
| 123 | |
---|
| 124 | chroot = this->cf->find_chroot("stable"); |
---|
| 125 | CPPUNIT_ASSERT((!chroot)); |
---|
| 126 | |
---|
| 127 | chroot = this->cf->find_chroot("invalid"); |
---|
| 128 | CPPUNIT_ASSERT((!chroot)); |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | void test_find_alias() |
---|
| 132 | { |
---|
| 133 | sbuild::chroot::ptr chroot; |
---|
| 134 | |
---|
| 135 | chroot = this->cf->find_alias("sid"); |
---|
| 136 | CPPUNIT_ASSERT((chroot)); |
---|
| 137 | CPPUNIT_ASSERT(chroot->get_name() == "sid"); |
---|
| 138 | |
---|
| 139 | chroot = this->cf->find_alias("stable"); |
---|
| 140 | CPPUNIT_ASSERT((chroot)); |
---|
| 141 | CPPUNIT_ASSERT(chroot->get_name() == "sarge"); |
---|
| 142 | |
---|
| 143 | chroot = this->cf->find_alias("invalid"); |
---|
| 144 | CPPUNIT_ASSERT((!chroot)); |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | void test_get_chroot_list() |
---|
| 148 | { |
---|
| 149 | sbuild::string_list chroots = this->cf->get_chroot_list(); |
---|
| 150 | CPPUNIT_ASSERT(chroots.size() == 7); // Includes aliases |
---|
| 151 | CPPUNIT_ASSERT(chroots[0] == "default"); |
---|
| 152 | CPPUNIT_ASSERT(chroots[1] == "experimental"); |
---|
| 153 | CPPUNIT_ASSERT(chroots[2] == "sarge"); |
---|
| 154 | CPPUNIT_ASSERT(chroots[3] == "sid"); |
---|
| 155 | CPPUNIT_ASSERT(chroots[4] == "sid-local"); |
---|
| 156 | CPPUNIT_ASSERT(chroots[5] == "stable"); |
---|
| 157 | CPPUNIT_ASSERT(chroots[6] == "unstable"); |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | void test_print_chroot_list() |
---|
| 161 | { |
---|
| 162 | this->cf->print_chroot_list(sbuild::cnull); |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | void test_print_chroot_info() |
---|
| 166 | { |
---|
| 167 | this->cf->print_chroot_info(this->cf->get_chroot_list(), sbuild::cnull); |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | void test_validate_chroots() |
---|
| 171 | { |
---|
| 172 | sbuild::string_list chroots; |
---|
| 173 | chroots.push_back("default"); |
---|
| 174 | chroots.push_back("invalid"); |
---|
| 175 | chroots.push_back("invalid2"); |
---|
| 176 | chroots.push_back("sarge"); |
---|
| 177 | chroots.push_back("unstable"); |
---|
| 178 | |
---|
| 179 | sbuild::string_list invalid = this->cf->validate_chroots(chroots); |
---|
| 180 | CPPUNIT_ASSERT(invalid.size() == 2); |
---|
| 181 | CPPUNIT_ASSERT(invalid[0] == "invalid"); |
---|
| 182 | CPPUNIT_ASSERT(invalid[1] == "invalid2"); |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | void test_config_fail() |
---|
| 186 | { |
---|
| 187 | sbuild::chroot_config c(TESTDATADIR "/config-directory-fail.ex", false); |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | void test_config_deprecated() |
---|
| 191 | { |
---|
| 192 | sbuild::chroot_config c(TESTDATADIR "/config-directory-deprecated.ex", false); |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | void test_config_valid() |
---|
| 196 | { |
---|
| 197 | sbuild::chroot_config c(TESTDATADIR "/config-directory-valid.ex", false); |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | }; |
---|
| 201 | |
---|
| 202 | CPPUNIT_TEST_SUITE_REGISTRATION(test_config); |
---|