1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00

made headers C++ compatible ; added basic server test

This commit is contained in:
Falk Werner 2019-01-30 22:28:50 +01:00
parent 7f8365811f
commit aa41fb3a6e
9 changed files with 89 additions and 0 deletions

View File

@ -72,6 +72,7 @@ pkg_check_modules(GTEST gtest_main)
add_executable(alltests add_executable(alltests
test-src/test_response_parser.cc test-src/test_response_parser.cc
test-src/test_server.cc
) )
target_link_libraries(alltests PUBLIC fuse-wsfs ${EXTRA_LIBS} ${GTEST_LIBRARIES}) target_link_libraries(alltests PUBLIC fuse-wsfs ${EXTRA_LIBS} ${GTEST_LIBRARIES})

View File

@ -1,8 +1,16 @@
#ifndef _WSFS_FUSE_H #ifndef _WSFS_FUSE_H
#define _WSFS_FUSE_H #define _WSFS_FUSE_H
#ifdef __cplusplus
extern "C" {
#endif
#define FUSE_USE_VERSION 31 #define FUSE_USE_VERSION 31
#include <fuse.h> #include <fuse.h>
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -1,9 +1,16 @@
#ifndef _WSFS_JSONRPC_H #ifndef _WSFS_JSONRPC_H
#define _WSFS_JSONRPC_H #define _WSFS_JSONRPC_H
#ifndef __cplusplus
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h> #include <stddef.h>
#include <stdbool.h> #include <stdbool.h>
#else
#include <cstdarg>
#include <cstddef>
using std::size_t;
#endif
#include <jansson.h> #include <jansson.h>
#include "wsfs/status.h" #include "wsfs/status.h"
@ -12,6 +19,10 @@ struct wsfs_jsonrpc;
typedef char * wsfs_create_message_fn(size_t size); typedef char * wsfs_create_message_fn(size_t size);
typedef bool wsfs_send_message_fn(char * message, size_t length, void * user_data); typedef bool wsfs_send_message_fn(char * message, size_t length, void * user_data);
#ifdef __cplusplus
extern "C" {
#endif
extern struct wsfs_jsonrpc * wsfs_jsonrpc_create( extern struct wsfs_jsonrpc * wsfs_jsonrpc_create(
wsfs_create_message_fn * create_message, wsfs_create_message_fn * create_message,
wsfs_send_message_fn * send_message, wsfs_send_message_fn * send_message,
@ -37,5 +48,9 @@ extern void wsfs_jsonrpc_on_message(
size_t length, size_t length,
void * user_data); void * user_data);
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -3,6 +3,10 @@
#include "wsfs/fuse_wrapper.h" #include "wsfs/fuse_wrapper.h"
#ifdef __cplusplus
extern "C" {
#endif
extern void wsfs_operations_init( extern void wsfs_operations_init(
struct fuse_operations * operations); struct fuse_operations * operations);
@ -34,5 +38,9 @@ extern int wsfs_operation_read(
off_t offset, off_t offset,
struct fuse_file_info * file_info); struct fuse_file_info * file_info);
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -1,13 +1,20 @@
#ifndef _WSFS_PROTOCOL_H #ifndef _WSFS_PROTOCOL_H
#define _WSFS_PROTOCOL_H #define _WSFS_PROTOCOL_H
#ifndef __cplusplus
#include <stdbool.h> #include <stdbool.h>
#endif
#include <libwebsockets.h> #include <libwebsockets.h>
#include <pthread.h> #include <pthread.h>
struct wsfs_protocol; struct wsfs_protocol;
struct wsfs_server; struct wsfs_server;
#ifdef __cplusplus
extern "C" {
#endif
extern struct wsfs_protocol * wsfs_protocol_create( extern struct wsfs_protocol * wsfs_protocol_create(
struct wsfs_server * server); struct wsfs_server * server);
@ -32,6 +39,10 @@ extern bool wsfs_protocol_send(
size_t length, size_t length,
void * user_data); void * user_data);
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -1,7 +1,13 @@
#ifndef _WSFS_RESPONSE_PARSER_H #ifndef _WSFS_RESPONSE_PARSER_H
#define _WFSF_RESPONSE_PARSER_H #define _WFSF_RESPONSE_PARSER_H
#ifndef __cplusplus
#include <stddef.h> #include <stddef.h>
#else
#include <cstddef>
using std::size_t;
#endif
#include <jansson.h> #include <jansson.h>
#include "wsfs/status.h" #include "wsfs/status.h"
@ -12,10 +18,18 @@ struct wsfs_response
json_t * result; json_t * result;
}; };
#ifdef __cplusplus
extern "C" {
#endif
extern void wsfs_response_parse( extern void wsfs_response_parse(
char const * buffer, char const * buffer,
size_t buffer_length, size_t buffer_length,
struct wsfs_response * response); struct wsfs_response * response);
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -1,7 +1,12 @@
#ifndef _WSFS_SERVER_H #ifndef _WSFS_SERVER_H
#define _WSFS_SERVER_H #define _WSFS_SERVER_H
#ifndef __cplusplus
#include <stddef.h> #include <stddef.h>
#else
#include <cstddef>
using std::size_t;
#endif
struct wsfs_server; struct wsfs_server;
struct wsfs_jsonrpc; struct wsfs_jsonrpc;
@ -15,6 +20,10 @@ struct wsfs_server_config
int port; int port;
}; };
#ifdef __cplusplus
extern "C" {
#endif
extern void wsfs_server_config_clear( extern void wsfs_server_config_clear(
struct wsfs_server_config * config); struct wsfs_server_config * config);
@ -38,5 +47,9 @@ extern void wsfs_server_handle_message(
char const * message, char const * message,
size_t length); size_t length);
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -13,7 +13,15 @@
typedef int wsfs_status; typedef int wsfs_status;
#ifdef __cplusplus
extern "C" {
#endif
extern int wsfs_status_to_rc(wsfs_status status); extern int wsfs_status_to_rc(wsfs_status status);
#ifdef __cplusplus
}
#endif
#endif #endif

11
test-src/test_server.cc Normal file
View File

@ -0,0 +1,11 @@
#include <gtest/gtest.h>
#include "wsfs/server.h"
TEST(server, create_dispose)
{
wsfs_server_config config = {nullptr, nullptr, nullptr, nullptr, 0};
wsfs_server * server = wsfs_server_create(&config);
ASSERT_NE(nullptr, server);
wsfs_server_dispose(server);
}