package xelement;

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

import org.w3c.dom.Element;

import helper.XmlHelper;

import x2x.translator.xcodeml.xelement.Xid;

public class XidTest {


  private Xid createXidFromString(){
    String simpleIdElement = "<id type=\"F7f9502e03d00\" sclass=\"ffunc\"><name>loop_extract</name></id>";
    Element id = XmlHelper.getElementFromString(simpleIdElement);
    assertNotNull(id);
    return new Xid(id);
  }


  @Test
  public void readElementInformationTest() {
    Xid simpleId = createXidFromString();
    assertEquals("loop_extract", simpleId.getName());
    assertEquals("F7f9502e03d00", simpleId.getType());
    assertEquals("ffunc", simpleId.getSclass());
  }

  @Test
  public void setElementInformationTest() {
    Xid simpleId = createXidFromString();
    simpleId.setName("new_name");
    simpleId.setType("new_type");
    simpleId.setSclass("auto");

    assertEquals("new_name", simpleId.getName());
    assertEquals("new_type", simpleId.getType());
    assertEquals("auto", simpleId.getSclass());
  }


}

@@ -197,139 +197,516 @@
 t %7B%0A
-%0A%0A  private Xid createXidFromString()%7B%0A    String simpleIdElement = %22%3Cid type=%5C%22F7f9502e03d00%5C%22 sclass=%5C%22ffunc%5C%22%3E%3Cname%3Eloop_extract
+  private static final String TEST_TYPE = %22F7f9502e03d00%22;%0A  private static final String TEST_SCLASS = %22ffunc%22;%0A  private static final String TEST_NAME = %22loop_extract%22;%0A%0A  private static final String ALT_TEST_TYPE = %22F7f81a04070d0%22;%0A  private static final String ALT_TEST_SCLASS = %22auto%22;%0A  private static final String ALT_TEST_NAME = %22func_name%22;%0A%0A  private Xid createXidFromString()%7B%0A    String simpleIdElement = %22%3Cid type=%5C%22%22 + TEST_TYPE + %22%5C%22 sclass=%5C%22%22 +%0A      TEST_SCLASS + %22%5C%22%3E%3Cname%3E%22 + TEST_NAME + %22
 %3C/na
@@ -834,17 +834,16 @@
 );%0A  %7D%0A%0A
-%0A
   @Test%0A
@@ -946,30 +946,25 @@
 tEquals(
-%22loop_extract%22
+TEST_NAME
 , simple
@@ -995,31 +995,25 @@
 tEquals(
-%22F7f9502e03d00%22
+TEST_TYPE
 , simple
@@ -1044,23 +1044,27 @@
 tEquals(
-%22ffunc%22
+TEST_SCLASS
 , simple
@@ -1200,26 +1200,29 @@
 setName(
-%22new_name%22
+ALT_TEST_NAME
 );%0A    s
@@ -1237,26 +1237,29 @@
 setType(
-%22new_type%22
+ALT_TEST_TYPE
 );%0A    s
@@ -1276,22 +1276,31 @@
 tSclass(
-%22auto%22
+ALT_TEST_SCLASS
 );%0A%0A    
@@ -1316,18 +1316,21 @@
 als(
-%22new_name%22
+ALT_TEST_NAME
 , si
@@ -1369,18 +1369,21 @@
 als(
-%22new_type%22
+ALT_TEST_TYPE
 , si
@@ -1418,22 +1418,31 @@
 tEquals(
-%22auto%22
+ALT_TEST_SCLASS
 , simple

Update test with constants