init
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
///-------------------------------------------------------------------------------------------------
|
||||
///
|
||||
/// \file CIdentifierTest.hpp
|
||||
/// \brief Test Definitions for OpenViBE Identifier Class.
|
||||
/// \author Thibaut Monseigne (Inria).
|
||||
/// \version 1.0.
|
||||
/// \date 23/06/2020.
|
||||
/// \copyright <a href="https://choosealicense.com/licenses/agpl-3.0/">GNU Affero General Public License v3.0</a>.
|
||||
///
|
||||
///-------------------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <openvibe/CIdentifier.hpp>
|
||||
|
||||
#include "utils.hpp"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
TEST(CIdentifier_Tests, constructors)
|
||||
{
|
||||
OpenViBE::CIdentifier id1, id2(10), id3(-1), id4(10, 10), id5("false string"), id6("(0x00000000, 0x0000000A)");
|
||||
const uint64_t undef = std::numeric_limits<uint64_t>::max();
|
||||
|
||||
EXPECT_EQ(id1.id(), undef) << ErrorMsg("Default Constructor", id1.id(), undef);
|
||||
EXPECT_EQ(id2.id(), 10) << ErrorMsg("Integer Constructor", id2.id(), 10);
|
||||
EXPECT_EQ(id3.id(), undef) << ErrorMsg("Negative value Constructor", id3.id(), undef);
|
||||
EXPECT_EQ(id4.id(), 42949672970) << ErrorMsg("Double ID Constructor", id4.id(), 42949672970); // 10 * 2^32 + 10
|
||||
EXPECT_EQ(id5.id(), undef) << ErrorMsg("False string Constructor", id5.id(), undef);
|
||||
EXPECT_EQ(id6.id(), 10) << ErrorMsg("String Constructor", id6.id(), 10);
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
TEST(CIdentifier_Tests, operators)
|
||||
{
|
||||
OpenViBE::CIdentifier id(10);
|
||||
const OpenViBE::CIdentifier id2(10);
|
||||
const uint64_t undef = std::numeric_limits<uint64_t>::max();
|
||||
|
||||
id = 0;
|
||||
EXPECT_EQ(id.id(), 0) << ErrorMsg("Assignement operator with unsigned", id.id(), 0);
|
||||
id = OpenViBE::CIdentifier::undefined();
|
||||
EXPECT_EQ(id.id(), undef) << ErrorMsg("Assignement operator with CIdentifier", id.id(), undef);
|
||||
|
||||
++id; // No change if undef
|
||||
EXPECT_EQ(id.id(), undef) << ErrorMsg("++ operator with undefined Identifier", id.id(), undef);
|
||||
--id; // No change if undef
|
||||
EXPECT_EQ(id.id(), undef) << ErrorMsg("-- operator with undefined Identifier", id.id(), undef);
|
||||
|
||||
id = 0;
|
||||
--id; // 0 became max - 1
|
||||
EXPECT_EQ(id.id(), undef - 1) << ErrorMsg("-- operator with Identifier 0", id.id(), undef - 1);
|
||||
++id; // max - 1 became 0
|
||||
EXPECT_EQ(id.id(), 0) << ErrorMsg("++ operator with Identifier 0", id.id(), undef - 1);
|
||||
|
||||
id = 0;
|
||||
EXPECT_TRUE(id<=id && id>=id && id < id2 && id2 > id) << ErrorMsg("Comparison Operator", id.id(), id2.id());
|
||||
|
||||
std::stringstream ss;
|
||||
ss << id;
|
||||
EXPECT_EQ(ss.str(), "(0x00000000, 0x00000000)") << ErrorMsg("ostream operator", ss.str(), "(0x00000000, 0x00000000)");
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
@@ -0,0 +1,18 @@
|
||||
#######################################################################
|
||||
# Software License Agreement : GNU Affero General Public License v3.0
|
||||
# https://choosealicense.com/licenses/agpl-3.0/
|
||||
#######################################################################
|
||||
|
||||
PROJECT(ov-base-test)
|
||||
|
||||
FILE(GLOB_RECURSE SRC_FILES *.cpp *.hpp)
|
||||
ADD_EXECUTABLE(${PROJECT_NAME} ${SRC_FILES})
|
||||
|
||||
SET_BUILD_PLATFORM() # Default build Platform
|
||||
INCLUDE("FindOpenViBE") # Find OpenViBE base includes and library
|
||||
INCLUDE("FindOpenViBECommon") # Find OpenViBE Common includes and library
|
||||
SET_PROPERTY(TARGET ${PROJECT_NAME} PROPERTY FOLDER ${TESTS_FOLDER}) # Place project in folder unit-test (for some IDE)
|
||||
|
||||
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${GTEST_BOTH_LIBRARIES}) # Add google Test
|
||||
|
||||
ADD_TEST(NAME base COMMAND ${PROJECT_NAME})
|
||||
@@ -0,0 +1,172 @@
|
||||
///-------------------------------------------------------------------------------------------------
|
||||
///
|
||||
/// \file CMatrixTest.hpp
|
||||
/// \brief Test Definitions for OpenViBE Matrix Class.
|
||||
/// \author Thibaut Monseigne (Inria).
|
||||
/// \version 1.0.
|
||||
/// \date 11/05/2020.
|
||||
/// \copyright <a href="https://choosealicense.com/licenses/agpl-3.0/">GNU Affero General Public License v3.0</a>.
|
||||
///
|
||||
///-------------------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <openvibe/CMatrix.hpp>
|
||||
#include "utils.hpp"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
class CMatrix_Tests : public testing::Test
|
||||
{
|
||||
protected:
|
||||
OpenViBE::CMatrix m_mat;
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
m_mat.resize(1, 2); // one row two column buffer not init
|
||||
m_mat.getBuffer()[0] = 10; // Buffer init with getBuffer and First element set
|
||||
m_mat.getBuffer()[1] = 20; // Second Element set (buffer already init so refresh function not run)
|
||||
m_mat.setDimensionLabel(0, 0, "dim0e0"); // Row label set
|
||||
m_mat.setDimensionLabel(1, 0, "dim1e0"); // Column 1 Label set
|
||||
m_mat.setDimensionLabel(1, 1, "dim1e1"); // Column 2 Label set
|
||||
}
|
||||
};
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
TEST_F(CMatrix_Tests, Constructor)
|
||||
{
|
||||
OpenViBE::CMatrix res;
|
||||
ASSERT_EQ(0, res.getSize()) << "Default constructor doesn't have a size of 0.";
|
||||
EXPECT_STREQ("", res.getDimensionLabel(0, 0)) << "Default constructor has no dimension so no label.";
|
||||
|
||||
ASSERT_EQ(2, m_mat.getSize()) << "Setup Matrix doesn't have 2 values.";
|
||||
ASSERT_EQ(2, m_mat.getDimensionCount()) << "Setup Matrix doesn't have 2 Dimensions.";
|
||||
ASSERT_EQ(1, m_mat.getDimensionSize(0)) << "Setup Matrix doesn't have 1 Row.";
|
||||
ASSERT_EQ(2, m_mat.getDimensionSize(1)) << "Setup Matrix doesn't have 2 Columns.";
|
||||
EXPECT_TRUE(AlmostEqual(10, m_mat.getBuffer()[0])) << "Setup Matrix 1st value isn't 10.";
|
||||
EXPECT_TRUE(AlmostEqual(20, m_mat.getBuffer()[1])) << "Setup Matrix 2nd value isn't 20.";
|
||||
EXPECT_STREQ("dim0e0", m_mat.getDimensionLabel(0, 0)) << "Setup Matrix Row Label isn't dim0e0.";
|
||||
EXPECT_STREQ("dim1e0", m_mat.getDimensionLabel(1, 0)) << "Setup Matrix 1st Column Label isn't dim1e0.";
|
||||
EXPECT_STREQ("dim1e1", m_mat.getDimensionLabel(1, 1)) << "Setup Matrix 2nd Column Label isn't dim1e1.";
|
||||
|
||||
EXPECT_TRUE(m_mat.isBufferValid()) << "Setup Matrix isn't valid";
|
||||
m_mat.getBuffer()[0] = std::numeric_limits<double>::infinity();
|
||||
EXPECT_FALSE(m_mat.isBufferValid()) << "infinity isn't considered as invalid";
|
||||
m_mat.getBuffer()[0] = std::numeric_limits<double>::quiet_NaN();
|
||||
EXPECT_FALSE(m_mat.isBufferValid()) << "Setup Matrix isn't valid";
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
TEST_F(CMatrix_Tests, Constructor_Copy)
|
||||
{
|
||||
OpenViBE::CMatrix res(m_mat);
|
||||
|
||||
EXPECT_TRUE(m_mat == res) << ErrorMsg("Copy Constructor", m_mat, res);
|
||||
|
||||
res.getBuffer()[0] = 15;
|
||||
res.getBuffer()[1] = 25;
|
||||
res.setDimensionLabel(1, 0, "changed");
|
||||
|
||||
EXPECT_TRUE(AlmostEqual(10, m_mat.getBuffer()[0])) << "Setup Matrix 1st value isn't 10.";
|
||||
EXPECT_TRUE(AlmostEqual(20, m_mat.getBuffer()[1])) << "Setup Matrix 2nd value isn't 20.";
|
||||
EXPECT_STREQ("dim1e0", m_mat.getDimensionLabel(1, 0)) << "Setup Matrix 1st Column Label isn't dim1e0.";
|
||||
EXPECT_TRUE(AlmostEqual(15, res.getBuffer()[0])) << "New Matrix 1st value isn't 15.";
|
||||
EXPECT_TRUE(AlmostEqual(25, res.getBuffer()[1])) << "New Matrix 2nd value isn't 25.";
|
||||
EXPECT_STREQ("changed", res.getDimensionLabel(1, 0)) << "New Matrix 1st Column Label isn't changed.";
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
TEST_F(CMatrix_Tests, Constructor_copy_in_array_push)
|
||||
{
|
||||
std::vector<OpenViBE::CMatrix> res;
|
||||
res.push_back(m_mat);
|
||||
res.push_back(m_mat);
|
||||
|
||||
res[0].getBuffer()[0] = 15;
|
||||
res[0].getBuffer()[1] = 25;
|
||||
res[0].setDimensionLabel(1, 0, "changed");
|
||||
|
||||
EXPECT_TRUE(AlmostEqual(15, res[0].getBuffer()[0])) << "1st Matrix 1st value isn't 15.";
|
||||
EXPECT_TRUE(AlmostEqual(25, res[0].getBuffer()[1])) << "1st Matrix 2nd value isn't 25.";
|
||||
EXPECT_STREQ("changed", res[0].getDimensionLabel(1, 0)) << "1st Matrix 1st Column Label isn't changed.";
|
||||
EXPECT_TRUE(AlmostEqual(10, res[1].getBuffer()[0])) << "2nd Matrix 1st value isn't 10.";
|
||||
EXPECT_TRUE(AlmostEqual(20, res[1].getBuffer()[1])) << "2nd Matrix 2nd value isn't 20.";
|
||||
EXPECT_STREQ("dim1e0", res[1].getDimensionLabel(1, 0)) << "2nd Matrix 1st Column Label isn't dim1e0.";
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
TEST_F(CMatrix_Tests, Operators)
|
||||
{
|
||||
OpenViBE::CMatrix res = m_mat;
|
||||
|
||||
EXPECT_TRUE(m_mat.isDescriptionEqual(m_mat)) << ErrorMsg("equality description", m_mat, m_mat);
|
||||
EXPECT_TRUE(m_mat.isBufferEqual(m_mat)) << ErrorMsg("equality buffer", m_mat, m_mat);
|
||||
EXPECT_TRUE(m_mat.isBufferAlmostEqual(m_mat)) << ErrorMsg("Almost equality buffer", m_mat, m_mat);
|
||||
EXPECT_TRUE(m_mat == m_mat) << ErrorMsg("equality operator", m_mat, m_mat);
|
||||
EXPECT_TRUE(m_mat == res) << ErrorMsg("Copy assignement", m_mat, res);
|
||||
|
||||
m_mat.getBuffer()[0] = 15;
|
||||
m_mat.getBuffer()[1] = 25;
|
||||
m_mat.setDimensionLabel(1, 0, "changed");
|
||||
|
||||
EXPECT_TRUE(AlmostEqual(15, m_mat.getBuffer()[0])) << "Setup Matrix 1st value isn't 15.";
|
||||
EXPECT_TRUE(AlmostEqual(25, m_mat.getBuffer()[1])) << "Setup Matrix 2nd value isn't 25.";
|
||||
EXPECT_STREQ("changed", m_mat.getDimensionLabel(1, 0)) << "Setup Matrix 1st Column Label isn't changed.";
|
||||
EXPECT_TRUE(AlmostEqual(10, res.getBuffer()[0])) << "New Matrix 1st value isn't 10.";
|
||||
EXPECT_TRUE(AlmostEqual(20, res.getBuffer()[1])) << "New Matrix 2nd value isn't 20.";
|
||||
EXPECT_STREQ("dim1e0", res.getDimensionLabel(1, 0)) << "New Matrix 1st Column Label isn't dim1e0.";
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
TEST_F(CMatrix_Tests, Resize)
|
||||
{
|
||||
OpenViBE::CMatrix res(1, 2);
|
||||
res.resetBuffer();
|
||||
res.setDimensionLabel(0, 0, "label");
|
||||
ASSERT_EQ(2, res.getDimensionCount()) << "Matrix doesn't have 2 Dimensions.";
|
||||
ASSERT_EQ(1, res.getDimensionSize(0)) << "Matrix doesn't have 1 Row.";
|
||||
ASSERT_EQ(2, res.getDimensionSize(1)) << "Matrix doesn't have 2 Columns.";
|
||||
EXPECT_TRUE(AlmostEqual(0, res.getBuffer()[0])) << "Matrix 1st default value isn't 0 after resize.";
|
||||
EXPECT_TRUE(AlmostEqual(0, res.getBuffer()[1])) << "Matrix 2nd default value isn't 0 after resize.";
|
||||
EXPECT_STREQ("label", res.getDimensionLabel(0, 0)) << "Matrix Row Label isn't \"label\".";
|
||||
EXPECT_STREQ("", res.getDimensionLabel(1, 0)) << "Matrix 1st Col default Label isn't empty.";
|
||||
EXPECT_STREQ("", res.getDimensionLabel(1, 1)) << "Matrix 2nd Col default Label isn't empty.";
|
||||
|
||||
res.resize(2, 2);
|
||||
res.setDimensionLabel(1, 1, "label");
|
||||
ASSERT_EQ(2, res.getDimensionCount()) << "Matrix doesn't have 2 Dimensions.";
|
||||
ASSERT_EQ(2, res.getDimensionSize(0)) << "Matrix doesn't have 2 Row.";
|
||||
ASSERT_EQ(2, res.getDimensionSize(1)) << "Matrix doesn't have 2 Columns.";
|
||||
EXPECT_STREQ("", res.getDimensionLabel(0, 0)) << "Matrix 1st Row default Label isn't empty."; // The resize remove all previous label and size
|
||||
EXPECT_STREQ("label", res.getDimensionLabel(1, 1)) << "Matrix 2nd Col Label isn't \"label\".";
|
||||
|
||||
res.resetLabels();
|
||||
EXPECT_STREQ("", res.getDimensionLabel(1, 1)) << "Matrix 2nd Col reseted Label isn't empty.";
|
||||
|
||||
res.resize(2);
|
||||
ASSERT_EQ(1, res.getDimensionCount()) << "Matrix doesn't have 1 Dimension.";
|
||||
ASSERT_EQ(2, res.getDimensionSize(0)) << "Matrix doesn't have 2 Row.";
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
TEST_F(CMatrix_Tests, Save_Load)
|
||||
{
|
||||
OpenViBE::CMatrix res;
|
||||
EXPECT_TRUE(m_mat.toTextFile("Save_2DMatrix-output.txt")) << "Error during Saving 2D Matrix : " << std::endl << m_mat << std::endl;
|
||||
EXPECT_TRUE(res.fromTextFile("Save_2DMatrix-output.txt")) << "Error during Loading 2D Matrix : " << std::endl << res << std::endl;
|
||||
EXPECT_TRUE(m_mat == res) << ErrorMsg("Save", m_mat, res);
|
||||
|
||||
OpenViBE::CMatrix row(2);
|
||||
row.getBuffer()[0] = -1;
|
||||
row.getBuffer()[1] = -4.549746549678;
|
||||
EXPECT_TRUE(row.toTextFile("Save_2DMatrix-output.txt")) << "Error during Saving 1D Matrix : " << std::endl << row << std::endl;
|
||||
EXPECT_TRUE(res.fromTextFile("Save_2DMatrix-output.txt")) << "Error during Loading 1D Matrix : " << std::endl << res << std::endl;
|
||||
EXPECT_TRUE(row == res) << ErrorMsg("Save", row, res);
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
@@ -0,0 +1,188 @@
|
||||
///-------------------------------------------------------------------------------------------------
|
||||
///
|
||||
/// \file CMatrixTest.hpp
|
||||
/// \brief Test Definitions for OpenViBE Matrix Class.
|
||||
/// \author Thibaut Monseigne (Inria).
|
||||
/// \version 1.0.
|
||||
/// \date 11/05/2020.
|
||||
/// \copyright <a href="https://choosealicense.com/licenses/agpl-3.0/">GNU Affero General Public License v3.0</a>.
|
||||
///
|
||||
///-------------------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <openvibe/CTime.hpp>
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
|
||||
#include "utils.hpp"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
namespace Dataset {
|
||||
|
||||
const double HOUR = 60 * 60;
|
||||
const double DAY = 24 * HOUR;
|
||||
const double WEEK = 7 * DAY;
|
||||
const double MONTH = 30 * DAY;
|
||||
const double YEAR = 365 * DAY;
|
||||
|
||||
/// <summary> time values to test in seconds </summary>
|
||||
const std::vector<double> SECONDS =
|
||||
{
|
||||
0, 0.001, 0.01, 0.1, 0.2, 0.25, 0.5, 1.0, 1.1, 1.5, 2,
|
||||
1.000001, 1.999, 1.999999,
|
||||
5, 10, 50, 100, 123.456789, 128.0, 500, 1000, 2500, 5000,
|
||||
DAY, DAY + 0.03, DAY + 0.999, DAY + 1,
|
||||
WEEK, WEEK + 0.03, WEEK + 0.999, WEEK + 1,
|
||||
MONTH, MONTH + 0.03, MONTH + 0.999, MONTH + 1,
|
||||
YEAR, YEAR + 0.03, YEAR + 0.999, YEAR + 1,
|
||||
};
|
||||
|
||||
/// <summary> Time values to test in fixed point format. </summary>
|
||||
const std::vector<uint64_t> FIXED_POINT =
|
||||
{
|
||||
1LL << 8, 1LL << 16, 1L << 19, 1LL << 22, 1LL << 27, 1L << 30, 1LL << 32, 10LL << 32, 100LL << 32, 123LL << 32, 500LL << 32, 512LL << 32, 1000LL << 32,
|
||||
1024LL << 32, 2001LL << 32, 5000LL << 32
|
||||
};
|
||||
|
||||
/// <summary> Sampling rates to test. </summary>
|
||||
const std::vector<size_t> SAMPLINGS = { 100, 128, 512, 1000, 1024, 16000, 44100 };
|
||||
|
||||
/// <summary> Samples to test. </summary>
|
||||
const std::vector<uint64_t> SAMPLES = { 0, 1, 100, 128, 512, 1000, 1021, 1024, 5005, 12345, 59876, 100000, 717893, 1000001 };
|
||||
|
||||
/// <summary> Epoch durations to test. </summary>
|
||||
const std::vector<double> DURATIONS = { 0.01, 0.1, 0.2, 0.25, 0.5, 1.0, 1.1, 1.5, 2, 5, 10, 50, 100 };
|
||||
|
||||
/// <summary> We select 10-9 tolerance for seconds, being the best precision capacity of the CTime class. </summary>
|
||||
const double TOLERANCE = 10e-9;
|
||||
} // namespace Dataset
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
TEST(CTime_Tests, constructor_time)
|
||||
{
|
||||
for (auto ref : Dataset::FIXED_POINT)
|
||||
{
|
||||
const OpenViBE::CTime res(ref);
|
||||
EXPECT_EQ(res.time(), ref) << ErrorMsg("Constructor with time", ref, res.time());
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
TEST(CTime_Tests, constructor_seconds)
|
||||
{
|
||||
// test construction & conversion second -> fixed point -> second
|
||||
for (auto ref : Dataset::SECONDS)
|
||||
{
|
||||
const auto res = OpenViBE::CTime(ref).toSeconds();
|
||||
EXPECT_LT(std::abs(res - ref), Dataset::TOLERANCE) << ErrorMsg("Constructor with seconds and conversion to seconds", ref, res);
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
TEST(CTime_Tests, constructor_sampling)
|
||||
{
|
||||
// test construction & conversion sample -> time -> sample
|
||||
for (auto sampling : Dataset::SAMPLINGS)
|
||||
{
|
||||
for (auto ref : Dataset::SAMPLES)
|
||||
{
|
||||
const auto res = OpenViBE::CTime(sampling, ref).toSampleCount(sampling);
|
||||
EXPECT_EQ(ref, res) << ErrorMsg("Constructor with sampling and sample count and conversion to sample count", ref, res);
|
||||
}
|
||||
}
|
||||
EXPECT_TRUE(OpenViBE::CTime(0, 1) == OpenViBE::CTime::max()) << ErrorMsg("Special Case if sampling = 0",
|
||||
OpenViBE::CTime::max(), OpenViBE::CTime(0, 1));
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
TEST(CTime_Tests, ceil)
|
||||
{
|
||||
// Ceil Test
|
||||
const OpenViBE::CTime t0 = OpenViBE::CTime().min().ceil();
|
||||
const OpenViBE::CTime t1 = OpenViBE::CTime().max().ceil();
|
||||
const OpenViBE::CTime t2 = OpenViBE::CTime(0xFEDCBA9876543210).ceil();
|
||||
const OpenViBE::CTime t3 = OpenViBE::CTime(0xFEDCBA9900000000);
|
||||
|
||||
EXPECT_TRUE(t0 == t0) << ErrorMsg("ceil of Time Min (0)", t0, t0);
|
||||
EXPECT_TRUE(t1 == t0) << ErrorMsg("ceil of Time Max (0xFFFFFFFFFFFFFFFF)", t0, t1);
|
||||
EXPECT_TRUE(t2 == t3) << ErrorMsg("ceil of Time (0xFEDCBA9876543210)", t3, t2);
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
TEST(CTime_Tests, operators)
|
||||
{
|
||||
// Operators Tests
|
||||
const OpenViBE::CTime t0 = OpenViBE::CTime(1.0) + OpenViBE::CTime(1.0);
|
||||
const OpenViBE::CTime t1 = OpenViBE::CTime(4.0) - OpenViBE::CTime(1.0);
|
||||
const OpenViBE::CTime t2 = OpenViBE::CTime(1.0) - OpenViBE::CTime(4.0);
|
||||
|
||||
const OpenViBE::CTime r0 = OpenViBE::CTime(2.0);
|
||||
const OpenViBE::CTime r1 = OpenViBE::CTime(3.0);
|
||||
// we remove 2 second from the max
|
||||
// - We have -3 as result, with uint max = -1 so result is max - 2
|
||||
// and max seconds = 2^32 - 1 (0xFFFFFFFF) so result is max - 2 : 0xFFFFFFFD so in Fixed Point 0xFFFFFFFD00000000)
|
||||
const OpenViBE::CTime r2 = OpenViBE::CTime(0xFFFFFFFD00000000);
|
||||
|
||||
// Comparison
|
||||
EXPECT_TRUE(r0 == r0) << ErrorMsg("ref == calc", t0, t0);
|
||||
EXPECT_FALSE(r0 != r0) << ErrorMsg("!(ref != calc)", t1, t1);
|
||||
EXPECT_TRUE(r0 < r1) << ErrorMsg("(ref < calc)", r0, r1);
|
||||
EXPECT_TRUE(r0 <= r1) << ErrorMsg("(ref <= calc)", r0, r1);
|
||||
EXPECT_TRUE(r1 > r0) << ErrorMsg("(ref > calc)", r1, r0);
|
||||
EXPECT_TRUE(r1 >= r0) << ErrorMsg("(ref >= calc)", r1, r0);
|
||||
|
||||
// Operation
|
||||
EXPECT_TRUE(t0 == r0) << ErrorMsg("Addition result", r0, t0);
|
||||
EXPECT_TRUE(t1 == r1) << ErrorMsg("Substract result", r1, t1);
|
||||
EXPECT_TRUE(t2 == r2) << ErrorMsg("substract with negative result", r2, t2);
|
||||
|
||||
// Str
|
||||
EXPECT_EQ("1.000 sec (0x0000000100000000)", OpenViBE::CTime(1.0).str(true, true));
|
||||
EXPECT_EQ("1.000 sec", OpenViBE::CTime(1.0).str(true, false));
|
||||
EXPECT_EQ("4294967296 (0x0000000100000000)", OpenViBE::CTime(1.0).str(false, true));
|
||||
EXPECT_EQ("4294967296", OpenViBE::CTime(1.0).str(false, false));
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
TEST(CTime_Tests, conversion_chain)
|
||||
{
|
||||
// test conversion time -> sample -> time
|
||||
for (auto sampling : Dataset::SAMPLINGS)
|
||||
{
|
||||
for (auto seconds : Dataset::SECONDS)
|
||||
{
|
||||
auto tmp = OpenViBE::CTime(seconds).time();
|
||||
// If the sample count would overflow an uint64_t we skip the test
|
||||
if (std::log2(sampling) + std::log2(tmp) >= 64) { continue; }
|
||||
|
||||
const uint64_t compute = OpenViBE::CTime(sampling, OpenViBE::CTime(tmp).toSampleCount(sampling)).time();
|
||||
const uint64_t difference = uint64_t(std::abs(int64_t(compute) - int64_t(tmp)));
|
||||
|
||||
EXPECT_LT(OpenViBE::CTime(difference).toSeconds(), (1.0 / double(sampling)))
|
||||
<< "Time difference too large between OV(" << seconds << ") and "
|
||||
<< "SCtoOV(" << sampling << ", OVtoSC(" << sampling << "," << tmp << "))";
|
||||
}
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
TEST(CTime_Tests, legacy_epoching)
|
||||
{
|
||||
// compare second -> time conversion to legacy method
|
||||
for (auto duration : Dataset::DURATIONS)
|
||||
{
|
||||
const auto legacy = uint64_t(duration * (1LL << 32)); // Legacy code from stimulationBasedEpoching
|
||||
const auto res = OpenViBE::CTime(duration).time();
|
||||
EXPECT_EQ(res, legacy) << ErrorMsg("Legacy Epoching for duration : " + std::to_string(duration), legacy, res);
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
@@ -0,0 +1,16 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
// ReSharper disable CppUnusedIncludeDirective
|
||||
#include "CMatrixTest.hpp"
|
||||
#include "CTimeTest.hpp"
|
||||
#include "CIdentifierTest.hpp"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
catch (std::exception&) { return 1; }
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
///-------------------------------------------------------------------------------------------------
|
||||
///
|
||||
/// \file utils.hpp
|
||||
/// \brief Some constants and functions for google tests
|
||||
/// \author Thibaut Monseigne (Inria).
|
||||
/// \version 0.1.
|
||||
/// \date 26/10/2018.
|
||||
/// \copyright <a href="https://choosealicense.com/licenses/agpl-3.0/">GNU Affero General Public License v3.0</a>.
|
||||
///
|
||||
///-------------------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "openvibe/CIdentifier.hpp"
|
||||
#include "openvibe/CTime.hpp"
|
||||
#include <openvibe/CMatrix.hpp>
|
||||
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
|
||||
const std::string SEP = "\n====================\n";
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
/// <summary> Check if double are almost equals. </summary>
|
||||
/// <param name="a"> The first number. </param>
|
||||
/// <param name="b"> The second number. </param>
|
||||
/// <param name="epsilon"> The tolerance. </param>
|
||||
/// <returns> <c>true</c> if almmost equals, <c>false</c> otherwise. </returns>
|
||||
inline bool AlmostEqual(const double a, const double b, const double epsilon = OV_EPSILON) { return std::fabs(a - b) < std::fabs(epsilon); }
|
||||
|
||||
//*****************************************************************
|
||||
//********** Error Message Standardization for googltest **********
|
||||
//*****************************************************************
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
/// <summary> Error message for numeric value. </summary>
|
||||
/// <param name="name"> The name of the test. </param>
|
||||
/// <param name="ref"> The reference value. </param>
|
||||
/// <param name="calc"> The calculate value. </param>
|
||||
/// <returns> Error message. </returns>
|
||||
/// <typeparam name="T"> Generic numeric type parameter. </typeparam>
|
||||
template <typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
|
||||
std::string ErrorMsg(const std::string& name, const T ref, const T calc)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << SEP << name << " : Reference : " << ref << ", \tCompute : " << calc << SEP;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
/// <summary> Error message for string value. </summary>
|
||||
/// <inheritdoc cref="ErrorMsg(const std::string&, const T, const T)"/>
|
||||
inline std::string ErrorMsg(const std::string& name, const std::string& ref, const std::string& calc)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << SEP << name << " : Reference : " << ref << ", \tCompute : " << calc << SEP;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
/// <summary> Error message for CTime value. </summary>
|
||||
/// <inheritdoc cref="ErrorMsg(const std::string&, const T, const T)"/>
|
||||
inline std::string ErrorMsg(const std::string& name, const OpenViBE::CTime& ref, const OpenViBE::CTime& calc)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << SEP << name << " : Reference : " << ref.str(true, true) << ", \tCompute : " << calc.str(true, true) << SEP;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
/// <summary> Error message for CIdentifier value. </summary>
|
||||
/// <inheritdoc cref="ErrorMsg(const std::string&, const T, const T)"/>
|
||||
inline std::string ErrorMsg(const std::string& name, const OpenViBE::CIdentifier& ref, const OpenViBE::CIdentifier& calc)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << SEP << name << " : Reference : " << ref << ", \tCompute : " << calc << SEP;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
/// <summary> Error message for CIdentifier value. </summary>
|
||||
/// <inheritdoc cref="ErrorMsg(const std::string&, const T, const T)"/>
|
||||
inline std::string ErrorMsg(const std::string& name, const OpenViBE::CMatrix& ref, const OpenViBE::CMatrix& calc)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << SEP << name << " : " << std::endl << "********** Reference **********\n" << ref << std::endl << "********** Compute **********\n" << calc << SEP;
|
||||
return ss.str();
|
||||
}
|
||||
Reference in New Issue
Block a user