This commit is contained in:
2021-10-14 13:47:35 +02:00
commit 6625a8dfaa
4026 changed files with 844291 additions and 0 deletions
@@ -0,0 +1,65 @@
#######################################################################
# Software License Agreement (AGPL-3 License)
#
# OpenViBE SDK Test Software
# Based on OpenViBE V1.1.0, Copyright (C) Inria, 2006-2015
# Copyright (C) Inria, 2015-2017,V1.0
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License version 3,
# as published by the Free Software Foundation.
#
# 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 <http://www.gnu.org/licenses/>.
#######################################################################
PROJECT(openvibe-test-unit-toolkit)
# ------------------
# Project variables
# ------------------
SET(PROJECT_VERSION_MAJOR ${OVT_GLOBAL_VERSION_MAJOR})
SET(PROJECT_VERSION_MINOR ${OVT_GLOBAL_VERSION_MINOR})
SET(PROJECT_VERSION_PATCH ${OVT_GLOBAL_VERSION_PATCH})
SET(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
# ---------------------------------
# Target macros
# Defines target operating system, architecture and compiler
# ---------------------------------
SET_BUILD_PLATFORM()
# ----------------------
# Generate target
# ----------------------
ADD_DEFINITIONS( -DPROJECT_VERSION="${PROJECT_VERSION}" )
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
FILE(GLOB_RECURSE SRC_FILES src/*.cpp include/*.h)
ADD_LIBRARY(${PROJECT_NAME} ${SRC_FILES})
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
FOLDER ${TESTS_FOLDER})
INCLUDE("FindOpenViBE")
INCLUDE("FindOpenViBECommon")
INCLUDE("FindOpenViBEToolkit")
# -------------
# External Use
# -------------
# Target name used by other target for linking purpose
SET(OVT_UNIT_TOOLKIT_LIB ${PROJECT_NAME} PARENT_SCOPE)
SET(OVT_UNIT_TOOLKIT_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include PARENT_SCOPE)
@@ -0,0 +1,88 @@
/*********************************************************************
* Software License Agreement (AGPL-3 License)
*
* OpenViBE SDK Test Software
* Based on OpenViBE V1.1.0, Copyright (C) Inria, 2006-2015
* Copyright (C) Inria, 2015-2017,V1.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License version 3,
* as published by the Free Software Foundation.
*
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <string>
namespace OpenViBE {
namespace Test {
void printError(const char* expression, const char* message, const char* file, const int line);
void printError(const char* expression, const std::string& message, const char* file, const int line);
void printError(const char* expression, const std::ostream& message, const char* file, const int line);
void printExpressionPair(const char* str1, const char* str2);
std::string buildExpressionFromPair(const char* str1, const char* str2);
} // namespace Test
} // namespace OpenViBE
/**
* OVT_ASSERT_PRIV: Assess expression and
* return EXIT_FAILURE if expr is false
* - expr: expression to assess
* - origin: original assessed expression
* - msg: custom error message
* WARNING: SHOULD NOT BE USED DIRECTLY
*/
#define OVT_ASSERT_PRIV(expr, origin, msg) \
do { \
if (!(expr)) \
{ \
OpenViBE::Test::printError(#origin, (msg), __FILE__, __LINE__); \
return EXIT_FAILURE; \
} \
} while (0)
/**
* OVT_ASSERT: Assess simple expression
* - expr: expression to assess
* - msg: custom error message
*/
#define OVT_ASSERT(expr, msg) OVT_ASSERT_PRIV((expr), (expr), (msg))
/**
* OVT_ASSERT_STR: Assess string equality
* - str1: reference string
* - str2: compared string
* - msg: custom error message
*/
#define OVT_ASSERT_STREQ(str1, str2, msg) \
do { \
if (!((str1) == (str2))) \
{ \
OpenViBE::Test::printError(OpenViBE::Test::buildExpressionFromPair(#str1, #str2).c_str(),(msg), __FILE__, __LINE__); \
OpenViBE::Test::printExpressionPair((str1).c_str(),(str2).c_str());\
return EXIT_FAILURE; \
} \
} while (0)
/**
* OVT_ASSERT_EX: Assess expr throws an
* exception
* - expr: expression to assess
* - msg: custom error message
*/
#define OVT_ASSERT_EX(expr, msg) \
do { \
bool hasTrown{ false }; \
try { (expr); } \
catch (...) { hasTrown = true; } \
OVT_ASSERT_PRIV(hasTrown, (msg)); \
} while (0)
@@ -0,0 +1,81 @@
/*********************************************************************
* Software License Agreement (AGPL-3 License)
*
* OpenViBE SDK Test Software
* Based on OpenViBE V1.1.0, Copyright (C) Inria, 2006-2015
* Copyright (C) Inria, 2015-2017,V1.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License version 3,
* as published by the Free Software Foundation.
*
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <memory>
namespace OpenViBE {
namespace Test {
/**
* \struct TestFixture
* \author cgarraud (INRIA)
* \date 2016-02-08
* \brief Base abstract struct for test fixture
*
* A test fixture is used when an environment has to be set for a specific test.
* TestFixture implementation should not be used directly but through ScopedTest.
*/
struct TestFixture
{
virtual ~TestFixture() = default;
TestFixture() = default;
/**
* \brief Setup resources for the test
*/
virtual void setUp() = 0;
/**
* \brief Release resources
*/
virtual void tearDown() = 0;
private:
TestFixture& operator=(const TestFixture&) = delete;
TestFixture(const TestFixture&) = delete;
};
/**
* \struct ScopedTest
* \author cgarraud (INRIA)
* \date 2016-02-08
* \brief Class used to ensure RAII when using TestFixture
*
* A scoped object is a wrapper around a test fixture used to
* ensure RAII when running tests.
*/
template <typename T>
struct ScopedTest
{
template <typename... TArgs>
explicit ScopedTest(TArgs&&... args) : fixture(new T(std::forward<TArgs>(args)...)) { fixture->setUp(); }
~ScopedTest() { fixture->tearDown(); }
const T* operator->() const { return fixture.get(); }
T* operator->() { return fixture.get(); }
std::unique_ptr<T> fixture;
};
} // namespace Test
} // namespace OpenViBE
@@ -0,0 +1,50 @@
/*********************************************************************
* Software License Agreement (AGPL-3 License)
*
* OpenViBE SDK Test Software
* Based on OpenViBE V1.1.0, Copyright (C) Inria, 2006-2015
* Copyright (C) Inria, 2015-2017,V1.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License version 3,
* as published by the Free Software Foundation.
*
* 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <string>
#include <openvibe/ov_all.h>
#include "ovtTestFixture.h"
// \note: This file contains fixture implementation shared by many unit tests
namespace OpenViBE {
namespace Test {
struct SKernelFixture final : TestFixture
{
SKernelFixture() = default;
explicit SKernelFixture(const std::string& configFile) : m_configFile(configFile) { }
void setConfigFile(const std::string& configFile) { m_configFile = configFile; }
void setUp() override;
void tearDown() override;
Kernel::IKernelContext* context{ nullptr };
private:
std::string m_configFile;
CKernelLoader m_kernelLoader;
};
} // namespace Test
} // namespace OpenViBE
@@ -0,0 +1,64 @@
/*********************************************************************
* Software License Agreement (AGPL-3 License)
*
* OpenViBE SDK Test Software
* Based on OpenViBE V1.1.0, Copyright (C) Inria, 2006-2015
* Copyright (C) Inria, 2015-2017,V1.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License version 3,
* as published by the Free Software Foundation.
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include "ovtAssert.h"
namespace OpenViBE {
namespace Test {
static void printErrorCore(const char* expression, const char* file, const int line)
{
std::cerr << "Failed to evaluate: " << expression << std::endl;
std::cerr << "File = " << file << std::endl;
std::cerr << "Line = " << line << std::endl;
}
void printError(const char* expression, const char* message, const char* file, const int line)
{
printErrorCore(expression, file, line);
std::cerr << "Error message: " << message << std::endl;
}
void printError(const char* expression, const std::string& message, const char* file, const int line) { printError(expression, message.c_str(), file, line); }
void printError(const char* expression, const std::ostream& message, const char* file, const int line)
{
printErrorCore(expression, file, line);
std::cerr << "Error message: " << message.rdbuf() << std::endl;
}
void printExpressionPair(const char* str1, const char* str2)
{
std::cerr << "Expression 1 is : " << str1 << std::endl;
std::cerr << "Expression 2 is : " << str2 << std::endl;
}
std::string buildExpressionFromPair(const char* str1, const char* str2)
{
std::string expression = "( " + std::string(str1);
expression += " = ";
expression += std::string(str2) + " )";
return expression;
}
} // namespace Test
} // namespace OpenViBE
@@ -0,0 +1,93 @@
/*********************************************************************
* Software License Agreement (AGPL-3 License)
*
* OpenViBE SDK Test Software
* Based on OpenViBE V1.1.0, Copyright (C) Inria, 2006-2015
* Copyright (C) Inria, 2015-2017,V1.0
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License version 3,
* as published by the Free Software Foundation.
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <toolkit/ovtk_all.h>
#include "ovtTestFixtureCommon.h"
namespace OpenViBE {
namespace Test {
void SKernelFixture::setUp()
{
#if defined TARGET_OS_Windows
const CString kernelFile = Directories::getLibDir() + "/openvibe-kernel.dll";
#elif defined TARGET_OS_Linux
const CString kernelFile = Directories::getLibDir() + "/libopenvibe-kernel.so";
#elif defined TARGET_OS_MacOS
const CString kernelFile = Directories::getLibDir() + "/libopenvibe-kernel.dylib";
#endif
CString error;
if (!m_kernelLoader.load(kernelFile, &error))
{
std::cerr << "ERROR: impossible to load kernel from file located at: " << kernelFile << std::endl;
std::cerr << "ERROR: kernel error: " << error << std::endl;
return;
}
m_kernelLoader.initialize();
Kernel::IKernelDesc* kernelDesc = nullptr;
m_kernelLoader.getKernelDesc(kernelDesc);
if (!kernelDesc)
{
std::cerr << "ERROR: impossible to retrieve kernel descriptor " << std::endl;
return;
}
CString configFile;
if (!m_configFile.empty()) { configFile = m_configFile.c_str(); }
else { configFile = CString(Directories::getDataDir() + "/kernel/openvibe.conf"); }
Kernel::IKernelContext* ctx = kernelDesc->createKernel("test-kernel", configFile);
if (!ctx)
{
std::cerr << "ERROR: impossible to create kernel context " << std::endl;
return;
}
ctx->initialize();
Toolkit::initialize(*ctx);
context = ctx;
}
void SKernelFixture::tearDown()
{
if (context)
{
Toolkit::uninitialize(*context);
Kernel::IKernelDesc* kernelDesc = nullptr;
m_kernelLoader.getKernelDesc(kernelDesc);
kernelDesc->releaseKernel(context);
context = nullptr;
}
m_kernelLoader.uninitialize();
m_kernelLoader.unload();
}
} // namespace Test
} // namespace OpenViBE