IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5435 for trunk/psModules/test


Ignore:
Timestamp:
Oct 20, 2005, 1:06:24 PM (21 years ago)
Author:
gusciora
Message:

....

Location:
trunk/psModules/test
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/test/astrom/tst_pmAstrometry.c

    r5169 r5435  
    11/** @file  tst_pmAstrometry.c
    22 *
    3  *  @brief Contains the tests for pmAstrometry.[ch].  Only the pmxxxAlloc()
     3 *  @brief Contains the tests: pmAstrometry.[ch].  Only the pmxxxAlloc()
    44 *  and psFree() functionality are used here.
    55 *
    66 *  @author George Gusciora, MHPCC
    77 *
    8  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2005-09-28 20:42:51 $
     8 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2005-10-20 23:06:24 $
    1010 *
    1111 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3232                          };
    3333
     34#define CHIP_ALLOC_NAME "ChipName"
     35#define CELL_ALLOC_NAME "CellName"
     36
    3437psS32 main(psS32 argc, char* argv[])
    3538{
     
    4447    // XXX: Do something more with these arguments.
    4548    const psMetadata *camera = psMetadataAlloc();
    46     psDB *db = NULL;
    47     pmFPA* fpa = pmFPAAlloc(camera, db);
     49    pmFPA* fpa = pmFPAAlloc(camera);
    4850
    4951    if (fpa == NULL) {
    50         psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc returned a NULL.");
     52        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc returned a NULL.");
    5153        return 1;
    5254    }
    5355
    5456    if (fpa->fromTangentPlane != NULL) {
    55         psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc did not set ->fromTangentPlane to NULL.");
     57        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc did not set ->fromTangentPlane to NULL.");
    5658        return 2;
    5759    }
    5860
    5961    if (fpa->toTangentPlane != NULL) {
    60         psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc did not set ->toTangentPlane to NULL.");
     62        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc did not set ->toTangentPlane to NULL.");
    6163        return 3;
    6264    }
    6365    if (fpa->projection != NULL) {
    64         psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc did not set ->projection to NULL.");
     66        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc did not set ->projection to NULL.");
    6567        return 4;
    6668    }
    6769
    6870    if (fpa->concepts == NULL) {
    69         psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc did not set ->concepts.");
     71        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc did not set ->concepts.");
    7072        return 5;
    7173    }
    7274
    73     if (fpa->analysis == NULL) {
    74         psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc did not set ->analysis.");
     75    if (fpa->analysis != NULL) {
     76        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc did not set ->analysis to NULL.");
    7577        return 6;
    7678    }
    7779
    7880    if (fpa->camera != camera) {
    79         psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc did not set ->camera.");
     81        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc did not set ->camera.");
    8082        return 7;
    8183    }
    8284
    8385    if (fpa->chips == NULL) {
    84         psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc did not set ->chips.");
     86        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc did not set ->chips.");
    8587        return 8;
    8688    }
    8789
    88     if (fpa->header != NULL) {
    89         psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc did not set ->header to NULL.");
     90    if (fpa->private != NULL) {
     91        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc did not set ->private to NULL.");
    9092        return 9;
    9193    }
    9294
    93     if (fpa->db != db) {
    94         psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc did not set ->db.");
     95    psFree(fpa);
     96    psFree(camera);
     97
     98    return 0;
     99}
     100
     101static psS32 testChipAlloc(void)
     102{
     103    const psMetadata *camera = psMetadataAlloc();
     104    pmFPA* fpa = pmFPAAlloc(camera);
     105    if (fpa == NULL) {
     106        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc returned a NULL.");
     107        return 1;
     108    }
     109
     110    pmChip *chip = pmChipAlloc(fpa, CHIP_ALLOC_NAME);
     111    if (chip == NULL) {
     112        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmChipAlloc returned a NULL.");
     113        return 1;
     114    }
     115
     116    if (chip->col0 != -1) {
     117        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: chip->col0 set improperly.\n");
     118        return 5;
     119    }
     120
     121    if (chip->row0 != -1) {
     122        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: chip->row0 set improperly.\n");
     123        return 6;
     124    }
     125
     126    if (chip->toFPA != NULL) {
     127        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: chip->toChip set improperly.\n");
     128        return 7;
     129    }
     130
     131    if (chip->fromFPA != NULL) {
     132        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: chip->toFPA set improperly.\n");
     133        return 8;
     134    }
     135
     136    if (chip->concepts == NULL) {
     137        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: chip->concepts set improperly.\n");
     138        return 21;
     139    } else {
     140        psMetadataItem *tmpMeta = psMetadataLookup(chip->concepts, "CHIP.NAME");
     141        if (0 != strcmp((char *) tmpMeta->data.V, CHIP_ALLOC_NAME)) {
     142            psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: The metadata was set improperly.\n");
     143            return (32);
     144        }
     145        // XXX: Code a test to ensure the metadata has the correct type
     146    }
     147
     148    if (chip->analysis != NULL) {
     149        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: chip->analysis set improperly.\n");
    95150        return 10;
    96151    }
    97152
    98     psFree(camera);
    99     psFree(fpa);
    100 
    101     return 0;
    102 }
    103 
    104 static psS32 testChipAlloc(void)
    105 {
    106     const psMetadata *camera = psMetadataAlloc();
    107     psDB *db = NULL;
    108     pmFPA* fpa = pmFPAAlloc(camera, db);
    109     if (fpa == NULL) {
    110         psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc returned a NULL.");
    111         return 1;
    112     }
    113 
    114     pmChip *chip = pmChipAlloc(fpa);
    115     if (chip == NULL) {
    116         psLogMsg(__func__,PS_LOG_ERROR, "pmChipAlloc returned a NULL.");
    117         return 1;
    118     }
    119 
    120     if (chip->col0 != -1) {
    121         psLogMsg(__func__, PS_LOG_ERROR, "chip->col0 set improperly.\n");
    122         return 5;
    123     }
    124 
    125     if (chip->row0 != -1) {
    126         psLogMsg(__func__, PS_LOG_ERROR, "chip->row0 set improperly.\n");
    127         return 6;
    128     }
    129 
    130     if (chip->toFPA != NULL) {
    131         psLogMsg(__func__, PS_LOG_ERROR, "chip->toChip set improperly.\n");
    132         return 7;
    133     }
    134 
    135     if (chip->fromFPA != NULL) {
    136         psLogMsg(__func__, PS_LOG_ERROR, "chip->toFPA set improperly.\n");
    137         return 8;
    138     }
    139 
    140     if (chip->concepts == NULL) {
    141         psLogMsg(__func__, PS_LOG_ERROR, "chip->concepts set improperly.\n");
    142         return 21;
    143     }
    144 
    145     if (chip->analysis == NULL) {
    146         psLogMsg(__func__, PS_LOG_ERROR, "chip->analysis set improperly.\n");
    147         return 10;
    148     }
    149 
    150153    if (chip->cells == NULL) {
    151         psLogMsg(__func__, PS_LOG_ERROR, "chip->cells set improperly.\n");
     154        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: chip->cells set improperly.\n");
    152155        return 22;
    153156    }
    154157
    155158    if (chip->parent != fpa) {
    156         psLogMsg(__func__, PS_LOG_ERROR, "chip->parent set improperly.\n");
     159        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: chip->parent set improperly.\n");
    157160        return 23;
    158161    }
    159162
    160163    if (chip->valid != false) {
    161         psLogMsg(__func__, PS_LOG_ERROR, "chip->valid set improperly.\n");
     164        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: chip->valid set improperly.\n");
    162165        return 24;
    163166    }
    164167
    165     if (chip->extname != NULL) {
    166         psLogMsg(__func__, PS_LOG_ERROR, "chip->extname set improperly.\n");
     168    if (chip->private != NULL) {
     169        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: chip->private set improperly.\n");
    167170        return 25;
    168     }
    169 
    170     if (chip->pixels != NULL) {
    171         psLogMsg(__func__, PS_LOG_ERROR, "chip->pixels set improperly.\n");
    172         return 26;
    173     }
    174 
    175     if (chip->header != NULL) {
    176         psLogMsg(__func__, PS_LOG_ERROR, "chip->header set improperly.\n");
    177         return 27;
    178171    }
    179172
     
    187180static psS32 testCellAlloc(void)
    188181{
    189     psDB *db = NULL;
    190182    const psMetadata *camera = psMetadataAlloc();
    191     pmFPA* fpa = pmFPAAlloc(camera, db);
     183    pmFPA* fpa = pmFPAAlloc(camera);
    192184    if (fpa == NULL) {
    193         psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc returned a NULL.n");
    194         return 1;
    195     }
    196 
    197     pmChip *chip = pmChipAlloc(fpa);
     185        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc returned a NULL.n");
     186        return 1;
     187    }
     188
     189    pmChip *chip = pmChipAlloc(fpa, CHIP_ALLOC_NAME);
    198190    if (chip == NULL) {
    199         psLogMsg(__func__,PS_LOG_ERROR, "pmChipAlloc returned a NULL.n");
     191        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmChipAlloc returned a NULL.n");
    200192        return 2;
    201193    }
    202194
    203     pmCell *cell = pmCellAlloc(chip);
     195    pmCell *cell = pmCellAlloc(chip, (psMetadata *) camera, CELL_ALLOC_NAME);
    204196    if (cell == NULL) {
    205         psLogMsg(__func__,PS_LOG_ERROR, "pmCellAlloc returned a NULL.n");
     197        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmCellAlloc returned a NULL.n");
    206198        return 3;
    207199    }
    208200
    209201    if (cell->col0 != -1) {
    210         psLogMsg(__func__, PS_LOG_ERROR, "cell->col0 set improperly.\n");
     202        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->col0 set improperly.\n");
    211203        return 5;
    212204    }
    213205
    214206    if (cell->row0 != -1) {
    215         psLogMsg(__func__, PS_LOG_ERROR, "cell->row0 set improperly.\n");
     207        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->row0 set improperly.\n");
    216208        return 6;
    217209    }
    218210
    219211    if (cell->toChip != NULL) {
    220         psLogMsg(__func__, PS_LOG_ERROR, "cell->toChip set improperly.\n");
     212        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->toChip set improperly.\n");
    221213        return 7;
    222214    }
    223215
    224216    if (cell->toFPA != NULL) {
    225         psLogMsg(__func__, PS_LOG_ERROR, "cell->toFPA set improperly.\n");
     217        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->toFPA set improperly.\n");
    226218        return 8;
    227219    }
    228220
    229221    if (cell->toSky != NULL) {
    230         psLogMsg(__func__, PS_LOG_ERROR, "cell->toSky set improperly.\n");
     222        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->toSky set improperly.\n");
    231223        return 9;
    232224    }
    233225
    234     if (cell->analysis == NULL) {
    235         psLogMsg(__func__, PS_LOG_ERROR, "cell->analysis set improperly.\n");
     226    if (cell->concepts == NULL) {
     227        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->concepts set improperly.\n");
     228        return 21;
     229    } else {
     230        psMetadataItem *tmpMeta = psMetadataLookup(cell->concepts, "CELL.NAME");
     231        if (0 != strcmp((char *) tmpMeta->data.V, CELL_ALLOC_NAME)) {
     232            psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: The metadata was set improperly.\n");
     233            return (32);
     234        }
     235        // XXX: Code a test to ensure the metadata has the correct type
     236    }
     237
     238    if (cell->camera != camera) {
     239        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->camera set improperly.\n");
     240        return 20;
     241    }
     242
     243    if (cell->analysis != NULL) {
     244        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->analysis set improperly.\n");
    236245        return 10;
    237246    }
    238247
    239     if (cell->concepts == NULL) {
    240         psLogMsg(__func__, PS_LOG_ERROR, "cell->concepts set improperly.\n");
    241         return 21;
    242     }
    243 
    244248    if (cell->readouts == NULL) {
    245         psLogMsg(__func__, PS_LOG_ERROR, "cell->readouts set improperly.\n");
     249        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->readouts set improperly.\n");
    246250        return 22;
    247251    }
    248252
    249253    if (cell->parent != chip) {
    250         psLogMsg(__func__, PS_LOG_ERROR, "cell->parent set improperly.\n");
     254        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->parent set improperly.\n");
    251255        return 23;
    252256    }
    253257
    254258    if (cell->valid != false) {
    255         psLogMsg(__func__, PS_LOG_ERROR, "cell->valid set improperly.\n");
     259        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->valid set improperly.\n");
    256260        return 24;
    257261    }
    258262
    259     if (cell->extname != NULL) {
    260         psLogMsg(__func__, PS_LOG_ERROR, "cell->extname set improperly.\n");
    261         return 25;
    262     }
    263 
    264     if (cell->pixels != NULL) {
    265         psLogMsg(__func__, PS_LOG_ERROR, "cell->pixels set improperly.\n");
    266         return 26;
    267     }
    268 
    269     if (cell->header != NULL) {
    270         psLogMsg(__func__, PS_LOG_ERROR, "cell->header set improperly.\n");
     263    if (cell->private != NULL) {
     264        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: cell->private set improperly.\n");
    271265        return 27;
    272266    }
     
    282276static psS32 testReadoutAlloc(void)
    283277{
    284     psDB *db = NULL;
    285278    const psMetadata *camera = psMetadataAlloc();
    286     pmFPA* fpa = pmFPAAlloc(camera, db);
     279    pmFPA* fpa = pmFPAAlloc(camera);
    287280
    288281    if (fpa == NULL) {
    289         psLogMsg(__func__,PS_LOG_ERROR, "pmFPAAlloc returned a NULL.\n");
    290         return 1;
    291     }
    292 
    293     pmChip *chip = pmChipAlloc(fpa);
     282        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmFPAAlloc returned a NULL.\n");
     283        return 1;
     284    }
     285
     286    pmChip *chip = pmChipAlloc(fpa, "ChipName");
    294287    if (chip == NULL) {
    295         psLogMsg(__func__,PS_LOG_ERROR, "pmChipAlloc returned a NULL.\n");
     288        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmChipAlloc returned a NULL.\n");
    296289        return 2;
    297290    }
    298291
    299     pmCell *cell = pmCellAlloc(chip);
     292    pmCell *cell = pmCellAlloc(chip, (psMetadata *) camera, "CellName");
    300293    if (cell == NULL) {
    301         psLogMsg(__func__,PS_LOG_ERROR, "pmCellAlloc returned a NULL.\n");
     294        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmCellAlloc returned a NULL.\n");
    302295        return 3;
    303296    }
     
    305298    pmReadout *readout = pmReadoutAlloc(cell);
    306299    if (readout == NULL) {
    307         psLogMsg(__func__,PS_LOG_ERROR, "pmReadoutAlloc returned a NULL.\n");
     300        psLogMsg(__func__,PS_LOG_ERROR, "TEST ERROR: pmReadoutAlloc returned a NULL.\n");
    308301        return 4;
    309302    }
    310303
    311304    if (readout->col0 != -1) {
    312         psLogMsg(__func__, PS_LOG_ERROR, "pmReadout->col0 set improperly.\n");
     305        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: pmReadout->col0 set improperly.\n");
    313306        return 5;
    314307    }
    315308
    316309    if (readout->row0 != -1) {
    317         psLogMsg(__func__, PS_LOG_ERROR, "pmReadout->row0 set improperly.\n");
     310        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: pmReadout->row0 set improperly.\n");
    318311        return 6;
    319312    }
    320313
    321314    if (readout->colBins != -1) {
    322         psLogMsg(__func__, PS_LOG_ERROR, "pmReadout->colBins set improperly.\n");
     315        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: pmReadout->colBins set improperly.\n");
    323316        return 7;
    324317    }
    325318
    326319    if (readout->rowBins != -1) {
    327         psLogMsg(__func__, PS_LOG_ERROR, "pmReadout->colBins set improperly.\n");
     320        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: pmReadout->colBins set improperly.\n");
    328321        return 8;
    329322    }
    330323
    331324    if (readout->image != NULL) {
    332         psLogMsg(__func__, PS_LOG_ERROR, "pmReadout->image set improperly.\n");
    333         return 9;
     325        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: pmReadout->image set improperly.\n");
     326        return 10;
    334327    }
    335328
    336329    if (readout->mask != NULL) {
    337         psLogMsg(__func__, PS_LOG_ERROR, "pmReadout->mask set improperly.\n");
    338         return 10;
     330        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: pmReadout->mask set improperly.\n");
     331        return 12;
     332    }
     333
     334    if (readout->weight != NULL) {
     335        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: pmReadout->weight set improperly.\n");
     336        return 14;
     337    }
     338
     339    if (readout->bias != NULL) {
     340        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: pmReadout->bias set improperly.\n");
     341        return 16;
    339342    }
    340343
    341344    if (readout->analysis == NULL) {
    342         psLogMsg(__func__, PS_LOG_ERROR, "pmReadout->analysis set improperly.\n");
    343         return 11;
    344     }
    345 
    346     if (readout->concepts == NULL) {
    347         psLogMsg(__func__, PS_LOG_ERROR, "pmReadout->concepts set improperly.\n");
    348         return 12;
     345        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: pmReadout->analysis set improperly.\n");
     346        return 18;
    349347    }
    350348
    351349    if (readout->parent != cell) {
    352         psLogMsg(__func__, PS_LOG_ERROR, "pmReadout->parent set improperly.\n");
    353         return 15;
     350        psLogMsg(__func__, PS_LOG_ERROR, "TEST ERROR: pmReadout->parent set improperly.\n");
     351        return 20;
    354352    }
    355353
     
    362360    return 0;
    363361}
     362
  • trunk/psModules/test/config/Makefile.am

    r5169 r5435  
    44AM_CFLAGS  = @AM_CFLAGS@ $(PSMODULE_CFLAGS) $(SRCINC)
    55
    6 TESTS =
     6TESTS = \
     7    tst_pmConfig
     8
     9tst_pmConfig_SOURCES = tst_pmConfig.c
    710
    811check_PROGRAMS = $(TESTS)
     
    1013TESTS_ENVIRONMENT = perl $(top_srcdir)/test/runTest --verified=$(srcdir)/verified
    1114
    12 tests:
     15tests: $(TESTS)
     16
     17EXTRA_DIST = verified
     18
     19CLEANFILES = $(TESTS) temp/*
    1320
    1421test: check
  • trunk/psModules/test/detrend/tst_pmFlatField.c

    r5169 r5435  
    2121 *  @author Ross Harman, MHPCC
    2222 *
    23  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    24  *  @date $Date: 2005-09-28 20:42:52 $
     23 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     24 *  @date $Date: 2005-10-20 23:06:24 $
    2525 *
    2626 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    8585    inReadout->row0 = 0;
    8686    inReadout->col0 = 0;
     87    CREATE_AND_SET_IMAGE(inMask, U8, 0, 3,3);
     88    inReadout->mask = inMask;
     89    PRINT_MATRIX((inReadout->mask),U8,"Input mask:");
    8790    PRINT_MATRIX(inImage,F64,"Input image:");
    88 
    89     CREATE_AND_SET_IMAGE(inMask,U8,0,3,3)
    90     pmReadout *inMaskReadout = pmReadoutAlloc(NULL);
    91     inMaskReadout->image = inMask;
    92     inMaskReadout->row0 = 0;
    93     inMaskReadout->col0 = 0;
    94     PRINT_MATRIX(inMask,U8,"Input mask:");
    9591
    9692    CREATE_AND_SET_IMAGE(flatImage1,F64,2.0,3,3)
     
    10197    PRINT_MATRIX(flatImage1,F64,"Flat image:");
    10298
    103     if ( !pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
     99    if ( !pmFlatField(inReadout, flatReadout) ) {
    104100        psError(PS_ERR_UNKNOWN,true,"Test A - Returned false should be true");
    105101        return 1;
     
    116112    PRINT_MATRIX(flatImage2, F64, "Flat image:");
    117113    flatReadout->image = flatImage2;
    118     if ( !pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
     114    if ( !pmFlatField(inReadout, flatReadout) ) {
    119115        psError(PS_ERR_UNKNOWN,true,"Test B - Returned false should be true");
    120116        return 2;
    121117    }
    122     PRINT_MATRIX(inMaskReadout->image, PS_TYPE_MASK_DATA, "Resulting mask:");
     118    PRINT_MATRIX(inReadout->mask, PS_TYPE_MASK_DATA, "Resulting mask:");
    123119    PRINT_MATRIX(inImage,F64,"Resulting image:");
    124120    printFooter(stdout, "pmFlatField", "Test B - Mask flat image data", true);
     
    135131    psFree(inReadout->mask);
    136132    inReadout->mask = mask1;
    137     if ( !pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
     133    if ( !pmFlatField(inReadout, flatReadout) ) {
    138134        psError(PS_ERR_UNKNOWN,true,"Test C - Returned false should be true");
    139135        return 3;
     
    149145    printNegativeTestHeader(stdout,"pmFlatField", "Test D - Attempt to use null flat readout",
    150146                            "Null not allowed for flat readout", 0);
    151     if( pmFlatField(inReadout, inMaskReadout, NULL) ) {
     147    if( pmFlatField(inReadout, NULL) ) {
    152148        psError(PS_ERR_UNKNOWN,true,"Test D - Returned true should be false");
    153149        return 4;
     
    162158    psImage *temp = inReadout->image;
    163159    inReadout->image = NULL;
    164     if ( pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
     160    if ( pmFlatField(inReadout, flatReadout) ) {
    165161        psError(PS_ERR_UNKNOWN,true,"Test E - Returned true should be false" );
    166162        return 5;
    167163    }
    168     inReadout->image = temp;
     164    inReadout->image = temp    ;
    169165    printFooter(stdout, "pmFlatField", "Test E - Attempt to use null input image", true);
    170166    printf("\n\n\n");
     
    176172    temp = flatReadout->image;
    177173    flatReadout->image = NULL;
    178     if ( pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
     174    if ( pmFlatField(inReadout, flatReadout) ) {
    179175        psError(PS_ERR_UNKNOWN,true,"Test F - Returned true should be false" );
    180176        return 6;
     
    191187    temp = flatReadout->image;
    192188    flatReadout->image = smallFlat;
    193     if ( pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
     189    if ( pmFlatField(inReadout, flatReadout) ) {
    194190        psError(PS_ERR_UNKNOWN,true,"Test G - Returned true should be false");
    195191        return 7;
     
    198194    printFooter(stdout, "pmFlatField", "Test G - Attempt to use input image bigger than flat image", true);
    199195    printf("\n\n\n");
    200 
    201196
    202197    // Test H - Attempt to use input image mask bigger than flat image
     
    204199                            "Input image mask size exceeds that of flat image", 0);
    205200    CREATE_AND_SET_IMAGE(largeMask,F64,0.0,5,5);
    206     temp = inReadout->mask;
    207     inMaskReadout->image = largeMask;
    208     if ( pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
     201    inReadout->mask = largeMask;
     202    if ( pmFlatField(inReadout, flatReadout) ) {
    209203        psError(PS_ERR_UNKNOWN,true,"Test H - Returned true should be false");
    210204        return 8;
    211205    }
    212     inReadout->mask = temp;
    213206    printFooter(stdout, "pmFlatField", "Test H - Attempt to use input image mask bigger than flat image", true);
    214207    printf("\n\n\n");
    215 
     208    inReadout->mask = mask1;
    216209
    217210    // Test I - Attempt to use offset greater than input image
     
    220213    *(int*)&inReadout->col0 = 50;
    221214    *(int*)&inReadout->row0 = 50;
    222     if ( pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
     215    if ( pmFlatField(inReadout, flatReadout) ) {
    223216        psError(PS_ERR_UNKNOWN,true,"Test I - Returned true should be false");
    224217        return 9;
     
    234227                            "Complex types not allowed for input image", 0);
    235228    *(psElemType* ) & inReadout->image->type.type = PS_TYPE_C64;
    236     if ( pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
     229    if ( pmFlatField(inReadout, flatReadout) ) {
    237230        psError(PS_ERR_UNKNOWN,true,"Test J - Returned true should be false");
    238231        return 10;
     
    247240                            "Complex types not allowed for flat image", 0);
    248241    *(psElemType* ) & flatReadout->image->type.type = PS_TYPE_C64;
    249     if ( pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
     242    if ( pmFlatField(inReadout, flatReadout) ) {
    250243        psError(PS_ERR_UNKNOWN,true,"Test K - Returned ture should be false");
    251244        return 11;
     
    260253                            "Input and flat image types differ", 0);
    261254    *(psElemType* ) & flatReadout->image->type.type = PS_TYPE_F32;
    262     if ( pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
     255    if ( pmFlatField(inReadout, flatReadout) ) {
    263256        psError(PS_ERR_UNKNOWN,true,"Test L - Returned true should be false");
    264257        return 12;
     
    273266                            "Mask must be PS_TYPE_MASK type", 0);
    274267    *(psElemType* ) & inReadout->mask->type.type = PS_TYPE_F32;
    275     if ( pmFlatField(inReadout, inMaskReadout, flatReadout) ) {
     268    if ( pmFlatField(inReadout, flatReadout) ) {
    276269        psError(PS_ERR_UNKNOWN,true,"Test M - Returned true should be false");
    277270        return 13;
     
    283276
    284277    // Free memory
    285     psFree(inMask);
    286     psFree(largeMask);
    287     inMaskReadout->image = NULL;
    288     psFree(inMaskReadout);
    289278    psFree(inReadout);
    290279    psFree(flatReadout);
     
    293282    //psFree(flatImage1);
    294283    psFree(smallFlat);
     284    psFree(largeMask);
    295285
    296286    return 0;
  • trunk/psModules/test/detrend/tst_pmNonLinear.c

    r5169 r5435  
    1 /** @file tst_pmNonLinear.c
     1/* @file tst_pmNonLinear.c
    22 *
    33 *  @brief Contains the tests for pmNonLinear.c:
     
    1616 *  @author GLG, MHPCC
    1717 *
    18  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    19  *  @date $Date: 2005-09-28 20:42:52 $
     18 *  XXX: Add tests in which the lookup file has incorrect number of entries,
     19 *  and where the data is outside the pmReadout range.
     20 *
     21 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     22 *  @date $Date: 2005-10-20 23:06:24 $
    2023 *
    2124 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3740                          };
    3841
    39 
    40 int main(int argc, char* argv[])
    41 {
    42     psLogSetFormat("HLNM");
    43     return !runTestSuite(stderr, "Test Point Driver", tests, argc, argv);
    44 }
    45 
    4642#define NUM_ROWS 8
    4743#define NUM_COLS 8
     44#define LOOKUP_FILENAME ".tmp_tst_pmNonLinearLookupFile"
     45int main(int argc, char* argv[])
     46{
     47    psLogSetFormat("HLNM");
     48    //
     49    // We generate a lookup file for future tests.  We should probably remove
     50    // it when we're done.
     51    //
     52    FILE *fp = fopen(LOOKUP_FILENAME, "w");
     53    ;
     54    for (psS32 i=0;i<PS_MAX(NUM_COLS, NUM_ROWS)*3;i++) {
     55        fprintf(fp, "%f %f\n", (float) i, (float) (2 * i));
     56    }
     57    fclose(fp);
     58
     59    //    system("rm LOOKUP_FILENAME");
     60    return !runTestSuite(stderr, "Test Point Driver", tests, argc, argv);
     61}
     62
    4863int doNonLinearityPolynomialTest(int numCols, int numRows)
    4964{
     
    105120    float expect;
    106121    int testStatus = true;
    107     int tableSize = PS_MAX(numCols, numRows)*2;
    108122    psImage *myImage = psImageAlloc(numCols, numRows, PS_TYPE_F32);
    109123    pmReadout *myReadout = pmReadoutAlloc(NULL);
    110124    myReadout->image = myImage;
    111     psVector *in = psVectorAlloc(tableSize, PS_TYPE_F32);
    112     psVector *out = psVectorAlloc(tableSize, PS_TYPE_F32);
    113125
    114126    printPositiveTestHeader(stdout, "pmNonLinear", "doNonLinearityLookupTest");
     
    119131    }
    120132
    121     for (i=0;i<tableSize;i++) {
    122         in->data.F32[i] = (float) i;
    123         out->data.F32[i] = (float) (2 * i);
    124     }
    125 
    126     myReadout = pmNonLinearityLookup(myReadout, in, out);
     133    myReadout = pmNonLinearityLookup(myReadout, LOOKUP_FILENAME);
    127134    for (i=0;i<numRows;i++) {
    128135        for (j=0;j<numCols;j++) {
     
    136143    }
    137144
    138 
    139     psFree(myReadout);
    140     psFree(in);
    141     psFree(out);
     145    psFree(myReadout);
    142146    printFooter(stdout, "pmNonLinear", "doNonLinearityLookupTest", true);
    143147    return(testStatus);
     
    220224int test03()
    221225{
    222     int i;
    223     int j;
    224     int testStatus = true;
    225     int tableSize = PS_MAX(NUM_COLS, NUM_ROWS)*3;
     226    int testStatus = true;
    226227    psImage *myImage = psImageAlloc(NUM_COLS, NUM_ROWS, PS_TYPE_F32);
    227228    pmReadout *myReadout = pmReadoutAlloc(NULL);
    228229    pmReadout *rc = NULL;
    229230    myReadout->image = myImage;
    230     psVector *in = psVectorAlloc(tableSize, PS_TYPE_F32);
    231     psVector *inOne = psVectorAlloc(1, PS_TYPE_F32);
    232     psVector *inSmall = psVectorAlloc(tableSize-1, PS_TYPE_F32);
    233     psVector *inBig = psVectorAlloc(tableSize+1, PS_TYPE_F32);
    234     psVector *out = psVectorAlloc(tableSize, PS_TYPE_F32);
    235     psVector *outOne = psVectorAlloc(1, PS_TYPE_F32);
    236     psVector *outSmall = psVectorAlloc(tableSize-1, PS_TYPE_F32);
    237     psVector *outBig = psVectorAlloc(tableSize+1, PS_TYPE_F32);
    238231
    239232    test03Init(myReadout);
    240     for (i=0;i<tableSize;i++) {
    241         in->data.F32[i] = (float) i;
    242         out->data.F32[i] = (float) (2 * i);
    243         inBig->data.F32[i] = (float) i;
    244         outBig->data.F32[i] = (float) (2 * i);
    245         if (i < tableSize-1) {
    246             inSmall->data.F32[i] = (float) i;
    247             outSmall->data.F32[i] = (float) (2 * i);
    248         }
    249     }
    250     inBig->data.F32[tableSize] = (float) tableSize;
    251     outBig->data.F32[tableSize] = (float) (2 * tableSize);
    252     inOne->data.F32[0] = 0.0;
    253     outOne->data.F32[0] = 0.0;
    254 
    255233    printf("------------------------------------------------------------\n");
    256234    printf("Calling pmNonLinearityLookup() with NULL input pmReadout.  Should generate error, return NULL.\n");
    257     rc = pmNonLinearityLookup(NULL, in, out);
     235    rc = pmNonLinearityLookup(NULL, LOOKUP_FILENAME);
    258236    if (rc != NULL) {
    259237        printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL pmReadout\n");
     
    265243    psImage *tmpImage = myReadout->image;
    266244    myReadout->image = NULL;
    267     rc = pmNonLinearityLookup(myReadout, in, out);
     245    rc = pmNonLinearityLookup(myReadout, LOOKUP_FILENAME);
    268246    if (rc != NULL) {
    269247        printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL pmReadout\n");
     
    273251
    274252    printf("------------------------------------------------------------\n");
    275     printf("Calling pmNonLinearityLookup() with NULL inFlux psVector.  Should generate error, return NULL.\n");
    276     rc = pmNonLinearityLookup(myReadout, NULL, out);
    277     if (rc != NULL) {
    278         printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL pmReadout\n");
    279         testStatus = false;
    280     }
    281 
    282     printf("------------------------------------------------------------\n");
    283     printf("Calling pmNonLinearityLookup() with NULL outFlux psVector.  Should generate error, return NULL.\n");
    284     rc = pmNonLinearityLookup(myReadout, in, NULL);
    285     if (rc != NULL) {
    286         printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL pmReadout\n");
    287         testStatus = false;
    288     }
    289 
    290     test03Init(myReadout);
    291     printf("------------------------------------------------------------\n");
    292     printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
    293     rc = pmNonLinearityLookup(myReadout, in, outBig);
     253    printf("Calling pmNonLinearityLookup() with non-existent lookup file.\n");
     254    rc = pmNonLinearityLookup(myReadout, "I_DONT_EXIST");
    294255    if (rc == NULL) {
    295256        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n");
    296257        testStatus = false;
    297258    }
    298     for (i=0;i<NUM_ROWS;i++) {
    299         for (j=0;j<NUM_COLS;j++) {
    300             psF32 expect = (float) (2 * (i + j));
    301             psF32 actual = rc->image->data.F32[i][j];
    302             if (FLT_EPSILON < fabs(expect - actual)) {
    303                 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
    304                 testStatus = false;
    305             }
    306         }
    307     }
    308 
    309 
    310     test03Init(myReadout);
    311     printf("------------------------------------------------------------\n");
    312     printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
    313     rc = pmNonLinearityLookup(myReadout, in, outSmall);
    314     if (rc == NULL) {
    315         printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n");
    316         testStatus = false;
    317     }
    318     for (i=0;i<NUM_ROWS;i++) {
    319         for (j=0;j<NUM_COLS;j++) {
    320             psF32 expect = (float) (2 * (i + j));
    321             psF32 actual = rc->image->data.F32[i][j];
    322             if (FLT_EPSILON < fabs(expect - actual)) {
    323                 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
    324                 testStatus = false;
    325             }
    326         }
    327     }
    328 
    329     test03Init(myReadout);
    330     printf("------------------------------------------------------------\n");
    331     printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
    332     rc = pmNonLinearityLookup(myReadout, inSmall, out);
    333     if (rc == NULL) {
    334         printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n");
    335         testStatus = false;
    336     }
    337     for (i=0;i<NUM_ROWS;i++) {
    338         for (j=0;j<NUM_COLS;j++) {
    339             psF32 expect = (float) (2 * (i + j));
    340             psF32 actual = rc->image->data.F32[i][j];
    341             if (FLT_EPSILON < fabs(expect - actual)) {
    342                 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
    343                 testStatus = false;
    344             }
    345         }
    346     }
    347 
    348     test03Init(myReadout);
    349     printf("------------------------------------------------------------\n");
    350     printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
    351     rc = pmNonLinearityLookup(myReadout, inBig, out);
    352     if (rc == NULL) {
    353         printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n");
    354         testStatus = false;
    355     }
    356     for (i=0;i<NUM_ROWS;i++) {
    357         for (j=0;j<NUM_COLS;j++) {
    358             psF32 expect = (float) (2 * (i + j));
    359             psF32 actual = rc->image->data.F32[i][j];
    360             if (FLT_EPSILON < fabs(expect - actual)) {
    361                 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
    362                 testStatus = false;
    363             }
    364         }
    365     }
    366 
    367     test03Init(myReadout);
    368     printf("------------------------------------------------------------\n");
    369     printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
    370     rc = pmNonLinearityLookup(myReadout, inSmall, outBig);
    371     if (rc == NULL) {
    372         printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n");
    373         testStatus = false;
    374     }
    375     for (i=0;i<NUM_ROWS;i++) {
    376         for (j=0;j<NUM_COLS;j++) {
    377             psF32 expect = (float) (2 * (i + j));
    378             psF32 actual = rc->image->data.F32[i][j];
    379             if (FLT_EPSILON < fabs(expect - actual)) {
    380                 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
    381                 testStatus = false;
    382             }
    383         }
    384     }
    385 
    386     test03Init(myReadout);
    387     printf("------------------------------------------------------------\n");
    388     printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
    389     rc = pmNonLinearityLookup(myReadout, inBig, outSmall);
    390     if (rc == NULL) {
    391         printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n");
    392         testStatus = false;
    393     }
    394     for (i=0;i<NUM_ROWS;i++) {
    395         for (j=0;j<NUM_COLS;j++) {
    396             psF32 expect = (float) (2 * (i + j));
    397             psF32 actual = rc->image->data.F32[i][j];
    398             if (FLT_EPSILON < fabs(expect - actual)) {
    399                 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
    400                 testStatus = false;
    401             }
    402         }
    403     }
    404 
    405     test03Init(myReadout);
    406     printf("------------------------------------------------------------\n");
    407     printf("Calling pmNonLinearityLookup() with inFlux psVector size 1.  Should generate error, return original pmReadout.\n");
    408     rc = pmNonLinearityLookup(myReadout, inOne, out);
    409     if (rc != myReadout) {
    410         printf("TEST ERROR: pmNonLinearityPolynomial() did not return the original pmReadout\n");
    411         testStatus = false;
    412     }
    413     for (i=0;i<NUM_ROWS;i++) {
    414         for (j=0;j<NUM_COLS;j++) {
    415             psF32 expect = (float) ((i + j));
    416             psF32 actual = rc->image->data.F32[i][j];
    417             if (FLT_EPSILON < fabs(expect - actual)) {
    418                 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
    419                 testStatus = false;
    420             }
    421         }
    422     }
     259
    423260
    424261    printf("------------------------------------------------------------\n");
    425262    printf("Calling pmNonLinearityLookup() with one pixels outside inFlux range.  Should generate warnings.\n");
    426     test03Init(myReadout);
    427     myReadout->image->data.F32[0][0] = -1;
    428     rc = pmNonLinearityLookup(myReadout, in, out);
    429     if (rc == NULL) {
    430         printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n");
    431         testStatus = false;
    432     }
    433     for (i=0;i<NUM_ROWS;i++) {
    434         for (j=0;j<NUM_COLS;j++) {
    435             psF32 expect = (float) (2 * (i + j));
    436             psF32 actual = rc->image->data.F32[i][j];
    437             if(i==0 && j==0) {
    438                 if(actual != 0.0) {
    439                     printf("TEST ERROR: image[%d][%d] is %f, should be %f\n",i,j,actual,0.0);
    440                 }
    441             } else {
    442                 if (FLT_EPSILON < fabs(expect - actual)) {
    443                     printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
    444                     testStatus = false;
    445                 }
    446             }
    447         }
    448     }
    449 
    450     printf("------------------------------------------------------------\n");
    451     printf("Calling pmNonLinearityLookup() with one pixels outside inFlux range.  Should generate warnings.\n");
    452     test03Init(myReadout);
    453     myReadout->image->data.F32[NUM_ROWS-1][NUM_COLS-1] = 100;
    454     rc = pmNonLinearityLookup(myReadout, in, out);
    455     if (rc == NULL) {
    456         printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n");
    457         testStatus = false;
    458     }
    459     for (i=0;i<NUM_ROWS;i++) {
    460         for (j=0;j<NUM_COLS;j++) {
    461             psF32 expect = (float) (2 * (i + j));
    462             psF32 actual = rc->image->data.F32[i][j];
    463             if(i==(NUM_ROWS-1) && j==(NUM_COLS-1)) {
    464                 if(actual != (tableSize-1)*2) {
    465                     printf("TEST ERROR: image[%d][%d] is %f, should be %f\n",i,j,actual,(tableSize-1)*2.0);
    466                 }
    467             } else {
    468                 if (FLT_EPSILON < fabs(expect - actual)) {
    469                     printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
    470                     testStatus = false;
    471                 }
    472             }
    473         }
    474     }
    475 
    476     test03Init(myReadout);
    477     printf("------------------------------------------------------------\n");
    478     printf("Calling pmNonLinearityLookup() with image values not in vector.\n");
    479     myReadout->image->data.F32[0][0] = 0.5;
    480     rc = pmNonLinearityLookup(myReadout, in, out);
    481     if (rc == NULL) {
    482         printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n");
    483         testStatus = false;
    484     }
    485     for (i=0;i<NUM_ROWS;i++) {
    486         for (j=0;j<NUM_COLS;j++) {
    487             psF32 expect = (float) (2 * (i + j));
    488             if(i==0 && j==0) {
    489                 expect = 1.0;
    490             }
    491             psF32 actual = rc->image->data.F32[i][j];
    492             if (FLT_EPSILON < fabs(expect - actual)) {
    493                 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
    494                 testStatus = false;
    495             }
    496         }
    497     }
    498 
    499     psFree(myReadout);
    500     psFree(in);
    501     psFree(inOne);
    502     psFree(inSmall);
    503     psFree(inBig);
    504     psFree(out);
    505     psFree(outOne);
    506     psFree(outSmall);
    507     psFree(outBig);
     263
     264    psFree(myReadout);
    508265
    509266    printFooter(stdout, "pmNonLinear", "Testing bad input parameter conditions.", true);
  • trunk/psModules/test/objects/tst_pmObjects01.c

    r5258 r5435  
    1 /** @file tst_pmFindObjects.c
     1/** @file tst_pmObjects.c
    22 *
    3  *  @brief Contains the tests for pmSubtractSky.c:
     3 *  @brief Contains the tests for pmObjects.c:
    44 *
    55 * test00: This code will ...
     
    99 * XXX: Must test
    1010 *       pmSourceRoughClass
     11 *  many others...
     12 *
    1113 *
    1214 * XXX: Must test output results for many other functions.
     
    2325Weakly Tested:
    2426    pmSourceMoments()
    25  
     27    most of psObjects.c is not tested
    2628 *
    27  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    28  *  @date $Date: 2005-10-10 21:55:42 $
     29 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     30 *  @date $Date: 2005-10-20 23:06:24 $
    2931 *
    3032 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    4749//static int test06(void);
    4850//static int test07(void);
    49 /*
    50 static int test08(void);
     51//static int test08(void);
    5152static int test09(void);
    5253static int test15(void);
    5354static int test16(void);
    5455static int test20(void);
    55 */
    5656testDescription tests[] = {
    5757                              {test00, 000, "pmObjects: structure allocators and deallocators", true, false},
     
    6363                              //                              {test06, 001, "pmObjects: pmSourceSetPixelsCircle()", true, false},
    6464                              //                              {test07, 001, "pmObjects: pmMin()", true, false},
    65                               /*
    66                                                             {test08, 001, "pmObjects: pmSourceModelGuess()", true, false},
    67                                                             {test09, 001, "pmObjects: pmSourceContour()", true, false},
    68                                                             {test15, 001, "pmObjects: pmSourceAddModel()", true, false},
    69                                                             {test16, 001, "pmObjects: pmSourceSubModel()", true, false},
    70                                                             {test20, 001, "pmObjects: pmSourceSubModel()", true, false},
    71                               */
     65                              //                              {test08, 001, "pmObjects: pmSourceModelGuess()", true, false},
     66                              {test09, 001, "pmObjects: pmSourceContour()", true, false},
     67                              {test15, 001, "pmObjects: pmSourceAddModel()", true, false},
     68                              {test16, 001, "pmObjects: pmSourceSubModel()", true, false},
     69                              {test20, 001, "pmObjects: pmSourceSubModel()", true, false},
    7270                              {NULL}
    7371                          };
     
    975973}
    976974
     975#define TST09_NUM_ROWS 70
     976#define TST09_NUM_COLS 70
     977#define TST09_SKY 5.0
     978#define TST09_INNER_RADIUS 3
     979#define TST09_OUTER_RADIUS 10
     980#define LEVEL (TST09_SKY + 10.0)
     981/******************************************************************************
     982test09(): We first test pmSourceContour() with various NULL and unallowable
     983input parameters.
     984 
     985XXX: We don't verify the numbers.
     986 *****************************************************************************/
     987int test09( void )
     988{
     989    bool testStatus = true;
     990    psImage *imgData = psImageAlloc(TST09_NUM_COLS, TST09_NUM_ROWS, PS_TYPE_F32);
     991    psImageInit(imgData, TST09_SKY);
     992    psImage *imgMask = psImageAlloc(TST09_NUM_COLS, TST09_NUM_ROWS, PS_TYPE_U8);
     993    psImageInit(imgMask, 0);
     994    pmPeak *tmpPeak = pmPeakAlloc((psF32) (TST09_NUM_ROWS / 2),
     995                                  (psF32) (TST09_NUM_COLS / 2),
     996                                  200.0,
     997                                  PM_PEAK_LONE);
     998    pmSource *tmpSource = pmSourceAlloc();
     999    tmpSource->pixels = imgData;
     1000    tmpSource->mask = imgMask;
     1001    tmpSource->peak = tmpPeak;
     1002    psBool rc = pmSourceLocalSky(tmpSource, PS_STAT_SAMPLE_MEAN, 10.0);
     1003    if (rc == false) {
     1004        printf("TEST ERROR: pmSourceLocalSky() returned a FALSE pmSource.\n");
     1005        testStatus = false;
     1006    }
     1007
     1008    printf("----------------------------------------------------------------------------------\n");
     1009    printf("Calling pmSourceContour with NULL pmSource .  Should generate error, return FALSE.\n");
     1010    rc = pmSourceContour(NULL, imgData, LEVEL, PS_CONTOUR_CRUDE);
     1011    if (rc != false) {
     1012        printf("TEST ERROR: pmSourceContour() returned TRUE.\n");
     1013        testStatus = false;
     1014        psFree(rc);
     1015    }
     1016
     1017    printf("----------------------------------------------------------------------------------\n");
     1018    printf("Calling pmSourceContour with NULL psImage .  Should generate error, return FALSE.\n");
     1019    rc = pmSourceContour(tmpSource, NULL, LEVEL, PS_CONTOUR_CRUDE);
     1020    if (rc != FALSE) {
     1021        printf("TEST ERROR: pmSourceContour() returned TRUE.\n");
     1022        testStatus = false;
     1023        psFree(rc);
     1024    }
     1025
     1026    //
     1027    // XXX: pmSourceContour() has a problem with contour tops/bottoms.
     1028    // Must correct this.
     1029    //
     1030    if (1) {
     1031        printf("----------------------------------------------------------------------------------\n");
     1032        printf("Calling pmSourceContour with acceptable data.\n");
     1033        printf("NOTE: must figure out the parameters for this test to be meaningful.\n");
     1034        tmpSource->modelPSF->params->data.F32[0] = TST09_SKY;
     1035        tmpSource->modelPSF->params->data.F32[1] = 15.0;
     1036        tmpSource->modelPSF->params->data.F32[2] = (psF32) (TST09_NUM_ROWS / 2);
     1037        tmpSource->modelPSF->params->data.F32[3] = (psF32) (TST09_NUM_COLS / 2);
     1038        tmpSource->modelPSF->params->data.F32[4] = 2.0;
     1039        tmpSource->modelPSF->params->data.F32[5] = 2.0;
     1040        tmpSource->modelPSF->params->data.F32[6] = 2.0;
     1041        rc = pmSourceContour(tmpSource, imgData, LEVEL, PS_CONTOUR_CRUDE);
     1042        if (rc == false) {
     1043            printf("TEST ERROR: pmSourceContour() returned FALSE.\n");
     1044            testStatus = false;
     1045        } else {
     1046            psFree(rc);
     1047        }
     1048    }
     1049
     1050    psFree(tmpSource);
     1051    return(testStatus);
     1052}
     1053
     1054#define TST15_NUM_ROWS 100
     1055#define TST15_NUM_COLS 100
     1056#define TST15_SKY 10.0
     1057#define TST15_INNER_RADIUS 3
     1058#define TST15_OUTER_RADIUS 5
     1059/******************************************************************************
     1060test15(): We first test pmSourceAddModel() with various NULL and unallowable
     1061input parameters.
     1062 
     1063XXX: We don't verify the numbers.
     1064 *****************************************************************************/
     1065int test15( void )
     1066{
     1067    bool testStatus = true;
     1068    psImage *imgData = psImageAlloc(TST15_NUM_COLS, TST15_NUM_ROWS, PS_TYPE_F32);
     1069    psImageInit(imgData, TST15_SKY);
     1070    psImage *imgMask = psImageAlloc(TST15_NUM_COLS, TST15_NUM_ROWS, PS_TYPE_U8);
     1071    psImageInit(imgMask, 0);
     1072    pmPeak *tmpPeak = pmPeakAlloc((psF32) (TST15_NUM_ROWS / 2),
     1073                                  (psF32) (TST15_NUM_COLS / 2),
     1074                                  200.0,
     1075                                  PM_PEAK_LONE);
     1076    pmSource *tmpSource = pmSourceAlloc();
     1077    tmpSource->pixels = imgData;
     1078    tmpSource->mask = imgMask;
     1079    tmpSource->peak = tmpPeak;
     1080    psBool rc = pmSourceLocalSky(tmpSource, PS_STAT_SAMPLE_MEAN, 10.0);
     1081    if (rc == false) {
     1082        printf("TEST ERROR: pmSourceLocalSky() returned a FALSE pmSource.\n");
     1083        testStatus = false;
     1084    }
     1085
     1086
     1087    tmpSource->modelPSF = pmModelAlloc(PS_MODEL_GAUSS);
     1088    tmpSource->modelPSF->params->data.F32[0] = 5.0;
     1089    tmpSource->modelPSF->params->data.F32[1] = 70.0;
     1090    tmpSource->modelPSF->params->data.F32[2] = (psF32) (TST15_NUM_ROWS / 2);
     1091    tmpSource->modelPSF->params->data.F32[3] = (psF32) (TST15_NUM_COLS / 2);
     1092    tmpSource->modelPSF->params->data.F32[4] = 1.0;
     1093    tmpSource->modelPSF->params->data.F32[5] = 1.0;
     1094    tmpSource->modelPSF->params->data.F32[6] = 2.0;
     1095
     1096    printf("----------------------------------------------------------------------------------\n");
     1097    printf("Calling pmSourceAddModel with NULL psImage.  Should generate error, return FALSE.\n");
     1098    rc = pmSourceAddModel(NULL, tmpSource, true);
     1099    if (rc == true) {
     1100        printf("TEST ERROR: pmSourceAddModel() returned TRUE.\n");
     1101        testStatus = false;
     1102    }
     1103
     1104    printf("----------------------------------------------------------------------------------\n");
     1105    printf("Calling pmSourceAddModel with NULL psSrc.  Should generate error, return FALSE.\n");
     1106    rc = pmSourceAddModel(imgData, NULL, true);
     1107    if (rc == true) {
     1108        printf("TEST ERROR: pmSourceAddModel() returned TRUE.\n");
     1109        testStatus = false;
     1110    }
     1111
     1112    printf("----------------------------------------------------------------------------------\n");
     1113    printf("Calling pmSourceAddModel with acceptable data.\n");
     1114    rc = pmSourceAddModel(imgData, tmpSource, true);
     1115    if (rc != true) {
     1116        printf("TEST ERROR: pmSourceAddModel() returned FALSE.\n");
     1117        testStatus = false;
     1118    }
     1119
     1120    psFree(tmpSource);
     1121    psFree(imgData);
     1122    return(testStatus);
     1123}
     1124
     1125#define TST16_NUM_ROWS 100
     1126#define TST16_NUM_COLS 100
     1127#define TST16_SKY 10.0
     1128#define TST16_INNER_RADIUS 3
     1129#define TST16_OUTER_RADIUS 5
     1130/******************************************************************************
     1131test16(): We first test pmSourceSubModel() with various NULL and unallowable
     1132input parameters.
     1133 
     1134XXX: We don't verify the numbers.
     1135 *****************************************************************************/
     1136int test16( void )
     1137{
     1138    bool testStatus = true;
     1139    psImage *imgData = psImageAlloc(TST16_NUM_COLS, TST16_NUM_ROWS, PS_TYPE_F32);
     1140    for (psS32 i = 0 ; i < imgData->numRows; i++) {
     1141        for (psS32 j = 0 ; j < imgData->numCols; j++) {
     1142            imgData->data.F32[i][j] = TST16_SKY;
     1143        }
     1144    }
     1145    pmSource *tmpSource = NULL;
     1146    psBool rc = false;
     1147
     1148    pmPeak *tmpPeak = pmPeakAlloc((psF32) (TST16_NUM_ROWS / 2),
     1149                                  (psF32) (TST16_NUM_COLS / 2),
     1150                                  200.0,
     1151                                  PM_PEAK_LONE);
     1152
     1153    printf("Calling pmSourceLocalSky with valid data.\n");
     1154    tmpPeak->x = (psF32) (TST16_NUM_ROWS / 2);
     1155    tmpPeak->y = (psF32) (TST16_NUM_COLS / 2);
     1156    tmpSource = pmSourceLocalSky(imgData,
     1157                                 tmpPeak,
     1158                                 PS_STAT_SAMPLE_MEAN,
     1159                                 (psF32) TST16_INNER_RADIUS,
     1160                                 (psF32) TST16_OUTER_RADIUS);
     1161
     1162    if (tmpSource == NULL) {
     1163        printf("TEST ERROR: pmSourceLocalSky() returned a NULL pmSource.\n");
     1164        testStatus = false;
     1165    }
     1166
     1167    tmpSource->modelPSF = pmModelAlloc(PS_MODEL_GAUSS);
     1168    tmpSource->modelPSF->params->data.F32[0] = 5.0;
     1169    tmpSource->modelPSF->params->data.F32[1] = 70.0;
     1170    tmpSource->modelPSF->params->data.F32[2] = (psF32) (TST16_NUM_ROWS / 2);
     1171    tmpSource->modelPSF->params->data.F32[3] = (psF32) (TST16_NUM_COLS / 2);
     1172    tmpSource->modelPSF->params->data.F32[4] = 1.0;
     1173    tmpSource->modelPSF->params->data.F32[5] = 1.0;
     1174    tmpSource->modelPSF->params->data.F32[6] = 2.0;
     1175
     1176    printf("----------------------------------------------------------------------------------\n");
     1177    printf("Calling pmSourceSubModel with NULL psImage.  Should generate error, return FALSE.\n");
     1178    rc = pmSourceSubModel(NULL, tmpSource, true);
     1179    if (rc == true) {
     1180        printf("TEST ERROR: pmSourceSubModel() returned TRUE.\n");
     1181        testStatus = false;
     1182    }
     1183
     1184    printf("----------------------------------------------------------------------------------\n");
     1185    printf("Calling pmSourceSubModel with NULL psSrc.  Should generate error, return FALSE.\n");
     1186    rc = pmSourceSubModel(imgData, NULL, true);
     1187    if (rc == true) {
     1188        printf("TEST ERROR: pmSourceSubModel() returned TRUE.\n");
     1189        testStatus = false;
     1190    }
     1191
     1192    printf("----------------------------------------------------------------------------------\n");
     1193    printf("Calling pmSourceSubModel with acceptable data.\n");
     1194    rc = pmSourceSubModel(imgData, tmpSource, true);
     1195    if (rc != true) {
     1196        printf("TEST ERROR: pmSourceSubModel() returned FALSE.\n");
     1197        testStatus = false;
     1198    }
     1199
     1200    psFree(tmpSource);
     1201    psFree(imgData);
     1202    return(testStatus);
     1203}
     1204
     1205#define TST20_NUM_ROWS 100
     1206#define TST20_NUM_COLS 100
     1207#define TST20_SKY 10.0
     1208#define TST20_INNER_RADIUS 3
     1209#define TST20_OUTER_RADIUS 5
     1210/******************************************************************************
     1211test20(): We first test pmSourceSubModel() with various NULL and unallowable
     1212input parameters.
     1213 
     1214XXX: We don't verify the numbers.
     1215 *****************************************************************************/
     1216int test20( void )
     1217{
     1218    bool testStatus = true;
     1219    psImage *imgData = psImageAlloc(TST20_NUM_COLS, TST20_NUM_ROWS, PS_TYPE_F32);
     1220    for (psS32 i = 0 ; i < imgData->numRows; i++) {
     1221        for (psS32 j = 0 ; j < imgData->numCols; j++) {
     1222            imgData->data.F32[i][j] = TST20_SKY;
     1223        }
     1224    }
     1225    pmSource *tmpSource = NULL;
     1226    psBool rc = false;
     1227
     1228    pmPeak *tmpPeak = pmPeakAlloc((psF32) (TST20_NUM_ROWS / 2),
     1229                                  (psF32) (TST20_NUM_COLS / 2),
     1230                                  200.0,
     1231                                  PM_PEAK_LONE);
     1232
     1233    printf("Calling pmSourceLocalSky with valid data.\n");
     1234    tmpPeak->x = (psF32) (TST20_NUM_ROWS / 2);
     1235    tmpPeak->y = (psF32) (TST20_NUM_COLS / 2);
     1236    tmpSource = pmSourceLocalSky(imgData,
     1237                                 tmpPeak,
     1238                                 PS_STAT_SAMPLE_MEAN,
     1239                                 (psF32) TST20_INNER_RADIUS,
     1240                                 (psF32) TST20_OUTER_RADIUS);
     1241
     1242    if (tmpSource == NULL) {
     1243        printf("TEST ERROR: pmSourceLocalSky() returned a NULL pmSource.\n");
     1244        testStatus = false;
     1245    }
     1246
     1247    tmpSource->modelPSF = pmModelAlloc(PS_MODEL_GAUSS);
     1248
     1249
     1250    tmpSource->modelPSF->params->data.F32[0] = 5.0;
     1251    tmpSource->modelPSF->params->data.F32[1] = 70.0;
     1252    tmpSource->modelPSF->params->data.F32[2] = (psF32) (TST20_NUM_ROWS / 2);
     1253    tmpSource->modelPSF->params->data.F32[3] = (psF32) (TST20_NUM_COLS / 2);
     1254    tmpSource->modelPSF->params->data.F32[4] = 1.0;
     1255    tmpSource->modelPSF->params->data.F32[5] = 1.0;
     1256    tmpSource->modelPSF->params->data.F32[6] = 2.0;
     1257
     1258    printf("----------------------------------------------------------------------------------\n");
     1259    printf("Calling pmSourceFitModel with NULL psImage.  Should generate error, return FALSE.\n");
     1260    rc = pmSourceFitModel(tmpSource, NULL);
     1261    if (rc == true) {
     1262        printf("TEST ERROR: pmSourceFitModel() returned TRUE.\n");
     1263        testStatus = false;
     1264    }
     1265
     1266    printf("----------------------------------------------------------------------------------\n");
     1267    printf("Calling pmSourceFitModel with NULL pmSource.  Should generate error, return FALSE.\n");
     1268    rc = pmSourceFitModel(NULL, imgData);
     1269    if (rc == true) {
     1270        printf("TEST ERROR: pmSourceFitModel() returned TRUE.\n");
     1271        testStatus = false;
     1272    }
     1273
     1274    printf("----------------------------------------------------------------------------------\n");
     1275    printf("Calling pmSourceFitModel with acceptable data.\n");
     1276    rc = pmSourceFitModel(tmpSource, imgData);
     1277    printf("pmSourceFitModel returned %d\n", rc);
     1278
     1279    // XXX: Memory leaks are not being tested
     1280    psVector *junk = psVectorAlloc(10, PS_TYPE_F32);
     1281    junk->data.F32[0] = 0.0;
     1282
     1283    psFree(tmpSource);
     1284    psFree(imgData);
     1285    return(testStatus);
     1286}
     1287
     1288
    9771289// this code will
    9781290
Note: See TracChangeset for help on using the changeset viewer.