xref: /haiku/src/tests/kits/support/bstring/StringCompareTest.cpp (revision f960e7e9a2b236d50e202d5c46b4d759d46b233a)
1 #include "StringCompareTest.h"
2 #include "cppunit/TestCaller.h"
3 #include <String.h>
4 
5 
StringCompareTest(std::string name)6 StringCompareTest::StringCompareTest(std::string name)
7 		: BTestCase(name)
8 {
9 }
10 
11 
~StringCompareTest()12 StringCompareTest::~StringCompareTest()
13 {
14 }
15 
16 
17 void
PerformTest(void)18 StringCompareTest::PerformTest(void)
19 {
20 	BString *string1, *string2;
21 
22 	// operator<(const BString &) const;
23 	NextSubTest();
24 	string1 = new BString("11111_a");
25 	string2 = new BString("22222_b");
26 	CPPUNIT_ASSERT(*string1 < *string2);
27 	delete string1;
28 	delete string2;
29 
30 	// operator<=(const BString &) const;
31 	NextSubTest();
32 	string1 = new BString("11111_a");
33 	string2 = new BString("22222_b");
34 	CPPUNIT_ASSERT(*string1 <= *string2);
35 	delete string1;
36 	delete string2;
37 
38 	NextSubTest();
39 	string1 = new BString("11111");
40 	string2 = new BString("11111");
41 	CPPUNIT_ASSERT(*string1 <= *string2);
42 	delete string1;
43 	delete string2;
44 
45 	// operator==(const BString &) const;
46 	NextSubTest();
47 	string1 = new BString("string");
48 	string2 = new BString("string");
49 	CPPUNIT_ASSERT(*string1 == *string2);
50 	delete string1;
51 	delete string2;
52 
53 	NextSubTest();
54 	string1 = new BString("text");
55 	string2 = new BString("string");
56 	CPPUNIT_ASSERT((*string1 == *string2) == false);
57 	delete string1;
58 	delete string2;
59 
60 	// operator>=(const BString &) const;
61 	NextSubTest();
62 	string1 = new BString("BBBBB");
63 	string2 = new BString("AAAAA");
64 	CPPUNIT_ASSERT(*string1 >= *string2);
65 	delete string1;
66 	delete string2;
67 
68 	NextSubTest();
69 	string1 = new BString("11111");
70 	string2 = new BString("11111");
71 	CPPUNIT_ASSERT(*string1 >= *string2);
72 	delete string1;
73 	delete string2;
74 
75 	// operator>(const BString &) const;
76 	NextSubTest();
77 	string1 = new BString("BBBBB");
78 	string2 = new BString("AAAAA");
79 	CPPUNIT_ASSERT(*string1 > *string2);
80 	delete string1;
81 	delete string2;
82 
83 	// operator!=(const BString &) const;
84 	NextSubTest();
85 	string1 = new BString("string");
86 	string2 = new BString("string");
87 	CPPUNIT_ASSERT((*string1 != *string2) == false);
88 	delete string1;
89 	delete string2;
90 
91 	NextSubTest();
92 	string1 = new BString("text");
93 	string2 = new BString("string");
94 	CPPUNIT_ASSERT(*string1 != *string2);
95 	delete string1;
96 	delete string2;
97 
98 	// operator<(const char *) const;
99 	NextSubTest();
100 	string1 = new BString("AAAAA");
101 	CPPUNIT_ASSERT(*string1 < "BBBBB");
102 	delete string1;
103 
104 	// operator<=(const char *) const;
105 	NextSubTest();
106 	string1 = new BString("AAAAA");
107 	CPPUNIT_ASSERT(*string1 <= "BBBBB");
108 	CPPUNIT_ASSERT(*string1 <= "AAAAA");
109 	delete string1;
110 
111 	// operator==(const char *) const;
112 	NextSubTest();
113 	string1 = new BString("AAAAA");
114 	CPPUNIT_ASSERT(*string1 == "AAAAA");
115 	delete string1;
116 
117 	NextSubTest();
118 	string1 = new BString("AAAAA");
119 	CPPUNIT_ASSERT((*string1 == "BBBB") == false);
120 	delete string1;
121 
122 	// operator>=(const char *) const;
123 	NextSubTest();
124 	string1 = new BString("BBBBB");
125 	CPPUNIT_ASSERT(*string1 >= "AAAAA");
126 	CPPUNIT_ASSERT(*string1 >= "BBBBB");
127 	delete string1;
128 
129 	// operator>(const char *) const;
130 	NextSubTest();
131 	string1 = new BString("BBBBB");
132 	CPPUNIT_ASSERT(*string1 > "AAAAA");
133 	delete string1;
134 
135 	// operator!=(const char *) const;
136 	NextSubTest();
137 	string1 = new BString("AAAAA");
138 	CPPUNIT_ASSERT((*string1 != "AAAAA") == false);
139 	delete string1;
140 
141 	NextSubTest();
142 	string1 = new BString("AAAAA");
143 	CPPUNIT_ASSERT(*string1 != "BBBB");
144 	delete string1;
145 }
146 
147 
suite(void)148 CppUnit::Test *StringCompareTest::suite(void)
149 {
150 	typedef CppUnit::TestCaller<StringCompareTest>
151 		StringCompareTestCaller;
152 
153 	return(new StringCompareTestCaller("BString::Compare Test",
154 		&StringCompareTest::PerformTest));
155 }
156