Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre/Tests/OgreMain/src/CompositorScriptCompilerTests.cpp @ 45

Last change on this file since 45 was 5, checked in by anonymous, 17 years ago

=hoffentlich gehts jetzt

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