Brought the tests back into the land of compilability.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3355 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: TestClient.java,v 1.17 2004/08/27 02:21:05 mdb Exp $
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
|
||||
@@ -21,17 +21,13 @@
|
||||
|
||||
package com.threerings.whirled;
|
||||
|
||||
import com.samskivert.util.Config;
|
||||
import com.samskivert.util.Queue;
|
||||
|
||||
import com.threerings.presents.client.*;
|
||||
import com.threerings.presents.dobj.DObjectManager;
|
||||
import com.threerings.presents.net.*;
|
||||
import com.threerings.presents.client.Client;
|
||||
|
||||
import com.threerings.crowd.Log;
|
||||
import com.threerings.crowd.client.*;
|
||||
import com.threerings.crowd.data.PlaceConfig;
|
||||
import com.threerings.crowd.data.PlaceObject;
|
||||
import com.threerings.crowd.util.CrowdContext;
|
||||
|
||||
import com.threerings.whirled.client.SceneDirector;
|
||||
import com.threerings.whirled.client.persist.SceneRepository;
|
||||
@@ -41,19 +37,15 @@ import com.threerings.whirled.data.SceneModel;
|
||||
import com.threerings.whirled.util.SceneFactory;
|
||||
import com.threerings.whirled.util.WhirledContext;
|
||||
|
||||
public class TestClient
|
||||
implements Client.Invoker, ClientObserver, LocationObserver
|
||||
public class TestClient extends com.threerings.crowd.client.TestClient
|
||||
implements LocationObserver
|
||||
{
|
||||
public TestClient (Credentials creds)
|
||||
public TestClient (String username)
|
||||
{
|
||||
// create our context
|
||||
_ctx = new WhirledContextImpl();
|
||||
super(username);
|
||||
|
||||
// create the handles for our various services
|
||||
_client = new Client(creds, this);
|
||||
_screp = new DummyClientSceneRepository();
|
||||
_occdir = new OccupantDirector(_ctx);
|
||||
_locdir = new LocationDirector(_ctx);
|
||||
|
||||
SceneFactory sfact = new SceneFactory() {
|
||||
public Scene createScene (SceneModel model, PlaceConfig config) {
|
||||
@@ -62,71 +54,20 @@ public class TestClient
|
||||
};
|
||||
_scdir = new SceneDirector(_ctx, _locdir, _screp, sfact);
|
||||
|
||||
// we want to know about logon/logoff
|
||||
_client.addClientObserver(this);
|
||||
|
||||
// we want to know about location changes
|
||||
_locdir.addLocationObserver(this);
|
||||
|
||||
// for test purposes, hardcode the server info
|
||||
_client.setServer("localhost", 4007);
|
||||
}
|
||||
|
||||
public void run ()
|
||||
{
|
||||
// log on
|
||||
_client.logon();
|
||||
|
||||
// loop over our queue, running the runnables
|
||||
while (true) {
|
||||
Runnable run = (Runnable)_queue.get();
|
||||
run.run();
|
||||
}
|
||||
}
|
||||
|
||||
public void invokeLater (Runnable run)
|
||||
{
|
||||
// queue it on up
|
||||
_queue.append(run);
|
||||
}
|
||||
|
||||
public void clientDidLogon (Client client)
|
||||
{
|
||||
// we specifically do not call super()
|
||||
|
||||
Log.info("Client did logon [client=" + client + "].");
|
||||
|
||||
// request to move to scene 0
|
||||
_ctx.getSceneDirector().moveTo(0);
|
||||
}
|
||||
|
||||
public void clientObjectDidChange (Client client)
|
||||
{
|
||||
Log.info("Client object did change [client=" + client + "].");
|
||||
}
|
||||
|
||||
public void clientFailedToLogon (Client client, Exception cause)
|
||||
{
|
||||
Log.info("Client failed to logon [client=" + client +
|
||||
", cause=" + cause + "].");
|
||||
}
|
||||
|
||||
public void clientConnectionFailed (Client client, Exception cause)
|
||||
{
|
||||
Log.info("Client connection failed [client=" + client +
|
||||
", cause=" + cause + "].");
|
||||
}
|
||||
|
||||
public boolean clientWillLogoff (Client client)
|
||||
{
|
||||
Log.info("Client will logoff [client=" + client + "].");
|
||||
return true;
|
||||
}
|
||||
|
||||
public void clientDidLogoff (Client client)
|
||||
{
|
||||
Log.info("Client did logoff [client=" + client + "].");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public boolean locationMayChange (int placeId)
|
||||
{
|
||||
// we're easy
|
||||
@@ -145,65 +86,30 @@ public class TestClient
|
||||
", reason=" + reason + "].");
|
||||
}
|
||||
|
||||
protected CrowdContext createContext ()
|
||||
{
|
||||
return (_ctx = new WhirledContextImpl());
|
||||
}
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
UsernamePasswordCreds creds =
|
||||
new UsernamePasswordCreds("test", "test");
|
||||
// create our test client
|
||||
TestClient tclient = new TestClient(creds);
|
||||
TestClient tclient = new TestClient("test");
|
||||
// start it running
|
||||
tclient.run();
|
||||
}
|
||||
|
||||
protected class WhirledContextImpl implements WhirledContext
|
||||
protected class WhirledContextImpl
|
||||
extends com.threerings.crowd.client.TestClient.CrowdContextImpl
|
||||
implements WhirledContext
|
||||
{
|
||||
public Config getConfig ()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public Client getClient ()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public DObjectManager getDObjectManager ()
|
||||
{
|
||||
return _client.getDObjectManager();
|
||||
}
|
||||
|
||||
public LocationDirector getLocationDirector ()
|
||||
{
|
||||
return _locdir;
|
||||
}
|
||||
|
||||
public OccupantDirector getOccupantDirector ()
|
||||
{
|
||||
return _occdir;
|
||||
}
|
||||
|
||||
public void setPlaceView (PlaceView view)
|
||||
{
|
||||
// nothing to do because we don't create views
|
||||
}
|
||||
|
||||
public void clearPlaceView (PlaceView view)
|
||||
{
|
||||
// nothing to do because we don't create views
|
||||
}
|
||||
|
||||
public SceneDirector getSceneDirector ()
|
||||
{
|
||||
return _scdir;
|
||||
}
|
||||
}
|
||||
|
||||
protected Client _client;
|
||||
protected LocationDirector _locdir;
|
||||
protected SceneDirector _scdir;
|
||||
protected OccupantDirector _occdir;
|
||||
protected SceneRepository _screp;
|
||||
protected WhirledContext _ctx;
|
||||
|
||||
protected Queue _queue = new Queue();
|
||||
protected SceneDirector _scdir;
|
||||
protected SceneRepository _screp;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user