updated build system
This commit is contained in:
@ -21,57 +21,81 @@
|
||||
*/
|
||||
#include "test.hpp"
|
||||
|
||||
namespace {
|
||||
static constexpr const auto file_type_count{1U};
|
||||
}
|
||||
|
||||
namespace repertory {
|
||||
TEST(utils_file, can_create_file) {
|
||||
auto path = test::generate_test_file_name("utils_file");
|
||||
EXPECT_FALSE(utils::file::is_file(path) || utils::file::is_directory(path));
|
||||
for (auto idx = 0U; idx < file_type_count; ++idx) {
|
||||
auto path = test::generate_test_file_name("utils_file");
|
||||
EXPECT_FALSE(utils::file::is_file(path) || utils::file::is_directory(path));
|
||||
|
||||
auto file = utils::file::file::open_or_create_file(path);
|
||||
EXPECT_TRUE(file);
|
||||
auto file = idx == 0U ? utils::file::file::open_or_create_file(path)
|
||||
: utils::file::thread_file::open_or_create_file(path);
|
||||
EXPECT_TRUE(*file);
|
||||
|
||||
EXPECT_TRUE(utils::file::is_file(path));
|
||||
EXPECT_TRUE(utils::file::is_file(path));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(utils_file, can_open_file) {
|
||||
auto path = test::generate_test_file_name("utils_file");
|
||||
for (auto idx = 0U; idx < file_type_count; ++idx) {
|
||||
auto path = test::generate_test_file_name("utils_file");
|
||||
|
||||
{
|
||||
auto file = utils::file::file::open_or_create_file(path);
|
||||
EXPECT_TRUE(file);
|
||||
}
|
||||
{
|
||||
auto file = idx == 0U
|
||||
? utils::file::file::open_or_create_file(path)
|
||||
: utils::file::thread_file::open_or_create_file(path);
|
||||
EXPECT_TRUE(*file);
|
||||
}
|
||||
|
||||
{
|
||||
auto file = utils::file::file::open_file(path);
|
||||
EXPECT_TRUE(file);
|
||||
{
|
||||
auto file = idx == 0U ? utils::file::file::open_file(path)
|
||||
: utils::file::thread_file::open_file(path);
|
||||
EXPECT_TRUE(*file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(utils_file, open_file_fails_if_not_found) {
|
||||
auto path = test::generate_test_file_name("utils_file");
|
||||
for (auto idx = 0U; idx < file_type_count; ++idx) {
|
||||
auto path = test::generate_test_file_name("utils_file");
|
||||
|
||||
auto file = utils::file::file::open_file(path);
|
||||
EXPECT_FALSE(file);
|
||||
auto file = idx == 0U ? utils::file::file::open_file(path)
|
||||
: utils::file::thread_file::open_file(path);
|
||||
EXPECT_FALSE(*file);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(utils_file, write_fails_for_read_only_file) {
|
||||
auto path = test::generate_test_file_name("utils_file");
|
||||
for (auto idx = 0U; idx < file_type_count; ++idx) {
|
||||
auto path = test::generate_test_file_name("utils_file");
|
||||
|
||||
auto file = utils::file::file::open_or_create_file(path, true);
|
||||
EXPECT_TRUE(utils::file::is_file(path));
|
||||
EXPECT_TRUE(file);
|
||||
std::size_t bytes_written{};
|
||||
EXPECT_FALSE(file.write(reinterpret_cast<const unsigned char *>("0"), 1U, 0U,
|
||||
&bytes_written));
|
||||
EXPECT_EQ(0U, bytes_written);
|
||||
auto file = idx == 0U
|
||||
? utils::file::file::open_or_create_file(path, true)
|
||||
: utils::file::thread_file::open_or_create_file(path, true);
|
||||
EXPECT_TRUE(utils::file::is_file(path));
|
||||
EXPECT_TRUE(*file);
|
||||
std::size_t bytes_written{};
|
||||
EXPECT_FALSE(file->write(reinterpret_cast<const unsigned char *>("0"), 1U,
|
||||
0U, &bytes_written));
|
||||
EXPECT_EQ(0U, bytes_written);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(utils_file, can_attach_file) {
|
||||
auto path = test::generate_test_file_name("utils_file");
|
||||
auto file = utils::file::file::open_or_create_file(path);
|
||||
auto file2 = utils::file::file::attach_file(file.get_handle());
|
||||
EXPECT_TRUE(file);
|
||||
EXPECT_TRUE(file2);
|
||||
EXPECT_EQ(file.get_path(), file2.get_path());
|
||||
for (auto idx = 0U; idx < file_type_count; ++idx) {
|
||||
auto path = test::generate_test_file_name("utils_file");
|
||||
auto file = idx == 0U ? utils::file::file::open_or_create_file(path)
|
||||
: utils::file::thread_file::open_or_create_file(path);
|
||||
auto file2 =
|
||||
idx == 0U ? utils::file::file::attach_file(file->get_handle())
|
||||
: utils::file::thread_file::attach_file(file->get_handle());
|
||||
EXPECT_TRUE(*file);
|
||||
EXPECT_TRUE(*file2);
|
||||
EXPECT_EQ(file->get_path(), file2->get_path());
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(PROJECT_ENABLE_JSON)
|
||||
@ -100,7 +124,7 @@ TEST(utils_file, read_and_write_json_file_encrypted) {
|
||||
{
|
||||
auto file = utils::file::file::open_file(path);
|
||||
data_buffer encrypted_data{};
|
||||
EXPECT_TRUE(file.read_all(encrypted_data, 0U));
|
||||
EXPECT_TRUE(file->read_all(encrypted_data, 0U));
|
||||
|
||||
data_buffer decrypted_data{};
|
||||
EXPECT_TRUE(utils::encryption::decrypt_data("moose", encrypted_data,
|
||||
|
Reference in New Issue
Block a user