1 /******************************************************************************
3 * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
20 #include "base/string.hpp"
21 #include <boost/test/unit_test.hpp>
22 #include <boost/foreach.hpp>
24 using namespace icinga;
26 BOOST_AUTO_TEST_SUITE(base_string)
28 BOOST_AUTO_TEST_CASE(construct)
30 BOOST_CHECK(String() == "");
31 BOOST_CHECK(String(5, 'n') == "nnnnn");
34 BOOST_AUTO_TEST_CASE(equal)
36 BOOST_CHECK(String("hello") == String("hello"));
37 BOOST_CHECK("hello" == String("hello"));
38 BOOST_CHECK(String("hello") == String("hello"));
40 BOOST_CHECK(String("hello") != String("helloworld"));
41 BOOST_CHECK("hello" != String("helloworld"));
42 BOOST_CHECK(String("hello") != "helloworld");
45 BOOST_AUTO_TEST_CASE(clear)
50 BOOST_CHECK(s.IsEmpty());
53 BOOST_AUTO_TEST_CASE(append)
60 BOOST_CHECK(s == "hello");
63 BOOST_AUTO_TEST_CASE(trim)
67 BOOST_CHECK(s1 == "hello");
71 BOOST_CHECK(s2 == "hello");
75 BOOST_CHECK(s3 == "hello");
77 String s4 = " hello ";
79 BOOST_CHECK(s4 == "hello");
82 BOOST_AUTO_TEST_CASE(contains)
84 String s1 = "hello world";
86 BOOST_CHECK(s1.Contains(s2));
88 String s3 = " hello world ";
90 BOOST_CHECK(s3.Contains(s4));
92 String s5 = " hello world ";
94 BOOST_CHECK(s5.Contains(s6));
97 BOOST_AUTO_TEST_CASE(replace)
101 s.Replace(0, 2, "x");
102 BOOST_CHECK(s == "xllo");
105 BOOST_AUTO_TEST_CASE(index)
108 BOOST_CHECK(s[0] == 'h');
111 BOOST_CHECK(s == "xello");
113 BOOST_FOREACH(char& ch, s) {
116 BOOST_CHECK(s == "yyyyy");
119 BOOST_AUTO_TEST_CASE(find)
122 BOOST_CHECK(s.Find("ll") == 2);
123 BOOST_CHECK(s.FindFirstOf("xl") == 2);
126 BOOST_AUTO_TEST_SUITE_END()