1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of OGRE |
---|
4 | (Object-oriented Graphics Rendering Engine) |
---|
5 | For the latest info, see http://www.ogre3d.org/ |
---|
6 | |
---|
7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
8 | Also see acknowledgements in Readme.html |
---|
9 | |
---|
10 | This program is free software; you can redistribute it and/or modify it under |
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
13 | version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
23 | |
---|
24 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | #include "StringTests.h" |
---|
30 | #include "OgreStringConverter.h" |
---|
31 | #include "OgreVector3.h" |
---|
32 | #include "OgreQuaternion.h" |
---|
33 | #include "OgreMatrix4.h" |
---|
34 | #include "OgreColourValue.h" |
---|
35 | |
---|
36 | using namespace Ogre; |
---|
37 | |
---|
38 | // Regsiter the suite |
---|
39 | CPPUNIT_TEST_SUITE_REGISTRATION( StringTests ); |
---|
40 | |
---|
41 | void StringTests::setUp() |
---|
42 | { |
---|
43 | testFileNoPath = "testfile.txt"; |
---|
44 | testFileRelativePathUnix = "this/is/relative/testfile.txt"; |
---|
45 | testFileRelativePathWindows = "this\\is\\relative\\testfile.txt"; |
---|
46 | testFileAbsolutePathUnix = "/this/is/absolute/testfile.txt"; |
---|
47 | testFileAbsolutePathWindows = "c:\\this\\is\\absolute\\testfile.txt"; |
---|
48 | } |
---|
49 | void StringTests::tearDown() |
---|
50 | { |
---|
51 | } |
---|
52 | |
---|
53 | void StringTests::testSplitFileNameNoPath() |
---|
54 | { |
---|
55 | String basename, path; |
---|
56 | StringUtil::splitFilename(testFileNoPath, basename, path); |
---|
57 | |
---|
58 | CPPUNIT_ASSERT_EQUAL(testFileNoPath, basename); |
---|
59 | CPPUNIT_ASSERT(path.empty()); |
---|
60 | } |
---|
61 | void StringTests::testSplitFileNameRelativePath() |
---|
62 | { |
---|
63 | String basename, path; |
---|
64 | // Unix |
---|
65 | StringUtil::splitFilename(testFileRelativePathUnix, basename, path); |
---|
66 | CPPUNIT_ASSERT_EQUAL(String("testfile.txt"), basename); |
---|
67 | CPPUNIT_ASSERT_EQUAL(String("this/is/relative/"), path); |
---|
68 | // Windows |
---|
69 | StringUtil::splitFilename(testFileRelativePathWindows, basename, path); |
---|
70 | CPPUNIT_ASSERT_EQUAL(String("testfile.txt"), basename); |
---|
71 | CPPUNIT_ASSERT_EQUAL(String("this/is/relative/"), path); |
---|
72 | |
---|
73 | } |
---|
74 | void StringTests::testSplitFileNameAbsolutePath() |
---|
75 | { |
---|
76 | String basename, path; |
---|
77 | // Unix |
---|
78 | StringUtil::splitFilename(testFileAbsolutePathUnix, basename, path); |
---|
79 | CPPUNIT_ASSERT_EQUAL(String("testfile.txt"), basename); |
---|
80 | CPPUNIT_ASSERT_EQUAL(String("/this/is/absolute/"), path); |
---|
81 | // Windows |
---|
82 | StringUtil::splitFilename(testFileAbsolutePathWindows, basename, path); |
---|
83 | CPPUNIT_ASSERT_EQUAL(String("testfile.txt"), basename); |
---|
84 | CPPUNIT_ASSERT_EQUAL(String("c:/this/is/absolute/"), path); |
---|
85 | } |
---|
86 | |
---|
87 | void StringTests::testMatchCaseSensitive() |
---|
88 | { |
---|
89 | // Test positive |
---|
90 | CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, testFileNoPath, true)); |
---|
91 | // Test negative |
---|
92 | String upperCase = testFileNoPath; |
---|
93 | StringUtil::toUpperCase(upperCase); |
---|
94 | CPPUNIT_ASSERT(!StringUtil::match(testFileNoPath, upperCase, true)); |
---|
95 | } |
---|
96 | void StringTests::testMatchCaseInSensitive() |
---|
97 | { |
---|
98 | // Test positive |
---|
99 | CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, testFileNoPath, false)); |
---|
100 | // Test positive |
---|
101 | String upperCase = testFileNoPath; |
---|
102 | StringUtil::toUpperCase(upperCase); |
---|
103 | CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, upperCase, false)); |
---|
104 | } |
---|
105 | void StringTests::testMatchGlobAll() |
---|
106 | { |
---|
107 | CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "*", true)); |
---|
108 | } |
---|
109 | void StringTests::testMatchGlobStart() |
---|
110 | { |
---|
111 | CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "*stfile.txt", true)); |
---|
112 | CPPUNIT_ASSERT(!StringUtil::match(testFileNoPath, "*astfile.txt", true)); |
---|
113 | } |
---|
114 | void StringTests::testMatchGlobEnd() |
---|
115 | { |
---|
116 | CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "testfile.*", true)); |
---|
117 | CPPUNIT_ASSERT(!StringUtil::match(testFileNoPath, "testfile.d*", true)); |
---|
118 | } |
---|
119 | void StringTests::testMatchGlobStartAndEnd() |
---|
120 | { |
---|
121 | CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "*stfile.*", true)); |
---|
122 | CPPUNIT_ASSERT(!StringUtil::match(testFileNoPath, "*astfile.d*", true)); |
---|
123 | } |
---|
124 | void StringTests::testMatchGlobMiddle() |
---|
125 | { |
---|
126 | CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "test*.txt", true)); |
---|
127 | CPPUNIT_ASSERT(!StringUtil::match(testFileNoPath, "last*.txt*", true)); |
---|
128 | } |
---|
129 | void StringTests::testMatchSuperGlobtastic() |
---|
130 | { |
---|
131 | CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "*e*tf*e.t*t", true)); |
---|
132 | } |
---|
133 | void StringTests::testParseReal() |
---|
134 | { |
---|
135 | Real r = 23.454; |
---|
136 | |
---|
137 | String s = StringConverter::toString(r); |
---|
138 | Real t = StringConverter::parseReal(s); |
---|
139 | |
---|
140 | CPPUNIT_ASSERT_EQUAL(r, t); |
---|
141 | |
---|
142 | |
---|
143 | } |
---|
144 | void StringTests::testParseInt() |
---|
145 | { |
---|
146 | |
---|
147 | int r = 223546; |
---|
148 | |
---|
149 | String s = StringConverter::toString(r); |
---|
150 | int t = StringConverter::parseInt(s); |
---|
151 | |
---|
152 | CPPUNIT_ASSERT_EQUAL(r, t); |
---|
153 | } |
---|
154 | void StringTests::testParseLong() |
---|
155 | { |
---|
156 | long r = -223546325346456; |
---|
157 | |
---|
158 | String s = StringConverter::toString(r); |
---|
159 | long t = StringConverter::parseLong(s); |
---|
160 | |
---|
161 | CPPUNIT_ASSERT_EQUAL(r, t); |
---|
162 | |
---|
163 | } |
---|
164 | void StringTests::testParseUnsignedLong() |
---|
165 | { |
---|
166 | unsigned long r = 1223546325346456; |
---|
167 | |
---|
168 | String s = StringConverter::toString(r); |
---|
169 | unsigned long t = StringConverter::parseUnsignedLong(s); |
---|
170 | |
---|
171 | CPPUNIT_ASSERT_EQUAL(r, t); |
---|
172 | |
---|
173 | } |
---|
174 | void StringTests::testParseVector3() |
---|
175 | { |
---|
176 | Vector3 r(0.12, 3.22, -4.04); |
---|
177 | |
---|
178 | String s = StringConverter::toString(r); |
---|
179 | Vector3 t = StringConverter::parseVector3(s); |
---|
180 | |
---|
181 | CPPUNIT_ASSERT_EQUAL(r, t); |
---|
182 | |
---|
183 | } |
---|
184 | void StringTests::testParseMatrix4() |
---|
185 | { |
---|
186 | Matrix4 r(1.12, 0, 0, 34, 0, 0.87, 0, 20, 0, 0, 0.56, 10, 0, 0, 0, 1); |
---|
187 | |
---|
188 | String s = StringConverter::toString(r); |
---|
189 | Matrix4 t = StringConverter::parseMatrix4(s); |
---|
190 | |
---|
191 | CPPUNIT_ASSERT_EQUAL(r, t); |
---|
192 | |
---|
193 | } |
---|
194 | void StringTests::testParseQuaternion() |
---|
195 | { |
---|
196 | Quaternion r(1.12, 0.87, 0.67, 1); |
---|
197 | |
---|
198 | String s = StringConverter::toString(r); |
---|
199 | Quaternion t = StringConverter::parseQuaternion(s); |
---|
200 | |
---|
201 | CPPUNIT_ASSERT_EQUAL(r, t); |
---|
202 | |
---|
203 | } |
---|
204 | void StringTests::testParseBool() |
---|
205 | { |
---|
206 | bool r = true; |
---|
207 | String s = StringConverter::toString(r); |
---|
208 | bool t = StringConverter::parseBool(s); |
---|
209 | CPPUNIT_ASSERT_EQUAL(r, t); |
---|
210 | |
---|
211 | r = false; |
---|
212 | s = StringConverter::toString(r); |
---|
213 | t = StringConverter::parseBool(s); |
---|
214 | CPPUNIT_ASSERT_EQUAL(r, t); |
---|
215 | |
---|
216 | } |
---|
217 | void StringTests::testParseColourValue() |
---|
218 | { |
---|
219 | ColourValue r(0.34, 0.44, 0.77, 1.0); |
---|
220 | |
---|
221 | String s = StringConverter::toString(r); |
---|
222 | ColourValue t = StringConverter::parseColourValue(s); |
---|
223 | CPPUNIT_ASSERT_EQUAL(r, t); |
---|
224 | |
---|
225 | } |
---|