Revision: 2149 http://vexi.svn.sourceforge.net/vexi/?rev=2149&view=rev Author: mkpg2 Date: 2007-09-08 18:12:44 -0700 (Sat, 08 Sep 2007)
Log Message: ----------- Reorganising tests, adding org.ibex.util test(s) to the hierarchy. Modified Paths: -------------- trunk/core/org.ibex.util/.classpath Added Paths: ----------- trunk/core/org.ibex.util/src_junit/org/ibex/util/TestUtil.java trunk/core/org.ibex.util/src_junit/test/ trunk/core/org.ibex.util/src_junit/test/Util.java Modified: trunk/core/org.ibex.util/.classpath =================================================================== --- trunk/core/org.ibex.util/.classpath 2007-09-09 00:56:24 UTC (rev 2148) +++ trunk/core/org.ibex.util/.classpath 2007-09-09 01:12:44 UTC (rev 2149) @@ -1,7 +1,9 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="src" path="src_dev"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> - <classpathentry kind="output" path="bin"/> -</classpath> +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="src" path="src_dev"/> + <classpathentry kind="src" path="src_junit"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3.8.1"/> + <classpathentry kind="output" path="bin"/> +</classpath> Added: trunk/core/org.ibex.util/src_junit/org/ibex/util/TestUtil.java =================================================================== --- trunk/core/org.ibex.util/src_junit/org/ibex/util/TestUtil.java (rev 0) +++ trunk/core/org.ibex.util/src_junit/org/ibex/util/TestUtil.java 2007-09-09 01:12:44 UTC (rev 2149) @@ -0,0 +1,15 @@ +package org.ibex.util; + +import test.Util; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class TestUtil extends TestCase{ + + static public Test suite() { + TestSuite suite = Util.newTestSuite(TestUtil.class); + suite.addTest(Util.suiteJava(TestXML.class)); + return suite; + } +} Property changes on: trunk/core/org.ibex.util/src_junit/org/ibex/util/TestUtil.java ___________________________________________________________________ Name: svn:mime-type + text/plain Copied: trunk/core/org.ibex.util/src_junit/test/Util.java (from rev 2069, trunk/core/org.ibex.js/src_junit/test/Util.java) =================================================================== --- trunk/core/org.ibex.util/src_junit/test/Util.java (rev 0) +++ trunk/core/org.ibex.util/src_junit/test/Util.java 2007-09-09 01:12:44 UTC (rev 2149) @@ -0,0 +1,124 @@ +package test; + +import java.io.File; +import java.io.FilenameFilter; +import java.lang.reflect.Method; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.ibex.util.Log; + +public class Util { + + static public File createTmpDir(){ + File tempDir = new File("_temp_"); + tempDir.mkdir(); + return tempDir; + } + + // Deletes all files and subdirectories under dir. + // Returns true if all deletions were successful. + // If a deletion fails, the method stops attempting to delete and returns false. + public static boolean deleteDir(File dir) { + if (dir.isDirectory()) { + String[] children = dir.list(); + for (int i=0; i<children.length; i++) { + boolean success = deleteDir(new File(dir, children[i])); + if (!success) { + return false; + } + } + } + + // The directory is now empty so delete it + return dir.delete(); + } + + static public TestSuite buildScriptSuite(Object obj){ + String packige = obj.getClass().getPackage().getName(); + TestSuite suite = (obj instanceof TestSuite)? (TestSuite)obj: Util.newTestSuite((obj.getClass())); + //String packige, TestSuite suite, File dir){ + buildTestSuite(packige, suite, new File(obj.getClass().getResource(".").getPath())); + return suite; + } + + static void buildTestSuite(String packige, TestSuite suite, File dir){ + String[] dirs = dir.list(); + for(int i=0; i<dirs.length; i++){ + File f = new File(dir, dirs[i]); + if(f.isDirectory()){ + String[] children = f.list(new FilenameFilter(){ + public boolean accept(File dir, String name) { + return !name.contains("$") && name.endsWith(".class"); + } + }); + TestSuite csuite = null; + if("traps".equals(dirs[i]) && packige.endsWith("traps")){ + System.out.println("!"); + } + String cpackige = packige+"."+dirs[i]; + for(int j=0; j<children.length; j++){ + String c = children[j]; + String cname = c.substring(0,c.lastIndexOf(".class")); + String cfullname = cpackige+"."+cname; + //System.out.println(cname); + try { + Class klass = Class.forName(cfullname); + try{ + Method m = (Method)klass.getMethod("suite", null); + csuite = (TestSuite)m.invoke(null, null); + break; + }catch(NoSuchMethodException e){continue;} + //klass.getSuperclass() + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException(); + } + } + if(csuite==null) csuite = new TestSuite(dirs[i]); + buildTestSuite(cpackige, csuite, f); + if(csuite.testCount()>1) + suite.addTest(csuite); + } + } + } + + static public void changeLogLevel(int level){ + if(Log.uLevel == level) return; + Log.uLevel = level; + Log.warn(Util.class, "Setting LOG LEVEL " + logLevelString(level)); + } + + public static String logLevelString(int level){ + switch(level){ + case Log.DEBUG: return "DEBUG"; + case Log.INFO: return "INFO"; + case Log.WARN: return "WARN"; + case Log.ERROR: return "ERRIR"; + default: return "??"; + } + } + + public static TestSuite newTestSuite(Class c){ + return new TestSuite(nameFromClass(c)); + } + + public static String nameFromClass(Class c){ + String name = c.getSimpleName(); + if(name.startsWith("Test")) + name = name.substring(4); + return name; + } + /* + static private boolean hasSuperClass(Class expected, Class testee){ + if(expected.equals(testee)) return true; + else if(expected.equals(Object.class)) return false; + else return hasSuperClass(expected, testee.getSuperclass()); + }*/ + + public static Test suiteJava(Class suiteClass){ + return new TestSuite(suiteClass, nameFromClass(suiteClass)); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn