IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

Improved test coverage.

File:
1 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");
Note: See TracChangeset for help on using the changeset viewer.