BLPAPI C++ 3.26.6
Loading...
Searching...
No Matches
Component blpapi_testutil

Detailed Description

Provides static utility for unit testing BLPAPI applications.

Purpose:
Provides static utility for unit testing BLPAPI applications.
Classes:
blpapi::test::TestUtilStatic utility class for unit testing
See also
Component blpapi_messageformatter
Description:
This component defines a class, TestUtil, that provides helpers for unit-testing BLPAPI. This includes serializing / deserializing services, creating test events, and appending / formatting messages in these events.
Usage:
Example: Create subscription data with correlation id:

For the purpose of unit testing the behavior of our tick processing, we want to create a subscription data event containing a single tick for a given subscription, identified with a correlation id correlationId that is available in the test.

We first create the service from a string:
const char *schema = "<ServiceDefinition name=...>...</ServiceDefinition>";
std::istringstream stream(schema);
Service service = TestUtil::deserializeService(stream);
Definition blpapi_event.h:325
Definition blpapi_name.h:228
Definition blpapi_messageformatter.h:808
Definition blpapi_testutil.h:488
Definition blpapi_testutil.h:594
static Service deserializeService(std::istream &stream)
Definition blpapi_testutil.h:683
We then create a subscription event
@ SUBSCRIPTION_DATA
Data updates resulting from a subscription.
Definition blpapi_event.h:344
static Event createEvent(Event::EventType eventType)
Definition blpapi_testutil.h:675
We prepare the message properties:
MessageProperties properties;
properties.setCorrelationId(correlationId);
Then, we obtain the definition for the message from the schema:
const Name msgName("MarketDataEvents");
const SchemaElementDefinition def = service.getEventDefinition(msgName);
Now we append a message and obtain a formatter:
MessageFormatter fmt = TestUtil::appendMessage(event, def, properties);
static MessageFormatter appendMessage(Event &event, const SchemaElementDefinition &elementDef, const MessageProperties &properties=MessageProperties())
Definition blpapi_testutil.h:705
test::MessageFormatter MessageFormatter
Definition blpapi_messageformatter.h:1386
The formatter can now be used to fill in the data we want to be using in the test. Note that service creation and the definitions for the ticks can be shared by all of the unit tests that need to create the same type of events.

Classes

class  MessageProperties
class  TestUtil

Typedefs

typedef test::TestUtil TestUtil

Typedef Documentation

◆ TestUtil