From 59e8a7ef447d0c8c56d33bfb7baf0010b5873fd7 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 8 Mar 2022 11:57:55 +0100 Subject: Add tests/stream_roundtrip --- tests/stream_roundtrip.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 tests/stream_roundtrip.c (limited to 'tests/stream_roundtrip.c') diff --git a/tests/stream_roundtrip.c b/tests/stream_roundtrip.c new file mode 100644 index 00000000..29099b1a --- /dev/null +++ b/tests/stream_roundtrip.c @@ -0,0 +1,140 @@ +/* + * stream_roundtrip.c + * + * Check that peaks and reflections can be sent on a stream round-trip + * + * Copyright © 2020-2022 Deutsches Elektronen-Synchrotron DESY, + * a research centre of the Helmholtz Association. + * + * Authors: + * 2020-2022 Thomas White + * + * This file is part of CrystFEL. + * + * CrystFEL 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. + * + * CrystFEL 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 CrystFEL. If not, see . + * + */ + + +#include + +#include +#include +#include + +#define N_PEAKS (10) + +int main(int argc, char *argv[]) +{ + gsl_rng *rng; + int i; + float peak_fs[N_PEAKS]; + float peak_ss[N_PEAKS]; + float peak_i[N_PEAKS]; + int peak_pn[N_PEAKS] = { 0, 0, 1, 1, 0, 1, 0, 1, 0, 1 }; + struct image *image; + DataTemplate *dtempl; + Stream *st; + int fail = 0; + + /* Create test data ................................................. */ + + rng = gsl_rng_alloc(gsl_rng_mt19937); + for ( i=0; ifeatures = image_feature_list_new(); + for ( i=0; ifeatures, peak_fs[i], peak_ss[i], + peak_pn[i], image, peak_i[i], NULL); + } + + st = stream_open_for_write("stream_roundtrip.stream", dtempl); + if ( st == NULL ) { + ERROR("Failed to open stream for writing\n"); + return 1; + } + + stream_write_geometry_file(st, argv[1]); + + if ( stream_write_chunk(st, image, STREAM_PEAKS) ) { + ERROR("Failed to write stream chunk\n"); + return 1; + } + + stream_close(st); + image_free(image); + + /* Read stream ...................................................... */ + + st = stream_open_for_read("stream_roundtrip.stream"); + if ( st == NULL ) { + ERROR("Failed to open stream for reading\n"); + return 1; + } + + image = stream_read_chunk(st, STREAM_PEAKS); + if ( image == NULL ) { + ERROR("Failed to read stream chunk\n"); + return 1; + } + + stream_close(st); + + for ( i=0; ifeatures); i++ ) { + struct imagefeature *f; + f = image_get_feature(image->features, i); + STATUS("%f %f %i %f\n", f->fs, f->ss, f->pn, f->intensity); + if ( f->pn != peak_pn[i] ) { + STATUS("Panel number doesn't match (should be %i)\n", + peak_pn[i]); + fail = 1; + } + if ( !within_tolerance(f->fs, peak_fs[i], 0.1) ) { + ERROR("fs doesn't match (should be %f)\n", peak_fs[i]); + fail = 1; + } + if ( !within_tolerance(f->ss, peak_ss[i], 0.1) ) { + ERROR("ss doesn't match (should be %f)\n", peak_ss[i]); + fail = 1; + } + if ( !within_tolerance(f->intensity, peak_i[i], 0.1) ) { + ERROR("Intensity doesn't match (should be %f)\n", + peak_i[i]); + fail = 1; + } + } + + return fail; +} -- cgit v1.2.3