Skip to content
Snippets Groups Projects
Commit 980bf79b authored by Joan Solà Ortega's avatar Joan Solà Ortega
Browse files

Merge branch 'frame-base-tests' into 'master'

Ctest configuration

This replicates issue #115 , which in turn traces back to !103, regarding `ctest` and `gtest`.

I finally left the project as this (checkout branch `frame-base-tests`):

  - `wolf/src/tests` --> here all the gtest files are located

  - In `wolf/CMakeLists.txt` 

```cmake
if(BUILD_TESTS)
    enable_testing()
endif()
```

  - In `wolf/src/CMakeLists.txt`

```cmake
if(BUILD_TESTS)    
    MESSAGE("Building tests.")
    add_subdirectory(test)
endif()
```

See merge request !104
parents e6bb58bf cc9ff40c
No related branches found
No related tags found
1 merge request!104Ctest configuration
......@@ -67,6 +67,17 @@ endif()
#OPTION(BUILD_DOC "Build Documentation" OFF)
OPTION(BUILD_TESTS "Build Unit tests" ON)
#############
## Testing ##
#############
#
if(BUILD_TESTS)
# Enables testing for this directory and below.
# Note that ctest expects to find a test file in the build directory root.
# Therefore, this command should be in the source directory root.
#include(CTest) # according to http://public.kitware.com/pipermail/cmake/2012-June/050853.html
enable_testing()
endif()
ADD_SUBDIRECTORY(src)
......@@ -127,13 +138,3 @@ ELSE(UNIX)
TARGET uninstall)
ENDIF(UNIX)
#############
## Testing ##
#############
#
if(BUILD_TESTS)
# Enables testing for this directory and below.
# Note that ctest expects to find a test file in the build directory root.
# Therefore, this command should be in the source directory root.
enable_testing()
endif()
......@@ -21,9 +21,14 @@ option(BUILD_EXAMPLES "Build examples" ON)
# Does this has any other interest
# but for the examples ?
#IF(BUILD_EXAMPLES)
IF(BUILD_EXAMPLES)
set(_WOLF_ROOT_DIR ${CMAKE_SOURCE_DIR})
ENDIF(BUILD_EXAMPLES)
#
# yes, for the tests !
IF(BUILD_TESTS)
set(_WOLF_ROOT_DIR ${CMAKE_SOURCE_DIR})
#ENDIF(BUILD_EXAMPLES)
ENDIF(BUILD_TESTS)
#find dependencies.
......@@ -478,12 +483,6 @@ INSTALL(DIRECTORY ${SPDLOG_INCLUDE_DIRS} DESTINATION "include/iri-algorithms/")
export(PACKAGE ${PROJECT_NAME})
IF(BUILD_EXAMPLES)
#Build examples & tests
MESSAGE("Building examples.")
ADD_SUBDIRECTORY(examples)
ENDIF(BUILD_EXAMPLES)
#############
## Testing ##
#############
......@@ -495,3 +494,9 @@ if(BUILD_TESTS)
endif()
IF(BUILD_EXAMPLES)
#Build examples & tests
MESSAGE("Building examples.")
ADD_SUBDIRECTORY(examples)
ENDIF(BUILD_EXAMPLES)
......@@ -11,6 +11,8 @@ namespace wolf {
class ConstraintFix: public ConstraintSparse<3,2,1>
{
public:
typedef std::shared_ptr<ConstraintFix> Ptr;
public:
// static const unsigned int N_BLOCKS = 2;
......
......@@ -15,6 +15,8 @@ struct IntrinsicsOdom2D : public IntrinsicsBase
class SensorOdom2D : public SensorBase
{
public:
typedef std::shared_ptr<SensorOdom2D> Ptr;
protected:
Scalar k_disp_to_disp_; ///< ratio of displacement variance to displacement, for odometry noise calculation
......
......@@ -12,18 +12,18 @@ include_directories(${PROJECT_SOURCE_DIR}/third_party/spdlog/include/)
## Added these two include_dirs: ######################
#
#CMAKE modules
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules")
MESSAGE(STATUS ${CMAKE_MODULE_PATH})
#SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules")
#MESSAGE(STATUS ${CMAKE_MODULE_PATH})
#
# Include Eigen
FIND_PACKAGE(Eigen 3 REQUIRED)
INCLUDE_DIRECTORIES(${EIGEN_INCLUDE_DIRS})
#FIND_PACKAGE(Eigen 3 REQUIRED)
#INCLUDE_DIRECTORIES(${EIGEN_INCLUDE_DIRS})
#
# Include Ceres
FIND_PACKAGE(Ceres QUIET) #Ceres is not required
IF(Ceres_FOUND)
INCLUDE_DIRECTORIES(${CERES_INCLUDE_DIRS})
ENDIF(Ceres_FOUND)
#FIND_PACKAGE(Ceres QUIET) #Ceres is not required
#IF(Ceres_FOUND)
# INCLUDE_DIRECTORIES(${CERES_INCLUDE_DIRS})
#ENDIF(Ceres_FOUND)
#
## and now gtest_motion_2d works ######################
......@@ -45,6 +45,10 @@ target_link_libraries(gtest_example ${PROJECT_NAME}) #
# ==== IN ALPHABETICAL ORDER! ==== #
# #
# FrameBase classes test
wolf_add_gtest(gtest_frame_base gtest_frame_base.cpp)
target_link_libraries(gtest_frame_base ${PROJECT_NAME})
# LocalParametrizationXxx classes test
wolf_add_gtest(gtest_local_param gtest_local_param.cpp)
target_link_libraries(gtest_local_param ${PROJECT_NAME})
......
/*
* gtest_frame_base.cpp
*
* Created on: Nov 15, 2016
* Author: jsola
*/
#include "utils_gtest.h"
#include "../logging.h"
#include "../frame_base.h"
#include "../sensor_odom_2D.h"
#include "../constraint_odom_2D.h"
#include "../capture_motion.h"
#include <iostream>
using namespace Eigen;
using namespace std;
using namespace wolf;
TEST(FrameBase, GettersAndSetters)
{
FrameBasePtr F = make_shared<FrameBase>(1, make_shared<StateBlock>(2), make_shared<StateBlock>(1));
// getters
ASSERT_EQ(F->id(), 1);
ASSERT_EQ(F->getTimeStamp(), 1);
TimeStamp t;
F->getTimeStamp(t);
ASSERT_EQ(t, 1);
ASSERT_EQ(F->isFixed(), false);
ASSERT_EQ(F->isKey(), false);
}
TEST(FrameBase, StateBlocks)
{
FrameBasePtr F = make_shared<FrameBase>(1, make_shared<StateBlock>(2), make_shared<StateBlock>(1));
ASSERT_EQ(F->getStateBlockVec().size(), 3);
ASSERT_EQ(F->getPPtr()->getVector().size(), 2);
ASSERT_EQ(F->getOPtr()->getVector().size(), 1);
ASSERT_EQ(F->getVPtr(), nullptr);
}
TEST(FrameBase, LinksBasic)
{
FrameBasePtr F = make_shared<FrameBase>(1, make_shared<StateBlock>(2), make_shared<StateBlock>(1));
ASSERT_FALSE(F->getTrajectoryPtr());
ASSERT_FALSE(F->getProblem());
// ASSERT_THROW(f->getPreviousFrame(), std::runtime_error); // protected by assert()
// ASSERT_EQ(f->getStatus(), ST_ESTIMATED); // protected
ASSERT_FALSE(F->getCaptureOf(make_shared<SensorOdom2D>(nullptr, nullptr, 1,1)));
ASSERT_TRUE(F->getCaptureList().empty());
ASSERT_TRUE(F->getConstrainedByList().empty());
ASSERT_EQ(F->getHits() , 0);
}
TEST(FrameBase, LinksToTree)
{
// Problem with 2 frames and one motion constraint between them
ProblemPtr P = Problem::create(FRM_PO_2D);
TrajectoryBasePtr T = P->getTrajectoryPtr();
SensorOdom2D::Ptr S = make_shared<SensorOdom2D>(make_shared<StateBlock>(2), make_shared<StateBlock>(1), 1,1);
P->getHardwarePtr()->addSensor(S);
FrameBasePtr F1 = make_shared<FrameBase>(1, make_shared<StateBlock>(2), make_shared<StateBlock>(1));
T->addFrame(F1);
FrameBasePtr F2 = make_shared<FrameBase>(1, make_shared<StateBlock>(2), make_shared<StateBlock>(1));
T->addFrame(F2);
CaptureMotion::Ptr C = make_shared<CaptureMotion>(1, S, Vector3s::Zero());
F1->addCapture(C);
FeatureBasePtr f = make_shared<FeatureBase>("f", 1);
C->addFeature(f);
ConstraintOdom2D::Ptr c = make_shared<ConstraintOdom2D>(f, F2);
f->addConstraint(c);
// c-by link F2 -> c not yet established
ASSERT_TRUE(F2->getConstrainedByList().empty());
// establish link F2 -> c
F2->addConstrainedBy(c);
// F1 has one capture and no constraints-by
ASSERT_FALSE(F1->getCaptureList().empty());
ASSERT_TRUE(F1->getConstrainedByList().empty());
ASSERT_EQ(F1->getHits() , 0);
// F2 has no capture and one constraint-by
ASSERT_TRUE(F2->getCaptureList().empty());
ASSERT_FALSE(F2->getConstrainedByList().empty());
ASSERT_EQ(F2->getHits() , 1);
// fix and unfix
F1->fix();
ASSERT_TRUE(F1->isFixed());
F1->unfix();
ASSERT_FALSE(F1->isFixed());
// set key
F1->setKey();
ASSERT_TRUE(F1->isKey());
// Unlink
F1->unlinkCapture(C);
ASSERT_TRUE(F1->getCaptureList().empty());
}
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment