source: OGRE/trunk/ogrenew/Tests/OgreMain/src/StringTests.cpp @ 657

Revision 657, 4.4 KB checked in by mattausch, 18 years ago (diff)

added ogre dependencies and patched ogre sources

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#include "StringTests.h"
26#include "OgreString.h"
27
28// Regsiter the suite
29CPPUNIT_TEST_SUITE_REGISTRATION( StringTests );
30
31void 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}
39void StringTests::tearDown()
40{
41}
42
43void 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}
51void 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}
64void 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
77void 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}
86void 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}
95void StringTests::testMatchGlobAll()
96{
97        CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "*", true));
98}
99void StringTests::testMatchGlobStart()
100{
101        CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "*stfile.txt", true));
102        CPPUNIT_ASSERT(!StringUtil::match(testFileNoPath, "*astfile.txt", true));
103}
104void StringTests::testMatchGlobEnd()
105{
106        CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "testfile.*", true));
107        CPPUNIT_ASSERT(!StringUtil::match(testFileNoPath, "testfile.d*", true));
108}
109void StringTests::testMatchGlobStartAndEnd()
110{
111        CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "*stfile.*", true));
112        CPPUNIT_ASSERT(!StringUtil::match(testFileNoPath, "*astfile.d*", true));
113}
114void StringTests::testMatchGlobMiddle()
115{
116        CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "test*.txt", true));
117        CPPUNIT_ASSERT(!StringUtil::match(testFileNoPath, "last*.txt*", true));
118}
119void StringTests::testMatchSuperGlobtastic()
120{
121        CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "*e*tf*e.t*t", true));
122}
Note: See TracBrowser for help on using the repository browser.