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
00029
00030
00031
00032 #ifdef HAVE_CONFIG_H
00033 #include <config.h>
00034 #endif
00035
00036 #include <string.h>
00037 #include <stdlib.h>
00038 #include <assert.h>
00039
00040 #include <cpl.h>
00041
00042
00043 #include "irplib_plugin.h"
00044
00045
00055
00056
00057
00058
00059
00060
00061
00062 #ifndef LINE_LEN_MAX
00063 #define LINE_LEN_MAX 1024
00064 #endif
00065
00066
00067 #define DEV_RANDOM "/dev/urandom"
00068
00069
00070 #define recipe_assert(bool) \
00071 ((bool) ? (cpl_msg_debug(cpl_func, \
00072 "OK in " __FILE__ " line %d (CPL-error state: '%s' in %s): %s",__LINE__, \
00073 cpl_error_get_message(), cpl_error_get_where(), #bool), 0) \
00074 : (cpl_msg_error(cpl_func, \
00075 "Failure in " __FILE__ " line %d (CPL-error state: '%s' in %s): %s", \
00076 __LINE__, cpl_error_get_message(), cpl_error_get_where(), #bool), 1))
00077
00078
00079
00080
00081
00082
00083
00084 static const cpl_parameter * irplib_parameterlist_get(const cpl_parameterlist *,
00085 const char *,
00086 const char *,
00087 const char *);
00088
00089 static void recipe_parameterlist_set(cpl_parameterlist *);
00090 static void recipe_frameset_load(cpl_frameset *, const char *);
00091
00092 static int recipe_sof_test_random(cpl_plugin *, size_t, const char *[]);
00093 static int recipe_sof_test_image_empty(cpl_plugin *, size_t, const char *[]);
00094 static int recipe_sof_test_local(cpl_plugin *);
00095 static int recipe_sof_test_from_env(cpl_plugin *);
00096 static void recipe_frameset_empty(cpl_frameset *);
00097
00098 static cpl_errorstate inistate;
00099
00102
00103
00104
00105
00106
00116
00117 const char * irplib_parameterlist_get_string(const cpl_parameterlist * self,
00118 const char * instrume,
00119 const char * recipe,
00120 const char * parameter)
00121 {
00122
00123 const cpl_parameter * par = irplib_parameterlist_get(self, instrume,
00124 recipe, parameter);
00125 const char * value;
00126
00127 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0);
00128 cpl_ensure(instrume != NULL, CPL_ERROR_NULL_INPUT, 0);
00129 cpl_ensure(recipe != NULL, CPL_ERROR_NULL_INPUT, 0);
00130 cpl_ensure(parameter != NULL, CPL_ERROR_NULL_INPUT, 0);
00131
00132 #if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
00133 cpl_error_ensure(par != NULL, CPL_ERROR_DATA_NOT_FOUND, return(NULL),
00134 "instrume=%s, recipe=%s, parameter=%s", instrume, recipe,
00135 parameter);
00136 #else
00137 cpl_ensure(par != NULL, CPL_ERROR_DATA_NOT_FOUND, NULL);
00138 #endif
00139
00140 cpl_ensure(cpl_parameter_get_type(par) == CPL_TYPE_STRING,
00141 CPL_ERROR_TYPE_MISMATCH, NULL);
00142
00143 value = cpl_parameter_get_string(par);
00144
00145 cpl_ensure(value != NULL, cpl_error_get_code(), NULL);
00146
00147 return value;
00148
00149 }
00150
00151
00161
00162 cpl_boolean irplib_parameterlist_get_bool(const cpl_parameterlist * self,
00163 const char * instrume,
00164 const char * recipe,
00165 const char * parameter)
00166 {
00167
00168 const cpl_parameter * par = irplib_parameterlist_get(self, instrume,
00169 recipe, parameter);
00170 cpl_errorstate prestate = cpl_errorstate_get();
00171 cpl_boolean value;
00172
00173 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0);
00174 cpl_ensure(instrume != NULL, CPL_ERROR_NULL_INPUT, 0);
00175 cpl_ensure(recipe != NULL, CPL_ERROR_NULL_INPUT, 0);
00176 cpl_ensure(parameter != NULL, CPL_ERROR_NULL_INPUT, 0);
00177
00178 #if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
00179 cpl_error_ensure(par != NULL, CPL_ERROR_DATA_NOT_FOUND, return(CPL_FALSE),
00180 "instrume=%s, recipe=%s, parameter=%s", instrume, recipe,
00181 parameter);
00182 #else
00183 cpl_ensure(par != NULL, CPL_ERROR_DATA_NOT_FOUND, CPL_FALSE);
00184 #endif
00185
00186
00187 cpl_ensure(cpl_parameter_get_type(par) == CPL_TYPE_BOOL,
00188 CPL_ERROR_TYPE_MISMATCH, CPL_FALSE);
00189
00190 value = cpl_parameter_get_bool(par);
00191
00192 if (!cpl_errorstate_is_equal(prestate)) (void)cpl_error_set_where(cpl_func);
00193
00194 return value;
00195
00196 }
00197
00198
00199
00209
00210 int irplib_parameterlist_get_int(const cpl_parameterlist * self,
00211 const char * instrume,
00212 const char * recipe,
00213 const char * parameter)
00214 {
00215
00216 const cpl_parameter * par = irplib_parameterlist_get(self, instrume,
00217 recipe, parameter);
00218 cpl_errorstate prestate = cpl_errorstate_get();
00219 int value;
00220
00221 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0);
00222 cpl_ensure(instrume != NULL, CPL_ERROR_NULL_INPUT, 0);
00223 cpl_ensure(recipe != NULL, CPL_ERROR_NULL_INPUT, 0);
00224 cpl_ensure(parameter != NULL, CPL_ERROR_NULL_INPUT, 0);
00225
00226 #if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
00227 cpl_error_ensure(par != NULL, CPL_ERROR_DATA_NOT_FOUND, return(0),
00228 "instrume=%s, recipe=%s, parameter=%s", instrume, recipe,
00229 parameter);
00230 #else
00231 cpl_ensure(par != NULL, CPL_ERROR_DATA_NOT_FOUND, 0);
00232 #endif
00233
00234 cpl_ensure(cpl_parameter_get_type(par) == CPL_TYPE_INT,
00235 CPL_ERROR_TYPE_MISMATCH, 0);
00236
00237 value = cpl_parameter_get_int(par);
00238
00239 if (!cpl_errorstate_is_equal(prestate)) (void)cpl_error_set_where(cpl_func);
00240
00241 return value;
00242 }
00243
00244
00254
00255 double irplib_parameterlist_get_double(const cpl_parameterlist * self,
00256 const char * instrume,
00257 const char * recipe,
00258 const char * parameter)
00259 {
00260
00261 const cpl_parameter * par = irplib_parameterlist_get(self, instrume,
00262 recipe, parameter);
00263 cpl_errorstate prestate = cpl_errorstate_get();
00264 double value;
00265
00266 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0);
00267 cpl_ensure(instrume != NULL, CPL_ERROR_NULL_INPUT, 0);
00268 cpl_ensure(recipe != NULL, CPL_ERROR_NULL_INPUT, 0);
00269 cpl_ensure(parameter != NULL, CPL_ERROR_NULL_INPUT, 0);
00270
00271 #if defined CPL_HAVE_VA_ARGS && CPL_HAVE_VA_ARGS != 0
00272 cpl_error_ensure(par != NULL, CPL_ERROR_DATA_NOT_FOUND, return(0.0),
00273 "instrume=%s, recipe=%s, parameter=%s", instrume, recipe,
00274 parameter);
00275 #else
00276 cpl_ensure(par != NULL, CPL_ERROR_DATA_NOT_FOUND, 0.0);
00277 #endif
00278
00279 cpl_ensure(cpl_parameter_get_type(par) == CPL_TYPE_DOUBLE,
00280 CPL_ERROR_TYPE_MISMATCH, 0.0);
00281
00282 value = cpl_parameter_get_double(par);
00283
00284 if (!cpl_errorstate_is_equal(prestate)) (void)cpl_error_set_where(cpl_func);
00285
00286 return value;
00287 }
00288
00289
00303
00304 cpl_error_code irplib_parameterlist_set_string(cpl_parameterlist * self,
00305 const char * instrume,
00306 const char * recipe,
00307 const char * parameter,
00308 const char * defvalue,
00309 const char * alias,
00310 const char * context,
00311 const char * man)
00312 {
00313
00314 cpl_error_code error;
00315 cpl_parameter * par;
00316 char * paramname = cpl_sprintf("%s.%s.%s", instrume, recipe,
00317 parameter);
00318
00319 cpl_ensure_code(paramname != NULL, cpl_error_get_code());
00320
00321 par = cpl_parameter_new_value(paramname, CPL_TYPE_STRING, man, context,
00322 defvalue);
00323 cpl_free(paramname);
00324
00325 cpl_ensure_code(par != NULL, cpl_error_get_code());
00326
00327 error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI, alias);
00328 cpl_ensure_code(!error, error);
00329
00330 error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
00331 cpl_ensure_code(!error, error);
00332
00333 error = cpl_parameterlist_append(self, par);
00334 cpl_ensure_code(!error, error);
00335
00336 return CPL_ERROR_NONE;
00337 }
00338
00339
00340
00354
00355 cpl_error_code irplib_parameterlist_set_bool(cpl_parameterlist * self,
00356 const char * instrume,
00357 const char * recipe,
00358 const char * parameter,
00359 cpl_boolean defvalue,
00360 const char * alias,
00361 const char * context,
00362 const char * man)
00363 {
00364
00365 cpl_error_code error;
00366 cpl_parameter * par;
00367 char * paramname = cpl_sprintf("%s.%s.%s", instrume, recipe,
00368 parameter);
00369
00370 cpl_ensure_code(paramname != NULL, cpl_error_get_code());
00371
00372 par = cpl_parameter_new_value(paramname, CPL_TYPE_BOOL, man, context,
00373 defvalue);
00374 cpl_free(paramname);
00375
00376 cpl_ensure_code(par != NULL, cpl_error_get_code());
00377
00378 error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI, alias);
00379 cpl_ensure_code(!error, error);
00380
00381 error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
00382 cpl_ensure_code(!error, error);
00383
00384 error = cpl_parameterlist_append(self, par);
00385 cpl_ensure_code(!error, error);
00386
00387 return CPL_ERROR_NONE;
00388 }
00389
00390
00391
00392
00406
00407 cpl_error_code irplib_parameterlist_set_int(cpl_parameterlist * self,
00408 const char * instrume,
00409 const char * recipe,
00410 const char * parameter,
00411 int defvalue,
00412 const char * alias,
00413 const char * context,
00414 const char * man)
00415 {
00416
00417 cpl_error_code error;
00418 cpl_parameter * par;
00419 char * paramname = cpl_sprintf("%s.%s.%s", instrume, recipe,
00420 parameter);
00421
00422 cpl_ensure_code(paramname != NULL, cpl_error_get_code());
00423
00424 par = cpl_parameter_new_value(paramname, CPL_TYPE_INT, man, context,
00425 defvalue);
00426 cpl_free(paramname);
00427
00428 cpl_ensure_code(par != NULL, cpl_error_get_code());
00429
00430 error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI, alias);
00431 cpl_ensure_code(!error, error);
00432
00433 error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
00434 cpl_ensure_code(!error, error);
00435
00436 error = cpl_parameterlist_append(self, par);
00437 cpl_ensure_code(!error, error);
00438
00439 return CPL_ERROR_NONE;
00440 }
00441
00442
00443
00457
00458 cpl_error_code irplib_parameterlist_set_double(cpl_parameterlist * self,
00459 const char * instrume,
00460 const char * recipe,
00461 const char * parameter,
00462 double defvalue,
00463 const char * alias,
00464 const char * context,
00465 const char * man)
00466 {
00467
00468 cpl_error_code error;
00469 cpl_parameter * par;
00470 char * paramname = cpl_sprintf("%s.%s.%s", instrume, recipe,
00471 parameter);
00472
00473 cpl_ensure_code(paramname != NULL, cpl_error_get_code());
00474
00475 par = cpl_parameter_new_value(paramname, CPL_TYPE_DOUBLE, man, context,
00476 defvalue);
00477 cpl_free(paramname);
00478
00479 cpl_ensure_code(par != NULL, cpl_error_get_code());
00480
00481 error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI, alias);
00482 cpl_ensure_code(!error, error);
00483
00484 error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
00485 cpl_ensure_code(!error, error);
00486
00487 error = cpl_parameterlist_append(self, par);
00488 cpl_ensure_code(!error, error);
00489
00490 return CPL_ERROR_NONE;
00491 }
00492
00493
00494
00506
00507 int irplib_plugin_test(cpl_pluginlist * self, size_t nstr, const char *astr[]) {
00508
00509 cpl_plugin * plugin;
00510 cpl_recipe * recipe;
00511 int (*recipe_create) (cpl_plugin *);
00512 int (*recipe_exec ) (cpl_plugin *);
00513 int (*recipe_deinit) (cpl_plugin *);
00514 const cpl_msg_severity msg_level = cpl_msg_get_level();
00515
00516 int recipe_nfail = 0;
00517 cpl_errorstate prestate;
00518 FILE * stream;
00519 cpl_boolean is_debug;
00520
00521
00522
00523
00524 if (getenv("CPL_MSG_LEVEL") == NULL) cpl_msg_set_level(CPL_MSG_OFF);
00525
00526 is_debug = cpl_msg_get_level() <= CPL_MSG_DEBUG ? CPL_TRUE : CPL_FALSE;
00527
00528
00529 stream = is_debug ? stdout : fopen("/dev/null", "a");
00530
00531 inistate = cpl_errorstate_get();
00532
00533 assert( nstr == 0 || astr != NULL );
00534
00535 plugin = cpl_pluginlist_get_first(self);
00536
00537 if (plugin == NULL) {
00538 cpl_msg_warning(cpl_func, "With an empty pluginlist, "
00539 "no tests can be made");
00540 cpl_msg_set_level(msg_level);
00541 return 0;
00542 }
00543
00544 cpl_plugin_dump(plugin, stream);
00545
00546 recipe_create = cpl_plugin_get_init(plugin);
00547 recipe_exec = cpl_plugin_get_exec(plugin);
00548 recipe_deinit = cpl_plugin_get_deinit(plugin);
00549
00550
00551 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
00552 cpl_msg_warning(cpl_func, "This plugin is not of type recipe, "
00553 "cannot test further");
00554 cpl_msg_set_level(msg_level);
00555 return 0;
00556 }
00557
00558 recipe_nfail += recipe_assert( recipe_create(plugin) == 0);
00559
00560 recipe = (cpl_recipe *) plugin;
00561
00562 recipe_nfail += recipe_assert( recipe->parameters != NULL);
00563
00564 recipe_parameterlist_set(recipe->parameters);
00565
00566 cpl_parameterlist_dump(recipe->parameters, stream);
00567
00568 recipe->frames = cpl_frameset_new();
00569
00570 cpl_msg_info(cpl_func,"Checking handling of pre-existing CPL error state - "
00571 "may produce warning(s)/error(s):");
00572 cpl_error_set(cpl_func, CPL_ERROR_UNSPECIFIED);
00573 prestate = cpl_errorstate_get();
00574
00575 recipe_nfail += recipe_assert( recipe_exec(plugin) != 0 );
00576
00577 recipe_nfail += recipe_assert( cpl_error_get_code() == CPL_ERROR_UNSPECIFIED );
00578
00579 if (!cpl_errorstate_is_equal(prestate)) {
00580 cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
00581 cpl_msg_debug(cpl_func, "Resetting error state");
00582 cpl_errorstate_set(prestate);
00583 }
00584
00585 cpl_errorstate_set(inistate);
00586
00587 cpl_msg_info(cpl_func,"Checking handling of empty frameset - "
00588 "may produce warning(s)/error(s):");
00589
00590 recipe_nfail += recipe_assert( recipe_exec(plugin) != 0 );
00591
00592 recipe_nfail += recipe_assert( cpl_error_get_code() != CPL_ERROR_NONE );
00593
00594 if (cpl_errorstate_is_equal(inistate)) {
00595 recipe_nfail += recipe_assert( !cpl_errorstate_is_equal(inistate) );
00596 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00597 } else if (is_debug) {
00598 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00599 }
00600 cpl_msg_debug(cpl_func, "Resetting error state");
00601 cpl_errorstate_set(inistate);
00602
00603 cpl_msg_info(cpl_func,"Checking handling of dummy frameset - "
00604 "may produce warning(s)/error(s):");
00605 do {
00606 cpl_frame * f = cpl_frame_new();
00607 recipe_nfail += recipe_assert( cpl_frame_set_filename(f, "/dev/null") == 0);
00608 recipe_nfail += recipe_assert( cpl_frame_set_tag(f, "RECIPE_DUMMY_TAG") == 0);
00609 recipe_nfail += recipe_assert( cpl_frameset_insert(recipe->frames, f) == 0);
00610
00611 if (!cpl_errorstate_is_equal(inistate)) {
00612 cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
00613 cpl_msg_debug(cpl_func, "Resetting error state");
00614 cpl_errorstate_set(inistate);
00615 }
00616
00617
00618 recipe_nfail += recipe_assert( recipe_exec(plugin) != 0 );
00619
00620 recipe_nfail += recipe_assert( cpl_error_get_code() != CPL_ERROR_NONE );
00621
00622 if (cpl_errorstate_is_equal(inistate)) {
00623 recipe_nfail += recipe_assert( !cpl_errorstate_is_equal(inistate) );
00624 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00625 } else if (is_debug) {
00626 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00627 }
00628 cpl_msg_debug(cpl_func, "Resetting error state");
00629 cpl_errorstate_set(inistate);
00630
00631 recipe_nfail += recipe_assert( cpl_frameset_erase_frame(recipe->frames, f)
00632 == CPL_ERROR_NONE );
00633
00634 } while (0);
00635
00636 recipe_nfail += recipe_sof_test_random(plugin, nstr, astr);
00637
00638 recipe_nfail += recipe_sof_test_image_empty(plugin, nstr, astr);
00639
00640 recipe_nfail += recipe_sof_test_local(plugin);
00641
00642 recipe_nfail += recipe_sof_test_from_env(plugin);
00643
00644 cpl_frameset_delete(recipe->frames);
00645
00646 recipe_nfail += recipe_assert( recipe_deinit(plugin) == 0 );
00647
00648 recipe_nfail += recipe_assert( cpl_error_get_code() == CPL_ERROR_NONE );
00649
00650 if (recipe_nfail) cpl_msg_error(cpl_func, "%d test(s) failed", recipe_nfail);
00651
00652 cpl_msg_set_level(msg_level);
00653
00654 if (stream != stdout) fclose(stream);
00655
00656 return recipe_nfail;
00657 }
00658
00661
00671
00672 static void recipe_parameterlist_set(cpl_parameterlist * self)
00673 {
00674
00675 cpl_parameter * p = cpl_parameterlist_get_first(self);
00676
00677 for (; p != NULL; p = cpl_parameterlist_get_next(self)) {
00678
00679 const char * envvar;
00680 const char * svalue;
00681
00682
00683 if (cpl_parameter_get_default_flag(p)) continue;
00684
00685 cpl_msg_debug(cpl_func, __FILE__ " line %u: OK", __LINE__);
00686
00687 envvar = cpl_parameter_get_alias(p, CPL_PARAMETER_MODE_ENV);
00688 svalue = envvar ? getenv(envvar) : NULL;
00689
00690 switch (cpl_parameter_get_type(p)) {
00691 case CPL_TYPE_BOOL: {
00692 const int value
00693 = svalue ? atoi(svalue) : cpl_parameter_get_default_bool(p);
00694 cpl_parameter_set_bool(p, value);
00695 break;
00696 }
00697 case CPL_TYPE_INT: {
00698 const int value
00699 = svalue ? atoi(svalue) : cpl_parameter_get_default_int(p);
00700 cpl_parameter_set_int(p, value);
00701 break;
00702 }
00703 case CPL_TYPE_DOUBLE: {
00704 const double value
00705 = svalue ? atof(svalue) : cpl_parameter_get_default_double(p);
00706 cpl_parameter_set_double(p, value);
00707 break;
00708 }
00709 case CPL_TYPE_STRING:
00710 {
00711 const char * s_default = cpl_parameter_get_default_string(p);
00712
00713 const char * value
00714 = svalue ? svalue : (s_default ? s_default : "");
00715 cpl_parameter_set_string(p, value);
00716 break;
00717 }
00718
00719 default:
00720 assert( 0 );
00721 }
00722 }
00723 }
00724
00725
00726
00733
00734 static int recipe_sof_test_random(cpl_plugin * plugin, size_t nstr,
00735 const char *astr[])
00736 {
00737 cpl_recipe * recipe = (cpl_recipe*)plugin;
00738
00739 int (*recipe_exec) (cpl_plugin *);
00740
00741
00742 int recipe_nfail = 0;
00743 size_t i;
00744
00745
00746 if (nstr < 1) return recipe_nfail;
00747
00748 cpl_msg_info(cpl_func, "Testing recipe with %u " DEV_RANDOM " as input ",
00749 (unsigned)nstr);
00750
00751 for (i = 0; i < nstr; i++) {
00752 cpl_frame * f = cpl_frame_new();
00753
00754 recipe_nfail += recipe_assert( cpl_frame_set_filename(f, DEV_RANDOM) == 0);
00755 recipe_nfail += recipe_assert( cpl_frame_set_tag(f, astr[i]) == 0);
00756 recipe_nfail += recipe_assert( cpl_frameset_insert(recipe->frames, f) == 0);
00757 }
00758
00759 recipe_exec = cpl_plugin_get_exec(plugin);
00760
00761 if (!cpl_errorstate_is_equal(inistate)) {
00762 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00763 cpl_msg_debug(cpl_func, "Resetting error state");
00764 cpl_errorstate_set(inistate);
00765 }
00766
00767
00768 recipe_nfail += recipe_assert( recipe_exec(plugin) != 0 );
00769
00770 recipe_nfail += recipe_assert( cpl_error_get_code() != CPL_ERROR_NONE );
00771
00772 if (cpl_errorstate_is_equal(inistate)) {
00773 recipe_nfail += recipe_assert( !cpl_errorstate_is_equal(inistate) );
00774 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00775 } else if (cpl_msg_get_level() <= CPL_MSG_DEBUG) {
00776 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00777 }
00778 cpl_msg_debug(cpl_func, "Resetting error state");
00779 cpl_errorstate_set(inistate);
00780
00781 recipe_frameset_empty(recipe->frames);
00782
00783 return recipe_nfail;
00784 }
00785
00786
00787
00794
00795 static int recipe_sof_test_image_empty(cpl_plugin * plugin, size_t nstr,
00796 const char *astr[])
00797 {
00798 cpl_recipe * recipe = (cpl_recipe*)plugin;
00799
00800 int (*recipe_exec) (cpl_plugin *);
00801
00802
00803 int recipe_nfail = 0;
00804 size_t i;
00805 cpl_frame * frame;
00806 cpl_image * iempty;
00807
00808
00809 if (nstr < 1) return recipe_nfail;
00810
00811 cpl_msg_info(cpl_func, "Testing recipe with %u empty images as input ",
00812 (unsigned)nstr);
00813
00814 iempty = cpl_image_new(13, 17, CPL_TYPE_FLOAT);
00815
00816 for (i = 0; i < nstr; i++) {
00817 cpl_frame * f = cpl_frame_new();
00818 char * rawname = cpl_sprintf("raw%05u.fits", (unsigned)(i+1));
00819
00820 recipe_nfail += recipe_assert( cpl_image_save(iempty, rawname,
00821 CPL_BPP_IEEE_FLOAT, NULL,
00822 CPL_IO_DEFAULT) == 0);
00823
00824 recipe_nfail += recipe_assert( cpl_frame_set_filename(f, rawname) == 0);
00825 recipe_nfail += recipe_assert( cpl_frame_set_tag(f, astr[i]) == 0);
00826 recipe_nfail += recipe_assert( cpl_frameset_insert(recipe->frames, f) == 0);
00827
00828 cpl_free(rawname);
00829 }
00830 cpl_image_delete(iempty);
00831
00832 recipe_exec = cpl_plugin_get_exec(plugin);
00833
00834 if (!cpl_errorstate_is_equal(inistate)) {
00835 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00836 cpl_msg_debug(cpl_func, "Resetting error state");
00837 cpl_errorstate_set(inistate);
00838 }
00839
00840
00841 recipe_nfail += recipe_assert( recipe_exec(plugin) != 0 );
00842
00843 recipe_nfail += recipe_assert( cpl_error_get_code() != CPL_ERROR_NONE );
00844
00845 if (cpl_errorstate_is_equal(inistate)) {
00846 recipe_nfail += recipe_assert( !cpl_errorstate_is_equal(inistate) );
00847 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00848 } else if (cpl_msg_get_level() <= CPL_MSG_DEBUG) {
00849 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00850 }
00851 cpl_msg_debug(cpl_func, "Resetting error state");
00852 cpl_errorstate_set(inistate);
00853
00854 for (frame = cpl_frameset_get_first(recipe->frames); frame != NULL;
00855 frame = cpl_frameset_get_first(recipe->frames))
00856 {
00857 recipe_nfail +=
00858 recipe_assert( remove(cpl_frame_get_filename(frame)) == 0);
00859 cpl_frameset_erase_frame(recipe->frames, frame);
00860 }
00861
00862 return recipe_nfail;
00863 }
00864
00865
00866
00873
00874 static int recipe_sof_test_from_env(cpl_plugin * plugin)
00875 {
00876 cpl_recipe * recipe = (cpl_recipe*)plugin;
00877 const char * recipename = cpl_plugin_get_name(plugin);
00878 const char * var_name = "RECIPE_SOF_PATH";
00879 const char * sof_path = getenv(var_name);
00880
00881
00882 int recipe_nfail = 0;
00883
00884 char * sof_name;
00885
00886 if (sof_path == NULL) {
00887 cpl_msg_warning(cpl_func, "Environment variable %s is unset: "
00888 "No SOFs to check", var_name);
00889 return recipe_nfail;
00890 }
00891
00892 cpl_msg_debug(cpl_func, "Checking for SOFs in %s", sof_path);
00893
00894 if (recipename == NULL) {
00895 recipe_nfail += recipe_assert(recipename != NULL);
00896 return recipe_nfail;
00897 }
00898
00899 sof_name = cpl_sprintf("%s/%s.sof", sof_path, recipename);
00900
00901 cpl_msg_debug(cpl_func, "Checking for SOF %s", sof_name);
00902
00903 recipe_frameset_load(recipe->frames, sof_name);
00904
00905 if (!cpl_frameset_is_empty(recipe->frames)) {
00906
00907 int (*recipe_exec ) (cpl_plugin *);
00908
00909 recipe_exec = cpl_plugin_get_exec(plugin);
00910
00911 cpl_msg_info(cpl_func,"Checking handling of SOF: %s", sof_name);
00912 recipe_nfail += recipe_assert( recipe_exec(plugin) == 0 );
00913 recipe_nfail += recipe_assert( cpl_error_get_code() == CPL_ERROR_NONE );
00914
00915 if (!cpl_errorstate_is_equal(inistate)) {
00916 recipe_nfail += recipe_assert( cpl_errorstate_is_equal(inistate) );
00917 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00918 cpl_msg_debug(cpl_func, "Resetting error state");
00919 cpl_errorstate_set(inistate);
00920 }
00921
00922 recipe_frameset_empty(recipe->frames);
00923 }
00924
00925 cpl_free(sof_name);
00926
00927 return recipe_nfail;
00928 }
00929
00930
00931
00932
00939
00940 static int recipe_sof_test_local(cpl_plugin * plugin)
00941 {
00942 cpl_recipe * recipe = (cpl_recipe*)plugin;
00943 const char * recipename = cpl_plugin_get_name(plugin);
00944
00945
00946 int recipe_nfail = 0;
00947
00948 char * sof_name = cpl_sprintf("%s.sof", recipename);
00949
00950 cpl_msg_debug(cpl_func, "Checking for SOF %s", sof_name);
00951
00952 recipe_frameset_load(recipe->frames, sof_name);
00953
00954 if (!cpl_frameset_is_empty(recipe->frames)) {
00955
00956 int (*recipe_exec ) (cpl_plugin *);
00957
00958 recipe_exec = cpl_plugin_get_exec(plugin);
00959
00960 cpl_msg_info(cpl_func,"Checking handling of SOF: %s", sof_name);
00961 recipe_nfail += recipe_assert( recipe_exec(plugin) == 0 );
00962 recipe_nfail += recipe_assert( cpl_error_get_code() == CPL_ERROR_NONE );
00963
00964 recipe_nfail
00965 += recipe_assert( cpl_dfs_update_product_header(recipe->frames)
00966 == CPL_ERROR_NONE );
00967
00968 if (!cpl_errorstate_is_equal(inistate)) {
00969 recipe_nfail += recipe_assert( cpl_errorstate_is_equal(inistate) );
00970 cpl_errorstate_dump(inistate, CPL_FALSE, NULL);
00971 cpl_msg_debug(cpl_func, "Resetting error state");
00972 cpl_errorstate_set(inistate);
00973 }
00974
00975 recipe_frameset_empty(recipe->frames);
00976 }
00977
00978 cpl_free(sof_name);
00979
00980 return recipe_nfail;
00981 }
00982
00983
00984
00985
00986
01000
01001
01002 static void recipe_frameset_load(cpl_frameset * set, const char *name)
01003 {
01004
01005 FILE *fp;
01006 char line[LINE_LEN_MAX];
01007 char path[LINE_LEN_MAX], group[LINE_LEN_MAX], tag[LINE_LEN_MAX];
01008 int line_number;
01009
01010 assert( set != NULL );
01011 assert( name != NULL );
01012
01013 fp = fopen(name, "r");
01014 if (fp == NULL) {
01015 cpl_msg_debug(cpl_func, "Unable to open SOF file '%s'", name);
01016 return;
01017 }
01018
01019
01020 for (line_number = 0; fgets(line, LINE_LEN_MAX - 1, fp); line_number++) {
01021
01022 cpl_frame_group grp;
01023 cpl_frame * frame;
01024 int n;
01025
01026 if (line[0] == '#') continue;
01027
01028 n = sscanf(line, "%s %s %s", path, tag, group);
01029
01030 if (n < 1) {
01031 cpl_msg_warning(cpl_func, "Spurious line no. %d in %s: %s",
01032 line_number, name, line);
01033 break;
01034 }
01035
01036
01037 frame = cpl_frame_new();
01038
01039
01040 cpl_frame_set_filename(frame, path);
01041
01042
01043 cpl_frame_set_tag(frame, n == 1 ? "" : tag);
01044
01045 cpl_frameset_insert(set, frame);
01046
01047
01048 if (n < 3) continue;
01049
01050 if (!strcmp(group, CPL_FRAME_GROUP_RAW_ID))
01051 grp = CPL_FRAME_GROUP_RAW;
01052 else if (!strcmp(group, CPL_FRAME_GROUP_CALIB_ID))
01053 grp = CPL_FRAME_GROUP_CALIB;
01054 else if (!strcmp(group, CPL_FRAME_GROUP_PRODUCT_ID))
01055 grp = CPL_FRAME_GROUP_PRODUCT;
01056 else
01057 grp = CPL_FRAME_GROUP_NONE;
01058
01059 cpl_frame_set_group(frame, grp);
01060 }
01061
01062 fclose(fp);
01063
01064 return;
01065
01066 }
01067
01068
01069
01079
01080 static const cpl_parameter * irplib_parameterlist_get(const cpl_parameterlist
01081 * self,
01082 const char * instrume,
01083 const char * recipe,
01084 const char * parameter)
01085 {
01086
01087 const cpl_parameter * par;
01088 char * paramname;
01089
01090
01091 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
01092 cpl_ensure(instrume != NULL, CPL_ERROR_NULL_INPUT, NULL);
01093 cpl_ensure(recipe != NULL, CPL_ERROR_NULL_INPUT, NULL);
01094 cpl_ensure(parameter != NULL, CPL_ERROR_NULL_INPUT, NULL);
01095
01096 paramname = cpl_sprintf("%s.%s.%s", instrume, recipe, parameter);
01097
01098 cpl_ensure(paramname != NULL, cpl_error_get_code(), NULL);
01099
01100 par = cpl_parameterlist_find_const(self, paramname);
01101
01102 cpl_free(paramname);
01103
01104 return par;
01105
01106 }
01107
01108
01109
01135
01136 static void recipe_frameset_empty(cpl_frameset * self)
01137 {
01138 cpl_frame * f;
01139
01140 if (self == NULL) {
01141 cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
01142 return;
01143 }
01144
01145 for (f = cpl_frameset_get_first(self); f != NULL;
01146 f = cpl_frameset_get_first(self))
01147 {
01148 cpl_frameset_erase_frame(self, f);
01149 }
01150 }