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

Revision 24167, 2.8 KB checked in by broder, 15 years ago (diff)
Import schroot upstream into subversion.
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-util.h>
20
21#include <cstdlib>
22
23#include <cppunit/extensions/HelperMacros.h>
24
25using namespace CppUnit;
26
27class test_util : public TestCase
28{
29  CPPUNIT_TEST_SUITE(test_util);
30  CPPUNIT_TEST(test_basename);
31  CPPUNIT_TEST(test_dirname);
32  CPPUNIT_TEST(test_string_list_to_string);
33  CPPUNIT_TEST(test_split_string);
34  CPPUNIT_TEST(test_find_program_in_path);
35  CPPUNIT_TEST_SUITE_END();
36
37public:
38  test_util()
39  {}
40
41  void test_basename()
42  {
43    CPPUNIT_ASSERT(sbuild::basename("/usr/bin/perl") == "perl");
44    CPPUNIT_ASSERT(sbuild::basename("/usr/lib") == "lib");
45    CPPUNIT_ASSERT(sbuild::basename("/usr/") == "usr");
46    CPPUNIT_ASSERT(sbuild::basename("usr") == "usr");
47    CPPUNIT_ASSERT(sbuild::basename("/") == "/");
48    CPPUNIT_ASSERT(sbuild::basename(".") == ".");
49    CPPUNIT_ASSERT(sbuild::basename("..") == "..");
50  }
51
52  void test_dirname()
53  {
54    CPPUNIT_ASSERT(sbuild::dirname("/usr/bin/perl") == "/usr/bin");
55    CPPUNIT_ASSERT(sbuild::dirname("/usr/lib") == "/usr");
56    CPPUNIT_ASSERT(sbuild::dirname("/usr/") == "/");
57    CPPUNIT_ASSERT(sbuild::dirname("usr") == ".");
58    CPPUNIT_ASSERT(sbuild::dirname("/") == "/");
59    CPPUNIT_ASSERT(sbuild::dirname(".") == ".");
60    CPPUNIT_ASSERT(sbuild::dirname("..") == ".");
61  }
62
63  void test_string_list_to_string()
64  {
65    sbuild::string_list items;
66    items.push_back("foo");
67    items.push_back("bar");
68    items.push_back("baz");
69
70    CPPUNIT_ASSERT(sbuild::string_list_to_string(items, "--") ==
71                   "foo--bar--baz");
72  }
73
74  void test_split_string()
75  {
76    sbuild::string_list items =
77      sbuild::split_string("/usr/share/info", "/");
78
79    CPPUNIT_ASSERT(items.size() == 3 &&
80                   items[0] == "usr" &&
81                   items[1] == "share" &&
82                   items[2] == "info");
83  }
84
85  void test_find_program_in_path()
86  {
87    std::string path("/usr/local/bin:/usr/bin:/bin");
88    CPPUNIT_ASSERT(sbuild::find_program_in_path("sh", path, "") == "/bin/sh");
89    CPPUNIT_ASSERT(sbuild::find_program_in_path("sed", path, "") == "/bin/sed");
90  }
91
92};
93
94CPPUNIT_TEST_SUITE_REGISTRATION(test_util);
Note: See TracBrowser for help on using the repository browser.