00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00039
00040
00041 #include "client_test_helpers.h"
00042 #include <warehouse/warehouse_client.h>
00043 #include <yaml-cpp/yaml.h>
00044 #include <ros/console.h>
00045 #include <boost/foreach.hpp>
00046 #include <gtest/gtest.h>
00047
00048 namespace wh=warehouse;
00049 namespace gm=geometry_msgs;
00050 using std::vector;
00051 using std::string;
00052
00053 typedef wh::MessageWithMetadata<gm::Pose>::ConstPtr PoseWithMetadata;
00054
00055 string makeMetadata (const string& v)
00056 {
00057 return wh::MetadataString().add("foo", v).add("bar", 42);
00058 }
00059
00060
00061 TEST(Warehouse, warehouseClient)
00062 {
00063 wh::WarehouseClient client("my_app");
00064
00068 vector<std::string> indexed_fields, additional_metadata;
00069 indexed_fields.push_back("position.x");
00070 indexed_fields.push_back("position.y");
00071
00072 wh::Collection<gm::Pose> coll;
00073 coll = client.setupCollection<gm::Pose>("poses", indexed_fields);
00074
00076 const gm::Pose p1 = makePose(24, 42, 0);
00077 const gm::Pose p2 = makePose(10, 532, 3);
00078 const gm::Pose p3 = makePose(53, 22, 5);
00079 const gm::Pose p4 = makePose(22, -5, 33);
00080 coll.publish(p1, makeMetadata("bar"));
00081 coll.publish(p2, makeMetadata("baz"));
00082 coll.publish(p3, makeMetadata("qux"));
00083 coll.publish(p1, makeMetadata("oof"));
00084 coll.publish(p4, makeMetadata("ooof"));
00085
00086
00087 vector<wh::Condition> c(2);
00088 c[0].field_name = "position.x";
00089 c[0].predicate = wh::Condition::LESS_THAN;
00090 c[0].args.push_back("40");
00091 c[1].field_name = "position.y";
00092 c[1].predicate = wh::Condition::GREATER_THAN;
00093 c[1].args.push_back("0");
00094
00095
00096 wh::OrderingCriterion order;
00097 order.field = "_creation_time";
00098 order.reverse = true;
00099
00100
00101 vector<PoseWithMetadata> poses = coll.pullAllResults(c, false, order);
00102
00103
00104 EXPECT_EQ(3u, poses.size());
00105 EXPECT_EQ(p1, *poses[0]);
00106 EXPECT_EQ(p2, *poses[1]);
00107 EXPECT_EQ(p1, *poses[2]);
00108
00109 EXPECT_EQ("oof", wh::getMetadataVal<string>(poses[0]->metadata, "foo"));
00110 EXPECT_EQ("baz", wh::getMetadataVal<string>(poses[1]->metadata, "foo"));
00111 EXPECT_EQ("bar", wh::getMetadataVal<string>(poses[2]->metadata, "foo"));
00112
00113
00114 wh::Collection<gm::Pose> coll2 =
00115 client.setupCollection<gm::Pose>("poses", indexed_fields);
00116
00117
00118 vector<wh::Condition> c2(1);
00119 c2[0].field_name = "position.y";
00120 c2[0].predicate = wh::Condition::LESS_THAN;
00121 c2[0].args.push_back("30");
00122
00123 vector<wh::Condition> c3;
00124 EXPECT_EQ(5u, coll2.pullAllResults(c3, false).size());
00125 EXPECT_EQ(2u, coll2.removeMessages(c2));
00126 EXPECT_EQ(3u, coll2.pullAllResults(c3, true).size());
00127
00128 coll.queryResults(c);
00129 }
00130
00131
00132 int main (int argc, char** argv)
00133 {
00134 ros::init(argc, argv, "client_test");
00135 testing::InitGoogleTest(&argc, argv);
00136 return RUN_ALL_TESTS();
00137 }
00138
00139