Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 3719def1 authored by promayon's avatar promayon
Browse files

NEW CamiTKTestMacro simplifies unit and integration testing (see...

NEW CamiTKTestMacro simplifies unit and integration testing (see tools/lml/test/CMakeLists.txt for an example)
NEW correct test for lml and pml
NEW start cmake macro documentation using doxygen (need more work)
FIXED negative values now possible for region growing threshold
FIXED compilation warning on gcc (double to float precision loss)



git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@670 ec899d31-69d1-42ba-9299-647d76f65fb3
parent c012dd80
......@@ -31,6 +31,8 @@ include(CamiTKInternalBuild)
include(CamiTKVariables)
# include CamiTK generic macros from CMAKE_MODULE_PATH directory
include(CamiTKMacros)
# include CamiTK test macros
include(CamiTKTestMacros)
# include CamiTK log configuration
include(CamiTKLog)
# include CamiTK auto-documentation generation
......
......@@ -127,8 +127,11 @@
</item>
<item row="0" column="2">
<widget class="QSpinBox" name="lowThresholdSpinBox">
<property name="minimum">
<number>-1000000</number>
</property>
<property name="maximum">
<number>9999</number>
<number>1000000</number>
</property>
</widget>
</item>
......@@ -141,6 +144,9 @@
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="highThresholdSpinBox">
<property name="minimum">
<number>-1000000</number>
</property>
<property name="maximum">
<number>9999</number>
</property>
......
#
# CamiTK Macros
# CamitK Macros
#
# MACRO get_subdirectories
#
# usage:
......@@ -130,32 +129,51 @@ macro(get_directory_name FullPathDirectory VariableName)
string(TOUPPER ${${VariableName}} ${VariableName}_CMAKE)
endmacro()
# MACRO export_headers
#
# Duplicate headers installation:
# - one is used at compiled time and puts everything in
# ${CAMITK_BUILD_DIR}/include/${GroupName}/${ComponentName}/${SubdirName}
# - the other one is used at installation time and puts everything in
# ${CAMITK_INSTALL_ROOT}/include/${GroupName}/${ComponentName}/${SubdirName}
#
# Note: if you use the CEP option, CMAKE_BINARY_DIR is used instead of CAMITK_BUILD_DIR
# and CMAKE_INSTALL_PREFIX is used instead of CAMITK_INSTALL_ROOT
#
# usage:
# export_headers(HeaderFile1.h HeaderFile2.h ...
# COMPONENT ComponentName
# [GROUP GroupName]
# [SUBDIRECTORY SubdirName]
# [CEP]
# )
#
# FILES = list of files to install
# COMPONENT = name of the component to use. This is also the include subdirectory name
# used for copying the file
# GROUP = the name of the group this install should be using group will be
# prepend to the component name.
# SUBDIRECTORY = optional subdirectory to use in ${CAMITK_INCLUDE_DIR}/include/${ComponentName}
# CEP = optional, states that the files should installed CEP wise
#!
#! \addtogroup CamiTKMacros
#!
#! export_headers is a macro that install header files at build and install time
#!
#! Duplicate headers installation:
#! - one is used at compiled time and puts everything in
#! ${CAMITK_BUILD_DIR}/include/${GroupName}/${ComponentName}/${SubdirName}
#! - the other one is used at installation time and puts everything in
#! ${CAMITK_INSTALL_ROOT}/include/${GroupName}/${ComponentName}/${SubdirName}
#!
#! \note
#! if you use the CEP option, CMAKE_BINARY_DIR is used instead of CAMITK_BUILD_DIR
#! and CMAKE_INSTALL_PREFIX is used instead of CAMITK_INSTALL_ROOT
#!
#! Usage:
#! \code
#! export_headers(HeaderFile1.h HeaderFile2.h ...
#! COMPONENT ComponentName
#! [GROUP GroupName]
#! [SUBDIRECTORY SubdirName]
#! [CEP]
#! )
#! \endcode
#!
#! \param HeaderFileX.h (required) A list of header files to install
#! \param COMPONENT name of the component to use. This is also the include subdirectory name
#! used for copying the file
#! \param GROUP (optional) the name of the group this install should be using group will be
#! prepend to the component name.
#! \param SUBDIRECTORY (optional) subdirectory to use in ${CAMITK_INCLUDE_DIR}/include/${ComponentName}
#! \param CEP (optional) states that the files should installed CEP wise
#!
#! Example invocation:
#!
#! \code
#!
#! #--------------
#! # installation
#! #--------------
#! export_headers(${MYPROJECT_HEADERS}
#! COMPONENT ${MYPROJECT_NAME}
#! )
#!
#! \endcode
macro(export_headers)
parse_arguments(EXPORT_HEADER
......
# see also http://www.cmake.org/cmake/help/v2.8.8/cmake.html#section_PropertiesonTests
#!
#! \addtogroup CamiTKMacros
#!
#! camitk_init_test is a macro to initialize a group of test (for the same command)
#! It is used to initialize a series of tests for a given target.
#! Usually this is placed in the same CMakeLists.txt as the add_executable() cmake instruction or
#! camitk_application() macro
#!
#! It does few useful things:
#! - check if the target (name of the executable to run) is properly defined
#! - initialize test id (then automatically incremented in camitk_test_declare
#! - initialize test output directory
#!
#! Usage:
#! \code
#! camitk_init_test(target)
#! \endcode
#!
#! \param target (required) The executable target to use during all the test series
#!
#! Example invocation:
#!
#! \code
#!
#! add_executable(myprogram)
#!
#! ...
#! # Start the test series for myprogram
#! camitk_init_test(myprogram)
#! camitk_add_test(...) # will be called myprogram_1
#! ...
#! camitk_add_test(...) # myprogram_2
#!
#! \endcode
#
#! @sa camitk_add_test
macro(camitk_init_test)
parse_arguments(CAMITK_INIT_TEST
"" # possible lists
""
${ARGN}
)
set(CAMITK_TEST_ID "0")
set(CAMITK_TEST_LIST "")
# check for executable
if(NOT CAMITK_INIT_TEST_DEFAULT_ARGS)
message(FATAL_ERROR "Initializing test ${CAMITK_TEST_BASENAME} cannot proceed: please specify the target in brackets")
else()
if(NOT TARGET ${CAMITK_INIT_TEST_DEFAULT_ARGS})
message(FATAL_ERROR "Initializing test ${CAMITK_TEST_BASENAME} cannot proceed: ${CAMITK_INIT_TEST_DEFAULT_ARGS} is not a proper target")
endif()
endif()
set(CAMITK_TEST_BASENAME ${CAMITK_INIT_TEST_DEFAULT_ARGS})
message(STATUS "Initializing test series for ${CAMITK_TEST_BASENAME}")
set(CAMITK_INIT_TEST_EXECUTABLE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CAMITK_INIT_TEST_DEFAULT_ARGS})
endmacro()
#!
#! \addtogroup CamiTKMacros
#!
#! camitk_add_test is a macro to add a new test to the CTest infrastructure
#! It encapsulates CMake add_test and adds useful way of testing programs.
#! It cannot operate on its on, you need to call camitk_init_test first (and only once) before
#! calling camitk_add_test
#!
#! Details on the runned test can be found in ${CMAKE_BINARY_DIR}/Testing/Temporary/target#
#! where target is the executable name (see camitk_init_test() macro), and # is the test order number.
#!
#! Usage:
#! \code
#! camitk_add_test(EXECUTABLE_ARGS "arg1 arg2 arg3"
#! PASS_FILE pristineOutput
#! PASS_REGULAR_EXPRESSION regexp
#! FAIL_REGULAR_EXPRESSION regexp
#! )
#! \endcode
#!
#! \param EXECUTABLE_ARGS (optional) The executable arguments (all in double quotes), typically each test will have different arguments. Can be empty
#! \param PASS_FILE (optional) If specified the test to perform is to compare the output of the command to this file. It the output is the same, then the test is passed, otherwise it is failed.
#! \param PASS_REGULAR_EXPRESSION (optional) This is equivalent to "PASS_REGULAR_EXPRESSION regexp" property for the test, see http://www.cmake.org/Wiki/CTest:FAQ#My_test_does_not_return_non-zero_on_failure._What_can_I_do.3F
#! \param FAIL_REGULAR_EXPRESSION This is equivalent to "FAIL_REGULAR_EXPRESSION regexp" property for the test, see http://www.cmake.org/Wiki/CTest:FAQ#My_test_does_not_return_non-zero_on_failure._What_can_I_do.3F
#!
#! If no argument are given, it does the equivalent as add_test(name target)
#!
#! \note
#! You can only choose one between nothing, PASS_FILE, PASS_REGULAR_EXPRESSION and FAIL_REGULAR_EXPRESSION
#!
#! Example invocation:
#!
#! \code
#!
#! add_executable(myprogram)
#!
#! ...
#! # Start the test series for myprogram
#! camitk_init_test(myprogram)
#! camitk_add_test(EXECUTABLE_ARGS "-a inputfile.xml -c" PASS_FILE pristineOuputToCompareTo.xml) # will be called myprogram1
#! ...
#! camitk_add_test(...) # myprogram2
#!
#! \endcode
#
#! @sa camitk_init_test
macro(camitk_add_test)
parse_arguments(CAMITK_ADD_TEST
"EXECUTABLE_ARGS;PASS_FILE;PASS_REGULAR_EXPRESSION;FAIL_REGULAR_EXPRESSION" # possible lists
"" # possible options
${ARGN}
)
math(EXPR CAMITK_TEST_ID "${CAMITK_TEST_ID} + 1")
set(CAMITK_TEST_NAME "${CAMITK_TEST_BASENAME}${CAMITK_TEST_ID}")
set(CAMITK_TEST_LIST ${CAMITK_TEST_LIST} ${CAMITK_TEST_NAME})
message(STATUS "Configuring test ${CAMITK_TEST_NAME}")
# create test output directory
set(CAMITK_TEST_OUTPUT_DIR "${CMAKE_BINARY_DIR}/Testing/Temporary/${CAMITK_TEST_NAME}")
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CAMITK_TEST_OUTPUT_DIR})
# check which test is to be done
if(CAMITK_ADD_TEST_PASS_FILE)
add_test(NAME ${CAMITK_TEST_NAME}
COMMAND ${CMAKE_COMMAND}
-DCAMITK_TEST_COMMAND=${CAMITK_INIT_TEST_EXECUTABLE}
-DCAMITK_TEST_COMMAND_ARG=${CAMITK_ADD_TEST_EXECUTABLE_ARGS}
-DCAMITK_TEST_PASS_FILE=${CAMITK_ADD_TEST_PASS_FILE}
-DCAMITK_TEST_OUTPUT_DIR=${CAMITK_TEST_OUTPUT_DIR}
-DCAMITK_TEST_NAME=${CAMITK_TEST_NAME}
-P ${CAMITK_SOURCE_DIR}/cmake/modules/CamiTKTestPassFile.cmake
)
else()
# set output files for more advanced checking/debugging
set(CAMITK_TEST_COMMAND_FILE ${CAMITK_TEST_OUTPUT_DIR}/command) # which command is run to test the exectable
# cleanup
execute_process(COMMAND ${CMAKE_COMMAND} -E remove -f ${CAMITK_TEST_COMMAND_FILE} )
file(WRITE ${CAMITK_TEST_COMMAND_FILE} "Test command: ${CAMITK_INIT_TEST_EXECUTABLE} ${CAMITK_ADD_TEST_EXECUTABLE_ARGS}\nPASS_REGULAR_EXPRESSION: '${CAMITK_ADD_TEST_PASS_REGULAR_EXPRESSION}'\n")
if(CAMITK_ADD_TEST_EXECUTABLE_ARGS)
# expands all arguments
string(REPLACE " " ";" CAMITK_TEST_COMMAND_ARG_LIST ${CAMITK_ADD_TEST_EXECUTABLE_ARGS})
else()
set(CAMITK_TEST_COMMAND_ARG_LIST)
endif()
# add the simple test command
add_test(NAME ${CAMITK_TEST_NAME}
COMMAND ${CAMITK_INIT_TEST_EXECUTABLE} ${CAMITK_TEST_COMMAND_ARG_LIST}
)
# add properties if needed
if(CAMITK_ADD_TEST_PASS_REGULAR_EXPRESSION)
set_tests_properties(${CAMITK_TEST_NAME} PROPERTIES PASS_REGULAR_EXPRESSION ${CAMITK_ADD_TEST_PASS_REGULAR_EXPRESSION})
else()
if(CAMITK_ADD_TEST_FAIL_REGULAR_EXPRESSION)
set_tests_properties(${CAMITK_TEST_NAME} PROPERTIES FAIL_REGULAR_EXPRESSION ${CAMITK_ADD_TEST_FAIL_REGULAR_EXPRESSION})
endif()
endif()
endif()
endmacro()
#! This CMake file run a command and put the output in
#! a given file
#! \note
#! You have to call camitk_test_init(..) first to prepare all variables
#
# Inspired from http://stackoverflow.com/questions/3305545/how-to-adapt-my-unit-tests-to-cmake-and-ctest
# and http://www.cmake.org/pipermail/cmake/2009-July/030619.html
# declare outputfiles
set(CAMITK_TEST_COMMAND_FILE ${CAMITK_TEST_OUTPUT_DIR}/command) # which command is run to test the exectable
set(CAMITK_TEST_COMMAND_RESULT_FILE ${CAMITK_TEST_OUTPUT_DIR}/command-result) # the exit result (0=success, 1=failure) of the tested command goes in this file
set(CAMITK_TEST_COMMAND_OUTPUT_FILE ${CAMITK_TEST_OUTPUT_DIR}/command-output) # the output of the tested command goes in this files
set(CAMITK_TEST_PASS_FILE_COMMAND_FILE ${CAMITK_TEST_OUTPUT_DIR}/test) # which command is run to diff the files
set(CAMITK_TEST_PASS_FILE_OUTPUT_FILE ${CAMITK_TEST_OUTPUT_DIR}/test-output) # output of the diff cmake command
set(CAMITK_TEST_PASS_FILE_RESULT_FILE ${CAMITK_TEST_OUTPUT_DIR}/test-result) # exit result (0=success, 1=failure)
# remove all
execute_process(COMMAND ${CMAKE_COMMAND} -E remove -f ${CAMITK_TEST_COMMAND_FILE} ${CAMITK_TEST_COMMAND_RESULT_FILE} ${CAMITK_TEST_COMMAND_OUTPUT_FILE} ${CAMITK_TEST_PASS_FILE_COMMAND_FILE} ${CAMITK_TEST_PASS_FILE_OUTPUT_FILE} ${CAMITK_TEST_PASS_FILE_RESULT_FILE})
# First run the executable
file(WRITE ${CAMITK_TEST_COMMAND_FILE} "${CAMITK_TEST_COMMAND} ${CAMITK_TEST_COMMAND_ARG}")
# expands all arguments
string(REPLACE " " ";" CAMITK_TEST_COMMAND_ARG_LIST ${CAMITK_TEST_COMMAND_ARG})
execute_process(
COMMAND ${CAMITK_TEST_COMMAND} ${CAMITK_TEST_COMMAND_ARG_LIST}
RESULT_VARIABLE CAMITK_TEST_COMMAND_RESULT
OUTPUT_VARIABLE CAMITK_TEST_COMMAND_OUTPUT
# WORKING_DIRECTORY
)
file(WRITE ${CAMITK_TEST_COMMAND_RESULT_FILE} ${CAMITK_TEST_COMMAND_RESULT})
file(WRITE ${CAMITK_TEST_COMMAND_OUTPUT_FILE} ${CAMITK_TEST_COMMAND_OUTPUT})
# Then compare output
file(WRITE ${CAMITK_TEST_PASS_FILE_COMMAND_FILE} "${CMAKE_COMMAND} -E compare_files ${CAMITK_TEST_PASS_FILE} ${CAMITK_TEST_COMMAND_OUTPUT_FILE}")
execute_process(
COMMAND ${CMAKE_COMMAND} -E compare_files ${CAMITK_TEST_PASS_FILE} ${CAMITK_TEST_COMMAND_OUTPUT_FILE}
RESULT_VARIABLE CAMITK_TEST_PASS_FILE_RESULT
OUTPUT_VARIABLE CAMITK_TEST_PASS_FILE_OUTPUT
OUTPUT_QUIET
ERROR_QUIET
)
file(WRITE ${CAMITK_TEST_PASS_FILE_OUTPUT_FILE} ${CAMITK_TEST_PASS_FILE_OUTPUT})
file(WRITE ${CAMITK_TEST_PASS_FILE_RESULT_FILE} ${CAMITK_TEST_PASS_FILE_RESULT})
# check result
if( CAMITK_TEST_PASS_FILE_RESULT )
message(SEND_ERROR "${CAMITK_TEST_NAME}: ${CAMITK_TEST_COMMAND_OUTPUT_FILE} does not match ${CAMITK_TEST_PASS_FILE}" )
endif()
\ No newline at end of file
......@@ -141,6 +141,7 @@ if(NOT ${CAMITK_INSTALL_ROOT} EQUAL "")
# include useful modules
include(CamiTKVariables)
include(CamiTKMacros)
include(CamiTKTestMacros)
# set install path
set (CMAKE_INSTALL_PREFIX ${CAMITK_INSTALL_ROOT} CACHE PATH "Path to install dir (deduced from CAMITK_INSTALL_ROOT)" FORCE)
......
......@@ -91,7 +91,7 @@ WARN_LOGFILE =
#---------------------------------------------------------------------------
INPUT = @DOXYGEN_INPUT_LIST@
INPUT_ENCODING = UTF-8
FILE_PATTERNS =
FILE_PATTERNS = *.h *.h.in *.cmake
RECURSIVE = YES
EXCLUDE =
EXCLUDE_SYMLINKS = NO
......
......@@ -87,6 +87,17 @@
* @page wiki CamiTK wiki
* Installation instructions, many tips and tutorials are proposed in the <a href="https://forge.imag.fr/plugins/mediawiki/wiki/camitk/index.php/Main_Page">CamiTK wiki</a> (you may want to edit it and share your knowledge).
*
* \namespace CMake
*
* \brief A pseudo-namespace used to group CMake macros and functions.
*
* This is not a regular C++ namespace. It is juse used to group the CMake
* macros and function of the CamiTK build system.
*
* \page CamiTKBuildSystem The CamiTK Build System (based on CMake Macros)
*
* \defgroup CamiTKMacros CamiTK CMake Macros
* This module contains CMake macros and functions which can be used by CamiTK developers.
*
**/
......
......@@ -368,7 +368,7 @@ public:
* @param b the value of the flag (true means "is selected")
* @param recursive if true (default), also updates the children Component selection flags.
*/
virtual void setSelected(const bool, const bool recursive = true);
virtual void setSelected(const bool b, const bool recursive = true);
/// get the file name where the data have to be stored/were stored
const QString getFileName() const;
......
......@@ -319,6 +319,7 @@ void ImageComponent::setViewIn3D(bool toggle) {
if (arbitrarySlices) {
arbitrarySlices->setViewSliceIn3D(false);
}
if (volumeRenderingChild) {
volumeRenderingChild->setVisibility(InteractiveViewer::get3DViewer(), false);
}
......@@ -410,6 +411,7 @@ void ImageComponent::pixelPicked(double x, double y, double z, SingleImageCompon
// Update each child even the one who is asking i order to display correctly the pixel pixed.
foreach( Component *dc, getChildren() ) {
SingleImageComponent *child = dynamic_cast<SingleImageComponent*>(dc);
if (child) {
child->setSlice(x, y, z);
}
......@@ -458,6 +460,7 @@ vtkSmartPointer<vtkWindowLevelLookupTable> ImageComponent::getLut() {
void ImageComponent::setSelected(const bool b, const bool) {
foreach(Component *dc, getChildren()) {
SingleImageComponent *child = dynamic_cast<SingleImageComponent*>(dc);
if ( child ) {
child->singleImageSelected(b);
}
......@@ -481,24 +484,31 @@ void ImageComponent::refresh() const {
}
}
// -------------------- getBoundingBox --------------------
vtkSmartPointer<vtkPolyData> ImageComponent::getBoundingBox() {
if (! originalImageData)
return NULL;
double * bounds = originalImageData->GetBounds();
float x[8][3]={{bounds[0],bounds[2],bounds[4]}, {bounds[1],bounds[2],bounds[4]},
double x[8][3]= {{bounds[0],bounds[2],bounds[4]}, {bounds[1],bounds[2],bounds[4]},
{bounds[1],bounds[3],bounds[4]}, {bounds[0],bounds[3],bounds[4]},
{bounds[0],bounds[2],bounds[5]}, {bounds[1],bounds[2],bounds[5]},
{bounds[1],bounds[3],bounds[5]}, {bounds[0],bounds[3],bounds[5]}};
vtkIdType pts[6][4]={{0,1,2,3}, {4,5,6,7}, {0,1,5,4},
{1,2,6,5}, {2,3,7,6}, {3,0,4,7}};
{bounds[1],bounds[3],bounds[5]}, {bounds[0],bounds[3],bounds[5]}
};
vtkIdType pts[6][4]= {{0,1,2,3}, {4,5,6,7}, {0,1,5,4},
{1,2,6,5}, {2,3,7,6}, {3,0,4,7}
};
vtkSmartPointer<vtkPolyData> bbox = vtkSmartPointer<vtkPolyData>::New();
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkCellArray> polys = vtkSmartPointer<vtkCellArray>::New();
vtkSmartPointer<vtkFloatArray> scalars = vtkSmartPointer<vtkFloatArray>::New();
for (int i=0; i<8; i++) points->InsertPoint(i,x[i]);
for (int i=0; i<6; i++) polys->InsertNextCell(4,pts[i]);
for (int i=0; i<8; i++)
points->InsertPoint(i,x[i]);
for (int i=0; i<6; i++)
polys->InsertNextCell(4,pts[i]);
bbox->SetPoints(points);
bbox->SetPolys(polys);
......
......@@ -4,39 +4,16 @@ set(LML_LIBRARIES lml ${LIBXML2_LIBRARIES})
target_link_libraries(lmltest ${LML_LIBRARIES})
add_dependencies(lmltest lml)
#----------
# Testing
# TODO build one big lml file with every tests in it, use -o and check that output is identical to input
#----------
# TODO compare output csv with a static output csv (that it should produce)
add_test(lmltestRun ${CAMITK_BIN_DIR}/lmltest)
add_test(lmlTestCubeIn ${CAMITK_BIN_DIR}/lmltest -i ${CMAKE_CURRENT_SOURCE_DIR}/cube.lml)
# set_tests_properties(lmlTestCubeIn PROPERTIES PASS_REGULAR_EXPRESSION "<?xml version="1.0" encoding="UTF-8"?>
# <!-- physical model load file -->
# <loads xmlns='http://www-timc.imag.fr/load'
# xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
# <load xsi:type="Translation">
# <appliedTo>0-3</appliedTo>
# <valueEvent date="0" value="14"/>
# <direction x="0" y="1" z="0"/>
# <unit>nm</unit>
# </load>
#
# <load xsi:type="Force">
# <appliedTo>4</appliedTo>
# <valueEvent date="0" value="50"/>
# <valueEvent date="0.5" value="0"/>
# <direction x="1" y="0" z="1"/>
# <unit>kN</unit>
# </load>
#
# <load xsi:type="Force">
# <appliedTo>6</appliedTo>
# <valueEvent date="0.5" value="50"/>
# <direction x="-1" y="0" z="-1"/>
# <unit>kN</unit>
# </load>
#
# </loads>")
add_test(lmlTestCubeOut ${CAMITK_BIN_DIR}/lmltest -i ${CMAKE_CURRENT_SOURCE_DIR}/cube.lml -o lmltestcubeout.lml)
add_test(lmlTestCubeCSV ${CAMITK_BIN_DIR}/lmltest -i ${CMAKE_CURRENT_SOURCE_DIR}/cube.lml -plot lmltestcubeout.csv)
add_test(lmlTestShouldFail ${CAMITK_BIN_DIR}/lmltest -error)
set_tests_properties(lmltestRun lmlTestCubeIn lmlTestCubeOut lmlTestCubeCSV lmlTestShouldFail PROPERTIES LABELS lml)
camitk_init_test(lmltest)
# should pass because lmltest run with no arguments shows usage and exit success
camitk_add_test()
# should pass because reading test.lml should not modify it (input == output)
camitk_add_test(EXECUTABLE_ARGS "-i ${CMAKE_CURRENT_SOURCE_DIR}/test.lml"
PASS_FILE ${CMAKE_CURRENT_SOURCE_DIR}/test.lml )
# should pass because invoking lmltest with a faulty arguments results in printing
# an "Argument error" message (and exit failure)
camitk_add_test(EXECUTABLE_ARGS "-error" PASS_REGULAR_EXPRESSION "Argument errors: ")
\ No newline at end of file
......@@ -47,16 +47,20 @@ void testActivation(std::string imlFile, double dt, std::string outcsv = "") {
// open the output file if needed
std::ofstream outStream;
if (outcsv != "") {
outStream.open(outcsv.c_str());
}
double t;
if (outcsv != "") {
outStream << "t ";
for (unsigned int i=0;i<list.numberOfLoads();i++) {
for (unsigned int i=0; i<list.numberOfLoads(); i++) {
outStream << list.getLoad(i)->getType() << " ";
}
outStream << std::endl;
}
......@@ -64,51 +68,63 @@ void testActivation(std::string imlFile, double dt, std::string outcsv = "") {
for (t=tmin-dt; t<=tmax+dt; t+=dt) {
std::cout << "---------------------------" << std::endl;
std::cout << "time t=" << t << std::endl;
if (outcsv != "") {
outStream << t << " ";
}
// check all the loads
for (unsigned int i=0; i<list.numberOfLoads();i++) {
for (unsigned int i=0; i<list.numberOfLoads(); i++) {
Load * l = list.getLoad(i);
// print the value
if (l->isActive(t)) {
std::cout << "\t- active ";
std::cout << l->getType() << ": ";
if (l->getDirection().isToward()) {
std::cout << "dir toward Atom#" << l->getDirection().getToward() << ", ";
}
else {
std::cout << "dir=(";
// x
if (l->getDirection().isXSpecified())
std::cout << l->getDirection().getX();
else if (l->getDirection().isXNull())
else
if (l->getDirection().isXNull())
std::cout << "NULL";
else
std::cout << "free";
std::cout << ",";
// y
if (l->getDirection().isYSpecified())
std::cout << l->getDirection().getY();
else if (l->getDirection().isYNull())
else
if (l->getDirection().isYNull())
std::cout << "NULL";
else
std::cout << "free";
std::cout << ",";
// z
if (l->getDirection().isZSpecified())
std::cout << l->getDirection().getZ();
else if (l->getDirection().isZNull())
else
if (l->getDirection().isZNull())
std::cout << "NULL";
else
std::cout << "free";
std::cout << "), ";
}
std::cout << "val=" << l->getValue(t);
std::cout << std::endl;
if (outcsv != "") {
outStream << l->getValue(t) << " ";
}
......@@ -119,6 +135,7 @@ void testActivation(std::string imlFile, double dt, std::string outcsv = "") {
}
}
}
if (outcsv != "") {
outStream << std::endl;
}
......@@ -144,7 +161,8 @@ int main(int argc, char *argv[]) {
// test the arguments
inputTest = outputTest = activationTest = ansysOutput = false;
for (int i=1;i<argc;i++) {
for (int i=1; i<argc; i++) {
if (!strcmp(argv[i],"-i")) {
ifile = argv[i+1];
inputTest = true;
......@@ -173,7 +191,14 @@ int main(int argc, char *argv[]) {
if ((!activationTest && !inputTest && !outputTest) ||
(!inputTest && ansysOutput) // can't do an ansys output if there are no input file