@@ -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,8 +110,8 @@ 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
#if !defined __ARM_ARCH
118
117
EXPECT_NE (std::string::npos, errors[1 ].Message ().find (
@@ -128,22 +127,22 @@ TEST(ErrorOutput, ParamErrorOutput)
128
127
ASSERT_EQ (errors.size (), 6u );
129
128
EXPECT_EQ (errors[0 ].Code (), sdf::ErrorCode::PARAMETER_ERROR);
130
129
EXPECT_NE (std::string::npos, errors[0 ].Message ().find (
131
- " Invalid boolean value" ));
130
+ " Invalid boolean value" ));
132
131
EXPECT_EQ (errors[1 ].Code (), sdf::ErrorCode::PARAMETER_ERROR);
133
132
EXPECT_NE (std::string::npos, errors[1 ].Message ().find (
134
- " Invalid parameter" ));
133
+ " Invalid parameter" ));
135
134
EXPECT_EQ (errors[2 ].Code (), sdf::ErrorCode::PARAMETER_ERROR);
136
135
EXPECT_NE (std::string::npos, errors[2 ].Message ().find (
137
- " Invalid boolean value" ));
136
+ " Invalid boolean value" ));
138
137
EXPECT_EQ (errors[3 ].Code (), sdf::ErrorCode::PARAMETER_ERROR);
139
138
EXPECT_NE (std::string::npos, errors[3 ].Message ().find (
140
- " Invalid [min] parameter in SDFormat description of [key]" ));
139
+ " Invalid [min] parameter in SDFormat description of [key]" ));
141
140
EXPECT_EQ (errors[4 ].Code (), sdf::ErrorCode::PARAMETER_ERROR);
142
141
EXPECT_NE (std::string::npos, errors[4 ].Message ().find (
143
- " Invalid boolean value" ));
142
+ " Invalid boolean value" ));
144
143
EXPECT_EQ (errors[5 ].Code (), sdf::ErrorCode::PARAMETER_ERROR);
145
144
EXPECT_NE (std::string::npos, errors[5 ].Message ().find (
146
- " Invalid [max] parameter in SDFormat description of [key]" ));
145
+ " Invalid [max] parameter in SDFormat description of [key]" ));
147
146
148
147
// Check nothing has been printed
149
148
EXPECT_TRUE (buffer.str ().empty ()) << buffer.str ();
@@ -155,7 +154,7 @@ TEST(ErrorOutput, ElementErrorOutput)
155
154
{
156
155
std::stringstream buffer;
157
156
sdf::testing::RedirectConsoleStream redir (
158
- sdf::Console::Instance ()->GetMsgStream (), &buffer);
157
+ sdf::Console::Instance ()->GetMsgStream (), &buffer);
159
158
160
159
sdf::Errors errors;
161
160
sdf::ElementPtr elem = std::make_shared<sdf::Element>();
@@ -165,59 +164,84 @@ TEST(ErrorOutput, ElementErrorOutput)
165
164
ASSERT_EQ (errors.size (), 1u );
166
165
EXPECT_EQ (errors[0 ].Code (), sdf::ErrorCode::ELEMENT_ERROR);
167
166
EXPECT_NE (std::string::npos, errors[0 ].Message ().find (
168
- " Unable to find value for key [test]" ));
167
+ " Unable to find value for key [test]" ));
169
168
170
169
errors.clear ();
171
170
elem->GetElement (" missingElement" , errors);
172
171
ASSERT_EQ (errors.size (), 1u );
173
172
EXPECT_NE (std::string::npos, errors[0 ].Message ().find (
174
- " Missing element description for [missingElement]" ));
173
+ " Missing element description for [missingElement]" ));
175
174
176
175
errors.clear ();
177
176
elem->AddAttribute (
178
- " invalidAttribute" , " int" , " invalidFormat" , false , errors);
177
+ " invalidAttribute" , " int" , " invalidFormat" , false , errors);
179
178
ASSERT_EQ (errors.size (), 2u );
180
179
EXPECT_NE (std::string::npos, errors[0 ].Message ().find (
181
- " Invalid argument. Unable to set value [invalidFormat]"
182
- " for key[invalidAttribute]" ));
180
+ " Invalid argument. Unable to set value [invalidFormat]"
181
+ " for key[invalidAttribute]" ));
183
182
EXPECT_NE (std::string::npos, errors[1 ].Message ().find (
184
- " Invalid parameter" ));
183
+ " Invalid parameter" ));
185
184
186
185
errors.clear ();
187
186
elem->AddValue (" type" , " value" , true , " a" , " b" , errors);
188
187
ASSERT_EQ (errors.size (), 9u );
189
188
EXPECT_NE (std::string::npos, errors[0 ].Message ().find (
190
- " Unknown parameter type[type]" ));
189
+ " Unknown parameter type[type]" ));
191
190
EXPECT_NE (std::string::npos, errors[1 ].Message ().find (
192
- " Invalid parameter" ));
191
+ " Invalid parameter" ));
193
192
EXPECT_NE (std::string::npos, errors[2 ].Message ().find (
194
- " Unknown parameter type[type]" ));
193
+ " Unknown parameter type[type]" ));
195
194
EXPECT_NE (std::string::npos, errors[3 ].Message ().find (
196
- " Invalid [min] parameter in SDFormat description of [testElement]" ));
195
+ " Invalid [min] parameter in SDFormat description of [testElement]" ));
197
196
EXPECT_NE (std::string::npos, errors[4 ].Message ().find (
198
- " Unknown parameter type[type]" ));
197
+ " Unknown parameter type[type]" ));
199
198
EXPECT_NE (std::string::npos, errors[5 ].Message ().find (
200
- " Invalid [max] parameter in SDFormat description of [testElement]" ));
199
+ " Invalid [max] parameter in SDFormat description of [testElement]" ));
201
200
EXPECT_NE (std::string::npos, errors[6 ].Message ().find (
202
- " Unknown parameter type[type]" ));
201
+ " Unknown parameter type[type]" ));
203
202
EXPECT_NE (std::string::npos, errors[7 ].Message ().find (
204
- " Failed to set value '0' to key [testElement] for new parent element"
205
- " of name 'testElement', reverting to previous value '0'." ));
203
+ " Failed to set value '0' to key [testElement] for new parent element"
204
+ " of name 'testElement', reverting to previous value '0'." ));
206
205
EXPECT_NE (std::string::npos, errors[8 ].Message ().find (
207
- " Cannot set parent Element of value to itself." ));
206
+ " Cannot set parent Element of value to itself." ));
208
207
errors.clear ();
209
208
210
209
elem->GetElement (" nonExistentElement" , errors);
211
210
ASSERT_EQ (errors.size (), 1u );
212
211
EXPECT_NE (std::string::npos, errors[0 ].Message ().find (
213
- " Missing element description for [nonExistentElement]" ));
212
+ " Missing element description for [nonExistentElement]" ));
214
213
errors.clear ();
215
214
216
215
elem->RemoveChild (sdf::ElementPtr (), errors);
217
216
ASSERT_EQ (errors.size (), 1u );
218
217
EXPECT_NE (std::string::npos, errors[0 ].Message ().find (
219
- " Cannot remove a nullptr child pointer" ));
218
+ " Cannot remove a nullptr child pointer" ));
219
+ // Check nothing has been printed
220
+ EXPECT_TRUE (buffer.str ().empty ()) << buffer.str ();
221
+ }
220
222
223
+ // //////////////////////////////////////
224
+ // Test PrintConfig class for sdf::Errors outputs
225
+ TEST (ErrorOutput, PrintConfigErrorOutput)
226
+ {
227
+ std::stringstream buffer;
228
+ sdf::testing::RedirectConsoleStream redir (
229
+ sdf::Console::Instance ()->GetMsgStream (), &buffer);
230
+
231
+ sdf::Errors errors;
232
+ sdf::PrintConfig printConfig;
233
+ ASSERT_FALSE (printConfig.SetRotationSnapToDegrees (361 , 300 , errors));
234
+ ASSERT_EQ (errors.size (), 1u );
235
+ EXPECT_NE (std::string::npos, errors[0 ].Message ().find (
236
+ " Interval value to snap to must be larger than 0,"
237
+ " and less than or equal to 360." ));
238
+ errors.clear ();
239
+
240
+ ASSERT_FALSE (printConfig.SetRotationSnapToDegrees (300 , 300 , errors));
241
+ ASSERT_EQ (errors.size (), 1u );
242
+ EXPECT_NE (std::string::npos, errors[0 ].Message ().find (
243
+ " Tolerance must be larger than 0, less than or equal to 360, "
244
+ " and less than the provided interval." ));
221
245
// Check nothing has been printed
222
246
EXPECT_TRUE (buffer.str ().empty ()) << buffer.str ();
223
247
}
0 commit comments