summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-03-17 14:14:52 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2015-03-17 14:14:52 (GMT)
commit8915cddcde6f8b0946e54f1cd6c9b8434bf4fd14 (patch)
tree9efbb513e5045b7bf01173bf193a8f5d537ef1a9 /Tests
parente9072d26c0d90a8ff521d46347e5d1b3555f8099 (diff)
parent49c8dcf7bb8ae9e7584286e552769a61bf23e61b (diff)
downloadCMake-8915cddcde6f8b0946e54f1cd6c9b8434bf4fd14.zip
CMake-8915cddcde6f8b0946e54f1cd6c9b8434bf4fd14.tar.gz
CMake-8915cddcde6f8b0946e54f1cd6c9b8434bf4fd14.tar.bz2
Merge topic 'FindMatlab-rewrite'
49c8dcf7 FindMatlab: Rewrite module and provide a usage API
Diffstat (limited to 'Tests')
-rw-r--r--Tests/CMakeLists.txt6
-rw-r--r--Tests/FindMatlab/basic_checks/CMakeLists.txt57
-rw-r--r--Tests/FindMatlab/cmake_matlab_unit_tests1.m33
-rw-r--r--Tests/FindMatlab/cmake_matlab_unit_tests2.m6
-rw-r--r--Tests/FindMatlab/cmake_matlab_unit_tests3.m5
-rw-r--r--Tests/FindMatlab/cmake_matlab_unit_tests_timeout.m16
-rw-r--r--Tests/FindMatlab/help_text1.m.txt2
-rw-r--r--Tests/FindMatlab/matlab_wrapper1.cpp26
-rw-r--r--Tests/FindMatlab/versions_checks/CMakeLists.txt52
-rw-r--r--Tests/RunCMake/CMakeLists.txt5
-rw-r--r--Tests/RunCMake/FindMatlab/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/FindMatlab/MatlabTest1-result.txt1
-rw-r--r--Tests/RunCMake/FindMatlab/MatlabTest1-stderr.txt2
-rw-r--r--Tests/RunCMake/FindMatlab/MatlabTest1.cmake22
-rw-r--r--Tests/RunCMake/FindMatlab/RunCMakeTest.cmake3
-rw-r--r--Tests/RunCMake/FindMatlab/cmake_matlab_unit_tests2.m6
-rw-r--r--Tests/RunCMake/FindMatlab/matlab_wrapper1.cpp26
17 files changed, 271 insertions, 0 deletions
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index c755651..40bea51 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -1256,6 +1256,12 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
add_subdirectory(FindJsonCpp)
endif()
+ # Matlab module
+ if(CMake_TEST_FindMatlab)
+ ADD_TEST_MACRO(FindMatlab.basic_checks ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>)
+ ADD_TEST_MACRO(FindMatlab.versions_checks ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION>)
+ endif()
+
find_package(GTK2 QUIET)
if(GTK2_FOUND)
add_subdirectory(FindGTK2)
diff --git a/Tests/FindMatlab/basic_checks/CMakeLists.txt b/Tests/FindMatlab/basic_checks/CMakeLists.txt
new file mode 100644
index 0000000..acf71ea
--- /dev/null
+++ b/Tests/FindMatlab/basic_checks/CMakeLists.txt
@@ -0,0 +1,57 @@
+
+cmake_minimum_required (VERSION 2.8.12)
+enable_testing()
+project(basic_checks)
+
+set(MATLAB_FIND_DEBUG TRUE)
+
+# the success of the following command is dependent on the current configuration:
+# - on 32bits builds (cmake is building with 32 bits), it looks for 32 bits Matlab
+# - on 64bits builds (cmake is building with 64 bits), it looks for 64 bits Matlab
+find_package(Matlab REQUIRED COMPONENTS MX_LIBRARY MAIN_PROGRAM)
+
+
+
+matlab_add_mex(
+ # target name
+ NAME cmake_matlab_test_wrapper1
+ # output name
+ OUTPUT_NAME cmake_matlab_mex1
+ SRC ${CMAKE_CURRENT_SOURCE_DIR}/../matlab_wrapper1.cpp
+ DOCUMENTATION ${CMAKE_CURRENT_SOURCE_DIR}/../help_text1.m.txt
+ )
+
+
+matlab_add_unit_test(
+ NAME ${PROJECT_NAME}_matlabtest-1
+ TIMEOUT 30
+ UNITTEST_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../cmake_matlab_unit_tests1.m
+ ADDITIONAL_PATH $<TARGET_FILE_DIR:cmake_matlab_test_wrapper1>
+ )
+
+matlab_add_unit_test(
+ NAME ${PROJECT_NAME}_matlabtest-2
+ TIMEOUT 15
+ UNITTEST_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../cmake_matlab_unit_tests_timeout.m
+ ADDITIONAL_PATH $<TARGET_FILE_DIR:cmake_matlab_test_wrapper1>
+ )
+set_tests_properties(${PROJECT_NAME}_matlabtest-2 PROPERTIES WILL_FAIL TRUE)
+
+
+# testing the test without the unittest framework of Matlab
+matlab_add_unit_test(
+ NAME ${PROJECT_NAME}_matlabtest-3
+ TIMEOUT 30
+ NO_UNITTEST_FRAMEWORK
+ UNITTEST_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../cmake_matlab_unit_tests2.m
+ ADDITIONAL_PATH $<TARGET_FILE_DIR:cmake_matlab_test_wrapper1>
+ )
+
+matlab_add_unit_test(
+ NAME ${PROJECT_NAME}_matlabtest-4
+ TIMEOUT 30
+ NO_UNITTEST_FRAMEWORK
+ UNITTEST_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../cmake_matlab_unit_tests3.m
+ ADDITIONAL_PATH $<TARGET_FILE_DIR:cmake_matlab_test_wrapper1>
+ )
+set_tests_properties(${PROJECT_NAME}_matlabtest-4 PROPERTIES WILL_FAIL TRUE)
diff --git a/Tests/FindMatlab/cmake_matlab_unit_tests1.m b/Tests/FindMatlab/cmake_matlab_unit_tests1.m
new file mode 100644
index 0000000..2371c3a
--- /dev/null
+++ b/Tests/FindMatlab/cmake_matlab_unit_tests1.m
@@ -0,0 +1,33 @@
+
+classdef cmake_matlab_unit_tests1 < matlab.unittest.TestCase
+ % some simple unit test for CMake Matlab wrapper
+ properties
+ end
+
+ methods (Test)
+ function testDummyCall(testCase)
+ % very simple call test
+ cmake_matlab_mex1(rand(3,3));
+ end
+
+ function testDummyCall2(testCase)
+ % very simple call test 2
+ ret = cmake_matlab_mex1(rand(3,3));
+ testCase.verifyEqual(size(ret), size(rand(3,3)));
+
+ testCase.verifyEqual(size(cmake_matlab_mex1(rand(4,3))), [4,3] );
+ end
+
+ function testFailTest(testCase)
+ testCase.verifyError(@() cmake_matlab_mex1(10), 'cmake_matlab:configuration');
+ testCase.verifyError(@() cmake_matlab_mex1([10]), 'cmake_matlab:configuration');
+ end
+
+ function testHelpContent(testCase)
+ % testing the help feature
+ testCase.verifySubstring(evalc('help cmake_matlab_mex1'), 'Dummy matlab extension in cmake');
+ end
+
+
+ end
+end
diff --git a/Tests/FindMatlab/cmake_matlab_unit_tests2.m b/Tests/FindMatlab/cmake_matlab_unit_tests2.m
new file mode 100644
index 0000000..7a8a342
--- /dev/null
+++ b/Tests/FindMatlab/cmake_matlab_unit_tests2.m
@@ -0,0 +1,6 @@
+
+ret = cmake_matlab_mex1(rand(3,3));
+
+if(size(ret) ~= size(rand(3,3)))
+ error('Dimension mismatch!');
+end
diff --git a/Tests/FindMatlab/cmake_matlab_unit_tests3.m b/Tests/FindMatlab/cmake_matlab_unit_tests3.m
new file mode 100644
index 0000000..2639325
--- /dev/null
+++ b/Tests/FindMatlab/cmake_matlab_unit_tests3.m
@@ -0,0 +1,5 @@
+
+cmake_matlab_mex1(10);
+
+% should not reach this point
+exit(0);
diff --git a/Tests/FindMatlab/cmake_matlab_unit_tests_timeout.m b/Tests/FindMatlab/cmake_matlab_unit_tests_timeout.m
new file mode 100644
index 0000000..11d5e9e
--- /dev/null
+++ b/Tests/FindMatlab/cmake_matlab_unit_tests_timeout.m
@@ -0,0 +1,16 @@
+
+classdef cmake_matlab_unit_tests_timeout < matlab.unittest.TestCase
+ % timeout tests
+
+ properties
+ end
+
+ methods (Test)
+ function testCallHangsShouldBeTimedOut(testCase)
+ cmake_matlab_mex1(rand(3,3));
+ disp('Will now wait.');
+ disp('Testing the cmake Matlab package timeout - do not kill');
+ pause(20); % supposed to be killed after 15s
+ end
+ end
+end
diff --git a/Tests/FindMatlab/help_text1.m.txt b/Tests/FindMatlab/help_text1.m.txt
new file mode 100644
index 0000000..a924355
--- /dev/null
+++ b/Tests/FindMatlab/help_text1.m.txt
@@ -0,0 +1,2 @@
+% Dummy matlab extension in cmake
+function ret = cmake_matlab_mex1(X)
diff --git a/Tests/FindMatlab/matlab_wrapper1.cpp b/Tests/FindMatlab/matlab_wrapper1.cpp
new file mode 100644
index 0000000..4149bb9
--- /dev/null
+++ b/Tests/FindMatlab/matlab_wrapper1.cpp
@@ -0,0 +1,26 @@
+
+// simple workaround to some compiler specific problems
+// see http://stackoverflow.com/questions/22367516/mex-compile-error-unknown-type-name-char16-t/23281916#23281916
+#include <algorithm>
+
+#include "mex.h"
+
+// this test should return a matrix of 10 x 10 and should check some of the arguments
+
+void mexFunction(const int nlhs, mxArray *plhs[], const int nrhs, const mxArray *prhs[])
+{
+ if(nrhs != 1)
+ {
+ mexErrMsgTxt("Incorrect arguments");
+ }
+
+ size_t dim1 = mxGetM(prhs[0]);
+ size_t dim2 = mxGetN(prhs[0]);
+
+ if(dim1 == 1 || dim2 == 1)
+ {
+ mexErrMsgIdAndTxt("cmake_matlab:configuration", "Incorrect arguments");
+ }
+
+ plhs[0] = mxCreateNumericMatrix(dim1, dim2, mxGetClassID(prhs[0]), mxREAL);
+}
diff --git a/Tests/FindMatlab/versions_checks/CMakeLists.txt b/Tests/FindMatlab/versions_checks/CMakeLists.txt
new file mode 100644
index 0000000..5d20685
--- /dev/null
+++ b/Tests/FindMatlab/versions_checks/CMakeLists.txt
@@ -0,0 +1,52 @@
+
+cmake_minimum_required (VERSION 2.8.12)
+enable_testing()
+project(versions_checks)
+
+set(MATLAB_FIND_DEBUG TRUE)
+set(MATLAB_ADDITIONAL_VERSIONS
+ "dummy=14.9")
+
+# the success of the following command is dependent on the current configuration
+# in this case, we are only interested in the version macros
+find_package(Matlab)
+
+
+
+if(NOT COMMAND matlab_get_version_from_release_name)
+ message(FATAL_ERROR "The macro matlab_get_version_from_release_name should be defined")
+endif()
+
+if(NOT COMMAND matlab_get_release_name_from_version)
+ message(FATAL_ERROR "The macro matlab_get_release_name_from_version should be defined")
+endif()
+
+
+# matlab_get_release_name_from_version
+matlab_get_release_name_from_version("7.13" release_name)
+if(NOT release_name STREQUAL "R2011b")
+ message(FATAL_ERROR "version 7.13 does not give release R2011b : '${release_name}' != R2011b")
+endif()
+
+matlab_get_release_name_from_version("14.9" release_name)
+if(NOT release_name STREQUAL "dummy")
+ message(FATAL_ERROR "version 14.9 does not give release dummy : '${release_name}' != dummy")
+endif()
+
+matlab_get_release_name_from_version("14.10" release_name)
+if(NOT release_name STREQUAL "")
+ message(FATAL_ERROR "version 14.10 does not give empty release: '${release_name}' != ''")
+endif()
+
+
+# matlab_get_version_from_release_name
+matlab_get_version_from_release_name("R2011a" version)
+if(NOT version STREQUAL "7.12")
+ message(FATAL_ERROR "Release R2011a does not give version 7.12 : '${version}' != 7.12")
+endif()
+
+matlab_get_version_from_release_name("dummy" version)
+#message(FATAL_ERROR "versionversion = ${version}")
+if(NOT version STREQUAL "14.9")
+ message(FATAL_ERROR "Release dummy does not give version 14.9 : '${version}' != 14.9")
+endif()
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index 1bcc3f3..7cbc9fe 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -211,3 +211,8 @@ if(RPMBUILD_EXECUTABLE)
endif()
add_RunCMake_test(COMPILE_LANGUAGE-genex)
+
+# Matlab module related tests
+if(CMake_TEST_FindMatlab)
+ add_RunCMake_test(FindMatlab)
+endif()
diff --git a/Tests/RunCMake/FindMatlab/CMakeLists.txt b/Tests/RunCMake/FindMatlab/CMakeLists.txt
new file mode 100644
index 0000000..1b9a957
--- /dev/null
+++ b/Tests/RunCMake/FindMatlab/CMakeLists.txt
@@ -0,0 +1,3 @@
+
+cmake_minimum_required(VERSION 2.8.12)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/FindMatlab/MatlabTest1-result.txt b/Tests/RunCMake/FindMatlab/MatlabTest1-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/FindMatlab/MatlabTest1-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/FindMatlab/MatlabTest1-stderr.txt b/Tests/RunCMake/FindMatlab/MatlabTest1-stderr.txt
new file mode 100644
index 0000000..95a787f
--- /dev/null
+++ b/Tests/RunCMake/FindMatlab/MatlabTest1-stderr.txt
@@ -0,0 +1,2 @@
+CMake Error at .*FindMatlab.cmake:[0-9]+ \(message\):
+ \[MATLAB\] This functionality needs the MAIN_PROGRAM component \(not default\)
diff --git a/Tests/RunCMake/FindMatlab/MatlabTest1.cmake b/Tests/RunCMake/FindMatlab/MatlabTest1.cmake
new file mode 100644
index 0000000..1cbc1c2
--- /dev/null
+++ b/Tests/RunCMake/FindMatlab/MatlabTest1.cmake
@@ -0,0 +1,22 @@
+
+cmake_minimum_required (VERSION 2.8.12)
+enable_testing()
+project(test_should_fail)
+
+find_package(Matlab REQUIRED COMPONENTS MX_LIBRARY)
+
+matlab_add_mex(
+ # target name
+ NAME cmake_matlab_test_wrapper1
+ # output name
+ OUTPUT_NAME cmake_matlab_mex1
+ SRC ${CMAKE_CURRENT_SOURCE_DIR}/matlab_wrapper1.cpp
+ )
+
+# this command should raise a FATAL_ERROR, component MAIN_PROGRAM is missing
+matlab_add_unit_test(
+ NAME ${PROJECT_NAME}_matlabtest-1
+ TIMEOUT 1
+ UNITTEST_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake_matlab_unit_tests2.m
+ ADDITIONAL_PATH $<TARGET_FILE_DIR:cmake_matlab_test_wrapper1>
+ )
diff --git a/Tests/RunCMake/FindMatlab/RunCMakeTest.cmake b/Tests/RunCMake/FindMatlab/RunCMakeTest.cmake
new file mode 100644
index 0000000..33dbb77
--- /dev/null
+++ b/Tests/RunCMake/FindMatlab/RunCMakeTest.cmake
@@ -0,0 +1,3 @@
+
+include(RunCMake)
+run_cmake(MatlabTest1)
diff --git a/Tests/RunCMake/FindMatlab/cmake_matlab_unit_tests2.m b/Tests/RunCMake/FindMatlab/cmake_matlab_unit_tests2.m
new file mode 100644
index 0000000..7a8a342
--- /dev/null
+++ b/Tests/RunCMake/FindMatlab/cmake_matlab_unit_tests2.m
@@ -0,0 +1,6 @@
+
+ret = cmake_matlab_mex1(rand(3,3));
+
+if(size(ret) ~= size(rand(3,3)))
+ error('Dimension mismatch!');
+end
diff --git a/Tests/RunCMake/FindMatlab/matlab_wrapper1.cpp b/Tests/RunCMake/FindMatlab/matlab_wrapper1.cpp
new file mode 100644
index 0000000..4149bb9
--- /dev/null
+++ b/Tests/RunCMake/FindMatlab/matlab_wrapper1.cpp
@@ -0,0 +1,26 @@
+
+// simple workaround to some compiler specific problems
+// see http://stackoverflow.com/questions/22367516/mex-compile-error-unknown-type-name-char16-t/23281916#23281916
+#include <algorithm>
+
+#include "mex.h"
+
+// this test should return a matrix of 10 x 10 and should check some of the arguments
+
+void mexFunction(const int nlhs, mxArray *plhs[], const int nrhs, const mxArray *prhs[])
+{
+ if(nrhs != 1)
+ {
+ mexErrMsgTxt("Incorrect arguments");
+ }
+
+ size_t dim1 = mxGetM(prhs[0]);
+ size_t dim2 = mxGetN(prhs[0]);
+
+ if(dim1 == 1 || dim2 == 1)
+ {
+ mexErrMsgIdAndTxt("cmake_matlab:configuration", "Incorrect arguments");
+ }
+
+ plhs[0] = mxCreateNumericMatrix(dim1, dim2, mxGetClassID(prhs[0]), mxREAL);
+}