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

Revision 692, 4.4 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

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
27using namespace Ogre;
28
29// Regsiter the suite
30CPPUNIT_TEST_SUITE_REGISTRATION( StringTests );
31
32void 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}
40void StringTests::tearDown()
41{
42}
43
44void 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}
52void 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}
65void 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
78void 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}
87void 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}
96void StringTests::testMatchGlobAll()
97{
98        CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "*", true));
99}
100void StringTests::testMatchGlobStart()
101{
102        CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "*stfile.txt", true));
103        CPPUNIT_ASSERT(!StringUtil::match(testFileNoPath, "*astfile.txt", true));
104}
105void StringTests::testMatchGlobEnd()
106{
107        CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "testfile.*", true));
108        CPPUNIT_ASSERT(!StringUtil::match(testFileNoPath, "testfile.d*", true));
109}
110void StringTests::testMatchGlobStartAndEnd()
111{
112        CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "*stfile.*", true));
113        CPPUNIT_ASSERT(!StringUtil::match(testFileNoPath, "*astfile.d*", true));
114}
115void StringTests::testMatchGlobMiddle()
116{
117        CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "test*.txt", true));
118        CPPUNIT_ASSERT(!StringUtil::match(testFileNoPath, "last*.txt*", true));
119}
120void StringTests::testMatchSuperGlobtastic()
121{
122        CPPUNIT_ASSERT(StringUtil::match(testFileNoPath, "*e*tf*e.t*t", true));
123}
Note: See TracBrowser for help on using the repository browser.