unit tests and fixes
This commit is contained in:
parent
7a69989275
commit
895464f50d
63
repertory/repertory_test/src/atomic_test.cpp
Normal file
63
repertory/repertory_test/src/atomic_test.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
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_common.hpp"
|
||||
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
TEST(atomic, atomic_primitive) {
|
||||
atomic<std::uint16_t> value;
|
||||
value = 5U;
|
||||
EXPECT_EQ(5U, static_cast<std::uint16_t>(value));
|
||||
}
|
||||
|
||||
TEST(atomic, atomic_primitive_equality) {
|
||||
atomic<std::uint16_t> value1{5U};
|
||||
atomic<std::uint16_t> value2{5U};
|
||||
EXPECT_EQ(value1, value1);
|
||||
EXPECT_EQ(value2, value2);
|
||||
EXPECT_EQ(value1, value2);
|
||||
EXPECT_EQ(static_cast<std::uint16_t>(value1), 5U);
|
||||
EXPECT_EQ(static_cast<std::uint16_t>(value2), 5U);
|
||||
}
|
||||
|
||||
TEST(atomic, atomic_primitive_inequality) {
|
||||
atomic<std::uint16_t> value1{5U};
|
||||
atomic<std::uint16_t> value2{6U};
|
||||
EXPECT_NE(value1, value2);
|
||||
EXPECT_NE(static_cast<std::uint16_t>(value1), 6U);
|
||||
EXPECT_NE(static_cast<std::uint16_t>(value2), 5U);
|
||||
}
|
||||
|
||||
TEST(atomic, atomic_struct) {
|
||||
atomic<encrypt_config> value{
|
||||
encrypt_config{
|
||||
.encryption_token = "token",
|
||||
.path = "path",
|
||||
},
|
||||
};
|
||||
|
||||
auto data = static_cast<encrypt_config>(value);
|
||||
EXPECT_STREQ("token", data.encryption_token.c_str());
|
||||
EXPECT_STREQ("path", data.path.c_str());
|
||||
}
|
||||
} // namespace repertory
|
163
repertory/repertory_test/src/json_serialize_test.cpp
Normal file
163
repertory/repertory_test/src/json_serialize_test.cpp
Normal file
@ -0,0 +1,163 @@
|
||||
/*
|
||||
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_common.hpp"
|
||||
|
||||
#include "types/remote.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
TEST(json_serialize, can_handle_directory_item) {
|
||||
directory_item cfg{
|
||||
"api", "parent", true, 2U, {{META_DIRECTORY, "true"}}, false,
|
||||
};
|
||||
|
||||
json data(cfg);
|
||||
EXPECT_STREQ("api", data.at("ApiPath").get<std::string>().c_str());
|
||||
EXPECT_STREQ("parent", data.at("ApiParent").get<std::string>().c_str());
|
||||
EXPECT_TRUE(data.at("Directory").get<bool>());
|
||||
EXPECT_STREQ("true", data.at("meta").at(META_DIRECTORY).get<std::string>());
|
||||
EXPECT_FALSE(data.at("Resolved").get<bool>());
|
||||
|
||||
{
|
||||
auto cfg2 = data.get<directory_item>();
|
||||
EXPECT_STREQ(cfg2.api_path.c_str(), cfg.api_path.c_str());
|
||||
EXPECT_STREQ(cfg2.api_parent.c_str(), cfg.api_parent.c_str());
|
||||
EXPECT_EQ(cfg2.directory, cfg.directory);
|
||||
EXPECT_STREQ(cfg2.meta.at(META_DIRECTORY).c_str(),
|
||||
cfg.meta.at(META_DIRECTORY).c_str());
|
||||
EXPECT_EQ(cfg2.resolved, cfg.resolved);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(json_serialize, can_handle_encrypt_config) {
|
||||
encrypt_config cfg{
|
||||
"token",
|
||||
"path",
|
||||
};
|
||||
|
||||
json data(cfg);
|
||||
EXPECT_STREQ("token", data.at("EncryptionToken").get<std::string>().c_str());
|
||||
EXPECT_STREQ("path", data.at("Path").get<std::string>().c_str());
|
||||
|
||||
{
|
||||
auto cfg2 = data.get<encrypt_config>();
|
||||
EXPECT_STREQ(cfg2.encryption_token.c_str(), cfg.encryption_token.c_str());
|
||||
EXPECT_STREQ(cfg2.path.c_str(), cfg.path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(json_serialize, can_handle_host_config) {
|
||||
host_config cfg{
|
||||
"agent", "pwd", "user", 1024U, "host", "path", "http", 11U,
|
||||
};
|
||||
|
||||
json data(cfg);
|
||||
EXPECT_STREQ("agent", data.at("AgentString").get<std::string>().c_str());
|
||||
EXPECT_STREQ("pwd", data.at("ApiPassword").get<std::string>().c_str());
|
||||
EXPECT_STREQ("user", data.at("ApiUser").get<std::string>().c_str());
|
||||
EXPECT_EQ(1024U, data.at("ApiPort").get<std::uint16_t>());
|
||||
EXPECT_STREQ("host", data.at("HostNameOrIp").get<std::string>().c_str());
|
||||
EXPECT_STREQ("path", data.at("Path").get<std::string>().c_str());
|
||||
EXPECT_STREQ("http", data.at("Protocol").get<std::string>().c_str());
|
||||
EXPECT_EQ(11U, data.at("TimeoutMs").get<std::uint16_t>());
|
||||
|
||||
{
|
||||
auto cfg2 = data.get<host_config>();
|
||||
EXPECT_STREQ(cfg2.agent_string.c_str(), cfg.agent_string.c_str());
|
||||
EXPECT_STREQ(cfg2.api_password.c_str(), cfg.api_password.c_str());
|
||||
EXPECT_STREQ(cfg2.api_user.c_str(), cfg.api_user.c_str());
|
||||
EXPECT_EQ(cfg2.api_port, cfg.api_port);
|
||||
EXPECT_STREQ(cfg2.host_name_or_ip.c_str(), cfg.host_name_or_ip.c_str());
|
||||
EXPECT_STREQ(cfg2.path.c_str(), cfg.path.c_str());
|
||||
EXPECT_STREQ(cfg2.protocol.c_str(), cfg.protocol.c_str());
|
||||
EXPECT_EQ(cfg2.timeout_ms, cfg.timeout_ms);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(json_serialize, can_handle_remote_config) {
|
||||
remote::remote_config cfg{
|
||||
1024U, "token", "host", 11U, 20U, 21U,
|
||||
};
|
||||
|
||||
json data(cfg);
|
||||
EXPECT_EQ(1024U, data.at("ApiPort").get<std::uint16_t>());
|
||||
EXPECT_STREQ("token", data.at("EncryptionToken").get<std::string>().c_str());
|
||||
EXPECT_STREQ("host", data.at("HostNameOrIp").get<std::string>().c_str());
|
||||
EXPECT_EQ(11U, data.at("MaxConnections").get<std::uint16_t>());
|
||||
EXPECT_EQ(20U, data.at("ReceiveTimeoutMs").get<std::uint32_t>());
|
||||
EXPECT_EQ(21U, data.at("SendTimeoutMs").get<std::uint32_t>());
|
||||
|
||||
{
|
||||
auto cfg2 = data.get<remote::remote_config>();
|
||||
EXPECT_EQ(cfg2.api_port, cfg.api_port);
|
||||
EXPECT_STREQ(cfg2.encryption_token.c_str(), cfg.encryption_token.c_str());
|
||||
EXPECT_STREQ(cfg2.host_name_or_ip.c_str(), cfg.host_name_or_ip.c_str());
|
||||
EXPECT_EQ(cfg2.max_connections, cfg.max_connections);
|
||||
EXPECT_EQ(cfg2.recv_timeout_ms, cfg.recv_timeout_ms);
|
||||
EXPECT_EQ(cfg2.send_timeout_ms, cfg.send_timeout_ms);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(json_serialize, can_handle_s3_config) {
|
||||
s3_config cfg{
|
||||
"access", "bucket", "token", "region", "secret", 31U, "url", true, false,
|
||||
};
|
||||
|
||||
json data(cfg);
|
||||
EXPECT_STREQ("access", data.at("AccessKey").get<std::string>().c_str());
|
||||
EXPECT_STREQ("bucket", data.at("Bucket").get<std::string>().c_str());
|
||||
EXPECT_STREQ("token", data.at("EncryptionToken").get<std::string>().c_str());
|
||||
EXPECT_STREQ("region", data.at("Region").get<std::string>().c_str());
|
||||
EXPECT_STREQ("secret", data.at("SecretKey").get<std::string>().c_str());
|
||||
EXPECT_EQ(31U, data.at("TimeoutMs").get<std::uint32_t>());
|
||||
EXPECT_STREQ("url", data.at("URL").get<std::string>().c_str());
|
||||
EXPECT_TRUE(data.at("UsePathStyle").get<bool>());
|
||||
EXPECT_FALSE(data.at("UseRegionInURL").get<bool>());
|
||||
|
||||
{
|
||||
auto cfg2 = data.get<s3_config>();
|
||||
EXPECT_STREQ(cfg2.access_key.c_str(), cfg.access_key.c_str());
|
||||
EXPECT_STREQ(cfg2.bucket.c_str(), cfg.bucket.c_str());
|
||||
EXPECT_STREQ(cfg2.encryption_token.c_str(), cfg.encryption_token.c_str());
|
||||
EXPECT_STREQ(cfg2.region.c_str(), cfg.region.c_str());
|
||||
EXPECT_STREQ(cfg2.secret_key.c_str(), cfg.secret_key.c_str());
|
||||
EXPECT_EQ(cfg2.timeout_ms, cfg.timeout_ms);
|
||||
EXPECT_STREQ(cfg2.url.c_str(), cfg.url.c_str());
|
||||
EXPECT_EQ(cfg2.use_path_style, cfg.use_path_style);
|
||||
EXPECT_EQ(cfg2.use_region_in_url, cfg.use_region_in_url);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(json_serialize, can_handle_sia_config) {
|
||||
sia_config cfg{
|
||||
"bucket",
|
||||
};
|
||||
|
||||
json data(cfg);
|
||||
EXPECT_STREQ("bucket", data.at("Bucket").get<std::string>().c_str());
|
||||
|
||||
{
|
||||
auto cfg2 = data.get<sia_config>();
|
||||
EXPECT_STREQ(cfg2.bucket.c_str(), cfg.bucket.c_str());
|
||||
}
|
||||
}
|
||||
} // namespace repertory
|
Loading…
x
Reference in New Issue
Block a user