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

Revision 692, 7.9 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 "OgreMaterialManager.h"
26#include "OgreCompositorManager.h"
27#include "CompositorScriptCompilerTests.h"
28#include "OgreCompositorScriptCompiler.h"
29#include "OgreStringConverter.h"
30
31// Regsiter the suite
32CPPUNIT_TEST_SUITE_REGISTRATION( CompositorScriptCompilerTests );
33
34void CompositorScriptCompilerTests::setUp()
35{
36}
37void CompositorScriptCompilerTests::tearDown()
38{
39}
40
41void CompositorScriptCompilerTests::testPositionToNextSymbol()
42{
43  struct test1result{
44    const char character;
45    const int line;
46  };
47
48  const String TestStr1 = "   \n\r  //c  \n\r// test\n\r  \t  c   - \n\r ,  e";
49  const test1result test1results[] = {
50    {'c', 4},
51    {'-', 4},
52    {',', 5},
53    {'e', 5}
54  };
55
56  // first test: see if positionToNextSymbol can find a valid Symbol
57  mSource = &TestStr1;
58  mCharPos = 0;
59  size_t resultID = 0;
60  mCurrentLine = 1;
61  mEndOfSource = mSource->length();
62  while (positionToNextLexeme()) {
63      CPPUNIT_ASSERT_MESSAGE( "test " + StringConverter::toString(resultID) + "  character found: " + (*mSource)[mCharPos] +
64          "  Line:%d  : " + StringConverter::toString(mCurrentLine)
65          , ((*mSource)[mCharPos] == test1results[resultID].character) && (mCurrentLine==test1results[resultID].line) );
66    resultID++;
67    mCharPos++;
68  }
69
70}
71
72void CompositorScriptCompilerTests::testIsFloatValue(void)
73{
74  struct testfloatresult{
75    const String teststr;
76    const float fvalue;
77    const size_t charsize;
78    testfloatresult(const String& _teststr, const float _fvalue, const size_t _charsize)
79        : teststr(_teststr)
80        , fvalue(_fvalue)
81        , charsize(_charsize)
82        {};
83  };
84
85  testfloatresult testfloatresults[] = {
86    testfloatresult("1 test", 1.0f, 1),
87    testfloatresult("2.3f test", 2.3f, 3),
88    testfloatresult("-0.5 test", -0.5f, 4),
89    testfloatresult(" 23.6 test", 23.6f, 5),
90    testfloatresult("  -0.021 test", -0.021f, 8),
91    testfloatresult("12 test", 12.0f, 2),
92    testfloatresult("3test", 3.0f, 1)
93  };
94
95  float fvalue = 0;
96  size_t charsize = 0;
97  mCharPos = 0;
98  size_t testsize = ARRAYSIZE(testfloatresults);
99  for(size_t resultID=0; resultID<testsize; resultID++)
100  {
101    mSource = &testfloatresults[resultID].teststr;
102    isFloatValue(fvalue, charsize);
103    CPPUNIT_ASSERT_MESSAGE( "test " + StringConverter::toString(resultID) + " value returned: " + StringConverter::toString(fvalue)
104        , fvalue == testfloatresults[resultID].fvalue);
105    CPPUNIT_ASSERT_MESSAGE( "test " + StringConverter::toString(resultID) + " char size returned: " + StringConverter::toString(charsize)
106        , charsize == testfloatresults[resultID].charsize);
107  }
108
109}
110
111void CompositorScriptCompilerTests::testIsLexemeMatch(void)
112{
113  const String TestStr = "Compositor test";
114  const String TestSymbols = "compositor";
115
116  mSource = &TestStr;
117  mCharPos = 0;
118  CPPUNIT_ASSERT(isLexemeMatch(TestSymbols, false));
119  CPPUNIT_ASSERT(isLexemeMatch(TestSymbols, true));
120  mCharPos = 1;
121  CPPUNIT_ASSERT(!isLexemeMatch(TestSymbols, false));
122  CPPUNIT_ASSERT(!isLexemeMatch(TestSymbols, true));
123
124}
125
126void CompositorScriptCompilerTests::testCompile()
127{
128    ResourceGroupManager* resGrpMgr = new ResourceGroupManager();
129    MaterialManager* matMgr = new MaterialManager();
130    matMgr->initialise();
131    CompositorManager* compositorMgr = new CompositorManager();
132    //compositorMgr->initialise();
133
134    const String simpleScript = "compositor Test { technique { target_output { } } }";
135    CPPUNIT_ASSERT(compile(simpleScript, "Test Compositor"));
136
137    const String BW_Script =
138        "/// Black and white effect \n"
139        "compositor B&W \n"
140        "{ \n"
141        "    technique \n"
142        "    { \n"
143        "        // Temporary textures \n"
144        "        texture scene target_width target_height PF_A8R8G8B8 \n"
145        " \n"
146        "        target scene \n"
147        "        { \n"
148        "            // Render output from previous compositor (or original scene) \n"
149        "            input previous \n"
150        "        }"
151        "        target_output \n"
152        "        { \n"
153        "            // Start with clear output \n"
154        "            input none \n"
155        "            // Draw a fullscreen quad with the blur \n"
156        "            pass render_quad \n"
157        "            { \n"
158        "                // Renders a fullscreen quad with a material \n"
159        "                material PostFilters/BlackAndWhite \n"
160        "                input 0 scene \n"
161        "            } \n"
162        "        } \n"
163        "    } \n"
164        "} \n";
165
166    CPPUNIT_ASSERT(compile(BW_Script, "Test Black & White Script"));
167
168    const String Bloom_Script =
169    "/// Manuel's bloom \n"
170    "/// Needs a scene-sized rtt, but does only one render of the scene \n"
171    "compositor Bloom \n"
172    "{ \n"
173    "    technique \n"
174    "    { \n"
175    "        // Temporary textures \n"
176    "        texture scene target_width target_height PF_A8R8G8B8 \n"
177    "        texture rt0 128 128 PF_A8R8G8B8 \n"
178    "        texture rt1 128 128 PF_A8R8G8B8 \n"
179    "     \n"
180    "        target scene \n"
181    "        { \n"
182    "            // Render output from previous compositor (or original scene) \n"
183    "            input previous \n"
184    "        } \n"
185    "        target rt0 \n"
186    "        { \n"
187    "            // Start with clear texture \n"
188    "            input none \n"
189    "            // Vertical blur pass \n"
190    "            pass render_quad \n"
191    "            { \n"
192    "                // Renders a fullscreen quad with a material \n"
193    "                material PostFilters/Blur0 \n"
194    "                input 0 scene \n"
195    "            } \n"
196    "        } \n"
197    "        target rt1 \n"
198    "        { \n"
199    "            // Start with clear texture \n"
200    "            input none \n"
201    "            // Horizontal blur pass \n"
202    "            pass render_quad \n"
203    "            { \n"
204    "                // Renders a fullscreen quad with a material \n"
205    "                material PostFilters/Blur1 \n"
206    "                input 0 rt0 \n"
207    "            } \n"
208    "        } \n"
209    "        target_output \n"
210    "        { \n"
211    "            // Start with clear output \n"
212    "            input none \n"
213    "            // Draw a fullscreen quad \n"
214    "            pass render_quad \n"
215    "            { \n"
216    "                // Renders a fullscreen quad with a material \n"
217    "                material PostFilters/BloomBlend \n"
218    "                input 0 scene \n"
219    "                input 1 rt1 \n"
220    "            } \n"
221    "        } \n"
222    "    } \n"
223    "} \n";
224    CPPUNIT_ASSERT(compile(Bloom_Script, "Test Bloom Script"));
225
226    delete compositorMgr;
227    delete matMgr;
228    delete resGrpMgr;
229}
230
Note: See TracBrowser for help on using the repository browser.