UVES Pipeline Reference Manual  5.4.6
cpl_propertylist-test.c
1 /* $Id: cpl_propertylist-test.c,v 1.6 2012-01-17 07:53:20 amodigli Exp $
2  *
3  * This file is part of the ESO Common Pipeline Library
4  * Copyright (C) 2001-2005 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: amodigli $
23  * $Date: 2012-01-17 07:53:20 $
24  * $Revision: 1.6 $
25  * $Name: not supported by cvs2svn $
26  */
27 #ifdef HAVE_CONFIG_H
28 # include <config.h>
29 #endif
30 
31 #undef CX_DISABLE_ASSERT
32 #undef CX_LOG_DOMAIN
33 
34 
35 #include <uves_propertylist.h>
36 
37 //#include "cpl_init.h"
38 //#include "cpl_error.h"
39 //#include "cpl_propertylist_impl.h"
40 #include <uves_error.h>
41 #include <cpl.h>
42 #include <cxmemory.h>
43 #include <cxmessages.h>
44 #include <cxdeque.h>
45 #include <qfits.h>
46 #include <fitsio.h>
47 
48 #include <stdio.h>
49 #include <stdlib.h>
50 #include <string.h>
51 #include <math.h>
52 #include <uves_propertylist.h>
53 #define FLT_EPS 1.0e-6
54 #define DBL_EPS 1.0e-14
55 
56 
57 static void
58 test_property_dump(cpl_property *property)
59 {
60 
61  const cxchar *name = cpl_property_get_name(property);
62  const cxchar *comment = cpl_property_get_comment(property);
63 
64  cxchar c;
65 
66  long size = cpl_property_get_size(property);
67 
68  cpl_type type = cpl_property_get_type(property);
69 
70 
71  fprintf(stderr, "Property at address %p\n", (void *)property);
72  fprintf(stderr, "\tname : %p '%s'\n", (void *)name, name);
73  fprintf(stderr, "\tcomment: %p '%s'\n", (void *)comment, comment);
74  fprintf(stderr, "\ttype : %#09x\n", type);
75  fprintf(stderr, "\tsize : %ld\n", size);
76  fprintf(stderr, "\tvalue : ");
77 
78 
79  switch (type) {
80  case CPL_TYPE_CHAR:
81  c = cpl_property_get_char(property);
82  if (!c)
83  fprintf(stderr, "''");
84  else
85  fprintf(stderr, "'%c'", c);
86  break;
87 
88  case CPL_TYPE_BOOL:
89  fprintf(stderr, "%d", cpl_property_get_bool(property));
90  break;
91 
92  case CPL_TYPE_INT:
93  fprintf(stderr, "%d", cpl_property_get_int(property));
94  break;
95 
96  case CPL_TYPE_LONG:
97  fprintf(stderr, "%ld", cpl_property_get_long(property));
98  break;
99 
100  case CPL_TYPE_FLOAT:
101  fprintf(stderr, "%.7g", cpl_property_get_float(property));
102  break;
103 
104  case CPL_TYPE_DOUBLE:
105  fprintf(stderr, "%.15g", cpl_property_get_double(property));
106  break;
107 
108  case CPL_TYPE_STRING:
109  fprintf(stderr, "'%s'", cpl_property_get_string(property));
110  break;
111 
112  default:
113  fprintf(stderr, "unknown.");
114  break;
115 
116  }
117 
118  fprintf(stderr, "\n");
119 
120  return;
121 
122 }
123 
124 
125 static void
126 test_plist_dump(cpl_propertylist *plist)
127 {
128 
129  cxlong i;
130  cxlong sz = cpl_propertylist_get_size(plist);
131 
132 
133  fprintf(stderr, "Property list at address %p:\n", (void *) plist);
134 
135  for (i = 0; i < sz; i++) {
136  cpl_property *p = cpl_propertylist_get(plist, i);
137  test_property_dump(p);
138  }
139 
140  return;
141 
142 }
143 
144 static int test_main(void)
145 {
146 
147  const cxchar *keys[] = {
148  "a", "b", "c", "d", "e", "f", "g",
149  "A", "B", "C", "D", "E", "F", "G"
150  };
151 
152  const cxchar *comments[] = {
153  "A character value",
154  "A boolean value",
155  "A integer value",
156  "A long integer value",
157  "A floating point number",
158  "A double precision number",
159  "A string value",
160  };
161 
162  cpl_type types[] = {
163  CPL_TYPE_CHAR,
164  CPL_TYPE_BOOL,
165  CPL_TYPE_INT,
166  CPL_TYPE_LONG,
167  CPL_TYPE_FLOAT,
168  CPL_TYPE_DOUBLE,
169  CPL_TYPE_STRING
170  };
171 
172  cxlong i;
173 
174  cxfloat fval[] = {-1.23456789, 0.};
175  cxdouble dval[] = {-1.23456789, 0.};
176 
177  cpl_propertylist *plist=NULL;
178  cpl_propertylist *_plist=NULL;
179 
180  cpl_propertylist *header=NULL;
181  //cpl_propertylist *_header=NULL;
182  cpl_property* p=NULL;
183 
184  struct fcard {
185  const cxchar *key;
186  const cxchar *val;
187  const cxchar *com;
188  cpl_type type;
189  };
190 
191  struct fcard hdr[] = {
192  {"SIMPLE", "T",
193  // "Standard FITS format (NOST-100.0)",
194  //"Fits format",
195  "file does conform to FITS standard",
196  CPL_TYPE_BOOL},
197  {"BITPIX", "16",
198  // "# of bits storing pix values",
199  //"Bits per pixel",
200  "number of bits per data pixel",
201  CPL_TYPE_INT},
202  {"NAXIS", "2",
203  // "# of axes in frame",
204  "number of data axes",
205  CPL_TYPE_INT},
206  {"NAXIS1", "2148",
207  // "# pixels/axis",
208  "length of data axis 1",
209  CPL_TYPE_INT},
210  {"NAXIS2", "2340",
211  // "# pixels/axis",
212  "length of data axis 2",
213  CPL_TYPE_INT},
214  {"EXTEND", "T",
215  // "# pixels/axis",
216  "FITS dataset may contain extensions",
217  CPL_TYPE_BOOL},
218  {"ORIGIN", "ESO",
219  "European Southern Observatory",
220  CPL_TYPE_STRING},
221  {"DATE", "2002-03-08T04:27:21.420",
222  "Date this file was written (dd/mm/yyyy)",
223  CPL_TYPE_STRING},
224  {"MJD-OBS", "52341.17813019",
225  "Obs start 2002-03-08T04:16:30.448",
226  CPL_TYPE_DOUBLE},
227  {"DATE-OBS", "2002-03-08T04:16:30.448",
228  "Date of observation",
229  CPL_TYPE_STRING},
230  {"EXPTIME", "600.000",
231  "Total integration time. 00:10:00.000",
232  CPL_TYPE_DOUBLE},
233  {"TELESCOP", "VLT",
234  "ESO <TEL>",
235  CPL_TYPE_STRING},
236  {"RA", "181.41734",
237  "12:05:40.1 RA (J2000) pointing",
238  CPL_TYPE_DOUBLE},
239  {"DEC", "-7.65555",
240  "-07:39:19.9 DEC (J2000) pointing",
241  CPL_TYPE_DOUBLE},
242  {"EQUINOX", "2000.",
243  "Standard FK5 (years)",
244  CPL_TYPE_DOUBLE},
245  {"RADECSYS", "FK5",
246  "Coordinate reference frame",
247  CPL_TYPE_STRING},
248  {"LST", "38309.370",
249  "10:38:29.370 LST at start",
250  CPL_TYPE_DOUBLE},
251  {"UTC", "15438.000",
252  "04:17:18.000 UT at start",
253  CPL_TYPE_DOUBLE},
254  {"OBSERVER", "UNKNOWN",
255  "Name of observer",
256  CPL_TYPE_STRING},
257  {"INSTRUME", "UNKNOWN",
258  "Instrument used",
259  CPL_TYPE_STRING},
260  {"PI-COI", "'555555555'",
261  "Name of PI and COI",
262  CPL_TYPE_STRING},
263  {"OBJECT", "None",
264  "Original target",
265  CPL_TYPE_STRING},
266  {"PCOUNT", "0",
267  "Number of parameters per group",
268  CPL_TYPE_INT},
269  {"GCOUNT", "1",
270  "Number of groups",
271  CPL_TYPE_INT},
272  {"CRVAL1", "181.41734",
273  "12:05:40.1, RA at ref pixel",
274  CPL_TYPE_DOUBLE},
275  {"CRPIX1", "2341.8585366",
276  "Reference pixel in X",
277  CPL_TYPE_DOUBLE},
278  {"CDELT1", "0.20500000",
279  "SS arcsec per pixel in RA",
280  CPL_TYPE_DOUBLE},
281  {"CTYPE1", "RA---TAN",
282  "pixel coordinate system",
283  CPL_TYPE_STRING},
284  {"CRVAL2", "-7.65555",
285  "-07:39:19.9, DEC at ref pixel",
286  CPL_TYPE_DOUBLE},
287  {"CRPIX2", "2487.8585366",
288  "Reference pixel in Y",
289  CPL_TYPE_DOUBLE},
290  {"CDELT2", "0.20500000",
291  "SS arcsec per pixel in DEC",
292  CPL_TYPE_DOUBLE},
293  {"CTYPE2", "DEC--TAN",
294  "pixel coordinate system",
295  CPL_TYPE_STRING},
296  {"BSCALE", "1.0",
297  "pixel=FITS*BSCALE+BZERO",
298  CPL_TYPE_DOUBLE},
299  {"BZERO", "32768.0",
300  "pixel=FITS*BSCALE+BZERO",
301  CPL_TYPE_DOUBLE},
302  {"CD1_1", "0.000057",
303  "Translation matrix element",
304  CPL_TYPE_DOUBLE},
305  {"CD1_2", "0.000000",
306  "Translation matrix element",
307  CPL_TYPE_DOUBLE},
308  {"CD2_1", "0.000000",
309  "Translation matrix element",
310  CPL_TYPE_DOUBLE},
311  {"CD2_2", "0.000057",
312  "Translation matrix element",
313  CPL_TYPE_DOUBLE},
314  {"HIERARCH ESO OBS DID", "ESO-VLT-DIC.OBS-1.7",
315  "OBS Dictionary",
316  CPL_TYPE_STRING},
317  {"HIERARCH ESO OBS OBSERVER", "UNKNOWN",
318  "Observer Name",
319  CPL_TYPE_STRING},
320  {"HIERARCH ESO OBS PI-COI NAME", "UNKNOWN",
321  "PI-COI name",
322  CPL_TYPE_STRING},
323  {"HIERARCH ESO INS GRAT NAME", "HR",
324  "Grating name",
325  CPL_TYPE_STRING},
326  {"HIERARCH ESO PRO CATG", "X",
327  "Product category",
328  CPL_TYPE_STRING},
329  {"HIERARCH ESO TPL NEXP", "5",
330  "Number of exposures",
331  CPL_TYPE_INT},
332  {"HISTORY", "1st history record", NULL, CPL_TYPE_STRING},
333  {"COMMENT", "1st comment record", NULL, CPL_TYPE_STRING},
334  {"HISTORY", "2st history record", NULL, CPL_TYPE_STRING},
335  {"COMMENT", "2st comment record", NULL, CPL_TYPE_STRING},
336  {"COMMENT", "3st comment record", NULL, CPL_TYPE_STRING},
337  {"HISTORY", "3st history record", NULL, CPL_TYPE_STRING},
338  {"END", NULL, NULL, CPL_TYPE_STRING}
339  };
340  cpl_image* ima;
341 
342  FILE *file;
343  /*
344  const cxchar *longname = "0123456789012345678901234567890123456789"
345  "0123456789012345678901234567890123456789";
346 
347  */
348  /*
349  * Test 1: Create a property list and check its validity.
350  */
351  plist = cpl_propertylist_new();
352 
353  cx_assert(plist != NULL);
354  cx_assert(cpl_propertylist_is_empty(plist));
355  cx_assert(cpl_propertylist_get_size(plist) == 0);
356  check_nomsg( cpl_error_get_code() );
357 
358  /*
359  * Test 2: Append properties to the list created in the previous test
360  * and verify the data.
361  */
362  cpl_propertylist_append_char(plist, keys[0], 'a');
363  cpl_propertylist_set_comment(plist, keys[0], comments[0]);
364 
365  cpl_propertylist_append_bool(plist, keys[1], 1);
366  cpl_propertylist_set_comment(plist, keys[1], comments[1]);
367 
368  cpl_propertylist_append_int(plist, keys[2], -1);
369  cpl_propertylist_set_comment(plist, keys[2], comments[2]);
370 
371  cpl_propertylist_append_long(plist, keys[3], 32768);
372  cpl_propertylist_set_comment(plist, keys[3], comments[3]);
373 
374  cpl_propertylist_append_float(plist, keys[4], fval[0]);
375  cpl_propertylist_set_comment(plist, keys[4], comments[4]);
376 
377  cpl_propertylist_append_double(plist, keys[5], dval[0]);
378  cpl_propertylist_set_comment(plist, keys[5], comments[5]);
379 
380  cpl_propertylist_append_string(plist, keys[6], comments[6]);
381  cpl_propertylist_set_comment(plist, keys[6], comments[6]);
382 
383  cx_assert(!cpl_propertylist_is_empty(plist));
384  cx_assert(cpl_propertylist_get_size(plist) == 7);
385 
386 
387  for (i = 0; i < cpl_propertylist_get_size(plist); i++) {
388  cpl_property *prop = cpl_propertylist_get(plist, i);
389 
390  cx_assert(!strcmp(cpl_property_get_name(prop), keys[i]));
391  cx_assert(!strcmp(cpl_property_get_comment(prop), comments[i]));
392  cx_assert(cpl_property_get_type(prop) == types[i]);
393 
394  cx_assert(my_uves_propertylist_contains(plist, keys[i]));
395  cx_assert(!strcmp(cpl_propertylist_get_comment(plist, keys[i]),
396  comments[i]));
397  cx_assert(cpl_propertylist_get_type(plist, keys[i]) == types[i]);
398  }
399 
400  cx_assert(cpl_propertylist_get_char(plist, keys[0]) == 'a');
401  cx_assert(cpl_propertylist_get_bool(plist, keys[1]) == 1);
402  cx_assert(cpl_propertylist_get_int(plist, keys[2]) == -1);
403  cx_assert(cpl_propertylist_get_long(plist, keys[3]) == 32768);
404 
405  fval[1] = cpl_propertylist_get_float(plist, keys[4]);
406  cx_assert(!memcmp(&fval[0], &fval[1], sizeof(float)));
407 
408  dval[1] = cpl_propertylist_get_double(plist, keys[5]);
409  cx_assert(!memcmp(&dval[0], &dval[1], sizeof(double)));
410 
411  cx_assert(!strcmp(cpl_propertylist_get_string(plist, keys[6]),
412  comments[6]));
413  check_nomsg( cpl_error_get_code() );
414 
415  /*
416  * Test 3: Modify the values of the property list entries
417  * and verify the data.
418  */
419 
420  cx_assert(cpl_propertylist_set_char(plist, keys[0], 'b') == 0);
421  cx_assert(cpl_propertylist_get_char(plist, keys[0]) == 'b');
422 
423  cx_assert(cpl_propertylist_set_bool(plist, keys[1], 0) == 0);
424  cx_assert(cpl_propertylist_get_bool(plist, keys[1]) == 0);
425 
426  cx_assert(cpl_propertylist_set_int(plist, keys[2], -1) == 0);
427  cx_assert(cpl_propertylist_get_int(plist, keys[2]) == -1);
428 
429  cx_assert(cpl_propertylist_set_long(plist, keys[3], 1) == 0);
430  cx_assert(cpl_propertylist_get_long(plist, keys[3]) == 1);
431 
432  fval[0] = 9.87654321;
433  cx_assert(cpl_propertylist_set_float(plist, keys[4], fval[0]) == 0);
434  fval[1] = cpl_propertylist_get_float(plist, keys[4]);
435  cx_assert(!memcmp(&fval[0], &fval[1], sizeof(float)));
436 
437  dval[0] = -9.87654321;
438  cx_assert(cpl_propertylist_set_double(plist, keys[5], dval[0]) == 0);
439  dval[1] = cpl_propertylist_get_double(plist, keys[5]);
440  cx_assert(!memcmp(&dval[0], &dval[1], sizeof(double)));
441 
442  cx_assert(cpl_propertylist_set_string(plist, keys[6], comments[0]) == 0);
443  cx_assert(!strcmp(cpl_propertylist_get_string(plist, keys[6]),
444  comments[0]));
445  check_nomsg( cpl_error_get_code() );
446 
447 
448  /*
449  * Test 4: Check that trying to modify an entry with a different
450  * type is properly failing.
451  */
452 
453  check_nomsg( cpl_error_get_code() );
454  if (0) test_plist_dump(plist);
455  check_nomsg( cpl_error_get_code() );
456 
457  if(cpl_propertylist_set_char(plist, keys[1], 'a') ==
458  CPL_ERROR_TYPE_MISMATCH) { cpl_error_reset(); }
459 
460  check_nomsg( cpl_error_get_code() );
461  if (0) test_plist_dump(plist);
462 
463 
464  check_nomsg( cpl_error_get_code() );
465  if(cpl_propertylist_set_bool(plist, keys[2], 1) ==
466  CPL_ERROR_TYPE_MISMATCH) { cpl_error_reset(); }
467 
468  check_nomsg( cpl_error_get_code() );
469  if(cpl_propertylist_set_int(plist, keys[3], 1) ==
470  CPL_ERROR_TYPE_MISMATCH){ cpl_error_reset(); }
471 
472  check_nomsg( cpl_error_get_code() );
473  if(cpl_propertylist_set_long(plist, keys[4], 1) ==
474  CPL_ERROR_TYPE_MISMATCH){ cpl_error_reset(); }
475  check_nomsg( cpl_error_get_code() );
476  if(cpl_propertylist_set_float(plist, keys[5], 1.) ==
477  CPL_ERROR_TYPE_MISMATCH){ cpl_error_reset(); }
478  check_nomsg( cpl_error_get_code() );
479  if(cpl_propertylist_set_double(plist, keys[6], 1.) ==
480  CPL_ERROR_TYPE_MISMATCH){ cpl_error_reset(); }
481 
482  check_nomsg( cpl_error_get_code() );
483  if(cpl_propertylist_set_string(plist, keys[0], comments[0]) ==
484  CPL_ERROR_TYPE_MISMATCH){ cpl_error_reset(); }
485  check_nomsg( cpl_error_get_code() );
486 
487 
488 
489  /*
490  * Test 5: Verify that values are inserted correctly into the property
491  * list.
492  */
493 
494 
495  cx_assert(cpl_propertylist_insert_char(plist, keys[0],
496  keys[7], 'a') == 0);
497  cx_assert(cpl_propertylist_insert_after_char(plist, keys[0],
498  keys[7], 'c') == 0);
499 
500  cx_assert(cpl_propertylist_insert_bool(plist, keys[1],
501  keys[8], 0) == 0);
502  cx_assert(cpl_propertylist_insert_after_bool(plist, keys[1],
503  keys[8], 1) == 0);
504 
505  cx_assert(cpl_propertylist_insert_int(plist, keys[2],
506  keys[9], 0) == 0);
507  cx_assert(cpl_propertylist_insert_after_int(plist, keys[2],
508  keys[9], 1) == 0);
509 
510  cx_assert(cpl_propertylist_insert_long(plist, keys[3], keys[10],
511  123456789) == 0);
512  cx_assert(cpl_propertylist_insert_after_long(plist, keys[3], keys[10],
513  123456789) == 0);
514 
515  cx_assert(cpl_propertylist_insert_float(plist, keys[4], keys[11],
516  fval[0]) == 0);
517  cx_assert(cpl_propertylist_insert_after_float(plist, keys[4], keys[11],
518  -fval[0]) == 0);
519 
520  cx_assert(cpl_propertylist_insert_double(plist, keys[5], keys[12],
521  dval[0]) == 0);
522  cx_assert(cpl_propertylist_insert_after_double(plist, keys[5], keys[12],
523  -dval[0]) == 0);
524 
525  cx_assert(cpl_propertylist_insert_string(plist, keys[6],
526  keys[13], "") == 0);
527  cx_assert(cpl_propertylist_insert_after_string(plist, keys[6],
528  keys[13], "") == 0);
529  for (i = 0; i < 7; i++) {
530  cpl_property *p0 = cpl_propertylist_get(plist, 3 * i);
531  cpl_property *p1 = cpl_propertylist_get(plist, 3 * i + 1);
532  cpl_property *p2 = cpl_propertylist_get(plist, 3 * i + 2);
533 
534  cx_assert(!strcmp(cpl_property_get_name(p0), keys[i + 7]));
535  cx_assert(!strcmp(cpl_property_get_name(p1), keys[i]));
536  cx_assert(!strcmp(cpl_property_get_name(p2), keys[i + 7]));
537 
538  switch (cpl_property_get_type(p0)) {
539  case CPL_TYPE_CHAR:
540  cx_assert(cpl_property_get_char(p0) == 'a');
541  cx_assert(cpl_property_get_char(p2) == 'c');
542  break;
543 
544  case CPL_TYPE_BOOL:
545  cx_assert(cpl_property_get_bool(p0) == 0);
546  cx_assert(cpl_property_get_bool(p2) == 1);
547  break;
548 
549  case CPL_TYPE_INT:
550  cx_assert(cpl_property_get_int(p0) == 0);
551  cx_assert(cpl_property_get_int(p2) == 1);
552  break;
553 
554  case CPL_TYPE_LONG:
555  cx_assert(cpl_property_get_long(p0) == 123456789);
556  cx_assert(cpl_property_get_long(p2) == 123456789);
557  break;
558 
559  case CPL_TYPE_FLOAT:
560  fval[1] = cpl_property_get_float(p0);
561  cx_assert(!memcmp(&fval[0], &fval[1], sizeof(float)));
562 
563  fval[1] = -cpl_property_get_float(p2);
564  cx_assert(!memcmp(&fval[0], &fval[1], sizeof(float)));
565  break;
566 
567  case CPL_TYPE_DOUBLE:
568  dval[1] = cpl_property_get_double(p0);
569  cx_assert(!memcmp(&dval[0], &dval[1], sizeof(double)));
570 
571  dval[1] = -cpl_property_get_double(p2);
572  cx_assert(!memcmp(&dval[0], &dval[1], sizeof(double)));
573  break;
574 
575  case CPL_TYPE_STRING:
576  cx_assert(!strcmp(cpl_property_get_string(p0), ""));
577  cx_assert(!strcmp(cpl_property_get_string(p2), ""));
578  break;
579 
580  default:
581  /* This point should never be reached */
582  cx_log("cpl_propertylist-test", CX_LOG_LEVEL_ERROR, "file %s: "
583  "line %d: Invalid value type encountered", __FILE__,
584  __LINE__);
585  break;
586  }
587  }
588 
589  check_nomsg( cpl_error_get_code() );
590 
591 
592  /*
593  * Test 6: Verify that modification of or insertion at/after a non
594  * existing elements is reported correctly.
595  */
596 
597  cx_assert(my_uves_propertylist_contains(plist, "Non-existing key") == 0);
598  check_nomsg( cpl_error_get_code() );
599 
600  if(cpl_propertylist_set_char(plist, "Non-existing key", 'a') ==
601  CPL_ERROR_DATA_NOT_FOUND){ cpl_error_reset(); }
602 
603  check_nomsg( cpl_error_get_code() );
604  if(cpl_propertylist_set_bool(plist, "Non-existing key", 1) ==
605  CPL_ERROR_DATA_NOT_FOUND) { cpl_error_reset(); }
606  check_nomsg( cpl_error_get_code() );
607  if(cpl_propertylist_set_int(plist, "Non-existing key", 1) ==
608  CPL_ERROR_DATA_NOT_FOUND){ cpl_error_reset(); }
609  check_nomsg( cpl_error_get_code() );
610  if(cpl_propertylist_set_long(plist, "Non-existing key", 1) ==
611  CPL_ERROR_DATA_NOT_FOUND){ cpl_error_reset(); }
612  check_nomsg( cpl_error_get_code() );
613  if(cpl_propertylist_set_float(plist, "Non-existing key", 1) ==
614  CPL_ERROR_DATA_NOT_FOUND){ cpl_error_reset(); }
615  check_nomsg( cpl_error_get_code() );
616  if(cpl_propertylist_set_double(plist, "Non-existing key", 1) ==
617  CPL_ERROR_DATA_NOT_FOUND){ cpl_error_reset(); }
618  check_nomsg( cpl_error_get_code() );
619  if(cpl_propertylist_set_string(plist, "Non-existing key", "") ==
620  CPL_ERROR_DATA_NOT_FOUND){ cpl_error_reset(); }
621 
622  if(cpl_propertylist_insert_char(plist, "Non-existing key",
623  "h", 'a') == 1){ cpl_error_reset(); }
624 
625  if(cpl_propertylist_insert_bool(plist, "Non-existing key",
626  "h", 1) == 1){ cpl_error_reset(); }
627 
628  if(cpl_propertylist_insert_int(plist, "Non-existing key",
629  "h", 1) == 1) { cpl_error_reset(); }
630 
631  if(cpl_propertylist_insert_long(plist, "Non-existing key",
632  "h", 1) == 1) { cpl_error_reset(); }
633  if(cpl_propertylist_insert_float(plist, "Non-existing key",
634  "h", 1) == 1){ cpl_error_reset(); }
635 
636  if(cpl_propertylist_insert_double(plist, "Non-existing key",
637  "h", 1) == 1){ cpl_error_reset(); }
638  if(cpl_propertylist_insert_string(plist, "Non-existing key",
639  "h", "") == 1){ cpl_error_reset(); }
640  check_nomsg( cpl_error_get_code() );
641 
642  if(cpl_propertylist_insert_after_char(plist, "Non-existing key",
643  "h", 'a') == 1){ cpl_error_reset(); }
644  if(cpl_propertylist_insert_after_bool(plist, "Non-existing key",
645  "h", 1) == 1){ cpl_error_reset(); }
646  if(cpl_propertylist_insert_after_int(plist, "Non-existing key",
647  "h", 1) == 1){ cpl_error_reset(); }
648  if(cpl_propertylist_insert_after_long(plist, "Non-existing key",
649  "h", 1) == 1){ cpl_error_reset(); }
650  if(cpl_propertylist_insert_after_float(plist, "Non-existing key",
651  "h", 1) == 1){ cpl_error_reset(); }
652  if(cpl_propertylist_insert_after_double(plist, "Non-existing key",
653  "h", 1) == 1){ cpl_error_reset(); }
654  if(cpl_propertylist_insert_after_string(plist, "Non-existing key",
655  "h", "") == 1){ cpl_error_reset(); }
656 
657 
658 
659  /*
660  * Test 7: Create a copy of the property list and verify that original
661  * and copy are identical but do not share any resources.
662  */
663 
664  cpl_propertylist_delete(_plist);
665 
666  _plist = cpl_propertylist_duplicate(plist);
667 
668 
669  cx_assert(_plist != NULL);
670  cx_assert(_plist != plist);
671 
672 
673  for (i = 0; i < cpl_propertylist_get_size(plist); i++) {
674  cpl_property *prop = cpl_propertylist_get(plist, i);
675  cpl_property *_prop = cpl_propertylist_get(_plist, i);
676 
677 
678  cx_assert(cpl_property_get_name(prop) != cpl_property_get_name(_prop));
679  cx_assert(!strcmp(cpl_property_get_name(prop),
680  cpl_property_get_name(_prop)));
681  cx_assert(cpl_property_get_comment(prop) == NULL ||
682  (cpl_property_get_comment(prop) !=
683  cpl_property_get_comment(_prop)));
684  cx_assert(cpl_property_get_comment(prop) == NULL ||
685  !strcmp(cpl_property_get_comment(prop),
686  cpl_property_get_comment(_prop)));
687 
688  switch (cpl_property_get_type(prop)) {
689  case CPL_TYPE_CHAR:
690  cx_assert(cpl_property_get_char(prop) ==
691  cpl_property_get_char(_prop));
692  break;
693 
694  case CPL_TYPE_BOOL:
695  cx_assert(cpl_property_get_bool(prop) ==
696  cpl_property_get_bool(_prop));
697  break;
698 
699  case CPL_TYPE_INT:
700  cx_assert(cpl_property_get_int(prop) ==
701  cpl_property_get_int(_prop));
702  break;
703 
704  case CPL_TYPE_LONG:
705  cx_assert(cpl_property_get_long(prop) ==
706  cpl_property_get_long(_prop));
707  break;
708 
709  case CPL_TYPE_FLOAT:
710  fval[0] = cpl_property_get_float(prop);
711  fval[1] = cpl_property_get_float(_prop);
712  cx_assert(!memcmp(&fval[0], &fval[1], sizeof(float)));
713  break;
714 
715  case CPL_TYPE_DOUBLE:
716  dval[0] = cpl_property_get_double(prop);
717  dval[1] = cpl_property_get_double(_prop);
718  cx_assert(!memcmp(&dval[0], &dval[1], sizeof(double)));
719  break;
720 
721  case CPL_TYPE_STRING:
722  cx_assert(!strcmp(cpl_property_get_string(prop),
723  cpl_property_get_string(_prop)));
724  break;
725 
726  default:
727  /* This point should never be reached */
728  cx_log("cpl_propertylist-test", CX_LOG_LEVEL_ERROR, "file %s: "
729  "line %d: Invalid value type encountered", __FILE__,
730  __LINE__);
731  break;
732  }
733 
734 
735  }
736 
737  cpl_propertylist_delete(_plist);
738  check_nomsg( cpl_error_get_code() );
739 
740 
741  /*
742  * Test 8: Erase elements from the property list and verify the list
743  * structure and the data.
744  */
745 
746  for (i = 0; i < 7; i++) {
747  cpl_propertylist_erase(plist, keys[i + 7]);
748  cx_assert(my_uves_propertylist_contains(plist, keys[i + 7]) == 1);
749 
750  cpl_propertylist_erase(plist, keys[i + 7]);
751  cx_assert(my_uves_propertylist_contains(plist, keys[i + 7]) == 0);
752  }
753  cx_assert(cpl_propertylist_get_size(plist) == 7);
754 
755  for (i = 0; i < 7; i++) {
756  cpl_property *prop = cpl_propertylist_get(plist, i);
757  cx_assert(!strcmp(cpl_property_get_name(prop), keys[i]));
758  }
759 
760  if (0) test_plist_dump(plist);
761 
762  cx_assert(cpl_propertylist_get_char(plist, keys[0]) == 'b');
763  cx_assert(cpl_propertylist_get_bool(plist, keys[1]) == 0);
764  cx_assert(cpl_propertylist_get_int(plist, keys[2]) == -1);
765  cx_assert(cpl_propertylist_get_long(plist, keys[3]) == 1);
766 
767  fval[0] = 9.87654321;
768  fval[1] = cpl_propertylist_get_float(plist, keys[4]);
769  cx_assert(!memcmp(&fval[0], &fval[1], sizeof(float)));
770 
771  dval[0] = -9.87654321;
772  dval[1] = cpl_propertylist_get_double(plist, keys[5]);
773  cx_assert(!memcmp(&dval[0], &dval[1], sizeof(double)));
774 
775  cx_assert(!strcmp(cpl_propertylist_get_string(plist, keys[6]),
776  comments[0]));
777 
778  check_nomsg( cpl_error_get_code() );
779 
780 
781  /*
782  * Test 9: Erase all elements from the property list and verify that
783  * the list is empty.
784  */
785 
786 
787  cpl_propertylist_empty(plist);
788 
789  cx_assert(cpl_propertylist_is_empty(plist));
790  cx_assert(cpl_propertylist_get_size(plist) == 0);
791 
792  cpl_propertylist_delete(plist);
793 
794  check_nomsg( cpl_error_get_code() );
795 
796 
797  /*
798  * Test 10: Create a property list from an input (FITS) file. Verify the
799  * loaded data.
800  */
801 
802  /* Create a sample FITS header and save it to a file */
803 
804 
805  header = cpl_propertylist_new();
806 
807  check_nomsg( cpl_error_get_code() );
808  for (i = 0; (cxsize)i < sizeof hdr / sizeof(struct fcard); i++) {
809  cpl_msg_info(cpl_func,"iter=%d",(int)i);
810  cpl_msg_info(cpl_func,"key=%s",hdr[i].key);
811  cpl_msg_info(cpl_func,"com=%s",hdr[i].com);
812  cpl_msg_info(cpl_func,"typ=%d",hdr[i].type);
813 
814 
815  switch (hdr[i].type) {
816  case CPL_TYPE_CHAR:
817  cpl_propertylist_append_char(header,hdr[i].key,atoi(hdr[i].val));
818  p=cpl_propertylist_get_property(header,hdr[i].key);
819  cpl_propertylist_set_comment(header,hdr[i].key,hdr[i].com);
820  cpl_msg_info(cpl_func,"val=%d",atoi(hdr[i].val));
821 
822  break;
823 
824  case CPL_TYPE_BOOL:
825  cpl_propertylist_append_bool(header,hdr[i].key,atoi(hdr[i].val));
826  p=cpl_propertylist_get_property(header,hdr[i].key);
827  cpl_propertylist_set_comment(header,hdr[i].key,hdr[i].com);
828  cpl_msg_info(cpl_func,"val=%d",atoi(hdr[i].val));
829 
830  break;
831 
832  case CPL_TYPE_INT:
833  cpl_propertylist_append_int(header,hdr[i].key,atoi(hdr[i].val));
834  p=cpl_propertylist_get_property(header,hdr[i].key);
835  cpl_propertylist_set_comment(header,hdr[i].key,hdr[i].com);
836  cpl_msg_info(cpl_func,"val=%d",atoi(hdr[i].val));
837 
838  break;
839 
840  case CPL_TYPE_LONG:
841  cpl_propertylist_append_long(header,hdr[i].key,atol(hdr[i].val));
842  p=cpl_propertylist_get_property(header,hdr[i].key);
843  cpl_propertylist_set_comment(header,hdr[i].key,hdr[i].com);
844  cpl_msg_info(cpl_func,"val=%ld",atol(hdr[i].val));
845 
846  break;
847 
848  case CPL_TYPE_FLOAT:
849  cpl_propertylist_append_long(header,hdr[i].key,atof(hdr[i].val));
850  p=cpl_propertylist_get_property(header,hdr[i].key);
851  cpl_propertylist_set_comment(header,hdr[i].key,hdr[i].com);
852  cpl_msg_info(cpl_func,"val=%f",atof(hdr[i].val));
853 
854  break;
855 
856  case CPL_TYPE_DOUBLE:
857  cpl_propertylist_append_double(header,hdr[i].key,atof(hdr[i].val));
858  p=cpl_propertylist_get_property(header,hdr[i].key);
859  cpl_propertylist_set_comment(header,hdr[i].key,hdr[i].com);
860  cpl_msg_info(cpl_func,"val=%f",atof(hdr[i].val));
861 
862  break;
863 
864  case CPL_TYPE_STRING:
865  if(strcmp(hdr[i].key,"END") != 0) {
866  cpl_propertylist_append_string(header,hdr[i].key,hdr[i].val);
867  p=cpl_propertylist_get_property(header,hdr[i].key);
868  cpl_propertylist_set_comment(header,hdr[i].key,hdr[i].com);
869  cpl_msg_info(cpl_func,"val=%s",hdr[i].val);
870  }
871 
872  break;
873 
874  default:
875  /* This point should never be reached */
876  cx_log("uves_propertylist-test", CX_LOG_LEVEL_ERROR, "file %s: "
877  "line %d: Invalid value type encountered", __FILE__,
878  __LINE__);
879  break;
880  }
881 
882  }
883  check_nomsg( cpl_error_get_code() );
884 
885 
886  file = fopen("cpltest1.fits", "w");
887  cpl_propertylist_save(header,"cpltest1.fits",CPL_IO_CREATE);
888 
889 
890  ima=cpl_image_new(2148,2340,CPL_TYPE_FLOAT);
891  check_nomsg( cpl_error_get_code() );
892  cpl_image_save(ima,"cpltest1.fits",CPL_BPP_16_SIGNED,header,CPL_IO_DEFAULT);
893 
894  cpl_image_delete(ima);
895  fclose(file);
896  cpl_propertylist_delete(header);
897 
898 
899  /* Load the 1st FITS header into a property list */
900  plist = cpl_propertylist_load("cpltest1.fits", 0);
901 
902 
903 
904  cx_assert(plist != NULL);
905 
906 
907  cx_assert(my_uves_propertylist_contains(plist, "END") == 0);
908 
909 
910  cpl_msg_info(cpl_func,"size plist=%" CPL_SIZE_FORMAT "",cpl_propertylist_get_size(plist));
911  cpl_msg_info(cpl_func,"size hdr=%ld",sizeof hdr);
912  cpl_msg_info(cpl_func,"size fcard=%ld",sizeof(struct fcard));
913 
914  check_nomsg( cpl_error_get_code() );
915  //cx_assert(cpl_propertylist_get_size(plist) ==
916  // (sizeof hdr / sizeof(struct fcard) - 1));
917  /*
918  for (i = 0; i < cpl_propertylist_get_size(plist); i++) {
919  const cxchar *s = hdr[i].key;
920  cpl_property *p = cpl_propertylist_get(plist, i);
921 
922 
923  // Strip HIERARCH from the keyword if it is present. HIERARCH
924  // is not carried over to the property name.
925 
926  cpl_msg_info(cpl_func,"key=%s",hdr[i].key);
927  cpl_msg_info(cpl_func,"com=%s",hdr[i].com);
928  cpl_msg_info(cpl_func,"typ=%ld",hdr[i].type);
929 
930  cpl_msg_info(cpl_func,"p name=%s",cpl_property_get_name(p));
931  cpl_msg_info(cpl_func,"p comm=%s",cpl_property_get_comment(p));
932 
933  if(strcmp(cpl_property_get_name(p),"COMMENT") == 0) {
934  i++;
935  }
936  if (strstr(hdr[i].key, "HIERARCH"))
937  s = hdr[i].key + strlen("HIERARCH") + 1;
938 
939  cx_assert(!strcmp(cpl_property_get_name(p), s));
940  cx_assert(hdr[i].com == NULL ||
941  !strcmp(cpl_property_get_comment(p), hdr[i].com));
942  cx_assert(cpl_property_get_type(p) == hdr[i].type);
943 
944  switch (hdr[i].type) {
945  case CPL_TYPE_BOOL:
946  cx_assert(cpl_property_get_bool(p) ==
947  (*hdr[i].val == 'T' ? 1 : 0));
948  break;
949 
950  case CPL_TYPE_INT:
951  cpl_msg_info(cpl_func,"prop name=%s",cpl_property_get_name(p));
952  cpl_msg_info(cpl_func,"prop value=%d",cpl_property_get_int(p));
953  cpl_msg_info(cpl_func,"check value=%d",atoi(hdr[i].val));
954 
955  cx_assert(cpl_property_get_int(p) == atoi(hdr[i].val));
956  break;
957 
958  case CPL_TYPE_DOUBLE:
959  dval[0] = cpl_property_get_double(p);
960  dval[1] = atof(hdr[i].val);
961  cx_assert(!memcmp(&dval[0], &dval[1], sizeof(double)));
962  break;
963 
964  case CPL_TYPE_STRING:
965  cx_assert(!strcmp(cpl_property_get_string(p),
966  qfits_pretty_string(hdr[i].val)));
967  break;
968 
969  default:
970  cx_log("cpl_propertylist-test", CX_LOG_LEVEL_ERROR, "file %s: "
971  "line %d: Invalid value type encountered", __FILE__,
972  __LINE__);
973  break;
974  }
975  }
976  */
977  check_nomsg( cpl_error_get_code() );
978 
979  /*
980  * Test 11: Convert the qfits FITS header back into a property list and
981  * verify that the original property list and the one created
982  * from the FITS header are identical.
983  */
984 
985  /* AMO: Suppressed unit test as cpl_propertylist_from_fitsfile is a CPL
986  internal function that should not be accessed.
987  Still leave the code.
988 
989  fitsfile* fits_file=NULL;
990  cxint status = 0;
991 
992 
993  fits_open_diskfile(&fits_file,(cxchar*)"cpltest1.fits", READONLY, &status);
994  _plist = cpl_propertylist_from_fitsfile(fits_file) ;
995  cx_assert(_plist != NULL);
996  cx_assert(cpl_propertylist_get_size(plist) ==
997  cpl_propertylist_get_size(_plist));
998 
999 
1000 
1001  for (i = 0; i < cpl_propertylist_get_size(plist); i++) {
1002  cpl_property *p = cpl_propertylist_get(plist, i);
1003  cpl_property *_p = cpl_propertylist_get(_plist, i);
1004 
1005  cx_assert(strcmp(cpl_property_get_name(p),
1006  cpl_property_get_name(_p)) == 0);
1007  cx_assert(strcmp(cpl_property_get_comment(p),
1008  cpl_property_get_comment(_p)) == 0);
1009  cx_assert(cpl_property_get_type(p) == cpl_property_get_type(_p));
1010 
1011  switch (cpl_property_get_type(p)) {
1012  case CPL_TYPE_BOOL:
1013  cx_assert(cpl_property_get_bool(p) == cpl_property_get_bool(_p));
1014  break;
1015 
1016  case CPL_TYPE_INT:
1017  cx_assert(cpl_property_get_int(p) == cpl_property_get_int(_p));
1018  break;
1019 
1020  case CPL_TYPE_DOUBLE:
1021  cx_assert(cpl_property_get_double(p) ==
1022  cpl_property_get_double(_p));
1023  break;
1024 
1025  case CPL_TYPE_STRING:
1026  cx_assert(strcmp(cpl_property_get_string(p),
1027  cpl_property_get_string(_p)) == 0);
1028  break;
1029 
1030  default:
1031  cx_log("cpl_propertylist-test", CX_LOG_LEVEL_ERROR,
1032  "file %s: line %d: Invalid value type encountered",
1033  __FILE__, __LINE__);
1034  break;
1035  }
1036  }
1037 
1038  fits_close_file(fits_file, &status);
1039  cpl_propertylist_delete(_plist);
1040 
1041  check_nomsg( cpl_error_get_code() );
1042 
1043  */
1044 
1045 
1046  /*
1047  * Test 12: Create a qfits header from the property list and verify
1048  * the header data. Note that cpl_propertylist_to_fits establishes
1049  * the DICB sorting order.
1050  */
1051  /*
1052  cx_deque_compare _compare = (cx_deque_compare)compare;
1053  cpl_propertylist_sort(header,_compare);
1054 
1055  fits_open_diskfile(&fits_file,(cxchar*)"cpltest1.fits", READONLY, &status);
1056  cpl_propertylist_save(header,"cpltest1.fits",CPL_IO_CREATE);
1057  fits_close_file(fits_file, &status);
1058 
1059 
1060  _header = cpl_propertylist_to_fits(plist);
1061  cx_assert(_header != NULL);
1062 
1063  file = fopen("cpltest2.fits", "w");
1064  qfits_header_dump(_header, file);
1065  fclose(file);
1066 
1067 
1068  for (i = 0; i < header->n; i++) {
1069  cxchar key[FITS_LINESZ + 1];
1070  cxchar val[FITS_LINESZ + 1];
1071  cxchar com[FITS_LINESZ + 1];
1072 
1073  cxchar _key[FITS_LINESZ + 1];
1074  cxchar _val[FITS_LINESZ + 1];
1075  cxchar _com[FITS_LINESZ + 1];
1076 
1077 
1078  qfits_header_getitem(header, i, key, val, com, NULL);
1079  cx_assert(qfits_header_getitem(_header, i, _key, _val,
1080  _com, NULL) == 0);
1081 
1082  cx_assert(!strcmp(key, _key));
1083  cx_assert(_com == NULL || !strcmp(com, _com));
1084 
1085  switch (qfits_get_type(val)) {
1086  case QFITS_FLOAT:
1087  fval[0] = atof(val);
1088  fval[1] = atof(_val);
1089 
1090  cx_assert(fabs(fval[0] - fval[1]) < FLT_EPS);
1091  break;
1092 
1093  default:
1094  cx_assert(strlen(val) == 0 ||
1095  !strcmp(qfits_pretty_string(val),
1096  qfits_pretty_string(_val)));
1097  break;
1098  }
1099 
1100  }
1101 
1102  qfits_header_destroy(header);
1103  qfits_header_destroy(_header);
1104  */
1105 
1106 
1107 
1108 
1109  /*
1110  * Test 13: Copy all propertys matching a given pattern from one
1111  * property list to another.
1112  */
1113 
1114  _plist = cpl_propertylist_new();
1115 
1116 
1117 
1118  cpl_propertylist_copy_property_regexp(_plist, plist, "^ESO .*", 0);
1119 
1120 
1121 
1122 
1123  cx_assert(cpl_propertylist_get_size(_plist) == 6);
1124  cx_assert(my_uves_propertylist_contains(_plist, "ESO OBS DID") != 0);
1125  cx_assert(my_uves_propertylist_contains(_plist, "ESO OBS OBSERVER") != 0);
1126  cx_assert(my_uves_propertylist_contains(_plist, "ESO OBS PI-COI NAME") != 0);
1127  cx_assert(my_uves_propertylist_contains(_plist, "ESO INS GRAT NAME") != 0);
1128  cx_assert(my_uves_propertylist_contains(_plist, "ESO PRO CATG") != 0);
1129  cx_assert(my_uves_propertylist_contains(_plist, "ESO TPL NEXP") != 0);
1130 
1131 
1132 
1133  cpl_propertylist_empty(_plist);
1134  cx_assert(cpl_propertylist_is_empty(_plist) != 0);
1135 
1136  cpl_propertylist_copy_property_regexp(_plist, plist, "^ESO .*", 1);
1137  cx_assert(cpl_propertylist_get_size(_plist) ==
1138  (cpl_propertylist_get_size(plist) - 6));
1139 
1140  check_nomsg( cpl_error_get_code() );
1141 
1142 
1143 
1144  /*
1145  * Test 14: Erase all properties matching the given pattern from the
1146  * property list.
1147  */
1148 
1149  cpl_propertylist_empty(_plist);
1150  cx_assert(cpl_propertylist_is_empty(_plist) != 0);
1151 
1152  cpl_propertylist_copy_property_regexp(_plist, plist, "^ESO .*", 0);
1153  cx_assert(cpl_propertylist_get_size(_plist) == 6);
1154 
1155  cpl_propertylist_erase_regexp(_plist, "^ESO OBS .*", 0);
1156  cx_assert(cpl_propertylist_get_size(_plist) == 3);
1157 
1158  cpl_propertylist_erase_regexp(_plist, "ESO TPL NEXP", 0);
1159  cx_assert(cpl_propertylist_get_size(_plist) == 2);
1160 
1161  cpl_propertylist_delete(_plist);
1162  cpl_propertylist_delete(plist);
1163  check_nomsg( cpl_error_get_code() );
1164 
1165 
1166 
1167  /*
1168  * Test 15: Create a property list from a file. Only properties matching
1169  * the given pattern are loaded.
1170  */
1171 
1172  plist = NULL;
1173 
1174  plist = cpl_propertylist_load_regexp("cpltest1.fits", 0,
1175  "^ESO .*", 0);
1176  cx_assert(plist != NULL);
1177  cx_assert(cpl_propertylist_is_empty(plist) == 0);
1178  cx_assert(cpl_propertylist_get_size(plist) == 6);
1179  cx_assert(my_uves_propertylist_contains(plist, "ESO OBS DID") != 0);
1180  cx_assert(my_uves_propertylist_contains(plist, "ESO OBS OBSERVER") != 0);
1181  cx_assert(my_uves_propertylist_contains(plist, "ESO OBS PI-COI NAME") != 0);
1182  cx_assert(my_uves_propertylist_contains(plist, "ESO INS GRAT NAME") != 0);
1183  cx_assert(my_uves_propertylist_contains(plist, "ESO PRO CATG") != 0);
1184  cx_assert(my_uves_propertylist_contains(plist, "ESO TPL NEXP") != 0);
1185 
1186  cpl_propertylist_delete(plist);
1187  check_nomsg( cpl_error_get_code() );
1188 
1189 
1190 
1191 
1192  /*
1193  * Test 16: Append a property list to another.
1194  */
1195 
1196  plist = cpl_propertylist_new();
1197  _plist = cpl_propertylist_new();
1198 
1199  cpl_propertylist_append_char(plist, keys[0], 'a');
1200  cpl_propertylist_set_comment(plist, keys[0], comments[0]);
1201 
1202  cpl_propertylist_append_bool(plist, keys[1], 1);
1203  cpl_propertylist_set_comment(plist, keys[1], comments[1]);
1204 
1205  cpl_propertylist_append_int(plist, keys[2], -1);
1206  cpl_propertylist_set_comment(plist, keys[2], comments[2]);
1207 
1208  cpl_propertylist_append_long(plist, keys[3], 32768);
1209  cpl_propertylist_set_comment(plist, keys[3], comments[3]);
1210 
1211  cpl_propertylist_append_float(_plist, keys[4], fval[0]);
1212  cpl_propertylist_set_comment(_plist, keys[4], comments[4]);
1213 
1214  cpl_propertylist_append_double(_plist, keys[5], dval[0]);
1215  cpl_propertylist_set_comment(_plist, keys[5], comments[5]);
1216 
1217  cpl_propertylist_append_string(_plist, keys[6], comments[6]);
1218  cpl_propertylist_set_comment(_plist, keys[6], comments[6]);
1219 
1220  cx_assert(!cpl_propertylist_is_empty(plist));
1221  cx_assert(cpl_propertylist_get_size(plist) == 4);
1222 
1223  cx_assert(!cpl_propertylist_is_empty(_plist));
1224  cx_assert(cpl_propertylist_get_size(_plist) == 3);
1225 
1226  cpl_propertylist_append(plist, _plist);
1227 
1228  cx_assert(!cpl_propertylist_is_empty(plist));
1229  cx_assert(cpl_propertylist_get_size(plist) == 7);
1230 
1231  cx_assert(!cpl_propertylist_is_empty(_plist));
1232  cx_assert(cpl_propertylist_get_size(_plist) == 3);
1233 
1234  for (i = 0; i < cpl_propertylist_get_size(plist); i++) {
1235  cpl_property *prop = cpl_propertylist_get(plist, i);
1236 
1237  cx_assert(!strcmp(cpl_property_get_name(prop), keys[i]));
1238  cx_assert(!strcmp(cpl_property_get_comment(prop), comments[i]));
1239  cx_assert(cpl_property_get_type(prop) == types[i]);
1240 
1241  cx_assert(my_uves_propertylist_contains(plist, keys[i]));
1242  cx_assert(!strcmp(cpl_propertylist_get_comment(plist, keys[i]),
1243  comments[i]));
1244  cx_assert(cpl_propertylist_get_type(plist, keys[i]) == types[i]);
1245  }
1246 
1247  check_nomsg( cpl_error_get_code() );
1248 
1249  cpl_propertylist_delete(_plist);
1250  cpl_propertylist_delete(plist);
1251 
1252 
1253 
1254  /*
1255  * Test 17: Create a FITS header using a list containing a property with
1256  * a name of length 80 characters (the length of a FITS card)
1257  */
1258 
1259  /*
1260  cpl_propertylist_empty(plist);
1261 
1262  cpl_propertylist_append_string(plist, longname, comments[6]);
1263 
1264  qfits_header_destroy(cpl_propertylist_to_fits(plist));
1265 
1266 
1267  cpl_propertylist_delete(_plist);
1268  _plist = NULL;
1269 
1270  cpl_propertylist_delete(plist);
1271  plist = NULL;
1272 
1273  cx_assert( cpl_error_get_code() == CPL_ERROR_UNSPECIFIED );
1274  cpl_error_reset();
1275  */
1276  /*
1277  * All tests succeeded
1278  */
1279  cleanup:
1280 
1281  return 0;
1282 
1283 }
1284 
1285 int main(void)
1286 {
1287 
1288  cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
1289  //cpl_msg_set_level(CPL_MSG_DEBUG);
1290  test_main();
1291 
1292  return cpl_test_end(0);
1293 }
#define check_nomsg(CMD)
Definition: uves_error.h:204
int my_uves_propertylist_contains(const cpl_propertylist *self, const char *name)
Check whether a property is present in a property list.
int main(void)
Various tests of low-level library functions.
Definition: uves-test.c:393