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

STY: Linting.

parent c19c78af
No related branches found
No related tags found
1 merge request!2ENH: Retrieving single entities works on the mex side.
Pipeline #11673 passed with warnings
Pipeline: caosdb-octaveinttest

#11674

    ......@@ -80,10 +80,10 @@ classdef Caosdb < handle
    % id: string
    % The ID of the entity to be retrieved.
    function collection = retrieve(obj, id)
    assert(ischar(id),
    "maox:InvalidArgument",
    "ID must be a string, was:\n%s",
    disp(id))
    assert(ischar(id), ...
    "maox:InvalidArgument", ...
    "ID must be a string, was:\n%s", ...
    disp(id));
    disp(["ID (oct): >", id, "<"]);
    try
    collection = maox_retrieve(obj.connection, id);
    ......@@ -95,5 +95,6 @@ classdef Caosdb < handle
    rethrow(lasterror());
    end
    end
    end
    end
    ......@@ -43,8 +43,7 @@ auto mxFromCaosDBMessages(const caosdb::entity::Messages &messages) -> mxArray *
    /**
    * Generate a mex error message from a TransactionStatus.
    */
    auto transactionStatusToMessage(
    const caosdb::transaction::Transaction *const trans)
    auto transactionStatusToMessage(const caosdb::transaction::Transaction *const trans)
    -> std::pair<string, string> {
    auto status = trans->GetStatus();
    auto code = status.GetCode();
    ......@@ -59,8 +58,7 @@ auto transactionStatusToMessage(
    /**
    * Throw an Octave error if the transaction did not finish properly.
    */
    void throwOctExceptionIfError(
    const caosdb::transaction::Transaction *const trans) {
    void throwOctExceptionIfError(const caosdb::transaction::Transaction *const trans) {
    auto msg = maoxdb::transactionStatusToMessage(trans);
    if (msg.first != "") {
    mexErrMsgIdAndTxt(msg.first.c_str(), msg.second.c_str());
    ......@@ -70,12 +68,10 @@ void throwOctExceptionIfError(
    /**
    * Extract useful strings from an Exception: ID and description.
    */
    auto exceptionToMessage(const caosdb::exceptions::Exception &exc)
    -> std::pair<string, string> {
    auto exceptionToMessage(const caosdb::exceptions::Exception &exc) -> std::pair<string, string> {
    string id = std::to_string(exc.GetCode());
    string text =
    caosdb::get_status_description(exc.GetCode()) + "\n" + exc.what();
    string text = caosdb::get_status_description(exc.GetCode()) + "\n" + exc.what();
    return std::pair<string, string>(id, text);
    }
    ......@@ -93,8 +89,7 @@ void throwOctException(const caosdb::exceptions::Exception &exc) {
    /**
    * @brief Convert a ResultSet to a struct mexArray.
    */
    auto mxFromResultSet(const caosdb::transaction::ResultSet &resultSet)
    -> mxArray * {
    auto mxFromResultSet(const caosdb::transaction::ResultSet &resultSet) -> mxArray * {
    auto resSize = resultSet.Size();
    std::array<mwSize, 2> dims = {1, resSize};
    std::vector<const mxArray *> entities;
    ......@@ -112,6 +107,7 @@ auto mxFromResultSet(const caosdb::transaction::ResultSet &resultSet)
    * @brief Convert an Entity from libcaosdb to Octave struct mexArray.
    */
    auto mxFromCaosDBEntity(const caosdb::entity::Entity &entity) -> mxArray * {
    // clang-format off
    auto fields = std::vector<const char*>
    {"role",
    "id",
    ......@@ -127,6 +123,7 @@ auto mxFromCaosDBEntity(const caosdb::entity::Entity &entity) -> mxArray * {
    "warnings",
    "infos"
    };
    // clang-format on
    std::array<mwSize, 2> dims = {1, (mwSize)fields.size()};
    auto *result = mxCreateStructArray(2, dims.data(), fields.size(), fields.data());
    // Fill with scalar values
    ......@@ -149,17 +146,18 @@ auto mxFromCaosDBEntity(const caosdb::entity::Entity &entity) -> mxArray * {
    mxSetField(result, 0, "warnings", mxFromCaosDBMessages(entity.GetWarnings()));
    mxSetField(result, 0, "infos", mxFromCaosDBMessages(entity.GetInfos()));
    return result;
    }
    // Parents to struct array
    auto mxFromCaosDBParents(const caosdb::entity::Parents &parents) -> mxArray * {
    // clang-format off
    std::vector<const char*> fields =
    {"id",
    "name",
    "description"
    };
    // clang-format on
    std::array<mwSize, 2> fieldDims = {1, (mwSize)fields.size()};
    std::array<mwSize, 2> dims = {1, (mwSize)parents.Size()};
    auto *result = mxCreateStructArray(2, dims.data(), fields.size(), fields.data());
    ......@@ -168,13 +166,15 @@ auto mxFromCaosDBParents(const caosdb::entity::Parents &parents) -> mxArray * {
    mxSetField(result, i, "id", mxCreateString(parent.GetId().c_str()));
    mxSetField(result, i, "name", mxCreateString(parent.GetName().c_str()));
    // FIXME Add again once upstream is ready.
    // mxSetField(result, i, "description", mxCreateString(parent.GetDescription().c_str()));
    // mxSetField(result, i, "description",
    // mxCreateString(parent.GetDescription().c_str()));
    }
    return result;
    }
    // Properties to struct array
    auto mxFromCaosDBProperties(const caosdb::entity::Properties &properties) -> mxArray * {
    // clang-format off
    std::vector<const char*> fields =
    {"id",
    "name",
    ......@@ -184,6 +184,7 @@ auto mxFromCaosDBProperties(const caosdb::entity::Properties &properties) -> mxA
    "unit",
    "datatype"
    };
    // clang-format on
    std::array<mwSize, 2> fieldDims = {1, (mwSize)fields.size()};
    std::array<mwSize, 2> dims = {1, (mwSize)properties.Size()};
    auto *result = mxCreateStructArray(2, dims.data(), fields.size(), fields.data());
    ......@@ -203,9 +204,9 @@ auto mxFromCaosDBProperties(const caosdb::entity::Properties &properties) -> mxA
    // Messages to struct array
    auto mxFromCaosDBMessages(const caosdb::entity::Messages &messages) -> mxArray * {
    std::vector<const char*> fields =
    {"code",
    "description"
    std::vector<const char *> fields = {
    "code", //
    "description" //
    };
    std::array<mwSize, 2> fieldDims = {1, (mwSize)fields.size()};
    std::array<mwSize, 2> dims = {1, (mwSize)messages.Size()};
    ......
    ......@@ -14,10 +14,11 @@
    *
    * \b{Data exchange}
    *
    * Exchanging data between the Octave side wrapper and this C++ library is done via Octave struct
    * arrays, each struct corresponds to one CaosDB Entity.
    * Exchanging data between the Octave side wrapper and this C++ library is done
    * via Octave struct arrays, each struct corresponds to one CaosDB Entity.
    *
    * The Entity structs have the following structure (not all keys may exist for all roles):
    * The Entity structs have the following structure (not all keys may exist for
    * all roles):
    *
    * - role: One of "RecordType", "Record", "Property"
    * - id
    ......@@ -49,7 +50,6 @@
    // Macros /////////////////////////////////////////////////////////////////////
    // Utility functions //////////////////////////////////////////////////////////
    namespace maoxdb {
    ......@@ -84,10 +84,10 @@ inline auto mxEmptyDOUBLE() -> mxArray * {
    /**
    * @brief Convert the string-typed value in an Entity-like object to a mxArray.
    *
    * @details For the existing datatypes, see https://docs.indiscale.com/caosdb-server/specification/Datatype.html
    * @details For the existing datatypes, see
    * https://docs.indiscale.com/caosdb-server/specification/Datatype.html
    */
    template <class T>
    auto mxScalarFromStringValue(const T& entity) -> mxArray * {
    template <class T> auto mxScalarFromStringValue(const T &entity) -> mxArray * {
    mxArray *result;
    auto dt = entity.GetDatatype();
    auto value = entity.GetValue();
    ......@@ -129,8 +129,8 @@ auto mxScalarFromStringValue(const T& entity) -> mxArray * {
    /**
    * @brief Generate a mex error message from a TransactionStatus.
    *
    * @details Preprocess the transaction status of a transaction, to create the necessary
    * information for raising an Octave error.
    * @details Preprocess the transaction status of a transaction, to create the
    * necessary information for raising an Octave error.
    *
    * @param trans
    * The transaction of which to handle the status.
    ......@@ -139,14 +139,14 @@ auto mxScalarFromStringValue(const T& entity) -> mxArray * {
    * The message ID and description of any error. If the transaction status is
    * SUCCESS, or some kind of "still running", both strings are empty.
    */
    auto
    transactionStatusToMessage(const caosdb::transaction::Transaction *const trans)
    auto transactionStatusToMessage(const caosdb::transaction::Transaction *const trans)
    -> std::pair<string, string>;
    /**
    * @brief Throw an Octave error if the transaction did not finish properly.
    *
    * @details On error, this function will leave this C++ context and fall back to Octave.
    * @details On error, this function will leave this C++ context and fall back to
    * Octave.
    *
    * @param trans
    * The transaction to check.
    ......@@ -168,8 +168,7 @@ void throwOctExceptionIfError(const caosdb::transaction::Transaction *const tran
    * @note Additional utility functions should be easy to implement when the
    * libcaosdb error handling changes.
    */
    auto
    exceptionToMessage(const caosdb::exceptions::Exception &exc) -> std::pair<string, string>;
    auto exceptionToMessage(const caosdb::exceptions::Exception &exc) -> std::pair<string, string>;
    /**
    * @brief Throw a CaosDB Exception inside Octave.
    ......@@ -184,7 +183,6 @@ exceptionToMessage(const caosdb::exceptions::Exception &exc) -> std::pair<string
    */
    void throwOctException(const caosdb::exceptions::Exception &exc);
    // Entity handling ////////////////////////////////////////////////////////////
    /**
    ......@@ -197,7 +195,8 @@ auto mxFromResultSet(const caosdb::transaction::ResultSet &resultSet) -> mxArray
    /**
    * @brief Convert an Entity from libcaosdb to Octave struct mexArray.
    *
    * @return A 1x1 struct array whose entry follows the maoxdb Entity convention outlined above.
    * @return A 1x1 struct array whose entry follows the maoxdb Entity convention
    * outlined above.
    */
    auto mxFromCaosDBEntity(const caosdb::entity::Entity &entity) -> mxArray *;
    ......@@ -206,7 +205,8 @@ auto mxFromCaosDBEntity(const caosdb::entity::Entity &entity) -> mxArray *;
    /**
    * @brief Merges a number of scalar mex structs into a 1xN struct.
    *
    * @details The content (the mxArrays behind the input structs values) is duplicated.
    * @details The content (the mxArrays behind the input structs values) is
    * duplicated.
    *
    * @param structs: Must all have the same fields.
    *
    ......
    ......@@ -17,12 +17,11 @@ void print_usage() {
    mexPrintf(" --help Print this help and return.\n");
    mexPrintf(" --version Print the version of OctaveCaosDB and "
    "libcaosdb and return.\n");
    mexPrintf(
    " --test-connection Test the default connection and return.\n");
    mexPrintf(" --test-connection Test the default connection and return.\n");
    };
    const std::string FULL_VERSION = std::string(
    "v0.1 (libcaosdb v" + std::to_string(caosdb::LIBCAOSDB_VERSION_MAJOR) + "." +
    const std::string FULL_VERSION =
    std::string("v0.1 (libcaosdb v" + std::to_string(caosdb::LIBCAOSDB_VERSION_MAJOR) + "." +
    std::to_string(caosdb::LIBCAOSDB_VERSION_MINOR) + "." +
    std::to_string(caosdb::LIBCAOSDB_VERSION_PATCH) + ")");
    ......@@ -33,17 +32,14 @@ auto print_version() -> const char * {
    };
    void test_connection() {
    const auto &connection =
    caosdb::connection::ConnectionManager::GetDefaultConnection();
    const auto &connection = caosdb::connection::ConnectionManager::GetDefaultConnection();
    const auto &version_info = connection->GetVersionInfo();
    mexPrintf("Server Version: v%d.%d.%d-%s-%s\n", version_info->GetMajor(),
    version_info->GetMinor(), version_info->GetPatch(),
    version_info->GetPreRelease().c_str(),
    mexPrintf("Server Version: v%d.%d.%d-%s-%s\n", version_info->GetMajor(), version_info->GetMinor(),
    version_info->GetPatch(), version_info->GetPreRelease().c_str(),
    version_info->GetBuild().c_str());
    }
    void mexFunction(int /*nlhs*/, mxArray *plhs[], int nrhs,
    const mxArray *prhs[]) {
    void mexFunction(int /*nlhs*/, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
    if (nrhs == 1) {
    auto const *first_arg = mxArrayToString(prhs[0]);
    ......
    ......@@ -30,16 +30,11 @@ auto info(string const &connection_name) -> mxArray * {
    std::array<mwSize, 2> dims = {1, 1};
    mxArray *info_struct = mxCreateStructArray(2, dims.data(), 5, keys); // NOLINT
    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()));
    mxSetField(info_struct, 0, "build",
    mxCreateString(version_info.GetBuild().c_str()));
    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()));
    mxSetField(info_struct, 0, "build", mxCreateString(version_info.GetBuild().c_str()));
    return info_struct;
    }
    ......@@ -53,8 +48,7 @@ auto info(string const &connection_name) -> mxArray * {
    *
    * @return return type
    */
    void mexFunction(int /*nlhs*/, mxArray *plhs[], int nrhs,
    const mxArray *prhs[]) {
    void mexFunction(int /*nlhs*/, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
    string conn_name;
    if (nrhs >= 1 && mxGetNumberOfElements(prhs[0]) > 0) {
    ......
    ......@@ -32,16 +32,11 @@ auto info(string const &connection_name) -> mxArray * {
    std::array<mwSize, 2> dims = {1, 1};
    mxArray *info_struct = mxCreateStructArray(2, dims.data(), 5, keys); // NOLINT
    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()));
    mxSetField(info_struct, 0, "build",
    mxCreateString(version_info.GetBuild().c_str()));
    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()));
    mxSetField(info_struct, 0, "build", mxCreateString(version_info.GetBuild().c_str()));
    return info_struct;
    }
    ......@@ -57,15 +52,13 @@ auto info(string const &connection_name) -> mxArray * {
    *
    * @return collection A struct with the entities.
    */
    void mexFunction(int /*nlhs*/, mxArray *plhs[], int nrhs,
    const mxArray *prhs[]) {
    void mexFunction(int /*nlhs*/, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
    string conn_name;
    std::vector<string> ids;
    try {
    if (nrhs < 2) {
    mexErrMsgIdAndTxt(
    "maox:InsufficientArguments",
    mexErrMsgIdAndTxt("maox:InsufficientArguments",
    "Need at least 2 arguments: connection_name and 1 or more IDs");
    }
    if (mxGetNumberOfElements(prhs[0]) > 0) {
    ......@@ -77,8 +70,7 @@ void mexFunction(int /*nlhs*/, mxArray *plhs[], int nrhs,
    ids.emplace_back(mxArrayToString(prhs[i]));
    }
    } catch (...) {
    mexErrMsgIdAndTxt("maox:ArgumentHandling",
    "Error while handling the arguments.");
    mexErrMsgIdAndTxt("maox:ArgumentHandling", "Error while handling the arguments.");
    }
    auto n_ids = ids.size();
    ......
    ......@@ -19,5 +19,5 @@
    pkg load caosdb;
    test_result = moxunit_runtests("-verbose", "test_unittest.m");
    if not(test_result)
    exit(1)
    exit(1);
    end
    ......@@ -28,7 +28,7 @@ end
    function test_local()
    % default connection
    c1 = Caosdb();
    assertEqual(c1.connection, "")
    assertEqual(c1.connection, "");
    % class with explicit connection
    c2 = Caosdb("local-caosdb-admin");
    assertEqual(c2.connection, "local-caosdb-admin");
    ......
    ......@@ -67,10 +67,10 @@ void test_scalar_logical(bool value) {
    /**
    * Generate a vector with useful values for testing.
    */
    template<typename T>
    auto values() -> std::vector<T> {
    std::vector<T> values =
    {0, 1,
    template <typename T> auto values() -> std::vector<T> {
    std::vector<T> values = {
    0,
    1,
    std::numeric_limits<T>::max(),
    std::numeric_limits<T>::min(),
    std::numeric_limits<T>::lowest(),
    ......@@ -116,10 +116,9 @@ TEST(test_utilities, exception_handling) {
    caosdb::exceptions::AuthenticationError exc("Authentication failed.");
    auto strings = exceptionToMessage(exc);
    EXPECT_EQ(strings.first, std::string("16"));
    EXPECT_EQ(strings.second,
    std::string("The attempt to execute this transaction has not been "
    EXPECT_EQ(strings.second, std::string("The attempt to execute this transaction has not been "
    "executed at all because the authentication did not "
    "succeed.\nAuthentication failed."));
    }
    } // maoxdb
    } // namespace maoxdb
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment