IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13614


Ignore:
Timestamp:
Jun 4, 2007, 10:25:32 AM (19 years ago)
Author:
gusciora
Message:

Improved test coverage.

Location:
trunk/psLib/test
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/astro/tap_psTime_01.c

    r12607 r13614  
    2323 *  @author  Eric Van Alst, MHPCC
    2424 *
    25  *  @version $Revision: 1.5 $  $Name: not supported by cvs2svn $
    26  *  @date  $Date: 2007-03-27 22:52:02 $
     25 *  @version $Revision: 1.6 $  $Name: not supported by cvs2svn $
     26 *  @date  $Date: 2007-06-04 20:25:32 $
    2727 *
    2828 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    131131    psLogSetFormat("HLNM");
    132132    psLogSetLevel(PS_LOG_INFO);
    133     plan_tests(178);
     133    plan_tests(198);
    134134    // Initialize library internal structures
    135135    psLibInit("pslib.config");
    136136
    137137
    138     // Test psTimeAlloc()
     138    // Allocate new psTime with unallowed time type
     139    // Following should generate error message
     140    {
     141        psMemId id = psMemGetId();
     142        psTime *time = psTimeAlloc(-100);
     143        ok(time == NULL, "psTimeAlloc(-100) returned NULL");
     144        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     145    }
     146
     147
     148    // Test psTimeAlloc(TAI)
    139149    {
    140150        psMemId id = psMemGetId();
     
    151161    }
    152162
    153     // Allocate new psTime with invalid time type
    154     // Following should generate error message
    155     {
    156         psMemId id = psMemGetId();
    157         psTime *time = psTimeAlloc(-100);
    158         ok(time == NULL, "psTimeAlloc(-100) returned NULL");
    159         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    160     }
     163
     164    // Test psTimeAlloc(UTC)
     165    {
     166        psMemId id = psMemGetId();
     167        psTime *time = psTimeAlloc(PS_TIME_UTC);
     168        ok(time != NULL, "psTimeAlloc() did not return NULL");
     169        skip_start(time == NULL, 4, "Skipping tests because psTimeAlloc() failed");
     170        ok(time->type == PS_TIME_UTC, "psTimeAlloc() correctly set psTime->type");
     171        ok(time->sec == 0, "psTimeAlloc() correctly set psTime->sec");
     172        ok(time->nsec == 0, "psTimeAlloc() correctly set psTime->nsec");
     173        ok(time->leapsecond == false, "psTimeAlloc() correctly set psTime->leapsecond");
     174        psFree(time);
     175        skip_end();
     176        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     177    }
     178
     179
     180    // Test psTimeAlloc(UT1)
     181    {
     182        psMemId id = psMemGetId();
     183        psTime *time = psTimeAlloc(PS_TIME_UT1);
     184        ok(time != NULL, "psTimeAlloc() did not return NULL");
     185        skip_start(time == NULL, 4, "Skipping tests because psTimeAlloc() failed");
     186        ok(time->type == PS_TIME_UT1, "psTimeAlloc() correctly set psTime->type");
     187        ok(time->sec == 0, "psTimeAlloc() correctly set psTime->sec");
     188        ok(time->nsec == 0, "psTimeAlloc() correctly set psTime->nsec");
     189        ok(time->leapsecond == false, "psTimeAlloc() correctly set psTime->leapsecond");
     190        psFree(time);
     191        skip_end();
     192        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     193    }
     194
     195
     196    // Test psTimeAlloc(TT)
     197    {
     198        psMemId id = psMemGetId();
     199        psTime *time = psTimeAlloc(PS_TIME_TT);
     200        ok(time != NULL, "psTimeAlloc() did not return NULL");
     201        skip_start(time == NULL, 4, "Skipping tests because psTimeAlloc() failed");
     202        ok(time->type == PS_TIME_TT, "psTimeAlloc() correctly set psTime->type");
     203        ok(time->sec == 0, "psTimeAlloc() correctly set psTime->sec");
     204        ok(time->nsec == 0, "psTimeAlloc() correctly set psTime->nsec");
     205        ok(time->leapsecond == false, "psTimeAlloc() correctly set psTime->leapsecond");
     206        psFree(time);
     207        skip_end();
     208        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     209    }
     210
    161211
    162212    // Test psTimeGetNow()
     213    // Attempt to get time with unallowed type
     214    // Following should generate an error message for unallowed time type
     215    {
     216        psMemId id = psMemGetId();
     217        psTime *timeNow = psTimeGetNow(-100);
     218        ok(timeNow == NULL, "psTimeGetNow(-100) returned NULL");
     219        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     220    }
     221
     222
     223    // Test psTimeGetNow(TAI)
    163224    {
    164225        psMemId id = psMemGetId();
     
    167228        skip_start(time == NULL, 4, "Skipping tests because psTimeGetNow() failed");
    168229        ok(timeNow->type == PS_TIME_TAI, "psTimeGetNow() correctly set psTime->type");
     230        ok(timeNow->sec != 0, "psTimeAlloc() set psTime->sec to something");
     231        ok(timeNow->nsec != 0, "psTimeAlloc() set psTime->nsec to something");
    169232        psFree(timeNow);
    170233        skip_end();
     
    172235    }
    173236
    174     // Attempt to get time with invalid type
    175     // Following should generate an error message for invalid time type
    176     {
    177         psMemId id = psMemGetId();
    178         psTime *timeNow = psTimeGetNow(-100);
    179         ok(timeNow == NULL, "psTimeGetNow(-100) returned NULL");
    180         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    181     }
    182237
    183238    // Test psTimeGetUT1Delta()
     
    191246    }
    192247
    193     // Attempt to convert invalid time
     248    // Attempt to convert unallowed time
    194249    // Following should generate an error message for incorrect time
    195250    {
     
    205260    }
    206261
    207     // Attempt to convert time with invalid bulletin
     262    // Attempt to convert time with unallowed bulletin
    208263    // Following should generate an error message for incorrect bulletin
    209264    {
     
    360415        time->nsec = testTime1NanosecondsUTC;
    361416        psF64 mjd = psTimeToMJD(time);
    362 
    363417        is_double_tol(mjd, 53207.765929, ERROR_TOL, "psTimeToMJD() returned correct time after 1/1/1970 epoch");
    364 
    365         psFree(time);
    366         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    367     }
     418        psFree(time);
     419        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     420    }
     421
    368422
    369423    // psTimeToMJD()
     
    375429        time->nsec = testTime4NanosecondsUTC;
    376430        psF64 mjd = psTimeToMJD(time);
    377 
    378431        is_double_tol(mjd, testTime4MJD, ERROR_TOL, "psTimeToMJD() returned correct time before 1/1/1970 epoch");
    379 
    380432        psFree(time);
    381433        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     
    390442        psMemId id = psMemGetId();
    391443        psF64 jd = psTimeToJD(NULL);
    392 
    393444        is_double(jd, NAN, "psTimeToJD(NULL) returned NULL");
    394445        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    395446    }
     447
    396448
    397449    // psTimeToJD()
     
    406458        time->leapsecond = false;
    407459        psF64 jd = psTimeToJD(time);
    408        
    409460        is_double(jd, NAN, "psTimeToJD() returned NAN for incorrect time");
    410 
    411461        psFree(time);
    412462        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     
    422472        time->nsec = testTime1NanosecondsUTC;
    423473        psF64 jd = psTimeToJD(time);
    424 
    425474        is_double_tol(jd, 2453208.265929, ERROR_TOL, "psTimeToJD() returned the correct time after 1/1/1970 epoch");
    426 
    427475        psFree(time);
    428476        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     
    438486        time->nsec = testTime4NanosecondsUTC;
    439487        psF64 jd = psTimeToJD(time);
    440 
    441488        is_double_tol(jd, testTime4JD, ERROR_TOL, "psTimeToJD() returned the correct time before 1/1/1970 epoch");
    442 
    443489        psFree(time);
    444490        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     
    453499        psMemId id = psMemGetId();
    454500        char *timeStr = psTimeToISO(NULL);
    455 
    456501        ok(timeStr == NULL, "psTimeToISO(NULL) returned NULL");
    457 
    458502        psFree(timeStr);
    459503        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    460504    }
     505
    461506
    462507    // Test psTimeToISO()
     
    471516        time->nsec = 2e9;
    472517        char *timeStr = psTimeToISO(time);
    473 
    474518        ok(timeStr == NULL, "psTimeToISO(time) returned NULL for incorrect time");
    475 
    476519        psFree(time);
    477520        psFree(timeStr);
     
    490533        time->nsec = testTime5NanosecondsUTC;
    491534        char *timeStr = psTimeToISO(time);
    492 
    493535        ok(timeStr == NULL, "psTimeToISO(time) returned NULL for time prior to year 0000");
    494 
    495536        psFree(time);
    496537        psFree(timeStr);
     
    527568        time->nsec = testTime1NanosecondsUTC;
    528569        char *timeStr = psTimeToISO(time);
    529 
    530570        is_str(timeStr, testTime1Str, "psTimeToISO(time) returned correct time (no leapsecond)");
    531 
    532571        psFree(timeStr);
    533572        psFree(time);
     
    546585        time->leapsecond = true;
    547586        char *timeStr = psTimeToISO(time);
    548 
    549587        is_str(timeStr, testTime1StrLeap, "psTimeToISO(time) returned correct time (with leapsecond)");
    550 
    551588        psFree(timeStr);
    552589        psFree(time);
     
    580617        time->nsec = 2e9;
    581618        struct timeval *timevalTime = psTimeToTimeval(time);
    582 
    583619        ok(timevalTime == NULL, "psTimeToTimeval() returned NULL for incorrect time");
    584 
    585620        psFree(time);
    586621        psFree(timevalTime);
     
    599634        time->nsec = 0;
    600635        struct timeval *timevalTime = psTimeToTimeval(time);
    601 
    602636        ok(timevalTime == NULL, "psTimeToTimeval() returned NULL for incorrect time");
    603 
    604637        psFree(time);
    605638        psFree(timevalTime);
     
    617650        time->nsec = testTime1NanosecondsUTC;
    618651        struct timeval *timevalTime = psTimeToTimeval(time);
    619 
    620652        is_long(timevalTime->tv_sec, testTime1TimevalSec, "psTimeToTimeval()->tv_sec");
    621653        is_long(timevalTime->tv_usec, testTime1TimevalUsec, "psTimeToTimeval()->tv_usec");
    622 
    623654        psFree(time);
    624655        psFree(timevalTime);
     
    632663        psMemId id = psMemGetId();
    633664        psTime *time = psTimeFromMJD(testTime1MJDTAI);
    634 
    635665        ok(time->type == PS_TIME_TAI, "psTimeFromMJD() returned the correct type");
    636666        is_long(time->sec, testTime1SecondsTAI, "psTimeFromMJD()->sec");
    637 
    638667        psFree(time);
    639668        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     
    646675        psMemId id = psMemGetId();
    647676        psTime *time = psTimeFromMJD(testTime4MJD);
    648 
    649677        ok(time->type == PS_TIME_TAI, "psTimeFromMJD() returned the correct type");
    650678        is_long(time->sec, testTime4SecondsUTC, "psTimeFromMJD()->sec");
    651 
    652679        psFree(time);
    653680        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     
    660687        psMemId id = psMemGetId();
    661688        psTime *time = psTimeFromJD(testTime1JDTAI);
    662 
    663689        ok(time->type == PS_TIME_TAI, "psTimeFromJD() returned the correct type");
    664690        is_long(time->sec, testTime1SecondsTAI, "psTimeFromJD()->sec");
    665 
    666691        psFree(time);
    667692        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     
    843868
    844869    // psTimeConvert()
    845     // Attempt to convert to incorrect type
    846     // Following should generate an error message for incorrect type
     870    // Following should generate an error message for incorrect type output
     871    // Input psTime struct is PS_TIME_TAI
    847872    // XXX: We don't test whether the error message is generated
    848873    {
     
    850875        psTime *time1 = psTimeAlloc(PS_TIME_TAI);
    851876        psTime *time2 = psTimeConvert(time1,-100);
    852 
    853877        ok(time2 == NULL, "psTimeConvert(time1, -100) returned NULL");
    854 
    855         psFree(time1);
     878        psFree(time1);
     879        psFree(time2);
     880        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     881    }
     882
     883
     884    // psTimeConvert()
     885    // Following should generate an error message for incorrect type output
     886    // Input psTime struct is PS_TIME_UTC
     887    // XXX: We don't test whether the error message is generated
     888    {
     889        psMemId id = psMemGetId();
     890        psTime *time1 = psTimeAlloc(PS_TIME_UTC);
     891        psTime *time2 = psTimeConvert(time1,-100);
     892        ok(time2 == NULL, "psTimeConvert(time1, -100) returned NULL");
     893        psFree(time1);
     894        psFree(time2);
    856895        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    857896    }
     
    860899    // psTimeConvert()
    861900    // Following should generate an error message for incorrect type
    862     // XXX: We don't test whether the error message is generated
    863     {
    864         psMemId id = psMemGetId();
    865         psTime *time1 = psTimeAlloc(PS_TIME_TAI);
    866         time1->type = PS_TIME_UTC;
     901    // Input psTime struct is PS_TIME_TT
     902    // XXX: We don't test whether the error message is generated
     903    {
     904        psMemId id = psMemGetId();
     905        psTime *time1 = psTimeAlloc(PS_TIME_TT);
    867906        psTime *time2 = psTimeConvert(time1,-100);
    868 
    869907        ok(time2 == NULL, "psTimeConvert(time1, -100) returned NULL");
    870 
    871         psFree(time1);
    872         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    873     }
    874 
    875 
    876     // psTimeConvert()
    877     // Following should generate an error message for incorrect type
    878     // XXX: We don't test whether the error message is generated
    879     {
    880         psMemId id = psMemGetId();
    881         psTime *time1 = psTimeAlloc(PS_TIME_TAI);
    882         time1->type = PS_TIME_TT;
    883         psTime *time2 = psTimeConvert(time1,-100);
    884 
    885         ok(time2 == NULL, "psTimeConvert(time1, -100) returned NULL");
    886 
    887         psFree(time1);
    888         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    889     }
    890 
    891 
    892     // psTimeConvert()
    893     // Following should generate an error message for incorrect type
     908        psFree(time1);
     909        psFree(time2);
     910        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     911    }
     912
     913
     914    // psTimeConvert()
     915    // Following should generate an error message for incorrect type input
    894916    // XXX: We don't test whether the error message is generated
    895917    {
     
    898920        time1->type = -100;
    899921        psTime *time2 = psTimeConvert(time1,PS_TIME_TAI);
    900 
    901922        ok(time2 == NULL, "psTimeConvert(time1, PS_TIME_TAI) returned NULL");
    902 
    903         psFree(time1);
     923        psFree(time1);
     924        psFree(time2);
    904925        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    905926    }
     
    915936        time1->nsec = 2e9;
    916937        psTime *time2 = psTimeConvert(time1, PS_TIME_TAI);
    917 
    918938        ok(time2 == NULL, "psTimeConvert(time1, PS_TIME_TAI) returns NULL for incorrect psTime object");
    919 
    920         psFree(time1);
     939        psFree(time1);
     940        psFree(time2);
    921941        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    922942    }
     
    932952        time1->type = PS_TIME_TAI;
    933953        time1->leapsecond = false;
    934 
    935954        psTime *time2 = psTimeConvert(time1, PS_TIME_TAI);
    936955        ok(time2 == time1, "psTimeConvert(time, ...) returns time for conversion to same type");
  • trunk/psLib/test/astro/tap_psTime_02.c

    r12607 r13614  
    1212 *  @author  Eric Van Alst, MHPCC
    1313 *
    14  *  @version $Revision: 1.4 $  $Name: not supported by cvs2svn $
    15  *  @date  $Date: 2007-03-27 22:52:02 $
     14 *  @version $Revision: 1.5 $  $Name: not supported by cvs2svn $
     15 *  @date  $Date: 2007-06-04 20:25:32 $
    1616 *
    1717 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    6464    {
    6565        psMemId id = psMemGetId();
    66 
    6766        psF64 lmst = psTimeToLMST(NULL, 0);
    68         is_double(lmst, NAN, "psTimeToLMST(time,0) returned NAN");
    69 
     67        is_double(lmst, NAN, "psTimeToLMST(NULL, 0) returned NAN");
    7068        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    7169    }
     
    8078        time->nsec = testTime1NanosecondsUTC;
    8179        time->leapsecond = false;
    82 
    8380        psF64 lmst = psTimeToLMST(time, 0.0);
    8481        is_double_tol(lmst, testTime1LMST0, ERROR_TOL, "psTimeToLMST() returned the correct time");
    85 
    8682        psFree(time);
    8783        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     
    9086
    9187    // psTimeToLMST()
    92     // Attempt to get LMST with invalid input time UT1
     88    // Attempt to get LMST with unallowed input time UT1
    9389    // Following should generate error message for incorrect type
    9490    // XXX: We do not test the error generation
     
    10096        time->leapsecond = false;
    10197        time->type = PS_TIME_UT1;
    102 
    10398        psF64 lmst = psTimeToLMST(time,0.0);
    10499        is_double(lmst, NAN, "psTimeToLMST() generated a NAN for incorrect type");
    105 
    106100        psFree(time);
    107101        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     
    115109    {
    116110        psMemId id = psMemGetId();
    117 
    118111        psS64 delta = psTimeLeapSecondDelta(NULL, NULL);
    119112        is_long(delta, 0, "psTimeLeapSecondDelta(NULL, NULL) returned 0");
    120 
    121         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    122     }
    123 
    124 
     113        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     114    }
     115
     116
     117    // psTimeLeapSecondDelta()
    125118    // Set test time 1
    126119    // Attempt to get delta with NULL time2 argument
     
    133126        time1->nsec = testTime1NanosecondsUTC;
    134127        time1->leapsecond = false;
    135 
    136128        psS64 delta = psTimeLeapSecondDelta(time1, NULL);
    137129        is_long(delta, 0, "psTimeLeapSecondDelta(time1, NULL) returned 0");
    138 
    139         psFree(time1);
    140         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    141     }
    142 
    143 
    144     // Set test time 2 with invalid time
    145     // Attempt to get delta with invalid time2
    146     // Following should generate an error message for invalid time
     130        psFree(time1);
     131        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     132    }
     133
     134
     135    // psTimeLeapSecondDelta()
     136    // Set test time 2 with unallowed time
     137    // Attempt to get delta with unallowed time2
     138    // Following should generate an error message for unallowed time
    147139    // XXX: We do not test the error generation
    148140    {
     
    156148        time2->nsec = 2e9;
    157149        time2->leapsecond = false;
    158 
    159150        psS64 delta = psTimeLeapSecondDelta(time1, time2);
    160151        is_long(delta, 0, "psTimeLeapSecondDelta(time1, time2) returned 0 with incorrect time2");
    161 
    162152        psFree(time1);
    163153        psFree(time2);
     
    166156
    167157
     158    // psTimeLeapSecondDelta()
    168159    // Set test time 2 valid
    169     // Attempt to get delta with invalid time1
    170     // Following should generate an error message for invalid time
     160    // Attempt to get delta with unallowed time1
     161    // Following should generate an error message for unallowed time
    171162    // XXX: We do not test the error generation
    172163    {
     
    181172        time1->sec = 0;
    182173        time1->nsec = 2e9;
    183 
    184174        psS64 delta = psTimeLeapSecondDelta(time1,time2);
    185175        is_long(delta, 0, "psTimeLeapSecondDelta(time1, time2) returned 0 with incorrect time1");
    186 
    187176        psFree(time1);
    188177        psFree(time2);
     
    191180
    192181
     182    // psTimeLeapSecondDelta()
    193183    // Set test time 1 to greater time
    194184    {
     
    202192        time2->sec = testTime2SecondsUTC;
    203193        time2->nsec = testTime2NanosecondsUTC;
    204 
    205194        psS64 delta = psTimeLeapSecondDelta(time1,time2);
    206195        is_long(delta, testTimeLeapSecondDelta1, "psTimeLeapSecondDelta() produced the correct result");
    207 
    208196        psFree(time1);
    209197        psFree(time2);
     
    212200
    213201
     202    // psTimeLeapSecondDelta()
    214203    // Set test time 1 to lesser time
    215204    {
     
    222211        time2->sec = testTime2SecondsUTC;
    223212        time2->nsec = testTime2NanosecondsUTC;
    224 
    225213        psS64 delta = psTimeLeapSecondDelta(time2, time1);
    226214        is_long(delta, testTimeLeapSecondDelta1, "psTimeLeapSecondDelta() produced the correct result");
    227 
    228215        psFree(time1);
    229216        psFree(time2);
     
    232219
    233220
     221    // psTimeLeapSecondDelta()
    234222    // Attempt to get delta with times equal
    235223    {
     
    239227        time1->nsec = testTime1NanosecondsUTC;
    240228        time1->leapsecond = false;
    241 
    242229        psS64 delta = psTimeLeapSecondDelta(time1,time1);
    243230        is_long(delta, 0, "psTimeLeapSecondDelta() produced the correct result");
    244 
    245231        psFree(time1);
    246232        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     
    254240    {
    255241        psMemId id = psMemGetId();
    256 
    257242        bool leapsecond = psTimeIsLeapSecond(NULL);
    258243        is_bool(leapsecond, false, "psTimeIsLeapSecond(NULL) returned correct value");
    259 
    260         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    261     }
    262 
    263 
    264     // psTimeIsLeapSecond()
    265     // Set time
     244        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     245    }
     246
     247
     248    // psTimeIsLeapSecond()
    266249    // Attempt to determine if leap second with non-UTC time
    267     // Following should generate an error message for invalid type
     250    // Following should generate an error message for unallowed type
    268251    // XXX: We do not test the error generation
    269252    {
     
    273256        time->nsec = testTime1NanosecondsUTC;
    274257        time->leapsecond = false;
    275 
    276258        bool leapsecond = psTimeIsLeapSecond(time);
    277259        is_bool(leapsecond, false, "psTimeIsLeapSecond() returned false with incorrect type");
    278 
    279260        psFree(time);
    280261        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     
    292273        time->leapsecond = false;
    293274        time->type = PS_TIME_UTC;
    294 
    295275        bool leapsecond = psTimeIsLeapSecond(time);
    296276        is_bool(leapsecond, false, "psTimeIsLeapSecond() returned false");
    297 
    298277        psFree(time);
    299278        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     
    309288        time->sec = testTime3SecondsUTC;
    310289        time->nsec = testTime3NanosecondsUTC;
    311 
    312290        bool leapsecond = psTimeIsLeapSecond(time);
    313291        is_bool(leapsecond, true, "psTimeIsLeapSecond() returned true");
    314 
    315292        psFree(time);
    316293        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     
    327304        time->nsec = testTime3NanosecondsUTC;
    328305        time->sec--;
    329 
    330306        bool leapsecond = psTimeIsLeapSecond(time);
    331307        is_bool(leapsecond, false, "psTimeIsLeapSecond() returned false");
    332 
    333308        psFree(time);
    334309        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     
    343318        time->sec = testTime3SecondsUTC;
    344319        time->nsec = testTime3NanosecondsUTC;
    345         time->sec ++;
    346 
     320        time->sec++;
    347321        bool leapsecond = psTimeIsLeapSecond(time);
    348322        is_bool(leapsecond, false, "psTimeIsLeapSecond() returned false");
    349 
    350323        psFree(time);
    351324        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     
    354327
    355328    // psTimeFromTT()
    356     // Attempt to create psTime with invalid time
    357     // Following should generate an error message for invalid time
     329    // Attempt to create psTime with unallowed time
     330    // Following should generate an error message for unallowed time
    358331    // XXX: We do not test the error generation
    359332    {
     
    389362
    390363    // psTimeFromUTC()
    391     // Attempt to create psTime with invalid time
    392     // Following should generate an error message for invalid time
     364    // Attempt to create psTime with unallowed time
     365    // Following should generate an error message for unallowed time
    393366    // XXX: We do not test the error generation
    394367    {
  • trunk/psLib/test/astro/tap_psTime_04.c

    r12415 r13614  
    1818 *  @author  David Robbins, MHPCC
    1919 *
    20  *  @version $Revision: 1.2 $  $Name: not supported by cvs2svn $
    21  *  @date  $Date: 2007-03-13 00:23:20 $
     20 *  @version $Revision: 1.3 $  $Name: not supported by cvs2svn $
     21 *  @date  $Date: 2007-06-04 20:25:32 $
    2222 *
    2323 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    3434    psLogSetFormat("HLNM");
    3535    psLogSetLevel(PS_LOG_INFO);
    36     plan_tests(16);
     36    plan_tests(19);
    3737
    3838
     
    114114    }
    115115
     116
    116117    // testTideUT1Corr()
     118    // Verify NULL return with NULL input
     119    // XXX: Verify error
    117120    {
    118121        psMemId id = psMemGetId();
    119         psTime *tide = NULL;
     122        psTime *empty = psTime_TideUT1Corr(NULL);
     123        ok(empty == NULL, "psTime_TideUT1Corr() returned NULL for NULL input time");
     124        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     125        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     126    }
     127
     128
     129    // testTideUT1Corr()
     130    //
     131    {
     132        psMemId id = psMemGetId();
    120133        psTime *noTide = psTimeAlloc(PS_TIME_UTC);
    121134        noTide->sec = 1049160600;
    122135        noTide->nsec = 0;
    123136        noTide->leapsecond = false;
    124         // Following should generate error message
    125         // XXX: We do not test error generation here
    126         psTime *empty = empty = psTime_TideUT1Corr(tide);
    127         ok(empty == NULL, "psTime_TideUT1Corr() returned NULL for NULL input time");
    128 
    129         empty = psTime_TideUT1Corr(noTide);
     137        psTime *empty = psTime_TideUT1Corr(noTide);
    130138        is_long(empty->sec, 1049160599, "psTime_TideUT1Corr() returned correct ->sec");
    131139        is_long(empty->nsec, 656981971, "psTime_TideUT1Corr() returned correct ->nsec");
    132 
    133140        ok(p_psTimeFinalize(), "p_psTimeFinalize() successful");
    134 
    135141        psFree(empty);
    136142        psFree(noTide);
    137143        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     144        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    138145    }
    139146}
  • trunk/psLib/test/imageops/tap_psImageGeomManip.c

    r13123 r13614  
    55 *  @author Robert DeSonia, MHPCC
    66 *
    7  *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2007-05-02 04:14:33 $
     7 *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2007-06-04 20:25:32 $
    99 *
    1010 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    1616#include "pstap.h"
    1717#define VERBOSE 0
     18
     19void genericImageRollTest(int numRows, int numCols)
     20{
     21    psMemId id = psMemGetId();
     22    psImage *in;
     23    psImage *out;
     24    psImage *out2;
     25
     26    // The function psImageRoll shall generate a new psImage structure by
     27    // rolling the input image the correponding number of pixels in the vertical
     28    // and/or horizontal direction. The image output image shall be the same size
     29    // as the input image. Values which roll off the image are wrapped to the
     30    // other side.
     31    //
     32    // Verify the returned psImage structure contains expected values, if the
     33    // input image contains known values and the roll performed is known.
     34    // Cases should include no roll, vertical roll, horizontal roll and
     35    // combination vertical/horizontal rolls. Positive and negative rolls
     36    // should be performed.
     37
     38    in = psImageAlloc(numCols,numRows,PS_TYPE_F32);
     39    for (psS32 row=0;row<numRows;row++) {
     40        for (psS32 col=0;col<numCols;col++) {
     41            in->data.F32[row][col] = (psF32)row+(psF32)col/1000.0f;
     42        }
     43    }
     44
     45    out = psImageRoll(NULL,in,0,0);
     46    bool errorFlag = false;
     47    for (psS32 row=0;row<numRows;row++) {
     48        psF32 *inRow = in->data.F32[row];
     49        psF32 *outRow = out->data.F32[row];
     50        for (psS32 col=0;col<numCols;col++) {
     51            if (inRow[col] != outRow[col]) {
     52                diag("psImageRoll didn't produce expected result "
     53                     "at %d,%d (%f vs %f) for dx=0, dy=0",
     54                     col,row,inRow[col],outRow[col]);
     55                errorFlag = true;
     56            }
     57        }
     58    }
     59    ok(!errorFlag, "psImageRoll() produced the correct data values (no roll)");
     60
     61    errorFlag = false;
     62    out2 = psImageRoll(out,in,numCols/4,0);
     63    for (psS32 row=0;row<numRows;row++)
     64    {
     65        psF32 *inRow = in->data.F32[row];
     66        psF32 *outRow = out->data.F32[row];
     67        for (psS32 col=0;col<numCols;col++) {
     68            if (inRow[(col+numCols/4) % numCols] != outRow[col]) {
     69                diag("psImageRoll didn't produce expected result "
     70                     "at %d,%d (%f vs %f) for dx=numCols/4, dy=0",
     71                     col,row,inRow[(col+numCols/4) % numCols],outRow[col]);
     72                errorFlag = true;
     73            }
     74        }
     75    }
     76    ok(!errorFlag, "psImageRoll() produced the correct data values (column roll only");
     77
     78    // Verify the returned psImage structure pointer is equal to the input
     79    // parameter out if provided.
     80    ok(out2 == out, "psImageRoll did recycle the out psImage");
     81
     82    errorFlag = false;
     83    out = psImageRoll(out,in,0,numRows/4);
     84    for (psS32 row=0;row<numRows;row++)
     85    {
     86        psF32 *inRow = in->data.F32[(row+numRows/4)%numRows];
     87        psF32 *outRow = out->data.F32[row];
     88        for (psS32 col=0;col<numCols;col++) {
     89            if (inRow[col] != outRow[col]) {
     90                diag("psImageRoll didn't produce expected result "
     91                     "at %d,%d (%f vs %f) for dx=0, dy=numRows/4",
     92                     col,row,inRow[col],outRow[col]);
     93                errorFlag = true;
     94            }
     95        }
     96    }
     97    ok(!errorFlag, "psImageRoll() produced the correct data values (row roll onlt)");
     98
     99    errorFlag = false;
     100    out = psImageRoll(out,in,numCols/4,numRows/4);
     101    for (psS32 row=0;row<numRows;row++)
     102    {
     103        psF32 *inRow = in->data.F32[(row+numRows/4)%numRows];
     104        psF32 *outRow = out->data.F32[row];
     105        for (psS32 col=0;col<numCols;col++) {
     106            if (inRow[(col+numCols/4) % numCols] != outRow[col]) {
     107                diag("psImageRoll didn't produce expected result "
     108                     "at %d,%d (%f vs %f) for dx=numCols/4, dy=numRows/4",
     109                     col,row,inRow[(col+numCols/4) % numCols],outRow[col]);
     110                errorFlag = true;
     111            }
     112        }
     113    }
     114    ok(!errorFlag, "psImageRoll() produced the correct data values (column and row roll)");
     115
     116    errorFlag = false;
     117    out = psImageRoll(out,in,-numCols/4,0);
     118    for (psS32 row=0;row<numRows;row++)
     119    {
     120        psF32 *inRow = in->data.F32[row];
     121        psF32 *outRow = out->data.F32[row];
     122        for (psS32 col=0;col<numCols;col++) {
     123            if (inRow[(col+(numCols-numCols/4)) % numCols] != outRow[col]) {
     124                diag("psImageRoll didn't produce expected result "
     125                     "at %d,%d (%f vs %f) for dx=-numCols/4, dy=0",
     126                     col,row,inRow[(col+(numCols-numCols/4)) % numCols],outRow[col]);
     127                errorFlag = true;
     128            }
     129        }
     130    }
     131    ok(!errorFlag, "psImageRoll() produced the correct data values (negative column roll)");
     132
     133    errorFlag = false;
     134    out = psImageRoll(out,in,0,-numRows/4);
     135    for (psS32 row=0;row<numRows;row++)
     136    {
     137        psF32 *inRow = in->data.F32[(row+numRows-numRows/4)%numRows];
     138        psF32 *outRow = out->data.F32[row];
     139        for (psS32 col=0;col<numCols;col++) {
     140            if (inRow[col] != outRow[col]) {
     141                diag("psImageRoll didn't produce expected result "
     142                     "at %d,%d (%f vs %f) for dx=0, dy=-numRows/4",
     143                     col,row,inRow[col],outRow[col]);
     144                errorFlag = true;
     145            }
     146        }
     147    }
     148    ok(!errorFlag, "psImageRoll() produced the correct data values (negative row roll)");
     149
     150    errorFlag = false;
     151    out = psImageRoll(out,in,-numCols/4,-numRows/4);
     152    for (psS32 row=0;row<numRows;row++)
     153    {
     154        psF32 *inRow = in->data.F32[(row+numRows-numRows/4)%numRows];
     155        psF32 *outRow = out->data.F32[row];
     156        for (psS32 col=0;col<numCols;col++) {
     157            if (inRow[(col+numCols-numCols/4) % numCols] != outRow[col]) {
     158                diag("psImageRoll didn't produce expected result "
     159                     "at %d,%d (%f vs %f) for dx=numCols/4, dy=numRows/4",
     160                     col,row,inRow[(col+numCols-numCols/4) % numCols],outRow[col]);
     161                errorFlag = true;
     162            }
     163        }
     164    }
     165    ok(!errorFlag, "psImageRoll() produced the correct data values (negative column and row roll)");
     166    psFree(in);
     167    psFree(out);
     168    ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     169}
     170
     171
    18172
    19173bool testImageShiftCase(psS32 cols,
     
    152306    psLogSetFormat("HLNM");
    153307    psLogSetLevel(PS_LOG_INFO);
    154     plan_tests(237);
     308    plan_tests(280);
    155309
    156310    // test psImageRebin()
     
    366520    if (1) {
    367521        psMemId id = psMemGetId();
     522        // Perform generic tests with various image sizes
     523        genericImageRollTest(8, 1);
     524        genericImageRollTest(1, 8);
     525        genericImageRollTest(8, 8);
     526        genericImageRollTest(8, 16);
     527        genericImageRollTest(16, 8);
     528
    368529        psImage *in;
    369530        psImage *out;
     
    373534        psS32 rows1 = 8;
    374535        psS32 cols1 = 8;
    375 
    376         // The function psImageRoll shall generate a new psImage structure by
    377         // rolling the input image the correponding number of pixels in the vertical
    378         // and/or horizontal direction. The image output image shall be the same size
    379         // as the input image. Values which roll off the image are wrapped to the
    380         // other side.
    381         //
    382         // Verify the returned psImage structure contains expected values, if the
    383         // input image contains known values and the roll performed is known.
    384         // Cases should include no roll, vertical roll, horizontal roll and
    385         // combination vertical/horizontal rolls. Positive and negative rolls
    386         // should be performed.
    387 
    388536        in = psImageAlloc(cols,rows,PS_TYPE_F32);
    389537        for (psS32 row=0;row<rows;row++) {
     
    393541        }
    394542
    395         out = psImageRoll(NULL,in,0,0);
    396543        bool errorFlag = false;
    397         for (psS32 row=0;row<rows;row++) {
    398             psF32 *inRow = in->data.F32[row];
    399             psF32 *outRow = out->data.F32[row];
    400             for (psS32 col=0;col<cols;col++) {
    401                 if (inRow[col] != outRow[col]) {
    402                     diag("psImageRoll didn't produce expected result "
    403                          "at %d,%d (%f vs %f) for dx=0, dy=0",
    404                          col,row,inRow[col],outRow[col]);
    405                     errorFlag = true;
    406                 }
    407             }
    408         }
    409         ok(!errorFlag, "psImageRoll() produced the correct data values");
    410 
    411         errorFlag = false;
    412         out2 = psImageRoll(out,in,cols/4,0);
    413         for (psS32 row=0;row<rows;row++)
    414         {
    415             psF32 *inRow = in->data.F32[row];
    416             psF32 *outRow = out->data.F32[row];
    417             for (psS32 col=0;col<cols;col++) {
    418                 if (inRow[(col+cols/4) % cols] != outRow[col]) {
    419                     diag("psImageRoll didn't produce expected result "
    420                          "at %d,%d (%f vs %f) for dx=cols/4, dy=0",
    421                          col,row,inRow[(col+cols/4) % cols],outRow[col]);
    422                     errorFlag = true;
    423                 }
    424             }
    425         }
    426         ok(!errorFlag, "psImageRoll() produced the correct data values");
    427 
    428         // Verify the returned psImage structure pointer is equal to the input
    429         // parameter out if provided.
    430         ok(out2 == out, "psImageRoll didt recycle the out psImage");
    431 
    432         errorFlag = false;
    433         out = psImageRoll(out,in,0,rows/4);
    434         for (psS32 row=0;row<rows;row++)
    435         {
    436             psF32 *inRow = in->data.F32[(row+rows/4)%rows];
    437             psF32 *outRow = out->data.F32[row];
    438             for (psS32 col=0;col<cols;col++) {
    439                 if (inRow[col] != outRow[col]) {
    440                     diag("psImageRoll didn't produce expected result "
    441                          "at %d,%d (%f vs %f) for dx=0, dy=rows/4",
    442                          col,row,inRow[col],outRow[col]);
    443                     errorFlag = true;
    444                 }
    445             }
    446         }
    447         ok(!errorFlag, "psImageRoll() produced the correct data values");
    448 
    449         errorFlag = false;
    450         out = psImageRoll(out,in,cols/4,rows/4);
    451         for (psS32 row=0;row<rows;row++)
    452         {
    453             psF32 *inRow = in->data.F32[(row+rows/4)%rows];
    454             psF32 *outRow = out->data.F32[row];
    455             for (psS32 col=0;col<cols;col++) {
    456                 if (inRow[(col+cols/4) % cols] != outRow[col]) {
    457                     diag("psImageRoll didn't produce expected result "
    458                          "at %d,%d (%f vs %f) for dx=cols/4, dy=rows/4",
    459                          col,row,inRow[(col+cols/4) % cols],outRow[col]);
    460                     errorFlag = true;
    461                 }
    462             }
    463         }
    464         ok(!errorFlag, "psImageRoll() produced the correct data values");
    465 
    466         errorFlag = false;
    467         out = psImageRoll(out,in,-cols/4,0);
    468         for (psS32 row=0;row<rows;row++)
    469         {
    470             psF32 *inRow = in->data.F32[row];
    471             psF32 *outRow = out->data.F32[row];
    472             for (psS32 col=0;col<cols;col++) {
    473                 if (inRow[(col+(cols-cols/4)) % cols] != outRow[col]) {
    474                     diag("psImageRoll didn't produce expected result "
    475                          "at %d,%d (%f vs %f) for dx=-cols/4, dy=0",
    476                          col,row,inRow[(col+(cols-cols/4)) % cols],outRow[col]);
    477                     errorFlag = true;
    478                 }
    479             }
    480         }
    481         ok(!errorFlag, "psImageRoll() produced the correct data values");
    482 
    483         errorFlag = false;
    484         out = psImageRoll(out,in,0,-rows/4);
    485         for (psS32 row=0;row<rows;row++)
    486         {
    487             psF32 *inRow = in->data.F32[(row+rows-rows/4)%rows];
    488             psF32 *outRow = out->data.F32[row];
    489             for (psS32 col=0;col<cols;col++) {
    490                 if (inRow[col] != outRow[col]) {
    491                     diag("psImageRoll didn't produce expected result "
    492                          "at %d,%d (%f vs %f) for dx=0, dy=-rows/4",
    493                          col,row,inRow[col],outRow[col]);
    494                     errorFlag = true;
    495                 }
    496             }
    497         }
    498         ok(!errorFlag, "psImageRoll() produced the correct data values");
    499 
    500         errorFlag = false;
    501         out = psImageRoll(out,in,-cols/4,-rows/4);
    502         for (psS32 row=0;row<rows;row++)
    503         {
    504             psF32 *inRow = in->data.F32[(row+rows-rows/4)%rows];
    505             psF32 *outRow = out->data.F32[row];
    506             for (psS32 col=0;col<cols;col++) {
    507                 if (inRow[(col+cols-cols/4) % cols] != outRow[col]) {
    508                     diag("psImageRoll didn't produce expected result "
    509                          "at %d,%d (%f vs %f) for dx=cols/4, dy=rows/4",
    510                          col,row,inRow[(col+cols-cols/4) % cols],outRow[col]);
    511                     errorFlag = true;
    512                 }
    513             }
    514         }
    515         ok(!errorFlag, "psImageRoll() produced the correct data values");
    516 
    517 
    518544        // Verify the returned psImage structure pointer is NULL and program
    519545        // execution doesn't stop, if input parameter input is NULL.
  • trunk/psLib/test/imageops/tap_psImagePixelExtract.c

    r13127 r13614  
    66*  @author Robert DeSonia, MHPCC
    77*
    8 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    9 *  @date $Date: 2007-05-02 04:34:13 $
     8*  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     9*  @date $Date: 2007-06-04 20:25:32 $
    1010*
    1111*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    1717#include "pstap.h"
    1818
     19void genericImageRowColTests(int numRows, int numCols)
     20{
     21    psMemId id = psMemGetId();
     22    psImage *image = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     23    for (int i = 0 ; i < numRows; i++) {
     24        for (int j = 0 ; j < numCols; j++) {
     25            image->data.F32[0][0] = (float) i+j;
     26        }
     27    }           
     28
     29    bool errorFlag = false;
     30    for (int i = 0 ; i < numRows; i++) {
     31        psVector *out = psImageRow(NULL, image, i);
     32        ok(out != NULL, "psImageRow returned non-NULL");
     33        if (out != NULL) {
     34            for (int j = 0 ; j < numCols; j++) {
     35                if (out->data.F32[j] != image->data.F32[i][j]) {
     36                    diag("TEST ERROR: image->data.F32[%d][%d] is %f, should be %f", i, j,
     37                         image->data.F32[i][j], out->data.F32[j]);
     38                    errorFlag = true;
     39                }
     40            }
     41            psFree(out);
     42        } else {
     43            errorFlag = true;
     44        }
     45    }
     46    ok(!errorFlag, "psImageRow() passed tests with correct data inputs");
     47    psFree(image);
     48    ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     49}
     50
     51
     52
    1953psS32 main(psS32 argc, char* argv[])
    2054{
    2155    psLogSetFormat("HLNM");
    2256    psLogSetLevel(PS_LOG_INFO);
    23     plan_tests(248);
     57    plan_tests(295);
    2458
    2559    // test psImageSlice()
     
    807841        ok(out == NULL, "psImageCol() returned NULL");
    808842
    809    
    810         //Test valid cases.
    811         //XXX: We do not verify the data values.
    812         P_PSIMAGE_SET_COL0(image, 10);
    813         P_PSIMAGE_SET_ROW0(image, 5);
    814         *(int*)&(image->numRows) = 3;
    815         *(int*)&(image->numCols) = 3;
     843        // Test on correct input data for several sizes   
     844        genericImageRowColTests(1, 8);
     845        genericImageRowColTests(8, 1);
     846        genericImageRowColTests(8, 8);
     847        genericImageRowColTests(8, 16);
     848        genericImageRowColTests(16, 8);
     849        psFree(image);
     850        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");   
     851    }
     852
     853    // testImageRowColF64()
     854    {
     855        psMemId id = psMemGetId();
     856        psVector *rowcol = NULL;
     857        psVector *empty = NULL;
     858        psImage *image = NULL;
     859   
     860        image = psImageAlloc(3, 3, PS_TYPE_F64);
     861        rowcol = psVectorAlloc(3, PS_TYPE_F64);
     862
    816863        image->data.F64[0][0] = 666.666;
    817864        image->data.F64[1][0] = 66.6;
     
    823870        image->data.F64[1][2] = 666.66;
    824871        image->data.F64[2][2] = 66.66;
    825         num = 7;
    826         out = psImageRow(out, image, num);
    827 
    828 
    829         ok(out != NULL, "psImageRow returned non-NULL");
    830         psFree(out);
    831         out = NULL;
    832         num = 11;
    833         out = psImageCol(NULL, image, num);
    834         ok(out != NULL, "psImageCol returned non-NULL");
    835         psFree(out);
    836         out = NULL;
    837 
    838    
    839         num = -3;
    840         out = psImageRow(out, image, num);
    841         ok(out != NULL, "psImageRow returned non-NULL");
    842         psFree(out);
    843         out = NULL;
    844 
    845 
    846         num = -1;
    847         out = psImageCol(NULL, image, num);
    848         ok(out != NULL, "psImageCol returned non-NULL");
    849         psFree(out);
    850         psFree(image);
    851         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    852     }
    853 
    854    
    855 
    856 
    857 
    858 
    859 
    860 
    861 
    862 
    863 
    864 
    865 
    866 
    867 
    868 
    869     // testImageRowColF64()
    870     {
    871         psMemId id = psMemGetId();
    872         psVector *rowcol = NULL;
    873         psVector *empty = NULL;
    874         psImage *image = NULL;
    875    
    876         image = psImageAlloc(3, 3, PS_TYPE_F64);
    877         rowcol = psVectorAlloc(3, PS_TYPE_F64);
    878 
    879         image->data.F64[0][0] = 666.666;
    880         image->data.F64[1][0] = 66.6;
    881         image->data.F64[2][0] = 6.66;
    882         image->data.F64[0][1] = 6.6;
    883         image->data.F64[1][1] = 6.666;
    884         image->data.F64[2][1] = 66.666;
    885         image->data.F64[0][2] = 666.6;
    886         image->data.F64[1][2] = 666.66;
    887         image->data.F64[2][2] = 66.66;
    888872   
    889873        //Test for error with NULL image
  • trunk/psLib/test/imageops/tap_psImagePixelManip.c

    r13123 r13614  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2007-05-02 04:14:33 $
     8 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2007-06-04 20:25:32 $
    1010 *
    1111 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    1818#define VERBOSE false
    1919
     20void genericImageClipTest(int numRows, int numCols) {
     21    psMemId id = psMemGetId();
     22
     23    psImage *image = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     24    for (int row = 0 ; row < numRows ; row++) {
     25        for (int col = 0 ; col < numCols ; col++) {
     26            image->data.F32[row][col] = (float) (row + col);
     27        }
     28    }
     29    psF32 min = (psF64)numRows/2.0;
     30    psF32 max = (psF64)numRows;
     31
     32    psS32 retVal = psImageClip(image, min, (double)PS_MIN_F32, max, (double)PS_MAX_F32);
     33    int numClipped = 0;
     34    bool errorFlag = false;
     35    for (int row=0;row<numRows;row++) {
     36        for (int col=0;col<numCols;col++) {
     37            psF32 value = (psF32)(row+col);
     38            if (value < min) {
     39                numClipped++;
     40                value = PS_MIN_F32;
     41            } else if (value > max) {
     42                numClipped++;
     43                value = PS_MAX_F32;
     44            }
     45            if (fabsf(image->data.F32[row][col]-value) > FLT_EPSILON) {
     46                diag("Pixel value is not as expected (%g vs %g) at %u,%u",
     47                     (psF64)image->data.F32[row][col], (psF64)value, col, row);
     48                errorFlag = true;
     49            }
     50        }
     51    }
     52    ok(!errorFlag, "psImageClip() produced the correct data values");
     53    ok(retVal == numClipped, "Got the expected number of clips");
     54    psFree(image);
     55
     56    ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     57}
     58
     59
    2060psS32 main(psS32 argc, char* argv[])
    2161{
    2262    psLogSetFormat("HLNM");
    2363    psLogSetLevel(PS_LOG_INFO);
    24     plan_tests(107);
     64    plan_tests(122);
    2565
    2666    // test psImageClip()
     
    4989        // and program executions doesn't stop, if input parameter min is larger than max.
    5090        // create image
     91
     92        genericImageClipTest(8, 1);
     93        genericImageClipTest(1, 8);
     94        genericImageClipTest(8, 8);
     95        genericImageClipTest(8, 16);
     96        genericImageClipTest(16, 8);
     97
    5198        #define testImageClipByType(datatype) \
    5299        { \
  • trunk/psLib/test/imageops/tap_psImageStructManip.c

    r13123 r13614  
    55*  @author Robert DeSonia, MHPCC
    66*
    7 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    8 *  @date $Date: 2007-05-02 04:14:33 $
     7*  psLib functions tested:
     8*     psImageSubset()
     9*     psImageCopy()
     10*     psImageTrim()
     11*
     12*  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2007-06-04 20:25:32 $
    914*
    1015*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    1621#include "pstap.h"
    1722
    18 psS32 main( psS32 argc, char* argv[] )
     23
     24void genericImageSubsetTest(int numRows, int numCols)
    1925{
    20     psLogSetFormat("HLNM");
    21     psLogSetLevel(PS_LOG_INFO);
    22     plan_tests(185);
    23 
    24 
    2526    // psImageSubset shall create child image of a specified size from a
    2627    // parent psImage structure
     
    2930        psMemId id = psMemGetId();
    3031        psImage preSubsetStruct;
    31         psS32 c = 128;
    32         psS32 r = 256;
    33         psRegion region1 = psRegionSet(0, c/2, 0, r/2);
    34         psRegion region2 = psRegionSet(c/4, c/4+c/2, r/4, r/4+r/2);
    35 
    36         psImage* original = psImageAlloc(c,r,PS_TYPE_U32);
    37         for (psS32 row=0;row<r;row++) {
    38             for (psS32 col=0;col<c;col++) {
     32        psRegion region1 = psRegionSet(0, numCols/2, 0, numRows/2);
     33        psRegion region2 = psRegionSet(numCols/4, numCols/4+numCols/2, numRows/4, numRows/4+numRows/2);
     34
     35        psImage* original = psImageAlloc(numCols,numRows,PS_TYPE_U32);
     36        for (psS32 row=0;row<numRows;row++) {
     37            for (psS32 col=0;col<numCols;col++) {
    3938                original->data.F32[row][col] = row*1000+col;
    4039            }
    4140        }
    4241
    43         memcpy(&preSubsetStruct,original,sizeof(psImage));
    44         psImage* subset2 = psImageSubset(original,region2);
     42        memcpy(&preSubsetStruct, original, sizeof(psImage));
     43        psImage* subset2 = psImageSubset(original, region2);
    4544        ok(subset2, "psImageSubset() returned non-NULL (subset2)");
    4645        skip_start(subset2 == NULL, 25, "Skipping tests because psImageSubset() returned NULL");
    47         psImage* subset3 = psImageSubset(original,region1);
     46        psImage* subset3 = psImageSubset(original, region1);
    4847        ok(subset3, "psImageSubset() returned non-NULL (subset3)");
    4948        skip_start(subset3 == NULL, 24, "Skipping tests because psImageSubset() returned NULL");
     
    5150        // Verify the returned psImage structure members nrow and ncol are equal to
    5251        // the input parameter nrow and ncol respectively
    53         ok(subset2->numCols == c/2 && subset2->numRows == r/2,
     52        ok(subset2->numCols == numCols/2 && subset2->numRows == numRows/2,
    5453           "psImageSubset output size set properly");
    55         ok(subset3->numCols == c/2 && subset3->numRows == r/2,
     54        ok(subset3->numCols == numCols/2 && subset3->numRows == numRows/2,
    5655           "psImageSubset output size set properly");
    5756
    5857        // Verify the returned psImage structure contains expected values in the
    5958        // row member, if the input psImage structure image contains known values
    60 
    6159        bool errorFlag = false;
    62         for (psS32 row=0;row<r/2;row++) {
    63             for (psS32 col=0;col<c/2;col++) {
    64                 if (subset2->data.U32[row][col] != original->data.U32[row+r/4][col+c/4]) {
     60        for (psS32 row=0;row<numRows/2;row++) {
     61            for (psS32 col=0;col<numCols/2;col++) {
     62                if (subset2->data.U32[row][col] != original->data.U32[row+numRows/4][col+numCols/4]) {
    6563                    diag("psImageSubset output #1 was wrong at %dx%d (%d vs %d).",
    66                          row,col,subset2->data.U32[row][col], original->data.U32[row+r/4][col+c/4]);
     64                         row,col,subset2->data.U32[row][col], original->data.U32[row+numRows/4][col+numCols/4]);
    6765                    errorFlag = true;
    6866                }
     
    8381        // Verify the returned psImage structure members row0 and col0 are equal to
    8482        // the input parameters row0 and col0 respectively
    85         ok(subset2->col0 == c/4 && subset2->row0 == r/4,
     83        ok(subset2->col0 == numCols/4 && subset2->row0 == numRows/4,
    8684           "psImageSubset() set col0/row0 correctly (subset2)");
    8785        ok(subset3->col0 == 0 && subset3->row0 == 0,
     
    10199        ok(original->children->data[0] == subset2 && original->children->data[1] == subset3,
    102100           "psImageSubset did properly store the children pointers.");
    103 
    104101
    105102        // Verify the returned psImage structure pointer is null and program
     
    111108        ok(subset1 == NULL, "psImageSubset returned NULL when input image was NULL.");
    112109
    113 
    114110        // Verify the returned psImage structure pointer is null and program
    115111        // execution doesn't stop, if the input parameters nrow and/or ncol are zero.
     
    117113        // An error should follow...
    118114        // XXX: Verify error
    119         memcpy(&preSubsetStruct,original,sizeof(psImage));
    120         subset1 = psImageSubset(original, psRegionSet(0,c/2,r/2,r/2));
    121         ok(subset1 == NULL, "psImageSubset returned NULL when numRows=0.");
    122         // An error should follow...
    123         // XXX: Verify error
    124         subset1 = psImageSubset(original,psRegionSet(c/2,c/2,0,r/2));
    125         ok(subset1 == NULL, "psImageSubset returned NULL when numCols=0.");
    126         ok(memcmp(original,&preSubsetStruct,sizeof(psImage)) == 0,
    127            "psImageSubset didn't change the original struct though it failed to subset.");
     115        {
     116            memcpy(&preSubsetStruct,original,sizeof(psImage));
     117            subset1 = psImageSubset(original, psRegionSet(0,numCols/2,numRows/2,numRows/2));
     118            ok(subset1 == NULL, "psImageSubset returned NULL when numRows=0.");
     119            // An error should follow...
     120            // XXX: Verify error
     121            subset1 = psImageSubset(original,psRegionSet(numCols/2,numCols/2,0,numRows/2));
     122            ok(subset1 == NULL, "psImageSubset returned NULL when numCols=0.");
     123            ok(memcmp(original,&preSubsetStruct,sizeof(psImage)) == 0,
     124               "psImageSubset didn't change the original struct though it failed to subset.");
     125        }
    128126
    129127        // Verify the returned psImage structure pointer is null and program
     
    132130        // An error should follow...
    133131        // XXX: Verify error
    134         subset1 = psImageSubset(original, psRegionSet(0,c/2, 0,r*2));
    135         ok(subset1 == NULL,
    136            "psImageSubset returned NULL when subset origin was outside of image (via cols)");
    137         // An error should follow...
    138         // XXX: Verify error
    139         subset1 = psImageSubset(original,psRegionSet(0,c*2,0,r/2));
    140         ok(subset1 == NULL,
    141            "psImageSubset returned NULL when subset origin was outside of image (via rows)");
    142         // An error should follow...
    143         // XXX: Verify error
    144         subset1 = psImageSubset(original, psRegionSet(-1,c/2,0,r/2));
    145         ok(subset1 == NULL,
    146            "psImageSubset returned NULL when subset origin was outside of image (col0=-1)");
    147         // An error should follow...
    148         // XXX: Verify error
    149         subset1 = psImageSubset(original, psRegionSet(0,c/2,-1,r/2));
    150         ok(subset1 == NULL,
    151            "psImageSubset returned NULL when subset origin was outside of image (row0=-1)");
    152 
     132        {
     133            subset1 = psImageSubset(original, psRegionSet(0,numCols/2, 0,numRows*2));
     134            ok(subset1 == NULL,
     135               "psImageSubset returned NULL when subset origin was outside of image (via cols)");
     136            // An error should follow...
     137            // XXX: Verify error
     138            subset1 = psImageSubset(original,psRegionSet(0,numCols*2,0,numRows/2));
     139            ok(subset1 == NULL,
     140               "psImageSubset returned NULL when subset origin was outside of image (via rows)");
     141            // An error should follow...
     142            // XXX: Verify error
     143            subset1 = psImageSubset(original, psRegionSet(-1,numCols/2,0,numRows/2));
     144            ok(subset1 == NULL,
     145               "psImageSubset returned NULL when subset origin was outside of image (col0=-1)");
     146            // An error should follow...
     147            // XXX: Verify error
     148            subset1 = psImageSubset(original, psRegionSet(0,numCols/2,-1,numRows/2));
     149            ok(subset1 == NULL,
     150               "psImageSubset returned NULL when subset origin was outside of image (row0=-1)");
     151        }   
    153152
    154153        // Verify the returned psImage structure pointer is null and program
     
    158157        // An error should follow...
    159158        // XXX: Verify error
    160         subset1 = psImageSubset(original,psRegionSet(0,c/2,0,r+1));
    161         ok(subset1 == NULL,
    162            "psImageSubset returned NULL when subset was outside of image (via rows)");
    163         // An error should follow...
    164         // XXX: Verify error
    165         subset1 = psImageSubset(original, psRegionSet(0,c+1,0,r/2));
    166         ok(subset1 == NULL,
    167            "psImageSubset returned NULL when subset was outside of image (via cols)");
    168         // An error should follow...
    169         // XXX: Verify error
    170         subset1 = psImageSubset(original,psRegionSet(0,c+1,0,r+1));
    171         ok(subset1 == NULL,
    172            "psImageSubset returned NULL when subset was outside of image (via row+cols)");
    173 
     159        {
     160            subset1 = psImageSubset(original,psRegionSet(0,numCols/2,0,numRows+1));
     161            ok(subset1 == NULL,
     162               "psImageSubset returned NULL when subset was outside of image (via rows)");
     163            // An error should follow...
     164            // XXX: Verify error
     165            subset1 = psImageSubset(original, psRegionSet(0,numCols+1,0,numRows/2));
     166            ok(subset1 == NULL,
     167               "psImageSubset returned NULL when subset was outside of image (via cols)");
     168            // An error should follow...
     169            // XXX: Verify error
     170            subset1 = psImageSubset(original,psRegionSet(0,numCols+1,0,numRows+1));
     171            ok(subset1 == NULL,
     172               "psImageSubset returned NULL when subset was outside of image (via row+cols)");
     173        }
    174174
    175175        // psImageFreeChildren shall deallocate any children images of a
     
    196196        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    197197    }
     198}
     199
     200psS32 main(psS32 argc, char* argv[])
     201{
     202    psLogSetFormat("HLNM");
     203    psLogSetLevel(PS_LOG_INFO);
     204    plan_tests(239);
     205
     206    genericImageSubsetTest(128, 256);
     207    genericImageSubsetTest(256, 128);
     208    genericImageSubsetTest(128, 128);
    198209
    199210    // psImageCopy()
Note: See TracChangeset for help on using the changeset viewer.