Skip to content

Commit 3722572

Browse files
committed
Generate unit test for the grup case
1 parent ffe69eb commit 3722572

6 files changed

+125
-14
lines changed

Diff for: tests/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ FASTTYPEGEN_TARGET(simple_types9 simple9.xml)
2121
FASTTYPEGEN_TARGET(simple_types10 simple10.xml)
2222
FASTTYPEGEN_TARGET(simple_types11 simple11.xml)
2323
FASTTYPEGEN_TARGET(simple_types12 simple12.xml)
24+
FASTTYPEGEN_TARGET(simple_types13 simple13.xml)
2425

2526

2627
FASTTYPEGEN_TARGET(test_types1 test1.xml test2.xml)
@@ -41,6 +42,8 @@ add_executable (mfast_test
4142
encoder_decoder_test.cpp
4243
encoder_decoder_test_v2.cpp
4344
field_comparator_test.cpp
45+
group_encoder_decoder_v2.cpp
46+
group_encoder_decoder.cpp
4447
coder_test.cpp
4548
value_storage_test.cpp
4649
${FASTTYPEGEN_test_types1_OUTPUTS}
@@ -60,6 +63,7 @@ add_executable (mfast_test
6063
${FASTTYPEGEN_simple_types10_OUTPUTS}
6164
${FASTTYPEGEN_simple_types11_OUTPUTS}
6265
${FASTTYPEGEN_simple_types12_OUTPUTS}
66+
${FASTTYPEGEN_simple_types13_OUTPUTS}
6367
fast_type_gen_test.cpp
6468
dictionary_builder_test.cpp
6569
json_test.cpp

Diff for: tests/fast_test_coding_case.hpp

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <mfast.h>
2+
#include <mfast/coder/fast_encoder.h>
3+
#include <mfast/coder/fast_decoder.h>
4+
#include "byte_stream.h"
5+
6+
namespace test::coding
7+
{
8+
template<typename DESC>
9+
class fast_test_coding_case
10+
{
11+
public:
12+
fast_test_coding_case()
13+
{
14+
encoder_.include({DESC::instance()});
15+
decoder_.include({DESC::instance()});
16+
}
17+
18+
bool encoding(const mfast::message_cref& msg_ref, const byte_stream& result, bool reset=false)
19+
{
20+
const int buffer_size = 128;
21+
char buffer[buffer_size];
22+
23+
std::size_t encoded_size = encoder_.encode(msg_ref,
24+
buffer,
25+
buffer_size,
26+
reset);
27+
28+
if (result == byte_stream(buffer, encoded_size))
29+
return true;
30+
31+
INFO( "Got \"" << byte_stream(buffer, encoded_size) << "\" instead." );
32+
return false;
33+
}
34+
35+
bool decoding(const byte_stream& bytes, const mfast::message_cref& result, bool reset=false)
36+
{
37+
const char* first = bytes.data();
38+
mfast::message_cref msg = decoder_.decode(first, first+bytes.size(), reset);
39+
40+
return (msg == result);
41+
}
42+
43+
private:
44+
mfast::fast_encoder encoder_;
45+
mfast::fast_decoder decoder_;
46+
};
47+
}

Diff for: tests/fast_test_coding_case_v2.hpp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <mfast.h>
2+
#include <mfast/coder/fast_encoder_v2.h>
3+
#include <mfast/coder/fast_decoder_v2.h>
4+
#include "byte_stream.h"
5+
6+
namespace test::coding
7+
{
8+
template<typename DESC>
9+
class fast_test_coding_case_v2
10+
{
11+
public:
12+
fast_test_coding_case_v2():
13+
encoder_v2_(DESC::instance()),
14+
decoder_v2_(DESC::instance())
15+
{}
16+
17+
bool
18+
encoding(const mfast::message_cref& msg_ref, const byte_stream& result, bool reset=false)
19+
{
20+
const int buffer_size = 128;
21+
char buffer[buffer_size];
22+
23+
std::size_t encoded_size = encoder_v2_.encode(msg_ref, buffer, buffer_size, reset);
24+
if (result == byte_stream(buffer, encoded_size))
25+
return true;
26+
27+
INFO( "Got \"" << byte_stream(buffer, encoded_size) << "\" instead." );
28+
return false;
29+
}
30+
31+
bool
32+
decoding(const byte_stream& bytes, const mfast::message_cref& result, bool reset=false)
33+
{
34+
const char* first = bytes.data();
35+
mfast::message_cref msg = decoder_v2_.decode(first, first+bytes.size(), reset);
36+
37+
return (msg == result);
38+
}
39+
40+
private:
41+
mfast::fast_encoder_v2 encoder_v2_;
42+
mfast::fast_decoder_v2<0> decoder_v2_;
43+
};
44+
}

Diff for: tests/group_encoder_decoder.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
#include "fast_test_coding_case.hpp"
55
#include "byte_stream.h"
66

7-
#include "simple14.h"
7+
#include "simple13.h"
88

99
using namespace test::coding;
1010

1111
TEST_CASE("only field without group encoder/decoder","[field_without_group_encoder_decoder]")
1212
{
13-
fast_test_coding_case<simple14::templates_description> test_case;
13+
fast_test_coding_case<simple13::templates_description> test_case;
1414

15-
simple14::Test_1 test_1;
16-
simple14::Test_1_mref test_1_mref = test_1.mref();
15+
simple13::Test_1 test_1;
16+
simple13::Test_1_mref test_1_mref = test_1.mref();
1717

1818
test_1_mref.set_field_1_1().as(30);
1919
test_1_mref.set_field_1_2().as(40);
@@ -24,10 +24,10 @@ TEST_CASE("only field without group encoder/decoder","[field_without_group_encod
2424

2525
TEST_CASE("field with group encoder/decoder","[field_without_group_encoder_decoder]")
2626
{
27-
fast_test_coding_case<simple14::templates_description> test_case;
27+
fast_test_coding_case<simple13::templates_description> test_case;
2828

29-
simple14::Test_1 test_1;
30-
simple14::Test_1_mref test_1_mref = test_1.mref();
29+
simple13::Test_1 test_1;
30+
simple13::Test_1_mref test_1_mref = test_1.mref();
3131

3232
test_1_mref.set_field_1_1().as(30);
3333
test_1_mref.set_field_1_2().as(40);

Diff for: tests/group_encoder_decoder_v2.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
#include "fast_test_coding_case_v2.hpp"
55
#include "byte_stream.h"
66

7-
#include "simple14.h"
7+
#include "simple13.h"
88

99
using namespace test::coding;
1010

1111
TEST_CASE("only field without group encoder_v2/decoder_v2","[field_without_group_encoder_v2_decoder_v2]")
1212
{
13-
fast_test_coding_case_v2<simple14::templates_description> test_case;
13+
fast_test_coding_case_v2<simple13::templates_description> test_case;
1414

15-
simple14::Test_1 test_1;
16-
simple14::Test_1_mref test_1_mref = test_1.mref();
15+
simple13::Test_1 test_1;
16+
simple13::Test_1_mref test_1_mref = test_1.mref();
1717

1818
test_1_mref.set_field_1_1().as(30);
1919
test_1_mref.set_field_1_2().as(40);
@@ -24,10 +24,10 @@ TEST_CASE("only field without group encoder_v2/decoder_v2","[field_without_group
2424

2525
TEST_CASE("field with group encoder_v2/decoder_v2","[field_without_group_encoder_v2_decoder_v2]")
2626
{
27-
fast_test_coding_case_v2<simple14::templates_description> test_case;
27+
fast_test_coding_case_v2<simple13::templates_description> test_case;
2828

29-
simple14::Test_1 test_1;
30-
simple14::Test_1_mref test_1_mref = test_1.mref();
29+
simple13::Test_1 test_1;
30+
simple13::Test_1_mref test_1_mref = test_1.mref();
3131

3232
test_1_mref.set_field_1_1().as(30);
3333
test_1_mref.set_field_1_2().as(40);

Diff for: tests/simple13.xml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version=\" 1.0 \"?>
2+
<templates xmlns="http://www.fixprotocol.org/ns/fast/td/1.1">
3+
<template name="Test_1" id="1">
4+
<uInt32 name="field_1_1" id="11" presence="optional"></uInt32>
5+
<uInt32 name="field_1_2" id="12"></uInt32>
6+
<group name="group_1" presence="optional">
7+
<string name="field_1_3" id="13">
8+
<default value="test"/>
9+
</string>
10+
<uInt32 name="field_1_4" id="14" presence="optional"></uInt32>
11+
</group>
12+
</template>
13+
<template name="Test_2" id="2">
14+
<uInt32 name="field_2_1" id="21" presence="optional"></uInt32>
15+
</template>
16+
</templates>

0 commit comments

Comments
 (0)