diff options
author | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2013-02-21 10:34:37 +0100 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2013-02-21 10:48:55 +0100 |
commit | b66797bd19d3ffda8a69c05378e352f16fa5e43d (patch) | |
tree | 2de42b51ee8d05d741d1de0ed10768be57c558fa /tests | |
parent | 743ccb117a6e6ce633e037eb8d46add2aff74e57 (diff) |
Add ufo_buffer_convert_from_data and unit tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 5 | ||||
-rw-r--r-- | tests/test-buffer.c | 130 | ||||
-rw-r--r-- | tests/test-suite.c | 1 | ||||
-rw-r--r-- | tests/test-suite.h | 1 |
4 files changed, 133 insertions, 4 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 84736dd..9c9ecde 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,11 +3,8 @@ cmake_minimum_required(VERSION 2.8) # configure unit tests set(TEST_SRCS test-suite.c - #test-buffer.c - #test-channel.c + test-buffer.c test-config.c - #test-filter.c - #test-filter-direct.c test-graph.c test-profiler.c ) diff --git a/tests/test-buffer.c b/tests/test-buffer.c new file mode 100644 index 0000000..89bf503 --- /dev/null +++ b/tests/test-buffer.c @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2011-2013 Karlsruhe Institute of Technology + * + * This file is part of Ufo. + * + * This library is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <string.h> +#include <ufo.h> +#include "test-suite.h" + +typedef struct { + UfoBuffer *buffer; + guint n_data; + const guint8 *data8; + const guint16 *data16; +} Fixture; + +static void +setup (Fixture *fixture, gconstpointer data) +{ + static const guint8 data8[8] = { 1, 2, 1, 3, 1, 255, 1, 254 }; + static const guint16 data16[8] = { 1, 2, 1, 3, 1, 65535, 1, 65534 }; + + UfoRequisition requisition = { + .n_dims = 1, + .dims[0] = 8, + }; + + fixture->buffer = ufo_buffer_new (&requisition, NULL); + fixture->data8 = data8; + fixture->data16 = data16; + fixture->n_data = 8; +} + +static void +teardown (Fixture *fixture, gconstpointer data) +{ + g_object_unref (fixture->buffer); +} + +static void +test_convert_8 (Fixture *fixture, + gconstpointer unused) +{ + gfloat *host_data; + + host_data = ufo_buffer_get_host_array (fixture->buffer, NULL); + g_memmove (host_data, fixture->data8, fixture->n_data); + + ufo_buffer_convert (fixture->buffer, UFO_BUFFER_DEPTH_8U); + host_data = ufo_buffer_get_host_array (fixture->buffer, NULL); + + for (guint i = 0; i < fixture->n_data; i++) + g_assert (host_data[i] == ((gfloat) fixture->data8[i])); +} + +static void +test_convert_8_from_data (Fixture *fixture, + gconstpointer unused) +{ + gfloat *host_data; + + ufo_buffer_convert_from_data (fixture->buffer, fixture->data8, UFO_BUFFER_DEPTH_8U); + host_data = ufo_buffer_get_host_array (fixture->buffer, NULL); + + for (guint i = 0; i < fixture->n_data; i++) + g_assert (host_data[i] == ((gfloat) fixture->data8[i])); +} + +static void +test_convert_16 (Fixture *fixture, + gconstpointer unused) +{ + gfloat *host_data; + + host_data = ufo_buffer_get_host_array (fixture->buffer, NULL); + g_memmove (host_data, fixture->data16, fixture->n_data * sizeof (guint16)); + + ufo_buffer_convert (fixture->buffer, UFO_BUFFER_DEPTH_16U); + host_data = ufo_buffer_get_host_array (fixture->buffer, NULL); + + for (guint i = 0; i < fixture->n_data; i++) + g_assert (host_data[i] == ((gfloat) fixture->data16[i])); +} + +static void +test_convert_16_from_data (Fixture *fixture, + gconstpointer unused) +{ + gfloat *host_data; + + ufo_buffer_convert_from_data (fixture->buffer, fixture->data16, UFO_BUFFER_DEPTH_16U); + host_data = ufo_buffer_get_host_array (fixture->buffer, NULL); + + for (guint i = 0; i < fixture->n_data; i++) + g_assert (host_data[i] == ((gfloat) fixture->data16[i])); +} + +void +test_add_buffer (void) +{ + g_test_add ("/buffer/convert/8/host", + Fixture, NULL, + setup, test_convert_8, teardown); + + g_test_add ("/buffer/convert/8/data", + Fixture, NULL, + setup, test_convert_8_from_data, teardown); + + g_test_add ("/buffer/convert/16/host", + Fixture, NULL, + setup, test_convert_16, teardown); + + g_test_add ("/buffer/convert/16/data", + Fixture, NULL, + setup, test_convert_16_from_data, teardown); +} diff --git a/tests/test-suite.c b/tests/test-suite.c index d16b214..b4ad15a 100644 --- a/tests/test-suite.c +++ b/tests/test-suite.c @@ -37,6 +37,7 @@ int main(int argc, char *argv[]) g_log_set_handler ("Ufo", G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, ignore_log, NULL); g_log_set_handler ("ocl", G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, ignore_log, NULL); + test_add_buffer (); test_add_config (); test_add_graph (); test_add_profiler (); diff --git a/tests/test-suite.h b/tests/test-suite.h index 02bf8ff..febfc68 100644 --- a/tests/test-suite.h +++ b/tests/test-suite.h @@ -1,6 +1,7 @@ #ifndef TEST_SUITE_H #define TEST_SUITE_H +void test_add_buffer (void); void test_add_config (void); void test_add_graph (void); void test_add_profiler (void); |