Commit 66897ee9 authored by Akseppal's avatar Akseppal
Browse files

modify tests/CMakeLists.txt and add unit tests

parent c2a83619
macro(add_affordance_test test_name)
add_executable(${ARGV})
target_link_libraries(${test_name}
hpp-affordance
# Copyright 2016 CNRS-LAAS
#
# Author: Anna Seppala
#
# This file is part of hpp-affordance
# hpp-affordance is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# hpp-affordance is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Lesser Public License for more details.
# You should have received a copy of the GNU Lesser General Public License
# along with hpp-affordance If not, see <http://www.gnu.org/licenses/>.
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src)
# Make Boost.Test generates the main function in test cases.
#ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN)
# ADD_TESTCASE(NAME)
# ------------------------
#
# Define a test named `NAME'.
#
# This macro will create a binary from `NAME.cc', link it against
# Boost and add it to the test suite.
#
macro(add_testcase NAME GENERATED)
IF (${GENERATED} STREQUAL TRUE)
add_executable(${NAME} ${CMAKE_CURRENT_BINARY_DIR}/${NAME.cc)
ELSE()
add_executable(${NAME} ${NAME}.cc)
ENDIF()
add_test(${NAME} ${RUNTIME_OUTPUT_DIRECTORY}/${NAME})
PKG_CONFIG_USE_DEPENDENCY(${NAME} hpp-fcl)
target_link_libraries(${NAME}
${Boost_LIBRARIES}
${PROJECT_NAME}
hpp-affordance
)
add_test(${test_name} ${EXECUTABLE_OUTPUT_PATH}/${test_name})
endmacro(add_affordance_test)
message ("executable output path: ${EXECUTABLE_OUTPUT_PATH}")
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${Boost_INCLUDE_DIRS})
endmacro(add_testcase)
message ("current binary dir:, ${CMAKE_CURRENT_BINARY_DIR}")
message ("boos include dir: ${Boost_INCLUDE_DIRS}")
# add_affordance_test(test-create-mesh test-create-mesh.cc)
# add_affordance_test(test-create-affordance test-main3.cc)
#add_affordance_test(test-basic test-main.cc)
add_affordance_test(test-create-mesh test-create-mesh.cc)
add_affordance_test(test-create-affordance test-main3.cc)
add_testcase (test-operations FALSE)
add_testcase (test-one-triangle FALSE)
// Copyright (C) 2016 LAAS-CNRS
// Author: Anna Seppala
//
// This file is part of the hpp-affordance.
//
// hpp-affordance is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// hpp-affordance is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with hpp-affordance. If not, see <http://www.gnu.org/licenses/>.
#include <hpp/affordance/affordance-extraction.hh>
#include <hpp/affordance/operations.hh>
#include <hpp/fcl/BVH/BVH_model.h>
#include <hpp/fcl/shape/geometric_shape_to_BVH_model.h>
#define BOOST_TEST_MODULE test-one-triangle
#include <boost/test/included/unit_test.hpp>
BOOST_AUTO_TEST_SUITE (test_affordance)
BOOST_AUTO_TEST_CASE (one_triangle)
{
hpp::affordance::SupportOperationPtr_t support (new hpp::affordance::SupportOperation());
hpp::affordance::LeanOperationPtr_t lean (new hpp::affordance::LeanOperation(0.1));
std::vector <hpp::affordance::OperationBasePtr_t> operations;
operations.push_back(support);
operations.push_back(lean);
std::vector<fcl::Vec3f> vertices;
std::vector<fcl::Triangle> triangles;
typedef fcl::BVHModel<fcl::OBBRSS> Model;
boost::shared_ptr<Model> model (new Model ());
fcl::Vec3f vert1 (0,0,0);
fcl::Vec3f vert2 (1,0,0);
fcl::Vec3f vert3 (0,1,0);
vertices.push_back (vert1);
vertices.push_back (vert2);
vertices.push_back (vert3);
fcl::Triangle tri (0,1,2);
triangles.push_back (tri);
fcl::Matrix3f R;
R.setIdentity ();
fcl::Vec3f T (0,0,0);
fcl::Transform3f pose (R, T);
model->beginModel ();
model->addSubModel (vertices, triangles);
model->endModel ();
boost::shared_ptr <fcl::CollisionObject> obj (new fcl::CollisionObject(model, pose));
hpp::affordance::SemanticsDataPtr_t h = hpp::affordance::affordanceAnalysis (obj, operations);
BOOST_CHECK_MESSAGE (h->affordances_.size() == 2,
"strictly two affordance types should exist.");
BOOST_CHECK_MESSAGE (h->affordances_[0].size() == 1,
"strictly one support affordance should have been found.");
BOOST_CHECK_MESSAGE (h->affordances_[1].size() == 0,
"no lean affordance should have been found at this point.");
}
BOOST_AUTO_TEST_SUITE_END ()
// Copyright (C) 2016 LAAS-CNRS
// Author: Anna Seppala
//
// This file is part of the hpp-affordance.
//
// hpp-affordance is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// hpp-affordance is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with hpp-affordance. If not, see <http://www.gnu.org/licenses/>.
#include <hpp/affordance/operations.hh>
#include <hpp/affordance/fwd.hh>
#define BOOST_TEST_MODULE test-operations
#include <boost/test/included/unit_test.hpp>
BOOST_AUTO_TEST_SUITE (test_affordance)
BOOST_AUTO_TEST_CASE (operations)
{
hpp::affordance::SupportOperationPtr_t support (new hpp::affordance::SupportOperation(0.3));
hpp::affordance::LeanOperationPtr_t lean (new hpp::affordance::LeanOperation(0.1));
std::vector <hpp::affordance::OperationBasePtr_t> operations;
operations.push_back(support);
operations.push_back(lean);
const fcl::Vec3f normal1(0, 0, 1);
BOOST_CHECK_MESSAGE (support->zWorld_ == normal1,
"default value for zWorld should be " << normal1);
BOOST_CHECK_MESSAGE (lean->margin_ == 0.1,
"margin should match the one given when creating operation");
BOOST_CHECK_MESSAGE (operations.size () == 2,
"operation vector should have size 2 after adding support and lean");
}
BOOST_AUTO_TEST_SUITE_END ()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment