Initial integration of Cmocka (not finished)
This commit is contained in:
+6
-3
@@ -1,3 +1,6 @@
|
||||
[submodule "external/Unity"]
|
||||
path = external/Unity
|
||||
url = https://github.com/ThrowTheSwitch/Unity.git
|
||||
# [submodule "external/Unity"]
|
||||
# path = external/Unity
|
||||
# url = https://github.com/ThrowTheSwitch/Unity.git
|
||||
[submodule "external/cmocka"]
|
||||
path = external/cmocka
|
||||
url = https://git.cryptomilk.org/projects/cmocka.git
|
||||
|
||||
+5
-6
@@ -40,12 +40,11 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
add_subdirectory(src)
|
||||
|
||||
if(TARGET_GROUP STREQUAL test)
|
||||
include(CTest)
|
||||
|
||||
add_subdirectory(external)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
# Testing
|
||||
enable_testing()
|
||||
include(cmake/OptionsCMocka.cmake)
|
||||
add_subdirectory(external/cmocka)
|
||||
add_subdirectory(test)
|
||||
|
||||
install(
|
||||
TARGETS zbbs-server
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
# Disable things we don't need from CMocka
|
||||
set(WITH_EXAMPLES OFF CACHE BOOL "Build examples" FORCE)
|
||||
set(UNIT_TESTING OFF CACHE BOOL "Build CMocka's own tests" FORCE)
|
||||
set(WITH_CMOCKERY_SUPPORT OFF CACHE BOOL "" FORCE)
|
||||
|
||||
# Force static library (easier for most projects)
|
||||
set(WITH_STATIC_LIB ON CACHE BOOL "Build static library" FORCE)
|
||||
Vendored
-7
@@ -1,7 +0,0 @@
|
||||
add_library(Unity STATIC
|
||||
Unity/src/unity.c
|
||||
)
|
||||
|
||||
target_include_directories(Unity PUBLIC
|
||||
Unity/src
|
||||
)
|
||||
+1
Submodule external/cmocka added at 7f736f65dc
@@ -9,11 +9,24 @@ target_sources(zbbs-server
|
||||
${M_SOURCES}
|
||||
)
|
||||
|
||||
add_library(main INTERFACE)
|
||||
|
||||
target_sources(main
|
||||
PUBLIC
|
||||
FILE_SET HEADERS
|
||||
FILES
|
||||
main.h
|
||||
)
|
||||
|
||||
|
||||
add_subdirectory(libs)
|
||||
add_subdirectory(db)
|
||||
add_subdirectory(components)
|
||||
|
||||
target_link_libraries(zbbs-server
|
||||
PRIVATE
|
||||
session
|
||||
client
|
||||
db
|
||||
murmur3
|
||||
OpenSSL::Crypto
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
add_subdirectory(client)
|
||||
add_subdirectory(session)
|
||||
@@ -0,0 +1,18 @@
|
||||
add_library(client STATIC)
|
||||
|
||||
target_link_libraries(client
|
||||
PRIVATE
|
||||
db
|
||||
main
|
||||
murmur3
|
||||
OpenSSL::Crypto
|
||||
)
|
||||
|
||||
target_sources(client
|
||||
PRIVATE
|
||||
client.c
|
||||
PUBLIC
|
||||
FILE_SET HEADERS
|
||||
FILES
|
||||
client.h
|
||||
)
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "client.h"
|
||||
#include "file_p.h"
|
||||
#include "main.h"
|
||||
#include <main.h>
|
||||
#include "session.h"
|
||||
#include "utils.h"
|
||||
#include <fcntl.h>
|
||||
@@ -4,7 +4,7 @@
|
||||
#ifndef CLIENT_H
|
||||
#define CLIENT_H
|
||||
|
||||
#include "main.h"
|
||||
#include <main.h>
|
||||
void process_client_command(char *line, session *sess, server_data_t *s_d);
|
||||
void download_confirm(char *line, session *sess, server_data_t *s_d);
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
add_library(session STATIC)
|
||||
|
||||
target_link_libraries(session
|
||||
PRIVATE
|
||||
client
|
||||
db
|
||||
murmur3
|
||||
OpenSSL::Crypto
|
||||
)
|
||||
|
||||
target_sources(session
|
||||
PRIVATE
|
||||
session.c
|
||||
PUBLIC
|
||||
FILE_SET HEADERS
|
||||
FILES
|
||||
session.h
|
||||
)
|
||||
@@ -2,11 +2,11 @@
|
||||
/* Copyright (c) 2026 Oleksandr Zhylin */
|
||||
|
||||
#include "session.h"
|
||||
#include "client.h"
|
||||
#include "file_p.h"
|
||||
#include "main.h"
|
||||
#include "user.h"
|
||||
#include "utils.h"
|
||||
#include "../../client.h"
|
||||
#include "../../file_p.h"
|
||||
#include "../../main.h"
|
||||
#include "../../user.h"
|
||||
#include "../../utils.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <db.h>
|
||||
#include <fcntl.h>
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#ifndef SESSION_H
|
||||
#define SESSION_H
|
||||
#include "main.h"
|
||||
#include "../../main.h"
|
||||
#include <stdio.h>
|
||||
int accept_client(int ls, session *connections[], char *wm);
|
||||
void session_send_string(struct session *sess, const char *str, ...);
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
int32_t create_user(session *sess, char *line) {
|
||||
i_db_user_create p;
|
||||
int32_t privileges;
|
||||
int32_t res;
|
||||
if (sscanf(line, "register %s %s %s", p.uname, p.pass, p.email) == 3) {
|
||||
res = db_user_create(&p);
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
add_subdirectory(file_p)
|
||||
add_subdirectory(session)
|
||||
@@ -1,10 +0,0 @@
|
||||
add_executable(file_p_app
|
||||
file_p.c
|
||||
)
|
||||
|
||||
target_link_libraries(file_p_app
|
||||
file_p
|
||||
Unity
|
||||
)
|
||||
|
||||
add_test(file_p_test file_p_app)
|
||||
@@ -1 +0,0 @@
|
||||
#include <unity.h>
|
||||
@@ -0,0 +1,12 @@
|
||||
add_executable(session_app
|
||||
session.c
|
||||
)
|
||||
|
||||
target_link_libraries(session_app
|
||||
cmocka
|
||||
session
|
||||
)
|
||||
|
||||
target_link_options(session_app PRIVATE -Wl,--wrap=read)
|
||||
|
||||
add_test(session_test session_app)
|
||||
@@ -0,0 +1,35 @@
|
||||
#include <cmocka.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <session.h>
|
||||
#include "../../src/main.h"
|
||||
|
||||
#define TEST_BUF "Hello world!\n"
|
||||
|
||||
int __wrap_read(int fd, void *buf, size_t nbytes) {
|
||||
return sizeof TEST_BUF - 1;
|
||||
}
|
||||
|
||||
void test_session_do_read(void** state) {
|
||||
session sess = {
|
||||
.buf = TEST_BUF,
|
||||
.buf_used = sizeof TEST_BUF,
|
||||
.sd = 2,
|
||||
};
|
||||
char *str;
|
||||
session_do_read(NULL, &str);
|
||||
assert_memory_equal(str, TEST_BUF, sizeof (TEST_BUF)-1);
|
||||
}
|
||||
|
||||
int setup(void **state) { return 0; }
|
||||
int tear_down(void **state) { return 0; }
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
const struct CMUnitTest tests[] = {cmocka_unit_test(test_session_do_read)};
|
||||
|
||||
return cmocka_run_group_tests(tests, setup, tear_down);
|
||||
}
|
||||
Reference in New Issue
Block a user