int main() { { AtlasStreamClient * asc = new AtlasStreamClient; delete asc; } TestAtlasStreamClient * asc = new TestAtlasStreamClient; { Atlas::Objects::Root obj; asc->test_objectArrived(obj); obj->setParents(std::list<std::string>()); asc->test_objectArrived(obj); obj->setParents(std::list<std::string>(1, "foo")); asc->test_objectArrived(obj); obj->setObjtype("foo"); asc->test_objectArrived(obj); } Operation op; asc->test_objectArrived(op); asc->test_operation(op); TestClientTask * tct = new TestClientTask(); // Test starting a task asc->runTask(tct, "foo"); assert(asc->test_currentTask() == tct); // Try and start it again will busy, as one is running asc->runTask(new TestClientTask(), "foo"); assert(asc->test_currentTask() == tct); asc->endTask(); assert(asc->test_currentTask() == 0); asc->endTask(); assert(asc->test_currentTask() == 0); tct = new TestClientTask(); asc->runTask(tct, "foo"); // Pass in an operation while a task is running. asc->test_operation(op); assert(asc->test_currentTask() == tct); tct->make_complete(); asc->test_operation(op); assert(asc->test_currentTask() == 0); tct = new TestClientTask(); asc->runTask(tct, "foo"); assert(asc->test_currentTask() == tct); // Pass in an operation while a task is running. asc->test_operation(op); assert(asc->test_currentTask() == tct); { Atlas::Objects::Operation::Info op; asc->test_operation(op); Atlas::Objects::Entity::Anonymous arg; op->setArgs1(arg); asc->test_operation(op); op->setRefno(23); asc->test_operation(op); op->setRefno(asc->newSerialNo()); asc->test_operation(op); op->setFrom("1"); asc->test_operation(op); } { Atlas::Objects::Operation::Error op; asc->test_operation(op); Atlas::Objects::Entity::Anonymous arg; op->setArgs1(arg); asc->test_operation(op); arg->setAttr("message", 1); asc->test_operation(op); arg->setAttr("message", "Real message"); asc->test_operation(op); } { Atlas::Objects::Operation::Appearance op; asc->test_operation(op); } { Atlas::Objects::Operation::Disappearance op; asc->test_operation(op); } { Atlas::Objects::Operation::Sight op; asc->test_operation(op); } { Atlas::Objects::Operation::Sound op; asc->test_operation(op); } assert(asc->test_currentTask() == tct); // Verify these bale out cleanly when unconnected asc->poll(); asc->login("foo", "bar"); asc->create("player", "foo", "bar"); int ret = asc->connect("localhost", 2323); assert(ret != 0); ret = asc->connectLocal("/sys/thereisnofilehere"); assert(ret != 0); }
int main() { TestWorld world; CommServer server; { Peer * p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); delete p; } { Peer * p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); Atlas::Objects::Operation::RootOperation op; OpVector res; p->operation(op, res); delete p; } { // Test the setting of authentiaction states Peer * p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); assert(p->getAuthState() == PEER_INIT); p->setAuthState(PEER_AUTHENTICATED); assert(p->getAuthState() == PEER_AUTHENTICATED); delete p; } { Peer *p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); Atlas::Objects::Operation::Info op; OpVector res; p->operation(op, res); } // Authenticating (no args) { Peer *p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATING); Atlas::Objects::Operation::Info op; OpVector res; p->operation(op, res); } // Authenticating (empty arg) { Peer *p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATING); Atlas::Objects::Operation::Info op; Atlas::Objects::Root arg; op->setArgs1(arg); OpVector res; p->operation(op, res); } // Authenticating (full arg) { TestPeer *p = new TestPeer(*(CommSocket*)0, *(ServerRouting*)0, "addr", "1", 1); p->setAuthState(PEER_AUTHENTICATING); Atlas::Objects::Operation::Info op; Atlas::Objects::Root arg; arg->setId("2"); std::list<std::string> parents; parents.push_back("server"); arg->setParents(parents); op->setArgs1(arg); OpVector res; p->operation(op, res); assert(p->getAccountType() == "server"); } // Authenticated (no args) { Peer *p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATED); Atlas::Objects::Operation::Info op; OpVector res; p->operation(op, res); } { Peer *p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); Atlas::Objects::Operation::Error op; OpVector res; p->operation(op, res); } // Not authenticated { Peer *p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); Entity e("3", 3); int ret = p->teleportEntity(&e); assert(ret == -1); } // Authenticated { TestCommClient client(server, ""); Peer *p = new Peer(client, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATED); Entity e("3", 3); int ret = p->teleportEntity(&e); assert(ret == 0); assert(stub_CommClient_sent_op.isValid()); assert(stub_CommClient_sent_op->getArgs().size() == 1); } // Re-teleport same entity { TestCommClient client(server, ""); Peer *p = new Peer(client, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATED); Entity e("3", 3); int ret = p->teleportEntity(&e); assert(ret == 0); assert(stub_CommClient_sent_op.isValid()); assert(stub_CommClient_sent_op->getArgs().size() == 1); ret = p->teleportEntity(&e); assert(ret != 0); } // Character (no mind) { TestCommClient client(server, ""); Peer *p = new Peer(client, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATED); Character e("3", 3); int ret = p->teleportEntity(&e); assert(ret == 0); assert(stub_CommClient_sent_op.isValid()); assert(stub_CommClient_sent_op->getArgs().size() == 1); } // Character (externl mind, unconnected) { TestCommClient client(server, ""); Peer *p = new Peer(client, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATED); Character e("3", 3); e.m_externalMind = new ExternalMind(e); int ret = p->teleportEntity(&e); assert(ret == 0); assert(stub_CommClient_sent_op.isValid()); assert(stub_CommClient_sent_op->getArgs().size() == 1); } // Character (externl mind, connected) { TestCommClient client(server, ""); Peer *p = new Peer(client, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATED); Character e("3", 3); ExternalMind * mind = new ExternalMind(e); mind->linkUp((Link*)23); e.m_externalMind = mind; int ret = p->teleportEntity(&e); assert(ret == 0); assert(stub_CommClient_sent_op.isValid()); assert(stub_CommClient_sent_op->getArgs().size() == 2); } // No arg { Peer *p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); Atlas::Objects::Operation::Info op; OpVector res; p->peerTeleportResponse(op, res); } // Empty arg, no refno { Peer *p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); Atlas::Objects::Operation::Info op; OpVector res; Atlas::Objects::Root arg; op->setArgs1(arg); p->peerTeleportResponse(op, res); } // Empty arg, made up refno, not CommPeer { TestCommClient *peerConn = new TestCommClient(*(CommServer*)0, "name"); Peer *p = new Peer(*peerConn, *(ServerRouting*)0, "addr", 6767, "1", 1); Atlas::Objects::Operation::Info op; OpVector res; Atlas::Objects::Root arg; op->setArgs1(arg); op->setRefno(23); p->peerTeleportResponse(op, res); } // Empty arg, made up refno { CommPeer *peerConn = new CommPeer(*(CommServer*)0, "name"); Peer *p = new Peer(*peerConn, *(ServerRouting*)0, "addr", 6767, "1", 1); Atlas::Objects::Operation::Info op; OpVector res; Atlas::Objects::Root arg; op->setArgs1(arg); op->setRefno(23); p->peerTeleportResponse(op, res); } // Empty arg, refno that matches earlier teleport, not in world { CommPeer *peerConn = new CommPeer(server, "name"); Peer *p = new Peer(*peerConn, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATED); Entity e("23", 23); int ret = p->teleportEntity(&e); assert(ret == 0); Atlas::Objects::Operation::Info op; OpVector res; Atlas::Objects::Root arg; op->setArgs1(arg); op->setRefno(23); p->peerTeleportResponse(op, res); } // Empty arg, refno that matches earlier teleport, in world { CommPeer *peerConn = new CommPeer(server, "name"); Peer *p = new Peer(*peerConn, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATED); Entity e("23", 23); int ret = p->teleportEntity(&e); assert(ret == 0); world.test_addEntity(&e, 23); Atlas::Objects::Operation::Info op; OpVector res; Atlas::Objects::Root arg; op->setArgs1(arg); op->setRefno(23); p->peerTeleportResponse(op, res); world.test_delEntity(23); } // Empty arg, refno that matches earlier teleport, with mind { CommPeer *peerConn = new CommPeer(server, "name"); Peer *p = new Peer(*peerConn, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATED); Character e("23", 23); ExternalMind * mind = new ExternalMind(e); mind->linkUp((Link*)23); e.m_externalMind = mind; int ret = p->teleportEntity(&e); assert(ret == 0); world.test_addEntity(&e, 23); Atlas::Objects::Operation::Info op; OpVector res; Atlas::Objects::Root arg; op->setArgs1(arg); op->setRefno(23); p->peerTeleportResponse(op, res); world.test_delEntity(23); } // No teleports to clear { Peer *p = new Peer(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, "1", 1); p->cleanTeleports(); } // One teleport to clear { TestCommClient client(server, ""); Peer *p = new Peer(client, *(ServerRouting*)0, "addr", 6767, "1", 1); p->setAuthState(PEER_AUTHENTICATED); Entity e("23", 23); int ret = p->teleportEntity(&e); assert(ret == 0); p->cleanTeleports(); } return 0; }