UVES Pipeline Reference Manual  5.4.6
recipe_main.c
1 /* $Id: recipe_main.c,v 1.3 2009-06-05 05:57:38 amodigli Exp $
2  *
3  * This file is part of the UVES Pipeline
4  * Copyright (C) 2002,2003 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: amodigli $
23  * $Date: 2009-06-05 05:57:38 $
24  * $Revision: 1.3 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 /*-----------------------------------------------------------------------------
33  Includes
34  -----------------------------------------------------------------------------*/
35 
36 #include <stdlib.h>
37 #include <unistd.h>
38 #include <sys/stat.h>
39 #include <sys/types.h>
40 
41 #include <cpl.h>
42 
43 #include <irplib_plugin.h>
44 #include <cpl_test.h>
45 #include <uves_dfs.h>
46 #include <uves_msg.h>
47 
48 #ifdef UVES_TEST_NAME
49 # define STRINGIFY(macro) CPL_XSTRINGIFY(macro)
50 # define LOG_FILE_NAME STRINGIFY(UVES_TEST_NAME)"-test-run.log"
51 # define TEST_NAME STRINGIFY(UVES_TEST_NAME)
52 #else
53 # define LOG_FILE_NAME __FILE__
54 # define TEST_NAME __FILE__
55 #endif
56 
57 
58 /*----------------------------------------------------------------------------*/
62 /*----------------------------------------------------------------------------*/
63 
66 /*-----------------------------------------------------------------------------
67  Function definitions
68  -----------------------------------------------------------------------------*/
69 
70 
71 /*----------------------------------------------------------------------------*/
77 /*----------------------------------------------------------------------------*/
78 int main(void)
79 {
80 
81  const char * tags[] = {
82 
83  "BIAS_RED",
84  "PDARK_RED",
85  "DFLAT_RED",
86  "ORDER_FLAT_RED",
87  "ARC_LAMP_FORM_RED",
88  "ARC_LAMP_RED",
89  "STANDARD_RED",
90  "SCIENCE_RED",
91 
92  "LINE_REFER_TABLE",
93  "FLUX_STD_TABLE",
94  "EXTCOEFF_TABLE",
95  "INSTR_RESPONSE_REDL",
96  "INSTR_RESPONSE_REDU",
97 
98  "MASTER_BIAS_REDL",
99  "MASTER_BIAS_REDU",
100  "MASTER_DARK_REDL",
101  "MASTER_DARK_REDU",
102  "MASTER_FLAT_REDL",
103  "MASTER_FLAT_REDU",
104 
105  "ORDER_TABLE_REDL",
106  "ORDER_TABLE_REDU",
107  "LINE_TABLE_REDL",
108  "LINE_TABLE_REDU",
109  "ORDER_GUESS_TAB_REDL",
110  "ORDER_GUESS_TAB_REDU",
111 
112  "DARK_BLUE",
113  "BIAS_BLUE",
114  "MASTER_BIAS_BLUE",
115  "IFLAT_BLUE",
116  "TFLAT_BLUE",
117  "ARC_LAMP_FORM_BLUE",
118  "ARC_LAMP_BLUE",
119  "STANDARD_BLUE",
120  "SCI_POINT_BLUE",
121  "SCIENCE_BLUE",
122 
123  "FLUX_STD_TABLE",
124  "EXTCOEFF_TABLE",
125  "INSTR_RESPONSE_BLUE",
126  "FLUX_STD_TABLE",
127  "EXTCOEFF_TABLE",
128  "INSTR_RESPONSE_BLUE",
129 
130  "ORDER_TABLE_BLUE",
131  "ORDER_FLAT_BLUE",
132  "ORDER_GUESS_TAB_BLUE",
133  "MASTER_BIAS_BLUE",
134  "MASTER_DARK_BLUE",
135  "MASTER_PDARK_BLUE",
136  "MASTER_FLAT_BLUE",
137  "ORDER_TABLE_BLUE",
138  "LINE_TABLE_BLUE",
139 
140 
141  "SFLAT_RED",
142  "FIB_ORDEF_RED",
143  "FIB_ARC_LAMP_FORM_RED",
144  "FIB_FF_ODD_RED",
145  "FIB_FF_EVEN_RED",
146  "FIB_FF_ALL_RED",
147  "FIB_ARC_LAMP_RED",
148  "FIB_FF_ODD_RED",
149  "FIB_FF_EVEN_RED",
150  "FIB_FF_ALL_RED",
151  "FIB_ARC_LAMP_RED",
152  "FIB_ORDEF_RED",
153  "FIB_ARC_LAMP_FORM_RED",
154  "FIB_SCI_RED",
155 
156 
157  "FIB_ORD_GUE_REDL",
158  "FIB_ORD_GUE_REDU",
159  "FIB_ORD_TAB_REDL",
160  "FIB_ORD_TAB_REDU",
161  "MASTER_SFLAT_REDL",
162  "MASTER_SFLAT_REDU",
163  "MASTER_SFLAT_REDL",
164  "MASTER_SFLAT_REDU",
165  "MASTER_SFLAT_REDL",
166  "MASTER_SFLAT_REDU",
167  "FIB_ORDEF_REDL",
168  "FIB_ORDEF_REDU",
169  "FIB_LIN_GUE_REDL",
170  "FIB_LIN_GUE_REDU",
171  "FIB_ORDEF_TABLE_REDL",
172  "FIB_ORDEF_TABLE_REDU",
173  "FIB_FF_BPC_REDL",
174  "FIB_FF_COM_REDL",
175  "FIB_FF_DTC_REDL",
176  "FIB_FF_NOR_REDL",
177  "FIB_FF_NSG_REDL",
178  "FIB_FF_SGC_REDL",
179  "FIB_FF_BPC_REDU",
180  "FIB_FF_COM_REDU",
181  "FIB_FF_DTC_REDU",
182  "FIB_FF_NOR_REDU",
183  "FIB_FF_NSG_REDU",
184  "FIB_FF_SGC_REDU",
185  "FIB_LINE_TABLE_REDL",
186  "FIB_LINE_TABLE_REDU",
187  "FIB_ORDEF_TABLE_REDL",
188  "FIB_ORDEF_TABLE_REDU",
189  "SLIT_FF_BNC_REDL",
190  "SLIT_FF_BPC_REDL",
191  "SLIT_FF_COM_REDL",
192  "SLIT_FF_DTC_REDL",
193  "SLIT_FF_NOR_REDL",
194  "SLIT_FF_SGC_REDL",
195  "SLIT_FF_BNC_REDU",
196  "SLIT_FF_BPC_REDU",
197  "SLIT_FF_COM_REDU",
198  "SLIT_FF_DTC_REDU",
199  "SLIT_FF_NOR_REDU",
200  "SLIT_FF_SGC_REDU"
201 
202  };
203 
204  cpl_pluginlist * pluginlist;
205  const size_t ntags = sizeof(tags) / sizeof(char*);
206 
207  char * old_dir = NULL;
208  char * new_dir = NULL;
209 
210  cpl_test_init_macro(LOG_FILE_NAME, PACKAGE_BUGREPORT, CPL_MSG_WARNING);
211  uves_msg("Hello world!");
212 
213  /* Save the current working directory. */
214  old_dir = cpl_malloc(1024*4);
215  cpl_test_assert(old_dir != NULL);
216  cpl_test_assert(getcwd(old_dir, 1024*4) != NULL);
217 
218  /* Create a new sub directory and change to that directory. */
219  new_dir = cpl_sprintf("%s/workdir_%s_pid%d", old_dir, TEST_NAME,
220  (int)getpid());
221  cpl_test_assert(new_dir != NULL);
222  cpl_msg_debug(cpl_func, "Changing current working directory to: %s",
223  new_dir);
224  cpl_test_assert(mkdir(new_dir, 0777) == 0);
225  cpl_test_assert(chdir(new_dir) == 0);
226 
227  /* Now we can run the plugin tests in their own directory without worrying
228  * that we will have any race conditions with other unit tests. */
229 
230  pluginlist = cpl_pluginlist_new();
231 
232  cpl_test(!cpl_plugin_get_info(pluginlist));
233 
234  cpl_test(!irplib_plugin_test(pluginlist, ntags, tags));
235 
236  cpl_pluginlist_delete(pluginlist);
237 
238  (void) system("rm -f "TEST_NAME"*.fits"); /* cleanup any FITS files. */
239 
240  /* Restore the current directory to the initial value and remove the
241  * temporary sub-directory if there were no unit test failures. */
242  cpl_msg_debug(cpl_func, "Restoring current working directory to: %s",
243  old_dir);
244  cpl_test_assert(chdir(old_dir) == 0);
245  cpl_free(old_dir);
246  if (cpl_test_get_failed() == 0) {
247  cpl_test_assert(rmdir(new_dir) == 0);
248  }
249  cpl_free(new_dir);
250 
251  return cpl_test_end(0);
252 }
253 
int main(void)
Find a plugin and submit it to some tests.
Definition: recipe_main.c:78
#define uves_msg(...)
Print a message on 'info' or 'debug' level.
Definition: uves_msg.h:119
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.