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 #ifdef HAVE_CONFIG_H
00028 # include <config.h>
00029 #endif
00030
00031 #undef CX_DISABLE_ASSERT
00032 #undef CX_LOG_DOMAIN
00033
00034
00035 #include <uves_propertylist.h>
00036
00037
00038
00039
00040 #include <uves_error.h>
00041 #include <cpl.h>
00042 #include <cxmemory.h>
00043 #include <cxmessages.h>
00044 #include <cxdeque.h>
00045 #include <qfits.h>
00046 #include <fitsio.h>
00047
00048 #include <stdio.h>
00049 #include <stdlib.h>
00050 #include <string.h>
00051 #include <math.h>
00052 #include <uves_propertylist.h>
00053 #define FLT_EPS 1.0e-6
00054 #define DBL_EPS 1.0e-14
00055
00056
00057 static void
00058 test_property_dump(cpl_property *property)
00059 {
00060
00061 const cxchar *name = cpl_property_get_name(property);
00062 const cxchar *comment = cpl_property_get_comment(property);
00063
00064 cxchar c;
00065
00066 long size = cpl_property_get_size(property);
00067
00068 cpl_type type = cpl_property_get_type(property);
00069
00070
00071 fprintf(stderr, "Property at address %p\n", (void *)property);
00072 fprintf(stderr, "\tname : %p '%s'\n", (void *)name, name);
00073 fprintf(stderr, "\tcomment: %p '%s'\n", (void *)comment, comment);
00074 fprintf(stderr, "\ttype : %#09x\n", type);
00075 fprintf(stderr, "\tsize : %ld\n", size);
00076 fprintf(stderr, "\tvalue : ");
00077
00078
00079 switch (type) {
00080 case CPL_TYPE_CHAR:
00081 c = cpl_property_get_char(property);
00082 if (!c)
00083 fprintf(stderr, "''");
00084 else
00085 fprintf(stderr, "'%c'", c);
00086 break;
00087
00088 case CPL_TYPE_BOOL:
00089 fprintf(stderr, "%d", cpl_property_get_bool(property));
00090 break;
00091
00092 case CPL_TYPE_INT:
00093 fprintf(stderr, "%d", cpl_property_get_int(property));
00094 break;
00095
00096 case CPL_TYPE_LONG:
00097 fprintf(stderr, "%ld", cpl_property_get_long(property));
00098 break;
00099
00100 case CPL_TYPE_FLOAT:
00101 fprintf(stderr, "%.7g", cpl_property_get_float(property));
00102 break;
00103
00104 case CPL_TYPE_DOUBLE:
00105 fprintf(stderr, "%.15g", cpl_property_get_double(property));
00106 break;
00107
00108 case CPL_TYPE_STRING:
00109 fprintf(stderr, "'%s'", cpl_property_get_string(property));
00110 break;
00111
00112 default:
00113 fprintf(stderr, "unknown.");
00114 break;
00115
00116 }
00117
00118 fprintf(stderr, "\n");
00119
00120 return;
00121
00122 }
00123
00124
00125 static void
00126 test_plist_dump(cpl_propertylist *plist)
00127 {
00128
00129 cxlong i;
00130 cxlong sz = cpl_propertylist_get_size(plist);
00131
00132
00133 fprintf(stderr, "Property list at address %p:\n", (void *) plist);
00134
00135 for (i = 0; i < sz; i++) {
00136 cpl_property *p = cpl_propertylist_get(plist, i);
00137 test_property_dump(p);
00138 }
00139
00140 return;
00141
00142 }
00143
00144 static int test_main(void)
00145 {
00146
00147 const cxchar *keys[] = {
00148 "a", "b", "c", "d", "e", "f", "g",
00149 "A", "B", "C", "D", "E", "F", "G"
00150 };
00151
00152 const cxchar *comments[] = {
00153 "A character value",
00154 "A boolean value",
00155 "A integer value",
00156 "A long integer value",
00157 "A floating point number",
00158 "A double precision number",
00159 "A string value",
00160 };
00161
00162 cpl_type types[] = {
00163 CPL_TYPE_CHAR,
00164 CPL_TYPE_BOOL,
00165 CPL_TYPE_INT,
00166 CPL_TYPE_LONG,
00167 CPL_TYPE_FLOAT,
00168 CPL_TYPE_DOUBLE,
00169 CPL_TYPE_STRING
00170 };
00171
00172 cxlong i;
00173
00174 cxfloat fval[] = {-1.23456789, 0.};
00175 cxdouble dval[] = {-1.23456789, 0.};
00176
00177 cpl_propertylist *plist=NULL;
00178 cpl_propertylist *_plist=NULL;
00179
00180 cpl_propertylist *header=NULL;
00181
00182 cpl_property* p=NULL;
00183
00184 struct fcard {
00185 const cxchar *key;
00186 const cxchar *val;
00187 const cxchar *com;
00188 cpl_type type;
00189 };
00190
00191 struct fcard hdr[] = {
00192 {"SIMPLE", "T",
00193
00194
00195 "file does conform to FITS standard",
00196 CPL_TYPE_BOOL},
00197 {"BITPIX", "16",
00198
00199
00200 "number of bits per data pixel",
00201 CPL_TYPE_INT},
00202 {"NAXIS", "2",
00203
00204 "number of data axes",
00205 CPL_TYPE_INT},
00206 {"NAXIS1", "2148",
00207
00208 "length of data axis 1",
00209 CPL_TYPE_INT},
00210 {"NAXIS2", "2340",
00211
00212 "length of data axis 2",
00213 CPL_TYPE_INT},
00214 {"EXTEND", "T",
00215
00216 "FITS dataset may contain extensions",
00217 CPL_TYPE_BOOL},
00218 {"ORIGIN", "ESO",
00219 "European Southern Observatory",
00220 CPL_TYPE_STRING},
00221 {"DATE", "2002-03-08T04:27:21.420",
00222 "Date this file was written (dd/mm/yyyy)",
00223 CPL_TYPE_STRING},
00224 {"MJD-OBS", "52341.17813019",
00225 "Obs start 2002-03-08T04:16:30.448",
00226 CPL_TYPE_DOUBLE},
00227 {"DATE-OBS", "2002-03-08T04:16:30.448",
00228 "Date of observation",
00229 CPL_TYPE_STRING},
00230 {"EXPTIME", "600.000",
00231 "Total integration time. 00:10:00.000",
00232 CPL_TYPE_DOUBLE},
00233 {"TELESCOP", "VLT",
00234 "ESO <TEL>",
00235 CPL_TYPE_STRING},
00236 {"RA", "181.41734",
00237 "12:05:40.1 RA (J2000) pointing",
00238 CPL_TYPE_DOUBLE},
00239 {"DEC", "-7.65555",
00240 "-07:39:19.9 DEC (J2000) pointing",
00241 CPL_TYPE_DOUBLE},
00242 {"EQUINOX", "2000.",
00243 "Standard FK5 (years)",
00244 CPL_TYPE_DOUBLE},
00245 {"RADECSYS", "FK5",
00246 "Coordinate reference frame",
00247 CPL_TYPE_STRING},
00248 {"LST", "38309.370",
00249 "10:38:29.370 LST at start",
00250 CPL_TYPE_DOUBLE},
00251 {"UTC", "15438.000",
00252 "04:17:18.000 UT at start",
00253 CPL_TYPE_DOUBLE},
00254 {"OBSERVER", "UNKNOWN",
00255 "Name of observer",
00256 CPL_TYPE_STRING},
00257 {"INSTRUME", "UNKNOWN",
00258 "Instrument used",
00259 CPL_TYPE_STRING},
00260 {"PI-COI", "'555555555'",
00261 "Name of PI and COI",
00262 CPL_TYPE_STRING},
00263 {"OBJECT", "None",
00264 "Original target",
00265 CPL_TYPE_STRING},
00266 {"PCOUNT", "0",
00267 "Number of parameters per group",
00268 CPL_TYPE_INT},
00269 {"GCOUNT", "1",
00270 "Number of groups",
00271 CPL_TYPE_INT},
00272 {"CRVAL1", "181.41734",
00273 "12:05:40.1, RA at ref pixel",
00274 CPL_TYPE_DOUBLE},
00275 {"CRPIX1", "2341.8585366",
00276 "Reference pixel in X",
00277 CPL_TYPE_DOUBLE},
00278 {"CDELT1", "0.20500000",
00279 "SS arcsec per pixel in RA",
00280 CPL_TYPE_DOUBLE},
00281 {"CTYPE1", "RA---TAN",
00282 "pixel coordinate system",
00283 CPL_TYPE_STRING},
00284 {"CRVAL2", "-7.65555",
00285 "-07:39:19.9, DEC at ref pixel",
00286 CPL_TYPE_DOUBLE},
00287 {"CRPIX2", "2487.8585366",
00288 "Reference pixel in Y",
00289 CPL_TYPE_DOUBLE},
00290 {"CDELT2", "0.20500000",
00291 "SS arcsec per pixel in DEC",
00292 CPL_TYPE_DOUBLE},
00293 {"CTYPE2", "DEC--TAN",
00294 "pixel coordinate system",
00295 CPL_TYPE_STRING},
00296 {"BSCALE", "1.0",
00297 "pixel=FITS*BSCALE+BZERO",
00298 CPL_TYPE_DOUBLE},
00299 {"BZERO", "32768.0",
00300 "pixel=FITS*BSCALE+BZERO",
00301 CPL_TYPE_DOUBLE},
00302 {"CD1_1", "0.000057",
00303 "Translation matrix element",
00304 CPL_TYPE_DOUBLE},
00305 {"CD1_2", "0.000000",
00306 "Translation matrix element",
00307 CPL_TYPE_DOUBLE},
00308 {"CD2_1", "0.000000",
00309 "Translation matrix element",
00310 CPL_TYPE_DOUBLE},
00311 {"CD2_2", "0.000057",
00312 "Translation matrix element",
00313 CPL_TYPE_DOUBLE},
00314 {"HIERARCH ESO OBS DID", "ESO-VLT-DIC.OBS-1.7",
00315 "OBS Dictionary",
00316 CPL_TYPE_STRING},
00317 {"HIERARCH ESO OBS OBSERVER", "UNKNOWN",
00318 "Observer Name",
00319 CPL_TYPE_STRING},
00320 {"HIERARCH ESO OBS PI-COI NAME", "UNKNOWN",
00321 "PI-COI name",
00322 CPL_TYPE_STRING},
00323 {"HIERARCH ESO INS GRAT NAME", "HR",
00324 "Grating name",
00325 CPL_TYPE_STRING},
00326 {"HIERARCH ESO PRO CATG", "X",
00327 "Product category",
00328 CPL_TYPE_STRING},
00329 {"HIERARCH ESO TPL NEXP", "5",
00330 "Number of exposures",
00331 CPL_TYPE_INT},
00332 {"HISTORY", "1st history record", NULL, CPL_TYPE_STRING},
00333 {"COMMENT", "1st comment record", NULL, CPL_TYPE_STRING},
00334 {"HISTORY", "2st history record", NULL, CPL_TYPE_STRING},
00335 {"COMMENT", "2st comment record", NULL, CPL_TYPE_STRING},
00336 {"COMMENT", "3st comment record", NULL, CPL_TYPE_STRING},
00337 {"HISTORY", "3st history record", NULL, CPL_TYPE_STRING},
00338 {"END", NULL, NULL, CPL_TYPE_STRING}
00339 };
00340
00341 FILE *file;
00342
00343
00344
00345
00346
00347
00348
00349
00350 plist = cpl_propertylist_new();
00351
00352 cx_assert(plist != NULL);
00353 cx_assert(cpl_propertylist_is_empty(plist));
00354 cx_assert(cpl_propertylist_get_size(plist) == 0);
00355 check_nomsg( cpl_error_get_code() );
00356
00357
00358
00359
00360
00361 cpl_propertylist_append_char(plist, keys[0], 'a');
00362 cpl_propertylist_set_comment(plist, keys[0], comments[0]);
00363
00364 cpl_propertylist_append_bool(plist, keys[1], 1);
00365 cpl_propertylist_set_comment(plist, keys[1], comments[1]);
00366
00367 cpl_propertylist_append_int(plist, keys[2], -1);
00368 cpl_propertylist_set_comment(plist, keys[2], comments[2]);
00369
00370 cpl_propertylist_append_long(plist, keys[3], 32768);
00371 cpl_propertylist_set_comment(plist, keys[3], comments[3]);
00372
00373 cpl_propertylist_append_float(plist, keys[4], fval[0]);
00374 cpl_propertylist_set_comment(plist, keys[4], comments[4]);
00375
00376 cpl_propertylist_append_double(plist, keys[5], dval[0]);
00377 cpl_propertylist_set_comment(plist, keys[5], comments[5]);
00378
00379 cpl_propertylist_append_string(plist, keys[6], comments[6]);
00380 cpl_propertylist_set_comment(plist, keys[6], comments[6]);
00381
00382 cx_assert(!cpl_propertylist_is_empty(plist));
00383 cx_assert(cpl_propertylist_get_size(plist) == 7);
00384
00385
00386 for (i = 0; i < cpl_propertylist_get_size(plist); i++) {
00387 cpl_property *p = cpl_propertylist_get(plist, i);
00388
00389 cx_assert(!strcmp(cpl_property_get_name(p), keys[i]));
00390 cx_assert(!strcmp(cpl_property_get_comment(p), comments[i]));
00391 cx_assert(cpl_property_get_type(p) == types[i]);
00392
00393 cx_assert(my_uves_propertylist_contains(plist, keys[i]));
00394 cx_assert(!strcmp(cpl_propertylist_get_comment(plist, keys[i]),
00395 comments[i]));
00396 cx_assert(cpl_propertylist_get_type(plist, keys[i]) == types[i]);
00397 }
00398
00399 cx_assert(cpl_propertylist_get_char(plist, keys[0]) == 'a');
00400 cx_assert(cpl_propertylist_get_bool(plist, keys[1]) == 1);
00401 cx_assert(cpl_propertylist_get_int(plist, keys[2]) == -1);
00402 cx_assert(cpl_propertylist_get_long(plist, keys[3]) == 32768);
00403
00404 fval[1] = cpl_propertylist_get_float(plist, keys[4]);
00405 cx_assert(!memcmp(&fval[0], &fval[1], sizeof(float)));
00406
00407 dval[1] = cpl_propertylist_get_double(plist, keys[5]);
00408 cx_assert(!memcmp(&dval[0], &dval[1], sizeof(double)));
00409
00410 cx_assert(!strcmp(cpl_propertylist_get_string(plist, keys[6]),
00411 comments[6]));
00412 check_nomsg( cpl_error_get_code() );
00413
00414
00415
00416
00417
00418
00419 cx_assert(cpl_propertylist_set_char(plist, keys[0], 'b') == 0);
00420 cx_assert(cpl_propertylist_get_char(plist, keys[0]) == 'b');
00421
00422 cx_assert(cpl_propertylist_set_bool(plist, keys[1], 0) == 0);
00423 cx_assert(cpl_propertylist_get_bool(plist, keys[1]) == 0);
00424
00425 cx_assert(cpl_propertylist_set_int(plist, keys[2], -1) == 0);
00426 cx_assert(cpl_propertylist_get_int(plist, keys[2]) == -1);
00427
00428 cx_assert(cpl_propertylist_set_long(plist, keys[3], 1) == 0);
00429 cx_assert(cpl_propertylist_get_long(plist, keys[3]) == 1);
00430
00431 fval[0] = 9.87654321;
00432 cx_assert(cpl_propertylist_set_float(plist, keys[4], fval[0]) == 0);
00433 fval[1] = cpl_propertylist_get_float(plist, keys[4]);
00434 cx_assert(!memcmp(&fval[0], &fval[1], sizeof(float)));
00435
00436 dval[0] = -9.87654321;
00437 cx_assert(cpl_propertylist_set_double(plist, keys[5], dval[0]) == 0);
00438 dval[1] = cpl_propertylist_get_double(plist, keys[5]);
00439 cx_assert(!memcmp(&dval[0], &dval[1], sizeof(double)));
00440
00441 cx_assert(cpl_propertylist_set_string(plist, keys[6], comments[0]) == 0);
00442 cx_assert(!strcmp(cpl_propertylist_get_string(plist, keys[6]),
00443 comments[0]));
00444 check_nomsg( cpl_error_get_code() );
00445
00446
00447
00448
00449
00450
00451
00452 check_nomsg( cpl_error_get_code() );
00453 if (0) test_plist_dump(plist);
00454 check_nomsg( cpl_error_get_code() );
00455
00456 if(cpl_propertylist_set_char(plist, keys[1], 'a') ==
00457 CPL_ERROR_TYPE_MISMATCH) { cpl_error_reset(); }
00458
00459 check_nomsg( cpl_error_get_code() );
00460 if (0) test_plist_dump(plist);
00461
00462
00463 check_nomsg( cpl_error_get_code() );
00464 if(cpl_propertylist_set_bool(plist, keys[2], 1) ==
00465 CPL_ERROR_TYPE_MISMATCH) { cpl_error_reset(); }
00466
00467 check_nomsg( cpl_error_get_code() );
00468 if(cpl_propertylist_set_int(plist, keys[3], 1) ==
00469 CPL_ERROR_TYPE_MISMATCH){ cpl_error_reset(); }
00470
00471 check_nomsg( cpl_error_get_code() );
00472 if(cpl_propertylist_set_long(plist, keys[4], 1) ==
00473 CPL_ERROR_TYPE_MISMATCH){ cpl_error_reset(); }
00474 check_nomsg( cpl_error_get_code() );
00475 if(cpl_propertylist_set_float(plist, keys[5], 1.) ==
00476 CPL_ERROR_TYPE_MISMATCH){ cpl_error_reset(); }
00477 check_nomsg( cpl_error_get_code() );
00478 if(cpl_propertylist_set_double(plist, keys[6], 1.) ==
00479 CPL_ERROR_TYPE_MISMATCH){ cpl_error_reset(); }
00480
00481 check_nomsg( cpl_error_get_code() );
00482 if(cpl_propertylist_set_string(plist, keys[0], comments[0]) ==
00483 CPL_ERROR_TYPE_MISMATCH){ cpl_error_reset(); }
00484 check_nomsg( cpl_error_get_code() );
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494 cx_assert(cpl_propertylist_insert_char(plist, keys[0],
00495 keys[7], 'a') == 0);
00496 cx_assert(cpl_propertylist_insert_after_char(plist, keys[0],
00497 keys[7], 'c') == 0);
00498
00499 cx_assert(cpl_propertylist_insert_bool(plist, keys[1],
00500 keys[8], 0) == 0);
00501 cx_assert(cpl_propertylist_insert_after_bool(plist, keys[1],
00502 keys[8], 1) == 0);
00503
00504 cx_assert(cpl_propertylist_insert_int(plist, keys[2],
00505 keys[9], 0) == 0);
00506 cx_assert(cpl_propertylist_insert_after_int(plist, keys[2],
00507 keys[9], 1) == 0);
00508
00509 cx_assert(cpl_propertylist_insert_long(plist, keys[3], keys[10],
00510 123456789) == 0);
00511 cx_assert(cpl_propertylist_insert_after_long(plist, keys[3], keys[10],
00512 123456789) == 0);
00513
00514 cx_assert(cpl_propertylist_insert_float(plist, keys[4], keys[11],
00515 fval[0]) == 0);
00516 cx_assert(cpl_propertylist_insert_after_float(plist, keys[4], keys[11],
00517 -fval[0]) == 0);
00518
00519 cx_assert(cpl_propertylist_insert_double(plist, keys[5], keys[12],
00520 dval[0]) == 0);
00521 cx_assert(cpl_propertylist_insert_after_double(plist, keys[5], keys[12],
00522 -dval[0]) == 0);
00523
00524 cx_assert(cpl_propertylist_insert_string(plist, keys[6],
00525 keys[13], "") == 0);
00526 cx_assert(cpl_propertylist_insert_after_string(plist, keys[6],
00527 keys[13], "") == 0);
00528 for (i = 0; i < 7; i++) {
00529 cpl_property *p0 = cpl_propertylist_get(plist, 3 * i);
00530 cpl_property *p1 = cpl_propertylist_get(plist, 3 * i + 1);
00531 cpl_property *p2 = cpl_propertylist_get(plist, 3 * i + 2);
00532
00533 cx_assert(!strcmp(cpl_property_get_name(p0), keys[i + 7]));
00534 cx_assert(!strcmp(cpl_property_get_name(p1), keys[i]));
00535 cx_assert(!strcmp(cpl_property_get_name(p2), keys[i + 7]));
00536
00537 switch (cpl_property_get_type(p0)) {
00538 case CPL_TYPE_CHAR:
00539 cx_assert(cpl_property_get_char(p0) == 'a');
00540 cx_assert(cpl_property_get_char(p2) == 'c');
00541 break;
00542
00543 case CPL_TYPE_BOOL:
00544 cx_assert(cpl_property_get_bool(p0) == 0);
00545 cx_assert(cpl_property_get_bool(p2) == 1);
00546 break;
00547
00548 case CPL_TYPE_INT:
00549 cx_assert(cpl_property_get_int(p0) == 0);
00550 cx_assert(cpl_property_get_int(p2) == 1);
00551 break;
00552
00553 case CPL_TYPE_LONG:
00554 cx_assert(cpl_property_get_long(p0) == 123456789);
00555 cx_assert(cpl_property_get_long(p2) == 123456789);
00556 break;
00557
00558 case CPL_TYPE_FLOAT:
00559 fval[1] = cpl_property_get_float(p0);
00560 cx_assert(!memcmp(&fval[0], &fval[1], sizeof(float)));
00561
00562 fval[1] = -cpl_property_get_float(p2);
00563 cx_assert(!memcmp(&fval[0], &fval[1], sizeof(float)));
00564 break;
00565
00566 case CPL_TYPE_DOUBLE:
00567 dval[1] = cpl_property_get_double(p0);
00568 cx_assert(!memcmp(&dval[0], &dval[1], sizeof(double)));
00569
00570 dval[1] = -cpl_property_get_double(p2);
00571 cx_assert(!memcmp(&dval[0], &dval[1], sizeof(double)));
00572 break;
00573
00574 case CPL_TYPE_STRING:
00575 cx_assert(!strcmp(cpl_property_get_string(p0), ""));
00576 cx_assert(!strcmp(cpl_property_get_string(p2), ""));
00577 break;
00578
00579 default:
00580
00581 cx_log("cpl_propertylist-test", CX_LOG_LEVEL_ERROR, "file %s: "
00582 "line %d: Invalid value type encountered", __FILE__,
00583 __LINE__);
00584 break;
00585 }
00586 }
00587
00588 check_nomsg( cpl_error_get_code() );
00589
00590
00591
00592
00593
00594
00595
00596 cx_assert(my_uves_propertylist_contains(plist, "Non-existing key") == 0);
00597 check_nomsg( cpl_error_get_code() );
00598
00599 if(cpl_propertylist_set_char(plist, "Non-existing key", 'a') ==
00600 CPL_ERROR_DATA_NOT_FOUND){ cpl_error_reset(); }
00601
00602 check_nomsg( cpl_error_get_code() );
00603 if(cpl_propertylist_set_bool(plist, "Non-existing key", 1) ==
00604 CPL_ERROR_DATA_NOT_FOUND) { cpl_error_reset(); }
00605 check_nomsg( cpl_error_get_code() );
00606 if(cpl_propertylist_set_int(plist, "Non-existing key", 1) ==
00607 CPL_ERROR_DATA_NOT_FOUND){ cpl_error_reset(); }
00608 check_nomsg( cpl_error_get_code() );
00609 if(cpl_propertylist_set_long(plist, "Non-existing key", 1) ==
00610 CPL_ERROR_DATA_NOT_FOUND){ cpl_error_reset(); }
00611 check_nomsg( cpl_error_get_code() );
00612 if(cpl_propertylist_set_float(plist, "Non-existing key", 1) ==
00613 CPL_ERROR_DATA_NOT_FOUND){ cpl_error_reset(); }
00614 check_nomsg( cpl_error_get_code() );
00615 if(cpl_propertylist_set_double(plist, "Non-existing key", 1) ==
00616 CPL_ERROR_DATA_NOT_FOUND){ cpl_error_reset(); }
00617 check_nomsg( cpl_error_get_code() );
00618 if(cpl_propertylist_set_string(plist, "Non-existing key", "") ==
00619 CPL_ERROR_DATA_NOT_FOUND){ cpl_error_reset(); }
00620
00621 if(cpl_propertylist_insert_char(plist, "Non-existing key",
00622 "h", 'a') == 1){ cpl_error_reset(); }
00623
00624 if(cpl_propertylist_insert_bool(plist, "Non-existing key",
00625 "h", 1) == 1){ cpl_error_reset(); }
00626
00627 if(cpl_propertylist_insert_int(plist, "Non-existing key",
00628 "h", 1) == 1) { cpl_error_reset(); }
00629
00630 if(cpl_propertylist_insert_long(plist, "Non-existing key",
00631 "h", 1) == 1) { cpl_error_reset(); }
00632 if(cpl_propertylist_insert_float(plist, "Non-existing key",
00633 "h", 1) == 1){ cpl_error_reset(); }
00634
00635 if(cpl_propertylist_insert_double(plist, "Non-existing key",
00636 "h", 1) == 1){ cpl_error_reset(); }
00637 if(cpl_propertylist_insert_string(plist, "Non-existing key",
00638 "h", "") == 1){ cpl_error_reset(); }
00639 check_nomsg( cpl_error_get_code() );
00640
00641 if(cpl_propertylist_insert_after_char(plist, "Non-existing key",
00642 "h", 'a') == 1){ cpl_error_reset(); }
00643 if(cpl_propertylist_insert_after_bool(plist, "Non-existing key",
00644 "h", 1) == 1){ cpl_error_reset(); }
00645 if(cpl_propertylist_insert_after_int(plist, "Non-existing key",
00646 "h", 1) == 1){ cpl_error_reset(); }
00647 if(cpl_propertylist_insert_after_long(plist, "Non-existing key",
00648 "h", 1) == 1){ cpl_error_reset(); }
00649 if(cpl_propertylist_insert_after_float(plist, "Non-existing key",
00650 "h", 1) == 1){ cpl_error_reset(); }
00651 if(cpl_propertylist_insert_after_double(plist, "Non-existing key",
00652 "h", 1) == 1){ cpl_error_reset(); }
00653 if(cpl_propertylist_insert_after_string(plist, "Non-existing key",
00654 "h", "") == 1){ cpl_error_reset(); }
00655
00656
00657
00658
00659
00660
00661
00662
00663 cpl_propertylist_delete(_plist);
00664
00665 _plist = cpl_propertylist_duplicate(plist);
00666
00667
00668 cx_assert(_plist != NULL);
00669 cx_assert(_plist != plist);
00670
00671
00672 for (i = 0; i < cpl_propertylist_get_size(plist); i++) {
00673 cpl_property *p = cpl_propertylist_get(plist, i);
00674 cpl_property *_p = cpl_propertylist_get(_plist, i);
00675
00676
00677 cx_assert(cpl_property_get_name(p) != cpl_property_get_name(_p));
00678 cx_assert(!strcmp(cpl_property_get_name(p),
00679 cpl_property_get_name(_p)));
00680 cx_assert(cpl_property_get_comment(p) == NULL ||
00681 (cpl_property_get_comment(p) !=
00682 cpl_property_get_comment(_p)));
00683 cx_assert(cpl_property_get_comment(p) == NULL ||
00684 !strcmp(cpl_property_get_comment(p),
00685 cpl_property_get_comment(_p)));
00686
00687 switch (cpl_property_get_type(p)) {
00688 case CPL_TYPE_CHAR:
00689 cx_assert(cpl_property_get_char(p) ==
00690 cpl_property_get_char(_p));
00691 break;
00692
00693 case CPL_TYPE_BOOL:
00694 cx_assert(cpl_property_get_bool(p) ==
00695 cpl_property_get_bool(_p));
00696 break;
00697
00698 case CPL_TYPE_INT:
00699 cx_assert(cpl_property_get_int(p) ==
00700 cpl_property_get_int(_p));
00701 break;
00702
00703 case CPL_TYPE_LONG:
00704 cx_assert(cpl_property_get_long(p) ==
00705 cpl_property_get_long(_p));
00706 break;
00707
00708 case CPL_TYPE_FLOAT:
00709 fval[0] = cpl_property_get_float(p);
00710 fval[1] = cpl_property_get_float(_p);
00711 cx_assert(!memcmp(&fval[0], &fval[1], sizeof(float)));
00712 break;
00713
00714 case CPL_TYPE_DOUBLE:
00715 dval[0] = cpl_property_get_double(p);
00716 dval[1] = cpl_property_get_double(_p);
00717 cx_assert(!memcmp(&dval[0], &dval[1], sizeof(double)));
00718 break;
00719
00720 case CPL_TYPE_STRING:
00721 cx_assert(!strcmp(cpl_property_get_string(p),
00722 cpl_property_get_string(_p)));
00723 break;
00724
00725 default:
00726
00727 cx_log("cpl_propertylist-test", CX_LOG_LEVEL_ERROR, "file %s: "
00728 "line %d: Invalid value type encountered", __FILE__,
00729 __LINE__);
00730 break;
00731 }
00732
00733
00734 }
00735
00736 cpl_propertylist_delete(_plist);
00737 check_nomsg( cpl_error_get_code() );
00738
00739
00740
00741
00742
00743
00744
00745 for (i = 0; i < 7; i++) {
00746 cpl_propertylist_erase(plist, keys[i + 7]);
00747 cx_assert(my_uves_propertylist_contains(plist, keys[i + 7]) == 1);
00748
00749 cpl_propertylist_erase(plist, keys[i + 7]);
00750 cx_assert(my_uves_propertylist_contains(plist, keys[i + 7]) == 0);
00751 }
00752 cx_assert(cpl_propertylist_get_size(plist) == 7);
00753
00754 for (i = 0; i < 7; i++) {
00755 cpl_property *p = cpl_propertylist_get(plist, i);
00756 cx_assert(!strcmp(cpl_property_get_name(p), keys[i]));
00757 }
00758
00759 if (0) test_plist_dump(plist);
00760
00761 cx_assert(cpl_propertylist_get_char(plist, keys[0]) == 'b');
00762 cx_assert(cpl_propertylist_get_bool(plist, keys[1]) == 0);
00763 cx_assert(cpl_propertylist_get_int(plist, keys[2]) == -1);
00764 cx_assert(cpl_propertylist_get_long(plist, keys[3]) == 1);
00765
00766 fval[0] = 9.87654321;
00767 fval[1] = cpl_propertylist_get_float(plist, keys[4]);
00768 cx_assert(!memcmp(&fval[0], &fval[1], sizeof(float)));
00769
00770 dval[0] = -9.87654321;
00771 dval[1] = cpl_propertylist_get_double(plist, keys[5]);
00772 cx_assert(!memcmp(&dval[0], &dval[1], sizeof(double)));
00773
00774 cx_assert(!strcmp(cpl_propertylist_get_string(plist, keys[6]),
00775 comments[0]));
00776
00777 check_nomsg( cpl_error_get_code() );
00778
00779
00780
00781
00782
00783
00784
00785
00786 cpl_propertylist_empty(plist);
00787
00788 cx_assert(cpl_propertylist_is_empty(plist));
00789 cx_assert(cpl_propertylist_get_size(plist) == 0);
00790
00791 cpl_propertylist_delete(plist);
00792
00793 check_nomsg( cpl_error_get_code() );
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804 header = cpl_propertylist_new();
00805
00806 check_nomsg( cpl_error_get_code() );
00807 for (i = 0; (cxsize)i < sizeof hdr / sizeof(struct fcard); i++) {
00808 cpl_msg_info(cpl_func,"iter=%d",(int)i);
00809 cpl_msg_info(cpl_func,"key=%s",hdr[i].key);
00810 cpl_msg_info(cpl_func,"com=%s",hdr[i].com);
00811 cpl_msg_info(cpl_func,"typ=%d",hdr[i].type);
00812
00813
00814 switch (hdr[i].type) {
00815 case CPL_TYPE_CHAR:
00816 cpl_propertylist_append_char(header,hdr[i].key,atoi(hdr[i].val));
00817 p=cpl_propertylist_get_property(header,hdr[i].key);
00818 cpl_propertylist_set_comment(header,hdr[i].key,hdr[i].com);
00819 cpl_msg_info(cpl_func,"val=%d",atoi(hdr[i].val));
00820
00821 break;
00822
00823 case CPL_TYPE_BOOL:
00824 cpl_propertylist_append_bool(header,hdr[i].key,atoi(hdr[i].val));
00825 p=cpl_propertylist_get_property(header,hdr[i].key);
00826 cpl_propertylist_set_comment(header,hdr[i].key,hdr[i].com);
00827 cpl_msg_info(cpl_func,"val=%d",atoi(hdr[i].val));
00828
00829 break;
00830
00831 case CPL_TYPE_INT:
00832 cpl_propertylist_append_int(header,hdr[i].key,atoi(hdr[i].val));
00833 p=cpl_propertylist_get_property(header,hdr[i].key);
00834 cpl_propertylist_set_comment(header,hdr[i].key,hdr[i].com);
00835 cpl_msg_info(cpl_func,"val=%d",atoi(hdr[i].val));
00836
00837 break;
00838
00839 case CPL_TYPE_LONG:
00840 cpl_propertylist_append_long(header,hdr[i].key,atol(hdr[i].val));
00841 p=cpl_propertylist_get_property(header,hdr[i].key);
00842 cpl_propertylist_set_comment(header,hdr[i].key,hdr[i].com);
00843 cpl_msg_info(cpl_func,"val=%ld",atol(hdr[i].val));
00844
00845 break;
00846
00847 case CPL_TYPE_FLOAT:
00848 cpl_propertylist_append_long(header,hdr[i].key,atof(hdr[i].val));
00849 p=cpl_propertylist_get_property(header,hdr[i].key);
00850 cpl_propertylist_set_comment(header,hdr[i].key,hdr[i].com);
00851 cpl_msg_info(cpl_func,"val=%f",atof(hdr[i].val));
00852
00853 break;
00854
00855 case CPL_TYPE_DOUBLE:
00856 cpl_propertylist_append_double(header,hdr[i].key,atof(hdr[i].val));
00857 p=cpl_propertylist_get_property(header,hdr[i].key);
00858 cpl_propertylist_set_comment(header,hdr[i].key,hdr[i].com);
00859 cpl_msg_info(cpl_func,"val=%f",atof(hdr[i].val));
00860
00861 break;
00862
00863 case CPL_TYPE_STRING:
00864 if(strcmp(hdr[i].key,"END") != 0) {
00865 cpl_propertylist_append_string(header,hdr[i].key,hdr[i].val);
00866 p=cpl_propertylist_get_property(header,hdr[i].key);
00867 cpl_propertylist_set_comment(header,hdr[i].key,hdr[i].com);
00868 cpl_msg_info(cpl_func,"val=%s",hdr[i].val);
00869 }
00870
00871 break;
00872
00873 default:
00874
00875 cx_log("uves_propertylist-test", CX_LOG_LEVEL_ERROR, "file %s: "
00876 "line %d: Invalid value type encountered", __FILE__,
00877 __LINE__);
00878 break;
00879 }
00880
00881 }
00882 check_nomsg( cpl_error_get_code() );
00883
00884
00885 file = fopen("cpltest1.fits", "w");
00886 cpl_propertylist_save(header,"cpltest1.fits",CPL_IO_CREATE);
00887
00888
00889 cpl_image* ima=cpl_image_new(2148,2340,CPL_TYPE_FLOAT);
00890 check_nomsg( cpl_error_get_code() );
00891 cpl_image_save(ima,"cpltest1.fits",CPL_BPP_16_SIGNED,header,CPL_IO_DEFAULT);
00892
00893 cpl_image_delete(ima);
00894 fclose(file);
00895
00896
00897
00898 cpl_propertylist_delete(plist);
00899 plist = cpl_propertylist_load("cpltest1.fits", 0);
00900
00901
00902
00903 cx_assert(plist != NULL);
00904
00905
00906 cx_assert(my_uves_propertylist_contains(plist, "END") == 0);
00907
00908
00909 cpl_msg_info(cpl_func,"size plist=%" CPL_SIZE_FORMAT "",cpl_propertylist_get_size(plist));
00910 cpl_msg_info(cpl_func,"size hdr=%d",sizeof hdr);
00911 cpl_msg_info(cpl_func,"size fcard=%d",sizeof(struct fcard));
00912
00913 check_nomsg( cpl_error_get_code() );
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976 check_nomsg( cpl_error_get_code() );
00977
00978
00979
00980
00981
00982
00983 fitsfile* fits_file=NULL;
00984 cxint status = 0;
00985
00986
00987 fits_open_diskfile(&fits_file,(cxchar*)"cpltest1.fits", READONLY, &status);
00988 _plist = cpl_propertylist_from_fitsfile(fits_file) ;
00989 cx_assert(_plist != NULL);
00990 cx_assert(cpl_propertylist_get_size(plist) ==
00991 cpl_propertylist_get_size(_plist));
00992
00993
00994
00995 for (i = 0; i < cpl_propertylist_get_size(plist); i++) {
00996 cpl_property *p = cpl_propertylist_get(plist, i);
00997 cpl_property *_p = cpl_propertylist_get(_plist, i);
00998
00999 cx_assert(strcmp(cpl_property_get_name(p),
01000 cpl_property_get_name(_p)) == 0);
01001 cx_assert(strcmp(cpl_property_get_comment(p),
01002 cpl_property_get_comment(_p)) == 0);
01003 cx_assert(cpl_property_get_type(p) == cpl_property_get_type(_p));
01004
01005 switch (cpl_property_get_type(p)) {
01006 case CPL_TYPE_BOOL:
01007 cx_assert(cpl_property_get_bool(p) == cpl_property_get_bool(_p));
01008 break;
01009
01010 case CPL_TYPE_INT:
01011 cx_assert(cpl_property_get_int(p) == cpl_property_get_int(_p));
01012 break;
01013
01014 case CPL_TYPE_DOUBLE:
01015 cx_assert(cpl_property_get_double(p) ==
01016 cpl_property_get_double(_p));
01017 break;
01018
01019 case CPL_TYPE_STRING:
01020 cx_assert(strcmp(cpl_property_get_string(p),
01021 cpl_property_get_string(_p)) == 0);
01022 break;
01023
01024 default:
01025 cx_log("cpl_propertylist-test", CX_LOG_LEVEL_ERROR,
01026 "file %s: line %d: Invalid value type encountered",
01027 __FILE__, __LINE__);
01028 break;
01029 }
01030 }
01031
01032 fits_close_file(fits_file, &status);
01033 cpl_propertylist_delete(_plist);
01034
01035 check_nomsg( cpl_error_get_code() );
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108 _plist = cpl_propertylist_new();
01109
01110
01111
01112 cpl_propertylist_copy_property_regexp(_plist, plist, "^ESO .*", 0);
01113
01114
01115
01116
01117 cx_assert(cpl_propertylist_get_size(_plist) == 6);
01118 cx_assert(my_uves_propertylist_contains(_plist, "ESO OBS DID") != 0);
01119 cx_assert(my_uves_propertylist_contains(_plist, "ESO OBS OBSERVER") != 0);
01120 cx_assert(my_uves_propertylist_contains(_plist, "ESO OBS PI-COI NAME") != 0);
01121 cx_assert(my_uves_propertylist_contains(_plist, "ESO INS GRAT NAME") != 0);
01122 cx_assert(my_uves_propertylist_contains(_plist, "ESO PRO CATG") != 0);
01123 cx_assert(my_uves_propertylist_contains(_plist, "ESO TPL NEXP") != 0);
01124
01125
01126
01127 cpl_propertylist_empty(_plist);
01128 cx_assert(cpl_propertylist_is_empty(_plist) != 0);
01129
01130 cpl_propertylist_copy_property_regexp(_plist, plist, "^ESO .*", 1);
01131 cx_assert(cpl_propertylist_get_size(_plist) ==
01132 (cpl_propertylist_get_size(plist) - 6));
01133
01134 check_nomsg( cpl_error_get_code() );
01135
01136
01137
01138
01139
01140
01141
01142
01143 cpl_propertylist_empty(_plist);
01144 cx_assert(cpl_propertylist_is_empty(_plist) != 0);
01145
01146 cpl_propertylist_copy_property_regexp(_plist, plist, "^ESO .*", 0);
01147 cx_assert(cpl_propertylist_get_size(_plist) == 6);
01148
01149 cpl_propertylist_erase_regexp(_plist, "^ESO OBS .*", 0);
01150 cx_assert(cpl_propertylist_get_size(_plist) == 3);
01151
01152 cpl_propertylist_erase_regexp(_plist, "ESO TPL NEXP", 0);
01153 cx_assert(cpl_propertylist_get_size(_plist) == 2);
01154
01155 cpl_propertylist_delete(_plist);
01156 cpl_propertylist_delete(plist);
01157 check_nomsg( cpl_error_get_code() );
01158
01159
01160
01161
01162
01163
01164
01165
01166 plist = NULL;
01167
01168 plist = cpl_propertylist_load_regexp("cpltest1.fits", 0,
01169 "^ESO .*", 0);
01170 cx_assert(plist != NULL);
01171 cx_assert(cpl_propertylist_is_empty(plist) == 0);
01172 cx_assert(cpl_propertylist_get_size(plist) == 6);
01173 cx_assert(my_uves_propertylist_contains(plist, "ESO OBS DID") != 0);
01174 cx_assert(my_uves_propertylist_contains(plist, "ESO OBS OBSERVER") != 0);
01175 cx_assert(my_uves_propertylist_contains(plist, "ESO OBS PI-COI NAME") != 0);
01176 cx_assert(my_uves_propertylist_contains(plist, "ESO INS GRAT NAME") != 0);
01177 cx_assert(my_uves_propertylist_contains(plist, "ESO PRO CATG") != 0);
01178 cx_assert(my_uves_propertylist_contains(plist, "ESO TPL NEXP") != 0);
01179
01180 cpl_propertylist_delete(plist);
01181 check_nomsg( cpl_error_get_code() );
01182
01183
01184
01185
01186
01187
01188
01189
01190 plist = cpl_propertylist_new();
01191 _plist = cpl_propertylist_new();
01192
01193 cpl_propertylist_append_char(plist, keys[0], 'a');
01194 cpl_propertylist_set_comment(plist, keys[0], comments[0]);
01195
01196 cpl_propertylist_append_bool(plist, keys[1], 1);
01197 cpl_propertylist_set_comment(plist, keys[1], comments[1]);
01198
01199 cpl_propertylist_append_int(plist, keys[2], -1);
01200 cpl_propertylist_set_comment(plist, keys[2], comments[2]);
01201
01202 cpl_propertylist_append_long(plist, keys[3], 32768);
01203 cpl_propertylist_set_comment(plist, keys[3], comments[3]);
01204
01205 cpl_propertylist_append_float(_plist, keys[4], fval[0]);
01206 cpl_propertylist_set_comment(_plist, keys[4], comments[4]);
01207
01208 cpl_propertylist_append_double(_plist, keys[5], dval[0]);
01209 cpl_propertylist_set_comment(_plist, keys[5], comments[5]);
01210
01211 cpl_propertylist_append_string(_plist, keys[6], comments[6]);
01212 cpl_propertylist_set_comment(_plist, keys[6], comments[6]);
01213
01214 cx_assert(!cpl_propertylist_is_empty(plist));
01215 cx_assert(cpl_propertylist_get_size(plist) == 4);
01216
01217 cx_assert(!cpl_propertylist_is_empty(_plist));
01218 cx_assert(cpl_propertylist_get_size(_plist) == 3);
01219
01220 cpl_propertylist_append(plist, _plist);
01221
01222 cx_assert(!cpl_propertylist_is_empty(plist));
01223 cx_assert(cpl_propertylist_get_size(plist) == 7);
01224
01225 cx_assert(!cpl_propertylist_is_empty(_plist));
01226 cx_assert(cpl_propertylist_get_size(_plist) == 3);
01227
01228 for (i = 0; i < cpl_propertylist_get_size(plist); i++) {
01229 cpl_property *p = cpl_propertylist_get(plist, i);
01230
01231 cx_assert(!strcmp(cpl_property_get_name(p), keys[i]));
01232 cx_assert(!strcmp(cpl_property_get_comment(p), comments[i]));
01233 cx_assert(cpl_property_get_type(p) == types[i]);
01234
01235 cx_assert(my_uves_propertylist_contains(plist, keys[i]));
01236 cx_assert(!strcmp(cpl_propertylist_get_comment(plist, keys[i]),
01237 comments[i]));
01238 cx_assert(cpl_propertylist_get_type(plist, keys[i]) == types[i]);
01239 }
01240
01241 check_nomsg( cpl_error_get_code() );
01242
01243 cpl_propertylist_delete(_plist);
01244 cpl_propertylist_delete(plist);
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273 cleanup:
01274
01275 return 0;
01276
01277 }
01278
01279 int main(void)
01280 {
01281
01282 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
01283
01284 test_main();
01285
01286 return cpl_test_end(0);
01287 }