CR2RE Pipeline Reference Manual 1.6.10
irplib_plugin-test.c
1/* *
2 * This file is part of the ESO IRPLIB package *
3 * Copyright (C) 2004,2005 European Southern Observatory *
4 * *
5 * This library is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA *
18 * */
19
20#ifdef HAVE_CONFIG_H
21# include <config.h>
22#endif
23
24/*-----------------------------------------------------------------------------
25 Includes
26 -----------------------------------------------------------------------------*/
27
28#include <irplib_plugin.h>
29#include <irplib_utils.h>
30#include <string.h>
31#include <float.h>
32
33/*-----------------------------------------------------------------------------
34 Function prototypes
35 -----------------------------------------------------------------------------*/
36
37/* Declare routines defining a dummy recipe to test the irplib_plugin_test
38 * function. */
39cpl_recipe_define(test_recipe, 123, "Some Author", "someone@local.org", "2014",
40 "For testing.", "Simple recipe for testing.");
41
42static void test_irplib_recipe_test(void);
43
44/*----------------------------------------------------------------------------*/
48/*----------------------------------------------------------------------------*/
49
50
51/*----------------------------------------------------------------------------*/
55/*----------------------------------------------------------------------------*/
56
57int main(void)
58{
59
60
61
62 cpl_parameterlist * parlist;
63
64 /* Initialize CPL for unit testing */
65 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
66
67 parlist = cpl_parameterlist_new();
68
69
70 (void)irplib_parameterlist_get_double(parlist, "INST", "RECIPE", NULL);
71 cpl_test_error(CPL_ERROR_NULL_INPUT);
72
73 (void)irplib_parameterlist_get_double(parlist, "INST", NULL, "PAR");
74 cpl_test_error(CPL_ERROR_NULL_INPUT);
75
76 (void)irplib_parameterlist_get_double(parlist, NULL, "RECIPE", "PAR");
77 cpl_test_error(CPL_ERROR_NULL_INPUT);
78
79 (void)irplib_parameterlist_get_double(NULL, "INST", "RECIPE", "PAR");
80 cpl_test_error(CPL_ERROR_NULL_INPUT);
81
82 (void)irplib_parameterlist_get_double(parlist, "INST", "RECIPE", "PAR");
83 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
84
85
86 (void)irplib_parameterlist_get_int(parlist, "INST", "RECIPE", NULL);
87 cpl_test_error(CPL_ERROR_NULL_INPUT);
88
89 (void)irplib_parameterlist_get_int(parlist, "INST", NULL, "PAR");
90 cpl_test_error(CPL_ERROR_NULL_INPUT);
91
92 (void)irplib_parameterlist_get_int(parlist, NULL, "RECIPE", "PAR");
93 cpl_test_error(CPL_ERROR_NULL_INPUT);
94
95 (void)irplib_parameterlist_get_int(NULL, "INST", "RECIPE", "PAR");
96 cpl_test_error(CPL_ERROR_NULL_INPUT);
97
98 (void)irplib_parameterlist_get_int(parlist, "INST", "RECIPE", "PAR");
99 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
100
101
102 (void)irplib_parameterlist_get_bool(parlist, "INST", "RECIPE", NULL);
103 cpl_test_error(CPL_ERROR_NULL_INPUT);
104
105 (void)irplib_parameterlist_get_bool(parlist, "INST", NULL, "PAR");
106 cpl_test_error(CPL_ERROR_NULL_INPUT);
107
108 (void)irplib_parameterlist_get_bool(parlist, NULL, "RECIPE", "PAR");
109 cpl_test_error(CPL_ERROR_NULL_INPUT);
110
111 (void)irplib_parameterlist_get_bool(NULL, "INST", "RECIPE", "PAR");
112 cpl_test_error(CPL_ERROR_NULL_INPUT);
113
114 (void)irplib_parameterlist_get_bool(parlist, "INST", "RECIPE", "PAR");
115 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
116
117
118 (void)irplib_parameterlist_get_string(parlist, "INST", "RECIPE", NULL);
119 cpl_test_error(CPL_ERROR_NULL_INPUT);
120
121 (void)irplib_parameterlist_get_string(parlist, "INST", NULL, "PAR");
122 cpl_test_error(CPL_ERROR_NULL_INPUT);
123
124 (void)irplib_parameterlist_get_string(parlist, NULL, "RECIPE", "PAR");
125 cpl_test_error(CPL_ERROR_NULL_INPUT);
126
127 (void)irplib_parameterlist_get_string(NULL, "INST", "RECIPE", "PAR");
128 cpl_test_error(CPL_ERROR_NULL_INPUT);
129
130 (void)irplib_parameterlist_get_string(parlist, "INST", "RECIPE", "PAR");
131 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
132
133
134 cpl_parameterlist_delete(parlist);
135
136 test_irplib_recipe_test();
137
138 return cpl_test_end(0);
139}
140
141
142static void test_irplib_recipe_test(void)
143{
144 /* Execute a simple test with the irplib_plugin_test to see that there are
145 * no serious errors with that routine. */
146
147 const char * tags[] = {
148 "TEST_TAG",
149 "ANOTHER_TAG"
150 };
151 cpl_pluginlist * pluginlist;
152 const size_t ntags = sizeof(tags) / sizeof(char*);
153 pluginlist = cpl_pluginlist_new();
154 cpl_test_nonnull(pluginlist);
155
156 cpl_test_zero(cpl_plugin_get_info(pluginlist));
157 cpl_test_zero(irplib_plugin_test(pluginlist, ntags, tags));
158
159 cpl_pluginlist_delete(pluginlist);
160}
161
166static cpl_error_code test_recipe_fill_parameterlist(cpl_parameterlist *self)
167{
168 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
169 return CPL_ERROR_NONE;
170}
171
176static int test_recipe(cpl_frameset *frames, const cpl_parameterlist *params)
177{
178 cpl_frameset_iterator * iterator = NULL;
179 const cpl_frame * frame;
180
181 cpl_ensure_code(frames != NULL && params != NULL, CPL_ERROR_NULL_INPUT);
182 cpl_ensure_code(cpl_frameset_get_size(frames) > 0,
183 CPL_ERROR_DATA_NOT_FOUND);
184
185 /* Assume all input files are FITS files and just try load the primary
186 * header. If an error occurs then return it properly. This will exercise
187 * the tests run by irplib_plugin_test. */
188 for (frame = irplib_frameset_get_first_const(&iterator, frames);
189 frame != NULL;
190 frame = irplib_frameset_get_next_const(iterator))
191 {
192 const char * name = cpl_frame_get_filename(frame);
193 cpl_propertylist * props = cpl_propertylist_load(name, 0);
194 if (props == NULL) {
195 cpl_frameset_iterator_delete(iterator);
196 return cpl_error_get_code();
197 }
198 cpl_propertylist_delete(props);
199 }
200
201 cpl_frameset_iterator_delete(iterator);
202 return CPL_ERROR_NONE;
203}