Namespaces

Component blpapi_testutil
[Package blpapi]

Provides static utility for unit testing BLPAPI applications. More...

Namespaces

namespace  blpapi

Detailed Description

Provides static utility for unit testing BLPAPI applications.

Outline
Purpose:
Provides static utility for unit testing BLPAPI applications.
Classes:
blpapi::test::TestUtil Static 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:
 using BloombergLP::blpapi::Event;
 using BloombergLP::blpapi::Name;
using BloombergLP::blpapi::test::MessageFormatter; using BloombergLP::blpapi::test::MessageProperties; using BloombergLP::blpapi::test::TestUtil;
 const char *schema = "<ServiceDefinition name=...>...</ServiceDefinition>";

 std::istringstream stream(schema);
 Service service = TestUtil::deserializeService(stream);
We then create a subscription event
 Event event = TestUtil::createSubscriptionEvent(service);
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);
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.