void BaseMindtest::test_sightCreateOperation() { Atlas::Objects::Operation::Create sub_op; Atlas::Objects::Operation::Sight op; op->setArgs1(sub_op); OpVector res; bm->operation(op, res); sub_op->setArgs1(Atlas::Objects::Entity::Anonymous()); bm->operation(op, res); sub_op->setArgs1(Atlas::Objects::Entity::Anonymous(0)); bm->operation(op, res); }
void BaseMindtest::test_sightOperation() { OpVector res; Atlas::Objects::Operation::Sight op; bm->operation(op, res); op->setArgs1(Atlas::Objects::Entity::Anonymous()); bm->operation(op, res); op->setArgs1(Atlas::Objects::Entity::RootEntity(0)); bm->operation(op, res); op->setArgs1(Atlas::Objects::Operation::Get()); bm->operation(op, res); }
void BaseMindtest::test_sightSetOperation() { Atlas::Objects::Operation::Set sub_op; Atlas::Objects::Operation::Sight op; op->setArgs1(sub_op); OpVector res; bm->operation(op, res); sub_op->setArgs1(Atlas::Objects::Entity::Anonymous()); bm->operation(op, res); sub_op->setArgs1(Atlas::Objects::Entity::Anonymous(0)); bm->operation(op, res); Atlas::Objects::Entity::Anonymous arg; arg->setId("2"); sub_op->setArgs1(arg); bm->operation(op, res); }
int main(int argc, char** argv) { std::string atlas_xml_path; char * srcdir_env = getenv("srcdir"); if (srcdir_env != 0) { atlas_xml_path = srcdir_env; atlas_xml_path += "/"; } atlas_xml_path += "../../protocol/spec/atlas.xml"; try { Atlas::Objects::loadDefaults(atlas_xml_path); } catch(Atlas::Objects::DefaultLoadingException e) { std::cout << "DefaultLoadingException: " << e.getDescription() << std::endl; } Root root = Atlas::Objects::objectDefinitions.find("root")->second; Root root_inst; root_inst->setAttr("id", std::string("root_instantiation")); assert(root->getAttr("id").asString() == "root"); assert(root_inst->getAttr("id").asString() == "root_instantiation"); assert(root->getAttr("parents").asList().size() == 0); assert(root_inst->getAttr("parents").asList().size() == 1); assert((*root_inst->getAttr("parents").asList().begin()).asString() == "root"); Look look = smart_dynamic_cast<Look>(objectDefinitions.find("look")->second); Look look_inst; look_inst->setAttr("id", std::string("look_instantiation")); assert(look->getAttr("id").asString() == "look"); assert(look_inst->getAttr("id").asString() == "look_instantiation"); assert(look->getAttr("parents").asList().size() == 1); assert((*look->getAttr("parents").asList().begin()).asString() == "perceive"); assert(look_inst->getAttr("parents").asList().size() == 1); assert((*look_inst->getAttr("parents").asList().begin()).asString() == "look"); Account acct = smart_dynamic_cast<Account>(objectDefinitions.find("account")->second); Account acct_inst; acct_inst->setAttr("id", std::string("account_instantiation")); assert(acct->getAttr("id").asString() == "account"); assert(acct_inst->getAttr("id").asString() == "account_instantiation"); assert(acct->getAttr("parents").asList().size() == 1); assert((*acct->getAttr("parents").asList().begin()).asString() == "admin_entity"); assert(acct_inst->getAttr("parents").asList().size() == 1); assert((*acct_inst->getAttr("parents").asList().begin()).asString() == "account"); { Atlas::Objects::Entity::Anonymous anon; anon->setLoc("12345"); ListType velocity; velocity.push_back(1.4); velocity.push_back(2.4); velocity.push_back(3.4); anon->setVelocityAsList(velocity); ListType bbox; bbox.push_back(1.4); bbox.push_back(2.4); bbox.push_back(3.4); bbox.push_back(2.4); anon->setAttr("bbox", bbox); Atlas::Objects::Operation::Move move; move->setFrom("123456"); move->setTo("123456"); move->setSeconds(12345678); move->setId("123456"); move->setArgs1(anon); Atlas::Objects::Operation::Sight sight; sight->setFrom("123456"); sight->setTo("123456"); sight->setSeconds(12345678); sight->setId("123456"); sight->setArgs1(move); Atlas::Message::MapType map; sight->addToMessage(map); std::cout << map.size() << std::flush; assert(map.size() == 7); assert(map["objtype"].String() == "op"); assert(map["from"].String() == "123456"); assert(map["to"].String() == "123456"); assert(map["seconds"].Float() == 12345678); assert(map["id"].String() == "123456"); assert(map["args"].List().size() == 1); } }
int main() { TestWorld world; { Entity e("2", 2); ExternalMind em(e); } { Entity e("2", 2); TestExternalMind em(e); em.test_deleteEntity("3"); } // Purge with empty contains { Entity e("2", 2); e.m_contains = new LocatedEntitySet; TestExternalMind em(e); em.test_purgeEntity(e); } // Purge with populated contains { Entity e("2", 2); e.m_contains = new LocatedEntitySet; e.m_contains->insert(new Entity("3", 3)); TestExternalMind em(e); em.test_purgeEntity(e); } // Connect to nothing { Entity e("2", 2); ExternalMind em(e); em.linkUp(0); } // Connect to something { Entity e("2", 2); ExternalMind em(e); em.linkUp(new Connection(*(CommSocket*)0, *(ServerRouting*)0, "addr", "4", 4)); } // Connect to something, then disconnect { Entity e("2", 2); ExternalMind em(e); em.linkUp(new Connection(*(CommSocket*)0, *(ServerRouting*)0, "addr", "4", 4)); em.linkUp(0); } // Connect to something, then check connection ID { Entity e("2", 2); ExternalMind em(e); em.linkUp(new Connection(*(CommSocket*)0, *(ServerRouting*)0, "addr", "4", 4)); const std::string & id = em.connectionId(); assert(id == "4"); } // Send a random operation { Entity e("2", 2); TestExternalMind em(e); em.test_setLossTime(BaseWorld::instance().getTime()); stub_baseworld_receieved_op = -1; OpVector res; em.operation(Atlas::Objects::Operation::RootOperation(), res); assert(stub_baseworld_receieved_op == -1); } // Send a Delete operation { Entity e("2", 2); TestExternalMind em(e); em.test_setLossTime(BaseWorld::instance().getTime()); stub_baseworld_receieved_op = -1; OpVector res; em.operation(Atlas::Objects::Operation::Delete(), res); assert(stub_baseworld_receieved_op == -1); } // Send a Delete operation to an ephemeral entity { Entity e("2", 2); e.setFlags(entity_ephem); TestExternalMind em(e); em.test_setLossTime(BaseWorld::instance().getTime()); stub_baseworld_receieved_op = -1; OpVector res; em.operation(Atlas::Objects::Operation::Delete(), res); assert(stub_baseworld_receieved_op == -1); } // Send a non Delete operation to an ephemeral entity { Entity e("2", 2); e.setFlags(entity_ephem); TestExternalMind em(e); em.test_setLossTime(BaseWorld::instance().getTime()); stub_baseworld_receieved_op = -1; OpVector res; em.operation(Atlas::Objects::Operation::RootOperation(), res); assert(stub_baseworld_receieved_op == Atlas::Objects::Operation::DELETE_NO); } // Send a random operation to something that has been recorded as // disconnected for a while { Entity e("2", 2); // FIXME hard code the expiry time here. TestExternalMind em(e); em.test_setLossTime(BaseWorld::instance().getTime() - 60*60 - 5); stub_baseworld_receieved_op = -1; OpVector res; em.operation(Atlas::Objects::Operation::RootOperation(), res); assert(stub_baseworld_receieved_op == Atlas::Objects::Operation::DELETE_NO); } // Send a random operation to a connected mind { Entity e("2", 2); TestExternalMind em(e); em.linkUp(new Connection(*(CommSocket*)0, *(ServerRouting*)0, "addr", "4", 4)); stub_link_send_op = -1; stub_link_send_count = 0; OpVector res; em.operation(Atlas::Objects::Operation::RootOperation(), res); assert(stub_link_send_op == Atlas::Objects::Operation::ROOT_OPERATION_NO); assert(stub_link_send_count == 1); } // Send a Sight operation to a connected mind { Entity e("2", 2); TestExternalMind em(e); em.linkUp(new Connection(*(CommSocket*)0, *(ServerRouting*)0, "addr", "4", 4)); stub_link_send_op = -1; stub_link_send_count = 0; OpVector res; em.operation(Atlas::Objects::Operation::Sight(), res); assert(stub_link_send_op == Atlas::Objects::Operation::SIGHT_NO); assert(stub_link_send_count == 1); } // Send a Sight(Set) of hungry operation to a connected mind { Entity e("2", 2); TestExternalMind em(e); em.linkUp(new Connection(*(CommSocket*)0, *(ServerRouting*)0, "addr", "4", 4)); stub_link_send_op = -1; stub_link_send_count = 0; // A sight(set) of a starving entity Atlas::Objects::Root arg; arg->setAttr("status", 0.05); arg->setId(e.getId()); Atlas::Objects::Operation::Set set; set->setArgs1(arg); Atlas::Objects::Operation::Sight op; op->setArgs1(set); // It should trigger an extra Sight(Imaginary) OpVector res; em.operation(op, res); assert(stub_link_send_op == Atlas::Objects::Operation::SIGHT_NO); assert(stub_link_send_count > 1); } // Send a Sight(Set) of starving operation to a connected mind { Entity e("2", 2); TestExternalMind em(e); em.linkUp(new Connection(*(CommSocket*)0, *(ServerRouting*)0, "addr", "4", 4)); stub_link_send_op = -1; stub_link_send_count = 0; // A sight(set) of a starving entity Atlas::Objects::Root arg; arg->setAttr("status", 0.005); arg->setId(e.getId()); Atlas::Objects::Operation::Set set; set->setArgs1(arg); Atlas::Objects::Operation::Sight op; op->setArgs1(set); // It should trigger an extra Sight(Imaginary) OpVector res; em.operation(op, res); assert(stub_link_send_op == Atlas::Objects::Operation::SIGHT_NO); assert(stub_link_send_count > 1); } return 0; }
void StorageManager::restorePropertiesRecursively(LocatedEntity * ent) { Database * db = Database::instance(); PropertyManager * pm = PropertyManager::instance(); DatabaseResult res = db->selectProperties(ent->getId()); //Keep track of those properties that have been set on the instance, so we'll know what //type properties we should ignore. std::unordered_set<std::string> instanceProperties; DatabaseResult::const_iterator I = res.begin(); DatabaseResult::const_iterator Iend = res.end(); for (; I != Iend; ++I) { const std::string name = I.column("name"); if (name.empty()) { log(ERROR, compose("No name column in property row for %1", ent->getId())); continue; } const std::string val_string = I.column("value"); if (name.empty()) { log(ERROR, compose("No value column in property row for %1,%2", ent->getId(), name)); continue; } MapType prop_data; db->decodeMessage(val_string, prop_data); MapType::const_iterator J = prop_data.find("val"); if (J == prop_data.end()) { log(ERROR, compose("No property value data for %1:%2", ent->getId(), name)); continue; } assert(ent->getType() != 0); const Element & val = J->second; Element existingVal; if (ent->getAttr(name, existingVal) == 0) { if (existingVal == val) { //If the existing property, either on the instance or the type, is equal to the persisted one just skip it. continue; } } PropertyBase * prop = ent->modProperty(name); if (prop == nullptr) { prop = pm->addProperty(name, val.getType()); prop->install(ent, name); //This transfers ownership of the property to the entity. ent->setProperty(name, prop); } //If we get to here the property either doesn't exists, or have a different value than the default or existing property. prop->set(val); prop->setFlags(per_clean | per_seen); prop->apply(ent); instanceProperties.insert(name); } if (ent->getType()) { for (auto& propIter : ent->getType()->defaults()) { if (!instanceProperties.count(propIter.first)) { PropertyBase * prop = propIter.second; // If a property is in the class it won't have been installed // as setAttr() checks prop->install(ent, propIter.first); // The property will have been applied if it has an overriden // value, so we only apply it the value is still default. prop->apply(ent); } } } //Now restore all properties of the child entities. if (ent->m_contains) { for (auto& childEntity : *ent->m_contains) { restorePropertiesRecursively(childEntity); } } //We must send a sight op to the entity informing it of itself before we send any thoughts. //Else the mind won't have any information about itself. { Atlas::Objects::Operation::Sight sight; sight->setTo(ent->getId()); Atlas::Objects::Entity::Anonymous args; ent->addToEntity(args); sight->setArgs1(args); ent->sendWorld(sight); } //We should also send a sight op to the parent entity which owns the entity. //TODO: should this really be necessary or should we rely on other Sight functionality? if (ent->m_location.m_loc) { Atlas::Objects::Operation::Sight sight; sight->setTo(ent->m_location.m_loc->getId()); Atlas::Objects::Entity::Anonymous args; ent->addToEntity(args); sight->setArgs1(args); ent->m_location.m_loc->sendWorld(sight); } restoreThoughts(ent); }