/*
 * 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 XifStatement, Xcondition, Xthen, Xelse classes.
 *
 * @author clementval
 */
public class XifStatementTest {

  private static final String ifStmt1 =
      "<FifStatement construct_name=\"myif\" lineno=\"3\" file=\"test.f90\">" +
      "<condition>" +
      "<FlogicalConstant type=\"Flogical\">.TRUE.</FlogicalConstant>" +
      "</condition>" +
      "<then>" +
      "<body>" +
      "</body>" +
      "</then>" +
      "<else>" +
      "<body>" +
      "</body>" +
      "</else>" +
      "</FifStatement>";


  @Test
  public void simpleIfStatementTest(){
    XifStatement ifStmt = XmlHelper.createXifStatement(ifStmt1);
    assertNotNull(ifStmt);
    assertNotNull(ifStmt.getConstructName());
    assertEquals("myif", ifStmt.getConstructName());
    assertNotNull(ifStmt.getCondition());
    assertNotNull(ifStmt.getCondition().getExprModel());
    assertTrue(ifStmt.getCondition().getExprModel().isLogicalConst());
    assertNotNull(ifStmt.getCondition().getExprModel().getLogicalConstant());
    assertEquals(".TRUE.",
        ifStmt.getCondition().getExprModel().getLogicalConstant().getValue());
    assertEquals(XelementName.TYPE_F_LOGICAL,
        ifStmt.getCondition().getExprModel().getLogicalConstant().getType());
    assertNotNull(ifStmt.getThen());
    assertNotNull(ifStmt.getThen().getBody());
    assertNotNull(ifStmt.getElse());
    assertNotNull(ifStmt.getElse().getBody());

    assertEquals(3, ifStmt.getLineNo());
    assertEquals("test.f90", ifStmt.getFile());
  }
}

@@ -126,16 +126,78 @@
 ement;%0A%0A
+import cx2x.xcodeml.exception.IllegalTransformationException;%0A
 import h
@@ -236,16 +236,17 @@
 t.Test;%0A
+%0A
 import s
@@ -1791,11 +1791,768 @@
 ());%0A  %7D
+%0A%0A  @Test%0A  public void createIfStatementTest()%7B%0A    try %7B%0A      XcodeProgram xcodeml = XmlHelper.getDummyXcodeProgram();%0A      XifStatement stmt1 = XifStatement.create(xcodeml);%0A      assertNotNull(stmt1);%0A      assertNotNull(stmt1.getCondition());%0A      assertNotNull(stmt1.getThen());%0A      assertNotNull(stmt1.getThen().getBody());%0A      assertNull(stmt1.getElse());%0A%0A      XifStatement stmt2 = XifStatement.createWithElseBlock(xcodeml);%0A      assertNotNull(stmt2);%0A      assertNotNull(stmt2.getCondition());%0A      assertNotNull(stmt2.getThen());%0A      assertNotNull(stmt2.getThen().getBody());%0A      assertNotNull(stmt2.getElse());%0A      assertNotNull(stmt2.getElse().getBody());%0A    %7D catch (IllegalTransformationException e) %7B%0A      fail();%0A    %7D%0A  %7D
 %0A%7D%0A

Add unit tests for if statement creation