Go to the documentation of this file.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 #include <gtest/gtest.h>
00031
00032 #include <ros/ros.h>
00033
00034 #include <yaml-cpp/yaml.h>
00035
00036 #include <sstream>
00037
00038 #include <rviz/properties/vector_property.h>
00039 #include <rviz/properties/color_property.h>
00040 #include <rviz/display_group.h>
00041
00042 #include "mock_display.h"
00043 #include "mock_context.h"
00044
00045 using namespace rviz;
00046
00047 TEST( Display, load_properties )
00048 {
00049 std::stringstream input( "Name: sample\n"
00050 "Enabled: true\n"
00051 "Count: 7\n"
00052 "Pi: 3.2\n"
00053 "Offset: {X: -1, Y: 1.1, Z: 1.1e3}\n"
00054 "Color: white\n"
00055 "Style: loosey goosey\n" );
00056
00057 YAML::Parser parser( input );
00058 YAML::Node node;
00059 parser.GetNextDocument( node );
00060
00061 MockDisplay d;
00062 d.load( node );
00063
00064 EXPECT_EQ( 7, d.count_->getValue().toInt() );
00065 EXPECT_EQ( "loosey goosey", d.style_->getValue().toString().toStdString() );
00066 EXPECT_EQ( 3.2f, d.pi_->getValue().toFloat() );
00067 Ogre::Vector3 offset = d.offset_->getVector();
00068 EXPECT_EQ( -1.f, offset.x );
00069 EXPECT_EQ( 1.1f, offset.y );
00070 EXPECT_EQ( 1100.f, offset.z );
00071 EXPECT_EQ( "255; 255; 255", d.color_->getValue().toString().toStdString() );
00072 EXPECT_EQ( true, d.getValue().toBool() );
00073 }
00074
00075 TEST( DisplayGroup, load_properties )
00076 {
00077 std::stringstream input(
00078 "Name: root\n"
00079 "Enabled: true\n"
00080 "Displays:\n"
00081 " -\n"
00082 " Class: MockDisplay\n"
00083 " Name: Steven\n"
00084 " Enabled: false\n"
00085 " Count: 17\n"
00086 " -\n"
00087 " Name: sub group\n"
00088 " Class: DisplayGroup\n"
00089 " Enabled: true\n"
00090 " Displays:\n"
00091 " -\n"
00092 " Class: MockDisplay\n"
00093 " Name: Curly\n"
00094 " Enabled: false\n"
00095 " Count: 900\n"
00096 " -\n"
00097 " Class: BrokenDisplay\n"
00098 " Name: Joe\n"
00099 " Enabled: true\n"
00100 " Count: 33\n"
00101 );
00102
00103 YAML::Parser parser( input );
00104 YAML::Node node;
00105 parser.GetNextDocument( node );
00106
00107 MockContext context;
00108
00109 DisplayGroup g;
00110 g.initialize( &context );
00111 g.load( node );
00112
00113 EXPECT_EQ( true, g.getValue().toBool() );
00114 EXPECT_EQ( false, g.subProp("Steven")->getValue().toBool() );
00115 EXPECT_EQ( 17, g.subProp("Steven")->subProp("Count")->getValue().toInt() );
00116 EXPECT_EQ( 900, g.subProp("sub group")->subProp("Curly")->subProp("Count")->getValue().toInt() );
00117 EXPECT_EQ( "The class required for this display, 'BrokenDisplay', could not be loaded.",
00118 g.subProp("Joe")->getDescription().left( 74 ).toStdString());
00119 }
00120
00121 TEST( Display, save_properties)
00122 {
00123 MockDisplay d;
00124 d.setName( "Steven" );
00125 d.subProp( "Count" )->setValue( 37 );
00126
00127 YAML::Emitter out;
00128 d.save( out );
00129
00130
00131
00132 EXPECT_EQ( std::string(
00133 "Class: \"\"\n"
00134 "Name: Steven\n"
00135 "Enabled: false\n"
00136 "Count: 37\n"
00137 "Style: chunky\n"
00138 "Pi: 3.14159\n"
00139 "Offset: {X: 1, Y: 2, Z: 3}\n"
00140 "Color: 10; 20; 30"
00141 )
00142 , out.c_str() );
00143 }
00144
00145 TEST( DisplayGroup, save_properties)
00146 {
00147 DisplayGroup g;
00148 g.setName( "Charles" );
00149
00150 MockDisplay *d = new MockDisplay;
00151 d->setName( "Steven" );
00152 d->subProp( "Count" )->setValue( 101 );
00153 g.addChild( d );
00154
00155 d = new MockDisplay;
00156 d->setName( "Katherine" );
00157 d->subProp( "Pi" )->setValue( 1.1 );
00158 g.addChild( d );
00159
00160 YAML::Emitter out;
00161 g.save( out );
00162
00163
00164
00165 EXPECT_EQ( std::string(
00166 "Class: \"\"\n"
00167 "Name: Charles\n"
00168 "Enabled: false\n"
00169 "Displays:\n"
00170 " - Class: \"\"\n"
00171 " Name: Steven\n"
00172 " Enabled: false\n"
00173 " Count: 101\n"
00174 " Style: chunky\n"
00175 " Pi: 3.14159\n"
00176 " Offset: {X: 1, Y: 2, Z: 3}\n"
00177 " Color: 10; 20; 30\n"
00178 " - Class: \"\"\n"
00179 " Name: Katherine\n"
00180 " Enabled: false\n"
00181 " Count: 10\n"
00182 " Style: chunky\n"
00183 " Pi: 1.1\n"
00184 " Offset: {X: 1, Y: 2, Z: 3}\n"
00185 " Color: 10; 20; 30"
00186 )
00187 , out.c_str() );
00188 }
00189
00190 TEST( DisplayFactory, class_name )
00191 {
00192 std::stringstream input(
00193 "Displays:\n"
00194 " -\n"
00195 " Class: MockDisplay\n"
00196 );
00197
00198 YAML::Parser parser( input );
00199 YAML::Node node;
00200 parser.GetNextDocument( node );
00201
00202 MockContext context;
00203
00204 DisplayGroup g;
00205 g.initialize( &context );
00206 g.load( node );
00207
00208 EXPECT_EQ( 1, g.numChildren() );
00209 EXPECT_EQ( "MockDisplay", g.getDisplayAt( 0 )->getClassId().toStdString() );
00210 }
00211
00212 TEST( DisplayFactory, failed_display )
00213 {
00214 std::stringstream input(
00215 "Displays:\n"
00216 " - Class: MissingDisplay\n"
00217 " Name: Chubbers\n"
00218 " NumLemurs: 77\n"
00219 " LemurStyle: chunky\n"
00220 " SubYaml:\n"
00221 " - 1\n"
00222 " - foo: bar\n"
00223 " food: bard\n"
00224 );
00225
00226 YAML::Parser parser( input );
00227 YAML::Node node;
00228 parser.GetNextDocument( node );
00229
00230 MockContext context;
00231
00232 DisplayGroup g;
00233 g.initialize( &context );
00234 g.load( node );
00235
00236 EXPECT_EQ( 1, g.numChildren() );
00237 EXPECT_EQ( "MissingDisplay", g.getDisplayAt( 0 )->getClassId().toStdString() );
00238 EXPECT_EQ( 0, g.getDisplayAt( 0 )->numChildren() );
00239
00240
00241
00242 YAML::Emitter out;
00243 g.save( out );
00244 EXPECT_EQ( std::string(
00245 "Class: \"\"\n"
00246 "Name: \"\"\n"
00247 "Enabled: false\n"
00248 "Displays:\n"
00249 " - Class: MissingDisplay\n"
00250 " LemurStyle: chunky\n"
00251 " Name: Chubbers\n"
00252 " NumLemurs: 77\n"
00253 " SubYaml:\n"
00254 " - 1\n"
00255 " - foo: bar\n"
00256 " food: bard"
00257 )
00258 , out.c_str() );
00259 }
00260
00261 int main( int argc, char **argv ) {
00262 ros::init( argc, argv, "test", ros::init_options::AnonymousName );
00263 testing::InitGoogleTest( &argc, argv );
00264 return RUN_ALL_TESTS();
00265 }