Make elemental tests compile. Set ant task to run them.

- For some reason elemental tests were disabled, enabling them
  in order to realise when the api changes, or something breaks it.
- Fixing compilation, and disabling broken tests which have to
  be fixed in separated patches.

Change-Id: I06befa1b26efe55ad6964c582283adcb8efcfa1e
diff --git a/elemental/build.xml b/elemental/build.xml
index d486a2a..7333987 100644
--- a/elemental/build.xml
+++ b/elemental/build.xml
@@ -10,6 +10,12 @@
   <property.ensure name="gwt.dev.jar" location="${gwt.build.lib}/gwt-dev.jar" />
   <property.ensure name="gwt.user.jar" location="${gwt.build.lib}/gwt-user.jar" />
 
+  <target name="check.generated" description="Check whether elemental code has been generated">
+    <condition property="generated">
+      <available file="idl/generated/src" type="dir" />
+    </condition>
+  </target>
+
   <target name="generate" description="Generate Elemental bindings from IDL">
     <exec executable="idl/build" dir="." failonerror="true"/>
   </target>
@@ -24,6 +30,19 @@
     </gwt.javac>
   </target>
 
+  <target name="compile.tests" if="generated" depends="check.generated" description="Compile Tests">
+    <echo message="${javac.junit.out}" />
+    <mkdir dir="${javac.junit.out}" />
+    <javac srcdir="src:idl/generated/src:tests" destdir="${javac.junit.out}" excludes="**/super/**">
+      <classpath>
+        <pathelement location="${javac.out}"/>
+        <pathelement location="${gwt.dev.jar}" />
+        <pathelement location="${gwt.user.jar}" />
+        <pathelement location="${gwt.tools.lib}/junit/junit-4.8.2.jar" />
+      </classpath>
+    </javac>
+  </target>
+
   <target name="build" depends="generate, compile"
       description="Creates gwt-elemental.jar">
     <mkdir dir="${gwt.build.lib}" />
@@ -34,6 +53,24 @@
     </gwt.jar>
   </target>
 
+  <target name="test" if="generated" depends="compile.tests" description="Run tests">
+    <mkdir dir="${junit.out}/elemental" />
+    <fileset id="tests" dir="${javac.junit.out}" includes="**/AllTests.class" />
+    <gwt.junit test.name="test"
+        test.args="${test.args}"
+        test.jvmargs="${test.jvmargs}"
+        test.out="${junit.out}/codeserver"
+        test.cases="tests">
+      <extraclasspaths>
+        <pathelement location="${gwt.root}/elemental/src" />
+        <pathelement location="${gwt.root}/elemental/idl/generated/src" />
+        <pathelement location="${gwt.root}/elemental/tests" />
+        <pathelement location="${gwt.dev.jar}" />
+        <pathelement location="${gwt.user.jar}" />
+      </extraclasspaths>
+    </gwt.junit>
+  </target>
+
     <macrodef name="compileModule">
       <element name="module" />
       <sequential>
@@ -60,6 +97,7 @@
     <delete dir="idl/generated" />
     <delete dir="idl/database" />
     <delete dir="${project.build}" />
+    <delete dir="${javac.junit.out}" />
     <delete file="${project.lib}" />
   </target>
 </project>