Commit 0c726a3f authored by hbristow's avatar hbristow

Improved exception handling and unit tests

parent bbece095
......@@ -27,6 +27,16 @@ std::vector<Bridge> {{function.name}}({{clss.name}}& inst, const std::vector<Bri
// setup
// invoke
try {
// invoke
} catch(cv::Exception& e) {
mexErrMsgTxt(std::string("cv::exception caught: ").append(e.what()).c_str());
} catch(std::exception& e) {
mexErrMsgTxt(std::string("std::exception caught: ").append(e.what()).c_str());
} catch(...) {
mexErrMsgTxt("Uncaught exception occurred in {{fun.name}}");
}
// setdown
}
......
......@@ -11,6 +11,7 @@
#include "bridge.hpp"
#include <string>
#include <vector>
#include <exception>
#include <opencv2/core.hpp>
{% block includes %}
{% endblock %}
......@@ -42,7 +43,9 @@ void mexFunction(int nlhs, mxArray* plhs[],
try {
{{fun.name}}();
} catch(cv::Exception& e) {
mexErrMsgTxt(std::string("OpenCV exception caught: ").append(e.what()).c_str());
mexErrMsgTxt(std::string("cv::exception caught: ").append(e.what()).c_str());
} catch(std::exception& e) {
mexErrMsgTxt(std::string("std::exception caught: ").append(e.what()).c_str());
} catch(...) {
mexErrMsgTxt("Uncaught exception occurred in {{fun.name}}");
}
......
......@@ -5,7 +5,7 @@ classdef OpenCVTest < matlab.unittest.TestCase
methods(Test)
% check if the autogenerated functions can be found
function randExists(testcase)
function functionsExist(testcase)
try
cv.rand();
catch
......@@ -13,5 +13,33 @@ classdef OpenCVTest < matlab.unittest.TestCase
end
testcase.verifyTrue(true);
end
% check that std exception is thrown
function stdException(testcase)
try
std_exception();
testcase.verifyFail();
catch
% TODO: Catch more specific exception
testcase.verifyTrue(true);
end
end
% check that OpenCV exceptions are correctly caught
function cvException(testcase)
testcase.verifyFail();
end
% check that all exceptions are caught
function allException(testcase)
try
exception();
testcase.verifyFail();
catch
% TODO: Catch more specific exception
testcase.verifyTrue(true);
end
end
end
end
......@@ -3,3 +3,6 @@ opencv_tests = OpenCVTest();
%run the tests
result = run(opencv_tests);
% shutdown
exit();
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