From 58c48c61f0cfd482741e80c7efb614733443cd06 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Sun, 29 Nov 2015 17:20:14 +1000 Subject: [PATCH] * add tests dir --- CMakeLists.txt | 1 + tests/CMakeLists.txt | 6 ++++++ tests/parse_config.c | 26 ++++++++++++++++++++++++++ tests/test.conf | 9 +++++++++ 4 files changed, 42 insertions(+) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/parse_config.c create mode 100644 tests/test.conf diff --git a/CMakeLists.txt b/CMakeLists.txt index af8dcb3..0e4389f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,3 +16,4 @@ message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}") message(STATUS "Library directory: ${INSTALL_LIB}") add_subdirectory (src) +add_subdirectory (tests) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..2388b8d --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,6 @@ +enable_testing() + +set(SRC_DIR "../src") + +add_executable("parse_config" "${SRC_DIR}/config.c" "parse_config.c") +add_test("parse_config" "parse_config") diff --git a/tests/parse_config.c b/tests/parse_config.c new file mode 100644 index 0000000..d86eb82 --- /dev/null +++ b/tests/parse_config.c @@ -0,0 +1,26 @@ +#include +#include +#include +#include + +#include "../src/config.h" + +int main(void) { + oal_config_t config; + + memset(&config, 0x0, sizeof(oal_config_t)); + + if (parse_config(&config, "test.conf") != 0) { + fputs(config.error, stderr); + return 1; + } + + assert(config.bindtimeout == 5); + assert(strcmp(config.bindpass, "strong-password") == 0); + assert(strcmp(config.bindurls, "ldap://127.0.0.1 ldaps://172.16.17.1") == 0); + assert(strcmp(config.binddn, "cn=admin,dc=example,dc=com") == 0); + assert(strcmp(config.basedn, "ou=users,dc=example,dc=com") == 0); + assert(strcmp(config.userfilter, "(objectClass=inetOrgPerson)") == 0); + + return 0; +} diff --git a/tests/test.conf b/tests/test.conf new file mode 100644 index 0000000..07bf5b9 --- /dev/null +++ b/tests/test.conf @@ -0,0 +1,9 @@ +bindurls ldap://127.0.0.1 ldaps://172.16.17.1 +binddn cn=admin,dc=example,dc=com +# comment +bindpass strong-password +bindtimeout 5 + # another comment and empty string below + +basedn ou=users,dc=example,dc=com +userfilter (objectClass=inetOrgPerson)