Skip to content

Commit 4b7f789

Browse files
committed
Remove setting of SERIALIZED_MEMBER_SIZE when serializing vector of booleans as array (#332)
* Fix Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev> * Fix uncrustify Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev> --------- Signed-off-by: Ricardo González Moreno <ricardo@richiware.dev> (cherry picked from commit 4f983f2)
1 parent 8cc6088 commit 4b7f789

2 files changed

Lines changed: 72 additions & 7 deletions

File tree

src/cpp/Cdr.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ Cdr& Cdr::read_encapsulation()
263263
}
264264
break;
265265
default:
266-
throw BadParamException("Unexpected encoding algorithm received in Cdr::read_encapsulation for DDS CDR");
266+
throw BadParamException(
267+
"Unexpected encoding algorithm received in Cdr::read_encapsulation for DDS CDR");
267268
}
268269
reset_callbacks();
269270

@@ -2209,11 +2210,6 @@ Cdr& Cdr::serialize_bool_array(
22092210
throw NotEnoughMemoryException(NotEnoughMemoryException::NOT_ENOUGH_MEMORY_MESSAGE_DEFAULT);
22102211
}
22112212

2212-
if (CdrVersion::XCDRv2 == cdr_version_)
2213-
{
2214-
serialized_member_size_ = SERIALIZED_MEMBER_SIZE;
2215-
}
2216-
22172213
return *this;
22182214
}
22192215

test/cdr/array_as_std_vector.cpp

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using XCdrStreamValues =
2525
std::array<std::vector<uint8_t>,
2626
1 + EncodingAlgorithmFlag::PL_CDR2 + Cdr::Endianness::LITTLE_ENDIANNESS>;
2727

28-
class CdrArrayAsSTDVectorTest : public ::testing::TestWithParam< std::tuple<EncodingAlgorithmFlag, Cdr::Endianness>>
28+
class CdrArrayAsSTDVectorTest : public ::testing::TestWithParam<std::tuple<EncodingAlgorithmFlag, Cdr::Endianness>>
2929
{
3030
};
3131

@@ -266,6 +266,75 @@ TEST_P(CdrArrayAsSTDVectorTest, array_ulong_as_std_vector)
266266
serialize_array(expected_streams, encoding, endianness, array_value);
267267
}
268268

269+
/*!
270+
* @test Test an array of boolean type stored in a std::vector.
271+
*/
272+
TEST_P(CdrArrayAsSTDVectorTest, array_bool_as_std_vector)
273+
{
274+
const std::vector<bool> array_value {true, false};
275+
constexpr uint8_t tval {0x01};
276+
constexpr uint8_t fval {0x00};
277+
278+
//{ Defining expected XCDR streams
279+
XCdrStreamValues expected_streams;
280+
expected_streams[0 + EncodingAlgorithmFlag::PLAIN_CDR + Cdr::Endianness::BIG_ENDIANNESS] =
281+
{
282+
0x00, 0x00, 0x00, 0x00, // Encapsulation
283+
tval, fval // Boolean
284+
};
285+
expected_streams[0 + EncodingAlgorithmFlag::PLAIN_CDR + Cdr::Endianness::LITTLE_ENDIANNESS] =
286+
{
287+
0x00, 0x01, 0x00, 0x00, // Encapsulation
288+
tval, fval // Boolean
289+
};
290+
expected_streams[0 + EncodingAlgorithmFlag::PL_CDR + Cdr::Endianness::BIG_ENDIANNESS] =
291+
{
292+
0x00, 0x02, 0x00, 0x00, // Encapsulation
293+
tval, fval // Boolean
294+
};
295+
expected_streams[0 + EncodingAlgorithmFlag::PL_CDR + Cdr::Endianness::LITTLE_ENDIANNESS] =
296+
{
297+
0x00, 0x03, 0x00, 0x00, // Encapsulation
298+
tval, fval // Boolean
299+
};
300+
expected_streams[0 + EncodingAlgorithmFlag::PLAIN_CDR2 + Cdr::Endianness::BIG_ENDIANNESS] =
301+
{
302+
0x00, 0x06, 0x00, 0x00, // Encapsulation
303+
tval, fval // Boolean
304+
};
305+
expected_streams[0 + EncodingAlgorithmFlag::PLAIN_CDR2 + Cdr::Endianness::LITTLE_ENDIANNESS] =
306+
{
307+
0x00, 0x07, 0x00, 0x00, // Encapsulation
308+
tval, fval // Boolean
309+
};
310+
expected_streams[0 + EncodingAlgorithmFlag::DELIMIT_CDR2 + Cdr::Endianness::BIG_ENDIANNESS] =
311+
{
312+
0x00, 0x08, 0x00, 0x00, // Encapsulation
313+
tval, fval // Boolean
314+
};
315+
expected_streams[0 + EncodingAlgorithmFlag::DELIMIT_CDR2 + Cdr::Endianness::LITTLE_ENDIANNESS] =
316+
{
317+
0x00, 0x09, 0x00, 0x00, // Encapsulation
318+
tval, fval // Boolean
319+
};
320+
expected_streams[0 + EncodingAlgorithmFlag::PL_CDR2 + Cdr::Endianness::BIG_ENDIANNESS] =
321+
{
322+
0x00, 0x0A, 0x00, 0x00, // Encapsulation
323+
tval, fval // Boolean
324+
};
325+
expected_streams[0 + EncodingAlgorithmFlag::PL_CDR2 + Cdr::Endianness::LITTLE_ENDIANNESS] =
326+
{
327+
0x00, 0x0B, 0x00, 0x00, // Encapsulation
328+
tval, fval // Boolean
329+
};
330+
//}
331+
332+
EncodingAlgorithmFlag encoding = std::get<0>(GetParam());
333+
Cdr::Endianness endianness = std::get<1>(GetParam());
334+
335+
serialize_array(expected_streams, encoding, endianness, array_value);
336+
}
337+
269338
/*!
270339
* @test Test an array of struct type stored in a std::vector.
271340
* @code{.idl}

0 commit comments

Comments
 (0)