Skip to content
Snippets Groups Projects
Commit e8611e5c authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

Merge branch 'f-minimum' into 'dev'

Initial functionality

See merge request !1
parents 9c84c574 d225b154
No related branches found
No related tags found
1 merge request!1Initial functionality
Pipeline #12028 passed
Pipeline: caosdb-octaveinttest

#12032

    % 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/>.
    function test_suite=test_unittest()
    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
    % Only tests which don't need a connection to a server.
    function test_local()
    % default connection
    c1 = Caosdb();
    assertEqual(c1.connection, "")
    % class with explicit connection
    c2 = Caosdb("local-caosdb-admin");
    assertEqual(c2.connection, "local-caosdb-admin");
    % TODO(daniel) Re-write s.th. version >= 0.0.6 (or whatever minimal
    % version will be valid then) is checked.
    % Only get the local versions.
    % version = caosdb_exec("--version");
    % assertEqual(version, "v0.1 (libcaosdb v0.0.7)");
    end
    /*
    * 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/>.
    */
    #include "caosdb/exceptions.h"
    #include "maoxdb.hpp"
    #include "mex.h"
    // #include "mexproto.h"
    #include <gtest/gtest.h>
    #include <limits>
    #include <string>
    #include <vector>
    namespace maoxdb {
    ///////////////////////////////////////////////////////////////////////////////
    // Helper functions //
    ///////////////////////////////////////////////////////////////////////////////
    /*
    * These functions test if the value can be converted to a mex scalar.
    */
    void test_scalar_uint64(UINT64_T value) {
    mxArray *scalar = mxScalarUINT64(value);
    EXPECT_TRUE(mxIsUint64(scalar));
    EXPECT_EQ(mxGetNumberOfElements(scalar), 1);
    EXPECT_EQ(*((UINT64_T *) mxGetData(scalar)), value);
    }
    void test_scalar_int64(INT64_T value) {
    mxArray *scalar = mxScalarINT64(value);
    EXPECT_TRUE(mxIsInt64(scalar));
    EXPECT_EQ(mxGetNumberOfElements(scalar), 1);
    EXPECT_EQ(*((INT64_T *) mxGetData(scalar)), value);
    }
    void test_scalar_double(double value) {
    mxArray *scalar = mxScalarDOUBLE(value);
    EXPECT_TRUE(mxIsDouble(scalar));
    EXPECT_EQ(mxGetNumberOfElements(scalar), 1);
    EXPECT_EQ(*((double *) mxGetData(scalar)), value);
    }
    void test_scalar_logical(bool value) {
    mxArray *scalar = mxScalarLOGICAL(value);
    EXPECT_TRUE(mxIsLogical(scalar));
    EXPECT_EQ(mxGetNumberOfElements(scalar), 1);
    EXPECT_EQ(*((bool *) mxGetData(scalar)), value);
    }
    /**
    * Generate a vector with useful values for testing.
    */
    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(),
    std::numeric_limits<T>::epsilon() // 0 for integers, but who cares?
    };
    return values;
    }
    ///////////////////////////////////////////////////////////////////////////////
    // Actual tests //
    ///////////////////////////////////////////////////////////////////////////////
    /**
    * Test if construction of scalar mex arrays works
    */
    TEST(test_utilities, scalar_arrays) {
    auto values_uint64 = values<UINT64_T>();
    for (auto value : values_uint64) {
    test_scalar_uint64(value);
    }
    auto values_int64 = values<INT64_T>();
    for (auto value : values_int64) {
    test_scalar_int64(value);
    }
    auto values_double = values<double>();
    for (auto value : values_double) {
    test_scalar_double(value);
    }
    std::vector<bool> values_logical = {true, false};
    for (auto value : values_logical) {
    test_scalar_logical(value);
    }
    }
    /**
    * Test exception handling
    */
    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 "
    "executed at all because the authentication did not "
    "succeed.\nAuthentication failed."));
    }
    } // maoxdb
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment