31 #undef CX_DISABLE_ASSERT
35 #include <uves_propertylist.h>
44 #include <cxmessages.h>
52 #define FLT_EPS 1.0e-6
53 #define DBL_EPS 1.0e-14
57 test_property_dump(cpl_property *property)
60 const cxchar *name = cpl_property_get_name(property);
61 const cxchar *comment = cpl_property_get_comment(property);
65 long size = cpl_property_get_size(property);
67 cpl_type type = cpl_property_get_type(property);
70 fprintf(stderr,
"Property at address %p\n", (
void *)property);
71 fprintf(stderr,
"\tname : %p '%s'\n", (
void *)name, name);
72 fprintf(stderr,
"\tcomment: %p '%s'\n", (
void *)comment, comment);
73 fprintf(stderr,
"\ttype : %#09x\n", type);
74 fprintf(stderr,
"\tsize : %ld\n", size);
75 fprintf(stderr,
"\tvalue : ");
80 c = cpl_property_get_char(property);
82 fprintf(stderr,
"''");
84 fprintf(stderr,
"'%c'", c);
88 fprintf(stderr,
"%d", cpl_property_get_bool(property));
92 fprintf(stderr,
"%d", cpl_property_get_int(property));
96 fprintf(stderr,
"%ld", cpl_property_get_long(property));
100 fprintf(stderr,
"%.7g", cpl_property_get_float(property));
103 case CPL_TYPE_DOUBLE:
104 fprintf(stderr,
"%.15g", cpl_property_get_double(property));
107 case CPL_TYPE_STRING:
108 fprintf(stderr,
"'%s'", cpl_property_get_string(property));
112 fprintf(stderr,
"unknown.");
117 fprintf(stderr,
"\n");
132 fprintf(stderr,
"Property list at address %p:\n", (
void *) plist);
134 for (i = 0; i < sz; i++) {
135 cpl_property *p = uves_propertylist_get(plist, i);
136 test_property_dump(p);
143 static int test_main(
void)
146 const cxchar *keys[] = {
147 "a",
"b",
"c",
"d",
"e",
"f",
"g",
148 "A",
"B",
"C",
"D",
"E",
"F",
"G"
151 const cxchar *comments[] = {
155 "A long integer value",
156 "A floating point number",
157 "A double precision number",
173 cxfloat fval[] = {-1.23456789, 0.};
174 cxdouble dval[] = {-1.23456789, 0.};
178 qfits_header *header, *_header;
187 struct fcard hdr[] = {
189 "Standard FITS format (NOST-100.0)",
192 "# of bits storing pix values",
195 "# of axes in frame",
204 "European Southern Observatory",
206 {
"DATE",
"2002-03-08T04:27:21.420",
207 "Date this file was written (dd/mm/yyyy)",
209 {
"MJD-OBS",
"52341.17813019",
210 "Obs start 2002-03-08T04:16:30.448",
212 {
"DATE-OBS",
"2002-03-08T04:16:30.448",
213 "Date of observation",
215 {
"EXPTIME",
"600.000",
216 "Total integration time. 00:10:00.000",
222 "12:05:40.1 RA (J2000) pointing",
225 "-07:39:19.9 DEC (J2000) pointing",
228 "Standard FK5 (years)",
231 "Coordinate reference frame",
234 "10:38:29.370 LST at start",
237 "04:17:18.000 UT at start",
239 {
"OBSERVER",
"UNKNOWN",
242 {
"INSTRUME",
"UNKNOWN",
245 {
"PI-COI",
"'555555555'",
246 "Name of PI and COI",
252 "Number of parameters per group",
257 {
"CRVAL1",
"181.41734",
258 "12:05:40.1, RA at ref pixel",
260 {
"CRPIX1",
"2341.8585366",
261 "Reference pixel in X",
263 {
"CDELT1",
"0.20500000",
264 "SS arcsec per pixel in RA",
266 {
"CTYPE1",
"RA---TAN",
267 "pixel coordinate system",
269 {
"CRVAL2",
"-7.65555",
270 "-07:39:19.9, DEC at ref pixel",
272 {
"CRPIX2",
"2487.8585366",
273 "Reference pixel in Y",
275 {
"CDELT2",
"0.20500000",
276 "SS arcsec per pixel in DEC",
278 {
"CTYPE2",
"DEC--TAN",
279 "pixel coordinate system",
282 "pixel=FITS*BSCALE+BZERO",
285 "pixel=FITS*BSCALE+BZERO",
287 {
"CD1_1",
"0.000057",
288 "Translation matrix element",
290 {
"CD1_2",
"0.000000",
291 "Translation matrix element",
293 {
"CD2_1",
"0.000000",
294 "Translation matrix element",
296 {
"CD2_2",
"0.000057",
297 "Translation matrix element",
299 {
"HIERARCH ESO OBS DID",
"ESO-VLT-DIC.OBS-1.7",
302 {
"HIERARCH ESO OBS OBSERVER",
"UNKNOWN",
305 {
"HIERARCH ESO OBS PI-COI NAME",
"UNKNOWN",
308 {
"HIERARCH ESO INS GRAT NAME",
"HR",
311 {
"HIERARCH ESO PRO CATG",
"X",
314 {
"HIERARCH ESO TPL NEXP",
"5",
315 "Number of exposures",
317 {
"HISTORY",
"1st history record", NULL, CPL_TYPE_STRING},
318 {
"COMMENT",
"1st comment record", NULL, CPL_TYPE_STRING},
319 {
"HISTORY",
"2st history record", NULL, CPL_TYPE_STRING},
320 {
"COMMENT",
"2st comment record", NULL, CPL_TYPE_STRING},
321 {
"COMMENT",
"3st comment record", NULL, CPL_TYPE_STRING},
322 {
"HISTORY",
"3st history record", NULL, CPL_TYPE_STRING},
323 {
"END", NULL, NULL, CPL_TYPE_STRING}
328 const cxchar *longname =
"0123456789012345678901234567890123456789"
329 "0123456789012345678901234567890123456789";
338 cx_assert(plist != NULL);
348 uves_propertylist_append_char(plist, keys[0],
'a');
351 uves_propertylist_append_bool(plist, keys[1], 1);
354 uves_propertylist_append_int(plist, keys[2], -1);
357 uves_propertylist_append_long(plist, keys[3], 32768);
360 uves_propertylist_append_float(plist, keys[4], fval[0]);
363 uves_propertylist_append_double(plist, keys[5], dval[0]);
366 uves_propertylist_append_string(plist, keys[6], comments[6]);
374 cpl_property *p = uves_propertylist_get(plist, i);
376 cx_assert(!strcmp(cpl_property_get_name(p), keys[i]));
377 cx_assert(!strcmp(cpl_property_get_comment(p), comments[i]));
378 cx_assert(cpl_property_get_type(p) == types[i]);
392 cx_assert(!memcmp(&fval[0], &fval[1],
sizeof(
float)));
395 cx_assert(!memcmp(&dval[0], &dval[1],
sizeof(
double)));
418 fval[0] = 9.87654321;
421 cx_assert(!memcmp(&fval[0], &fval[1],
sizeof(
float)));
423 dval[0] = -9.87654321;
426 cx_assert(!memcmp(&dval[0], &dval[1],
sizeof(
double)));
437 if (0) test_plist_dump(plist);
440 CPL_ERROR_TYPE_MISMATCH);
441 if (0) test_plist_dump(plist);
445 CPL_ERROR_TYPE_MISMATCH);
448 CPL_ERROR_TYPE_MISMATCH);
450 CPL_ERROR_TYPE_MISMATCH);
452 CPL_ERROR_TYPE_MISMATCH);
454 CPL_ERROR_TYPE_MISMATCH);
457 CPL_ERROR_TYPE_MISMATCH);
498 for (i = 0; i < 7; i++) {
499 cpl_property *p0 = uves_propertylist_get(plist, 3 * i);
500 cpl_property *p1 = uves_propertylist_get(plist, 3 * i + 1);
501 cpl_property *p2 = uves_propertylist_get(plist, 3 * i + 2);
503 cx_assert(!strcmp(cpl_property_get_name(p0), keys[i + 7]));
504 cx_assert(!strcmp(cpl_property_get_name(p1), keys[i]));
505 cx_assert(!strcmp(cpl_property_get_name(p2), keys[i + 7]));
507 switch (cpl_property_get_type(p0)) {
509 cx_assert(cpl_property_get_char(p0) ==
'a');
510 cx_assert(cpl_property_get_char(p2) ==
'c');
514 cx_assert(cpl_property_get_bool(p0) == 0);
515 cx_assert(cpl_property_get_bool(p2) == 1);
519 cx_assert(cpl_property_get_int(p0) == 0);
520 cx_assert(cpl_property_get_int(p2) == 1);
524 cx_assert(cpl_property_get_long(p0) == 123456789);
525 cx_assert(cpl_property_get_long(p2) == 123456789);
529 fval[1] = cpl_property_get_float(p0);
530 cx_assert(!memcmp(&fval[0], &fval[1],
sizeof(
float)));
532 fval[1] = -cpl_property_get_float(p2);
533 cx_assert(!memcmp(&fval[0], &fval[1],
sizeof(
float)));
536 case CPL_TYPE_DOUBLE:
537 dval[1] = cpl_property_get_double(p0);
538 cx_assert(!memcmp(&dval[0], &dval[1],
sizeof(
double)));
540 dval[1] = -cpl_property_get_double(p2);
541 cx_assert(!memcmp(&dval[0], &dval[1],
sizeof(
double)));
544 case CPL_TYPE_STRING:
545 cx_assert(!strcmp(cpl_property_get_string(p0),
""));
546 cx_assert(!strcmp(cpl_property_get_string(p2),
""));
551 cx_log(
"uves_propertylist-test", CX_LOG_LEVEL_ERROR,
"file %s: "
552 "line %d: Invalid value type encountered", __FILE__,
566 CPL_ERROR_DATA_NOT_FOUND);
568 CPL_ERROR_DATA_NOT_FOUND);
570 CPL_ERROR_DATA_NOT_FOUND);
572 CPL_ERROR_DATA_NOT_FOUND);
574 CPL_ERROR_DATA_NOT_FOUND);
576 CPL_ERROR_DATA_NOT_FOUND);
578 CPL_ERROR_DATA_NOT_FOUND);
617 cx_assert(_plist != NULL);
618 cx_assert(_plist != plist);
621 cpl_property *p = uves_propertylist_get(plist, i);
622 cpl_property *_p = uves_propertylist_get(_plist, i);
624 cx_assert(cpl_property_get_name(p) != cpl_property_get_name(_p));
625 cx_assert(!strcmp(cpl_property_get_name(p),
626 cpl_property_get_name(_p)));
627 cx_assert(cpl_property_get_comment(p) == NULL ||
628 (cpl_property_get_comment(p) !=
629 cpl_property_get_comment(_p)));
630 cx_assert(cpl_property_get_comment(p) == NULL ||
631 !strcmp(cpl_property_get_comment(p),
632 cpl_property_get_comment(_p)));
634 switch (cpl_property_get_type(p)) {
636 cx_assert(cpl_property_get_char(p) ==
637 cpl_property_get_char(_p));
641 cx_assert(cpl_property_get_bool(p) ==
642 cpl_property_get_bool(_p));
646 cx_assert(cpl_property_get_int(p) ==
647 cpl_property_get_int(_p));
651 cx_assert(cpl_property_get_long(p) ==
652 cpl_property_get_long(_p));
656 fval[0] = cpl_property_get_float(p);
657 fval[1] = cpl_property_get_float(_p);
658 cx_assert(!memcmp(&fval[0], &fval[1],
sizeof(
float)));
661 case CPL_TYPE_DOUBLE:
662 dval[0] = cpl_property_get_double(p);
663 dval[1] = cpl_property_get_double(_p);
664 cx_assert(!memcmp(&dval[0], &dval[1],
sizeof(
double)));
667 case CPL_TYPE_STRING:
668 cx_assert(!strcmp(cpl_property_get_string(p),
669 cpl_property_get_string(_p)));
674 cx_log(
"uves_propertylist-test", CX_LOG_LEVEL_ERROR,
"file %s: "
675 "line %d: Invalid value type encountered", __FILE__,
688 for (i = 0; i < 7; i++) {
697 for (i = 0; i < 7; i++) {
698 cpl_property *p = uves_propertylist_get(plist, i);
699 cx_assert(!strcmp(cpl_property_get_name(p), keys[i]));
702 if (0) test_plist_dump(plist);
709 fval[0] = 9.87654321;
711 cx_assert(!memcmp(&fval[0], &fval[1],
sizeof(
float)));
713 dval[0] = -9.87654321;
715 cx_assert(!memcmp(&dval[0], &dval[1],
sizeof(
double)));
740 header = qfits_header_new();
742 for (i = 0; (cxsize)i <
sizeof hdr /
sizeof(
struct fcard); i++)
743 qfits_header_append(header, hdr[i].key, hdr[i].val, hdr[i].com, NULL);
745 file = fopen(
"cpltest1.fits",
"w");
746 qfits_header_dump(header, file);
752 cx_assert(plist != NULL);
756 (
sizeof hdr /
sizeof(
struct fcard) - 1));
759 const cxchar *s = hdr[i].key;
760 cpl_property *p = uves_propertylist_get(plist, i);
767 if (strstr(hdr[i].key,
"HIERARCH"))
768 s = hdr[i].key + strlen(
"HIERARCH") + 1;
770 cx_assert(!strcmp(cpl_property_get_name(p), s));
771 cx_assert(hdr[i].com == NULL ||
772 !strcmp(cpl_property_get_comment(p), hdr[i].com));
773 cx_assert(cpl_property_get_type(p) == hdr[i].type);
775 switch (hdr[i].type) {
777 cx_assert(cpl_property_get_bool(p) ==
778 (*hdr[i].val ==
'T' ? 1 : 0));
782 cx_assert(cpl_property_get_int(p) == atoi(hdr[i].val));
785 case CPL_TYPE_DOUBLE:
786 dval[0] = cpl_property_get_double(p);
787 dval[1] = atof(hdr[i].val);
788 cx_assert(!memcmp(&dval[0], &dval[1],
sizeof(
double)));
791 case CPL_TYPE_STRING:
792 cx_assert(!strcmp(cpl_property_get_string(p),
793 qfits_pretty_string(hdr[i].val)));
797 cx_log(
"uves_propertylist-test", CX_LOG_LEVEL_ERROR,
"file %s: "
798 "line %d: Invalid value type encountered", __FILE__,
811 _plist = uves_propertylist_from_fits(header) ;
812 cx_assert(_plist != NULL);
817 cpl_property *p = uves_propertylist_get(plist, i);
818 cpl_property *_p = uves_propertylist_get(_plist, i);
820 cx_assert(strcmp(cpl_property_get_name(p),
821 cpl_property_get_name(_p)) == 0);
822 cx_assert(strcmp(cpl_property_get_comment(p),
823 cpl_property_get_comment(_p)) == 0);
824 cx_assert(cpl_property_get_type(p) == cpl_property_get_type(_p));
826 switch (cpl_property_get_type(p)) {
828 cx_assert(cpl_property_get_bool(p) == cpl_property_get_bool(_p));
832 cx_assert(cpl_property_get_int(p) == cpl_property_get_int(_p));
835 case CPL_TYPE_DOUBLE:
836 cx_assert(cpl_property_get_double(p) ==
837 cpl_property_get_double(_p));
840 case CPL_TYPE_STRING:
841 cx_assert(strcmp(cpl_property_get_string(p),
842 cpl_property_get_string(_p)) == 0);
846 cx_log(
"uves_propertylist-test", CX_LOG_LEVEL_ERROR,
847 "file %s: line %d: Invalid value type encountered",
862 qfits_header_sort(&header);
864 file = fopen(
"cpltest1.fits",
"w");
865 qfits_header_dump(header, file);
869 _header = uves_propertylist_to_fits(plist);
870 cx_assert(_header != NULL);
872 file = fopen(
"cpltest2.fits",
"w");
873 qfits_header_dump(_header, file);
877 for (i = 0; i < header->n; i++) {
878 cxchar key[FITS_LINESZ + 1];
879 cxchar val[FITS_LINESZ + 1];
880 cxchar com[FITS_LINESZ + 1];
882 cxchar _key[FITS_LINESZ + 1];
883 cxchar _val[FITS_LINESZ + 1];
884 cxchar _com[FITS_LINESZ + 1];
887 qfits_header_getitem(header, i, key, val, com, NULL);
888 cx_assert(qfits_header_getitem(_header, i, _key, _val,
891 cx_assert(!strcmp(key, _key));
892 cx_assert(_com == NULL || !strcmp(com, _com));
894 switch (qfits_get_type(val)) {
897 fval[1] = atof(_val);
899 cx_assert(fabs(fval[0] - fval[1]) < FLT_EPS);
903 cx_assert(strlen(val) == 0 ||
904 !strcmp(qfits_pretty_string(val),
905 qfits_pretty_string(_val)));
911 qfits_header_destroy(header);
912 qfits_header_destroy(_header);
969 cx_assert(plist != NULL);
989 uves_propertylist_append_char(plist, keys[0],
'a');
992 uves_propertylist_append_bool(plist, keys[1], 1);
995 uves_propertylist_append_int(plist, keys[2], -1);
998 uves_propertylist_append_long(plist, keys[3], 32768);
1001 uves_propertylist_append_float(_plist, keys[4], fval[0]);
1004 uves_propertylist_append_double(_plist, keys[5], dval[0]);
1007 uves_propertylist_append_string(_plist, keys[6], comments[6]);
1025 cpl_property *p = uves_propertylist_get(plist, i);
1027 cx_assert(!strcmp(cpl_property_get_name(p), keys[i]));
1028 cx_assert(!strcmp(cpl_property_get_comment(p), comments[i]));
1029 cx_assert(cpl_property_get_type(p) == types[i]);
1045 uves_propertylist_append_string(plist, longname, comments[6]);
1047 qfits_header_destroy(uves_propertylist_to_fits(plist));
1056 cx_assert( cpl_error_get_code() == CPL_ERROR_UNSPECIFIED );
1069 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
1074 return cpl_test_end(0);
cpl_error_code uves_propertylist_insert_after_double(uves_propertylist *self, const char *after, const char *name, double value)
Insert a double value into a property list after the given position.
int uves_propertylist_get_bool(const uves_propertylist *self, const char *name)
Get the boolean value of the given property list entry.
const char * uves_propertylist_get_comment(const uves_propertylist *self, const char *name)
Get the comment of the given property list entry.
cpl_error_code uves_propertylist_insert_int(uves_propertylist *self, const char *here, const char *name, int value)
Insert a integer value into a property list at the given position.
void uves_propertylist_empty(uves_propertylist *self)
Remove all properties from a property list.
int uves_propertylist_erase(uves_propertylist *self, const char *name)
Erase the given property from a property list.
cpl_error_code uves_propertylist_insert_after_char(uves_propertylist *self, const char *after, const char *name, char value)
Insert a character value into a property list after the given position.
int uves_propertylist_is_empty(const uves_propertylist *self)
Check whether a property list is empty.
double uves_propertylist_get_double(const uves_propertylist *self, const char *name)
Get the double value of the given property list entry.
cpl_error_code uves_propertylist_insert_float(uves_propertylist *self, const char *here, const char *name, float value)
Insert a float value into a property list at the given position.
cpl_error_code uves_propertylist_set_double(uves_propertylist *self, const char *name, double value)
Set the value of the given double property list entry.
cpl_error_code uves_propertylist_insert_bool(uves_propertylist *self, const char *here, const char *name, int value)
Insert a boolean value into a property list at the given position.
cpl_error_code uves_propertylist_insert_after_long(uves_propertylist *self, const char *after, const char *name, long value)
Insert a long value into a property list after the given position.
cpl_error_code uves_propertylist_insert_long(uves_propertylist *self, const char *here, const char *name, long value)
Insert a long value into a property list at the given position.
long uves_propertylist_get_long(const uves_propertylist *self, const char *name)
Get the long value of the given property list entry.
cpl_type uves_propertylist_get_type(const uves_propertylist *self, const char *name)
Get the the type of a property list entry.
uves_propertylist * uves_propertylist_new(void)
Create an empty property list.
long uves_propertylist_get_size(const uves_propertylist *self)
Get the current size of a property list.
cpl_error_code uves_propertylist_set_comment(uves_propertylist *self, const char *name, const char *comment)
Modify the comment field of the given property list entry.
const char * uves_propertylist_get_string(const uves_propertylist *self, const char *name)
Get the string value of the given property list entry.
uves_propertylist * uves_propertylist_load(const char *name, int position)
Create a property list from a file.
cpl_error_code uves_propertylist_set_string(uves_propertylist *self, const char *name, const char *value)
Set the value of the given string property list entry.
cpl_error_code uves_propertylist_set_int(uves_propertylist *self, const char *name, int value)
Set the value of the given integer property list entry.
cpl_error_code uves_propertylist_copy_property_regexp(uves_propertylist *self, const uves_propertylist *other, const char *regexp, int invert)
Copy matching properties from another property list.
char uves_propertylist_get_char(const uves_propertylist *self, const char *name)
Get the character value of the given property list entry.
cpl_error_code uves_propertylist_insert_char(uves_propertylist *self, const char *here, const char *name, char value)
Insert a character value into a property list at the given position.
cpl_error_code uves_propertylist_set_float(uves_propertylist *self, const char *name, float value)
Set the value of the given float property list entry.
int uves_propertylist_get_int(const uves_propertylist *self, const char *name)
Get the integer value of the given property list entry.
cpl_error_code uves_propertylist_set_char(uves_propertylist *self, const char *name, char value)
Set the value of the given character property list entry.
int uves_propertylist_erase_regexp(uves_propertylist *self, const char *regexp, int invert)
Erase all properties with name matching a given regular expression.
cpl_error_code uves_propertylist_insert_double(uves_propertylist *self, const char *here, const char *name, double value)
Insert a double value into a property list at the given position.
cpl_error_code uves_propertylist_insert_after_string(uves_propertylist *self, const char *after, const char *name, const char *value)
Insert a string value into a property list after the given position.
cpl_error_code uves_propertylist_insert_after_bool(uves_propertylist *self, const char *after, const char *name, int value)
Insert a boolean value into a property list after the given position.
cpl_error_code uves_propertylist_insert_after_int(uves_propertylist *self, const char *after, const char *name, int value)
Insert a integer value into a property list after the given position.
cpl_error_code uves_propertylist_set_long(uves_propertylist *self, const char *name, long value)
Set the value of the given long property list entry.
uves_propertylist * uves_propertylist_duplicate(const uves_propertylist *self)
Create a copy of the given property list.
int uves_propertylist_contains(const uves_propertylist *self, const char *name)
Check whether a property is present in a property list.
void uves_propertylist_delete(const uves_propertylist *self)
Destroy a property list.
float uves_propertylist_get_float(const uves_propertylist *self, const char *name)
Get the float value of the given property list entry.
cpl_error_code uves_propertylist_insert_after_float(uves_propertylist *self, const char *after, const char *name, float value)
Insert a float value into a property list after the given position.
cpl_error_code uves_propertylist_set_bool(uves_propertylist *self, const char *name, int value)
Set the value of the given boolean property list entry.
cpl_error_code uves_propertylist_insert_string(uves_propertylist *self, const char *here, const char *name, const char *value)
Insert a string value into a property list at the given position.
int main(void)
Various tests of low-level library functions.
uves_propertylist * uves_propertylist_load_regexp(const char *name, int position, const char *regexp, int invert)
Create a filtered property list from a file.
cpl_error_code uves_propertylist_append(uves_propertylist *self, const uves_propertylist *other)
Append a property list..