Commit bbece095 authored by hbristow's avatar hbristow

Starting writing Matlab testing framework

parent 31415e34
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
# MATLAB_FOUND: true/false # MATLAB_FOUND: true/false
# MATLAB_ROOT_DIR: Root of Matlab installation # MATLAB_ROOT_DIR: Root of Matlab installation
# MATLAB_MEX_SCRIPT: The mex script used to compile mex files # MATLAB_MEX_SCRIPT: The mex script used to compile mex files
# MATLAB_BIN: The actual Matlab executable
# MATLAB_INCLUDE_DIR: Path to "mex.h" # MATLAB_INCLUDE_DIR: Path to "mex.h"
# MATLAB_LIBRARY_DIR: Path to mex and matrix libraries # MATLAB_LIBRARY_DIR: Path to mex and matrix libraries
# MATLAB_LIBS: The Matlab libs, usually mx, mex, mat # MATLAB_LIBS: The Matlab libs, usually mx, mex, mat
...@@ -119,8 +120,12 @@ function(locate_matlab_components MATLAB_ROOT_DIR) ...@@ -119,8 +120,12 @@ function(locate_matlab_components MATLAB_ROOT_DIR)
# get the mex shell script # get the mex shell script
find_file(MATLAB_MEX_SCRIPT_ NAMES mex mex.bat PATHS ${MATLAB_ROOT_DIR}/bin NO_DEFAULT_PATH) find_file(MATLAB_MEX_SCRIPT_ NAMES mex mex.bat PATHS ${MATLAB_ROOT_DIR}/bin NO_DEFAULT_PATH)
# get the Matlab executable
find_file(MATLAB_BIN_ NAMES matlab matlab.exe PATHS ${MATLAB_ROOT_DIR}/bin NO_DEFAULT_PATH)
# export into parent scope # export into parent scope
if (MATLAB_MEX_SCRIPT_ AND MATLAB_LIBS_ AND MATLAB_INCLUDE_DIR_) if (MATLAB_MEX_SCRIPT_ AND MATLAB_LIBS_ AND MATLAB_INCLUDE_DIR_)
set(MATLAB_BIN ${MATLAB_BIN_} PARENT_SCOPE)
set(MATLAB_MEX_SCRIPT ${MATLAB_MEX_SCRIPT_} PARENT_SCOPE) set(MATLAB_MEX_SCRIPT ${MATLAB_MEX_SCRIPT_} PARENT_SCOPE)
set(MATLAB_INCLUDE_DIR ${MATLAB_INCLUDE_DIR_} PARENT_SCOPE) set(MATLAB_INCLUDE_DIR ${MATLAB_INCLUDE_DIR_} PARENT_SCOPE)
set(MATLAB_LIBS ${MATLAB_LIBS_} PARENT_SCOPE) set(MATLAB_LIBS ${MATLAB_LIBS_} PARENT_SCOPE)
...@@ -151,7 +156,7 @@ if (NOT MATLAB_FOUND) ...@@ -151,7 +156,7 @@ if (NOT MATLAB_FOUND)
endif() endif()
find_package_handle_standard_args(Matlab DEFAULT_MSG MATLAB_MEX_SCRIPT MATLAB_INCLUDE_DIR find_package_handle_standard_args(Matlab DEFAULT_MSG MATLAB_MEX_SCRIPT MATLAB_INCLUDE_DIR
MATLAB_ROOT_DIR MATLAB_LIBS MATLAB_LIBRARY_DIR MATLAB_ROOT_DIR MATLAB_LIBS MATLAB_LIBRARY_DIR
MATLAB_MEXEXT MATLAB_ARCH) MATLAB_MEXEXT MATLAB_ARCH MATLAB_BIN)
# if Matlab was not found, unset the local variables # if Matlab was not found, unset the local variables
if (NOT MATLAB_FOUND) if (NOT MATLAB_FOUND)
......
...@@ -46,14 +46,16 @@ ocv_add_module(matlab BINDINGS opencv_core opencv_imgproc ...@@ -46,14 +46,16 @@ ocv_add_module(matlab BINDINGS opencv_core opencv_imgproc
opencv_highgui opencv_ml opencv_calib3d opencv_photo opencv_highgui opencv_ml opencv_calib3d opencv_photo
opencv_nonfree opencv_calib) opencv_nonfree opencv_calib)
set(HDR_PARSER_PATH ${OPENCV_MODULE_opencv_python_LOCATION}/src2) if (BUILD_TESTS)
add_subdirectory(test)
# get the include path of the Bridge endif()
prepend("-I" MEX_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/include)
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# Configure time components # Configure time components
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
set(HDR_PARSER_PATH ${OPENCV_MODULE_opencv_python_LOCATION}/src2)
prepend("-I" MEX_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/include)
message("-- Trying to generate Matlab code") message("-- Trying to generate Matlab code")
execute_process( execute_process(
COMMAND ${PYTHON_EXECUTABLE} COMMAND ${PYTHON_EXECUTABLE}
...@@ -124,3 +126,7 @@ foreach(SOURCE_FILE ${SOURCE_FILES}) ...@@ -124,3 +126,7 @@ foreach(SOURCE_FILE ${SOURCE_FILES})
DEPENDS opencv_matlab_sources DEPENDS opencv_matlab_sources
) )
endforeach() endforeach()
# ----------------------------------------------------------------------------
# Install time components
# ----------------------------------------------------------------------------
# glob the source files # run the matlab test suite
file(GLOB SOURCE_FILES *.cpp) add_test(opencv_matlab_test
COMMAND ${MATLAB_BIN} "-nodisplay" "-r" "testsuite.m"
# compile each source WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
foreach(SOURCE_FILE_ ${SOURCE_FILES}) )
get_filename_component(SOURCE_FILE_NAME_ ${SOURCE_FILE_} NAME_WE)
add_custom_target(${SOURCE_FILE_NAME_} ALL ${MATLAB_MEX_SCRIPT} ${SOURCE_FILE_})
endforeach()
% Matlab binding test cases
% Uses Matlab's builtin testing framework
classdef OpenCVTest < matlab.unittest.TestCase
methods(Test)
% check if the autogenerated functions can be found
function randExists(testcase)
try
cv.rand();
catch
testcase.verifyFail();
end
testcase.verifyTrue(true);
end
end
end
/*
* file: exception.cpp
* author: Hilton Bristow
* date: Wed, 19 Jun 2013 11:15:15
*
* See LICENCE for full modification and redistribution details.
* Copyright 2013 The OpenCV Foundation
*/
#include <exception>
#include <opencv2/core.hpp>
#include "mex.h"
/*
* exception
* Gateway routine
* nlhs - number of return arguments
* plhs - pointers to return arguments
* nrhs - number of input arguments
* prhs - pointers to input arguments
*/
void mexFunction(int nlhs, mxArray* plhs[],
int nrhs, const mxArray* prhs[]) {
// call the opencv function
// [out =] namespace.fun(src1, ..., srcn, dst1, ..., dstn, opt1, ..., optn);
try {
throw cv::exception;
} catch(cv::exception& e) {
mexErrMsgTxt(e.what());
} catch(...) {
mexErrMsgTxt("Incorrect exception caught!");
}
}
/*
* file: exception.cpp
* author: Hilton Bristow
* date: Wed, 19 Jun 2013 11:15:15
*
* See LICENCE for full modification and redistribution details.
* Copyright 2013 The OpenCV Foundation
*/
#include "mex.h"
/*
* exception
* Gateway routine
* nlhs - number of return arguments
* plhs - pointers to return arguments
* nrhs - number of input arguments
* prhs - pointers to input arguments
*/
void mexFunction(int nlhs, mxArray* plhs[],
int nrhs, const mxArray* prhs[]) {
// call the opencv function
// [out =] namespace.fun(src1, ..., srcn, dst1, ..., dstn, opt1, ..., optn);
try {
throw 1;
} catch(...) {
mexErrMsgTxt("Uncaught exception occurred!");
}
}
/*
* file: exception.cpp
* author: Hilton Bristow
* date: Wed, 19 Jun 2013 11:15:15
*
* See LICENCE for full modification and redistribution details.
* Copyright 2013 The OpenCV Foundation
*/
#include <exception>
#include "mex.h"
/*
* exception
* Gateway routine
* nlhs - number of return arguments
* plhs - pointers to return arguments
* nrhs - number of input arguments
* prhs - pointers to input arguments
*/
void mexFunction(int nlhs, mxArray* plhs[],
int nrhs, const mxArray* prhs[]) {
// call the opencv function
// [out =] namespace.fun(src1, ..., srcn, dst1, ..., dstn, opt1, ..., optn);
try {
throw std::exception();
} catch(std::exception& e) {
mexErrMsgTxt(e.what());
} catch(...) {
mexErrMsgTxt("Incorrect exception caught!");
}
}
%setup the tests
opencv_tests = OpenCVTest();
%run the tests
result = run(opencv_tests);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment