v2.0.1-rc (#13)
All checks were successful
BlockStorage/repertory_osx_builds/pipeline/head This commit looks good
BlockStorage/repertory_linux_builds/pipeline/head This commit looks good

Reviewed-on: #13
This commit is contained in:
2023-12-10 18:11:20 +00:00
parent f43c41f88a
commit 1b8de3b097
404 changed files with 410072 additions and 146106 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,77 +1,77 @@
/*
Copyright <2018-2023> <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_common.hpp"
#include "comm/curl/curl_comm.hpp"
#include "types/repertory.hpp"
namespace repertory {
TEST(curl_comm, can_create_s3_host_config) {
s3_config config{};
config.bucket = "repertory";
config.url = "https://s3.test.com";
config.region = "any";
auto hc = curl_comm::create_host_config(config, false);
EXPECT_STREQ("https", hc.protocol.c_str());
EXPECT_STREQ("repertory.s3.test.com", hc.host_name_or_ip.c_str());
EXPECT_TRUE(hc.path.empty());
}
TEST(curl_comm, can_create_s3_host_config_with_path_style) {
s3_config config{};
config.bucket = "repertory";
config.url = "https://s3.test.com";
config.region = "any";
auto hc = curl_comm::create_host_config(config, true);
EXPECT_STREQ("https", hc.protocol.c_str());
EXPECT_STREQ("s3.test.com", hc.host_name_or_ip.c_str());
EXPECT_STREQ("/repertory", hc.path.c_str());
}
TEST(curl_comm, can_create_s3_host_config_with_region) {
s3_config config{};
config.bucket = "repertory";
config.url = "https://s3.test.com";
config.region = "any";
config.use_region_in_url = true;
auto hc = curl_comm::create_host_config(config, false);
EXPECT_STREQ("https", hc.protocol.c_str());
EXPECT_STREQ("repertory.s3.any.test.com", hc.host_name_or_ip.c_str());
EXPECT_TRUE(hc.path.empty());
}
TEST(curl_comm, can_create_s3_host_config_with_region_and_path_style) {
s3_config config{};
config.bucket = "repertory";
config.url = "https://s3.test.com";
config.region = "any";
config.use_region_in_url = true;
auto hc = curl_comm::create_host_config(config, true);
EXPECT_STREQ("https", hc.protocol.c_str());
EXPECT_STREQ("s3.any.test.com", hc.host_name_or_ip.c_str());
EXPECT_STREQ("/repertory", hc.path.c_str());
}
} // namespace repertory
/*
Copyright <2018-2023> <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_common.hpp"
#include "comm/curl/curl_comm.hpp"
#include "types/repertory.hpp"
namespace repertory {
TEST(curl_comm, can_create_s3_host_config) {
s3_config config{};
config.bucket = "repertory";
config.url = "https://s3.test.com";
config.region = "any";
auto hc = curl_comm::create_host_config(config, false);
EXPECT_STREQ("https", hc.protocol.c_str());
EXPECT_STREQ("repertory.s3.test.com", hc.host_name_or_ip.c_str());
EXPECT_TRUE(hc.path.empty());
}
TEST(curl_comm, can_create_s3_host_config_with_path_style) {
s3_config config{};
config.bucket = "repertory";
config.url = "https://s3.test.com";
config.region = "any";
auto hc = curl_comm::create_host_config(config, true);
EXPECT_STREQ("https", hc.protocol.c_str());
EXPECT_STREQ("s3.test.com", hc.host_name_or_ip.c_str());
EXPECT_STREQ("/repertory", hc.path.c_str());
}
TEST(curl_comm, can_create_s3_host_config_with_region) {
s3_config config{};
config.bucket = "repertory";
config.url = "https://s3.test.com";
config.region = "any";
config.use_region_in_url = true;
auto hc = curl_comm::create_host_config(config, false);
EXPECT_STREQ("https", hc.protocol.c_str());
EXPECT_STREQ("repertory.s3.any.test.com", hc.host_name_or_ip.c_str());
EXPECT_TRUE(hc.path.empty());
}
TEST(curl_comm, can_create_s3_host_config_with_region_and_path_style) {
s3_config config{};
config.bucket = "repertory";
config.url = "https://s3.test.com";
config.region = "any";
config.use_region_in_url = true;
auto hc = curl_comm::create_host_config(config, true);
EXPECT_STREQ("https", hc.protocol.c_str());
EXPECT_STREQ("s3.any.test.com", hc.host_name_or_ip.c_str());
EXPECT_STREQ("/repertory", hc.path.c_str());
}
} // namespace repertory

124
tests/database_test.cpp Normal file
View File

@@ -0,0 +1,124 @@
/*
Copyright <2018-2023> <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_common.hpp"
#include "database/db_common.hpp"
#include "database/db_insert.hpp"
#include "database/db_select.hpp"
#include "utils/path_utils.hpp"
namespace repertory {
TEST(database, db_insert) {
console_consumer consumer1;
event_system::instance().start();
{
db3_t db3;
{
sqlite3 *db3_ptr{nullptr};
auto res = sqlite3_open_v2(
utils::path::absolute(
utils::path::combine(get_test_dir(), {"test.db3"}))
.c_str(),
&db3_ptr, SQLITE_OPEN_READWRITE, nullptr);
ASSERT_EQ(SQLITE_OK, res);
ASSERT_TRUE(db3_ptr != nullptr);
db3.reset(db3_ptr);
}
auto query = db::db_insert{*db3.get(), "table"}
.column_value("column1", "test9")
.column_value("column2", "test9");
auto query_str = query.dump();
std::cout << query_str << std::endl;
EXPECT_STREQ(
R"(INSERT INTO "table" ("column1", "column2") VALUES (?1, ?2);)",
query_str.c_str());
query = db::db_insert{*db3.get(), "table"}
.or_replace()
.column_value("column1", "test1")
.column_value("column2", "test2");
query_str = query.dump();
std::cout << query_str << std::endl;
EXPECT_STREQ(
R"(INSERT OR REPLACE INTO "table" ("column1", "column2") VALUES (?1, ?2);)",
query_str.c_str());
auto res = query.go();
EXPECT_TRUE(res.ok());
EXPECT_FALSE(res.has_row());
}
event_system::instance().stop();
}
TEST(database, db_select) {
console_consumer consumer1;
event_system::instance().start();
{
db3_t db3;
{
sqlite3 *db3_ptr{nullptr};
auto res = sqlite3_open_v2(
utils::path::combine(get_test_dir(), {"test.db3"}).c_str(), &db3_ptr,
SQLITE_OPEN_READWRITE, nullptr);
ASSERT_EQ(SQLITE_OK, res);
ASSERT_TRUE(db3_ptr != nullptr);
db3.reset(db3_ptr);
}
auto query = db::db_select{*db3.get(), "table"}
.where("column1")
.equals("test1")
.and_where("column2")
.equals("test2");
auto query_str = query.dump();
std::cout << query_str << std::endl;
EXPECT_STREQ(
R"(SELECT * FROM "table" WHERE ("column1"=?1 AND "column2"=?2);)",
query_str.c_str());
auto res = query.go();
EXPECT_TRUE(res.ok());
EXPECT_TRUE(res.has_row());
std::size_t row_count{};
while (res.has_row()) {
std::optional<db::db_select::row> row;
EXPECT_TRUE(res.get_row(row));
EXPECT_TRUE(row.has_value());
if (row.has_value()) {
for (const auto &column : row.value().get_columns()) {
std::cout << column.get_index() << ':';
std::cout << column.get_name() << ':';
std::cout << column.get_value<std::string>() << std::endl;
}
}
++row_count;
}
EXPECT_EQ(std::size_t(1U), row_count);
}
event_system::instance().stop();
}
} // namespace repertory

View File

@@ -1,321 +0,0 @@
/*
Copyright <2018-2023> <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_common.hpp"
#include "fixtures/directory_db_fixture.hpp"
namespace repertory {
static const auto dirs = {"/",
"/root",
"/root/sub1",
"/root/sub2",
"/root/sub2/sub2_sub1",
"/root/sub2/sub2_sub2",
"/root/sub2/sub2_sub2/sub2_sub2_sub1",
"/root/sub3"};
TEST_F(directory_db_test, is_directory) {
for (const auto &dir : dirs) {
EXPECT_EQ(api_error::success, db_->create_directory(dir));
}
for (const auto &dir : dirs) {
EXPECT_TRUE(db_->is_directory(dir));
}
}
TEST_F(directory_db_test, remove_directory) {
for (const auto &dir : dirs) {
EXPECT_EQ(api_error::success, db_->create_directory(dir));
}
EXPECT_EQ(api_error::success, db_->remove_directory("/root/sub2/sub2_sub1"));
EXPECT_FALSE(db_->is_directory("/root/sub2/sub2_sub1"));
EXPECT_EQ(1u, db_->get_sub_directory_count("/root/sub2"));
EXPECT_TRUE(db_->is_directory("/root/sub2/sub2_sub2"));
}
TEST_F(directory_db_test, get_sub_directory_count) {
for (const auto &dir : dirs) {
EXPECT_EQ(api_error::success, db_->create_directory(dir));
}
EXPECT_EQ(1u, db_->get_sub_directory_count("/"));
EXPECT_EQ(3u, db_->get_sub_directory_count("/root"));
EXPECT_EQ(0u, db_->get_sub_directory_count("/root/sub1"));
EXPECT_EQ(2u, db_->get_sub_directory_count("/root/sub2"));
EXPECT_EQ(0u, db_->get_sub_directory_count("/root/sub2/sub2_sub1"));
EXPECT_EQ(1u, db_->get_sub_directory_count("/root/sub2/sub2_sub2"));
EXPECT_EQ(0u, db_->get_sub_directory_count("/root/sub3"));
}
TEST_F(directory_db_test, populate_sub_directories) {
for (const auto &dir : dirs) {
EXPECT_EQ(api_error::success, db_->create_directory(dir));
}
directory_item_list list{};
const auto dump_directory_list = [&]() {
for (const auto &di : list) {
std::cout << di.to_json().dump(2) << std::endl;
}
list.clear();
};
std::cout << "/" << std::endl;
db_->populate_sub_directories(
"/", [](directory_item &) {}, list);
EXPECT_EQ(1u, list.size());
dump_directory_list();
std::cout << std::endl << "/root" << std::endl;
db_->populate_sub_directories(
"/root", [](directory_item &) {}, list);
EXPECT_EQ(3u, list.size());
dump_directory_list();
std::cout << std::endl << "/root/sub1" << std::endl;
db_->populate_sub_directories(
"/root/sub1", [](directory_item &) {}, list);
EXPECT_EQ(0u, list.size());
dump_directory_list();
std::cout << std::endl << "/root/sub2" << std::endl;
db_->populate_sub_directories(
"/root/sub2", [](directory_item &) {}, list);
EXPECT_EQ(2u, list.size());
dump_directory_list();
std::cout << std::endl << "/root/sub2/sub2_sub1" << std::endl;
db_->populate_sub_directories(
"/root/sub2/sub2_sub1", [](directory_item &) {}, list);
EXPECT_EQ(0u, list.size());
dump_directory_list();
std::cout << std::endl << "/root/sub2/sub2_sub2" << std::endl;
db_->populate_sub_directories(
"/root/sub2/sub2_sub2", [](directory_item &) {}, list);
EXPECT_EQ(1u, list.size());
dump_directory_list();
std::cout << std::endl << "/root/sub3" << std::endl;
db_->populate_sub_directories(
"/root/sub3", [](directory_item &) {}, list);
EXPECT_EQ(0u, list.size());
dump_directory_list();
}
TEST_F(directory_db_test, is_file) {
for (const auto &dir : dirs) {
EXPECT_EQ(api_error::success, db_->create_directory(dir));
}
EXPECT_EQ(api_error::success, db_->create_file("/cow.txt"));
EXPECT_TRUE(db_->is_file("/cow.txt"));
EXPECT_FALSE(db_->is_directory("/cow.txt"));
EXPECT_EQ(api_error::item_exists, db_->create_file("/cow.txt"));
EXPECT_EQ(api_error::item_exists, db_->create_directory("/cow.txt"));
}
TEST_F(directory_db_test, remove_file) {
for (const auto &dir : dirs) {
EXPECT_EQ(api_error::success, db_->create_directory(dir));
}
EXPECT_EQ(api_error::success, db_->create_file("/cow.txt"));
EXPECT_EQ(api_error::directory_not_found, db_->remove_directory("/cow.txt"));
EXPECT_TRUE(db_->remove_file("/cow.txt"));
EXPECT_FALSE(db_->is_file("/cow.txt"));
}
TEST_F(directory_db_test, get_directory_item_count) {
EXPECT_EQ(api_error::success, db_->create_directory("/"));
EXPECT_EQ(api_error::success, db_->create_file("/cow.txt"));
EXPECT_EQ(api_error::success, db_->create_file("/cow2.txt"));
EXPECT_EQ(api_error::success, db_->create_directory("/cow"));
EXPECT_EQ(3u, db_->get_directory_item_count("/"));
}
TEST_F(directory_db_test, get_file) {
EXPECT_EQ(api_error::success, db_->create_directory("/"));
EXPECT_EQ(api_error::success, db_->create_file("/cow.txt"));
api_file file{};
EXPECT_EQ(api_error::success,
db_->get_file("/cow.txt", file, [](api_file &file) {
EXPECT_STREQ("/cow.txt", file.api_path.c_str());
}));
EXPECT_STREQ("/cow.txt", file.api_path.c_str());
}
TEST_F(directory_db_test, get_file_list) {
EXPECT_EQ(api_error::success, db_->create_directory("/"));
EXPECT_EQ(api_error::success, db_->create_file("/cow.txt"));
EXPECT_EQ(api_error::success, db_->create_file("/cow2.txt"));
api_file_list list;
int i = 0;
EXPECT_EQ(api_error::success, db_->get_file_list(list, [&i](api_file &file) {
if (i++ == 0) {
EXPECT_STREQ("/cow.txt", file.api_path.c_str());
} else {
EXPECT_STREQ("/cow2.txt", file.api_path.c_str());
}
}));
EXPECT_EQ(std::size_t(2u), list.size());
EXPECT_STREQ("/cow.txt", list[0u].api_path.c_str());
EXPECT_STREQ("/cow2.txt", list[1u].api_path.c_str());
}
TEST_F(directory_db_test, get_total_item_count) {
EXPECT_EQ(api_error::success, db_->create_directory("/"));
EXPECT_EQ(api_error::success, db_->create_file("/cow.txt"));
EXPECT_EQ(api_error::success, db_->create_file("/cow2.txt"));
EXPECT_EQ(api_error::success, db_->create_directory("/cow"));
EXPECT_EQ(api_error::success, db_->create_directory("/cow/moose"));
EXPECT_EQ(std::uint64_t(5), db_->get_total_item_count());
}
TEST_F(directory_db_test, populate_directory_files) {
EXPECT_EQ(api_error::success, db_->create_directory("/"));
EXPECT_EQ(api_error::success, db_->create_file("/cow.txt"));
EXPECT_EQ(api_error::success, db_->create_file("/cow2.txt"));
directory_item_list list;
int i = 0;
db_->populate_directory_files(
"/",
[&i](directory_item &di) {
di.meta[META_SIZE] = std::to_string(i + 1);
EXPECT_FALSE(di.directory);
if (i++ == 0) {
EXPECT_STREQ("/cow.txt", &di.api_path[0]);
} else {
EXPECT_STREQ("/cow2.txt", &di.api_path[0]);
}
},
list);
EXPECT_EQ(std::size_t(2u), list.size());
EXPECT_EQ(1u, list[0].size);
EXPECT_STREQ("/cow.txt", &list[0].api_path[0]);
EXPECT_EQ(2u, list[1].size);
EXPECT_STREQ("/cow2.txt", &list[1].api_path[0]);
}
TEST_F(directory_db_test, create_directory_fails_if_directory_exists) {
for (const auto &dir : dirs) {
EXPECT_EQ(api_error::success, db_->create_directory(dir));
}
EXPECT_EQ(api_error::directory_exists, db_->create_file("/root/sub1"));
EXPECT_TRUE(db_->is_directory("/root/sub1"));
}
TEST_F(directory_db_test, create_file_fails_if_file_exists) {
for (const auto &dir : dirs) {
EXPECT_EQ(api_error::success, db_->create_directory(dir));
}
EXPECT_EQ(api_error::success, db_->create_file("/cow.txt"));
EXPECT_EQ(api_error::item_exists, db_->create_directory("/cow.txt"));
}
TEST_F(directory_db_test, create_file_fails_if_parent_does_not_exist) {
for (const auto &dir : dirs) {
EXPECT_EQ(api_error::success, db_->create_directory(dir));
}
EXPECT_EQ(api_error::directory_not_found, db_->create_file("/moose/cow.txt"));
}
TEST_F(directory_db_test, create_directory_fails_if_parent_does_not_exist) {
for (const auto &dir : dirs) {
EXPECT_EQ(api_error::success, db_->create_directory(dir));
}
EXPECT_EQ(api_error::directory_not_found, db_->create_file("/cow/moose"));
}
TEST_F(directory_db_test, remove_file_fails_if_directory_exists) {
for (const auto &dir : dirs) {
EXPECT_EQ(api_error::success, db_->create_directory(dir));
}
EXPECT_FALSE(db_->remove_file("/root/sub1"));
}
TEST_F(directory_db_test, remove_directory_fails_if_file_exists) {
for (const auto &dir : dirs) {
EXPECT_EQ(api_error::success, db_->create_directory(dir));
}
EXPECT_EQ(api_error::success, db_->create_file("/cow.txt"));
EXPECT_EQ(api_error::directory_not_found, db_->remove_directory("/cow.txt"));
}
TEST_F(directory_db_test, remove_directory_fails_if_sub_directories_exist) {
EXPECT_EQ(api_error::success, db_->create_directory("/"));
EXPECT_EQ(api_error::success, db_->create_directory("/sub"));
EXPECT_EQ(api_error::success, db_->create_directory("/sub/sub2"));
EXPECT_EQ(api_error::directory_not_empty, db_->remove_directory("/sub"));
EXPECT_TRUE(db_->is_directory("/sub"));
EXPECT_TRUE(db_->is_directory("/sub/sub2"));
}
TEST_F(directory_db_test, remove_directory_fails_if_files_exist) {
EXPECT_EQ(api_error::success, db_->create_directory("/"));
EXPECT_EQ(api_error::success, db_->create_directory("/sub"));
EXPECT_EQ(api_error::success, db_->create_file("/sub/test.txt"));
EXPECT_EQ(api_error::directory_not_empty, db_->remove_directory("/sub"));
EXPECT_TRUE(db_->is_directory("/sub"));
EXPECT_TRUE(db_->is_file("/sub/test.txt"));
}
TEST_F(directory_db_test,
remove_directory_fails_for_root_directory_by_default) {
EXPECT_EQ(api_error::success, db_->create_directory("/"));
EXPECT_EQ(api_error::access_denied, db_->remove_directory("/"));
EXPECT_TRUE(db_->is_directory("/"));
}
TEST_F(
directory_db_test,
remove_directory_succeeds_for_root_directory_if_allow_remove_root_is_true) {
EXPECT_EQ(api_error::success, db_->create_directory("/"));
EXPECT_EQ(api_error::success, db_->remove_directory("/", true));
EXPECT_FALSE(db_->is_directory("/"));
}
} // namespace repertory

View File

@@ -1,172 +1,170 @@
/*
Copyright <2018-2023> <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_common.hpp"
#include "app_config.hpp"
#include "events/consumers/console_consumer.hpp"
#include "providers/encrypt/encrypt_provider.hpp"
#include "utils/path_utils.hpp"
namespace repertory {
/* TEST(encrypt_provider, can_construct_encrypt_provider) {
ASSERT_TRUE(
utils::file::delete_directory_recursively("./encrypt_provider_test"));
{
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::encrypt, "./encrypt_provider_test");
encrypt_provider provider(cfg);
event_system::instance().stop();
}
ASSERT_TRUE(
utils::file::delete_directory_recursively("./encrypt_provider_test"));
}
TEST(encrypt_provider, can_get_file_list) {
ASSERT_TRUE(
utils::file::delete_directory_recursively("./encrypt_provider_test"));
{
console_consumer cc{};
event_system::instance().start();
const auto path = std::filesystem::path(utils::path::absolute(__FILE__))
.parent_path()
.string();
app_config cfg(provider_type::encrypt, "./encrypt_provider_test");
EXPECT_STREQ(
path.c_str(),
cfg.set_value_by_name("EncryptConfig.Path", path.c_str()).c_str());
EXPECT_STREQ(
"test_token",
cfg.set_value_by_name("EncryptConfig.EncryptionToken", "test_token")
.c_str());
encrypt_provider provider(cfg);
api_file_list list{};
EXPECT_EQ(api_error::success, provider.get_file_list(list));
api_file_list list2{};
EXPECT_EQ(api_error::success, provider.get_file_list(list2));
EXPECT_EQ(list.size(), list2.size());
for (std::size_t idx = 0U; idx < list.size(); idx++) {
EXPECT_STREQ(list.at(idx).api_path.c_str(),
list2.at(idx).api_path.c_str());
EXPECT_STREQ(list.at(idx).api_parent.c_str(),
list2.at(idx).api_parent.c_str());
EXPECT_EQ(list.at(idx).accessed_date, list2.at(idx).accessed_date);
EXPECT_EQ(list.at(idx).changed_date, list2.at(idx).changed_date);
EXPECT_TRUE(list.at(idx).encryption_token.empty());
EXPECT_TRUE(list2.at(idx).encryption_token.empty());
EXPECT_EQ(list.at(idx).file_size, list2.at(idx).file_size);
EXPECT_TRUE(list.at(idx).key.empty());
EXPECT_TRUE(list2.at(idx).key.empty());
EXPECT_EQ(list.at(idx).modified_date, list2.at(idx).modified_date);
EXPECT_STREQ(list.at(idx).source_path.c_str(),
list2.at(idx).source_path.c_str());
}
event_system::instance().stop();
}
ASSERT_TRUE(
utils::file::delete_directory_recursively("./encrypt_provider_test"));
}
TEST(encrypt_provider, can_encrypt_and_decrypt_file) {
ASSERT_TRUE(
utils::file::delete_directory_recursively("./encrypt_provider_test"));
{
console_consumer cc{};
event_system::instance().start();
const auto path = std::filesystem::path(utils::path::absolute(__FILE__))
.parent_path()
.string();
app_config cfg(provider_type::encrypt, "./encrypt_provider_test");
EXPECT_STREQ(
path.c_str(),
cfg.set_value_by_name("EncryptConfig.Path", path.c_str()).c_str());
EXPECT_STREQ(
"test_token",
cfg.set_value_by_name("EncryptConfig.EncryptionToken", "test_token")
.c_str());
encrypt_provider provider(cfg);
api_file_list list{};
EXPECT_EQ(api_error::success, provider.get_file_list(list));
for (const auto &file : list) {
std::string file_path{file.api_path};
EXPECT_EQ(api_error::success,
utils::encryption::decrypt_file_path(
cfg.get_encrypt_config().encryption_token, file_path));
file_path =
utils::path::combine(cfg.get_encrypt_config().path, {file_path});
EXPECT_TRUE(std::filesystem::equivalent(file.source_path, file_path));
std::vector<char> encrypted_data{};
stop_type stop_requested = false;
EXPECT_EQ(api_error::success,
provider.read_file_bytes(file.api_path, file.file_size, 0U,
encrypted_data, stop_requested));
EXPECT_EQ(file.file_size, encrypted_data.size());
std::vector<char> decrypted_data{};
EXPECT_TRUE(utils::encryption::decrypt_data(
cfg.get_encrypt_config().encryption_token, encrypted_data,
decrypted_data));
native_file::native_file_ptr nf{};
EXPECT_EQ(api_error::success, native_file::open(file.source_path, nf));
std::uint64_t file_size{};
EXPECT_TRUE(nf->get_file_size(file_size));
EXPECT_EQ(file_size, decrypted_data.size());
std::size_t bytes_read{};
std::vector<char> file_data{};
file_data.resize(file_size);
EXPECT_TRUE(nf->read_bytes(file_data.data(), file_size, 0U, bytes_read));
nf->close();
EXPECT_EQ(file_size, bytes_read);
for (std::uint64_t i = 0U; i < bytes_read; i++) {
ASSERT_EQ(file_data[i], decrypted_data[i]);
}
}
event_system::instance().stop();
}
ASSERT_TRUE(
utils::file::delete_directory_recursively("./encrypt_provider_test"));
} */
} // namespace repertory
/*
Copyright <2018-2023> <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_common.hpp"
#include "app_config.hpp"
#include "events/consumers/console_consumer.hpp"
#include "providers/encrypt/encrypt_provider.hpp"
#include "utils/path_utils.hpp"
namespace repertory {
/* TEST(encrypt_provider, can_construct_encrypt_provider) {
ASSERT_TRUE(
utils::file::delete_directory_recursively("./encrypt_provider_test"));
{
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::encrypt, "./encrypt_provider_test");
encrypt_provider provider(cfg);
event_system::instance().stop();
}
ASSERT_TRUE(
utils::file::delete_directory_recursively("./encrypt_provider_test"));
}
TEST(encrypt_provider, can_get_file_list) {
ASSERT_TRUE(
utils::file::delete_directory_recursively("./encrypt_provider_test"));
{
console_consumer cc{};
event_system::instance().start();
const auto path = std::filesystem::path(utils::path::absolute(__FILE__))
.parent_path()
.string();
app_config cfg(provider_type::encrypt, "./encrypt_provider_test");
EXPECT_STREQ(
path.c_str(),
cfg.set_value_by_name("EncryptConfig.Path", path.c_str()).c_str());
EXPECT_STREQ(
"test_token",
cfg.set_value_by_name("EncryptConfig.EncryptionToken", "test_token")
.c_str());
encrypt_provider provider(cfg);
api_file_list list{};
EXPECT_EQ(api_error::success, provider.get_file_list(list));
api_file_list list2{};
EXPECT_EQ(api_error::success, provider.get_file_list(list2));
EXPECT_EQ(list.size(), list2.size());
for (std::size_t idx = 0U; idx < list.size(); idx++) {
EXPECT_STREQ(list.at(idx).api_path.c_str(),
list2.at(idx).api_path.c_str());
EXPECT_STREQ(list.at(idx).api_parent.c_str(),
list2.at(idx).api_parent.c_str());
EXPECT_EQ(list.at(idx).accessed_date, list2.at(idx).accessed_date);
EXPECT_EQ(list.at(idx).changed_date, list2.at(idx).changed_date);
EXPECT_EQ(list.at(idx).file_size, list2.at(idx).file_size);
EXPECT_TRUE(list.at(idx).key.empty());
EXPECT_TRUE(list2.at(idx).key.empty());
EXPECT_EQ(list.at(idx).modified_date, list2.at(idx).modified_date);
EXPECT_STREQ(list.at(idx).source_path.c_str(),
list2.at(idx).source_path.c_str());
}
event_system::instance().stop();
}
ASSERT_TRUE(
utils::file::delete_directory_recursively("./encrypt_provider_test"));
}
TEST(encrypt_provider, can_encrypt_and_decrypt_file) {
ASSERT_TRUE(
utils::file::delete_directory_recursively("./encrypt_provider_test"));
{
console_consumer cc{};
event_system::instance().start();
const auto path = std::filesystem::path(utils::path::absolute(__FILE__))
.parent_path()
.string();
app_config cfg(provider_type::encrypt, "./encrypt_provider_test");
EXPECT_STREQ(
path.c_str(),
cfg.set_value_by_name("EncryptConfig.Path", path.c_str()).c_str());
EXPECT_STREQ(
"test_token",
cfg.set_value_by_name("EncryptConfig.EncryptionToken", "test_token")
.c_str());
encrypt_provider provider(cfg);
api_file_list list{};
EXPECT_EQ(api_error::success, provider.get_file_list(list));
for (const auto &file : list) {
std::string file_path{file.api_path};
EXPECT_EQ(api_error::success,
utils::encryption::decrypt_file_path(
cfg.get_encrypt_config().encryption_token, file_path));
file_path =
utils::path::combine(cfg.get_encrypt_config().path, {file_path});
EXPECT_TRUE(std::filesystem::equivalent(file.source_path, file_path));
std::vector<char> encrypted_data{};
stop_type stop_requested = false;
EXPECT_EQ(api_error::success,
provider.read_file_bytes(file.api_path, file.file_size, 0U,
encrypted_data, stop_requested));
EXPECT_EQ(file.file_size, encrypted_data.size());
std::vector<char> decrypted_data{};
EXPECT_TRUE(utils::encryption::decrypt_data(
cfg.get_encrypt_config().encryption_token, encrypted_data,
decrypted_data));
native_file::native_file_ptr nf{};
EXPECT_EQ(api_error::success, native_file::open(file.source_path, nf));
std::uint64_t file_size{};
EXPECT_TRUE(nf->get_file_size(file_size));
EXPECT_EQ(file_size, decrypted_data.size());
std::size_t bytes_read{};
std::vector<char> file_data{};
file_data.resize(file_size);
EXPECT_TRUE(nf->read_bytes(file_data.data(), file_size, 0U, bytes_read));
nf->close();
EXPECT_EQ(file_size, bytes_read);
for (std::uint64_t i = 0U; i < bytes_read; i++) {
ASSERT_EQ(file_data[i], decrypted_data[i]);
}
}
event_system::instance().stop();
}
ASSERT_TRUE(
utils::file::delete_directory_recursively("./encrypt_provider_test"));
} */
} // namespace repertory

View File

@@ -1,272 +1,282 @@
/*
Copyright <2018-2023> <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_common.hpp"
#include "types/repertory.hpp"
#include "utils/encrypting_reader.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
namespace repertory {
static std::string get_source_file_name() {
return generate_test_file_name("./", "encrypting_reader");
}
TEST(encrypting_reader, get_encrypted_file_name) {
const auto source_file_name = get_source_file_name();
ASSERT_TRUE(utils::file::retry_delete_file(source_file_name));
const auto token = std::string("moose");
auto source_file = create_random_file(source_file_name, 1024ul);
EXPECT_TRUE(source_file != nullptr);
if (source_file) {
stop_type stop_requested = false;
utils::encryption::encrypting_reader reader("test.dat", source_file_name,
stop_requested, token);
auto file_name = reader.get_encrypted_file_name();
std::cout << file_name << std::endl;
EXPECT_EQ(api_error::success,
utils::encryption::decrypt_file_name(token, file_name));
std::cout << file_name << std::endl;
EXPECT_STREQ("test.dat", file_name.c_str());
source_file->close();
}
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
}
TEST(encrypting_reader, file_data) {
const auto source_file_name = get_source_file_name();
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
const auto token = std::string("moose");
auto source_file = create_random_file(
source_file_name,
8u * utils::encryption::encrypting_reader::get_data_chunk_size());
EXPECT_TRUE(source_file != nullptr);
if (source_file) {
stop_type stop_requested = false;
utils::encryption::encrypting_reader reader("test.dat", source_file_name,
stop_requested, token);
for (std::uint8_t i = 0u; i < 8u; i++) {
data_buffer buffer(
utils::encryption::encrypting_reader::get_encrypted_chunk_size());
for (std::uint8_t j = 0u; j < 2u; j++) {
EXPECT_EQ(buffer.size() / 2u,
utils::encryption::encrypting_reader::reader_function(
&buffer[(buffer.size() / 2u) * j], buffer.size() / 2u, 1u,
&reader));
}
data_buffer decrypted_data;
EXPECT_TRUE(
utils::encryption::decrypt_data(token, buffer, decrypted_data));
EXPECT_EQ(utils::encryption::encrypting_reader::get_data_chunk_size(),
decrypted_data.size());
std::size_t bytes_read{};
data_buffer file_data(decrypted_data.size());
EXPECT_TRUE(source_file->read_bytes(
&file_data[0u], file_data.size(),
utils::encryption::encrypting_reader::get_data_chunk_size() * i,
bytes_read));
EXPECT_EQ(0, std::memcmp(&file_data[0u], &decrypted_data[0u],
file_data.size()));
}
source_file->close();
}
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
}
TEST(encrypting_reader, file_data_in_multiple_chunks) {
const auto source_file_name = get_source_file_name();
ASSERT_TRUE(utils::file::retry_delete_file(source_file_name));
const auto token = std::string("moose");
auto source_file = create_random_file(
source_file_name,
8u * utils::encryption::encrypting_reader::get_data_chunk_size());
EXPECT_TRUE(source_file != nullptr);
if (source_file) {
stop_type stop_requested = false;
utils::encryption::encrypting_reader reader("test.dat", source_file_name,
stop_requested, token);
for (std::uint8_t i = 0u; i < 8u; i += 2u) {
data_buffer buffer(
utils::encryption::encrypting_reader::get_encrypted_chunk_size() *
2u);
EXPECT_EQ(buffer.size(),
utils::encryption::encrypting_reader::reader_function(
&buffer[0u], buffer.size(), 1u, &reader));
for (std::uint8_t j = 0u; j < 2u; j++) {
data_buffer decrypted_data;
const auto offset = (j * (buffer.size() / 2u));
EXPECT_TRUE(utils::encryption::decrypt_data(
token,
data_buffer(buffer.begin() + offset,
buffer.begin() + offset + (buffer.size() / 2u)),
decrypted_data));
EXPECT_EQ(utils::encryption::encrypting_reader::get_data_chunk_size(),
decrypted_data.size());
std::size_t bytes_read{};
data_buffer file_data(decrypted_data.size());
EXPECT_TRUE(source_file->read_bytes(
&file_data[0u], file_data.size(),
(utils::encryption::encrypting_reader::get_data_chunk_size() * i) +
(j *
utils::encryption::encrypting_reader::get_data_chunk_size()),
bytes_read));
EXPECT_EQ(0, std::memcmp(&file_data[0u], &decrypted_data[0u],
file_data.size()));
}
}
source_file->close();
}
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
}
TEST(encrypting_reader, file_data_as_stream) {
const auto source_file_name = get_source_file_name();
ASSERT_TRUE(utils::file::retry_delete_file(source_file_name));
const auto token = std::string("moose");
auto source_file = create_random_file(
source_file_name,
8u * utils::encryption::encrypting_reader::get_data_chunk_size());
EXPECT_TRUE(source_file != nullptr);
if (source_file) {
stop_type stop_requested = false;
utils::encryption::encrypting_reader reader("test.dat", source_file_name,
stop_requested, token);
auto io_stream = reader.create_iostream();
EXPECT_FALSE(io_stream->seekg(0, std::ios_base::end).fail());
EXPECT_TRUE(io_stream->good());
EXPECT_EQ(reader.get_total_size(),
static_cast<std::uint64_t>(io_stream->tellg()));
EXPECT_FALSE(io_stream->seekg(0, std::ios_base::beg).fail());
EXPECT_TRUE(io_stream->good());
for (std::uint8_t i = 0u; i < 8u; i++) {
data_buffer buffer(
utils::encryption::encrypting_reader::get_encrypted_chunk_size());
EXPECT_FALSE(io_stream->seekg(i * buffer.size()).fail());
EXPECT_TRUE(io_stream->good());
for (std::uint8_t j = 0u; j < 2u; j++) {
EXPECT_FALSE(
io_stream
->read(&buffer[(buffer.size() / 2u) * j], buffer.size() / 2u)
.fail());
EXPECT_TRUE(io_stream->good());
}
data_buffer decrypted_data;
EXPECT_TRUE(
utils::encryption::decrypt_data(token, buffer, decrypted_data));
EXPECT_EQ(utils::encryption::encrypting_reader::get_data_chunk_size(),
decrypted_data.size());
std::size_t bytes_read{};
data_buffer file_data(decrypted_data.size());
EXPECT_TRUE(source_file->read_bytes(
&file_data[0u], file_data.size(),
utils::encryption::encrypting_reader::get_data_chunk_size() * i,
bytes_read));
EXPECT_EQ(0, std::memcmp(&file_data[0u], &decrypted_data[0u],
file_data.size()));
}
source_file->close();
}
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
}
TEST(encrypting_reader, file_data_in_multiple_chunks_as_stream) {
const auto source_file_name = get_source_file_name();
ASSERT_TRUE(utils::file::retry_delete_file(source_file_name));
const auto token = std::string("moose");
auto source_file = create_random_file(
source_file_name,
8u * utils::encryption::encrypting_reader::get_data_chunk_size());
EXPECT_TRUE(source_file != nullptr);
if (source_file) {
stop_type stop_requested = false;
utils::encryption::encrypting_reader reader("test.dat", source_file_name,
stop_requested, token);
auto io_stream = reader.create_iostream();
EXPECT_FALSE(io_stream->seekg(0, std::ios_base::end).fail());
EXPECT_TRUE(io_stream->good());
EXPECT_EQ(reader.get_total_size(),
static_cast<std::uint64_t>(io_stream->tellg()));
EXPECT_FALSE(io_stream->seekg(0, std::ios_base::beg).fail());
EXPECT_TRUE(io_stream->good());
for (std::uint8_t i = 0u; i < 8u; i += 2u) {
data_buffer buffer(
utils::encryption::encrypting_reader::get_encrypted_chunk_size() *
2u);
EXPECT_FALSE(io_stream->read(&buffer[0u], buffer.size()).fail());
EXPECT_TRUE(io_stream->good());
for (std::uint8_t j = 0u; j < 2u; j++) {
data_buffer decrypted_data;
const auto offset = (j * (buffer.size() / 2u));
EXPECT_TRUE(utils::encryption::decrypt_data(
token,
data_buffer(buffer.begin() + offset,
buffer.begin() + offset + (buffer.size() / 2u)),
decrypted_data));
EXPECT_EQ(utils::encryption::encrypting_reader::get_data_chunk_size(),
decrypted_data.size());
std::size_t bytes_read{};
data_buffer file_data(decrypted_data.size());
EXPECT_TRUE(source_file->read_bytes(
&file_data[0u], file_data.size(),
(utils::encryption::encrypting_reader::get_data_chunk_size() * i) +
(j *
utils::encryption::encrypting_reader::get_data_chunk_size()),
bytes_read));
EXPECT_EQ(0, std::memcmp(&file_data[0u], &decrypted_data[0u],
file_data.size()));
}
}
source_file->close();
}
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
}
} // namespace repertory
/*
Copyright <2018-2023> <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_common.hpp"
#include "types/repertory.hpp"
#include "utils/encrypting_reader.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
namespace repertory {
static auto get_source_file_name() -> std::string {
return generate_test_file_name("./", "encrypting_reader");
}
TEST(encrypting_reader, get_encrypted_file_name) {
const auto source_file_name = get_source_file_name();
ASSERT_TRUE(utils::file::retry_delete_file(source_file_name));
const auto token = std::string("moose");
auto source_file = create_random_file(source_file_name, 1024UL);
EXPECT_TRUE(source_file != nullptr);
if (source_file) {
stop_type stop_requested = false;
utils::encryption::encrypting_reader reader(
"test.dat", source_file_name, stop_requested, token, std::nullopt);
auto file_name = reader.get_encrypted_file_name();
std::cout << file_name << std::endl;
EXPECT_EQ(api_error::success,
utils::encryption::decrypt_file_name(token, file_name));
std::cout << file_name << std::endl;
EXPECT_STREQ("test.dat", file_name.c_str());
source_file->close();
}
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
}
TEST(encrypting_reader, file_data) {
const auto source_file_name = get_source_file_name();
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
const auto token = std::string("moose");
auto source_file = create_random_file(
source_file_name,
8U * utils::encryption::encrypting_reader::get_data_chunk_size());
EXPECT_TRUE(source_file != nullptr);
if (source_file) {
stop_type stop_requested = false;
utils::encryption::encrypting_reader reader("test.dat", source_file_name,
stop_requested, token);
for (std::uint8_t i = 0U; i < 8U; i++) {
data_buffer buffer(
utils::encryption::encrypting_reader::get_encrypted_chunk_size());
for (std::uint8_t j = 0U; j < 2U; j++) {
EXPECT_EQ(buffer.size() / 2U,
utils::encryption::encrypting_reader::reader_function(
&buffer[(buffer.size() / 2U) * j], buffer.size() / 2U, 1U,
&reader));
}
data_buffer decrypted_data;
EXPECT_TRUE(
utils::encryption::decrypt_data(token, buffer, decrypted_data));
EXPECT_EQ(utils::encryption::encrypting_reader::get_data_chunk_size(),
decrypted_data.size());
std::size_t bytes_read{};
data_buffer file_data(decrypted_data.size());
EXPECT_TRUE(source_file->read_bytes(
file_data.data(), file_data.size(),
utils::encryption::encrypting_reader::get_data_chunk_size() * i,
bytes_read));
EXPECT_EQ(0, std::memcmp(file_data.data(), decrypted_data.data(),
file_data.size()));
}
source_file->close();
}
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
}
TEST(encrypting_reader, file_data_in_multiple_chunks) {
const auto source_file_name = get_source_file_name();
ASSERT_TRUE(utils::file::retry_delete_file(source_file_name));
const auto token = std::string("moose");
auto source_file = create_random_file(
source_file_name,
8U * utils::encryption::encrypting_reader::get_data_chunk_size());
EXPECT_TRUE(source_file != nullptr);
if (source_file) {
stop_type stop_requested = false;
utils::encryption::encrypting_reader reader("test.dat", source_file_name,
stop_requested, token);
for (std::uint8_t i = 0U; i < 8U; i += 2U) {
data_buffer buffer(
utils::encryption::encrypting_reader::get_encrypted_chunk_size() *
2U);
EXPECT_EQ(buffer.size(),
utils::encryption::encrypting_reader::reader_function(
buffer.data(), buffer.size(), 1U, &reader));
for (std::uint8_t j = 0U; j < 2U; j++) {
data_buffer decrypted_data;
const auto offset = (j * (buffer.size() / 2U));
EXPECT_TRUE(utils::encryption::decrypt_data(
token,
data_buffer(
std::next(buffer.begin(), static_cast<std::int64_t>(offset)),
std::next(buffer.begin(), static_cast<std::int64_t>(
offset + (buffer.size() / 2U)))),
decrypted_data));
EXPECT_EQ(utils::encryption::encrypting_reader::get_data_chunk_size(),
decrypted_data.size());
std::size_t bytes_read{};
data_buffer file_data(decrypted_data.size());
EXPECT_TRUE(source_file->read_bytes(
file_data.data(), file_data.size(),
(utils::encryption::encrypting_reader::get_data_chunk_size() * i) +
(j *
utils::encryption::encrypting_reader::get_data_chunk_size()),
bytes_read));
EXPECT_EQ(0, std::memcmp(file_data.data(), decrypted_data.data(),
file_data.size()));
}
}
source_file->close();
}
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
}
TEST(encrypting_reader, file_data_as_stream) {
const auto source_file_name = get_source_file_name();
ASSERT_TRUE(utils::file::retry_delete_file(source_file_name));
const auto token = std::string("moose");
auto source_file = create_random_file(
source_file_name,
8U * utils::encryption::encrypting_reader::get_data_chunk_size());
EXPECT_TRUE(source_file != nullptr);
if (source_file) {
stop_type stop_requested = false;
utils::encryption::encrypting_reader reader("test.dat", source_file_name,
stop_requested, token);
auto io_stream = reader.create_iostream();
EXPECT_FALSE(io_stream->seekg(0, std::ios_base::end).fail());
EXPECT_TRUE(io_stream->good());
EXPECT_EQ(reader.get_total_size(),
static_cast<std::uint64_t>(io_stream->tellg()));
EXPECT_FALSE(io_stream->seekg(0, std::ios_base::beg).fail());
EXPECT_TRUE(io_stream->good());
for (std::uint8_t i = 0U; i < 8U; i++) {
data_buffer buffer(
utils::encryption::encrypting_reader::get_encrypted_chunk_size());
EXPECT_FALSE(
io_stream->seekg(static_cast<std::streamoff>(i * buffer.size()))
.fail());
EXPECT_TRUE(io_stream->good());
for (std::uint8_t j = 0U; j < 2U; j++) {
EXPECT_FALSE(
io_stream
->read(&buffer[(buffer.size() / 2U) * j],
static_cast<std::streamsize>(buffer.size()) / 2U)
.fail());
EXPECT_TRUE(io_stream->good());
}
data_buffer decrypted_data;
EXPECT_TRUE(
utils::encryption::decrypt_data(token, buffer, decrypted_data));
EXPECT_EQ(utils::encryption::encrypting_reader::get_data_chunk_size(),
decrypted_data.size());
std::size_t bytes_read{};
data_buffer file_data(decrypted_data.size());
EXPECT_TRUE(source_file->read_bytes(
file_data.data(), file_data.size(),
utils::encryption::encrypting_reader::get_data_chunk_size() * i,
bytes_read));
EXPECT_EQ(0, std::memcmp(file_data.data(), decrypted_data.data(),
file_data.size()));
}
source_file->close();
}
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
}
TEST(encrypting_reader, file_data_in_multiple_chunks_as_stream) {
const auto source_file_name = get_source_file_name();
ASSERT_TRUE(utils::file::retry_delete_file(source_file_name));
const auto token = std::string("moose");
auto source_file = create_random_file(
source_file_name,
8u * utils::encryption::encrypting_reader::get_data_chunk_size());
EXPECT_TRUE(source_file != nullptr);
if (source_file) {
stop_type stop_requested = false;
utils::encryption::encrypting_reader reader("test.dat", source_file_name,
stop_requested, token);
auto io_stream = reader.create_iostream();
EXPECT_FALSE(io_stream->seekg(0, std::ios_base::end).fail());
EXPECT_TRUE(io_stream->good());
EXPECT_EQ(reader.get_total_size(),
static_cast<std::uint64_t>(io_stream->tellg()));
EXPECT_FALSE(io_stream->seekg(0, std::ios_base::beg).fail());
EXPECT_TRUE(io_stream->good());
for (std::uint8_t i = 0U; i < 8U; i += 2U) {
data_buffer buffer(
utils::encryption::encrypting_reader::get_encrypted_chunk_size() *
2U);
EXPECT_FALSE(
io_stream
->read(buffer.data(), static_cast<std::streamsize>(buffer.size()))
.fail());
EXPECT_TRUE(io_stream->good());
for (std::uint8_t j = 0U; j < 2U; j++) {
data_buffer decrypted_data;
const auto offset = (j * (buffer.size() / 2U));
EXPECT_TRUE(utils::encryption::decrypt_data(
token,
data_buffer(
std::next(buffer.begin(), static_cast<std::int64_t>(offset)),
std::next(buffer.begin(), static_cast<std::int64_t>(
offset + (buffer.size() / 2U)))),
decrypted_data));
EXPECT_EQ(utils::encryption::encrypting_reader::get_data_chunk_size(),
decrypted_data.size());
std::size_t bytes_read{};
data_buffer file_data(decrypted_data.size());
EXPECT_TRUE(source_file->read_bytes(
file_data.data(), file_data.size(),
(utils::encryption::encrypting_reader::get_data_chunk_size() * i) +
(j *
utils::encryption::encrypting_reader::get_data_chunk_size()),
bytes_read));
EXPECT_EQ(0, std::memcmp(file_data.data(), decrypted_data.data(),
file_data.size()));
}
}
source_file->close();
}
EXPECT_TRUE(utils::file::retry_delete_file(source_file_name));
}
} // namespace repertory

View File

@@ -1,125 +1,125 @@
/*
Copyright <2018-2023> <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_common.hpp"
#include "types/repertory.hpp"
#include "utils/encryption.hpp"
#include "utils/file_utils.hpp"
namespace repertory {
static const std::string buffer = "cow moose dog chicken";
static const std::string token = "moose";
static void test_encrypted_result(const data_buffer &result) {
EXPECT_EQ(buffer.size() +
utils::encryption::encrypting_reader::get_header_size(),
result.size());
std::string data;
EXPECT_TRUE(utils::encryption::decrypt_data(token, result, data));
EXPECT_EQ(buffer.size(), data.size());
EXPECT_STREQ(buffer.c_str(), data.c_str());
}
TEST(encryption, generate_key) {
const auto key = utils::encryption::generate_key(token);
const auto str = utils::to_hex_string(key);
EXPECT_STREQ(
"182072537ada59e4d6b18034a80302ebae935f66adbdf0f271d3d36309c2d481",
str.c_str());
}
TEST(encryption, encrypt_data_buffer) {
data_buffer result;
utils::encryption::encrypt_data(token, buffer, result);
test_encrypted_result(result);
}
TEST(encryption, encrypt_data_buffer_with_key) {
const auto key = utils::encryption::generate_key(token);
data_buffer result;
utils::encryption::encrypt_data(key, buffer, result);
test_encrypted_result(result);
}
TEST(encryption, encrypt_data_pointer) {
data_buffer result;
utils::encryption::encrypt_data(token, &buffer[0u], buffer.size(), result);
test_encrypted_result(result);
}
TEST(encryption, encrypt_data_pointer_with_key) {
const auto key = utils::encryption::generate_key(token);
data_buffer result;
utils::encryption::encrypt_data(key, &buffer[0u], buffer.size(), result);
test_encrypted_result(result);
}
TEST(encryption, decrypt_data_pointer) {
const auto key = utils::encryption::generate_key(token);
data_buffer result;
utils::encryption::encrypt_data(key, &buffer[0u], buffer.size(), result);
std::string data;
EXPECT_TRUE(
utils::encryption::decrypt_data(token, &result[0u], result.size(), data));
EXPECT_EQ(buffer.size(), data.size());
EXPECT_STREQ(buffer.c_str(), data.c_str());
}
TEST(encryption, decrypt_data_buffer_with_key) {
const auto key = utils::encryption::generate_key(token);
data_buffer result;
utils::encryption::encrypt_data(key, &buffer[0u], buffer.size(), result);
std::string data;
EXPECT_TRUE(utils::encryption::decrypt_data(key, result, data));
EXPECT_EQ(buffer.size(), data.size());
EXPECT_STREQ(buffer.c_str(), data.c_str());
}
TEST(encryption, decrypt_data_pointer_with_key) {
const auto key = utils::encryption::generate_key(token);
data_buffer result;
utils::encryption::encrypt_data(key, &buffer[0u], buffer.size(), result);
std::string data;
EXPECT_TRUE(
utils::encryption::decrypt_data(key, &result[0u], result.size(), data));
EXPECT_EQ(buffer.size(), data.size());
EXPECT_STREQ(buffer.c_str(), data.c_str());
}
TEST(encryption, decryption_failure) {
const auto key = utils::encryption::generate_key(token);
data_buffer result;
utils::encryption::encrypt_data(key, &buffer[0u], buffer.size(), result);
result[0u] = 0u;
result[1u] = 1u;
result[2u] = 2u;
std::string data;
EXPECT_FALSE(utils::encryption::decrypt_data(key, result, data));
}
} // namespace repertory
/*
Copyright <2018-2023> <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_common.hpp"
#include "types/repertory.hpp"
#include "utils/encryption.hpp"
#include "utils/file_utils.hpp"
namespace repertory {
static const std::string buffer = "cow moose dog chicken";
static const std::string token = "moose";
static void test_encrypted_result(const data_buffer &result) {
EXPECT_EQ(buffer.size() +
utils::encryption::encrypting_reader::get_header_size(),
result.size());
std::string data;
EXPECT_TRUE(utils::encryption::decrypt_data(token, result, data));
EXPECT_EQ(buffer.size(), data.size());
EXPECT_STREQ(buffer.c_str(), data.c_str());
}
TEST(encryption, generate_key) {
const auto key = utils::encryption::generate_key(token);
const auto str = utils::to_hex_string(key);
EXPECT_STREQ(
"182072537ada59e4d6b18034a80302ebae935f66adbdf0f271d3d36309c2d481",
str.c_str());
}
TEST(encryption, encrypt_data_buffer) {
data_buffer result;
utils::encryption::encrypt_data(token, buffer, result);
test_encrypted_result(result);
}
TEST(encryption, encrypt_data_buffer_with_key) {
const auto key = utils::encryption::generate_key(token);
data_buffer result;
utils::encryption::encrypt_data(key, buffer, result);
test_encrypted_result(result);
}
TEST(encryption, encrypt_data_pointer) {
data_buffer result;
utils::encryption::encrypt_data(token, &buffer[0u], buffer.size(), result);
test_encrypted_result(result);
}
TEST(encryption, encrypt_data_pointer_with_key) {
const auto key = utils::encryption::generate_key(token);
data_buffer result;
utils::encryption::encrypt_data(key, &buffer[0u], buffer.size(), result);
test_encrypted_result(result);
}
TEST(encryption, decrypt_data_pointer) {
const auto key = utils::encryption::generate_key(token);
data_buffer result;
utils::encryption::encrypt_data(key, &buffer[0u], buffer.size(), result);
std::string data;
EXPECT_TRUE(
utils::encryption::decrypt_data(token, &result[0u], result.size(), data));
EXPECT_EQ(buffer.size(), data.size());
EXPECT_STREQ(buffer.c_str(), data.c_str());
}
TEST(encryption, decrypt_data_buffer_with_key) {
const auto key = utils::encryption::generate_key(token);
data_buffer result;
utils::encryption::encrypt_data(key, &buffer[0u], buffer.size(), result);
std::string data;
EXPECT_TRUE(utils::encryption::decrypt_data(key, result, data));
EXPECT_EQ(buffer.size(), data.size());
EXPECT_STREQ(buffer.c_str(), data.c_str());
}
TEST(encryption, decrypt_data_pointer_with_key) {
const auto key = utils::encryption::generate_key(token);
data_buffer result;
utils::encryption::encrypt_data(key, &buffer[0u], buffer.size(), result);
std::string data;
EXPECT_TRUE(
utils::encryption::decrypt_data(key, &result[0u], result.size(), data));
EXPECT_EQ(buffer.size(), data.size());
EXPECT_STREQ(buffer.c_str(), data.c_str());
}
TEST(encryption, decryption_failure) {
const auto key = utils::encryption::generate_key(token);
data_buffer result;
utils::encryption::encrypt_data(key, &buffer[0u], buffer.size(), result);
result[0u] = 0u;
result[1u] = 1u;
result[2u] = 2u;
std::string data;
EXPECT_FALSE(utils::encryption::decrypt_data(key, result, data));
}
} // namespace repertory

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,190 +1,184 @@
/*
Copyright <2018-2023> <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_common.hpp"
#include "file_manager/file_manager.hpp"
#include "mocks/mock_provider.hpp"
#include "mocks/mock_upload_manager.hpp"
#include "utils/event_capture.hpp"
#include "utils/path_utils.hpp"
namespace repertory {
static constexpr const std::size_t test_chunk_size = 1024u;
TEST(upload, can_upload_a_valid_file) {
console_consumer c;
event_system::instance().start();
const auto source_path = generate_test_file_name(".", "test");
mock_provider mp;
EXPECT_CALL(mp, is_direct_only()).WillRepeatedly(Return(false));
filesystem_item fsi;
fsi.api_path = "/test.txt";
fsi.size = test_chunk_size * 4u;
fsi.source_path = source_path;
event_consumer ec("file_upload_completed", [&fsi](const event &e) {
const auto &ee = dynamic_cast<const file_upload_completed &>(e);
EXPECT_STREQ(fsi.api_path.c_str(),
ee.get_api_path().get<std::string>().c_str());
EXPECT_STREQ(fsi.source_path.c_str(),
ee.get_source().get<std::string>().c_str());
EXPECT_STREQ("success", ee.get_result().get<std::string>().c_str());
EXPECT_STREQ("0", ee.get_cancelled().get<std::string>().c_str());
});
EXPECT_CALL(
mp, upload_file(fsi.api_path, fsi.source_path, fsi.encryption_token, _))
.WillOnce([&fsi](const std::string &, const std::string &,
const std::string &,
stop_type &stop_requested) -> api_error {
EXPECT_FALSE(stop_requested);
return api_error::success;
});
file_manager::upload upload(fsi, mp);
event_capture e({"file_upload_completed"});
e.wait_for_empty();
EXPECT_EQ(api_error::success, upload.get_api_error());
EXPECT_FALSE(upload.is_cancelled());
event_system::instance().stop();
}
TEST(upload, can_cancel_upload) {
console_consumer c;
event_system::instance().start();
const auto source_path = generate_test_file_name(".", "test");
// create_random_file(source_path, test_chunk_size * 4u)->close();
mock_provider mp;
EXPECT_CALL(mp, is_direct_only()).WillRepeatedly(Return(false));
filesystem_item fsi;
fsi.api_path = "/test.txt";
fsi.size = test_chunk_size * 4u;
fsi.source_path = source_path;
event_consumer ec("file_upload_completed", [&fsi](const event &e) {
const auto &ee = dynamic_cast<const file_upload_completed &>(e);
EXPECT_STREQ(fsi.api_path.c_str(),
ee.get_api_path().get<std::string>().c_str());
EXPECT_STREQ(fsi.source_path.c_str(),
ee.get_source().get<std::string>().c_str());
EXPECT_STREQ("upload_stopped", ee.get_result().get<std::string>().c_str());
EXPECT_STREQ("1", ee.get_cancelled().get<std::string>().c_str());
});
std::mutex mtx;
std::condition_variable cv;
EXPECT_CALL(
mp, upload_file(fsi.api_path, fsi.source_path, fsi.encryption_token, _))
.WillOnce([&cv, &fsi, &mtx](const std::string &, const std::string &,
const std::string &,
stop_type &stop_requested) -> api_error {
EXPECT_FALSE(stop_requested);
unique_mutex_lock l(mtx);
cv.notify_one();
l.unlock();
l.lock();
cv.wait(l);
l.unlock();
EXPECT_TRUE(stop_requested);
return api_error::upload_stopped;
});
unique_mutex_lock l(mtx);
file_manager::upload upload(fsi, mp);
cv.wait(l);
upload.cancel();
cv.notify_one();
l.unlock();
event_capture e({"file_upload_completed"});
e.wait_for_empty();
EXPECT_EQ(api_error::upload_stopped, upload.get_api_error());
EXPECT_TRUE(upload.is_cancelled());
event_system::instance().stop();
}
TEST(upload, can_stop_upload) {
console_consumer c;
event_system::instance().start();
const auto source_path = generate_test_file_name(".", "test");
mock_provider mp;
EXPECT_CALL(mp, is_direct_only()).WillRepeatedly(Return(false));
filesystem_item fsi;
fsi.api_path = "/test.txt";
fsi.size = test_chunk_size * 4u;
fsi.source_path = source_path;
event_consumer ec("file_upload_completed", [&fsi](const event &e) {
const auto &ee = dynamic_cast<const file_upload_completed &>(e);
EXPECT_STREQ(fsi.api_path.c_str(),
ee.get_api_path().get<std::string>().c_str());
EXPECT_STREQ(fsi.source_path.c_str(),
ee.get_source().get<std::string>().c_str());
EXPECT_STREQ("upload_stopped", ee.get_result().get<std::string>().c_str());
EXPECT_STREQ("0", ee.get_cancelled().get<std::string>().c_str());
});
EXPECT_CALL(
mp, upload_file(fsi.api_path, fsi.source_path, fsi.encryption_token, _))
.WillOnce([&fsi](const std::string &, const std::string &,
const std::string &,
stop_type &stop_requested) -> api_error {
std::this_thread::sleep_for(3s);
EXPECT_TRUE(stop_requested);
return api_error::upload_stopped;
});
event_capture e({"file_upload_completed"});
{ file_manager::upload upload(fsi, mp); }
e.wait_for_empty();
event_system::instance().stop();
}
} // namespace repertory
/*
Copyright <2018-2023> <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_common.hpp"
#include "file_manager/file_manager.hpp"
#include "mocks/mock_provider.hpp"
#include "mocks/mock_upload_manager.hpp"
#include "utils/event_capture.hpp"
#include "utils/path_utils.hpp"
namespace repertory {
static constexpr const std::size_t test_chunk_size = 1024u;
TEST(upload, can_upload_a_valid_file) {
console_consumer c;
event_system::instance().start();
const auto source_path = generate_test_file_name(".", "test");
mock_provider mp;
EXPECT_CALL(mp, is_direct_only()).WillRepeatedly(Return(false));
filesystem_item fsi;
fsi.api_path = "/test.txt";
fsi.size = test_chunk_size * 4u;
fsi.source_path = source_path;
event_consumer ec("file_upload_completed", [&fsi](const event &e) {
const auto &ee = dynamic_cast<const file_upload_completed &>(e);
EXPECT_STREQ(fsi.api_path.c_str(),
ee.get_api_path().get<std::string>().c_str());
EXPECT_STREQ(fsi.source_path.c_str(),
ee.get_source().get<std::string>().c_str());
EXPECT_STREQ("success", ee.get_result().get<std::string>().c_str());
EXPECT_STREQ("0", ee.get_cancelled().get<std::string>().c_str());
});
EXPECT_CALL(mp, upload_file(fsi.api_path, fsi.source_path, _))
.WillOnce([&fsi](const std::string &, const std::string &,
stop_type &stop_requested) -> api_error {
EXPECT_FALSE(stop_requested);
return api_error::success;
});
file_manager::upload upload(fsi, mp);
event_capture e({"file_upload_completed"});
e.wait_for_empty();
EXPECT_EQ(api_error::success, upload.get_api_error());
EXPECT_FALSE(upload.is_cancelled());
event_system::instance().stop();
}
TEST(upload, can_cancel_upload) {
console_consumer c;
event_system::instance().start();
const auto source_path = generate_test_file_name(".", "test");
// create_random_file(source_path, test_chunk_size * 4u)->close();
mock_provider mp;
EXPECT_CALL(mp, is_direct_only()).WillRepeatedly(Return(false));
filesystem_item fsi;
fsi.api_path = "/test.txt";
fsi.size = test_chunk_size * 4u;
fsi.source_path = source_path;
event_consumer ec("file_upload_completed", [&fsi](const event &e) {
const auto &ee = dynamic_cast<const file_upload_completed &>(e);
EXPECT_STREQ(fsi.api_path.c_str(),
ee.get_api_path().get<std::string>().c_str());
EXPECT_STREQ(fsi.source_path.c_str(),
ee.get_source().get<std::string>().c_str());
EXPECT_STREQ("upload_stopped", ee.get_result().get<std::string>().c_str());
EXPECT_STREQ("1", ee.get_cancelled().get<std::string>().c_str());
});
std::mutex mtx;
std::condition_variable cv;
EXPECT_CALL(mp, upload_file(fsi.api_path, fsi.source_path, _))
.WillOnce([&cv, &fsi, &mtx](const std::string &, const std::string &,
stop_type &stop_requested) -> api_error {
EXPECT_FALSE(stop_requested);
unique_mutex_lock l(mtx);
cv.notify_one();
l.unlock();
l.lock();
cv.wait(l);
l.unlock();
EXPECT_TRUE(stop_requested);
return api_error::upload_stopped;
});
unique_mutex_lock l(mtx);
file_manager::upload upload(fsi, mp);
cv.wait(l);
upload.cancel();
cv.notify_one();
l.unlock();
event_capture e({"file_upload_completed"});
e.wait_for_empty();
EXPECT_EQ(api_error::upload_stopped, upload.get_api_error());
EXPECT_TRUE(upload.is_cancelled());
event_system::instance().stop();
}
TEST(upload, can_stop_upload) {
console_consumer c;
event_system::instance().start();
const auto source_path = generate_test_file_name(".", "test");
mock_provider mp;
EXPECT_CALL(mp, is_direct_only()).WillRepeatedly(Return(false));
filesystem_item fsi;
fsi.api_path = "/test.txt";
fsi.size = test_chunk_size * 4u;
fsi.source_path = source_path;
event_consumer ec("file_upload_completed", [&fsi](const event &e) {
const auto &ee = dynamic_cast<const file_upload_completed &>(e);
EXPECT_STREQ(fsi.api_path.c_str(),
ee.get_api_path().get<std::string>().c_str());
EXPECT_STREQ(fsi.source_path.c_str(),
ee.get_source().get<std::string>().c_str());
EXPECT_STREQ("upload_stopped", ee.get_result().get<std::string>().c_str());
EXPECT_STREQ("0", ee.get_cancelled().get<std::string>().c_str());
});
EXPECT_CALL(mp, upload_file(fsi.api_path, fsi.source_path, _))
.WillOnce([&fsi](const std::string &, const std::string &,
stop_type &stop_requested) -> api_error {
std::this_thread::sleep_for(3s);
EXPECT_TRUE(stop_requested);
return api_error::upload_stopped;
});
event_capture e({"file_upload_completed"});
{ file_manager::upload upload(fsi, mp); }
e.wait_for_empty();
event_system::instance().stop();
}
} // namespace repertory

View File

@@ -1,57 +0,0 @@
/*
Copyright <2018-2023> <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.
*/
#ifndef REPERTORY_DIRECTORY_DB_FIXTURE_H
#define REPERTORY_DIRECTORY_DB_FIXTURE_H
#include "test_common.hpp"
#include "app_config.hpp"
#include "db/directory_db.hpp"
#include "utils/path_utils.hpp"
namespace repertory {
class directory_db_test : public ::testing::Test {
private:
const std::string config_location_ = utils::path::absolute("./directorydb");
protected:
std::unique_ptr<app_config> config_;
std::unique_ptr<directory_db> db_;
public:
void SetUp() override {
ASSERT_TRUE(utils::file::delete_directory_recursively(config_location_));
config_ =
std::make_unique<app_config>(provider_type::encrypt, config_location_);
db_ = std::make_unique<directory_db>(*config_.get());
}
void TearDown() override {
db_.reset();
config_.reset();
EXPECT_TRUE(utils::file::delete_directory_recursively(config_location_));
}
};
} // namespace repertory
#endif // REPERTORY_DIRECTORY_DB_FIXTURE_H

View File

@@ -1,57 +0,0 @@
/*
Copyright <2018-2023> <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.
*/
#ifndef REPERTORY_META_DB_FIXTURE_H
#define REPERTORY_META_DB_FIXTURE_H
#include "test_common.hpp"
#include "app_config.hpp"
#include "db/meta_db.hpp"
#include "utils/path_utils.hpp"
namespace repertory {
class meta_db_test : public ::testing::Test {
private:
const std::string config_location_ = utils::path::absolute("./metadb");
protected:
std::unique_ptr<app_config> config_;
std::unique_ptr<meta_db> db_;
public:
void SetUp() override {
ASSERT_TRUE(utils::file::delete_directory_recursively(config_location_));
config_ =
std::make_unique<app_config>(provider_type::sia, config_location_);
db_ = std::make_unique<meta_db>(*config_.get());
}
void TearDown() override {
db_.reset();
config_.reset();
EXPECT_TRUE(utils::file::delete_directory_recursively(config_location_));
}
};
} // namespace repertory
#endif // REPERTORY_META_DB_FIXTURE_H

View File

@@ -1,88 +0,0 @@
/*
Copyright <2018-2023> <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.
*/
#ifndef REPERTORY_S3_COMM_FIXTURE_H
#define REPERTORY_S3_COMM_FIXTURE_H
#if defined(REPERTORY_ENABLE_S3) && defined(REPERTORY_ENABLE_S3_TESTING)
#include "test_common.hpp"
#include "app_config.hpp"
#include "comm/s3/s3_comm.hpp"
#include "utils/path_utils.hpp"
namespace repertory {
class s3_comm_test : public ::testing::Test {
private:
console_consumer c_;
protected:
std::unique_ptr<app_config> config_;
std::unique_ptr<s3_comm> s3_comm_;
public:
void SetUp() override {
const auto path = utils::path::absolute("./test/");
ASSERT_TRUE(utils::file::delete_directory_recursively(path));
{
app_config config(provider_type::s3,
utils::path::combine(get_test_dir(), {"filebase"}));
config_ = std::make_unique<app_config>(provider_type::s3, "./test");
config_->set_event_level(event_level::verbose);
EXPECT_FALSE(config_
->set_value_by_name("S3Config.AccessKey",
config.get_s3_config().access_key)
.empty());
EXPECT_FALSE(config_
->set_value_by_name("S3Config.SecretKey",
config.get_s3_config().secret_key)
.empty());
EXPECT_FALSE(config_
->set_value_by_name("S3Config.Region",
config.get_s3_config().region)
.empty());
EXPECT_FALSE(
config_->set_value_by_name("S3Config.URL", config.get_s3_config().url)
.empty());
EXPECT_FALSE(
config_->set_value_by_name("S3Config.Bucket", "repertory").empty());
}
s3_comm_ = std::make_unique<s3_comm>(*config_);
event_system::instance().start();
}
void TearDown() override {
event_system::instance().stop();
s3_comm_.reset();
config_.reset();
const auto path = utils::path::absolute("./test/");
EXPECT_TRUE(utils::file::delete_directory_recursively(path));
}
};
} // namespace repertory
#endif // REPERTORY_ENABLE_S3_TESTING
#endif // REPERTORY_S3_COMM_FIXTURE_H

View File

@@ -1,149 +0,0 @@
/*
Copyright <2018-2023> <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.
*/
#ifndef REPERTORY_S3_PROVIDER_FILE_LIST_FIXTURE_H
#define REPERTORY_S3_PROVIDER_FILE_LIST_FIXTURE_H
#if defined(REPERTORY_ENABLE_S3) && defined(REPERTORY_ENABLE_S3_TESTING)
#include "test_common.hpp"
#include "mocks/mock_s3_comm.hpp"
#include "providers/s3/s3_provider.hpp"
#include "types/s3.hpp"
#include "utils/path_utils.hpp"
namespace repertory {
class s3_provider_file_list_test : public ::testing::Test {
public:
console_consumer c;
api_file_list list;
std::unique_ptr<app_config> cfg;
std::unique_ptr<mock_s3_comm> comm;
std::unique_ptr<s3_provider> provider;
std::array<std::uint64_t, 10> times = {
utils::get_file_time_now(), utils::get_file_time_now(),
utils::get_file_time_now(), utils::get_file_time_now(),
utils::get_file_time_now(), utils::get_file_time_now(),
utils::get_file_time_now(), utils::get_file_time_now(),
utils::get_file_time_now(), utils::get_file_time_now(),
};
public:
void SetUp() override {
ASSERT_TRUE(utils::file::delete_directory_recursively(
utils::path::absolute("./data")));
event_system::instance().start();
cfg = std::make_unique<app_config>(provider_type::s3,
utils::path::absolute("./data"));
EXPECT_FALSE(cfg->set_value_by_name("S3Config.Bucket", "bucket").empty());
EXPECT_FALSE(
cfg->set_value_by_name("S3Config.URL", "https://url.com").empty());
comm = std::make_unique<mock_s3_comm>(cfg->get_s3_config());
provider = std::make_unique<s3_provider>(*cfg, *comm);
const auto create_file = [this](std::size_t idx,
bool create_sub_directory = false) {
api_file file{};
file.accessed_date = times[idx];
if (create_sub_directory) {
file.api_path = utils::path::create_api_path(
"/dir/file_" + std::to_string(idx) + ".txt");
} else {
file.api_path = utils::path::create_api_path(
"/file_" + std::to_string(idx) + ".txt");
}
file.api_parent = utils::path::get_parent_api_path(file.api_path);
file.changed_date = times[idx] + 1u;
file.creation_date = times[idx] + 2u;
file.encryption_token = "";
file.file_size = 100u + idx;
file.modified_date = times[idx] + 3u;
this->list.emplace_back(std::move(file));
};
for (std::size_t idx = 0u; idx < times.size(); idx++) {
create_file(idx);
}
for (std::size_t idx = 0u; idx < times.size(); idx++) {
create_file(idx, true);
}
EXPECT_CALL(*comm, get_file_list)
.WillRepeatedly(
[this](const get_api_file_token_callback &get_api_file_token,
const get_name_callback &get_name, api_file_list &l) {
for (auto i : list) {
auto object_name = i.api_path;
object_name = get_name(
*(utils::string::split(i.api_path, '/', false).end() - 1u),
object_name);
i.api_path = object_name;
i.api_parent = utils::path::get_parent_api_path(i.api_path);
i.encryption_token = get_api_file_token(i.api_path);
l.emplace_back(i);
}
return api_error::success;
});
EXPECT_CALL(*comm, get_file)
.WillRepeatedly(
[this](const std::string &api_path, const get_key_callback &get_key,
const get_name_callback &get_name,
const get_token_callback &get_token, api_file &file) {
auto f = std::find_if(list.begin(), list.end(),
[&api_path](const auto &f) -> bool {
return f.api_path == api_path;
});
if (f == list.end()) {
return api_error::item_not_found;
}
file = *f;
auto object_name = api_path;
const auto key = get_key();
object_name = get_name(key, object_name);
file.api_path = utils::path::create_api_path(object_name);
file.api_parent = utils::path::get_parent_api_path(file.api_path);
file.encryption_token = get_token();
return api_error::success;
});
}
void TearDown() override {
provider->stop();
comm.reset();
provider.reset();
cfg.reset();
event_system::instance().stop();
EXPECT_TRUE(utils::file::delete_directory_recursively(
utils::path::absolute("./data")));
}
};
} // namespace repertory
#endif // REPERTORY_ENABLE_S3_TESTING
#endif // REPERTORY_S3_PROVIDER_FILE_LIST_FIXTURE_H

View File

@@ -1,150 +1,148 @@
/*
Copyright <2018-2023> <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.
*/
#ifndef REPERTORY_WINFSP_FIXTURE_H
#define REPERTORY_WINFSP_FIXTURE_H
#if _WIN32
#include "test_common.hpp"
#include "app_config.hpp"
#include "comm/s3/s3_comm.hpp"
#include "comm/curl/curl_comm.hpp"
#include "drives/winfsp/winfsp_drive.hpp"
#include "platform/platform.hpp"
#include "providers/s3/s3_provider.hpp"
#include "providers/sia/sia_provider.hpp"
extern std::size_t PROVIDER_INDEX;
namespace repertory {
class winfsp_test : public ::testing::Test {
public:
lock_data lock_data_;
std::unique_ptr<app_config> config;
std::unique_ptr<curl_comm> comm;
std::unique_ptr<i_provider> provider;
std::unique_ptr<winfsp_drive> drive;
#ifdef REPERTORY_ENABLE_S3
std::unique_ptr<s3_comm> s3_comm_;
#endif
protected:
void SetUp() override {
if (PROVIDER_INDEX != 0) {
if (PROVIDER_INDEX == 1) {
#ifdef REPERTORY_ENABLE_S3
EXPECT_TRUE(utils::file::delete_directory_recursively(
"./winfsp_test" + std::to_string(PROVIDER_INDEX)));
app_config src_cfg(provider_type::s3,
utils::path::combine(get_test_dir(), {"filebase"}));
config = std::make_unique<app_config>(
provider_type::s3,
"./winfsp_test" + std::to_string(PROVIDER_INDEX));
EXPECT_FALSE(config
->set_value_by_name("S3Config.AccessKey",
src_cfg.get_s3_config().access_key)
.empty());
EXPECT_FALSE(config
->set_value_by_name("S3Config.SecretKey",
src_cfg.get_s3_config().secret_key)
.empty());
EXPECT_FALSE(config
->set_value_by_name("S3Config.Region",
src_cfg.get_s3_config().region)
.empty());
EXPECT_FALSE(
config
->set_value_by_name("S3Config.URL", src_cfg.get_s3_config().url)
.empty());
EXPECT_FALSE(
config->set_value_by_name("S3Config.Bucket", "repertory").empty());
config->set_event_level(event_level::verbose);
config->set_enable_drive_events(true);
event_system::instance().start();
s3_comm_ = std::make_unique<s3_comm>(*config);
provider = std::make_unique<s3_provider>(*config, *s3_comm_);
drive = std::make_unique<winfsp_drive>(*config, lock_data_, *provider);
#endif
return;
}
if (PROVIDER_INDEX == 2) {
EXPECT_TRUE(utils::file::delete_directory_recursively(
"./winfsp_test" + std::to_string(PROVIDER_INDEX)));
app_config src_cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
config = std::make_unique<app_config>(
provider_type::sia,
"./winfsp_test" + std::to_string(PROVIDER_INDEX));
[[maybe_unused]] auto val = config->set_value_by_name(
"HostConfig.AgentString", src_cfg.get_host_config().agent_string);
EXPECT_FALSE(
config
->set_value_by_name("HostConfig.ApiPassword",
src_cfg.get_host_config().api_password)
.empty());
EXPECT_FALSE(config
->set_value_by_name(
"HostConfig.ApiPort",
std::to_string(src_cfg.get_host_config().api_port))
.empty());
EXPECT_FALSE(
config
->set_value_by_name("HostConfig.HostNameOrIp",
src_cfg.get_host_config().host_name_or_ip)
.empty());
config->set_event_level(event_level::debug);
config->set_enable_drive_events(true);
event_system::instance().start();
comm = std::make_unique<curl_comm>(config->get_host_config());
provider = std::make_unique<sia_provider>(*config, *comm);
drive = std::make_unique<winfsp_drive>(*config, lock_data_, *provider);
return;
}
}
}
void TearDown() override {
if (PROVIDER_INDEX != 0) {
drive.reset();
provider.reset();
#ifdef REPERTORY_ENABLE_S3
s3_comm_.reset();
#endif
comm.reset();
config.reset();
event_system::instance().stop();
EXPECT_TRUE(utils::file::delete_directory_recursively(
"./winfsp_test" + std::to_string(PROVIDER_INDEX)));
}
}
};
} // namespace repertory
#endif
#endif // REPERTORY_WINFSP_FIXTURE_H
/*
Copyright <2018-2023> <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.
*/
#ifndef REPERTORY_WINFSP_FIXTURE_H
#define REPERTORY_WINFSP_FIXTURE_H
#if _WIN32
#include "test_common.hpp"
#include "app_config.hpp"
#include "comm/curl/curl_comm.hpp"
#include "drives/winfsp/winfsp_drive.hpp"
#include "platform/platform.hpp"
#include "providers/s3/s3_provider.hpp"
#include "providers/sia/sia_provider.hpp"
extern std::size_t PROVIDER_INDEX;
namespace repertory {
class winfsp_test : public ::testing::Test {
public:
lock_data lock_data_;
std::unique_ptr<app_config> config;
std::unique_ptr<curl_comm> comm;
std::unique_ptr<i_provider> provider;
std::unique_ptr<winfsp_drive> drive;
protected:
void SetUp() override {
if (PROVIDER_INDEX != 0) {
if (PROVIDER_INDEX == 1) {
#ifdef REPERTORY_ENABLE_S3
EXPECT_TRUE(utils::file::delete_directory_recursively(
"./winfsp_test" + std::to_string(PROVIDER_INDEX)));
app_config src_cfg(provider_type::s3,
utils::path::combine(get_test_dir(), {"storj"}));
config = std::make_unique<app_config>(
provider_type::s3,
"./winfsp_test" + std::to_string(PROVIDER_INDEX));
EXPECT_FALSE(config
->set_value_by_name("S3Config.AccessKey",
src_cfg.get_s3_config().access_key)
.empty());
EXPECT_FALSE(config
->set_value_by_name("S3Config.SecretKey",
src_cfg.get_s3_config().secret_key)
.empty());
EXPECT_FALSE(config
->set_value_by_name("S3Config.Region",
src_cfg.get_s3_config().region)
.empty());
EXPECT_FALSE(
config
->set_value_by_name("S3Config.EncryptionToken",
src_cfg.get_s3_config().encryption_token)
.empty());
EXPECT_FALSE(
config
->set_value_by_name("S3Config.URL", src_cfg.get_s3_config().url)
.empty());
EXPECT_FALSE(
config->set_value_by_name("S3Config.Bucket", "repertory").empty());
config->set_event_level(event_level::verbose);
config->set_enable_drive_events(true);
event_system::instance().start();
comm = std::make_unique<curl_comm>(config->get_s3_config());
provider = std::make_unique<s3_provider>(*config, *comm);
drive = std::make_unique<winfsp_drive>(*config, lock_data_, *provider);
#endif
return;
}
if (PROVIDER_INDEX == 2) {
EXPECT_TRUE(utils::file::delete_directory_recursively(
"./winfsp_test" + std::to_string(PROVIDER_INDEX)));
app_config src_cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
config = std::make_unique<app_config>(
provider_type::sia,
"./winfsp_test" + std::to_string(PROVIDER_INDEX));
[[maybe_unused]] auto val = config->set_value_by_name(
"HostConfig.AgentString", src_cfg.get_host_config().agent_string);
EXPECT_FALSE(
config
->set_value_by_name("HostConfig.ApiPassword",
src_cfg.get_host_config().api_password)
.empty());
EXPECT_FALSE(config
->set_value_by_name(
"HostConfig.ApiPort",
std::to_string(src_cfg.get_host_config().api_port))
.empty());
EXPECT_FALSE(
config
->set_value_by_name("HostConfig.HostNameOrIp",
src_cfg.get_host_config().host_name_or_ip)
.empty());
config->set_event_level(event_level::debug);
config->set_enable_drive_events(true);
event_system::instance().start();
comm = std::make_unique<curl_comm>(config->get_host_config());
provider = std::make_unique<sia_provider>(*config, *comm);
drive = std::make_unique<winfsp_drive>(*config, lock_data_, *provider);
return;
}
}
}
void TearDown() override {
if (PROVIDER_INDEX != 0) {
drive.reset();
provider.reset();
comm.reset();
config.reset();
event_system::instance().stop();
EXPECT_TRUE(utils::file::delete_directory_recursively(
"./winfsp_test" + std::to_string(PROVIDER_INDEX)));
}
}
};
} // namespace repertory
#endif
#endif // REPERTORY_WINFSP_FIXTURE_H

File diff suppressed because it is too large Load Diff

View File

@@ -1,104 +1,104 @@
/*
Copyright <2018-2023> <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_common.hpp"
#include "platform/platform.hpp"
namespace repertory {
TEST(lock_data, lock_and_unlock) {
{
lock_data l(provider_type::sia, "1");
EXPECT_EQ(lock_result::success, l.grab_lock());
std::thread([]() {
lock_data l(provider_type::sia, "1");
EXPECT_EQ(lock_result::locked, l.grab_lock(10));
}).join();
}
std::thread([]() {
lock_data l(provider_type::sia, "1");
EXPECT_EQ(lock_result::success, l.grab_lock(10));
}).join();
#ifdef _WIN32
lock_data l2(provider_type::remote, "1");
EXPECT_EQ(lock_result::success, l2.grab_lock());
lock_data l3(provider_type::remote, "2");
EXPECT_EQ(lock_result::success, l3.grab_lock());
#endif
}
#ifdef _WIN32
TEST(lock_data, set_and_unset_mount_state) {
lock_data l(provider_type::sia, "1");
EXPECT_TRUE(l.set_mount_state(true, "C:", 99));
lock_data l2(provider_type::remote, "1");
EXPECT_TRUE(l2.set_mount_state(true, "D:", 97));
lock_data l3(provider_type::remote, "2");
EXPECT_TRUE(l3.set_mount_state(true, "E:", 96));
json mount_state;
EXPECT_TRUE(l.get_mount_state(mount_state));
EXPECT_STREQ(R"({"Active":true,"Location":"C:","PID":99})",
mount_state["Sia1"].dump().c_str());
EXPECT_STREQ(R"({"Active":true,"Location":"D:","PID":97})",
mount_state["Remote1"].dump().c_str());
EXPECT_STREQ(R"({"Active":true,"Location":"E:","PID":96})",
mount_state["Remote2"].dump().c_str());
EXPECT_TRUE(l.set_mount_state(false, "C:", 99));
EXPECT_TRUE(l2.set_mount_state(false, "D:", 98));
EXPECT_TRUE(l3.set_mount_state(false, "E:", 97));
EXPECT_TRUE(l.get_mount_state(mount_state));
EXPECT_STREQ(R"({"Active":false,"Location":"","PID":-1})",
mount_state["Sia1"].dump().c_str());
EXPECT_STREQ(R"({"Active":false,"Location":"","PID":-1})",
mount_state["Remote1"].dump().c_str());
EXPECT_STREQ(R"({"Active":false,"Location":"","PID":-1})",
mount_state["Remote2"].dump().c_str());
}
#else
TEST(lock_data, set_and_unset_mount_state) {
lock_data l(provider_type::sia, "1");
EXPECT_TRUE(l.set_mount_state(true, "/mnt/1", 99));
json mount_state;
EXPECT_TRUE(l.get_mount_state(mount_state));
EXPECT_STREQ(R"({"Active":true,"Location":"/mnt/1","PID":99})",
mount_state["Sia1"].dump().c_str());
EXPECT_TRUE(l.set_mount_state(false, "/mnt/1", 99));
EXPECT_TRUE(l.get_mount_state(mount_state));
EXPECT_STREQ(R"({"Active":false,"Location":"","PID":-1})",
mount_state["Sia1"].dump().c_str());
}
#endif
} // namespace repertory
/*
Copyright <2018-2023> <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_common.hpp"
#include "platform/platform.hpp"
namespace repertory {
TEST(lock_data, lock_and_unlock) {
{
lock_data l(provider_type::sia, "1");
EXPECT_EQ(lock_result::success, l.grab_lock());
std::thread([]() {
lock_data l2(provider_type::sia, "1");
EXPECT_EQ(lock_result::locked, l2.grab_lock(10));
}).join();
}
std::thread([]() {
lock_data l(provider_type::sia, "1");
EXPECT_EQ(lock_result::success, l.grab_lock(10));
}).join();
#ifdef _WIN32
lock_data l2(provider_type::remote, "1");
EXPECT_EQ(lock_result::success, l2.grab_lock());
lock_data l3(provider_type::remote, "2");
EXPECT_EQ(lock_result::success, l3.grab_lock());
#endif
}
#ifdef _WIN32
TEST(lock_data, set_and_unset_mount_state) {
lock_data l(provider_type::sia, "1");
EXPECT_TRUE(l.set_mount_state(true, "C:", 99));
lock_data l2(provider_type::remote, "1");
EXPECT_TRUE(l2.set_mount_state(true, "D:", 97));
lock_data l3(provider_type::remote, "2");
EXPECT_TRUE(l3.set_mount_state(true, "E:", 96));
json mount_state;
EXPECT_TRUE(l.get_mount_state(mount_state));
EXPECT_STREQ(R"({"Active":true,"Location":"C:","PID":99})",
mount_state["Sia1"].dump().c_str());
EXPECT_STREQ(R"({"Active":true,"Location":"D:","PID":97})",
mount_state["Remote1"].dump().c_str());
EXPECT_STREQ(R"({"Active":true,"Location":"E:","PID":96})",
mount_state["Remote2"].dump().c_str());
EXPECT_TRUE(l.set_mount_state(false, "C:", 99));
EXPECT_TRUE(l2.set_mount_state(false, "D:", 98));
EXPECT_TRUE(l3.set_mount_state(false, "E:", 97));
EXPECT_TRUE(l.get_mount_state(mount_state));
EXPECT_STREQ(R"({"Active":false,"Location":"","PID":-1})",
mount_state["Sia1"].dump().c_str());
EXPECT_STREQ(R"({"Active":false,"Location":"","PID":-1})",
mount_state["Remote1"].dump().c_str());
EXPECT_STREQ(R"({"Active":false,"Location":"","PID":-1})",
mount_state["Remote2"].dump().c_str());
}
#else
TEST(lock_data, set_and_unset_mount_state) {
lock_data l(provider_type::sia, "1");
EXPECT_TRUE(l.set_mount_state(true, "/mnt/1", 99));
json mount_state;
EXPECT_TRUE(l.get_mount_state(mount_state));
EXPECT_STREQ(R"({"Active":true,"Location":"/mnt/1","PID":99})",
mount_state["Sia1"].dump().c_str());
EXPECT_TRUE(l.set_mount_state(false, "/mnt/1", 99));
EXPECT_TRUE(l.get_mount_state(mount_state));
EXPECT_STREQ(R"({"Active":false,"Location":"","PID":-1})",
mount_state["Sia1"].dump().c_str());
}
#endif
} // namespace repertory

View File

@@ -1,292 +0,0 @@
/*
Copyright <2018-2023> <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_common.hpp"
#include "fixtures/meta_db_fixture.hpp"
namespace repertory {
TEST_F(meta_db_test, get_and_set_item_meta) {
api_meta_map meta{
{"test", "test_value"},
{"test2", "test_value2"},
{"test3", "test_value3"},
};
EXPECT_EQ(api_error::success, db_->set_item_meta("/test/item", meta));
api_meta_map meta2{};
EXPECT_EQ(api_error::success, db_->get_item_meta("/test/item", meta2));
EXPECT_EQ(meta, meta2);
}
TEST_F(meta_db_test, get_and_set_item_meta_single_key) {
EXPECT_EQ(api_error::success,
db_->set_item_meta("/test/item", "test", "moose"));
std::string value;
EXPECT_EQ(api_error::success,
db_->get_item_meta("/test/item", "test", value));
EXPECT_STREQ("moose", value.c_str());
}
TEST_F(meta_db_test,
get_item_meta_fails_with_not_found_for_items_that_dont_exist) {
api_meta_map meta{};
EXPECT_EQ(api_error::item_not_found, db_->get_item_meta("/test/item", meta));
std::string value;
EXPECT_EQ(api_error::item_not_found,
db_->get_item_meta("/test/item", "test", value));
EXPECT_TRUE(value.empty());
}
TEST_F(meta_db_test, get_item_meta_exists) {
EXPECT_EQ(api_error::success,
db_->set_item_meta("/test/item", "test", "value"));
EXPECT_TRUE(db_->get_item_meta_exists("/test/item"));
}
TEST_F(meta_db_test, get_item_meta_exists_is_false_if_not_found) {
EXPECT_FALSE(db_->get_item_meta_exists("/test/item"));
}
TEST_F(meta_db_test, remove_item_meta) {
api_meta_map meta{
{"test", "test_value"},
{"test2", "test_value2"},
{"test3", "test_value3"},
};
EXPECT_EQ(api_error::success, db_->set_item_meta("/test/item", meta));
EXPECT_EQ(api_error::success, db_->remove_item_meta("/test/item"));
api_meta_map meta2{};
EXPECT_EQ(api_error::item_not_found, db_->get_item_meta("/test/item", meta2));
EXPECT_TRUE(meta2.empty());
}
TEST_F(meta_db_test, remove_item_meta_single_key) {
api_meta_map meta{
{"test", "test_value"},
{"test2", "test_value2"},
{"test3", "test_value3"},
};
EXPECT_EQ(api_error::success, db_->set_item_meta("/test/item", meta));
EXPECT_EQ(api_error::success, db_->remove_item_meta("/test/item", "test"));
api_meta_map meta2{};
EXPECT_EQ(api_error::success, db_->get_item_meta("/test/item", meta2));
meta.erase("test");
EXPECT_EQ(meta, meta2);
}
TEST_F(meta_db_test, get_and_set_source_path) {
EXPECT_EQ(api_error::success,
db_->set_source_path("/test/item", "/test/path"));
std::string value;
EXPECT_EQ(api_error::success,
db_->get_item_meta("/test/item", META_SOURCE, value));
EXPECT_STREQ("/test/path", value.c_str());
}
// TEST_F(meta_db_test, set_source_path_fails_on_empty_path) {
// EXPECT_EQ(api_error::invalid_operation, db_->set_source_path("/test/item",
// ""));
//
// std::string value;
// EXPECT_EQ(api_error::item_not_found, db_->get_item_meta("/test/item",
// META_SOURCE, value)); EXPECT_TRUE(value.empty());
// }
TEST_F(meta_db_test, get_api_path_from_source) {
EXPECT_EQ(api_error::success,
db_->set_source_path("/test/item", "/test/path"));
std::string value;
EXPECT_EQ(api_error::success,
db_->get_api_path_from_source("/test/path", value));
EXPECT_STREQ("/test/item", value.c_str());
}
TEST_F(meta_db_test, get_api_path_from_source_succeeds_after_change) {
EXPECT_EQ(api_error::success,
db_->set_source_path("/test/item", "/test/path"));
EXPECT_EQ(api_error::success,
db_->set_source_path("/test/item", "/test/path2"));
std::string value;
EXPECT_EQ(api_error::success,
db_->get_api_path_from_source("/test/path2", value));
EXPECT_STREQ("/test/item", value.c_str());
value.clear();
EXPECT_EQ(api_error::item_not_found,
db_->get_api_path_from_source("/test/path", value));
EXPECT_TRUE(value.empty());
}
TEST_F(meta_db_test, get_api_path_from_source_fails_after_remove_all_meta) {
EXPECT_EQ(api_error::success,
db_->set_source_path("/test/item", "/test/path"));
EXPECT_EQ(api_error::success, db_->remove_item_meta("/test/item"));
std::string value;
EXPECT_EQ(api_error::item_not_found,
db_->get_api_path_from_source("/test/path", value));
EXPECT_TRUE(value.empty());
}
TEST_F(meta_db_test, get_api_path_from_source_fails_after_remove_source_key) {
EXPECT_EQ(api_error::success,
db_->set_source_path("/test/item", "/test/path"));
EXPECT_EQ(api_error::success,
db_->remove_item_meta("/test/item", META_SOURCE));
std::string value;
EXPECT_EQ(api_error::item_not_found,
db_->get_api_path_from_source("/test/path", value));
EXPECT_TRUE(value.empty());
}
TEST_F(meta_db_test, get_source_path_exists) {
EXPECT_EQ(api_error::success,
db_->set_source_path("/test/item", "/test/path"));
EXPECT_TRUE(db_->get_source_path_exists("/test/path"));
}
TEST_F(meta_db_test, get_source_path_exists_is_false_if_not_found) {
EXPECT_FALSE(db_->get_source_path_exists("/test/item"));
}
TEST_F(meta_db_test, get_api_path_from_key) {
EXPECT_EQ(api_error::success,
db_->set_item_meta("/test/item", META_KEY, "key"));
std::string value;
EXPECT_EQ(api_error::success, db_->get_api_path_from_key("key", value));
EXPECT_STREQ("/test/item", value.c_str());
}
TEST_F(meta_db_test, remove_item_meta_succeeds_for_items_that_dont_exist) {
EXPECT_EQ(api_error::success, db_->remove_item_meta("/test/item"));
EXPECT_EQ(api_error::success, db_->remove_item_meta("/test/item", "test"));
}
TEST_F(meta_db_test, remove_item_meta_removes_source_path) {
EXPECT_EQ(api_error::success,
db_->set_source_path("/test/item", "/source/path"));
EXPECT_EQ(api_error::success, db_->remove_item_meta("/test/item"));
std::string api_path;
EXPECT_EQ(api_error::item_not_found,
db_->get_api_path_from_source("/source/path", api_path));
EXPECT_TRUE(api_path.empty());
}
TEST_F(meta_db_test, remove_item_meta_by_key_removes_source_path) {
EXPECT_EQ(api_error::success,
db_->set_source_path("/test/item", "/source/path"));
EXPECT_EQ(api_error::success,
db_->remove_item_meta("/test/item", META_SOURCE));
std::string api_path;
EXPECT_EQ(api_error::item_not_found,
db_->get_api_path_from_source("/source/path", api_path));
EXPECT_TRUE(api_path.empty());
}
TEST_F(meta_db_test, remove_item_meta_removes_key) {
EXPECT_EQ(api_error::success,
db_->set_item_meta("/test/item", META_KEY, "key"));
EXPECT_EQ(api_error::success, db_->remove_item_meta("/test/item"));
std::string api_path;
EXPECT_EQ(api_error::item_not_found,
db_->get_api_path_from_key("key", api_path));
EXPECT_TRUE(api_path.empty());
}
TEST_F(meta_db_test, remove_item_meta_by_key_removes_key) {
EXPECT_EQ(api_error::success,
db_->set_item_meta("/test/item", META_KEY, "key"));
EXPECT_EQ(api_error::success, db_->remove_item_meta("/test/item", META_KEY));
std::string api_path;
EXPECT_EQ(api_error::item_not_found,
db_->get_api_path_from_key("/source/path", api_path));
EXPECT_TRUE(api_path.empty());
}
TEST_F(meta_db_test, rename_item_meta) {
api_meta_map meta{
{"test", "test_value"},
{"test2", "test_value2"},
{"test3", "test_value3"},
};
EXPECT_EQ(api_error::success, db_->set_item_meta("/test/item", meta));
EXPECT_EQ(api_error::success,
db_->rename_item_meta("", "/test/item", "/test/item2"));
api_meta_map meta2{};
EXPECT_EQ(api_error::item_not_found, db_->get_item_meta("/test/item", meta2));
EXPECT_EQ(api_error::success, db_->get_item_meta("/test/item2", meta2));
EXPECT_EQ(meta, meta2);
}
TEST_F(meta_db_test, rename_item_meta_with_key) {
api_meta_map meta{
{META_KEY, "test_key"},
{"test2", "test_value2"},
{"test3", "test_value3"},
};
EXPECT_EQ(api_error::success, db_->set_item_meta("/test/item", meta));
EXPECT_EQ(api_error::success,
db_->rename_item_meta("", "/test/item", "/test/item2"));
std::string api_path;
EXPECT_EQ(api_error::success,
db_->get_api_path_from_key("test_key", api_path));
EXPECT_STREQ("/test/item2", api_path.c_str());
}
TEST_F(meta_db_test, rename_item_meta_with_source_path) {
api_meta_map meta{
{META_SOURCE, "/test/source"},
{"test2", "test_value2"},
{"test3", "test_value3"},
};
EXPECT_EQ(api_error::success, db_->set_item_meta("/test/item", meta));
EXPECT_EQ(api_error::success,
db_->rename_item_meta("/test/source", "/test/item", "/test/item2"));
std::string api_path;
EXPECT_EQ(api_error::success,
db_->get_api_path_from_source("/test/source", api_path));
EXPECT_STREQ("/test/item2", api_path.c_str());
}
} // namespace repertory

View File

@@ -1,151 +1,158 @@
/*
Copyright <2018-2023> <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.
*/
#ifndef TESTS_MOCKS_MOCK_FUSE_DRIVE_HPP_
#define TESTS_MOCKS_MOCK_FUSE_DRIVE_HPP_
#ifndef _WIN32
#include "test_common.hpp"
#include "drives/fuse/i_fuse_drive.hpp"
#include "types/remote.hpp"
#include "types/repertory.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/utils.hpp"
namespace repertory {
class mock_fuse_drive final : public virtual i_fuse_drive {
public:
explicit mock_fuse_drive(std::string mount_location)
: mount_location_(std::move(mount_location)) {}
private:
const std::string mount_location_;
std::unordered_map<std::string, api_meta_map> meta_;
public:
api_error check_owner(const std::string &) const override {
return api_error::success;
}
api_error check_parent_access(const std::string &, int) const override {
return api_error::success;
}
std::uint64_t get_directory_item_count(const std::string &) const override {
return 1;
}
directory_item_list get_directory_items(const std::string &) const override {
directory_item_list list{};
directory_item di{};
di.api_path = ".";
di.directory = true;
di.size = 0;
di.meta = {{META_ATTRIBUTES, "16"},
{META_MODIFIED, std::to_string(utils::get_file_time_now())},
{META_WRITTEN, std::to_string(utils::get_file_time_now())},
{META_ACCESSED, std::to_string(utils::get_file_time_now())},
{META_CREATION, std::to_string(utils::get_file_time_now())}};
list.emplace_back(di);
di.api_path = "..";
list.emplace_back(di);
return list;
}
std::uint64_t get_file_size(const std::string &) const override { return 0u; }
api_error get_item_meta(const std::string &api_path,
api_meta_map &meta) const override {
meta = const_cast<mock_fuse_drive *>(this)->meta_[api_path];
return api_error::success;
}
api_error get_item_meta(const std::string &api_path, const std::string &name,
std::string &value) const override {
value = const_cast<mock_fuse_drive *>(this)->meta_[api_path][name];
if (value.empty()) {
value = "0";
}
return api_error::success;
}
std::uint64_t get_total_drive_space() const override {
return 100 * 1024 * 1024;
}
std::uint64_t get_total_item_count() const override { return 0u; }
std::uint64_t get_used_drive_space() const override { return 0u; }
void get_volume_info(UINT64 &total_size, UINT64 &free_size,
std::string &volume_label) const override {
free_size = 100u;
total_size = 200u;
volume_label = "TestVolumeLabel";
}
void populate_stat(const directory_item &, struct stat &) const override {}
int rename_directory(const std::string &from_api_path,
const std::string &to_api_path) override {
const auto from_file_path =
utils::path::combine(mount_location_, {from_api_path});
const auto to_file_path =
utils::path::combine(mount_location_, {to_api_path});
return rename(from_file_path.c_str(), to_file_path.c_str());
}
int rename_file(const std::string &from_api_path,
const std::string &to_api_path, bool overwrite) override {
const auto from_file_path =
utils::path::combine(mount_location_, {from_api_path});
const auto to_file_path =
utils::path::combine(mount_location_, {to_api_path});
if (overwrite) {
if (not utils::file::retry_delete_file(to_file_path)) {
return -1;
}
} else if (utils::file::is_directory(to_file_path) ||
utils::file::is_file(to_file_path)) {
errno = EEXIST;
return -1;
}
return rename(from_file_path.c_str(), to_file_path.c_str());
}
bool is_processing(const std::string &) const override { return false; }
void set_item_meta(const std::string &api_path, const std::string &key,
const std::string &value) override {
meta_[api_path][key] = value;
}
};
} // namespace repertory
#endif // _WIN32
#endif // TESTS_MOCKS_MOCK_FUSE_DRIVE_HPP_
/*
Copyright <2018-2023> <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.
*/
#ifndef TESTS_MOCKS_MOCK_FUSE_DRIVE_HPP_
#define TESTS_MOCKS_MOCK_FUSE_DRIVE_HPP_
#ifndef _WIN32
#include "test_common.hpp"
#include "drives/fuse/i_fuse_drive.hpp"
#include "types/remote.hpp"
#include "types/repertory.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/utils.hpp"
namespace repertory {
class mock_fuse_drive final : public virtual i_fuse_drive {
public:
explicit mock_fuse_drive(std::string mount_location)
: mount_location_(std::move(mount_location)) {}
private:
std::string mount_location_;
std::unordered_map<std::string, api_meta_map> meta_;
public:
auto check_owner(const std::string &) const -> api_error override {
return api_error::success;
}
auto check_parent_access(const std::string &, int) const
-> api_error override {
return api_error::success;
}
auto get_directory_item_count(const std::string &) const
-> std::uint64_t override {
return 1;
}
auto get_directory_items(const std::string &) const
-> directory_item_list override {
directory_item_list list{};
directory_item dir_item{};
dir_item.api_path = ".";
dir_item.directory = true;
dir_item.size = 0;
dir_item.meta = {
{META_ATTRIBUTES, "16"},
{META_MODIFIED, std::to_string(utils::get_file_time_now())},
{META_WRITTEN, std::to_string(utils::get_file_time_now())},
{META_ACCESSED, std::to_string(utils::get_file_time_now())},
{META_CREATION, std::to_string(utils::get_file_time_now())}};
list.emplace_back(dir_item);
dir_item.api_path = "..";
list.emplace_back(dir_item);
return list;
}
auto get_file_size(const std::string &) const -> std::uint64_t override {
return 0U;
}
auto get_item_meta(const std::string &api_path, api_meta_map &meta) const
-> api_error override {
meta = const_cast<mock_fuse_drive *>(this)->meta_[api_path];
return api_error::success;
}
auto get_item_meta(const std::string &api_path, const std::string &name,
std::string &value) const -> api_error override {
value = const_cast<mock_fuse_drive *>(this)->meta_[api_path][name];
if (value.empty()) {
value = "0";
}
return api_error::success;
}
auto get_total_drive_space() const -> std::uint64_t override {
return 100ULL * 1024ULL * 1024ULL;
}
auto get_total_item_count() const -> std::uint64_t override { return 0U; }
auto get_used_drive_space() const -> std::uint64_t override { return 0U; }
void get_volume_info(UINT64 &total_size, UINT64 &free_size,
std::string &volume_label) const override {
free_size = 100u;
total_size = 200u;
volume_label = "TestVolumeLabel";
}
auto rename_directory(const std::string &from_api_path,
const std::string &to_api_path) -> int override {
const auto from_file_path =
utils::path::combine(mount_location_, {from_api_path});
const auto to_file_path =
utils::path::combine(mount_location_, {to_api_path});
return rename(from_file_path.c_str(), to_file_path.c_str());
}
auto rename_file(const std::string &from_api_path,
const std::string &to_api_path, bool overwrite)
-> int override {
const auto from_file_path =
utils::path::combine(mount_location_, {from_api_path});
const auto to_file_path =
utils::path::combine(mount_location_, {to_api_path});
if (overwrite) {
if (not utils::file::retry_delete_file(to_file_path)) {
return -1;
}
} else if (utils::file::is_directory(to_file_path) ||
utils::file::is_file(to_file_path)) {
errno = EEXIST;
return -1;
}
return rename(from_file_path.c_str(), to_file_path.c_str());
}
auto is_processing(const std::string &) const -> bool override {
return false;
}
void set_item_meta(const std::string &api_path, const std::string &key,
const std::string &value) override {
meta_[api_path][key] = value;
}
};
} // namespace repertory
#endif // _WIN32
#endif // TESTS_MOCKS_MOCK_FUSE_DRIVE_HPP_

View File

@@ -1,97 +1,99 @@
/*
Copyright <2018-2023> <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.
*/
#ifndef TESTS_MOCKS_MOCK_OPEN_FILE_HPP_
#define TESTS_MOCKS_MOCK_OPEN_FILE_HPP_
#include "test_common.hpp"
#include "file_manager/i_open_file.hpp"
namespace repertory {
class mock_open_file : public virtual i_closeable_open_file {
public:
MOCK_METHOD(std::string, get_api_path, (), (const, override));
MOCK_METHOD(std::size_t, get_chunk_size, (), (const, override));
MOCK_METHOD(std::uint64_t, get_file_size, (), (const, override));
MOCK_METHOD(filesystem_item, get_filesystem_item, (), (const, override));
MOCK_METHOD(open_file_data, get_open_data, (std::uint64_t handle),
(const, override));
MOCK_METHOD(std::size_t, get_open_file_count, (), (const, override));
MOCK_METHOD(boost::dynamic_bitset<>, get_read_state, (), (const, override));
MOCK_METHOD(bool, get_read_state, (std::size_t chunk), (const, override));
MOCK_METHOD(std::string, get_source_path, (), (const, override));
MOCK_METHOD(bool, is_directory, (), (const, override));
MOCK_METHOD(api_error, native_operation,
(const native_operation_callback &cb), (override));
MOCK_METHOD(api_error, native_operation,
(std::uint64_t new_file_size,
const native_operation_callback &cb),
(override));
MOCK_METHOD(api_error, read,
(std::size_t read_size, std::uint64_t read_offset,
data_buffer &data),
(override));
MOCK_METHOD(api_error, resize, (std::uint64_t new_file_size), (override));
MOCK_METHOD(void, set_api_path, (const std::string &api_path), (override));
MOCK_METHOD(api_error, write,
(std::uint64_t write_offset, const data_buffer &data,
std::size_t &bytes_written),
(override));
MOCK_METHOD(void, add, (std::uint64_t handle, open_file_data ofd),
(override));
MOCK_METHOD(bool, can_close, (), (const, override));
MOCK_METHOD(bool, close, (), (override));
MOCK_METHOD(std::vector<std::uint64_t>, get_handles, (), (const, override));
MOCK_METHOD((std::map<std::uint64_t, open_file_data>), get_open_data, (),
(const, override));
MOCK_METHOD(bool, is_complete, (), (const, override));
MOCK_METHOD(bool, is_modified, (), (const, override));
MOCK_METHOD(bool, is_write_supported, (), (const, override));
MOCK_METHOD(void, remove, (std::uint64_t handle), (override));
};
} // namespace repertory
#endif // TESTS_MOCKS_MOCK_OPEN_FILE_HPP_
/*
Copyright <2018-2023> <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.
*/
#ifndef TESTS_MOCKS_MOCK_OPEN_FILE_HPP_
#define TESTS_MOCKS_MOCK_OPEN_FILE_HPP_
#include "test_common.hpp"
#include "file_manager/i_open_file.hpp"
namespace repertory {
class mock_open_file : public virtual i_closeable_open_file {
public:
MOCK_METHOD(std::string, get_api_path, (), (const, override));
MOCK_METHOD(std::size_t, get_chunk_size, (), (const, override));
MOCK_METHOD(std::uint64_t, get_file_size, (), (const, override));
MOCK_METHOD(filesystem_item, get_filesystem_item, (), (const, override));
MOCK_METHOD(open_file_data, get_open_data, (std::uint64_t handle),
(const, override));
MOCK_METHOD(std::size_t, get_open_file_count, (), (const, override));
MOCK_METHOD(boost::dynamic_bitset<>, get_read_state, (), (const, override));
MOCK_METHOD(bool, get_read_state, (std::size_t chunk), (const, override));
MOCK_METHOD(std::string, get_source_path, (), (const, override));
MOCK_METHOD(bool, has_handle, (std::uint64_t handle), (const, override));
MOCK_METHOD(bool, is_directory, (), (const, override));
MOCK_METHOD(api_error, native_operation,
(const native_operation_callback &callback), (override));
MOCK_METHOD(api_error, native_operation,
(std::uint64_t new_file_size,
const native_operation_callback &callback),
(override));
MOCK_METHOD(api_error, read,
(std::size_t read_size, std::uint64_t read_offset,
data_buffer &data),
(override));
MOCK_METHOD(api_error, resize, (std::uint64_t new_file_size), (override));
MOCK_METHOD(void, set_api_path, (const std::string &api_path), (override));
MOCK_METHOD(api_error, write,
(std::uint64_t write_offset, const data_buffer &data,
std::size_t &bytes_written),
(override));
MOCK_METHOD(void, add, (std::uint64_t handle, open_file_data ofd),
(override));
MOCK_METHOD(bool, can_close, (), (const, override));
MOCK_METHOD(bool, close, (), (override));
MOCK_METHOD(std::vector<std::uint64_t>, get_handles, (), (const, override));
MOCK_METHOD((std::map<std::uint64_t, open_file_data>), get_open_data, (),
(const, override));
MOCK_METHOD(bool, is_complete, (), (const, override));
MOCK_METHOD(bool, is_modified, (), (const, override));
MOCK_METHOD(bool, is_write_supported, (), (const, override));
MOCK_METHOD(void, remove, (std::uint64_t handle), (override));
};
} // namespace repertory
#endif // TESTS_MOCKS_MOCK_OPEN_FILE_HPP_

View File

@@ -1,162 +1,162 @@
/*
Copyright <2018-2023> <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.
*/
#ifndef TESTS_MOCKS_MOCK_PROVIDER_HPP_
#define TESTS_MOCKS_MOCK_PROVIDER_HPP_
#include "test_common.hpp"
#include "providers/i_provider.hpp"
#include "types/repertory.hpp"
namespace repertory {
class mock_provider : public virtual i_provider {
public:
mock_provider(bool allow_rename = true) : allow_rename_(allow_rename) {}
private:
const bool allow_rename_;
public:
MOCK_METHOD(api_error, create_directory,
(const std::string &api_path, api_meta_map &meta), (override));
MOCK_METHOD(api_error, create_directory_clone_source_meta,
(const std::string &source_api_path, const std::string &api_path),
(override));
MOCK_METHOD(api_error, create_file,
(const std::string &api_path, api_meta_map &meta), (override));
MOCK_METHOD(api_error, get_api_path_from_source,
(const std::string &source_path, std::string &api_path),
(const, override));
MOCK_METHOD(std::uint64_t, get_directory_item_count,
(const std::string &api_path), (const, override));
MOCK_METHOD(api_error, get_directory_items,
(const std::string &api_path, directory_item_list &list),
(const, override));
MOCK_METHOD(api_error, get_file,
(const std::string &api_path, api_file &file), (const, override));
MOCK_METHOD(api_error, get_file_list, (api_file_list & list),
(const, override));
MOCK_METHOD(api_error, get_file_size,
(const std::string &api_path, std::uint64_t &file_size),
(const, override));
MOCK_METHOD(api_error, get_filesystem_item,
(const std::string &api_path, bool directory,
filesystem_item &fsi),
(const, override));
MOCK_METHOD(api_error, get_filesystem_item_and_file,
(const std::string &api_path, api_file &file,
filesystem_item &fsi),
(const, override));
MOCK_METHOD(api_error, get_filesystem_item_from_source_path,
(const std::string &source_path, filesystem_item &fsi),
(const, override));
MOCK_METHOD(api_error, get_item_meta,
(const std::string &api_path, api_meta_map &meta),
(const, override));
MOCK_METHOD(api_error, get_item_meta,
(const std::string &api_path, const std::string &key,
std::string &value),
(const, override));
MOCK_METHOD((std::vector<std::string>), get_pinned_files, (),
(const, override));
MOCK_METHOD(provider_type, get_provider_type, (), (const, override));
MOCK_METHOD(std::uint64_t, get_total_drive_space, (), (const, override));
MOCK_METHOD(std::uint64_t, get_total_item_count, (), (const, override));
MOCK_METHOD(std::uint64_t, get_used_drive_space, (), (const, override));
MOCK_METHOD(bool, is_direct_only, (), (const, override));
MOCK_METHOD(api_error, is_directory,
(const std::string &api_path, bool &exists), (const, override));
MOCK_METHOD(api_error, is_file, (const std::string &api_path, bool &exists),
(const, override));
bool is_file_writeable(const std::string & /* api_path */) const override {
return true;
}
MOCK_METHOD(bool, is_online, (), (const, override));
bool is_rename_supported() const override { return allow_rename_; }
MOCK_METHOD(api_error, read_file_bytes,
(const std::string &path, std::size_t size, std::uint64_t offset,
data_buffer &data, stop_type &stop_requested),
(override));
MOCK_METHOD(api_error, remove_directory, (const std::string &api_path),
(override));
MOCK_METHOD(api_error, remove_file, (const std::string &api_path),
(override));
MOCK_METHOD(api_error, remove_item_meta,
(const std::string &api_path, const std::string &key),
(override));
MOCK_METHOD(api_error, rename_file,
(const std::string &from_api_path,
const std::string &to_api_path),
(override));
MOCK_METHOD(api_error, set_item_meta,
(const std::string &api_path, const std::string &key,
const std::string &value),
(override));
MOCK_METHOD(api_error, set_item_meta,
(const std::string &api_path, const api_meta_map &meta),
(override));
MOCK_METHOD(bool, start,
(api_item_added_callback api_item_added, i_file_manager *fm),
(override));
MOCK_METHOD(void, stop, (), (override));
MOCK_METHOD(api_error, upload_file,
(const std::string &api_path, const std::string &source_path,
const std::string &encryption_token, stop_type &stop_requested),
(override));
};
} // namespace repertory
#endif // TESTS_MOCKS_MOCK_PROVIDER_HPP_
/*
Copyright <2018-2023> <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.
*/
#ifndef TESTS_MOCKS_MOCK_PROVIDER_HPP_
#define TESTS_MOCKS_MOCK_PROVIDER_HPP_
#include "test_common.hpp"
#include "providers/i_provider.hpp"
#include "types/repertory.hpp"
namespace repertory {
class mock_provider : public virtual i_provider {
public:
mock_provider(bool allow_rename = true) : allow_rename_(allow_rename) {}
private:
const bool allow_rename_;
public:
MOCK_METHOD(api_error, create_directory,
(const std::string &api_path, api_meta_map &meta), (override));
MOCK_METHOD(api_error, create_directory_clone_source_meta,
(const std::string &source_api_path, const std::string &api_path),
(override));
MOCK_METHOD(api_error, create_file,
(const std::string &api_path, api_meta_map &meta), (override));
MOCK_METHOD(api_error, get_api_path_from_source,
(const std::string &source_path, std::string &api_path),
(const, override));
MOCK_METHOD(std::uint64_t, get_directory_item_count,
(const std::string &api_path), (const, override));
MOCK_METHOD(api_error, get_directory_items,
(const std::string &api_path, directory_item_list &list),
(const, override));
MOCK_METHOD(api_error, get_file,
(const std::string &api_path, api_file &file), (const, override));
MOCK_METHOD(api_error, get_file_list, (api_file_list & list),
(const, override));
MOCK_METHOD(api_error, get_file_size,
(const std::string &api_path, std::uint64_t &file_size),
(const, override));
MOCK_METHOD(api_error, get_filesystem_item,
(const std::string &api_path, bool directory,
filesystem_item &fsi),
(const, override));
MOCK_METHOD(api_error, get_filesystem_item_and_file,
(const std::string &api_path, api_file &file,
filesystem_item &fsi),
(const, override));
MOCK_METHOD(api_error, get_filesystem_item_from_source_path,
(const std::string &source_path, filesystem_item &fsi),
(const, override));
MOCK_METHOD(api_error, get_item_meta,
(const std::string &api_path, api_meta_map &meta),
(const, override));
MOCK_METHOD(api_error, get_item_meta,
(const std::string &api_path, const std::string &key,
std::string &value),
(const, override));
MOCK_METHOD((std::vector<std::string>), get_pinned_files, (),
(const, override));
MOCK_METHOD(provider_type, get_provider_type, (), (const, override));
MOCK_METHOD(std::uint64_t, get_total_drive_space, (), (const, override));
MOCK_METHOD(std::uint64_t, get_total_item_count, (), (const, override));
MOCK_METHOD(std::uint64_t, get_used_drive_space, (), (const, override));
MOCK_METHOD(bool, is_direct_only, (), (const, override));
MOCK_METHOD(api_error, is_directory,
(const std::string &api_path, bool &exists), (const, override));
MOCK_METHOD(api_error, is_file, (const std::string &api_path, bool &exists),
(const, override));
bool is_file_writeable(const std::string & /* api_path */) const override {
return true;
}
MOCK_METHOD(bool, is_online, (), (const, override));
bool is_rename_supported() const override { return allow_rename_; }
MOCK_METHOD(api_error, read_file_bytes,
(const std::string &path, std::size_t size, std::uint64_t offset,
data_buffer &data, stop_type &stop_requested),
(override));
MOCK_METHOD(api_error, remove_directory, (const std::string &api_path),
(override));
MOCK_METHOD(api_error, remove_file, (const std::string &api_path),
(override));
MOCK_METHOD(api_error, remove_item_meta,
(const std::string &api_path, const std::string &key),
(override));
MOCK_METHOD(api_error, rename_file,
(const std::string &from_api_path,
const std::string &to_api_path),
(override));
MOCK_METHOD(api_error, set_item_meta,
(const std::string &api_path, const std::string &key,
const std::string &value),
(override));
MOCK_METHOD(api_error, set_item_meta,
(const std::string &api_path, const api_meta_map &meta),
(override));
MOCK_METHOD(bool, start,
(api_item_added_callback api_item_added, i_file_manager *fm),
(override));
MOCK_METHOD(void, stop, (), (override));
MOCK_METHOD(api_error, upload_file,
(const std::string &api_path, const std::string &source_path,
stop_type &stop_requested),
(override));
};
} // namespace repertory
#endif // TESTS_MOCKS_MOCK_PROVIDER_HPP_

View File

@@ -1,186 +0,0 @@
/*
Copyright <2018-2023> <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.
*/
#ifndef TESTS_MOCKS_MOCK_S3_COMM_HPP_
#define TESTS_MOCKS_MOCK_S3_COMM_HPP_
#if defined(REPERTORY_ENABLE_S3) && defined(REPERTORY_ENABLE_S3_TESTING)
#include "test_common.hpp"
#include "comm/i_s3_comm.hpp"
#include "types/repertory.hpp"
namespace repertory {
class mock_s3_comm final : public i_s3_comm {
public:
mock_s3_comm(s3_config cfg) : s3_config_(cfg) {}
private:
s3_config s3_config_;
public:
// [[nodiscard]] virtual api_error create_directory(const std::string
// &api_path) = 0;
//
MOCK_METHOD(api_error, create_directory, (const std::string &api_path),
(override));
// [[nodiscard]] virtual api_error directory_exists(const std::string
// &api_path) const = 0;
//
MOCK_METHOD(api_error, directory_exists, (const std::string &api_path),
(const, override));
// [[nodiscard]] virtual api_error file_exists(const std::string &api_path,
// const get_key_callback
// &get_key) const = 0;
MOCK_METHOD(api_error, file_exists,
(const std::string &api_path, const get_key_callback &get_key),
(const, override));
// [[nodiscard]] virtual std::size_t
// get_directory_item_count(const std::string &api_path,
// meta_provider_callback meta_provider) const
// = 0;
//
MOCK_METHOD(std::size_t, get_directory_item_count,
(const std::string &api_path,
meta_provider_callback meta_provider),
(const, override));
// [[nodiscard]] virtual api_error get_directory_items(const std::string
// &api_path,
// const
// meta_provider_callback
// &meta_provider,
// directory_item_list
// &list) const = 0;
//
MOCK_METHOD(api_error, get_directory_items,
(const std::string &api_path,
meta_provider_callback meta_provider,
directory_item_list &list),
(const, override));
// [[nodiscard]] virtual api_error
// get_directory_list(api_file_list &list) const = 0;
//
MOCK_METHOD(api_error, get_directory_list, (api_file_list & list),
(const, override));
// [[nodiscard]] virtual api_error get_file(const std::string &api_path,
// const get_key_callback &get_key,
// const get_name_callback &get_name,
// const get_token_callback
// &get_token, api_file &file) const
// = 0;
//
MOCK_METHOD(api_error, get_file,
(const std::string &api_path, const get_key_callback &get_key,
const get_name_callback &get_name,
const get_token_callback &get_token, api_file &file),
(const, override));
// [[nodiscard]] virtual api_error
// get_file_list(const get_api_file_token_callback &get_api_file_token,
// const get_name_callback &get_name, api_file_list &list) const
// = 0;
//
MOCK_METHOD(api_error, get_file_list,
(const get_api_file_token_callback &get_api_file_token,
const get_name_callback &get_name, api_file_list &list),
(const, override));
// [[nodiscard]] virtual api_error get_object_list(std::vector<directory_item>
// &list) const = 0;
//
MOCK_METHOD(api_error, get_object_list, (std::vector<directory_item> & list),
(const, override));
// virtual std::string get_object_name(const std::string &api_path,
// const get_key_callback &get_key) const
// = 0;
//
MOCK_METHOD(std::string, get_object_name,
(const std::string &api_path, const get_key_callback &get_key),
(const, override));
[[nodiscard]] s3_config get_s3_config() override { return s3_config_; }
[[nodiscard]] s3_config get_s3_config() const override { return s3_config_; }
// [[nodiscard]] virtual bool is_online() const = 0;
//
MOCK_METHOD(bool, is_online, (), (const, override));
// [[nodiscard]] virtual api_error
// read_file_bytes(const std::string &api_path, std::size_t size, const
// std::uint64_t &offset,
// data_buffer &data, const get_key_callback &get_key,
// const get_size_callback &get_size, const get_token_callback
// &get_token, stop_type &stop_requested) const = 0;
//
MOCK_METHOD(api_error, read_file_bytes,
(const std::string &api_path, std::size_t size,
std::uint64_t offset, data_buffer &data,
const get_key_callback &get_key,
const get_size_callback &get_size,
const get_token_callback &get_token, stop_type &stop_requested),
(const, override));
// [[nodiscard]] virtual api_error remove_directory(const std::string
// &api_path) = 0;
//
MOCK_METHOD(api_error, remove_directory, (const std::string &api_path),
(override));
// [[nodiscard]] virtual api_error remove_file(const std::string &api_path,
// const get_key_callback
// &get_key) = 0;
//
MOCK_METHOD(api_error, remove_file,
(const std::string &api_path, const get_key_callback &get_key),
(override));
// [[nodiscard]] virtual api_error rename_file(const std::string &api_path,
// const std::string
// &new_api_path) = 0;
//
MOCK_METHOD(api_error, rename_file,
(const std::string &api_path, const std::string &new_api_path),
(override));
// [[nodiscard]] virtual api_error
// upload_file(const std::string &api_path, const std::string &source_path,
// const std::string &encryption_token, const get_key_callback
// &get_key, const set_key_callback &set_key, stop_type
// &stop_requested) = 0;
MOCK_METHOD(api_error, upload_file,
(const std::string &api_path, const std::string &source_path,
const std::string &encryption_token,
const get_key_callback &get_key, const set_key_callback &set_key,
stop_type &stop_requested),
(override));
};
} // namespace repertory
#endif // REPERTORY_ENABLE_S3_TESTING
#endif // TESTS_MOCKS_MOCK_S3_COMM_HPP_

View File

@@ -1,44 +1,44 @@
/*
Copyright <2018-2023> <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.
*/
#ifndef TESTS_MOCKS_MOCK_UPLOAD_MANAGER_HPP_
#define TESTS_MOCKS_MOCK_UPLOAD_MANAGER_HPP_
#include "test_common.hpp"
#include "file_manager/i_upload_manager.hpp"
namespace repertory {
class mock_upload_manager : public i_upload_manager {
public:
MOCK_METHOD(void, queue_upload, (const i_open_file &o), (override));
MOCK_METHOD(void, remove_resume,
(const std::string &api_path, const std::string &source_path),
(override));
MOCK_METHOD(void, remove_upload, (const std::string &api_path), (override));
MOCK_METHOD(void, store_resume, (const i_open_file &o), (override));
};
} // namespace repertory
#endif // TESTS_MOCKS_MOCK_UPLOAD_MANAGER_HPP_
/*
Copyright <2018-2023> <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.
*/
#ifndef TESTS_MOCKS_MOCK_UPLOAD_MANAGER_HPP_
#define TESTS_MOCKS_MOCK_UPLOAD_MANAGER_HPP_
#include "test_common.hpp"
#include "file_manager/i_upload_manager.hpp"
namespace repertory {
class mock_upload_manager : public i_upload_manager {
public:
MOCK_METHOD(void, queue_upload, (const i_open_file &o), (override));
MOCK_METHOD(void, remove_resume,
(const std::string &api_path, const std::string &source_path),
(override));
MOCK_METHOD(void, remove_upload, (const std::string &api_path), (override));
MOCK_METHOD(void, store_resume, (const i_open_file &o), (override));
};
} // namespace repertory
#endif // TESTS_MOCKS_MOCK_UPLOAD_MANAGER_HPP_

View File

@@ -1,168 +1,168 @@
/*
Copyright <2018-2023> <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.
*/
#ifndef TESTS_MOCKS_MOCK_WINFSP_DRIVE_HPP_
#define TESTS_MOCKS_MOCK_WINFSP_DRIVE_HPP_
#ifdef _WIN32
#include "test_common.hpp"
#include "drives/winfsp/i_winfsp_drive.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/utils.hpp"
namespace repertory {
class mock_winfsp_drive final : public virtual i_winfsp_drive {
public:
explicit mock_winfsp_drive(std::string mount_location)
: mount_location_(std::move(mount_location)) {}
private:
const std::string mount_location_;
public:
[[nodiscard]] auto
get_directory_item_count(const std::string & /*api_path*/) const
-> std::uint64_t override {
return 1;
}
[[nodiscard]] auto get_directory_items(const std::string & /*api_path*/) const
-> directory_item_list override {
directory_item_list list{};
directory_item di{};
di.api_path = ".";
di.directory = true;
di.size = 0u;
di.meta = {{META_ATTRIBUTES, "16"},
{META_MODIFIED, std::to_string(utils::get_file_time_now())},
{META_WRITTEN, std::to_string(utils::get_file_time_now())},
{META_ACCESSED, std::to_string(utils::get_file_time_now())},
{META_CREATION, std::to_string(utils::get_file_time_now())}};
list.emplace_back(di);
di.api_path = "..";
list.emplace_back(di);
return list;
}
[[nodiscard]] auto get_file_size(const std::string & /*api_path*/) const
-> std::uint64_t override {
return 0;
}
auto get_item_meta(const std::string & /*api_path*/, api_meta_map &meta) const
-> api_error override {
return api_error::error;
}
auto get_item_meta(const std::string & /*api_path*/,
const std::string & /*name*/,
std::string & /*value*/) const -> api_error override {
return api_error::error;
}
auto get_security_by_name(PWSTR /*file_name*/, PUINT32 attributes,
PSECURITY_DESCRIPTOR descriptor,
std::uint64_t *descriptor_size)
-> NTSTATUS override {
auto ret = STATUS_SUCCESS;
if (attributes) {
*attributes = FILE_ATTRIBUTE_NORMAL;
}
if (descriptor_size) {
ULONG sz = 0;
PSECURITY_DESCRIPTOR sd = nullptr;
if (::ConvertStringSecurityDescriptorToSecurityDescriptor(
"O:BAG:BAD:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;FA;;;WD)",
SDDL_REVISION_1, &sd, &sz)) {
if (sz > *descriptor_size) {
ret = STATUS_BUFFER_TOO_SMALL;
} else {
::CopyMemory(descriptor, sd, sz);
}
*descriptor_size = sz;
::LocalFree(sd);
} else {
ret = FspNtStatusFromWin32(::GetLastError());
}
}
return ret;
}
[[nodiscard]] auto get_total_drive_space() const -> std::uint64_t override {
return 100 * 1024 * 1024;
}
[[nodiscard]] auto get_total_item_count() const -> std::uint64_t override {
return 0;
}
[[nodiscard]] auto get_used_drive_space() const -> std::uint64_t override {
return 0;
}
void get_volume_info(UINT64 &total_size, UINT64 &free_size,
std::string &volume_label) const override {
free_size = 100;
total_size = 200;
volume_label = "TestVolumeLabel";
}
auto populate_file_info(const std::string &api_path,
remote::file_info &file_info) -> api_error override {
const auto file_path = utils::path::combine(mount_location_, {api_path});
const auto directory = utils::file::is_directory(file_path);
const auto attributes =
FILE_FLAG_BACKUP_SEMANTICS |
(directory ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL);
const auto share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE;
auto handle = ::CreateFileA(&file_path[0], GENERIC_READ, share_mode,
nullptr, OPEN_EXISTING, attributes, nullptr);
FILE_BASIC_INFO fi{};
::GetFileInformationByHandleEx(handle, FileBasicInfo, &fi, sizeof(fi));
if (not directory) {
utils::file::get_file_size(file_path, file_info.FileSize);
}
file_info.AllocationSize =
directory ? 0
: utils::divide_with_ceiling(file_info.FileSize,
WINFSP_ALLOCATION_UNIT) *
WINFSP_ALLOCATION_UNIT;
file_info.FileAttributes = fi.FileAttributes;
file_info.ChangeTime = fi.ChangeTime.QuadPart;
file_info.CreationTime = fi.CreationTime.QuadPart;
file_info.LastAccessTime = fi.LastAccessTime.QuadPart;
file_info.LastWriteTime = fi.LastWriteTime.QuadPart;
::CloseHandle(handle);
return api_error::success;
}
};
} // namespace repertory
#endif // _WIN32
#endif // TESTS_MOCKS_MOCK_WINFSP_DRIVE_HPP_
/*
Copyright <2018-2023> <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.
*/
#ifndef TESTS_MOCKS_MOCK_WINFSP_DRIVE_HPP_
#define TESTS_MOCKS_MOCK_WINFSP_DRIVE_HPP_
#ifdef _WIN32
#include "test_common.hpp"
#include "drives/winfsp/i_winfsp_drive.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/utils.hpp"
namespace repertory {
class mock_winfsp_drive final : public virtual i_winfsp_drive {
public:
explicit mock_winfsp_drive(std::string mount_location)
: mount_location_(std::move(mount_location)) {}
private:
const std::string mount_location_;
public:
[[nodiscard]] auto
get_directory_item_count(const std::string & /*api_path*/) const
-> std::uint64_t override {
return 1;
}
[[nodiscard]] auto get_directory_items(const std::string & /*api_path*/) const
-> directory_item_list override {
directory_item_list list{};
directory_item di{};
di.api_path = ".";
di.directory = true;
di.size = 0u;
di.meta = {{META_ATTRIBUTES, "16"},
{META_MODIFIED, std::to_string(utils::get_file_time_now())},
{META_WRITTEN, std::to_string(utils::get_file_time_now())},
{META_ACCESSED, std::to_string(utils::get_file_time_now())},
{META_CREATION, std::to_string(utils::get_file_time_now())}};
list.emplace_back(di);
di.api_path = "..";
list.emplace_back(di);
return list;
}
[[nodiscard]] auto get_file_size(const std::string & /*api_path*/) const
-> std::uint64_t override {
return 0;
}
auto get_item_meta(const std::string & /*api_path*/, api_meta_map &meta) const
-> api_error override {
return api_error::error;
}
auto get_item_meta(const std::string & /*api_path*/,
const std::string & /*name*/,
std::string & /*value*/) const -> api_error override {
return api_error::error;
}
auto get_security_by_name(PWSTR /*file_name*/, PUINT32 attributes,
PSECURITY_DESCRIPTOR descriptor,
std::uint64_t *descriptor_size)
-> NTSTATUS override {
auto ret = STATUS_SUCCESS;
if (attributes) {
*attributes = FILE_ATTRIBUTE_NORMAL;
}
if (descriptor_size) {
ULONG sz = 0;
PSECURITY_DESCRIPTOR sd = nullptr;
if (::ConvertStringSecurityDescriptorToSecurityDescriptor(
"O:BAG:BAD:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;FA;;;WD)",
SDDL_REVISION_1, &sd, &sz)) {
if (sz > *descriptor_size) {
ret = STATUS_BUFFER_TOO_SMALL;
} else {
::CopyMemory(descriptor, sd, sz);
}
*descriptor_size = sz;
::LocalFree(sd);
} else {
ret = FspNtStatusFromWin32(::GetLastError());
}
}
return ret;
}
[[nodiscard]] auto get_total_drive_space() const -> std::uint64_t override {
return 100 * 1024 * 1024;
}
[[nodiscard]] auto get_total_item_count() const -> std::uint64_t override {
return 0;
}
[[nodiscard]] auto get_used_drive_space() const -> std::uint64_t override {
return 0;
}
void get_volume_info(UINT64 &total_size, UINT64 &free_size,
std::string &volume_label) const override {
free_size = 100;
total_size = 200;
volume_label = "TestVolumeLabel";
}
auto populate_file_info(const std::string &api_path,
remote::file_info &file_info) -> api_error override {
const auto file_path = utils::path::combine(mount_location_, {api_path});
const auto directory = utils::file::is_directory(file_path);
const auto attributes =
FILE_FLAG_BACKUP_SEMANTICS |
(directory ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL);
const auto share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE;
auto handle = ::CreateFileA(&file_path[0], GENERIC_READ, share_mode,
nullptr, OPEN_EXISTING, attributes, nullptr);
FILE_BASIC_INFO fi{};
::GetFileInformationByHandleEx(handle, FileBasicInfo, &fi, sizeof(fi));
if (not directory) {
utils::file::get_file_size(file_path, file_info.FileSize);
}
file_info.AllocationSize =
directory ? 0
: utils::divide_with_ceiling(file_info.FileSize,
WINFSP_ALLOCATION_UNIT) *
WINFSP_ALLOCATION_UNIT;
file_info.FileAttributes = fi.FileAttributes;
file_info.ChangeTime = fi.ChangeTime.QuadPart;
file_info.CreationTime = fi.CreationTime.QuadPart;
file_info.LastAccessTime = fi.LastAccessTime.QuadPart;
file_info.LastWriteTime = fi.LastWriteTime.QuadPart;
::CloseHandle(handle);
return api_error::success;
}
};
} // namespace repertory
#endif // _WIN32
#endif // TESTS_MOCKS_MOCK_WINFSP_DRIVE_HPP_

View File

@@ -1,41 +1,41 @@
/*
Copyright <2018-2023> <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_common.hpp"
#include "comm/packet/packet.hpp"
namespace repertory {
TEST(packet, encrypt_and_decrypt) {
packet packet;
packet.encode("test");
packet.encrypt("moose");
std::uint32_t size{};
EXPECT_EQ(0, packet.decode(size));
EXPECT_EQ(0, packet.decrypt("moose"));
std::string data;
EXPECT_EQ(0, packet.decode(data));
EXPECT_STREQ("test", data.c_str());
}
} // namespace repertory
/*
Copyright <2018-2023> <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_common.hpp"
#include "comm/packet/packet.hpp"
namespace repertory {
TEST(packet, encrypt_and_decrypt) {
packet test_packet;
test_packet.encode("test");
test_packet.encrypt("moose");
std::uint32_t size{};
EXPECT_EQ(0, test_packet.decode(size));
EXPECT_EQ(0, test_packet.decrypt("moose"));
std::string data;
EXPECT_EQ(0, test_packet.decode(data));
EXPECT_STREQ("test", data.c_str());
}
} // namespace repertory

View File

@@ -1,133 +1,133 @@
/*
Copyright <2018-2023> <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_common.hpp"
#include "utils/path_utils.hpp"
namespace repertory {
TEST(path_utils, combine) {
auto s = utils::path::combine(R"(\test\path)", {});
#ifdef _WIN32
EXPECT_STREQ(R"(\test\path)", s.c_str());
#else
EXPECT_STREQ("/test/path", s.c_str());
#endif
s = utils::path::combine(R"(\test)", {R"(\path)"});
#ifdef _WIN32
EXPECT_STREQ(R"(\test\path)", s.c_str());
#else
EXPECT_STREQ("/test/path", s.c_str());
#endif
s = utils::path::combine(R"(\test)", {R"(\path)", R"(\again\)"});
#ifdef _WIN32
EXPECT_STREQ(R"(\test\path\again)", s.c_str());
#else
EXPECT_STREQ("/test/path/again", s.c_str());
#endif
}
TEST(path_utils, create_api_path) {
auto s = utils::path::create_api_path("");
EXPECT_STREQ("/", s.c_str());
s = utils::path::create_api_path(R"(\)");
EXPECT_STREQ("/", s.c_str());
s = utils::path::create_api_path("/");
EXPECT_STREQ("/", s.c_str());
s = utils::path::create_api_path(".");
EXPECT_STREQ("/", s.c_str());
s = utils::path::create_api_path(R"(\\)");
EXPECT_STREQ("/", s.c_str());
s = utils::path::create_api_path("//");
EXPECT_STREQ("/", s.c_str());
s = utils::path::create_api_path("/cow///moose/////dog/chicken");
EXPECT_STREQ("/cow/moose/dog/chicken", s.c_str());
s = utils::path::create_api_path("\\cow\\\\\\moose\\\\\\\\dog\\chicken/");
EXPECT_STREQ("/cow/moose/dog/chicken", s.c_str());
s = utils::path::create_api_path("/cow\\\\/moose\\\\/\\dog\\chicken\\");
EXPECT_STREQ("/cow/moose/dog/chicken", s.c_str());
}
TEST(path_utils, finalize) {
auto s = utils::path::finalize("");
EXPECT_STREQ("", s.c_str());
s = utils::path::finalize(R"(\)");
#ifdef _WIN32
EXPECT_STREQ(R"(\)", s.c_str());
#else
EXPECT_STREQ("/", s.c_str());
#endif
s = utils::path::finalize("/");
#ifdef _WIN32
EXPECT_STREQ(R"(\)", s.c_str());
#else
EXPECT_STREQ("/", s.c_str());
#endif
s = utils::path::finalize(R"(\\)");
#ifdef _WIN32
EXPECT_STREQ(R"(\)", s.c_str());
#else
EXPECT_STREQ("/", s.c_str());
#endif
s = utils::path::finalize("//");
#ifdef _WIN32
EXPECT_STREQ(R"(\)", s.c_str());
#else
EXPECT_STREQ("/", s.c_str());
#endif
s = utils::path::finalize("/cow///moose/////dog/chicken");
#ifdef _WIN32
EXPECT_STREQ(R"(\cow\moose\dog\chicken)", s.c_str());
#else
EXPECT_STREQ("/cow/moose/dog/chicken", s.c_str());
#endif
s = utils::path::finalize("\\cow\\\\\\moose\\\\\\\\dog\\chicken/");
#ifdef _WIN32
EXPECT_STREQ(R"(\cow\moose\dog\chicken)", s.c_str());
#else
EXPECT_STREQ("/cow/moose/dog/chicken", s.c_str());
#endif
s = utils::path::finalize("/cow\\\\/moose\\\\/\\dog\\chicken\\");
#ifdef _WIN32
EXPECT_STREQ(R"(\cow\moose\dog\chicken)", s.c_str());
#else
EXPECT_STREQ("/cow/moose/dog/chicken", s.c_str());
#endif
}
} // namespace repertory
/*
Copyright <2018-2023> <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_common.hpp"
#include "utils/path_utils.hpp"
namespace repertory {
TEST(path_utils, combine) {
auto s = utils::path::combine(R"(\test\path)", {});
#ifdef _WIN32
EXPECT_STREQ(R"(\test\path)", s.c_str());
#else
EXPECT_STREQ("/test/path", s.c_str());
#endif
s = utils::path::combine(R"(\test)", {R"(\path)"});
#ifdef _WIN32
EXPECT_STREQ(R"(\test\path)", s.c_str());
#else
EXPECT_STREQ("/test/path", s.c_str());
#endif
s = utils::path::combine(R"(\test)", {R"(\path)", R"(\again\)"});
#ifdef _WIN32
EXPECT_STREQ(R"(\test\path\again)", s.c_str());
#else
EXPECT_STREQ("/test/path/again", s.c_str());
#endif
}
TEST(path_utils, create_api_path) {
auto s = utils::path::create_api_path("");
EXPECT_STREQ("/", s.c_str());
s = utils::path::create_api_path(R"(\)");
EXPECT_STREQ("/", s.c_str());
s = utils::path::create_api_path("/");
EXPECT_STREQ("/", s.c_str());
s = utils::path::create_api_path(".");
EXPECT_STREQ("/", s.c_str());
s = utils::path::create_api_path(R"(\\)");
EXPECT_STREQ("/", s.c_str());
s = utils::path::create_api_path("//");
EXPECT_STREQ("/", s.c_str());
s = utils::path::create_api_path("/cow///moose/////dog/chicken");
EXPECT_STREQ("/cow/moose/dog/chicken", s.c_str());
s = utils::path::create_api_path("\\cow\\\\\\moose\\\\\\\\dog\\chicken/");
EXPECT_STREQ("/cow/moose/dog/chicken", s.c_str());
s = utils::path::create_api_path("/cow\\\\/moose\\\\/\\dog\\chicken\\");
EXPECT_STREQ("/cow/moose/dog/chicken", s.c_str());
}
TEST(path_utils, finalize) {
auto s = utils::path::finalize("");
EXPECT_STREQ("", s.c_str());
s = utils::path::finalize(R"(\)");
#ifdef _WIN32
EXPECT_STREQ(R"(\)", s.c_str());
#else
EXPECT_STREQ("/", s.c_str());
#endif
s = utils::path::finalize("/");
#ifdef _WIN32
EXPECT_STREQ(R"(\)", s.c_str());
#else
EXPECT_STREQ("/", s.c_str());
#endif
s = utils::path::finalize(R"(\\)");
#ifdef _WIN32
EXPECT_STREQ(R"(\)", s.c_str());
#else
EXPECT_STREQ("/", s.c_str());
#endif
s = utils::path::finalize("//");
#ifdef _WIN32
EXPECT_STREQ(R"(\)", s.c_str());
#else
EXPECT_STREQ("/", s.c_str());
#endif
s = utils::path::finalize("/cow///moose/////dog/chicken");
#ifdef _WIN32
EXPECT_STREQ(R"(\cow\moose\dog\chicken)", s.c_str());
#else
EXPECT_STREQ("/cow/moose/dog/chicken", s.c_str());
#endif
s = utils::path::finalize("\\cow\\\\\\moose\\\\\\\\dog\\chicken/");
#ifdef _WIN32
EXPECT_STREQ(R"(\cow\moose\dog\chicken)", s.c_str());
#else
EXPECT_STREQ("/cow/moose/dog/chicken", s.c_str());
#endif
s = utils::path::finalize("/cow\\\\/moose\\\\/\\dog\\chicken\\");
#ifdef _WIN32
EXPECT_STREQ(R"(\cow\moose\dog\chicken)", s.c_str());
#else
EXPECT_STREQ("/cow/moose/dog/chicken", s.c_str());
#endif
}
} // namespace repertory

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,205 +0,0 @@
/*
Copyright <2018-2023> <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.
*/
#if defined(REPERTORY_ENABLE_S3) && defined(REPERTORY_ENABLE_S3_TESTING)
#include "test_common.hpp"
#include "comm/s3/s3_comm.hpp"
#include "fixtures/s3_comm_fixture.hpp"
#include "types/repertory.hpp"
namespace repertory {
TEST_F(s3_comm_test, create_and_remove_directory) {
auto ret = s3_comm_->create_directory("/dir");
EXPECT_EQ(api_error::success, ret);
EXPECT_EQ(api_error::directory_exists, s3_comm_->directory_exists("/dir"));
ret = s3_comm_->remove_directory("/dir");
EXPECT_EQ(api_error::success, ret);
EXPECT_EQ(api_error::directory_not_found, s3_comm_->directory_exists("/dir"));
ret = s3_comm_->remove_directory("/dir");
EXPECT_TRUE(ret == api_error::success ||
ret == api_error::directory_not_found);
}
TEST_F(s3_comm_test, upload_file) {
stop_type stop_requested = false;
auto ret = s3_comm_->upload_file(
"/test.txt", __FILE__, "", []() -> std::string { return ""; },
[](const std::string &) -> api_error { return api_error::success; },
stop_requested);
EXPECT_EQ(api_error::success, ret);
ret = s3_comm_->upload_file(
"/subdir/test2.txt", __FILE__, "", []() -> std::string { return ""; },
[](const std::string &) -> api_error { return api_error::success; },
stop_requested);
EXPECT_EQ(api_error::success, ret);
}
TEST_F(s3_comm_test, get_directory_items) {
directory_item_list list{};
auto ret = s3_comm_->get_directory_items(
"/subdir", [](directory_item &) {}, list);
EXPECT_EQ(api_error::success, ret);
}
TEST_F(s3_comm_test, list_directories) {
api_file_list list{};
auto ret = s3_comm_->get_directory_list(list);
EXPECT_EQ(api_error::success, ret);
}
TEST_F(s3_comm_test, list_files) {
api_file_list list{};
auto ret = s3_comm_->get_file_list(
[](const std::string &) -> std::string { return ""; },
[](const std::string &, const std::string &object_name) -> std::string {
return object_name;
},
list);
EXPECT_EQ(api_error::success, ret);
}
TEST_F(s3_comm_test, read_file_bytes) {
stop_type stop_requested = false;
data_buffer data;
auto ret = s3_comm_->read_file_bytes(
"/test.txt", 2, 0, data, []() -> std::string { return ""; },
[]() -> std::uint64_t { return 0ull; },
[]() -> std::string { return ""; }, stop_requested);
EXPECT_EQ(api_error::success, ret);
}
TEST_F(s3_comm_test, exists) {
EXPECT_EQ(
api_error::item_exists,
s3_comm_->file_exists("/test.txt", []() -> std::string { return ""; }));
EXPECT_EQ(api_error::item_not_found,
s3_comm_->file_exists("/subdir/test.txt",
[]() -> std::string { return ""; }));
}
TEST_F(s3_comm_test, get_file) {
api_file file{};
auto ret = s3_comm_->get_file(
"/test.txt", []() -> std::string { return ""; },
[](const std::string &, const std::string &object_name) -> std::string {
return object_name;
},
[]() -> std::string { return ""; }, file);
EXPECT_EQ(api_error::success, ret);
}
TEST_F(s3_comm_test, remove_file) {
auto ret =
s3_comm_->remove_file("/test.txt", []() -> std::string { return ""; });
EXPECT_EQ(api_error::success, ret);
ret = s3_comm_->remove_file("/subdir/test2.txt",
[]() -> std::string { return ""; });
EXPECT_EQ(api_error::success, ret);
}
TEST_F(s3_comm_test, rename_file) {
stop_type stop_requested = false;
auto ret =
s3_comm_->remove_file("/test_r2.txt", []() -> std::string { return ""; });
ret = s3_comm_->upload_file(
"/test_r1.txt", __FILE__, "", []() -> std::string { return ""; },
[](const std::string &) -> api_error { return api_error::success; },
stop_requested);
EXPECT_EQ(api_error::success, ret);
ret = s3_comm_->rename_file("/test_r1.txt", "/test_r2.txt");
EXPECT_EQ(api_error::not_implemented, ret);
EXPECT_EQ(api_error::item_exists,
s3_comm_->file_exists("/test_r1.txt",
[]() -> std::string { return ""; }));
EXPECT_EQ(api_error::item_not_found,
s3_comm_->file_exists("/test_r2.txt",
[]() -> std::string { return ""; }));
EXPECT_EQ(api_error::success,
s3_comm_->remove_file("/test_r1.txt",
[]() -> std::string { return ""; }));
}
TEST_F(s3_comm_test, upload_file_encrypted) {
const auto source_file_path = generate_test_file_name("./", "awscomm");
auto file_size =
2u * utils::encryption::encrypting_reader::get_data_chunk_size() + 3u;
auto source_file = create_random_file(source_file_path, file_size);
stop_type stop_requested = false;
std::string key;
auto ret = s3_comm_->upload_file(
"/test.txt", source_file_path, "test", []() -> std::string { return ""; },
[&key](const std::string &k) -> api_error {
key = k;
std::cout << "key:" << key << std::endl;
return api_error::success;
},
stop_requested);
EXPECT_EQ(api_error::success, ret);
std::uint64_t offset = 0u;
auto remain = file_size;
while ((ret == api_error::success) && remain) {
data_buffer data;
ret = s3_comm_->read_file_bytes(
"/test.txt",
std::min(remain,
utils::encryption::encrypting_reader::get_data_chunk_size()),
offset, data, [&key]() -> std::string { return key; },
[&file_size]() -> std::uint64_t { return file_size; },
[]() -> std::string { return "test"; }, stop_requested);
EXPECT_EQ(api_error::success, ret);
data_buffer data2(data.size());
std::size_t bytes_read{};
EXPECT_TRUE(
source_file->read_bytes(&data2[0u], data2.size(), offset, bytes_read));
EXPECT_EQ(0, std::memcmp(&data2[0u], &data[0u], data2.size()));
remain -= data.size();
offset += data.size();
}
source_file->close();
EXPECT_TRUE(utils::file::retry_delete_file(source_file_path));
EXPECT_EQ(api_error::success,
s3_comm_->remove_file("/test.txt",
[&key]() -> std::string { return key; }));
}
TEST_F(s3_comm_test, get_directory_item_count) {}
TEST_F(s3_comm_test, get_object_list) {}
TEST_F(s3_comm_test, get_object_name) {}
TEST_F(s3_comm_test, is_online) {}
} // namespace repertory
#endif // REPERTORY_ENABLE_S3_TESTING

View File

@@ -1,189 +0,0 @@
/*
Copyright <2018-2023> <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.
*/
#if defined(REPERTORY_ENABLE_S3) && defined(REPERTORY_ENABLE_S3_TESTING)
#include "test_common.hpp"
#include "app_config.hpp"
#include "events/consumers/console_consumer.hpp"
#include "events/event_system.hpp"
#include "file_manager/file_manager.hpp"
#include "fixtures/s3_provider_file_list_fixture.hpp"
#include "mocks/mock_s3_comm.hpp"
#include "platform/platform.hpp"
#include "providers/s3/s3_provider.hpp"
#include "types/s3.hpp"
#include "types/startup_exception.hpp"
#include "utils/path_utils.hpp"
#include "utils/utils.hpp"
namespace repertory {
// TEST(s3_provider, can_construct_s3_provider) {
// {
// app_config cfg(provider_type::s3, "./s3_provider_test");
// EXPECT_FALSE(cfg.set_value_by_name("S3Config.Bucket", "bucket").empty());
// EXPECT_FALSE(
// cfg.set_value_by_name("S3Config.URL", "https://url.com").empty());
// mock_s3_comm comm(cfg.get_s3_config());
// s3_provider s3(cfg, comm);
// EXPECT_EQ(s3.get_total_item_count(), 0u);
// }
//
// EXPECT_TRUE(utils::file::delete_directory_recursively("./s3_provider_test"));
// }
//
TEST(s3_provider, start_fails_with_empty_bucket) {
{
app_config cfg(provider_type::s3, "./s3_provider_test");
EXPECT_TRUE(cfg.set_value_by_name("S3Config.Bucket", "").empty());
EXPECT_FALSE(
cfg.set_value_by_name("S3Config.URL", "https://url.com").empty());
mock_s3_comm comm(cfg.get_s3_config());
s3_provider s3(cfg, comm);
file_manager fm(cfg, s3);
try {
auto res = s3.start(
[](bool, api_file & /* file */) -> api_error {
return api_error::success;
},
&fm);
std::cerr << "unexpected return-should throw|err|" << res << std::endl;
} catch (const startup_exception &e) {
EXPECT_STREQ("s3 bucket name cannot be empty", e.what());
return;
}
throw std::runtime_error("exception not thrown");
}
EXPECT_TRUE(utils::file::delete_directory_recursively("./s3_provider_test"));
}
TEST(s3_provider, start_fails_when_provider_is_offline) {
{
app_config cfg(provider_type::s3, "./s3_provider_test");
EXPECT_FALSE(cfg.set_value_by_name("S3Config.Bucket", "bucket").empty());
EXPECT_FALSE(
cfg.set_value_by_name("S3Config.URL", "https://url.com").empty());
cfg.set_online_check_retry_secs(2u);
mock_s3_comm comm(cfg.get_s3_config());
s3_provider s3(cfg, comm);
file_manager fm(cfg, s3);
EXPECT_CALL(comm, is_online()).WillRepeatedly(Return(false));
EXPECT_FALSE(s3.start([](bool, api_file & /* file */)
-> api_error { return api_error::success; },
&fm));
}
EXPECT_TRUE(utils::file::delete_directory_recursively("./s3_provider_test"));
}
// TEST(s3_provider, get_empty_file_list) {
// {
// app_config cfg(provider_type::s3, "./s3_provider_test");
// EXPECT_FALSE(cfg.set_value_by_name("S3Config.Bucket", "bucket").empty());
// EXPECT_FALSE(
// cfg.set_value_by_name("S3Config.URL", "https://url.com").empty());
// cfg.set_online_check_retry_secs(2u);
// mock_s3_comm comm(cfg.get_s3_config());
// s3_provider s3(cfg, comm);
// file_manager fm(cfg, s3);
//
// api_file_list list{};
// EXPECT_CALL(comm, get_file_list)
// .WillOnce([](const get_api_file_token_callback &,
// const get_name_callback &,
// api_file_list &) { return api_error::success; });
//
// EXPECT_EQ(api_error::success, s3.get_file_list(list));
// }
//
// EXPECT_TRUE(utils::file::delete_directory_recursively("./s3_provider_test"));
// }
//
// TEST_F(s3_provider_file_list_test, can_add_new_files_and_directories) {
// provider->set_callback([this](bool directory, api_file &file) -> api_error
// {
// std::cout << "added|api_path|" << file.api_path << "|api_parent|"
// << file.api_parent << "|source|" << file.source_path
// << "|directory|" << directory << "|create_date|"
// << file.creation_date << "|access_date|" << file.accessed_date
// << "|modified_date|" << file.modified_date << "|changed_date|"
// << file.changed_date << std::endl;
// return provider_meta_handler(*provider, directory, file);
// });
//
// api_file_list l{};
// auto res = provider->get_file_list(l);
// EXPECT_EQ(api_error::success, res);
// EXPECT_EQ(list.size(), l.size());
// EXPECT_EQ(std::size_t(22u), provider->get_total_item_count());
//
// bool exists{};
// EXPECT_EQ(api_error::success, provider->is_directory("/", exists));
// EXPECT_TRUE(exists);
//
// EXPECT_EQ(api_error::success, provider->is_directory("/dir", exists));
// EXPECT_TRUE(exists);
//
// const auto check_file = [this, &l](std::size_t idx,
// bool check_sub_directory) {
// const auto &file = l.at(idx);
// const auto base_idx = idx - (check_sub_directory ? l.size() / 2 : 0u);
// EXPECT_EQ(this->times[base_idx], file.accessed_date);
// if (check_sub_directory) {
// EXPECT_EQ(utils::path::create_api_path("/dir/file_" +
// std::to_string(base_idx) +
// ".txt"),
// file.api_path);
// EXPECT_EQ(utils::path::get_parent_api_path(utils::path::create_api_path(
// "/dir/file_" + std::to_string(base_idx) + ".txt")),
// file.api_parent);
// } else {
// EXPECT_EQ(utils::path::create_api_path("/file_" +
// std::to_string(base_idx) +
// ".txt"),
// file.api_path);
// EXPECT_EQ(utils::path::get_parent_api_path(utils::path::create_api_path(
// "/file_" + std::to_string(base_idx) + ".txt")),
// file.api_parent);
// }
// EXPECT_EQ(this->times[base_idx] + 1u, file.changed_date);
// EXPECT_EQ(this->times[base_idx] + 2u, file.creation_date);
// EXPECT_TRUE(file.encryption_token.empty());
// EXPECT_EQ(100u + base_idx, file.file_size);
// EXPECT_EQ(this->times[base_idx] + 3u, file.modified_date);
// };
//
// for (std::size_t idx = 0u; idx < l.size() / 2u; idx++) {
// check_file(idx, false);
// }
//
// for (std::size_t idx = l.size() / 2u; idx < l.size(); idx++) {
// check_file(idx, true);
// }
// }
} // namespace repertory
#endif // REPERTORY_ENABLE_S3_TESTING

View File

@@ -1,326 +1,326 @@
/*
Copyright <2018-2023> <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_common.hpp"
#include "app_config.hpp"
#include "comm/curl/curl_comm.hpp"
#include "events/consumers/console_consumer.hpp"
#include "events/event_system.hpp"
#include "file_manager/file_manager.hpp"
#include "platform/platform.hpp"
#include "providers/sia/sia_provider.hpp"
#include "types/startup_exception.hpp"
#include "utils/path_utils.hpp"
#include "utils/utils.hpp"
namespace repertory {
/* TEST(sia_provider, can_construct_sia_provider) {
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider provider(cfg, comm);
EXPECT_EQ(provider_type::sia, provider.get_provider_type());
EXPECT_FALSE(provider.is_direct_only());
EXPECT_FALSE(provider.is_rename_supported());
}
TEST(sia_provider, can_create_and_remove_directory) {
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider sia(cfg, comm);
i_provider &provider = sia;
EXPECT_TRUE(provider.start(
[&](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
nullptr));
api_meta_map meta{};
meta[META_ACCESSED] = std::to_string(utils::get_file_time_now());
meta[META_CHANGED] = std::to_string(utils::get_file_time_now());
meta[META_CREATION] = std::to_string(utils::get_file_time_now());
meta[META_MODIFIED] = std::to_string(utils::get_file_time_now());
EXPECT_EQ(api_error::success, provider.create_directory("/moose2", meta));
bool exists{};
EXPECT_EQ(api_error::success, provider.is_directory("/moose2", exists));
EXPECT_TRUE(exists);
EXPECT_EQ(api_error::success, provider.is_file("/moose2", exists));
EXPECT_FALSE(exists);
EXPECT_FALSE(provider.is_file_writeable("/moose2"));
EXPECT_EQ(api_error::directory_exists, provider.remove_file("/moose2"));
EXPECT_EQ(api_error::success, provider.remove_directory("/moose2"));
api_meta_map m{};
EXPECT_EQ(api_error::item_not_found, provider.get_item_meta("/moose2", m));
EXPECT_TRUE(m.empty());
provider.stop();
event_system::instance().stop();
}
TEST(sia_provider, can_create_and_remove_file) {
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider sia(cfg, comm);
i_provider &provider = sia;
EXPECT_TRUE(provider.start(
[&](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
nullptr));
api_meta_map meta{};
meta[META_ACCESSED] = std::to_string(utils::get_file_time_now());
meta[META_CHANGED] = std::to_string(utils::get_file_time_now());
meta[META_CREATION] = std::to_string(utils::get_file_time_now());
meta[META_MODIFIED] = std::to_string(utils::get_file_time_now());
meta[META_SIZE] = "0";
EXPECT_EQ(api_error::success, provider.create_file("/moose.txt", meta));
bool exists{};
EXPECT_EQ(api_error::success, provider.is_file("/moose.txt", exists));
EXPECT_TRUE(exists);
EXPECT_EQ(api_error::success, provider.is_directory("/moose.txt", exists));
EXPECT_FALSE(exists);
EXPECT_TRUE(provider.is_file_writeable("/moose.txt"));
EXPECT_EQ(api_error::item_not_found, provider.remove_directory("/moose.txt"));
EXPECT_EQ(api_error::success, provider.remove_file("/moose.txt"));
api_meta_map m{};
EXPECT_EQ(api_error::item_not_found, provider.get_item_meta("/moose.txt", m));
EXPECT_TRUE(m.empty());
provider.stop();
event_system::instance().stop();
}
TEST(sia_provider, can_get_file_list) {
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider sia(cfg, comm);
i_provider &provider = sia;
EXPECT_TRUE(provider.start(
[&](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
nullptr));
api_file_list list{};
EXPECT_EQ(api_error::success, provider.get_file_list(list));
provider.stop();
event_system::instance().stop();
}
TEST(sia_provider, can_get_and_set_item_meta) {
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider sia(cfg, comm);
i_provider &provider = sia;
EXPECT_TRUE(provider.start(
[&](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
nullptr));
api_meta_map meta{};
meta[META_ACCESSED] = std::to_string(utils::get_file_time_now());
meta[META_CHANGED] = std::to_string(utils::get_file_time_now());
meta[META_CREATION] = std::to_string(utils::get_file_time_now());
meta[META_MODIFIED] = std::to_string(utils::get_file_time_now());
EXPECT_EQ(api_error::success, provider.create_directory("/moose2", meta));
EXPECT_EQ(api_error::success, provider.create_file("/moose2.txt", meta));
{
api_meta_map m{
{"test_one", "one"},
{"test_two", "two"},
};
EXPECT_EQ(api_error::success, provider.set_item_meta("/moose2", m));
api_meta_map m2{};
EXPECT_EQ(api_error::success, provider.get_item_meta("/moose2", m2));
EXPECT_EQ(meta.size() + m.size(), m2.size());
EXPECT_STREQ("one", m2["test_one"].c_str());
EXPECT_STREQ("two", m2["test_two"].c_str());
}
{
api_meta_map m{
{"test_one", "one1"},
{"test_two", "two2"},
};
EXPECT_EQ(api_error::success, provider.set_item_meta("/moose2.txt", m));
api_meta_map m2{};
EXPECT_EQ(api_error::success, provider.get_item_meta("/moose2.txt", m2));
EXPECT_EQ(meta.size() + m.size(), m2.size());
EXPECT_STREQ("one1", m2["test_one"].c_str());
EXPECT_STREQ("two2", m2["test_two"].c_str());
}
EXPECT_EQ(api_error::success, provider.remove_directory("/moose2"));
EXPECT_EQ(api_error::success, provider.remove_file("/moose2.txt"));
provider.stop();
event_system::instance().stop();
}
TEST(sia_provider, can_get_and_set_individual_item_meta) {
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider sia(cfg, comm);
i_provider &provider = sia;
EXPECT_TRUE(provider.start(
[&](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
nullptr));
api_meta_map meta{};
meta[META_ACCESSED] = std::to_string(utils::get_file_time_now());
meta[META_CHANGED] = std::to_string(utils::get_file_time_now());
meta[META_CREATION] = std::to_string(utils::get_file_time_now());
meta[META_MODIFIED] = std::to_string(utils::get_file_time_now());
EXPECT_EQ(api_error::success, provider.create_directory("/moose2", meta));
EXPECT_EQ(api_error::success, provider.create_file("/moose2.txt", meta));
{
EXPECT_EQ(api_error::success,
provider.set_item_meta("/moose2", "test_meta", "cow2"));
std::string value{};
EXPECT_EQ(api_error::success,
provider.get_item_meta("/moose2", "test_meta", value));
EXPECT_STREQ("cow2", value.c_str());
}
{
EXPECT_EQ(api_error::success,
provider.set_item_meta("/moose2.txt", "test_meta", "cow"));
std::string value{};
EXPECT_EQ(api_error::success,
provider.get_item_meta("/moose2.txt", "test_meta", value));
EXPECT_STREQ("cow", value.c_str());
}
EXPECT_EQ(api_error::success, provider.remove_directory("/moose2"));
EXPECT_EQ(api_error::success, provider.remove_file("/moose2.txt"));
provider.stop();
event_system::instance().stop();
}
TEST(sia_provider, can_read_file_bytes) {
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider sia(cfg, comm);
i_provider &provider = sia;
EXPECT_TRUE(provider.start(
[&](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
nullptr));
data_buffer data{};
stop_type stop_requested = false;
EXPECT_EQ(api_error::success,
provider.read_file_bytes("/renterd_linux_amd64.zip", 10U, 0U, data,
stop_requested));
EXPECT_EQ(10U, data.size());
provider.stop();
event_system::instance().stop();
}
TEST(sia_provider, can_upload_file) {
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider sia(cfg, comm);
i_provider &provider = sia;
EXPECT_TRUE(provider.start(
[&](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
nullptr));
stop_type stop_requested = false;
EXPECT_EQ(api_error::success,
provider.upload_file("/sia_provider_test.cpp", __FILE__, "",
stop_requested));
api_meta_map meta = {{"test", "test"}};
EXPECT_EQ(api_error::success,
provider.set_item_meta("/sia_provider_test.cpp", meta));
EXPECT_EQ(api_error::success, provider.remove_file("/sia_provider_test.cpp"));
provider.stop();
event_system::instance().stop();
} */
} // namespace repertory
/*
Copyright <2018-2023> <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_common.hpp"
#include "app_config.hpp"
#include "comm/curl/curl_comm.hpp"
#include "events/consumers/console_consumer.hpp"
#include "events/event_system.hpp"
#include "file_manager/file_manager.hpp"
#include "platform/platform.hpp"
#include "providers/sia/sia_provider.hpp"
#include "types/startup_exception.hpp"
#include "utils/path_utils.hpp"
#include "utils/utils.hpp"
namespace repertory {
/* TEST(sia_provider, can_construct_sia_provider) {
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider provider(cfg, comm);
EXPECT_EQ(provider_type::sia, provider.get_provider_type());
EXPECT_FALSE(provider.is_direct_only());
EXPECT_FALSE(provider.is_rename_supported());
}
TEST(sia_provider, can_create_and_remove_directory) {
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider sia(cfg, comm);
i_provider &provider = sia;
EXPECT_TRUE(provider.start(
[&](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
nullptr));
api_meta_map meta{};
meta[META_ACCESSED] = std::to_string(utils::get_file_time_now());
meta[META_CHANGED] = std::to_string(utils::get_file_time_now());
meta[META_CREATION] = std::to_string(utils::get_file_time_now());
meta[META_MODIFIED] = std::to_string(utils::get_file_time_now());
EXPECT_EQ(api_error::success, provider.create_directory("/moose2", meta));
bool exists{};
EXPECT_EQ(api_error::success, provider.is_directory("/moose2", exists));
EXPECT_TRUE(exists);
EXPECT_EQ(api_error::success, provider.is_file("/moose2", exists));
EXPECT_FALSE(exists);
EXPECT_FALSE(provider.is_file_writeable("/moose2"));
EXPECT_EQ(api_error::directory_exists, provider.remove_file("/moose2"));
EXPECT_EQ(api_error::success, provider.remove_directory("/moose2"));
api_meta_map m{};
EXPECT_EQ(api_error::item_not_found, provider.get_item_meta("/moose2", m));
EXPECT_TRUE(m.empty());
provider.stop();
event_system::instance().stop();
}
TEST(sia_provider, can_create_and_remove_file) {
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider sia(cfg, comm);
i_provider &provider = sia;
EXPECT_TRUE(provider.start(
[&](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
nullptr));
api_meta_map meta{};
meta[META_ACCESSED] = std::to_string(utils::get_file_time_now());
meta[META_CHANGED] = std::to_string(utils::get_file_time_now());
meta[META_CREATION] = std::to_string(utils::get_file_time_now());
meta[META_MODIFIED] = std::to_string(utils::get_file_time_now());
meta[META_SIZE] = "0";
EXPECT_EQ(api_error::success, provider.create_file("/moose.txt", meta));
bool exists{};
EXPECT_EQ(api_error::success, provider.is_file("/moose.txt", exists));
EXPECT_TRUE(exists);
EXPECT_EQ(api_error::success, provider.is_directory("/moose.txt", exists));
EXPECT_FALSE(exists);
EXPECT_TRUE(provider.is_file_writeable("/moose.txt"));
EXPECT_EQ(api_error::item_not_found, provider.remove_directory("/moose.txt"));
EXPECT_EQ(api_error::success, provider.remove_file("/moose.txt"));
api_meta_map m{};
EXPECT_EQ(api_error::item_not_found, provider.get_item_meta("/moose.txt", m));
EXPECT_TRUE(m.empty());
provider.stop();
event_system::instance().stop();
}
TEST(sia_provider, can_get_file_list) {
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider sia(cfg, comm);
i_provider &provider = sia;
EXPECT_TRUE(provider.start(
[&](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
nullptr));
api_file_list list{};
EXPECT_EQ(api_error::success, provider.get_file_list(list));
provider.stop();
event_system::instance().stop();
}
TEST(sia_provider, can_get_and_set_item_meta) {
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider sia(cfg, comm);
i_provider &provider = sia;
EXPECT_TRUE(provider.start(
[&](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
nullptr));
api_meta_map meta{};
meta[META_ACCESSED] = std::to_string(utils::get_file_time_now());
meta[META_CHANGED] = std::to_string(utils::get_file_time_now());
meta[META_CREATION] = std::to_string(utils::get_file_time_now());
meta[META_MODIFIED] = std::to_string(utils::get_file_time_now());
EXPECT_EQ(api_error::success, provider.create_directory("/moose2", meta));
EXPECT_EQ(api_error::success, provider.create_file("/moose2.txt", meta));
{
api_meta_map m{
{"test_one", "one"},
{"test_two", "two"},
};
EXPECT_EQ(api_error::success, provider.set_item_meta("/moose2", m));
api_meta_map m2{};
EXPECT_EQ(api_error::success, provider.get_item_meta("/moose2", m2));
EXPECT_EQ(meta.size() + m.size(), m2.size());
EXPECT_STREQ("one", m2["test_one"].c_str());
EXPECT_STREQ("two", m2["test_two"].c_str());
}
{
api_meta_map m{
{"test_one", "one1"},
{"test_two", "two2"},
};
EXPECT_EQ(api_error::success, provider.set_item_meta("/moose2.txt", m));
api_meta_map m2{};
EXPECT_EQ(api_error::success, provider.get_item_meta("/moose2.txt", m2));
EXPECT_EQ(meta.size() + m.size(), m2.size());
EXPECT_STREQ("one1", m2["test_one"].c_str());
EXPECT_STREQ("two2", m2["test_two"].c_str());
}
EXPECT_EQ(api_error::success, provider.remove_directory("/moose2"));
EXPECT_EQ(api_error::success, provider.remove_file("/moose2.txt"));
provider.stop();
event_system::instance().stop();
}
TEST(sia_provider, can_get_and_set_individual_item_meta) {
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider sia(cfg, comm);
i_provider &provider = sia;
EXPECT_TRUE(provider.start(
[&](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
nullptr));
api_meta_map meta{};
meta[META_ACCESSED] = std::to_string(utils::get_file_time_now());
meta[META_CHANGED] = std::to_string(utils::get_file_time_now());
meta[META_CREATION] = std::to_string(utils::get_file_time_now());
meta[META_MODIFIED] = std::to_string(utils::get_file_time_now());
EXPECT_EQ(api_error::success, provider.create_directory("/moose2", meta));
EXPECT_EQ(api_error::success, provider.create_file("/moose2.txt", meta));
{
EXPECT_EQ(api_error::success,
provider.set_item_meta("/moose2", "test_meta", "cow2"));
std::string value{};
EXPECT_EQ(api_error::success,
provider.get_item_meta("/moose2", "test_meta", value));
EXPECT_STREQ("cow2", value.c_str());
}
{
EXPECT_EQ(api_error::success,
provider.set_item_meta("/moose2.txt", "test_meta", "cow"));
std::string value{};
EXPECT_EQ(api_error::success,
provider.get_item_meta("/moose2.txt", "test_meta", value));
EXPECT_STREQ("cow", value.c_str());
}
EXPECT_EQ(api_error::success, provider.remove_directory("/moose2"));
EXPECT_EQ(api_error::success, provider.remove_file("/moose2.txt"));
provider.stop();
event_system::instance().stop();
}
TEST(sia_provider, can_read_file_bytes) {
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider sia(cfg, comm);
i_provider &provider = sia;
EXPECT_TRUE(provider.start(
[&](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
nullptr));
data_buffer data{};
stop_type stop_requested = false;
EXPECT_EQ(api_error::success,
provider.read_file_bytes("/renterd_linux_amd64.zip", 10U, 0U, data,
stop_requested));
EXPECT_EQ(10U, data.size());
provider.stop();
event_system::instance().stop();
}
TEST(sia_provider, can_upload_file) {
console_consumer cc{};
event_system::instance().start();
app_config cfg(provider_type::sia,
utils::path::combine(get_test_dir(), {"sia"}));
curl_comm comm(cfg.get_host_config());
sia_provider sia(cfg, comm);
i_provider &provider = sia;
EXPECT_TRUE(provider.start(
[&](bool directory, api_file &file) -> api_error {
return provider_meta_handler(provider, directory, file);
},
nullptr));
stop_type stop_requested = false;
EXPECT_EQ(api_error::success,
provider.upload_file("/sia_provider_test.cpp", __FILE__, "",
stop_requested));
api_meta_map meta = {{"test", "test"}};
EXPECT_EQ(api_error::success,
provider.set_item_meta("/sia_provider_test.cpp", meta));
EXPECT_EQ(api_error::success, provider.remove_file("/sia_provider_test.cpp"));
provider.stop();
event_system::instance().stop();
} */
} // namespace repertory

View File

@@ -1,48 +1,48 @@
/*
Copyright <2018-2023> <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_common.hpp"
#include "utils/string_utils.hpp"
namespace repertory {
TEST(string_utils, is_numeric) {
EXPECT_TRUE(utils::string::is_numeric("100"));
EXPECT_TRUE(utils::string::is_numeric("+100"));
EXPECT_TRUE(utils::string::is_numeric("-100"));
EXPECT_TRUE(utils::string::is_numeric("100.00"));
EXPECT_TRUE(utils::string::is_numeric("+100.00"));
EXPECT_TRUE(utils::string::is_numeric("-100.00"));
EXPECT_FALSE(utils::string::is_numeric("1.00.00"));
EXPECT_FALSE(utils::string::is_numeric("+1.00.00"));
EXPECT_FALSE(utils::string::is_numeric("-1.00.00"));
EXPECT_FALSE(utils::string::is_numeric("a1"));
EXPECT_FALSE(utils::string::is_numeric("1a"));
EXPECT_FALSE(utils::string::is_numeric("+"));
EXPECT_FALSE(utils::string::is_numeric("-"));
EXPECT_FALSE(utils::string::is_numeric(""));
}
} // namespace repertory
/*
Copyright <2018-2023> <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_common.hpp"
#include "utils/string_utils.hpp"
namespace repertory {
TEST(string_utils, is_numeric) {
EXPECT_TRUE(utils::string::is_numeric("100"));
EXPECT_TRUE(utils::string::is_numeric("+100"));
EXPECT_TRUE(utils::string::is_numeric("-100"));
EXPECT_TRUE(utils::string::is_numeric("100.00"));
EXPECT_TRUE(utils::string::is_numeric("+100.00"));
EXPECT_TRUE(utils::string::is_numeric("-100.00"));
EXPECT_FALSE(utils::string::is_numeric("1.00.00"));
EXPECT_FALSE(utils::string::is_numeric("+1.00.00"));
EXPECT_FALSE(utils::string::is_numeric("-1.00.00"));
EXPECT_FALSE(utils::string::is_numeric("a1"));
EXPECT_FALSE(utils::string::is_numeric("1a"));
EXPECT_FALSE(utils::string::is_numeric("+"));
EXPECT_FALSE(utils::string::is_numeric("-"));
EXPECT_FALSE(utils::string::is_numeric(""));
}
} // namespace repertory

View File

@@ -1,80 +1,76 @@
/*
Copyright <2018-2023> <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_common.hpp"
#include "types/repertory.hpp"
#include "utils/path_utils.hpp"
#include "utils/utils.hpp"
namespace repertory {
static std::vector<std::string> generated_files;
void delete_generated_files() {
for (const auto &f : generated_files) {
EXPECT_TRUE(utils::file::retry_delete_file(f));
}
}
auto create_random_file(std::string path, std::size_t size) -> native_file_ptr {
native_file_ptr nf;
if (native_file::create_or_open(path, nf) == api_error::success) {
generated_files.emplace_back(utils::path::absolute(path));
EXPECT_TRUE(nf->truncate(0u));
data_buffer buf(size);
randombytes_buf(buf.data(), buf.size());
std::size_t bytes_written{};
EXPECT_TRUE(nf->write_bytes(&buf[0u], buf.size(), 0u, bytes_written));
nf->flush();
std::uint64_t current_size;
EXPECT_TRUE(utils::file::get_file_size(path, current_size));
EXPECT_EQ(size, current_size);
}
return nf;
}
auto generate_test_file_name(const std::string &directory,
const std::string &file_name_no_extension)
-> std::string {
static std::atomic<std::uint32_t> idx{0U};
auto path = utils::path::absolute(utils::path::combine(
directory, {file_name_no_extension + std::to_string(idx++) + ".dat"}));
generated_files.emplace_back(path);
return path;
}
auto get_test_dir() -> std::string {
auto dir = utils::get_environment_variable("REPERTORY_TEST_DIR");
if (not dir.empty()) {
return utils::path::absolute(dir);
}
#ifdef _WIN32
return utils::path::absolute("..\\..\\..");
#else
return utils::path::absolute("../..");
#endif
}
} // namespace repertory
/*
Copyright <2018-2023> <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_common.hpp"
#include "types/repertory.hpp"
#include "utils/path_utils.hpp"
#include "utils/utils.hpp"
namespace repertory {
std::vector<std::string> generated_files;
void delete_generated_files() {
for (const auto &file : generated_files) {
EXPECT_TRUE(utils::file::retry_delete_file(file));
}
}
auto create_random_file(std::string path, std::size_t size) -> native_file_ptr {
native_file_ptr file;
if (native_file::create_or_open(path, file) == api_error::success) {
generated_files.emplace_back(utils::path::absolute(path));
EXPECT_TRUE(file->truncate(0U));
data_buffer buf(size);
randombytes_buf(buf.data(), buf.size());
std::size_t bytes_written{};
EXPECT_TRUE(file->write_bytes(buf.data(), buf.size(), 0U, bytes_written));
file->flush();
std::uint64_t current_size{};
EXPECT_TRUE(utils::file::get_file_size(path, current_size));
EXPECT_EQ(size, current_size);
}
return file;
}
auto generate_test_file_name(const std::string &directory,
const std::string &file_name_no_extension)
-> std::string {
static std::atomic<std::uint32_t> idx{0U};
auto path = utils::path::absolute(utils::path::combine(
directory, {file_name_no_extension + std::to_string(idx++) + ".dat"}));
generated_files.emplace_back(path);
return path;
}
auto get_test_dir() -> std::string {
auto dir = utils::get_environment_variable("REPERTORY_TEST_DIR");
if (not dir.empty()) {
return utils::path::absolute(dir);
}
return utils::path::absolute(utils::path::combine("..", {".."}));
}
} // namespace repertory

View File

@@ -1,71 +1,66 @@
/*
Copyright <2018-2023> <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.
*/
#ifndef TESTS_TEST_COMMON_HPP_
#define TESTS_TEST_COMMON_HPP_
#ifdef U
#undef U
#endif
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "events/consumers/console_consumer.hpp"
#include "events/event_system.hpp"
#include "events/events.hpp"
#ifdef _WIN32
// Disable DLL-interface warnings
#pragma warning(disable : 4251)
#pragma warning(disable : 4275)
#endif
#include "utils/encryption.hpp"
#include "utils/file_utils.hpp"
#include "utils/native_file.hpp"
#define COMMA ,
using ::testing::_;
using namespace ::testing;
namespace repertory {
[[nodiscard]] auto create_random_file(std::string path, std::size_t size)
-> native_file_ptr;
void delete_generated_files();
[[nodiscard]] auto
generate_test_file_name(const std::string &directory,
const std::string &file_name_no_extension)
-> std::string;
template <typename T, typename T2>
static void decrypt_and_verify(const T &buffer, const std::string &token,
T2 &result) {
EXPECT_TRUE(utils::encryption::decrypt_data(token, buffer, result));
}
[[nodiscard]] auto get_test_dir() -> std::string;
} // namespace repertory
#endif // TESTS_TEST_COMMON_HPP_
/*
Copyright <2018-2023> <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.
*/
#ifndef TESTS_TEST_COMMON_HPP_
#define TESTS_TEST_COMMON_HPP_
#ifdef U
#undef U
#endif
REPERTORY_IGNORE_WARNINGS_ENABLE()
#include <gmock/gmock.h>
#include <gtest/gtest.h>
REPERTORY_IGNORE_WARNINGS_DISABLE()
#include "events/consumers/console_consumer.hpp"
#include "events/event_system.hpp"
#include "events/events.hpp"
#include "utils/encryption.hpp"
#include "utils/file_utils.hpp"
#include "utils/native_file.hpp"
#define COMMA ,
using ::testing::_;
using namespace ::testing;
namespace repertory {
[[nodiscard]] auto create_random_file(std::string path, std::size_t size)
-> native_file_ptr;
void delete_generated_files();
[[nodiscard]] auto
generate_test_file_name(const std::string &directory,
const std::string &file_name_no_extension)
-> std::string;
template <typename T, typename T2>
static void decrypt_and_verify(const T &buffer, const std::string &token,
T2 &result) {
EXPECT_TRUE(utils::encryption::decrypt_data(token, buffer, result));
}
[[nodiscard]] auto get_test_dir() -> std::string;
} // namespace repertory
#endif // TESTS_TEST_COMMON_HPP_

View File

@@ -1,108 +1,108 @@
/*
Copyright <2018-2023> <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.
*/
#ifndef TESTS_UTILS_EVENT_CAPTURE_HPP_
#define TESTS_UTILS_EVENT_CAPTURE_HPP_
#include "test_common.hpp"
#include "utils/utils.hpp"
namespace repertory {
class event_capture final {
E_CONSUMER();
public:
explicit event_capture(std::vector<std::string> event_names,
std::vector<std::string> non_fired_event_names = {})
: event_names_(std::move(event_names)),
non_fired_event_names_(std::move(non_fired_event_names)) {
E_SUBSCRIBE_ALL(process_event);
}
~event_capture() {
wait_for_empty();
E_CONSUMER_RELEASE();
EXPECT_TRUE(event_names_.empty());
for (const auto &event_name : event_names_) {
std::cerr << '\t' << event_name << std::endl;
}
}
private:
std::vector<std::string> event_names_;
std::vector<std::string> fired_event_names_;
std::vector<std::string> non_fired_event_names_;
std::mutex mutex_;
std::condition_variable notify_;
public:
void process_event(const event &event) {
unique_mutex_lock l(mutex_);
utils::remove_element_from(event_names_, event.get_name());
fired_event_names_.emplace_back(event.get_name());
notify_.notify_all();
l.unlock();
for (size_t i = 0; i < non_fired_event_names_.size(); i++) {
const auto it = std::find(non_fired_event_names_.begin(),
non_fired_event_names_.end(), event.get_name());
EXPECT_EQ(non_fired_event_names_.end(), it);
if (it != non_fired_event_names_.end()) {
std::cerr << '\t' << *it << std::endl;
}
}
}
void wait_for_empty() {
const auto start_time = std::chrono::system_clock::now();
unique_mutex_lock l(mutex_);
while (not event_names_.empty() &&
(std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now() - start_time)
.count() < 10)) {
notify_.wait_for(l, 1s);
}
l.unlock();
}
[[nodiscard]] auto wait_for_event(const std::string &event_name) -> bool {
auto missing = true;
const auto start_time = std::chrono::system_clock::now();
unique_mutex_lock l(mutex_);
while ((std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now() - start_time)
.count() < 10) &&
(missing =
(std::find(fired_event_names_.begin(), fired_event_names_.end(),
event_name) == fired_event_names_.end()))) {
notify_.wait_for(l, 1s);
}
l.unlock();
return not missing;
}
};
} // namespace repertory
#endif // TESTS_UTILS_EVENT_CAPTURE_HPP_
/*
Copyright <2018-2023> <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.
*/
#ifndef TESTS_UTILS_EVENT_CAPTURE_HPP_
#define TESTS_UTILS_EVENT_CAPTURE_HPP_
#include "test_common.hpp"
#include "utils/utils.hpp"
namespace repertory {
class event_capture final {
E_CONSUMER();
public:
explicit event_capture(std::vector<std::string> event_names,
std::vector<std::string> non_fired_event_names = {})
: event_names_(std::move(event_names)),
non_fired_event_names_(std::move(non_fired_event_names)) {
E_SUBSCRIBE_ALL(process_event);
}
~event_capture() {
wait_for_empty();
E_CONSUMER_RELEASE();
EXPECT_TRUE(event_names_.empty());
for (const auto &event_name : event_names_) {
std::cerr << '\t' << event_name << std::endl;
}
}
private:
std::vector<std::string> event_names_;
std::vector<std::string> fired_event_names_;
std::vector<std::string> non_fired_event_names_;
std::mutex mutex_;
std::condition_variable notify_;
public:
void process_event(const event &event) {
unique_mutex_lock l(mutex_);
utils::remove_element_from(event_names_, event.get_name());
fired_event_names_.emplace_back(event.get_name());
notify_.notify_all();
l.unlock();
for (size_t i = 0; i < non_fired_event_names_.size(); i++) {
const auto it = std::find(non_fired_event_names_.begin(),
non_fired_event_names_.end(), event.get_name());
EXPECT_EQ(non_fired_event_names_.end(), it);
if (it != non_fired_event_names_.end()) {
std::cerr << '\t' << *it << std::endl;
}
}
}
void wait_for_empty() {
const auto start_time = std::chrono::system_clock::now();
unique_mutex_lock l(mutex_);
while (not event_names_.empty() &&
(std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now() - start_time)
.count() < 10)) {
notify_.wait_for(l, 1s);
}
l.unlock();
}
[[nodiscard]] auto wait_for_event(const std::string &event_name) -> bool {
auto missing = true;
const auto start_time = std::chrono::system_clock::now();
unique_mutex_lock l(mutex_);
while ((std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now() - start_time)
.count() < 10) &&
(missing =
(std::find(fired_event_names_.begin(), fired_event_names_.end(),
event_name) == fired_event_names_.end()))) {
notify_.wait_for(l, 1s);
}
l.unlock();
return not missing;
}
};
} // namespace repertory
#endif // TESTS_UTILS_EVENT_CAPTURE_HPP_

View File

@@ -1,77 +1,77 @@
/*
Copyright <2018-2023> <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_common.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/string_utils.hpp"
#include "utils/utils.hpp"
namespace repertory {
#ifdef _WIN32
TEST(utils, convert_api_date) {
LARGE_INTEGER li{};
li.QuadPart = utils::convert_api_date("2009-10-12T17:50:30.111Z");
SYSTEMTIME st{};
FileTimeToSystemTime(reinterpret_cast<FILETIME *>(&li), &st);
SYSTEMTIME lt{};
SystemTimeToTzSpecificLocalTime(nullptr, &st, &lt);
EXPECT_EQ(2009, lt.wYear);
EXPECT_EQ(10, lt.wMonth);
EXPECT_EQ(12, lt.wDay);
EXPECT_EQ(17, lt.wHour);
EXPECT_EQ(50, lt.wMinute);
EXPECT_EQ(20, lt.wSecond);
EXPECT_EQ(111, lt.wMilliseconds);
}
#endif
TEST(utils, create_uuid_string) {
const auto uuid1 = utils::create_uuid_string();
const auto uuid2 = utils::create_uuid_string();
ASSERT_EQ(36u, uuid1.size());
ASSERT_EQ(36u, uuid2.size());
ASSERT_STRNE(&uuid1[0], &uuid2[0]);
}
TEST(utils, generate_sha256) {
const auto res = utils::file::generate_sha256(__FILE__);
std::cout << res << std::endl;
}
TEST(utils, string_to_bool) {
EXPECT_TRUE(utils::string::to_bool("1"));
EXPECT_TRUE(utils::string::to_bool("-1"));
EXPECT_TRUE(utils::string::to_bool("0.1"));
EXPECT_TRUE(utils::string::to_bool("-0.1"));
EXPECT_TRUE(utils::string::to_bool("00000.1000000"));
EXPECT_TRUE(utils::string::to_bool("true"));
EXPECT_FALSE(utils::string::to_bool("false"));
EXPECT_FALSE(utils::string::to_bool("0"));
EXPECT_FALSE(utils::string::to_bool("00000.00000"));
}
} // namespace repertory
/*
Copyright <2018-2023> <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_common.hpp"
#include "utils/file_utils.hpp"
#include "utils/path_utils.hpp"
#include "utils/string_utils.hpp"
#include "utils/utils.hpp"
namespace repertory {
#ifdef _WIN32
TEST(utils, convert_api_date) {
LARGE_INTEGER li{};
li.QuadPart = utils::convert_api_date("2009-10-12T17:50:30.111Z");
SYSTEMTIME st{};
FileTimeToSystemTime(reinterpret_cast<FILETIME *>(&li), &st);
SYSTEMTIME lt{};
SystemTimeToTzSpecificLocalTime(nullptr, &st, &lt);
EXPECT_EQ(2009, lt.wYear);
EXPECT_EQ(10, lt.wMonth);
EXPECT_EQ(12, lt.wDay);
EXPECT_EQ(17, lt.wHour);
EXPECT_EQ(50, lt.wMinute);
EXPECT_EQ(20, lt.wSecond);
EXPECT_EQ(111, lt.wMilliseconds);
}
#endif
TEST(utils, create_uuid_string) {
const auto uuid1 = utils::create_uuid_string();
const auto uuid2 = utils::create_uuid_string();
ASSERT_EQ(36u, uuid1.size());
ASSERT_EQ(36u, uuid2.size());
ASSERT_STRNE(&uuid1[0], &uuid2[0]);
}
TEST(utils, generate_sha256) {
const auto res = utils::file::generate_sha256(__FILE__);
std::cout << res << std::endl;
}
TEST(utils, string_to_bool) {
EXPECT_TRUE(utils::string::to_bool("1"));
EXPECT_TRUE(utils::string::to_bool("-1"));
EXPECT_TRUE(utils::string::to_bool("0.1"));
EXPECT_TRUE(utils::string::to_bool("-0.1"));
EXPECT_TRUE(utils::string::to_bool("00000.1000000"));
EXPECT_TRUE(utils::string::to_bool("true"));
EXPECT_FALSE(utils::string::to_bool("false"));
EXPECT_FALSE(utils::string::to_bool("0"));
EXPECT_FALSE(utils::string::to_bool("00000.00000"));
}
} // namespace repertory

View File

@@ -1,57 +1,57 @@
/*
Copyright <2018-2023> <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_common.hpp"
#include "utils/utils.hpp"
namespace repertory {
TEST(version, equal) {
EXPECT_EQ(0, utils::compare_version_strings("1.0", "1.0"));
EXPECT_EQ(0, utils::compare_version_strings("1.0.0", "1.0"));
EXPECT_EQ(0, utils::compare_version_strings("1.0.0.0", "1.0"));
EXPECT_EQ(0, utils::compare_version_strings("1.0.0.0", "1.0.0"));
}
TEST(version, greater) {
EXPECT_EQ(1, utils::compare_version_strings("1.0.1", "1.0"));
EXPECT_EQ(1, utils::compare_version_strings("1.0.1", "1.0.0"));
EXPECT_EQ(1, utils::compare_version_strings("1.0.1", "1.0.0.0"));
EXPECT_EQ(1, utils::compare_version_strings("1.0.1.0", "1.0"));
EXPECT_EQ(1, utils::compare_version_strings("1.0.1.0", "1.0.0"));
EXPECT_EQ(1, utils::compare_version_strings("1.0.1.0", "1.0.0.0"));
EXPECT_EQ(1, utils::compare_version_strings("1.0", "0.9.9"));
EXPECT_EQ(1, utils::compare_version_strings("1.0.1", "0.9.9"));
EXPECT_EQ(1, utils::compare_version_strings("1.0.1.0", "0.9.9"));
}
TEST(version, less) {
EXPECT_EQ(-1, utils::compare_version_strings("0.9.9", "1.0"));
EXPECT_EQ(-1, utils::compare_version_strings("0.9.9", "1.0.1"));
EXPECT_EQ(-1, utils::compare_version_strings("0.9.9", "1.0.1.0"));
EXPECT_EQ(-1, utils::compare_version_strings("1.0", "1.0.1"));
EXPECT_EQ(-1, utils::compare_version_strings("1.0", "1.0.1.0"));
EXPECT_EQ(-1, utils::compare_version_strings("1.0.0", "1.0.1"));
EXPECT_EQ(-1, utils::compare_version_strings("1.0.0", "1.0.1.0"));
EXPECT_EQ(-1, utils::compare_version_strings("1.0.0.0", "1.0.1"));
EXPECT_EQ(-1, utils::compare_version_strings("1.0.0.0", "1.0.1.0"));
}
} // namespace repertory
/*
Copyright <2018-2023> <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_common.hpp"
#include "utils/utils.hpp"
namespace repertory {
TEST(version, equal) {
EXPECT_EQ(0, utils::compare_version_strings("1.0", "1.0"));
EXPECT_EQ(0, utils::compare_version_strings("1.0.0", "1.0"));
EXPECT_EQ(0, utils::compare_version_strings("1.0.0.0", "1.0"));
EXPECT_EQ(0, utils::compare_version_strings("1.0.0.0", "1.0.0"));
}
TEST(version, greater) {
EXPECT_EQ(1, utils::compare_version_strings("1.0.1", "1.0"));
EXPECT_EQ(1, utils::compare_version_strings("1.0.1", "1.0.0"));
EXPECT_EQ(1, utils::compare_version_strings("1.0.1", "1.0.0.0"));
EXPECT_EQ(1, utils::compare_version_strings("1.0.1.0", "1.0"));
EXPECT_EQ(1, utils::compare_version_strings("1.0.1.0", "1.0.0"));
EXPECT_EQ(1, utils::compare_version_strings("1.0.1.0", "1.0.0.0"));
EXPECT_EQ(1, utils::compare_version_strings("1.0", "0.9.9"));
EXPECT_EQ(1, utils::compare_version_strings("1.0.1", "0.9.9"));
EXPECT_EQ(1, utils::compare_version_strings("1.0.1.0", "0.9.9"));
}
TEST(version, less) {
EXPECT_EQ(-1, utils::compare_version_strings("0.9.9", "1.0"));
EXPECT_EQ(-1, utils::compare_version_strings("0.9.9", "1.0.1"));
EXPECT_EQ(-1, utils::compare_version_strings("0.9.9", "1.0.1.0"));
EXPECT_EQ(-1, utils::compare_version_strings("1.0", "1.0.1"));
EXPECT_EQ(-1, utils::compare_version_strings("1.0", "1.0.1.0"));
EXPECT_EQ(-1, utils::compare_version_strings("1.0.0", "1.0.1"));
EXPECT_EQ(-1, utils::compare_version_strings("1.0.0", "1.0.1.0"));
EXPECT_EQ(-1, utils::compare_version_strings("1.0.0.0", "1.0.1"));
EXPECT_EQ(-1, utils::compare_version_strings("1.0.0.0", "1.0.1.0"));
}
} // namespace repertory

View File

@@ -1,385 +1,385 @@
/*
Copyright <2018-2023> <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.
*/
#if _WIN32
#include "test_common.hpp"
#include "fixtures/winfsp_fixture.hpp"
#include "types/repertory.hpp"
#include "utils/event_capture.hpp"
namespace repertory {
void launch_app(std::string cmd) {
PROCESS_INFORMATION pi{};
STARTUPINFO si{};
si.cb = sizeof(si);
if (!::CreateProcessA(nullptr, (LPSTR)cmd.c_str(), nullptr, nullptr, FALSE,
CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP, nullptr,
nullptr, &si, &pi)) {
throw std::runtime_error("CreateProcess failed (" +
std::to_string(::GetLastError()) + ")");
}
::WaitForSingleObject(pi.hProcess, INFINITE);
DWORD code{};
::GetExitCodeProcess(pi.hProcess, &code);
::CloseHandle(pi.hProcess);
::CloseHandle(pi.hThread);
EXPECT_EQ(0, code);
}
E_SIMPLE1(test_begin, normal, false, std::string, test_name, TN, E_STRING);
#define TEST_HEADER(func) \
event_system::instance().raise<test_begin>( \
std::string(func) + \
"\r\n***********************\r\n***********************")
static auto mount_setup(std::string &mount_point) {
mount_point = "U:";
return std::vector<std::string>({"unittests", "-f", mount_point});
}
static void execute_mount(winfsp_test *test,
const std::vector<std::string> &drive_args,
std::thread &th) {
ASSERT_EQ(0, test->drive->mount(drive_args));
th.join();
}
static void unmount(winfsp_test *test, const std::string &mount_point) {
test->drive->shutdown();
auto mounted = utils::file::is_directory(mount_point);
for (auto i = 0; mounted && (i < 50); i++) {
std::this_thread::sleep_for(100ms);
mounted = utils::file::is_directory(mount_point);
}
EXPECT_FALSE(utils::file::is_directory(mount_point));
}
static void root_creation_test(const std::string &mount_point) {
TEST_HEADER(__FUNCTION__);
WIN32_FILE_ATTRIBUTE_DATA ad{};
EXPECT_TRUE(
::GetFileAttributesEx(&mount_point[0], GetFileExInfoStandard, &ad));
EXPECT_EQ(FILE_ATTRIBUTE_DIRECTORY, ad.dwFileAttributes);
EXPECT_EQ(0, ad.nFileSizeHigh);
EXPECT_EQ(0, ad.nFileSizeLow);
}
static auto create_test(winfsp_test *test, const std::string &mount_point) {
TEST_HEADER(__FUNCTION__);
auto file = utils::path::combine(mount_point, {{"test_create.txt"}});
auto handle = ::CreateFileA(&file[0], GENERIC_READ, FILE_SHARE_READ, nullptr,
CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
EXPECT_NE(INVALID_HANDLE_VALUE, handle);
EXPECT_TRUE(::CloseHandle(handle));
EXPECT_TRUE(utils::file::is_file(file));
std::uint64_t file_size;
EXPECT_TRUE(utils::file::get_file_size(file, file_size));
EXPECT_EQ(0, file_size);
std::string attr;
EXPECT_EQ(api_error::success, test->provider->get_item_meta(
"/test_create.txt", META_ATTRIBUTES, attr));
EXPECT_EQ(FILE_ATTRIBUTE_NORMAL, utils::string::to_uint32(attr));
return file;
}
static void delete_file_test(const std::string &file) {
TEST_HEADER(__FUNCTION__);
event_capture ec({"file_removed"});
EXPECT_TRUE(utils::file::retry_delete_file(file));
EXPECT_FALSE(utils::file::is_file(file));
}
static void create_directory_test(const std::string &directory) {
TEST_HEADER(__FUNCTION__);
EXPECT_FALSE(::PathIsDirectory(&directory[0]));
EXPECT_TRUE(::CreateDirectoryA(&directory[0], nullptr));
EXPECT_TRUE(::PathIsDirectory(&directory[0]));
}
static void remove_directory_test(const std::string &directory) {
TEST_HEADER(__FUNCTION__);
event_capture ec({"directory_removed"});
EXPECT_TRUE(::PathIsDirectory(&directory[0]));
EXPECT_TRUE(::RemoveDirectoryA(&directory[0]));
EXPECT_FALSE(::PathIsDirectory(&directory[0]));
}
static void write_file_test(const std::string &mount_point) {
TEST_HEADER(__FUNCTION__);
const auto file = utils::path::combine(mount_point, {"test_write.txt"});
auto handle =
::CreateFileA(&file[0], GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ,
nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
EXPECT_NE(INVALID_HANDLE_VALUE, handle);
const std::string data = "0123456789";
DWORD bytes_written = 0;
EXPECT_TRUE(::WriteFile(handle, &data[0], static_cast<DWORD>(data.size()),
&bytes_written, nullptr));
EXPECT_EQ(10, bytes_written);
EXPECT_TRUE(::CloseHandle(handle));
EXPECT_TRUE(utils::file::is_file(file));
std::uint64_t file_size;
EXPECT_TRUE(utils::file::get_file_size(file, file_size));
EXPECT_EQ(10, file_size);
}
static void read_file_test(const std::string &mount_point) {
TEST_HEADER(__FUNCTION__);
const auto file = utils::path::combine(mount_point, {"test_read.txt"});
auto handle =
::CreateFileA(&file[0], GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ,
nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
EXPECT_NE(INVALID_HANDLE_VALUE, handle);
const std::string data = "0123456789";
DWORD bytes_written = 0;
EXPECT_TRUE(::WriteFile(handle, &data[0], static_cast<DWORD>(data.size()),
&bytes_written, nullptr));
EXPECT_EQ(10, bytes_written);
data_buffer data2;
data2.resize(10);
DWORD bytes_read = 0;
EXPECT_EQ(0, ::SetFilePointer(handle, 0, nullptr, FILE_BEGIN));
EXPECT_TRUE(::ReadFile(handle, &data2[0], static_cast<DWORD>(data2.size()),
&bytes_read, nullptr));
EXPECT_EQ(10, bytes_read);
for (auto i = 0; i < data.size(); i++) {
EXPECT_EQ(data[i], data2[i]);
}
EXPECT_TRUE(::CloseHandle(handle));
}
static void rename_file_test(winfsp_test *test,
const std::string &mount_point) {
TEST_HEADER(__FUNCTION__);
const auto file = utils::path::combine(mount_point, {"rename_file.txt"});
auto handle = ::CreateFileA(&file[0], GENERIC_READ, FILE_SHARE_READ, nullptr,
CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
EXPECT_NE(INVALID_HANDLE_VALUE, handle);
EXPECT_TRUE(::CloseHandle(handle));
api_meta_map meta1{};
EXPECT_EQ(api_error::success,
test->provider->get_item_meta("/rename_file.txt", meta1));
const auto file2 = utils::path::combine(mount_point, {"rename_file2.txt"});
EXPECT_TRUE(::MoveFile(&file[0], &file2[0]));
EXPECT_TRUE(utils::file::is_file(file2));
EXPECT_FALSE(utils::file::is_file(file));
api_meta_map meta2{};
EXPECT_EQ(api_error::success,
test->provider->get_item_meta("/rename_file2.txt", meta2));
EXPECT_STREQ(meta1[META_SOURCE].c_str(), meta2[META_SOURCE].c_str());
filesystem_item fsi{};
EXPECT_EQ(api_error::success, test->provider->get_filesystem_item(
"/rename_file2.txt", false, fsi));
EXPECT_STREQ(meta1[META_SOURCE].c_str(), fsi.source_path.c_str());
filesystem_item fsi2{};
EXPECT_EQ(api_error::success,
test->provider->get_filesystem_item_from_source_path(
fsi.source_path, fsi2));
EXPECT_STREQ("/rename_file2.txt", fsi2.api_path.c_str());
EXPECT_EQ(api_error::item_not_found,
test->provider->get_item_meta("/rename_file.txt", meta2));
}
static void rename_directory_test(const std::string &mount_point) {
TEST_HEADER(__FUNCTION__);
std::string directory = "rename_dir";
const auto full_directory = utils::path::combine(mount_point, {directory});
std::string directory2 = "rename_dir2";
const auto full_directory2 = utils::path::combine(mount_point, {directory2});
EXPECT_FALSE(::PathIsDirectory(&full_directory[0]));
EXPECT_TRUE(::CreateDirectoryA(&full_directory[0], nullptr));
EXPECT_TRUE(::PathIsDirectory(&full_directory[0]));
EXPECT_TRUE(::MoveFile(&full_directory[0], &full_directory2[0]));
EXPECT_FALSE(::PathIsDirectory(&full_directory[0]));
EXPECT_TRUE(::PathIsDirectory(&full_directory2[0]));
}
static void get_set_basic_info_test(const std::string &mount_point) {
TEST_HEADER(__FUNCTION__);
const auto file =
utils::path::combine(mount_point, {"setbasicinfo_file.txt"});
auto handle =
::CreateFileA(&file[0], GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ,
nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
EXPECT_NE(INVALID_HANDLE_VALUE, handle);
SYSTEMTIME st{};
::GetSystemTime(&st);
st.wMinute = 0;
FILETIME test_ch_time{};
st.wMinute++;
::SystemTimeToFileTime(&st, &test_ch_time);
FILETIME test_cr_time{};
st.wMinute++;
::SystemTimeToFileTime(&st, &test_cr_time);
FILETIME test_la_time{};
st.wMinute++;
::SystemTimeToFileTime(&st, &test_la_time);
FILETIME test_lw_time{};
st.wMinute++;
::SystemTimeToFileTime(&st, &test_lw_time);
FILE_BASIC_INFO fbi{};
fbi.FileAttributes = FILE_ATTRIBUTE_HIDDEN;
fbi.ChangeTime.HighPart = test_ch_time.dwHighDateTime;
fbi.ChangeTime.LowPart = test_ch_time.dwLowDateTime;
fbi.CreationTime = *(LARGE_INTEGER *)&test_cr_time;
fbi.LastAccessTime = *(LARGE_INTEGER *)&test_la_time;
fbi.LastWriteTime = *(LARGE_INTEGER *)&test_lw_time;
EXPECT_TRUE(::SetFileInformationByHandle(handle, FileBasicInfo, &fbi,
sizeof(FILE_BASIC_INFO)));
FILE_BASIC_INFO fbi2{};
EXPECT_TRUE(::GetFileInformationByHandleEx(handle, FileBasicInfo, &fbi2,
sizeof(FILE_BASIC_INFO)));
EXPECT_EQ(0, memcmp(&fbi, &fbi2, sizeof(FILE_BASIC_INFO)));
std::cout << fbi.FileAttributes << " " << fbi.ChangeTime.QuadPart << " "
<< fbi.CreationTime.QuadPart << " " << fbi.LastAccessTime.QuadPart
<< " " << fbi.LastWriteTime.QuadPart << std::endl;
std::cout << fbi2.FileAttributes << " " << fbi2.ChangeTime.QuadPart << " "
<< fbi2.CreationTime.QuadPart << " " << fbi2.LastAccessTime.QuadPart
<< " " << fbi2.LastWriteTime.QuadPart << std::endl;
EXPECT_TRUE(::CloseHandle(handle));
}
static void overwrite_file_test(const std::string &mount_point) {
TEST_HEADER(__FUNCTION__);
const auto file = utils::path::combine("./", {"test_overwrite.txt"});
auto handle =
::CreateFileA(&file[0], GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ,
nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
EXPECT_NE(INVALID_HANDLE_VALUE, handle);
if (handle != INVALID_HANDLE_VALUE) {
const std::string data = "0123456789";
DWORD bytes_written = 0;
EXPECT_TRUE(::WriteFile(handle, &data[0], static_cast<DWORD>(data.size()),
&bytes_written, nullptr));
EXPECT_EQ(10, bytes_written);
EXPECT_TRUE(::CloseHandle(handle));
if (bytes_written == 10) {
const auto file2 =
utils::path::combine(mount_point, {"test_overwrite2.txt"});
EXPECT_TRUE(::CopyFile(&file[0], &file2[0], TRUE));
EXPECT_FALSE(::CopyFile(&file[0], &file2[0], TRUE));
}
}
}
TEST_F(winfsp_test, all_tests) {
if (PROVIDER_INDEX == 0) {
for (std::size_t idx = 0U; idx < 2U; idx++) {
launch_app(
("cmd.exe /c unittests.exe --gtest_filter=winfsp_test.all_tests "
"--provider_index " +
std::to_string(idx) + " > unittests" + std::to_string(idx) +
".log 2>&1"));
}
return;
}
#ifndef REPERTORY_ENABLE_S3
if (PROVIDER_INDEX == 1U) {
return;
}
#endif
std::string mount_point;
const auto drive_args = mount_setup(mount_point);
event_capture ec({
"drive_mounted",
"drive_unmounted",
"drive_unmount_pending",
"drive_mount_result",
});
std::thread th([&] {
const auto mounted = ec.wait_for_event("drive_mounted");
EXPECT_TRUE(mounted);
if (mounted) {
root_creation_test(mount_point);
{
const auto file = create_test(this, mount_point);
delete_file_test(file);
}
{
const auto dir = utils::path::combine(mount_point, {"TestDir"});
create_directory_test(dir);
remove_directory_test(dir);
}
write_file_test(mount_point);
read_file_test(mount_point);
// TODO enable after rename support is available
// rename_file_test(this, mount_point);
// rename_directory_test(mount_point);
overwrite_file_test(mount_point);
get_set_basic_info_test(mount_point);
}
if (mounted) {
unmount(this, mount_point);
ec.wait_for_empty();
}
});
execute_mount(this, drive_args, th);
}
} // namespace repertory
#endif
/*
Copyright <2018-2023> <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.
*/
#if _WIN32
#include "test_common.hpp"
#include "fixtures/winfsp_fixture.hpp"
#include "types/repertory.hpp"
#include "utils/event_capture.hpp"
namespace repertory {
void launch_app(std::string cmd) {
PROCESS_INFORMATION pi{};
STARTUPINFO si{};
si.cb = sizeof(si);
if (!::CreateProcessA(nullptr, (LPSTR)cmd.c_str(), nullptr, nullptr, FALSE,
CREATE_NEW_CONSOLE | CREATE_NEW_PROCESS_GROUP, nullptr,
nullptr, &si, &pi)) {
throw std::runtime_error("CreateProcess failed (" +
std::to_string(::GetLastError()) + ")");
}
::WaitForSingleObject(pi.hProcess, INFINITE);
DWORD code{};
::GetExitCodeProcess(pi.hProcess, &code);
::CloseHandle(pi.hProcess);
::CloseHandle(pi.hThread);
EXPECT_EQ(0, code);
}
E_SIMPLE1(test_begin, normal, false, std::string, test_name, TN, E_STRING);
#define TEST_HEADER(func) \
event_system::instance().raise<test_begin>( \
std::string(func) + \
"\r\n***********************\r\n***********************")
static auto mount_setup(std::string &mount_point) {
mount_point = "U:";
return std::vector<std::string>({"unittests", "-f", mount_point});
}
static void execute_mount(winfsp_test *test,
const std::vector<std::string> &drive_args,
std::thread &th) {
ASSERT_EQ(0, test->drive->mount(drive_args));
th.join();
}
static void unmount(winfsp_test *test, const std::string &mount_point) {
test->drive->shutdown();
auto mounted = utils::file::is_directory(mount_point);
for (auto i = 0; mounted && (i < 50); i++) {
std::this_thread::sleep_for(100ms);
mounted = utils::file::is_directory(mount_point);
}
EXPECT_FALSE(utils::file::is_directory(mount_point));
}
static void root_creation_test(const std::string &mount_point) {
TEST_HEADER(__FUNCTION__);
WIN32_FILE_ATTRIBUTE_DATA ad{};
EXPECT_TRUE(
::GetFileAttributesEx(&mount_point[0], GetFileExInfoStandard, &ad));
EXPECT_EQ(FILE_ATTRIBUTE_DIRECTORY, ad.dwFileAttributes);
EXPECT_EQ(0, ad.nFileSizeHigh);
EXPECT_EQ(0, ad.nFileSizeLow);
}
static auto create_test(winfsp_test *test, const std::string &mount_point) {
TEST_HEADER(__FUNCTION__);
auto file = utils::path::combine(mount_point, {{"test_create.txt"}});
auto handle = ::CreateFileA(&file[0], GENERIC_READ, FILE_SHARE_READ, nullptr,
CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
EXPECT_NE(INVALID_HANDLE_VALUE, handle);
EXPECT_TRUE(::CloseHandle(handle));
EXPECT_TRUE(utils::file::is_file(file));
std::uint64_t file_size;
EXPECT_TRUE(utils::file::get_file_size(file, file_size));
EXPECT_EQ(0, file_size);
std::string attr;
EXPECT_EQ(api_error::success, test->provider->get_item_meta(
"/test_create.txt", META_ATTRIBUTES, attr));
EXPECT_EQ(FILE_ATTRIBUTE_NORMAL, utils::string::to_uint32(attr));
return file;
}
static void delete_file_test(const std::string &file) {
TEST_HEADER(__FUNCTION__);
event_capture ec({"file_removed"});
EXPECT_TRUE(utils::file::retry_delete_file(file));
EXPECT_FALSE(utils::file::is_file(file));
}
static void create_directory_test(const std::string &directory) {
TEST_HEADER(__FUNCTION__);
EXPECT_FALSE(::PathIsDirectory(&directory[0]));
EXPECT_TRUE(::CreateDirectoryA(&directory[0], nullptr));
EXPECT_TRUE(::PathIsDirectory(&directory[0]));
}
static void remove_directory_test(const std::string &directory) {
TEST_HEADER(__FUNCTION__);
event_capture ec({"directory_removed"});
EXPECT_TRUE(::PathIsDirectory(&directory[0]));
EXPECT_TRUE(::RemoveDirectoryA(&directory[0]));
EXPECT_FALSE(::PathIsDirectory(&directory[0]));
}
static void write_file_test(const std::string &mount_point) {
TEST_HEADER(__FUNCTION__);
const auto file = utils::path::combine(mount_point, {"test_write.txt"});
auto handle =
::CreateFileA(&file[0], GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ,
nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
EXPECT_NE(INVALID_HANDLE_VALUE, handle);
const std::string data = "0123456789";
DWORD bytes_written = 0;
EXPECT_TRUE(::WriteFile(handle, &data[0], static_cast<DWORD>(data.size()),
&bytes_written, nullptr));
EXPECT_EQ(10, bytes_written);
EXPECT_TRUE(::CloseHandle(handle));
EXPECT_TRUE(utils::file::is_file(file));
std::uint64_t file_size;
EXPECT_TRUE(utils::file::get_file_size(file, file_size));
EXPECT_EQ(10, file_size);
}
static void read_file_test(const std::string &mount_point) {
TEST_HEADER(__FUNCTION__);
const auto file = utils::path::combine(mount_point, {"test_read.txt"});
auto handle =
::CreateFileA(&file[0], GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ,
nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
EXPECT_NE(INVALID_HANDLE_VALUE, handle);
const std::string data = "0123456789";
DWORD bytes_written = 0;
EXPECT_TRUE(::WriteFile(handle, &data[0], static_cast<DWORD>(data.size()),
&bytes_written, nullptr));
EXPECT_EQ(10, bytes_written);
data_buffer data2;
data2.resize(10);
DWORD bytes_read = 0;
EXPECT_EQ(0, ::SetFilePointer(handle, 0, nullptr, FILE_BEGIN));
EXPECT_TRUE(::ReadFile(handle, &data2[0], static_cast<DWORD>(data2.size()),
&bytes_read, nullptr));
EXPECT_EQ(10, bytes_read);
for (auto i = 0; i < data.size(); i++) {
EXPECT_EQ(data[i], data2[i]);
}
EXPECT_TRUE(::CloseHandle(handle));
}
static void rename_file_test(winfsp_test *test,
const std::string &mount_point) {
TEST_HEADER(__FUNCTION__);
const auto file = utils::path::combine(mount_point, {"rename_file.txt"});
auto handle = ::CreateFileA(&file[0], GENERIC_READ, FILE_SHARE_READ, nullptr,
CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
EXPECT_NE(INVALID_HANDLE_VALUE, handle);
EXPECT_TRUE(::CloseHandle(handle));
api_meta_map meta1{};
EXPECT_EQ(api_error::success,
test->provider->get_item_meta("/rename_file.txt", meta1));
const auto file2 = utils::path::combine(mount_point, {"rename_file2.txt"});
EXPECT_TRUE(::MoveFile(&file[0], &file2[0]));
EXPECT_TRUE(utils::file::is_file(file2));
EXPECT_FALSE(utils::file::is_file(file));
api_meta_map meta2{};
EXPECT_EQ(api_error::success,
test->provider->get_item_meta("/rename_file2.txt", meta2));
EXPECT_STREQ(meta1[META_SOURCE].c_str(), meta2[META_SOURCE].c_str());
filesystem_item fsi{};
EXPECT_EQ(api_error::success, test->provider->get_filesystem_item(
"/rename_file2.txt", false, fsi));
EXPECT_STREQ(meta1[META_SOURCE].c_str(), fsi.source_path.c_str());
filesystem_item fsi2{};
EXPECT_EQ(api_error::success,
test->provider->get_filesystem_item_from_source_path(
fsi.source_path, fsi2));
EXPECT_STREQ("/rename_file2.txt", fsi2.api_path.c_str());
EXPECT_EQ(api_error::item_not_found,
test->provider->get_item_meta("/rename_file.txt", meta2));
}
static void rename_directory_test(const std::string &mount_point) {
TEST_HEADER(__FUNCTION__);
std::string directory = "rename_dir";
const auto full_directory = utils::path::combine(mount_point, {directory});
std::string directory2 = "rename_dir2";
const auto full_directory2 = utils::path::combine(mount_point, {directory2});
EXPECT_FALSE(::PathIsDirectory(&full_directory[0]));
EXPECT_TRUE(::CreateDirectoryA(&full_directory[0], nullptr));
EXPECT_TRUE(::PathIsDirectory(&full_directory[0]));
EXPECT_TRUE(::MoveFile(&full_directory[0], &full_directory2[0]));
EXPECT_FALSE(::PathIsDirectory(&full_directory[0]));
EXPECT_TRUE(::PathIsDirectory(&full_directory2[0]));
}
static void get_set_basic_info_test(const std::string &mount_point) {
TEST_HEADER(__FUNCTION__);
const auto file =
utils::path::combine(mount_point, {"setbasicinfo_file.txt"});
auto handle =
::CreateFileA(&file[0], GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ,
nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr);
EXPECT_NE(INVALID_HANDLE_VALUE, handle);
SYSTEMTIME st{};
::GetSystemTime(&st);
st.wMinute = 0;
FILETIME test_ch_time{};
st.wMinute++;
::SystemTimeToFileTime(&st, &test_ch_time);
FILETIME test_cr_time{};
st.wMinute++;
::SystemTimeToFileTime(&st, &test_cr_time);
FILETIME test_la_time{};
st.wMinute++;
::SystemTimeToFileTime(&st, &test_la_time);
FILETIME test_lw_time{};
st.wMinute++;
::SystemTimeToFileTime(&st, &test_lw_time);
FILE_BASIC_INFO fbi{};
fbi.FileAttributes = FILE_ATTRIBUTE_HIDDEN;
fbi.ChangeTime.HighPart = test_ch_time.dwHighDateTime;
fbi.ChangeTime.LowPart = test_ch_time.dwLowDateTime;
fbi.CreationTime = *(LARGE_INTEGER *)&test_cr_time;
fbi.LastAccessTime = *(LARGE_INTEGER *)&test_la_time;
fbi.LastWriteTime = *(LARGE_INTEGER *)&test_lw_time;
EXPECT_TRUE(::SetFileInformationByHandle(handle, FileBasicInfo, &fbi,
sizeof(FILE_BASIC_INFO)));
FILE_BASIC_INFO fbi2{};
EXPECT_TRUE(::GetFileInformationByHandleEx(handle, FileBasicInfo, &fbi2,
sizeof(FILE_BASIC_INFO)));
EXPECT_EQ(0, memcmp(&fbi, &fbi2, sizeof(FILE_BASIC_INFO)));
std::cout << fbi.FileAttributes << " " << fbi.ChangeTime.QuadPart << " "
<< fbi.CreationTime.QuadPart << " " << fbi.LastAccessTime.QuadPart
<< " " << fbi.LastWriteTime.QuadPart << std::endl;
std::cout << fbi2.FileAttributes << " " << fbi2.ChangeTime.QuadPart << " "
<< fbi2.CreationTime.QuadPart << " " << fbi2.LastAccessTime.QuadPart
<< " " << fbi2.LastWriteTime.QuadPart << std::endl;
EXPECT_TRUE(::CloseHandle(handle));
}
static void overwrite_file_test(const std::string &mount_point) {
TEST_HEADER(__FUNCTION__);
const auto file = utils::path::combine("./", {"test_overwrite.txt"});
auto handle =
::CreateFileA(&file[0], GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ,
nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
EXPECT_NE(INVALID_HANDLE_VALUE, handle);
if (handle != INVALID_HANDLE_VALUE) {
const std::string data = "0123456789";
DWORD bytes_written = 0;
EXPECT_TRUE(::WriteFile(handle, &data[0], static_cast<DWORD>(data.size()),
&bytes_written, nullptr));
EXPECT_EQ(10, bytes_written);
EXPECT_TRUE(::CloseHandle(handle));
if (bytes_written == 10) {
const auto file2 =
utils::path::combine(mount_point, {"test_overwrite2.txt"});
EXPECT_TRUE(::CopyFile(&file[0], &file2[0], TRUE));
EXPECT_FALSE(::CopyFile(&file[0], &file2[0], TRUE));
}
}
}
TEST_F(winfsp_test, all_tests) {
if (PROVIDER_INDEX == 0) {
for (std::size_t idx = 0U; idx < 2U; idx++) {
launch_app(
("cmd.exe /c unittests.exe --gtest_filter=winfsp_test.all_tests "
"--provider_index " +
std::to_string(idx) + " > unittests" + std::to_string(idx) +
".log 2>&1"));
}
return;
}
#ifndef REPERTORY_ENABLE_S3
if (PROVIDER_INDEX == 1U) {
return;
}
#endif
std::string mount_point;
const auto drive_args = mount_setup(mount_point);
event_capture ec({
"drive_mounted",
"drive_unmounted",
"drive_unmount_pending",
"drive_mount_result",
});
std::thread th([&] {
const auto mounted = ec.wait_for_event("drive_mounted");
EXPECT_TRUE(mounted);
if (mounted) {
root_creation_test(mount_point);
{
const auto file = create_test(this, mount_point);
delete_file_test(file);
}
{
const auto dir = utils::path::combine(mount_point, {"TestDir"});
create_directory_test(dir);
remove_directory_test(dir);
}
write_file_test(mount_point);
read_file_test(mount_point);
// TODO enable after rename support is available
// rename_file_test(this, mount_point);
// rename_directory_test(mount_point);
overwrite_file_test(mount_point);
get_set_basic_info_test(mount_point);
}
if (mounted) {
unmount(this, mount_point);
ec.wait_for_empty();
}
});
execute_mount(this, drive_args, th);
}
} // namespace repertory
#endif