Table of Contents

Tests

Define unit tests, based on boost framework . You can know more about boost with this link : http://www.boost.org

Your Unit tests for a specific component, should be placed in the component directory/unittest. If you have used the SolARComponent template, this directory should be already there.

Unit test directory
  • Open {yourcomponent}/unittest/{yourcomponent}unittest.pro

  • You have to describe your unit tests in the file {yourcomponent}unittest.cpp

For example

#define
BOOST_TEST_MODULE \{Yourcomponent}UnitTest

#include <boost/test/unit_test.hpp> (1)
#BOOST_AUTO_TEST_CASE(TestLoadImage) (2)
{ // test execution instructions
}
1 Please note your code contains include of boost
2 You have to define the name of your test thanks to the boost macro "BOOST_AUTO_TEST_CASE".

In this example , the definition of the test case "TestLoadImage" for your component.

It means, that when you will execute the unit test, it will executes this test "TestLoadImage" following the instructions in this declaration. You can define several test cases.

Inside your test, please write a kind of demo main function, but where you check results of your component function thanks to macro BOOST CHECK and/or BOOST_TEST.

You will find easily information about BOOST macro on Internet http://www.boost.org/doc/libs/1_64_0/libs/test/doc/html/index.html [boost.org information,role="external", window="_blank"] .

There is no "main" function, as it is automatically generated by boost (used in unit tests).
  • Please ensure that it contains sufficient tests cases to verify your code is OK (normal case, error cases).

Example here : // Case normal, with an existing image file.

remplacer ici par le nouveau code source SolAR
BOOST_AUTO_TEST_CASE(TestLoadImage)
{ // To simplify this example test, let's suppose we'll test 'float'.
 // Some test are stupid, but all should pass.
 int result= 0;
 std::shared_ptr<IArgoImage> myArgoImage0 = getArgoImageInstance();

....
BOOST_CHECK( myArgoImage0 !=  NULL);
....

// getArgoImageInstance should not return a null pointer result

myArgoImage0->LoadImage("../test.jpg");
BOOST_TEST( result= = 0,"ARGO ERROR: Load Image should return 0");
// As the image indicated exists, loadImage should return 0, as a normal case

}

BOOST_AUTO_TEST_CASE(TestLoadImageInexistante)
{
// Some test are stupid, but all should pass.
int result= 0; std::shared_ptr<IArgoImage>
myArgoImage0 =  getArgoImageInstance();

....
BOOST_TEST(( myArgoImage0 !=  NULL),&quot;ARGO ERROR: ArgoImage should not return null pointer&quot;);

result=  myArgoImage0-&gt;LoadImage(&quot;../test2.jpg&quot;);
BOOST_TEST( result= = -1,&quot;ARGO ERROR: Load Image should return -1&quot;);
....

// As the image indicated does not exist, loadImage should return -1, an error

 }