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

Revision 692, 4.5 KB checked in by mattausch, 18 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
26#include "OgreMaterialManager.h"
27#include "MaterialScriptCompilerTests.h"
28#include "OgreStringConverter.h"
29
30// Regsiter the suite
31CPPUNIT_TEST_SUITE_REGISTRATION( MaterialScriptCompilerTests );
32
33void MaterialScriptCompilerTests::setUp()
34{
35}
36void MaterialScriptCompilerTests::tearDown()
37{
38}
39
40void MaterialScriptCompilerTests::testPositionToNextSymbol()
41{
42  struct test1result{
43    const char character;
44    const int line;
45  };
46
47  const String TestStr1 = "   \n\r  //c  \n\r// test\n\r  \t  c   - \n\r ,  e";
48  const test1result test1results[] = {
49    {'c', 4},
50    {'-', 4},
51    {',', 5},
52    {'e', 5}
53  };
54
55  // first test: see if positionToNextSymbol can find a valid Symbol
56  mSource = &TestStr1;
57  mCharPos = 0;
58  size_t resultID = 0;
59  mCurrentLine = 1;
60  mEndOfSource = mSource->length();
61  while (positionToNextLexeme()) {
62      CPPUNIT_ASSERT_MESSAGE( "test " + StringConverter::toString(resultID) + "  character found: " + (*mSource)[mCharPos] +
63          "  Line:%d  : " + StringConverter::toString(mCurrentLine)
64          , ((*mSource)[mCharPos] == test1results[resultID].character) && (mCurrentLine==test1results[resultID].line) );
65    resultID++;
66    mCharPos++;
67  }
68
69}
70
71void MaterialScriptCompilerTests::testIsFloatValue(void)
72{
73  struct testfloatresult{
74    const String teststr;
75    const float fvalue;
76    const size_t charsize;
77    testfloatresult(const String& _teststr, const float _fvalue, const size_t _charsize)
78        : teststr(_teststr)
79        , fvalue(_fvalue)
80        , charsize(_charsize)
81        {};
82  };
83
84  testfloatresult testfloatresults[] = {
85    testfloatresult("1 test", 1.0f, 1),
86    testfloatresult("2.3f test", 2.3f, 3),
87    testfloatresult("-0.5 test", -0.5f, 4),
88    testfloatresult(" 23.6 test", 23.6f, 5),
89    testfloatresult("  -0.021 test", -0.021f, 8),
90    testfloatresult("12 test", 12.0f, 2),
91    testfloatresult("3test", 3.0f, 1)
92  };
93
94  float fvalue = 0;
95  size_t charsize = 0;
96  mCharPos = 0;
97  size_t testsize = ARRAYSIZE(testfloatresults);
98  for(size_t resultID=0; resultID<testsize; resultID++)
99  {
100    mSource = &testfloatresults[resultID].teststr;
101    isFloatValue(fvalue, charsize);
102    CPPUNIT_ASSERT_MESSAGE( "test " + StringConverter::toString(resultID) + " value returned: " + StringConverter::toString(fvalue)
103        , fvalue == testfloatresults[resultID].fvalue);
104    CPPUNIT_ASSERT_MESSAGE( "test " + StringConverter::toString(resultID) + " char size returned: " + StringConverter::toString(charsize)
105        , charsize == testfloatresults[resultID].charsize);
106  }
107
108}
109
110void MaterialScriptCompilerTests::testIsLexemeMatch(void)
111{
112  const String TestStr = "material test";
113  const String TestSymbols = "material";
114
115  mSource = &TestStr;
116  mCharPos = 0;
117  CPPUNIT_ASSERT(isLexemeMatch(TestSymbols, false));
118  CPPUNIT_ASSERT(isLexemeMatch(TestSymbols, true));
119  mCharPos = 1;
120  CPPUNIT_ASSERT(!isLexemeMatch(TestSymbols, false));
121  CPPUNIT_ASSERT(!isLexemeMatch(TestSymbols, true));
122
123}
124
125void MaterialScriptCompilerTests::testCompileMaterialScript()
126{
127    Math* mth = new Math();
128    ResourceGroupManager* resGrpMgr = new ResourceGroupManager();
129    MaterialManager* matMgr = new MaterialManager();
130    matMgr->initialise();
131
132    const String simpleScript = "material test { technique { pass {} } }";
133    CPPUNIT_ASSERT(compile(simpleScript, "MaterialScriptTest"));
134    delete matMgr;
135    delete resGrpMgr;
136    delete mth;
137}
138
Note: See TracBrowser for help on using the repository browser.