Enable build flags and fix compilation warnings (gcc 14.1.0) (#66)

* Fix rpc build with other examples

CPP_COMPILE is an option, a cache variable, thus regular unset() is not
working for it since it tries to unset the scope variable.

This causing cmake to skip compilation of rpc.
Unset CPP_COMPILE from CACHE to make it work as intended.

* Fix compiler flags with build targets

Currently tests, soak and examples are build without extra flags,
because add_compile_options is specified after defining build targets.

From add_compile_options() docs:
Adds options to the compiler command line for targets in the current
directory and below that are added *after* this command is invoked.

* Pass debug callbacks as struct

Fixes:
warning: ISO C forbids conversion of function pointer to object pointer
type

* Move global variables under NBNET_IMPL

Nb net could be included multiple times, to prevent creation of global
variables in each file move them under NBNET_IMPL.

Also use designated initializer to initiate a driver structure to
remove warnings about partial initialization. Designated initializer
would initialize other members to zero.

* Resolve unused variables warnings.

Cast unused function arguments to (void) to suspend warnings.

* Resolve signed vs unsigned warnings

Remove unnecessary lt 0 checks and sync types to remove signed vs
unsigned warnings.

* Resolve string related warnings

Fixes:
nbnet/tests/string_tests.c:18:9: error: ‘strncpy’
output truncated before terminating nul copying 5 bytes from a string of
the same length
[-Werror=stringop-truncation]
   18 |         strncpy(res + pos, b, len_b);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

nbnet/tests/string_tests.c:24:9: error: ‘strncpy’
specified bound depends on the length of the source argument
[-Werror=stringop-truncation]

* Resolve function defined but not used warnings

Mark GameServer_GetClientCount() as inline.

* Attempt to fix warning in ASSERT_VALUE_IN_RANGE

In case when value in unsigned type and min is 0, this commit just
obfuscates types, maybe there's better solution.

Fixes:
warning: comparison of unsigned expression in ‘>= 0’ is always true
[-Wtype-limits]

* Ensure that read len is less than word size

In release mode(-DCMAKE_BUILD_TYPE=Release) tests returning following
error:
nbnet/tests/../nbnet.h:2272:9: error: ‘memcpy’ forming offset [4, 7] is
out of the bound s [0, 4] of object ‘word’ with type ‘Word’ {aka
‘unsigned int’} [-Werror=array-bounds=]
 2272 |         memcpy(bytes, &word, length); |
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

Add check to verify that length is less than Word size.

* add -Wno-unknown-pragmas flag

* fix examples compilation on windows

* fix examples compilation on windows

* fix examples compilation on windows

* fix unit tests compilation on windows

* fix soak test compilation on windows

* fix unit tests compilation on windows

* fix unit tests compilation on windows

---------

Co-authored-by: BIAGINI Nathan <nath.biagini@gmail.com>
This commit is contained in:
Volodymyr FialkoandBIAGINI Nathan authored and GitHub committed 2024-08-10 12:02:42 +02:00
1 parent c5d34df9fd
commit 15d823dab6
17 files changed
+115 -75

No files matched your search

+1 -1
View File
@@ -7,4 +7,4 @@ add_subdirectory(echo_bytes)
if (NOT DEFINED CPP_COMPILE)
# not supported in CPP
add_subdirectory(rpc)
endif (CPP_COMPILE)
endif (NOT DEFINED CPP_COMPILE)
+7 -3
View File
@@ -13,13 +13,17 @@ if (CPP_COMPILE)
set (CMAKE_CXX_STANDARD 20)
endif (CPP_COMPILE)
unset(CPP_COMPILE)
unset(CPP_COMPILE CACHE)
add_compile_options(-Wall)
if(CMAKE_COMPILER_IS_GNUCXX)
add_compile_options(-Wextra -Wpedantic)
endif (CMAKE_COMPILER_IS_GNUCXX)
add_executable(echo_client client.c shared.c)
add_executable(echo_server server.c shared.c)
add_compile_options(-Wall -Wextra -Wpedantic)
if (ENABLE_TLS)
message("Compile with TLS enabled")
target_compile_definitions(echo_server PUBLIC NBN_TLS)
+2
View File
@@ -125,6 +125,8 @@ int main(int argc, const char **argv)
#endif
}
(void) argc;
(void) argv;
// Registering messages, have to be done after NBN_GameServer_StartEx
NBN_GameServer_RegisterMessage(ECHO_MESSAGE_TYPE,
(NBN_MessageBuilder)EchoMessage_Create,
+7 -3
View File
@@ -11,13 +11,17 @@ if (CPP_COMPILE)
set (CMAKE_CXX_STANDARD 20)
endif (CPP_COMPILE)
unset(CPP_COMPILE)
unset(CPP_COMPILE CACHE)
add_compile_options(-Wall)
if(CMAKE_COMPILER_IS_GNUCXX)
add_compile_options(-Wextra -Wpedantic)
endif (CMAKE_COMPILER_IS_GNUCXX)
add_executable(echo_bytes_client client.c shared.c)
add_executable(echo_bytes_server server.c shared.c)
add_compile_options(-Wall -Wextra -Wpedantic)
target_compile_definitions(echo_bytes_client PUBLIC NBN_DEBUG)
target_compile_definitions(echo_bytes_server PUBLIC NBN_DEBUG)
+5 -1
View File
@@ -7,7 +7,11 @@ set(raylib_DIR cmake)
set(CLIENT_SOURCES client.c shared.c)
set(SERVER_SOURCES server.c shared.c)
add_compile_options(-Wall -Wextra -Wpedantic -Wno-unknown-pragmas -Wno-type-limits -std=c99)
add_compile_options(-Wall -Wno-unknown-pragmas -Wno-type-limits -std=c99)
if(CMAKE_COMPILER_IS_GNUCXX)
add_compile_options(-Wextra -Wpedantic)
endif (CMAKE_COMPILER_IS_GNUCXX)
add_executable(raylib_client ${CLIENT_SOURCES})
add_executable(raylib_server ${SERVER_SOURCES})
+7 -3
View File
@@ -11,13 +11,17 @@ if (CPP_COMPILE)
set (CMAKE_CXX_STANDARD 20)
endif (CPP_COMPILE)
unset(CPP_COMPILE)
unset(CPP_COMPILE CACHE)
add_compile_options(-Wall)
if(CMAKE_COMPILER_IS_GNUCXX)
add_compile_options(-Wextra -Wpedantic)
endif (CMAKE_COMPILER_IS_GNUCXX)
add_executable(rpc_client client.c shared.c)
add_executable(rpc_server server.c shared.c)
add_compile_options(-Wall -Wextra -Wpedantic)
target_compile_definitions(rpc_client PUBLIC NBN_DEBUG)
target_compile_definitions(rpc_server PUBLIC NBN_DEBUG)
+7 -3
View File
@@ -35,6 +35,8 @@ static bool disconnected = false;
static void TestRPC2(unsigned int param_count, NBN_RPC_Param params[NBN_RPC_MAX_PARAM_COUNT], NBN_ConnectionHandle sender)
{
(void) sender;
TEST_VERIFY(param_count == 2);
Log(LOG_INFO, "TestRPC2 called !");
Log(LOG_INFO, "Parameter 1 (float): %f", NBN_RPC_GetFloat(params, 0));
Log(LOG_INFO, "Parameter 2 (string): %s", NBN_RPC_GetString(params, 1));
@@ -48,7 +50,7 @@ void OnConnected(void)
int ret = NBN_GameClient_CallRPC(TEST_RPC_ID, 4242, -1234.5678f, true);
assert(ret == 0);
TEST_VERIFY(ret == 0);
}
void OnDisconnected(void)
@@ -62,6 +64,8 @@ void OnDisconnected(void)
int main(int argc, char *argv[])
{
(void) argc;
(void) argv;
#ifdef __EMSCRIPTEN__
NBN_WebRTC_Register(); // Register the WebRTC driver
#else
@@ -84,11 +88,11 @@ int main(int argc, char *argv[])
int ret = NBN_GameClient_RegisterRPC(TEST_RPC_ID, TEST_RPC_SIGNATURE, NULL);
assert(ret == 0);
TEST_VERIFY(ret == 0);
ret = NBN_GameClient_RegisterRPC(TEST_RPC_2_ID, TEST_RPC_2_SIGNATURE, TestRPC2);
assert(ret == 0);
TEST_VERIFY(ret == 0);
// Number of seconds between client ticks
double dt = 1.0 / RPC_TICK_RATE;
+1 -2
View File
@@ -29,12 +29,11 @@
#include "shared.h"
static NBN_Connection *client = NULL;
static bool error = false;
static void TestRPC(unsigned int param_count, NBN_RPC_Param params[NBN_RPC_MAX_PARAM_COUNT], NBN_ConnectionHandle sender)
{
TEST_VERIFY(param_count == 3);
Log(LOG_INFO, "TestRPC called ! (Sender: %d)", sender);
Log(LOG_INFO, "Parameter 1 (int): %d", NBN_RPC_GetInt(params, 0));
Log(LOG_INFO, "Parameter 2 (float): %f", NBN_RPC_GetFloat(params, 1));
+3
View File
@@ -23,6 +23,8 @@
#ifndef RPC_EXAMPLE_SHARED_H
#define RPC_EXAMPLE_SHARED_H
#include <stdlib.h>
#if defined(_WIN32) || defined(_WIN64)
/*
@@ -86,6 +88,7 @@ typedef struct tagMSG *LPMSG;
#define TEST_RPC_2_ID 1
#define TEST_RPC_SIGNATURE NBN_RPC_BuildSignature(3, NBN_RPC_PARAM_INT, NBN_RPC_PARAM_FLOAT, NBN_RPC_PARAM_BOOL)
#define TEST_RPC_2_SIGNATURE NBN_RPC_BuildSignature(2, NBN_RPC_PARAM_FLOAT, NBN_RPC_PARAM_STRING)
#define TEST_VERIFY(exp) if(!(exp)) abort()
// nbnet logging
// nbnet does not implement any logging capabilities, you need to provide your own
+37 -48
View File
@@ -154,7 +154,7 @@ typedef uint32_t Word;
#define B_IS_SET(mask, n) ((B_MASK(n) & mask) == B_MASK(n))
#define B_IS_UNSET(mask, n) ((B_MASK(n) & mask) == 0)
#define ASSERT_VALUE_IN_RANGE(v, min, max) assert(v >= min && v <= max)
#define ASSERT_VALUE_IN_RANGE(v, min, max) assert(v >= (int64_t)min && v <= (int64_t)max)
#define ASSERTED_SERIALIZE(stream, v, min, max, func) \
{ \
if (stream->type == NBN_STREAM_WRITE) \
@@ -743,9 +743,8 @@ typedef struct NBN_ConnectionStats
#ifdef NBN_DEBUG
typedef enum NBN_ConnectionDebugCallback
{
NBN_DEBUG_CB_MSG_ADDED_TO_RECV_QUEUE
typedef struct NBN_ConnectionDebugCallback {
void (*OnMessageAddedToRecvQueue)(NBN_Connection *, NBN_Message *);
} NBN_ConnectionDebugCallback;
#endif /* NBN_DEBUG */
@@ -769,8 +768,7 @@ struct NBN_Connection
void *driver_data; /* Data attached to the connection by the underlying driver */
#ifdef NBN_DEBUG
/* Debug callbacks */
void (*OnMessageAddedToRecvQueue)(struct NBN_Connection *, NBN_Message *);
NBN_ConnectionDebugCallback debug_callbacks;
#endif /* NBN_DEBUG */
/*
@@ -941,8 +939,7 @@ struct NBN_Endpoint
double time; /* Current time */
#ifdef NBN_DEBUG
/* Debug callbacks */
void (*OnMessageAddedToRecvQueue)(NBN_Connection *, NBN_Message *);
NBN_ConnectionDebugCallback debug_callbacks;
#endif
#if defined(NBN_DEBUG) && defined(NBN_USE_PACKET_SIMULATOR)
@@ -1177,7 +1174,7 @@ int NBN_GameClient_CallRPC(unsigned int id, ...);
#ifdef NBN_DEBUG
void NBN_GameClient_Debug_RegisterCallback(NBN_ConnectionDebugCallback, void *);
void NBN_GameClient_Debug_RegisterCallback(NBN_ConnectionDebugCallback);
#endif /* NBN_DEBUG */
@@ -1481,7 +1478,7 @@ int NBN_GameServer_CallRPC(unsigned int id, NBN_ConnectionHandle connection_hand
#ifdef NBN_DEBUG
void NBN_GameServer_Debug_RegisterCallback(NBN_ConnectionDebugCallback, void *);
void NBN_GameServer_Debug_RegisterCallback(NBN_ConnectionDebugCallback);
#endif /* NBN_DEBUG */
@@ -1534,18 +1531,6 @@ struct NBN_Driver
NBN_DriverImplementation impl;
};
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
static NBN_Driver nbn_drivers[NBN_MAX_DRIVERS] = {
{-1, NULL},
{-1, NULL},
{-1, NULL},
{-1, NULL}
};
#pragma clang diagnostic pop
static unsigned int nbn_driver_count = 0;
/**
* Register a new network driver, at least one network driver has to be registered.
*
@@ -1596,6 +1581,15 @@ int NBN_Driver_RaiseEvent(NBN_DriverEvent ev, void *data);
#ifdef NBNET_IMPL
static NBN_Driver nbn_drivers[NBN_MAX_DRIVERS] = {
{.id = -1},
{.id = -1},
{.id = -1},
{.id = -1}
};
static unsigned int nbn_driver_count = 0;
#pragma region NBN_ConnectionVector
#define NBN_CONNECTION_VECTOR_INITIAL_CAPACITY 32
@@ -2221,7 +2215,7 @@ int NBN_ReadStream_SerializeBool(NBN_ReadStream *read_stream, bool *value)
if (NBN_BitReader_Read(&read_stream->bit_reader, &v, 1) < 0)
return NBN_ERROR;
if (v < 0 || v > 1)
if (v > 1)
return NBN_ERROR;
*value = v;
@@ -2264,7 +2258,7 @@ int NBN_ReadStream_SerializeBytes(NBN_ReadStream *read_stream, uint8_t *bytes, u
// make sure we are at the start of a new byte after applying padding
assert(bit_reader->scratch_bits_count % 8 == 0);
if (length * 8 <= bit_reader->scratch_bits_count)
if (length * 8 <= bit_reader->scratch_bits_count && length <= sizeof(Word))
{
// the byte array is fully contained inside the read word
@@ -2642,6 +2636,8 @@ int NBN_Packet_WriteMessage(NBN_Packet *packet, NBN_Message *message, NBN_Messag
int NBN_Packet_Seal(NBN_Packet *packet, NBN_Connection *connection)
{
(void) connection;
if (packet->mode != NBN_PACKET_MODE_WRITE)
return NBN_ERROR;
@@ -3014,8 +3010,8 @@ int NBN_Connection_ProcessReceivedPacket(NBN_Connection *connection, NBN_Packet
NBN_LogTrace("Received message %d on channel %d : added to recv queue", message.header.id, channel->id);
#ifdef NBN_DEBUG
if (connection->OnMessageAddedToRecvQueue)
connection->OnMessageAddedToRecvQueue(connection, &message);
if (connection->debug_callbacks.OnMessageAddedToRecvQueue)
connection->debug_callbacks.OnMessageAddedToRecvQueue(connection, &message);
#endif
}
else
@@ -3033,6 +3029,7 @@ int NBN_Connection_EnqueueOutgoingMessage(NBN_Connection *connection, NBN_Channe
{
assert(!connection->is_closed || message->header.type == NBN_CLIENT_CLOSED_MESSAGE_TYPE);
assert(!connection->is_stale);
(void) connection;
NBN_LogTrace("Enqueue message of type %d on channel %d", message->header.type, channel->id);
@@ -3189,6 +3186,8 @@ int NBN_Connection_InitChannel(NBN_Connection *connection, NBN_Channel *channel)
bool NBN_Connection_CheckIfStale(NBN_Connection *connection, double time)
{
#if defined(NBN_DEBUG) && defined(NBN_DISABLE_STALE_CONNECTION_DETECTION)
(void) connection;
(void) time;
/* When testing under bad network conditions (in soak test for instance), we don't want to deal
with stale connections */
return false;
@@ -3575,7 +3574,7 @@ static NBN_RPC_Message *Connection_BuildRPC(NBN_Connection *connection, NBN_RPC
static void Connection_HandleReceivedRPC(NBN_ConnectionHandle connection, NBN_Endpoint *endpoint, NBN_RPC_Message *msg)
{
if (msg->id < 0 || msg->id > NBN_RPC_MAX - 1)
if (msg->id > NBN_RPC_MAX - 1)
{
NBN_LogError("Received an invalid RPC");
@@ -4199,7 +4198,7 @@ static void Endpoint_Init(NBN_Endpoint *endpoint, bool is_server)
endpoint, (NBN_MessageDestructor)NBN_RPC_Message_Destroy, NBN_RPC_MESSAGE_TYPE);
#ifdef NBN_DEBUG
endpoint->OnMessageAddedToRecvQueue = NULL;
memset(&endpoint->debug_callbacks, 0, sizeof(endpoint->debug_callbacks));
#endif
#if defined(NBN_DEBUG) && defined(NBN_USE_PACKET_SIMULATOR)
@@ -4272,7 +4271,7 @@ static NBN_Connection *Endpoint_CreateConnection(NBN_Endpoint *endpoint, uint32_
static int Endpoint_RegisterRPC(NBN_Endpoint *endpoint, unsigned int id, NBN_RPC_Signature signature, NBN_RPC_Func func)
{
if (id < 0 || id >= NBN_RPC_MAX)
if (id >= NBN_RPC_MAX)
{
NBN_LogError("Failed to register RPC, invalid ID");
@@ -4843,7 +4842,7 @@ NBN_Connection *NBN_GameClient_CreateServerConnection(int driver_id, void *drive
NBN_Connection *server_connection = Endpoint_CreateConnection(&nbn_game_client.endpoint, 0, protocol_id, driver_id, driver_data);
#ifdef NBN_DEBUG
server_connection->OnMessageAddedToRecvQueue = nbn_game_client.endpoint.OnMessageAddedToRecvQueue;
server_connection->debug_callbacks = nbn_game_client.endpoint.debug_callbacks;
#endif
nbn_game_client.server_connection = server_connection;
@@ -4882,7 +4881,7 @@ int NBN_GameClient_CallRPC(unsigned int id, ...)
{
NBN_RPC rpc = nbn_game_client.endpoint.rpcs[id];
if (rpc.id < 0 || rpc.id != id)
if (rpc.id != id)
{
NBN_LogError("Cannot call invalid RPC (ID: %d)", id);
@@ -4916,14 +4915,9 @@ rpc_error:
#ifdef NBN_DEBUG
void NBN_GameClient_Debug_RegisterCallback(NBN_ConnectionDebugCallback cb_type, void *cb)
void NBN_GameClient_Debug_RegisterCallback(NBN_ConnectionDebugCallback cbs)
{
switch (cb_type)
{
case NBN_DEBUG_CB_MSG_ADDED_TO_RECV_QUEUE:
nbn_game_client.endpoint.OnMessageAddedToRecvQueue = (void (*)(NBN_Connection *, NBN_Message *))cb;
break;
}
nbn_game_client.endpoint.debug_callbacks = cbs;
}
#endif /* NBN_DEBUG */
@@ -5242,7 +5236,7 @@ NBN_Connection *NBN_GameServer_CreateClientConnection(int driver_id, void *drive
NBN_Connection *client = Endpoint_CreateConnection(&nbn_game_server.endpoint, conn_id, protocol_id, driver_id, driver_data);
#ifdef NBN_DEBUG
client->OnMessageAddedToRecvQueue = nbn_game_server.endpoint.OnMessageAddedToRecvQueue;
client->debug_callbacks = nbn_game_server.endpoint.debug_callbacks;
#endif
return client;
@@ -5436,7 +5430,7 @@ int NBN_GameServer_CallRPC(unsigned int id, NBN_ConnectionHandle connection_hand
NBN_RPC rpc = nbn_game_server.endpoint.rpcs[id];
if (rpc.id < 0 || rpc.id != id)
if (rpc.id != id)
{
NBN_LogError("Cannot call invalid RPC (ID: %d)", id);
@@ -5470,14 +5464,9 @@ rpc_error:
#ifdef NBN_DEBUG
void NBN_GameServer_Debug_RegisterCallback(NBN_ConnectionDebugCallback cb_type, void *cb)
void NBN_GameServer_Debug_RegisterCallback(NBN_ConnectionDebugCallback cbs)
{
switch (cb_type)
{
case NBN_DEBUG_CB_MSG_ADDED_TO_RECV_QUEUE:
nbn_game_server.endpoint.OnMessageAddedToRecvQueue = (void (*)(NBN_Connection *, NBN_Message *))cb;
break;
}
nbn_game_server.endpoint.debug_callbacks = cbs;
}
#endif /* NBN_DEBUG */
@@ -5599,7 +5588,7 @@ static void GameServer_AddClientToClosedList(NBN_Connection *client)
}
}
static unsigned int GameServer_GetClientCount(void)
static inline unsigned int GameServer_GetClientCount(void)
{
return nbn_game_server.clients->count;
}
+6 -2
View File
@@ -12,11 +12,15 @@ endif (CPP_COMPILE)
unset(CPP_COMPILE)
add_compile_options(-Wall)
if(CMAKE_COMPILER_IS_GNUCXX)
add_compile_options(-Wextra -Wpedantic)
endif (CMAKE_COMPILER_IS_GNUCXX)
add_executable(client client.c soak.c logging.c cargs.c)
add_executable(server server.c soak.c logging.c cargs.c)
add_compile_options(-Wall -Wextra -Wpedantic)
target_compile_definitions(client PUBLIC NBN_DEBUG NBN_DISABLE_STALE_CONNECTION_DETECTION NBN_USE_PACKET_SIMULATOR SOAK_CLIENT)
target_compile_definitions(server PUBLIC NBN_DEBUG NBN_DISABLE_STALE_CONNECTION_DETECTION NBN_USE_PACKET_SIMULATOR SOAK_SERVER)
+7 -4
View File
@@ -62,7 +62,7 @@ static unsigned int done_channel_count = 0;
static void GenerateRandomBytes(uint8_t *data, unsigned int length)
{
for (int i = 0; i < length; i++)
for (unsigned int i = 0; i < length; i++)
data[i] = rand() % 255 + 1;
}
@@ -95,7 +95,7 @@ static int SendSoakMessages(SoakChannel *channel, uint8_t channel_id)
Soak_LogInfo("Will send %d soak messages this tick", send_message_count);
for (int i = 0; i < send_message_count; i++)
for (unsigned int i = 0; i < send_message_count; i++)
{
SoakMessage *msg = SoakMessage_CreateOutgoing();
@@ -338,7 +338,7 @@ int main(int argc, char *argv[])
unsigned int leftover_message_count = message_count % channel_count;
SoakChannel *channels = (SoakChannel *)malloc(sizeof(SoakChannel) * channel_count);
for (int c = 0; c < channel_count; c++)
for (unsigned int c = 0; c < channel_count; c++)
{
SoakChannel *channel = &channels[c];
@@ -356,7 +356,10 @@ int main(int argc, char *argv[])
channels[channel_count - 1].message_count += leftover_message_count;
NBN_GameClient_Debug_RegisterCallback(NBN_DEBUG_CB_MSG_ADDED_TO_RECV_QUEUE, (void *)Soak_Debug_PrintAddedToRecvQueue);
NBN_ConnectionDebugCallback cbs = {
.OnMessageAddedToRecvQueue = Soak_Debug_PrintAddedToRecvQueue,
};
NBN_GameClient_Debug_RegisterCallback(cbs);
int ret = Soak_MainLoop(Tick, channels);
+5 -1
View File
@@ -309,6 +309,7 @@ static void SigintHandler(int dummy)
unsigned int destroyed_outgoing_message_count = Soak_GetDestroyedOutgoingSoakMessageCount();
unsigned int created_incoming_message_count = Soak_GetCreatedIncomingSoakMessageCount();
unsigned int destroyed_incoming_message_count = Soak_GetDestroyedIncomingSoakMessageCount();
(void) dummy;
Soak_LogInfo("Outgoing soak messages created: %d", created_outgoing_message_count);
Soak_LogInfo("Outgoing soak messages destroyed: %d", destroyed_outgoing_message_count);
@@ -375,7 +376,10 @@ int main(int argc, char *argv[])
return 1;
}
NBN_GameServer_Debug_RegisterCallback(NBN_DEBUG_CB_MSG_ADDED_TO_RECV_QUEUE, (void *)Soak_Debug_PrintAddedToRecvQueue);
NBN_ConnectionDebugCallback cbs = {
.OnMessageAddedToRecvQueue = Soak_Debug_PrintAddedToRecvQueue,
};
NBN_GameServer_Debug_RegisterCallback(cbs);
int ret = Soak_MainLoop(Tick, NULL);
+5
View File
@@ -64,6 +64,9 @@ static void Usage(void)
int Soak_Init(int argc, char *argv[])
{
(void) argc;
(void) argv;
srand(SOAK_SEED);
SoakOptions options = Soak_GetOptions();
@@ -258,6 +261,8 @@ SoakOptions Soak_GetOptions(void)
void Soak_Debug_PrintAddedToRecvQueue(NBN_Connection *conn, NBN_Message *msg)
{
(void) conn;
(void) msg;
// FIXME
/*if (msg->header.type == NBN_MESSAGE_CHUNK_TYPE)
{
+6 -1
View File
@@ -3,11 +3,16 @@ cmake_minimum_required(VERSION 3.0)
project(unit_tests C)
enable_testing()
add_compile_options(-Wall)
if(CMAKE_COMPILER_IS_GNUCXX)
add_compile_options(-Wextra -Wpedantic -Werror -Wno-unknown-pragmas)
endif (CMAKE_COMPILER_IS_GNUCXX)
# add_executable(message_chunks message_chunks.c CuTest.c)
add_executable(string_tests string_tests.c CuTest.c)
add_executable(serialization_tests serialization.c CuTest.c)
add_compile_options(-Wall -Wextra -Werror)
target_link_libraries(string_tests -lm)
target_link_libraries(serialization_tests -lm)
+3
View File
@@ -102,6 +102,9 @@ void Test_SerializeUInt64(CuTest *tc)
int main(int argc, char *argv[])
{
(void) argc;
(void) argv;
CuString *output = CuStringNew();
CuSuite* suite = CuSuiteNew();
+6 -3
View File
@@ -14,14 +14,14 @@ static void StringReplaceAll(char *res, const char *str, const char *a, const ch
{
int pos = substr - str;
strncpy(res, str, pos);
strncpy(res + pos, b, len_b);
memcpy(res, str, pos);
memcpy(res + pos, b, len_b);
StringReplaceAll(res + pos + len_b, str + pos + len_a, a, b);
}
else
{
strncpy(res, str, strlen(str) + 1);
memcpy(res, str, strlen(str) + 1);
}
}
@@ -47,6 +47,9 @@ int main(int argc, char *argv[])
CuString *output = CuStringNew();
CuSuite* suite = CuSuiteNew();
(void) argc;
(void) argv;
SUITE_ADD_TEST(suite, Test_StringReplaceAll);
CuSuiteRun(suite);