summaryrefslogtreecommitdiffstats
path: root/Tests/FindMatlab/matlab_wrapper3.cpp
diff options
context:
space:
mode:
authorCris Luengo <cris.l.luengo@gmail.com>2018-10-22 08:19:04 (GMT)
committerCris Luengo <cris.l.luengo@gmail.com>2018-10-24 06:09:06 (GMT)
commit160499296c61b0edf2e6b08c44b31444e022528f (patch)
tree416376babb083f6b3aeeff3831e4111264be4071 /Tests/FindMatlab/matlab_wrapper3.cpp
parentee7e97a7d35a793985cf6f9aa185069460cf0ec6 (diff)
downloadCMake-160499296c61b0edf2e6b08c44b31444e022528f.zip
CMake-160499296c61b0edf2e6b08c44b31444e022528f.tar.gz
CMake-160499296c61b0edf2e6b08c44b31444e022528f.tar.bz2
FindMatlab: added unit tests for new functionality.
Also allowing a way to select which of multiple installed MATLAB versions to use in the test.
Diffstat (limited to 'Tests/FindMatlab/matlab_wrapper3.cpp')
-rw-r--r--Tests/FindMatlab/matlab_wrapper3.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/Tests/FindMatlab/matlab_wrapper3.cpp b/Tests/FindMatlab/matlab_wrapper3.cpp
new file mode 100644
index 0000000..6670815
--- /dev/null
+++ b/Tests/FindMatlab/matlab_wrapper3.cpp
@@ -0,0 +1,29 @@
+#include "mex.hpp"
+#include "mexAdapter.hpp"
+
+// This test uses the new C++ API (R2018a and newer)
+
+// The input should be a scalar double array. The output is a copy of that
+// array.
+
+using namespace matlab::data;
+using matlab::mex::ArgumentList;
+
+class MexFunction : public matlab::mex::Function
+{
+public:
+ void operator()(ArgumentList outputs, ArgumentList inputs)
+ {
+ std::shared_ptr<matlab::engine::MATLABEngine> matlabPtr = getEngine();
+ ArrayFactory factory;
+ if (inputs[0].getType() != ArrayType::DOUBLE ||
+ inputs[0].getType() == ArrayType::COMPLEX_DOUBLE ||
+ inputs[0].getNumberOfElements() != 1) {
+ matlabPtr->feval(
+ u"error", 0,
+ std::vector<Array>({ factory.createScalar("Incorrect arguments") }));
+ }
+ double a = inputs[0][0];
+ outputs[0] = factory.createScalar(a);
+ }
+};