Provides static utility for unit testing BLPAPI applications.
- Purpose:
- Provides static utility for unit testing BLPAPI applications.
- Classes:
-
- 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);
Definition blpapi_event.h:325
Definition blpapi_name.h:228
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:
static MessageFormatter appendMessage(Event &event, const SchemaElementDefinition &elementDef, const MessageProperties &properties=MessageProperties())
Definition blpapi_testutil.h:705
- 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.
◆ TestUtil