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

Revision 24167, 2.7 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-parse-value.h>
20
21#include <cppunit/extensions/HelperMacros.h>
22
23using namespace CppUnit;
24
25class test_parse_value : public TestCase
26{
27  CPPUNIT_TEST_SUITE(test_parse_value);
28  CPPUNIT_TEST(test_bool);
29  CPPUNIT_TEST(test_bool_fail);
30  CPPUNIT_TEST(test_int);
31  CPPUNIT_TEST(test_int_fail);
32  CPPUNIT_TEST(test_string);
33  CPPUNIT_TEST_SUITE_END();
34
35public:
36  test_parse_value()
37  {}
38
39  void test_bool()
40  {
41    bool result;
42
43    result = false;
44    sbuild::parse_value("true", result);
45    CPPUNIT_ASSERT(result == true);
46    result = false;
47    sbuild::parse_value("yes", result);
48    CPPUNIT_ASSERT(result == true);
49    result = false;
50    sbuild::parse_value("1", result);
51    CPPUNIT_ASSERT(result == true);
52
53    result = true;
54    sbuild::parse_value("false", result);
55    CPPUNIT_ASSERT(result == false);
56    result = true;
57    sbuild::parse_value("no", result);
58    CPPUNIT_ASSERT(result == false);
59    result = true;
60    sbuild::parse_value("0", result);
61    CPPUNIT_ASSERT(result == false);
62  }
63
64  void test_bool_fail()
65  {
66    bool result = true;
67
68    try
69      {
70        sbuild::parse_value("invalid", result);
71      }
72    catch (sbuild::parse_value_error const& e)
73      {
74        // Exception thown, and original value unmodified.
75        CPPUNIT_ASSERT(result == true);
76        return;
77      }
78    // Should never be reached
79    CPPUNIT_ASSERT(false);
80  }
81
82  void test_int()
83  {
84    int result = 0;
85    sbuild::parse_value("23", result);
86    CPPUNIT_ASSERT(result == 23);
87  }
88
89  void test_int_fail()
90  {
91    int result = 22;
92
93    try
94      {
95        sbuild::parse_value("invalid", result);
96      }
97    catch (sbuild::parse_value_error const& e)
98      {
99        // Exception thown, and original value unmodified.
100        CPPUNIT_ASSERT(result == 22);
101        return;
102      }
103    // Should never be reached
104    CPPUNIT_ASSERT(false);
105  }
106
107  void test_string()
108  {
109    std::string result;
110
111    sbuild::parse_value("test string", result);
112    CPPUNIT_ASSERT(result == "test string");
113  }
114};
115
116CPPUNIT_TEST_SUITE_REGISTRATION(test_parse_value);
Note: See TracBrowser for help on using the repository browser.