From 0e1ec5a6e9da2861a8a333879915899fa6c2bd8e Mon Sep 17 00:00:00 2001 From: Daniel <d.hornung@indiscale.com> Date: Tue, 3 Aug 2021 12:36:00 +0200 Subject: [PATCH] FIX: Updated for libcaosdb changes and more. - scalar matrix convenience functions - style changes --- .miss_hit | 2 +- Makefile | 3 ++- README_SETUP.md | 6 ++++-- src/caosdb_exec.m | 29 +++++++++++++++++++++++++++++ src/lib/maoxdb.hpp | 24 ++++++++++++++++++++++-- src/private/maox_info.cpp | 22 ++++++++++------------ test/Run_Test.m | 3 +-- test/test_caosdb.m | 36 ++++++++++++++++++++++++++++-------- 8 files changed, 97 insertions(+), 28 deletions(-) create mode 100644 src/caosdb_exec.m diff --git a/.miss_hit b/.miss_hit index 025b96a..f15ccfe 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 431bc7b..0fe4b3e 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 8d00d43..32c9d1a 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 0000000..3bcf273 --- /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 46ff817..6d443fa 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 9009e3d..e268da8 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 a1b6c1b..374da3c 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 27928c7..057b5c1 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 -- GitLab