Browse Source

[tests] t/test_array.c

(more tests should be added, but starting with something has benefits)
personal/stbuehler/fix-fdevent
Glenn Strauss 3 years ago
parent
commit
66ff05db8f
  1. 1
      .gitignore
  2. 12
      src/CMakeLists.txt
  3. 5
      src/Makefile.am
  4. 24
      src/array.c
  5. 6
      src/meson.build
  6. 82
      src/t/test_array.c

1
.gitignore

@ -47,6 +47,7 @@ mod_ssi_exprparser.h
scgi-responder
sconsbuild/
stamp-h1
test_array
test_base64
test_buffer
test_burl

12
src/CMakeLists.txt

@ -654,6 +654,16 @@ add_and_install_library(mod_vhostdb mod_vhostdb.c)
add_and_install_library(mod_webdav mod_webdav.c)
add_and_install_library(mod_wstunnel mod_wstunnel.c)
add_executable(test_array
t/test_array.c
array.c
data_array.c
data_integer.c
data_string.c
buffer.c
)
add_test(NAME test_array COMMAND test_array)
add_executable(test_buffer
t/test_buffer.c
buffer.c
@ -895,6 +905,8 @@ if(WITH_LIBUNWIND)
target_link_libraries(lighttpd ${LIBUNWIND_LDFLAGS})
add_target_properties(lighttpd COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
target_link_libraries(test_array ${LIBUNWIND_LDFLAGS})
add_target_properties(test_array COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
target_link_libraries(test_buffer ${LIBUNWIND_LDFLAGS})
add_target_properties(test_buffer COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
target_link_libraries(test_burl ${LIBUNWIND_LDFLAGS})

5
src/Makefile.am

@ -1,6 +1,7 @@
AM_CFLAGS = $(FAM_CFLAGS) $(LIBUNWIND_CFLAGS)
noinst_PROGRAMS=\
t/test_array \
t/test_buffer \
t/test_burl \
t/test_base64 \
@ -11,6 +12,7 @@ sbin_PROGRAMS=lighttpd lighttpd-angel
LEMON=$(top_builddir)/src/lemon$(BUILD_EXEEXT)
TESTS=\
t/test_array$(EXEEXT) \
t/test_buffer$(EXEEXT) \
t/test_burl$(EXEEXT) \
t/test_base64$(EXEEXT) \
@ -534,6 +536,9 @@ lighttpd_LDFLAGS = -export-dynamic
endif
t_test_array_SOURCES = t/test_array.c array.c data_array.c data_integer.c data_string.c buffer.c
t_test_array_LDADD = $(LIBUNWIND_LIBS)
t_test_buffer_SOURCES = t/test_buffer.c buffer.c
t_test_buffer_LDADD = $(LIBUNWIND_LIBS)

24
src/array.c

@ -574,27 +574,3 @@ int array_print(array *a, int depth) {
return 0;
}
#ifdef DEBUG_ARRAY
int main (int argc, char **argv) {
array *a;
UNUSED(argc);
UNUSED(argv);
a = array_init();
array_insert_key_value(a, CONST_STR_LEN("abc"), CONST_STR_LEN("alfrag"));
array_insert_key_value(a, CONST_STR_LEN("abc"), CONST_STR_LEN("hameplman"));
array_insert_key_value(a, CONST_STR_LEN("123"), CONST_STR_LEN("alfrag"));
array_print(a, 0);
array_free(a);
fprintf(stderr, "%d\n",
buffer_caseless_compare(CONST_STR_LEN("Content-Type"), CONST_STR_LEN("Content-type")));
return 0;
}
#endif

6
src/meson.build

@ -703,6 +703,12 @@ executable('lighttpd', configparser,
install_dir: sbinddir,
)
test('test_array', executable('test_array',
sources: ['t/test_array.c', 'array.c', 'data_array.c', 'data_integer.c', 'data_string.c', 'buffer.c'],
dependencies: common_flags + libunwind,
build_by_default: false,
))
test('test_buffer', executable('test_buffer',
sources: ['t/test_buffer.c', 'buffer.c'],
dependencies: common_flags + libunwind,

82
src/t/test_array.c

@ -0,0 +1,82 @@
#include "first.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "array.h"
#include "buffer.h"
static void test_array_insert_value (void) {
data_string *ds;
array *a = array_init();
array_insert_value(a, CONST_STR_LEN("def"));
ds = (data_string *)a->data[0];
assert(NULL != ds);
assert(buffer_is_equal_string(ds->value, CONST_STR_LEN("def")));
array_free(a);
}
static void test_array_insert_key_value (void) {
data_string *ds;
array *a = array_init();
array_insert_key_value(a, CONST_STR_LEN("abc"), CONST_STR_LEN("alfrag"));
ds = (data_string *)array_get_element_klen(a, CONST_STR_LEN("does-not-exist"));
assert(NULL == ds);
ds = (data_string *)array_get_element_klen(a, CONST_STR_LEN("abc"));
assert(NULL != ds);
assert(buffer_is_equal_string(ds->key, CONST_STR_LEN("abc")));
assert(buffer_is_equal_string(ds->value, CONST_STR_LEN("alfrag")));
array_insert_key_value(a, CONST_STR_LEN("abc"), CONST_STR_LEN("hameplman"));
ds = (data_string *)array_get_element_klen(a, CONST_STR_LEN("does-not-exist"));
assert(NULL == ds);
ds = (data_string *)array_get_element_klen(a, CONST_STR_LEN("abc"));
assert(NULL != ds);
assert(buffer_is_equal_string(ds->key, CONST_STR_LEN("abc")));
assert(buffer_is_equal_string(ds->value, CONST_STR_LEN("alfrag, hameplman")));
array_insert_key_value(a, CONST_STR_LEN("123"), CONST_STR_LEN("alfrag"));
ds = (data_string *)array_get_element_klen(a, CONST_STR_LEN("does-not-exist"));
assert(NULL == ds);
ds = (data_string *)array_get_element_klen(a, CONST_STR_LEN("123"));
assert(NULL != ds);
assert(buffer_is_equal_string(ds->key, CONST_STR_LEN("123")));
assert(buffer_is_equal_string(ds->value, CONST_STR_LEN("alfrag")));
array_free(a);
}
static void test_array_set_key_value (void) {
data_string *ds;
array *a = array_init();
array_set_key_value(a, CONST_STR_LEN("abc"), CONST_STR_LEN("def"));
ds = (data_string *)array_get_element_klen(a, CONST_STR_LEN("does-not-exist"));
assert(NULL == ds);
ds = (data_string *)array_get_element_klen(a, CONST_STR_LEN("abc"));
assert(NULL != ds);
assert(buffer_is_equal_string(ds->key, CONST_STR_LEN("abc")));
assert(buffer_is_equal_string(ds->value, CONST_STR_LEN("def")));
array_set_key_value(a, CONST_STR_LEN("abc"), CONST_STR_LEN("ghi"));
ds = (data_string *)array_get_element_klen(a, CONST_STR_LEN("does-not-exist"));
assert(NULL == ds);
ds = (data_string *)array_get_element_klen(a, CONST_STR_LEN("abc"));
assert(NULL != ds);
assert(buffer_is_equal_string(ds->key, CONST_STR_LEN("abc")));
assert(buffer_is_equal_string(ds->value, CONST_STR_LEN("ghi")));
array_free(a);
}
int main() {
test_array_insert_value();
test_array_insert_key_value();
test_array_set_key_value();
return 0;
}
Loading…
Cancel
Save