summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2013-09-01 06:12:18 (GMT)
committerSwift Review <review@swift.im>2013-09-01 19:50:30 (GMT)
commit4f1274bcdd2af1a38b7de0b3ef4c18d6cd83c4a3 (patch)
treeeea00fbd093d746e862bc3e8fccadd98c7b0286b /Swiften
parent41bb9db24566f15d60d2522eaea6f00cbaabdf4a (diff)
downloadswift-4f1274bcdd2af1a38b7de0b3ef4c18d6cd83c4a3.zip
swift-4f1274bcdd2af1a38b7de0b3ef4c18d6cd83c4a3.tar.bz2
Sluift: More PubSub convenience methods & use cases.
- Convenience iterators to PubSub and PubSubNode. - Retrieving X most recent items - Retrieving a single item - Fixed GeoLocation serializer Change-Id: Ib4ecde225fb274b21163fcc9b52e19b0d3431860
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/QA/ScriptedTests/PubSub.lua38
-rw-r--r--Swiften/Serializer/PayloadSerializers/UserLocationSerializer.cpp44
2 files changed, 56 insertions, 26 deletions
diff --git a/Swiften/QA/ScriptedTests/PubSub.lua b/Swiften/QA/ScriptedTests/PubSub.lua
index a9c0fe8..cb4679a 100644
--- a/Swiften/QA/ScriptedTests/PubSub.lua
+++ b/Swiften/QA/ScriptedTests/PubSub.lua
@@ -22,6 +22,7 @@ local subscriber_node
local publish_item = {id = 'item_id', data = {{ _type = 'software_version', name = 'MyTest', os = 'Lua' }} }
local publish_item2 = {id = 'item_id2', data = {{ _type = 'software_version', name = 'MyTest2', os = 'Lua' }} }
+local publish_item3 = {id = 'item_id3', data = {{ _type = 'software_version', name = 'MyTest3', os = 'Lua' }} }
--------------------------------------------------------------------------------
-- Helper methods
@@ -109,11 +110,40 @@ function test_subscriber_use_cases()
-- 6.5 Retrieve items of a node
assert(node:create())
- assert(node:publish {item = publish_item})
+ assert(node:set_configuration{configuration = {['pubsub#max_items'] = '10'}})
+ assert(node:publish{item = publish_item})
+ assert(node:publish{item = publish_item2})
local items = assert(subscriber_node:get_items())
- assert(#items == 1)
+ assert(#items == 2)
assert(items[1].id == 'item_id')
assert(items[1].data[1].name == 'MyTest')
+ assert(items[2].id == 'item_id2')
+ assert(items[2].data[1].name == 'MyTest2')
+ assert(node:delete())
+
+ -- 6.5.7 Requesting most recent items
+ assert(node:create())
+ assert(node:set_configuration{configuration = {['pubsub#max_items'] = '10'}})
+ assert(node:publish{item = publish_item})
+ assert(node:publish{item = publish_item2})
+ assert(node:publish{item = publish_item3})
+ local items = assert(subscriber_node:get_items{maximum_items = 2})
+ assert(#items == 2)
+ assert(items[1].id == 'item_id2')
+ assert(items[1].data[1].name == 'MyTest2')
+ assert(items[2].id == 'item_id3')
+ assert(items[2].data[1].name == 'MyTest3')
+ assert(node:delete())
+
+ -- 6.5.8 requesting specific item
+ assert(node:create())
+ assert(node:set_configuration{configuration = {['pubsub#max_items'] = '10'}})
+ assert(node:publish{item = publish_item})
+ assert(node:publish{item = publish_item2})
+ local items = assert(subscriber_node:get_item{id = 'item_id2'})
+ assert(#items == 1)
+ assert(items[1].id == 'item_id2')
+ assert(items[1].data[1].name == 'MyTest2')
assert(node:delete())
end
@@ -141,7 +171,7 @@ function test_publisher_use_cases()
assert(node:create())
assert(subscriber_node:subscribe({ jid = subscriber_jid }))
assert(node:publish {items = {publish_item}})
- assert(node:retract { item = 'item_id', notify = true })
+ assert(node:retract { id = 'item_id', notify = true })
assert(node:delete())
-- 7.2.2.1 Delete and notify
@@ -149,7 +179,7 @@ function test_publisher_use_cases()
assert(subscriber_node:subscribe({ jid = subscriber_jid }))
assert(node:publish {items = {publish_item}})
purge_pubsub_events(subscriber)
- assert(node:retract { item = 'item_id', notify = true })
+ assert(node:retract { id = 'item_id', notify = true })
local event = assert(subscriber:get_next_event { type = 'pubsub' })
assert(event._type == 'pubsub_event_items')
assert(event.retracts[1].id == 'item_id')
diff --git a/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.cpp b/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.cpp
index 373276b..e257654 100644
--- a/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.cpp
+++ b/Swiften/Serializer/PayloadSerializers/UserLocationSerializer.cpp
@@ -25,67 +25,67 @@ std::string UserLocationSerializer::serializePayload(
if (boost::optional<std::string> value = payload->getArea()) {
result.addNode(boost::make_shared<XMLElement>("area", "", *value));
}
- else if (boost::optional<float> value = payload->getAltitude()) {
+ if (boost::optional<float> value = payload->getAltitude()) {
result.addNode(boost::make_shared<XMLElement>("alt", "", boost::lexical_cast<std::string>(*value)));
}
- else if (boost::optional<std::string> value = payload->getLocality()) {
+ if (boost::optional<std::string> value = payload->getLocality()) {
result.addNode(boost::make_shared<XMLElement>("locality", "", *value));
}
- else if (boost::optional<float> value = payload->getLatitude()) {
+ if (boost::optional<float> value = payload->getLatitude()) {
result.addNode(boost::make_shared<XMLElement>("lat", "", boost::lexical_cast<std::string>(*value)));
}
- else if (boost::optional<float> value = payload->getAccuracy()) {
- result.addNode(boost::make_shared<XMLElement>("lon", "", boost::lexical_cast<std::string>(*value)));
+ if (boost::optional<float> value = payload->getAccuracy()) {
+ result.addNode(boost::make_shared<XMLElement>("accuracy", "", boost::lexical_cast<std::string>(*value)));
}
- else if (boost::optional<std::string> value = payload->getDescription()) {
+ if (boost::optional<std::string> value = payload->getDescription()) {
result.addNode(boost::make_shared<XMLElement>("description", "", *value));
}
- else if (boost::optional<std::string> value = payload->getCountryCode()) {
+ if (boost::optional<std::string> value = payload->getCountryCode()) {
result.addNode(boost::make_shared<XMLElement>("countrycode", "", *value));
}
- else if (boost::optional<boost::posix_time::ptime> value = payload->getTimestamp()) {
+ if (boost::optional<boost::posix_time::ptime> value = payload->getTimestamp()) {
result.addNode(boost::make_shared<XMLElement>("timestamp", "", dateTimeToString(*value)));
}
- else if (boost::optional<std::string> value = payload->getFloor()) {
+ if (boost::optional<std::string> value = payload->getFloor()) {
result.addNode(boost::make_shared<XMLElement>("floor", "", *value));
}
- else if (boost::optional<std::string> value = payload->getBuilding()) {
+ if (boost::optional<std::string> value = payload->getBuilding()) {
result.addNode(boost::make_shared<XMLElement>("building", "", *value));
}
- else if (boost::optional<std::string> value = payload->getRoom()) {
+ if (boost::optional<std::string> value = payload->getRoom()) {
result.addNode(boost::make_shared<XMLElement>("room", "", *value));
}
- else if (boost::optional<std::string> value = payload->getCountry()) {
+ if (boost::optional<std::string> value = payload->getCountry()) {
result.addNode(boost::make_shared<XMLElement>("country", "", *value));
}
- else if (boost::optional<std::string> value = payload->getRegion()) {
+ if (boost::optional<std::string> value = payload->getRegion()) {
result.addNode(boost::make_shared<XMLElement>("region", "", *value));
}
- else if (boost::optional<std::string> value = payload->getURI()) {
+ if (boost::optional<std::string> value = payload->getURI()) {
result.addNode(boost::make_shared<XMLElement>("uri", "", *value));
}
- else if (boost::optional<float> value = payload->getLongitude()) {
+ if (boost::optional<float> value = payload->getLongitude()) {
result.addNode(boost::make_shared<XMLElement>("lon", "", boost::lexical_cast<std::string>(*value)));
}
- else if (boost::optional<float> value = payload->getError()) {
+ if (boost::optional<float> value = payload->getError()) {
result.addNode(boost::make_shared<XMLElement>("error", "", boost::lexical_cast<std::string>(*value)));
}
- else if (boost::optional<std::string> value = payload->getPostalCode()) {
+ if (boost::optional<std::string> value = payload->getPostalCode()) {
result.addNode(boost::make_shared<XMLElement>("postalcode", "", *value));
}
- else if (boost::optional<float> value = payload->getBearing()) {
+ if (boost::optional<float> value = payload->getBearing()) {
result.addNode(boost::make_shared<XMLElement>("bearing", "", boost::lexical_cast<std::string>(*value)));
}
- else if (boost::optional<std::string> value = payload->getText()) {
+ if (boost::optional<std::string> value = payload->getText()) {
result.addNode(boost::make_shared<XMLElement>("text", "", *value));
}
- else if (boost::optional<std::string> value = payload->getDatum()) {
+ if (boost::optional<std::string> value = payload->getDatum()) {
result.addNode(boost::make_shared<XMLElement>("datum", "", *value));
}
- else if (boost::optional<std::string> value = payload->getStreet()) {
+ if (boost::optional<std::string> value = payload->getStreet()) {
result.addNode(boost::make_shared<XMLElement>("street", "", *value));
}
- else if (boost::optional<float> value = payload->getSpeed()) {
+ if (boost::optional<float> value = payload->getSpeed()) {
result.addNode(boost::make_shared<XMLElement>("speed", "", boost::lexical_cast<std::string>(*value)));
}
return result.serialize();