1 /******************************************************************************
3 * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) *
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 <BoostTestTargetConfig.h>
23 using namespace icinga;
25 BOOST_AUTO_TEST_SUITE(base_string)
27 BOOST_AUTO_TEST_CASE(construct)
29 BOOST_CHECK(String() == "");
30 BOOST_CHECK(String(5, 'n') == "nnnnn");
33 BOOST_AUTO_TEST_CASE(equal)
35 BOOST_CHECK(String("hello") == String("hello"));
36 BOOST_CHECK("hello" == String("hello"));
37 BOOST_CHECK(String("hello") == String("hello"));
39 BOOST_CHECK(String("hello") != String("helloworld"));
40 BOOST_CHECK("hello" != String("helloworld"));
41 BOOST_CHECK(String("hello") != "helloworld");
44 BOOST_AUTO_TEST_CASE(clear)
49 BOOST_CHECK(s.IsEmpty());
52 BOOST_AUTO_TEST_CASE(append)
59 BOOST_CHECK(s == "hello");
62 BOOST_AUTO_TEST_CASE(trim)
65 BOOST_CHECK(s1.Trim() == "hello");
68 BOOST_CHECK(s2.Trim() == "hello");
71 BOOST_CHECK(s3.Trim() == "hello");
73 String s4 = " hello ";
74 BOOST_CHECK(s4.Trim() == "hello");
77 BOOST_AUTO_TEST_CASE(contains)
79 String s1 = "hello world";
81 BOOST_CHECK(s1.Contains(s2));
83 String s3 = " hello world ";
85 BOOST_CHECK(s3.Contains(s4));
87 String s5 = " hello world ";
89 BOOST_CHECK(s5.Contains(s6));
92 BOOST_AUTO_TEST_CASE(replace)
97 BOOST_CHECK(s == "xllo");
100 BOOST_AUTO_TEST_CASE(index)
103 BOOST_CHECK(s[0] == 'h');
106 BOOST_CHECK(s == "xello");
111 BOOST_CHECK(s == "yyyyy");
114 BOOST_AUTO_TEST_CASE(find)
117 BOOST_CHECK(s.Find("ll") == 2);
118 BOOST_CHECK(s.FindFirstOf("xl") == 2);
121 BOOST_AUTO_TEST_SUITE_END()