Initial integration of Cmocka (not finished)
This commit is contained in:
+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