BLPAPI C++ 3.26.6
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
37
38#ifndef INCLUDED_BLPAPI_TESTUTIL
39#define INCLUDED_BLPAPI_TESTUTIL
40
129
130#include <blpapi_correlationid.h>
131#include <blpapi_datetime.h>
132#include <blpapi_defs.h>
133#include <blpapi_event.h>
135#include <blpapi_service.h>
136#include <blpapi_streamproxy.h>
137#include <blpapi_topic.h>
138#include <blpapi_types.h>
139
140#ifdef __cplusplus
141extern "C" {
142#endif
143
145
148
165BLPAPI_EXPORT
166int blpapi_TestUtil_createEvent(blpapi_Event_t **event, int eventType);
167
186BLPAPI_EXPORT
187int blpapi_TestUtil_deserializeService(
188 const char *schema, size_t schemaLength, blpapi_Service_t **service);
189
204BLPAPI_EXPORT
205int blpapi_TestUtil_serializeService(blpapi_StreamWriter_t streamWriter,
206 void *stream,
207 const blpapi_Service_t *service);
208
230BLPAPI_EXPORT
231int blpapi_TestUtil_appendMessage(blpapi_MessageFormatter_t **formatter,
232 blpapi_Event_t *event,
233 const blpapi_SchemaElementDefinition_t *messageType,
234 const blpapi_MessageProperties_t *properties);
235
253BLPAPI_EXPORT
254int blpapi_TestUtil_createTopic(
255 blpapi_Topic_t **topic, const blpapi_Service_t *service, int isActive);
256
272BLPAPI_EXPORT
273int blpapi_TestUtil_getAdminMessageDefinition(
274 blpapi_SchemaElementDefinition_t **definition,
275 blpapi_Name_t *messageName);
276
294BLPAPI_EXPORT
295int blpapi_MessageProperties_create(
296 blpapi_MessageProperties_t **messageProperties);
297
309BLPAPI_EXPORT
310void blpapi_MessageProperties_destroy(
311 blpapi_MessageProperties_t *messageProperties);
312
328BLPAPI_EXPORT
329int blpapi_MessageProperties_copy(blpapi_MessageProperties_t **dest,
330 const blpapi_MessageProperties_t *src);
331
344BLPAPI_EXPORT
345int blpapi_MessageProperties_assign(blpapi_MessageProperties_t *lhs,
346 const blpapi_MessageProperties_t *rhs);
347
364BLPAPI_EXPORT
365int blpapi_MessageProperties_setCorrelationIds(
366 blpapi_MessageProperties_t *messageProperties,
367 const blpapi_CorrelationId_t *correlationIds,
368 size_t numCorrelationIds);
369
391BLPAPI_EXPORT
392int blpapi_MessageProperties_setRecapType(
393 blpapi_MessageProperties_t *messageProperties,
394 int recap,
395 int fragment);
396
411BLPAPI_EXPORT
412int blpapi_MessageProperties_setTimeReceived(
413 blpapi_MessageProperties_t *messageProperties,
414 const blpapi_HighPrecisionDatetime_t *timestamp);
415
430BLPAPI_EXPORT
431int blpapi_MessageProperties_setService(
432 blpapi_MessageProperties_t *messageProperties,
433 const blpapi_Service_t *service);
434
451BLPAPI_EXPORT
452int blpapi_MessageProperties_setRequestId(
453 blpapi_MessageProperties_t *messageProperties, const char *requestId);
454
457
458#ifdef __cplusplus
459} // extern "C"
460
461#include <cassert>
462#include <cstdio>
463#include <fstream>
464#include <vector>
465
466namespace BloombergLP {
467namespace blpapi {
474
475namespace test {
476
477// =======================
478// class MessageProperties
479// =======================
480
489
490 private:
491 blpapi_MessageProperties_t *d_handle_p;
492
493 public:
494 // CREATORS
505
506 MessageProperties(const MessageProperties& original);
510
515
516 // MANIPULATORS
521
523 const blpapi_CorrelationId_t *correlationIds,
524 size_t correlationIdCount);
533
535 const std::vector<CorrelationId>& correlationIds);
541
542 MessageProperties& setCorrelationId(const CorrelationId& correlationId);
546
553
554 MessageProperties& setTimeReceived(const Datetime& timeReceived);
560
561 MessageProperties& setService(const Service& service);
565
566 MessageProperties& setRequestId(const char *requestId);
572
573 // ACCESSORS
575 blpapi_MessageProperties_t *handle() const;
581};
582
583// ==============
584// class TestUtil
585// ==============
586
594class TestUtil {
595
596 public:
597 // TYPES
598
599 /*
600 * \deprecated Following typedef is provided for backwards compatibility.
601 * It will be removed in a future release.
602 */
604
605 // CLASS METHODS
606 static Event createEvent(Event::EventType eventType);
614
616 const SchemaElementDefinition& elementDef,
617 const MessageProperties& properties = MessageProperties());
629
630 static Service deserializeService(std::istream& stream);
638
639 static void serializeService(std::ostream& stream, const Service& service);
645
646 static Topic createTopic(const Service& service, bool isActive = true);
655
657 const Name& messageName);
662};
663
666
667// ============================================================================
668// INLINE FUNCTION DEFINITIONS
669// ============================================================================
670
671// --------------
672// class TestUtil
673// --------------
674
676{
677 blpapi_Event_t *event = 0;
679 BLPAPI_CALL(blpapi_TestUtil_createEvent)(&event, eventType));
680 return Event(event);
681}
682
683inline Service TestUtil::deserializeService(std::istream& stream)
684{
685 blpapi_Service_t *buffer = 0;
686
687 // This is a workaround for SunOS compiler not supporting construction from
688 // 'std::istreambuf_iterator'.
689 std::string schema;
690 std::getline(stream, schema, '\0');
691
693 BLPAPI_CALL(blpapi_TestUtil_deserializeService)(
694 schema.c_str(), schema.length(), &buffer));
695 return Service(buffer, Service::TestService());
696}
697
699 std::ostream& stream, const Service& service)
700{
701 ExceptionUtil::throwOnError(BLPAPI_CALL(blpapi_TestUtil_serializeService)(
702 StreamProxyOstream::writeToStream, &stream, service.handle()));
703}
704
706 const SchemaElementDefinition& elementDef,
707 const MessageProperties& properties)
708{
709 blpapi_MessageFormatter_t *formatter = 0;
710 ExceptionUtil::throwOnError(BLPAPI_CALL(blpapi_TestUtil_appendMessage)(
711 &formatter, event.impl(), elementDef.impl(), properties.handle()));
712
713 return MessageFormatter(formatter);
714}
715
716inline Topic TestUtil::createTopic(const Service& service, bool isActive)
717{
718 blpapi_Topic_t *topic = 0;
719 ExceptionUtil::throwOnError(BLPAPI_CALL(blpapi_TestUtil_createTopic)(
720 &topic, service.handle(), isActive));
721 return Topic(topic);
722}
723
725 const Name& messageName)
726{
727 blpapi_SchemaElementDefinition_t *definition = 0;
729 BLPAPI_CALL(blpapi_TestUtil_getAdminMessageDefinition)(
730 &definition, messageName.impl()));
731 return SchemaElementDefinition(definition);
732}
733
735{
737 BLPAPI_CALL(blpapi_MessageProperties_create)(&d_handle_p));
738}
739
741{
742 ExceptionUtil::throwOnError(BLPAPI_CALL(blpapi_MessageProperties_copy)(
743 &d_handle_p, original.handle()));
744}
745
747 const MessageProperties& rhs)
748{
749 ExceptionUtil::throwOnError(BLPAPI_CALL(blpapi_MessageProperties_assign)(
750 d_handle_p, rhs.handle()));
751 return *this;
752}
753
755{
756 BLPAPI_CALL_UNCHECKED(blpapi_MessageProperties_destroy)(d_handle_p);
757}
758
760inline blpapi_MessageProperties_t *MessageProperties::handle() const
761{
762 return d_handle_p;
763}
765
767 const CorrelationId& cid)
768{
770 BLPAPI_CALL(blpapi_MessageProperties_setCorrelationIds)(
771 d_handle_p, &cid.impl(), 1));
772 return *this;
773}
774
776 const std::vector<CorrelationId>& cids)
777{
778 assert(!cids.empty());
779
781 BLPAPI_CALL(blpapi_MessageProperties_setCorrelationIds)(
782 d_handle_p, &cids[0].impl(), cids.size()));
783 return *this;
784}
785
787 const blpapi_CorrelationId_t *correlationIds,
788 size_t correlationIdCount)
789{
791 BLPAPI_CALL(blpapi_MessageProperties_setCorrelationIds)(
792 d_handle_p, correlationIds, correlationIdCount));
793 return *this;
794}
795
797 Message::RecapType::Type recapType, Message::Fragment fragmentType)
798{
800 BLPAPI_CALL(blpapi_MessageProperties_setRecapType)(d_handle_p,
801 static_cast<int>(recapType),
802 static_cast<int>(fragmentType)));
803 return *this;
804}
805
807 const Datetime& timeReceived)
808{
810 BLPAPI_CALL(blpapi_MessageProperties_setTimeReceived)(
811 d_handle_p, &timeReceived.rawHighPrecisionValue()));
812 return *this;
813}
814
816{
818 BLPAPI_CALL(blpapi_MessageProperties_setService)(
819 d_handle_p, service.handle()));
820 return *this;
821}
822
824 const char *requestId)
825{
826 ExceptionUtil::throwOnError(BLPAPI_CALL(
827 blpapi_MessageProperties_setRequestId)(d_handle_p, requestId));
828 return *this;
829}
830
831} // close namespace test
832
833// *Deprecated*
834// Following typedef is provided for backwards compatibility. It will be
835// removed in a future release.
837
838} // close namespace blpapi
839} // close namespace BloombergLP
840
841#endif // #ifdef __cplusplus
842#endif // #ifndef INCLUDED_BLPAPI_TESTUTIL
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:306
Definition blpapi_datetime.h:312
blpapi_HighPrecisionDatetime_t & rawHighPrecisionValue()
Definition blpapi_datetime.h:2020
Definition blpapi_event.h:325
EventType
The possible types of event.
Definition blpapi_event.h:331
static void throwOnError(int errorCode)
Definition blpapi_exception.h:556
Fragment
Definition blpapi_message.h:354
@ FRAGMENT_NONE
message is not fragmented
Definition blpapi_message.h:356
Definition blpapi_name.h:228
Definition blpapi_schema.h:597
Definition blpapi_service.h:619
Definition blpapi_topic.h:177
Definition blpapi_messageformatter.h:808
Definition blpapi_testutil.h:488
MessageProperties & setRecapType(Message::RecapType::Type recapType, Message::Fragment fragmentType=Message::FRAGMENT_NONE)
Definition blpapi_testutil.h:796
MessageProperties & setRequestId(const char *requestId)
Definition blpapi_testutil.h:823
~MessageProperties()
Definition blpapi_testutil.h:754
MessageProperties & setService(const Service &service)
Definition blpapi_testutil.h:815
MessageProperties & setCorrelationIds(const blpapi_CorrelationId_t *correlationIds, size_t correlationIdCount)
Definition blpapi_testutil.h:786
MessageProperties & operator=(const MessageProperties &rhs)
Definition blpapi_testutil.h:746
MessageProperties & setTimeReceived(const Datetime &timeReceived)
Definition blpapi_testutil.h:806
MessageProperties()
Definition blpapi_testutil.h:734
MessageProperties & setCorrelationId(const CorrelationId &correlationId)
Definition blpapi_testutil.h:766
Definition blpapi_testutil.h:594
static MessageFormatter appendMessage(Event &event, const SchemaElementDefinition &elementDef, const MessageProperties &properties=MessageProperties())
Definition blpapi_testutil.h:705
static void serializeService(std::ostream &stream, const Service &service)
Definition blpapi_testutil.h:698
static Topic createTopic(const Service &service, bool isActive=true)
Definition blpapi_testutil.h:716
static Event createEvent(Event::EventType eventType)
Definition blpapi_testutil.h:675
static SchemaElementDefinition getAdminMessageDefinition(const Name &messageName)
Definition blpapi_testutil.h:724
test::MessageProperties MessageProperties
Definition blpapi_testutil.h:603
static Service deserializeService(std::istream &stream)
Definition blpapi_testutil.h:683
test::MessageFormatter MessageFormatter
Definition blpapi_messageformatter.h:1386
test::TestUtil TestUtil
Definition blpapi_testutil.h:836
Definition blpapi_messageformatter.h:791
Definition blpapi_abstractsession.h:452
Definition blpapi_abstractsession.h:451
Type
Definition blpapi_message.h:380
Definition blpapi_service.h:628
static int writeToStream(const char *data, int length, void *stream)
Definition blpapi_streamproxy.h:108