Skip to content
Snippets Groups Projects
Commit 0e1ec5a6 authored by Daniel Hornung's avatar Daniel Hornung
Browse files

FIX: Updated for libcaosdb changes and more.

- scalar matrix convenience functions
- style changes
parent 855d1ed6
No related branches found
No related tags found
1 merge request!1Initial functionality
Pipeline #11188 failed
......@@ -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
......@@ -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
......
......@@ -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
......
% 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
......@@ -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.
......
......@@ -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;
......
......@@ -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;
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment