ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

gtest problem with main function

asked 2013-06-01 02:59:35 -0600

madmax gravatar image

updated 2013-06-01 23:15:57 -0600

Hi,

I have a line.cpp with a main function and some other functions I want to test.
Then I have my utest.cpp with my test cases and another main function to call them.

A solution would be to just comment the main function and then test, but that is not the solution I am looking for.
I understand that I can not have multiple main files in my project, but how can I test my functions? Because in the robot_pose_ekf package, there are also two main files and it works.

The CMake relevant part looks like this:

rosbuild_add_executable(line src/line.cpp)

rosbuild_add_gtest(test/utest test/utest.cpp)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-06-02 14:34:13 -0600

joq gravatar image

A simple solution is to move the functions you want to test into another source file, with a header to declare their interfaces. You can compile that into a library or just add it to the source file lists of both the line and test/utest targets.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-06-01 02:59:35 -0600

Seen: 1,545 times

Last updated: Jun 02 '13