1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
/* Copyright © 2006-2007 Roger Leigh <rleigh@codelibre.net>
*
* schroot is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* schroot is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*
*********************************************************************/
#include <sbuild/sbuild-chroot-config.h>
#include <sbuild/sbuild-nostream.h>
#include <fstream>
#include <sstream>
#include <vector>
#include <cppunit/extensions/HelperMacros.h>
#include <config.h>
using namespace CppUnit;
class test_config : public TestFixture
{
CPPUNIT_TEST_SUITE(test_config);
CPPUNIT_TEST(test_construction_file);
CPPUNIT_TEST(test_construction_dir);
CPPUNIT_TEST_EXCEPTION(test_construction_fail, sbuild::error_base);
CPPUNIT_TEST(test_add_file);
CPPUNIT_TEST(test_add_dir);
CPPUNIT_TEST_EXCEPTION(test_add_fail, sbuild::error_base);
CPPUNIT_TEST(test_get_chroots);
CPPUNIT_TEST(test_find_chroot);
CPPUNIT_TEST(test_find_alias);
CPPUNIT_TEST(test_get_chroot_list);
CPPUNIT_TEST(test_get_alias_list);
CPPUNIT_TEST(test_validate_chroots);
CPPUNIT_TEST_EXCEPTION(test_validate_chroots_fail, sbuild::error_base);
CPPUNIT_TEST_EXCEPTION(test_config_fail, sbuild::error_base);
CPPUNIT_TEST(test_config_deprecated);
CPPUNIT_TEST(test_config_valid);
CPPUNIT_TEST_SUITE_END();
protected:
sbuild::chroot_config *cf;
public:
test_config():
TestFixture(),
cf()
{}
virtual ~test_config()
{}
void setUp()
{
this->cf = new sbuild::chroot_config("chroot", TESTDATADIR "/config.ex1");
}
void tearDown()
{
delete this->cf;
}
void test_construction_file()
{
sbuild::chroot_config c("chroot", TESTDATADIR "/config.ex1");
}
void test_construction_dir()
{
sbuild::chroot_config c("chroot", TESTDATADIR "/config.ex2");
}
void test_construction_fail()
{
sbuild::chroot_config c("chroot", TESTDATADIR "/config.nonexistent");
}
void test_construction_fail_wrong()
{
sbuild::chroot_config c("chroot", TESTDATADIR "/config.ex3");
}
void test_add_file()
{
sbuild::chroot_config c;
c.add("chroot", TESTDATADIR "/config.ex1");
}
void test_add_dir()
{
sbuild::chroot_config c;
c.add("chroot", TESTDATADIR "/config.ex2");
}
void test_add_fail()
{
sbuild::chroot_config c;
c.add("chroot", TESTDATADIR "/config.nonexistent");
}
void test_get_chroots()
{
CPPUNIT_ASSERT(this->cf->get_chroots("chroot").size() == 4);
}
void test_find_chroot()
{
sbuild::chroot::ptr chroot;
chroot = this->cf->find_chroot("chroot", "sid");
CPPUNIT_ASSERT((chroot));
CPPUNIT_ASSERT(chroot->get_name() == "sid");
chroot = this->cf->find_chroot("chroot", "stable");
CPPUNIT_ASSERT((!chroot));
chroot = this->cf->find_chroot("chroot", "invalid");
CPPUNIT_ASSERT((!chroot));
}
void test_find_alias()
{
sbuild::chroot::ptr chroot;
chroot = this->cf->find_alias("chroot", "sid");
CPPUNIT_ASSERT((chroot));
CPPUNIT_ASSERT(chroot->get_name() == "sid");
chroot = this->cf->find_alias("chroot", "stable");
CPPUNIT_ASSERT((chroot));
CPPUNIT_ASSERT(chroot->get_name() == "sarge");
chroot = this->cf->find_alias("chroot", "invalid");
CPPUNIT_ASSERT((!chroot));
}
void test_get_chroot_list()
{
sbuild::string_list chroots = this->cf->get_chroot_list("chroot");
CPPUNIT_ASSERT(chroots.size() == 4);
CPPUNIT_ASSERT(chroots[0] == "chroot:experimental");
CPPUNIT_ASSERT(chroots[1] == "chroot:sarge");
CPPUNIT_ASSERT(chroots[2] == "chroot:sid");
CPPUNIT_ASSERT(chroots[3] == "chroot:sid-local");
}
void test_get_alias_list()
{
sbuild::string_list chroots = this->cf->get_alias_list("chroot");
CPPUNIT_ASSERT(chroots.size() == 7);
CPPUNIT_ASSERT(chroots[0] == "chroot:default");
CPPUNIT_ASSERT(chroots[1] == "chroot:experimental");
CPPUNIT_ASSERT(chroots[2] == "chroot:sarge");
CPPUNIT_ASSERT(chroots[3] == "chroot:sid");
CPPUNIT_ASSERT(chroots[4] == "chroot:sid-local");
CPPUNIT_ASSERT(chroots[5] == "chroot:stable");
CPPUNIT_ASSERT(chroots[6] == "chroot:unstable");
}
void test_validate_chroots()
{
sbuild::string_list chroots;
chroots.push_back("default");
chroots.push_back("sarge");
chroots.push_back("unstable");
sbuild::chroot_config::chroot_map m = this->cf->validate_chroots("chroot", chroots);
assert(m.size() == 3);
}
void test_validate_chroots_fail()
{
sbuild::string_list chroots;
chroots.push_back("default");
chroots.push_back("invalid");
chroots.push_back("invalid2");
chroots.push_back("sarge");
chroots.push_back("unstable");
this->cf->validate_chroots("chroot", chroots);
}
void test_config_fail()
{
sbuild::chroot_config c("chroot", TESTDATADIR "/config-directory-fail.ex");
}
void test_config_deprecated()
{
sbuild::chroot_config c("chroot", TESTDATADIR "/config-directory-deprecated.ex");
}
void test_config_valid()
{
sbuild::chroot_config c("chroot", TESTDATADIR "/config-directory-valid.ex");
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(test_config);
|