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 cpl_boolean irplib_plugin_has_sof_from_env(const cpl_plugin *,
00091 const char *);
00092
00093 static void recipe_frameset_load(cpl_frameset *, const char *);
00094
00095 static void recipe_sof_test_devfile(cpl_plugin *, const char *, size_t,
00096 const char *[]);
00097 static void recipe_sof_test_image_empty(cpl_plugin *, size_t, const char *[]);
00098 static void recipe_sof_test_local(cpl_plugin *);
00099 static void recipe_sof_test_from_env(cpl_plugin *);
00100 static void recipe_frameset_empty(cpl_frameset *);
00101 static void recipe_frameset_test_frame(const cpl_frame *);
00102 static void recipe_frameset_test_frameset_diff(const cpl_frameset *,
00103 const cpl_frameset *);
00104
00105 static cpl_errorstate inistate;
00106
00109
00110
00111
00112
00113
00123
00124 const char * irplib_parameterlist_get_string(const cpl_parameterlist * self,
00125 const char * instrume,
00126 const char * recipe,
00127 const char * parameter)
00128 {
00129 const cpl_parameter * par = irplib_parameterlist_get(self, instrume,
00130 recipe, parameter);
00131
00132 if (par == NULL) {
00133
00134 (void)cpl_error_set_where(cpl_func);
00135
00136 return NULL;
00137 } else {
00138 const char * value = cpl_parameter_get_string(par);
00139
00140 if (value == NULL) (void)cpl_error_set_where(cpl_func);
00141
00142 return value;
00143 }
00144 }
00145
00146
00156
00157 cpl_boolean irplib_parameterlist_get_bool(const cpl_parameterlist * self,
00158 const char * instrume,
00159 const char * recipe,
00160 const char * parameter)
00161 {
00162 const cpl_parameter * par = irplib_parameterlist_get(self, instrume,
00163 recipe, parameter);
00164
00165 if (par == NULL) {
00166
00167 (void)cpl_error_set_where(cpl_func);
00168
00169 return CPL_FALSE;
00170 } else {
00171 cpl_errorstate prestate = cpl_errorstate_get();
00172 const cpl_boolean value = cpl_parameter_get_bool(par);
00173
00174 if (!cpl_errorstate_is_equal(prestate))
00175 (void)cpl_error_set_where(cpl_func);
00176
00177 return value;
00178 }
00179 }
00180
00181
00182
00192
00193 int irplib_parameterlist_get_int(const cpl_parameterlist * self,
00194 const char * instrume,
00195 const char * recipe,
00196 const char * parameter)
00197 {
00198 const cpl_parameter * par = irplib_parameterlist_get(self, instrume,
00199 recipe, parameter);
00200
00201 if (par == NULL) {
00202
00203 (void)cpl_error_set_where(cpl_func);
00204
00205 return 0;
00206 } else {
00207 cpl_errorstate prestate = cpl_errorstate_get();
00208 const int value = cpl_parameter_get_int(par);
00209
00210 if (!cpl_errorstate_is_equal(prestate))
00211 (void)cpl_error_set_where(cpl_func);
00212
00213 return value;
00214 }
00215 }
00216
00217
00227
00228 double irplib_parameterlist_get_double(const cpl_parameterlist * self,
00229 const char * instrume,
00230 const char * recipe,
00231 const char * parameter)
00232 {
00233 const cpl_parameter * par = irplib_parameterlist_get(self, instrume,
00234 recipe, parameter);
00235
00236 if (par == NULL) {
00237
00238 (void)cpl_error_set_where(cpl_func);
00239
00240 return 0.0;
00241 } else {
00242 cpl_errorstate prestate = cpl_errorstate_get();
00243 const double value = cpl_parameter_get_double(par);
00244
00245 if (!cpl_errorstate_is_equal(prestate))
00246 (void)cpl_error_set_where(cpl_func);
00247
00248 return value;
00249 }
00250 }
00251
00252
00266
00267 cpl_error_code irplib_parameterlist_set_string(cpl_parameterlist * self,
00268 const char * instrume,
00269 const char * recipe,
00270 const char * parameter,
00271 const char * defvalue,
00272 const char * alias,
00273 const char * context,
00274 const char * man)
00275 {
00276
00277 cpl_error_code error;
00278 cpl_parameter * par;
00279 char * paramname = cpl_sprintf("%s.%s.%s", instrume, recipe,
00280 parameter);
00281
00282 cpl_ensure_code(paramname != NULL, cpl_error_get_code());
00283
00284 par = cpl_parameter_new_value(paramname, CPL_TYPE_STRING, man, context,
00285 defvalue);
00286 cpl_free(paramname);
00287
00288 cpl_ensure_code(par != NULL, cpl_error_get_code());
00289
00290 error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI,
00291 alias ? alias : parameter);
00292 cpl_ensure_code(!error, error);
00293
00294 error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
00295 cpl_ensure_code(!error, error);
00296
00297 error = cpl_parameterlist_append(self, par);
00298 cpl_ensure_code(!error, error);
00299
00300 return CPL_ERROR_NONE;
00301 }
00302
00303
00304
00318
00319 cpl_error_code irplib_parameterlist_set_bool(cpl_parameterlist * self,
00320 const char * instrume,
00321 const char * recipe,
00322 const char * parameter,
00323 cpl_boolean defvalue,
00324 const char * alias,
00325 const char * context,
00326 const char * man)
00327 {
00328
00329 cpl_error_code error;
00330 cpl_parameter * par;
00331 char * paramname = cpl_sprintf("%s.%s.%s", instrume, recipe,
00332 parameter);
00333
00334 cpl_ensure_code(paramname != NULL, cpl_error_get_code());
00335
00336 par = cpl_parameter_new_value(paramname, CPL_TYPE_BOOL, man, context,
00337 defvalue);
00338 cpl_free(paramname);
00339
00340 cpl_ensure_code(par != NULL, cpl_error_get_code());
00341
00342 error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI,
00343 alias ? alias : parameter);
00344 cpl_ensure_code(!error, error);
00345
00346 error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
00347 cpl_ensure_code(!error, error);
00348
00349 error = cpl_parameterlist_append(self, par);
00350 cpl_ensure_code(!error, error);
00351
00352 return CPL_ERROR_NONE;
00353 }
00354
00355
00356
00357
00371
00372 cpl_error_code irplib_parameterlist_set_int(cpl_parameterlist * self,
00373 const char * instrume,
00374 const char * recipe,
00375 const char * parameter,
00376 int defvalue,
00377 const char * alias,
00378 const char * context,
00379 const char * man)
00380 {
00381
00382 cpl_error_code error;
00383 cpl_parameter * par;
00384 char * paramname = cpl_sprintf("%s.%s.%s", instrume, recipe,
00385 parameter);
00386
00387 cpl_ensure_code(paramname != NULL, cpl_error_get_code());
00388
00389 par = cpl_parameter_new_value(paramname, CPL_TYPE_INT, man, context,
00390 defvalue);
00391 cpl_free(paramname);
00392
00393 cpl_ensure_code(par != NULL, cpl_error_get_code());
00394
00395 error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI,
00396 alias ? alias : parameter);
00397 cpl_ensure_code(!error, error);
00398
00399 error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
00400 cpl_ensure_code(!error, error);
00401
00402 error = cpl_parameterlist_append(self, par);
00403 cpl_ensure_code(!error, error);
00404
00405 return CPL_ERROR_NONE;
00406 }
00407
00408
00409
00423
00424 cpl_error_code irplib_parameterlist_set_double(cpl_parameterlist * self,
00425 const char * instrume,
00426 const char * recipe,
00427 const char * parameter,
00428 double defvalue,
00429 const char * alias,
00430 const char * context,
00431 const char * man)
00432 {
00433
00434 cpl_error_code error;
00435 cpl_parameter * par;
00436 char * paramname = cpl_sprintf("%s.%s.%s", instrume, recipe,
00437 parameter);
00438
00439 cpl_ensure_code(paramname != NULL, cpl_error_get_code());
00440
00441 par = cpl_parameter_new_value(paramname, CPL_TYPE_DOUBLE, man, context,
00442 defvalue);
00443 cpl_free(paramname);
00444
00445 cpl_ensure_code(par != NULL, cpl_error_get_code());
00446
00447 error = cpl_parameter_set_alias(par, CPL_PARAMETER_MODE_CLI,
00448 alias ? alias : parameter);
00449 cpl_ensure_code(!error, error);
00450
00451 error = cpl_parameter_disable(par, CPL_PARAMETER_MODE_ENV);
00452 cpl_ensure_code(!error, error);
00453
00454 error = cpl_parameterlist_append(self, par);
00455 cpl_ensure_code(!error, error);
00456
00457 return CPL_ERROR_NONE;
00458 }
00459
00460
00461
00475
00476 int irplib_plugin_test(cpl_pluginlist * self, size_t nstr, const char *astr[]) {
00477
00478 cpl_plugin * plugin;
00479 int (*recipe_create) (cpl_plugin *);
00480 int (*recipe_exec ) (cpl_plugin *);
00481 int (*recipe_deinit) (cpl_plugin *);
00482 FILE * stream;
00483 cpl_boolean is_debug;
00484
00485
00486 is_debug = cpl_msg_get_level() <= CPL_MSG_DEBUG ? CPL_TRUE : CPL_FALSE;
00487
00488
00489 stream = is_debug ? stdout : fopen("/dev/null", "a");
00490
00491 inistate = cpl_errorstate_get();
00492
00493 assert( nstr == 0 || astr != NULL );
00494
00495 plugin = cpl_pluginlist_get_first(self);
00496
00497 if (plugin == NULL) {
00498 cpl_msg_warning(cpl_func, "With an empty pluginlist, "
00499 "no tests can be made");
00500 return 0;
00501 }
00502
00503 cpl_plugin_dump(plugin, stream);
00504
00505 recipe_create = cpl_plugin_get_init(plugin);
00506 cpl_test( recipe_create != NULL);
00507
00508 recipe_exec = cpl_plugin_get_exec(plugin);
00509 cpl_test( recipe_exec != NULL);
00510
00511 recipe_deinit = cpl_plugin_get_deinit(plugin);
00512 cpl_test( recipe_deinit != NULL);
00513
00514
00515 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
00516 cpl_msg_warning(cpl_func, "This plugin is not of type recipe, "
00517 "cannot test further");
00518 return 0;
00519 }
00520
00521 if (recipe_create != NULL && recipe_exec != NULL && recipe_deinit != NULL) {
00522
00523 cpl_error_code error;
00524 cpl_recipe * recipe;
00525
00526 cpl_test_zero(recipe_create(plugin));
00527
00528 recipe = (cpl_recipe *) plugin;
00529
00530 cpl_test_nonnull( recipe->parameters );
00531
00532 recipe_parameterlist_set(recipe->parameters);
00533
00534 cpl_parameterlist_dump(recipe->parameters, stream);
00535
00536 recipe->frames = cpl_frameset_new();
00537
00538 if (irplib_plugin_has_sof_from_env(plugin, "RECIPE_SOF_PATH")) {
00539
00540 recipe_sof_test_from_env(plugin);
00541
00542 } else {
00543
00544 const cpl_msg_severity msg_level = cpl_msg_get_level();
00545
00546
00547
00548 if (getenv("CPL_MSG_LEVEL") == NULL) cpl_msg_set_level(CPL_MSG_OFF);
00549
00550 cpl_msg_info(cpl_func,"Checking handling of pre-existing CPL error "
00551 "state - may produce warning(s)/error(s):");
00552 cpl_error_set(cpl_func, CPL_ERROR_EOL);
00553
00554 cpl_test( recipe_exec(plugin) );
00555
00556 cpl_test_error( CPL_ERROR_EOL );
00557
00558 cpl_msg_info(cpl_func,"Checking handling of empty frameset - "
00559 "may produce warning(s)/error(s):");
00560
00561 cpl_test( recipe_exec(plugin) );
00562 error = cpl_error_get_code();
00563
00564 cpl_test_error( error );
00565 cpl_test( error );
00566
00567 cpl_msg_info(cpl_func,"Checking handling of dummy frameset - "
00568 "may produce warning(s)/error(s):");
00569 do {
00570 cpl_frame * f = cpl_frame_new();
00571 error = cpl_frame_set_filename(f, "/dev/null");
00572 cpl_test_eq_error(error, CPL_ERROR_NONE);
00573 error = cpl_frame_set_tag(f, "RECIPE_DUMMY_TAG");
00574 cpl_test_eq_error(error, CPL_ERROR_NONE);
00575 error = cpl_frameset_insert(recipe->frames, f);
00576 cpl_test_eq_error(error, CPL_ERROR_NONE);
00577
00578
00579 cpl_test( recipe_exec(plugin) );
00580 error = cpl_error_get_code();
00581
00582 cpl_test_error( error );
00583 cpl_test( error );
00584
00585 error = cpl_frameset_erase_frame(recipe->frames, f);
00586 cpl_test_eq_error(error, CPL_ERROR_NONE);
00587
00588 } while (0);
00589
00590 #ifdef IRPLIB_TEST_RANDOM_SOF
00591 recipe_sof_test_devfile(plugin, DEV_RANDOM, nstr, astr);
00592 #endif
00593
00594 recipe_sof_test_devfile(plugin, "/dev/null", nstr, astr);
00595
00596 recipe_sof_test_devfile(plugin, ".", nstr, astr);
00597
00598 recipe_sof_test_image_empty(plugin, nstr, astr);
00599
00600 recipe_sof_test_local(plugin);
00601
00602 cpl_msg_set_level(msg_level);
00603
00604 }
00605
00606 cpl_frameset_delete(recipe->frames);
00607
00608 error = recipe_deinit(plugin);
00609 cpl_test_eq_error(error, CPL_ERROR_NONE);
00610 }
00611
00612 if (stream != stdout) fclose(stream);
00613
00614 return 0;
00615 }
00616
00619
00629
00630 static void recipe_parameterlist_set(cpl_parameterlist * self)
00631 {
00632
00633 cpl_parameter * p = cpl_parameterlist_get_first(self);
00634
00635 for (; p != NULL; p = cpl_parameterlist_get_next(self)) {
00636
00637 const char * envvar;
00638 const char * svalue;
00639
00640
00641 if (cpl_parameter_get_default_flag(p)) continue;
00642
00643 cpl_msg_debug(cpl_func, __FILE__ " line %u: OK", __LINE__);
00644
00645 envvar = cpl_parameter_get_alias(p, CPL_PARAMETER_MODE_ENV);
00646 svalue = envvar ? getenv(envvar) : NULL;
00647
00648 switch (cpl_parameter_get_type(p)) {
00649 case CPL_TYPE_BOOL: {
00650 const int value
00651 = svalue ? atoi(svalue) : cpl_parameter_get_default_bool(p);
00652 cpl_parameter_set_bool(p, value);
00653 break;
00654 }
00655 case CPL_TYPE_INT: {
00656 const int value
00657 = svalue ? atoi(svalue) : cpl_parameter_get_default_int(p);
00658 cpl_parameter_set_int(p, value);
00659 break;
00660 }
00661 case CPL_TYPE_DOUBLE: {
00662 const double value
00663 = svalue ? atof(svalue) : cpl_parameter_get_default_double(p);
00664 cpl_parameter_set_double(p, value);
00665 break;
00666 }
00667 case CPL_TYPE_STRING:
00668 {
00669 const char * s_default = cpl_parameter_get_default_string(p);
00670
00671 const char * value
00672 = svalue ? svalue : (s_default ? s_default : "");
00673 cpl_parameter_set_string(p, value);
00674 break;
00675 }
00676
00677 default:
00678 assert( 0 );
00679 }
00680 }
00681 }
00682
00683
00684
00694
00695 static void recipe_sof_test_devfile(cpl_plugin * plugin, const char * filename,
00696 size_t nstr, const char *astr[])
00697 {
00698 cpl_recipe * recipe = (cpl_recipe*)plugin;
00699 int (*recipe_exec) (cpl_plugin *);
00700 cpl_frameset * copy;
00701 cpl_error_code error;
00702 size_t i;
00703
00704
00705 if (nstr < 1) return;
00706 if (filename == NULL) return;
00707
00708 cpl_msg_info(cpl_func, "Testing recipe with %u %s as input ",
00709 (unsigned)nstr, filename);
00710
00711 for (i = 0; i < nstr; i++) {
00712 cpl_frame * f = cpl_frame_new();
00713
00714 error = cpl_frame_set_filename(f, filename);
00715 cpl_test_eq_error(error, CPL_ERROR_NONE);
00716
00717 error = cpl_frame_set_tag(f, astr[i]);
00718 cpl_test_eq_error(error, CPL_ERROR_NONE);
00719
00720 error = cpl_frameset_insert(recipe->frames, f);
00721 cpl_test_eq_error(error, CPL_ERROR_NONE);
00722 }
00723
00724 copy = cpl_frameset_duplicate(recipe->frames);
00725
00726 recipe_exec = cpl_plugin_get_exec(plugin);
00727 cpl_test( recipe_exec != NULL);
00728
00729 if (recipe_exec != NULL) {
00730
00731
00732 cpl_test( recipe_exec(plugin) );
00733 error = cpl_error_get_code();
00734
00735 cpl_test_error( error );
00736 cpl_test( error );
00737
00738 recipe_frameset_test_frameset_diff(recipe->frames, copy);
00739
00740 recipe_frameset_empty(recipe->frames);
00741 }
00742
00743 cpl_frameset_delete(copy);
00744
00745 return;
00746 }
00747
00748
00755
00756 static void recipe_sof_test_image_empty(cpl_plugin * plugin, size_t nstr,
00757 const char *astr[])
00758 {
00759 cpl_recipe * recipe = (cpl_recipe*)plugin;
00760 int (*recipe_exec) (cpl_plugin *);
00761 cpl_frameset * copy;
00762 cpl_error_code error;
00763 size_t i;
00764 cpl_image * iempty;
00765
00766
00767 if (nstr < 1) return;
00768
00769 cpl_msg_info(cpl_func, "Testing recipe with %u empty images as input ",
00770 (unsigned)nstr);
00771
00772 iempty = cpl_image_new(13, 17, CPL_TYPE_FLOAT);
00773 cpl_test_nonnull(iempty);
00774
00775 for (i = 0; i < nstr; i++) {
00776 cpl_frame * f = cpl_frame_new();
00777 char * rawname = cpl_sprintf("%s-raw%05u.fits",
00778 cpl_plugin_get_name(plugin),
00779 (unsigned)(i+1));
00780
00781 error = cpl_image_save(iempty, rawname,CPL_BPP_IEEE_FLOAT, NULL,
00782 CPL_IO_DEFAULT);
00783 cpl_test_eq_error(error, CPL_ERROR_NONE);
00784
00785 error = cpl_frame_set_filename(f, rawname);
00786 cpl_test_eq_error(error, CPL_ERROR_NONE);
00787
00788 error = cpl_frame_set_tag(f, astr[i]);
00789 cpl_test_eq_error(error, CPL_ERROR_NONE);
00790
00791 error = cpl_frameset_insert(recipe->frames, f);
00792 cpl_test_eq_error(error, CPL_ERROR_NONE);
00793
00794 cpl_free(rawname);
00795 }
00796 cpl_image_delete(iempty);
00797
00798 copy = cpl_frameset_duplicate(recipe->frames);
00799
00800 recipe_exec = cpl_plugin_get_exec(plugin);
00801 cpl_test(recipe_exec != NULL);
00802
00803 if (recipe_exec != NULL) {
00804 const cpl_frame * frame;
00805 cpl_frameset_iterator * iterator = NULL;
00806 int retstat;
00807
00808
00809
00810
00811 retstat = recipe_exec(plugin);
00812 error = cpl_error_get_code();
00813
00814 if (error == 0) {
00815 cpl_test_zero(retstat);
00816 } else {
00817 cpl_test(retstat);
00818 }
00819 cpl_test_error( error );
00820
00821 recipe_frameset_test_frameset_diff(recipe->frames, copy);
00822
00823 for (frame = irplib_frameset_get_first_const(&iterator, recipe->frames);
00824 frame != NULL;
00825 frame = irplib_frameset_get_next_const(iterator))
00826 {
00827 cpl_test_zero( remove(cpl_frame_get_filename(frame)) );
00828 }
00829 cpl_frameset_iterator_delete(iterator);
00830
00831 recipe_frameset_empty(recipe->frames);
00832 }
00833
00834 cpl_frameset_delete(copy);
00835
00836 return;
00837 }
00838
00839
00840
00848
00849 cpl_boolean irplib_plugin_has_sof_from_env(const cpl_plugin * plugin,
00850 const char * envname)
00851 {
00852 const char * recipename = cpl_plugin_get_name(plugin);
00853 const char * sof_path = envname ? getenv(envname) : NULL;
00854 cpl_frameset * frames;
00855 char * sof_name;
00856 const cpl_frame * ffirst;
00857
00858 cpl_ensure(plugin != NULL, CPL_ERROR_NULL_INPUT, CPL_FALSE);
00859 cpl_ensure(envname != NULL, CPL_ERROR_NULL_INPUT, CPL_FALSE);
00860 cpl_ensure(recipename != NULL, CPL_ERROR_DATA_NOT_FOUND, CPL_FALSE);
00861 cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), CPL_FALSE);
00862
00863 if (sof_path == NULL) return CPL_FALSE;
00864
00865 sof_name = cpl_sprintf("%s/%s.sof", sof_path, recipename);
00866
00867 frames = cpl_frameset_new();
00868 recipe_frameset_load(frames, sof_name);
00869
00870 ffirst = cpl_frameset_get_position_const(frames, 0);
00871
00872 cpl_free(sof_name);
00873 cpl_frameset_delete(frames);
00874
00875 cpl_ensure(!cpl_error_get_code(), cpl_error_get_code(), CPL_FALSE);
00876
00877 return ffirst ? CPL_TRUE : CPL_FALSE;
00878
00879 }
00880
00881
00888
00889 static void recipe_sof_test_from_env(cpl_plugin * plugin)
00890 {
00891 cpl_recipe * recipe = (cpl_recipe*)plugin;
00892 const char * recipename = cpl_plugin_get_name(plugin);
00893 const char * var_name = "RECIPE_SOF_PATH";
00894 const char * sof_path = getenv(var_name);
00895
00896 char * sof_name;
00897
00898 if (sof_path == NULL) {
00899 cpl_msg_warning(cpl_func, "Environment variable %s is unset: "
00900 "No SOFs to check", var_name);
00901 return;
00902 }
00903
00904 cpl_msg_debug(cpl_func, "Checking for SOFs in %s", sof_path);
00905
00906 cpl_test_nonnull( recipename );
00907 if (recipename == NULL) return;
00908
00909 sof_name = cpl_sprintf("%s/%s.sof", sof_path, recipename);
00910
00911 cpl_msg_debug(cpl_func, "Checking for SOF %s", sof_name);
00912
00913 recipe_frameset_load(recipe->frames, sof_name);
00914
00915 if (!cpl_frameset_is_empty(recipe->frames)) {
00916
00917 int (*recipe_exec ) (cpl_plugin *);
00918 cpl_frameset * copy = cpl_frameset_duplicate(recipe->frames);
00919
00920 recipe_exec = cpl_plugin_get_exec(plugin);
00921 cpl_test(recipe_exec != NULL);
00922
00923 if (recipe_exec != NULL) {
00924 cpl_error_code error;
00925 cpl_msg_info(cpl_func,"Checking handling of SOF: %s", sof_name);
00926
00927
00928 cpl_test_zero( recipe_exec(plugin) );
00929
00930 cpl_test_error(CPL_ERROR_NONE);
00931
00932 error = cpl_dfs_update_product_header(recipe->frames);
00933 cpl_test_eq_error(error, CPL_ERROR_NONE);
00934
00935 recipe_frameset_test_frameset_diff(recipe->frames, copy);
00936
00937 recipe_frameset_empty(recipe->frames);
00938 }
00939
00940 cpl_frameset_delete(copy);
00941
00942 }
00943
00944 cpl_free(sof_name);
00945
00946 return;
00947 }
00948
00949
00950
00951
00958
00959 static void recipe_sof_test_local(cpl_plugin * plugin)
00960 {
00961 cpl_recipe * recipe = (cpl_recipe*)plugin;
00962 const char * recipename = cpl_plugin_get_name(plugin);
00963 char * sof_name = cpl_sprintf("%s.sof", recipename);
00964
00965 cpl_msg_debug(cpl_func, "Checking for SOF %s", sof_name);
00966
00967 recipe_frameset_load(recipe->frames, sof_name);
00968
00969 if (!cpl_frameset_is_empty(recipe->frames)) {
00970
00971 int (*recipe_exec ) (cpl_plugin *);
00972 cpl_frameset * copy = cpl_frameset_duplicate(recipe->frames);
00973
00974 recipe_exec = cpl_plugin_get_exec(plugin);
00975 cpl_test(recipe_exec != NULL);
00976
00977 if (recipe_exec != NULL) {
00978 cpl_error_code error;
00979
00980 cpl_msg_info(cpl_func,"Checking handling of SOF: %s", sof_name);
00981
00982
00983 cpl_test_zero( recipe_exec(plugin) );
00984
00985 cpl_test_error(CPL_ERROR_NONE);
00986
00987 error = cpl_dfs_update_product_header(recipe->frames);
00988 cpl_test_eq_error( error, CPL_ERROR_NONE );
00989
00990 recipe_frameset_test_frameset_diff(recipe->frames, copy);
00991
00992 recipe_frameset_empty(recipe->frames);
00993 }
00994
00995 cpl_frameset_delete(copy);
00996 }
00997
00998 cpl_free(sof_name);
00999
01000 return;
01001 }
01002
01003
01004
01005
01006
01020
01021
01022 static void recipe_frameset_load(cpl_frameset * set, const char *name)
01023 {
01024
01025 FILE *fp;
01026 char line[LINE_LEN_MAX];
01027 char path[LINE_LEN_MAX], group[LINE_LEN_MAX], tag[LINE_LEN_MAX];
01028 int line_number;
01029
01030 assert( set != NULL );
01031 assert( name != NULL );
01032
01033 fp = fopen(name, "r");
01034 if (fp == NULL) {
01035 cpl_msg_debug(cpl_func, "Unable to open SOF file '%s'", name);
01036 return;
01037 }
01038
01039
01040 for (line_number = 0; fgets(line, LINE_LEN_MAX - 1, fp); line_number++) {
01041
01042 char scan_fmt[50];
01043 cpl_frame_group grp;
01044 cpl_frame * frame;
01045 int n;
01046
01047 if (line[0] == '#') continue;
01048
01049 snprintf(scan_fmt, 49, "%%%ds %%%ds %%%ds", LINE_LEN_MAX - 1,
01050 LINE_LEN_MAX - 1, LINE_LEN_MAX - 1);
01051 n = sscanf(line, scan_fmt, path, tag, group);
01052
01053 if (n < 1) {
01054 cpl_msg_warning(cpl_func, "Spurious line no. %d in %s: %s",
01055 line_number, name, line);
01056 break;
01057 }
01058
01059
01060 frame = cpl_frame_new();
01061
01062
01063 cpl_frame_set_filename(frame, path);
01064
01065
01066 cpl_frame_set_tag(frame, n == 1 ? "" : tag);
01067
01068 cpl_frameset_insert(set, frame);
01069
01070
01071 if (n < 3) continue;
01072
01073 if (!strcmp(group, CPL_FRAME_GROUP_RAW_ID))
01074 grp = CPL_FRAME_GROUP_RAW;
01075 else if (!strcmp(group, CPL_FRAME_GROUP_CALIB_ID))
01076 grp = CPL_FRAME_GROUP_CALIB;
01077 else if (!strcmp(group, CPL_FRAME_GROUP_PRODUCT_ID))
01078 grp = CPL_FRAME_GROUP_PRODUCT;
01079 else
01080 grp = CPL_FRAME_GROUP_NONE;
01081
01082 cpl_frame_set_group(frame, grp);
01083 }
01084
01085 fclose(fp);
01086
01087 return;
01088
01089 }
01090
01091
01092
01102
01103 static
01104 const cpl_parameter * irplib_parameterlist_get(const cpl_parameterlist * self,
01105 const char * instrume,
01106 const char * recipe,
01107 const char * parameter)
01108 {
01109
01110 char * paramname;
01111 const cpl_parameter * par;
01112
01113
01114 cpl_ensure(instrume != NULL, CPL_ERROR_NULL_INPUT, NULL);
01115 cpl_ensure(recipe != NULL, CPL_ERROR_NULL_INPUT, NULL);
01116 cpl_ensure(parameter != NULL, CPL_ERROR_NULL_INPUT, NULL);
01117
01118 paramname = cpl_sprintf("%s.%s.%s", instrume, recipe, parameter);
01119
01120 par = cpl_parameterlist_find_const(self, paramname);
01121
01122 if (par == NULL) (void)cpl_error_set_message(cpl_func,
01123 cpl_error_get_code()
01124 ? cpl_error_get_code()
01125 : CPL_ERROR_DATA_NOT_FOUND,
01126 "%s", paramname);
01127
01128 cpl_free(paramname);
01129
01130 return par;
01131
01132 }
01133
01134
01135
01161
01162 static void recipe_frameset_empty(cpl_frameset * self)
01163 {
01164 cpl_size i, n;
01165
01166 if (self == NULL) {
01167 cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
01168 return;
01169 }
01170
01171 n = cpl_frameset_get_size(self);
01172 for (i = 0; i < n; ++i)
01173 {
01174 cpl_frame * f = cpl_frameset_get_position(self, n-1-i);
01175 cpl_frameset_erase_frame(self, f);
01176 }
01177 }
01178
01179
01180
01200
01201 static void recipe_frameset_test_frame(const cpl_frame * self)
01202 {
01203
01204 cpl_msg_info(cpl_func, "Validating new frame: %s",
01205 cpl_frame_get_filename(self));
01206
01207 cpl_test_nonnull(self);
01208
01209
01210 cpl_test_nonnull(cpl_frame_get_tag(self));
01211
01212
01213 cpl_test_eq(cpl_frame_get_group(self), CPL_FRAME_GROUP_PRODUCT);
01214
01215 if (cpl_frame_get_type(self) != CPL_FRAME_TYPE_PAF) {
01216
01217 cpl_test_fits(cpl_frame_get_filename(self));
01218 } else {
01219
01220 cpl_test_nonnull(cpl_frame_get_filename(self));
01221 }
01222 }
01223
01224
01245
01246 static void recipe_frameset_test_frameset_diff(const cpl_frameset * self,
01247 const cpl_frameset * other)
01248 {
01249
01250 cpl_frameset_iterator * it1 = NULL;
01251 cpl_frameset_iterator * it2 = NULL;
01252 const cpl_frame * frame = irplib_frameset_get_first_const(&it2, other);
01253
01254
01255 for (;frame != NULL; frame = irplib_frameset_get_next_const(it2)) {
01256 const char * file = cpl_frame_get_filename(frame);
01257
01258 if (file == NULL) {
01259 cpl_test_nonnull(cpl_frame_get_filename(frame));
01260 break;
01261 }
01262 }
01263 cpl_frameset_iterator_delete(it2);
01264 it2 = NULL;
01265 if (frame != NULL) return;
01266
01267 frame = irplib_frameset_get_first_const(&it1, self);
01268
01269 for (;frame != NULL; frame = irplib_frameset_get_next_const(it1)) {
01270 const cpl_frame * cmp;
01271 const char * file = cpl_frame_get_filename(frame);
01272
01273 if (file == NULL) {
01274 cpl_test_nonnull(cpl_frame_get_filename(frame));
01275 continue;
01276 }
01277
01278 cmp = irplib_frameset_get_first_const(&it2, other);
01279 for (;cmp != NULL; cmp = irplib_frameset_get_next_const(it2)) {
01280 const char * cfile = cpl_frame_get_filename(cmp);
01281
01282 if (!strcmp(file, cfile)) break;
01283
01284 }
01285 cpl_frameset_iterator_delete(it2);
01286 it2 = NULL;
01287 if (cmp == NULL) {
01288
01289
01290 cpl_test_eq(cpl_frame_get_group(frame), CPL_FRAME_GROUP_PRODUCT);
01291 recipe_frameset_test_frame(frame);
01292 }
01293 }
01294
01295 cpl_frameset_iterator_delete(it1);
01296 }