1 /******************************************************************************
3 * Copyright (C) 2012-2013 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/qstring.h"
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(replace)
87 BOOST_CHECK(s == "xllo");
90 BOOST_AUTO_TEST_CASE(index)
93 BOOST_CHECK(s[0] == 'h');
96 BOOST_CHECK(s == "xello");
98 BOOST_FOREACH(char& ch, s) {
101 BOOST_CHECK(s == "yyyyy");
104 BOOST_AUTO_TEST_CASE(find)
107 BOOST_CHECK(s.Find("ll") == 2);
108 BOOST_CHECK(s.FindFirstOf("xl") == 2);
111 BOOST_AUTO_TEST_SUITE_END()