IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 39421


Ignore:
Timestamp:
Mar 1, 2016, 11:38:17 AM (10 years ago)
Author:
eugene
Message:

fix signed / unsigned inconsistencies; free memory in tablecomp.c test; drop tests for non-ansi-C %L-style formats

Location:
branches/eam_branches/ohana.20160226/src/libfits/test
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ohana.20160226/src/libfits/test/imagecomp.c

    r38553 r39421  
    1717static int NY = 10;
    1818
    19 int main (int argc, char **argv) {
     19int main (void) {
    2020 
    2121  plan_tests (3*3*234);
     
    196196  }     
    197197
    198   int Ztile[2] = {NX, NY};
    199   ok (gfits_compress_image (&rawheader, &rawmatrix, &ftable, (int *) &Ztile, zcmptype), "compressed image");
     198  unsigned long int Ztile[2] = {NX, NY};
     199  ok (gfits_compress_image (&rawheader, &rawmatrix, &ftable, (unsigned long int *) &Ztile, zcmptype), "compressed image");
    200200  // ok (gfits_compress_image (&rawheader, &rawmatrix, &ftable, NULL, zcmptype), "compressed image");
    201201  ok (gfits_uncompress_image (&outheader, &outmatrix, &ftable), "uncompressed image");
  • branches/eam_branches/ohana.20160226/src/libfits/test/keywords.c

    r39321 r39421  
    1515  tmp = Pout[3]; Pout[3] = Pout[4]; Pout[4] = tmp; }
    1616
    17 int main (int argc, char **argv) {
     17int main (void) {
    1818 
    1919  plan_tests (14);
     
    2121  diag ("libfits keyword tests");
    2222
    23   int i, err;
    24   double srcbuf[NSRC], tgtbuf[NTGT], outbuf[NOUT];
    25  
    2623  {
    2724   
     
    9693    ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good");
    9794
    98     ok (gfits_modify (&header, "D_LONG3", "%Ld", 1, (long long) 0x100), "wrote a keyword");
    99     ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good");
     95    // this is not ISO C99:
     96    // ok (gfits_modify (&header, "D_LONG3", "%Ld", 1, (long long) 0x100), "wrote a keyword");
     97    // ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good");
    10098
    10199    // set one of each of the few numerical types (unsigned ints)
     
    109107    ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good");
    110108
    111     ok (gfits_modify (&header, "DU_LONG3", "%Lu", 1, (long long) 0x100), "wrote a keyword");
    112     ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good");
     109    // ok (gfits_modify (&header, "DU_LONG3", "%Lu", 1, (long long) 0x100), "wrote a keyword");
     110    // ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good");
    113111
    114112    ok (gfits_modify (&header, "D_SHORT", "%hd", 1, 0x20), "wrote a keyword");
     
    229227    ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good");
    230228
    231     ok (gfits_scan (&header, "D_LONG3", "%Ld", 1, &Kvalue), "read a keyword");
    232     ok (Kvalue == 0x100, "got the right value");
    233     ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good");
     229    // ok (gfits_scan (&header, "D_LONG3", "%Ld", 1, &Kvalue), "read a keyword");
     230    // ok (Kvalue == 0x100, "got the right value");
     231    // ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good");
    234232
    235233    // set one of each of the few numerical types (unsigned ints)
     
    246244    ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good");
    247245
    248     ok (gfits_scan (&header, "DU_LONG3", "%Lu", 1, &Ulonglong), "read a keyword");
    249     ok (Ulonglong == 0x100, "got the right value");
    250     ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good");
     246    // ok (gfits_scan (&header, "DU_LONG3", "%Lu", 1, &Ulonglong), "read a keyword");
     247    // ok (Ulonglong == 0x100, "got the right value");
     248    // ptr = gfits_header_field (&header, "END", 1); ok (ptr, "END still good");
    251249
    252250    ok (gfits_scan (&header, "D_SHORT", "%hd", 1, &Ishort), "read a keyword");
  • branches/eam_branches/ohana.20160226/src/libfits/test/ricetest.c

    r38404 r39421  
    11# include <ohana.h>
    22# include <gfitsio.h>
     3# include <gfits_compress.h>
    34# include "tap_ohana.h"
    45
     
    67# define NBYTE 4*NPIX
    78
    8 int main (int argc, char **argv) {
     9int main (void) {
    910 
    1011  plan_tests (45);
     
    1213  diag ("libfits ricetest.c tests");
    1314
    14   // buffers to store max array
    15   char rawdata[NBYTE];
    16   char cmpdata[NBYTE];
    17   char outdata[NBYTE];
    18 
    1915  // ok (1, "failure");
    2016
    2117  if (1) {
     18    // buffers to store max array
     19    char rawdata[NBYTE];
     20    unsigned char outdata[NBYTE];
     21    unsigned char cmpdata[NBYTE];
    2222    char *rawvalue = (char *) rawdata;
    2323    char *outvalue = (char *) outdata;
     
    4646
    4747  if (1) {
     48    // buffers to store max array
     49    char rawdata[NBYTE];
     50    unsigned short outdata[NBYTE];
     51    unsigned char cmpdata[NBYTE];
     52
    4853    short *rawvalue = (short *) rawdata;
    4954    short *outvalue = (short *) outdata;
     
    7277
    7378  if (1) {
     79    // buffers to store max array
     80    char rawdata[NBYTE];
     81    unsigned int outdata[NBYTE];
     82    unsigned char cmpdata[NBYTE];
     83
    7484    int *rawvalue = (int *) rawdata;
    7585    int *outvalue = (int *) outdata;
  • branches/eam_branches/ohana.20160226/src/libfits/test/tablecomp.c

    r38553 r39421  
    1010char *cmptype[] = {"NONE", "NONE_1", "NONE_2", "GZIP_1", "GZIP_2", "RICE_1", "RICE_ONE", "AUTO", NULL};
    1111
    12 int main (int argc, char **argv) {
    13  
    14   plan_tests (668);
     12int main (void) {
     13 
     14  plan_tests (668+428);
    1515
    1616  diag ("libfits tablecomp.c tests");
     
    2828    test_compress_empty (cmptype[i]);
    2929    ok (ohana_memcheck (TRUE), "no memory corruption");
     30    ohana_memdump (TRUE);
    3031  }
    3132
     
    8990    ok (gfits_compress_table (&ftable, &cmptable, 10, zcmptype), "compressed table");
    9091
     92    if (0) { int ix, iy;
     93      for (ix = 0; ix < 12; ix++) {
     94        for (iy = 0; iy < 16; iy++) {
     95          fprintf (stderr, "%x ", (int) cmptable.buffer[ix*16 + iy]);
     96        }
     97      }
     98    }
     99
     100    Header rawheader;
     101    FTable rawtable;
     102    rawtable.header = &rawheader;
     103    ok (gfits_uncompress_table (&cmptable, &rawtable), "uncompressed table");
     104
     105    gfits_free_header (&cmpheader);
     106    gfits_free_table (&cmptable);
     107
     108    outheader = &rawheader;
     109    outtable  = &rawtable;
     110  }
     111
     112  char type[16];
     113  int Ncol;
     114  off_t Nrow;
     115
     116  char    *VAL_B_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_B", type, &Nrow, &Ncol); ok (!strcmp (type, "byte"),    "read byte    table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
     117  short   *VAL_I_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_I", type, &Nrow, &Ncol); ok (!strcmp (type, "short"),   "read short   table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
     118  int     *VAL_J_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_J", type, &Nrow, &Ncol); ok (!strcmp (type, "int"),     "read int     table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
     119  int64_t *VAL_K_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_K", type, &Nrow, &Ncol); ok (!strcmp (type, "int64_t"), "read int64_t table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
     120  float   *VAL_E_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_E", type, &Nrow, &Ncol); ok (!strcmp (type, "float"),   "read float   table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
     121  double  *VAL_D_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_D", type, &Nrow, &Ncol); ok (!strcmp (type, "double"),  "read double  table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
     122
     123  // count mismatched values
     124  int NVAL_B_bad = 0;
     125  int NVAL_I_bad = 0;
     126  int NVAL_J_bad = 0;
     127  int NVAL_K_bad = 0;
     128  int NVAL_E_bad = 0;
     129  int NVAL_D_bad = 0;
     130
     131  // for (i = 0; i < Nval; i++) {
     132  //   fprintf (stderr, "%0llx : %0llx\n", (long long) VAL_K[i], (long long) VAL_K_t[i]);
     133  // }
     134
     135  for (i = 0; i < Nval; i++) {
     136    if (VAL_B[i] != VAL_B_t[i]) NVAL_B_bad++;
     137    if (VAL_I[i] != VAL_I_t[i]) NVAL_I_bad++;
     138    if (VAL_J[i] != VAL_J_t[i]) NVAL_J_bad++;
     139    if (VAL_K[i] != VAL_K_t[i]) NVAL_K_bad++;
     140    if (VAL_E[i] != VAL_E_t[i]) NVAL_E_bad++;
     141    if (VAL_D[i] != VAL_D_t[i]) NVAL_D_bad++;
     142  }
     143
     144  ok (!NVAL_B_bad, "byte    values match (input vs output)");
     145  ok (!NVAL_I_bad, "short   values match (input vs output)");
     146  ok (!NVAL_J_bad, "int     values match (input vs output)");
     147  ok (!NVAL_K_bad, "int64_t values match (input vs output)");
     148  ok (!NVAL_E_bad, "float   values match (input vs output)");
     149  ok (!NVAL_D_bad, "double  values match (input vs output)");
     150
     151  free (VAL_B);
     152  free (VAL_I);
     153  free (VAL_J);
     154  free (VAL_K);
     155  free (VAL_E);
     156  free (VAL_D);
     157
     158  free (VAL_B_t);
     159  free (VAL_I_t);
     160  free (VAL_J_t);
     161  free (VAL_K_t);
     162  free (VAL_E_t);
     163  free (VAL_D_t);
     164
     165  gfits_free_header (&header);
     166  gfits_free_table (&ftable);
     167  if (zcmptype) {
     168    gfits_free_header (outheader);
     169    gfits_free_table (outtable);
     170  }
     171  return TRUE;
     172}
     173
     174int test_compress_fullrange (char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE"
     175
     176  Header header;
     177  FTable ftable;
     178
     179  diag ("--- starting test_compress with zcmptype %s ---", zcmptype);
     180  ok (gfits_init_header (&header), "inited the header");
     181  ok (gfits_init_table (&ftable), "inited the table");
     182
     183  ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header");
     184
     185  ok (gfits_define_bintable_column (&header, "B", "VAL_B", "byte",   "none", 1.0, 0.0), "defined byte column");
     186  ok (gfits_define_bintable_column (&header, "I", "VAL_I", "short",  "none", 1.0, 0.0), "defined short column");
     187  ok (gfits_define_bintable_column (&header, "J", "VAL_J", "int",    "none", 1.0, 0.0),  "defined int column");
     188  ok (gfits_define_bintable_column (&header, "K", "VAL_K", "long",   "none", 1.0, 0.0),  "defined long column");
     189  ok (gfits_define_bintable_column (&header, "E", "VAL_E", "float",  "degree", 1.0, 0.0),   "defined float column");
     190  ok (gfits_define_bintable_column (&header, "D", "VAL_D", "double", "degree", 1.0, 0.0),   "defined double column");
     191 
     192  // generate the output array that carries the data
     193  ok (gfits_create_table (&header, &ftable), "created the basic table");
     194
     195  int Nval = 1000;
     196  char    *VAL_B;  ALLOCATE (VAL_B, char,    Nval);
     197  short   *VAL_I;  ALLOCATE (VAL_I, short,   Nval);
     198  int     *VAL_J;  ALLOCATE (VAL_J, int,     Nval);
     199  int64_t *VAL_K;  ALLOCATE (VAL_K, int64_t, Nval);
     200  float   *VAL_E;  ALLOCATE (VAL_E, float,   Nval);
     201  double  *VAL_D;  ALLOCATE (VAL_D, double,  Nval);
     202 
     203  long A = time(NULL);
     204  srand48(A);
     205
     206  int i;
     207  for (i = 0; i < Nval; i++) {
     208    VAL_B[i] =       0xff & lrand48();
     209    VAL_I[i] =     0xffff & lrand48();
     210    VAL_J[i] = 0xffffffff & lrand48();
     211    VAL_K[i] = (((int64_t)lrand48()) << 32) + (int64_t)lrand48();
     212    VAL_E[i] = FLT_MAX * (2.0*drand48() - 1.0);
     213    VAL_D[i] = DBL_MAX * (2.0*drand48() - 1.0);
     214  }     
     215
     216  // add the columns to the output array
     217  ok (gfits_set_bintable_column (&header, &ftable, "VAL_B", VAL_B, Nval), "set byte   table column");
     218  ok (gfits_set_bintable_column (&header, &ftable, "VAL_I", VAL_I, Nval), "set short  table column");
     219  ok (gfits_set_bintable_column (&header, &ftable, "VAL_J", VAL_J, Nval), "set int    table column");
     220  ok (gfits_set_bintable_column (&header, &ftable, "VAL_K", VAL_K, Nval), "set long   table column");
     221  ok (gfits_set_bintable_column (&header, &ftable, "VAL_E", VAL_E, Nval), "set float  table column");
     222  ok (gfits_set_bintable_column (&header, &ftable, "VAL_D", VAL_D, Nval), "set double table column");
     223
     224  Header *outheader = &header;
     225  FTable *outtable = &ftable;
     226
     227  if (zcmptype) {
     228    Header cmpheader;
     229    FTable cmptable;
     230    cmptable.header = &cmpheader;
     231    ok (gfits_compress_table (&ftable, &cmptable, 10, zcmptype), "compressed table");
     232
    91233    Header rawheader;
    92234    FTable rawtable;
     
    120262  int NVAL_D_bad = 0;
    121263
    122   // for (i = 0; i < Nval; i++) {
    123   //   fprintf (stderr, "%0llx : %0llx\n", (long long) VAL_K[i], (long long) VAL_K_t[i]);
    124   // }
    125 
    126264  for (i = 0; i < Nval; i++) {
    127265    if (VAL_B[i] != VAL_B_t[i]) NVAL_B_bad++;
     
    140278  ok (!NVAL_D_bad, "double  values match (input vs output)");
    141279
     280  free (VAL_B);
     281  free (VAL_I);
     282  free (VAL_J);
     283  free (VAL_K);
     284  free (VAL_E);
     285  free (VAL_D);
     286
     287  free (VAL_B_t);
     288  free (VAL_I_t);
     289  free (VAL_J_t);
     290  free (VAL_K_t);
     291  free (VAL_E_t);
     292  free (VAL_D_t);
     293
    142294  gfits_free_header (&header);
    143295  gfits_free_table (&ftable);
     
    149301}
    150302
    151 int test_compress_fullrange (char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE"
     303int test_compress_single_full (char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE"
     304
     305  Header header;
     306  FTable ftable;
     307
     308  diag ("--- starting test_compress with zcmptype %s ---", zcmptype);
     309  ok (gfits_init_header (&header), "inited the header");
     310  ok (gfits_init_table (&ftable), "inited the table");
     311
     312  ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header");
     313
     314  ok (gfits_define_bintable_column (&header, "I", "SEQ", "seq", "none", 1.0, 0.0), "defined short column");
     315 
     316  // generate the output array that carries the data
     317  ok (gfits_create_table (&header, &ftable), "created the basic table");
     318
     319  int Nval = 1000;
     320  short *SEQ;  ALLOCATE (SEQ, short,  Nval);
     321 
     322  int i;
     323  for (i = 0; i < Nval; i++) {
     324    SEQ[i] = i;
     325  }     
     326
     327  // add the columns to the output array
     328  ok (gfits_set_bintable_column (&header, &ftable, "SEQ", SEQ, Nval), "set short  table column");
     329
     330  Header *outheader = &header;
     331  FTable *outtable = &ftable;
     332
     333  if (zcmptype) {
     334    Header cmpheader;
     335    FTable cmptable;
     336    cmptable.header = &cmpheader;
     337    ok (gfits_compress_table (&ftable, &cmptable, 0, zcmptype), "compressed table");
     338
     339    Header rawheader;
     340    FTable rawtable;
     341    rawtable.header = &rawheader;
     342    ok (gfits_uncompress_table (&cmptable, &rawtable), "uncompressed table");
     343   
     344    gfits_free_header (&cmpheader);
     345    gfits_free_table (&cmptable);
     346
     347    outheader = &rawheader;
     348    outtable  = &rawtable;
     349  }
     350
     351  char type[16];
     352  int Ncol;
     353  off_t Nrow;
     354
     355  short  *SEQ_t = gfits_get_bintable_column_data (outheader, outtable, "SEQ", type, &Nrow, &Ncol); ok (!strcmp (type, "short"),  "read short  table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
     356
     357  // count mismatched values
     358  int Nseq = 0;
     359  for (i = 0; i < Nval; i++) {
     360    if (SEQ[i] != SEQ_t[i]) Nseq++;
     361  }
     362
     363  ok (!Nseq,   "short  values match (input vs output)");
     364
     365  gfits_free_header (&header);
     366  gfits_free_table (&ftable);
     367  if (zcmptype) {
     368    gfits_free_header (outheader);
     369    gfits_free_table (outtable);
     370  }
     371  return TRUE;
     372}
     373
     374int test_compress_empty (char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE"
    152375
    153376  Header header;
     
    170393  ok (gfits_create_table (&header, &ftable), "created the basic table");
    171394
    172   int Nval = 1000;
     395  int Nval = 0;
    173396  char    *VAL_B;  ALLOCATE (VAL_B, char,    Nval);
    174397  short   *VAL_I;  ALLOCATE (VAL_I, short,   Nval);
     
    178401  double  *VAL_D;  ALLOCATE (VAL_D, double,  Nval);
    179402 
    180   long A = time(NULL);
    181   srand48(A);
    182 
    183403  int i;
    184404  for (i = 0; i < Nval; i++) {
    185     VAL_B[i] =       0xff & lrand48();
    186     VAL_I[i] =     0xffff & lrand48();
    187     VAL_J[i] = 0xffffffff & lrand48();
    188     VAL_K[i] = (((int64_t)lrand48()) << 32) + (int64_t)lrand48();
    189     VAL_E[i] = FLT_MAX * (2.0*drand48() - 1.0);
    190     VAL_D[i] = DBL_MAX * (2.0*drand48() - 1.0);
     405    VAL_B[i] = (i % 255) - 128;
     406    VAL_I[i] = i;
     407    VAL_J[i] = 10000*i + 100*i;
     408    VAL_K[i] = 10000*i + 330*i;
     409    VAL_E[i] = 0.1*i;
     410    VAL_D[i] = 1.001*i;
    191411  }     
    192412
     
    206426    FTable cmptable;
    207427    cmptable.header = &cmpheader;
    208     ok (gfits_compress_table (&ftable, &cmptable, 10, zcmptype), "compressed table");
     428    ok (gfits_compress_table (&ftable, &cmptable, 0, zcmptype), "compressed table");
    209429
    210430    Header rawheader;
     
    239459  int NVAL_D_bad = 0;
    240460
     461  // for (i = 0; i < Nval; i++) {
     462  //   fprintf (stderr, "%0llx : %0llx\n", (long long) VAL_K[i], (long long) VAL_K_t[i]);
     463  // }
     464
    241465  for (i = 0; i < Nval; i++) {
    242466    if (VAL_B[i] != VAL_B_t[i]) NVAL_B_bad++;
     
    255479  ok (!NVAL_D_bad, "double  values match (input vs output)");
    256480
     481  free (VAL_B);
     482  free (VAL_I);
     483  free (VAL_J);
     484  free (VAL_K);
     485  free (VAL_E);
     486  free (VAL_D);
     487
     488  free (VAL_B_t);
     489  free (VAL_I_t);
     490  free (VAL_J_t);
     491  free (VAL_K_t);
     492  free (VAL_E_t);
     493  free (VAL_D_t);
     494
    257495  gfits_free_header (&header);
    258496  gfits_free_table (&ftable);
     
    264502}
    265503
    266 int test_compress_single_full (char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE"
    267 
    268   Header header;
    269   FTable ftable;
    270 
    271   diag ("--- starting test_compress with zcmptype %s ---", zcmptype);
    272   ok (gfits_init_header (&header), "inited the header");
    273   ok (gfits_init_table (&ftable), "inited the table");
    274 
    275   ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header");
    276 
    277   ok (gfits_define_bintable_column (&header, "I", "SEQ", "seq", "none", 1.0, 0.0), "defined short column");
    278  
    279   // generate the output array that carries the data
    280   ok (gfits_create_table (&header, &ftable), "created the basic table");
    281 
    282   int Nval = 1000;
    283   short *SEQ;  ALLOCATE (SEQ, short,  Nval);
    284  
    285   int i;
    286   for (i = 0; i < Nval; i++) {
    287     SEQ[i] = i;
    288   }     
    289 
    290   // add the columns to the output array
    291   ok (gfits_set_bintable_column (&header, &ftable, "SEQ", SEQ, Nval), "set short  table column");
    292 
    293   Header *outheader = &header;
    294   FTable *outtable = &ftable;
    295 
    296   if (zcmptype) {
    297     Header cmpheader;
    298     FTable cmptable;
    299     cmptable.header = &cmpheader;
    300     ok (gfits_compress_table (&ftable, &cmptable, 0, zcmptype), "compressed table");
    301 
    302     Header rawheader;
    303     FTable rawtable;
    304     rawtable.header = &rawheader;
    305     ok (gfits_uncompress_table (&cmptable, &rawtable), "uncompressed table");
    306    
    307     gfits_free_header (&cmpheader);
    308     gfits_free_table (&cmptable);
    309 
    310     outheader = &rawheader;
    311     outtable  = &rawtable;
    312   }
    313 
    314   char type[16];
    315   int Ncol;
    316   off_t Nrow;
    317 
    318   short  *SEQ_t = gfits_get_bintable_column_data (outheader, outtable, "SEQ", type, &Nrow, &Ncol); ok (!strcmp (type, "short"),  "read short  table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
    319 
    320   // count mismatched values
    321   int Nseq = 0;
    322   for (i = 0; i < Nval; i++) {
    323     if (SEQ[i] != SEQ_t[i]) Nseq++;
    324   }
    325 
    326   ok (!Nseq,   "short  values match (input vs output)");
    327 
    328   gfits_free_header (&header);
    329   gfits_free_table (&ftable);
    330   if (zcmptype) {
    331     gfits_free_header (outheader);
    332     gfits_free_table (outtable);
    333   }
    334   return TRUE;
    335 }
    336 
    337 int test_compress_empty (char *zcmptype) { // test 2: make a table, compress, uncompress, compare : use compression "NONE"
    338 
    339   Header header;
    340   FTable ftable;
    341 
    342   diag ("--- starting test_compress with zcmptype %s ---", zcmptype);
    343   ok (gfits_init_header (&header), "inited the header");
    344   ok (gfits_init_table (&ftable), "inited the table");
    345 
    346   ok (gfits_create_table_header (&header, "BINTABLE", "TESTDATA"), "created the table header");
    347 
    348   ok (gfits_define_bintable_column (&header, "B", "VAL_B", "byte",   "none", 1.0, 0.0), "defined byte column");
    349   ok (gfits_define_bintable_column (&header, "I", "VAL_I", "short",  "none", 1.0, 0.0), "defined short column");
    350   ok (gfits_define_bintable_column (&header, "J", "VAL_J", "int",    "none", 1.0, 0.0),  "defined int column");
    351   ok (gfits_define_bintable_column (&header, "K", "VAL_K", "long",   "none", 1.0, 0.0),  "defined long column");
    352   ok (gfits_define_bintable_column (&header, "E", "VAL_E", "float",  "degree", 1.0, 0.0),   "defined float column");
    353   ok (gfits_define_bintable_column (&header, "D", "VAL_D", "double", "degree", 1.0, 0.0),   "defined double column");
    354  
    355   // generate the output array that carries the data
    356   ok (gfits_create_table (&header, &ftable), "created the basic table");
    357 
    358   int Nval = 0;
    359   char    *VAL_B;  ALLOCATE (VAL_B, char,    Nval);
    360   short   *VAL_I;  ALLOCATE (VAL_I, short,   Nval);
    361   int     *VAL_J;  ALLOCATE (VAL_J, int,     Nval);
    362   int64_t *VAL_K;  ALLOCATE (VAL_K, int64_t, Nval);
    363   float   *VAL_E;  ALLOCATE (VAL_E, float,   Nval);
    364   double  *VAL_D;  ALLOCATE (VAL_D, double,  Nval);
    365  
    366   int i;
    367   for (i = 0; i < Nval; i++) {
    368     VAL_B[i] = (i % 255) - 128;
    369     VAL_I[i] = i;
    370     VAL_J[i] = 10000*i + 100*i;
    371     VAL_K[i] = 10000*i + 330*i;
    372     VAL_E[i] = 0.1*i;
    373     VAL_D[i] = 1.001*i;
    374   }     
    375 
    376   // add the columns to the output array
    377   ok (gfits_set_bintable_column (&header, &ftable, "VAL_B", VAL_B, Nval), "set byte   table column");
    378   ok (gfits_set_bintable_column (&header, &ftable, "VAL_I", VAL_I, Nval), "set short  table column");
    379   ok (gfits_set_bintable_column (&header, &ftable, "VAL_J", VAL_J, Nval), "set int    table column");
    380   ok (gfits_set_bintable_column (&header, &ftable, "VAL_K", VAL_K, Nval), "set long   table column");
    381   ok (gfits_set_bintable_column (&header, &ftable, "VAL_E", VAL_E, Nval), "set float  table column");
    382   ok (gfits_set_bintable_column (&header, &ftable, "VAL_D", VAL_D, Nval), "set double table column");
    383 
    384   Header *outheader = &header;
    385   FTable *outtable = &ftable;
    386 
    387   if (zcmptype) {
    388     Header cmpheader;
    389     FTable cmptable;
    390     cmptable.header = &cmpheader;
    391     ok (gfits_compress_table (&ftable, &cmptable, 0, zcmptype), "compressed table");
    392 
    393     Header rawheader;
    394     FTable rawtable;
    395     rawtable.header = &rawheader;
    396     ok (gfits_uncompress_table (&cmptable, &rawtable), "uncompressed table");
    397    
    398     gfits_free_header (&cmpheader);
    399     gfits_free_table (&cmptable);
    400 
    401     outheader = &rawheader;
    402     outtable  = &rawtable;
    403   }
    404 
    405   char type[16];
    406   int Ncol;
    407   off_t Nrow;
    408 
    409   char    *VAL_B_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_B", type, &Nrow, &Ncol); ok (!strcmp (type, "byte"),    "read byte    table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
    410   short   *VAL_I_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_I", type, &Nrow, &Ncol); ok (!strcmp (type, "short"),   "read short   table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
    411   int     *VAL_J_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_J", type, &Nrow, &Ncol); ok (!strcmp (type, "int"),     "read int     table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
    412   int64_t *VAL_K_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_K", type, &Nrow, &Ncol); ok (!strcmp (type, "int64_t"), "read int64_t table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
    413   float   *VAL_E_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_E", type, &Nrow, &Ncol); ok (!strcmp (type, "float"),   "read float   table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
    414   double  *VAL_D_t = gfits_get_bintable_column_data (outheader, outtable, "VAL_D", type, &Nrow, &Ncol); ok (!strcmp (type, "double"),  "read double  table column"); ok (Nrow == Nval, "right number of rows"); ok (Ncol == 1, "right number of cols");
    415 
    416   // count mismatched values
    417   int NVAL_B_bad = 0;
    418   int NVAL_I_bad = 0;
    419   int NVAL_J_bad = 0;
    420   int NVAL_K_bad = 0;
    421   int NVAL_E_bad = 0;
    422   int NVAL_D_bad = 0;
    423 
    424   // for (i = 0; i < Nval; i++) {
    425   //   fprintf (stderr, "%0llx : %0llx\n", (long long) VAL_K[i], (long long) VAL_K_t[i]);
    426   // }
    427 
    428   for (i = 0; i < Nval; i++) {
    429     if (VAL_B[i] != VAL_B_t[i]) NVAL_B_bad++;
    430     if (VAL_I[i] != VAL_I_t[i]) NVAL_I_bad++;
    431     if (VAL_J[i] != VAL_J_t[i]) NVAL_J_bad++;
    432     if (VAL_K[i] != VAL_K_t[i]) NVAL_K_bad++;
    433     if (VAL_E[i] != VAL_E_t[i]) NVAL_E_bad++;
    434     if (VAL_D[i] != VAL_D_t[i]) NVAL_D_bad++;
    435   }
    436 
    437   ok (!NVAL_B_bad, "byte    values match (input vs output)");
    438   ok (!NVAL_I_bad, "short   values match (input vs output)");
    439   ok (!NVAL_J_bad, "int     values match (input vs output)");
    440   ok (!NVAL_K_bad, "int64_t values match (input vs output)");
    441   ok (!NVAL_E_bad, "float   values match (input vs output)");
    442   ok (!NVAL_D_bad, "double  values match (input vs output)");
    443 
    444   gfits_free_header (&header);
    445   gfits_free_table (&ftable);
    446   if (zcmptype) {
    447     gfits_free_header (outheader);
    448     gfits_free_table (outtable);
    449   }
    450   return TRUE;
    451 }
    452 
    453 
     504
  • branches/eam_branches/ohana.20160226/src/libfits/test/zlib.c

    r38442 r39421  
    1616  tmp = Pout[3]; Pout[3] = Pout[4]; Pout[4] = tmp; }
    1717
    18 int main (int argc, char **argv) {
     18int main (void) {
    1919 
    2020  plan_tests (14);
     
    3030  {
    3131    z_stream zdn;
    32     zdn.next_in = (char *) srcbuf;
     32    zdn.next_in = (unsigned char *) srcbuf;
    3333    zdn.avail_in = NSRC * sizeof(double);
    34     zdn.next_out = (char *) tgtbuf;
     34    zdn.next_out = (unsigned char *) tgtbuf;
    3535    zdn.avail_out = NTGT * sizeof(double);
    3636 
     
    8383  {
    8484    z_stream zup;
    85     zup.next_in = (char *) tgtbuf;
     85    zup.next_in = (unsigned char *) tgtbuf;
    8686    zup.avail_in = NTGT * sizeof(double);
    87     zup.next_out = (char *) outbuf;
     87    zup.next_out = (unsigned char *) outbuf;
    8888    zup.avail_out = NOUT * sizeof(double);
    8989 
     
    120120  {
    121121    z_stream zdn;
    122     zdn.next_in = (char *) srcbuf;
     122    zdn.next_in = (unsigned char *) srcbuf;
    123123    zdn.avail_in = NSRC * sizeof(double);
    124     zdn.next_out = (char *) tgtbuf;
     124    zdn.next_out = (unsigned char *) tgtbuf;
    125125    zdn.avail_out = NTGT * sizeof(double);
    126126 
     
    174174  {
    175175    z_stream zup;
    176     zup.next_in = (char *) tgtbuf;
     176    zup.next_in = (unsigned char *) tgtbuf;
    177177    zup.avail_in = NTGT * sizeof(double);
    178     zup.next_out = (char *) outbuf;
     178    zup.next_out = (unsigned char *) outbuf;
    179179    zup.avail_out = NOUT * sizeof(double);
    180180 
Note: See TracChangeset for help on using the changeset viewer.