package se.ejp.traci.lang.interpreter.node;

import static org.junit.Assert.assertEquals;

import org.antlr.runtime.RecognitionException;
import org.junit.Test;

import se.ejp.traci.lang.interpreter.TraciValue.Type;
import se.ejp.traci.lang.interpreter.exceptions.InterpreterRuntimeException;
import se.ejp.traci.math.Transformations;
import se.ejp.traci.math.Vector;
import se.ejp.traci.model.Color;
import se.ejp.traci.model.material.pigment.Checker;
import se.ejp.traci.model.material.pigment.FileImage;
import se.ejp.traci.model.material.pigment.Solid;

public class InterpreterPigmentTest extends InterpreterObjectBase
{
    public InterpreterPigmentTest()
    {
        super(Type.PIGMENT);
    }

    @Test
    public void testSolid() throws RecognitionException, InterpreterRuntimeException
    {
        final String args = "color [.1, .2, .3]";
        final String modifiers = "rotx 2.23;";

        for (final Solid solid : runTests("solid", Solid.class, args, null))
        {
            assertEquals(Color.make(.1, .2, .3), solid.getColor(Vector.ORIGO));
        }

        for (final Solid solid: runTests("solid", Solid.class, args, modifiers))
        {
            assertEquals(Color.make(.1, .2, .3), solid.getColor(Vector.ORIGO));
        }
    }

    @Test
    public void testChecker() throws RecognitionException, InterpreterRuntimeException
    {
        final String args = "color [.5, .5, .5], color [.1, .2, .3]";
        final String modifiers = "rotx 2.23;";

        for (final Checker checker : runTests("checker", Checker.class, args, null))
        {
            assertEquals(Color.make(.5, .5, .5), checker.color1.color);
            assertEquals(Color.make(.1, .2, .3), checker.color2.color);
            assertEquals(Transformations.identity(), checker.getTransformation());
        }

        for (final Checker checker: runTests("checker", Checker.class, args, modifiers))
        {
            assertEquals(Color.make(.5, .5, .5), checker.color1.color);
            assertEquals(Color.make(.1, .2, .3), checker.color2.color);
            assertEquals(Transformations.rotx(2.23), checker.getTransformation());
        }
    }

    @Test
    public void testImage() throws RecognitionException, InterpreterRuntimeException
    {
        final String args = "\"images/lenna.png\", \"repeat\", \"cylinder\"";
        final String modifiers = "rotx 2.23;";

        runTests("image", FileImage.class, args, null);
        runTests("image", FileImage.class, args, modifiers);
    }
}

@@ -268,32 +268,143 @@
 erpreter
-RuntimeException
+IOException;%0Aimport se.ejp.traci.lang.interpreter.exceptions.InterpreterRuntimeException;%0Aimport se.ejp.traci.math.Projection2D
 ;%0Aimport
@@ -611,16 +611,73 @@
 eImage;%0A
+import se.ejp.traci.model.material.pigment.RepeatPolicy;%0A
 import s
@@ -2449,24 +2449,25 @@
  String args
+1
  = %22%5C%22images
@@ -2507,16 +2507,104 @@
 der%5C%22%22;%0A
+        final String args2 = %22%5C%22images/lenna.png%5C%22, %5C%22border%5C%22, %5C%22xy%5C%22, color %5B1,1,1%5D%22;%0A
         
@@ -2642,32 +2642,65 @@
 2.23;%22;%0A%0A       
+ for (final FileImage fileImage :
  runTests(%22image
@@ -2727,24 +2727,434 @@
 args
+1
 , null)
-;%0A       
+)%0A        %7B%0A            assertEquals(%22images/lenna.png%22, fileImage.filename);%0A            assertEquals(RepeatPolicy.REPEAT, fileImage.repeatPolicy);%0A            assertEquals(Projection2D.CYLINDER, fileImage.projection);%0A            assertEquals(Color.BLACK, fileImage.borderColor);%0A            assertEquals(Transformations.identity(), fileImage.getTransformation());%0A        %7D%0A%0A        for (final FileImage fileImage :
  run
@@ -3181,32 +3181,33 @@
 mage.class, args
+2
 , modifiers);%0A  
@@ -3202,16 +3202,752 @@
 difiers)
+)%0A        %7B%0A            assertEquals(%22images/lenna.png%22, fileImage.filename);%0A            assertEquals(RepeatPolicy.BORDER, fileImage.repeatPolicy);%0A            assertEquals(Projection2D.XY_PLANE, fileImage.projection);%0A            assertEquals(Color.WHITE, fileImage.borderColor);%0A            assertEquals(Transformations.rotx(2.23), fileImage.getTransformation());%0A        %7D%0A%0A        runTestsFail(InterpreterIOException.class, %22image%22, %22%5C%22non/existing/file.png%5C%22, %5C%22repeat%5C%22, %5C%22cylinder%5C%22%22, null);%0A        runTestsFail(InterpreterRuntimeException.class, %22image%22, %22%5C%22images/lenna.png%5C%22, %5C%22knas%5C%22, %5C%22cylinder%5C%22%22, null);%0A        runTestsFail(InterpreterRuntimeException.class, %22image%22, %22%5C%22images/lenna.png%5C%22, %5C%22repeat%5C%22, %5C%22knas%5C%22%22, null)
 ;%0A    %7D%0A

Test image.