commit 8670933a63421a7abb15983c2bc752c28e800196
parent a36cc65beceb9781978b9f4ad4bf6a7f1ba376c6
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 29 Jun 2018 11:55:38 +0200
Test the htmie creation function
Diffstat:
3 files changed, 102 insertions(+), 0 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -82,6 +82,8 @@ if(NOT NO_TEST)
build_test(${_name})
add_test(${_name} ${_name})
endfunction()
+
+ new_test(test_htmie)
endif()
################################################################################
diff --git a/src/test_htmie.c b/src/test_htmie.c
@@ -0,0 +1,66 @@
+/* Copyright (C) 2018 |Meso|Star> (contact@meso-star.com)
+ *
+* This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "htmie.h"
+#include "test_htmie_utils.h"
+
+#include <rsys/logger.h>
+
+static void
+log_stream(const char* msg, void* ctx)
+{
+ ASSERT(msg);
+ (void)msg, (void)ctx;
+ printf("%s\n", msg);
+}
+
+int
+main(int argc, char** argv)
+{
+ struct mem_allocator allocator;
+ struct logger logger;
+ struct htmie* htmie = NULL;
+ (void)argc, (void)argv;
+
+ CHK(htmie_create(NULL, NULL, 0, NULL) == RES_BAD_ARG);
+ CHK(htmie_create(NULL, NULL, 0, &htmie) == RES_OK);
+
+ CHK(htmie_ref_get(NULL) == RES_BAD_ARG);
+ CHK(htmie_ref_get(htmie) == RES_OK);
+ CHK(htmie_ref_put(NULL) == RES_BAD_ARG);
+ CHK(htmie_ref_put(htmie) == RES_OK);
+ CHK(htmie_ref_put(htmie) == RES_OK);
+
+ CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK);
+ CHK(htmie_create(NULL, &allocator, 1, &htmie) == RES_OK);
+ CHK(htmie_ref_put(htmie) == RES_OK);
+
+ CHK(logger_init(&allocator, &logger) == RES_OK);
+ logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL);
+ logger_set_stream(&logger, LOG_ERROR, log_stream, NULL);
+ logger_set_stream(&logger, LOG_WARNING, log_stream, NULL);
+
+ CHK(htmie_create(&logger, &allocator, 0, &htmie) == RES_OK);
+ CHK(htmie_ref_put(htmie) == RES_OK);
+ CHK(htmie_create(&logger, NULL, 0, &htmie) == RES_OK);
+ CHK(htmie_ref_put(htmie) == RES_OK);
+
+ logger_release(&logger);
+ check_memory_allocator(&allocator);
+ mem_shutdown_proxy_allocator(&allocator);
+ CHK(mem_allocated_size() == 0);
+ return 0;
+}
+
diff --git a/src/test_htmie_utils.h b/src/test_htmie_utils.h
@@ -0,0 +1,34 @@
+/* Copyright (C) 2018 |Meso|Star> (contact@meso-star.com)
+ *
+* This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef TEST_HTMIE_UTILS_H
+#define TEST_HTMIE_UTILS_H
+
+#include <rsys/mem_allocator.h>
+#include <stdio.h>
+
+static INLINE void
+check_memory_allocator(struct mem_allocator* allocator)
+{
+ if(MEM_ALLOCATED_SIZE(allocator)) {
+ char dump[512];
+ MEM_DUMP(allocator, dump, sizeof(dump)/sizeof(char));
+ fprintf(stderr, "%s\n", dump);
+ FATAL("Memory leaks\n");
+ }
+}
+
+#endif /* TEST_HTMIE_UTILS_H */
+