ke: Add unit tests

personal/stbuehler/wip
Stefan Bühler 13 years ago
parent 419414df8c
commit c5bffcc261
  1. 2
      CMakeLists.txt
  2. 17
      src/CMakeLists.txt
  3. 51
      src/unittests/test-utils.c

@ -7,6 +7,6 @@ SET(PACKAGE_VERSION 2.0.0)
SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
#INCLUDE(CTest)
#ENABLE_TESTING()
ENABLE_TESTING()
ADD_SUBDIRECTORY(src build)

@ -24,6 +24,7 @@ OPTION(BUILD_STATIC "build a static lighttpd with all modules added")
OPTION(BUILD_EXTRA_WARNINGS "extra warnings")
OPTION(WITH_BZIP "with bzip2-support for mod_deflate")
OPTION(WITH_ZLIB "with deflate-support for mod_deflate")
OPTION(BUILD_UNIT_TESTS "build unit tests for testing")
IF(BUILD_STATIC)
SET(LIGHTTPD_STATIC 1)
@ -365,3 +366,19 @@ INSTALL(TARGETS ${L_INSTALL_TARGETS}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib/static)
ENDIF(NOT WIN32)
IF(BUILD_UNIT_TESTS)
MACRO(ADD_TEST_BINARY TESTNAME EXENAME SRCFILES)
ADD_EXECUTABLE(${EXENAME} ${SRCFILES})
ADD_TARGET_PROPERTIES(${EXENAME} LINK_FLAGS ${COMMON_LDFLAGS})
ADD_TARGET_PROPERTIES(${EXENAME} COMPILE_FLAGS ${COMMON_CFLAGS})
TARGET_LINK_LIBRARIES(${EXENAME} lighttpd-common lighttpd-shared)
ADD_TEST(${TESTNAME} ${EXENAME})
ENDMACRO(ADD_TEST_BINARY)
ADD_TEST_BINARY(Utils-UnitTest test-utils unittests/test-utils.c)
ENDIF(BUILD_UNIT_TESTS)

@ -0,0 +1,51 @@
#include <lighttpd/base.h>
#define perror(msg) g_error("(%s:%i) %s failed: %s", __FILE__, __LINE__, msg, g_strerror(errno))
static void test_send_fd(void) {
int pipefds[2], sockfd[2], rfd = -1;
char buf[6];
g_printerr("start\n");
if (-1 == pipe(pipefds)) {
perror("pipe");
}
if (-1 == socketpair(AF_UNIX, SOCK_STREAM, 0, sockfd)) {
perror("socketpair");
}
if (-1 == li_send_fd(sockfd[0], pipefds[0])) {
perror("li_send_fd");
}
if (-1 == li_receive_fd(sockfd[1], &rfd)) {
perror("li_receive_fd");
}
write(pipefds[1], CONST_STR_LEN("test\0"));
if (-1 == read(rfd, buf, 5)) {
perror("read");
}
buf[5] = '\0';
g_test_message("received: %s", buf);
g_assert_cmpstr(buf, ==, "test");
close(pipefds[0]); close(pipefds[1]);
close(sockfd[0]); close(sockfd[1]);
close(rfd);
}
int main(int argc, char **argv) {
g_test_init(&argc, &argv, NULL);
g_test_add_func("/utils/send_fd", test_send_fd);
return g_test_run();
}
Loading…
Cancel
Save