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-2005 The OGRE Team
|
---|
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 | */
|
---|
25 | #include "StringTests.h"
|
---|
26 | #include "OgreString.h"
|
---|
27 |
|
---|
28 | // Regsiter the suite
|
---|
29 | CPPUNIT_TEST_SUITE_REGISTRATION( StringTests );
|
---|
30 |
|
---|
31 | void StringTests::setUp()
|
---|
32 | {
|
---|
33 | testFileNoPath = "testfile.txt";
|
---|
34 | testFileRelativePathUnix = "this/is/relative/testfile.txt";
|
---|
35 | testFileRelativePathWindows = "this\\is\\relative\\testfile.txt";
|
---|
36 | testFileAbsolutePathUnix = "/this/is/absolute/testfile.txt";
|
---|
37 | testFileAbsolutePathWindows = "c:\\this\\is\\absolute\\testfile.txt";
|
---|
38 | }
|
---|
39 | void StringTests::tearDown()
|
---|
40 | {
|
---|
41 | }
|
---|
42 |
|
---|
43 | void StringTests::testSplitFileNameNoPath()
|
---|
44 | {
|
---|
45 | String basename, path;
|
---|
46 | StringUtil::splitFilename(testFileNoPath, basename, path);
|
---|
47 |
|
---|
48 | CPPUNIT_ASSERT_EQUAL(testFileNoPath, basename);
|
---|
49 | CPPUNIT_ASSERT(path.empty());
|
---|
50 | }
|
---|
51 | void StringTests::testSplitFileNameRelativePath()
|
---|
52 | {
|
---|
53 | String basename, path;
|
---|
54 | // Unix
|
---|
55 | StringUtil::splitFilename(testFileRelativePathUnix, basename, path);
|
---|
56 | CPPUNIT_ASSERT_EQUAL(String("testfile.txt"), basename);
|
---|
57 | CPPUNIT_ASSERT_EQUAL(String("this/is/relative/"), path);
|
---|
58 | // Windows
|
---|
59 | StringUtil::splitFilename(testFileRelativePathWindows, basename, path);
|
---|
60 | CPPUNIT_ASSERT_EQUAL(String("testfile.txt"), basename);
|
---|
61 | CPPUNIT_ASSERT_EQUAL(String("this/is/relative/"), path);
|
---|
62 |
|
---|
63 | }
|
---|
64 | void StringTests::testSplitFileNameAbsolutePath()
|
---|
65 | {
|
---|
66 | String basename, path;
|
---|
67 | // Unix
|
---|
68 | StringUtil::splitFilename(testFileAbsolutePathUnix, basename, path);
|
---|
69 | CPPUNIT_ASSERT_EQUAL(String("testfile.txt"), basename);
|
---|
70 | CPPUNIT_ASSERT_EQUAL(String("/this/is/absolute/"), path);
|
---|
71 | // Windows
|
---|
72 | StringUtil::splitFilename(testFileAbsolutePathWindows, basename, path);
|
---|
73 | CPPUNIT_ASSERT_EQUAL(String("testfile.txt"), basename);
|
---|
74 | CPPUNIT_ASSERT_EQUAL(String("c:/this/is/absolute/"), path);
|
---|
75 | }
|
---|
76 |
|
---|
77 | void StringTests::testMatchCaseSensitive()
|
---|
78 | {
|
---|
79 | // Test positive
|
---|
80 | CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, testFileNoPath, true));
|
---|
81 | // Test negative
|
---|
82 | String upperCase = testFileNoPath;
|
---|
83 | StringUtil::toUpperCase(upperCase);
|
---|
84 | CPPUNIT_ASSERT(!StringUtil::match(testFileNoPath, upperCase, true));
|
---|
85 | }
|
---|
86 | void StringTests::testMatchCaseInSensitive()
|
---|
87 | {
|
---|
88 | // Test positive
|
---|
89 | CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, testFileNoPath, false));
|
---|
90 | // Test positive
|
---|
91 | String upperCase = testFileNoPath;
|
---|
92 | StringUtil::toUpperCase(upperCase);
|
---|
93 | CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, upperCase, false));
|
---|
94 | }
|
---|
95 | void StringTests::testMatchGlobAll()
|
---|
96 | {
|
---|
97 | CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "*", true));
|
---|
98 | }
|
---|
99 | void StringTests::testMatchGlobStart()
|
---|
100 | {
|
---|
101 | CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "*stfile.txt", true));
|
---|
102 | CPPUNIT_ASSERT(!StringUtil::match(testFileNoPath, "*astfile.txt", true));
|
---|
103 | }
|
---|
104 | void StringTests::testMatchGlobEnd()
|
---|
105 | {
|
---|
106 | CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "testfile.*", true));
|
---|
107 | CPPUNIT_ASSERT(!StringUtil::match(testFileNoPath, "testfile.d*", true));
|
---|
108 | }
|
---|
109 | void StringTests::testMatchGlobStartAndEnd()
|
---|
110 | {
|
---|
111 | CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "*stfile.*", true));
|
---|
112 | CPPUNIT_ASSERT(!StringUtil::match(testFileNoPath, "*astfile.d*", true));
|
---|
113 | }
|
---|
114 | void StringTests::testMatchGlobMiddle()
|
---|
115 | {
|
---|
116 | CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "test*.txt", true));
|
---|
117 | CPPUNIT_ASSERT(!StringUtil::match(testFileNoPath, "last*.txt*", true));
|
---|
118 | }
|
---|
119 | void StringTests::testMatchSuperGlobtastic()
|
---|
120 | {
|
---|
121 | CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "*e*tf*e.t*t", true));
|
---|
122 | }
|
---|