VISIR Pipeline Reference Manual  4.1.0
visir_recipes_test.c
1 /* $Id: visir_recipes_test.c,v 1.3 2012-03-20 12:38:51 llundin Exp $
2  *
3  * This file is part of the VISIR Pipeline
4  * Copyright (C) 20011 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: llundin $
23  * $Date: 2012-03-20 12:38:51 $
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 "visir_recipes_test.h"
37 
38 #include <irplib_utils.h>
39 
40 #include <math.h>
41 
42 
43 /*-----------------------------------------------------------------------------
44  Private Functions prototypes
45  -----------------------------------------------------------------------------*/
46 
47 static cpl_error_code visir_util_clip_test_one_fill_frameset(cpl_frameset *);
48 static cpl_error_code visir_util_clip_test_one_save_imagelist(const char *);
49 static cpl_error_code visir_util_clip_test_one_save_bpm(const char *);
50 
51 /*----------------------------------------------------------------------------*/
55 /*----------------------------------------------------------------------------*/
56 
59 /*-----------------------------------------------------------------------------
60  Function definitions
61  -----------------------------------------------------------------------------*/
62 
63 
64 /*----------------------------------------------------------------------------*/
71 /*----------------------------------------------------------------------------*/
72 void visir_util_clip_test_one(cpl_pluginlist * self) {
73 
74  cpl_plugin * plugin;
75  cpl_recipe * recipe;
76  int (*recipe_create) (cpl_plugin *);
77  int (*recipe_exec ) (cpl_plugin *);
78  int (*recipe_deinit) (cpl_plugin *);
79  cpl_error_code error;
80 
81 
82  plugin = cpl_pluginlist_get_first(self);
83  cpl_test_nonnull(plugin);
84 
85  if (plugin == NULL) return;
86 
87  recipe_create = cpl_plugin_get_init(plugin);
88  cpl_test( recipe_create != NULL);
89 
90  recipe_exec = cpl_plugin_get_exec(plugin);
91  cpl_test( recipe_exec != NULL);
92 
93  recipe_deinit = cpl_plugin_get_deinit(plugin);
94  cpl_test( recipe_deinit != NULL);
95 
96  /* Only plugins of type recipe are tested (further) */
97  cpl_test_eq(cpl_plugin_get_type(plugin), CPL_PLUGIN_TYPE_RECIPE);
98 
99  if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) return;
100 
101  cpl_test_zero(recipe_create(plugin));
102 
103  recipe = (cpl_recipe *) plugin;
104 
105  cpl_test_nonnull( recipe->parameters );
106 
107  recipe->frames = cpl_frameset_new();
108 
109  error = visir_util_clip_test_one_fill_frameset(recipe->frames);
110  cpl_test_eq_error(error, CPL_ERROR_NONE);
111 
112  error = recipe_exec(plugin);
113 
114  cpl_test_eq_error(error, CPL_ERROR_NONE);
115 
116  cpl_frameset_delete(recipe->frames);
117 
118  error = recipe_deinit(plugin);
119  cpl_test_eq_error(error, CPL_ERROR_NONE);
120 
121  return;
122 }
123 
126 static
127 cpl_error_code visir_util_clip_test_one_fill_frameset(cpl_frameset * self)
128 {
129 
130  cpl_frame * frame = cpl_frame_new();
131  const char * filename = "visir_util_clip_one.fits";
132  const char * bpmname = "visir_util_clip_one_bpm.fits";
133 
134  bug_if(self == NULL);
135 
136  bug_if(visir_util_clip_test_one_save_imagelist(filename));
137  bug_if(visir_util_clip_test_one_save_bpm(bpmname));
138 
139  bug_if(cpl_frame_set_filename(frame, filename));
140  bug_if(cpl_frame_set_tag(frame, "RAW"));
141 
142  bug_if(cpl_frameset_insert(self, frame));
143 
144  frame = cpl_frame_new();
145 
146  bug_if(cpl_frame_set_filename(frame, bpmname));
147  bug_if(cpl_frame_set_tag(frame, "BPM"));
148 
149  bug_if(cpl_frameset_insert(self, frame));
150  frame = NULL;
151 
152  end_skip;
153 
154  cpl_frame_delete(frame);
155 
156  return cpl_error_get_code();
157 
158 }
159 
160 
161 static
162 cpl_error_code visir_util_clip_test_one_save_imagelist(const char * filename)
163 {
164 
165  cpl_image * image = cpl_image_new(1, 1, CPL_TYPE_FLOAT);
166  int i;
167 
168  skip_if(cpl_propertylist_save(NULL, filename, CPL_IO_CREATE));
169 
170  for (i = 0; i < 300; i++) {
171  double value;
172  if (i > 270) {
173  value = 2.0;
174  } else {
175  const double x = 3.0 * (i - 135) / 135.0; /* sigma = 3 */
176  value = 1.0 / (CPL_MATH_SQRT2PI * exp(x * x / 2.0));
177  }
178  bug_if(cpl_image_set(image, 1, 1, value));
179 
180  skip_if(cpl_image_save(image, filename, CPL_TYPE_FLOAT, NULL,
181  CPL_IO_EXTEND));
182  }
183 
184  end_skip;
185 
186  cpl_image_delete(image);
187 
188  return cpl_error_get_code();
189 
190 }
191 
192 
193 static
194 cpl_error_code visir_util_clip_test_one_save_bpm(const char * filename)
195 {
196 
197  cpl_image * image = cpl_image_new(1, 1, CPL_TYPE_INT);
198  int i;
199 
200  skip_if(cpl_propertylist_save(NULL, filename, CPL_IO_CREATE));
201 
202  for (i = 0; i < 300; i++) {
203 
204  skip_if(cpl_image_save(image, filename, CPL_TYPE_FLOAT, NULL,
205  CPL_IO_EXTEND));
206  }
207 
208  end_skip;
209 
210  cpl_image_delete(image);
211 
212  return cpl_error_get_code();
213 
214 }
void visir_util_clip_test_one(cpl_pluginlist *self)
Find a plugin and submit it to some tests.