UVES Pipeline Reference Manual  5.4.2
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 <string.h>
30 #include <float.h>
31 
32 /*-----------------------------------------------------------------------------
33  Function prototypes
34  -----------------------------------------------------------------------------*/
35 
36 /* Declare routines defining a dummy recipe to test the irplib_plugin_test
37  * function. */
38 cpl_recipe_define(test_recipe, 123, "Some Author", "someone@local.org", "2014",
39  "For testing.", "Simple recipe for testing.");
40 
41 static cpl_error_code test_recipe_fill_parameterlist(cpl_parameterlist *self);
42 static int test_recipe(cpl_frameset *frames, const cpl_parameterlist *params);
43 
44 static void test_irplib_recipe_test(void);
45 
46 /*----------------------------------------------------------------------------*/
50 /*----------------------------------------------------------------------------*/
51 
52 
53 /*----------------------------------------------------------------------------*/
57 /*----------------------------------------------------------------------------*/
58 
59 int main(void)
60 {
61 
62 
63 
64  cpl_parameterlist * parlist;
65 
66  /* Initialize CPL for unit testing */
67  cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
68 
69  parlist = cpl_parameterlist_new();
70 
71 
72  (void)irplib_parameterlist_get_double(parlist, "INST", "RECIPE", NULL);
73  cpl_test_error(CPL_ERROR_NULL_INPUT);
74 
75  (void)irplib_parameterlist_get_double(parlist, "INST", NULL, "PAR");
76  cpl_test_error(CPL_ERROR_NULL_INPUT);
77 
78  (void)irplib_parameterlist_get_double(parlist, NULL, "RECIPE", "PAR");
79  cpl_test_error(CPL_ERROR_NULL_INPUT);
80 
81  (void)irplib_parameterlist_get_double(NULL, "INST", "RECIPE", "PAR");
82  cpl_test_error(CPL_ERROR_NULL_INPUT);
83 
84  (void)irplib_parameterlist_get_double(parlist, "INST", "RECIPE", "PAR");
85  cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
86 
87 
88  (void)irplib_parameterlist_get_int(parlist, "INST", "RECIPE", NULL);
89  cpl_test_error(CPL_ERROR_NULL_INPUT);
90 
91  (void)irplib_parameterlist_get_int(parlist, "INST", NULL, "PAR");
92  cpl_test_error(CPL_ERROR_NULL_INPUT);
93 
94  (void)irplib_parameterlist_get_int(parlist, NULL, "RECIPE", "PAR");
95  cpl_test_error(CPL_ERROR_NULL_INPUT);
96 
97  (void)irplib_parameterlist_get_int(NULL, "INST", "RECIPE", "PAR");
98  cpl_test_error(CPL_ERROR_NULL_INPUT);
99 
100  (void)irplib_parameterlist_get_int(parlist, "INST", "RECIPE", "PAR");
101  cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
102 
103 
104  (void)irplib_parameterlist_get_bool(parlist, "INST", "RECIPE", NULL);
105  cpl_test_error(CPL_ERROR_NULL_INPUT);
106 
107  (void)irplib_parameterlist_get_bool(parlist, "INST", NULL, "PAR");
108  cpl_test_error(CPL_ERROR_NULL_INPUT);
109 
110  (void)irplib_parameterlist_get_bool(parlist, NULL, "RECIPE", "PAR");
111  cpl_test_error(CPL_ERROR_NULL_INPUT);
112 
113  (void)irplib_parameterlist_get_bool(NULL, "INST", "RECIPE", "PAR");
114  cpl_test_error(CPL_ERROR_NULL_INPUT);
115 
116  (void)irplib_parameterlist_get_bool(parlist, "INST", "RECIPE", "PAR");
117  cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
118 
119 
120  (void)irplib_parameterlist_get_string(parlist, "INST", "RECIPE", NULL);
121  cpl_test_error(CPL_ERROR_NULL_INPUT);
122 
123  (void)irplib_parameterlist_get_string(parlist, "INST", NULL, "PAR");
124  cpl_test_error(CPL_ERROR_NULL_INPUT);
125 
126  (void)irplib_parameterlist_get_string(parlist, NULL, "RECIPE", "PAR");
127  cpl_test_error(CPL_ERROR_NULL_INPUT);
128 
129  (void)irplib_parameterlist_get_string(NULL, "INST", "RECIPE", "PAR");
130  cpl_test_error(CPL_ERROR_NULL_INPUT);
131 
132  (void)irplib_parameterlist_get_string(parlist, "INST", "RECIPE", "PAR");
133  cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
134 
135 
136  cpl_parameterlist_delete(parlist);
137 
138  test_irplib_recipe_test();
139 
140  return cpl_test_end(0);
141 }
142 
143 
144 static void test_irplib_recipe_test(void)
145 {
146  /* Execute a simple test with the irplib_plugin_test to see that there are
147  * no serious errors with that routine. */
148 
149  const char * tags[] = {
150  "TEST_TAG",
151  "ANOTHER_TAG"
152  };
153  cpl_pluginlist * pluginlist;
154  const size_t ntags = sizeof(tags) / sizeof(char*);
155  pluginlist = cpl_pluginlist_new();
156  cpl_test_nonnull(pluginlist);
157 
158  cpl_test_zero(cpl_plugin_get_info(pluginlist));
159  cpl_test_zero(irplib_plugin_test(pluginlist, ntags, tags));
160 
161  cpl_pluginlist_delete(pluginlist);
162 }
163 
168 static cpl_error_code test_recipe_fill_parameterlist(cpl_parameterlist *self)
169 {
170  cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
171  return CPL_ERROR_NONE;
172 }
173 
178 static int test_recipe(cpl_frameset *frames, const cpl_parameterlist *params)
179 {
180  cpl_frameset_iterator * iterator = NULL;
181  const cpl_frame * frame;
182 
183  cpl_ensure_code(frames != NULL && params != NULL, CPL_ERROR_NULL_INPUT);
184  cpl_ensure_code(cpl_frameset_get_size(frames) > 0,
185  CPL_ERROR_DATA_NOT_FOUND);
186 
187  /* Assume all input files are FITS files and just try load the primary
188  * header. If an error occurs then return it properly. This will exercise
189  * the tests run by irplib_plugin_test. */
190  for (frame = irplib_frameset_get_first_const(&iterator, frames);
191  frame != NULL;
192  frame = irplib_frameset_get_next_const(iterator))
193  {
194  const char * name = cpl_frame_get_filename(frame);
195  cpl_propertylist * props = cpl_propertylist_load(name, 0);
196  if (props == NULL) {
197  cpl_frameset_iterator_delete(iterator);
198  return cpl_error_get_code();
199  }
200  cpl_propertylist_delete(props);
201  }
202 
203  cpl_frameset_iterator_delete(iterator);
204  return CPL_ERROR_NONE;
205 }