Marine systems simulation

The testing of FhSim features is based on the Google C++ Testing Framework (Primer :

Unit tests

Unit tests are used for testing smaller parts of the software, such as functions or classes. They are usually collected in a separate directory, containing a CMakeLists.txt, a source file specifying the main function based on Google Test and a collection of source files specifying the tests. Conventionally, the test files are named after the unit they are testing.

The unit tests should preferably be independent of resources which can not be assumed to be present on all supported platforms, and their run time should be short. If this is not the case, their name should be added the suffix _NO_CI. This disables these tests from being run on the build servers.

Running the tests

  • Build the project and locate the test executable, e.g. testFhSimBase.
  • Run the executable from the working directory
  • The Google Test command line arguments can be used e.g. for only running selected tests.

SimObject tests

fhsim/testing/tools contains methods frequently used when testing features in FhSim and it's external libraries. They include code for parsing output files, calculating errors and standard setups of simulation tests. The methods compromise the shared library tools, which is used when testing SimObjects from external projects.

fhsim/testing/test contains the individual collections of tests, which include unit tests of some of the tools. The tests are run by Run_Test.cpp and compiled to the executable testFhSim.

fhsim/testing/in contains input files required by some of the available tests.

Running The Tests

  • Build the project and locate the executable testFhSim.
  • Locate the working directory where you have FhSim installed
  • Run the executable testFhSim from the working directory with the following four arguments:
    1. The absolute location of fhsim/testing
    2. The verbosity to the screen ('0' - Nolog, '1' - Error, '2' - Warning, '3' - Info, '4' - Debug") -# The verbosity to the logfile ('0' - Nolog, '1' - Error, '2' - Warning, '3' - Info, '4' - Debug")
    3. Option to get prompted for the ogre settings (y/n)

An example (Windows):

testFhSim.exe C://DEV//fhsim//testing 1 4 n

If you wish to run the tests from outside the FhSim "bin" directory, and you have not set the FHSIM_DIR environment variable, you kan specify its path as a fifth argument.

Testing Your Code

SimObjects and specific methods/calculations are usually tested in their respective libraries or projects.
Examples of unit tests and simulation tests are found in fhsim/testing/test. You are welcome to test your code in any way.

Common tools and set-ups used when testing external simobject libraries are found in the library "tools" installed and compiled from FhSim/testing/tools.

How To Add A Simple SimObject Test

You have made a SimOBject CSomename.

  • Put the inputfile containing the SimObject (CSomename) you want to test test in a folder testing/in/SimObj-CSomename, name the inputfile SimObj-CSomename_in.xml.
  • Put what you consider to be a expected output in the same folder, name the expected file SimObj-CSomename_exp.txt.
  • Create your test testing/tests/SimObj-CSomename_Test.cpp. An example of a test that compares all results in the results with your exp-file:
#include "TestSetup.h"
namespace {
const std::string dirname = "SimObj-CSomename";
const double simTime = 11.0;
const double realTime = 30.0;
TEST(SimObject, CSomename) {
std::vector<bool> initSim = test::SetUpTest(dirname, simTime, realTime);
ASSERT_TRUE(initSim[0]); // Parsing of inputfile and initiation
ASSERT_TRUE(initSim[1]); // Simulation
std::vector<double> rmsError = test::RmsComparison(dirname);
for (size_t i = 0 ; i < rmsError.size() ; ++i) {
EXPECT_NEAR(0, rmsError[i], 0.01);