Пример #1
0
int main()
{
    Eris::Logged.connect(sigc::ptr_fun(writeLog));
    Eris::setLogLevel(Eris::LOG_DEBUG);
    {
        TestConnection con("name", "localhost",
                                                    6767, true);

        TestAccount acc(&con);
        
        std::string fake_char_id("1");
        TestAvatar ea(&acc, fake_char_id);
        acc.setup_insertActiveCharacters(&ea);
        TestEntity* char_ent = new TestEntity(fake_char_id, 0, ea.getView());
        ea.setup_setEntity(char_ent);
        
        typedef std::map<std::string, Atlas::Message::Element> ElementStore;
        ElementStore modTypes;
        ElementStore shapes;
        
        ElementStore levelMods;
        Atlas::Message::MapType levelMod1;
        levelMod1["type"] = Atlas::Message::Element("levelmod");
        levelMods["1"] = levelMod1;
        Atlas::Message::MapType levelMod2(levelMod1);
        levelMod2["height"] = 20;
        levelMods["2"] = levelMod2;
        Atlas::Message::MapType levelMod3(levelMod1);
        levelMod2["heightoffset"] = 30;
        levelMods["3"] = levelMod3;
        
        
        ElementStore adjustMods;
        Atlas::Message::MapType adjustMod1;
        adjustMod1["type"] = Atlas::Message::Element("adjustmod");
        adjustMods["1"] = levelMod1;
        Atlas::Message::MapType adjustMod2(adjustMod1);
        adjustMod2["height"] = 20;
        adjustMods["2"] = adjustMod2;
        Atlas::Message::MapType adjustMod3(adjustMod1);
        adjustMod2["heightoffset"] = 30;
        adjustMods["3"] = adjustMod3;
        
        Atlas::Message::MapType craterMod1;
        craterMod1["type"] = Atlas::Message::Element("cratermod");
        
        ElementStore slopeMods;
        Atlas::Message::MapType slopeMod1;
        slopeMod1["type"] = Atlas::Message::Element("slopemod");
        Atlas::Message::ListType slopes;
        slopes.push_back(10);
        slopes.push_back(20);
        slopeMod1["slopes"] = slopes;
        slopeMods["1"] = slopeMod1;
        
        
        Atlas::Message::MapType shapeCircle;
        shapeCircle["radius"] = 15;
        shapeCircle["position"] = Atlas::Message::ListType(2, 0.);
        shapeCircle["type"] = "ball";
        shapes["ball"] = shapeCircle;
        
        Atlas::Message::MapType shapePolygon;
        Atlas::Message::ListType points;
        points.push_back(WFMath::Point<2>(0,0).toAtlas());
        points.push_back(WFMath::Point<2>(10,0).toAtlas());
        points.push_back(WFMath::Point<2>(10,10).toAtlas());
        points.push_back(WFMath::Point<2>(0,10).toAtlas());
        shapePolygon["points"] = points;
        shapePolygon["type"] = "polygon";
        shapes["polygon"] = shapePolygon;
        
        shapes["empty"] = Atlas::Message::MapType();
        
        //no terrain mod info
        {
            Atlas::Message::MapType emptyElement;
            TestEntity* mod_ent = new TestEntity("2", 0, ea.getView());
            mod_ent->setup_setAttr("terrainmod", emptyElement);
            
            Eris::TerrainModObserver mod(mod_ent);
            assert(!mod.init());
            
        }
        
        //no shape
        {
            Atlas::Message::MapType modElement = levelMod1;
            TestEntity* mod_ent = new TestEntity("2", 0, ea.getView());
            mod_ent->setup_setAttr("terrainmod", modElement);
            
            Eris::TerrainModObserver mod(mod_ent);
            assert(!mod.init());
            
        }       
         
        //test level mod
        for (ElementStore::iterator I = levelMods.begin(); I != levelMods.end(); ++I) {
            for (ElementStore::iterator J = shapes.begin(); J != shapes.end(); ++J) {
                std::cout << "Testing level mod " << I->first << " with " << J->first << std::endl;
                Atlas::Message::Element modElement = I->second;
                modElement.asMap()["shape"] = J->second;
                TestEntity* mod_ent = new TestEntity("2", 0, ea.getView());
                mod_ent->setup_setAttr("terrainmod", modElement);
                
                Eris::TerrainModObserver mod(mod_ent);
                if (J->first == "empty") {
                    assert(!mod.init());
                } else {
                    assert(mod.init());
                }
            }
        }        
        
        //test adjust mod
        for (ElementStore::iterator I = adjustMods.begin(); I != adjustMods.end(); ++I) {
            for (ElementStore::iterator J = shapes.begin(); J != shapes.end(); ++J) {
                std::cout << "Testing adjust mod " << I->first << " with " << J->first << std::endl;
                Atlas::Message::Element modElement = I->second;
                modElement.asMap()["shape"] = J->second;
                TestEntity* mod_ent = new TestEntity("2", 0, ea.getView());
                mod_ent->setup_setAttr("terrainmod", modElement);
                
                Eris::TerrainModObserver mod(mod_ent);
                if (J->first == "empty") {
                    assert(!mod.init());
                } else {
                    assert(mod.init());
                }
            }
        }
                
        //test slope mod
        for (ElementStore::iterator I = slopeMods.begin(); I != slopeMods.end(); ++I) {
            for (ElementStore::iterator J = shapes.begin(); J != shapes.end(); ++J) {
                std::cout << "Testing slope mod " << I->first << " with " << J->first << std::endl;
                Atlas::Message::Element modElement = I->second;
                modElement.asMap()["shape"] = J->second;
                TestEntity* mod_ent = new TestEntity("2", 0, ea.getView());
                mod_ent->setup_setAttr("terrainmod", modElement);
                
                Eris::TerrainModObserver mod(mod_ent);
                if (J->first == "empty") {
                    assert(!mod.init());
                } else {
                    assert(mod.init());
                }
            }
        }
        
        Atlas::Message::MapType shapeBall;
        shapeBall["radius"] = 15;
        shapeBall["position"] = Atlas::Message::ListType(3, 0.);
        shapeBall["type"] = "ball";
        
        //test crater mod
        {
            Atlas::Message::MapType modElement = craterMod1;
            modElement["shape"] = shapeCircle;
            TestEntity* mod_ent = new TestEntity("2", 0, ea.getView());
            mod_ent->setup_setAttr("terrainmod", modElement);
            
            Eris::TerrainModObserver mod(mod_ent);
            assert(mod.init());
            
        }
    }
    return 0;
}
Пример #2
0
int main()
{
    Eris::Logged.connect(sigc::ptr_fun(writeLog));
    Eris::setLogLevel(Eris::LOG_DEBUG);

    /////////////////////////// DateTime ///////////////////////////

    // Test constructor and destructor
    {
        Eris::DateTime dt;
    }

    // Test valid()
    {
        Eris::DateTime dt;

        assert(!dt.valid());
    }

    // Test year()
    {
        Eris::DateTime dt;

        dt.year();
    }

    // Test month()
    {
        Eris::DateTime dt;

        dt.month();
    }

    // Test dayOfMonth()
    {
        Eris::DateTime dt;

        dt.dayOfMonth();
    }

    // Test seconds()
    {
        Eris::DateTime dt;

        dt.seconds();
    }

    // Test minutes()
    {
        Eris::DateTime dt;

        dt.minutes();
    }

    // Test hours()
    {
        Eris::DateTime dt;

        dt.hours();
    }

    // Test year()
    {
        Eris::DateTime dt;

        dt.year();
    }

    /////////////////////////// Calendar ///////////////////////////

    // Test constructor
    {
        std::string fake_char_id("1");
		std::string fake_mind_id("12");
        Eris::Avatar * ea = new TestAvatar(nullptr, fake_mind_id, fake_char_id);
        Eris::Calendar ec(ea);
    }

    // FIXME Can't set the toplevel on the view, which is required to
    // test all paths through the constructor.

    // Test topLevelEntityChanged()
    {
        std::string fake_char_id("1");
		std::string fake_mind_id("12");
        Eris::Avatar * ea = new TestAvatar(nullptr, fake_mind_id, fake_char_id);

        TestCalendar ec(ea);

        ec.test_topLevelEntityChanged();
    }

    /// Test overflow of 32bit seconds

    // Test calendar process time at the origin of time
    {
        std::string fake_char_id("1");
		std::string fake_mind_id("12");
        Eris::Avatar * ea = new TestAvatar(nullptr, fake_mind_id, fake_char_id);

        TestCalendar ec(ea);

        ec.test_setSaneDefault();

        stub_worldtime = 0;

        Eris::DateTime dt = ec.now();

        assert(dt.year() == 0);
        assert(dt.month() == 0);
        assert(dt.dayOfMonth() == 0);
        assert(dt.hours() == 0);
        assert(dt.minutes() == 0);
        assert(dt.seconds() == 0);
    }

    // Test calendar process time at the origin of time plus some time
    {
        std::string fake_char_id("1");
		std::string fake_mind_id("12");
        Eris::Avatar * ea = new TestAvatar(nullptr, fake_mind_id, fake_char_id);

        TestCalendar ec(ea);

        ec.test_setSaneDefault();

        stub_worldtime = 1LL * MPY * DPM * HPD * MPH * SPM;

        Eris::DateTime dt = ec.now();

        assert(dt.year() == 1);
        assert(dt.month() == 0);
        assert(dt.dayOfMonth() == 0);
        assert(dt.hours() == 0);
        assert(dt.minutes() == 0);
        assert(dt.seconds() == 0);

        stub_worldtime = 1000LL * MPY * DPM * HPD * MPH * SPM;

        dt = ec.now();

        assert(dt.year() == 1000);
        assert(dt.month() == 0);
        assert(dt.dayOfMonth() == 0);
        assert(dt.hours() == 0);
        assert(dt.minutes() == 0);
        assert(dt.seconds() == 0);
    }

    // Test calendar process time at the limit of an unsigned 32bit int seconds
    {
        std::string fake_char_id("1");
		std::string fake_mind_id("12");
        Eris::Avatar * ea = new TestAvatar(nullptr, fake_mind_id, fake_char_id);

        TestCalendar ec(ea);

        ec.test_setSaneDefault();

        stub_worldtime = std::numeric_limits<unsigned int>::max() + 10LL;

        Eris::DateTime dt = ec.now();

        // std::cout << dt.year() << ":" << dt.month() << ":" << dt.dayOfMonth() << ":" << dt.hours() << ":" << dt.minutes() << ":" << dt.seconds() << std::endl;

        assert(dt.year() > 0);
    }

    // Test event emitted
    {
        SignalFlagger flagger;
        std::string fake_char_id("1");
		std::string fake_mind_id("12");
        Eris::Avatar * ea = new TestAvatar(nullptr, fake_mind_id, fake_char_id);

        TestCalendar ec(ea);
        ec.Updated.connect(sigc::mem_fun(flagger,
                &SignalFlagger::set));

        ec.test_setSaneDefault();

        assert(flagger.flagged());
    }


    return 0;
}