Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6996265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:08:02+00:00 2026-05-27T20:08:02+00:00

I’m trying to create a test environment for using an external C++ API so

  • 0

I’m trying to create a test environment for using an external C++ API so that I can test things offline without having to be connected to the actual service. In essence, I want to create my own fake service that will be used for testing purposes. However, I want to be able to change between these two environments easily without having to change a ton of code. Basically, I want to be able to use the external C++ API classes in a test environment somehow. One problem I’m running into is that since the classes are part of an external API, I can’t change them. I can only wrap them in other classes I create. How can I deal with that while being able to create an environment that doesn’t require me changing a ton of code every time I want to switch back and forth? I have some sample code below (the relevant pieces where the API is being used). How can I put these classes below in a test harness? Thanks!

...

SessionOptions sessionOptions;
sessionOptions.setServerHost(d_host.c_str());
sessionOptions.setServerPort(d_port);

Session session(sessionOptions);

if (! session.start())
{
    std::cerr <<"Failed to start session." << std::endl;
    return;
}

if (! session.openService("//blp/mktdata"))
{
    std::cerr <<"Failed to open //blp/mktdata" << std::endl;
    return;
}

...

SubscriptionList subscriptions;

std::set<std::string>::const_iterator cItorSubscriptionStrings(m_SubscriptionStrings.begin());

for ( ; cItorSubscriptionStrings != m_SubscriptionStrings.end(); ++cItorSubscriptionStrings)
{
    subscriptions.add((*cItorSubscriptionStrings).c_str(),
        "LAST_PRICE,BID,ASK,TIME",
        "",
        CorrelationId((char*)(*cItorSubscriptionStrings).c_str()));
}

session.subscribe(subscriptions);

while (true)
{
    Event event = session.nextEvent();
    MessageIterator msgIter(event);

    ...

    while (msgIter.next())
    {
        Message msg = msgIter.message();

        if (event.eventType() == Event::SUBSCRIPTION_DATA)
        {
            if ((msg.hasElement("LAST_PRICE")) || ((msg.hasElement("BID")) && msg.hasElement("ASK")))
            {
                double mid = 0;

                if ((msg.hasElement("BID")) && (msg.hasElement("ASK")))
                {
                    mid = (msg.getElementAsFloat64("BID") + msg.getElementAsFloat64("ASK")) / 2;
                }
                else
                {
                    mid = msg.getElementAsFloat64("LAST_PRICE");
                }

                ...
            }
        }
    }

    ...
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:08:03+00:00Added an answer on May 27, 2026 at 8:08 pm

    One thing you can do is to use the interface (i.e. the header files) and provide an implementation of your own, at least for those functions you care about. To switch between both versions essentially amounts to linking with different libraries: yours for testing, theirs for the real implementation.

    There are a few issues with that which can be addressed e.g. by only retaining the public interface and changing the private interface (on this case compilation needs to be directed at the different declarations, e.g. using different search pathes for the headers):

    • often the stubbed version wants to store different data
    • some object may need to construct private subobjects in specific ways
    • inline function may call other functions you don’t really want to implement
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.