BLPAPI C++ 3.26.5
Loading...
Searching...
No Matches
blpapi_testutil.h
Go to the documentation of this file.
1/* Copyright 2019. Bloomberg Finance L.P.
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to
5 * deal in the Software without restriction, including without limitation the
6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 * sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions: The above
9 * copyright notice and this permission notice shall be included in all copies
10 * or substantial portions of the Software.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
18 * IN THE SOFTWARE.
19 */
20
35
36#ifndef INCLUDED_BLPAPI_TESTUTIL
37#define INCLUDED_BLPAPI_TESTUTIL
38
135
136#include <blpapi_correlationid.h>
137#include <blpapi_datetime.h>
138#include <blpapi_defs.h>
139#include <blpapi_event.h>
141#include <blpapi_service.h>
142#include <blpapi_streamproxy.h>
143#include <blpapi_topic.h>
144#include <blpapi_types.h>
145
146#ifdef __cplusplus
147extern "C" {
148#endif
149
151
154
155BLPAPI_EXPORT
156int blpapi_TestUtil_createEvent(blpapi_Event_t **event, int eventType);
157
158BLPAPI_EXPORT
159int blpapi_TestUtil_deserializeService(
160 const char *schema, size_t schemaLength, blpapi_Service_t **service);
161
162BLPAPI_EXPORT
163int blpapi_TestUtil_serializeService(blpapi_StreamWriter_t streamWriter,
164 void *stream,
165 const blpapi_Service_t *service);
166
167BLPAPI_EXPORT
168int blpapi_TestUtil_appendMessage(blpapi_MessageFormatter_t **formatter,
169 blpapi_Event_t *event,
170 const blpapi_SchemaElementDefinition_t *messageType,
171 const blpapi_MessageProperties_t *properties);
172
173BLPAPI_EXPORT
174int blpapi_TestUtil_createTopic(
175 blpapi_Topic_t **topic, const blpapi_Service_t *service, int isActive);
176
177BLPAPI_EXPORT
178int blpapi_TestUtil_getAdminMessageDefinition(
179 blpapi_SchemaElementDefinition_t **definition,
180 blpapi_Name_t *messageName);
181
182BLPAPI_EXPORT
183int blpapi_MessageProperties_create(
184 blpapi_MessageProperties_t **messageProperties);
185
186BLPAPI_EXPORT
187void blpapi_MessageProperties_destroy(
188 blpapi_MessageProperties_t *messageProperties);
189
190BLPAPI_EXPORT
191int blpapi_MessageProperties_copy(blpapi_MessageProperties_t **dest,
192 const blpapi_MessageProperties_t *src);
193
194BLPAPI_EXPORT
195int blpapi_MessageProperties_assign(blpapi_MessageProperties_t *lhs,
196 const blpapi_MessageProperties_t *rhs);
197
198BLPAPI_EXPORT
199int blpapi_MessageProperties_setCorrelationIds(
200 blpapi_MessageProperties_t *messageProperties,
201 const blpapi_CorrelationId_t *correlationIds,
202 size_t numCorrelationIds);
203
204BLPAPI_EXPORT
205int blpapi_MessageProperties_setRecapType(
206 blpapi_MessageProperties_t *messageProperties,
207 int recap,
208 int fragment);
209
210BLPAPI_EXPORT
211int blpapi_MessageProperties_setTimeReceived(
212 blpapi_MessageProperties_t *messageProperties,
213 const blpapi_HighPrecisionDatetime_t *timestamp);
214
215BLPAPI_EXPORT
216int blpapi_MessageProperties_setService(
217 blpapi_MessageProperties_t *messageProperties,
218 const blpapi_Service_t *service);
219
220BLPAPI_EXPORT
221int blpapi_MessageProperties_setRequestId(
222 blpapi_MessageProperties_t *messageProperties, const char *requestId);
223
226
227#ifdef __cplusplus
228} // extern "C"
229
230#include <cassert>
231#include <cstdio>
232#include <fstream>
233#include <vector>
234
241
242namespace BloombergLP {
243namespace blpapi {
244namespace test {
245
246// =======================
247// class MessageProperties
248// =======================
249
258
259 private:
260 blpapi_MessageProperties_t *d_handle_p;
261
262 public:
263 // CREATORS
274
275 MessageProperties(const MessageProperties& original);
279
284
285 // MANIPULATORS
290
292 const blpapi_CorrelationId_t *correlationIds,
293 size_t correlationIdCount);
302
304 const std::vector<CorrelationId>& correlationIds);
310
311 MessageProperties& setCorrelationId(const CorrelationId& correlationId);
315
322
323 MessageProperties& setTimeReceived(const Datetime& timeReceived);
329
330 MessageProperties& setService(const Service& service);
334
335 MessageProperties& setRequestId(const char *requestId);
341
342 // ACCESSORS
343 blpapi_MessageProperties_t *handle() const;
348};
349
350// ==============
351// class TestUtil
352// ==============
353
361class TestUtil {
362
363 public:
364 // TYPES
365
366 /*
367 * \deprecated Following typedef is provided for backwards compatibility.
368 * It will be removed in a future release.
369 */
371
372 // CLASS METHODS
373 static Event createEvent(Event::EventType eventType);
381
383 const SchemaElementDefinition& elementDef,
384 const MessageProperties& properties = MessageProperties());
396
397 static Service deserializeService(std::istream& stream);
405
406 static void serializeService(std::ostream& stream, const Service& service);
412
413 static Topic createTopic(const Service& service, bool isActive = true);
422
424 const Name& messageName);
429};
430
433
434// ============================================================================
435// INLINE FUNCTION DEFINITIONS
436// ============================================================================
437
438// --------------
439// class TestUtil
440// --------------
441
443{
444 blpapi_Event_t *event = 0;
446 BLPAPI_CALL(blpapi_TestUtil_createEvent)(&event, eventType));
447 return Event(event);
448}
449
450inline Service TestUtil::deserializeService(std::istream& stream)
451{
452 blpapi_Service_t *buffer = 0;
453
454 // This is a workaround for SunOS compiler not supporting construction from
455 // 'std::istreambuf_iterator'.
456 std::string schema;
457 std::getline(stream, schema, '\0');
458
460 BLPAPI_CALL(blpapi_TestUtil_deserializeService)(
461 schema.c_str(), schema.length(), &buffer));
462 return Service(buffer, Service::TestService());
463}
464
466 std::ostream& stream, const Service& service)
467{
468 ExceptionUtil::throwOnError(BLPAPI_CALL(blpapi_TestUtil_serializeService)(
469 StreamProxyOstream::writeToStream, &stream, service.handle()));
470}
471
473 const SchemaElementDefinition& elementDef,
474 const MessageProperties& properties)
475{
476 blpapi_MessageFormatter_t *formatter = 0;
477 ExceptionUtil::throwOnError(BLPAPI_CALL(blpapi_TestUtil_appendMessage)(
478 &formatter, event.impl(), elementDef.impl(), properties.handle()));
479
480 return MessageFormatter(formatter);
481}
482
483inline Topic TestUtil::createTopic(const Service& service, bool isActive)
484{
485 blpapi_Topic_t *topic = 0;
486 ExceptionUtil::throwOnError(BLPAPI_CALL(blpapi_TestUtil_createTopic)(
487 &topic, service.handle(), isActive));
488 return Topic(topic);
489}
490
492 const Name& messageName)
493{
494 blpapi_SchemaElementDefinition_t *definition = 0;
496 BLPAPI_CALL(blpapi_TestUtil_getAdminMessageDefinition)(
497 &definition, messageName.impl()));
498 return SchemaElementDefinition(definition);
499}
500
502{
504 BLPAPI_CALL(blpapi_MessageProperties_create)(&d_handle_p));
505}
506
508{
509 ExceptionUtil::throwOnError(BLPAPI_CALL(blpapi_MessageProperties_copy)(
510 &d_handle_p, original.handle()));
511}
512
514 const MessageProperties& rhs)
515{
516 ExceptionUtil::throwOnError(BLPAPI_CALL(blpapi_MessageProperties_assign)(
517 d_handle_p, rhs.handle()));
518 return *this;
519}
520
522{
523 BLPAPI_CALL_UNCHECKED(blpapi_MessageProperties_destroy)(d_handle_p);
524}
525
526inline blpapi_MessageProperties_t *MessageProperties::handle() const
527{
528 return d_handle_p;
529}
530
532 const CorrelationId& cid)
533{
535 BLPAPI_CALL(blpapi_MessageProperties_setCorrelationIds)(
536 d_handle_p, &cid.impl(), 1));
537 return *this;
538}
539
541 const std::vector<CorrelationId>& cids)
542{
543 assert(!cids.empty());
544
546 BLPAPI_CALL(blpapi_MessageProperties_setCorrelationIds)(
547 d_handle_p, &cids[0].impl(), cids.size()));
548 return *this;
549}
550
552 const blpapi_CorrelationId_t *correlationIds,
553 size_t correlationIdCount)
554{
556 BLPAPI_CALL(blpapi_MessageProperties_setCorrelationIds)(
557 d_handle_p, correlationIds, correlationIdCount));
558 return *this;
559}
560
562 Message::RecapType::Type recapType, Message::Fragment fragmentType)
563{
565 BLPAPI_CALL(blpapi_MessageProperties_setRecapType)(d_handle_p,
566 static_cast<int>(recapType),
567 static_cast<int>(fragmentType)));
568 return *this;
569}
570
572 const Datetime& timeReceived)
573{
575 BLPAPI_CALL(blpapi_MessageProperties_setTimeReceived)(
576 d_handle_p, &timeReceived.rawHighPrecisionValue()));
577 return *this;
578}
579
581{
583 BLPAPI_CALL(blpapi_MessageProperties_setService)(
584 d_handle_p, service.handle()));
585 return *this;
586}
587
589 const char *requestId)
590{
592 blpapi_MessageProperties_setRequestId)(d_handle_p, requestId));
593 return *this;
594}
595
596} // close namespace test
597
598// *Deprecated*
599// Following typedef is provided for backwards compatibility. It will be
600// removed in a future release.
602
603} // close namespace blpapi
604} // close namespace BloombergLP
605
606#endif // #ifdef __cplusplus
607#endif // #ifndef INCLUDED_BLPAPI_TESTUTIL
#define BLPAPI_CALL_UNCHECKED(FUNCNAME)
Definition blpapi_call.h:362
#define BLPAPI_CALL(FUNCNAME)
Definition blpapi_call.h:361
Provide a key to identify individual subscriptions or requests.
Represents a date and/or time.
Common definitions used by the library.
A component which defines events related operations.
Format messages for publishing.
A service which provides access to API data (provide or consume).
A signature for callback on print and default C++ implementation.
Provide representation of a Topic.
Provide BLPAPI types.
Definition blpapi_correlationid.h:225
Definition blpapi_datetime.h:273
blpapi_HighPrecisionDatetime_t & rawHighPrecisionValue()
Definition blpapi_datetime.h:1982
Definition blpapi_event.h:212
EventType
The possible types of event.
Definition blpapi_event.h:218
blpapi_Event_t * impl() const
Definition blpapi_event.h:569
static void throwOnError(int errorCode)
Definition blpapi_exception.h:541
Fragment
Definition blpapi_message.h:187
@ FRAGMENT_NONE
message is not fragmented
Definition blpapi_message.h:189
Definition blpapi_name.h:242
blpapi_Name_t * impl() const
Definition blpapi_name.h:495
Definition blpapi_schema.h:342
blpapi_SchemaElementDefinition_t * impl() const
Definition blpapi_schema.h:763
Definition blpapi_service.h:320
blpapi_Service_t * handle() const
Definition blpapi_service.h:722
Definition blpapi_topic.h:130
Definition blpapi_messageformatter.h:278
Definition blpapi_testutil.h:257
MessageProperties & setRecapType(Message::RecapType::Type recapType, Message::Fragment fragmentType=Message::FRAGMENT_NONE)
Definition blpapi_testutil.h:561
MessageProperties & setRequestId(const char *requestId)
Definition blpapi_testutil.h:588
~MessageProperties()
Definition blpapi_testutil.h:521
MessageProperties & setService(const Service &service)
Definition blpapi_testutil.h:580
MessageProperties & setCorrelationIds(const blpapi_CorrelationId_t *correlationIds, size_t correlationIdCount)
Definition blpapi_testutil.h:551
MessageProperties & operator=(const MessageProperties &rhs)
Definition blpapi_testutil.h:513
blpapi_MessageProperties_t * handle() const
Definition blpapi_testutil.h:526
MessageProperties & setTimeReceived(const Datetime &timeReceived)
Definition blpapi_testutil.h:571
MessageProperties()
Definition blpapi_testutil.h:501
MessageProperties & setCorrelationId(const CorrelationId &correlationId)
Definition blpapi_testutil.h:531
Definition blpapi_testutil.h:361
static MessageFormatter appendMessage(Event &event, const SchemaElementDefinition &elementDef, const MessageProperties &properties=MessageProperties())
Definition blpapi_testutil.h:472
static void serializeService(std::ostream &stream, const Service &service)
Definition blpapi_testutil.h:465
static Topic createTopic(const Service &service, bool isActive=true)
Definition blpapi_testutil.h:483
static Event createEvent(Event::EventType eventType)
Definition blpapi_testutil.h:442
static SchemaElementDefinition getAdminMessageDefinition(const Name &messageName)
Definition blpapi_testutil.h:491
test::MessageProperties MessageProperties
Definition blpapi_testutil.h:370
static Service deserializeService(std::istream &stream)
Definition blpapi_testutil.h:450
test::MessageFormatter MessageFormatter
Definition blpapi_messageformatter.h:853
test::TestUtil TestUtil
Definition blpapi_testutil.h:601
Definition blpapi_messageformatter.h:261
Definition blpapi_abstractsession.h:212
Definition blpapi_abstractsession.h:211
Type
Definition blpapi_message.h:213
Definition blpapi_service.h:329
static int writeToStream(const char *data, int length, void *stream)
Definition blpapi_streamproxy.h:109