felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r579295 - in /felix/sandbox/clement/Tests/UTF: ./ src/ src/main/ src/main/java/ src/main/java/fr/ src/main/java/fr/imag/ src/main/java/fr/imag/adele/ src/main/java/fr/imag/adele/escoffier/ src/main/java/fr/imag/adele/escoffier/utf/ src/main...
Date Tue, 25 Sep 2007 15:18:51 GMT
Author: clement
Date: Tue Sep 25 08:18:49 2007
New Revision: 579295

URL: http://svn.apache.org/viewvc?rev=579295&view=rev
Log:
Initial import of UTF

Added:
    felix/sandbox/clement/Tests/UTF/pom.xml
    felix/sandbox/clement/Tests/UTF/src/
    felix/sandbox/clement/Tests/UTF/src/main/
    felix/sandbox/clement/Tests/UTF/src/main/java/
    felix/sandbox/clement/Tests/UTF/src/main/java/fr/
    felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/
    felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/
    felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/
    felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/
    felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/framework/
    felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/framework/AssertionFailed.java
    felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/framework/TestCase.java
    felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/framework/TestResult.java
    felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/framework/TestSuite.java
    felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/runner/
    felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/runner/ConsoleRunner.java
    felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/runner/InlineConsoleRunner.java
    felix/sandbox/clement/Tests/UTF/src/main/resources/

Added: felix/sandbox/clement/Tests/UTF/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/UTF/pom.xml?rev=579295&view=auto
==============================================================================
--- felix/sandbox/clement/Tests/UTF/pom.xml (added)
+++ felix/sandbox/clement/Tests/UTF/pom.xml Tue Sep 25 08:18:49 2007
@@ -0,0 +1,33 @@
+<project>
+  <groupId>ipojo.utf</groupId>
+  <version>0.1.1</version>
+  <modelVersion>4.0.0</modelVersion>
+  <name>Unitary Test Framework (UTF)</name>
+  <description>Unitary Test Framework</description>
+  <artifactId>utf</artifactId>
+  <packaging>bundle</packaging>
+  
+  <dependencies>
+  	<dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.osgi.core</artifactId>
+      <version>1.1.0-SNAPSHOT</version>
+    </dependency>
+  </dependencies>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <version>1.1.0-SNAPSHOT</version>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Export-Package>fr.imag.adele.escoffier.utf.framework;specification-version="0.1.1",fr.imag.adele.escoffier.utf.runner;specification-version="0.1.1"</Export-Package>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/framework/AssertionFailed.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/framework/AssertionFailed.java?rev=579295&view=auto
==============================================================================
--- felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/framework/AssertionFailed.java
(added)
+++ felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/framework/AssertionFailed.java
Tue Sep 25 08:18:49 2007
@@ -0,0 +1,10 @@
+package fr.imag.adele.escoffier.utf.framework;
+
+public class AssertionFailed extends RuntimeException {
+	
+	private static final long serialVersionUID = 3465374173996493787L;
+
+	public AssertionFailed(String message) { super(message); }
+	
+	public AssertionFailed() { super(); }
+}

Added: felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/framework/TestCase.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/framework/TestCase.java?rev=579295&view=auto
==============================================================================
--- felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/framework/TestCase.java
(added)
+++ felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/framework/TestCase.java
Tue Sep 25 08:18:49 2007
@@ -0,0 +1,132 @@
+package fr.imag.adele.escoffier.utf.framework;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.osgi.framework.BundleContext;
+
+public class TestCase {
+	
+	protected BundleContext context;
+	
+	public TestCase(BundleContext bc) {
+		context = bc;
+	}
+	
+	public void setUp() { }
+	
+	public void tearDown() { }
+	
+	public void assertTrue(String name, boolean bool) throws AssertionFailed {
+		if(bool) { return; }
+		else { throw new AssertionFailed(name); }
+	}
+	
+	public void assertFalse(String name, boolean bool) throws AssertionFailed {
+		if(!bool) { return; }
+		else { throw new AssertionFailed(name); }
+	}
+	
+	public void assertNotNull(String name, Object o) throws AssertionFailed {
+		if(o != null) { return; }
+		else { throw new AssertionFailed(name); }
+	}
+		
+	public void assertNull(String name, Object o) throws AssertionFailed {
+		if(o == null) { return; }
+		else { throw new AssertionFailed(name); }
+	}
+	
+	public void assertEquals(String name, Object o1, Object o2) throws AssertionFailed {
+		if(o1.equals(o2)) { return; }
+		else { throw new AssertionFailed(name); }
+	}
+	
+	public void assertEquals(String name, int o1, int o2) throws AssertionFailed {
+		if(o1 == o2) { return; }
+		else { throw new AssertionFailed(name); }
+	}
+	
+	public void assertEquals(String name, long o1, long o2) throws AssertionFailed {
+		if(o1 == o2) { return; }
+		else { throw new AssertionFailed(name); }
+	}
+	
+	public void assertEquals(String name, double o1, double o2) throws AssertionFailed {
+		if(o1 == o2) { return; }
+		else { throw new AssertionFailed(name); }
+	}
+	
+	public void assertNotEquals(String name, int o1, int o2) throws AssertionFailed {
+		if(o1 != o2) { return; }
+		else { throw new AssertionFailed(name); }
+	}
+	
+	public void assertNotEquals(String name, long o1, long o2) throws AssertionFailed {
+		if(o1 != o2) { return; }
+		else { throw new AssertionFailed(name); }
+	}
+	
+	public void assertNotEquals(String name, Object o1, Object o2) throws AssertionFailed {
+        if(!o1.equals(o2)) { return; }
+		else { throw new AssertionFailed(name); }
+	}
+	
+	public void assertNotSame(String name, Object o1, Object o2) throws AssertionFailed {
+		if(o1 != o2) { return; }
+		else { throw new AssertionFailed(name); }
+	}
+	
+	public void assertSame(String name, Object o1, Object o2) throws AssertionFailed {
+		if(o1 == o2) { return; }
+		else { throw new AssertionFailed(name); }
+	}
+	
+	public void fail() throws AssertionFailed {
+		throw new AssertionFailed();
+	}
+	
+	public void fail(String name) throws AssertionFailed {
+		throw new AssertionFailed(name);
+	}
+	
+	public List execute() {
+		List result = new ArrayList();
+		// Get the list of test of the test case
+		String clazz = this.getClass().getName();
+		Method[] all_methods = this.getClass().getMethods();
+		for(int i = 0; i < all_methods.length; i++) {
+			if(all_methods[i].getName().startsWith("test")) {
+				// We need to execute the test
+				long begin = 0;
+				this.setUp();
+				try {
+					begin = System.currentTimeMillis();
+					all_methods[i].invoke(this, new Object[0]);
+					long duration = System.currentTimeMillis() - begin;
+					result.add(new TestResult(clazz+":"+all_methods[i].getName(),"success", duration, TestResult.SUCCESS,
null));
+				} catch (IllegalArgumentException e) {
+					long duration = System.currentTimeMillis() - begin;
+					result.add(new TestResult(clazz+":"+all_methods[i].getName(),"test method cannot be
called -> " + e.getMessage(), duration, TestResult.FAILED, null));
+				} catch (IllegalAccessException e) {
+					long duration = System.currentTimeMillis() - begin;
+					result.add(new TestResult(clazz+":"+all_methods[i].getName(),"test method cannot be
called -> " + e.getMessage(), duration, TestResult.FAILED, null));
+				} catch (InvocationTargetException e) {
+					long duration = System.currentTimeMillis() - begin;
+					if((e.getCause() instanceof AssertionFailed)) {
+						result.add(new TestResult(clazz+":"+all_methods[i].getName(),"Assertion Failed ->
" + e.getCause().getMessage(), duration, TestResult.FAILED, null));
+					} else {
+						result.add(new TestResult(clazz+":"+all_methods[i].getName(),"The test method thrown
an exception -> " + e.getCause().getMessage(), duration, TestResult.FAILED, e.getCause()));
+					}
+				}
+				this.tearDown();
+			}
+		}
+		return result;
+	}
+			
+			
+
+}

Added: felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/framework/TestResult.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/framework/TestResult.java?rev=579295&view=auto
==============================================================================
--- felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/framework/TestResult.java
(added)
+++ felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/framework/TestResult.java
Tue Sep 25 08:18:49 2007
@@ -0,0 +1,37 @@
+package fr.imag.adele.escoffier.utf.framework;
+
+public class TestResult {
+	
+	public static final String FAILED = "failed";
+	public static final String SUCCESS = "success";
+	
+	private String name;
+	private String message;
+	private String status;
+	private long duration;
+	private Throwable exception;
+	
+	public TestResult(String name, String message, long duration, String status, Throwable e)
{
+		this.name = name;
+		this.message = message;
+		this.duration = duration;
+		this.status = status;
+		this.exception = e;
+	}
+	
+	public Throwable getException() {
+	    return exception;
+	}
+	
+	public String toString() {
+		if(status.equals(SUCCESS)) {
+			return name + " -> " + status + " [" + duration + " ms]";
+		}
+		else {
+			return name + " -> " + status + " : " + message +  " [" + duration + " ms]";
+		}
+	}
+	
+	public boolean isSuccess() { return status.equals(SUCCESS); }
+
+}

Added: felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/framework/TestSuite.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/framework/TestSuite.java?rev=579295&view=auto
==============================================================================
--- felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/framework/TestSuite.java
(added)
+++ felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/framework/TestSuite.java
Tue Sep 25 08:18:49 2007
@@ -0,0 +1,65 @@
+package fr.imag.adele.escoffier.utf.framework;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.osgi.framework.BundleContext;
+
+public abstract class TestSuite extends TestCase {
+	
+	protected BundleContext context;
+	
+	public TestSuite(BundleContext bc) {
+		super(bc);
+		context = bc;
+	}
+	
+	public abstract List suite();
+	
+	public List execute() {
+		List result = new ArrayList();
+		// Get the list of test of the test case
+		String clazz = this.getClass().getName();
+		Method[] all_methods = this.getClass().getMethods();
+		for(int i = 0; i < all_methods.length; i++) {
+			if(all_methods[i].getName().startsWith("test")) {
+				// We need to execute the test
+				long begin = 0;
+				this.setUp();
+				try {
+					begin = System.currentTimeMillis();
+					all_methods[i].invoke(this, new Object[0]);
+					long duration = System.currentTimeMillis() - begin;
+					result.add(new TestResult(clazz+":"+all_methods[i].getName(),"success", duration, TestResult.SUCCESS,
null));
+				} catch (IllegalArgumentException e) {
+					long duration = System.currentTimeMillis() - begin;
+					result.add(new TestResult(clazz+":"+all_methods[i].getName(),"test method cannot be
called -> " + e.getMessage(), duration, TestResult.FAILED, null));
+				} catch (IllegalAccessException e) {
+					long duration = System.currentTimeMillis() - begin;
+					result.add(new TestResult(clazz+":"+all_methods[i].getName(),"test method cannot be
called -> " + e.getMessage(), duration, TestResult.FAILED, null));
+				} catch (InvocationTargetException e) {
+					long duration = System.currentTimeMillis() - begin;
+					if((e.getCause() instanceof AssertionFailed)) {
+						result.add(new TestResult(clazz+":"+all_methods[i].getName(),"Assertion Failed ->
" + e.getCause().getMessage(), duration, TestResult.FAILED, e.getCause()));
+					} else {
+						result.add(new TestResult(clazz+":"+all_methods[i].getName(),"The test method thrown
an exception -> " + e.getCause().getMessage(), duration, TestResult.FAILED, null));
+						e.printStackTrace();
+					}
+				}
+				this.tearDown();
+			}
+		}
+		
+		// Then get the list of TestCase of the test suite
+		List testcases = this.suite();
+		for(int i = 0; i < testcases.size(); i++) {
+			TestCase tc = (TestCase) testcases.get(i);
+			result.addAll(tc.execute());
+		}
+		
+		return result;
+	}
+
+}

Added: felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/runner/ConsoleRunner.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/runner/ConsoleRunner.java?rev=579295&view=auto
==============================================================================
--- felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/runner/ConsoleRunner.java
(added)
+++ felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/runner/ConsoleRunner.java
Tue Sep 25 08:18:49 2007
@@ -0,0 +1,44 @@
+package fr.imag.adele.escoffier.utf.runner;
+
+import java.util.List;
+
+import fr.imag.adele.escoffier.utf.framework.TestCase;
+import fr.imag.adele.escoffier.utf.framework.TestResult;
+
+public class ConsoleRunner {
+	
+	public static void run(List tests, boolean stopOnFailed) {
+		System.out.println("Tests ...");
+        long t1 = System.currentTimeMillis();
+		int cases = 0;
+		int ut = 0;
+		int failed = 0;
+		int sucess = 0;
+		for(int i = 0; i < tests.size(); i++) {
+			cases++;
+			TestCase tc = (TestCase) tests.get(i);
+			List result = tc.execute();
+			for(int j = 0; j < result.size(); j++) {
+				ut++;
+				TestResult tr = (TestResult) result.get(j);
+				if(tr.isSuccess()) { 
+					sucess++;
+					System.out.println(tr);
+				} else { 
+					failed++;
+					System.err.println(tr);
+					if(stopOnFailed) { 
+					    if(tr.getException() != null) {
+	                        tr.getException().printStackTrace();
+	                    }
+					    return;
+					}
+				}
+				
+			}
+		}
+        long t2 = System.currentTimeMillis();
+		System.out.println("\n Summary : " + cases + " test cases, " + ut + " unitary tests, "
+ sucess + " success, " + failed + " failures " + "[" + (t2-t1) + " ms]");
+	}
+
+}

Added: felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/runner/InlineConsoleRunner.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/runner/InlineConsoleRunner.java?rev=579295&view=auto
==============================================================================
--- felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/runner/InlineConsoleRunner.java
(added)
+++ felix/sandbox/clement/Tests/UTF/src/main/java/fr/imag/adele/escoffier/utf/runner/InlineConsoleRunner.java
Tue Sep 25 08:18:49 2007
@@ -0,0 +1,61 @@
+package fr.imag.adele.escoffier.utf.runner;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import fr.imag.adele.escoffier.utf.framework.TestCase;
+import fr.imag.adele.escoffier.utf.framework.TestResult;
+import fr.imag.adele.escoffier.utf.framework.TestSuite;
+
+public class InlineConsoleRunner {
+	
+	public static void run(List tests, boolean stopOnFailed) {
+	    List inlined = new ArrayList();
+	    InlineTests(tests, inlined);
+		System.out.println("Executing " + inlined.size() + " tests ...");
+        long t1 = System.currentTimeMillis();
+		int cases = 0;
+		int ut = 0;
+		int failed = 0;
+		int sucess = 0;
+		for(int i = 0; i < inlined.size(); i++) {
+			cases++;
+			TestCase tc = (TestCase) inlined.get(i);
+			List result = tc.execute();
+			for(int j = 0; j < result.size(); j++) {
+				ut++;
+				TestResult tr = (TestResult) result.get(j);
+				if(tr.isSuccess()) { 
+					sucess++;
+					System.out.println(tr);
+				} else { 
+					failed++;
+					System.err.println(tr);
+					if(stopOnFailed) { 
+					    if(tr.getException() != null) {
+	                        tr.getException().printStackTrace();
+	                    }
+					    return;
+					}
+				}
+				
+			}
+		}
+        long t2 = System.currentTimeMillis();
+		System.out.println("\n Summary : " + cases + " test cases, " + ut + " unitary tests, "
+ sucess + " success, " + failed + " failures " + "[" + (t2-t1) + " ms]");
+	}
+
+    private static void InlineTests(List tests, List inlined) {
+        for(int i = 0; i <tests.size(); i++) {
+            if(tests.get(i) instanceof TestSuite) {
+                List inlined2 = new ArrayList();
+                TestSuite ts = (TestSuite) tests.get(i);
+                InlineTests(ts.suite(), inlined2);
+                inlined.addAll(inlined2);
+            } else {
+                inlined.add(tests.get(i));
+            }
+        }
+    }
+
+}



Mime
View raw message