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-regex.h> |
---|
20 | |
---|
21 | #include <iostream> |
---|
22 | #include <sstream> |
---|
23 | |
---|
24 | #include <cppunit/extensions/HelperMacros.h> |
---|
25 | |
---|
26 | using namespace CppUnit; |
---|
27 | |
---|
28 | class test_regex : public TestCase |
---|
29 | { |
---|
30 | CPPUNIT_TEST_SUITE(test_regex); |
---|
31 | CPPUNIT_TEST(test_construction); |
---|
32 | CPPUNIT_TEST_EXCEPTION(test_construction_fail, boost::regex_error); |
---|
33 | CPPUNIT_TEST(test_output); |
---|
34 | CPPUNIT_TEST(test_input); |
---|
35 | CPPUNIT_TEST_EXCEPTION(test_input_fail, boost::regex_error); |
---|
36 | CPPUNIT_TEST_SUITE_END(); |
---|
37 | |
---|
38 | public: |
---|
39 | test_regex() |
---|
40 | {} |
---|
41 | |
---|
42 | virtual ~test_regex() |
---|
43 | {} |
---|
44 | |
---|
45 | void |
---|
46 | test_construction() |
---|
47 | { |
---|
48 | sbuild::regex r1; |
---|
49 | |
---|
50 | sbuild::regex r2("foo"); |
---|
51 | |
---|
52 | std::string p("foo|bar$"); |
---|
53 | sbuild::regex r3(p); |
---|
54 | } |
---|
55 | |
---|
56 | void |
---|
57 | test_construction_fail() |
---|
58 | { |
---|
59 | sbuild::regex r("[foo"); |
---|
60 | } |
---|
61 | |
---|
62 | void |
---|
63 | test_output() |
---|
64 | { |
---|
65 | sbuild::regex r("foo"); |
---|
66 | std::ostringstream o; |
---|
67 | o << r; |
---|
68 | CPPUNIT_ASSERT(o.str() == "foo"); |
---|
69 | } |
---|
70 | |
---|
71 | void |
---|
72 | test_input() |
---|
73 | { |
---|
74 | sbuild::regex r; |
---|
75 | std::istringstream i("foo"); |
---|
76 | i >> r; |
---|
77 | CPPUNIT_ASSERT(r.str() == "foo"); |
---|
78 | } |
---|
79 | |
---|
80 | void |
---|
81 | test_input_fail() |
---|
82 | { |
---|
83 | sbuild::regex r; |
---|
84 | std::istringstream i("([[invalid_regex"); |
---|
85 | i >> r; |
---|
86 | } |
---|
87 | |
---|
88 | }; |
---|
89 | |
---|
90 | CPPUNIT_TEST_SUITE_REGISTRATION(test_regex); |
---|