p-unit-devel Mailing List for p-unit (Page 14)
Status: Beta
Brought to you by:
zhanghuangzhu
You can subscribe to this list here.
| 2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(182) |
Jun
(46) |
Jul
(3) |
Aug
(2) |
Sep
(1) |
Oct
(7) |
Nov
(18) |
Dec
(8) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2008 |
Jan
(9) |
Feb
(5) |
Mar
(10) |
Apr
(17) |
May
(16) |
Jun
(16) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <zha...@us...> - 2007-05-11 12:21:46
|
Revision: 20
http://p-unit.svn.sourceforge.net/p-unit/?rev=20&view=rev
Author: zhanghuangzhu
Date: 2007-05-11 05:21:47 -0700 (Fri, 11 May 2007)
Log Message:
-----------
Andrew Zhang: refactored a method name from "install" to "setWatchers"
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/testmethod/AbstractTestMethodRunner.java
Modified: trunk/punit/src/org/punit/runner/testmethod/AbstractTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/testmethod/AbstractTestMethodRunner.java 2007-05-11 12:15:34 UTC (rev 19)
+++ trunk/punit/src/org/punit/runner/testmethod/AbstractTestMethodRunner.java 2007-05-11 12:21:47 UTC (rev 20)
@@ -27,7 +27,7 @@
_watchers = new Watcher[] {new MemoryWatcher(), new TimeWatcher()};
}
- public void install(Watcher[] watchers) {
+ public void setWatchers(Watcher[] watchers) {
_watchers = watchers;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-11 12:15:32
|
Revision: 19
http://p-unit.svn.sourceforge.net/p-unit/?rev=19&view=rev
Author: zhanghuangzhu
Date: 2007-05-11 05:15:34 -0700 (Fri, 11 May 2007)
Log Message:
-----------
Andrew Zhang: no need to set method to be accessible again.
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/testmethod/AbstractTestMethodRunner.java
Modified: trunk/punit/src/org/punit/runner/testmethod/AbstractTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/testmethod/AbstractTestMethodRunner.java 2007-05-11 11:37:36 UTC (rev 18)
+++ trunk/punit/src/org/punit/runner/testmethod/AbstractTestMethodRunner.java 2007-05-11 12:15:34 UTC (rev 19)
@@ -53,7 +53,6 @@
_class = testInstance.getClass();
_params = params;
_method = method;
- _method.setAccessible(true);
_setUpMethod = ReflectionUtil.getMethodAndSetAccessible(_testInstance
.getClass(), "setUp", new Class[] {});
_tearDownMethod = ReflectionUtil.getMethodAndSetAccessible(
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-11 11:37:37
|
Revision: 18
http://p-unit.svn.sourceforge.net/p-unit/?rev=18&view=rev
Author: zhanghuangzhu
Date: 2007-05-11 04:37:36 -0700 (Fri, 11 May 2007)
Log Message:
-----------
Andrew Zhang: Refined test cases.
Modified Paths:
--------------
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java
trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java
trunk/punit.test/src/tests/sample/testcase/PUnitTestCaseSample.java
trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java
trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java
Added Paths:
-----------
trunk/punit.test/src/tests/api/org/punit/testclasses/ParameterizableTestSample.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestParameter.java
trunk/punit.test/src/tests/sample/testcase/ConcurrentParameterizableTestSample.java
trunk/punit.test/src/tests/sample/testcase/SampleTest.java
Modified: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-11 10:31:31 UTC (rev 17)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-11 11:37:36 UTC (rev 18)
@@ -6,6 +6,7 @@
import tests.api.org.punit.runner.*;
import tests.api.org.punit.util.*;
import tests.api.org.punit.watcher.*;
+import tests.sample.testcase.*;
public class AllTests {
public static Test suite() {
@@ -20,6 +21,7 @@
suite.addTestSuite(PUnitSoloRunnerTest.class);
suite.addTestSuite(PUnitTestMethodBuilderTest.class);
suite.addTestSuite(PUnitTestSuiteBuilderTest.class);
+ suite.addTestSuite(SampleTest.class);
suite.addTestSuite(ReflectionUtilTest.class);
suite.addTestSuite(TimeWatcherTest.class);
//$JUnit-END$
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/ParameterizableTestSample.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/ParameterizableTestSample.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/ParameterizableTestSample.java 2007-05-11 11:37:36 UTC (rev 18)
@@ -0,0 +1,25 @@
+package tests.api.org.punit.testclasses;
+
+import org.punit.runner.*;
+import org.punit.type.*;
+
+public class ParameterizableTestSample implements Parameterizable {
+
+ public static void main(String[] args) {
+ new PUnitSoloRunner().run(ParameterizableTestSample.class);
+ new PUnitSoloParameterizableRunner().run(ParameterizableTestSample.class);
+ }
+
+ public void test1(Parameter param) {
+ System.out.println("test1 " + param);
+ }
+
+ public void test2() {
+ System.out.println("test2");
+ }
+
+ public Parameter[] parameters() {
+ return new Parameter[] { new TestParameter(1), new TestParameter(2), };
+ }
+
+}
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/TestParameter.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestParameter.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestParameter.java 2007-05-11 11:37:36 UTC (rev 18)
@@ -0,0 +1,15 @@
+package tests.api.org.punit.testclasses;
+
+import org.punit.type.*;
+
+public class TestParameter implements Parameter {
+ public int value;
+
+ public TestParameter(int i) {
+ value = i;
+ }
+
+ public String toString() {
+ return "param: " + value;
+ }
+}
\ No newline at end of file
Added: trunk/punit.test/src/tests/sample/testcase/ConcurrentParameterizableTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/ConcurrentParameterizableTestSample.java (rev 0)
+++ trunk/punit.test/src/tests/sample/testcase/ConcurrentParameterizableTestSample.java 2007-05-11 11:37:36 UTC (rev 18)
@@ -0,0 +1,33 @@
+package tests.sample.testcase;
+
+import org.punit.runner.*;
+import org.punit.type.*;
+
+import tests.api.org.punit.testclasses.*;
+
+public class ConcurrentParameterizableTestSample implements Parameterizable, Concurrent {
+
+ public static void main(String[] args) {
+ new PUnitSoloRunner().run(ConcurrentParameterizableTestSample.class);
+ new PUnitSoloParameterizableRunner().run(ConcurrentParameterizableTestSample.class);
+ new PUnitConcurrentRunner().run(ConcurrentParameterizableTestSample.class);
+ new PUnitConcurrentParameterizableRunner().run(ConcurrentParameterizableTestSample.class);
+ }
+
+ public void test1(Parameter param) {
+ System.out.println("test1 " + param);
+ }
+
+ public void test2() {
+ System.out.println("test2");
+ }
+
+ public Parameter[] parameters() {
+ return new Parameter[] { new TestParameter(1), new TestParameter(2), };
+ }
+
+ public int concurrentCount() {
+ return 5;
+ }
+
+}
Modified: trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java 2007-05-11 10:31:31 UTC (rev 17)
+++ trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java 2007-05-11 11:37:36 UTC (rev 18)
@@ -10,15 +10,15 @@
}
public void test1() {
-
+ System.out.println("test1");
}
public void test2() {
-
+ System.out.println("test2");
}
public int concurrentCount() {
return 10;
}
-
+
}
Modified: trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java 2007-05-11 10:31:31 UTC (rev 17)
+++ trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java 2007-05-11 11:37:36 UTC (rev 18)
@@ -19,11 +19,11 @@
}
public void test1() {
-
+ System.out.println("test1");
}
public void test2() {
-
+ System.out.println("test2");
}
}
Modified: trunk/punit.test/src/tests/sample/testcase/PUnitTestCaseSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/PUnitTestCaseSample.java 2007-05-11 10:31:31 UTC (rev 17)
+++ trunk/punit.test/src/tests/sample/testcase/PUnitTestCaseSample.java 2007-05-11 11:37:36 UTC (rev 18)
@@ -10,31 +10,35 @@
}
public void setUpAfterWatchers() {
+ System.out.println("setUpAfterWatchers");
}
public void setUpBeforeWatchers() {
+ System.out.println("setUpBeforeWatchers");
}
public void tearDownBeforeWatchers() {
+ System.out.println("tearDownBeforeWatchers");
}
public void tearDownAfterWatchers() {
+ System.out.println("tearDownAfterWatchers");
}
public void setUp() {
-
+ System.out.println("setUp");
}
public void tearDown() {
-
+ System.out.println("tearDown");
}
public void test1() {
-
+ System.out.println("test1");
}
public void test2() {
-
+ System.out.println("test2");
}
}
Modified: trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java 2007-05-11 10:31:31 UTC (rev 17)
+++ trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java 2007-05-11 11:37:36 UTC (rev 18)
@@ -1,20 +1,27 @@
package tests.sample.testcase;
+import junit.framework.*;
+
import org.punit.runner.*;
-import org.punit.type.*;
+import org.punit.type.TestSuite;
-public class PUnitTestSuiteSample implements TestSuite {
+public class PUnitTestSuiteSample extends TestCase implements TestSuite {
+
public static void main(String[] args) {
new PUnitSoloRunner().run(PUnitTestSuiteSample.class);
new PUnitConcurrentRunner().run(PUnitTestSuiteSample.class);
+ new PUnitSoloParameterizableRunner().run(PUnitTestSuiteSample.class);
+ new PUnitConcurrentParameterizableRunner().run(PUnitTestSuiteSample.class);
}
-
+
public Class[] suite() {
return new Class[] {
- ConcurrentTestSample.class,
+ ConcurrentParameterizableTestSample.class,
+ ConcurrentTestSample.class,
JUnitTestSample.class,
+ ParameterizableTestSample.class,
+ PUnitTestCaseSample.class,
SimpleTestSample.class,
- PUnitTestCaseSample.class,
};
}
}
Modified: trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java 2007-05-11 10:31:31 UTC (rev 17)
+++ trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java 2007-05-11 11:37:36 UTC (rev 18)
@@ -3,6 +3,8 @@
import org.punit.runner.*;
import org.punit.type.*;
+import tests.api.org.punit.testclasses.*;
+
public class ParameterizableTestSample implements Parameterizable {
public static void main(String[] args) {
@@ -11,7 +13,7 @@
}
public void test1(Parameter param) {
- System.out.println("test1");
+ System.out.println("test1 " + param);
}
public void test2() {
@@ -19,15 +21,7 @@
}
public Parameter[] parameters() {
- return new Parameter[] { new Parameter1(1), new Parameter1(2), };
+ return new Parameter[] { new TestParameter(1), new TestParameter(2), };
}
- static class Parameter1 implements Parameter {
- int value;
-
- Parameter1(int i) {
- value = i;
- }
- }
-
}
Added: trunk/punit.test/src/tests/sample/testcase/SampleTest.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/SampleTest.java (rev 0)
+++ trunk/punit.test/src/tests/sample/testcase/SampleTest.java 2007-05-11 11:37:36 UTC (rev 18)
@@ -0,0 +1,23 @@
+package tests.sample.testcase;
+
+import org.punit.runner.*;
+
+import junit.framework.*;
+
+public class SampleTest extends TestCase {
+ public void testSoloRunner() {
+ new PUnitSoloRunner().run(PUnitTestSuiteSample.class);
+ }
+
+ public void testConcurrentRunner() {
+ new PUnitConcurrentRunner().run(PUnitTestSuiteSample.class);
+ }
+
+ public void testSoloParameterizableRunner() {
+ new PUnitSoloParameterizableRunner().run(PUnitTestSuiteSample.class);
+ }
+
+ public void testConcurrentParameterizableRunner() {
+ new PUnitConcurrentParameterizableRunner().run(PUnitTestSuiteSample.class);
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-11 10:31:31
|
Revision: 17
http://p-unit.svn.sourceforge.net/p-unit/?rev=17&view=rev
Author: zhanghuangzhu
Date: 2007-05-11 03:31:31 -0700 (Fri, 11 May 2007)
Log Message:
-----------
Andrew Zhang: Implemented PUnitConcurrentParameterizableRunner.
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java
trunk/punit/src/org/punit/runner/testmethod/ConcurrentTestMethodRunner.java
trunk/punit/src/org/punit/runner/testmethod/SoloTestMethodRunner.java
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloParameterizableRunnerTest.java
Added Paths:
-----------
trunk/punit/src/org/punit/runner/PUnitConcurrentParameterizableRunner.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitConcurrentParameterizableRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/ConcurrentParameterizableTestClass.java
Removed Paths:
-------------
trunk/punit/src/org/punit/runner/AbstractParameterizableRunner.java
trunk/punit/src/org/punit/runner/testmethod/SoloParameterizableTestMethodRunner.java
Deleted: trunk/punit/src/org/punit/runner/AbstractParameterizableRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractParameterizableRunner.java 2007-05-11 09:18:13 UTC (rev 16)
+++ trunk/punit/src/org/punit/runner/AbstractParameterizableRunner.java 2007-05-11 10:31:31 UTC (rev 17)
@@ -1,19 +0,0 @@
-package org.punit.runner;
-
-import org.punit.builder.*;
-import org.punit.runner.testmethod.*;
-import org.punit.type.*;
-
-public abstract class AbstractParameterizableRunner extends PUnitAbstractRunner implements ParameterizableRunner {
-
- public AbstractParameterizableRunner(TestSuiteBuilder testSuiteBuiler,
- TestMethodBuilder testMethodBuilder,
- TestMethodRunner testMethodRunner) {
- super(testSuiteBuiler, testMethodBuilder, testMethodRunner);
- }
-
- public boolean accept(Class clazz) {
- return Parameterizable.class.isAssignableFrom(clazz);
- }
-
-}
\ No newline at end of file
Modified: trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-11 09:18:13 UTC (rev 16)
+++ trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-11 10:31:31 UTC (rev 17)
@@ -76,6 +76,6 @@
return _testMethodBuilder.buildTestMethods(testClass);
}
- public abstract boolean accept(Class testCaseClass);
+ public abstract boolean accept(Class testClass);
}
Added: trunk/punit/src/org/punit/runner/PUnitConcurrentParameterizableRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitConcurrentParameterizableRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/PUnitConcurrentParameterizableRunner.java 2007-05-11 10:31:31 UTC (rev 17)
@@ -0,0 +1,21 @@
+package org.punit.runner;
+
+import org.punit.builder.*;
+import org.punit.runner.testmethod.*;
+import org.punit.type.*;
+
+public class PUnitConcurrentParameterizableRunner extends PUnitAbstractRunner
+ implements ParameterizableRunner {
+
+ public PUnitConcurrentParameterizableRunner() {
+ super(new PUnitTestSuiteBuilder(),
+ new PUnitParameterizableTestMethodBuilder(),
+ new ConcurrentTestMethodRunner());
+ }
+
+ public boolean accept(Class testClass) {
+ return Parameterizable.class.isAssignableFrom(testClass)
+ && Concurrent.class.isAssignableFrom(testClass);
+ }
+
+}
Modified: trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java 2007-05-11 09:18:13 UTC (rev 16)
+++ trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java 2007-05-11 10:31:31 UTC (rev 17)
@@ -4,11 +4,15 @@
import org.punit.runner.testmethod.*;
import org.punit.type.*;
-public class PUnitSoloParameterizableRunner extends AbstractParameterizableRunner {
+public class PUnitSoloParameterizableRunner extends PUnitAbstractRunner implements ParameterizableRunner {
public PUnitSoloParameterizableRunner() {
- super(new PUnitTestSuiteBuilder(), new PUnitParameterizableTestMethodBuilder(), new SoloParameterizableTestMethodRunner());
+ super(new PUnitTestSuiteBuilder(), new PUnitParameterizableTestMethodBuilder(), new SoloTestMethodRunner());
}
+ public boolean accept(Class testClass) {
+ return Parameterizable.class.isAssignableFrom(testClass);
+ }
+
}
Modified: trunk/punit/src/org/punit/runner/testmethod/ConcurrentTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/testmethod/ConcurrentTestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
+++ trunk/punit/src/org/punit/runner/testmethod/ConcurrentTestMethodRunner.java 2007-05-11 10:31:31 UTC (rev 17)
@@ -5,22 +5,23 @@
import org.punit.util.*;
public class ConcurrentTestMethodRunner extends AbstractTestMethodRunner {
+
TestMethodThread[] _threads;
ConcurrentException _concurrentException = new ConcurrentException();
- public ConcurrentTestMethodRunner() {
-
- }
-
protected void runImpl() throws Throwable {
startThreads();
joinThreads();
- if(_concurrentException.size() > 0) {
+ if (_concurrentException.size() > 0) {
throw _concurrentException;
}
}
+ protected void runMethod() throws Throwable {
+ ReflectionUtil.invokeMethod(_method, _testInstance, _params);
+ }
+
private void startThreads() {
for (int i = 0; i < _threads.length; ++i) {
_threads[i].start();
@@ -43,15 +44,20 @@
int threadCount = concurrentTestInstance.concurrentCount();
_threads = new TestMethodThread[threadCount];
for (int i = 0; i < _threads.length; ++i) {
- _threads[i] = new TestMethodThread();
+ _threads[i] = new TestMethodThread(this);
}
}
private class TestMethodThread extends Thread {
- // TODO: exception hanlding
+ ConcurrentTestMethodRunner _runner;
+
+ public TestMethodThread(ConcurrentTestMethodRunner runner) {
+ _runner = runner;
+ }
+
public void run() {
try {
- ReflectionUtil.invokeMethod(_method, _testInstance, _params);
+ _runner.runMethod();
} catch (ReflectionException e) {
_concurrentException.add(e.getCause());
} catch (Throwable t) {
Deleted: trunk/punit/src/org/punit/runner/testmethod/SoloParameterizableTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/testmethod/SoloParameterizableTestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
+++ trunk/punit/src/org/punit/runner/testmethod/SoloParameterizableTestMethodRunner.java 2007-05-11 10:31:31 UTC (rev 17)
@@ -1,17 +0,0 @@
-package org.punit.runner.testmethod;
-
-import org.punit.exception.*;
-import org.punit.type.*;
-import org.punit.util.*;
-
-public class SoloParameterizableTestMethodRunner extends AbstractTestMethodRunner {
-
- protected void runImpl() throws Throwable {
- try {
- ReflectionUtil.invokeMethod(_method, _testInstance, _params);
- } catch (ReflectionException e) {
- throw e.getCause();
- }
- }
-
-}
Modified: trunk/punit/src/org/punit/runner/testmethod/SoloTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/testmethod/SoloTestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
+++ trunk/punit/src/org/punit/runner/testmethod/SoloTestMethodRunner.java 2007-05-11 10:31:31 UTC (rev 17)
@@ -7,8 +7,7 @@
protected void runImpl() throws Throwable {
try {
- ReflectionUtil
- .invokeMethod(_method, _testInstance, new Object[] {});
+ ReflectionUtil.invokeMethod(_method, _testInstance, _params);
} catch (ReflectionException e) {
throw e.getCause();
}
Modified: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-11 09:18:13 UTC (rev 16)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-11 10:31:31 UTC (rev 17)
@@ -13,6 +13,7 @@
//$JUnit-BEGIN$
suite.addTestSuite(ConcurrentExceptionTest.class);
suite.addTestSuite(MemoryWatcherTest.class);
+ suite.addTestSuite(PUnitConcurrentParameterizableRunnerTest.class);
suite.addTestSuite(PUnitConcurrentRunnerTest.class);
suite.addTestSuite(PUnitParameterizableTestMethodBuilderTest.class);
suite.addTestSuite(PUnitSoloParameterizableRunnerTest.class);
Added: trunk/punit.test/src/tests/api/org/punit/runner/PUnitConcurrentParameterizableRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/PUnitConcurrentParameterizableRunnerTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/runner/PUnitConcurrentParameterizableRunnerTest.java 2007-05-11 10:31:31 UTC (rev 17)
@@ -0,0 +1,31 @@
+package tests.api.org.punit.runner;
+
+import junit.framework.*;
+
+import org.punit.runner.*;
+
+import tests.api.org.punit.testclasses.*;
+
+public class PUnitConcurrentParameterizableRunnerTest extends TestCase {
+ private PUnitConcurrentParameterizableRunner _runner;
+
+ protected void setUp() throws Exception {
+ _runner = new PUnitConcurrentParameterizableRunner();
+ ConcurrentParameterizableTestClass.reset();
+ }
+
+ public void testRunTest() {
+ _runner.run(ConcurrentParameterizableTestClass.class);
+ assertTestClassRun();
+ }
+
+ private void assertTestClassRun() {
+ assertEquals(ConcurrentParameterizableTestClass.SUM
+ * ConcurrentParameterizableTestClass.COCURRENT_COUNT,
+ ConcurrentParameterizableTestClass._test1);
+ assertFalse(ConcurrentParameterizableTestClass._test2);
+ assertTrue(ConcurrentParameterizableTestClass._setUp);
+ assertTrue(ConcurrentParameterizableTestClass._tearDown);
+ }
+
+}
Modified: trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloParameterizableRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloParameterizableRunnerTest.java 2007-05-11 09:18:13 UTC (rev 16)
+++ trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloParameterizableRunnerTest.java 2007-05-11 10:31:31 UTC (rev 17)
@@ -7,7 +7,7 @@
import tests.api.org.punit.testclasses.*;
public class PUnitSoloParameterizableRunnerTest extends TestCase {
- private AbstractParameterizableRunner _runner;
+ private PUnitSoloParameterizableRunner _runner;
protected void setUp() throws Exception {
_runner = new PUnitSoloParameterizableRunner();
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/ConcurrentParameterizableTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/ConcurrentParameterizableTestClass.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/ConcurrentParameterizableTestClass.java 2007-05-11 10:31:31 UTC (rev 17)
@@ -0,0 +1,70 @@
+package tests.api.org.punit.testclasses;
+
+import org.punit.type.*;
+
+public class ConcurrentParameterizableTestClass implements Parameterizable, Concurrent {
+
+ private static final int VALUE1 = 10;
+
+ private static final int VALUE2 = 20;
+
+ public static final int SUM = 30;
+
+ public static final int COCURRENT_COUNT = 5;
+
+ public static int _test1;
+
+ public static boolean _test2;
+
+ public static boolean _setUp;
+
+ public static boolean _tearDown;
+
+ public static void reset() {
+ _test1 = 0;
+ _test2 = false;
+ _setUp = false;
+ _tearDown = false;
+ }
+
+ private void setUp() {
+ _setUp = true;
+ }
+
+ private void tearDown() {
+ _tearDown = true;
+ }
+
+
+ public synchronized void test1(Parameter1 p) {
+ _test1 += p.value;
+ }
+
+ public void test2() {
+ _test2 = true;
+ }
+
+ public void test3(Parameter p) {
+
+ }
+
+ public void test3(int i) {
+
+ }
+
+ public Parameter[] parameters() {
+ return new Parameter[] { new Parameter1(VALUE1), new Parameter1(VALUE2), };
+ }
+
+ static class Parameter1 implements Parameter {
+ int value;
+
+ Parameter1(int i) {
+ value = i;
+ }
+ }
+
+ public int concurrentCount() {
+ return COCURRENT_COUNT;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-11 09:18:12
|
Revision: 16
http://p-unit.svn.sourceforge.net/p-unit/?rev=16&view=rev
Author: zhanghuangzhu
Date: 2007-05-11 02:18:13 -0700 (Fri, 11 May 2007)
Log Message:
-----------
Andrew Zhang: Implemented PUnitSoloParameterizableRunner.
Modified Paths:
--------------
trunk/punit/src/org/punit/builder/PUnitTestMethodBuilder.java
trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
trunk/punit/src/org/punit/runner/PUnitSoloRunner.java
trunk/punit/src/org/punit/type/Parameterizable.java
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestSuiteBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitTestClass.java
trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java
Added Paths:
-----------
trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java
trunk/punit/src/org/punit/builder/PUnitParameterizableTestMethodBuilder.java
trunk/punit/src/org/punit/runner/AbstractParameterizableRunner.java
trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java
trunk/punit/src/org/punit/runner/ParameterizableRunner.java
trunk/punit/src/org/punit/runner/testmethod/
trunk/punit/src/org/punit/runner/testmethod/AbstractTestMethodRunner.java
trunk/punit/src/org/punit/runner/testmethod/ConcurrentTestMethodRunner.java
trunk/punit/src/org/punit/runner/testmethod/SoloParameterizableTestMethodRunner.java
trunk/punit/src/org/punit/runner/testmethod/SoloTestMethodRunner.java
trunk/punit/src/org/punit/runner/testmethod/TestMethodRunner.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitParameterizableTestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloParameterizableRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/
trunk/punit.test/src/tests/api/org/punit/testclasses/ParameterizableTestClass.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass1.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass2.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass3.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass4.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass5.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite1.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite2.java
trunk/punit.test/src/tests/util/TestUtil.java
Removed Paths:
-------------
trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java
trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java
trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java
trunk/punit/src/org/punit/runner/TestMethodRunner.java
Added: trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java (rev 0)
+++ trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,40 @@
+package org.punit.builder;
+
+import java.lang.reflect.*;
+import java.util.*;
+
+import org.punit.type.*;
+
+public abstract class PUnitAbstractTestMethodBuilder implements TestMethodBuilder {
+ public Object[] buildTestMethods(Class testClass) {
+ Method[] methods = testClass.getDeclaredMethods();
+ Collection testMethods;
+ if (isAlphabetical(testClass)) {
+ testMethods = new TreeSet(new AlphabeticalMethodNameComparator());
+ } else {
+ testMethods = new ArrayList();
+ }
+ for (int i = 0; i < methods.length; ++i) {
+ Method method = methods[i];
+ if (isTestMethod(method)) {
+ testMethods.add(method);
+ }
+ }
+ return testMethods.toArray();
+ }
+
+ private boolean isAlphabetical(Class testClass) {
+ return Alphabetical.class.isAssignableFrom(testClass);
+ }
+
+ protected abstract boolean isTestMethod(Method method);
+
+ private static class AlphabeticalMethodNameComparator implements Comparator {
+ public int compare(Object o1, Object o2) {
+ Method m1 = (Method) o1;
+ Method m2 = (Method) o2;
+ return m1.getName().compareTo(m2.getName());
+ }
+ }
+
+}
Added: trunk/punit/src/org/punit/builder/PUnitParameterizableTestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/PUnitParameterizableTestMethodBuilder.java (rev 0)
+++ trunk/punit/src/org/punit/builder/PUnitParameterizableTestMethodBuilder.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,30 @@
+package org.punit.builder;
+
+import java.lang.reflect.*;
+
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class PUnitParameterizableTestMethodBuilder extends PUnitAbstractTestMethodBuilder {
+
+ /**
+ *
+ * Returns true if the method is public, not static, and has
+ * one Parameter argument and starts with "test",.
+ *
+ * @param method
+ * @return true if it is a test method
+ */
+ protected boolean isTestMethod(Method method) {
+ String name = method.getName();
+ return ReflectionUtil.isPublic(method)
+ && !ReflectionUtil.isStatic(method) && hasOnlyParameterParam(method)
+ && name.startsWith("test");
+ }
+
+ private boolean hasOnlyParameterParam(Method method) {
+ Class[] params = method.getParameterTypes();
+ return params.length == 1 && Parameter.class.isAssignableFrom(params[0]);
+ }
+
+}
Modified: trunk/punit/src/org/punit/builder/PUnitTestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/PUnitTestMethodBuilder.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit/src/org/punit/builder/PUnitTestMethodBuilder.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -1,40 +1,17 @@
package org.punit.builder;
import java.lang.reflect.*;
-import java.util.*;
-import org.punit.type.*;
import org.punit.util.*;
-public class PUnitTestMethodBuilder implements TestMethodBuilder {
+public class PUnitTestMethodBuilder extends PUnitAbstractTestMethodBuilder {
- public Object[] buildTestMethods(Class testClass) {
- Method[] methods = testClass.getDeclaredMethods();
- Collection testMethods;
- if (isAlphabetical(testClass)) {
- testMethods = new TreeSet(new AlphabeticalMethodNameComparator());
- } else {
- testMethods = new ArrayList();
- }
- for (int i = 0; i < methods.length; ++i) {
- Method method = methods[i];
- if (isTestMethod(method)) {
- testMethods.add(method);
- }
- }
- return testMethods.toArray();
- }
-
- private boolean isAlphabetical(Class testClass) {
- return Alphabetical.class.isAssignableFrom(testClass);
- }
-
/**
* Returns true if this method is regarded as a test method. Might be
* overriden by the subclass for convenience.
*
- * By default, returns true if the method is public and not static, and
- * starts with "test".
+ * Returns true if the method is public, not static, and has
+ * zero argument and starts with "test",.
*
* @param method
* @return true if it is a test method
@@ -42,14 +19,11 @@
protected boolean isTestMethod(Method method) {
String name = method.getName();
return ReflectionUtil.isPublic(method)
- && !ReflectionUtil.isStatic(method) && name.startsWith("test");
+ && !ReflectionUtil.isStatic(method) && hasNoParam(method)
+ && name.startsWith("test");
}
- private static class AlphabeticalMethodNameComparator implements Comparator {
- public int compare(Object o1, Object o2) {
- Method m1 = (Method) o1;
- Method m2 = (Method) o2;
- return m1.getName().compareTo(m2.getName());
- }
+ private boolean hasNoParam(Method method) {
+ return method.getParameterTypes().length == 0;
}
}
Added: trunk/punit/src/org/punit/runner/AbstractParameterizableRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractParameterizableRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/AbstractParameterizableRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,19 @@
+package org.punit.runner;
+
+import org.punit.builder.*;
+import org.punit.runner.testmethod.*;
+import org.punit.type.*;
+
+public abstract class AbstractParameterizableRunner extends PUnitAbstractRunner implements ParameterizableRunner {
+
+ public AbstractParameterizableRunner(TestSuiteBuilder testSuiteBuiler,
+ TestMethodBuilder testMethodBuilder,
+ TestMethodRunner testMethodRunner) {
+ super(testSuiteBuiler, testMethodBuilder, testMethodRunner);
+ }
+
+ public boolean accept(Class clazz) {
+ return Parameterizable.class.isAssignableFrom(clazz);
+ }
+
+}
\ No newline at end of file
Deleted: trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -1,138 +0,0 @@
-package org.punit.runner;
-
-import java.lang.reflect.*;
-
-import org.punit.exception.*;
-import org.punit.type.*;
-import org.punit.util.*;
-import org.punit.watcher.*;
-
-public abstract class AbstractTestMethodRunner implements TestMethodRunner {
-
- protected Watcher[] _watchers;
-
- protected Object _testInstance;
-
- protected Method _method;
-
- protected Class _class;
-
- protected Method _tearDownMethod;
-
- protected Method _setUpMethod;
-
- public AbstractTestMethodRunner() {
- _watchers = new Watcher[] {new MemoryWatcher(), new TimeWatcher()};
- }
-
- public void install(Watcher[] watchers) {
- _watchers = watchers;
- }
-
- public Object[] run(Class clazz, Method method) throws Throwable {
- try {
- init(clazz, method);
- setUpBeforeWatchers();
- startWatchers();
- setUpAfterWatchers();
- runImpl();
- } finally {
- tearDownBeforeWatchers();
- stopWatchers();
- tearDownAfterWatchers();
- }
- return watchersValues();
- }
-
- protected abstract void runImpl() throws Throwable;
-
- protected final void init(Class clazz, Method method) {
- _testInstance = ReflectionUtil.newInstance(clazz);
- _class = clazz;
- _method = method;
- _method.setAccessible(true);
- _setUpMethod = ReflectionUtil.getMethodAndSetAccessible(_testInstance
- .getClass(), "setUp", new Class[] {});
- _tearDownMethod = ReflectionUtil.getMethodAndSetAccessible(
- _testInstance.getClass(), "tearDown", new Class[] {});
- }
-
- /**
- * This method might be overriden by subclass.
- * The runner may do some more things during this step.
- *
- */
- protected void setUpBeforeWatchers() {
- if (isPUnitTest()) {
- ((PUnitTest) _testInstance).setUpBeforeWatchers();
- }
- }
-
- private void setUpAfterWatchers() throws Throwable {
- if (isPUnitTest()) {
- ((PUnitTest) _testInstance).setUpAfterWatchers();
- } else {
- setUp();
- }
- }
-
- private void tearDownBeforeWatchers() throws Throwable {
- if (isPUnitTest()) {
- ((PUnitTest) _testInstance).tearDownBeforeWatchers();
- } else {
- tearDown();
- }
- }
-
- private void tearDownAfterWatchers() {
- if (isPUnitTest()) {
- ((PUnitTest) _testInstance).tearDownAfterWatchers();
- }
- }
-
- private void setUp() throws Throwable {
- if (_setUpMethod != null) {
- try {
- ReflectionUtil.invokeMethod(_setUpMethod, _testInstance,
- new Object[] {});
- } catch (ReflectionException e) {
- throw e.getCause();
- }
- }
- }
-
- private void tearDown() throws Throwable {
- if (_tearDownMethod != null) {
- try {
- ReflectionUtil.invokeMethod(_tearDownMethod, _testInstance,
- new Object[] {});
- } catch (ReflectionException e) {
- throw e.getCause();
- }
- }
- }
-
- protected final void startWatchers() {
- for (int i = 0; i < _watchers.length; ++i) {
- _watchers[i].start();
- }
- }
-
- protected final void stopWatchers() {
- for (int i = 0; i < _watchers.length; ++i) {
- _watchers[i].stop();
- }
- }
-
- protected final Object[] watchersValues() {
- Object[] values = new Object[_watchers.length];
- for (int i = 0; i < _watchers.length; ++i) {
- values[i] = _watchers[i].value();
- }
- return values;
- }
-
- private boolean isPUnitTest() {
- return PUnitTest.class.isAssignableFrom(_class);
- }
-}
Deleted: trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -1,63 +0,0 @@
-package org.punit.runner;
-
-import org.punit.exception.*;
-import org.punit.type.*;
-import org.punit.util.*;
-
-public class ConcurrentTestMethodRunner extends AbstractTestMethodRunner {
- TestMethodThread[] _threads;
-
- ConcurrentException _concurrentException = new ConcurrentException();
-
- public ConcurrentTestMethodRunner() {
-
- }
-
- protected void runImpl() throws Throwable {
- startThreads();
- joinThreads();
- if(_concurrentException.size() > 0) {
- throw _concurrentException;
- }
- }
-
- private void startThreads() {
- for (int i = 0; i < _threads.length; ++i) {
- _threads[i].start();
- }
- }
-
- private void joinThreads() {
- for (int i = 0; i < _threads.length; ++i) {
- try {
- _threads[i].join();
- } catch (InterruptedException e) {
- _concurrentException.add(e);
- }
- }
- }
-
- protected void setUpBeforeWatchers() {
- super.setUpBeforeWatchers();
- Concurrent concurrentTestInstance = (Concurrent) _testInstance;
- int threadCount = concurrentTestInstance.concurrentCount();
- _threads = new TestMethodThread[threadCount];
- for (int i = 0; i < _threads.length; ++i) {
- _threads[i] = new TestMethodThread();
- }
- }
-
- private class TestMethodThread extends Thread {
- // TODO: exception hanlding
- public void run() {
- try {
- ReflectionUtil.invokeMethod(_method, _testInstance,
- new Object[] {});
- } catch (ReflectionException e) {
- _concurrentException.add(e.getCause());
- } catch (Throwable t) {
- _concurrentException.add(t);
- }
- }
- }
-}
Modified: trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -4,6 +4,9 @@
import org.punit.builder.*;
import org.punit.result.*;
+import org.punit.runner.testmethod.*;
+import org.punit.type.*;
+import org.punit.util.*;
public abstract class PUnitAbstractRunner implements Runner {
private TestSuiteBuilder _testSuiteBuiler;
@@ -39,14 +42,36 @@
private void runTestMethod(Class clazz, Method method) {
// TODO: add run result to the test result
+ Object testInstance = ReflectionUtil.newInstance(clazz);
try {
- _testMethodRunner.run(clazz, method);
+ if (needsRunParameterizable(clazz)) {
+ Parameterizable pInstance = (Parameterizable) testInstance;
+ Parameter[] params = pInstance.parameters();
+ for (int i = 0; i < params.length; ++i) {
+ _testMethodRunner.run(testInstance, method,
+ new Object[] { params[i] });
+ }
+ } else {
+ _testMethodRunner.run(testInstance, method, new Object[] {});
+ }
} catch (Throwable e) {
e.printStackTrace();
}
}
+ private boolean needsRunParameterizable(Class clazz) {
+ return isParameterizable(clazz) && isParameterizableRunner();
+ }
+
+ private boolean isParameterizableRunner() {
+ return (this instanceof ParameterizableRunner);
+ }
+
+ private boolean isParameterizable(Class clazz) {
+ return Parameterizable.class.isAssignableFrom(clazz);
+ }
+
private Object[] buildTestMethod(Class testClass) {
return _testMethodBuilder.buildTestMethods(testClass);
}
Modified: trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -1,6 +1,7 @@
package org.punit.runner;
import org.punit.builder.*;
+import org.punit.runner.testmethod.*;
import org.punit.type.*;
public class PUnitConcurrentRunner extends PUnitAbstractRunner {
Added: trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,14 @@
+package org.punit.runner;
+
+import org.punit.builder.*;
+import org.punit.runner.testmethod.*;
+import org.punit.type.*;
+
+public class PUnitSoloParameterizableRunner extends AbstractParameterizableRunner {
+
+ public PUnitSoloParameterizableRunner() {
+ super(new PUnitTestSuiteBuilder(), new PUnitParameterizableTestMethodBuilder(), new SoloParameterizableTestMethodRunner());
+ }
+
+
+}
Modified: trunk/punit/src/org/punit/runner/PUnitSoloRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitSoloRunner.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit/src/org/punit/runner/PUnitSoloRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -1,6 +1,7 @@
package org.punit.runner;
import org.punit.builder.*;
+import org.punit.runner.testmethod.*;
public class PUnitSoloRunner extends PUnitAbstractRunner {
Added: trunk/punit/src/org/punit/runner/ParameterizableRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/ParameterizableRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/ParameterizableRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,5 @@
+package org.punit.runner;
+
+public interface ParameterizableRunner {
+
+}
Deleted: trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -1,21 +0,0 @@
-package org.punit.runner;
-
-import org.punit.exception.*;
-import org.punit.util.*;
-
-public class SoloTestMethodRunner extends AbstractTestMethodRunner {
-
- public SoloTestMethodRunner() {
-
- }
-
- protected void runImpl() throws Throwable {
- try {
- ReflectionUtil
- .invokeMethod(_method, _testInstance, new Object[] {});
- } catch (ReflectionException e) {
- throw e.getCause();
- }
- }
-
-}
Deleted: trunk/punit/src/org/punit/runner/TestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/TestMethodRunner.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit/src/org/punit/runner/TestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -1,14 +0,0 @@
-package org.punit.runner;
-
-import java.lang.reflect.*;
-
-public interface TestMethodRunner {
- /**
- * Runs the test method, and returns the watcher values.
- * @param clazz
- * @param method
- * @return
- */
- public Object[] run(Class clazz, Method method) throws Throwable;
-
-}
Copied: trunk/punit/src/org/punit/runner/testmethod/AbstractTestMethodRunner.java (from rev 15, trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java)
===================================================================
--- trunk/punit/src/org/punit/runner/testmethod/AbstractTestMethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/testmethod/AbstractTestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,141 @@
+package org.punit.runner.testmethod;
+
+import java.lang.reflect.*;
+
+import org.punit.exception.*;
+import org.punit.type.*;
+import org.punit.util.*;
+import org.punit.watcher.*;
+
+public abstract class AbstractTestMethodRunner implements TestMethodRunner {
+
+ protected Watcher[] _watchers;
+
+ protected Object _testInstance;
+
+ protected Method _method;
+
+ protected Object[] _params;
+
+ protected Class _class;
+
+ protected Method _tearDownMethod;
+
+ protected Method _setUpMethod;
+
+ public AbstractTestMethodRunner() {
+ _watchers = new Watcher[] {new MemoryWatcher(), new TimeWatcher()};
+ }
+
+ public void install(Watcher[] watchers) {
+ _watchers = watchers;
+ }
+
+ public Object[] run(Object testInstance, Method method, Object[] params) throws Throwable {
+ try {
+ init(testInstance, method, params);
+ setUpBeforeWatchers();
+ startWatchers();
+ setUpAfterWatchers();
+ runImpl();
+ } finally {
+ tearDownBeforeWatchers();
+ stopWatchers();
+ tearDownAfterWatchers();
+ }
+ return watchersValues();
+ }
+
+ protected abstract void runImpl() throws Throwable;
+
+ protected final void init(Object testInstance, Method method, Object[] params) {
+ _testInstance = testInstance;
+ _class = testInstance.getClass();
+ _params = params;
+ _method = method;
+ _method.setAccessible(true);
+ _setUpMethod = ReflectionUtil.getMethodAndSetAccessible(_testInstance
+ .getClass(), "setUp", new Class[] {});
+ _tearDownMethod = ReflectionUtil.getMethodAndSetAccessible(
+ _testInstance.getClass(), "tearDown", new Class[] {});
+ }
+
+ /**
+ * This method might be overriden by subclass.
+ * The runner may do some more things during this step.
+ *
+ */
+ protected void setUpBeforeWatchers() {
+ if (isPUnitTest()) {
+ ((PUnitTest) _testInstance).setUpBeforeWatchers();
+ }
+ }
+
+ private void setUpAfterWatchers() throws Throwable {
+ if (isPUnitTest()) {
+ ((PUnitTest) _testInstance).setUpAfterWatchers();
+ } else {
+ setUp();
+ }
+ }
+
+ private void tearDownBeforeWatchers() throws Throwable {
+ if (isPUnitTest()) {
+ ((PUnitTest) _testInstance).tearDownBeforeWatchers();
+ } else {
+ tearDown();
+ }
+ }
+
+ private void tearDownAfterWatchers() {
+ if (isPUnitTest()) {
+ ((PUnitTest) _testInstance).tearDownAfterWatchers();
+ }
+ }
+
+ private void setUp() throws Throwable {
+ if (_setUpMethod != null) {
+ try {
+ ReflectionUtil.invokeMethod(_setUpMethod, _testInstance,
+ new Object[] {});
+ } catch (ReflectionException e) {
+ throw e.getCause();
+ }
+ }
+ }
+
+ private void tearDown() throws Throwable {
+ if (_tearDownMethod != null) {
+ try {
+ ReflectionUtil.invokeMethod(_tearDownMethod, _testInstance,
+ new Object[] {});
+ } catch (ReflectionException e) {
+ throw e.getCause();
+ }
+ }
+ }
+
+ protected final void startWatchers() {
+ for (int i = 0; i < _watchers.length; ++i) {
+ _watchers[i].start();
+ }
+ }
+
+ protected final void stopWatchers() {
+ for (int i = 0; i < _watchers.length; ++i) {
+ _watchers[i].stop();
+ }
+ }
+
+ protected final Object[] watchersValues() {
+ Object[] values = new Object[_watchers.length];
+ for (int i = 0; i < _watchers.length; ++i) {
+ values[i] = _watchers[i].value();
+ }
+ return values;
+ }
+
+ private boolean isPUnitTest() {
+ return PUnitTest.class.isAssignableFrom(_class);
+ }
+}
Copied: trunk/punit/src/org/punit/runner/testmethod/ConcurrentTestMethodRunner.java (from rev 15, trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java)
===================================================================
--- trunk/punit/src/org/punit/runner/testmethod/ConcurrentTestMethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/testmethod/ConcurrentTestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,62 @@
+package org.punit.runner.testmethod;
+
+import org.punit.exception.*;
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class ConcurrentTestMethodRunner extends AbstractTestMethodRunner {
+ TestMethodThread[] _threads;
+
+ ConcurrentException _concurrentException = new ConcurrentException();
+
+ public ConcurrentTestMethodRunner() {
+
+ }
+
+ protected void runImpl() throws Throwable {
+ startThreads();
+ joinThreads();
+ if(_concurrentException.size() > 0) {
+ throw _concurrentException;
+ }
+ }
+
+ private void startThreads() {
+ for (int i = 0; i < _threads.length; ++i) {
+ _threads[i].start();
+ }
+ }
+
+ private void joinThreads() {
+ for (int i = 0; i < _threads.length; ++i) {
+ try {
+ _threads[i].join();
+ } catch (InterruptedException e) {
+ _concurrentException.add(e);
+ }
+ }
+ }
+
+ protected void setUpBeforeWatchers() {
+ super.setUpBeforeWatchers();
+ Concurrent concurrentTestInstance = (Concurrent) _testInstance;
+ int threadCount = concurrentTestInstance.concurrentCount();
+ _threads = new TestMethodThread[threadCount];
+ for (int i = 0; i < _threads.length; ++i) {
+ _threads[i] = new TestMethodThread();
+ }
+ }
+
+ private class TestMethodThread extends Thread {
+ // TODO: exception hanlding
+ public void run() {
+ try {
+ ReflectionUtil.invokeMethod(_method, _testInstance, _params);
+ } catch (ReflectionException e) {
+ _concurrentException.add(e.getCause());
+ } catch (Throwable t) {
+ _concurrentException.add(t);
+ }
+ }
+ }
+}
Added: trunk/punit/src/org/punit/runner/testmethod/SoloParameterizableTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/testmethod/SoloParameterizableTestMethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/testmethod/SoloParameterizableTestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,17 @@
+package org.punit.runner.testmethod;
+
+import org.punit.exception.*;
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class SoloParameterizableTestMethodRunner extends AbstractTestMethodRunner {
+
+ protected void runImpl() throws Throwable {
+ try {
+ ReflectionUtil.invokeMethod(_method, _testInstance, _params);
+ } catch (ReflectionException e) {
+ throw e.getCause();
+ }
+ }
+
+}
Copied: trunk/punit/src/org/punit/runner/testmethod/SoloTestMethodRunner.java (from rev 15, trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java)
===================================================================
--- trunk/punit/src/org/punit/runner/testmethod/SoloTestMethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/testmethod/SoloTestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,17 @@
+package org.punit.runner.testmethod;
+
+import org.punit.exception.*;
+import org.punit.util.*;
+
+public class SoloTestMethodRunner extends AbstractTestMethodRunner {
+
+ protected void runImpl() throws Throwable {
+ try {
+ ReflectionUtil
+ .invokeMethod(_method, _testInstance, new Object[] {});
+ } catch (ReflectionException e) {
+ throw e.getCause();
+ }
+ }
+
+}
Copied: trunk/punit/src/org/punit/runner/testmethod/TestMethodRunner.java (from rev 12, trunk/punit/src/org/punit/runner/TestMethodRunner.java)
===================================================================
--- trunk/punit/src/org/punit/runner/testmethod/TestMethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/testmethod/TestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,14 @@
+package org.punit.runner.testmethod;
+
+import java.lang.reflect.*;
+
+public interface TestMethodRunner {
+ /**
+ * Runs the test method, and returns the watcher values.
+ * @param clazz
+ * @param method
+ * @return
+ */
+ public Object[] run(Object testInstance, Method method, Object[] params) throws Throwable;
+
+}
Modified: trunk/punit/src/org/punit/type/Parameterizable.java
===================================================================
--- trunk/punit/src/org/punit/type/Parameterizable.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit/src/org/punit/type/Parameterizable.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -1,5 +1,5 @@
package org.punit.type;
public interface Parameterizable {
- Parameter [] paramters();
+ Parameter [] parameters();
}
Modified: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -14,6 +14,8 @@
suite.addTestSuite(ConcurrentExceptionTest.class);
suite.addTestSuite(MemoryWatcherTest.class);
suite.addTestSuite(PUnitConcurrentRunnerTest.class);
+ suite.addTestSuite(PUnitParameterizableTestMethodBuilderTest.class);
+ suite.addTestSuite(PUnitSoloParameterizableRunnerTest.class);
suite.addTestSuite(PUnitSoloRunnerTest.class);
suite.addTestSuite(PUnitTestMethodBuilderTest.class);
suite.addTestSuite(PUnitTestSuiteBuilderTest.class);
Added: trunk/punit.test/src/tests/api/org/punit/builder/PUnitParameterizableTestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/PUnitParameterizableTestMethodBuilderTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/builder/PUnitParameterizableTestMethodBuilderTest.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,30 @@
+package tests.api.org.punit.builder;
+
+import org.punit.builder.*;
+
+import tests.api.org.punit.testclasses.*;
+import tests.util.*;
+
+import junit.framework.*;
+
+public class PUnitParameterizableTestMethodBuilderTest extends TestCase {
+ private PUnitParameterizableTestMethodBuilder _testMethodBuidler;
+
+ protected void setUp() throws Exception {
+ _testMethodBuidler = new PUnitParameterizableTestMethodBuilder();
+ }
+
+
+ public void test1() {
+ Object[] methods = _testMethodBuidler.buildTestMethods(ParameterizableTestClass.class);
+ assertEquals(2, methods.length);
+ String[] names = TestUtil.toMethodNameArray(methods);
+ AssertUtil.assertArrayContent(names, new String[] { "test1", "test3" });
+ }
+
+ public void test2() {
+ Object[] methods = _testMethodBuidler.buildTestMethods(TestClass2.class);
+ assertEquals(0, methods.length);
+ }
+
+}
\ No newline at end of file
Modified: trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -1,12 +1,10 @@
package tests.api.org.punit.builder;
-import java.lang.reflect.*;
-
import junit.framework.*;
import org.punit.builder.*;
-import org.punit.type.*;
+import tests.api.org.punit.testclasses.*;
import tests.util.*;
public class PUnitTestMethodBuilderTest extends TestCase {
@@ -17,86 +15,23 @@
}
public void testBuildTestMethods1() {
- Object[] methods = _testMethodBuidler.buildTestMethods(Test1.class);
- String[] names = toMethodNameArray(methods);
+ Object[] methods = _testMethodBuidler.buildTestMethods(TestClass1.class);
+ String[] names = TestUtil.toMethodNameArray(methods);
AssertUtil.assertArrayContent(names, new String[] { "test1", "test2",
"testa", "testb" });
}
public void testBuildTestMethods2() {
- Object[] methods = _testMethodBuidler.buildTestMethods(Test2.class);
- String[] names = toMethodNameArray(methods);
+ Object[] methods = _testMethodBuidler.buildTestMethods(TestClass2.class);
+ String[] names = TestUtil.toMethodNameArray(methods);
AssertUtil.assertArrayContent(names, new String[] { "test1", "test2",
"testa", "testb" });
}
public void testBuildTestMethods3() {
- Object[] methods = _testMethodBuidler.buildTestMethods(Test3.class);
- String[] names = toMethodNameArray(methods);
+ Object[] methods = _testMethodBuidler.buildTestMethods(TestClass3.class);
+ String[] names = TestUtil.toMethodNameArray(methods);
AssertUtil.assertArray(names, new String[] { "test1", "test2", "testa",
"testb" });
}
-
- private String[] toMethodNameArray(Object[] methods) {
- String[] names = new String[methods.length];
- for (int i = 0; i < methods.length; ++i) {
- names[i] = ((Method) methods[i]).getName();
- }
- return names;
- }
-
- private static class Test1 {
- public void test1() {
- }
-
- public void test2() {
- }
-
- public void testa() {
- }
-
- public void testb() {
- }
-
- public void _testc() {
- }
-
- void testd() {
- }
-
- private void teste() {
- }
-
- public static void testf() {
-
- }
- }
-
- private static class Test2 {
- public void test2() {
- }
-
- public void test1() {
- }
-
- public void testb() {
- }
-
- public void testa() {
- }
- }
-
- private static class Test3 implements Alphabetical {
- public void test2() {
- }
-
- public void test1() {
- }
-
- public void testb() {
- }
-
- public void testa() {
- }
- }
}
Modified: trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestSuiteBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestSuiteBuilderTest.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestSuiteBuilderTest.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -4,6 +4,7 @@
import org.punit.builder.*;
+import tests.api.org.punit.testclasses.*;
import tests.util.*;
public class PUnitTestSuiteBuilderTest extends TestCase {
@@ -14,57 +15,20 @@
}
public void testBuildTestClasses1() {
- Object[] classes = _testSuiteBuidler.buildTestClasses(Test1.class);
- AssertUtil.assertArray(classes, new Class[] { Test1.class });
+ Object[] classes = _testSuiteBuidler.buildTestClasses(TestClass1.class);
+ AssertUtil.assertArray(classes, new Class[] { TestClass1.class });
}
public void testBuildTestClasses2() {
- Object[] classes = _testSuiteBuidler.buildTestClasses(MorkTestSuite1.class);
- AssertUtil.assertArray(classes, new Class[] { Test1.class,
- Test2.class, Test3.class });
+ Object[] classes = _testSuiteBuidler.buildTestClasses(TestSuite1.class);
+ AssertUtil.assertArray(classes, new Class[] { TestClass1.class,
+ TestClass2.class, TestClass3.class });
}
public void testBuildTestClasses3() {
- Object[] classes = _testSuiteBuidler.buildTestClasses(MorkTestSuite2.class);
- AssertUtil.assertArray(classes, new Class[] { Test4.class,
- Test1.class, Test2.class, Test3.class, Test5.class });
+ Object[] classes = _testSuiteBuidler.buildTestClasses(TestSuite2.class);
+ AssertUtil.assertArray(classes, new Class[] { TestClass4.class,
+ TestClass1.class, TestClass2.class, TestClass3.class, TestClass5.class });
}
- private static class MorkTestSuite1 implements org.punit.type.TestSuite {
- public Class[] suite() {
- return new Class[] { Test1.class, Test2.class, Test3.class,
-
- };
- }
- }
-
- private static class MorkTestSuite2 implements org.punit.type.TestSuite {
- public Class[] suite() {
- return new Class[] { Test4.class, MorkTestSuite1.class,
- Test5.class,
-
- };
- }
- }
-
- private static class Test1 {
-
- }
-
- private static class Test2 {
-
- }
-
- private static class Test3 {
-
- }
-
- private static class Test4 {
-
- }
-
- private static class Test5 {
-
- }
-
}
Added: trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloParameterizableRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloParameterizableRunnerTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloParameterizableRunnerTest.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,29 @@
+package tests.api.org.punit.runner;
+
+import junit.framework.*;
+
+import org.punit.runner.*;
+
+import tests.api.org.punit.testclasses.*;
+
+public class PUnitSoloParameterizableRunnerTest extends TestCase {
+ private AbstractParameterizableRunner _runner;
+
+ protected void setUp() throws Exception {
+ _runner = new PUnitSoloParameterizableRunner();
+ ParameterizableTestClass.reset();
+ }
+
+ public void testRunTest() {
+ _runner.run(ParameterizableTestClass.class);
+ assertTestClassRun();
+ }
+
+ private void assertTestClassRun() {
+ assertEquals(ParameterizableTestClass.SUM, ParameterizableTestClass._test1);
+ assertFalse(ParameterizableTestClass._test2);
+ assertTrue(ParameterizableTestClass._setUp);
+ assertTrue(ParameterizableTestClass._tearDown);
+ }
+
+}
Modified: trunk/punit.test/src/tests/api/org/punit/runner/PUnitTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/PUnitTestClass.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit.test/src/tests/api/org/punit/runner/PUnitTestClass.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -47,6 +47,10 @@
_test2 = true;
}
+ public void test3(int i) {
+
+ }
+
public void setUpAfterWatchers() {
_setUpAfterWatchers = true;
}
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/ParameterizableTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/ParameterizableTestClass.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/ParameterizableTestClass.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,64 @@
+package tests.api.org.punit.testclasses;
+
+import org.punit.type.*;
+
+public class ParameterizableTestClass implements Parameterizable {
+
+ private static final int VALUE1 = 10;
+
+ private static final int VALUE2 = 20;
+
+ public static final int SUM = 30;
+
+ public static int _test1;
+
+ public static boolean _test2;
+
+ public static boolean _setUp;
+
+ public static boolean _tearDown;
+
+ public static void reset() {
+ _test1 = 0;
+ _test2 = false;
+ _setUp = false;
+ _tearDown = false;
+ }
+
+ private void setUp() {
+ _setUp = true;
+ }
+
+ private void tearDown() {
+ _tearDown = true;
+ }
+
+
+ public void test1(Parameter1 p) {
+ _test1 += p.value;
+ }
+
+ public void test2() {
+ _test2 = true;
+ }
+
+ public void test3(Parameter p) {
+
+ }
+
+ public void test3(int i) {
+
+ }
+
+ public Parameter[] parameters() {
+ return new Parameter[] { new Parameter1(VALUE1), new Parameter1(VALUE2), };
+ }
+
+ static class Parameter1 implements Parameter {
+ int value;
+
+ Parameter1(int i) {
+ value = i;
+ }
+ }
+}
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass1.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass1.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass1.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,41 @@
+package tests.api.org.punit.testclasses;
+
+import org.punit.type.*;
+
+public class TestClass1 {
+ public void test1() {
+ }
+
+ public void test1i(int i) {
+ }
+
+ public void test2() {
+ }
+
+ public void testa() {
+ }
+
+ public void testb() {
+ }
+
+ public void _testc() {
+ }
+
+ void testd() {
+ }
+
+ private void teste() {
+ }
+
+ public static void testf() {
+
+ }
+
+ public void testParam(Parameter p) {
+
+ }
+
+ public void testParamI(Parameter p, int i) {
+
+ }
+}
\ No newline at end of file
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass2.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass2.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass2.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,15 @@
+package tests.api.org.punit.testclasses;
+
+public class TestClass2 {
+ public void test2() {
+ }
+
+ public void test1() {
+ }
+
+ public void testb() {
+ }
+
+ public void testa() {
+ }
+}
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass3.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass3.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass3.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,17 @@
+package tests.api.org.punit.testclasses;
+
+import org.punit.type.*;
+
+public class TestClass3 implements Alphabetical {
+ public void test2() {
+ }
+
+ public void test1() {
+ }
+
+ public void testb() {
+ }
+
+ public void testa() {
+ }
+}
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass4.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass4.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass4.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,5 @@
+package tests.api.org.punit.testclasses;
+
+public class TestClass4 {
+
+}
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass5.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass5.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass5.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,5 @@
+package tests.api.org.punit.testclasses;
+
+public class TestClass5 {
+
+}
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite1.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite1.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite1.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,8 @@
+package tests.api.org.punit.testclasses;
+public class TestSuite1 implements org.punit.type.TestSuite {
+ public Class[] suite() {
+ return new Class[] { TestClass1.class, TestClass2.class, TestClass3.class,
+
+ };
+ }
+ }
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite2.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite2.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite2.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,10 @@
+package tests.api.org.punit.testclasses;
+
+public class TestSuite2 implements org.punit.type.TestSuite {
+ public Class[] suite() {
+ return new Class[] { TestClass4.class, TestSuite1.class,
+ TestClass5.class,
+
+ };
+ }
+}
\ No newline at end of file
Modified: trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -7,26 +7,27 @@
public static void main(String[] args) {
new PUnitSoloRunner().run(ParameterizableTestSample.class);
+ new PUnitSoloParameterizableRunner().run(ParameterizableTestSample.class);
}
- public void test1() {
-
+ public void test1(Parameter param) {
+ System.out.println("test1");
}
public void test2() {
-
+ System.out.println("test2");
}
- public Class[] implmentators() {
- throw new UnsupportedOperationException();
+ public Parameter[] parameters() {
+ return new Parameter[] { new Parameter1(1), new Parameter1(2), };
}
- public Class testInterface() {
- throw new UnsupportedOperationException();
+ static class Parameter1 implements Parameter {
+ int value;
+
+ Parameter1(int i) {
+ value = i;
+ }
}
- public Parameter[] paramters() {
- throw new UnsupportedOperationException();
- }
-
}
Added: trunk/punit.test/src/tests/util/TestUtil.java
===================================================================
--- trunk/punit.test/src/tests/util/TestUtil.java (rev 0)
+++ trunk/punit.test/src/tests/util/TestUtil.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,13 @@
+package tests.util;
+
+import java.lang.reflect.*;
+
+public class TestUtil {
+ public static String[] toMethodNameArray(Object[] methods) {
+ String[] names = new String[methods.length];
+ for (int i = 0; i < methods.length; ++i) {
+ names[i] = ((Method) methods[i]).getName();
+ }
+ return names;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-10 21:50:12
|
Revision: 15
http://p-unit.svn.sourceforge.net/p-unit/?rev=15&view=rev
Author: zhanghuangzhu
Date: 2007-05-10 14:50:13 -0700 (Thu, 10 May 2007)
Log Message:
-----------
Andrew Zhang: continue to implement the runner.
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java
trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java
trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
trunk/punit/src/org/punit/runner/Runner.java
trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java
trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java
trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java
trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java
trunk/punit.test/src/tests/sample/testcase/SimpleTestSample.java
trunk/punit.test/src/tests/sample/testcase/VMTestSample.java
trunk/punit.test/src/tests/sample/testcase/VersionCompetitiveTestSample.java
Added Paths:
-----------
trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
trunk/punit/src/org/punit/runner/PUnitSoloRunner.java
trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentTestClass.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitConcurrentRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitTestClass.java
trunk/punit.test/src/tests/api/org/punit/runner/TestClass.java
trunk/punit.test/src/tests/api/org/punit/runner/TestSuiteClass.java
trunk/punit.test/src/tests/sample/testcase/PUnitTestCaseSample.java
Removed Paths:
-------------
trunk/punit/src/org/punit/runner/PUnitRunner.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java
Modified: trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -9,7 +9,7 @@
public abstract class AbstractTestMethodRunner implements TestMethodRunner {
- protected final Watcher[] _watchers;
+ protected Watcher[] _watchers;
protected Object _testInstance;
@@ -21,7 +21,11 @@
protected Method _setUpMethod;
- public AbstractTestMethodRunner(Watcher[] watchers) {
+ public AbstractTestMethodRunner() {
+ _watchers = new Watcher[] {new MemoryWatcher(), new TimeWatcher()};
+ }
+
+ public void install(Watcher[] watchers) {
_watchers = watchers;
}
@@ -53,7 +57,12 @@
_testInstance.getClass(), "tearDown", new Class[] {});
}
- private void setUpBeforeWatchers() {
+ /**
+ * This method might be overriden by subclass.
+ * The runner may do some more things during this step.
+ *
+ */
+ protected void setUpBeforeWatchers() {
if (isPUnitTest()) {
((PUnitTest) _testInstance).setUpBeforeWatchers();
}
Modified: trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -1,18 +1,16 @@
package org.punit.runner;
import org.punit.exception.*;
-import org.punit.result.*;
import org.punit.type.*;
import org.punit.util.*;
-import org.punit.watcher.*;
public class ConcurrentTestMethodRunner extends AbstractTestMethodRunner {
TestMethodThread[] _threads;
ConcurrentException _concurrentException = new ConcurrentException();
- public ConcurrentTestMethodRunner(Watcher[] watchers) {
- super(watchers);
+ public ConcurrentTestMethodRunner() {
+
}
protected void runImpl() throws Throwable {
@@ -39,10 +37,8 @@
}
}
- /**
- * @Override
- */
protected void setUpBeforeWatchers() {
+ super.setUpBeforeWatchers();
Concurrent concurrentTestInstance = (Concurrent) _testInstance;
int threadCount = concurrentTestInstance.concurrentCount();
_threads = new TestMethodThread[threadCount];
Copied: trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java (from rev 12, trunk/punit/src/org/punit/runner/PUnitRunner.java)
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -0,0 +1,56 @@
+package org.punit.runner;
+
+import java.lang.reflect.*;
+
+import org.punit.builder.*;
+import org.punit.result.*;
+
+public abstract class PUnitAbstractRunner implements Runner {
+ private TestSuiteBuilder _testSuiteBuiler;
+
+ private TestMethodBuilder _testMethodBuilder;
+
+ private TestMethodRunner _testMethodRunner;
+
+ public PUnitAbstractRunner(TestSuiteBuilder testSuiteBuiler, TestMethodBuilder testMethodBuilder, TestMethodRunner testMethodRunner) {
+ _testSuiteBuiler = testSuiteBuiler;
+ _testMethodBuilder = testMethodBuilder;
+ _testMethodRunner = testMethodRunner;
+ }
+
+ public TestResult run(Class clazz) {
+ Object[] testClasses = _testSuiteBuiler.buildTestClasses(clazz);
+ for (int i = 0; i < testClasses.length; ++i) {
+ runTestClass((Class)testClasses[i]);
+ }
+ return null;
+ }
+
+ private void runTestClass(Class clazz) {
+ if(!accept(clazz)) {
+ return;
+ }
+ Object[] testMethods = buildTestMethod(clazz);
+ for(int i = 0; i < testMethods.length; ++i) {
+ Method method = (Method) testMethods[i];
+ runTestMethod(clazz, method);
+ }
+ }
+
+ private void runTestMethod(Class clazz, Method method) {
+ // TODO: add run result to the test result
+ try {
+ _testMethodRunner.run(clazz, method);
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ private Object[] buildTestMethod(Class testClass) {
+ return _testMethodBuilder.buildTestMethods(testClass);
+ }
+
+ public abstract boolean accept(Class testCaseClass);
+
+}
Modified: trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -1,11 +1,16 @@
package org.punit.runner;
-import org.punit.result.*;
+import org.punit.builder.*;
+import org.punit.type.*;
-public class PUnitConcurrentRunner implements Runner {
+public class PUnitConcurrentRunner extends PUnitAbstractRunner {
- public TestResult run(Class clazz) {
- throw new UnsupportedOperationException();
+ public PUnitConcurrentRunner() {
+ super(new PUnitTestSuiteBuilder(), new PUnitTestMethodBuilder(), new ConcurrentTestMethodRunner());
}
+ public boolean accept(Class clazz) {
+ return Concurrent.class.isAssignableFrom(clazz);
+ }
+
}
Deleted: trunk/punit/src/org/punit/runner/PUnitRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitRunner.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit/src/org/punit/runner/PUnitRunner.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -1,49 +0,0 @@
-package org.punit.runner;
-
-import java.lang.reflect.*;
-
-import org.punit.builder.*;
-import org.punit.result.*;
-
-public class PUnitRunner implements Runner {
- private TestSuiteBuilder _testSuiteBuiler;
-
- private TestMethodBuilder _testMethodBuilder;
-
- private TestMethodRunner _testMethodRunner;
-
- public PUnitRunner() {
- this(new PUnitTestSuiteBuilder(), new PUnitTestMethodBuilder());
- }
-
- public PUnitRunner(TestSuiteBuilder testSuiteBuiler, TestMethodBuilder testMethodBuilder) {
- _testSuiteBuiler = testSuiteBuiler;
- _testMethodBuilder = testMethodBuilder;
- }
-
- public TestResult run(Class clazz) {
- Object[] testClasses = _testSuiteBuiler.buildTestClasses(clazz);
- for (int i = 0; i < testClasses.length; ++i) {
- runTestClass((Class)testClasses[i]);
- }
- throw new UnsupportedOperationException();
- }
-
- private void runTestClass(Class clazz) {
- Object[] testMethods = buildTestMethod(clazz);
- for(int i = 0; i < testMethods.length; ++i) {
- Method method = (Method) testMethods[i];
- runTestMethod(clazz, method);
- }
- throw new UnsupportedOperationException();
- }
-
- private void runTestMethod(Class clazz, Method method) {
-
- }
-
- private Object[] buildTestMethod(Class testClass) {
- return _testMethodBuilder.buildTestMethods(testClass);
- }
-
-}
Added: trunk/punit/src/org/punit/runner/PUnitSoloRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitSoloRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/PUnitSoloRunner.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -0,0 +1,16 @@
+package org.punit.runner;
+
+import org.punit.builder.*;
+
+public class PUnitSoloRunner extends PUnitAbstractRunner {
+
+ public PUnitSoloRunner() {
+ super(new PUnitTestSuiteBuilder(), new PUnitTestMethodBuilder(), new SoloTestMethodRunner());
+
+ }
+
+ public boolean accept(Class clazz) {
+ return true;
+ }
+
+}
Modified: trunk/punit/src/org/punit/runner/Runner.java
===================================================================
--- trunk/punit/src/org/punit/runner/Runner.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit/src/org/punit/runner/Runner.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -1,6 +1,5 @@
package org.punit.runner;
-import org.punit.*;
import org.punit.result.*;
public interface Runner {
Modified: trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -2,12 +2,11 @@
import org.punit.exception.*;
import org.punit.util.*;
-import org.punit.watcher.*;
public class SoloTestMethodRunner extends AbstractTestMethodRunner {
- public SoloTestMethodRunner(Watcher[] watchers) {
- super(watchers);
+ public SoloTestMethodRunner() {
+
}
protected void runImpl() throws Throwable {
Modified: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -13,7 +13,8 @@
//$JUnit-BEGIN$
suite.addTestSuite(ConcurrentExceptionTest.class);
suite.addTestSuite(MemoryWatcherTest.class);
- suite.addTestSuite(PUnitRunnerTest.class);
+ suite.addTestSuite(PUnitConcurrentRunnerTest.class);
+ suite.addTestSuite(PUnitSoloRunnerTest.class);
suite.addTestSuite(PUnitTestMethodBuilderTest.class);
suite.addTestSuite(PUnitTestSuiteBuilderTest.class);
suite.addTestSuite(ReflectionUtilTest.class);
Added: trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentTestClass.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentTestClass.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -0,0 +1,20 @@
+package tests.api.org.punit.runner;
+
+import org.punit.type.*;
+
+public class ConcurrentTestClass implements Concurrent {
+
+ public static int value = 0;
+
+ public static void reset() {
+ value = 0;
+ }
+
+ public synchronized void test() {
+ ++value;
+ }
+
+ public int concurrentCount() {
+ return 5;
+ }
+}
Added: trunk/punit.test/src/tests/api/org/punit/runner/PUnitConcurrentRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/PUnitConcurrentRunnerTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/runner/PUnitConcurrentRunnerTest.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -0,0 +1,64 @@
+package tests.api.org.punit.runner;
+
+import org.punit.runner.*;
+
+import junit.framework.*;
+
+public class PUnitConcurrentRunnerTest extends TestCase {
+ private PUnitConcurrentRunner _runner;
+
+ protected void setUp() throws Exception {
+ _runner = new PUnitConcurrentRunner();
+ }
+
+ public void testRunConcurrent() {
+ ConcurrentTestClass.reset();
+ _runner.run(ConcurrentTestClass.class);
+ assertConcurrentTestClassRun();
+ }
+
+ public void testRunTest() {
+ TestClass.reset();
+ _runner.run(TestClass.class);
+ assertTestClassNotRun();
+ }
+
+ public void testRunPUnitTest() {
+ PUnitTestClass.reset();
+ _runner.run(PUnitTestClass.class);
+ assertPUnitTestNotRun();
+ }
+
+ public void testRunTestSuite() {
+ ConcurrentTestClass.reset();
+ TestClass.reset();
+ PUnitTestClass.reset();
+ _runner.run(TestSuiteClass.class);
+ assertConcurrentTestClassRun();
+ assertTestClassNotRun();
+ assertPUnitTestNotRun();
+ }
+
+ private void assertPUnitTestNotRun() {
+ assertFalse(PUnitTestClass._test1);
+ assertFalse(PUnitTestClass._test2);
+ assertFalse(PUnitTestClass._setUp);
+ assertFalse(PUnitTestClass._tearDown);
+ assertFalse(PUnitTestClass._setUpBeforeWatchers);
+ assertFalse(PUnitTestClass._setUpAfterWatchers);
+ assertFalse(PUnitTestClass._tearDownBeforeWatchers);
+ assertFalse(PUnitTestClass._tearDownAfterWatchers);
+ }
+
+ private void assertConcurrentTestClassRun() {
+ ConcurrentTestClass test = new ConcurrentTestClass();
+ assertEquals(test.concurrentCount(), ConcurrentTestClass.value);
+ }
+
+ private void assertTestClassNotRun() {
+ assertFalse(TestClass._test1);
+ assertFalse(TestClass._test2);
+ assertFalse(TestClass._setUp);
+ assertFalse(TestClass._tearDown);
+ }
+}
Deleted: trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -1,9 +0,0 @@
-package tests.api.org.punit.runner;
-
-import junit.framework.*;
-
-public class PUnitRunnerTest extends TestCase {
- public void test() {
-
- }
-}
Copied: trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloRunnerTest.java (from rev 12, trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java)
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloRunnerTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloRunnerTest.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -0,0 +1,62 @@
+package tests.api.org.punit.runner;
+
+import org.punit.runner.*;
+
+import junit.framework.*;
+
+public class PUnitSoloRunnerTest extends TestCase {
+ private PUnitSoloRunner _runner;
+
+ protected void setUp() throws Exception {
+ _runner = new PUnitSoloRunner();
+ }
+
+ public void testRunTest() {
+ TestClass.reset();
+ _runner.run(TestClass.class);
+ assertTestClassRun();
+ }
+
+ public void testRunPUnitTest() {
+ PUnitTestClass.reset();
+ assertPUnitTestClassRun();
+ }
+
+ public void testRunConcurrent() {
+ ConcurrentTestClass.reset();
+ _runner.run(ConcurrentTestClass.class);
+ assertConcurrentTestClassRun();
+ }
+
+
+ public void testRunTestSuite() {
+ TestClass.reset();
+ PUnitTestClass.reset();
+ _runner.run(TestSuiteClass.class);
+ assertTestClassRun();
+ assertPUnitTestClassRun();
+ }
+
+ private void assertTestClassRun() {
+ assertFalse(TestClass._test1);
+ assertTrue(TestClass._test2);
+ assertTrue(TestClass._setUp);
+ assertTrue(TestClass._tearDown);
+ }
+
+ private void assertPUnitTestClassRun() {
+ _runner.run(PUnitTestClass.class);
+ assertFalse(PUnitTestClass._test1);
+ assertTrue(PUnitTestClass._test2);
+ assertFalse(PUnitTestClass._setUp);
+ assertFalse(PUnitTestClass._tearDown);
+ assertTrue(PUnitTestClass._setUpBeforeWatchers);
+ assertTrue(PUnitTestClass._setUpAfterWatchers);
+ assertTrue(PUnitTestClass._tearDownBeforeWatchers);
+ assertTrue(PUnitTestClass._tearDownAfterWatchers);
+ }
+
+ private void assertConcurrentTestClassRun() {
+ assertEquals(1, ConcurrentTestClass.value);
+ }
+}
Added: trunk/punit.test/src/tests/api/org/punit/runner/PUnitTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/PUnitTestClass.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/runner/PUnitTestClass.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -0,0 +1,65 @@
+package tests.api.org.punit.runner;
+
+import org.punit.type.*;
+
+public class PUnitTestClass implements PUnitTest {
+ public static boolean _test1;
+
+ public static boolean _test2;
+
+ public static boolean _setUp;
+
+ public static boolean _tearDown;
+
+ public static boolean _setUpAfterWatchers;
+
+ public static boolean _setUpBeforeWatchers;
+
+ public static boolean _tearDownAfterWatchers;
+
+ public static boolean _tearDownBeforeWatchers;
+
+ public static void reset() {
+ _test1 = false;
+ _test2 = false;
+ _setUp = false;
+ _tearDown = false;
+ _setUpAfterWatchers = false;
+ _setUpBeforeWatchers = false;
+ _tearDownAfterWatchers = false;
+ _tearDownBeforeWatchers = false;
+
+ }
+
+ private void setUp() {
+ _setUp = true;
+ }
+
+ private void tearDown() {
+ _tearDown = true;
+ }
+
+ private void test1() {
+ _test1 = true;
+ }
+
+ public void test2() {
+ _test2 = true;
+ }
+
+ public void setUpAfterWatchers() {
+ _setUpAfterWatchers = true;
+ }
+
+ public void setUpBeforeWatchers() {
+ _setUpBeforeWatchers = true;
+ }
+
+ public void tearDownAfterWatchers() {
+ _tearDownAfterWatchers = true;
+ }
+
+ public void tearDownBeforeWatchers() {
+ _tearDownBeforeWatchers = true;
+ }
+}
Added: trunk/punit.test/src/tests/api/org/punit/runner/TestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/TestClass.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/runner/TestClass.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -0,0 +1,35 @@
+package tests.api.org.punit.runner;
+
+public class TestClass {
+ public static boolean _test1;
+
+ public static boolean _test2;
+
+ public static boolean _setUp;
+
+ public static boolean _tearDown;
+
+ public static void reset() {
+ _test1 = false;
+ _test2 = false;
+ _setUp = false;
+ _tearDown = false;
+ }
+
+
+ private void setUp() {
+ _setUp = true;
+ }
+
+ private void tearDown() {
+ _tearDown = true;
+ }
+
+ private void test1() {
+ _test1 = true;
+ }
+
+ public void test2() {
+ _test2 = true;
+ }
+}
Added: trunk/punit.test/src/tests/api/org/punit/runner/TestSuiteClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/TestSuiteClass.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/runner/TestSuiteClass.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -0,0 +1,14 @@
+package tests.api.org.punit.runner;
+
+import org.punit.type.*;
+
+public class TestSuiteClass implements TestSuite {
+
+ public Class[] suite() {
+ return new Class[] {
+ TestClass.class,
+ PUnitTestClass.class,
+ ConcurrentTestClass.class,
+ };
+ }
+}
Modified: trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -6,7 +6,7 @@
public class ConcurrentTestSample implements Concurrent {
public static void main(String[] args) {
- new PUnitRunner().run(ConcurrentTestSample.class);
+ new PUnitConcurrentRunner().run(ConcurrentTestSample.class);
}
public void test1() {
Modified: trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -7,9 +7,17 @@
public class JUnitTestSample extends TestCase {
public static void main(String[] args) {
- new PUnitRunner().run(JUnitTestSample.class);
+ new PUnitSoloRunner().run(JUnitTestSample.class);
}
+ public void setUp() {
+
+ }
+
+ public void tearDown() {
+
+ }
+
public void test1() {
}
@@ -17,5 +25,5 @@
public void test2() {
}
-
+
}
Added: trunk/punit.test/src/tests/sample/testcase/PUnitTestCaseSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/PUnitTestCaseSample.java (rev 0)
+++ trunk/punit.test/src/tests/sample/testcase/PUnitTestCaseSample.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -0,0 +1,40 @@
+package tests.sample.testcase;
+
+import org.punit.runner.*;
+import org.punit.type.*;
+
+public class PUnitTestCaseSample implements PUnitTest {
+
+ public static void main(String[] args) {
+ new PUnitSoloRunner().run(PUnitTestCaseSample.class);
+ }
+
+ public void setUpAfterWatchers() {
+ }
+
+ public void setUpBeforeWatchers() {
+ }
+
+ public void tearDownBeforeWatchers() {
+ }
+
+ public void tearDownAfterWatchers() {
+ }
+
+ public void setUp() {
+
+ }
+
+ public void tearDown() {
+
+ }
+
+ public void test1() {
+
+ }
+
+ public void test2() {
+
+ }
+
+}
Modified: trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -1,9 +1,20 @@
package tests.sample.testcase;
+import org.punit.runner.*;
import org.punit.type.*;
public class PUnitTestSuiteSample implements TestSuite {
+ public static void main(String[] args) {
+ new PUnitSoloRunner().run(PUnitTestSuiteSample.class);
+ new PUnitConcurrentRunner().run(PUnitTestSuiteSample.class);
+ }
+
public Class[] suite() {
- throw new UnsupportedOperationException();
+ return new Class[] {
+ ConcurrentTestSample.class,
+ JUnitTestSample.class,
+ SimpleTestSample.class,
+ PUnitTestCaseSample.class,
+ };
}
}
Modified: trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -6,7 +6,7 @@
public class ParameterizableTestSample implements Parameterizable {
public static void main(String[] args) {
- new PUnitRunner().run(ParameterizableTestSample.class);
+ new PUnitSoloRunner().run(ParameterizableTestSample.class);
}
public void test1() {
Modified: trunk/punit.test/src/tests/sample/testcase/SimpleTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/SimpleTestSample.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit.test/src/tests/sample/testcase/SimpleTestSample.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -5,9 +5,17 @@
public class SimpleTestSample {
public static void main(String[] args) {
- new PUnitRunner().run(SimpleTestSample.class);
+ new PUnitSoloRunner().run(SimpleTestSample.class);
}
+ public void setUp() {
+
+ }
+
+ public void tearDown() {
+
+ }
+
public void test1() {
}
Modified: trunk/punit.test/src/tests/sample/testcase/VMTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/VMTestSample.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit.test/src/tests/sample/testcase/VMTestSample.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -6,7 +6,7 @@
public class VMTestSample implements VMComparable {
public static void main(String[] args) {
- new PUnitRunner().run(VMTestSample.class);
+ new PUnitSoloRunner().run(VMTestSample.class);
}
public void test1() {
Modified: trunk/punit.test/src/tests/sample/testcase/VersionCompetitiveTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/VersionCompetitiveTestSample.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit.test/src/tests/sample/testcase/VersionCompetitiveTestSample.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -6,7 +6,7 @@
public class VersionCompetitiveTestSample implements VersionCompetitive {
public static void main(String[] args) {
- new PUnitRunner().run(VersionCompetitiveTestSample.class);
+ new PUnitSoloRunner().run(VersionCompetitiveTestSample.class);
}
public void test1() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-10 17:59:06
|
Revision: 14
http://p-unit.svn.sourceforge.net/p-unit/?rev=14&view=rev
Author: zhanghuangzhu
Date: 2007-05-10 10:59:07 -0700 (Thu, 10 May 2007)
Log Message:
-----------
Andrew Zhang: continue to implement the runner.
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java
trunk/punit/src/org/punit/util/ReflectionUtil.java
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java
Added Paths:
-----------
trunk/punit/src/org/punit/exception/ConcurrentException.java
trunk/punit/src/org/punit/type/PUnitTest.java
trunk/punit/src/org/punit/util/Visitor.java
trunk/punit/src/org/punit/util/VisitorUtil.java
trunk/punit.test/src/tests/api/org/punit/exception/
trunk/punit.test/src/tests/api/org/punit/exception/ConcurrentExceptionTest.java
Removed Paths:
-------------
trunk/punit/src/org/punit/result/ConcurrentException.java
trunk/punit/src/org/punit/type/Test.java
Copied: trunk/punit/src/org/punit/exception/ConcurrentException.java (from rev 12, trunk/punit/src/org/punit/result/ConcurrentException.java)
===================================================================
--- trunk/punit/src/org/punit/exception/ConcurrentException.java (rev 0)
+++ trunk/punit/src/org/punit/exception/ConcurrentException.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -0,0 +1,35 @@
+package org.punit.exception;
+
+import java.util.*;
+
+import org.punit.util.*;
+
+public class ConcurrentException extends RuntimeException {
+ private static final long serialVersionUID = 1253114975237734895L;
+
+ private Vector _throwables = new Vector();
+
+ public void add(Throwable t) {
+ _throwables.add(t);
+ }
+
+ public int size() {
+ return _throwables.size();
+ }
+
+ public String getMessage() {
+ GetMessageVisitor visitor = new GetMessageVisitor();
+ VisitorUtil.traverse(_throwables.iterator(), visitor);
+ return visitor.sb.toString();
+ }
+
+ static class GetMessageVisitor implements Visitor {
+ final StringBuffer sb = new StringBuffer();
+
+ public void visit(Object obj) {
+ sb.append(((Throwable) obj));
+ sb.append("\n");
+ }
+
+ }
+}
Deleted: trunk/punit/src/org/punit/result/ConcurrentException.java
===================================================================
--- trunk/punit/src/org/punit/result/ConcurrentException.java 2007-05-10 16:53:45 UTC (rev 13)
+++ trunk/punit/src/org/punit/result/ConcurrentException.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -1,13 +0,0 @@
-package org.punit.result;
-
-import java.util.*;
-
-public class ConcurrentException extends RuntimeException {
- private Vector _throwables;
- public void add(Throwable t) {
- _throwables.add(t);
- }
- public int size() {
- return _throwables.size();
- }
-}
Modified: trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java 2007-05-10 16:53:45 UTC (rev 13)
+++ trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -3,6 +3,7 @@
import java.lang.reflect.*;
import org.punit.exception.*;
+import org.punit.type.*;
import org.punit.util.*;
import org.punit.watcher.*;
@@ -27,13 +28,14 @@
public Object[] run(Class clazz, Method method) throws Throwable {
try {
init(clazz, method);
- setUp();
setUpBeforeWatchers();
startWatchers();
+ setUpAfterWatchers();
runImpl();
} finally {
+ tearDownBeforeWatchers();
stopWatchers();
- tearDown();
+ tearDownAfterWatchers();
}
return watchersValues();
}
@@ -45,22 +47,42 @@
_class = clazz;
_method = method;
_method.setAccessible(true);
+ _setUpMethod = ReflectionUtil.getMethodAndSetAccessible(_testInstance
+ .getClass(), "setUp", new Class[] {});
+ _tearDownMethod = ReflectionUtil.getMethodAndSetAccessible(
+ _testInstance.getClass(), "tearDown", new Class[] {});
}
- /**
- * Subclass could override this method to do some custom setup before
- * watchers start.
- *
- */
- protected void setUpBeforeWatchers() {
+ private void setUpBeforeWatchers() {
+ if (isPUnitTest()) {
+ ((PUnitTest) _testInstance).setUpBeforeWatchers();
+ }
+ }
+ private void setUpAfterWatchers() throws Throwable {
+ if (isPUnitTest()) {
+ ((PUnitTest) _testInstance).setUpAfterWatchers();
+ } else {
+ setUp();
+ }
}
- protected void setUp() throws Throwable {
- _setUpMethod = ReflectionUtil.getMethod(_testInstance.getClass(),
- "setUp", new Class[] {});
+ private void tearDownBeforeWatchers() throws Throwable {
+ if (isPUnitTest()) {
+ ((PUnitTest) _testInstance).tearDownBeforeWatchers();
+ } else {
+ tearDown();
+ }
+ }
+
+ private void tearDownAfterWatchers() {
+ if (isPUnitTest()) {
+ ((PUnitTest) _testInstance).tearDownAfterWatchers();
+ }
+ }
+
+ private void setUp() throws Throwable {
if (_setUpMethod != null) {
- _setUpMethod.setAccessible(true);
try {
ReflectionUtil.invokeMethod(_setUpMethod, _testInstance,
new Object[] {});
@@ -70,11 +92,8 @@
}
}
- protected void tearDown() throws Throwable {
- _tearDownMethod = ReflectionUtil.getMethod(_testInstance.getClass(),
- "tearDown", new Class[] {});
+ private void tearDown() throws Throwable {
if (_tearDownMethod != null) {
- _tearDownMethod.setAccessible(true);
try {
ReflectionUtil.invokeMethod(_tearDownMethod, _testInstance,
new Object[] {});
@@ -103,4 +122,8 @@
}
return values;
}
+
+ private boolean isPUnitTest() {
+ return PUnitTest.class.isAssignableFrom(_class);
+ }
}
Copied: trunk/punit/src/org/punit/type/PUnitTest.java (from rev 12, trunk/punit/src/org/punit/type/Test.java)
===================================================================
--- trunk/punit/src/org/punit/type/PUnitTest.java (rev 0)
+++ trunk/punit/src/org/punit/type/PUnitTest.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -0,0 +1,13 @@
+package org.punit.type;
+
+public interface PUnitTest {
+
+ public void setUpBeforeWatchers();
+
+ public void setUpAfterWatchers();
+
+ public void tearDownBeforeWatchers();
+
+ public void tearDownAfterWatchers();
+
+}
Deleted: trunk/punit/src/org/punit/type/Test.java
===================================================================
--- trunk/punit/src/org/punit/type/Test.java 2007-05-10 16:53:45 UTC (rev 13)
+++ trunk/punit/src/org/punit/type/Test.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -1,13 +0,0 @@
-package org.punit.type;
-
-public interface Test {
-
- public void setUpBeforeWatchers();
-
- public void setUpAfterWatchers();
-
- public void tearDownBeforeWatchers();
-
- public void tearDownAfterWatchers();
-
-}
Modified: trunk/punit/src/org/punit/util/ReflectionUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/ReflectionUtil.java 2007-05-10 16:53:45 UTC (rev 13)
+++ trunk/punit/src/org/punit/util/ReflectionUtil.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -18,12 +18,30 @@
public static Method getMethod(Class clazz, String methodName, Class[] params) {
try {
- return clazz.getDeclaredMethod(methodName, params);
+ Method method = clazz.getDeclaredMethod(methodName, params);
+ return method;
} catch (Exception e) {
return null;
}
}
+ /**
+ * Gets the method and sets the accessible to true
+ * @param clazz
+ * @param methodName
+ * @param params
+ * @return
+ */
+ public static Method getMethodAndSetAccessible(Class clazz, String methodName, Class[] params) {
+ try {
+ Method method = clazz.getDeclaredMethod(methodName, params);
+ method.setAccessible(true);
+ return method;
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
public static Object invokeMethod(Method method, Object instance, Object[] params) throws ReflectionException {
try {
return method.invoke(instance, params);
Added: trunk/punit/src/org/punit/util/Visitor.java
===================================================================
--- trunk/punit/src/org/punit/util/Visitor.java (rev 0)
+++ trunk/punit/src/org/punit/util/Visitor.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -0,0 +1,5 @@
+package org.punit.util;
+
+public interface Visitor {
+ public void visit(Object obj);
+}
Added: trunk/punit/src/org/punit/util/VisitorUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/VisitorUtil.java (rev 0)
+++ trunk/punit/src/org/punit/util/VisitorUtil.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -0,0 +1,11 @@
+package org.punit.util;
+
+import java.util.*;
+
+public class VisitorUtil {
+ public static void traverse(Iterator iter, Visitor visitor) {
+ while (iter.hasNext()) {
+ visitor.visit(iter.next());
+ }
+ }
+}
Modified: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-10 16:53:45 UTC (rev 13)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -2,6 +2,7 @@
import junit.framework.*;
import tests.api.org.punit.builder.*;
+import tests.api.org.punit.exception.*;
import tests.api.org.punit.runner.*;
import tests.api.org.punit.util.*;
import tests.api.org.punit.watcher.*;
@@ -10,6 +11,7 @@
public static Test suite() {
TestSuite suite = new TestSuite("Test for tests.api.org.punit");
//$JUnit-BEGIN$
+ suite.addTestSuite(ConcurrentExceptionTest.class);
suite.addTestSuite(MemoryWatcherTest.class);
suite.addTestSuite(PUnitRunnerTest.class);
suite.addTestSuite(PUnitTestMethodBuilderTest.class);
Modified: trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java 2007-05-10 16:53:45 UTC (rev 13)
+++ trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -19,47 +19,84 @@
public void testBuildTestMethods1() {
Object[] methods = _testMethodBuidler.buildTestMethods(Test1.class);
String[] names = toMethodNameArray(methods);
- AssertUtil.assertArrayContent(names, new String[] { "test1", "test2", "testa", "testb" });
+ AssertUtil.assertArrayContent(names, new String[] { "test1", "test2",
+ "testa", "testb" });
}
-
+
public void testBuildTestMethods2() {
Object[] methods = _testMethodBuidler.buildTestMethods(Test2.class);
String[] names = toMethodNameArray(methods);
- AssertUtil.assertArrayContent(names, new String[] { "test1", "test2", "testa", "testb" });
+ AssertUtil.assertArrayContent(names, new String[] { "test1", "test2",
+ "testa", "testb" });
}
public void testBuildTestMethods3() {
Object[] methods = _testMethodBuidler.buildTestMethods(Test3.class);
String[] names = toMethodNameArray(methods);
- AssertUtil.assertArray(names, new String[] { "test1", "test2", "testa", "testb" });
+ AssertUtil.assertArray(names, new String[] { "test1", "test2", "testa",
+ "testb" });
}
private String[] toMethodNameArray(Object[] methods) {
- String[] names = new String [methods.length];
- for(int i = 0; i < methods.length; ++i) {
- names[i] = ((Method)methods[i]).getName();
+ String[] names = new String[methods.length];
+ for (int i = 0; i < methods.length; ++i) {
+ names[i] = ((Method) methods[i]).getName();
}
return names;
}
private static class Test1 {
- public void test1() {}
- public void test2() {}
- public void testa() {}
- public void testb() {}
+ public void test1() {
+ }
+
+ public void test2() {
+ }
+
+ public void testa() {
+ }
+
+ public void testb() {
+ }
+
+ public void _testc() {
+ }
+
+ void testd() {
+ }
+
+ private void teste() {
+ }
+
+ public static void testf() {
+
+ }
}
private static class Test2 {
- public void test2() {}
- public void test1() {}
- public void testb() {}
- public void testa() {}
+ public void test2() {
+ }
+
+ public void test1() {
+ }
+
+ public void testb() {
+ }
+
+ public void testa() {
+ }
}
private static class Test3 implements Alphabetical {
- public void test2() {}
- public void test1() {}
- public void testb() {}
- public void testa() {}
+ public void test2() {
+ }
+
+ public void test1() {
+ }
+
+ public void testb() {
+ }
+
+ public void testa() {
+ }
}
}
Added: trunk/punit.test/src/tests/api/org/punit/exception/ConcurrentExceptionTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/exception/ConcurrentExceptionTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/exception/ConcurrentExceptionTest.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -0,0 +1,17 @@
+package tests.api.org.punit.exception;
+
+import org.punit.exception.*;
+
+import junit.framework.*;
+
+public class ConcurrentExceptionTest extends TestCase {
+ public void testGetMessage() {
+ ConcurrentException concurrentException = new ConcurrentException();
+ NullPointerException npe = new NullPointerException("NPE");
+ concurrentException.add(npe);
+ IllegalArgumentException iae = new IllegalArgumentException("IAE");
+ concurrentException.add(iae);
+ String message = concurrentException.getMessage();
+ assertEquals(npe + "\n" + iae + "\n", message);
+ }
+}
Modified: trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java 2007-05-10 16:53:45 UTC (rev 13)
+++ trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -30,10 +30,21 @@
method = ReflectionUtil.getMethod(Test1.class, "test2", new Class[] {});
assertNull(method);
- method = ReflectionUtil.getMethod(Test1.class, "test3", new Class[] {});
+ method = ReflectionUtil.getMethod(Test1.class, "test4", new Class[] {});
assertNull(method);
}
+ public void testGetMethodAndSetAccessible() {
+ Test1 obj = new Test1();
+ Method method = ReflectionUtil.getMethodAndSetAccessible(Test1.class,
+ "test1", new Class[] {});
+ ReflectionUtil.invokeMethod(method, obj, new Object[] {});
+
+ method = ReflectionUtil.getMethodAndSetAccessible(Test1.class,
+ "test3", new Class[] {});
+ ReflectionUtil.invokeMethod(method, obj, new Object[] {});
+ }
+
public void testInvokeMethod() {
final Test1 obj = new Test1();
final Method method = ReflectionUtil.getMethod(Test1.class, "test1",
@@ -111,6 +122,10 @@
private void test2(int i) {
value = i;
}
+
+ public void test3() {
+
+ }
}
private static class Test2 {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-10 16:53:44
|
Revision: 13
http://p-unit.svn.sourceforge.net/p-unit/?rev=13&view=rev
Author: zhanghuangzhu
Date: 2007-05-10 09:53:45 -0700 (Thu, 10 May 2007)
Log Message:
-----------
Andrew Zhang: Added a test case for ReflctionUtil.
Modified Paths:
--------------
trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java
Modified: trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java 2007-05-10 16:22:27 UTC (rev 12)
+++ trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java 2007-05-10 16:53:45 UTC (rev 13)
@@ -48,6 +48,12 @@
method.setAccessible(true);
ReflectionUtil.invokeMethod(method, obj, new Object[] {});
assertEquals(10, obj.value);
+
+ final Method method2 = ReflectionUtil.getMethod(Test1.class, "test2",
+ new Class[] {Integer.TYPE});
+ method2.setAccessible(true);
+ ReflectionUtil.invokeMethod(method2, obj, new Object[] { new Integer(100) });
+ assertEquals(100, obj.value);
}
public void testIsPublicMethod() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-10 16:22:28
|
Revision: 12
http://p-unit.svn.sourceforge.net/p-unit/?rev=12&view=rev
Author: zhanghuangzhu
Date: 2007-05-10 09:22:27 -0700 (Thu, 10 May 2007)
Log Message:
-----------
Andrew Zhang: first step to implement the runner.
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
trunk/punit/src/org/punit/runner/PUnitRunner.java
trunk/punit/src/org/punit/runner/Runner.java
trunk/punit/src/org/punit/type/Test.java
trunk/punit/src/org/punit/util/ReflectionUtil.java
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java
trunk/punit.test/src/tests/util/AssertUtil.java
Added Paths:
-----------
trunk/punit/src/org/punit/builder/
trunk/punit/src/org/punit/builder/PUnitTestMethodBuilder.java
trunk/punit/src/org/punit/builder/PUnitTestSuiteBuilder.java
trunk/punit/src/org/punit/builder/TestMethodBuilder.java
trunk/punit/src/org/punit/builder/TestSuiteBuilder.java
trunk/punit/src/org/punit/result/
trunk/punit/src/org/punit/result/ConcurrentException.java
trunk/punit/src/org/punit/result/TestResult.java
trunk/punit/src/org/punit/result/TestResultItem.java
trunk/punit/src/org/punit/result/TestResultItemImpl.java
trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java
trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java
trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java
trunk/punit/src/org/punit/runner/TestMethodRunner.java
trunk/punit/src/org/punit/type/Comparable.java
trunk/punit/src/org/punit/type/Version.java
trunk/punit/src/org/punit/type/VersionCompetitive.java
trunk/punit.test/src/tests/api/org/punit/builder/
trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestSuiteBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/util/
trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java
trunk/punit.test/src/tests/sample/testcase/VersionCompetitiveTestSample.java
trunk/punit.test/src/tests/util/CodeRunner.java
Removed Paths:
-------------
trunk/punit/src/org/punit/TestResult.java
trunk/punit/src/org/punit/type/Competitive.java
trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java
trunk/punit.test/src/tests/sample/testcase/PUnitTestSample.java
Deleted: trunk/punit/src/org/punit/TestResult.java
===================================================================
--- trunk/punit/src/org/punit/TestResult.java 2007-05-09 22:29:40 UTC (rev 11)
+++ trunk/punit/src/org/punit/TestResult.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -1,7 +0,0 @@
-package org.punit;
-
-import java.util.*;
-
-public interface TestResult extends Collection {
-
-}
Added: trunk/punit/src/org/punit/builder/PUnitTestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/PUnitTestMethodBuilder.java (rev 0)
+++ trunk/punit/src/org/punit/builder/PUnitTestMethodBuilder.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,55 @@
+package org.punit.builder;
+
+import java.lang.reflect.*;
+import java.util.*;
+
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class PUnitTestMethodBuilder implements TestMethodBuilder {
+
+ public Object[] buildTestMethods(Class testClass) {
+ Method[] methods = testClass.getDeclaredMethods();
+ Collection testMethods;
+ if (isAlphabetical(testClass)) {
+ testMethods = new TreeSet(new AlphabeticalMethodNameComparator());
+ } else {
+ testMethods = new ArrayList();
+ }
+ for (int i = 0; i < methods.length; ++i) {
+ Method method = methods[i];
+ if (isTestMethod(method)) {
+ testMethods.add(method);
+ }
+ }
+ return testMethods.toArray();
+ }
+
+ private boolean isAlphabetical(Class testClass) {
+ return Alphabetical.class.isAssignableFrom(testClass);
+ }
+
+ /**
+ * Returns true if this method is regarded as a test method. Might be
+ * overriden by the subclass for convenience.
+ *
+ * By default, returns true if the method is public and not static, and
+ * starts with "test".
+ *
+ * @param method
+ * @return true if it is a test method
+ */
+ protected boolean isTestMethod(Method method) {
+ String name = method.getName();
+ return ReflectionUtil.isPublic(method)
+ && !ReflectionUtil.isStatic(method) && name.startsWith("test");
+ }
+
+ private static class AlphabeticalMethodNameComparator implements Comparator {
+ public int compare(Object o1, Object o2) {
+ Method m1 = (Method) o1;
+ Method m2 = (Method) o2;
+ return m1.getName().compareTo(m2.getName());
+ }
+ }
+}
Added: trunk/punit/src/org/punit/builder/PUnitTestSuiteBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/PUnitTestSuiteBuilder.java (rev 0)
+++ trunk/punit/src/org/punit/builder/PUnitTestSuiteBuilder.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,41 @@
+package org.punit.builder;
+
+import java.util.*;
+
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class PUnitTestSuiteBuilder implements TestSuiteBuilder {
+ public Object[] buildTestClasses(Class clazz) {
+ List testClasses = new ArrayList();
+ buildTestClasses(testClasses, clazz);
+ return testClasses.toArray();
+ }
+
+ private void buildTestClasses(List testClasses, Class clazz) {
+ if(isTestSuite(clazz)) {
+ buildTestClassFromTestSuite(testClasses, clazz);
+ } else {
+ buildTestClassesFromClass(testClasses, clazz);
+ }
+ }
+
+ private void buildTestClassFromTestSuite(List testClasses, Class clazz) {
+ TestSuite testSuite = (TestSuite) ReflectionUtil.newInstance(clazz);
+ Class[] suite = testSuite.suite();
+ for(int i = 0; i < suite.length; ++i) {
+ buildTestClasses(testClasses, suite[i]);
+ }
+ }
+
+ private void buildTestClassesFromClass(List testClasses, Class clazz) {
+ String name = null;
+ testClasses.add(clazz);
+ }
+
+
+ private boolean isTestSuite(Class clazz) {
+ return TestSuite.class.isAssignableFrom(clazz);
+ }
+
+}
Added: trunk/punit/src/org/punit/builder/TestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/TestMethodBuilder.java (rev 0)
+++ trunk/punit/src/org/punit/builder/TestMethodBuilder.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,13 @@
+package org.punit.builder;
+
+public interface TestMethodBuilder {
+ /**
+ * Builds the test methods from the test class. Returns a list of methods.
+ * The real return type should be Method[]. It returns Object[] for java 1.4
+ * compatibility.
+ *
+ * @param clazz
+ * @return
+ */
+ public Object[] buildTestMethods(Class testClass);
+}
Added: trunk/punit/src/org/punit/builder/TestSuiteBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/TestSuiteBuilder.java (rev 0)
+++ trunk/punit/src/org/punit/builder/TestSuiteBuilder.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,12 @@
+package org.punit.builder;
+
+public interface TestSuiteBuilder {
+ /**
+ * Builds the test suite. Returns a list of test classes. The real return
+ * type should be Class[]. It returns Object[] for java 1.4 compatibility.
+ *
+ * @param clazz
+ * @return
+ */
+ public Object[] buildTestClasses(Class testSutie);
+}
Added: trunk/punit/src/org/punit/result/ConcurrentException.java
===================================================================
--- trunk/punit/src/org/punit/result/ConcurrentException.java (rev 0)
+++ trunk/punit/src/org/punit/result/ConcurrentException.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,13 @@
+package org.punit.result;
+
+import java.util.*;
+
+public class ConcurrentException extends RuntimeException {
+ private Vector _throwables;
+ public void add(Throwable t) {
+ _throwables.add(t);
+ }
+ public int size() {
+ return _throwables.size();
+ }
+}
Copied: trunk/punit/src/org/punit/result/TestResult.java (from rev 7, trunk/punit/src/org/punit/TestResult.java)
===================================================================
--- trunk/punit/src/org/punit/result/TestResult.java (rev 0)
+++ trunk/punit/src/org/punit/result/TestResult.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,6 @@
+package org.punit.result;
+
+
+public interface TestResult {
+ public TestResultItem [] result();
+}
Added: trunk/punit/src/org/punit/result/TestResultItem.java
===================================================================
--- trunk/punit/src/org/punit/result/TestResultItem.java (rev 0)
+++ trunk/punit/src/org/punit/result/TestResultItem.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,11 @@
+package org.punit.result;
+
+public interface TestResultItem {
+
+ public abstract int id();
+
+ public abstract String[] names();
+
+ public abstract long[] values();
+
+}
\ No newline at end of file
Added: trunk/punit/src/org/punit/result/TestResultItemImpl.java
===================================================================
--- trunk/punit/src/org/punit/result/TestResultItemImpl.java (rev 0)
+++ trunk/punit/src/org/punit/result/TestResultItemImpl.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,31 @@
+package org.punit.result;
+
+public class TestResultItemImpl implements TestResultItem {
+ private int id;
+
+ private String[] names;
+
+ private long[] values;
+
+ private Throwable throwable;
+
+
+ public TestResultItemImpl(int id, String[] names, long[] values, Throwable throwable) {
+ this.id = id;
+ this.names = names;
+ this.values = values;
+ this.throwable = throwable;
+ }
+
+ public int id() {
+ return id;
+ }
+
+ public String[] names() {
+ return names;
+ }
+
+ public long[] values() {
+ return values;
+ }
+}
Added: trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,106 @@
+package org.punit.runner;
+
+import java.lang.reflect.*;
+
+import org.punit.exception.*;
+import org.punit.util.*;
+import org.punit.watcher.*;
+
+public abstract class AbstractTestMethodRunner implements TestMethodRunner {
+
+ protected final Watcher[] _watchers;
+
+ protected Object _testInstance;
+
+ protected Method _method;
+
+ protected Class _class;
+
+ protected Method _tearDownMethod;
+
+ protected Method _setUpMethod;
+
+ public AbstractTestMethodRunner(Watcher[] watchers) {
+ _watchers = watchers;
+ }
+
+ public Object[] run(Class clazz, Method method) throws Throwable {
+ try {
+ init(clazz, method);
+ setUp();
+ setUpBeforeWatchers();
+ startWatchers();
+ runImpl();
+ } finally {
+ stopWatchers();
+ tearDown();
+ }
+ return watchersValues();
+ }
+
+ protected abstract void runImpl() throws Throwable;
+
+ protected final void init(Class clazz, Method method) {
+ _testInstance = ReflectionUtil.newInstance(clazz);
+ _class = clazz;
+ _method = method;
+ _method.setAccessible(true);
+ }
+
+ /**
+ * Subclass could override this method to do some custom setup before
+ * watchers start.
+ *
+ */
+ protected void setUpBeforeWatchers() {
+
+ }
+
+ protected void setUp() throws Throwable {
+ _setUpMethod = ReflectionUtil.getMethod(_testInstance.getClass(),
+ "setUp", new Class[] {});
+ if (_setUpMethod != null) {
+ _setUpMethod.setAccessible(true);
+ try {
+ ReflectionUtil.invokeMethod(_setUpMethod, _testInstance,
+ new Object[] {});
+ } catch (ReflectionException e) {
+ throw e.getCause();
+ }
+ }
+ }
+
+ protected void tearDown() throws Throwable {
+ _tearDownMethod = ReflectionUtil.getMethod(_testInstance.getClass(),
+ "tearDown", new Class[] {});
+ if (_tearDownMethod != null) {
+ _tearDownMethod.setAccessible(true);
+ try {
+ ReflectionUtil.invokeMethod(_tearDownMethod, _testInstance,
+ new Object[] {});
+ } catch (ReflectionException e) {
+ throw e.getCause();
+ }
+ }
+ }
+
+ protected final void startWatchers() {
+ for (int i = 0; i < _watchers.length; ++i) {
+ _watchers[i].start();
+ }
+ }
+
+ protected final void stopWatchers() {
+ for (int i = 0; i < _watchers.length; ++i) {
+ _watchers[i].stop();
+ }
+ }
+
+ protected final Object[] watchersValues() {
+ Object[] values = new Object[_watchers.length];
+ for (int i = 0; i < _watchers.length; ++i) {
+ values[i] = _watchers[i].value();
+ }
+ return values;
+ }
+}
Added: trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,67 @@
+package org.punit.runner;
+
+import org.punit.exception.*;
+import org.punit.result.*;
+import org.punit.type.*;
+import org.punit.util.*;
+import org.punit.watcher.*;
+
+public class ConcurrentTestMethodRunner extends AbstractTestMethodRunner {
+ TestMethodThread[] _threads;
+
+ ConcurrentException _concurrentException = new ConcurrentException();
+
+ public ConcurrentTestMethodRunner(Watcher[] watchers) {
+ super(watchers);
+ }
+
+ protected void runImpl() throws Throwable {
+ startThreads();
+ joinThreads();
+ if(_concurrentException.size() > 0) {
+ throw _concurrentException;
+ }
+ }
+
+ private void startThreads() {
+ for (int i = 0; i < _threads.length; ++i) {
+ _threads[i].start();
+ }
+ }
+
+ private void joinThreads() {
+ for (int i = 0; i < _threads.length; ++i) {
+ try {
+ _threads[i].join();
+ } catch (InterruptedException e) {
+ _concurrentException.add(e);
+ }
+ }
+ }
+
+ /**
+ * @Override
+ */
+ protected void setUpBeforeWatchers() {
+ Concurrent concurrentTestInstance = (Concurrent) _testInstance;
+ int threadCount = concurrentTestInstance.concurrentCount();
+ _threads = new TestMethodThread[threadCount];
+ for (int i = 0; i < _threads.length; ++i) {
+ _threads[i] = new TestMethodThread();
+ }
+ }
+
+ private class TestMethodThread extends Thread {
+ // TODO: exception hanlding
+ public void run() {
+ try {
+ ReflectionUtil.invokeMethod(_method, _testInstance,
+ new Object[] {});
+ } catch (ReflectionException e) {
+ _concurrentException.add(e.getCause());
+ } catch (Throwable t) {
+ _concurrentException.add(t);
+ }
+ }
+ }
+}
Modified: trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-09 22:29:40 UTC (rev 11)
+++ trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -1,6 +1,6 @@
package org.punit.runner;
-import org.punit.*;
+import org.punit.result.*;
public class PUnitConcurrentRunner implements Runner {
Modified: trunk/punit/src/org/punit/runner/PUnitRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitRunner.java 2007-05-09 22:29:40 UTC (rev 11)
+++ trunk/punit/src/org/punit/runner/PUnitRunner.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -1,46 +1,49 @@
package org.punit.runner;
-import java.util.*;
+import java.lang.reflect.*;
-import org.punit.*;
-import org.punit.type.*;
-import org.punit.util.*;
+import org.punit.builder.*;
+import org.punit.result.*;
public class PUnitRunner implements Runner {
+ private TestSuiteBuilder _testSuiteBuiler;
+
+ private TestMethodBuilder _testMethodBuilder;
+
+ private TestMethodRunner _testMethodRunner;
- public TestResult run(Class clazz) {
- List testClasses = buildTestClasses(clazz);
- throw new UnsupportedOperationException();
+ public PUnitRunner() {
+ this(new PUnitTestSuiteBuilder(), new PUnitTestMethodBuilder());
}
- protected List buildTestClasses(Class clazz) {
- List testClasses = new ArrayList();
- buildTestClasses(testClasses, clazz);
- return testClasses;
+ public PUnitRunner(TestSuiteBuilder testSuiteBuiler, TestMethodBuilder testMethodBuilder) {
+ _testSuiteBuiler = testSuiteBuiler;
+ _testMethodBuilder = testMethodBuilder;
}
- private void buildTestClasses(List testClasses, Class clazz) {
- if(isTestSuite(clazz)) {
- buildTestClassFromTestSuite(testClasses, clazz);
- } else {
- buildTestClassesFromClass(testClasses, clazz);
+ public TestResult run(Class clazz) {
+ Object[] testClasses = _testSuiteBuiler.buildTestClasses(clazz);
+ for (int i = 0; i < testClasses.length; ++i) {
+ runTestClass((Class)testClasses[i]);
}
+ throw new UnsupportedOperationException();
}
- private void buildTestClassFromTestSuite(List testClasses, Class clazz) {
- TestSuite testSuite = (TestSuite) ReflectionUtil.newInstance(clazz);
- Class[] suite = testSuite.suite();
- for(int i = 0; i < suite.length; ++i) {
- buildTestClasses(testClasses, suite[i]);
+ private void runTestClass(Class clazz) {
+ Object[] testMethods = buildTestMethod(clazz);
+ for(int i = 0; i < testMethods.length; ++i) {
+ Method method = (Method) testMethods[i];
+ runTestMethod(clazz, method);
}
- }
+ throw new UnsupportedOperationException();
+ }
- private void buildTestClassesFromClass(List testClasses, Class clazz) {
- testClasses.add(clazz);
+ private void runTestMethod(Class clazz, Method method) {
+
}
- private boolean isTestSuite(Class clazz) {
- return TestSuite.class.isAssignableFrom(clazz);
+ private Object[] buildTestMethod(Class testClass) {
+ return _testMethodBuilder.buildTestMethods(testClass);
}
}
Modified: trunk/punit/src/org/punit/runner/Runner.java
===================================================================
--- trunk/punit/src/org/punit/runner/Runner.java 2007-05-09 22:29:40 UTC (rev 11)
+++ trunk/punit/src/org/punit/runner/Runner.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -1,6 +1,7 @@
package org.punit.runner;
import org.punit.*;
+import org.punit.result.*;
public interface Runner {
public TestResult run(Class clazz);
Added: trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,22 @@
+package org.punit.runner;
+
+import org.punit.exception.*;
+import org.punit.util.*;
+import org.punit.watcher.*;
+
+public class SoloTestMethodRunner extends AbstractTestMethodRunner {
+
+ public SoloTestMethodRunner(Watcher[] watchers) {
+ super(watchers);
+ }
+
+ protected void runImpl() throws Throwable {
+ try {
+ ReflectionUtil
+ .invokeMethod(_method, _testInstance, new Object[] {});
+ } catch (ReflectionException e) {
+ throw e.getCause();
+ }
+ }
+
+}
Added: trunk/punit/src/org/punit/runner/TestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/TestMethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/TestMethodRunner.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,14 @@
+package org.punit.runner;
+
+import java.lang.reflect.*;
+
+public interface TestMethodRunner {
+ /**
+ * Runs the test method, and returns the watcher values.
+ * @param clazz
+ * @param method
+ * @return
+ */
+ public Object[] run(Class clazz, Method method) throws Throwable;
+
+}
Added: trunk/punit/src/org/punit/type/Comparable.java
===================================================================
--- trunk/punit/src/org/punit/type/Comparable.java (rev 0)
+++ trunk/punit/src/org/punit/type/Comparable.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,17 @@
+package org.punit.type;
+
+public interface Comparable {
+ /**
+ * returns an id of the test scenario. It may be possible that several tests
+ * return the same id, which means they are competing against the same
+ * scenario.
+ * @return id
+ */
+ public int id();
+
+ /**
+ * Returns the name of this test.
+ * @return
+ */
+ public String name();
+}
Deleted: trunk/punit/src/org/punit/type/Competitive.java
===================================================================
--- trunk/punit/src/org/punit/type/Competitive.java 2007-05-09 22:29:40 UTC (rev 11)
+++ trunk/punit/src/org/punit/type/Competitive.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -1,6 +0,0 @@
-package org.punit.type;
-
-public interface Competitive {
- public Class testInterface();
- public Class[] implmentators();
-}
Modified: trunk/punit/src/org/punit/type/Test.java
===================================================================
--- trunk/punit/src/org/punit/type/Test.java 2007-05-09 22:29:40 UTC (rev 11)
+++ trunk/punit/src/org/punit/type/Test.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -3,7 +3,11 @@
public interface Test {
public void setUpBeforeWatchers();
+
+ public void setUpAfterWatchers();
+ public void tearDownBeforeWatchers();
+
public void tearDownAfterWatchers();
}
Added: trunk/punit/src/org/punit/type/Version.java
===================================================================
--- trunk/punit/src/org/punit/type/Version.java (rev 0)
+++ trunk/punit/src/org/punit/type/Version.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,21 @@
+package org.punit.type;
+
+public class Version {
+
+ private String _resourcePath;
+
+ private String _versionName;
+
+ public Version(String path, String name) {
+ _resourcePath = path;
+ _versionName = name;
+ }
+
+ public String resourcePath() {
+ return _resourcePath;
+ }
+
+ public String versionName() {
+ return _versionName;
+ }
+}
Added: trunk/punit/src/org/punit/type/VersionCompetitive.java
===================================================================
--- trunk/punit/src/org/punit/type/VersionCompetitive.java (rev 0)
+++ trunk/punit/src/org/punit/type/VersionCompetitive.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,5 @@
+package org.punit.type;
+
+public interface VersionCompetitive {
+ public Version[] versions();
+}
Modified: trunk/punit/src/org/punit/util/ReflectionUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/ReflectionUtil.java 2007-05-09 22:29:40 UTC (rev 11)
+++ trunk/punit/src/org/punit/util/ReflectionUtil.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -5,6 +5,7 @@
import org.punit.exception.*;
public class ReflectionUtil {
+
public static Object newInstance(Class clazz) {
try {
Constructor constructor = clazz.getDeclaredConstructor(new Class[] {});
@@ -14,4 +15,39 @@
throw new ReflectionException(e);
}
}
+
+ public static Method getMethod(Class clazz, String methodName, Class[] params) {
+ try {
+ return clazz.getDeclaredMethod(methodName, params);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public static Object invokeMethod(Method method, Object instance, Object[] params) throws ReflectionException {
+ try {
+ return method.invoke(instance, params);
+ } catch (IllegalArgumentException e) {
+ throw new ReflectionException(e);
+ } catch (IllegalAccessException e) {
+ throw new ReflectionException(e);
+ } catch (InvocationTargetException e) {
+ throw new ReflectionException(e.getTargetException());
+ }
+ }
+
+ public static boolean isPublic(Method method) {
+ int modifier = method.getModifiers();
+ return isBitSet(modifier, Modifier.PUBLIC);
+ }
+
+ public static boolean isStatic(Method method) {
+ int modifier = method.getModifiers();
+ return isBitSet(modifier, Modifier.STATIC);
+ }
+
+ private static boolean isBitSet(int value, int expectedBit) {
+ return (value & expectedBit) != 0;
+
+ }
}
Modified: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-09 22:29:40 UTC (rev 11)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -1,15 +1,20 @@
package tests.api.org.punit.all;
import junit.framework.*;
+import tests.api.org.punit.builder.*;
import tests.api.org.punit.runner.*;
+import tests.api.org.punit.util.*;
import tests.api.org.punit.watcher.*;
public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite("Test for tests.api.org.punit");
//$JUnit-BEGIN$
+ suite.addTestSuite(MemoryWatcherTest.class);
suite.addTestSuite(PUnitRunnerTest.class);
- suite.addTestSuite(MemoryWatcherTest.class);
+ suite.addTestSuite(PUnitTestMethodBuilderTest.class);
+ suite.addTestSuite(PUnitTestSuiteBuilderTest.class);
+ suite.addTestSuite(ReflectionUtilTest.class);
suite.addTestSuite(TimeWatcherTest.class);
//$JUnit-END$
return suite;
Added: trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,65 @@
+package tests.api.org.punit.builder;
+
+import java.lang.reflect.*;
+
+import junit.framework.*;
+
+import org.punit.builder.*;
+import org.punit.type.*;
+
+import tests.util.*;
+
+public class PUnitTestMethodBuilderTest extends TestCase {
+ private PUnitTestMethodBuilder _testMethodBuidler;
+
+ protected void setUp() throws Exception {
+ _testMethodBuidler = new PUnitTestMethodBuilder();
+ }
+
+ public void testBuildTestMethods1() {
+ Object[] methods = _testMethodBuidler.buildTestMethods(Test1.class);
+ String[] names = toMethodNameArray(methods);
+ AssertUtil.assertArrayContent(names, new String[] { "test1", "test2", "testa", "testb" });
+ }
+
+ public void testBuildTestMethods2() {
+ Object[] methods = _testMethodBuidler.buildTestMethods(Test2.class);
+ String[] names = toMethodNameArray(methods);
+ AssertUtil.assertArrayContent(names, new String[] { "test1", "test2", "testa", "testb" });
+ }
+
+ public void testBuildTestMethods3() {
+ Object[] methods = _testMethodBuidler.buildTestMethods(Test3.class);
+ String[] names = toMethodNameArray(methods);
+ AssertUtil.assertArray(names, new String[] { "test1", "test2", "testa", "testb" });
+ }
+
+ private String[] toMethodNameArray(Object[] methods) {
+ String[] names = new String [methods.length];
+ for(int i = 0; i < methods.length; ++i) {
+ names[i] = ((Method)methods[i]).getName();
+ }
+ return names;
+ }
+
+ private static class Test1 {
+ public void test1() {}
+ public void test2() {}
+ public void testa() {}
+ public void testb() {}
+ }
+
+ private static class Test2 {
+ public void test2() {}
+ public void test1() {}
+ public void testb() {}
+ public void testa() {}
+ }
+
+ private static class Test3 implements Alphabetical {
+ public void test2() {}
+ public void test1() {}
+ public void testb() {}
+ public void testa() {}
+ }
+}
Added: trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestSuiteBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestSuiteBuilderTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestSuiteBuilderTest.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,70 @@
+package tests.api.org.punit.builder;
+
+import junit.framework.*;
+
+import org.punit.builder.*;
+
+import tests.util.*;
+
+public class PUnitTestSuiteBuilderTest extends TestCase {
+ private PUnitTestSuiteBuilder _testSuiteBuidler;
+
+ protected void setUp() throws Exception {
+ _testSuiteBuidler = new PUnitTestSuiteBuilder();
+ }
+
+ public void testBuildTestClasses1() {
+ Object[] classes = _testSuiteBuidler.buildTestClasses(Test1.class);
+ AssertUtil.assertArray(classes, new Class[] { Test1.class });
+ }
+
+ public void testBuildTestClasses2() {
+ Object[] classes = _testSuiteBuidler.buildTestClasses(MorkTestSuite1.class);
+ AssertUtil.assertArray(classes, new Class[] { Test1.class,
+ Test2.class, Test3.class });
+ }
+
+ public void testBuildTestClasses3() {
+ Object[] classes = _testSuiteBuidler.buildTestClasses(MorkTestSuite2.class);
+ AssertUtil.assertArray(classes, new Class[] { Test4.class,
+ Test1.class, Test2.class, Test3.class, Test5.class });
+ }
+
+ private static class MorkTestSuite1 implements org.punit.type.TestSuite {
+ public Class[] suite() {
+ return new Class[] { Test1.class, Test2.class, Test3.class,
+
+ };
+ }
+ }
+
+ private static class MorkTestSuite2 implements org.punit.type.TestSuite {
+ public Class[] suite() {
+ return new Class[] { Test4.class, MorkTestSuite1.class,
+ Test5.class,
+
+ };
+ }
+ }
+
+ private static class Test1 {
+
+ }
+
+ private static class Test2 {
+
+ }
+
+ private static class Test3 {
+
+ }
+
+ private static class Test4 {
+
+ }
+
+ private static class Test5 {
+
+ }
+
+}
Modified: trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java 2007-05-09 22:29:40 UTC (rev 11)
+++ trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -1,78 +1,9 @@
package tests.api.org.punit.runner;
-import java.util.*;
-
import junit.framework.*;
-import org.punit.runner.*;
-
-import tests.util.*;
-
public class PUnitRunnerTest extends TestCase {
+ public void test() {
- private MockPUnitRunner _runner;
-
- protected void setUp() throws Exception {
- _runner = new MockPUnitRunner();
}
-
- public void testBuildTestClasses1() {
- List list = _runner.publicBuildTestClasses(Test1.class);
- AssertUtil.assertArray(list.toArray(), new Class[] { Test1.class });
- }
-
- public void testBuildTestClasses2() {
- List list = _runner.publicBuildTestClasses(MorkTestSuite1.class);
- AssertUtil.assertArray(list.toArray(), new Class[] { Test1.class,
- Test2.class, Test3.class });
- }
-
- public void testBuildTestClasses3() {
- List list = _runner.publicBuildTestClasses(MorkTestSuite2.class);
- AssertUtil.assertArray(list.toArray(), new Class[] { Test4.class,
- Test1.class, Test2.class, Test3.class, Test5.class });
- }
-
- private static class MockPUnitRunner extends PUnitRunner {
- public List publicBuildTestClasses(Class clazz) {
- return super.buildTestClasses(clazz);
- }
- }
-
- private static class MorkTestSuite1 implements org.punit.type.TestSuite {
- public Class[] suite() {
- return new Class[] { Test1.class, Test2.class, Test3.class,
-
- };
- }
- }
-
- private static class MorkTestSuite2 implements org.punit.type.TestSuite {
- public Class[] suite() {
- return new Class[] { Test4.class, MorkTestSuite1.class,
- Test5.class,
-
- };
- }
- }
-
- private static class Test1 {
-
- }
-
- private static class Test2 {
-
- }
-
- private static class Test3 {
-
- }
-
- private static class Test4 {
-
- }
-
- private static class Test5 {
-
- }
}
Added: trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,114 @@
+package tests.api.org.punit.util;
+
+import java.lang.reflect.*;
+
+import junit.framework.*;
+
+import org.punit.exception.*;
+import org.punit.util.*;
+
+import tests.util.*;
+
+public class ReflectionUtilTest extends TestCase {
+
+ public void testNewInstance() {
+ Object obj = ReflectionUtil.newInstance(Test1.class);
+ assertNotNull(obj);
+ assertSame(Test1.class, obj.getClass());
+ AssertUtil.assertException(ReflectionException.class, new CodeRunner() {
+ public void run() throws Throwable {
+ ReflectionUtil.newInstance(Test2.class);
+ }
+ });
+ }
+
+ public void testGetMethod() {
+ Method method = ReflectionUtil.getMethod(Test1.class, "test1",
+ new Class[] {});
+ assertNotNull(method);
+
+ method = ReflectionUtil.getMethod(Test1.class, "test2", new Class[] {});
+ assertNull(method);
+
+ method = ReflectionUtil.getMethod(Test1.class, "test3", new Class[] {});
+ assertNull(method);
+ }
+
+ public void testInvokeMethod() {
+ final Test1 obj = new Test1();
+ final Method method = ReflectionUtil.getMethod(Test1.class, "test1",
+ new Class[] {});
+
+ AssertUtil.assertException(ReflectionException.class, new CodeRunner() {
+ public void run() throws Throwable {
+ ReflectionUtil.invokeMethod(method, obj, new Object[] {});
+ }
+ });
+
+ method.setAccessible(true);
+ ReflectionUtil.invokeMethod(method, obj, new Object[] {});
+ assertEquals(10, obj.value);
+ }
+
+ public void testIsPublicMethod() {
+ Method[] methods = MockClass.class.getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ Method method = methods[i];
+ String name = method.getName();
+ if (name.indexOf("public") != -1) {
+ assertTrue(name, ReflectionUtil.isPublic(method));
+ } else {
+ assertFalse(name, ReflectionUtil.isPublic(method));
+ }
+ }
+ }
+
+ public void testIsStaticMethod() {
+ Method[] methods = MockClass.class.getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ Method method = methods[i];
+ if (method.getName().indexOf("static") != -1) {
+ assertTrue(ReflectionUtil.isStatic(method));
+ } else {
+ assertFalse(ReflectionUtil.isStatic(method));
+ }
+ }
+ }
+
+ private static class MockClass {
+ public void test1_public() {
+ }
+
+ void test2() {
+ }
+
+ private void test3() {
+ }
+
+ public static void test4_public_static() {
+ }
+
+ static void test5_static() {
+ }
+
+ private static void test6_static() {
+ }
+ }
+
+ private static class Test1 {
+ public int value = 0;
+
+ private void test1() {
+ value = 10;
+ }
+
+ private void test2(int i) {
+ value = i;
+ }
+ }
+
+ private static class Test2 {
+ Test2(int i) {
+ }
+ }
+}
Deleted: trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java 2007-05-09 22:29:40 UTC (rev 11)
+++ trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -1,28 +0,0 @@
-package tests.sample.testcase;
-
-import org.punit.runner.*;
-import org.punit.type.*;
-
-public class CompetitiveTestSample implements Competitive {
-
- public static void main(String[] args) {
- new PUnitRunner().run(CompetitiveTestSample.class);
- }
-
- public void test1() {
-
- }
-
- public void test2() {
-
- }
-
- public Class[] implmentators() {
- throw new UnsupportedOperationException();
- }
-
- public Class testInterface() {
- throw new UnsupportedOperationException();
- }
-
-}
Deleted: trunk/punit.test/src/tests/sample/testcase/PUnitTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/PUnitTestSample.java 2007-05-09 22:29:40 UTC (rev 11)
+++ trunk/punit.test/src/tests/sample/testcase/PUnitTestSample.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -1,28 +0,0 @@
-package tests.sample.testcase;
-
-import org.punit.runner.*;
-import org.punit.type.*;
-
-public class PUnitTestSample implements Test {
-
- public static void main(String[] args) {
- new PUnitRunner().run(PUnitTestSample.class);
- }
-
- public void test1() {
-
- }
-
- public void test2() {
-
- }
-
- public void setUpBeforeWatchers() {
- throw new UnsupportedOperationException();
- }
-
- public void tearDownAfterWatchers() {
- throw new UnsupportedOperationException();
- }
-
-}
Added: trunk/punit.test/src/tests/sample/testcase/VersionCompetitiveTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/VersionCompetitiveTestSample.java (rev 0)
+++ trunk/punit.test/src/tests/sample/testcase/VersionCompetitiveTestSample.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,24 @@
+package tests.sample.testcase;
+
+import org.punit.runner.*;
+import org.punit.type.*;
+
+public class VersionCompetitiveTestSample implements VersionCompetitive {
+
+ public static void main(String[] args) {
+ new PUnitRunner().run(VersionCompetitiveTestSample.class);
+ }
+
+ public void test1() {
+
+ }
+
+ public void test2() {
+
+ }
+
+ public Version[] versions() {
+ throw new UnsupportedOperationException();
+ }
+
+}
Modified: trunk/punit.test/src/tests/util/AssertUtil.java
===================================================================
--- trunk/punit.test/src/tests/util/AssertUtil.java 2007-05-09 22:29:40 UTC (rev 11)
+++ trunk/punit.test/src/tests/util/AssertUtil.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -5,8 +5,55 @@
import junit.framework.*;
public class AssertUtil {
-
+
public static void assertArray(Object[] array1, Object[] array2) {
Assert.assertTrue(Arrays.equals(array1, array2));
}
+
+ /**
+ * Asserts whether array1 has the same contents as array2. It doesn't ensure
+ * that the content are exactly the same if there are duplicate values in
+ * the array.
+ *
+ * @param array1
+ * @param array2
+ */
+ public static void assertArrayContent(Object[] array1, Object[] array2) {
+ Assert.assertEquals(array1.length, array2.length);
+ assertArrayContains(array1, array2);
+ assertArrayContains(array2, array1);
+ }
+
+ /**
+ * Asserts array1 contains array2
+ *
+ * @param array1
+ * @param array2
+ */
+ public static void assertArrayContains(Object[] array1, Object[] array2) {
+ for (int i = 0; i < array2.length; ++i) {
+ assertObjectInArray(array2[i], array1);
+ }
+ }
+
+ public static void assertObjectInArray(Object o, Object[] array) {
+ Assert.assertTrue(isInArray(o, array));
+ }
+
+ public static void assertException(Class throwable, CodeRunner code) {
+ try {
+ code.run();
+ Assert.fail(throwable + " expected!");
+ } catch (Throwable e) {
+ Assert.assertSame(throwable, e.getClass());
+ }
+ }
+ private static boolean isInArray(Object o, Object[] array) {
+ for (int i = 0; i < array.length; ++i) {
+ if (o.equals(array[i])) {
+ return true;
+ }
+ }
+ return false;
+ }
}
Added: trunk/punit.test/src/tests/util/CodeRunner.java
===================================================================
--- trunk/punit.test/src/tests/util/CodeRunner.java (rev 0)
+++ trunk/punit.test/src/tests/util/CodeRunner.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,5 @@
+package tests.util;
+
+public interface CodeRunner {
+ public void run() throws Throwable;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-09 22:29:41
|
Revision: 11
http://p-unit.svn.sourceforge.net/p-unit/?rev=11&view=rev
Author: zhanghuangzhu
Date: 2007-05-09 15:29:40 -0700 (Wed, 09 May 2007)
Log Message:
-----------
Andrew Zhang: implemented buildTestClasses in PUnitRunner.
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/PUnitRunner.java
trunk/punit.test/src/tests/api/org/punit/watcher/MemoryWatcherTest.java
trunk/punit.test/src/tests/api/org/punit/watcher/TimeWatcherTest.java
Added Paths:
-----------
trunk/punit/src/org/punit/exception/
trunk/punit/src/org/punit/exception/ReflectionException.java
trunk/punit/src/org/punit/util/ReflectionUtil.java
trunk/punit.test/src/tests/api/org/punit/all/
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/api/org/punit/runner/
trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java
trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java
trunk/punit.test/src/tests/util/
trunk/punit.test/src/tests/util/AssertUtil.java
Added: trunk/punit/src/org/punit/exception/ReflectionException.java
===================================================================
--- trunk/punit/src/org/punit/exception/ReflectionException.java (rev 0)
+++ trunk/punit/src/org/punit/exception/ReflectionException.java 2007-05-09 22:29:40 UTC (rev 11)
@@ -0,0 +1,10 @@
+package org.punit.exception;
+
+public class ReflectionException extends RuntimeException {
+
+ private static final long serialVersionUID = -5498831354775690972L;
+
+ public ReflectionException(Throwable e) {
+ super(e);
+ }
+}
Modified: trunk/punit/src/org/punit/runner/PUnitRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitRunner.java 2007-05-09 20:09:16 UTC (rev 10)
+++ trunk/punit/src/org/punit/runner/PUnitRunner.java 2007-05-09 22:29:40 UTC (rev 11)
@@ -1,11 +1,46 @@
package org.punit.runner;
+import java.util.*;
+
import org.punit.*;
+import org.punit.type.*;
+import org.punit.util.*;
public class PUnitRunner implements Runner {
public TestResult run(Class clazz) {
+ List testClasses = buildTestClasses(clazz);
throw new UnsupportedOperationException();
}
+ protected List buildTestClasses(Class clazz) {
+ List testClasses = new ArrayList();
+ buildTestClasses(testClasses, clazz);
+ return testClasses;
+ }
+
+ private void buildTestClasses(List testClasses, Class clazz) {
+ if(isTestSuite(clazz)) {
+ buildTestClassFromTestSuite(testClasses, clazz);
+ } else {
+ buildTestClassesFromClass(testClasses, clazz);
+ }
+ }
+
+ private void buildTestClassFromTestSuite(List testClasses, Class clazz) {
+ TestSuite testSuite = (TestSuite) ReflectionUtil.newInstance(clazz);
+ Class[] suite = testSuite.suite();
+ for(int i = 0; i < suite.length; ++i) {
+ buildTestClasses(testClasses, suite[i]);
+ }
+ }
+
+ private void buildTestClassesFromClass(List testClasses, Class clazz) {
+ testClasses.add(clazz);
+ }
+
+ private boolean isTestSuite(Class clazz) {
+ return TestSuite.class.isAssignableFrom(clazz);
+ }
+
}
Added: trunk/punit/src/org/punit/util/ReflectionUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/ReflectionUtil.java (rev 0)
+++ trunk/punit/src/org/punit/util/ReflectionUtil.java 2007-05-09 22:29:40 UTC (rev 11)
@@ -0,0 +1,17 @@
+package org.punit.util;
+
+import java.lang.reflect.*;
+
+import org.punit.exception.*;
+
+public class ReflectionUtil {
+ public static Object newInstance(Class clazz) {
+ try {
+ Constructor constructor = clazz.getDeclaredConstructor(new Class[] {});
+ constructor.setAccessible(true);
+ return constructor.newInstance();
+ } catch (Exception e) {
+ throw new ReflectionException(e);
+ }
+ }
+}
Added: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-09 22:29:40 UTC (rev 11)
@@ -0,0 +1,17 @@
+package tests.api.org.punit.all;
+
+import junit.framework.*;
+import tests.api.org.punit.runner.*;
+import tests.api.org.punit.watcher.*;
+
+public class AllTests {
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Test for tests.api.org.punit");
+ //$JUnit-BEGIN$
+ suite.addTestSuite(PUnitRunnerTest.class);
+ suite.addTestSuite(MemoryWatcherTest.class);
+ suite.addTestSuite(TimeWatcherTest.class);
+ //$JUnit-END$
+ return suite;
+ }
+}
Added: trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java 2007-05-09 22:29:40 UTC (rev 11)
@@ -0,0 +1,78 @@
+package tests.api.org.punit.runner;
+
+import java.util.*;
+
+import junit.framework.*;
+
+import org.punit.runner.*;
+
+import tests.util.*;
+
+public class PUnitRunnerTest extends TestCase {
+
+ private MockPUnitRunner _runner;
+
+ protected void setUp() throws Exception {
+ _runner = new MockPUnitRunner();
+ }
+
+ public void testBuildTestClasses1() {
+ List list = _runner.publicBuildTestClasses(Test1.class);
+ AssertUtil.assertArray(list.toArray(), new Class[] { Test1.class });
+ }
+
+ public void testBuildTestClasses2() {
+ List list = _runner.publicBuildTestClasses(MorkTestSuite1.class);
+ AssertUtil.assertArray(list.toArray(), new Class[] { Test1.class,
+ Test2.class, Test3.class });
+ }
+
+ public void testBuildTestClasses3() {
+ List list = _runner.publicBuildTestClasses(MorkTestSuite2.class);
+ AssertUtil.assertArray(list.toArray(), new Class[] { Test4.class,
+ Test1.class, Test2.class, Test3.class, Test5.class });
+ }
+
+ private static class MockPUnitRunner extends PUnitRunner {
+ public List publicBuildTestClasses(Class clazz) {
+ return super.buildTestClasses(clazz);
+ }
+ }
+
+ private static class MorkTestSuite1 implements org.punit.type.TestSuite {
+ public Class[] suite() {
+ return new Class[] { Test1.class, Test2.class, Test3.class,
+
+ };
+ }
+ }
+
+ private static class MorkTestSuite2 implements org.punit.type.TestSuite {
+ public Class[] suite() {
+ return new Class[] { Test4.class, MorkTestSuite1.class,
+ Test5.class,
+
+ };
+ }
+ }
+
+ private static class Test1 {
+
+ }
+
+ private static class Test2 {
+
+ }
+
+ private static class Test3 {
+
+ }
+
+ private static class Test4 {
+
+ }
+
+ private static class Test5 {
+
+ }
+}
Modified: trunk/punit.test/src/tests/api/org/punit/watcher/MemoryWatcherTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/watcher/MemoryWatcherTest.java 2007-05-09 20:09:16 UTC (rev 10)
+++ trunk/punit.test/src/tests/api/org/punit/watcher/MemoryWatcherTest.java 2007-05-09 22:29:40 UTC (rev 11)
@@ -5,14 +5,16 @@
import org.punit.watcher.*;
public class MemoryWatcherTest extends TestCase {
+
private MemoryWatcher _watcher;
+
+ private static final int MEMORY_CONSUMPTION = 1024*1024;
protected void setUp() throws Exception {
_watcher = new MemoryWatcher();
}
public void test() throws Exception {
- final int MEMORY_CONSUMPTION = 1024*1024*10;
_watcher.start();
byte[] data = new byte[MEMORY_CONSUMPTION];
for(int i = 0; i < data.length; ++i) {
Modified: trunk/punit.test/src/tests/api/org/punit/watcher/TimeWatcherTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/watcher/TimeWatcherTest.java 2007-05-09 20:09:16 UTC (rev 10)
+++ trunk/punit.test/src/tests/api/org/punit/watcher/TimeWatcherTest.java 2007-05-09 22:29:40 UTC (rev 11)
@@ -5,6 +5,7 @@
import org.punit.watcher.*;
public class TimeWatcherTest extends TestCase {
+ private static final int SLEEP_TIME = 500;
private TimeWatcher _watcher;
protected void setUp() throws Exception {
@@ -13,13 +14,13 @@
public void test() throws Exception {
_watcher.start();
- Thread.sleep(1000);
+ Thread.sleep(SLEEP_TIME);
_watcher.stop();
Long value = (Long) _watcher.value();
long timeElapsed = value.longValue();
// The following assertions are not safe in theory, but it works
// practically.
- assertTrue(timeElapsed < 1500);
- assertTrue(timeElapsed > 500);
+ assertTrue(timeElapsed < SLEEP_TIME * 1.2);
+ assertTrue(timeElapsed > SLEEP_TIME * 0.8);
}
}
Added: trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java (rev 0)
+++ trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java 2007-05-09 22:29:40 UTC (rev 11)
@@ -0,0 +1,9 @@
+package tests.sample.testcase;
+
+import org.punit.type.*;
+
+public class PUnitTestSuiteSample implements TestSuite {
+ public Class[] suite() {
+ throw new UnsupportedOperationException();
+ }
+}
Added: trunk/punit.test/src/tests/util/AssertUtil.java
===================================================================
--- trunk/punit.test/src/tests/util/AssertUtil.java (rev 0)
+++ trunk/punit.test/src/tests/util/AssertUtil.java 2007-05-09 22:29:40 UTC (rev 11)
@@ -0,0 +1,12 @@
+package tests.util;
+
+import java.util.*;
+
+import junit.framework.*;
+
+public class AssertUtil {
+
+ public static void assertArray(Object[] array1, Object[] array2) {
+ Assert.assertTrue(Arrays.equals(array1, array2));
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-09 20:09:14
|
Revision: 10
http://p-unit.svn.sourceforge.net/p-unit/?rev=10&view=rev
Author: zhanghuangzhu
Date: 2007-05-09 13:09:16 -0700 (Wed, 09 May 2007)
Log Message:
-----------
Andrew Zhang: defined TestSuite interface.
Added Paths:
-----------
trunk/punit/src/org/punit/type/TestSuite.java
Added: trunk/punit/src/org/punit/type/TestSuite.java
===================================================================
--- trunk/punit/src/org/punit/type/TestSuite.java (rev 0)
+++ trunk/punit/src/org/punit/type/TestSuite.java 2007-05-09 20:09:16 UTC (rev 10)
@@ -0,0 +1,5 @@
+package org.punit.type;
+
+public interface TestSuite {
+ public Class[] suite();
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-09 19:57:20
|
Revision: 9
http://p-unit.svn.sourceforge.net/p-unit/?rev=9&view=rev
Author: zhanghuangzhu
Date: 2007-05-09 12:57:21 -0700 (Wed, 09 May 2007)
Log Message:
-----------
Andrew Zhang: defined Test interface.
Added Paths:
-----------
trunk/punit/src/org/punit/type/Alphabetical.java
trunk/punit/src/org/punit/type/Test.java
trunk/punit.test/src/tests/sample/testcase/PUnitTestSample.java
Added: trunk/punit/src/org/punit/type/Alphabetical.java
===================================================================
--- trunk/punit/src/org/punit/type/Alphabetical.java (rev 0)
+++ trunk/punit/src/org/punit/type/Alphabetical.java 2007-05-09 19:57:21 UTC (rev 9)
@@ -0,0 +1,5 @@
+package org.punit.type;
+
+public interface Alphabetical {
+
+}
Added: trunk/punit/src/org/punit/type/Test.java
===================================================================
--- trunk/punit/src/org/punit/type/Test.java (rev 0)
+++ trunk/punit/src/org/punit/type/Test.java 2007-05-09 19:57:21 UTC (rev 9)
@@ -0,0 +1,9 @@
+package org.punit.type;
+
+public interface Test {
+
+ public void setUpBeforeWatchers();
+
+ public void tearDownAfterWatchers();
+
+}
Added: trunk/punit.test/src/tests/sample/testcase/PUnitTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/PUnitTestSample.java (rev 0)
+++ trunk/punit.test/src/tests/sample/testcase/PUnitTestSample.java 2007-05-09 19:57:21 UTC (rev 9)
@@ -0,0 +1,28 @@
+package tests.sample.testcase;
+
+import org.punit.runner.*;
+import org.punit.type.*;
+
+public class PUnitTestSample implements Test {
+
+ public static void main(String[] args) {
+ new PUnitRunner().run(PUnitTestSample.class);
+ }
+
+ public void test1() {
+
+ }
+
+ public void test2() {
+
+ }
+
+ public void setUpBeforeWatchers() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void tearDownAfterWatchers() {
+ throw new UnsupportedOperationException();
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-09 19:47:23
|
Revision: 8
http://p-unit.svn.sourceforge.net/p-unit/?rev=8&view=rev
Author: zhanghuangzhu
Date: 2007-05-09 12:47:22 -0700 (Wed, 09 May 2007)
Log Message:
-----------
Andrew Zhang: defined VMComparable interface
Added Paths:
-----------
trunk/punit/src/org/punit/type/VM.java
trunk/punit/src/org/punit/type/VMComparable.java
trunk/punit.test/src/tests/sample/testcase/VMTestSample.java
Added: trunk/punit/src/org/punit/type/VM.java
===================================================================
--- trunk/punit/src/org/punit/type/VM.java (rev 0)
+++ trunk/punit/src/org/punit/type/VM.java 2007-05-09 19:47:22 UTC (rev 8)
@@ -0,0 +1,21 @@
+package org.punit.type;
+
+public class VM {
+ private String _vmPath;
+
+ private String _vmName;
+
+ public VM(String path, String name) {
+ super();
+ _vmPath = path;
+ _vmName = name;
+ }
+
+ public String vmName() {
+ return _vmName;
+ }
+
+ public String vmPath() {
+ return _vmPath;
+ }
+}
Added: trunk/punit/src/org/punit/type/VMComparable.java
===================================================================
--- trunk/punit/src/org/punit/type/VMComparable.java (rev 0)
+++ trunk/punit/src/org/punit/type/VMComparable.java 2007-05-09 19:47:22 UTC (rev 8)
@@ -0,0 +1,5 @@
+package org.punit.type;
+
+public interface VMComparable {
+public VM[] vms();
+}
Added: trunk/punit.test/src/tests/sample/testcase/VMTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/VMTestSample.java (rev 0)
+++ trunk/punit.test/src/tests/sample/testcase/VMTestSample.java 2007-05-09 19:47:22 UTC (rev 8)
@@ -0,0 +1,32 @@
+package tests.sample.testcase;
+
+import org.punit.runner.*;
+import org.punit.type.*;
+
+public class VMTestSample implements VMComparable {
+
+ public static void main(String[] args) {
+ new PUnitRunner().run(VMTestSample.class);
+ }
+
+ public void test1() {
+
+ }
+
+ public void test2() {
+
+ }
+
+ public Class[] implmentators() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Class testInterface() {
+ throw new UnsupportedOperationException();
+ }
+
+ public VM[] vms() {
+ throw new UnsupportedOperationException();
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-09 06:49:48
|
Revision: 7
http://p-unit.svn.sourceforge.net/p-unit/?rev=7&view=rev
Author: zhanghuangzhu
Date: 2007-05-08 23:49:48 -0700 (Tue, 08 May 2007)
Log Message:
-----------
Andrew Zhang:
1. Defined Parameterizable interface, and move all interface to type package.
2. Defined TestResult as a sub interface of j.u.Collection.
Modified Paths:
--------------
trunk/punit/src/org/punit/TestResult.java
trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java
trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java
Added Paths:
-----------
trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
trunk/punit/src/org/punit/type/
trunk/punit/src/org/punit/type/Competitive.java
trunk/punit/src/org/punit/type/Concurrent.java
trunk/punit/src/org/punit/type/Parameter.java
trunk/punit/src/org/punit/type/Parameterizable.java
trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java
Removed Paths:
-------------
trunk/punit/src/org/punit/runner/Competitive.java
trunk/punit/src/org/punit/runner/Concurrent.java
Modified: trunk/punit/src/org/punit/TestResult.java
===================================================================
--- trunk/punit/src/org/punit/TestResult.java 2007-05-08 18:49:54 UTC (rev 6)
+++ trunk/punit/src/org/punit/TestResult.java 2007-05-09 06:49:48 UTC (rev 7)
@@ -1,5 +1,7 @@
package org.punit;
-public interface TestResult {
+import java.util.*;
+public interface TestResult extends Collection {
+
}
Deleted: trunk/punit/src/org/punit/runner/Competitive.java
===================================================================
--- trunk/punit/src/org/punit/runner/Competitive.java 2007-05-08 18:49:54 UTC (rev 6)
+++ trunk/punit/src/org/punit/runner/Competitive.java 2007-05-09 06:49:48 UTC (rev 7)
@@ -1,6 +0,0 @@
-package org.punit.runner;
-
-public interface Competitive {
- public Class testInterface();
- public Class[] implmentators();
-}
Deleted: trunk/punit/src/org/punit/runner/Concurrent.java
===================================================================
--- trunk/punit/src/org/punit/runner/Concurrent.java 2007-05-08 18:49:54 UTC (rev 6)
+++ trunk/punit/src/org/punit/runner/Concurrent.java 2007-05-09 06:49:48 UTC (rev 7)
@@ -1,5 +0,0 @@
-package org.punit.runner;
-
-public interface Concurrent {
- public int concurrentCount();
-}
Added: trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-09 06:49:48 UTC (rev 7)
@@ -0,0 +1,11 @@
+package org.punit.runner;
+
+import org.punit.*;
+
+public class PUnitConcurrentRunner implements Runner {
+
+ public TestResult run(Class clazz) {
+ throw new UnsupportedOperationException();
+ }
+
+}
Copied: trunk/punit/src/org/punit/type/Competitive.java (from rev 6, trunk/punit/src/org/punit/runner/Competitive.java)
===================================================================
--- trunk/punit/src/org/punit/type/Competitive.java (rev 0)
+++ trunk/punit/src/org/punit/type/Competitive.java 2007-05-09 06:49:48 UTC (rev 7)
@@ -0,0 +1,6 @@
+package org.punit.type;
+
+public interface Competitive {
+ public Class testInterface();
+ public Class[] implmentators();
+}
Copied: trunk/punit/src/org/punit/type/Concurrent.java (from rev 6, trunk/punit/src/org/punit/runner/Concurrent.java)
===================================================================
--- trunk/punit/src/org/punit/type/Concurrent.java (rev 0)
+++ trunk/punit/src/org/punit/type/Concurrent.java 2007-05-09 06:49:48 UTC (rev 7)
@@ -0,0 +1,5 @@
+package org.punit.type;
+
+public interface Concurrent {
+ public int concurrentCount();
+}
Added: trunk/punit/src/org/punit/type/Parameter.java
===================================================================
--- trunk/punit/src/org/punit/type/Parameter.java (rev 0)
+++ trunk/punit/src/org/punit/type/Parameter.java 2007-05-09 06:49:48 UTC (rev 7)
@@ -0,0 +1,5 @@
+package org.punit.type;
+
+public interface Parameter {
+
+}
Added: trunk/punit/src/org/punit/type/Parameterizable.java
===================================================================
--- trunk/punit/src/org/punit/type/Parameterizable.java (rev 0)
+++ trunk/punit/src/org/punit/type/Parameterizable.java 2007-05-09 06:49:48 UTC (rev 7)
@@ -0,0 +1,5 @@
+package org.punit.type;
+
+public interface Parameterizable {
+ Parameter [] paramters();
+}
Modified: trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java 2007-05-08 18:49:54 UTC (rev 6)
+++ trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java 2007-05-09 06:49:48 UTC (rev 7)
@@ -1,6 +1,7 @@
package tests.sample.testcase;
import org.punit.runner.*;
+import org.punit.type.*;
public class CompetitiveTestSample implements Competitive {
Modified: trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java 2007-05-08 18:49:54 UTC (rev 6)
+++ trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java 2007-05-09 06:49:48 UTC (rev 7)
@@ -1,6 +1,7 @@
package tests.sample.testcase;
import org.punit.runner.*;
+import org.punit.type.*;
public class ConcurrentTestSample implements Concurrent {
Added: trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java (rev 0)
+++ trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java 2007-05-09 06:49:48 UTC (rev 7)
@@ -0,0 +1,32 @@
+package tests.sample.testcase;
+
+import org.punit.runner.*;
+import org.punit.type.*;
+
+public class ParameterizableTestSample implements Parameterizable {
+
+ public static void main(String[] args) {
+ new PUnitRunner().run(ParameterizableTestSample.class);
+ }
+
+ public void test1() {
+
+ }
+
+ public void test2() {
+
+ }
+
+ public Class[] implmentators() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Class testInterface() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Parameter[] paramters() {
+ throw new UnsupportedOperationException();
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-08 18:49:52
|
Revision: 6
http://p-unit.svn.sourceforge.net/p-unit/?rev=6&view=rev
Author: zhanghuangzhu
Date: 2007-05-08 11:49:54 -0700 (Tue, 08 May 2007)
Log Message:
-----------
Andrew Zhang: Stubs for implementation and test code.
Added Paths:
-----------
trunk/punit/src/org/punit/TestResult.java
trunk/punit/src/org/punit/runner/
trunk/punit/src/org/punit/runner/Competitive.java
trunk/punit/src/org/punit/runner/Concurrent.java
trunk/punit/src/org/punit/runner/PUnitRunner.java
trunk/punit/src/org/punit/runner/Runner.java
trunk/punit.test/src/tests/sample/
trunk/punit.test/src/tests/sample/testcase/
trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java
trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java
trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java
trunk/punit.test/src/tests/sample/testcase/SimpleTestSample.java
Added: trunk/punit/src/org/punit/TestResult.java
===================================================================
--- trunk/punit/src/org/punit/TestResult.java (rev 0)
+++ trunk/punit/src/org/punit/TestResult.java 2007-05-08 18:49:54 UTC (rev 6)
@@ -0,0 +1,5 @@
+package org.punit;
+
+public interface TestResult {
+
+}
Added: trunk/punit/src/org/punit/runner/Competitive.java
===================================================================
--- trunk/punit/src/org/punit/runner/Competitive.java (rev 0)
+++ trunk/punit/src/org/punit/runner/Competitive.java 2007-05-08 18:49:54 UTC (rev 6)
@@ -0,0 +1,6 @@
+package org.punit.runner;
+
+public interface Competitive {
+ public Class testInterface();
+ public Class[] implmentators();
+}
Added: trunk/punit/src/org/punit/runner/Concurrent.java
===================================================================
--- trunk/punit/src/org/punit/runner/Concurrent.java (rev 0)
+++ trunk/punit/src/org/punit/runner/Concurrent.java 2007-05-08 18:49:54 UTC (rev 6)
@@ -0,0 +1,5 @@
+package org.punit.runner;
+
+public interface Concurrent {
+ public int concurrentCount();
+}
Added: trunk/punit/src/org/punit/runner/PUnitRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/PUnitRunner.java 2007-05-08 18:49:54 UTC (rev 6)
@@ -0,0 +1,11 @@
+package org.punit.runner;
+
+import org.punit.*;
+
+public class PUnitRunner implements Runner {
+
+ public TestResult run(Class clazz) {
+ throw new UnsupportedOperationException();
+ }
+
+}
Added: trunk/punit/src/org/punit/runner/Runner.java
===================================================================
--- trunk/punit/src/org/punit/runner/Runner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/Runner.java 2007-05-08 18:49:54 UTC (rev 6)
@@ -0,0 +1,7 @@
+package org.punit.runner;
+
+import org.punit.*;
+
+public interface Runner {
+ public TestResult run(Class clazz);
+}
Added: trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java (rev 0)
+++ trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java 2007-05-08 18:49:54 UTC (rev 6)
@@ -0,0 +1,27 @@
+package tests.sample.testcase;
+
+import org.punit.runner.*;
+
+public class CompetitiveTestSample implements Competitive {
+
+ public static void main(String[] args) {
+ new PUnitRunner().run(CompetitiveTestSample.class);
+ }
+
+ public void test1() {
+
+ }
+
+ public void test2() {
+
+ }
+
+ public Class[] implmentators() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Class testInterface() {
+ throw new UnsupportedOperationException();
+ }
+
+}
Added: trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java (rev 0)
+++ trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java 2007-05-08 18:49:54 UTC (rev 6)
@@ -0,0 +1,23 @@
+package tests.sample.testcase;
+
+import org.punit.runner.*;
+
+public class ConcurrentTestSample implements Concurrent {
+
+ public static void main(String[] args) {
+ new PUnitRunner().run(ConcurrentTestSample.class);
+ }
+
+ public void test1() {
+
+ }
+
+ public void test2() {
+
+ }
+
+ public int concurrentCount() {
+ return 10;
+ }
+
+}
Added: trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java (rev 0)
+++ trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java 2007-05-08 18:49:54 UTC (rev 6)
@@ -0,0 +1,21 @@
+package tests.sample.testcase;
+
+import junit.framework.*;
+
+import org.punit.runner.*;
+
+public class JUnitTestSample extends TestCase {
+
+ public static void main(String[] args) {
+ new PUnitRunner().run(JUnitTestSample.class);
+ }
+
+ public void test1() {
+
+ }
+
+ public void test2() {
+
+ }
+
+}
Added: trunk/punit.test/src/tests/sample/testcase/SimpleTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/SimpleTestSample.java (rev 0)
+++ trunk/punit.test/src/tests/sample/testcase/SimpleTestSample.java 2007-05-08 18:49:54 UTC (rev 6)
@@ -0,0 +1,19 @@
+package tests.sample.testcase;
+
+import org.punit.runner.*;
+
+public class SimpleTestSample {
+
+ public static void main(String[] args) {
+ new PUnitRunner().run(SimpleTestSample.class);
+ }
+
+ public void test1() {
+
+ }
+
+ public void test2() {
+
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-08 00:25:33
|
Revision: 5
http://p-unit.svn.sourceforge.net/p-unit/?rev=5&view=rev
Author: zhanghuangzhu
Date: 2007-05-07 17:25:32 -0700 (Mon, 07 May 2007)
Log Message:
-----------
Andrew Zhang: Watcher/Util classes and test cases.
Modified Paths:
--------------
trunk/punit.test/.classpath
Added Paths:
-----------
trunk/punit/Copyright.txt
trunk/punit/punit.license.txt
trunk/punit/src/org/
trunk/punit/src/org/punit/
trunk/punit/src/org/punit/util/
trunk/punit/src/org/punit/util/MemoryUtil.java
trunk/punit/src/org/punit/util/ThreadUtil.java
trunk/punit/src/org/punit/watcher/
trunk/punit/src/org/punit/watcher/MemoryWatcher.java
trunk/punit/src/org/punit/watcher/TimeWatcher.java
trunk/punit/src/org/punit/watcher/Watcher.java
trunk/punit.test/Copyright.txt
trunk/punit.test/punit.license.txt
trunk/punit.test/src/tests/
trunk/punit.test/src/tests/api/
trunk/punit.test/src/tests/api/org/
trunk/punit.test/src/tests/api/org/punit/
trunk/punit.test/src/tests/api/org/punit/watcher/
trunk/punit.test/src/tests/api/org/punit/watcher/MemoryWatcherTest.java
trunk/punit.test/src/tests/api/org/punit/watcher/TimeWatcherTest.java
Added: trunk/punit/Copyright.txt
===================================================================
--- trunk/punit/Copyright.txt (rev 0)
+++ trunk/punit/Copyright.txt 2007-05-08 00:25:32 UTC (rev 5)
@@ -0,0 +1,5 @@
+Copyright (C) 2007 reserved
+
+Author: Andrew Zhang
+
+Mail: zha...@gm...
\ No newline at end of file
Added: trunk/punit/punit.license.txt
===================================================================
--- trunk/punit/punit.license.txt (rev 0)
+++ trunk/punit/punit.license.txt 2007-05-08 00:25:32 UTC (rev 5)
@@ -0,0 +1,341 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
+
Added: trunk/punit/src/org/punit/util/MemoryUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/MemoryUtil.java (rev 0)
+++ trunk/punit/src/org/punit/util/MemoryUtil.java 2007-05-08 00:25:32 UTC (rev 5)
@@ -0,0 +1,15 @@
+package org.punit.util;
+
+public class MemoryUtil {
+
+ private static Runtime _runtime = Runtime.getRuntime();
+
+ public static long usedMemory() {
+ return _runtime.totalMemory() - _runtime.freeMemory();
+ }
+
+ public static void clear() {
+ System.gc();
+ System.runFinalization();
+ }
+}
Added: trunk/punit/src/org/punit/util/ThreadUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/ThreadUtil.java (rev 0)
+++ trunk/punit/src/org/punit/util/ThreadUtil.java 2007-05-08 00:25:32 UTC (rev 5)
@@ -0,0 +1,11 @@
+package org.punit.util;
+
+public class ThreadUtil {
+ public static void sleepIgnoreInterruption(long millis) {
+ try {
+ Thread.sleep(millis);
+ } catch (InterruptedException e) {
+
+ }
+ }
+}
Added: trunk/punit/src/org/punit/watcher/MemoryWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/MemoryWatcher.java (rev 0)
+++ trunk/punit/src/org/punit/watcher/MemoryWatcher.java 2007-05-08 00:25:32 UTC (rev 5)
@@ -0,0 +1,43 @@
+package org.punit.watcher;
+
+import org.punit.util.*;
+
+public class MemoryWatcher implements Watcher {
+
+ private long _startUsedMemory;
+
+ private long _maxUsedMemory;
+
+ private boolean _stop;
+
+ public void start() {
+ _stop = false;
+ MemoryUtil.clear();
+ _maxUsedMemory = _startUsedMemory = MemoryUtil.usedMemory();
+ new MemoryWatcherThread().start();
+ }
+
+ public void stop() {
+ _stop = true;
+ monitorMemory();
+ }
+
+ public Object value() {
+ return _maxUsedMemory - _startUsedMemory ;
+ }
+
+ private void monitorMemory() {
+ long usedMemory = MemoryUtil.usedMemory();
+ if(usedMemory > _maxUsedMemory) {
+ _maxUsedMemory = usedMemory;
+ }
+ }
+ private class MemoryWatcherThread extends Thread {
+ public void run() {
+ while(!_stop) {
+ monitorMemory();
+ ThreadUtil.sleepIgnoreInterruption(10);
+ }
+ }
+ }
+}
Added: trunk/punit/src/org/punit/watcher/TimeWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/TimeWatcher.java (rev 0)
+++ trunk/punit/src/org/punit/watcher/TimeWatcher.java 2007-05-08 00:25:32 UTC (rev 5)
@@ -0,0 +1,39 @@
+/*
+This file is part of the PolePosition database benchmark
+http://www.polepos.org
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with this program; if not, write to the Free
+Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+package org.punit.watcher;
+
+public class TimeWatcher implements Watcher {
+
+ private long _startTime;
+
+ private long _endTime;
+
+ public void start() {
+ _startTime = System.nanoTime();
+ }
+
+ public void stop() {
+ _endTime = System.nanoTime();
+ }
+
+ public Object value() {
+ return (_endTime - _startTime)/1000000;
+ }
+}
Added: trunk/punit/src/org/punit/watcher/Watcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/Watcher.java (rev 0)
+++ trunk/punit/src/org/punit/watcher/Watcher.java 2007-05-08 00:25:32 UTC (rev 5)
@@ -0,0 +1,11 @@
+package org.punit.watcher;
+
+public interface Watcher {
+
+ public void start();
+
+ public void stop();
+
+ public Object value();
+
+}
Modified: trunk/punit.test/.classpath
===================================================================
--- trunk/punit.test/.classpath 2007-05-07 22:23:07 UTC (rev 4)
+++ trunk/punit.test/.classpath 2007-05-08 00:25:32 UTC (rev 5)
@@ -3,5 +3,6 @@
<classpathentry path="src" kind="src"/>
<classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER" kind="con"/>
<classpathentry path="/punit" combineaccessrules="false" kind="src"/>
+ <classpathentry path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3.8.1" kind="con"/>
<classpathentry path="bin" kind="output"/>
</classpath>
Added: trunk/punit.test/Copyright.txt
===================================================================
--- trunk/punit.test/Copyright.txt (rev 0)
+++ trunk/punit.test/Copyright.txt 2007-05-08 00:25:32 UTC (rev 5)
@@ -0,0 +1,5 @@
+Copyright (C) 2007 reserved
+
+Author: Andrew Zhang
+
+Mail: zha...@gm...
\ No newline at end of file
Added: trunk/punit.test/punit.license.txt
===================================================================
--- trunk/punit.test/punit.license.txt (rev 0)
+++ trunk/punit.test/punit.license.txt 2007-05-08 00:25:32 UTC (rev 5)
@@ -0,0 +1,341 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
+
Added: trunk/punit.test/src/tests/api/org/punit/watcher/MemoryWatcherTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/watcher/MemoryWatcherTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/watcher/MemoryWatcherTest.java 2007-05-08 00:25:32 UTC (rev 5)
@@ -0,0 +1,29 @@
+package tests.api.org.punit.watcher;
+
+import junit.framework.*;
+
+import org.punit.watcher.*;
+
+public class MemoryWatcherTest extends TestCase {
+ private MemoryWatcher _watcher;
+
+ protected void setUp() throws Exception {
+ _watcher = new MemoryWatcher();
+ }
+
+ public void test() throws Exception {
+ final int MEMORY_CONSUMPTION = 1024*1024*10;
+ _watcher.start();
+ byte[] data = new byte[MEMORY_CONSUMPTION];
+ for(int i = 0; i < data.length; ++i) {
+ data[i] = 42;
+ }
+ _watcher.stop();
+ Long value = (Long) _watcher.value();
+ long memoryConsumed = value.longValue();
+ // The following assertions are not safe in theory, but it works
+ // practically.
+ assertTrue(memoryConsumed < data.length * 1.5);
+ assertTrue(memoryConsumed > data.length/2);
+ }
+}
Added: trunk/punit.test/src/tests/api/org/punit/watcher/TimeWatcherTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/watcher/TimeWatcherTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/watcher/TimeWatcherTest.java 2007-05-08 00:25:32 UTC (rev 5)
@@ -0,0 +1,25 @@
+package tests.api.org.punit.watcher;
+
+import junit.framework.*;
+
+import org.punit.watcher.*;
+
+public class TimeWatcherTest extends TestCase {
+ private TimeWatcher _watcher;
+
+ protected void setUp() throws Exception {
+ _watcher = new TimeWatcher();
+ }
+
+ public void test() throws Exception {
+ _watcher.start();
+ Thread.sleep(1000);
+ _watcher.stop();
+ Long value = (Long) _watcher.value();
+ long timeElapsed = value.longValue();
+ // The following assertions are not safe in theory, but it works
+ // practically.
+ assertTrue(timeElapsed < 1500);
+ assertTrue(timeElapsed > 500);
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|