diff --git a/Applications/Analyze/tests/CMakeLists.txt b/Applications/Analyze/tests/CMakeLists.txt index ce41cc006b..377b4c01db 100644 --- a/Applications/Analyze/tests/CMakeLists.txt +++ b/Applications/Analyze/tests/CMakeLists.txt @@ -1,16 +1,90 @@ find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") -file(GLOB TEST_PROGS "test*.cpp") -file(GLOB TEST_FILES resources/*.osim - resources/*.xml - resources/*.sto - resources/*.mot) +OpenSimAddTest(NAME testAnalyzeTool + LINKLIBS osimTools + RESOURCES resources/BothLegs.osim + resources/PlotterTool.xml + resources/Tug_of_War_ConstantVelocity.sto + resources/Tug_of_War_ConstantVelocity_RampActivation.sto + resources/Tug_of_War_Millard_Iso.osim + resources/Tug_of_War_Setup_Analyze.xml + resources/double_pendulum.osim + resources/double_pendum1sec.sto + resources/plotterGeneratedStates.sto + resources/plotterGeneratedStatesHip45.sto + resources/std_BothLegsHip45__FiberLength.sto + resources/std_BothLegs_fiberLength.sto + ) -OpenSimAddTests( - TESTPROGRAMS ${TEST_PROGS} - DATAFILES ${TEST_FILES} - LINKLIBS osimTools Catch2::Catch2WithMain - ) +OpenSimAddTest(NAME testInducedAccelerations + LINKLIBS osimTools + RESOURCES resources/double_pendulum.osim + resources/double_pendulum_Setup_IAA.xml + resources/double_pendulum_states.sto + resources/gait2392_CMC_Actuators_232.xml + resources/pendulum_controls.xml + resources/std_subject02_running_arms_InducedAccelerations_CENTER_OF_MASS.sto + resources/subject02_Setup_IAA_02_232.xml + resources/subject02_grf_HiFreq.mot + resources/subject02_grf_HiFreq.xml + resources/subject02_running_CMC_controls.xml + resources/subject02_running_CMC_states.sto + resources/subject02_running_RRA_cycle02_sim02_07_v232.osim + ) + +OpenSimAddTest(NAME testJointReactions + LINKLIBS osimTools + RESOURCES resources/DoublePendulum3D.osim + resources/DoublePendulum3D_Setup_JointReaction.xml + resources/DoublePendulum3D_states_degrees.mot + resources/SinglePin.osim + resources/SinglePin_Setup_JointReaction.xml + resources/SinglePin_Setup_JointReaction_FrameKeyword.xml + resources/SinglePin_states.sto + resources/std_DoublePendulum3D_JointReaction_ReactionLoads.sto + resources/std_DoublePendulum3D_JointReaction_ReactionLoads_FrameKeyword.sto + resources/std_SinglePin_JointReaction_ReactionLoads.sto + resources/std_SinglePin_JointReaction_ReactionLoads_FrameKeyword.sto + ) + +OpenSimAddTest(NAME testPointKinematics + LINKLIBS osimTools + RESOURCES resources/SinglePin.osim + resources/subject01.osim + resources/subject01_walk1_ik.mot + ) + +OpenSimAddTest(NAME testStaticOptimization + LINKLIBS osimTools + RESOURCES resources/arm26.osim + resources/arm26_InverseKinematics.mot + resources/arm26_Setup_StaticOptimization.xml + resources/arm26_bounds.osim + resources/arm26_bounds_Setup_StaticOptimization.xml + resources/externalForces.xml + resources/gait10dof_Actuators_weak.xml + resources/staticoptimization_spring_Setup.xml + resources/std_Millard2012EquilibriumMuscle_arm26_StaticOptimization_activation.sto + resources/std_Millard2012EquilibriumMuscle_arm26_StaticOptimization_force.sto + resources/std_Millard2012EquilibriumMuscle_arm26_bounds_StaticOptimization_activation.sto + resources/std_Millard2012EquilibriumMuscle_arm26_bounds_StaticOptimization_force.sto + resources/std_Thelen2003Muscle_Deprecated_arm26_StaticOptimization_activation.sto + resources/std_Thelen2003Muscle_Deprecated_arm26_StaticOptimization_force.sto + resources/std_Thelen2003Muscle_Deprecated_arm26_bounds_StaticOptimization_activation.sto + resources/std_Thelen2003Muscle_Deprecated_arm26_bounds_StaticOptimization_force.sto + resources/std_Thelen2003Muscle_arm26_StaticOptimization_activation.sto + resources/std_Thelen2003Muscle_arm26_StaticOptimization_force.sto + resources/std_Thelen2003Muscle_arm26_bounds_StaticOptimization_activation.sto + resources/std_Thelen2003Muscle_arm26_bounds_StaticOptimization_force.sto + resources/std_walk_subject01_ankle_spring_StaticOptimization_activation.sto + resources/std_walk_subject01_ankle_spring_StaticOptimization_force.sto + resources/subject01.osim + resources/subject01_Setup_StaticOptimization.xml + resources/subject01_adjusted_spring.osim + resources/subject01_walk1_grf.mot + resources/subject01_walk1_ik.mot + resources/walk_subject01_Kinematics_q.sto + ) file(COPY "resources/UsingRelativePaths" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") diff --git a/Applications/CMC/tests/CMakeLists.txt b/Applications/CMC/tests/CMakeLists.txt index 08fd33f4c6..cdf0faabaa 100644 --- a/Applications/CMC/tests/CMakeLists.txt +++ b/Applications/CMC/tests/CMakeLists.txt @@ -1,15 +1,131 @@ find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") -file(GLOB TEST_PROGS "test*.cpp") -file(GLOB TEST_FILES resources/*.osim - resources/*.xml - resources/*.sto - resources/*.mot - resources/*.vtp) - -OpenSimAddTests( - TESTPROGRAMS ${TEST_PROGS} - DATAFILES ${TEST_FILES} - LINKLIBS osimTools Catch2::Catch2WithMain - ) +OpenSimAddTest(NAME testCMCArm26_Millard + LINKLIBS osimTools + RESOURCES resources/arm26.osim + resources/arm26_ComputedMuscleControl_Tasks.xml + resources/arm26_InverseKinematics.mot + resources/arm26_Reserve_Actuators.xml + resources/arm26_Setup_CMC.xml + resources/std_arm26_states.sto + ) + +OpenSimAddTest(NAME testCMCArm26_Thelen + LINKLIBS osimTools + RESOURCES resources/arm26.osim + resources/arm26_ComputedMuscleControl_Tasks.xml + resources/arm26_InverseKinematics.mot + resources/arm26_Reserve_Actuators.xml + resources/arm26_Setup_CMC.xml + resources/std_arm26_states.sto + ) + +OpenSimAddTest(NAME testCMCEMGDrivenArm_Millard + LINKLIBS osimTools + RESOURCES resources/arm26.osim + resources/arm26_ComputedMuscleControl_Tasks_EMG.xml + resources/arm26_InverseKinematics.mot + resources/arm26_Reserve_Actuators.xml + resources/arm26_Setup_ComputedMuscleControl_EMG.xml + resources/muscle_emg.sto + resources/std_arm26_states.sto + ) + +OpenSimAddTest(NAME testCMCEMGDrivenArm_Thelen + LINKLIBS osimTools + RESOURCES resources/arm26.osim + resources/arm26_ComputedMuscleControl_Tasks_EMG.xml + resources/arm26_InverseKinematics.mot + resources/arm26_Reserve_Actuators.xml + resources/arm26_Setup_ComputedMuscleControl_EMG.xml + resources/muscle_emg.sto + resources/std_arm26_states.sto + ) + +OpenSimAddTest(NAME testCMCGait10dof18musc + LINKLIBS osimTools + RESOURCES resources/gait10dof18musc_Setup_CMC.xml + resources/gait10dof18musc_std_walk_subject_states_unix.sto + resources/gait10dof18musc_subject01.osim + resources/gait10dof18musc_subject01_walk_grf.mot + resources/gait10dof18musc_subject01_walk_grf.xml + resources/gait10dof18musc_subject_adjusted_Kinematics_q.sto + resources/gait10dof_Kinematics_Tracking_Tasks.xml + resources/gait10dof_Reserve_Actuators.xml + ) + +OpenSimAddTest(NAME testCMCLeg6Dof9Musc + LINKLIBS osimTools + RESOURCES resources/Leg6Dof9MuscSwing_std_leg6dof9musc_states.sto + resources/leg69_CMC_Swing_Tracking_Tasks.xml + resources/leg69_CMC_residuals_motors.xml + resources/leg69_IK_stance.mot + resources/leg69_IK_swing.mot + resources/leg69_Setup_CMC_Stance.xml + resources/leg69_Tracking_Tasks.xml + resources/leg69_muscles_control_limits.xml + resources/leg69_muscles_residuals_motor_control_limits.xml + resources/leg69_right_grf.xml + resources/leg69_stance_grf.mot + resources/leg6dof9musc.osim + resources/leg6dof9musc_added_mass.osim + resources/leg6dof9musc_adjusted_Kinematics_q.sto + resources/leg6dof9musc_setup_Swing.xml + resources/leg6dof9musc_std_RRA_adjusted_states.sto + ) + +OpenSimAddTest(NAME testCMCSingleMuscle + LINKLIBS osimTools + RESOURCES resources/block_hanging_from_muscle.osim + resources/block_hanging_from_muscle_CMC_Tasks.xml + resources/block_hanging_from_muscle_Setup_CMC.xml + resources/block_hanging_from_muscle_Setup_Forward.xml + resources/block_hanging_from_muscle_controls.sto + ) + +OpenSimAddTest(NAME testCMCSingleRigidTendonMuscle + LINKLIBS osimTools + RESOURCES resources/block_hanging_from_muscle.osim + resources/block_hanging_from_muscle_CMC_Tasks.xml + resources/block_hanging_from_muscle_Setup_CMC.xml + resources/block_hanging_from_muscle_Setup_Forward.xml + resources/block_hanging_from_muscle_controls.sto + ) + +OpenSimAddTest(NAME testCMCTwoMusclesOnBlock + LINKLIBS osimTools + RESOURCES resources/anchor1.vtp + resources/anchor2.vtp + resources/block.vtp + resources/twoMusclesOnBlock.osim + resources/twoMusclesOnBlock_CMC_Tasks.xml + resources/twoMusclesOnBlock_Setup_CMC.xml + resources/twoMusclesOnBlock_Setup_Forward.xml + ) + +OpenSimAddTest(NAME testCMCWithControlConstraintsGait2354 + LINKLIBS osimTools + RESOURCES resources/gait2354_CMC_Actuators.xml + resources/gait2354_CMC_ControlConstraints.xml + resources/gait2354_CMC_Tasks.xml + resources/std_subject01_walk1_states_WithControlConstraints.sto + resources/subject01_Setup_CMC.xml + resources/subject01_externalForces.xml + resources/subject01_simbody_adjusted.osim + resources/subject01_walk1_RRA_Kinematics_initial_q.sto + resources/subject01_walk1_grf.mot + ) + +OpenSimAddTest(NAME testCMCWithControlConstraintsRunningModel + LINKLIBS osimTools + RESOURCES resources/runningModel_CMC_Actuators.xml + resources/runningModel_CMC_Tasks.xml + resources/runningModel_CMC_test.osim + resources/runningModel_ControlConstraints.xml + resources/runningModel_GRF.xml + resources/runningModel_GRF_data.mot + resources/runningModel_Kinematics_q.sto + resources/runningModel_Setup_CMC_test.xml + resources/std_runningModel_CMC_states.sto + ) diff --git a/Applications/Forward/tests/CMakeLists.txt b/Applications/Forward/tests/CMakeLists.txt index db59ef3fb4..034855bc00 100644 --- a/Applications/Forward/tests/CMakeLists.txt +++ b/Applications/Forward/tests/CMakeLists.txt @@ -1,14 +1,28 @@ find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") -file(GLOB TEST_PROGS "test*.cpp") -file(GLOB TEST_FILES resources/*.osim - resources/*.xml - resources/*.sto - resources/*.mot) - -OpenSimAddTests( - TESTPROGRAMS ${TEST_PROGS} - DATAFILES ${TEST_FILES} - LINKLIBS osimTools Catch2::Catch2WithMain - ) +OpenSimAddTest(NAME testForward + LINKLIBS osimTools + RESOURCES resources/arm26.osim + resources/arm26_InitialStates.sto + resources/arm26_Setup_Forward.xml + resources/arm26_StaticOptimization_controls.xml + resources/gait2354_CMC_Actuators.xml + resources/pendulum.osim + resources/pendulum_Setup_Forward.xml + resources/pendulum_ext_gravity_Setup_Forward.xml + resources/pendulum_ext_point_in_ground_Setup_Forward.xml + resources/pendulum_external_load.sto + resources/pendulum_external_load.xml + resources/pendulum_external_load_point_in_ground.sto + resources/pendulum_external_load_point_in_ground.xml + resources/pendulum_no_gravity.osim + resources/std_arm26_states.sto + resources/std_subject01_walk1_states.sto + resources/subject01_GRFs.xml + resources/subject01_Setup_Forward.xml + resources/subject01_Setup_Forward_Controller.xml + resources/subject01_adjusted.osim + resources/subject01_walk1_controls.xml + resources/subject01_walk1_grf.mot + ) diff --git a/Applications/ID/tests/CMakeLists.txt b/Applications/ID/tests/CMakeLists.txt index 466c14f94a..94f435a695 100644 --- a/Applications/ID/tests/CMakeLists.txt +++ b/Applications/ID/tests/CMakeLists.txt @@ -1,15 +1,19 @@ find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") -file(GLOB TEST_PROGS "test*.cpp") -file(GLOB TEST_FILES resources/*.osim - resources/*.xml - resources/*.sto - resources/*.mot) -list(APPEND TEST_FILES ${CMAKE_SOURCE_DIR}/OpenSim/Tests/shared/ThoracoscapularShoulderModel.osim) - -OpenSimAddTests( - TESTPROGRAMS ${TEST_PROGS} - DATAFILES ${TEST_FILES} - LINKLIBS osimTools Catch2::Catch2WithMain - ) +OpenSimAddTest(NAME testID + LINKLIBS osimTools + RESOURCES "${CMAKE_SOURCE_DIR}/OpenSim/Tests/shared/ThoracoscapularShoulderModel.osim" + resources/ThorascapularShoulderModel_ID_static.xml + resources/ThorascapularShoulderModel_static.mot + resources/arm26.osim + resources/arm26_InverseKinematics.mot + resources/arm26_Setup_InverseDynamics.xml + resources/std_arm26_InverseDynamics.sto + resources/std_subject01_InverseDynamics.sto + resources/subject01.osim + resources/subject01_Setup_InverseDynamics.xml + resources/subject01_walk1_grf.mot + resources/subject01_walk1_grf.xml + resources/subject01_walk1_ik.mot + ) diff --git a/Applications/IK/tests/CMakeLists.txt b/Applications/IK/tests/CMakeLists.txt index 132a243eeb..3c0e96f723 100644 --- a/Applications/IK/tests/CMakeLists.txt +++ b/Applications/IK/tests/CMakeLists.txt @@ -1,15 +1,25 @@ find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") -file(GLOB TEST_PROGS "test*.cpp") -file(GLOB TEST_FILES resources/*.osim - resources/*.xml - resources/*.sto - resources/*.mot - resources/*.trc) +OpenSimAddTest(NAME testIK + LINKLIBS osimTools + RESOURCES resources/abdbonepin.trc + resources/constraintTest.trc + resources/constraintTest_ikOnly.osim + resources/constraintTest_setup_ik.xml + resources/gait2354_IK_Tasks_uniform.xml + resources/setup_ik_abdbonepin.xml + resources/std_subject01_walk1_ik.mot + resources/std_subject1_abdbonepin_IK.mot + resources/subject01_Setup_InverseKinematics.xml + resources/subject01_Setup_InverseKinematics_NoModel.xml + resources/subject01_simbody.osim + resources/subject01_synthetic_marker_data.trc + resources/subject1_abdbonepin.osim + ) -OpenSimAddTests( - TESTPROGRAMS ${TEST_PROGS} - DATAFILES ${TEST_FILES} - LINKLIBS osimTools Catch2::Catch2WithMain - ) +OpenSimAddTest(NAME testLiveIK + LINKLIBS osimTools + RESOURCES resources/std_subject01_walk1_ik.mot + resources/subject01_simbody.osim + ) diff --git a/Applications/RRA/tests/CMakeLists.txt b/Applications/RRA/tests/CMakeLists.txt index 5825e678ae..099dd01d78 100644 --- a/Applications/RRA/tests/CMakeLists.txt +++ b/Applications/RRA/tests/CMakeLists.txt @@ -1,15 +1,16 @@ - find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") -file(GLOB TEST_PROGS "test*.cpp") -file(GLOB TEST_FILES resources/*.osim - resources/*.xml - resources/*.sto - resources/*.mot) - -OpenSimAddTests( - TESTPROGRAMS ${TEST_PROGS} - DATAFILES ${TEST_FILES} - LINKLIBS osimTools Catch2::Catch2WithMain - ) +OpenSimAddTest(NAME testRRA + LINKLIBS osimTools + RESOURCES resources/gait2354_RRA_Actuators.xml + resources/gait2354_RRA_ControlConstraints.xml + resources/gait2354_RRA_Tasks.xml + resources/subject01_RRA_adjusted.osim + resources/subject01_Setup_RRA.xml + resources/subject01_externalForces.xml + resources/subject01_simbody.osim + resources/subject01_walk1_RRA_Kinematics_q_standard.sto + resources/subject01_walk1_grf.mot + resources/subject01_walk1_ik.mot + ) diff --git a/Applications/Scale/tests/CMakeLists.txt b/Applications/Scale/tests/CMakeLists.txt index 132a243eeb..36abbdbeb5 100644 --- a/Applications/Scale/tests/CMakeLists.txt +++ b/Applications/Scale/tests/CMakeLists.txt @@ -1,15 +1,16 @@ find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") -file(GLOB TEST_PROGS "test*.cpp") -file(GLOB TEST_FILES resources/*.osim - resources/*.xml - resources/*.sto - resources/*.mot - resources/*.trc) - -OpenSimAddTests( - TESTPROGRAMS ${TEST_PROGS} - DATAFILES ${TEST_FILES} - LINKLIBS osimTools Catch2::Catch2WithMain - ) +OpenSimAddTest(NAME testScale + LINKLIBS osimTools + RESOURCES resources/gait2354_Scale_MarkerSet.xml + resources/gait2354_simbody.osim + resources/std_subject01_scaleSet_applied.xml + resources/std_subject01_simbody.osim + resources/std_toyLigamentModelScaled.osim + resources/subject01_Setup_Scale.xml + resources/subject01_Setup_Scale_GUI.xml + resources/subject01_static.trc + resources/toyLigamentModel.osim + resources/toyLigamentModel_Setup_Scale.xml + ) diff --git a/Applications/opensense/tests/CMakeLists.txt b/Applications/opensense/tests/CMakeLists.txt index 03822d6669..ee8530a91f 100644 --- a/Applications/opensense/tests/CMakeLists.txt +++ b/Applications/opensense/tests/CMakeLists.txt @@ -1,13 +1,21 @@ find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") -file(GLOB TEST_PROGS "test*.cpp") -file(GLOB TEST_FILES resources/*.osim - resources/*.xml - resources/*.sto) - -OpenSimAddTests( - TESTPROGRAMS ${TEST_PROGS} - DATAFILES ${TEST_FILES} - LINKLIBS osimTools Catch2::Catch2WithMain - ) +OpenSimAddTest(NAME testOpenSense + LINKLIBS osimTools + RESOURCES resources/MT_012005D6_009-quaternions_RHJCSwinger.sto + resources/MT_012005D6_009-quaternions_calibration_trial_Facing_X.sto + resources/MT_012005D6_009-quaternions_calibration_trial_Facing_negX.sto + resources/calibrate_rotated.xml + resources/imuOrientations.sto + resources/imuPlacer.xml + resources/imuPlacerFaceNegX.xml + resources/imuPlacerFaceX.xml + resources/model_Rajagopal2015_posed.osim + resources/myComplexTasksTrial_orientations.sto + resources/setup_IMUInverseKinematics_HJC_trial.xml + resources/setup_IMUInverseKinematics_HJC_trial_nofeet.xml + resources/std_calibrated_pelvis_rot.osim + resources/std_calibrated_subject07.osim + resources/subject07.osim + ) diff --git a/Applications/opensim-cmd/tests/CMakeLists.txt b/Applications/opensim-cmd/tests/CMakeLists.txt index 75c247fa44..a7924d0b58 100644 --- a/Applications/opensim-cmd/tests/CMakeLists.txt +++ b/Applications/opensim-cmd/tests/CMakeLists.txt @@ -1,12 +1,7 @@ find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") -OpenSimAddTests( - TESTPROGRAMS testCommandLineInterface.cpp - # Don't need OpenSim since we only interact with OpenSim through the - # command line tool. But we use Simbody for its Testing.h. - LINKLIBS SimTKcommon Catch2::Catch2WithMain - ) +OpenSimAddTest(NAME testCommandLineInterface) add_dependencies(testCommandLineInterface opensim-cmd) diff --git a/Applications/opensim-cmd/tests/testCommandLineInterface.cpp b/Applications/opensim-cmd/tests/testCommandLineInterface.cpp index 0952d1dbce..59477de9bd 100644 --- a/Applications/opensim-cmd/tests/testCommandLineInterface.cpp +++ b/Applications/opensim-cmd/tests/testCommandLineInterface.cpp @@ -21,7 +21,6 @@ * limitations under the License. * * -------------------------------------------------------------------------- */ -#include #include #include #include diff --git a/Bindings/Java/OpenSimJNI/Test/CMakeLists.txt b/Bindings/Java/OpenSimJNI/Test/CMakeLists.txt index 78db6bfd05..c5e87a9e7c 100644 --- a/Bindings/Java/OpenSimJNI/Test/CMakeLists.txt +++ b/Bindings/Java/OpenSimJNI/Test/CMakeLists.txt @@ -1,13 +1,13 @@ -if(BUILD_JAVA_WRAPPING) +if(BUILD_JAVA_WRAPPING) - file(GLOB TEST_PROGS "test*.cpp") - file(GLOB TEST_FILES *.osim *.xml *.sto *.mot) + find_package(Catch2 REQUIRED + HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") - OpenSimAddTests( - TESTPROGRAMS ${TEST_PROGS} - DATAFILES ${TEST_FILES} + OpenSimAddTest(NAME testContext LINKLIBS osimJavaJNI - SOURCES "../OpenSimContext.cpp" + EXTRA_SOURCES "../OpenSimContext.cpp" + RESOURCES arm26_20.osim + wrist.osim ) endif(BUILD_JAVA_WRAPPING) diff --git a/Bindings/Java/OpenSimJNI/Test/testContext.cpp b/Bindings/Java/OpenSimJNI/Test/testContext.cpp index 54bed517b2..2c0d985787 100644 --- a/Bindings/Java/OpenSimJNI/Test/testContext.cpp +++ b/Bindings/Java/OpenSimJNI/Test/testContext.cpp @@ -45,58 +45,70 @@ #include #include +#include + +#include + using namespace OpenSim; using namespace SimTK; using namespace std; -#define ASSERT_EQUAL(expected, found, tolerance) { \ -double tol = std::max((tolerance), std::abs((expected)*(tolerance))); \ -if ((found)<(expected)-(tol) || (found)>(expected)+(tol)) throw(exception());} - -int main() -{ - try { - int status = 0; +namespace { - // To Retrace the steps taken by the GUI this test case follows the same call sequence: - // new Model(file) - // new OpenSimContext(model.initSystem(), model); - // context.updateDisplayer(muscle) // to display muscles - // context.getCurrentPath(muscle) - // context.getTransform(body) - // context.transformPosition(body, loc, global) // to display markers - // context.getLocked(Coordinate) - // context.getValue(cooridnate) +// The models used below are deserialized at runtime, so the libraries +// registering their component types must be loaded first. +void loadOpenSimLibraries() { LoadOpenSimLibrary("osimActuators"); LoadOpenSimLibrary("osimSimulation"); LoadOpenSimLibrary("osimJavaJNI"); +} + +} // namespace - Model *model = new Model("wrist.osim"); +TEST_CASE("OpenSimContext force groups") { + loadOpenSimLibraries(); + + Model* model = new Model("wrist.osim"); OpenSimContext* context = new OpenSimContext(&model->initSystem(), model); const ForceSet& fs = model->getForceSet(); int n1 = fs.getNumGroups(); const ObjectGroup* grp = fs.getGroup("wrist"); - assert(grp); + REQUIRE(grp); const Array& members = grp->getMembers(); int sz = members.getSize(); - ASSERT_EQUAL(sz,5,0); - assert(members.get(0)->getName()=="ECRB"); + OpenSim_CHECK_EQUAL(sz, 5); + CHECK(members.get(0)->getName() == "ECRB"); delete model; delete context; - model = new Model("arm26_20.osim"); - context = new OpenSimContext(&model->initSystem(), model); - // Make a copy of state contained in context ad make sure content match +} + +// To Retrace the steps taken by the GUI this test case follows the same call +// sequence: +// new Model(file) +// new OpenSimContext(model.initSystem(), model); +// context.updateDisplayer(muscle) // to display muscles +// context.getCurrentPath(muscle) +// context.getTransform(body) +// context.transformPosition(body, loc, global) // to display markers +// context.getLocked(Coordinate) +// context.getValue(cooridnate) +TEST_CASE("OpenSimContext GUI call sequence") { + loadOpenSimLibraries(); + + Model* model = new Model("arm26_20.osim"); + OpenSimContext* context = new OpenSimContext(&model->initSystem(), model); + // Make a copy of state contained in context ad make sure content match SimTK::State stateCopy = context->getCurrentStateCopy(); - assert(context->getCurrentStateRef().toString()==stateCopy.toString()); + CHECK(context->getCurrentStateRef().toString() == stateCopy.toString()); Array stateNames = model->getStateVariableNames(); OpenSim::Force* dForce=&(model->updForceSet().get("TRIlong")); Muscle* dTRIlong = dynamic_cast(dForce); - assert(dTRIlong); + REQUIRE(dTRIlong); context->setPropertiesFromState(); OpenSim::Thelen2003Muscle* thelenMsl = dynamic_cast(dTRIlong); AbstractProperty& dProp = thelenMsl->updPropertyByName("ignore_tendon_compliance"); - + PropertyHelper::setValueBool(true, dProp); cout << "Prop after is " << dProp.toString() << endl; @@ -104,7 +116,7 @@ int main() try{// adding to the system should cause Muscle that do not handle // ignore_tendon_compliance to throw an exception context->recreateSystemKeepStage(); - } + } catch (const std::exception& e) { cout << e.what() << endl; exceptionThrown = true; @@ -114,13 +126,14 @@ int main() context->recreateSystemKeepStage(); } - SimTK_ASSERT_ALWAYS(exceptionThrown, "Setting ignore_tendon_compliance must throw an exception."); - + INFO("Setting ignore_tendon_compliance must throw an exception."); + REQUIRE(exceptionThrown); AbstractProperty& dProp2 = thelenMsl->updPropertyByName("ignore_tendon_compliance"); cout << "Prop after create system is " << dProp2.toString() << endl; bool after = PropertyHelper::getValueBool(dProp); - SimTK_ASSERT_ALWAYS(!after, "Property has wrong value!!"); + INFO("Property has wrong value!!"); + CHECK(!after); dTRIlong->updGeometryPath().updateGeometry(context->getCurrentStateRef()); const OpenSim::Array& path = context->getCurrentPath(*dTRIlong); cout << "Muscle Path" << endl; @@ -128,7 +141,7 @@ int main() for(int i=0; i< path.getSize(); i++) cout << path[i]->getParentFrame().getName() << path[i]->getLocation(context->getCurrentStateRef()) << endl; - // Compare to known path + // Compare to known path const OpenSim::Body& dBody = model->getBodySet().get("r_ulna_radius_hand"); Transform xform = context->getTransform(dBody); cout << xform << endl; @@ -138,17 +151,17 @@ int main() double markerPosition[] = {.005000000000, -0.290400000000, 0.030000000000}; double markerPositionInGround[3]; context->transformPosition(dBody, markerPosition, markerPositionInGround); // to display markers - cout << "Global frame position = " << markerPositionInGround[0] << + cout << "Global frame position = " << markerPositionInGround[0] << markerPositionInGround[1] << markerPositionInGround[2]<< endl; // Check xformed point against known position const Coordinate& dr_elbow_flex = model->getCoordinateSet().get("r_elbow_flex"); bool isLocked = context->getLocked(dr_elbow_flex); - assert(!isLocked); + CHECK(!isLocked); double startValue = context->getValue(dr_elbow_flex); cout << "Coordinate start value = " << startValue << endl; double length1 = context->getMuscleLength(*dTRIlong); cout << length1 << endl; - ASSERT_EQUAL(.277609, length1, 1e-5); + OpenSim_CHECK_EQUAL(.277609, length1, 1e-5); // Coordinate Slider context->setValue(dr_elbow_flex, 100*SimTK_PI/180.); // Get body transform, marker position and muscle path (tests wrapping as well) @@ -159,15 +172,15 @@ int main() dTRIlong->updGeometryPath().updateGeometry(context->getCurrentStateRef()); const OpenSim::Array& newPath = context->getCurrentPath(*dTRIlong); context->realizePosition(); - // Compare to known path + // Compare to known path cout << "New Muscle Path" << endl; cout << path.getSize() << endl; for(int i=0; i< path.getSize(); i++) - cout << path[i]->getParentFrame().getName() + cout << path[i]->getParentFrame().getName() << path[i]->getLocation(context->getCurrentStateRef()) << endl; double length2 = context->getMuscleLength(*dTRIlong); cout << length2 << endl; - ASSERT_EQUAL(.315748, length2, 1e-5); + OpenSim_CHECK_EQUAL(.315748, length2, 1e-5); // Test that we can lock coordinates to specific value and make this persistant. Coordinate& dr_elbow_flex_mod = model->updCoordinateSet().get("r_elbow_flex"); //dr_elbow_flex_mod.setDefaultValue(0.5); @@ -176,8 +189,8 @@ int main() //model->print("wrist_locked_elbow.osim"); context->recreateSystemKeepStage(); const Coordinate& dr_elbow_flexNew = model->getCoordinateSet().get("r_elbow_flex"); - assert(context->getLocked(dr_elbow_flexNew)); - ASSERT_EQUAL(0.5, context->getValue(dr_elbow_flexNew), 0.000001); + CHECK(context->getLocked(dr_elbow_flexNew)); + OpenSim_CHECK_EQUAL(0.5, context->getValue(dr_elbow_flexNew), 0.000001); // Exercise Editing workflow // These are the same calls done from GUI code base through Property edits @@ -199,16 +212,16 @@ int main() AbstractPathPoint* clonedPoint = savePoint.clone(); // Test delete second PathPoint from TRIlong muscle - context->deletePathPoint(dTRIlong->updGeometryPath(), 2); - assert(pathPoints.getSize() == origSize - 1); + context->deletePathPoint(dTRIlong->updGeometryPath(), 2); + CHECK(pathPoints.getSize() == origSize - 1); std::string pathAfterDeletionInXML = dTRIlong->updGeometryPath().dump(); std::cout << pathAfterDeletionInXML << endl; - + // Test adding PathPoint to TRIlong muscle (Stationary) Component& frame = model->updBodySet().updComponent(saveFrameName); PhysicalFrame* physFrame = PhysicalFrame::safeDownCast(&frame); context->addPathPoint(dTRIlong->updGeometryPath(), 3, *physFrame); - assert(pathPoints.getSize() == origSize); + CHECK(pathPoints.getSize() == origSize); std::string pathAfterReinsertionInXML = dTRIlong->updGeometryPath().dump(); std::cout << pathAfterReinsertionInXML << endl; @@ -218,11 +231,11 @@ int main() newPoint->setCoordinate(model->getCoordinateSet().get(0)); newPoint->setParentFrame(oldPoint.getParentFrame()); context->replacePathPoint(dTRIlong->updGeometryPath(), oldPoint, *newPoint); - assert(pathPoints.getSize() == origSize); + CHECK(pathPoints.getSize() == origSize); std::string pathAfterTypeChangeToViaInXML = dTRIlong->updGeometryPath().dump(); std::cout << pathAfterTypeChangeToViaInXML << endl; - + // Make a change to a socket that is invalid and verify that we can recover // from that invalid change by not making it on model directly // context has reference to the model already @@ -231,7 +244,7 @@ int main() AbstractSocket& socket = shoulder.updSocket("child_frame"); try { // create an invalid model where joint connects two frames on ground, - // the test will verify the connectee has not been changed + // the test will verify the connectee has not been changed context->setSocketConnecteePath(socket, "ground"); } catch (const std::exception& e) { @@ -242,7 +255,7 @@ int main() AbstractSocket& psocket = shoulder.updSocket("parent_frame"); const Object& connecteeBefore = psocket.getConnecteeAsObject(); try { - // Try to create an invalid model again, this call should leave the + // Try to create an invalid model again, this call should leave the // model untouched since change invalidates psocket context->setSocketConnecteePath(psocket, "r_ulna_radius_hand"); @@ -253,13 +266,10 @@ int main() cout << "Exception: " << e.what() << endl; } const Object& connecteeAfter = psocket.getConnecteeAsObject(); - OPENSIM_THROW_IF(&connecteeAfter != &connecteeBefore, OpenSim::Exception, - "Connectee changed after unsuccessful edit"); + INFO("Connectee changed after unsuccessful edit"); + CHECK(&connecteeAfter == &connecteeBefore); // model is still valid here despite attempts to make invalid edits - return status; - } catch (const std::exception& e) { - cout << "Exception: " << e.what() << endl; - return 1; - } -} + delete model; + delete context; +} diff --git a/OpenSim/Actuators/tests/CMakeLists.txt b/OpenSim/Actuators/tests/CMakeLists.txt index d9512fde88..2d34a89904 100644 --- a/OpenSim/Actuators/tests/CMakeLists.txt +++ b/OpenSim/Actuators/tests/CMakeLists.txt @@ -1,8 +1,26 @@ find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") -file(GLOB TEST_PROGS "test*.cpp") -OpenSimAddTests( - TESTPROGRAMS ${TEST_PROGS} - LINKLIBS osimTools Catch2::Catch2WithMain - ) \ No newline at end of file +OpenSimAddTest(NAME testActuators + LINKLIBS osimTools) + +OpenSimAddTest(NAME testDeGrooteFregly2016Muscle + LINKLIBS osimTools) + +OpenSimAddTest(NAME testModelProcessor + LINKLIBS osimTools) + +OpenSimAddTest(NAME testMuscleFirstOrderActivationDynamicModel + LINKLIBS osimTools) + +OpenSimAddTest(NAME testMuscleFixedWidthPennationModel + LINKLIBS osimTools) + +OpenSimAddTest(NAME testMuscles + LINKLIBS osimTools) + +OpenSimAddTest(NAME testPolynomialPathFitter + LINKLIBS osimTools) + +OpenSimAddTest(NAME testSerializableMuscleCurves + LINKLIBS osimTools) diff --git a/OpenSim/Analyses/tests/CMakeLists.txt b/OpenSim/Analyses/tests/CMakeLists.txt index 0dbb7a6491..8056523592 100644 --- a/OpenSim/Analyses/tests/CMakeLists.txt +++ b/OpenSim/Analyses/tests/CMakeLists.txt @@ -1,12 +1,5 @@ find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") -file(GLOB TEST_PROGS "test*.cpp") -file(GLOB TEST_FILES *.osim *.xml *.sto *.mot *.obj *.vtp *.stl) - -OpenSimAddTests( - TESTPROGRAMS ${TEST_PROGS} - DATAFILES ${TEST_FILES} - LINKLIBS osimCommon osimSimulation osimAnalyses osimActuators osimLepton Catch2::Catch2WithMain - ) - +OpenSimAddTest(NAME testOutputReporter + LINKLIBS osimCommon osimSimulation osimAnalyses osimActuators osimLepton) diff --git a/OpenSim/Common/tests/CMakeLists.txt b/OpenSim/Common/tests/CMakeLists.txt index 140e536e52..8c8f93c2d1 100644 --- a/OpenSim/Common/tests/CMakeLists.txt +++ b/OpenSim/Common/tests/CMakeLists.txt @@ -1,31 +1,139 @@ find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") -file(GLOB TEST_PROGS "*test*.cpp") -file(GLOB TEST_FILES resources/*.osim - resources/*.xml - resources/*.sto - resources/*.mot - resources/*.trc) -file(GLOB TRC_TEST_FILES "${CMAKE_SOURCE_DIR}/Applications/*/tests/resources/*.trc") -file(GLOB MOT_TEST_FILES "${CMAKE_SOURCE_DIR}/Applications/*/tests/resources/*.mot") -file(GLOB C3D_TEST_FILES "${CMAKE_SOURCE_DIR}/OpenSim/Tests/shared/*.c3d") -file(GLOB XSENS_TEST_FILES "${CMAKE_SOURCE_DIR}/OpenSim/Tests/shared/IMUData/Xsens/*.txt") -file(GLOB APDM_TEST_FILES "${CMAKE_SOURCE_DIR}/OpenSim/Tests/shared/IMUData/APDM/*.csv") - -list(APPEND TRC_TEST_FILES - "${OPENSIM_SHARED_TEST_FILES_DIR}/gait10dof18musc_walk_CRLF_line_ending.trc") -list(APPEND MOT_TEST_FILES - "${OPENSIM_SHARED_TEST_FILES_DIR}/gait10dof18musc_ik_CRLF_line_ending.mot") - -if(NOT WITH_EZC3D) - file(GLOB C3D_TESTPROG *testC3DFileAdapter.cpp) - list(REMOVE_ITEM TEST_PROGS ${C3D_TESTPROG}) +set(OSIM_COMMON_TEST_LIBS osimCommon ${SIMTK_ALL_LIBS}) +set(OSIM_SHARED_DIR "${CMAKE_SOURCE_DIR}/OpenSim/Tests/shared") +set(OSIM_APPS_DIR "${CMAKE_SOURCE_DIR}/Applications") + +OpenSimAddTest(NAME testAPDMDataReader + LINKLIBS ${OSIM_COMMON_TEST_LIBS} + RESOURCES "${OSIM_SHARED_DIR}/IMUData/APDM/apdm_format7.csv" + "${OSIM_SHARED_DIR}/IMUData/APDM/imuData01.csv" + ) + +OpenSimAddTest(NAME testArray + LINKLIBS ${OSIM_COMMON_TEST_LIBS}) + +OpenSimAddTest(NAME testAssertion + LINKLIBS ${OSIM_COMMON_TEST_LIBS}) + +if(WITH_EZC3D) + OpenSimAddTest(NAME testC3DFileAdapter + LINKLIBS ${OSIM_COMMON_TEST_LIBS} + RESOURCES "${OSIM_SHARED_DIR}/walking2.c3d" + "${OSIM_SHARED_DIR}/walking5.c3d" + resources/std_cop_walking2_grfs.sto + resources/std_cop_walking5_grfs.sto + resources/std_walking2_analog.sto + resources/std_walking2_grfs.sto + resources/std_walking2_markers.trc + resources/std_walking5_analog.sto + resources/std_walking5_grfs.sto + resources/std_walking5_markers.trc + ) endif() -OpenSimAddTests( - TESTPROGRAMS ${TEST_PROGS} - DATAFILES ${TEST_FILES} ${C3D_TEST_FILES} ${TRC_TEST_FILES} ${XSENS_TEST_FILES} ${APDM_TEST_FILES} - ${MOT_TEST_FILES} - LINKLIBS osimCommon Catch2::Catch2WithMain ${SIMTK_ALL_LIBS} - ) +OpenSimAddTest(NAME testCommonUtilities + LINKLIBS ${OSIM_COMMON_TEST_LIBS}) + +OpenSimAddTest(NAME testComponentInterface + LINKLIBS ${OSIM_COMMON_TEST_LIBS} + RESOURCES resources/dataWithEformat.trc + ) + +OpenSimAddTest(NAME testDataTable + LINKLIBS ${OSIM_COMMON_TEST_LIBS} + RESOURCES resources/test.sto + ) + +OpenSimAddTest(NAME testFunctionAdapter + LINKLIBS ${OSIM_COMMON_TEST_LIBS}) + +OpenSimAddTest(NAME testFunctions + LINKLIBS ${OSIM_COMMON_TEST_LIBS}) + +OpenSimAddTest(NAME testGCVSpline + LINKLIBS ${OSIM_COMMON_TEST_LIBS}) + +OpenSimAddTest(NAME testLatinHypercubeDesign + LINKLIBS ${OSIM_COMMON_TEST_LIBS}) + +OpenSimAddTest(NAME testMarkerData + LINKLIBS ${OSIM_COMMON_TEST_LIBS} + RESOURCES resources/dataWithEformat.trc + resources/dataWithNaNsOfDifferentCases.trc + resources/dataWithNaNsWithSpaces.trc + ) + +OpenSimAddTest(NAME testNCSpline + LINKLIBS ${OSIM_COMMON_TEST_LIBS}) + +OpenSimAddTest(NAME testPath + LINKLIBS ${OSIM_COMMON_TEST_LIBS}) + +OpenSimAddTest(NAME testRootSolver + LINKLIBS ${OSIM_COMMON_TEST_LIBS}) + +OpenSimAddTest(NAME testSTOFileAdapter + LINKLIBS ${OSIM_COMMON_TEST_LIBS} + RESOURCES "${OSIM_APPS_DIR}/Analyze/tests/resources/subject01_walk1_grf.mot" + "${OSIM_APPS_DIR}/Analyze/tests/resources/subject02_running_arms_ik.mot" + "${OSIM_APPS_DIR}/CMC/tests/resources/gait10dof18musc_subject01_walk_grf.mot" + "${OSIM_APPS_DIR}/CMC/tests/resources/runningModel_GRF_data.mot" + "${OSIM_APPS_DIR}/IK/tests/resources/std_subject01_walk1_ik.mot" + "${OSIM_SHARED_DIR}/gait10dof18musc_ik_CRLF_line_ending.mot" + resources/test.sto + ) + +OpenSimAddTest(NAME testScopeExit + LINKLIBS ${OSIM_COMMON_TEST_LIBS}) + +OpenSimAddTest(NAME testSerialization + LINKLIBS ${OSIM_COMMON_TEST_LIBS} + RESOURCES resources/obj1Bad.xml + resources/obj1Defaults.xml + ) + +OpenSimAddTest(NAME testSmoothSegmentedFunctionFactory + LINKLIBS ${OSIM_COMMON_TEST_LIBS}) + +OpenSimAddTest(NAME testStorage + LINKLIBS ${OSIM_COMMON_TEST_LIBS} + RESOURCES resources/dataWithNaNsOfDifferentCases.trc + resources/sampleOutputs.sto + resources/sampleOutputsSpatialVec.sto + resources/sampleOutputsVec3.sto + resources/test.sto + resources/testDiff.sto + ) + +OpenSimAddTest(NAME testTRCFileAdapter + LINKLIBS ${OSIM_COMMON_TEST_LIBS} + RESOURCES "${OSIM_APPS_DIR}/IK/tests/resources/constraintTest.trc" + "${OSIM_APPS_DIR}/IK/tests/resources/subject01_synthetic_marker_data.trc" + "${OSIM_APPS_DIR}/Scale/tests/resources/subject01_static.trc" + "${OSIM_SHARED_DIR}/gait10dof18musc_walk_CRLF_line_ending.trc" + resources/dataWithBlanksForMissingMarkers.trc + resources/dataWithEformat.trc + resources/dataWithNaNsOfDifferentCases.trc + resources/dataWithNaNsWithSpaces.trc + resources/exampleFormat.trc + ) + +OpenSimAddTest(NAME testXsensDataReader + LINKLIBS ${OSIM_COMMON_TEST_LIBS} + RESOURCES "${OSIM_SHARED_DIR}/IMUData/Xsens/MT2022_ACC_00B42D4B.txt" + "${OSIM_SHARED_DIR}/IMUData/Xsens/MT2022_ACC_GYRO_ROT_ALL_TAB_NAN_00B42D4B.txt" + "${OSIM_SHARED_DIR}/IMUData/Xsens/MT2022_ACC_GYRO_ROT_EULER_TAB_00B42D4F.txt" + "${OSIM_SHARED_DIR}/IMUData/Xsens/MT2022_ACC_GYRO_ROT_MAT_COMMA_00B42D4B.txt" + "${OSIM_SHARED_DIR}/IMUData/Xsens/MT2022_ACC_GYRO_ROT_MAT_SEMICOLON_00B42D4B.txt" + "${OSIM_SHARED_DIR}/IMUData/Xsens/MT2022_ACC_GYRO_ROT_MAT_SPACE_00B42D4B.txt" + "${OSIM_SHARED_DIR}/IMUData/Xsens/MT46_01-000_00B42D4D.txt" + "${OSIM_SHARED_DIR}/IMUData/Xsens/MT46_01-000_00B42D4E.txt" + "${OSIM_SHARED_DIR}/IMUData/Xsens/MT_01200312-002-000_00B474BA.txt" + "${OSIM_SHARED_DIR}/IMUData/Xsens/MT_01200454_000-000_00B40DE4.txt" + "${OSIM_SHARED_DIR}/IMUData/Xsens/MT_012005D6-000_sit_to_stand-000_00B421ED.txt" + "${OSIM_SHARED_DIR}/IMUData/Xsens/MT_012005D6_031-000_00B421AF.txt" + "${OSIM_SHARED_DIR}/IMUData/Xsens/MT_012005D6_031-000_00B4227B.txt" + "${OSIM_SHARED_DIR}/IMUData/Xsens/test1_00B421E6.txt" + ) diff --git a/OpenSim/Moco/tests/CMakeLists.txt b/OpenSim/Moco/tests/CMakeLists.txt index 3b2b4e7753..8a58b00adc 100644 --- a/OpenSim/Moco/tests/CMakeLists.txt +++ b/OpenSim/Moco/tests/CMakeLists.txt @@ -1,84 +1,85 @@ -include(CMakeParseArguments) - find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") -# Create an executable for the file ${TEST_NAME}.cpp, which depends on -# libraries ${LIB_DEPENDENCIES}. Also create a CTest test for this executable. -function(MocoAddTest) - set(options) - set(oneValueArgs NAME REQUIRES_CASADI) - set(multiValueArgs LIB_DEPENDS RESOURCES) - cmake_parse_arguments(MOCOTEST - "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - add_executable(${MOCOTEST_NAME} ${MOCOTEST_NAME}.cpp - "${CMAKE_SOURCE_DIR}/tests/Testing.h") - # To organize targets in Visual Studio's Solution Explorer. - set_target_properties(${MOCOTEST_NAME} PROPERTIES FOLDER "Moco/Tests") - target_link_libraries(${MOCOTEST_NAME} osimMoco ${MOCOTEST_LIB_DEPENDS} - osimTesting Catch2::Catch2WithMain) - if(APPLE) - list(APPEND test_args "~[win]~[linux]~[win/linux]~[linux/win]") - endif() - if(LINUX) - list(APPEND test_args "~[win]~[mac]~[win/mac]~[mac/win]") - endif() - if(WIN32) - list(APPEND test_args "~[mac]~[linux]~[mac/linux]~[linux/mac]~[unix]") - endif() - add_test(NAME ${MOCOTEST_NAME} COMMAND ${MOCOTEST_NAME} ${test_args}) - # Default to requiring CasADi unless the caller explicitly passes REQUIRES_CASADI FALSE. - if(NOT DEFINED MOCOTEST_REQUIRES_CASADI) - set(MOCOTEST_REQUIRES_CASADI TRUE) - endif() - if(MOCOTEST_REQUIRES_CASADI AND NOT OPENSIM_WITH_CASADI) - set_tests_properties(${MOCOTEST_NAME} PROPERTIES DISABLED TRUE) - endif() - # Tests likely run faster if we parallelize the tests rather than the - # individual problems. - set_property(TEST ${MOCOTEST_NAME} APPEND PROPERTY - ENVIRONMENT "OPENSIM_MOCO_PARALLEL=0") - file(COPY ${MOCOTEST_RESOURCES} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") -endfunction() - -MocoAddTest(NAME testMocoInterface) - -MocoAddTest(NAME testMocoGoals) - -MocoAddTest(NAME testMocoParameters) - -MocoAddTest(NAME testMocoImplicit) - -MocoAddTest(NAME testMocoConstraints) - -MocoAddTest(NAME testMocoContact RESOURCES - resources/subject_20dof18musc_running.osim - resources/running_solution_full_stride.sto) - -MocoAddTest(NAME testMocoControllers) - -MocoAddTest(NAME testMocoActuators) +if(OPENSIM_WITH_CASADI) + set(MOCO_CASADI_TESTS_DISABLED FALSE) +else() + set(MOCO_CASADI_TESTS_DISABLED TRUE) +endif() + +OpenSimAddTest(NAME testMocoInterface + LINKLIBS osimMoco + DISABLED ${MOCO_CASADI_TESTS_DISABLED} + ENVIRONMENT "OPENSIM_MOCO_PARALLEL=0") + +OpenSimAddTest(NAME testMocoGoals + LINKLIBS osimMoco + DISABLED ${MOCO_CASADI_TESTS_DISABLED} + ENVIRONMENT "OPENSIM_MOCO_PARALLEL=0") + +OpenSimAddTest(NAME testMocoParameters + LINKLIBS osimMoco + DISABLED ${MOCO_CASADI_TESTS_DISABLED} + ENVIRONMENT "OPENSIM_MOCO_PARALLEL=0") + +OpenSimAddTest(NAME testMocoImplicit + LINKLIBS osimMoco + DISABLED ${MOCO_CASADI_TESTS_DISABLED} + ENVIRONMENT "OPENSIM_MOCO_PARALLEL=0") + +OpenSimAddTest(NAME testMocoConstraints + LINKLIBS osimMoco + DISABLED ${MOCO_CASADI_TESTS_DISABLED} + ENVIRONMENT "OPENSIM_MOCO_PARALLEL=0") + +OpenSimAddTest(NAME testMocoContact + LINKLIBS osimMoco + DISABLED ${MOCO_CASADI_TESTS_DISABLED} + ENVIRONMENT "OPENSIM_MOCO_PARALLEL=0" + RESOURCES resources/subject_20dof18musc_running.osim + resources/running_solution_full_stride.sto + ) -MocoAddTest(NAME testMocoInverse RESOURCES - resources/subject_walk_armless_18musc.osim - resources/subject_walk_armless_coordinates.mot - resources/subject_walk_armless_grfs.mot - resources/subject_walk_armless_external_loads.xml - resources/std_testMocoInverse_subject_18musc_solution.sto +OpenSimAddTest(NAME testMocoControllers + LINKLIBS osimMoco + DISABLED ${MOCO_CASADI_TESTS_DISABLED} + ENVIRONMENT "OPENSIM_MOCO_PARALLEL=0") + +OpenSimAddTest(NAME testMocoActuators + LINKLIBS osimMoco + DISABLED ${MOCO_CASADI_TESTS_DISABLED} + ENVIRONMENT "OPENSIM_MOCO_PARALLEL=0") + +OpenSimAddTest(NAME testMocoInverse + LINKLIBS osimMoco + DISABLED ${MOCO_CASADI_TESTS_DISABLED} + ENVIRONMENT "OPENSIM_MOCO_PARALLEL=0" + RESOURCES resources/subject_walk_armless_18musc.osim + resources/subject_walk_armless_coordinates.mot + resources/subject_walk_armless_grfs.mot + resources/subject_walk_armless_external_loads.xml + resources/std_testMocoInverse_subject_18musc_solution.sto ) -MocoAddTest(NAME testMocoTrack RESOURCES - resources/walk_gait1018_subject01.osim - resources/walk_gait1018_state_reference.mot - resources/walk_gait1018_subject01_grf.xml - resources/walk_gait1018_subject01_grf.mot - resources/std_testMocoTrackGait10dof18musc_solution.sto +OpenSimAddTest(NAME testMocoTrack + LINKLIBS osimMoco + DISABLED ${MOCO_CASADI_TESTS_DISABLED} + ENVIRONMENT "OPENSIM_MOCO_PARALLEL=0" + RESOURCES resources/walk_gait1018_subject01.osim + resources/walk_gait1018_state_reference.mot + resources/walk_gait1018_subject01_grf.xml + resources/walk_gait1018_subject01_grf.mot + resources/std_testMocoTrackGait10dof18musc_solution.sto ) -MocoAddTest(NAME testMocoAnalytic) +OpenSimAddTest(NAME testMocoAnalytic + LINKLIBS osimMoco + DISABLED ${MOCO_CASADI_TESTS_DISABLED} + ENVIRONMENT "OPENSIM_MOCO_PARALLEL=0") -MocoAddTest(NAME testMocoMetabolics REQUIRES_CASADI FALSE RESOURCES - resources/testMocoMetabolics_hanging_muscle.osim +OpenSimAddTest(NAME testMocoMetabolics + LINKLIBS osimMoco + RESOURCES resources/testMocoMetabolics_hanging_muscle.osim ) file(COPY resources/subject_walk_armless_18musc.osim @@ -87,4 +88,4 @@ file(COPY resources/subject_walk_armless_18musc.osim file(COPY resources/walk_gait1018_subject01.osim resources/walk_gait1018_state_reference.mot - DESTINATION "${CMAKE_BINARY_DIR}/OpenSim/Tests/Wrapping") + DESTINATION "${CMAKE_BINARY_DIR}/OpenSim/Tests/Wrapping") diff --git a/OpenSim/Simulation/SimbodyEngine/tests/CMakeLists.txt b/OpenSim/Simulation/SimbodyEngine/tests/CMakeLists.txt index 9d462a3bd9..dd3c5aa215 100644 --- a/OpenSim/Simulation/SimbodyEngine/tests/CMakeLists.txt +++ b/OpenSim/Simulation/SimbodyEngine/tests/CMakeLists.txt @@ -1,14 +1,13 @@ find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") -file(GLOB TEST_PROGS "test*.cpp") -file(GLOB TEST_FILES resources/*.osim - resources/*.xml - resources/*.sto - resources/*.mot) +OpenSimAddTest(NAME testConstraints + LINKLIBS osimSimulation osimCommon osimAnalyses + RESOURCES resources/testJointConstraints.osim + ) -OpenSimAddTests( - TESTPROGRAMS ${TEST_PROGS} - DATAFILES ${TEST_FILES} - LINKLIBS osimSimulation osimCommon osimAnalyses Catch2::Catch2WithMain - ) +OpenSimAddTest(NAME testJoints + LINKLIBS osimSimulation osimCommon osimAnalyses + RESOURCES resources/double_pendulum_testReverse.osim + resources/testJointConstraints.osim + ) diff --git a/OpenSim/Simulation/tests/CMakeLists.txt b/OpenSim/Simulation/tests/CMakeLists.txt index e7e73bd4b2..041f04e4de 100644 --- a/OpenSim/Simulation/tests/CMakeLists.txt +++ b/OpenSim/Simulation/tests/CMakeLists.txt @@ -1,19 +1,135 @@ find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") -file(GLOB TEST_PROGS "test*.cpp") -file(GLOB TEST_FILES resources/*.osim - resources/*.xml - resources/*.sto - resources/*.mot - resources/*.obj - resources/*.vtp - resources/*.stl) - -OpenSimAddTests( - TESTPROGRAMS ${TEST_PROGS} - DATAFILES ${TEST_FILES} - LINKLIBS osimCommon osimSimulation osimAnalyses osimActuators osimLepton Catch2::Catch2WithMain - ) +set(OSIM_SIMULATION_TEST_LIBS + osimCommon osimSimulation osimAnalyses osimActuators osimLepton) + +OpenSimAddTest(NAME testAssemblySolver + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS} + RESOURCES resources/PushUpToesOnGroundExactConstraints.osim + resources/PushUpToesOnGroundLessPreciseConstraints.osim + resources/PushUpToesOnGroundWithMuscles.osim + resources/knee_patella_ligament.osim + ) + +OpenSimAddTest(NAME testContactGeometry + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS} + RESOURCES resources/sphere_10cm_radius.obj + resources/sphere_10cm_radius.stl + resources/sphere_10cm_radius.vtp + ) + +OpenSimAddTest(NAME testExponentialContact + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS}) + +OpenSimAddTest(NAME testForceProducer + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS}) + +OpenSimAddTest(NAME testForces + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS} + RESOURCES resources/BouncingBallModelEF.osim + resources/BouncingBall_HuntCrossley.osim + resources/BouncingBall_SmoothSphereHalfSpace.osim + resources/BushingForceModel_30000.osim + resources/BushingForceOffsetModel_30000.osim + resources/PushUpToesOnGroundWithMuscles.osim + resources/bouncing_block_30000.osim + resources/external_force_data.sto + resources/sphere.obj + ) + +OpenSimAddTest(NAME testFrames + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS} + RESOURCES resources/double_pendulum.osim + ) + +OpenSimAddTest(NAME testFunctionBasedPath + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS}) + +OpenSimAddTest(NAME testInitState + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS} + RESOURCES resources/arm26.osim + resources/arm26_StaticOptimization_controls.xml + ) + +OpenSimAddTest(NAME testInverseKinematicsSolver + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS}) + +OpenSimAddTest(NAME testManager + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS} + RESOURCES resources/arm26.osim + ) + +OpenSimAddTest(NAME testModelInterface + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS} + RESOURCES resources/arm26.osim + ) + +OpenSimAddTest(NAME testMomentArms + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS} + RESOURCES resources/BothLegs22.osim + resources/CoupledCoordinatesMPPsMomentArmTest.osim + resources/MovingPathPointMomentArmTest.osim + resources/MovingPointCustomJointMomentArmTest.osim + resources/MultipleMPPsMomentArmTest.osim + resources/P2PBallCustomJointMomentArmTest.osim + resources/P2PBallJointMomentArmTest.osim + resources/P2PCustomJointMomentArmTest.osim + resources/PathOnConstrainedBodyMomentArmTest.osim + resources/WrapPathCustomJointMomentArmTest.osim + resources/gait2354_simbody.osim + resources/testMomentArmsConstraintA.osim + resources/testMomentArmsConstraintB.osim + resources/wrist_mass.osim + ) + +OpenSimAddTest(NAME testMuscleMetabolicsProbes + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS}) + +OpenSimAddTest(NAME testNestedModelComponents + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS} + RESOURCES resources/double_pendulum.osim + ) + +OpenSimAddTest(NAME testPointToPointSpring + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS}) + +OpenSimAddTest(NAME testPoints + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS} + RESOURCES resources/double_pendulum.osim + ) + +OpenSimAddTest(NAME testPrescribedForce + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS}) + +OpenSimAddTest(NAME testProbes + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS}) + +OpenSimAddTest(NAME testReportersWithModel + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS}) + +OpenSimAddTest(NAME testSimulationUtilities + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS} + RESOURCES resources/testSimulationUtilities_leg69_IK_stance_pre4.mot + resources/testSimulationUtilities_leg6dof9musc_20303.osim + ) + +OpenSimAddTest(NAME testStatesDocument + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS}) + +OpenSimAddTest(NAME testStatesTrajectory + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS} + RESOURCES resources/arm26.osim + resources/gait2354_simbody.osim + ) + +OpenSimAddTest(NAME testStationDefinedFrame + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS} + RESOURCES resources/StationDefinedFrames_Advanced.osim + resources/StationDefinedFrames_Basic.osim + ) + +OpenSimAddTest(NAME testTableProcessor + LINKLIBS ${OSIM_SIMULATION_TEST_LIBS}) OpenSimCopySharedTestFiles(std_subject01_walk1_states.sto) diff --git a/OpenSim/Tests/AddComponents/CMakeLists.txt b/OpenSim/Tests/AddComponents/CMakeLists.txt index 57d3d29995..5f6ca12b9f 100644 --- a/OpenSim/Tests/AddComponents/CMakeLists.txt +++ b/OpenSim/Tests/AddComponents/CMakeLists.txt @@ -1,44 +1,9 @@ find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") -# Define test target and current test dir -set(TEST_TARGET testAddComponents) -set(TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}) - -# Copy dependencies from ExampleMain into the run directory -set(EXAMPLE_DIR ${OpenSim_SOURCE_DIR}/OpenSim/Examples/ExampleMain) -file(GLOB TEST_FILES - ${EXAMPLE_DIR}/*.obj - ${EXAMPLE_DIR}/*.osim - ${EXAMPLE_DIR}/*.xml - ${EXAMPLE_DIR}/*.sto - ${EXAMPLE_DIR}/*.mot - *.obj *.osim *.xml *.sto *.mot) - -# -# Copy example files to run dir -# -foreach(dataFile ${TEST_FILES}) - file(COPY ${dataFile} DESTINATION ${TEST_DIR}) -endforeach(dataFile) - -# Copy the standard answer for example main -set(TEST_EXAMPLE_DIR ${OpenSim_SOURCE_DIR}/OpenSim/Tests/ExampleMain) -file(GLOB STD_TEST_FILES - ${TEST_EXAMPLE_DIR}/*.sto - ${TEST_EXAMPLE_DIR}/*.mot) - -# -# Copy standard test results to the run dir -# -foreach(dataFile ${STD_TEST_FILES}) - file(COPY ${dataFile} DESTINATION ${TEST_DIR}) -endforeach(dataFile) - -# -# Testing -# -OpenSimAddTests( - TESTPROGRAMS ${TEST_TARGET}.cpp - LINKLIBS osimTools osimSimulation osimActuators Catch2::Catch2WithMain - ) \ No newline at end of file +OpenSimAddTest(NAME testAddComponents + LINKLIBS osimTools osimSimulation osimActuators + RESOURCES "${OpenSim_SOURCE_DIR}/OpenSim/Examples/ExampleMain/blockMesh.obj" + "${OpenSim_SOURCE_DIR}/OpenSim/Tests/ExampleMain/std_tugOfWar_forces.mot" + "${OpenSim_SOURCE_DIR}/OpenSim/Tests/ExampleMain/std_tugOfWar_states.sto" + ) diff --git a/OpenSim/Tests/Components/CMakeLists.txt b/OpenSim/Tests/Components/CMakeLists.txt index 831e551104..5abf724c83 100644 --- a/OpenSim/Tests/Components/CMakeLists.txt +++ b/OpenSim/Tests/Components/CMakeLists.txt @@ -1,9 +1,6 @@ find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") -file(GLOB TEST_PROGS "test*.cpp") OpenSimCopySharedTestFiles(gait10dof18musc_subject01.osim) -OpenSimAddTests( - TESTPROGRAMS ${TEST_PROGS} - LINKLIBS osimTools Catch2::Catch2WithMain - ) +OpenSimAddTest(NAME testComponents + LINKLIBS osimTools) diff --git a/OpenSim/Tests/ConstantCurvatureExample/CMakeLists.txt b/OpenSim/Tests/ConstantCurvatureExample/CMakeLists.txt index 5c12a64c44..0cb488fec0 100644 --- a/OpenSim/Tests/ConstantCurvatureExample/CMakeLists.txt +++ b/OpenSim/Tests/ConstantCurvatureExample/CMakeLists.txt @@ -1,9 +1,5 @@ find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") -file(GLOB TEST_PROGS "test*.cpp") - -OpenSimAddTests( - TESTPROGRAMS ${TEST_PROGS} - LINKLIBS osimTools Catch2::Catch2WithMain - ) +OpenSimAddTest(NAME testConstantCurvature + LINKLIBS osimTools) diff --git a/OpenSim/Tests/Wrapping/CMakeLists.txt b/OpenSim/Tests/Wrapping/CMakeLists.txt index e8e9927542..9a505ed4c6 100644 --- a/OpenSim/Tests/Wrapping/CMakeLists.txt +++ b/OpenSim/Tests/Wrapping/CMakeLists.txt @@ -1,16 +1,21 @@ find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") -set(TEST_PROGS - testWrapObject.cpp - testWrapCylinder.cpp - testGeometryPathWrapping.cpp - testScholz2015GeometryPath.cpp -) -file(GLOB TEST_FILES *.osim *.xml *.sto *.mot) -OpenSimAddTests( - TESTPROGRAMS ${TEST_PROGS} - DATAFILES ${TEST_FILES} - LINKLIBS osimTools Catch2::Catch2WithMain - ) +OpenSimAddTest(NAME testGeometryPathWrapping + LINKLIBS osimTools + RESOURCES std_testGeometryPathWrapping_subject_walk_armless_muscle_lengths.sto + std_testGeometryPathWrapping_walk_gait1018_muscle_lengths.sto + testGeometryPathWrapping_ShoulderWrappingWithPathSprings.osim + ) + +OpenSimAddTest(NAME testScholz2015GeometryPath + LINKLIBS osimTools) + +OpenSimAddTest(NAME testWrapCylinder + LINKLIBS osimTools) + +OpenSimAddTest(NAME testWrapObject + LINKLIBS osimTools + RESOURCES testWrapObject_updateFromXMLNode30515.osim + ) diff --git a/OpenSim/Tests/testIterators/CMakeLists.txt b/OpenSim/Tests/testIterators/CMakeLists.txt index 9b5918089c..8d0b204243 100644 --- a/OpenSim/Tests/testIterators/CMakeLists.txt +++ b/OpenSim/Tests/testIterators/CMakeLists.txt @@ -1,11 +1,7 @@ find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") -file(GLOB TEST_PROGS "test*.cpp") - OpenSimCopySharedTestFiles(arm26.osim) -OpenSimAddTests( - TESTPROGRAMS ${TEST_PROGS} - LINKLIBS osimSimulation osimActuators Catch2::Catch2WithMain - ) +OpenSimAddTest(NAME testIterators + LINKLIBS osimSimulation osimActuators) diff --git a/OpenSim/Tools/tests/CMakeLists.txt b/OpenSim/Tools/tests/CMakeLists.txt index b076dc122d..c389109ffb 100644 --- a/OpenSim/Tools/tests/CMakeLists.txt +++ b/OpenSim/Tools/tests/CMakeLists.txt @@ -1,21 +1,45 @@ find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") -file(GLOB TEST_PROGS "test*.cpp") -file(GLOB TEST_FILES resources/*.osim - resources/*.xml - resources/*.sto - resources/*.mot - resources/*.txt - resources/*.obj - resources/*.vtp) +OpenSimAddTest(NAME testControllers + LINKLIBS osimTools + RESOURCES resources/arm26.osim + resources/arm26_Reserve_Actuators.xml + resources/arm26_controls.xml + resources/block.vtp + resources/testControllers_TugOfWar.osim + ) -OpenSimAddTests( - TESTPROGRAMS ${TEST_PROGS} - DATAFILES ${TEST_FILES} - LINKLIBS osimTools Catch2::Catch2WithMain - ) +OpenSimAddTest(NAME testExternalLoads + LINKLIBS osimTools + RESOURCES resources/Pendulum.osim + resources/cylinder.vtp + ) +OpenSimAddTest(NAME testModelCopy + LINKLIBS osimTools + RESOURCES resources/Neck3dof_point_constraint.osim + resources/arm26.osim + ) + +OpenSimAddTest(NAME testSerializeOpenSimObjects + LINKLIBS osimTools + RESOURCES resources/ikToolNoDocumentTag.xml + ) + +OpenSimAddTest(NAME testVisualization + LINKLIBS osimTools + RESOURCES resources/BuiltinGeometry.osim + resources/block.vtp + resources/cylinder.vtp + resources/double_pendulum33.osim + resources/doubletransform33.osim + resources/sphere.vtp + resources/test_wrapAllVis.osim + resources/vis_AppearanceTest.txt + resources/vis_BuiltinGeometry.txt + resources/visualize_contacts.osim + ) # edge-case: one test ensures that `ExternalLoads` still works - even when it isn't in # the working directory of the test runner (#3926) diff --git a/Vendors/lepton/tests/CMakeLists.txt b/Vendors/lepton/tests/CMakeLists.txt index a8cd0e7b1f..d64a1f9755 100644 --- a/Vendors/lepton/tests/CMakeLists.txt +++ b/Vendors/lepton/tests/CMakeLists.txt @@ -1,9 +1,5 @@ find_package(Catch2 REQUIRED HINTS "${OPENSIM_DEPENDENCIES_DIR}/catch2") -file(GLOB TEST_PROGS "*test*.cpp") - -OpenSimAddTests( - TESTPROGRAMS ${TEST_PROGS} - LINKLIBS osimLepton Catch2::Catch2WithMain - ) +OpenSimAddTest(NAME testLepton + LINKLIBS osimLepton) diff --git a/cmake/OpenSimMacros.cmake b/cmake/OpenSimMacros.cmake index 2698bfcafb..8c4e7ee96b 100644 --- a/cmake/OpenSimMacros.cmake +++ b/cmake/OpenSimMacros.cmake @@ -412,87 +412,80 @@ function(OpenSimCopySharedTestFiles) endif() endfunction() -# Create test targets for this directory. -# TESTPROGRAMS: Names of test CPP files. One test will be created for each cpp -# of these files. -# DATAFILES: Files necessary to run the test. These will be copied into the -# corresponding build directory. + +# Create an executable for the file ${OSIMTEST_NAME}.cpp, which depends on +# libraries ${LINKLIBS}. Also, create a CTest test for this executable. +# +# RESOURCES: Files necessary to run the test. These will be symlinked into the +# corresponding build directory. Relative paths are interpreted +# relative to the current source directory. # LINKLIBS: Arguments to TARGET_LINK_LIBRARIES. -# SOURCES: Extra source files for the executable. +# EXTRA_SOURCES: Extra source files for the executable. +# ENVIRONMENT: "NAME=VALUE" entries to add to the test's ENVIRONMENT property. +# DISABLED: If TRUE, the test is still built and registered, but will be +# skipped by CTest instead of run. # # Here's an example: -# file(GLOB TEST_PROGRAMS "test*.cpp") -# file(GLOB DATA_FILES *.osim *.xml *.sto *.mot) -# OpenSimAddTests( -# TESTPROGRAMS ${TEST_PROGRAMS} -# DATAFILES ${DATA_FILES} -# LINKLIBS osimCommon osimSimulation osimAnalyses -# ) -function(OpenSimAddTests) +# OpenSimAddTest(NAME testMocoContact +# LINKLIBS osimMoco +# DISABLED ${MOCO_CASADI_TESTS_DISABLED} +# ENVIRONMENT "OPENSIM_MOCO_PARALLEL=0" +# RESOURCES resources/subject_20dof18musc_running.osim +# resources/running_solution_full_stride.sto) +# +function(OpenSimAddTest) if(BUILD_TESTING) # Parse arguments. # ---------------- - # http://www.cmake.org/cmake/help/v2.8.9/cmake.html#module:CMakeParseArguments set(options) - set(oneValueArgs) - set(multiValueArgs TESTPROGRAMS DATAFILES LINKLIBS SOURCES) - cmake_parse_arguments( - OSIMADDTESTS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - - # If EXECUTABLE_OUTPUT_PATH is set, then that's where the tests will be - # located. Otherwise, they are located in the current binary directory. - if(EXECUTABLE_OUTPUT_PATH) - set(TEST_PATH "${EXECUTABLE_OUTPUT_PATH}") - else() - set(TEST_PATH "${CMAKE_CURRENT_BINARY_DIR}") + set(oneValueArgs NAME DISABLED) + set(multiValueArgs RESOURCES LINKLIBS EXTRA_SOURCES ENVIRONMENT) + cmake_parse_arguments(OSIMTEST + "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + add_executable(${OSIMTEST_NAME} ${OSIMTEST_NAME}.cpp + "${CMAKE_SOURCE_DIR}/tests/Testing.h" ${OSIMTEST_EXTRA_SOURCES}) + OpenSimConfigureTarget(${OSIMTEST_NAME}) + set_target_properties(${OSIMTEST_NAME} PROPERTIES FOLDER "Tests") + target_link_libraries(${OSIMTEST_NAME} ${OSIMTEST_LINKLIBS} + osimTesting Catch2::Catch2WithMain) + + # Platform-specific test exclusion. + if(APPLE) + list(APPEND test_args "~[win]~[linux]~[win/linux]~[linux/win]") + endif() + if(LINUX) + list(APPEND test_args "~[win]~[mac]~[win/mac]~[mac/win]") + endif() + if(WIN32) + list(APPEND test_args "~[mac]~[linux]~[mac/linux]~[linux/mac]~[unix]") endif() - # Make test targets. - foreach(test_program ${OSIMADDTESTS_TESTPROGRAMS}) - # NAME_WE stands for "name without extension" - get_filename_component(TEST_NAME ${test_program} NAME_WE) - - add_executable(${TEST_NAME} ${test_program} - ${OSIMADDTESTS_SOURCES}) - OpenSimConfigureTarget(${TEST_NAME}) - target_link_libraries(${TEST_NAME} ${OSIMADDTESTS_LINKLIBS} - osimTesting) - set(test_args "") - if(APPLE) - list(APPEND test_args "~[win]~[linux]~[win/linux]~[linux/win]") - endif() - if(LINUX) - list(APPEND test_args "~[win]~[mac]~[win/mac]~[mac/win]") - endif() - if(WIN32) - list(APPEND test_args "~[mac]~[linux]~[mac/linux]~[linux/mac]~[unix]") - endif() - add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME} ${test_args}) - set_target_properties(${TEST_NAME} PROPERTIES - FOLDER "Tests" - ) - endforeach() - - # Copy data files to build directory. - foreach(data_file ${OSIMADDTESTS_DATAFILES}) - # This command symlinks the data files - # from the source directories into the running directory. - # This preserves changes to source files. - get_filename_component(FILENAME ${data_file} NAME) - add_custom_command( - TARGET ${TEST_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E create_symlink - "${data_file}" - "${CMAKE_CURRENT_BINARY_DIR}/${FILENAME}") + # Add the test. + add_test(NAME ${OSIMTEST_NAME} COMMAND ${OSIMTEST_NAME} ${test_args}) + + # Skip this test, if required. + set_tests_properties(${OSIMTEST_NAME} PROPERTIES + DISABLED "${OSIMTEST_DISABLED}") + + # Set any test-specific environment variables. + set_property(TEST ${OSIMTEST_NAME} APPEND PROPERTY + ENVIRONMENT ${OSIMTEST_ENVIRONMENT}) + + # Symlink test resources into the build directory. + foreach(resource ${OSIMTEST_RESOURCES}) + get_filename_component(RESOURCE_PATH "${resource}" ABSOLUTE + BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") + get_filename_component(RESOURCE_NAME "${resource}" NAME) + # Create the symlink, falling back to a plain file copy + # if the symlink fails. + file(CREATE_LINK "${RESOURCE_PATH}" + "${CMAKE_CURRENT_BINARY_DIR}/${RESOURCE_NAME}" + SYMBOLIC COPY_ON_ERROR) endforeach() - #if(UNIX) - # add_definitions(-fprofile-arcs -ftest-coverage) - # link_libraries(gcov) - #endif(UNIX) - endif() endfunction()