[opengtl-commits] [609] add a test for a filter example

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 609
Author:   cyrille
Date:     2009-03-13 19:44:07 +0100 (Fri, 13 Mar 2009)

Log Message:
-----------
add a test for a filter example

Modified Paths:
--------------
    trunk/OpenGTL/OpenShiva/OpenShiva/LightParser_p.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/Source.cpp
    trunk/OpenGTL/OpenShiva/tests/library/TestSource.h


Modified: trunk/OpenGTL/OpenShiva/OpenShiva/LightParser_p.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/LightParser_p.cpp	2009-03-13 18:35:56 UTC (rev 608)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/LightParser_p.cpp	2009-03-13 18:44:07 UTC (rev 609)
@@ -117,51 +117,48 @@
               while(currentToken().type != GTLCore::Token::ENDBRACE and currentToken().type != GTLCore::Token::END_OF_FILE )
               {
                 // Next is either a type or a end bracket
-                if( isType(currentToken()) or currentToken().type == GTLCore::Token::OUTPUT or currentToken().type == GTLCore::Token::INPUT or currentToken().type == GTLCore::Token::VARYING )
+                bool output = false;
+                bool varying = false;
+                if( currentToken().type == GTLCore::Token::OUTPUT )
                 {
-                  bool output = false;
-                  bool varying = false;
-                  if( currentToken().type == GTLCore::Token::OUTPUT )
+                  output = true;
+                  getNextToken();
+                } else if( currentToken().type == GTLCore::Token::VARYING )
+                {
+                  varying = true;
+                  getNextToken();
+                }else if( currentToken().type == GTLCore::Token::INPUT )
+                {
+                  getNextToken();
+                }
+                if( currentToken().type == GTLCore::Token::IDENTIFIER )
+                {
+                  Source::ImageType image;
+                  if( currentToken().string == "image" or currentToken().string == "pixel" )
                   {
-                    output = true;
-                    getNextToken();
-                  } else if( currentToken().type == GTLCore::Token::VARYING )
+                    image = Source::Image;
+                  } else if( currentToken().string == "image1" or currentToken().string == "pixel1" )
                   {
-                    varying = true;
-                    getNextToken();
-                  }else if( currentToken().type == GTLCore::Token::INPUT )
+                    image = Source::Image1;
+                  } else if( currentToken().string == "image2" or currentToken().string == "pixel2" )
                   {
-                    getNextToken();
+                    image = Source::Image2;
+                  } else if( currentToken().string == "image3" or currentToken().string == "pixel3" )
+                  {
+                    image = Source::Image3;
+                  } else if( currentToken().string == "image4" or currentToken().string == "pixel4" )
+                  {
+                    image = Source::Image4;
+                  } else {
+                    image = Source::InvalidImage;
                   }
-                  if( currentToken().type == GTLCore::Token::IDENTIFIER )
+                  if( output )
                   {
-                    Source::ImageType image;
-                    if( currentToken().string == "image" or currentToken().string == "pixel" )
-                    {
-                      image = Source::Image;
-                    } else if( currentToken().string == "image1" or currentToken().string == "pixel1" )
-                    {
-                      image = Source::Image1;
-                    } else if( currentToken().string == "image2" or currentToken().string == "pixel2" )
-                    {
-                      image = Source::Image2;
-                    } else if( currentToken().string == "image3" or currentToken().string == "pixel3" )
-                    {
-                      image = Source::Image3;
-                    } else if( currentToken().string == "image4" or currentToken().string == "pixel4" )
-                    {
-                      image = Source::Image4;
-                    } else {
-                      image = Source::InvalidImage;
-                    }
-                    if( output )
-                    {
-                      d->outputImageType = image;
-                    } else {
-                      d->inputImageTypes.push_back(image);
-                    }
-                    eatUntil( GTLCore::Token::ENDBRACE, GTLCore::Token::COMA );
+                    d->outputImageType = image;
+                  } else {
+                    d->inputImageTypes.push_back(image);
                   }
+                  eatUntil( GTLCore::Token::ENDBRACE, GTLCore::Token::COMA );
                 }
               }
             } else {

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Source.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Source.cpp	2009-03-13 18:35:56 UTC (rev 608)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Source.cpp	2009-03-13 18:44:07 UTC (rev 609)
@@ -167,7 +167,7 @@
 
 Source::ImageType Source::inputImageType(int idx) const
 {
-  if( idx > 0 and (std::size_t)idx < d->inputImageTypes.size())
+  if( idx >= 0 and (std::size_t)idx < d->inputImageTypes.size())
   {
     return d->inputImageTypes[idx];
   }

Modified: trunk/OpenGTL/OpenShiva/tests/library/TestSource.h
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/library/TestSource.h	2009-03-13 18:35:56 UTC (rev 608)
+++ trunk/OpenGTL/OpenShiva/tests/library/TestSource.h	2009-03-13 18:44:07 UTC (rev 609)
@@ -24,20 +24,39 @@
     TestSource() : GTLTest::Case("Source") {}
     virtual void runTest()
     {
-      GTLCore::String sourceCodeGenerator = "\
-kernel myGenerator { \
-  void evaluatePixel(out pixel result) \
-  { } \
-}";
-      OpenShiva::Source sourceGenerator;
-      sourceGenerator.setSource(sourceCodeGenerator);
-      GTLTEST_CHECK_EQUAL( sourceGenerator.source(), sourceCodeGenerator );
-      GTLTEST_CHECK_EQUAL( sourceGenerator.name(), "myGenerator" );
-      GTLTEST_CHECK_EQUAL( sourceGenerator.metadataCompilationErrors().size(), 0 );
-      GTLTEST_CHECK_EQUAL( sourceGenerator.sourceType(), OpenShiva::Source::GeneratorKernel );
-      GTLTEST_CHECK_EQUAL( sourceGenerator.outputImageType(), OpenShiva::Source::Image );
-      GTLTEST_CHECK_EQUAL( sourceGenerator.countInputImages(), 0 );
-      GTLTEST_CHECK_EQUAL( sourceGenerator.inputImageType(0), OpenShiva::Source::InvalidImage );
+      {
+        GTLCore::String sourceCodeGenerator = "\
+  kernel myGenerator { \
+    void evaluatePixel(out pixel result) \
+    { } \
+  }";
+        OpenShiva::Source sourceGenerator;
+        sourceGenerator.setSource(sourceCodeGenerator);
+        GTLTEST_CHECK_EQUAL( sourceGenerator.source(), sourceCodeGenerator );
+        GTLTEST_CHECK_EQUAL( sourceGenerator.name(), "myGenerator" );
+        GTLTEST_CHECK_EQUAL( sourceGenerator.metadataCompilationErrors().size(), 0 );
+        GTLTEST_CHECK_EQUAL( sourceGenerator.sourceType(), OpenShiva::Source::GeneratorKernel );
+        GTLTEST_CHECK_EQUAL( sourceGenerator.outputImageType(), OpenShiva::Source::Image );
+        GTLTEST_CHECK_EQUAL( sourceGenerator.countInputImages(), 0 );
+        GTLTEST_CHECK_EQUAL( sourceGenerator.inputImageType(0), OpenShiva::Source::InvalidImage );
+      }
+      {
+        GTLCore::String sourceCodeFilter = "\
+  kernel myFilter { \
+    void evaluatePixel(image2 im1, out pixel3 result) \
+    { } \
+  }";
+        OpenShiva::Source sourceFilter;
+        sourceFilter.setSource(sourceCodeFilter);
+        GTLTEST_CHECK_EQUAL( sourceFilter.source(), sourceCodeFilter );
+        GTLTEST_CHECK_EQUAL( sourceFilter.name(), "myFilter" );
+        GTLTEST_CHECK_EQUAL( sourceFilter.metadataCompilationErrors().size(), 0 );
+        GTLTEST_CHECK_EQUAL( sourceFilter.sourceType(), OpenShiva::Source::FilterKernel );
+        GTLTEST_CHECK_EQUAL( sourceFilter.outputImageType(), OpenShiva::Source::Image3 );
+        GTLTEST_CHECK_EQUAL( sourceFilter.countInputImages(), 1 );
+        GTLTEST_CHECK_EQUAL( sourceFilter.inputImageType(0), OpenShiva::Source::Image2 );
+        GTLTEST_CHECK_EQUAL( sourceFilter.inputImageType(1), OpenShiva::Source::InvalidImage );
+      }
     }
 };
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/