@@ -32,16 +32,16 @@ TEST(ErrorOutput, ParamErrorOutput)
32
32
{
33
33
std::stringstream buffer;
34
34
sdf::testing::RedirectConsoleStream redir (
35
- sdf::Console::Instance ()->GetMsgStream (), &buffer);
35
+ sdf::Console::Instance ()->GetMsgStream (), &buffer);
36
36
37
37
sdf::Errors errors;
38
38
ASSERT_NO_THROW (sdf::Param param1 (" key" , " not_valid_type" , " true" , false ,
39
- errors, " description" ));
39
+ errors, " description" ));
40
40
ASSERT_GE (2u , errors.size ());
41
41
EXPECT_EQ (errors[0 ].Code (), sdf::ErrorCode::UNKNOWN_PARAMETER_TYPE);
42
42
EXPECT_NE (std::string::npos,
43
43
errors[0 ].Message ().find (
44
- " Unknown parameter type[not_valid_type]" ));
44
+ " Unknown parameter type[not_valid_type]" ));
45
45
EXPECT_EQ (errors[1 ].Code (), sdf::ErrorCode::PARAMETER_ERROR);
46
46
EXPECT_NE (std::string::npos,
47
47
errors[1 ].Message ().find (" Invalid parameter" ));
@@ -52,10 +52,10 @@ TEST(ErrorOutput, ParamErrorOutput)
52
52
ASSERT_GE (2u , errors.size ());
53
53
EXPECT_EQ (errors[0 ].Code (), sdf::ErrorCode::UNKNOWN_PARAMETER_TYPE);
54
54
EXPECT_NE (std::string::npos,
55
- errors[0 ].Message ().find (" Unknown parameter type[not_valid_type]" ));
55
+ errors[0 ].Message ().find (" Unknown parameter type[not_valid_type]" ));
56
56
EXPECT_EQ (errors[1 ].Code (), sdf::ErrorCode::PARAMETER_ERROR);
57
57
EXPECT_NE (std::string::npos,
58
- errors[1 ].Message ().find (" Invalid parameter" ));
58
+ errors[1 ].Message ().find (" Invalid parameter" ));
59
59
60
60
errors.clear ();
61
61
sdf::Param param3 (" key" , " bool" , " true" , false , errors, " description" );
@@ -73,15 +73,15 @@ TEST(ErrorOutput, ParamErrorOutput)
73
73
ASSERT_GE (errors.size (), 1u );
74
74
EXPECT_EQ (errors[0 ].Code (), sdf::ErrorCode::PARAMETER_ERROR);
75
75
EXPECT_NE (std::string::npos, errors[0 ].Message ().find (
76
- " The value for //pose[@rotation_format='euler_rpy'] must have 6 "
77
- " values, but 1 were found instead in '1'." ));
76
+ " The value for //pose[@rotation_format='euler_rpy'] must have 6 "
77
+ " values, but 1 were found instead in '1'." ));
78
78
79
79
errors.clear ();
80
80
param3.Update (errors);
81
81
ASSERT_GE (errors.size (), 1u );
82
82
EXPECT_EQ (errors[0 ].Code (), sdf::ErrorCode::PARAMETER_ERROR);
83
83
EXPECT_NE (std::string::npos, errors[0 ].Message ().find (
84
- " [updateFunc] is not set." ));
84
+ " [updateFunc] is not set." ));
85
85
86
86
errors.clear ();
87
87
sdf::Param requiredParam (" key" , " int" , " 1" , true , " 2" , " 4" , errors,
@@ -92,14 +92,13 @@ TEST(ErrorOutput, ParamErrorOutput)
92
92
ASSERT_GE (errors.size (), 1u );
93
93
EXPECT_EQ (errors[0 ].Code (), sdf::ErrorCode::PARAMETER_ERROR);
94
94
EXPECT_NE (std::string::npos, errors[0 ].Message ().find (
95
- " Empty string used when setting a required parameter. Key[key]" ));
95
+ " Empty string used when setting a required parameter. Key[key]" ));
96
96
EXPECT_FALSE (requiredParam.ValidateValue (errors));
97
97
ASSERT_GE (errors.size (), 2u );
98
98
EXPECT_EQ (errors[1 ].Code (), sdf::ErrorCode::PARAMETER_ERROR);
99
99
EXPECT_NE (std::string::npos, errors[1 ].Message ().find (
100
- " The value [1] is less than the minimum allowed value of [2] for "
101
- " key [key]" ));
102
-
100
+ " The value [1] is less than the minimum allowed value of [2] for "
101
+ " key [key]" ));
103
102
104
103
errors.clear ();
105
104
// Adding a parent with @rotation_format to something invalid
@@ -111,37 +110,37 @@ TEST(ErrorOutput, ParamErrorOutput)
111
110
ASSERT_EQ (errors.size (), 2u );
112
111
EXPECT_EQ (errors[0 ].Code (), sdf::ErrorCode::PARAMETER_ERROR);
113
112
EXPECT_NE (std::string::npos, errors[0 ].Message ().find (
114
- " Undefined attribute //pose[@rotation_format='invalid_format'], "
115
- " only 'euler_rpy' and 'quat_xyzw' is supported." ));
113
+ " Undefined attribute //pose[@rotation_format='invalid_format'], "
114
+ " only 'euler_rpy' and 'quat_xyzw' is supported." ));
116
115
EXPECT_EQ (errors[1 ].Code (), sdf::ErrorCode::PARAMETER_ERROR);
117
116
EXPECT_NE (std::string::npos, errors[1 ].Message ().find (
118
- " Failed to set value '1 2 3 0.40000000000000002 0.5 "
119
- " 0.59999999999999987' to key [] for new parent element of name '',"
120
- " reverting to previous value '1 2 3 0.40000000000000002 0.5 "
121
- " 0.59999999999999987'." ));
117
+ " Failed to set value '1 2 3 0.40000000000000002 0.5 "
118
+ " 0.59999999999999987' to key [] for new parent element of name '',"
119
+ " reverting to previous value '1 2 3 0.40000000000000002 0.5 "
120
+ " 0.59999999999999987'." ));
122
121
123
122
errors.clear ();
124
123
sdf::Param param4 (" key" , " bool" , " 15" , false , " a" , " b" , errors,
125
124
" description" );
126
125
ASSERT_EQ (errors.size (), 6u );
127
126
EXPECT_EQ (errors[0 ].Code (), sdf::ErrorCode::PARAMETER_ERROR);
128
127
EXPECT_NE (std::string::npos, errors[0 ].Message ().find (
129
- " Invalid boolean value" ));
128
+ " Invalid boolean value" ));
130
129
EXPECT_EQ (errors[1 ].Code (), sdf::ErrorCode::PARAMETER_ERROR);
131
130
EXPECT_NE (std::string::npos, errors[1 ].Message ().find (
132
- " Invalid parameter" ));
131
+ " Invalid parameter" ));
133
132
EXPECT_EQ (errors[2 ].Code (), sdf::ErrorCode::PARAMETER_ERROR);
134
133
EXPECT_NE (std::string::npos, errors[2 ].Message ().find (
135
- " Invalid boolean value" ));
134
+ " Invalid boolean value" ));
136
135
EXPECT_EQ (errors[3 ].Code (), sdf::ErrorCode::PARAMETER_ERROR);
137
136
EXPECT_NE (std::string::npos, errors[3 ].Message ().find (
138
- " Invalid [min] parameter in SDFormat description of [key]" ));
137
+ " Invalid [min] parameter in SDFormat description of [key]" ));
139
138
EXPECT_EQ (errors[4 ].Code (), sdf::ErrorCode::PARAMETER_ERROR);
140
139
EXPECT_NE (std::string::npos, errors[4 ].Message ().find (
141
- " Invalid boolean value" ));
140
+ " Invalid boolean value" ));
142
141
EXPECT_EQ (errors[5 ].Code (), sdf::ErrorCode::PARAMETER_ERROR);
143
142
EXPECT_NE (std::string::npos, errors[5 ].Message ().find (
144
- " Invalid [max] parameter in SDFormat description of [key]" ));
143
+ " Invalid [max] parameter in SDFormat description of [key]" ));
145
144
146
145
// Check nothing has been printed
147
146
EXPECT_TRUE (buffer.str ().empty ()) << buffer.str ();
@@ -153,7 +152,7 @@ TEST(ErrorOutput, ElementErrorOutput)
153
152
{
154
153
std::stringstream buffer;
155
154
sdf::testing::RedirectConsoleStream redir (
156
- sdf::Console::Instance ()->GetMsgStream (), &buffer);
155
+ sdf::Console::Instance ()->GetMsgStream (), &buffer);
157
156
158
157
sdf::Errors errors;
159
158
sdf::ElementPtr elem = std::make_shared<sdf::Element>();
@@ -163,59 +162,84 @@ TEST(ErrorOutput, ElementErrorOutput)
163
162
ASSERT_EQ (errors.size (), 1u );
164
163
EXPECT_EQ (errors[0 ].Code (), sdf::ErrorCode::ELEMENT_ERROR);
165
164
EXPECT_NE (std::string::npos, errors[0 ].Message ().find (
166
- " Unable to find value for key [test]" ));
165
+ " Unable to find value for key [test]" ));
167
166
168
167
errors.clear ();
169
168
elem->GetElement (" missingElement" , errors);
170
169
ASSERT_EQ (errors.size (), 1u );
171
170
EXPECT_NE (std::string::npos, errors[0 ].Message ().find (
172
- " Missing element description for [missingElement]" ));
171
+ " Missing element description for [missingElement]" ));
173
172
174
173
errors.clear ();
175
174
elem->AddAttribute (
176
- " invalidAttribute" , " int" , " invalidFormat" , false , errors);
175
+ " invalidAttribute" , " int" , " invalidFormat" , false , errors);
177
176
ASSERT_EQ (errors.size (), 2u );
178
177
EXPECT_NE (std::string::npos, errors[0 ].Message ().find (
179
- " Invalid argument. Unable to set value [invalidFormat]"
180
- " for key[invalidAttribute]" ));
178
+ " Invalid argument. Unable to set value [invalidFormat]"
179
+ " for key[invalidAttribute]" ));
181
180
EXPECT_NE (std::string::npos, errors[1 ].Message ().find (
182
- " Invalid parameter" ));
181
+ " Invalid parameter" ));
183
182
184
183
errors.clear ();
185
184
elem->AddValue (" type" , " value" , true , " a" , " b" , errors);
186
185
ASSERT_EQ (errors.size (), 9u );
187
186
EXPECT_NE (std::string::npos, errors[0 ].Message ().find (
188
- " Unknown parameter type[type]" ));
187
+ " Unknown parameter type[type]" ));
189
188
EXPECT_NE (std::string::npos, errors[1 ].Message ().find (
190
- " Invalid parameter" ));
189
+ " Invalid parameter" ));
191
190
EXPECT_NE (std::string::npos, errors[2 ].Message ().find (
192
- " Unknown parameter type[type]" ));
191
+ " Unknown parameter type[type]" ));
193
192
EXPECT_NE (std::string::npos, errors[3 ].Message ().find (
194
- " Invalid [min] parameter in SDFormat description of [testElement]" ));
193
+ " Invalid [min] parameter in SDFormat description of [testElement]" ));
195
194
EXPECT_NE (std::string::npos, errors[4 ].Message ().find (
196
- " Unknown parameter type[type]" ));
195
+ " Unknown parameter type[type]" ));
197
196
EXPECT_NE (std::string::npos, errors[5 ].Message ().find (
198
- " Invalid [max] parameter in SDFormat description of [testElement]" ));
197
+ " Invalid [max] parameter in SDFormat description of [testElement]" ));
199
198
EXPECT_NE (std::string::npos, errors[6 ].Message ().find (
200
- " Unknown parameter type[type]" ));
199
+ " Unknown parameter type[type]" ));
201
200
EXPECT_NE (std::string::npos, errors[7 ].Message ().find (
202
- " Failed to set value '0' to key [testElement] for new parent element"
203
- " of name 'testElement', reverting to previous value '0'." ));
201
+ " Failed to set value '0' to key [testElement] for new parent element"
202
+ " of name 'testElement', reverting to previous value '0'." ));
204
203
EXPECT_NE (std::string::npos, errors[8 ].Message ().find (
205
- " Cannot set parent Element of value to itself." ));
204
+ " Cannot set parent Element of value to itself." ));
206
205
errors.clear ();
207
206
208
207
elem->GetElement (" nonExistentElement" , errors);
209
208
ASSERT_EQ (errors.size (), 1u );
210
209
EXPECT_NE (std::string::npos, errors[0 ].Message ().find (
211
- " Missing element description for [nonExistentElement]" ));
210
+ " Missing element description for [nonExistentElement]" ));
212
211
errors.clear ();
213
212
214
213
elem->RemoveChild (sdf::ElementPtr (), errors);
215
214
ASSERT_EQ (errors.size (), 1u );
216
215
EXPECT_NE (std::string::npos, errors[0 ].Message ().find (
217
- " Cannot remove a nullptr child pointer" ));
216
+ " Cannot remove a nullptr child pointer" ));
217
+ // Check nothing has been printed
218
+ EXPECT_TRUE (buffer.str ().empty ()) << buffer.str ();
219
+ }
218
220
221
+ // //////////////////////////////////////
222
+ // Test PrintConfig class for sdf::Errors outputs
223
+ TEST (ErrorOutput, PrintConfigErrorOutput)
224
+ {
225
+ std::stringstream buffer;
226
+ sdf::testing::RedirectConsoleStream redir (
227
+ sdf::Console::Instance ()->GetMsgStream (), &buffer);
228
+
229
+ sdf::Errors errors;
230
+ sdf::PrintConfig printConfig;
231
+ ASSERT_FALSE (printConfig.SetRotationSnapToDegrees (361 , 300 , errors));
232
+ ASSERT_EQ (errors.size (), 1u );
233
+ EXPECT_NE (std::string::npos, errors[0 ].Message ().find (
234
+ " Interval value to snap to must be larger than 0,"
235
+ " and less than or equal to 360." ));
236
+ errors.clear ();
237
+
238
+ ASSERT_FALSE (printConfig.SetRotationSnapToDegrees (300 , 300 , errors));
239
+ ASSERT_EQ (errors.size (), 1u );
240
+ EXPECT_NE (std::string::npos, errors[0 ].Message ().find (
241
+ " Tolerance must be larger than 0, less than or equal to 360, "
242
+ " and less than the provided interval." ));
219
243
// Check nothing has been printed
220
244
EXPECT_TRUE (buffer.str ().empty ()) << buffer.str ();
221
245
}
0 commit comments