updated build system
This commit is contained in:
65
support/test/src/utils/file_test.cpp
Normal file
65
support/test/src/utils/file_test.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#include "test.hpp"
|
||||
|
||||
namespace repertory {
|
||||
#if defined(PROJECT_ENABLE_JSON)
|
||||
TEST(utils_file, read_and_write_json_file) {
|
||||
auto path = test::generate_test_file_name("utils_file");
|
||||
|
||||
auto data = nlohmann::json({{"moose", "cow"}});
|
||||
EXPECT_TRUE(utils::file::write_json_file(path, data));
|
||||
|
||||
nlohmann::json data2{};
|
||||
EXPECT_TRUE(utils::file::read_json_file(path, data2));
|
||||
EXPECT_STREQ(data.dump().c_str(), data2.dump().c_str());
|
||||
}
|
||||
|
||||
#if defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
|
||||
TEST(utils_file, read_and_write_json_file_encrypted) {
|
||||
auto path = test::generate_test_file_name("utils_file");
|
||||
|
||||
auto data = nlohmann::json({{"moose", "cow"}});
|
||||
EXPECT_TRUE(utils::file::write_json_file(path, data, "moose"));
|
||||
|
||||
nlohmann::json data2{};
|
||||
EXPECT_TRUE(utils::file::read_json_file(path, data2, "moose"));
|
||||
EXPECT_STREQ(data.dump().c_str(), data2.dump().c_str());
|
||||
|
||||
{
|
||||
auto file = utils::file::file::open_file(path);
|
||||
data_buffer encrypted_data{};
|
||||
EXPECT_TRUE(file.read_all(encrypted_data, 0U));
|
||||
|
||||
data_buffer decrypted_data{};
|
||||
EXPECT_TRUE(utils::encryption::decrypt_data("moose", encrypted_data,
|
||||
decrypted_data));
|
||||
EXPECT_STREQ(data.dump().c_str(),
|
||||
nlohmann::json::parse(
|
||||
std::string{decrypted_data.begin(), decrypted_data.end()})
|
||||
.dump()
|
||||
.c_str());
|
||||
}
|
||||
}
|
||||
#endif // defined(PROJECT_ENABLE_LIBSODIUM) && defined(PROJECT_ENABLE_BOOST)
|
||||
#endif // defined(PROJECT_ENABLE_JSON)
|
||||
} // namespace repertory
|
Reference in New Issue
Block a user