Browse Source

* add tests dir

master
Alex 'AdUser' Z 9 years ago
parent
commit
58c48c61f0
  1. 1
      CMakeLists.txt
  2. 6
      tests/CMakeLists.txt
  3. 26
      tests/parse_config.c
  4. 9
      tests/test.conf

1
CMakeLists.txt

@ -16,3 +16,4 @@ message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")
message(STATUS "Library directory: ${INSTALL_LIB}") message(STATUS "Library directory: ${INSTALL_LIB}")
add_subdirectory (src) add_subdirectory (src)
add_subdirectory (tests)

6
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")

26
tests/parse_config.c

@ -0,0 +1,26 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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;
}

9
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)
Loading…
Cancel
Save