commit 6ad2f044c98eeaddcb1bbf2003043349806fce1c
parent edc3c424bdffc248fc2adbe7a794fdc84d7225c3
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 22 Dec 2023 15:48:21 +0100
Test the sdis_source API
Diffstat:
2 files changed, 82 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -191,6 +191,7 @@ TEST_SRC =\
src/test_sdis_solve_probe_2d.c\
src/test_sdis_solve_probe2_2d.c\
src/test_sdis_solve_probe3_2d.c\
+ src/test_sdis_source.c\
src/test_sdis_transcient.c\
src/test_sdis_unstationary_atm.c\
src/test_sdis_volumic_power.c\
@@ -288,6 +289,7 @@ src/test_sdis_solve_probe.d \
src/test_sdis_solve_probe_2d.d \
src/test_sdis_solve_probe2_2d.d \
src/test_sdis_solve_probe3_2d \
+src/test_sdis_source.d \
src/test_sdis_transcient.d \
src/test_sdis_unstationary_atm.d \
src/test_sdis_utils.d \
@@ -318,6 +320,7 @@ src/test_sdis_solve_probe.o \
src/test_sdis_solve_probe_2d.o \
src/test_sdis_solve_probe2_2d.o \
src/test_sdis_solve_probe3_2d.o \
+src/test_sdis_source.o \
src/test_sdis_transcient.o \
src/test_sdis_unstationary_atm.o \
src/test_sdis_utils.o \
@@ -348,6 +351,7 @@ test_sdis_solve_probe \
test_sdis_solve_probe_2d \
test_sdis_solve_probe2_2d \
test_sdis_solve_probe3_2d \
+test_sdis_source \
test_sdis_transcient \
test_sdis_unstationary_atm \
test_sdis_volumic_power \
diff --git a/src/test_sdis_source.c b/src/test_sdis_source.c
@@ -0,0 +1,78 @@
+/* Copyright (C) 2016-2023 |Méso|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 "sdis.h"
+#include "test_sdis_utils.h"
+
+/*******************************************************************************
+ * Helper functions
+ ******************************************************************************/
+static void
+spherical_source_get_position
+ (const double time,
+ double pos[3],
+ struct sdis_data* data)
+{
+ (void)time, (void)data;
+ pos[0] = pos[1] = pos[2] = 1.234;
+}
+
+static void
+check_spherical_source(struct sdis_device* dev)
+{
+ struct sdis_spherical_source_create_args args =
+ SDIS_SPHERICAL_SOURCE_CREATE_ARGS_NULL;
+ struct sdis_source* src = NULL;
+ struct sdis_data* data = NULL;
+
+ /* Create a data to check its memory management */
+ OK(sdis_data_create(dev, sizeof(double[3]), ALIGNOF(double[3]), NULL, &data));
+
+ args.position = spherical_source_get_position;
+ args.data = data;
+ args.radius = 1;
+ args.power = 10;
+
+ BA(sdis_spherical_source_create(NULL, &args, &src));
+ BA(sdis_spherical_source_create(dev, NULL, &src));
+ BA(sdis_spherical_source_create(dev, &args, NULL));
+ OK(sdis_spherical_source_create(dev, &args, &src));
+
+ BA(sdis_source_ref_get(NULL));
+ OK(sdis_source_ref_get(src));
+ BA(sdis_source_ref_put(NULL));
+ OK(sdis_source_ref_put(src));
+ OK(sdis_source_ref_put(src));
+
+ OK(sdis_data_ref_put(data));
+}
+
+/*******************************************************************************
+ * The test
+ ******************************************************************************/
+int
+main(int argc, char** argv)
+{
+ struct sdis_device* dev = NULL;
+ (void)argc, (void)argv;
+
+ OK(sdis_device_create(&SDIS_DEVICE_CREATE_ARGS_DEFAULT, &dev));
+
+ check_spherical_source(dev);
+
+ OK(sdis_device_ref_put(dev));
+ CHK(mem_allocated_size() == 0);
+ return 0;
+}