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