Provides static utility for unit testing BLPAPI applications.
More...
Provides static utility for unit testing BLPAPI applications.
- 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:
const char *schema = "<ServiceDefinition name=...>...</ServiceDefinition>";
std::istringstream stream(schema);
Service service = TestUtil::deserializeService(stream);
- We then create a subscription event
Event event = TestUtil::createEvent(Event::EventType::SUBSCRIPTION_DATA);
- 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:
-
- 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