NACO Pipeline Reference Manual  4.4.0
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 void test_irplib_recipe_test(void);
42 
43 /*----------------------------------------------------------------------------*/
47 /*----------------------------------------------------------------------------*/
48 
49 
50 /*----------------------------------------------------------------------------*/
54 /*----------------------------------------------------------------------------*/
55 
56 int main(void)
57 {
58 
59 
60 
61  cpl_parameterlist * parlist;
62 
63  /* Initialize CPL for unit testing */
64  cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
65 
66  parlist = cpl_parameterlist_new();
67 
68 
69  (void)irplib_parameterlist_get_double(parlist, "INST", "RECIPE", NULL);
70  cpl_test_error(CPL_ERROR_NULL_INPUT);
71 
72  (void)irplib_parameterlist_get_double(parlist, "INST", NULL, "PAR");
73  cpl_test_error(CPL_ERROR_NULL_INPUT);
74 
75  (void)irplib_parameterlist_get_double(parlist, NULL, "RECIPE", "PAR");
76  cpl_test_error(CPL_ERROR_NULL_INPUT);
77 
78  (void)irplib_parameterlist_get_double(NULL, "INST", "RECIPE", "PAR");
79  cpl_test_error(CPL_ERROR_NULL_INPUT);
80 
81  (void)irplib_parameterlist_get_double(parlist, "INST", "RECIPE", "PAR");
82  cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
83 
84 
85  (void)irplib_parameterlist_get_int(parlist, "INST", "RECIPE", NULL);
86  cpl_test_error(CPL_ERROR_NULL_INPUT);
87 
88  (void)irplib_parameterlist_get_int(parlist, "INST", NULL, "PAR");
89  cpl_test_error(CPL_ERROR_NULL_INPUT);
90 
91  (void)irplib_parameterlist_get_int(parlist, NULL, "RECIPE", "PAR");
92  cpl_test_error(CPL_ERROR_NULL_INPUT);
93 
94  (void)irplib_parameterlist_get_int(NULL, "INST", "RECIPE", "PAR");
95  cpl_test_error(CPL_ERROR_NULL_INPUT);
96 
97  (void)irplib_parameterlist_get_int(parlist, "INST", "RECIPE", "PAR");
98  cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
99 
100 
101  (void)irplib_parameterlist_get_bool(parlist, "INST", "RECIPE", NULL);
102  cpl_test_error(CPL_ERROR_NULL_INPUT);
103 
104  (void)irplib_parameterlist_get_bool(parlist, "INST", NULL, "PAR");
105  cpl_test_error(CPL_ERROR_NULL_INPUT);
106 
107  (void)irplib_parameterlist_get_bool(parlist, NULL, "RECIPE", "PAR");
108  cpl_test_error(CPL_ERROR_NULL_INPUT);
109 
110  (void)irplib_parameterlist_get_bool(NULL, "INST", "RECIPE", "PAR");
111  cpl_test_error(CPL_ERROR_NULL_INPUT);
112 
113  (void)irplib_parameterlist_get_bool(parlist, "INST", "RECIPE", "PAR");
114  cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
115 
116 
117  (void)irplib_parameterlist_get_string(parlist, "INST", "RECIPE", NULL);
118  cpl_test_error(CPL_ERROR_NULL_INPUT);
119 
120  (void)irplib_parameterlist_get_string(parlist, "INST", NULL, "PAR");
121  cpl_test_error(CPL_ERROR_NULL_INPUT);
122 
123  (void)irplib_parameterlist_get_string(parlist, NULL, "RECIPE", "PAR");
124  cpl_test_error(CPL_ERROR_NULL_INPUT);
125 
126  (void)irplib_parameterlist_get_string(NULL, "INST", "RECIPE", "PAR");
127  cpl_test_error(CPL_ERROR_NULL_INPUT);
128 
129  (void)irplib_parameterlist_get_string(parlist, "INST", "RECIPE", "PAR");
130  cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
131 
132 
133  cpl_parameterlist_delete(parlist);
134 
135  test_irplib_recipe_test();
136 
137  return cpl_test_end(0);
138 }
139 
140 
141 static void test_irplib_recipe_test(void)
142 {
143  /* Execute a simple test with the irplib_plugin_test to see that there are
144  * no serious errors with that routine. */
145 
146  const char * tags[] = {
147  "TEST_TAG",
148  "ANOTHER_TAG"
149  };
150  cpl_pluginlist * pluginlist;
151  const size_t ntags = sizeof(tags) / sizeof(char*);
152  pluginlist = cpl_pluginlist_new();
153  cpl_test_nonnull(pluginlist);
154 
155  cpl_test_zero(cpl_plugin_get_info(pluginlist));
156  cpl_test_zero(irplib_plugin_test(pluginlist, ntags, tags));
157 
158  cpl_pluginlist_delete(pluginlist);
159 }
160 
165 static cpl_error_code test_recipe_fill_parameterlist(cpl_parameterlist *self)
166 {
167  cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
168  return CPL_ERROR_NONE;
169 }
170 
175 static int test_recipe(cpl_frameset *frames, const cpl_parameterlist *params)
176 {
177  cpl_frameset_iterator * iterator = NULL;
178  const cpl_frame * frame;
179 
180  cpl_ensure_code(frames != NULL && params != NULL, CPL_ERROR_NULL_INPUT);
181  cpl_ensure_code(cpl_frameset_get_size(frames) > 0,
182  CPL_ERROR_DATA_NOT_FOUND);
183 
184  /* Assume all input files are FITS files and just try load the primary
185  * header. If an error occurs then return it properly. This will exercise
186  * the tests run by irplib_plugin_test. */
187  for (frame = irplib_frameset_get_first_const(&iterator, frames);
188  frame != NULL;
189  frame = irplib_frameset_get_next_const(iterator))
190  {
191  const char * name = cpl_frame_get_filename(frame);
192  cpl_propertylist * props = cpl_propertylist_load(name, 0);
193  if (props == NULL) {
194  cpl_frameset_iterator_delete(iterator);
195  return cpl_error_get_code();
196  }
197  cpl_propertylist_delete(props);
198  }
199 
200  cpl_frameset_iterator_delete(iterator);
201  return CPL_ERROR_NONE;
202 }
int main(void)
Find a plugin and submit it to some tests.
Definition: recipe_main.c:61