From cd9135171a367401f91908e9d60b525bde7175d3 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sat, 9 Jun 2001 23:39:42 +0000 Subject: [PATCH] Some testing code. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@31 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/presents/server/DOMTest.java | 59 +++++++++++++++++++ .../presents/server/TestObject.dobj | 44 ++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 tests/src/java/com/threerings/presents/server/DOMTest.java create mode 100644 tests/src/java/com/threerings/presents/server/TestObject.dobj diff --git a/tests/src/java/com/threerings/presents/server/DOMTest.java b/tests/src/java/com/threerings/presents/server/DOMTest.java new file mode 100644 index 000000000..9bbac6f9b --- /dev/null +++ b/tests/src/java/com/threerings/presents/server/DOMTest.java @@ -0,0 +1,59 @@ +// +// $Id: DOMTest.java,v 1.1 2001/06/09 23:39:42 mdb Exp $ + +package com.threerings.cocktail.cher.server.test; + +import com.threerings.cocktail.cher.Log; +import com.threerings.cocktail.cher.dobj.*; +import com.threerings.cocktail.cher.server.*; + +/** + * A simple test case for the dobjmgr. + */ +public class DOMTest implements Subscriber +{ + public void objectAvailable (DObject object) + { + Log.info("Object available: " + object); + // set some values + TestObject to = (TestObject)object; + to.setFoo(25); + to.setBar("howdy"); + } + + public void requestFailed (int oid, ObjectAccessException cause) + { + Log.info("Request failed: " + cause); + omgr.shutdown(); + } + + public boolean handleEvent (DEvent event, DObject target) + { + Log.info("Got event [event=" + event + ", target=" + target + "]."); + + // if this is the second event, request a shutdown + AttributeChangedEvent ace = (AttributeChangedEvent)event; + if (ace.getName().equals(TestObject.BAR)) { + omgr.shutdown(); + } + + return true; + } + + public static CherDObjectMgr omgr = new CherDObjectMgr(); + + public static void main (String[] args) + { + // create our subscriber who will do things + DOMTest sub = new DOMTest(); + + // request that a new TestObject be created + omgr.createObject(TestObject.class, sub, true); + + // or for fun you can try this bogus create request + // omgr.createObject(Integer.class, sub, true); + + // and run the object manager + omgr.run(); + } +} diff --git a/tests/src/java/com/threerings/presents/server/TestObject.dobj b/tests/src/java/com/threerings/presents/server/TestObject.dobj new file mode 100644 index 000000000..03c41618d --- /dev/null +++ b/tests/src/java/com/threerings/presents/server/TestObject.dobj @@ -0,0 +1,44 @@ +// +// $Id: TestObject.dobj,v 1.1 2001/06/09 23:39:42 mdb Exp $ + +package com.threerings.cocktail.cher.server.test; + +import com.threerings.cocktail.cher.dobj.*; + +/** + * I use this to test until I get the actual DObject generation script + * working. + */ +public class TestObject extends DObject +{ + public static final String FOO = "foo"; + + public int foo; + + public static final String BAR = "bar"; + + public String bar; + + public void setFoo (int foo) + { + // generate an attribute changed event + AttributeChangedEvent event = new AttributeChangedEvent( + _oid, FOO, new Integer(foo)); + // and dispatch it to our dobjmgr + _mgr.postEvent(event); + } + + public void setBar (String bar) + { + // generate an attribute changed event + AttributeChangedEvent event = new AttributeChangedEvent( + _oid, BAR, bar); + // and dispatch it to our dobjmgr + _mgr.postEvent(event); + } + + public String toString () + { + return "[foo=" + foo + ", bar=" + bar + "]"; + } +}