]> granicus.if.org Git - icinga2/blob - test/base-string.cpp
Merge pull request #6999 from Icinga/bugfix/compiler-warnings
[icinga2] / test / base-string.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "base/string.hpp"
4 #include <BoostTestTargetConfig.h>
5
6 using namespace icinga;
7
8 BOOST_AUTO_TEST_SUITE(base_string)
9
10 BOOST_AUTO_TEST_CASE(construct)
11 {
12         BOOST_CHECK(String() == "");
13         BOOST_CHECK(String(5, 'n') == "nnnnn");
14 }
15
16 BOOST_AUTO_TEST_CASE(equal)
17 {
18         BOOST_CHECK(String("hello") == String("hello"));
19         BOOST_CHECK("hello" == String("hello"));
20         BOOST_CHECK(String("hello") == String("hello"));
21
22         BOOST_CHECK(String("hello") != String("helloworld"));
23         BOOST_CHECK("hello" != String("helloworld"));
24         BOOST_CHECK(String("hello") != "helloworld");
25 }
26
27 BOOST_AUTO_TEST_CASE(clear)
28 {
29         String s = "hello";
30         s.Clear();
31         BOOST_CHECK(s == "");
32         BOOST_CHECK(s.IsEmpty());
33 }
34
35 BOOST_AUTO_TEST_CASE(append)
36 {
37         String s;
38         s += "he";
39         s += String("ll");
40         s += 'o';
41
42         BOOST_CHECK(s == "hello");
43 }
44
45 BOOST_AUTO_TEST_CASE(trim)
46 {
47         String s1 = "hello";
48         BOOST_CHECK(s1.Trim() == "hello");
49
50         String s2 = "  hello";
51         BOOST_CHECK(s2.Trim() == "hello");
52
53         String s3 = "hello ";
54         BOOST_CHECK(s3.Trim() == "hello");
55
56         String s4 = " hello ";
57         BOOST_CHECK(s4.Trim() == "hello");
58 }
59
60 BOOST_AUTO_TEST_CASE(contains)
61 {
62         String s1 = "hello world";
63         String s2 = "hello";
64         BOOST_CHECK(s1.Contains(s2));
65
66         String s3 = "  hello world  ";
67         String s4 = "  hello";
68         BOOST_CHECK(s3.Contains(s4));
69
70         String s5 = "  hello world  ";
71         String s6 = "world  ";
72         BOOST_CHECK(s5.Contains(s6));
73 }
74
75 BOOST_AUTO_TEST_CASE(replace)
76 {
77         String s = "hello";
78
79         s.Replace(0, 2, "x");
80         BOOST_CHECK(s == "xllo");
81 }
82
83 BOOST_AUTO_TEST_CASE(index)
84 {
85         String s = "hello";
86         BOOST_CHECK(s[0] == 'h');
87
88         s[0] = 'x';
89         BOOST_CHECK(s == "xello");
90
91         for (char& ch : s) {
92                 ch = 'y';
93         }
94         BOOST_CHECK(s == "yyyyy");
95 }
96
97 BOOST_AUTO_TEST_CASE(find)
98 {
99         String s = "hello";
100         BOOST_CHECK(s.Find("ll") == 2);
101         BOOST_CHECK(s.FindFirstOf("xl") == 2);
102 }
103
104 BOOST_AUTO_TEST_SUITE_END()