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-personality.h> |
---|
20 | |
---|
21 | #include <iostream> |
---|
22 | #include <sstream> |
---|
23 | |
---|
24 | #include <cppunit/extensions/HelperMacros.h> |
---|
25 | |
---|
26 | using namespace CppUnit; |
---|
27 | |
---|
28 | class test_personality : public TestCase |
---|
29 | { |
---|
30 | CPPUNIT_TEST_SUITE(test_personality); |
---|
31 | CPPUNIT_TEST(test_construction); |
---|
32 | CPPUNIT_TEST(test_output); |
---|
33 | CPPUNIT_TEST(test_input); |
---|
34 | CPPUNIT_TEST_EXCEPTION(test_input_fail, sbuild::personality::error); |
---|
35 | CPPUNIT_TEST_SUITE_END(); |
---|
36 | |
---|
37 | public: |
---|
38 | test_personality() |
---|
39 | {} |
---|
40 | |
---|
41 | virtual ~test_personality() |
---|
42 | {} |
---|
43 | |
---|
44 | void |
---|
45 | test_construction() |
---|
46 | { |
---|
47 | sbuild::personality p1; |
---|
48 | #if defined(SBUILD_FEATURE_PERSONALITY) && defined (__linux__) |
---|
49 | CPPUNIT_ASSERT(p1.get_name() == "linux" || |
---|
50 | p1.get_name() == "linux_32bit" || |
---|
51 | p1.get_name() == "linux32"); |
---|
52 | #else |
---|
53 | CPPUNIT_ASSERT(p1.get_name() == "undefined"); |
---|
54 | #endif |
---|
55 | |
---|
56 | sbuild::personality p2(0xffffffff); |
---|
57 | CPPUNIT_ASSERT(p2.get_name() == "undefined"); |
---|
58 | |
---|
59 | sbuild::personality p3("invalid_personality"); |
---|
60 | CPPUNIT_ASSERT(p3.get_name() == "undefined"); |
---|
61 | |
---|
62 | sbuild::personality p4("linux"); |
---|
63 | #if defined(SBUILD_FEATURE_PERSONALITY) && defined (__linux__) |
---|
64 | CPPUNIT_ASSERT(p4.get_name() == "linux"); |
---|
65 | #else |
---|
66 | CPPUNIT_ASSERT(p4.get_name() == "undefined"); |
---|
67 | #endif |
---|
68 | } |
---|
69 | |
---|
70 | void |
---|
71 | test_output() |
---|
72 | { |
---|
73 | sbuild::personality p2(0xffffffff); |
---|
74 | std::ostringstream ps2; |
---|
75 | ps2 << p2; |
---|
76 | CPPUNIT_ASSERT(ps2.str() == "undefined"); |
---|
77 | |
---|
78 | sbuild::personality p3("invalid_personality"); |
---|
79 | std::ostringstream ps3; |
---|
80 | ps3 << p3; |
---|
81 | CPPUNIT_ASSERT(ps3.str() == "undefined"); |
---|
82 | |
---|
83 | sbuild::personality p4("linux"); |
---|
84 | std::ostringstream ps4; |
---|
85 | ps4 << p4; |
---|
86 | #if defined(SBUILD_FEATURE_PERSONALITY) && defined (__linux__) |
---|
87 | CPPUNIT_ASSERT(ps4.str() == "linux"); |
---|
88 | #else |
---|
89 | CPPUNIT_ASSERT(ps4.str() == "undefined"); |
---|
90 | #endif |
---|
91 | } |
---|
92 | |
---|
93 | void |
---|
94 | test_input() |
---|
95 | { |
---|
96 | sbuild::personality p2; |
---|
97 | std::istringstream ps2("undefined"); |
---|
98 | ps2 >> p2; |
---|
99 | CPPUNIT_ASSERT(p2.get_name() == "undefined"); |
---|
100 | |
---|
101 | sbuild::personality p4; |
---|
102 | #if defined(SBUILD_FEATURE_PERSONALITY) && defined (__linux__) |
---|
103 | std::istringstream ps4("linux"); |
---|
104 | #else |
---|
105 | std::istringstream ps4("undefined"); |
---|
106 | #endif |
---|
107 | ps4 >> p4; |
---|
108 | #if defined(SBUILD_FEATURE_PERSONALITY) && defined (__linux__) |
---|
109 | CPPUNIT_ASSERT(p4.get_name() == "linux"); |
---|
110 | #else |
---|
111 | CPPUNIT_ASSERT(p4.get_name() == "undefined"); |
---|
112 | #endif |
---|
113 | } |
---|
114 | |
---|
115 | void |
---|
116 | test_input_fail() |
---|
117 | { |
---|
118 | sbuild::personality p3; |
---|
119 | std::istringstream ps3("invalid_personality"); |
---|
120 | ps3 >> p3; |
---|
121 | CPPUNIT_ASSERT(p3.get_name() == "undefined"); |
---|
122 | } |
---|
123 | |
---|
124 | }; |
---|
125 | |
---|
126 | CPPUNIT_TEST_SUITE_REGISTRATION(test_personality); |
---|