|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- #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();
- }
|