Whipped unit tests into shape. Added simple test for dobject transactions.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@978 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-02-09 07:50:04 +00:00
parent c57ff60e69
commit a1162ae85a
11 changed files with 79 additions and 93 deletions
@@ -1,5 +1,5 @@
//
// $Id: BundledComponentRepositoryTest.java,v 1.5 2002/01/16 03:01:24 mdb Exp $
// $Id: BundledComponentRepositoryTest.java,v 1.6 2002/02/09 07:50:04 mdb Exp $
package com.threerings.cast.bundle;
@@ -28,21 +28,21 @@ public class BundledComponentRepositoryTest extends TestCase
BundledComponentRepository repo =
new BundledComponentRepository(rmgr, imgr, "components");
System.out.println("Classes: " + StringUtil.toString(
repo.enumerateComponentClasses()));
// System.out.println("Classes: " + StringUtil.toString(
// repo.enumerateComponentClasses()));
System.out.println("Actions: " + StringUtil.toString(
repo.enumerateActionSequences()));
// System.out.println("Actions: " + StringUtil.toString(
// repo.enumerateActionSequences()));
System.out.println("Action sets: " + StringUtil.toString(
repo._actionSets.values().iterator()));
// System.out.println("Action sets: " + StringUtil.toString(
// repo._actionSets.values().iterator()));
Iterator iter = repo.enumerateComponentClasses();
while (iter.hasNext()) {
ComponentClass cclass = (ComponentClass)iter.next();
System.out.println("IDs [" + cclass + "]: " +
StringUtil.toString(
repo.enumerateComponentIds(cclass)));
// System.out.println("IDs [" + cclass + "]: " +
// StringUtil.toString(
// repo.enumerateComponentIds(cclass)));
}
} catch (Exception e) {
@@ -1,5 +1,5 @@
//
// $Id: BundledTileSetRepositoryTest.java,v 1.5 2002/01/16 03:01:24 mdb Exp $
// $Id: BundledTileSetRepositoryTest.java,v 1.6 2002/02/09 07:50:04 mdb Exp $
package com.threerings.media.tile.bundle;
@@ -27,7 +27,8 @@ public class BundledTileSetRepositoryTest extends TestCase
new BundledTileSetRepository(rmgr, imgr, "tilesets");
Iterator sets = repo.enumerateTileSets();
while (sets.hasNext()) {
System.out.println(sets.next());
sets.next();
// System.out.println(sets.next());
}
} catch (Exception e) {
@@ -1,5 +1,5 @@
//
// $Id: XMLTileSetParserTest.java,v 1.3 2002/02/05 20:29:09 mdb Exp $
// $Id: XMLTileSetParserTest.java,v 1.4 2002/02/09 07:50:04 mdb Exp $
package com.threerings.media.tile.tools.xml;
@@ -34,7 +34,8 @@ public class XMLTileSetParserTest extends TestCase
// print them out
Iterator iter = sets.values().iterator();
while (iter.hasNext()) {
System.out.println(iter.next());
iter.next();
// System.out.println(iter.next());
}
} catch (IOException ioe) {
@@ -1,5 +1,5 @@
//
// $Id: DOMTest.java,v 1.6 2001/11/08 05:40:07 mdb Exp $
// $Id: DOMTest.java,v 1.7 2002/02/09 07:50:04 mdb Exp $
package com.threerings.presents.server;
@@ -12,8 +12,7 @@ import com.threerings.presents.dobj.*;
/**
* A simple test case for the dobjmgr.
*/
public class DOMTest
extends TestCase
public class DOMTest extends TestCase
implements Subscriber, AttributeChangeListener
{
public DOMTest ()
@@ -26,8 +25,15 @@ public class DOMTest
// add ourselves as a listener
object.addListener(this);
// set some values
TestObject to = (TestObject)object;
// test transactions
to.startTransaction();
to.setFoo(99);
to.setBar("hoopie");
to.commitTransaction();
// now set some values straight up
to.setFoo(25);
to.setBar("howdy");
}
@@ -35,37 +41,53 @@ public class DOMTest
public void requestFailed (int oid, ObjectAccessException cause)
{
fail("Request failed: " + cause);
omgr.shutdown();
_omgr.shutdown();
}
public void attributeChanged (AttributeChangedEvent event)
{
// if this is the second event, request a shutdown
if (event.getName().equals(TestObject.FOO)) {
assert("foo=25", event.getIntValue() == 25);
assert(fields[_fcount] + " == " + values[_fcount],
event.getName().equals(fields[_fcount]) &&
event.getValue().equals(values[_fcount]));
} else if (event.getName().equals(TestObject.BAR)) {
assert("bar=howdy", "howdy".equals(event.getValue()));
omgr.shutdown();
// shutdown once we receive our last update
if (++_fcount == fields.length) {
_omgr.shutdown();
}
}
public void runTest ()
{
// request that a new TestObject be created
omgr.createObject(TestObject.class, this);
_omgr.createObject(TestObject.class, this);
// or for fun you can try this bogus create request
// omgr.createObject(Integer.class, sub);
// _omgr.createObject(Integer.class, sub);
// and run the object manager
omgr.run();
_omgr.run();
}
public static Test suite ()
{
return new RefTest();
return new DOMTest();
}
public static PresentsDObjectMgr omgr = new PresentsDObjectMgr();
public static void main (String[] args)
{
DOMTest test = new DOMTest();
test.runTest();
}
protected int _fcount = 0;
// the fields that will change in attribute changed events
protected Object[] fields = {
TestObject.FOO, TestObject.BAR, TestObject.FOO, TestObject.BAR };
// the values we'll receive via attribute changed events
protected Object[] values = {
new Integer(99), "hoopie", new Integer(25), "howdy" };
protected static PresentsDObjectMgr _omgr = new PresentsDObjectMgr();
}
@@ -1,5 +1,5 @@
//
// $Id: DestroyedRefTest.java,v 1.6 2001/11/08 05:40:07 mdb Exp $
// $Id: DestroyedRefTest.java,v 1.7 2002/02/09 07:50:04 mdb Exp $
package com.threerings.presents.server;
@@ -71,7 +71,7 @@ public class DestroyedRefTest
} else if (event instanceof AttributeChangedEvent) {
// go bye bye
PresentsServer.shutdown();
_omgr.shutdown();
} else {
fail("Got unexpected event: " + event);
@@ -80,23 +80,12 @@ public class DestroyedRefTest
public void runTest ()
{
PresentsServer server = new TestPresentsServer();
try {
// initialize the server
server.init();
// create two test objects
_omgr.createObject(TestObject.class, this);
_omgr.createObject(TestObject.class, this);
// create two test objects
PresentsServer.omgr.createObject(TestObject.class, this);
PresentsServer.omgr.createObject(TestObject.class, this);
// start the server to running (this method call won't return
// until the server is shut down)
server.run();
} catch (Exception e) {
Log.warning("Unable to initialize server.");
Log.logStackTrace(e);
}
// and run the object manager
_omgr.run();
}
public static Test suite ()
@@ -106,4 +95,6 @@ public class DestroyedRefTest
protected TestObject _objone;
protected TestObject _objtwo;
protected static PresentsDObjectMgr _omgr = new PresentsDObjectMgr();
}
@@ -1,5 +1,5 @@
//
// $Id: RefTest.java,v 1.6 2001/11/08 05:40:07 mdb Exp $
// $Id: RefTest.java,v 1.7 2002/02/09 07:50:04 mdb Exp $
package com.threerings.presents.server;
@@ -63,7 +63,7 @@ public class RefTest
} else {
// Log.info("Other object destroyed.");
// go bye bye
PresentsServer.shutdown();
_omgr.shutdown();
}
} else if (event instanceof ObjectRemovedEvent) {
@@ -76,23 +76,12 @@ public class RefTest
public void runTest ()
{
PresentsServer server = new TestPresentsServer();
try {
// initialize the server
server.init();
// create two test objects
_omgr.createObject(TestObject.class, this);
_omgr.createObject(TestObject.class, this);
// create two test objects
PresentsServer.omgr.createObject(TestObject.class, this);
PresentsServer.omgr.createObject(TestObject.class, this);
// start the server to running (this method call won't return
// until the server is shut down)
server.run();
} catch (Exception e) {
Log.warning("Unable to initialize server.");
Log.logStackTrace(e);
}
// and run the object manager
_omgr.run();
}
public static Test suite ()
@@ -102,4 +91,6 @@ public class RefTest
protected TestObject _objone;
protected TestObject _objtwo;
protected static PresentsDObjectMgr _omgr = new PresentsDObjectMgr();
}
@@ -1,17 +0,0 @@
//
// $Id: TestPresentsServer.java,v 1.1 2001/11/08 05:40:07 mdb Exp $
package com.threerings.presents.server;
/**
* This test version of the server avoids creating a connection manager
* because that requires a shared library which we don't have available
* when testing via ant/JUnit.
*/
public class TestPresentsServer extends PresentsServer
{
protected boolean createConnectionManager ()
{
return false;
}
}
@@ -1,5 +1,5 @@
//
// $Id: SpotSceneParserTest.java,v 1.2 2001/12/13 01:35:52 mdb Exp $
// $Id: SpotSceneParserTest.java,v 1.3 2002/02/09 07:50:04 mdb Exp $
package com.threerings.whirled.tools.spot.xml;
@@ -23,7 +23,7 @@ public class SpotSceneParserTest extends TestCase
SpotSceneParser parser = new SpotSceneParser("scene");
String tspath = TestUtil.getResourcePath(TEST_SCENE_PATH);
EditableSpotScene scene = parser.parseScene(tspath);
System.out.println("Parsed " + scene.getSpotSceneModel() + ".");
// System.out.println("Parsed " + scene.getSpotSceneModel() + ".");
} catch (Exception e) {
e.printStackTrace();
@@ -1,5 +1,5 @@
//
// $Id: SceneParserTest.java,v 1.2 2001/12/13 01:35:52 mdb Exp $
// $Id: SceneParserTest.java,v 1.3 2002/02/09 07:50:04 mdb Exp $
package com.threerings.whirled.tools.xml;
@@ -23,7 +23,7 @@ public class SceneParserTest extends TestCase
SceneParser parser = new SceneParser("scene");
String tspath = TestUtil.getResourcePath(TEST_SCENE_PATH);
EditableScene scene = parser.parseScene(tspath);
System.out.println("Parsed " + scene.getSceneModel() + ".");
// System.out.println("Parsed " + scene.getSceneModel() + ".");
} catch (Exception e) {
e.printStackTrace();