From aa41fb3a6eea19d67cb05ee40dfd75ca933900b2 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Wed, 30 Jan 2019 22:28:50 +0100 Subject: [PATCH] made headers C++ compatible ; added basic server test --- CMakeLists.txt | 1 + src/wsfs/fuse_wrapper.h | 8 ++++++++ src/wsfs/jsonrpc.h | 15 +++++++++++++++ src/wsfs/operations.h | 8 ++++++++ src/wsfs/protocol.h | 11 +++++++++++ src/wsfs/response_parser.h | 14 ++++++++++++++ src/wsfs/server.h | 13 +++++++++++++ src/wsfs/status.h | 8 ++++++++ test-src/test_server.cc | 11 +++++++++++ 9 files changed, 89 insertions(+) create mode 100644 test-src/test_server.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 78c7082..73e8550 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,7 @@ pkg_check_modules(GTEST gtest_main) add_executable(alltests test-src/test_response_parser.cc + test-src/test_server.cc ) target_link_libraries(alltests PUBLIC fuse-wsfs ${EXTRA_LIBS} ${GTEST_LIBRARIES}) diff --git a/src/wsfs/fuse_wrapper.h b/src/wsfs/fuse_wrapper.h index 3a12825..006ef6d 100644 --- a/src/wsfs/fuse_wrapper.h +++ b/src/wsfs/fuse_wrapper.h @@ -1,8 +1,16 @@ #ifndef _WSFS_FUSE_H #define _WSFS_FUSE_H +#ifdef __cplusplus +extern "C" { +#endif + #define FUSE_USE_VERSION 31 #include +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/wsfs/jsonrpc.h b/src/wsfs/jsonrpc.h index 52e8b83..9299236 100644 --- a/src/wsfs/jsonrpc.h +++ b/src/wsfs/jsonrpc.h @@ -1,9 +1,16 @@ #ifndef _WSFS_JSONRPC_H #define _WSFS_JSONRPC_H +#ifndef __cplusplus #include #include #include +#else +#include +#include +using std::size_t; +#endif + #include #include "wsfs/status.h" @@ -12,6 +19,10 @@ struct wsfs_jsonrpc; typedef char * wsfs_create_message_fn(size_t size); 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( wsfs_create_message_fn * create_message, wsfs_send_message_fn * send_message, @@ -37,5 +48,9 @@ extern void wsfs_jsonrpc_on_message( size_t length, void * user_data); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/wsfs/operations.h b/src/wsfs/operations.h index a47adb1..84080ed 100644 --- a/src/wsfs/operations.h +++ b/src/wsfs/operations.h @@ -3,6 +3,10 @@ #include "wsfs/fuse_wrapper.h" +#ifdef __cplusplus +extern "C" { +#endif + extern void wsfs_operations_init( struct fuse_operations * operations); @@ -33,6 +37,10 @@ extern int wsfs_operation_read( size_t buffer_size, off_t offset, struct fuse_file_info * file_info); + +#ifdef __cplusplus +} +#endif #endif diff --git a/src/wsfs/protocol.h b/src/wsfs/protocol.h index 232dadd..a049696 100644 --- a/src/wsfs/protocol.h +++ b/src/wsfs/protocol.h @@ -1,13 +1,20 @@ #ifndef _WSFS_PROTOCOL_H #define _WSFS_PROTOCOL_H +#ifndef __cplusplus #include +#endif + #include #include struct wsfs_protocol; struct wsfs_server; +#ifdef __cplusplus +extern "C" { +#endif + extern struct wsfs_protocol * wsfs_protocol_create( struct wsfs_server * server); @@ -32,6 +39,10 @@ extern bool wsfs_protocol_send( size_t length, void * user_data); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/wsfs/response_parser.h b/src/wsfs/response_parser.h index b976621..6dc2dca 100644 --- a/src/wsfs/response_parser.h +++ b/src/wsfs/response_parser.h @@ -1,7 +1,13 @@ #ifndef _WSFS_RESPONSE_PARSER_H #define _WFSF_RESPONSE_PARSER_H +#ifndef __cplusplus #include +#else +#include +using std::size_t; +#endif + #include #include "wsfs/status.h" @@ -12,10 +18,18 @@ struct wsfs_response json_t * result; }; +#ifdef __cplusplus +extern "C" { +#endif + extern void wsfs_response_parse( char const * buffer, size_t buffer_length, struct wsfs_response * response); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/wsfs/server.h b/src/wsfs/server.h index 9b5762c..c3671cb 100644 --- a/src/wsfs/server.h +++ b/src/wsfs/server.h @@ -1,7 +1,12 @@ #ifndef _WSFS_SERVER_H #define _WSFS_SERVER_H +#ifndef __cplusplus #include +#else +#include +using std::size_t; +#endif struct wsfs_server; struct wsfs_jsonrpc; @@ -15,6 +20,10 @@ struct wsfs_server_config int port; }; +#ifdef __cplusplus +extern "C" { +#endif + extern void wsfs_server_config_clear( struct wsfs_server_config * config); @@ -38,5 +47,9 @@ extern void wsfs_server_handle_message( char const * message, size_t length); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/wsfs/status.h b/src/wsfs/status.h index f44afb4..50d2587 100644 --- a/src/wsfs/status.h +++ b/src/wsfs/status.h @@ -13,7 +13,15 @@ typedef int wsfs_status; +#ifdef __cplusplus +extern "C" { +#endif + extern int wsfs_status_to_rc(wsfs_status status); +#ifdef __cplusplus +} +#endif + #endif diff --git a/test-src/test_server.cc b/test-src/test_server.cc new file mode 100644 index 0000000..62af241 --- /dev/null +++ b/test-src/test_server.cc @@ -0,0 +1,11 @@ +#include +#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); +} \ No newline at end of file