mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
feat(API wrapper): separates implementation from public API
* moves implementation to impl subdirectory * adds prefix _impl to implementation symbols * removes double compilation for shared and static libraries * fixes include guards * fixes usage of extern "C"
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#define MOCK_AUTHENTICATOR_H
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include "wsfs/adapter/authenticator.h"
|
||||
#include "wsfs/adapter/impl/authenticator.h"
|
||||
|
||||
namespace wsfs_test
|
||||
{
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
#include "mock_authenticator.hpp"
|
||||
|
||||
#include "wsfs/adapter/authenticator.h"
|
||||
#include "wsfs/adapter/credentials_intern.h"
|
||||
#include "wsfs/adapter/impl/authenticator.h"
|
||||
#include "wsfs/adapter/impl/credentials.h"
|
||||
|
||||
using ::testing::Return;
|
||||
using ::testing::_;
|
||||
@@ -20,7 +20,7 @@ TEST(Authenticator, Authenticate)
|
||||
set_authenticator(&mock);
|
||||
|
||||
struct wsfs_credentials creds;
|
||||
wsfs_credentials_init(&creds, "username", nullptr);
|
||||
wsfs_impl_credentials_init(&creds, "username", nullptr);
|
||||
char dummy[] = "usr_data";
|
||||
void * user_data = reinterpret_cast<void*>(dummy);
|
||||
|
||||
@@ -28,16 +28,16 @@ TEST(Authenticator, Authenticate)
|
||||
.Times(1)
|
||||
.WillRepeatedly(Return(true));
|
||||
|
||||
struct wsfs_authenticator * authenticator = wsfs_authenticator_create(
|
||||
struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticator_create(
|
||||
"username",
|
||||
&authenticate,
|
||||
user_data);
|
||||
|
||||
bool result = wsfs_authenticator_autenticate(authenticator, &creds);
|
||||
bool result = wsfs_impl_authenticator_autenticate(authenticator, &creds);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
wsfs_authenticator_dispose(authenticator);
|
||||
wsfs_credentials_cleanup(&creds);
|
||||
wsfs_impl_authenticator_dispose(authenticator);
|
||||
wsfs_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
|
||||
TEST(Authenticator, SkipAuthenticationWithWrongType)
|
||||
@@ -46,18 +46,18 @@ TEST(Authenticator, SkipAuthenticationWithWrongType)
|
||||
set_authenticator(&mock);
|
||||
|
||||
struct wsfs_credentials creds;
|
||||
wsfs_credentials_init(&creds, "username", nullptr);
|
||||
wsfs_impl_credentials_init(&creds, "username", nullptr);
|
||||
EXPECT_CALL(mock, authenticate(_, _))
|
||||
.Times(0);
|
||||
|
||||
struct wsfs_authenticator * authenticator = wsfs_authenticator_create(
|
||||
struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticator_create(
|
||||
"certificate",
|
||||
&authenticate,
|
||||
nullptr);
|
||||
|
||||
bool result = wsfs_authenticator_autenticate(authenticator, &creds);
|
||||
bool result = wsfs_impl_authenticator_autenticate(authenticator, &creds);
|
||||
ASSERT_FALSE(result);
|
||||
|
||||
wsfs_authenticator_dispose(authenticator);
|
||||
wsfs_credentials_cleanup(&creds);
|
||||
wsfs_impl_authenticator_dispose(authenticator);
|
||||
wsfs_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include "wsfs/adapter/authenticators.h"
|
||||
#include "wsfs/adapter/credentials_intern.h"
|
||||
#include "wsfs/adapter/impl/authenticators.h"
|
||||
#include "wsfs/adapter/impl/credentials.h"
|
||||
#include "mock_authenticator.hpp"
|
||||
|
||||
using ::testing::_;
|
||||
@@ -16,71 +16,71 @@ using ::wsfs_test::authenticate_2;
|
||||
|
||||
TEST(Authenticators, CloneEmpty)
|
||||
{
|
||||
struct wsfs_authenticators authenticators;
|
||||
struct wsfs_authenticators clone;
|
||||
struct wsfs_impl_authenticators authenticators;
|
||||
struct wsfs_impl_authenticators clone;
|
||||
|
||||
wsfs_authenticators_init(&authenticators);
|
||||
wsfs_impl_authenticators_init(&authenticators);
|
||||
ASSERT_EQ(nullptr, authenticators.first);
|
||||
|
||||
wsfs_authenticators_clone(&authenticators, &clone);
|
||||
wsfs_impl_authenticators_clone(&authenticators, &clone);
|
||||
ASSERT_EQ(nullptr, clone.first);
|
||||
|
||||
wsfs_authenticators_cleanup(&authenticators);
|
||||
wsfs_authenticators_cleanup(&clone);
|
||||
wsfs_impl_authenticators_cleanup(&authenticators);
|
||||
wsfs_impl_authenticators_cleanup(&clone);
|
||||
}
|
||||
|
||||
TEST(Authenticators, Clone)
|
||||
{
|
||||
struct wsfs_authenticators authenticators;
|
||||
struct wsfs_authenticators clone;
|
||||
struct wsfs_impl_authenticators authenticators;
|
||||
struct wsfs_impl_authenticators clone;
|
||||
|
||||
wsfs_authenticators_init(&authenticators);
|
||||
wsfs_authenticators_add(&authenticators, "username", &authenticate, nullptr);
|
||||
wsfs_impl_authenticators_init(&authenticators);
|
||||
wsfs_impl_authenticators_add(&authenticators, "username", &authenticate, nullptr);
|
||||
ASSERT_NE(nullptr, authenticators.first);
|
||||
|
||||
wsfs_authenticators_clone(&authenticators, &clone);
|
||||
wsfs_impl_authenticators_clone(&authenticators, &clone);
|
||||
ASSERT_NE(nullptr, clone.first);
|
||||
ASSERT_NE(nullptr, authenticators.first);
|
||||
ASSERT_NE(authenticators.first, clone.first);
|
||||
|
||||
wsfs_authenticators_cleanup(&authenticators);
|
||||
wsfs_authenticators_cleanup(&clone);
|
||||
wsfs_impl_authenticators_cleanup(&authenticators);
|
||||
wsfs_impl_authenticators_cleanup(&clone);
|
||||
}
|
||||
|
||||
TEST(Authenticators, Move)
|
||||
{
|
||||
struct wsfs_authenticators authenticators;
|
||||
struct wsfs_authenticators clone;
|
||||
struct wsfs_impl_authenticators authenticators;
|
||||
struct wsfs_impl_authenticators clone;
|
||||
|
||||
wsfs_authenticators_init(&authenticators);
|
||||
wsfs_authenticators_add(&authenticators, "username", &authenticate, nullptr);
|
||||
wsfs_impl_authenticators_init(&authenticators);
|
||||
wsfs_impl_authenticators_add(&authenticators, "username", &authenticate, nullptr);
|
||||
ASSERT_NE(nullptr, authenticators.first);
|
||||
|
||||
wsfs_authenticators_move(&authenticators, &clone);
|
||||
wsfs_impl_authenticators_move(&authenticators, &clone);
|
||||
ASSERT_NE(nullptr, clone.first);
|
||||
ASSERT_EQ(nullptr, authenticators.first);
|
||||
ASSERT_NE(authenticators.first, clone.first);
|
||||
|
||||
wsfs_authenticators_cleanup(&authenticators);
|
||||
wsfs_authenticators_cleanup(&clone);
|
||||
wsfs_impl_authenticators_cleanup(&authenticators);
|
||||
wsfs_impl_authenticators_cleanup(&clone);
|
||||
}
|
||||
|
||||
TEST(Authenticators, AuthenticateWithoutAuthenticators)
|
||||
{
|
||||
struct wsfs_credentials creds;
|
||||
wsfs_credentials_init(&creds, "username", nullptr);
|
||||
wsfs_impl_credentials_init(&creds, "username", nullptr);
|
||||
|
||||
struct wsfs_authenticators authenticators;
|
||||
wsfs_authenticators_init(&authenticators);
|
||||
struct wsfs_impl_authenticators authenticators;
|
||||
wsfs_impl_authenticators_init(&authenticators);
|
||||
|
||||
bool result = wsfs_authenticators_authenticate(&authenticators, &creds);
|
||||
bool result = wsfs_impl_authenticators_authenticate(&authenticators, &creds);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
result = wsfs_authenticators_authenticate(&authenticators, nullptr);
|
||||
result = wsfs_impl_authenticators_authenticate(&authenticators, nullptr);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
wsfs_authenticators_cleanup(&authenticators);
|
||||
wsfs_credentials_cleanup(&creds);
|
||||
wsfs_impl_authenticators_cleanup(&authenticators);
|
||||
wsfs_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
|
||||
TEST(Authenticators, FailToAuthenticateWithoutCredentials)
|
||||
@@ -88,20 +88,20 @@ TEST(Authenticators, FailToAuthenticateWithoutCredentials)
|
||||
MockAuthenticator mock;
|
||||
set_authenticator(&mock);
|
||||
|
||||
struct wsfs_authenticators authenticators;
|
||||
wsfs_authenticators_init(&authenticators);
|
||||
wsfs_authenticators_add(&authenticators, "username", &authenticate, nullptr);
|
||||
struct wsfs_impl_authenticators authenticators;
|
||||
wsfs_impl_authenticators_init(&authenticators);
|
||||
wsfs_impl_authenticators_add(&authenticators, "username", &authenticate, nullptr);
|
||||
|
||||
bool result = wsfs_authenticators_authenticate(&authenticators, nullptr);
|
||||
bool result = wsfs_impl_authenticators_authenticate(&authenticators, nullptr);
|
||||
ASSERT_FALSE(result);
|
||||
|
||||
wsfs_authenticators_cleanup(&authenticators);
|
||||
wsfs_impl_authenticators_cleanup(&authenticators);
|
||||
}
|
||||
|
||||
TEST(Authenticators, AuthenticateWithMultipleCredentials)
|
||||
{
|
||||
struct wsfs_credentials creds;
|
||||
wsfs_credentials_init(&creds, "username", nullptr);
|
||||
wsfs_impl_credentials_init(&creds, "username", nullptr);
|
||||
|
||||
MockAuthenticator username_mock;
|
||||
set_authenticator(1, &username_mock);
|
||||
@@ -114,22 +114,22 @@ TEST(Authenticators, AuthenticateWithMultipleCredentials)
|
||||
EXPECT_CALL(certificate_mock, authenticate(_, _))
|
||||
.Times(0);
|
||||
|
||||
struct wsfs_authenticators authenticators;
|
||||
wsfs_authenticators_init(&authenticators);
|
||||
wsfs_authenticators_add(&authenticators, "username", &authenticate_1, nullptr);
|
||||
wsfs_authenticators_add(&authenticators, "certificate", &authenticate_2, nullptr);
|
||||
struct wsfs_impl_authenticators authenticators;
|
||||
wsfs_impl_authenticators_init(&authenticators);
|
||||
wsfs_impl_authenticators_add(&authenticators, "username", &authenticate_1, nullptr);
|
||||
wsfs_impl_authenticators_add(&authenticators, "certificate", &authenticate_2, nullptr);
|
||||
|
||||
bool result = wsfs_authenticators_authenticate(&authenticators, &creds);
|
||||
bool result = wsfs_impl_authenticators_authenticate(&authenticators, &creds);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
wsfs_authenticators_cleanup(&authenticators);
|
||||
wsfs_credentials_cleanup(&creds);
|
||||
wsfs_impl_authenticators_cleanup(&authenticators);
|
||||
wsfs_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
|
||||
TEST(Authenticators, FailedAuthenticateWithWrongType)
|
||||
{
|
||||
struct wsfs_credentials creds;
|
||||
wsfs_credentials_init(&creds, "token", nullptr);
|
||||
wsfs_impl_credentials_init(&creds, "token", nullptr);
|
||||
|
||||
MockAuthenticator username_mock;
|
||||
set_authenticator(1, &username_mock);
|
||||
@@ -141,14 +141,14 @@ TEST(Authenticators, FailedAuthenticateWithWrongType)
|
||||
EXPECT_CALL(certificate_mock, authenticate(_, _))
|
||||
.Times(0);
|
||||
|
||||
struct wsfs_authenticators authenticators;
|
||||
wsfs_authenticators_init(&authenticators);
|
||||
wsfs_authenticators_add(&authenticators, "username", &authenticate_1, nullptr);
|
||||
wsfs_authenticators_add(&authenticators, "certificate", &authenticate_2, nullptr);
|
||||
struct wsfs_impl_authenticators authenticators;
|
||||
wsfs_impl_authenticators_init(&authenticators);
|
||||
wsfs_impl_authenticators_add(&authenticators, "username", &authenticate_1, nullptr);
|
||||
wsfs_impl_authenticators_add(&authenticators, "certificate", &authenticate_2, nullptr);
|
||||
|
||||
bool result = wsfs_authenticators_authenticate(&authenticators, &creds);
|
||||
bool result = wsfs_impl_authenticators_authenticate(&authenticators, &creds);
|
||||
ASSERT_FALSE(result);
|
||||
|
||||
wsfs_authenticators_cleanup(&authenticators);
|
||||
wsfs_credentials_cleanup(&creds);
|
||||
wsfs_impl_authenticators_cleanup(&authenticators);
|
||||
wsfs_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wsfs/adapter/credentials_intern.h"
|
||||
#include "wsfs/adapter/impl/credentials.h"
|
||||
#include <jansson.h>
|
||||
|
||||
TEST(Credentials, Type)
|
||||
{
|
||||
struct wsfs_credentials creds;
|
||||
|
||||
wsfs_credentials_init(&creds, "test", nullptr);
|
||||
ASSERT_STREQ("test", wsfs_credentials_type(&creds));
|
||||
wsfs_credentials_cleanup(&creds);
|
||||
wsfs_impl_credentials_init(&creds, "test", nullptr);
|
||||
ASSERT_STREQ("test", wsfs_impl_credentials_type(&creds));
|
||||
wsfs_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
|
||||
TEST(Credentials, Get)
|
||||
@@ -19,12 +19,12 @@ TEST(Credentials, Get)
|
||||
json_object_set_new(data, "username", json_string("bob"));
|
||||
json_object_set_new(data, "password", json_string("<secret>"));
|
||||
|
||||
wsfs_credentials_init(&creds, "username", data);
|
||||
ASSERT_STREQ("username", wsfs_credentials_type(&creds));
|
||||
ASSERT_STREQ("bob", wsfs_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ("<secret>", wsfs_credentials_get(&creds, "password"));
|
||||
wsfs_impl_credentials_init(&creds, "username", data);
|
||||
ASSERT_STREQ("username", wsfs_impl_credentials_type(&creds));
|
||||
ASSERT_STREQ("bob", wsfs_impl_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ("<secret>", wsfs_impl_credentials_get(&creds, "password"));
|
||||
|
||||
wsfs_credentials_cleanup(&creds);
|
||||
wsfs_impl_credentials_cleanup(&creds);
|
||||
json_decref(data);
|
||||
}
|
||||
|
||||
@@ -33,12 +33,12 @@ TEST(Credentials, FailedToGetNonexistingValue)
|
||||
struct wsfs_credentials creds;
|
||||
json_t * data = json_object();
|
||||
|
||||
wsfs_credentials_init(&creds, "username", data);
|
||||
ASSERT_STREQ("username", wsfs_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wsfs_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wsfs_credentials_get(&creds, "password"));
|
||||
wsfs_impl_credentials_init(&creds, "username", data);
|
||||
ASSERT_STREQ("username", wsfs_impl_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "password"));
|
||||
|
||||
wsfs_credentials_cleanup(&creds);
|
||||
wsfs_impl_credentials_cleanup(&creds);
|
||||
json_decref(data);
|
||||
}
|
||||
|
||||
@@ -46,12 +46,12 @@ TEST(Credentials, FailedToGetWithoutData)
|
||||
{
|
||||
struct wsfs_credentials creds;
|
||||
|
||||
wsfs_credentials_init(&creds, "username", nullptr);
|
||||
ASSERT_STREQ("username", wsfs_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wsfs_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wsfs_credentials_get(&creds, "password"));
|
||||
wsfs_impl_credentials_init(&creds, "username", nullptr);
|
||||
ASSERT_STREQ("username", wsfs_impl_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "password"));
|
||||
|
||||
wsfs_credentials_cleanup(&creds);
|
||||
wsfs_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
|
||||
TEST(Credentials, FailedToGetWrongDataType)
|
||||
@@ -59,12 +59,12 @@ TEST(Credentials, FailedToGetWrongDataType)
|
||||
struct wsfs_credentials creds;
|
||||
json_t * data = json_string("invalid_creds");
|
||||
|
||||
wsfs_credentials_init(&creds, "username", data);
|
||||
ASSERT_STREQ("username", wsfs_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wsfs_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wsfs_credentials_get(&creds, "password"));
|
||||
wsfs_impl_credentials_init(&creds, "username", data);
|
||||
ASSERT_STREQ("username", wsfs_impl_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "password"));
|
||||
|
||||
wsfs_credentials_cleanup(&creds);
|
||||
wsfs_impl_credentials_cleanup(&creds);
|
||||
json_decref(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,59 +1,59 @@
|
||||
#include <string>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wsfs/adapter/jsonrpc/response.h"
|
||||
#include "wsfs/adapter/impl/jsonrpc/response.h"
|
||||
|
||||
|
||||
static void wsfs_response_parse_str(
|
||||
static void response_parse_str(
|
||||
std::string const & buffer,
|
||||
struct wsfs_jsonrpc_response * response)
|
||||
struct wsfs_impl_jsonrpc_response * response)
|
||||
{
|
||||
wsfs_jsonrpc_response_init(response, buffer.c_str(), buffer.size());
|
||||
wsfs_impl_jsonrpc_response_init(response, buffer.c_str(), buffer.size());
|
||||
}
|
||||
|
||||
TEST(response_parser, test)
|
||||
{
|
||||
struct wsfs_jsonrpc_response response;
|
||||
struct wsfs_impl_jsonrpc_response response;
|
||||
|
||||
// invalid json
|
||||
wsfs_response_parse_str("", &response);
|
||||
response_parse_str("", &response);
|
||||
ASSERT_NE(WSFS_GOOD, response.status);
|
||||
ASSERT_EQ(-1, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
// invalid json
|
||||
wsfs_response_parse_str("invalid_json", &response);
|
||||
response_parse_str("invalid_json", &response);
|
||||
ASSERT_NE(WSFS_GOOD, response.status);
|
||||
ASSERT_EQ(-1, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
// no object
|
||||
wsfs_response_parse_str("[]", &response);
|
||||
response_parse_str("[]", &response);
|
||||
ASSERT_NE(WSFS_GOOD, response.status);
|
||||
ASSERT_EQ(-1, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
// empty
|
||||
wsfs_response_parse_str("{}", &response);
|
||||
response_parse_str("{}", &response);
|
||||
ASSERT_NE(WSFS_GOOD, response.status);
|
||||
ASSERT_EQ(-1, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
// no data
|
||||
wsfs_response_parse_str("{\"id\":42}", &response);
|
||||
response_parse_str("{\"id\":42}", &response);
|
||||
ASSERT_NE(WSFS_GOOD, response.status);
|
||||
ASSERT_EQ(42, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
// custom error code
|
||||
wsfs_response_parse_str("{\"error\":{\"code\": 42}, \"id\": 42}", &response);
|
||||
response_parse_str("{\"error\":{\"code\": 42}, \"id\": 42}", &response);
|
||||
ASSERT_NE(WSFS_GOOD, response.status);
|
||||
ASSERT_EQ(42, response.status);
|
||||
ASSERT_EQ(42, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
// valid response
|
||||
wsfs_response_parse_str("{\"result\": true, \"id\": 42}", &response);
|
||||
response_parse_str("{\"result\": true, \"id\": 42}", &response);
|
||||
ASSERT_EQ(WSFS_GOOD, response.status);
|
||||
ASSERT_EQ(42, response.id);
|
||||
ASSERT_NE(nullptr, response.result);
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "msleep.hpp"
|
||||
#include "wsfs/adapter/time/timepoint.h"
|
||||
#include "wsfs/adapter/impl/time/timepoint.h"
|
||||
|
||||
using wsfs_test::msleep;
|
||||
|
||||
TEST(timepoint, now)
|
||||
{
|
||||
wsfs_timepoint start = wsfs_timepoint_now();
|
||||
wsfs_impl_timepoint start = wsfs_impl_timepoint_now();
|
||||
msleep(42);
|
||||
wsfs_timepoint end = wsfs_timepoint_now();
|
||||
wsfs_impl_timepoint end = wsfs_impl_timepoint_now();
|
||||
|
||||
ASSERT_LT(start, end);
|
||||
ASSERT_LT(end, start + 500);
|
||||
@@ -17,20 +17,20 @@ TEST(timepoint, now)
|
||||
|
||||
TEST(timepoint, in_msec)
|
||||
{
|
||||
wsfs_timepoint now = wsfs_timepoint_now();
|
||||
wsfs_timepoint later = wsfs_timepoint_in_msec(42);
|
||||
wsfs_impl_timepoint now = wsfs_impl_timepoint_now();
|
||||
wsfs_impl_timepoint later = wsfs_impl_timepoint_in_msec(42);
|
||||
|
||||
ASSERT_LT(now, later);
|
||||
ASSERT_LT(later, now + 500);
|
||||
}
|
||||
|
||||
TEST(timepoint, elapsed)
|
||||
TEST(wsfs_impl_timepoint, elapsed)
|
||||
{
|
||||
wsfs_timepoint now;
|
||||
wsfs_impl_timepoint now;
|
||||
|
||||
now = wsfs_timepoint_now();
|
||||
ASSERT_TRUE(wsfs_timepoint_is_elapsed(now - 1));
|
||||
now = wsfs_impl_timepoint_now();
|
||||
ASSERT_TRUE(wsfs_impl_timepoint_is_elapsed(now - 1));
|
||||
|
||||
now = wsfs_timepoint_now();
|
||||
ASSERT_FALSE(wsfs_timepoint_is_elapsed(now + 500));
|
||||
now =wsfs_impl_timepoint_now();
|
||||
ASSERT_FALSE(wsfs_impl_timepoint_is_elapsed(now + 500));
|
||||
}
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
#include <cstddef>
|
||||
|
||||
#include "msleep.hpp"
|
||||
#include "wsfs/adapter/time/timer.h"
|
||||
#include "wsfs/adapter/time/timeout_manager.h"
|
||||
#include "wsfs/adapter/impl/time/timer.h"
|
||||
#include "wsfs/adapter/impl/time/timeout_manager.h"
|
||||
|
||||
using std::size_t;
|
||||
using wsfs_test::msleep;
|
||||
|
||||
namespace
|
||||
{
|
||||
void on_timeout(struct wsfs_timer * timer)
|
||||
void on_timeout(struct wsfs_impl_timer * timer)
|
||||
{
|
||||
bool * triggered = reinterpret_cast<bool*>(timer->user_data);
|
||||
*triggered = true;
|
||||
@@ -20,82 +20,82 @@ namespace
|
||||
|
||||
TEST(timer, init)
|
||||
{
|
||||
struct wsfs_timeout_manager manager;
|
||||
struct wsfs_timer timer;
|
||||
struct wsfs_impl_timeout_manager manager;
|
||||
struct wsfs_impl_timer timer;
|
||||
|
||||
wsfs_timeout_manager_init(&manager);
|
||||
wsfs_timer_init(&timer, &manager);
|
||||
wsfs_impl_timeout_manager_init(&manager);
|
||||
wsfs_impl_timer_init(&timer, &manager);
|
||||
|
||||
wsfs_timer_cleanup(&timer);
|
||||
wsfs_timeout_manager_cleanup(&manager);
|
||||
wsfs_impl_timer_cleanup(&timer);
|
||||
wsfs_impl_timeout_manager_cleanup(&manager);
|
||||
}
|
||||
|
||||
TEST(timer, trigger)
|
||||
{
|
||||
struct wsfs_timeout_manager manager;
|
||||
struct wsfs_timer timer;
|
||||
struct wsfs_impl_timeout_manager manager;
|
||||
struct wsfs_impl_timer timer;
|
||||
|
||||
wsfs_timeout_manager_init(&manager);
|
||||
wsfs_timer_init(&timer, &manager);
|
||||
wsfs_impl_timeout_manager_init(&manager);
|
||||
wsfs_impl_timer_init(&timer, &manager);
|
||||
|
||||
bool triggered = false;
|
||||
wsfs_timer_start(&timer, wsfs_timepoint_in_msec(250), &on_timeout, reinterpret_cast<void*>(&triggered));
|
||||
wsfs_impl_timer_start(&timer, wsfs_impl_timepoint_in_msec(250), &on_timeout, reinterpret_cast<void*>(&triggered));
|
||||
msleep(500);
|
||||
wsfs_timeout_manager_check(&manager);
|
||||
wsfs_impl_timeout_manager_check(&manager);
|
||||
|
||||
ASSERT_TRUE(triggered);
|
||||
|
||||
wsfs_timer_cleanup(&timer);
|
||||
wsfs_timeout_manager_cleanup(&manager);
|
||||
wsfs_impl_timer_cleanup(&timer);
|
||||
wsfs_impl_timeout_manager_cleanup(&manager);
|
||||
}
|
||||
|
||||
TEST(timer, cancel)
|
||||
{
|
||||
struct wsfs_timeout_manager manager;
|
||||
struct wsfs_timer timer;
|
||||
struct wsfs_impl_timeout_manager manager;
|
||||
struct wsfs_impl_timer timer;
|
||||
|
||||
wsfs_timeout_manager_init(&manager);
|
||||
wsfs_timer_init(&timer, &manager);
|
||||
wsfs_impl_timeout_manager_init(&manager);
|
||||
wsfs_impl_timer_init(&timer, &manager);
|
||||
|
||||
bool triggered = false;
|
||||
wsfs_timer_start(&timer, wsfs_timepoint_in_msec(250), &on_timeout, &triggered);
|
||||
wsfs_impl_timer_start(&timer, wsfs_impl_timepoint_in_msec(250), &on_timeout, &triggered);
|
||||
msleep(500);
|
||||
wsfs_timer_cancel(&timer);
|
||||
wsfs_timeout_manager_check(&manager);
|
||||
wsfs_impl_timer_cancel(&timer);
|
||||
wsfs_impl_timeout_manager_check(&manager);
|
||||
|
||||
ASSERT_FALSE(triggered);
|
||||
|
||||
wsfs_timer_cleanup(&timer);
|
||||
wsfs_timeout_manager_cleanup(&manager);
|
||||
wsfs_impl_timer_cleanup(&timer);
|
||||
wsfs_impl_timeout_manager_cleanup(&manager);
|
||||
}
|
||||
|
||||
TEST(timer, multiple_timers)
|
||||
{
|
||||
static size_t const count = 5;
|
||||
struct wsfs_timeout_manager manager;
|
||||
struct wsfs_timer timer[count];
|
||||
struct wsfs_impl_timeout_manager manager;
|
||||
struct wsfs_impl_timer timer[count];
|
||||
bool triggered[count];
|
||||
|
||||
wsfs_timeout_manager_init(&manager);
|
||||
wsfs_impl_timeout_manager_init(&manager);
|
||||
|
||||
for(size_t i = 0; i < count; i++)
|
||||
{
|
||||
wsfs_timer_init(&timer[i], &manager);
|
||||
wsfs_impl_timer_init(&timer[i], &manager);
|
||||
triggered[i] = false;
|
||||
wsfs_timer_start(&timer[i], wsfs_timepoint_in_msec(300 - (50 * i)), &on_timeout, &triggered[i]);
|
||||
wsfs_impl_timer_start(&timer[i], wsfs_impl_timepoint_in_msec(300 - (50 * i)), &on_timeout, &triggered[i]);
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < count; i++)
|
||||
{
|
||||
msleep(100);
|
||||
wsfs_timeout_manager_check(&manager);
|
||||
wsfs_impl_timeout_manager_check(&manager);
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < count; i++)
|
||||
{
|
||||
ASSERT_TRUE(triggered[i]);
|
||||
wsfs_timer_cleanup(&timer[i]);
|
||||
wsfs_impl_timer_cleanup(&timer[i]);
|
||||
}
|
||||
|
||||
wsfs_timeout_manager_cleanup(&manager);
|
||||
wsfs_impl_timeout_manager_cleanup(&manager);
|
||||
}
|
||||
|
||||
@@ -1,69 +1,69 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wsfs/provider/url.h"
|
||||
#include "wsfs/provider/impl/url.h"
|
||||
|
||||
TEST(url, ParseWs)
|
||||
{
|
||||
struct wsfsp_url url;
|
||||
bool result = wsfsp_url_init(&url, "ws://localhost/");
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "ws://localhost/");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_EQ(80, url.port);
|
||||
ASSERT_FALSE(url.use_tls);
|
||||
ASSERT_STREQ("localhost", url.host);
|
||||
ASSERT_STREQ("/", url.path);
|
||||
|
||||
wsfsp_url_cleanup(&url);
|
||||
wsfsp_impl_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, ParswWss)
|
||||
{
|
||||
struct wsfsp_url url;
|
||||
bool result = wsfsp_url_init(&url, "wss://localhost/");
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "wss://localhost/");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_EQ(443, url.port);
|
||||
ASSERT_TRUE(url.use_tls);
|
||||
ASSERT_STREQ("localhost", url.host);
|
||||
ASSERT_STREQ("/", url.path);
|
||||
|
||||
wsfsp_url_cleanup(&url);
|
||||
wsfsp_impl_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, ParseIPAdress)
|
||||
{
|
||||
struct wsfsp_url url;
|
||||
bool result = wsfsp_url_init(&url, "ws://127.0.0.1/");
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "ws://127.0.0.1/");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_EQ(80, url.port);
|
||||
ASSERT_STREQ("127.0.0.1", url.host);
|
||||
ASSERT_STREQ("/", url.path);
|
||||
|
||||
wsfsp_url_cleanup(&url);
|
||||
wsfsp_impl_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, ParsePort)
|
||||
{
|
||||
struct wsfsp_url url;
|
||||
bool result = wsfsp_url_init(&url, "ws://localhost:54321/");
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "ws://localhost:54321/");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_EQ(54321, url.port);
|
||||
|
||||
wsfsp_url_cleanup(&url);
|
||||
wsfsp_impl_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, ParseNonEmptyPath)
|
||||
{
|
||||
struct wsfsp_url url;
|
||||
bool result = wsfsp_url_init(&url, "ws://localhost/some_path?query");
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "ws://localhost/some_path?query");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_STREQ("/some_path?query", url.path);
|
||||
|
||||
wsfsp_url_cleanup(&url);
|
||||
wsfsp_impl_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, FailToParseUnknownProtocol)
|
||||
{
|
||||
struct wsfsp_url url;
|
||||
bool result = wsfsp_url_init(&url, "unknown://localhost/");
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "unknown://localhost/");
|
||||
ASSERT_FALSE(result);
|
||||
ASSERT_EQ(0, url.port);
|
||||
ASSERT_EQ(nullptr, url.path);
|
||||
@@ -72,8 +72,8 @@ TEST(url, FailToParseUnknownProtocol)
|
||||
|
||||
TEST(url, FailToParseMissingProtocol)
|
||||
{
|
||||
struct wsfsp_url url;
|
||||
bool result = wsfsp_url_init(&url, "unknown");
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "unknown");
|
||||
ASSERT_FALSE(result);
|
||||
ASSERT_EQ(0, url.port);
|
||||
ASSERT_EQ(nullptr, url.path);
|
||||
@@ -82,8 +82,8 @@ TEST(url, FailToParseMissingProtocol)
|
||||
|
||||
TEST(url, FailToParseMissingPath)
|
||||
{
|
||||
struct wsfsp_url url;
|
||||
bool result = wsfsp_url_init(&url, "ws://localhost");
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "ws://localhost");
|
||||
ASSERT_FALSE(result);
|
||||
ASSERT_EQ(0, url.port);
|
||||
ASSERT_EQ(nullptr, url.path);
|
||||
|
||||
Reference in New Issue
Block a user