blob: 6a6fa66110627dbcd2518cc72d2106908085ac47 (
plain)
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
|
/* Copyright © 2006-2013 Roger Leigh <rleigh@debian.org>
*
* 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/util.h>
#include <cstdlib>
#include <cppunit/extensions/HelperMacros.h>
using namespace CppUnit;
class test_util : public TestCase
{
CPPUNIT_TEST_SUITE(test_util);
CPPUNIT_TEST(test_basename);
CPPUNIT_TEST(test_dirname);
CPPUNIT_TEST(test_string_list_to_string);
CPPUNIT_TEST(test_split_string);
CPPUNIT_TEST(test_find_program_in_path);
CPPUNIT_TEST_SUITE_END();
public:
test_util()
{}
void test_basename()
{
CPPUNIT_ASSERT(sbuild::basename("/usr/bin/perl") == "perl");
CPPUNIT_ASSERT(sbuild::basename("/usr/lib") == "lib");
CPPUNIT_ASSERT(sbuild::basename("/usr/") == "usr");
CPPUNIT_ASSERT(sbuild::basename("usr") == "usr");
CPPUNIT_ASSERT(sbuild::basename("/") == "/");
CPPUNIT_ASSERT(sbuild::basename(".") == ".");
CPPUNIT_ASSERT(sbuild::basename("..") == "..");
}
void test_dirname()
{
CPPUNIT_ASSERT(sbuild::dirname("/usr/bin/perl") == "/usr/bin");
CPPUNIT_ASSERT(sbuild::dirname("/usr/lib") == "/usr");
CPPUNIT_ASSERT(sbuild::dirname("/usr/") == "/");
CPPUNIT_ASSERT(sbuild::dirname("usr") == ".");
CPPUNIT_ASSERT(sbuild::dirname("/") == "/");
CPPUNIT_ASSERT(sbuild::dirname(".") == ".");
CPPUNIT_ASSERT(sbuild::dirname("..") == ".");
}
void test_string_list_to_string()
{
sbuild::string_list items;
items.push_back("foo");
items.push_back("bar");
items.push_back("baz");
CPPUNIT_ASSERT(sbuild::string_list_to_string(items, "--") ==
"foo--bar--baz");
}
void test_split_string()
{
sbuild::string_list items =
sbuild::split_string("/usr/share/info", "/");
CPPUNIT_ASSERT(items.size() == 3 &&
items[0] == "usr" &&
items[1] == "share" &&
items[2] == "info");
}
void test_find_program_in_path()
{
std::string path("/usr/local/bin:/usr/bin:/bin");
CPPUNIT_ASSERT(sbuild::find_program_in_path("sh", path, "") == "/bin/sh");
CPPUNIT_ASSERT(sbuild::find_program_in_path("sed", path, "") == "/bin/sed");
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(test_util);
|