Skip to content

Commit 6171f6f

Browse files
committed
add unit test for the sequence case
1 parent f4480c7 commit 6171f6f

3 files changed

Lines changed: 100 additions & 8 deletions

File tree

tests/encoder_decoder_test.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,38 @@ TEST_CASE("simple optional field with default value encoder/decoder","[optional_
245245
REQUIRE(test_case.decoding("\xD0\x86\x82",test_6.cref(),true));
246246
}
247247
}
248+
249+
TEST_CASE("sequence optional with constant length encoder/decoder","[optional_sequence_with_constant_length_encoder_decoder]")
250+
{
251+
fast_test_coding_case<simple12::templates_description> test_case;
252+
253+
SECTION("encode fields without sequence")
254+
{
255+
simple12::Test_7 test_7;
256+
simple12::Test_7_mref test_7_mref = test_7.mref();
257+
test_7_mref.set_field_7_1().as(1);
258+
REQUIRE(test_case.encoding(test_7.cref(),"\xE0\x87\x82",true));
259+
REQUIRE(test_case.decoding("\xE0\x87\x82",test_7.cref(),true));
260+
}
261+
262+
SECTION("encode fields with sequence")
263+
{
264+
simple12::Test_7 test_7;
265+
simple12::Test_7_mref test_7_mref = test_7.mref();
266+
test_7_mref.set_field_7_1().as(1);
267+
268+
{
269+
auto sequence_7_mref = test_7_mref.set_sequence_7();
270+
sequence_7_mref.resize(1);
271+
272+
{
273+
auto element_sequence = sequence_7_mref.front();
274+
element_sequence.set_field_7_4().as(1);
275+
element_sequence.set_field_7_5().as(1);
276+
}
277+
}
278+
279+
REQUIRE(test_case.encoding(test_7.cref(),"\xF0\x87\x82\xa0\x82\x82",true));
280+
REQUIRE(test_case.decoding("\xF0\x87\x82\xa0\x82\x82",test_7.cref(),true));
281+
}
282+
}

tests/encoder_decoder_test_v2.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ TEST_CASE("simple field and sequence optional encoder_v2/decoder_v2","[field_seq
2222
// 1 : Set Template Id.
2323
// 1 : Set Field field_1_1
2424
// 0 : XXX
25-
REQUIRE(test_case.encoding(test_1.cref(),"\xE0\x81\x82\x81",true));
25+
REQUIRE(test_case.encoding(test_1.cref(),"\xE0\x81\x82\x80",true));
2626
REQUIRE(test_case.decoding("\xE0\x81\x82\x80",test_1.cref(),true));
2727
}
2828

@@ -246,3 +246,38 @@ TEST_CASE("simple optional field with default value encoder_v2/decoder_v2","[opt
246246
REQUIRE(test_case.decoding("\xD0\x86\x82",test_6.cref(),true));
247247
}
248248
}
249+
250+
TEST_CASE("sequence optional with constant length encoder_v2/decoder_v2","[optional_sequence_with_constant_length_encoder_v2/decoder_v2]")
251+
{
252+
fast_test_coding_case_v2<simple12::templates_description> test_case;
253+
254+
SECTION("encode fields without sequence")
255+
{
256+
simple12::Test_7 test_7;
257+
simple12::Test_7_mref test_7_mref = test_7.mref();
258+
test_7_mref.set_field_7_1().as(1);
259+
REQUIRE(test_case.encoding(test_7.cref(),"\xE0\x87\x82",true));
260+
REQUIRE(test_case.decoding("\xE0\x87\x82",test_7.cref(),true));
261+
}
262+
263+
SECTION("encode fields with sequence")
264+
{
265+
simple12::Test_7 test_7;
266+
simple12::Test_7_mref test_7_mref = test_7.mref();
267+
test_7_mref.set_field_7_1().as(1);
268+
269+
{
270+
auto sequence_7_mref = test_7_mref.set_sequence_7();
271+
sequence_7_mref.resize(1);
272+
273+
{
274+
auto element_sequence = sequence_7_mref.front();
275+
element_sequence.set_field_7_4().as(1);
276+
element_sequence.set_field_7_5().as(1);
277+
}
278+
}
279+
280+
REQUIRE(test_case.encoding(test_7.cref(),"\xF0\x87\x82\xa0\x82\x82",true));
281+
REQUIRE(test_case.decoding("\xF0\x87\x82\xa0\x82\x82",test_7.cref(),true));
282+
}
283+
}

tests/simple12.xml

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
<template name="Test_1" id="1">
44
<uInt32 name="field_1_1" id="11" presence="optional"><copy/></uInt32>
55
<sequence name="sequence_1" presence="optional">
6-
<uInt32 name="field_1_2" id="12" presence="optional"></uInt32>
7-
<uInt32 name="field_1_3" id="13" presence="optional"></uInt32>
6+
<length name="num_elements" id="12"/>
7+
<uInt32 name="field_1_2" id="13" presence="optional"></uInt32>
8+
<uInt32 name="field_1_3" id="14" presence="optional"></uInt32>
89
</sequence>
910
</template>
1011
<template name="Test_2" id="2">
@@ -14,8 +15,9 @@
1415
<template name="Test_3" id="3">
1516
<uInt32 name="field_3_1" id="31"><copy/></uInt32>
1617
<sequence name="sequence_3">
17-
<uInt32 name="field_3_2" id="32"></uInt32>
18-
<uInt32 name="field_3_3" id="33"></uInt32>
18+
<length name="num_elements" id="32"/>
19+
<uInt32 name="field_3_2" id="33"></uInt32>
20+
<uInt32 name="field_3_3" id="34"></uInt32>
1921
</sequence>
2022
</template>
2123
<template name="Test_4" id="4">
@@ -26,10 +28,11 @@
2628
<uInt32 name="field_5_1" id="51" presence="optional"><copy/></uInt32>
2729
<group name="test_5_group" presence="optional">
2830
<sequence name="sequence_5">
29-
<uInt32 name="field_5_2" id="52"></uInt32>
30-
<uInt32 name="field_5_3" id="53"></uInt32>
31+
<length name="num_elements" id="52"/>
32+
<uInt32 name="field_5_2" id="53"></uInt32>
33+
<uInt32 name="field_5_3" id="54"></uInt32>
3134
</sequence>
32-
<uInt32 name="field_5_5" id="54" presence="optional"><copy/></uInt32>
35+
<uInt32 name="field_5_5" id="55" presence="optional"><copy/></uInt32>
3336
</group>
3437
</template>
3538
<template name="Test_6" id="6">
@@ -43,4 +46,23 @@
4346
<default value="1"/>
4447
</uInt32>
4548
</template>
49+
<template name="Test_7" id="7">
50+
<uInt32 name="field_7_1" id="71" presence="optional">
51+
<copy/>
52+
</uInt32>
53+
<sequence name="sequence_7" presence="optional">
54+
<length name="num_elements" id="72">
55+
<constant value="1"/>
56+
</length>
57+
<uInt32 name="field_7_3" id="73">
58+
<default value="0"/>
59+
</uInt32>
60+
<uInt32 name="field_7_4" id="74" presence="optional">
61+
<delta/>
62+
</uInt32>
63+
<uInt32 name="field_7_5" id="75" presence="optional">
64+
<copy/>
65+
</uInt32>
66+
</sequence>
67+
</template>
4668
</templates>

0 commit comments

Comments
 (0)