init
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
#######################################################################
|
||||
# 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-kernel-test)
|
||||
|
||||
# ---------------------------------
|
||||
# Target macros
|
||||
# Defines target operating system, architecture and compiler
|
||||
# ---------------------------------
|
||||
SET_BUILD_PLATFORM()
|
||||
|
||||
# ----------------------
|
||||
# Configure test target
|
||||
# ----------------------
|
||||
|
||||
# Test that needs to called with parameters
|
||||
SET(TEST_WITH_PARAM
|
||||
urErrorManagerTest.cpp
|
||||
)
|
||||
|
||||
# Test that needs to called without parameters
|
||||
SET(TEST_NO_PARAM
|
||||
)
|
||||
|
||||
# Create test sources list
|
||||
# This macro auto-generate ${PROJECT_NAME}.cpp
|
||||
# in the build tree. ${PROJECT_NAME}.cpp is
|
||||
# the test driver called by ctest to run
|
||||
# the different tests added to this target.
|
||||
CREATE_TEST_SOURCELIST (Tests
|
||||
${PROJECT_NAME}.cpp
|
||||
${TEST_WITH_PARAM}
|
||||
${TEST_NO_PARAM}
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(${PROJECT_NAME} ${Tests})
|
||||
INCLUDE("FindOpenViBE")
|
||||
INCLUDE("FindOpenViBECommon")
|
||||
SET_PROPERTY(TARGET ${PROJECT_NAME} PROPERTY FOLDER ${TESTS_FOLDER})
|
||||
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${OVT_UNIT_TOOLKIT_LIB} ${GTEST_BOTH_LIBRARIES} ${OV_LIBS})
|
||||
|
||||
# Add test without parameter to driver
|
||||
FOREACH(test ${TEST_NO_PARAM})
|
||||
GET_FILENAME_COMPONENT(TName ${test} NAME_WE)
|
||||
ADD_TEST(NAME ${TName} COMMAND ${PROJECT_NAME} ${TName})
|
||||
ENDFOREACH()
|
||||
|
||||
# Add test with parameter to driver
|
||||
ADD_TEST(NAME urErrorManagerTest COMMAND ${PROJECT_NAME} urErrorManagerTest "${OVT_OPENVIBE_DATA}/kernel/openvibe.conf")
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "ovtAssert.h"
|
||||
#include "ovtTestFixtureCommon.h"
|
||||
|
||||
// DO NOT USE a global Test::ScopedTest<Test::SKernelFixture> variable here
|
||||
// because it causes a bug due to plugins global descriptors beeing destroyed before the kernel context.
|
||||
OpenViBE::Kernel::IKernelContext* context = nullptr;
|
||||
|
||||
TEST(error_manager_test_case, test_init)
|
||||
{
|
||||
// here we use assert because we want to fail directly
|
||||
// in order to avoid a segfault
|
||||
ASSERT_TRUE(context != nullptr);
|
||||
|
||||
auto& errorManager = context->getErrorManager();
|
||||
|
||||
// check manager is correctly initialized
|
||||
EXPECT_FALSE(errorManager.hasError());
|
||||
EXPECT_TRUE(errorManager.getLastError() == nullptr);
|
||||
EXPECT_TRUE(std::string(errorManager.getLastErrorString()).empty());
|
||||
EXPECT_EQ(errorManager.getLastErrorType(), OpenViBE::Kernel::ErrorType::NoErrorFound);
|
||||
|
||||
EXPECT_NO_THROW(errorManager.releaseErrors());
|
||||
}
|
||||
|
||||
TEST(error_manager_test_case, test_push)
|
||||
{
|
||||
// here we use assert because we want to fail directly
|
||||
// in order to avoid a segfault
|
||||
ASSERT_TRUE(context != nullptr);
|
||||
|
||||
auto& errorManager = context->getErrorManager();
|
||||
|
||||
// push an error
|
||||
errorManager.pushError(OpenViBE::Kernel::ErrorType::Overflow, "An integer overflow error occurred");
|
||||
|
||||
EXPECT_TRUE(errorManager.hasError());
|
||||
EXPECT_STREQ(errorManager.getLastErrorString(), "An integer overflow error occurred");
|
||||
EXPECT_EQ(errorManager.getLastErrorType(), OpenViBE::Kernel::ErrorType::Overflow);
|
||||
|
||||
// test match error features returned direclty by manager match error features
|
||||
auto error = errorManager.getLastError();
|
||||
|
||||
ASSERT_TRUE(error != nullptr);
|
||||
EXPECT_STREQ(error->getErrorString(), "An integer overflow error occurred");
|
||||
EXPECT_EQ(error->getErrorType(), OpenViBE::Kernel::ErrorType::Overflow);
|
||||
EXPECT_STREQ(error->getErrorLocation(), "NoLocationInfo:0");
|
||||
EXPECT_TRUE(error->getNestedError() == nullptr);
|
||||
|
||||
// push another error
|
||||
errorManager.pushErrorAtLocation(OpenViBE::Kernel::ErrorType::BadAlloc, "Memory allocation failed", "urErrorManagerTest.cpp", 64);
|
||||
|
||||
// test top error has changed
|
||||
EXPECT_STREQ(errorManager.getLastErrorString(), "Memory allocation failed");
|
||||
EXPECT_EQ(errorManager.getLastErrorType(), OpenViBE::Kernel::ErrorType::BadAlloc);
|
||||
|
||||
error = errorManager.getLastError();
|
||||
ASSERT_TRUE(error != nullptr);
|
||||
EXPECT_STREQ(error->getErrorString(), "Memory allocation failed");
|
||||
EXPECT_EQ(error->getErrorType(), OpenViBE::Kernel::ErrorType::BadAlloc);
|
||||
EXPECT_STREQ(error->getErrorLocation(), "urErrorManagerTest.cpp:64");
|
||||
|
||||
auto nestedError = error->getNestedError();
|
||||
ASSERT_TRUE(nestedError != nullptr);
|
||||
EXPECT_STREQ(nestedError->getErrorString(), "An integer overflow error occurred");
|
||||
EXPECT_EQ(nestedError->getErrorType(), OpenViBE::Kernel::ErrorType::Overflow);
|
||||
EXPECT_STREQ(nestedError->getErrorLocation(), "NoLocationInfo:0");
|
||||
EXPECT_TRUE(nestedError->getNestedError() == nullptr);
|
||||
}
|
||||
|
||||
TEST(error_manager_test_case, test_release)
|
||||
{
|
||||
// here we use assert because we want to fail directly
|
||||
// in order to avoid a segfault
|
||||
ASSERT_TRUE(context != nullptr);
|
||||
|
||||
auto& errorManager = context->getErrorManager();
|
||||
errorManager.releaseErrors();
|
||||
|
||||
// check manager is correctly released
|
||||
EXPECT_FALSE(errorManager.hasError());
|
||||
EXPECT_TRUE(errorManager.getLastError() == nullptr);
|
||||
EXPECT_TRUE(std::string(errorManager.getLastErrorString()).empty());
|
||||
EXPECT_EQ(errorManager.getLastErrorType(), OpenViBE::Kernel::ErrorType::NoErrorFound);
|
||||
|
||||
// add an error after release
|
||||
errorManager.pushErrorAtLocation(OpenViBE::Kernel::ErrorType::ResourceNotFound, "File not found on system", "urErrorManagerTest.cpp", 93);
|
||||
|
||||
EXPECT_TRUE(errorManager.hasError());
|
||||
EXPECT_STREQ(errorManager.getLastErrorString(), "File not found on system");
|
||||
EXPECT_EQ(errorManager.getLastErrorType(), OpenViBE::Kernel::ErrorType::ResourceNotFound);
|
||||
|
||||
auto error = errorManager.getLastError();
|
||||
|
||||
ASSERT_TRUE(error != nullptr);
|
||||
EXPECT_STREQ(error->getErrorString(), "File not found on system");
|
||||
EXPECT_EQ(error->getErrorType(), OpenViBE::Kernel::ErrorType::ResourceNotFound);
|
||||
EXPECT_STREQ(error->getErrorLocation(), "urErrorManagerTest.cpp:93");
|
||||
EXPECT_TRUE(error->getNestedError() == nullptr);
|
||||
}
|
||||
|
||||
TEST(error_manager_test_case, test_stress_push)
|
||||
{
|
||||
// here we use assert because we want to fail directly
|
||||
// in order to avoid a segfault
|
||||
ASSERT_TRUE(context != nullptr);
|
||||
|
||||
auto& errorManager = context->getErrorManager();
|
||||
|
||||
errorManager.releaseErrors();
|
||||
const size_t expectedErrorCount = 10;
|
||||
for (size_t i = 0; i < expectedErrorCount; ++i) { errorManager.pushError(OpenViBE::Kernel::ErrorType::Unknown, "Error"); }
|
||||
|
||||
size_t errorCount = 0;
|
||||
auto error = errorManager.getLastError();
|
||||
while (error)
|
||||
{
|
||||
errorCount++;
|
||||
error = error->getNestedError();
|
||||
}
|
||||
|
||||
EXPECT_EQ(errorCount, expectedErrorCount);
|
||||
}
|
||||
|
||||
int urErrorManagerTest(int argc, char* argv[])
|
||||
{
|
||||
OVT_ASSERT(argc >= 2, "Failure retrieve test parameters");
|
||||
|
||||
OpenViBE::Test::ScopedTest<OpenViBE::Test::SKernelFixture> fixture;
|
||||
fixture->setConfigFile(argv[1]);
|
||||
|
||||
context = fixture->context;
|
||||
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
::testing::GTEST_FLAG(filter) = "error_manager_test_case.*";
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
Reference in New Issue
Block a user