diff --git a/.miss_hit b/.miss_hit index 025b96a2a7564bc4ee528971fd7c4ad201a2e3d1..f15ccfe29ff4a2e193fb4ae51ca5a7bd1cc3a88d 100644 --- a/.miss_hit +++ b/.miss_hit @@ -2,6 +2,6 @@ # See https://florianschanda.github.io/miss_hit/style_checker.html line_length: 100 -# regex_function_name: "[a-z]+(_[a-z]+)*" +regex_function_name: "[a-z]+(_[a-z]+)*" suppress_rule: "whitespace_comments" tab_width: 2 diff --git a/Makefile b/Makefile index 431bc7b2935ce3a4959ad135c38fb6298f88f8e7..0fe4b3ee03ae431914366609b3e9ab48c198c9af 100644 --- a/Makefile +++ b/Makefile @@ -34,11 +34,12 @@ doc: cd doc && $(MAKE) html style: - mh_style --fix --octave src doc + mh_style --octave src doc test clang-format-11 --dry-run --verbose --Werror $(shell find test/ src/ -type f -iname "*.cpp" -o -iname "*.hpp" -o -iname "*.h" -o -iname "*.h.in") .PHONY: style style_fix: + mh_style --fix --octave src doc test clang-format-11 -i --verbose --Werror $(shell find test/ src/ -type f -iname "*.cpp" -o -iname "*.hpp" -o -iname "*.h" -o -iname "*.h.in") .PHONY: style_fix diff --git a/README_SETUP.md b/README_SETUP.md index 8d00d43f1ef616b48fd906437f88acade005851c..32c9d1a8b038085056248fca7d50d3d4874d58a9 100644 --- a/README_SETUP.md +++ b/README_SETUP.md @@ -22,11 +22,13 @@ This package requires the following software: ## Run Unit Tests -We use the standard test framework of octave. +We use the standard test framework of Octave. -See [this articel](https://wiki.octave.org/Tests) for a primer and use +See [this article](https://wiki.octave.org/Tests) for a primer and use [this](https://octave.org/doc/interpreter/Test-Functions.html) as a reference. +Additionally we use the [MOxUnit](https://github.com/MOxUnit/MOxUnit) framework. + ## Code Formatting Code formatting is done with the diff --git a/src/caosdb_exec.m b/src/caosdb_exec.m new file mode 100644 index 0000000000000000000000000000000000000000..3bcf273b0ff908ff1197ec0e1b40223e726dfd5e --- /dev/null +++ b/src/caosdb_exec.m @@ -0,0 +1,29 @@ +% This file is a part of the CaosDB Project. +% +% Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> +% Copyright (C) 2021 Daniel Hornung <d.hornung@indiscale.com> +% +% This program is free software: you can redistribute it and/or modify +% it under the terms of the GNU Affero General Public License as +% published by the Free Software Foundation, either version 3 of the +% License, or (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU Affero General Public License for more details. +% +% You should have received a copy of the GNU Affero General Public License +% along with this program. If not, see <https://www.gnu.org/licenses/>. + +% -*- texinfo -*- +% @deftypefn {Function File} {@var{out} =} caosdb_exec (arg) +% @cindex index term +% Calls the equivalkent of the @code{caosdb} command line interface executable. Mostly, this can +% output the version of libcaosdb. +% +% Typical arguments are @code{"--version"} or @code{"--test-connection"}. +% @end deftypefn +function out = caosdb_exec(arg) + out = maox_caosdb(arg); +end diff --git a/src/lib/maoxdb.hpp b/src/lib/maoxdb.hpp index 46ff817090dcd6353d2ecdf93bc09a7948e8af21..6d443fa857d140485c2e81d9dd272eac0fa9271d 100644 --- a/src/lib/maoxdb.hpp +++ b/src/lib/maoxdb.hpp @@ -36,8 +36,28 @@ namespace maoxdb { using std::string; -// doxy -void test(); + +template <typename T> auto mxScalar(T value, mxClassID class_id) -> mxArray * { + mxArray *array = mxCreateNumericMatrix(1, 1, class_id, mxREAL); + auto *data = (T *)mxGetData(array); + data[0] = value; + return array; +} + +// Convenience shortcut functions + +inline auto mxScalarUINT64(UINT64_T value) -> mxArray * { + return mxScalar<UINT64_T>(value, mxUINT64_CLASS); +} +inline auto mxScalarINT64(INT64_T value) -> mxArray * { + return mxScalar<UINT64_T>(value, mxUINT64_CLASS); +} +inline auto mxScalarDOUBLE(double value) -> mxArray * { + return mxScalar<double>(value, mxDOUBLE_CLASS); +} +inline auto mxScalarLOGICAL(bool value) -> mxArray * { + return mxScalar<UINT8_T>(value, mxLOGICAL_CLASS); +} /** * @brief Handle a CaosDB Exception and transform into error code and message. diff --git a/src/private/maox_info.cpp b/src/private/maox_info.cpp index 9009e3d194c7ef6d52b0003c552e5a49b8d0589c..e268da828e7be000db9dfdf161641d2cf6ab726e 100644 --- a/src/private/maox_info.cpp +++ b/src/private/maox_info.cpp @@ -2,12 +2,12 @@ #include "caosdb/constants.h" // for LIBCAOSDB_VERSION_MAJOR, LIBCAOSDB_VE... #include "caosdb/exceptions.h" // for all error handling #include "caosdb/info.h" // for VersionInfo +#include "maoxdb.hpp" // caosDB utils for mex files #include "mex.h" // for mxArray, mexFunction #include "mexproto.h" // for mexPrintf, mxCreateString, mxGetChars #include <cstring> // for strcmp #include <memory> // for unique_ptr, __shared_ptr_access, shar... #include <string> // for allocator, char_traits, operator+ -#include "maoxdb.hpp" // caosDB utils for mex files using caosdb::connection::Connection; using caosdb::connection::ConnectionManager; @@ -25,22 +25,21 @@ mxArray *info(string const &connection_name) { } else { connection = ConnectionManager::GetConnection(connection_name); } - const auto &version_info = connection->GetVersionInfo(); + const auto &version_info = connection->RetrieveVersionInfo(); const char *keys[] = {"major", "minor", "patch", "pre_release", "build"}; mwSize dims[2] = {1, 1}; mxArray *info_struct = mxCreateStructArray(2, dims, 5, keys); - auto *major = mxSCALAR(UINT64, major, version_info->GetMajor()); - auto *minor = mxSCALAR(UINT64, minor, version_info->GetMinor()); - auto *patch = mxSCALAR(UINT64, patch, version_info->GetPatch()); - - mxSetField(info_struct, 0, "major", major); - mxSetField(info_struct, 0, "minor", minor); - mxSetField(info_struct, 0, "patch", patch); + mxSetField(info_struct, 0, "major", + maoxdb::mxScalarUINT64(version_info.GetMajor())); + mxSetField(info_struct, 0, "minor", + maoxdb::mxScalarUINT64(version_info.GetMinor())); + mxSetField(info_struct, 0, "patch", + maoxdb::mxScalarUINT64(version_info.GetPatch())); mxSetField(info_struct, 0, "pre_release", - mxCreateString(version_info->GetPreRelease().c_str())); + mxCreateString(version_info.GetPreRelease().c_str())); mxSetField(info_struct, 0, "build", - mxCreateString(version_info->GetBuild().c_str())); + mxCreateString(version_info.GetBuild().c_str())); return info_struct; } @@ -60,7 +59,6 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { if (nrhs >= 1 && mxGetNumberOfElements(prhs[0]) > 0) { conn_name = mxGetChars(prhs[0]); } - mexPrintf("Connection: >%s< \t %d\n", conn_name.c_str(), nrhs); try { auto info_struct = info(conn_name); plhs[0] = info_struct; diff --git a/test/Run_Test.m b/test/Run_Test.m index a1b6c1b1905e66871dc92a4aa6af06c408b6d239..374da3ca629b360779a0d404ddc6451ed6f5cc50 100644 --- a/test/Run_Test.m +++ b/test/Run_Test.m @@ -16,6 +16,5 @@ % You should have received a copy of the GNU Affero General Public License % along with this program. If not, see <https://www.gnu.org/licenses/>. -pkg install ..; pkg load caosdb; -moxunit_runtests -verbose test_caosdb.m +moxunit_runtests -verbose test_caosdb.m; diff --git a/test/test_caosdb.m b/test/test_caosdb.m index 27928c7a4d85e930c1c9552049401447620c5094..057b5c1aaa97561efb3b832d30ab7b804cebbf1f 100644 --- a/test/test_caosdb.m +++ b/test/test_caosdb.m @@ -1,10 +1,30 @@ -function test_suite=test_caosdb - try % assignment of 'localfunctions' is necessary in Matlab >= 2016 - test_functions=localfunctions(); - catch % no problem; early Matlab versions can use initTestSuite fine - end - initTestSuite; +% This file is a part of the CaosDB Project. +% +% Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> +% Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> +% +% This program is free software: you can redistribute it and/or modify +% it under the terms of the GNU Affero General Public License as +% published by the Free Software Foundation, either version 3 of the +% License, or (at your option) any later version. +% +% This program is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU Affero General Public License for more details. +% +% You should have received a copy of the GNU Affero General Public License +% along with this program. If not, see <https://www.gnu.org/licenses/>. + +function test_suite = test_caosdb + try % assignment of 'localfunctions' is necessary in Matlab >= 2016 + test_functions = localfunctions(); + catch % no problem; early Matlab versions can use initTestSuite fine + end + initTestSuite; +end function test_print_version - v = caosdb("--version") - assertEqual(v, "v0.1 (libcaosdb v0.0.6)") + v = caosdb_exec("--version"); + assertEqual(v, "v0.1 (libcaosdb v0.0.6)"); +end