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

STY: Style fixes.

parent 7ca28765
No related branches found
No related tags found
1 merge request!2ENH: Retrieving single entities works on the mex side.
Pipeline #11774 failed
${BUILD_DIR}/inst/caosdb.mex
caosdb.m
#!/bin/bash
set -e
# See https://octave.org/doc/interpreter/Creating-Packages.html
echo "Octave CaosDB SRC_DIR: $PWD"
......@@ -10,6 +12,8 @@ echo "Octave CaosDB INST_DIR: $INST_DIR"
rm -r "${INST_DIR}" || true
mkdir -p "${INST_DIR}"
mkdir -p "${INST_DIR}/private"
cp *.m "${INST_DIR}"
cp private/*.m "${INST_DIR}/private"
BUILD_DIR="$(realpath ../build)"
echo "Octave CaosDB BUILD_DIR: $BUILD_DIR"
......
......@@ -104,8 +104,8 @@ template <class T> auto mxScalarFromStringValue(const T &entity) -> mxArray * {
if (boost::to_upper_copy(value) != "FALSE") {
mxAssert(boost::to_upper_copy(value) == "FALSE",
std::string("Value >") + value + "< is neither FALSE nor TRUE.");
throw std::invalid_argument(std::string("Value >") + value
+ "< is neither FALSE nor TRUE.");
throw std::invalid_argument(std::string("Value >") + value +
"< is neither FALSE nor TRUE.");
}
result = mxScalarLOGICAL(0);
}
......@@ -138,7 +138,7 @@ template <class T> auto mxScalarFromStringValue(const T &entity) -> mxArray * {
*
* @return The std::string.
*/
auto mxGetStdString(const mxArray * array) -> std::string;
auto mxGetStdString(const mxArray *array) -> std::string;
// Exception and error handling ///////////////////////////////////////////////
......
......@@ -40,8 +40,7 @@ namespace maoxdb {
///////////////////////////////////////////////////////////////////////////////
// Helper implementation ...
template<typename T>
void test_value_impl(const mxArray * mxValue, const T &value) {
template <typename T> void test_value_impl(const mxArray *mxValue, const T &value) {
EXPECT_EQ(mxGetNumberOfElements(mxValue), 1);
if (value != value) { // equality test does not make sense for NaN
EXPECT_NE(*((T *)mxGetData(mxValue)), *((T *)mxGetData(mxValue)));
......@@ -50,21 +49,19 @@ void test_value_impl(const mxArray * mxValue, const T &value) {
}
}
// ... and specializations.
template<> // string
void test_value_impl(const mxArray * mxValue, const string &value) {
template <> // string
void test_value_impl(const mxArray *mxValue, const string &value) {
EXPECT_EQ(mxGetNumberOfElements(mxValue), value.size());
EXPECT_EQ(mxGetStdString(mxValue), value);
}
/**
* Can be instantiated for e.g. Entity and Property.
*
* This expects T to be either "scalar" types, or std::string.
*/
template<typename EntType, typename T>
void test_type_value(const string &datatype,
const std::vector<T> &values,
template <typename EntType, typename T>
void test_type_value(const string &datatype, const std::vector<T> &values,
const std::vector<string> &validStrings,
const std::vector<string> &invalidStrings,
const std::vector<string> &expectedErrors) {
......@@ -88,22 +85,18 @@ void test_type_value(const string &datatype,
valueEntity.SetValue(invalidString);
auto mxValue = mxScalarFromStringValue(valueEntity);
ADD_FAILURE() << "Expected error for value '" << invalidString << "'.";
}
catch(std::exception const & err) {
EXPECT_EQ(err.what(), expectedError);
}
catch(...) {
ADD_FAILURE() << "Expected std::exception for value '" << invalidString << "'.";
} catch (std::exception const &err) {
EXPECT_EQ(err.what(), expectedError);
} catch (...) {
ADD_FAILURE() << "Expected std::exception for value '" << invalidString << "'.";
}
}
}
/**
* Generate a vector with useful values for testing.
*/
template <typename T>
auto generateValues() -> std::vector<T> {
template <typename T> auto generateValues() -> std::vector<T> {
std::vector<T> values = {
0,
1,
......@@ -118,9 +111,8 @@ auto generateValues() -> std::vector<T> {
/**
* Convenience wrapper around std::to_chars
*/
template <typename T>
auto toStr(T value) -> std::string {
char* chars = reinterpret_cast<char*>(std::malloc(50 * sizeof(char)));
template <typename T> auto toStr(T value) -> std::string {
char *chars = reinterpret_cast<char *>(std::malloc(50 * sizeof(char)));
std::to_chars(chars, chars + 50, value);
auto result = string(chars);
std::free(chars);
......@@ -128,8 +120,7 @@ auto toStr(T value) -> std::string {
}
// to_chars is not widely supported for floats yet.
template <>
auto toStr(double value) -> std::string {
template <> auto toStr(double value) -> std::string {
auto result = boost::lexical_cast<std::string>(value);
return result;
}
......@@ -146,8 +137,8 @@ TEST(caosdb_conversion, value_TEXT) {
auto validStrings = std::vector<string>(values);
auto invalidStrings = std::vector<string>();
auto expectedErrors = std::vector<string>();
for (auto datatype: std::vector<string>{"TEXT", "REFERENCE", "DATETIME", "custom name"}) {
test_type_value<caosdb::entity::Entity, string>(datatype, values, validStrings,
for (auto datatype : std::vector<string>{"TEXT", "REFERENCE", "DATETIME", "custom name"}) {
test_type_value<caosdb::entity::Entity, string>(datatype, values, validStrings, // NOSTYLE
invalidStrings, expectedErrors);
test_type_value<caosdb::entity::Property, string>(datatype, values, validStrings,
invalidStrings, expectedErrors);
......@@ -161,9 +152,9 @@ TEST(caosdb_conversion, value_BOOLEAN) {
auto expectedErrors = std::vector<string>{"Value >no< is neither FALSE nor TRUE.",
"Value >yes< is neither FALSE nor TRUE.",
"Value >MAYBE< is neither FALSE nor TRUE."};
test_type_value<caosdb::entity::Entity, bool>("BOOLEAN", values, validStrings,
test_type_value<caosdb::entity::Entity, bool>("BOOLEAN", values, validStrings, // NOSTYLE
invalidStrings, expectedErrors);
test_type_value<caosdb::entity::Property, bool>("BOOLEAN", values, validStrings,
test_type_value<caosdb::entity::Property, bool>("BOOLEAN", values, validStrings, // NOSTYLE
invalidStrings, expectedErrors);
}
......@@ -171,13 +162,13 @@ TEST(caosdb_conversion, value_INTEGER) {
auto values = generateValues<long>();
auto validStrings = std::vector<string>(values.size());
std::transform(values.begin(), values.end(), validStrings.begin(),
[](long value) -> string {return std::to_string(value);});
[](long value) -> string { return std::to_string(value); });
auto invalidStrings = std::vector<string>{"NaN", "zero", "many"};
auto expectedErrors = std::vector<string>{"stol", "stol", "stol"};
test_type_value<caosdb::entity::Entity, long>("INTEGER", values, validStrings,
invalidStrings, expectedErrors);
test_type_value<caosdb::entity::Property, long>("INTEGER", values, validStrings,
test_type_value<caosdb::entity::Entity, long>("INTEGER", values, validStrings, // NOSTYLE
invalidStrings, expectedErrors);
test_type_value<caosdb::entity::Property, long>("INTEGER", values, validStrings, // NOSTYLE
invalidStrings, expectedErrors);
}
TEST(caosdb_conversion, value_DOUBLE) {
......@@ -187,16 +178,16 @@ TEST(caosdb_conversion, value_DOUBLE) {
values.push_back(-std::numeric_limits<double>::infinity());
auto validStrings = std::vector<string>(values.size());
std::transform(values.begin(), values.end(), validStrings.begin(),
[](double value) -> string {return toStr<double>(value);});
[](double value) -> string { return toStr<double>(value); });
// for (size_t i = 0; i < values.size(); ++i) {
// std::cout << values[i] << " -> " << validStrings[i] << std::endl;
// }
auto invalidStrings = std::vector<string>{"dunno", "zero", "many"};
auto expectedErrors = std::vector<string>{"stod", "stod", "stod"};
test_type_value<caosdb::entity::Entity, double>("DOUBLE", values, validStrings,
invalidStrings, expectedErrors);
test_type_value<caosdb::entity::Property, double>("DOUBLE", values, validStrings,
test_type_value<caosdb::entity::Entity, double>("DOUBLE", values, validStrings, // NOSTYLE
invalidStrings, expectedErrors);
test_type_value<caosdb::entity::Property, double>("DOUBLE", values, validStrings, // NOSTYLE
invalidStrings, expectedErrors);
}
/*
......
......@@ -114,9 +114,7 @@ TEST(utilities, scalar_arrays) {
}
}
TEST(utilities, empty_array) {
test_scalar_empty();
}
TEST(utilities, empty_array) { test_scalar_empty(); }
/**
* Test exception handling
......
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