commit 6cd5a2d27503eddf4d71969c9af9f903abc33a70
parent e2acd5e8de1609388e5e807fd7df89f11a465e18
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 31 Jan 2018 16:14:49 +0100
Test the device API
Diffstat:
3 files changed, 101 insertions(+), 2 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (C) CNRS
+# Copyright (C) CNRS 2018
#
# 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
@@ -81,7 +81,7 @@ if(NOT NO_TEST)
add_test(${_name} ${_name})
endfunction()
- # TODO register tests here
+ new_test(test_htvx_device)
endif()
################################################################################
diff --git a/src/test_htvx_device.c b/src/test_htvx_device.c
@@ -0,0 +1,65 @@
+/* Copyright (C) CNRS 2018
+ *
+ * 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 "htvx.h"
+#include "test_htvx_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 htvx_device* htvx;
+ (void)argc, (void)argv;
+
+ CHK(htvx_device_create(NULL, NULL, 0, NULL) == RES_BAD_ARG);
+ CHK(htvx_device_create(NULL, NULL, 0, &htvx) == RES_OK);
+
+ CHK(htvx_device_ref_get(NULL) == RES_BAD_ARG);
+ CHK(htvx_device_ref_get(htvx) == RES_OK);
+ CHK(htvx_device_ref_put(NULL) == RES_BAD_ARG);
+ CHK(htvx_device_ref_put(htvx) == RES_OK);
+ CHK(htvx_device_ref_put(htvx) == RES_OK);
+
+ CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK);
+ CHK(htvx_device_create(NULL, &allocator, 1, &htvx) == RES_OK);
+ CHK(htvx_device_ref_put(htvx) == 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(htvx_device_create(&logger, &allocator, 0, &htvx) == RES_OK);
+ CHK(htvx_device_ref_put(htvx) == RES_OK);
+ CHK(htvx_device_create(&logger, NULL, 0, &htvx) == RES_OK);
+ CHK(htvx_device_ref_put(htvx) == 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_htvx_utils.h b/src/test_htvx_utils.h
@@ -0,0 +1,34 @@
+/* Copyright (C) CNRS 2018
+ *
+ * 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_HTVX_UTILS_H
+#define TEST_HTVX_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_HTVX_UTILS_H */
+