Linking third party libraries (Boost) with Forecast

In this article I will explain how to set up Forecast so you can use third party libraries. This is an extremely powerful feature that allows you to leverage code written by others to solve common problems. In this example I will use Boost library as an example and Boost.Regex to be more precise.

The first thing to do is to copy over header files to “Facilita install folder“/Forecast/lib/include/ (By default: C:\Program Files (x86)\Facilita\Forecast\lib\include). With boost there are numerous header only libraries, so for most things this is all you will need.

If you actually need to link something together, such as Boost.Regex or Boost.Asio (or any other library), the next step is  to compile our library in Static library (.lib) format. As this part is not something that is specific to Forecast, I will not go into further details about how to do this. For Boost you can find info here: http://www.boost.org/doc/libs/1_48_0/more/getting_started/windows.html
After this is done you need to inform Forecast to link this library during the building process. Go to Your Workspace (Forecast Studio) -> Virtual User -> Profiles -> Select the one MaleExtra you use. Next you need to add needed .lib file.

And now we actually get to the step that this all was actually done for – using the Boost Library! Here I will just show how to do some Boost magic inside VirtualUser class (same principle works for any other place):

Add needed includes to header file (I will use Boost.Math & Boost.Regex):

#include <boost/math/common_factor.hpp>
#include <boost/regex.hpp>

Next some Boost action in cpp file in any of methods (I put it in pre method):

writeMessage("gcd(6, 15)", utils::str(boost::math::gcd(6, 15)));
writeMessage("lcm(6, 15)", utils::str(boost::math::lcm(6, 15)));

string regx = "(([[:lower:]]+)|([[:upper:]]+))+";
string text = "aBBcccDDDDDeeeeeeee";

boost::regex e(regx);
boost::smatch what;

writeMessage("Expression", regx);
writeMessage("Text", text);

if(boost::regex_match(text, what, e, boost::match_extra))
{
writeMessage("** Match found **");
}
else
{
writeMessage("** No Match found **");
}

Boost.Math functions only need that you include header file (#include <boost/math/common_factor.hpp>) and that this file is in some place that Forecast knows about (/lib/include/ directory is the place that Forecast looks for header files).

Leveraging the power of other peoples code and minimising time spent re-inventing the wheel is a powerful way to maximise your productively as a performance tester.

Leave a Reply

Your email address will not be published. Required fields are marked *