Mon, 07 Nov 2016 19:32:17 +0100
adds first libidav tests
Makefile | file | annotate | diff | comparison | revisions | |
dav/db.c | file | annotate | diff | comparison | revisions | |
test/Makefile | file | annotate | diff | comparison | revisions | |
test/base64.c | file | annotate | diff | comparison | revisions | |
test/base64.h | file | annotate | diff | comparison | revisions | |
test/main.c | file | annotate | diff | comparison | revisions |
--- a/Makefile Sun Sep 18 08:56:54 2016 +0200 +++ b/Makefile Mon Nov 07 19:32:17 2016 +0100 @@ -42,7 +42,7 @@ include $(CONF).mk -all: build/tool build/ucx build/libidav ucx libidav dav +all: build/tool build/ucx build/libidav build/test ucx libidav dav test build/tool: mkdir -p build/tool @@ -53,6 +53,9 @@ build/libidav: mkdir -p build/libidav +build/test: + mkdir -p build/test + ucx: FORCE cd ucx; $(MAKE) CONF=$(CONF) all @@ -62,6 +65,9 @@ dav: FORCE libidav ucx cd dav; $(MAKE) CONF=$(CONF) all +test: FORCE dav + cd test; $(MAKE) CONF=$(CONF) all + run: FORCE dav ./build/dav$(APP_EXT)
--- a/dav/db.c Sun Sep 18 08:56:54 2016 +0200 +++ b/dav/db.c Mon Nov 07 19:32:17 2016 +0100 @@ -60,7 +60,7 @@ xmlDoc *doc = doc = xmlNewDoc(BAD_CAST "1.0"); xmlNode *root = xmlNewNode(NULL, BAD_CAST "directory"); xmlDocSetRootElement(doc, root); - if(!xmlSaveFormatFileEnc(db_file, doc, "UTF-8", 1) == -1) { + if(xmlSaveFormatFileEnc(db_file, doc, "UTF-8", 1) == -1) { destroy_db(db); db = NULL; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/Makefile Mon Nov 07 19:32:17 2016 +0100 @@ -0,0 +1,48 @@ +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2016 Olaf Wintermann. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +include ../$(CONF).mk + +TEST_SRC = main.c +TEST_SRC += base64.c + + +TEST_OBJ = $(TEST_SRC:%.c=../build/test/%$(OBJ_EXT)) + +TEST_TARGET = ../build/runtests$(APP_EXT) + +all: $(TEST_TARGET) + +$(TEST_TARGET): $(TEST_OBJ) ../build/libidav$(LIB_EXT) + $(LD) -o $(TEST_TARGET) $(TEST_OBJ) \ + ../build/libidav$(LIB_EXT) ../build/libucx$(LIB_EXT) \ + $(LDFLAGS) $(DAV_LDFLAGS) + +../build/test/%$(OBJ_EXT): %.c + $(CC) $(CFLAGS) $(DAV_CFLAGS) -I../ -o $@ $< +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/base64.c Mon Nov 07 19:32:17 2016 +0100 @@ -0,0 +1,157 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2016 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "base64.h" + +#include <ucx/string.h> +#include <libidav/utils.h> + +UCX_TEST(test_util_base64decode) { + char *s1 = util_base64decode("YWJj"); + char *s2 = util_base64decode("aGVsbG8gd29ybGQ="); + char *s3 = util_base64decode("MA=="); + char *s4 = util_base64decode("MHh4MQ=="); + + UCX_TEST_BEGIN; + + UCX_TEST_ASSERT(!strcmp(s1, "abc"), "s1 wrong"); + UCX_TEST_ASSERT(!strcmp(s2, "hello world"), "s2 wrong"); + UCX_TEST_ASSERT(!strcmp(s3, "0"), "s3 wrong"); + UCX_TEST_ASSERT(!strcmp(s4, "0xx1"), "s4 wrong"); + + UCX_TEST_END; + + free(s1); + free(s2); + free(s3); + free(s4); +} + +UCX_TEST(test_util_base64decode_len) { + int len1, len2, len3, len4, len5, len6; + char *s1 = util_base64decode_len("aGVsbG8=", &len1); // 5 + char *s2 = util_base64decode_len("MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5", &len2); // 30 + char *s3 = util_base64decode_len("Lg==", &len3); // 1 + char *s4 = util_base64decode_len("bG9s", &len4); // 3 + char *s5 = util_base64decode_len("YWJjLS0tLS0tM3g=", &len5); // 11 + char *s6 = util_base64decode_len("YWJjZGVmZy4uLjs7MGhlbGxv", &len6); // 18 + + UCX_TEST_BEGIN; + + UCX_TEST_ASSERT(!strcmp(s1, "hello"), "s1 wrong"); + UCX_TEST_ASSERT(len1 == 5, "len1 wrong"); + + UCX_TEST_ASSERT(!strcmp(s2, "012345678901234567890123456789"), "s2 wrong"); + UCX_TEST_ASSERT(len2 == 30, "len2 wrong"); + + UCX_TEST_ASSERT(!strcmp(s3, "."), "s3 wrong"); + UCX_TEST_ASSERT(len3 == 1, "len3 wrong"); + + UCX_TEST_ASSERT(!strcmp(s4, "lol"), "s4 wrong"); + UCX_TEST_ASSERT(len4 == 3, "len4 wrong"); + + UCX_TEST_ASSERT(!strcmp(s5, "abc------3x"), "s5 wrong"); + UCX_TEST_ASSERT(len5 == 11, "len5 wrong"); + + UCX_TEST_ASSERT(!strcmp(s6, "abcdefg...;;0hello"), "s6 failed"); + UCX_TEST_ASSERT(len6 == 18, "len6 wrong"); + + UCX_TEST_END; + + free(s1); + free(s2); + free(s3); + free(s4); + free(s5); + free(s6); +} + +UCX_TEST(test_util_base64encode) { + char *str1 = "hello world"; + char *str2 = "test string"; + char *str3 = "01234567890123456789012345678901234567890123456789"; + char str4[8]; + str4[0] = 0; + str4[1] = 12; + str4[2] = 3; + str4[3] = 50; + str4[4] = 2; + str4[5] = 110; + str4[6] = 63; + str4[7] = 1; + + char *str5 = "a"; + char *str6 = "ab"; + char *str7 = "abc"; + char *str8 = "abcd"; + char *str9 = "abcde"; + char *str10 = "abcdef"; + + char *b1 = util_base64encode(str1, strlen(str1)); + char *b2 = util_base64encode(str2, strlen(str2)); + char *b3 = util_base64encode(str3, strlen(str3)); + char *b4 = util_base64encode(str4, 8); + char *b5 = util_base64encode(str5, strlen(str5)); + char *b6 = util_base64encode(str6, strlen(str6)); + char *b7 = util_base64encode(str7, strlen(str7)); + char *b8 = util_base64encode(str8, strlen(str8)); + char *b9 = util_base64encode(str9, strlen(str9)); + char *b10 = util_base64encode(str10, strlen(str10)); + + UCX_TEST_BEGIN; + + UCX_TEST_ASSERT(!strcmp(b1, "aGVsbG8gd29ybGQ="), "b1 failed"); + UCX_TEST_ASSERT(!strcmp(b2, "dGVzdCBzdHJpbmc="), "b2 failed"); + UCX_TEST_ASSERT(!strcmp(b3, "MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODk="), "b3 failed"); + UCX_TEST_ASSERT(!strcmp(b4, "AAwDMgJuPwE="), "b4 failed"); + + UCX_TEST_ASSERT(!strcmp(b5, "YQ=="), "b5 failed"); + UCX_TEST_ASSERT(!strcmp(b6, "YWI="), "b6 failed"); + UCX_TEST_ASSERT(!strcmp(b7, "YWJj"), "b7 failed"); + UCX_TEST_ASSERT(!strcmp(b8, "YWJjZA=="), "b8 failed"); + UCX_TEST_ASSERT(!strcmp(b9, "YWJjZGU="), "b9 failed"); + UCX_TEST_ASSERT(!strcmp(b10, "YWJjZGVm"), "b10 failed"); + + UCX_TEST_END; + + free(b1); + free(b2); + free(b3); + free(b4); + free(b5); + free(b6); + free(b7); + free(b8); + free(b9); + free(b10); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/base64.h Mon Nov 07 19:32:17 2016 +0100 @@ -0,0 +1,48 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2016 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef BASE64_H +#define BASE64_H + +#include <ucx/test.h> + +#ifdef __cplusplus +extern "C" { +#endif + +UCX_TEST(test_util_base64decode); +UCX_TEST(test_util_base64decode_len); +UCX_TEST(test_util_base64encode); + + +#ifdef __cplusplus +} +#endif + +#endif /* BASE64_H */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/main.c Mon Nov 07 19:32:17 2016 +0100 @@ -0,0 +1,52 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2016 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <stdio.h> +#include <stdlib.h> + +#include <ucx/test.h> + +#include "base64.h" + +int main(int argc, char **argv) { + printf("libidav tests\n"); + printf("-------------\n\n"); + + UcxTestSuite* suite = ucx_test_suite_new(); + + ucx_test_register(suite, test_util_base64decode); + ucx_test_register(suite, test_util_base64decode_len); + ucx_test_register(suite, test_util_base64encode); + + ucx_test_run(suite, stdout); + fflush(stdout); + ucx_test_suite_free(suite); + + return 0; +} +