/*
 * This file is released under terms of BSD license
 * See LICENSE file for more information
 */

package cx2x.xcodeml.xelement;

import helper.XmlHelper;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 * Test features of the XindexRange class. 
 *
 * @author clementval
 */
public class XindexRangeTest {

  private static final String idxRange1 =
      "<indexRange>" +
      "<lowerBound>" +
      "<FintConstant type=\"Fint\">1</FintConstant>" +
      "</lowerBound>" +
      "<upperBound>" +
      "<FintConstant type=\"Fint\">10</FintConstant>" +
      "</upperBound>" +
      "<step>" +
      "<FintConstant type=\"Fint\">1</FintConstant>" +
      "</step>" +
      "</indexRange>";

  @Test
  public void simpleIndexRangeTest(){
    XindexRange idx = XmlHelper.createXindexRange(idxRange1);
    assertNotNull(idx);
    assertNotNull(idx.getLowerBound());
    assertNotNull(idx.getUpperBound());
    assertNotNull(idx.getStep());
    assertTrue(idx.getLowerBound().getExprModel().isIntConst());
    assertTrue(idx.getUpperBound().getExprModel().isIntConst());
    assertTrue(idx.getStep().getExprModel().isIntConst());

    assertEquals("1",
        idx.getLowerBound().getExprModel().getIntConstant().getValue());
    assertEquals("10",
        idx.getUpperBound().getExprModel().getIntConstant().getValue());
    assertEquals("1",
        idx.getStep().getExprModel().getIntConstant().getValue());
  }
}

@@ -126,16 +126,121 @@
 ement;%0A%0A
+import cx2x.xcodeml.exception.IllegalTransformationException;%0Aimport cx2x.xcodeml.helper.XelementHelper;%0A
 import h
@@ -1526,11 +1526,1497 @@
 ());%0A  %7D
+%0A%0A  @Test%0A  public void createTest()%7B%0A    try %7B%0A      XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram();%0A      Xvar var = Xvar.create(%22dummy%22, %22array1%22, Xscope.LOCAL, xcodeml);%0A      XindexRange range = XindexRange.createAssumedShapeRange(xcodeml, var);%0A      assertFalse(range.isAssumedShape());%0A      assertNotNull(range.getLowerBound());%0A%0A      assertNotNull(range.getLowerBound().getExprModel());%0A      assertTrue(range.getLowerBound().getExprModel().isIntConst());%0A      assertNotNull(range.getLowerBound().getExprModel().getIntConstant());%0A      assertEquals(%220%22, range.getLowerBound().getExprModel().getIntConstant().%0A          getValue());%0A%0A      assertNotNull(range.getUpperBound());%0A      assertTrue(range.getUpperBound().getExprModel().isFctCall());%0A      assertNotNull(range.getUpperBound().getExprModel().getFctCall());%0A      assertTrue(range.getUpperBound().getExprModel().getFctCall().%0A          isIntrinsic());%0A      assertNotNull(range.getUpperBound().getExprModel().getFctCall().%0A          getName());%0A      assertEquals(XelementName.INTRINSIC_SIZE,%0A          range.getUpperBound().getExprModel().getFctCall().getName().%0A              getValue());%0A      assertEquals(1, range.getUpperBound().getExprModel().getFctCall().%0A          getArgumentsTable().count());%0A      assertNotNull(range.getUpperBound().getExprModel().getFctCall().%0A          getArgumentsTable().findArgument(%22array1%22));%0A    %7D catch (IllegalTransformationException itex) %7B%0A      fail();%0A    %7D%0A  %7D
 %0A%7D%0A

Add unit test for createAssumedShapeRange