Hi,
I just started using CMake and the Boost Libraries. In this progress I encountered some problems.
One of these problems is combining Boost unit tests with cmake. I don't know how to set the whole project up. I tried to set up a simple test project. This contains a main.cpp a comp.cpp and the comp.h
The main.cpp isn't doing anything at the moment. Comp contains a class:
class Comp
{
int add(int a, int b);
int sub(int a, int b);
}
Well the content of the cpp should be obvious I hope.
Additional I wrote the runner.cpp:
#define BOOST_TEST_MODULE "C++ Unit Tests for Calculator"
#include <boost/test/unit_test.hpp>
#include "Comp_Test.h"
and the Comp_Test.h:
#include <boost/test/unit_test.hpp>
#include"inc/Comp.h"
BOOST_AUTO_TEST_SUITE(adder_test_suite);
BOOST_AUTO_TEST_CASE(add_test_case)
{
Adder adder;
BOOST_REQUIRE_EQUAL(adder.add(10,5),15);
}
BOOST_AUTO_TEST_SUITE_END();
The folder structure is as followed:
main
|prog
| |inc
| | |Comp.h
| |main.cpp
| |Comp.cpp
| |CMakelists.txt[1]
|test
| |inc
| | |Comp_Test.h
| |runner.cpp
| |CMakelists.txt[2]
CMakelists.txt[1] should set up the makefile for the project itself and has following content:
cmake_minimum_required(VERSION 2.6)
project(comp)
ENABLE_TESTING()
include_directories(inc)
add_executable(prog
main.cpp
Comp.cpp
)
ADD_TEST(test1 TEST_BINARY_DIRECTORY comp_test)
and the second CMakelists.txt contains:
cmake_minimum_required(VERSION 2.6)
project(Test)
find_package(Boost REQUIRED unit_test_framework)
include_directories(inc)
include_directories(../prog)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
add_executable(test
runner.cpp)
target_link_libraries(
test
${Boost_LIBRARIES}
)
So far am I. I think this contains some errors.
Some questions I couldn't answer myself:
- Is it even possible to separate this in 2 projects like I tried?
- If I don't separate it what happens to the testcode when I don't want to test? I hope it will only be executed if I execute "make test".
Well, sorry for the long code I hope somebody can help me. Thank you in advance for everybody who has taken the effort to read till the end.