Esempio n. 1
0
void Accountintegration::test_LogoutOperation()
{
    Logout op;
    op->setSerialno(1);

    Anonymous op_arg;
    op_arg->setParents(std::list<std::string>());
    op->setArgs1(op_arg);

    OpVector res;
    m_ac->operation(op, res);

    // FIXME Account should have been removed from Lobby, and also from
    // Connection
}
Esempio n. 2
0
int main()
{
    // WorldRouter world;
    // Entity & e = world.m_gameWorld;

    ServerRouting server(*(BaseWorld*)0, "noruleset", "unittesting",
                         "1", 1, "2", 2);

    CommServer commServer(server);

    TestCommClient * tcc = new TestCommClient(commServer);
    TestConnection * tc = new TestConnection(*tcc, server, "addr", "3", 3);

    Account * ac = tc->testAddAccount("bob", "foo");
    assert(ac != 0);

    ac = tc->testRemoveAccount(ac);
    assert(ac != 0);
    tc->removeObject(ac);

    assert(tc->numObjects() == 0);

    {
        Create op;
        OpVector res;
        tc->operation(op, res);
        op->setArgs1(Root());
        tc->operation(op, res);
        restricted_flag = true;
        tc->operation(op, res);
        restricted_flag = false;
        Anonymous op_arg;
        op->setArgs1(op_arg);
        tc->operation(op, res);
        op_arg->setId("jim");
        // Legacy op
        tc->operation(op, res);
        op_arg->setAttr("username", 1);
        // Malformed username
        tc->operation(op, res);
        op_arg->setAttr("username", "jim");
        // username, no password
        tc->operation(op, res);
        op_arg->setAttr("password", "");
        // zero length password
        tc->operation(op, res);
        op_arg->setAttr("username", "");
        op_arg->setAttr("password", "foo");
        // zero length username
        tc->operation(op, res);
        op_arg->setAttr("username", "jim");
        // valid username and password
        tc->operation(op, res);
        assert(tc->numObjects() != 0);
    }

    {
        Login op;
        OpVector res;
        tc->operation(op, res);
        op->setArgs1(Root());
        tc->operation(op, res);
        Anonymous op_arg;
        op->setArgs1(op_arg);
        tc->operation(op, res);
        op_arg->setId("bob");
        tc->operation(op, res);
        op_arg->setAttr("username", 1);
        tc->operation(op, res);
        op_arg->setAttr("username", "");
        tc->operation(op, res);
        op_arg->setAttr("username", "bob");
        tc->operation(op, res);
        op_arg->setAttr("password", "foo");
        tc->operation(op, res);
        tc->operation(op, res);
    }

    {
        Get op;
        OpVector res;
        tc->operation(op, res);
        Root op_arg;
        op->setArgs1(op_arg);
        tc->operation(op, res);
        op_arg->setId("1");
        tc->operation(op, res);
        op_arg->setId("game_entity");
        tc->operation(op, res);
    }

    {
        Logout op;
        OpVector res;
        tc->operation(op, res);
        op->setSerialno(24);
        tc->operation(op, res);
        Root op_arg;
        op->setArgs1(op_arg);
        tc->operation(op, res);
        op_arg->setId("-1");
        tc->operation(op, res);
        op_arg->setId("23");
        tc->operation(op, res);
        // How to determine the real ID?
        const RouterMap rm = tc->getObjects();
        RouterMap::const_iterator I = rm.begin();
        for (;I != rm.end(); ++I) {
            std::string object_id = String::compose("%1", I->first);
            std::cout << "ID: " << object_id << std::endl;
            op_arg->setId(object_id);
            tc->operation(op, res);
        }
    }

    delete tc;
}
Esempio n. 3
0
int main()
{
    database_flag = false;

    (void)new Domain;

    WorldRouter world;
    Entity & e = world.m_gameWorld;

    ServerRouting server(world, "noruleset", "unittesting",
                         "1", 1, "2", 2);

    CommServer commServer(server);

    TestCommClient * tc = new TestCommClient(commServer);
    Connection * c = new Connection(*tc, server, "addr", "3", 3);
    TestAccount * ac = new TestAccount(c, "user", "password", "4", 4);
    Entity * chr;

    {
        chr = new Entity("5", 5);
        chr->m_location.m_loc = &e;
        chr->m_location.m_loc->makeContainer();
        assert(chr->m_location.m_loc->m_contains != 0);
        chr->m_location.m_loc->m_contains->insert(chr);

        ac->addCharacter(chr);

        chr->destroy();

    }

    {
        chr = new Character("6", 6);
        chr->m_location.m_loc = &e;
        chr->m_location.m_loc->makeContainer();
        assert(chr->m_location.m_loc->m_contains != 0);
        chr->m_location.m_loc->m_contains->insert(chr);

        ac->addCharacter(chr);

        chr->destroy();

    }

    {
        chr = new Character("7", 7);
        chr->m_location.m_loc = &e;
        chr->m_location.m_loc->makeContainer();
        assert(chr->m_location.m_loc->m_contains != 0);
        chr->m_location.m_loc->m_contains->insert(chr);

        ac->addCharacter(chr);
    }

    {
        Anonymous new_char;
        Entity * chr = ac->testAddNewCharacter("thing", new_char,
                                               RootEntity());
        assert(chr != 0);
    }

    ac->getType();

    {
        MapType emap;
        ac->addToMessage(emap);
    }

    {
        RootEntity ent;
        ac->addToEntity(ent);
    }

    {
        Create op;
        OpVector res;
        ac->operation(op, res);
        op->setArgs1(Root());
        ac->operation(op, res);
        Anonymous op_arg;
        op->setArgs1(op_arg);
        ac->operation(op, res);
        op_arg->setParents(std::list<std::string>());
        ac->operation(op, res);
        op_arg->setParents(std::list<std::string>(1, "game_entity"));
        ac->operation(op, res);
        op_arg->setName("Bob");
        ac->operation(op, res);
    }

    {
        Get op;
        OpVector res;
        ac->operation(op, res);
        op->setArgs1(Root());
        ac->operation(op, res);
        Anonymous op_arg;
        op->setArgs1(op_arg);
        ac->operation(op, res);
        op_arg->setParents(std::list<std::string>());
        ac->operation(op, res);
    }

    {
        Imaginary op;
        OpVector res;
        ac->operation(op, res);
        op->setArgs1(Root());
        ac->operation(op, res);
        op->setSerialno(1);
        ac->operation(op, res);
        Anonymous op_arg;
        op->setArgs1(op_arg);
        ac->operation(op, res);
        op_arg->setLoc("2");
        ac->operation(op, res);
    }

    {
        Look op;
        OpVector res;
        ac->operation(op, res);
        op->setArgs1(Root());
        ac->operation(op, res);
        Anonymous op_arg;
        op->setArgs1(op_arg);
        ac->operation(op, res);
        op_arg->setId("1");
        ac->operation(op, res);
        op_arg->setId(chr->getId());
        ac->operation(op, res);
    }

    {
        Set op;
        OpVector res;
        ac->operation(op, res);
        op->setArgs1(Root());
        ac->operation(op, res);
        Anonymous op_arg;
        op->setArgs1(op_arg);
        ac->operation(op, res);
        op_arg->setId("1");
        ac->operation(op, res);
        op_arg->setId(chr->getId());
        ac->operation(op, res);
        op_arg->setAttr("guise", "foo");
        ac->operation(op, res);
        op_arg->setAttr("height", 3.0);
        ac->operation(op, res);
        BBox newBox(WFMath::Point<3>(-0.5, -0.5, 0.0),
                    WFMath::Point<3>(-0.5, -0.5, 2.0));
        chr->m_location.setBBox(newBox);
        op_arg->setAttr("height", 3.0);
        ac->operation(op, res);
        op_arg->setAttr("tasks", ListType());
        ac->operation(op, res);
    }

    {
        Talk op;
        OpVector res;
        ac->operation(op, res);
        op->setArgs1(Root());
        ac->operation(op, res);
        Anonymous op_arg;
        op->setArgs1(op_arg);
        ac->operation(op, res);
        op_arg->setParents(std::list<std::string>());
        ac->operation(op, res);
        op->setSerialno(1);
        ac->operation(op, res);
        op_arg->setLoc("1");
        ac->operation(op, res);
    }

    {
        Logout op;
        OpVector res;
        ac->operation(op, res);
        op->setSerialno(1);
        ac->operation(op, res);
        op->setArgs1(Root());
        ac->operation(op, res);
        Anonymous op_arg;
        op->setArgs1(op_arg);
        ac->operation(op, res);
        op_arg->setParents(std::list<std::string>());
        ac->operation(op, res);
    }

    {
        // Move has no meaning
        Move op;
        OpVector res;
        ac->operation(op, res);
        op->setArgs1(Root());
        ac->operation(op, res);
        Anonymous op_arg;
        op->setArgs1(op_arg);
        ac->operation(op, res);
        op_arg->setParents(std::list<std::string>());
        ac->operation(op, res);
    }

    {
        Entity e("7", 7);

        int ret = ac->connectCharacter(&e);
        assert(ret == -1);
    }

    {
        Character e("8", 8);

        int ret = ac->connectCharacter(&e);
        assert(ret == 0);
    }

    delete ac;

    return 0;
}