BLPAPI C++ 3.26.4
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
28#ifndef INCLUDED_BLPAPI_TESTUTIL
29#define INCLUDED_BLPAPI_TESTUTIL
30
128#include <blpapi_correlationid.h>
129#include <blpapi_datetime.h>
130#include <blpapi_defs.h>
131#include <blpapi_event.h>
133#include <blpapi_service.h>
134#include <blpapi_streamproxy.h>
135#include <blpapi_topic.h>
136#include <blpapi_types.h>
137
138#ifdef __cplusplus
139extern "C" {
140#endif
141
143int blpapi_TestUtil_createEvent(blpapi_Event_t **event, int eventType);
144
147 const char *schema, size_t schemaLength, blpapi_Service_t **service);
148
151 void *stream,
152 const blpapi_Service_t *service);
153
156 blpapi_Event_t *event,
157 const blpapi_SchemaElementDefinition_t *messageType,
158 const blpapi_MessageProperties_t *properties);
159
162 blpapi_Topic_t **topic, const blpapi_Service_t *service, int isActive);
163
167 blpapi_Name_t *messageName);
168
171 blpapi_MessageProperties_t **messageProperties);
172
175 blpapi_MessageProperties_t *messageProperties);
176
179 const blpapi_MessageProperties_t *src);
180
183 const blpapi_MessageProperties_t *rhs);
184
187 blpapi_MessageProperties_t *messageProperties,
188 const blpapi_CorrelationId_t *correlationIds,
189 size_t numCorrelationIds);
190
193 blpapi_MessageProperties_t *messageProperties,
194 int recap,
195 int fragment);
196
199 blpapi_MessageProperties_t *messageProperties,
200 const blpapi_HighPrecisionDatetime_t *timestamp);
201
204 blpapi_MessageProperties_t *messageProperties,
205 const blpapi_Service_t *service);
206
209 blpapi_MessageProperties_t *messageProperties, const char *requestId);
210
211#ifdef __cplusplus
212} // extern "C"
213
214#include <cassert>
215#include <cstdio>
216#include <fstream>
217#include <vector>
218
226namespace BloombergLP {
227namespace blpapi {
228namespace test {
229
230// =======================
231// class MessageProperties
232// =======================
233
242
243 private:
244 blpapi_MessageProperties_t *d_handle_p;
245
246 public:
247 // CREATORS
259 MessageProperties(const MessageProperties& original);
269 // MANIPULATORS
276 const blpapi_CorrelationId_t *correlationIds,
277 size_t correlationIdCount);
288 const std::vector<CorrelationId>& correlationIds);
295 MessageProperties& setCorrelationId(const CorrelationId& correlationId);
307 MessageProperties& setTimeReceived(const Datetime& timeReceived);
314 MessageProperties& setService(const Service& service);
319 MessageProperties& setRequestId(const char *requestId);
326 // ACCESSORS
332};
333
334// ==============
335// class TestUtil
336// ==============
337
345class TestUtil {
346
347 public:
348 // TYPES
349
350 /*
351 * \deprecated Following typedef is provided for backwards compatibility.
352 * It will be removed in a future release.
353 */
355
356 // CLASS METHODS
357 static Event createEvent(Event::EventType eventType);
367 const SchemaElementDefinition& elementDef,
368 const MessageProperties& properties = MessageProperties());
381 static Service deserializeService(std::istream& stream);
390 static void serializeService(std::ostream& stream, const Service& service);
397 static Topic createTopic(const Service& service, bool isActive = true);
408 const Name& messageName);
413};
414
418// ============================================================================
419// INLINE FUNCTION DEFINITIONS
420// ============================================================================
421
422// --------------
423// class TestUtil
424// --------------
425
427{
428 blpapi_Event_t *event = 0;
430 BLPAPI_CALL(blpapi_TestUtil_createEvent)(&event, eventType));
431 return Event(event);
432}
433
434inline Service TestUtil::deserializeService(std::istream& stream)
435{
436 blpapi_Service_t *buffer = 0;
437
438 // This is a workaround for SunOS compiler not supporting construction from
439 // 'std::istreambuf_iterator'.
440 std::string schema;
441 std::getline(stream, schema, '\0');
442
445 schema.c_str(), schema.length(), &buffer));
446 return Service(buffer, Service::TestService());
447}
448
450 std::ostream& stream, const Service& service)
451{
453 StreamProxyOstream::writeToStream, &stream, service.handle()));
454}
455
457 const SchemaElementDefinition& elementDef,
458 const MessageProperties& properties)
459{
460 blpapi_MessageFormatter_t *formatter = 0;
462 &formatter, event.impl(), elementDef.impl(), properties.handle()));
463
464 return MessageFormatter(formatter);
465}
466
467inline Topic TestUtil::createTopic(const Service& service, bool isActive)
468{
469 blpapi_Topic_t *topic = 0;
471 &topic, service.handle(), isActive));
472 return Topic(topic);
473}
474
476 const Name& messageName)
477{
478 blpapi_SchemaElementDefinition_t *definition = 0;
481 &definition, messageName.impl()));
482 return SchemaElementDefinition(definition);
483}
484
490
496
504
509
511{
512 return d_handle_p;
513}
514
516 const CorrelationId& cid)
517{
520 d_handle_p, &cid.impl(), 1));
521 return *this;
522}
523
525 const std::vector<CorrelationId>& cids)
526{
527 assert(!cids.empty());
528
531 d_handle_p, &cids[0].impl(), cids.size()));
532 return *this;
533}
534
536 const blpapi_CorrelationId_t *correlationIds,
537 size_t correlationIdCount)
538{
541 d_handle_p, correlationIds, correlationIdCount));
542 return *this;
543}
544
546 Message::RecapType::Type recapType, Message::Fragment fragmentType)
547{
550 static_cast<int>(recapType),
551 static_cast<int>(fragmentType)));
552 return *this;
553}
554
556 const Datetime& timeReceived)
557{
560 d_handle_p, &timeReceived.rawHighPrecisionValue()));
561 return *this;
562}
563
565{
568 d_handle_p, service.handle()));
569 return *this;
570}
571
573 const char *requestId)
574{
576 blpapi_MessageProperties_setRequestId)(d_handle_p, requestId));
577 return *this;
578}
579
580} // close namespace test
581
582// *Deprecated*
583// Following typedef is provided for backwards compatibility. It will be
584// removed in a future release.
586
587} // close namespace blpapi
588} // close namespace BloombergLP
589
590#endif // #ifdef __cplusplus
591#endif // #ifndef INCLUDED_BLPAPI_TESTUTIL
#define BLPAPI_CALL_UNCHECKED(FUNCNAME)
Definition blpapi_call.h:354
#define BLPAPI_CALL(FUNCNAME)
Definition blpapi_call.h:353
Provide a key to identify individual subscriptions or requests.
Represents a date and/or time.
Common definitions used by the library.
#define BLPAPI_EXPORT
Definition blpapi_defs.h:172
struct blpapi_CorrelationId_t_ blpapi_CorrelationId_t
Definition blpapi_dispatchtbl.h:74
struct blpapi_Topic blpapi_Topic_t
Definition blpapi_dispatchtbl.h:77
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.
int(* blpapi_StreamWriter_t)(const char *data, int length, void *stream)
Definition blpapi_streamproxy.h:53
BLPAPI_EXPORT int blpapi_MessageProperties_copy(blpapi_MessageProperties_t **dest, const blpapi_MessageProperties_t *src)
BLPAPI_EXPORT int blpapi_TestUtil_deserializeService(const char *schema, size_t schemaLength, blpapi_Service_t **service)
BLPAPI_EXPORT int blpapi_TestUtil_getAdminMessageDefinition(blpapi_SchemaElementDefinition_t **definition, blpapi_Name_t *messageName)
BLPAPI_EXPORT int blpapi_MessageProperties_setCorrelationIds(blpapi_MessageProperties_t *messageProperties, const blpapi_CorrelationId_t *correlationIds, size_t numCorrelationIds)
BLPAPI_EXPORT int blpapi_TestUtil_serializeService(blpapi_StreamWriter_t streamWriter, void *stream, const blpapi_Service_t *service)
BLPAPI_EXPORT int blpapi_MessageProperties_setRecapType(blpapi_MessageProperties_t *messageProperties, int recap, int fragment)
BLPAPI_EXPORT int blpapi_TestUtil_appendMessage(blpapi_MessageFormatter_t **formatter, blpapi_Event_t *event, const blpapi_SchemaElementDefinition_t *messageType, const blpapi_MessageProperties_t *properties)
BLPAPI_EXPORT int blpapi_MessageProperties_create(blpapi_MessageProperties_t **messageProperties)
BLPAPI_EXPORT int blpapi_TestUtil_createEvent(blpapi_Event_t **event, int eventType)
BLPAPI_EXPORT int blpapi_MessageProperties_setTimeReceived(blpapi_MessageProperties_t *messageProperties, const blpapi_HighPrecisionDatetime_t *timestamp)
BLPAPI_EXPORT int blpapi_MessageProperties_assign(blpapi_MessageProperties_t *lhs, const blpapi_MessageProperties_t *rhs)
BLPAPI_EXPORT int blpapi_TestUtil_createTopic(blpapi_Topic_t **topic, const blpapi_Service_t *service, int isActive)
BLPAPI_EXPORT int blpapi_MessageProperties_setService(blpapi_MessageProperties_t *messageProperties, const blpapi_Service_t *service)
BLPAPI_EXPORT void blpapi_MessageProperties_destroy(blpapi_MessageProperties_t *messageProperties)
BLPAPI_EXPORT int blpapi_MessageProperties_setRequestId(blpapi_MessageProperties_t *messageProperties, const char *requestId)
Provide representation of a Topic.
Provide BLPAPI types.
Definition blpapi_correlationid.h:206
Definition blpapi_datetime.h:245
blpapi_HighPrecisionDatetime_t & rawHighPrecisionValue()
Definition blpapi_datetime.h:1954
Definition blpapi_event.h:196
EventType
The possible types of event.
Definition blpapi_event.h:202
blpapi_Event_t * impl() const
Definition blpapi_event.h:553
static void throwOnError(int errorCode)
Definition blpapi_exception.h:526
Fragment
Definition blpapi_message.h:171
@ FRAGMENT_NONE
message is not fragmented
Definition blpapi_message.h:173
Definition blpapi_name.h:150
blpapi_Name_t * impl() const
Definition blpapi_name.h:403
Definition blpapi_schema.h:327
blpapi_SchemaElementDefinition_t * impl() const
Definition blpapi_schema.h:744
Definition blpapi_service.h:304
blpapi_Service_t * handle() const
Definition blpapi_service.h:706
Definition blpapi_topic.h:114
Definition blpapi_messageformatter.h:262
Definition blpapi_testutil.h:241
MessageProperties & setRecapType(Message::RecapType::Type recapType, Message::Fragment fragmentType=Message::FRAGMENT_NONE)
Definition blpapi_testutil.h:545
MessageProperties & setRequestId(const char *requestId)
Definition blpapi_testutil.h:572
~MessageProperties()
Definition blpapi_testutil.h:505
MessageProperties & setService(const Service &service)
Definition blpapi_testutil.h:564
MessageProperties & setCorrelationIds(const blpapi_CorrelationId_t *correlationIds, size_t correlationIdCount)
Definition blpapi_testutil.h:535
MessageProperties & operator=(const MessageProperties &rhs)
Definition blpapi_testutil.h:497
blpapi_MessageProperties_t * handle() const
Definition blpapi_testutil.h:510
MessageProperties & setTimeReceived(const Datetime &timeReceived)
Definition blpapi_testutil.h:555
MessageProperties()
Definition blpapi_testutil.h:485
MessageProperties & setCorrelationId(const CorrelationId &correlationId)
Definition blpapi_testutil.h:515
Definition blpapi_testutil.h:345
static MessageFormatter appendMessage(Event &event, const SchemaElementDefinition &elementDef, const MessageProperties &properties=MessageProperties())
Definition blpapi_testutil.h:456
static void serializeService(std::ostream &stream, const Service &service)
Definition blpapi_testutil.h:449
static Topic createTopic(const Service &service, bool isActive=true)
Definition blpapi_testutil.h:467
static Event createEvent(Event::EventType eventType)
Definition blpapi_testutil.h:426
static SchemaElementDefinition getAdminMessageDefinition(const Name &messageName)
Definition blpapi_testutil.h:475
test::MessageProperties MessageProperties
Definition blpapi_testutil.h:354
static Service deserializeService(std::istream &stream)
Definition blpapi_testutil.h:434
test::TestUtil TestUtil
Definition blpapi_testutil.h:585
struct blpapi_Service blpapi_Service_t
Definition blpapi_types.h:166
struct blpapi_MessageProperties blpapi_MessageProperties_t
Definition blpapi_types.h:200
struct blpapi_Event blpapi_Event_t
Definition blpapi_types.h:139
struct blpapi_MessageFormatter blpapi_MessageFormatter_t
Definition blpapi_types.h:197
struct blpapi_Name blpapi_Name_t
Definition blpapi_types.h:154
struct blpapi_SchemaElementDefinition blpapi_SchemaElementDefinition_t
Definition blpapi_types.h:191
Definition blpapi_abstractsession.h:195
Type
Definition blpapi_message.h:197
Definition blpapi_service.h:313
static int writeToStream(const char *data, int length, void *stream)
Definition blpapi_streamproxy.h:93
Definition blpapi_datetime.h:115