-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathtestRoundTrip.cpp
More file actions
310 lines (264 loc) · 13.6 KB
/
Copy pathtestRoundTrip.cpp
File metadata and controls
310 lines (264 loc) · 13.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
// Copyright (c) 2009, Object Computing, Inc.
// All rights reserved.
// See the file license.txt for licensing information.
#include <Common/QuickFASTPch.h>
#define BOOST_TEST_NO_MAIN QuickFASTTest
#include <boost/test/unit_test.hpp>
#include <Codecs/XMLTemplateParser.h>
#include <Codecs/TemplateRegistry.h>
#include <Codecs/Encoder.h>
#include <Codecs/Decoder.h>
#include <Codecs/DataDestinationString.h>
#include <Codecs/DataSourceString.h>
#include <Codecs/SingleMessageConsumer.h>
#include <Codecs/GenericMessageBuilder.h>
#include <Messages/Message.h>
#include <Messages/FieldIdentity.h>
#include <Messages/FieldInt32.h>
#include <Messages/FieldUInt32.h>
#include <Messages/FieldInt64.h>
#include <Messages/FieldUInt64.h>
#include <Messages/FieldAscii.h>
#include <Messages/FieldByteVector.h>
#include <Messages/FieldDecimal.h>
#include <Messages/FieldGroup.h>
#include <Messages/FieldSequence.h>
#include <Messages/FieldUtf8.h>
#include <Messages/Sequence.h>
#include <Common/Exceptions.h>
using namespace QuickFAST;
namespace{
void validateMessage1(Messages::Message & message)
{
BOOST_CHECK_EQUAL(message.getApplicationType(), "instrumentreferencedata");
Messages::FieldCPtr value;
//msg.addField(identity_timestamp, Messages::FieldUInt32::create(1));
BOOST_CHECK(message.getField("timestamp", value));
BOOST_CHECK_EQUAL(value->toUInt32(), 1);
//msg.addField(identity_srcId, Messages::FieldUInt32::create(2));
BOOST_CHECK(message.getField("srcId", value));
BOOST_CHECK_EQUAL(value->toUInt32(), 2);
//msg.addField(identity_seqNum, Messages::FieldUInt32::create(3));
BOOST_CHECK(message.getField("seqNum", value));
BOOST_CHECK_EQUAL(value->toUInt32(), 3);
//msg.addField(identity_isix, Messages::FieldUInt32::create(4));
BOOST_CHECK(message.getField("isix", value));
BOOST_CHECK_EQUAL(value->toUInt32(), 4);
//msg.addField(identity_isin, Messages::FieldAscii::create("isin"));
BOOST_CHECK(message.getField("isin", value));
BOOST_CHECK_EQUAL(value->toAscii(), "isin");
//msg.addField(identity_exchId, Messages::FieldAscii::create("exchId"));
BOOST_CHECK(message.getField("exchId", value));
BOOST_CHECK_EQUAL(value->toAscii(), "exchId");
//msg.addField(identity_instGrp, Messages::FieldAscii::create("instGrp"));
BOOST_CHECK(message.getField("instGrp", value));
BOOST_CHECK_EQUAL(value->toAscii(), "instGrp");
//msg.addField(identity_instTypCod, Messages::FieldAscii::create("instTypCod"));
BOOST_CHECK(message.getField("instTypCod", value));
BOOST_CHECK_EQUAL(value->toAscii(), "instTypCod");
//msg.addField(identity_currCode, Messages::FieldAscii::create("currCode"));
BOOST_CHECK(message.getField("currCode", value));
BOOST_CHECK_EQUAL(value->toAscii(), "currCode");
//msg.addField(identity_ticSiz, Messages::FieldDecimal::create(Decimal(123, -1)));
BOOST_CHECK(message.getField("ticSiz", value));
BOOST_CHECK_EQUAL(value->toDecimal(), Decimal(123, -1));
//msg.addField(identity_setId, Messages::FieldUInt32::create(5));
BOOST_CHECK(message.getField("setId", value));
BOOST_CHECK_EQUAL(value->toUInt32(), 5);
BOOST_CHECK(message.getField("MDFeedTypes", value));
const Messages::SequenceCPtr & mdft = value->toSequence();
BOOST_CHECK_EQUAL(mdft->size(), 2);
Messages::FieldSetCPtr seqEntry = (*mdft)[0];
//entry->addField(identity_streamType, Messages::FieldAscii::create("streamType"));
BOOST_CHECK( seqEntry->getField("streamType", value));
BOOST_CHECK_EQUAL(value->toAscii(), "streamType");
//entry->addField(identity_streamService, Messages::FieldAscii::create("streamService"));
BOOST_CHECK( seqEntry->getField("streamService", value));
BOOST_CHECK_EQUAL(value->toAscii(), "streamService");
//entry->addField(identity_inetAddr, Messages::FieldAscii::create("inetAddr.com"));
BOOST_CHECK( seqEntry->getField("inetAddr", value));
BOOST_CHECK_EQUAL(value->toAscii(), "inetAddr.com");
//entry->addField(identity_port, Messages::FieldUInt32::create(2222));
BOOST_CHECK( seqEntry->getField("port", value));
BOOST_CHECK_EQUAL(value->toUInt32(), 2222);
//entry->addField(identity_mktDepth, Messages::FieldUInt32::create(10));
BOOST_CHECK( seqEntry->getField("mktDepth", value));
BOOST_CHECK_EQUAL(value->toUInt32(), 10);
// optional field omitted
BOOST_CHECK(!seqEntry->getField("mdBookType", value));
seqEntry = (*mdft)[1];
//entry->addField(identity_streamType, Messages::FieldAscii::create("streamType2"));
BOOST_CHECK( seqEntry->getField("streamType", value));
BOOST_CHECK_EQUAL(value->toAscii(), "streamType2");
//entry->addField(identity_streamService, Messages::FieldAscii::create("streamService2"));
BOOST_CHECK( seqEntry->getField("streamService", value));
BOOST_CHECK_EQUAL(value->toAscii(), "streamService2");
//entry->addField(identity_inetAddr, Messages::FieldAscii::create("inetAddr.org"));
BOOST_CHECK( seqEntry->getField("inetAddr", value));
BOOST_CHECK_EQUAL(value->toAscii(), "inetAddr.org");
//entry->addField(identity_port, Messages::FieldUInt32::create(2224));
BOOST_CHECK( seqEntry->getField("port", value));
BOOST_CHECK_EQUAL(value->toUInt32(), 2224);
// optional field omitted
BOOST_CHECK(!seqEntry->getField("mktDepth", value));
//entry->addField(identity_mdBookType, Messages::FieldUInt32::create(3));
BOOST_CHECK(seqEntry->getField("mdBookType", value));
BOOST_CHECK_EQUAL(value->toUInt32(), 3);
}
}
BOOST_AUTO_TEST_CASE(testRoundTripSequenceNoPMAP)
{
// Template from Issue #1
std::string theTemplate =
"<templates>"
" <template name=\"InstrumentReferenceData\" id=\"3\">"
" <typeRef name=\"instrumentreferencedata\"/>"
" <uInt32 name=\"timestamp\" id=\"52\">"
" <delta/>"
" </uInt32>"
" <uInt32 name=\"srcId\" id=\"50\">"
" <copy/>"
" </uInt32>"
" <uInt32 name=\"seqNum\" id=\"34\">"
" <increment value=\"1\"/>"
" </uInt32>"
" <uInt32 name=\"isix\" id=\"48\">"
" <delta/>"
" </uInt32>"
" <string name=\"isin\" id=\"455\">"
" <delta/>"
" </string>"
" <string name=\"exchId\" id=\"207\">"
" <copy/>"
" </string>"
" <string name=\"instGrp\" id=\"1151\">"
" <copy/>"
" </string>"
" <string name=\"instTypCod\" id=\"461\">"
" <copy/>"
" </string>"
" <string name=\"currCode\" id=\"15\">"
" <copy/>"
" </string>"
" <decimal name=\"ticSiz\" id=\"969\">"
" <delta/>"
" </decimal>"
" <uInt32 name=\"setId\" id=\"TBD\">"
" <copy/>"
" </uInt32>"
" <sequence name=\"MDFeedTypes\">"
" <length name=\"noOfStreams\" id=\"1141\"/>"
" <string name=\"streamType\" id=\"1022\"/>"
" <string name=\"streamService\"/>"
" <string name=\"inetAddr\">"
" <delta/>"
" </string>"
" <uInt32 name=\"port\" id=\"TBD\">"
" <delta/>"
" </uInt32>"
" <uInt32 name=\"mktDepth\" id=\"264\" presence=\"optional\"/>"
" <uInt32 name=\"mdBookType\" id=\"1021\" presence=\"optional\"/>"
" </sequence>"
" </template>"
"</templates>";
Codecs::XMLTemplateParser parser;
std::stringstream templateStream(theTemplate);
Codecs::TemplateRegistryPtr templateRegistry =
parser.parse(templateStream);
BOOST_CHECK(templateRegistry);
BOOST_CHECK_EQUAL(templateRegistry->maxFieldCount(), 12);
Messages::FieldIdentityCPtr identity_timestamp = new Messages::FieldIdentity("timestamp");
Messages::FieldIdentityCPtr identity_srcId = new Messages::FieldIdentity("srcId");
Messages::FieldIdentityCPtr identity_seqNum = new Messages::FieldIdentity("seqNum");
Messages::FieldIdentityCPtr identity_isix = new Messages::FieldIdentity("isix");
Messages::FieldIdentityCPtr identity_isin = new Messages::FieldIdentity("isin");
Messages::FieldIdentityCPtr identity_exchId = new Messages::FieldIdentity("exchId");
Messages::FieldIdentityCPtr identity_instGrp = new Messages::FieldIdentity("instGrp");
Messages::FieldIdentityCPtr identity_instTypCod = new Messages::FieldIdentity("instTypCod");
Messages::FieldIdentityCPtr identity_currCode = new Messages::FieldIdentity("currCode");
Messages::FieldIdentityCPtr identity_ticSiz = new Messages::FieldIdentity("ticSiz");
Messages::FieldIdentityCPtr identity_setId = new Messages::FieldIdentity("setId");
Messages::FieldIdentityCPtr identity_MDFeedTypes = new Messages::FieldIdentity("MDFeedTypes");
// We don't need a fieldIdentity for the length field.
// Messages::FieldIdentityCPtr identity_noOfStreams = new Messages::FieldIdentity("noOfStreams");
Messages::FieldIdentityCPtr identity_streamType = new Messages::FieldIdentity("streamType");
Messages::FieldIdentityCPtr identity_streamService = new Messages::FieldIdentity("streamService");
Messages::FieldIdentityCPtr identity_inetAddr = new Messages::FieldIdentity("inetAddr");
Messages::FieldIdentityCPtr identity_port = new Messages::FieldIdentity("port");
Messages::FieldIdentityCPtr identity_mktDepth = new Messages::FieldIdentity("mktDepth");
Messages::FieldIdentityCPtr identity_mdBookType = new Messages::FieldIdentity("mdBookType");
Messages::MessagePtr msg(new Messages::Message(templateRegistry->maxFieldCount()));
// <uInt32 name=\"timestamp\" id=\"52\"><delta/></uInt32>"
msg->addField(identity_timestamp, Messages::FieldUInt32::create(1));
// <uInt32 name=\"srcId\" id=\"50\"><copy/></uInt32>"
msg->addField(identity_srcId, Messages::FieldUInt32::create(2));
// <uInt32 name=\"seqNum\" id=\"34\"><increment value=\"1\"/></uInt32>"
msg->addField(identity_seqNum, Messages::FieldUInt32::create(3));
// <uInt32 name=\"isix\" id=\"48\"><delta/></uInt32>"
msg->addField(identity_isix, Messages::FieldUInt32::create(4));
// <string name=\"isin\" id=\"455\"><delta/></string>"
msg->addField(identity_isin, Messages::FieldAscii::create("isin"));
// <string name=\"exchId\" id=\"207\"><copy/></string>"
msg->addField(identity_exchId, Messages::FieldAscii::create("exchId"));
// <string name=\"instGrp\" id=\"1151\"><copy/></string>"
msg->addField(identity_instGrp, Messages::FieldAscii::create("instGrp"));
// <string name=\"instTypCod\" id=\"461\"><copy/></string>"
msg->addField(identity_instTypCod, Messages::FieldAscii::create("instTypCod"));
// <string name=\"currCode\" id=\"15\"><copy/></string>"
msg->addField(identity_currCode, Messages::FieldAscii::create("currCode"));
// <decimal name=\"ticSiz\" id=\"969\"><delta/></decimal>"
msg->addField(identity_ticSiz, Messages::FieldDecimal::create(Decimal(123, -1)));
// <uInt32 name=\"setId\" id=\"TBD\"><copy/></uInt32>"
msg->addField(identity_setId, Messages::FieldUInt32::create(5));
// <sequence name=\"MDFeedTypes\">"
// <length name=\"noOfStreams\" id=\"1141\"/>"
Messages::FieldIdentityPtr lengthIdentity(new Messages::FieldIdentity("noOfStreams",""));
Messages::FieldIdentityCPtr cLengthIdentity(lengthIdentity);
lengthIdentity->setId("1141");
Messages::SequencePtr sequence_MDFeedTypes(new Messages::Sequence(cLengthIdentity, 2));
Messages::FieldSetPtr entry(new Messages::FieldSet(6)); // todo Hardcoded 6?
// <string name=\"streamType\" id=\"1022\"/>"
entry->addField(identity_streamType, Messages::FieldAscii::create("streamType"));
// <string name=\"streamService\"/>"
entry->addField(identity_streamService, Messages::FieldAscii::create("streamService"));
// <string name=\"inetAddr\"><delta/></string>"
entry->addField(identity_inetAddr, Messages::FieldAscii::create("inetAddr.com"));
// <uInt32 name=\"port\" id=\"TBD\"><delta/></uInt32>"
entry->addField(identity_port, Messages::FieldUInt32::create(2222));
// <uInt32 name=\"mktDepth\" id=\"264\" presence=\"optional\"/>"
entry->addField(identity_mktDepth, Messages::FieldUInt32::create(10));
// <uInt32 name=\"mdBookType\" id=\"1021\" presence=\"optional\"/>"
// optional field omitted
sequence_MDFeedTypes->addEntry(Messages::FieldSetCPtr(entry));
entry.reset(new Messages::FieldSet(6));
// <string name=\"streamType\" id=\"1022\"/>"
entry->addField(identity_streamType, Messages::FieldAscii::create("streamType2"));
// <string name=\"streamService\"/>"
entry->addField(identity_streamService, Messages::FieldAscii::create("streamService2"));
// <string name=\"inetAddr\"><delta/></string>"
entry->addField(identity_inetAddr, Messages::FieldAscii::create("inetAddr.org"));
// <uInt32 name=\"port\" id=\"TBD\"><delta/></uInt32>"
entry->addField(identity_port, Messages::FieldUInt32::create(2224));
// <uInt32 name=\"mktDepth\" id=\"264\" presence=\"optional\"/>"
// optional field omitted
// <uInt32 name=\"mdBookType\" id=\"1021\" presence=\"optional\"/>"
entry->addField(identity_mdBookType, Messages::FieldUInt32::create(3));
sequence_MDFeedTypes->addEntry(Messages::FieldSetCPtr(entry));
msg->addField(identity_MDFeedTypes, Messages::FieldSequence::create(sequence_MDFeedTypes));
Codecs::Encoder encoder(templateRegistry);
Codecs::DataDestinationString destination;
template_id_t templId = 3; // from the XML above
encoder.encodeMessage(destination, templId, *msg);
const std::string & fastString = destination.getValue();
Codecs::Decoder decoder(templateRegistry);
Codecs::DataSourceString source(fastString);
Codecs::SingleMessageConsumer consumer;
Codecs::GenericMessageBuilder builder(consumer);
decoder.decodeMessage(source, builder);
Messages::Message & msgOut(consumer.message());
validateMessage1(msgOut);
// wanna see it again?
encoder.encodeMessage(destination, templId, msgOut);
const std::string reencoded = destination.getValue();
BOOST_CHECK(fastString == reencoded);
}