mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
project structure changed
This commit is contained in:
7
test/test_fuse_req.cc
Normal file
7
test/test_fuse_req.cc
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "wsfs/fuse_wrapper.h"
|
||||
|
||||
TEST(libfuse, fuse_req_t_size)
|
||||
{
|
||||
ASSERT_EQ(sizeof(void*), sizeof(fuse_req_t));
|
||||
}
|
||||
63
test/test_response_parser.cc
Normal file
63
test/test_response_parser.cc
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <cstring>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
extern "C" {
|
||||
#include "wsfs/jsonrpc/response.h"
|
||||
}
|
||||
|
||||
static void wsfs_response_parse_str(
|
||||
char const * buffer,
|
||||
struct wsfs_jsonrpc_response * response)
|
||||
{
|
||||
size_t length = strlen(buffer);
|
||||
wsfs_jsonrpc_response_init(response, buffer, length);
|
||||
}
|
||||
|
||||
TEST(response_parser, test)
|
||||
{
|
||||
struct wsfs_jsonrpc_response response;
|
||||
|
||||
// invalid json
|
||||
wsfs_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);
|
||||
ASSERT_NE(WSFS_GOOD, response.status);
|
||||
ASSERT_EQ(-1, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
// no object
|
||||
wsfs_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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
ASSERT_EQ(WSFS_GOOD, response.status);
|
||||
ASSERT_EQ(42, response.id);
|
||||
ASSERT_NE(nullptr, response.result);
|
||||
json_decref(response.result);
|
||||
}
|
||||
24
test/test_server.cc
Normal file
24
test/test_server.cc
Normal file
@@ -0,0 +1,24 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "wsfs/server.h"
|
||||
#include "wsfs/server_config.h"
|
||||
|
||||
|
||||
TEST(server, create_dispose)
|
||||
{
|
||||
mkdir("test", 0700);
|
||||
|
||||
struct wsfs_server_config config = {strdup("test"), nullptr, nullptr, nullptr, nullptr, 0};
|
||||
struct wsfs_server * server = wsfs_server_create(&config);
|
||||
ASSERT_NE(nullptr, server);
|
||||
|
||||
wsfs_server_dispose(server);
|
||||
wsfs_server_config_cleanup(&config);
|
||||
|
||||
rmdir("test");
|
||||
}
|
||||
34
test/test_timepoint.cc
Normal file
34
test/test_timepoint.cc
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <unistd.h>
|
||||
#include "wsfs/time/timepoint.h"
|
||||
|
||||
|
||||
TEST(timepoint, now)
|
||||
{
|
||||
wsfs_timepoint start = wsfs_timepoint_now();
|
||||
usleep(42 * 1000);
|
||||
wsfs_timepoint end = wsfs_timepoint_now();
|
||||
|
||||
ASSERT_LT(start, end);
|
||||
ASSERT_LT(end, start + 500);
|
||||
}
|
||||
|
||||
TEST(timepoint, in_msec)
|
||||
{
|
||||
wsfs_timepoint now = wsfs_timepoint_now();
|
||||
wsfs_timepoint later = wsfs_timepoint_in_msec(42);
|
||||
|
||||
ASSERT_LT(now, later);
|
||||
ASSERT_LT(later, now + 500);
|
||||
}
|
||||
|
||||
TEST(timepoint, elapsed)
|
||||
{
|
||||
wsfs_timepoint now;
|
||||
|
||||
now = wsfs_timepoint_now();
|
||||
ASSERT_TRUE(wsfs_timepoint_is_elapsed(now - 1));
|
||||
|
||||
now = wsfs_timepoint_now();
|
||||
ASSERT_FALSE(wsfs_timepoint_is_elapsed(now + 500));
|
||||
}
|
||||
100
test/test_timer.cc
Normal file
100
test/test_timer.cc
Normal file
@@ -0,0 +1,100 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "wsfs/time/timer.h"
|
||||
#include "wsfs/time/timeout_manager.h"
|
||||
|
||||
using std::size_t;
|
||||
|
||||
namespace
|
||||
{
|
||||
void on_timeout(struct wsfs_timer * timer)
|
||||
{
|
||||
bool * triggered = reinterpret_cast<bool*>(timer->user_data);
|
||||
*triggered = true;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(timer, init)
|
||||
{
|
||||
struct wsfs_timeout_manager manager;
|
||||
struct wsfs_timer timer;
|
||||
|
||||
wsfs_timeout_manager_init(&manager);
|
||||
wsfs_timer_init(&timer, &manager);
|
||||
|
||||
wsfs_timer_cleanup(&timer);
|
||||
wsfs_timeout_manager_cleanup(&manager);
|
||||
}
|
||||
|
||||
TEST(timer, trigger)
|
||||
{
|
||||
struct wsfs_timeout_manager manager;
|
||||
struct wsfs_timer timer;
|
||||
|
||||
wsfs_timeout_manager_init(&manager);
|
||||
wsfs_timer_init(&timer, &manager);
|
||||
|
||||
bool triggered = false;
|
||||
wsfs_timer_start(&timer, wsfs_timepoint_in_msec(250), &on_timeout, reinterpret_cast<void*>(&triggered));
|
||||
usleep(500 * 1000);
|
||||
wsfs_timeout_manager_check(&manager);
|
||||
|
||||
ASSERT_TRUE(triggered);
|
||||
|
||||
wsfs_timer_cleanup(&timer);
|
||||
wsfs_timeout_manager_cleanup(&manager);
|
||||
}
|
||||
|
||||
TEST(timer, cancel)
|
||||
{
|
||||
struct wsfs_timeout_manager manager;
|
||||
struct wsfs_timer timer;
|
||||
|
||||
wsfs_timeout_manager_init(&manager);
|
||||
wsfs_timer_init(&timer, &manager);
|
||||
|
||||
bool triggered = false;
|
||||
wsfs_timer_start(&timer, wsfs_timepoint_in_msec(250), &on_timeout, &triggered);
|
||||
usleep(500 * 1000);
|
||||
wsfs_timer_cancel(&timer);
|
||||
wsfs_timeout_manager_check(&manager);
|
||||
|
||||
ASSERT_FALSE(triggered);
|
||||
|
||||
wsfs_timer_cleanup(&timer);
|
||||
wsfs_timeout_manager_cleanup(&manager);
|
||||
}
|
||||
|
||||
TEST(timer, multiple_timers)
|
||||
{
|
||||
static size_t const count = 5;
|
||||
struct wsfs_timeout_manager manager;
|
||||
struct wsfs_timer timer[count];
|
||||
bool triggered[count];
|
||||
|
||||
wsfs_timeout_manager_init(&manager);
|
||||
|
||||
for(size_t i = 0; i < count; i++)
|
||||
{
|
||||
wsfs_timer_init(&timer[i], &manager);
|
||||
triggered[i] = false;
|
||||
wsfs_timer_start(&timer[i], wsfs_timepoint_in_msec(300 - (50 * i)), &on_timeout, &triggered[i]);
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < count; i++)
|
||||
{
|
||||
usleep(100 * 1000);
|
||||
wsfs_timeout_manager_check(&manager);
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < count; i++)
|
||||
{
|
||||
ASSERT_TRUE(triggered[i]);
|
||||
wsfs_timer_cleanup(&timer[i]);
|
||||
}
|
||||
|
||||
wsfs_timeout_manager_cleanup(&manager);
|
||||
}
|
||||
Reference in New Issue
Block a user