visir_recipes_test.c
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032
00033
00034
00035
00036 #include "visir_recipes_test.h"
00037
00038 #include <irplib_utils.h>
00039
00040 #include <math.h>
00041
00042
00043
00044
00045
00046
00047 static cpl_error_code visir_util_clip_test_one_fill_frameset(cpl_frameset *);
00048 static cpl_error_code visir_util_clip_test_one_save_imagelist(const char *);
00049 static cpl_error_code visir_util_clip_test_one_save_bpm(const char *);
00050
00051
00055
00056
00059
00060
00061
00062
00063
00064
00071
00072 void visir_util_clip_test_one(cpl_pluginlist * self) {
00073
00074 cpl_plugin * plugin;
00075 cpl_recipe * recipe;
00076 int (*recipe_create) (cpl_plugin *);
00077 int (*recipe_exec ) (cpl_plugin *);
00078 int (*recipe_deinit) (cpl_plugin *);
00079 cpl_error_code error;
00080
00081
00082 plugin = cpl_pluginlist_get_first(self);
00083 cpl_test_nonnull(plugin);
00084
00085 if (plugin == NULL) return;
00086
00087 recipe_create = cpl_plugin_get_init(plugin);
00088 cpl_test_nonnull( recipe_create);
00089
00090 recipe_exec = cpl_plugin_get_exec(plugin);
00091 cpl_test_nonnull( recipe_exec);
00092
00093 recipe_deinit = cpl_plugin_get_deinit(plugin);
00094 cpl_test_nonnull( recipe_deinit);
00095
00096
00097 cpl_test_eq(cpl_plugin_get_type(plugin), CPL_PLUGIN_TYPE_RECIPE);
00098
00099 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) return;
00100
00101 cpl_test_zero(recipe_create(plugin));
00102
00103 recipe = (cpl_recipe *) plugin;
00104
00105 cpl_test_nonnull( recipe->parameters );
00106
00107 recipe->frames = cpl_frameset_new();
00108
00109 error = visir_util_clip_test_one_fill_frameset(recipe->frames);
00110 cpl_test_eq_error(error, CPL_ERROR_NONE);
00111
00112 error = recipe_exec(plugin);
00113
00114 cpl_test_eq_error(error, CPL_ERROR_NONE);
00115
00116 cpl_frameset_delete(recipe->frames);
00117
00118 error = recipe_deinit(plugin);
00119 cpl_test_eq_error(error, CPL_ERROR_NONE);
00120
00121 return;
00122 }
00123
00126 static
00127 cpl_error_code visir_util_clip_test_one_fill_frameset(cpl_frameset * self)
00128 {
00129
00130 cpl_frame * frame = cpl_frame_new();
00131 const char * filename = "visir_util_clip_one.fits";
00132 const char * bpmname = "visir_util_clip_one_bpm.fits";
00133
00134 bug_if(self == NULL);
00135
00136 bug_if(visir_util_clip_test_one_save_imagelist(filename));
00137 bug_if(visir_util_clip_test_one_save_bpm(bpmname));
00138
00139 bug_if(cpl_frame_set_filename(frame, filename));
00140 bug_if(cpl_frame_set_tag(frame, "RAW"));
00141
00142 bug_if(cpl_frameset_insert(self, frame));
00143
00144 frame = cpl_frame_new();
00145
00146 bug_if(cpl_frame_set_filename(frame, bpmname));
00147 bug_if(cpl_frame_set_tag(frame, "BPM"));
00148
00149 bug_if(cpl_frameset_insert(self, frame));
00150 frame = NULL;
00151
00152 end_skip;
00153
00154 cpl_frame_delete(frame);
00155
00156 return cpl_error_get_code();
00157
00158 }
00159
00160
00161 static
00162 cpl_error_code visir_util_clip_test_one_save_imagelist(const char * filename)
00163 {
00164
00165 cpl_image * image = cpl_image_new(1, 1, CPL_TYPE_FLOAT);
00166 int i;
00167
00168 skip_if(cpl_propertylist_save(NULL, filename, CPL_IO_CREATE));
00169
00170 for (i = 0; i < 300; i++) {
00171 double value;
00172 if (i > 270) {
00173 value = 2.0;
00174 } else {
00175 const double x = 3.0 * (i - 135) / 135.0;
00176 value = 1.0 / (CPL_MATH_SQRT2PI * exp(x * x / 2.0));
00177 }
00178 bug_if(cpl_image_set(image, 1, 1, value));
00179
00180 skip_if(cpl_image_save(image, filename, CPL_TYPE_FLOAT, NULL,
00181 CPL_IO_EXTEND));
00182 }
00183
00184 end_skip;
00185
00186 cpl_image_delete(image);
00187
00188 return cpl_error_get_code();
00189
00190 }
00191
00192
00193 static
00194 cpl_error_code visir_util_clip_test_one_save_bpm(const char * filename)
00195 {
00196
00197 cpl_image * image = cpl_image_new(1, 1, CPL_TYPE_INT);
00198 int i;
00199
00200 skip_if(cpl_propertylist_save(NULL, filename, CPL_IO_CREATE));
00201
00202 for (i = 0; i < 300; i++) {
00203
00204 skip_if(cpl_image_save(image, filename, CPL_TYPE_FLOAT, NULL,
00205 CPL_IO_EXTEND));
00206 }
00207
00208 end_skip;
00209
00210 cpl_image_delete(image);
00211
00212 return cpl_error_get_code();
00213
00214 }