updated build system
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
This commit is contained in:
65
support/test/src/utils/error_test.cpp
Normal file
65
support/test/src/utils/error_test.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#include "test.hpp"
|
||||
|
||||
namespace repertory {
|
||||
template <typename T, typename U>
|
||||
constexpr bool is_decay_equ = std::is_same_v<std::decay_t<T>, U>;
|
||||
|
||||
TEST(utils_error, check_default_exception_handler) {
|
||||
EXPECT_EQ(&utils::error::default_exception_handler,
|
||||
utils::error::get_exception_handler());
|
||||
|
||||
auto default_handler_is_iostream =
|
||||
is_decay_equ<decltype(utils::error::default_exception_handler),
|
||||
utils::error::iostream_exception_handler>;
|
||||
EXPECT_TRUE(default_handler_is_iostream);
|
||||
}
|
||||
|
||||
TEST(utils_error, can_override_exception_handler) {
|
||||
struct my_exc_handler : public utils::error::i_exception_handler {
|
||||
MOCK_METHOD(void, handle_exception, (std::string_view function_name),
|
||||
(const, override));
|
||||
|
||||
MOCK_METHOD(void, handle_exception,
|
||||
(std::string_view function_name, const std::exception &ex),
|
||||
(const, override));
|
||||
};
|
||||
|
||||
my_exc_handler handler{};
|
||||
utils::error::set_exception_handler(&handler);
|
||||
|
||||
EXPECT_CALL(handler, handle_exception("test_func")).WillOnce(Return());
|
||||
utils::error::handle_exception("test_func");
|
||||
|
||||
auto ex = std::runtime_error("moose");
|
||||
EXPECT_CALL(handler, handle_exception(_, _))
|
||||
.WillOnce(
|
||||
[&ex](std::string_view function_name, const std::exception &ex2) {
|
||||
EXPECT_EQ("test_func_ex", function_name);
|
||||
EXPECT_STREQ(ex.what(), ex2.what());
|
||||
});
|
||||
utils::error::handle_exception("test_func_ex", ex);
|
||||
|
||||
utils::error::set_exception_handler(&utils::error::default_exception_handler);
|
||||
}
|
||||
} // namespace repertory
|
@ -393,4 +393,128 @@ TEST(utils_path, absolute_can_resolve_path_variables) {
|
||||
EXPECT_STREQ(home.c_str(), expanded_str.c_str());
|
||||
#endif // defined(_WIN32)
|
||||
}
|
||||
|
||||
TEST(utils_path, get_parent_directory) {
|
||||
#if defined(_WIN32)
|
||||
{
|
||||
auto dir = R"(c:\test)";
|
||||
auto parent = utils::path::get_parent_directory(dir);
|
||||
EXPECT_STREQ("c:", parent.c_str());
|
||||
|
||||
dir = R"(c:\test\file.txt)";
|
||||
parent = utils::path::get_parent_directory(dir);
|
||||
EXPECT_STREQ(R"(c:\test)", parent.c_str());
|
||||
|
||||
dir = "c:";
|
||||
parent = utils::path::get_parent_directory(dir);
|
||||
EXPECT_STREQ("c:", parent.c_str());
|
||||
}
|
||||
|
||||
{
|
||||
auto dir = LR"(c:\test)";
|
||||
auto parent = utils::path::get_parent_directory(dir);
|
||||
EXPECT_STREQ(L"c:", parent.c_str());
|
||||
|
||||
dir = LR"(c:\test\file.txt)";
|
||||
parent = utils::path::get_parent_directory(dir);
|
||||
EXPECT_STREQ(LR"(c:\test)", parent.c_str());
|
||||
|
||||
dir = L"c:";
|
||||
parent = utils::path::get_parent_directory(dir);
|
||||
EXPECT_STREQ(L"c:", parent.c_str());
|
||||
}
|
||||
#else // !defined(_WIN32)
|
||||
{
|
||||
auto dir = "/test";
|
||||
auto parent = utils::path::get_parent_directory(dir);
|
||||
EXPECT_STREQ("/", parent.c_str());
|
||||
|
||||
dir = "/test/test";
|
||||
parent = utils::path::get_parent_directory(dir);
|
||||
EXPECT_STREQ("/test", parent.c_str());
|
||||
}
|
||||
|
||||
{
|
||||
auto dir = L"/test";
|
||||
auto parent = utils::path::get_parent_directory(dir);
|
||||
EXPECT_STREQ(L"/", parent.c_str());
|
||||
|
||||
dir = L"/test/test";
|
||||
parent = utils::path::get_parent_directory(dir);
|
||||
EXPECT_STREQ(L"/test", parent.c_str());
|
||||
}
|
||||
#endif // defined(_WIN32)
|
||||
}
|
||||
|
||||
TEST(utils_path, contains_trash_directory) {
|
||||
#if defined(_WIN32)
|
||||
{
|
||||
auto dir = R"(c:\$recycle.bin)";
|
||||
EXPECT_TRUE(utils::path::contains_trash_directory(dir));
|
||||
|
||||
dir = R"(c:\$recycle.bin\moose.txt)";
|
||||
EXPECT_TRUE(utils::path::contains_trash_directory(dir));
|
||||
}
|
||||
|
||||
{
|
||||
auto dir = LR"(c:\$recycle.bin)";
|
||||
EXPECT_TRUE(utils::path::contains_trash_directory(dir));
|
||||
|
||||
dir = LR"(c:\$recycle.bin\moose.txt)";
|
||||
EXPECT_TRUE(utils::path::contains_trash_directory(dir));
|
||||
}
|
||||
#else // !defined(_WIN32)
|
||||
{
|
||||
auto dir = "/$recycle.bin";
|
||||
EXPECT_TRUE(utils::path::contains_trash_directory(dir));
|
||||
|
||||
dir = "/$recycle.bin/moose.txt";
|
||||
EXPECT_TRUE(utils::path::contains_trash_directory(dir));
|
||||
}
|
||||
|
||||
{
|
||||
auto dir = L"/$recycle.bin";
|
||||
EXPECT_TRUE(utils::path::contains_trash_directory(dir));
|
||||
|
||||
dir = L"/$recycle.bin/moose.txt";
|
||||
EXPECT_TRUE(utils::path::contains_trash_directory(dir));
|
||||
}
|
||||
#endif // defined(_WIN32)
|
||||
}
|
||||
|
||||
TEST(utils_path, does_not_contain_trash_directory) {
|
||||
#if defined(_WIN32)
|
||||
{
|
||||
auto dir = R"(c:\recycle.bin)";
|
||||
EXPECT_FALSE(utils::path::contains_trash_directory(dir));
|
||||
|
||||
dir = R"(c:\recycle.bin\moose.txt)";
|
||||
EXPECT_FALSE(utils::path::contains_trash_directory(dir));
|
||||
}
|
||||
|
||||
{
|
||||
auto dir = LR"(c:\recycle.bin)";
|
||||
EXPECT_FALSE(utils::path::contains_trash_directory(dir));
|
||||
|
||||
dir = LR"(c:\recycle.bin\moose.txt)";
|
||||
EXPECT_FALSE(utils::path::contains_trash_directory(dir));
|
||||
}
|
||||
#else // !defined(_WIN32)
|
||||
{
|
||||
auto dir = "/recycle.bin";
|
||||
EXPECT_FALSE(utils::path::contains_trash_directory(dir));
|
||||
|
||||
dir = "/recycle.bin/moose.txt)";
|
||||
EXPECT_FALSE(utils::path::contains_trash_directory(dir));
|
||||
}
|
||||
|
||||
{
|
||||
auto dir = L"/recycle.bin";
|
||||
EXPECT_FALSE(utils::path::contains_trash_directory(dir));
|
||||
|
||||
dir = L"/recycle.bin/moose.txt)";
|
||||
EXPECT_FALSE(utils::path::contains_trash_directory(dir));
|
||||
}
|
||||
#endif // defined(_WIN32)
|
||||
}
|
||||
} // namespace repertory
|
||||
|
Reference in New Issue
Block a user