Changeset 4059
- Timestamp:
- May 31, 2005, 12:02:28 PM (21 years ago)
- Location:
- trunk/psLib/test/astronomy
- Files:
-
- 1 added
- 8 edited
-
tst_psTime_01.c (modified) (2 diffs)
-
tst_psTime_03.c (modified) (3 diffs)
-
tst_psTime_04.c (modified) (2 diffs)
-
verified/tst_psTime_01.stderr (added)
-
verified/tst_psTime_01.stdout (modified) (1 diff)
-
verified/tst_psTime_03.stderr (modified) (1 diff)
-
verified/tst_psTime_03.stdout (modified) (1 diff)
-
verified/tst_psTime_04.stderr (modified) (1 diff)
-
verified/tst_psTime_04.stdout (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/astronomy/tst_psTime_01.c
r3712 r4059 4 4 * 5 5 * This test driver contains the following tests for psTime: 6 * A) Get current TAI time7 * B) Print test time8 * C) Convert psTime to ISO time9 * D) Convert ISO time to psTime10 * E) Convert psTime to UTC time11 * F) Convert UTC time to psTime12 * G) Convert psTime to MJD time13 * H) Convert MJD time to psTime14 * I) Convert psTime to JD time15 * J) Convert JD time to psTime16 * K) Convert psTime to timeval time17 * L) Convert timeval time to psTime18 * M) Convert psTime to tm time19 * N) Convert tm time to psTime6 * 1) Allocate psTime structure 7 * 2) Get current time 8 * 3) Get UT1 UTC delta 9 * 4) Convert psTime to MJD 10 * 5) Convert psTime to JD 11 * 6) Convert psTime to ISO 12 * 7) Convert psTime to timeval 13 * 8) Create psTime from MJD 14 * 9) Create psTime from JD 15 * 10) Create psTime from ISO 16 * 11) Create psTime from timeval 17 * 12) Create psTime from TM 18 * 13) Convert time between different types 19 * 20 20 * O) Convert psTime time to LMST 21 * P) Free data22 21 * 23 22 * @author Ross Harman, MHPCC 23 * @author Eric Van Alst, MHPCC 24 24 * 25 * @version $Revision: 1.2 5$ $Name: not supported by cvs2svn $26 * @date $Date: 2005-0 4-19 02:13:53$25 * @version $Revision: 1.26 $ $Name: not supported by cvs2svn $ 26 * @date $Date: 2005-05-31 21:56:31 $ 27 27 * 28 28 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 30 30 */ 31 31 32 #include <string.h>33 32 #include "pslib_strict.h" 34 33 #include "psTest.h" 34 #include <string.h> 35 36 #define ERROR_TOL 0.0001 37 38 static psS32 testTimeAlloc(void); 39 static psS32 testTimeGetNow(void); 40 static psS32 testTimeGetUT1Delta(void); 41 static psS32 testTimeToMJD(void); 42 static psS32 testTimeToJD(void); 43 static psS32 testTimeToISO(void); 44 static psS32 testTimeToTimeval(void); 45 static psS32 testTimeFromMJD(void); 46 static psS32 testTimeFromJD(void); 47 static psS32 testTimeFromISO(void); 48 static psS32 testTimeFromTimeval(void); 49 static psS32 testTimeFromTM(void); 50 static psS32 testTimeConvert(void); 51 52 testDescription tests[] = { 53 {testTimeAlloc,000,"psTimeAlloc",0,false}, 54 {testTimeGetNow,000,"psTimeGetNow",0,false}, 55 {testTimeGetUT1Delta,000,"psTimeGetUT1Delta",0,false}, 56 {testTimeToMJD,000,"psTimeToMJD",0,false}, 57 {testTimeToJD,000,"psTimeToJD",0,false}, 58 {testTimeToISO,000,"psTimeToISO",0,false}, 59 {testTimeToTimeval,000,"psTimeToTimeval",0,false}, 60 {testTimeFromMJD,000,"psTimeFromMJD",0,false}, 61 {testTimeFromJD,000,"psTimeFromJD",0,false}, 62 {testTimeFromISO,000,"psTimeFromISO",0,false}, 63 {testTimeFromTimeval,000,"psTimeFromTimeval",0,false}, 64 {testTimeFromTM,000,"p_psTimeFromTM",0,false}, 65 {testTimeConvert,000,"psTimeConvert",0,false}, 66 {NULL} 67 }; 68 69 // Test Time 1 : July 21, 2004 18:22:24.3 70 // MJD = 53207.765559 71 // JD = 2453208.265559 72 // UTC Test Time 1 73 const psS64 testTime1SecondsUTC = 1090434144; 74 const psU32 testTime1NanosecondsUTC = 272044000; 75 // TAI Test Time 1 76 const psS64 testTime1SecondsTAI = 1090434176; 77 const psU32 testTime1NanosecondsTAI = 272044000; 78 const psF64 testTime1MJDTAI = 53207.76592937; 79 const psF64 testTime1JDTAI = 2453208.26592937; 80 81 // TT Test Time 1 82 const psS64 testTime1SecondsTT = 1090434208; 83 const psU32 testTime1NanosecondsTT = 456044000; 84 // Expected UT1-UTC IERS A & B 85 const psF64 testTime1UT1DeltaBullA = -0.457233186; 86 const psF64 testTime1UT1DeltaBullB = -0.457227; 87 // UT1 Test Time 1 88 const psS64 testTime1SecondsUT1 = 1090434143; 89 const psU32 testTime1NanosecondsUT1 = 814810814; 90 // Expected MJD & JD 91 const psF64 testTime1MJD = 53207.765559; 92 const psF64 testTime1JD = 2453208.265559; 93 // Expected ISO string 94 const char* testTime1Str = "2004-07-21T18:22:24,2Z"; 95 const char* testTime1StrLeap = "2004-07-21T18:22:60,2Z"; 96 // Expected timeval values 97 const psS32 testTime1TimevalSec = 1090434144; 98 const psS32 testTime1TimevalUsec = 272044; 99 100 // Test Time 2 : Jan. 1, 1973 00:00:00.0000 101 // MJD = 41683.0000 102 // JD = 2441683.5000 103 const psS64 testTime2SecondsUTC = 94694400; 104 const psU32 testTime2NanosecondsUTC = 0; 105 106 // Expected UT1-UTC IERS A & B 107 const psF64 testTime2UT1DeltaBullA = 0.000000; 108 const psF64 testTime2UT1DeltaBullB = 0.000000; 109 110 // Test Time 3 : Sept. 21, 2006 00:00:00.0000 111 // MJD = 53999 112 // JD = 2453999.5 113 const psS64 testTime3SecondsUTC = 1158796800; 114 const psU32 testTime3NanosecondsUTC = 0; 115 // Expected UT1-UTC IERS A & B 116 const psF64 testTime3UT1DeltaBullA = -0.63574; 117 const psF64 testTime3UT1DeltaBullB = -0.63574; 118 119 // Test Time 4 : Jan. 1, 1969 00:00:00.0000 120 // MJD = 40222 121 // JD = 2440222.5 122 const psS64 testTime4SecondsUTC = -31536000; 123 const psU32 testTime4NanosecondsUTC = 0; 124 // Expected MJD and JD 125 const psF64 testTime4MJD = 40222.0; 126 const psF64 testTime4JD = 2440222.5; 127 128 // Test Time 5 : Dec 31, 0001 BC 23:59:59 129 // MJD = -1397755 130 // JD = 1002245.4999 131 const psS64 testTime5SecondsUTC = -62125920001; 132 const psU32 testTime5NanosecondsUTC = 0; 133 134 // Test Time 6 : Jan. 1, 10000 AD 00:00:00 135 const psS64 testTime6SecondsUTC = 253202544001; 136 const psU32 testTime6NanosecondsUTC = 0; 137 138 // Test Time 7 : Jan. 1, 2004 00:00:00,0 139 const psS64 testTime7Seconds = 1072915200; 140 const psU32 testTime7Nanoseconds = 0; 141 const psS32 testTime7TmYear = 104; 142 const psS32 testTime7TmMon = 0; 143 const psS32 testTime7TmDay = 1; 144 const psS32 testTime7TmHour = 0; 145 const psS32 testTime7TmMin = 0; 146 const psS32 testTime7TmSec = 0; 147 148 // Test Time 8 : Dec. 31, 2003 00:00:00,0 149 const psS64 testTime8Seconds = 1072828800; 150 const psU32 testTime8Nanoseconds = 0; 151 const psS32 testTime8TmYear = 103; 152 const psS32 testTime8TmMon = 11; 153 const psS32 testTime8TmDay = 31; 154 const psS32 testTime8TmHour = 0; 155 const psS32 testTime8TmMin = 0; 156 const psS32 testTime8TmSec = 0; 35 157 36 158 psS32 main(psS32 argc, char* argv[]) 37 159 { 38 ps Time *testTime;39 char *testString = "2004-07-21T18:22:24.272Z"; 40 160 psLogSetLevel(PS_LOG_INFO); 161 162 // Initialize library internal structures 41 163 psLibInit(true,"psTime.config"); 42 164 43 // Test time was taken at July 21, 2004 at 18:22:24.272044 44 testTime = (psTime*)psAlloc(sizeof(psTime)); 45 testTime->sec = 1090434144; 46 testTime->nsec = 272044000; 47 testTime->type = PS_TIME_TAI; 48 49 // Test A - Get current TAI time 50 printPositiveTestHeader(stdout,"psTime", "Get current TAI time"); 51 psTime *timeA = NULL; 52 timeA = psTimeGetNow(PS_TIME_TAI); 53 psFree(timeA); 54 printFooter(stdout, "psTime", "Get current TAI time", true); 55 56 57 // Test B - Print test time 58 printPositiveTestHeader(stdout,"psTime", "Print test time"); 59 printf("Test time: Seconds = %lld Nanoseconds = %u\n", 60 (long long int)testTime->sec, 61 testTime->nsec); 62 printFooter(stdout, "psTime", "Print test time", true); 63 64 65 // Test C - Convert psTime to ISO time 66 printPositiveTestHeader(stdout,"psTime", "Convert psTime to ISO time"); 67 char *isoString; 68 isoString = psTimeToISO(testTime); 69 printf("%s\n", isoString); 70 if(strncmp(isoString, testString, 256)) { 71 printf("ERROR - ISO string incorrect\n"); 72 printf("Returned: %s\n", isoString); 73 } 74 printFooter(stdout, "psTime", "Convert psTime to ISO time", true); 75 76 77 // Test D - Convert ISO time to psTime 78 printPositiveTestHeader(stdout,"psTime", "Convert ISO time to psTime"); 79 psTime *timeD = NULL; 80 timeD = psTimeFromISO(isoString); 81 printf("psTime: Seconds = %lld Nanoseconds = %u\n", 82 (long long int)timeD->sec, 83 timeD->nsec); 84 psFree(isoString); 85 psFree(timeD); 86 printFooter(stdout, "psTime", "Convert ISO time to psTime", true); 87 88 89 // Test E - Convert TAI to UTC time 90 printPositiveTestHeader(stdout,"psTime", "Convert psTime time to UTC time"); 91 psTime *timeE = NULL; 92 timeE = (psTime*)psAlloc(sizeof(psTime)); 93 timeE->sec = 1090434144; 94 timeE->nsec = 272044000; 95 timeE->type = PS_TIME_TAI; 96 timeE = psTimeConvert(timeE, PS_TIME_UTC); 97 psFree(timeE); 98 printf("psTime: Seconds = %lld Nanoseconds = %u\n", 99 (long long int)timeE->sec, 100 timeE->nsec); 101 printFooter(stdout, "psTime", "Convert psTime time to UTC time", true); 102 103 104 // Test F - Convert UTC time to psTime 105 printPositiveTestHeader(stdout,"psTime", "Convert UTC time to psTime"); 106 psTime *timeF = NULL; 107 timeF = (psTime*)psAlloc(sizeof(psTime)); 108 timeF->sec = 1090434112; 109 timeF->nsec = 272044000; 110 timeF->type = PS_TIME_UTC; 111 timeF = psTimeConvert(timeF, PS_TIME_TAI); 112 psFree(timeF); 113 printf("psTime: Seconds = %lld Nanoseconds = %u\n", 114 (long long int)timeF->sec, 115 timeF->nsec); 116 printFooter(stdout, "psTime", "Convert UTC time to psTime", true); 117 118 119 // Test G - Convert psTime to MJD time 120 printPositiveTestHeader(stdout,"psTime", "Convert psTime to MJD time"); 121 double mjdTime = 0.0; 122 mjdTime = psTimeToMJD(testTime); 123 printf("MJD = %f\n", mjdTime); 124 printFooter(stdout, "psTime", "Convert psTime to MJD time", true); 125 126 127 // Test H - Convert MJD time to psTime 128 printPositiveTestHeader(stdout,"psTime", "Convert MJD time to psTime"); 129 psTime *timeH = NULL; 130 timeH = psTimeFromMJD(mjdTime); 131 printf("psTime: Seconds = %lld Nanoseconds = %u\n", 132 (long long int)timeH->sec, 133 timeH->nsec); 134 psFree(timeH); 135 printFooter(stdout, "psTime", "Convert MJD time to psTime", true); 136 137 138 // Test I - Convert psTime to JD time 139 printPositiveTestHeader(stdout,"psTime", "Convert psTime to JD time"); 140 double jdTime = 0.0; 141 jdTime = psTimeToJD(testTime); 142 printf("JD = %f\n", jdTime); 143 printFooter(stdout, "psTime", "Convert psTime to JD time", true); 144 145 146 // Test J - Convert JD time to psTime 147 printPositiveTestHeader(stdout,"psTime", "Convert JD time to psTime"); 148 psTime *timeJ = NULL; 149 timeJ = psTimeFromJD(jdTime); 150 printf("psTime: Seconds = %lld Nanoseconds = %u\n", 151 (long long int)timeJ->sec, 152 timeJ->nsec); 153 psFree(timeJ); 154 printFooter(stdout, "psTime", "Convert JD time to psTime", true); 155 156 157 // Test K - Convert psTime to timeval time 158 printPositiveTestHeader(stdout,"psTime", "Convert psTime to timeval time"); 159 struct timeval timevalTime; 160 timevalTime = psTimeToTimeval(testTime); 161 printf("timevalTime: Seconds = %lld Microseconds = %lld\n", 162 (long long int)timevalTime.tv_sec, 163 (long long int)timevalTime.tv_usec); 164 printFooter(stdout, "psTime", "Convert psTime to timeval time", true); 165 166 167 // Test L - Convert timeval time to psTime 168 printPositiveTestHeader(stdout,"psTime", "Convert timeval time to psTime"); 169 psTime *timeL = NULL; 170 timeL = psTimeFromTimeval(&timevalTime); 171 printf("psTime: Seconds = %lld Nanoseconds = %u\n", 172 (long long int)timeL->sec, 173 timeL->nsec); 174 psFree(timeL); 175 printFooter(stdout, "psTime", "Convert timeval time to psTime", true); 176 177 178 // Test M - Convert psTime to tm time 179 printPositiveTestHeader(stdout,"psTime", "Convert psTime to tm time"); 180 struct tm *tmTime; 181 tmTime = psTimeToTM(testTime); 182 printf("tmTime:\n"); 183 printf("tmTime->tm_year = %d\n", tmTime->tm_year); 184 printf("tmTime->tm_mon = %d\n", tmTime->tm_mon); 185 printf("tmTime->tm_mday = %d\n", tmTime->tm_mday); 186 printf("tmTime->tm_hour = %d\n", tmTime->tm_hour); 187 printf("tmTime->tm_min = %d\n", tmTime->tm_min); 188 printf("tmTime->tm_sec = %d\n", tmTime->tm_sec); 189 printFooter(stdout, "psTime", "Convert psTime to tm time", true); 190 191 192 // Test N - Convert tm time to psTime 193 printPositiveTestHeader(stdout, "psTime", "Convert tm time to psTime"); 194 psTime *timeN = NULL; 195 timeN = psTimeFromTM(tmTime); 196 printf("psTime: Seconds = %lld Nanoseconds = %u\n", 197 (long long int)timeN->sec, 198 timeN->nsec); 199 psFree(timeN); 165 if( !runTestSuite(stderr,"psTime",tests,argc,argv)) { 166 return 1; 167 } 168 169 // Cleanup library 170 psLibFinalize(); 171 172 return 0; 173 } 174 175 psS32 testTimeAlloc(void) 176 { 177 psTime* time = NULL; 178 179 // Allocate new psTime with valid time type 180 time = psTimeAlloc(PS_TIME_TAI); 181 if(time == NULL) { 182 psError(PS_ERR_UNKNOWN,true,"Return NULL when psTime object ptr expected"); 183 return 1; 184 } 185 // Verify members set properly 186 if(time->type != PS_TIME_TAI) { 187 psError(PS_ERR_UNKNOWN,true,"Member type = %d not as expected %d",time->type,PS_TIME_TAI); 188 return 2; 189 } 190 if((time->sec != 0) && (time->nsec != 0) && (time->leapsecond != false)) { 191 psError(PS_ERR_UNKNOWN,true,"Members not set appropriately"); 192 return 3; 193 } 194 psFree(time); 195 196 // Allocate new psTime with invalid time type 197 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message"); 198 time = psTimeAlloc(-100); 199 if(time != NULL) { 200 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for invalid time type"); 201 return 4; 202 } 203 204 return 0; 205 } 206 psS32 testTimeGetNow(void) 207 { 208 psTime* timeNow = NULL; 209 210 // Get current time and verify return is psTime structure 211 timeNow = psTimeGetNow(PS_TIME_TAI); 212 if(timeNow == NULL) { 213 psError(PS_ERR_UNKNOWN,true,"Did not return valid psTime struct"); 214 return 1; 215 } 216 if(timeNow->type != PS_TIME_TAI) { 217 psError(PS_ERR_UNKNOWN,true,"Time type %d not as expected %d", 218 timeNow->type, PS_TIME_TAI); 219 return 2; 220 } 221 psFree(timeNow); 222 223 // Attempt to get time with invalid type 224 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time type"); 225 timeNow = psTimeGetNow(-100); 226 if(timeNow != NULL) { 227 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for invalid time type"); 228 return 3; 229 } 230 231 return 0; 232 } 233 234 psS32 testTimeGetUT1Delta(void) 235 { 236 psTime* time = NULL; 237 psF64 ut1Delta = 0.0; 238 239 // Attempt to convert NULL time 240 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL time"); 241 ut1Delta = psTimeGetUT1Delta(time,PS_IERS_B); 242 if( !isnan(ut1Delta)) { 243 psError(PS_ERR_UNKNOWN,true,"Did not return NAN for NULL psTime"); 244 return 1; 245 } 246 247 // Attempt to convert invalid time 248 time = psTimeAlloc(PS_TIME_TAI); 249 time->sec = 1; 250 time->nsec = 2e9; 251 time->leapsecond = false; 252 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time"); 253 ut1Delta = psTimeGetUT1Delta(time,PS_IERS_B); 254 if( !isnan(ut1Delta)) { 255 psError(PS_ERR_UNKNOWN,true,"Did not return NAN for invalid time"); 256 return 2; 257 } 258 259 // Attempt to convert time with invalid bulletin 260 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid bulletin"); 261 time->nsec = 2; 262 ut1Delta = psTimeGetUT1Delta(time,-100); 263 if( !isnan(ut1Delta)) { 264 psError(PS_ERR_UNKNOWN,true,"Did not return NAN for invalid bulletin"); 265 return 3; 266 } 267 268 // Attempt to get delta with valid time and bulletin A 269 time->sec = testTime1SecondsUTC; 270 time->nsec = testTime1NanosecondsUTC; 271 time->type = PS_TIME_UTC; 272 ut1Delta = psTimeGetUT1Delta(time,PS_IERS_A); 273 if(fabs(ut1Delta - testTime1UT1DeltaBullA) > ERROR_TOL) { 274 psError(PS_ERR_UNKNOWN,true,"UT1 Delta %lf not as expected %lf test time 1 bulletin A", 275 ut1Delta,testTime1UT1DeltaBullA); 276 return 4; 277 } 278 279 // Attempt to get delta with valid time and bulletin B 280 ut1Delta = psTimeGetUT1Delta(time,PS_IERS_B); 281 if(fabs(ut1Delta - testTime1UT1DeltaBullB) > ERROR_TOL) { 282 psError(PS_ERR_UNKNOWN,true,"UT1 Delta %lf not as expected %lf test time 1 bulletin B", 283 ut1Delta,testTime1UT1DeltaBullB); 284 return 5; 285 } 286 287 // Attempt to get delta with valid time and bulletin A 288 time->sec = testTime2SecondsUTC; 289 time->nsec = testTime2NanosecondsUTC; 290 time->type = PS_TIME_UTC; 291 psLogMsg(__func__,PS_LOG_INFO,"Following should generate a warning message predating table"); 292 ut1Delta = psTimeGetUT1Delta(time,PS_IERS_A); 293 if(fabs(ut1Delta - testTime2UT1DeltaBullA) > ERROR_TOL) { 294 psError(PS_ERR_UNKNOWN,true,"UT1 Delta %lf not as expected %lf test time 2 bulletin A", 295 ut1Delta,testTime2UT1DeltaBullA); 296 return 6; 297 } 298 299 // Attempt to get delta with valid time and bulletin B 300 psLogMsg(__func__,PS_LOG_INFO,"Following should generate a warning message predating table"); 301 ut1Delta = psTimeGetUT1Delta(time,PS_IERS_B); 302 if(fabs(ut1Delta - testTime2UT1DeltaBullB) > ERROR_TOL) { 303 psError(PS_ERR_UNKNOWN,true,"UT1 Delta %lf not as expected %lf test time 2 bulletin B", 304 ut1Delta,testTime2UT1DeltaBullB); 305 return 7; 306 } 307 308 // Attempt to get delta with valid time and bulletin A 309 time->sec = testTime3SecondsUTC; 310 time->nsec = testTime3NanosecondsUTC; 311 time->type = PS_TIME_UTC; 312 psLogMsg(__func__,PS_LOG_INFO,"Following should generate a warning message postdating table"); 313 ut1Delta = psTimeGetUT1Delta(time,PS_IERS_A); 314 if(fabs(ut1Delta - testTime3UT1DeltaBullA) > ERROR_TOL) { 315 psError(PS_ERR_UNKNOWN,true,"UT1 Delta %lf not as expected %lf test time 3 bulletin A", 316 ut1Delta,testTime3UT1DeltaBullA); 317 return 8; 318 } 319 320 // Attempt to get delta with valid time and bulletin B 321 psLogMsg(__func__,PS_LOG_INFO,"Following should generate a warning message postdating table"); 322 ut1Delta = psTimeGetUT1Delta(time,PS_IERS_B); 323 if(fabs(ut1Delta - testTime3UT1DeltaBullB) > ERROR_TOL) { 324 psError(PS_ERR_UNKNOWN,true,"UT1 Delta %lf not as expected %lf test time 3 bulletin B", 325 ut1Delta,testTime3UT1DeltaBullB); 326 return 9; 327 } 328 329 psFree(time); 330 331 return 0; 332 } 333 334 psS32 testTimeToMJD(void) 335 { 336 psTime* time = NULL; 337 psF64 mjd = 0.0; 338 339 // Attempt to convert with time NULL 340 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL time"); 341 mjd = psTimeToMJD(NULL); 342 if(!isnan(mjd)) { 343 psError(PS_ERR_UNKNOWN,true,"Expected NaN for NULL time"); 344 return 1; 345 } 346 347 // Attempt to convert invalid time 348 time = psTimeAlloc(PS_TIME_UTC); 349 time->sec = 1; 350 time->nsec = 2e9; 351 time->leapsecond = false; 352 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time"); 353 mjd = psTimeToMJD(time); 354 if( !isnan(mjd)) { 355 psError(PS_ERR_UNKNOWN,true,"Did not return NAN for invalid time"); 356 return 2; 357 } 358 359 // Check valid time conversion to MJD after 1/1/1970 epoch 360 time->sec = testTime1SecondsUTC; 361 time->nsec = testTime1NanosecondsUTC; 362 mjd = psTimeToMJD(time); 363 if(fabs(mjd - testTime1MJD) > ERROR_TOL) { 364 psError(PS_ERR_UNKNOWN,true,"Expected MJD = %lf not as expected %lf", 365 mjd, testTime1MJD); 366 return 3; 367 } 368 369 // Check valid time conversion to MJD before 1/1/1970 epoch 370 time->sec = testTime4SecondsUTC; 371 time->nsec = testTime4NanosecondsUTC; 372 mjd = psTimeToMJD(time); 373 if(fabs(mjd - testTime4MJD) > ERROR_TOL) { 374 psError(PS_ERR_UNKNOWN,true,"Expected MJD = %lf not as expected %lf", 375 mjd, testTime4MJD); 376 return 4; 377 } 378 379 psFree(time); 380 381 return 0; 382 } 383 384 psS32 testTimeToJD(void) 385 { 386 psTime* time = NULL; 387 psF64 jd = 0.0; 388 389 // Attempt to convert with time NULL 390 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL time"); 391 jd = psTimeToJD(NULL); 392 if(!isnan(jd)) { 393 psError(PS_ERR_UNKNOWN,true,"Expected NaN for NULL time"); 394 return 1; 395 } 396 397 // Attempt to convert invalid time 398 time = psTimeAlloc(PS_TIME_UTC); 399 time->sec = 1; 400 time->nsec = 2e9; 401 time->leapsecond = false; 402 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time"); 403 jd = psTimeToJD(time); 404 if( !isnan(jd)) { 405 psError(PS_ERR_UNKNOWN,true,"Did not return NAN for invalid time"); 406 return 2; 407 } 408 409 // Check valid time conversion to MJD after 1/1/1970 epoch 410 time->sec = testTime1SecondsUTC; 411 time->nsec = testTime1NanosecondsUTC; 412 jd = psTimeToJD(time); 413 if(fabs(jd - testTime1JD) > ERROR_TOL) { 414 psError(PS_ERR_UNKNOWN,true,"Expected JD = %lf not as expected %lf", 415 jd, testTime1JD); 416 return 3; 417 } 418 419 // Check valid time conversion to MJD before 1/1/1970 epoch 420 time->sec = testTime4SecondsUTC; 421 time->nsec = testTime4NanosecondsUTC; 422 jd = psTimeToJD(time); 423 if(fabs(jd - testTime4JD) > ERROR_TOL) { 424 psError(PS_ERR_UNKNOWN,true,"Expected JD = %lf not as expected %lf", 425 jd, testTime4JD); 426 return 4; 427 } 428 429 psFree(time); 430 431 return 0; 432 } 433 434 psS32 testTimeToISO(void) 435 { 436 psTime* time = NULL; 437 char* timeStr = NULL; 438 439 // Attempt to convert with NULL time 440 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL time"); 441 timeStr = psTimeToISO(time); 442 if(timeStr != NULL) { 443 psError(PS_ERR_UNKNOWN,true,"Did not return NULL as expected"); 444 return 1; 445 } 446 447 // Attempt to convert invalid time 448 time = psTimeAlloc(PS_TIME_UTC); 449 time->sec = 1; 450 time->nsec = 2e9; 451 time->leapsecond = false; 452 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time"); 453 timeStr = psTimeToISO(time); 454 if( timeStr != NULL) { 455 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for invalid time"); 456 return 2; 457 } 458 459 // Verify return NULL for time prior to year 0000 460 time->sec = testTime5SecondsUTC; 461 time->nsec = testTime5NanosecondsUTC; 462 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for time prior year 0000"); 463 timeStr = psTimeToISO(time); 464 if(timeStr != NULL) { 465 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for time prior to year 0000"); 466 return 3; 467 } 468 469 // Verify return NULL for time after to year 9999 470 time->sec = testTime6SecondsUTC; 471 time->nsec = testTime6NanosecondsUTC; 472 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for time after year 9999"); 473 timeStr = psTimeToISO(time); 474 if(timeStr != NULL) { 475 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for time after to year 9999"); 476 return 4; 477 } 478 479 // Verify return string with valid time 480 time->sec = testTime1SecondsUTC; 481 time->nsec = testTime1NanosecondsUTC; 482 timeStr = psTimeToISO(time); 483 if(strcmp(timeStr,testTime1Str) != 0) { 484 psError(PS_ERR_UNKNOWN,true,"String %s not as expected %s", 485 timeStr, testTime1Str); 486 return 5; 487 } 488 psFree(timeStr); 489 490 // Verify return string with valid time and leap second set 491 time->sec = testTime1SecondsUTC; 492 time->nsec = testTime1NanosecondsUTC; 493 time->leapsecond = true; 494 timeStr = psTimeToISO(time); 495 if(strcmp(timeStr,testTime1StrLeap) != 0) { 496 psError(PS_ERR_UNKNOWN,true,"String %s not as expected %s", 497 timeStr, testTime1StrLeap); 498 return 6; 499 } 500 psFree(timeStr); 501 psFree(time); 502 503 return 0; 504 } 505 506 psS32 testTimeToTimeval(void) 507 { 508 psTime* time = NULL; 509 struct timeval* timevalTime = NULL; 510 511 // Attempt to convert with NULL time 512 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL time"); 513 timevalTime = psTimeToTimeval(time); 514 if(timevalTime != NULL) { 515 psError(PS_ERR_UNKNOWN,true,"Did not return NULL as expected"); 516 return 1; 517 } 518 519 // Attempt to convert invalid time 520 time = psTimeAlloc(PS_TIME_UTC); 521 time->sec = 1; 522 time->nsec = 2e9; 523 time->leapsecond = false; 524 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time"); 525 timevalTime = psTimeToTimeval(time); 526 if( timevalTime != NULL) { 527 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for invalid time"); 528 return 2; 529 } 530 531 // Attempt to convert invalid time 532 time->sec = -1; 533 time->nsec = 0; 534 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time"); 535 timevalTime = psTimeToTimeval(time); 536 if( timevalTime != NULL) { 537 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for invalid time"); 538 return 2; 539 } 540 541 // Verify convert to timeval with valid time 542 time->sec = testTime1SecondsUTC; 543 time->nsec = testTime1NanosecondsUTC; 544 timevalTime = psTimeToTimeval(time); 545 if(timevalTime->tv_sec != testTime1TimevalSec) { 546 psError(PS_ERR_UNKNOWN,true,"Timeval seconds %ld not as expectd %ld", 547 timevalTime->tv_sec,testTime1TimevalSec); 548 return 4; 549 } 550 if(timevalTime->tv_usec != testTime1TimevalUsec) { 551 psError(PS_ERR_UNKNOWN,true,"Timeval useconds %ld not as expected %ld", 552 timevalTime->tv_usec,testTime1TimevalUsec); 553 return 5; 554 } 555 556 psFree(timevalTime); 557 psFree(time); 558 559 return 0; 560 } 561 562 psS32 testTimeFromMJD(void) 563 { 564 psTime* time = NULL; 565 566 // Attempt to convert valid time to psTime 567 time = psTimeFromMJD(testTime1MJDTAI); 568 if(time->type != PS_TIME_TAI) { 569 psError(PS_ERR_UNKNOWN,true,"Type %d not as expected %d", 570 time->type,PS_TIME_TAI); 571 return 1; 572 } 573 if(time->sec != testTime1SecondsTAI) { 574 psError(PS_ERR_UNKNOWN,true,"psTime seconds %ld not as expected %ld", 575 (long int)time->sec,testTime1SecondsTAI); 576 return 2; 577 } 578 psFree(time); 579 580 // Attempt to convert valid time before 1970 epoch 581 time = psTimeFromMJD(testTime4MJD); 582 if(time->type != PS_TIME_TAI) { 583 psError(PS_ERR_UNKNOWN,true,"Type %d not as expected %d", 584 time->type,PS_TIME_TAI); 585 return 3; 586 } 587 if(time->sec != testTime4SecondsUTC) { 588 psError(PS_ERR_UNKNOWN,true,"psTime seconds %ld not as expected %ld", 589 (long int)time->sec,testTime4SecondsUTC); 590 return 4; 591 } 592 psFree(time); 593 594 return 0; 595 } 596 597 psS32 testTimeFromJD(void) 598 { 599 psTime* time = NULL; 600 601 // Attempt to convert valid time to psTime 602 time = psTimeFromJD(testTime1JDTAI); 603 if(time->type != PS_TIME_TAI) { 604 psError(PS_ERR_UNKNOWN,true,"Type %d not as expected %d", 605 time->type,PS_TIME_TAI); 606 return 1; 607 } 608 if(time->sec != testTime1SecondsTAI) { 609 psError(PS_ERR_UNKNOWN,true,"psTime seconds %ld not as expected %ld", 610 (long int)time->sec,(long int)testTime1SecondsTAI); 611 return 2; 612 } 613 psFree(time); 614 615 // Attempt to convert valid time before 1970 epoch 616 time = psTimeFromJD(testTime4JD); 617 if(time->type != PS_TIME_TAI) { 618 psError(PS_ERR_UNKNOWN,true,"Type %d not as expected %d", 619 time->type,PS_TIME_TAI); 620 return 3; 621 } 622 if(time->sec != testTime4SecondsUTC) { 623 psError(PS_ERR_UNKNOWN,true,"psTime seconds %ld not as expected %ld", 624 (long int)time->sec,testTime4SecondsUTC); 625 return 4; 626 } 627 psFree(time); 628 629 return 0; 630 } 631 632 psS32 testTimeFromISO(void) 633 { 634 psTime* time = NULL; 635 636 // Attempt to convert NULL string 637 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL ISO string"); 638 time = psTimeFromISO(NULL); 639 if(time != NULL) { 640 psError(PS_ERR_UNKNOWN,true,"Did not return NULL as expected for NULL ISO string"); 641 return 1; 642 } 643 644 // Convert valid ISO string 645 time = psTimeFromISO(testTime1Str); 646 if(time->type != PS_TIME_TAI) { 647 psError(PS_ERR_UNKNOWN,true,"Type %d not as expected %d", 648 time->type, PS_TIME_TAI); 649 return 2; 650 } 651 if(time->sec != testTime1SecondsUTC) { 652 psError(PS_ERR_UNKNOWN,true,"psTime seconds %ld not as expected %ld", 653 (long int)time->sec,testTime1SecondsTAI); 654 return 3; 655 } 656 psFree(time); 657 658 // Attempt to convert invalid ISO string 659 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error for invalid ISO string"); 660 time = psTimeFromISO("Here I am"); 661 if(time != NULL) { 662 psError(PS_ERR_UNKNOWN,true,"Did not return NULL as expected for invalid ISO string"); 663 return 4; 664 } 665 psFree(time); 666 667 return 0; 668 } 669 670 psS32 testTimeFromTimeval(void) 671 { 672 psTime* time = NULL; 673 struct timeval* timevalTime = NULL; 674 675 // Attempt to create psTime from NULL timeval ptr 676 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL timeval"); 677 time = psTimeFromTimeval(NULL); 678 if(time != NULL) { 679 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for NULL timeval ptr"); 680 return 1; 681 } 682 683 // Convert valid timeval structure 684 timevalTime = (struct timeval*)psAlloc(sizeof(struct timeval)); 685 timevalTime->tv_sec = testTime1SecondsTAI; 686 timevalTime->tv_usec = testTime1NanosecondsTAI / 1000; 687 time = psTimeFromTimeval(timevalTime); 688 if(time == NULL) { 689 psError(PS_ERR_UNKNOWN,true,"Did not expect NULL return value for valid timeval"); 690 return 2; 691 } 692 if(time->type != PS_TIME_TAI) { 693 psError(PS_ERR_UNKNOWN,true,"psTime type %d not as expected %d", 694 time->type, PS_TIME_TAI); 695 return 3; 696 } 697 if(time->sec != testTime1SecondsTAI) { 698 psError(PS_ERR_UNKNOWN,true,"psTime seconds %ld not as expected %ld", 699 time->sec, testTime1SecondsTAI); 700 return 4; 701 } 702 if(time->nsec != testTime1NanosecondsTAI) { 703 psError(PS_ERR_UNKNOWN,true,"psTime nanosec %ld not as expected %ld", 704 time->nsec, testTime1NanosecondsTAI); 705 return 5; 706 } 707 psFree(timevalTime); 708 psFree(time); 709 710 return 0; 711 } 712 713 psS32 testTimeFromTM(void) 714 { 715 psTime* time = NULL; 716 struct tm* tmTime = NULL; 717 718 // Attempt to convert from NULL tm structure ptr 719 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL tm ptr"); 720 time = p_psTimeFromTM(tmTime); 721 if(time != NULL) { 722 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for NULL tm ptr"); 723 return 1; 724 } 725 726 // Verify convert for valid tm structure 727 tmTime = (struct tm*)psAlloc(sizeof(struct tm)); 728 tmTime->tm_year = testTime7TmYear; 729 tmTime->tm_mon = testTime7TmMon; 730 tmTime->tm_mday = testTime7TmDay; 731 tmTime->tm_hour = testTime7TmHour; 732 tmTime->tm_min = testTime7TmMin; 733 tmTime->tm_sec = testTime7TmSec; 734 time = p_psTimeFromTM(tmTime); 735 if(time == NULL) { 736 psError(PS_ERR_UNKNOWN,true,"Did not expect NULL return value for valid tm structure"); 737 return 2; 738 } 739 if(time->sec != testTime7Seconds) { 740 psError(PS_ERR_UNKNOWN,true,"psTime seconds %ld not as expected %ld", 741 (long int)time->sec, (long int)testTime7Seconds); 742 return 3; 743 } 744 if(time->nsec != testTime7Nanoseconds) { 745 psError(PS_ERR_UNKNOWN,true,"psTime nanoseconds %ld not as expected %ld", 746 time->nsec, testTime7Nanoseconds); 747 return 4; 748 } 200 749 psFree(tmTime); 201 printFooter(stdout, "psTime", "Convert tm time to psTime", true); 202 203 204 // Test O - psTime to LMST 205 printPositiveTestHeader(stdout, "psTime", "Convert psTime time to LST"); 206 char *testString2 = "2004-09-10T1:00:00.00Z"; 207 psTime* testTime2 = NULL; 208 testTime2 = psTimeFromISO(testString2); 209 double dblTime = psTimeToLMST(testTime2, 1); 210 printf("LST (rad): %lf\n", dblTime); 211 psFree(testTime2); 212 printFooter(stdout, "psTime", "Convert psTime time to LST", true); 213 214 215 // Test P - Free data 216 printPositiveTestHeader(stdout, "psMetadata", "Test P - Free data"); 217 psFree(testTime); 218 psLibFinalize(); 219 if( psMemCheckLeaks(0, NULL, stdout,false) != 0 ) { 220 psError(PS_ERR_UNKNOWN,true,"Memory leaks detected"); 750 psFree(time); 751 752 // Verify convert for valid tm structure 753 tmTime = (struct tm*)psAlloc(sizeof(struct tm)); 754 tmTime->tm_year = testTime8TmYear; 755 tmTime->tm_mon = testTime8TmMon; 756 tmTime->tm_mday = testTime8TmDay; 757 tmTime->tm_hour = testTime8TmHour; 758 tmTime->tm_min = testTime8TmMin; 759 tmTime->tm_sec = testTime8TmSec; 760 time = p_psTimeFromTM(tmTime); 761 if(time == NULL) { 762 psError(PS_ERR_UNKNOWN,true,"Did not expect NULL return value for valid tm structure"); 763 return 2; 764 } 765 if(time->sec != testTime8Seconds) { 766 psError(PS_ERR_UNKNOWN,true,"psTime seconds %ld not as expected %ld", 767 (long int)time->sec, (long int)testTime8Seconds); 768 return 3; 769 } 770 if(time->nsec != testTime8Nanoseconds) { 771 psError(PS_ERR_UNKNOWN,true,"psTime nanoseconds %ld not as expected %ld", 772 time->nsec, testTime8Nanoseconds); 773 return 4; 774 } 775 psFree(tmTime); 776 psFree(time); 777 778 return 0; 779 } 780 781 psS32 testTimeConvert(void) 782 { 783 psTime* time1 = NULL; 784 psTime* time2 = NULL; 785 786 // Attempt to convert NULL time 787 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL time"); 788 time2 = psTimeConvert(time1,PS_TIME_TAI); 789 // Verify return value is NULL 790 if(time2 != NULL) { 791 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for NULL time specified"); 792 return 1; 793 } 794 795 // Attempt to convert to invalid type 796 time1 = psTimeAlloc(PS_TIME_TAI); 797 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid type"); 798 time2 = psTimeConvert(time1,-100); 799 // Verify return value is NULL 800 if(time2 != time1) { 801 psError(PS_ERR_UNKNOWN,true,"Did not return time for invalid type to convert to"); 802 return 2; 803 } 804 time1->type = PS_TIME_UTC; 805 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid type"); 806 time2 = psTimeConvert(time1,-100); 807 // Verify return value is NULL 808 if(time2 != time1) { 809 psError(PS_ERR_UNKNOWN,true,"Did not return time for invalid type to convert to"); 810 return 2; 811 } 812 time1->type = PS_TIME_TT; 813 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid type"); 814 time2 = psTimeConvert(time1,-100); 815 // Verify return value is NULL 816 if(time2 != time1) { 817 psError(PS_ERR_UNKNOWN,true,"Did not return time for invalid type to convert to"); 818 return 2; 819 } 820 time1->type = -100; 821 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid type"); 822 time2 = psTimeConvert(time1,PS_TIME_TAI); 823 // Verify return value is NULL 824 if(time2 != time1) { 825 psError(PS_ERR_UNKNOWN,true,"Did not return time for invalid type to convert to"); 826 return 2; 827 } 828 829 // Attempt to convert with invalid time nsec > 1e9 830 time1->nsec = 2e9; 831 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time"); 832 time2 = psTimeConvert(time1,PS_TIME_TAI); 833 if(time2 != time1) { 834 psError(PS_ERR_UNKNOWN,true,"Did not return time for invalid time specified"); 835 return 3; 836 } 837 838 //Attempt to convert a time to the same type 839 time2 = NULL; 840 time1->sec = 1; 841 time1->nsec = 2; 842 time1->type = PS_TIME_TAI; 843 time1->leapsecond = false; 844 time2 = psTimeConvert(time1,PS_TIME_TAI); 845 if(time2 != time1) { 846 psError(PS_ERR_UNKNOWN,true,"Did not return time for conversion to same type"); 847 return 4; 848 } 849 // Verify time not changed 850 if((time2->sec != 1) || (time2->nsec != 2) || (time2->type != PS_TIME_TAI) || 851 (time2->leapsecond != false) ) { 852 psError(PS_ERR_UNKNOWN,true,"Time member changes when no change expected"); 853 return 5; 854 } 855 856 // Attempt to convert a UTC time to a TAI 857 time2 = NULL; 858 time1->sec = testTime1SecondsUTC; 859 time1->nsec = testTime1NanosecondsUTC; 860 time1->type = PS_TIME_UTC; 861 time1->leapsecond = false; 862 time2 = psTimeConvert(time1,PS_TIME_TAI); 863 if(time2 != time1) { 864 psError(PS_ERR_UNKNOWN,true,"Did not return time for conversion from UTC to TAI"); 865 return 6; 866 } 867 // Verify time type 868 if(time2->type != PS_TIME_TAI) { 869 psError(PS_ERR_UNKNOWN,true,"Returned time type %d not as expected %d", 870 time2->type, PS_TIME_TAI); 871 return 7; 872 } 873 // Verify time is TAI as expected 874 if(time2->sec != testTime1SecondsTAI) { 875 psError(PS_ERR_UNKNOWN,true,"TAI seconds = %ld not as expected %ld",(long int)time2->sec, 876 (long int)testTime1SecondsTAI); 877 return 7; 878 } 879 if(time2->nsec != testTime1NanosecondsTAI) { 880 psError(PS_ERR_UNKNOWN,true,"TAI nanoseconds = %ld not as expected %ld",(long int)time2->nsec, 881 (long int)testTime1NanosecondsTAI); 882 return 8; 883 } 884 885 // Attempt to convert a UTC time to a TT 886 time2 = NULL; 887 time1->sec = testTime1SecondsUTC; 888 time1->nsec = testTime1NanosecondsUTC; 889 time1->type = PS_TIME_UTC; 890 time1->leapsecond = false; 891 time2 = psTimeConvert(time1,PS_TIME_TT); 892 if(time2 != time1) { 893 psError(PS_ERR_UNKNOWN,true,"Did not return time for conversion from UTC to TT"); 894 return 6; 895 } 896 // Verify time type 897 if(time2->type != PS_TIME_TT) { 898 psError(PS_ERR_UNKNOWN,true,"Returned time type %d not as expected %d", 899 time2->type, PS_TIME_TT); 900 return 7; 901 } 902 // Verify time is TT as expected 903 if(time2->sec != testTime1SecondsTT) { 904 psError(PS_ERR_UNKNOWN,true,"TT seconds = %ld not as expected %ld",(long int)time2->sec, 905 (long int)testTime1SecondsTT); 906 return 7; 907 } 908 if(time2->nsec != testTime1NanosecondsTT) { 909 psError(PS_ERR_UNKNOWN,true,"TT nanoseconds = %ld not as expected %ld",(long int)time2->nsec, 910 (long int)testTime1NanosecondsTT); 911 return 8; 912 } 913 914 // Attempt to convert a UTC time to UT1 915 time2 = NULL; 916 time1->sec = testTime1SecondsUTC; 917 time1->nsec = testTime1NanosecondsUTC; 918 time1->type = PS_TIME_UTC; 919 time1->leapsecond = false; 920 time2 = psTimeConvert(time1,PS_TIME_UT1); 921 if(time1 != time2) { 922 psError(PS_ERR_UNKNOWN,true,"Did not return time for conversion from UTC to UT1"); 923 return 9; 924 } 925 // Verify time type 926 if(time2->type != PS_TIME_UT1) { 927 psError(PS_ERR_UNKNOWN,true,"Returned time type %d not as expected %d", 928 time2->type, PS_TIME_UT1); 929 return 7; 930 } 931 // Verify time is UT1 as expected 932 if(time2->sec != testTime1SecondsUT1) { 933 psError(PS_ERR_UNKNOWN,true,"UT1 seconds = %ld not as expected %ld",(long int)time2->sec, 934 (long int)testTime1SecondsUT1); 935 return 9; 936 } 937 if(time2->nsec != testTime1NanosecondsUT1) { 938 psError(PS_ERR_UNKNOWN,true,"UT1 nanoseconds = %d not as expected %d",time2->nsec, 939 testTime1NanosecondsUT1); 221 940 return 10; 222 941 } 223 psMemCheckCorruption(0); 224 psS32 nBad = psMemCheckCorruption(0); 225 if(nBad) { 226 printf("ERROR: Found %d bad memory blocks\n", nBad); 227 } 228 printFooter(stdout, "psMetadata", "Test P - Free data", true); 229 230 return 0; 231 } 942 943 // Attempt to convert a TAI time to UTC 944 time2 = NULL; 945 time1->sec = testTime1SecondsTAI; 946 time1->nsec = testTime1NanosecondsTAI; 947 time1->type = PS_TIME_TAI; 948 time1->leapsecond = false; 949 time2 = psTimeConvert(time1,PS_TIME_UTC); 950 if(time2 != time1) { 951 psError(PS_ERR_UNKNOWN,true,"Did not return time for conversion from TAI to UTC"); 952 return 11; 953 } 954 // Verify time type 955 if(time2->type != PS_TIME_UTC) { 956 psError(PS_ERR_UNKNOWN,true,"Returned time type %d not as expected %d", 957 time2->type, PS_TIME_UTC); 958 return 7; 959 } 960 // Verify time is UTC as expected 961 if(time2->sec != testTime1SecondsUTC) { 962 psError(PS_ERR_UNKNOWN,true,"UTC seconds = %ld not as expected %ld",(long int)time2->sec, 963 (long int)testTime1SecondsUTC); 964 return 12; 965 } 966 if(time2->nsec != testTime1NanosecondsUTC) { 967 psError(PS_ERR_UNKNOWN,true,"UTC nanoseconds = %ld not as expected %ld",(long int)time2->nsec, 968 (long int)testTime1NanosecondsUTC); 969 return 13; 970 } 971 972 // Attempt to convert a TAI time to TT 973 time2 = NULL; 974 time1->sec = testTime1SecondsTAI; 975 time1->nsec = testTime1NanosecondsTAI; 976 time1->type = PS_TIME_TAI; 977 time1->leapsecond = false; 978 time2 = psTimeConvert(time1,PS_TIME_TT); 979 if(time2 != time1) { 980 psError(PS_ERR_UNKNOWN,true,"Did not return time for conversion from TAI to TT"); 981 return 14; 982 } 983 // Verify time type 984 if(time2->type != PS_TIME_TT) { 985 psError(PS_ERR_UNKNOWN,true,"Returned time type %d not as expected %d", 986 time2->type, PS_TIME_TT); 987 return 7; 988 } 989 // Verify time is TT as expected 990 if(time2->sec != testTime1SecondsTT) { 991 psError(PS_ERR_UNKNOWN,true,"TT seconds = %ld not as expected %ld",(long int)time2->sec, 992 (long int)testTime1SecondsTT); 993 return 15; 994 } 995 if(time2->nsec != testTime1NanosecondsTT) { 996 psError(PS_ERR_UNKNOWN,true,"TT nanoseconds = %ld not as expected %ld",(long int)time2->nsec, 997 (long int)testTime1NanosecondsTT); 998 return 16; 999 } 1000 1001 // Attempt to convert a TAI time to UT1 1002 time2 = NULL; 1003 time1->sec = testTime1SecondsTAI; 1004 time1->nsec = testTime1NanosecondsTAI; 1005 time1->type = PS_TIME_TAI; 1006 time1->leapsecond = false; 1007 time2 = psTimeConvert(time1,PS_TIME_UT1); 1008 if(time1 != time2) { 1009 psError(PS_ERR_UNKNOWN,true,"Did not return time for conversion from TAI to UT1"); 1010 return 9; 1011 } 1012 // Verify time type 1013 if(time2->type != PS_TIME_UT1) { 1014 psError(PS_ERR_UNKNOWN,true,"Returned time type %d not as expected %d", 1015 time2->type, PS_TIME_UT1); 1016 return 7; 1017 } 1018 // Verify time is UT1 as expected 1019 if(time2->sec != testTime1SecondsUT1) { 1020 psError(PS_ERR_UNKNOWN,true,"UT1 seconds = %ld not as expected %ld",(long int)time2->sec, 1021 (long int)testTime1SecondsUT1); 1022 return 9; 1023 } 1024 if(time2->nsec != testTime1NanosecondsUT1) { 1025 psError(PS_ERR_UNKNOWN,true,"UT1 nanoseconds = %d not as expected %d",time2->nsec, 1026 testTime1NanosecondsUT1); 1027 return 10; 1028 } 1029 1030 // Attempt to convert a TT time to UTC 1031 time2 = NULL; 1032 time1->sec = testTime1SecondsTT; 1033 time1->nsec = testTime1NanosecondsTT; 1034 time1->type = PS_TIME_TT; 1035 time1->leapsecond = false; 1036 time2 = psTimeConvert(time1,PS_TIME_UTC); 1037 if(time2 != time1) { 1038 psError(PS_ERR_UNKNOWN,true,"Did not return time for conversion from TT to UTC"); 1039 return 17; 1040 } 1041 // Verify time type 1042 if(time2->type != PS_TIME_UTC) { 1043 psError(PS_ERR_UNKNOWN,true,"Returned time type %d not as expected %d", 1044 time2->type, PS_TIME_UTC); 1045 return 7; 1046 } 1047 // Verify time is UTC as expected 1048 if(time2->sec != testTime1SecondsUTC) { 1049 psError(PS_ERR_UNKNOWN,true,"UTC seconds = %ld not as expected %ld",(long int)time2->sec, 1050 (long int)testTime1SecondsUTC); 1051 return 18; 1052 } 1053 if(time2->nsec != testTime1NanosecondsUTC) { 1054 psError(PS_ERR_UNKNOWN,true,"UTC nanoseconds = %ld not as expected %ld",(long int)time2->nsec, 1055 (long int)testTime1NanosecondsUTC); 1056 return 19; 1057 } 1058 1059 // Attempt to convert a TT time to TAI 1060 time2 = NULL; 1061 time1->sec = testTime1SecondsTT; 1062 time1->nsec = testTime1NanosecondsTT; 1063 time1->type = PS_TIME_TT; 1064 time1->leapsecond = false; 1065 time2 = psTimeConvert(time1,PS_TIME_TAI); 1066 if(time2 != time1) { 1067 psError(PS_ERR_UNKNOWN,true,"Did not return time for conversion from TT to TAI"); 1068 return 20; 1069 } 1070 // Verify time type 1071 if(time2->type != PS_TIME_TAI) { 1072 psError(PS_ERR_UNKNOWN,true,"Returned time type %d not as expected %d", 1073 time2->type, PS_TIME_TAI); 1074 return 7; 1075 } 1076 // Verify time is TAI as expected 1077 if(time2->sec != testTime1SecondsTAI) { 1078 psError(PS_ERR_UNKNOWN,true,"TAI seconds = %ld not as expected %ld",(long int)time2->sec, 1079 (long int)testTime1SecondsTAI); 1080 return 21; 1081 } 1082 if(time2->nsec != testTime1NanosecondsTAI) { 1083 psError(PS_ERR_UNKNOWN,true,"TT nanoseconds = %ld not as expected %ld",(long int)time2->nsec, 1084 (long int)testTime1NanosecondsTAI); 1085 return 22; 1086 } 1087 1088 // Attempt to convert a TT time to UT1 1089 time2 = NULL; 1090 time1->sec = testTime1SecondsTT; 1091 time1->nsec = testTime1NanosecondsTT; 1092 time1->type = PS_TIME_TT; 1093 time1->leapsecond = false; 1094 time2 = psTimeConvert(time1,PS_TIME_UT1); 1095 if(time1 != time2) { 1096 psError(PS_ERR_UNKNOWN,true,"Did not return time for conversion from TT to UT1"); 1097 return 9; 1098 } 1099 // Verify time type 1100 if(time2->type != PS_TIME_UT1) { 1101 psError(PS_ERR_UNKNOWN,true,"Returned time type %d not as expected %d", 1102 time2->type, PS_TIME_UT1); 1103 return 7; 1104 } 1105 // Verify time is UT1 as expected 1106 if(time2->sec != testTime1SecondsUT1) { 1107 psError(PS_ERR_UNKNOWN,true,"UT1 seconds = %ld not as expected %ld",(long int)time2->sec, 1108 (long int)testTime1SecondsUT1); 1109 return 9; 1110 } 1111 if(time2->nsec != testTime1NanosecondsUT1) { 1112 psError(PS_ERR_UNKNOWN,true,"UT1 nanoseconds = %d not as expected %d",time2->nsec, 1113 testTime1NanosecondsUT1); 1114 return 10; 1115 } 1116 1117 // Attempt to convert from UT1 to TAI, UTC, TT 1118 time2 = NULL; 1119 time1->sec = 1; 1120 time1->nsec = 2; 1121 time1->type = PS_TIME_UT1; 1122 time1->leapsecond = false; 1123 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message converting from UT1"); 1124 time2 = psTimeConvert(time1,PS_TIME_UTC); 1125 if(time2 != time1) { 1126 psError(PS_ERR_UNKNOWN,true,"Did not return time for conversion from UT1"); 1127 return 23; 1128 } 1129 1130 psFree(time1); 1131 1132 return 0; 1133 } 1134 1135 //psS32 testTimeOther(void) 1136 //{ 1137 // psTime *testTime; 1138 // char *testString = "2004-07-21T18:22:24.272Z"; 1139 // 1140 // psLibInit(true,"psTime.config"); 1141 // 1142 // Test time was taken at July 21, 2004 at 18:22:24.272044 1143 // testTime = (psTime*)psAlloc(sizeof(psTime)); 1144 // testTime->sec = 1090434144; 1145 // testTime->nsec = 272044000; 1146 // testTime->type = PS_TIME_TAI; 1147 1148 // Test O - psTime to LMST 1149 // printPositiveTestHeader(stdout, "psTime", "Convert psTime time to LST"); 1150 // char *testString2 = "2004-09-10T1:00:00.00Z"; 1151 // psTime* testTime2 = NULL; 1152 // testTime2 = psTimeFromISO(testString2); 1153 // double dblTime = psTimeToLMST(testTime2, 1); 1154 // printf("LST (rad): %lf\n", dblTime); 1155 // psFree(testTime2); 1156 // printFooter(stdout, "psTime", "Convert psTime time to LST", true); 1157 1158 1159 // return 0; 1160 //} -
trunk/psLib/test/astronomy/tst_psTime_03.c
r3712 r4059 1 2 1 /** @file tst_psTime_03.c 3 2 * … … 5 4 * 6 5 * This test driver contains the following tests for psTime: 7 * 8 * Test A - Add two times 9 * Test B - Add two times with overflow in microseconds 10 * Test C - Subtact two times 11 * Test D - Subtact two times with underflow in microseconds 12 * Test E - Delta two times 13 * Test F - Delta two times with underflow in microseconds 14 * Test G - Add two times across leapsecond boundary 15 * Test H - Find number of leapseconds added between two times 16 * Test H1 - Verify error message to invalid time type in psTimeAlloc 17 * Test G - Free data 6 * 1) psTimeMath invalid times 7 * 2) psTimeMath valid time of different types 8 * 3) psTimeDelta valid times with different types 18 9 * 19 10 * @author Ross Harman, MHPCC 11 * @author Eric Van Alst, MHPCC 20 12 * 21 * @version $Revision: 1.1 6$ $Name: not supported by cvs2svn $22 * @date $Date: 2005-0 4-19 02:13:53$13 * @version $Revision: 1.17 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2005-05-31 22:01:27 $ 23 15 * 24 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 28 20 #include "pslib_strict.h" 29 21 #include "psTest.h" 30 31 #define PRINT_TIME(TEXT,TIME) \ 32 printf("%s Seconds = %lld Nanoseconds = %u\n", TEXT, (long long int)TIME->sec, TIME->nsec); 22 #include <string.h> 23 24 #define ERROR_TOL 0.001 25 26 static psS32 testTimeMath(void); 27 static psS32 testTimeDelta(void); 28 static psS32 testTimeConvert1(void); 29 30 // Test Time 1 : May 9, 2005 00:00:00,0 31 // MJD = 53499.00 32 // JD = 2453499.5 33 // UTC Test Time 1 34 const psS64 testTime1SecondsUTC = 1115596900; 35 const psU32 testTime1NanosecondsUTC = 0; 36 // TAI Test Time 1 37 const psS64 testTime1SecondsTAI = 1115596932; 38 const psU32 testTime1NanosecondsTAI = 0; 39 // TT Test Time 1 40 const psS64 testTime1SecondsTT = 1115596964; 41 const psU32 testTime1NanosecondsTT = 184000000; 42 // UT1 Test Time 1 43 const psS64 testTime1SecondsUT1 = 1115596900; 44 const psU32 testTime1NanosecondsUT1 = 184000000; 45 // Delta 1 46 const psF64 deltaTime1 = -15.5; 47 // Expected UTC Time 1 48 const psS64 newTestTime1SecondsUTC = 1115596884; 49 const psU32 newTestTime1NanosecondsUTC = 500000000; 50 // Expected TAI Time 1 51 const psS64 newTestTime1SecondsTAI = 1115596916; 52 const psU32 newTestTime1NanosecondsTAI = 500000000; 53 // Delta 2 54 const psF64 deltaTime2 = 123.066; 55 // Expected TT Time 1 w/ delta 2 56 const psS64 newTestTime1SecondsTT = 1115597087; 57 const psU32 newTestTime1NanosecondsTT = 250000000; 58 // Expected UT1 Time 1 w/ delta 2 59 const psS64 newTestTime1SecondsUT1 = 1115597023; 60 const psU32 newTestTime1NanosecondsUT1 = 250000000; 61 62 // Test Time 2 : Dec. 31 1998 23:59:45,0 63 // MJD = 51178.99983 64 // JD = 2451179.49983 65 // UTC Test Time 1 66 const psS64 testTime2SecondsUTC = 915148785; 67 const psU32 testTime2NanosecondsUTC = 0; 68 // Delta 3 69 const psF64 deltaTime3 = 30.0; 70 // Expected UTC Time 71 const psS64 newTestTime2SecondsUTC = 915148814; 72 const psU32 newTestTime2NanosecondsUTC = 0; 73 74 // Appendix B time conversion tests 75 // 76 #define APPB_TESTS 8 77 const psS64 testTimeBSeconds[APPB_TESTS] = 78 { 79 915148829, 80 915148829, 81 915148830, 82 915148830, 83 915148831, 84 915148831, 85 915148832, 86 915148832 87 }; 88 const psU32 testTimeBNanoseconds[APPB_TESTS] = 89 { 90 0, 91 500000000, 92 0, 93 500000000, 94 0, 95 500000000, 96 0, 97 500000000 98 }; 99 const psBool testTimeBLeapsecond[APPB_TESTS] = 100 { 101 false, 102 false, 103 false, 104 false, 105 true, 106 true, 107 false, 108 false 109 }; 110 // Expected results 111 const char* testTimeBStrUTC[APPB_TESTS] = 112 { 113 "1998-12-31T23:59:58,0Z", 114 "1998-12-31T23:59:58,5Z", 115 "1998-12-31T23:59:59,0Z", 116 "1998-12-31T23:59:59,5Z", 117 "1998-12-31T23:59:60,0Z", 118 "1998-12-31T23:59:60,5Z", 119 "1999-01-01T00:00:00,0Z", 120 "1999-01-01T00:00:00,5Z" 121 }; 122 const char* testTimeBStrTAI[APPB_TESTS] = 123 { 124 "1999-01-01T00:00:29,0Z", 125 "1999-01-01T00:00:29,5Z", 126 "1999-01-01T00:00:30,0Z", 127 "1999-01-01T00:00:30,5Z", 128 "1999-01-01T00:00:31,0Z", 129 "1999-01-01T00:00:31,5Z", 130 "1999-01-01T00:00:32,0Z", 131 "1999-01-01T00:00:32,5Z" 132 }; 133 const char* testTimeBStrTT[APPB_TESTS] = 134 { 135 "1999-01-01T00:01:01,1Z", 136 "1999-01-01T00:01:01,6Z", 137 "1999-01-01T00:01:02,1Z", 138 "1999-01-01T00:01:02,6Z", 139 "1999-01-01T00:01:03,1Z", 140 "1999-01-01T00:01:03,6Z", 141 "1999-01-01T00:01:04,1Z", 142 "1999-01-01T00:01:04,6Z" 143 }; 144 const char* testTimeBStrUT1[APPB_TESTS] = 145 { 146 "1998-12-31T23:59:58,7Z", 147 "1998-12-31T23:59:59,2Z", 148 "1998-12-31T23:59:59,7Z", 149 "1998-12-31T23:59:60,2Z", 150 "1998-12-31T23:59:60,7Z", 151 "1999-01-01T00:00:00,2Z", 152 "1999-01-01T00:00:00,7Z", 153 "1999-01-01T00:00:01,2Z" 154 }; 155 156 // Test Time B1 : Dec 31, 1998 23:59:58,0 157 // MJD = 51178.99998 158 // JD = 2451179.49998 159 //const psS64 testTimeB1SecondsUTC = 915148798; 160 //const psU32 testTimeB1NanosecondsUTC = 0; 161 // Expected ISO times 162 //const char testTimeB1StrUTC[] = "1998-12-31T23:59:58,0Z"; 163 //const char testTimeB1StrTAI[] = "1999-01-01T00:00:29,0Z"; 164 //const char testTimeB1StrTT[] = "1999-01-01T00:01:01,1Z"; 165 //const char testTimeB1StrUT1[] = "1998-12-31T23:59:57,7Z"; 166 // 167 // Test Time B2 : Dec 31, 1998 23:59:58,5 168 // 169 // 170 //const psS64 testTimeB2SecondsUTC = 915148798; 171 //const psU32 testTimeB2NanosecondsUTC = 500000000; 172 // Expected ISO times 173 //const char testTimeB2StrUTC[] = "1998-12-31T23:59:58,5Z"; 174 //const char testTimeB2StrTAI[] = "1991-01-01T00:00:29,5Z"; 175 //const char testTimeB2StrTT[] = "1999-01-01T00:01:01,6Z"; 176 //const char testTimeB2StrUT1[] = "1998-12-31T23:59:58,2Z"; 177 178 testDescription tests[] = { 179 {testTimeMath,000,"psTimeMath",0,false}, 180 {testTimeDelta,000,"psTimeDelta",0,false}, 181 {testTimeConvert1,000,"psTimeConvert",0,false}, 182 {NULL} 183 }; 33 184 34 185 psS32 main(psS32 argc, char* argv[]) 35 186 { 36 187 psLogSetLevel(PS_LOG_INFO); 188 189 // Initialize library internal structures 37 190 psLibInit(true,"psTime.config"); 38 191 39 // Test A - Add two times 40 printPositiveTestHeader(stdout, "psTime", "Test A - Add two times"); 41 psTime *time1a = NULL; 42 psF64 time1b = 1.111111; 43 psTime *timeOut1 = NULL; 44 time1a = psTimeAlloc(PS_TIME_TAI); 45 time1a->sec = 1; 46 time1a->nsec = 111111000; 47 timeOut1 = psTimeMath(time1a, time1b); 48 if(timeOut1->sec!=2 && timeOut1->nsec!=222222000) { 49 printf("ERROR: Incorrect time, %lld:%u. Expected 2:222222000\n",(long long int)timeOut1->sec, timeOut1->nsec); 50 } 51 printFooter(stdout, "psTime", "Test A - Add two times", true); 52 53 54 // Test B - Add two times with overflow in nanoseconds 55 printPositiveTestHeader(stdout, "psTime", "Test B - Add two times with overflow in microseconds"); 56 psTime *time2a = NULL; 57 psF64 time2b = 5.500001; 58 psTime *timeOut2 = NULL; 59 time2a = psTimeAlloc(PS_TIME_TAI); 60 time2a->sec = 6; 61 time2a->nsec = 600001000; 62 timeOut2 = psTimeMath(time2a, time2b); 63 if(timeOut2->sec!=12 && timeOut2->nsec!=100002000) { 64 printf("ERROR: Incorrect time, %lld:%u. Expected 12:100002000\n",(long long int)timeOut2->sec, timeOut2->nsec); 65 } 66 printFooter(stdout, "psTime", "Test B - Add two times with overflow in microseconds", true); 67 68 69 // Test C - Subtact two times 70 printPositiveTestHeader(stdout, "psTime", "Test C - Subtract two times"); 71 psTime *time3a = NULL; 72 psF64 time3b = -1.111111; 73 psTime *timeOut3 = NULL; 74 time3a = psTimeAlloc(PS_TIME_TAI); 75 time3a->sec = 3; 76 time3a->nsec = 333333000; 77 timeOut3 = psTimeMath(time3a, time3b); 78 if(timeOut3->sec!=2 && timeOut3->nsec!=222222000) { 79 printf("ERROR: Incorrect time, %lld:%u. Expected 2:222222000\n",(long long int)timeOut3->sec, timeOut3->nsec); 80 } 81 printFooter(stdout, "psTime", "Test C - Subtract two times", true); 82 83 84 // Test D - Subtact two times with underflow in nanoseconds 85 printPositiveTestHeader(stdout, "psTime", "Test D - Subtact two times with underflow in nanoseconds"); 86 psTime *time4a = NULL; 87 psF64 time4b = -2.000003; 88 psTime *timeOut4 = NULL; 89 time4a = psTimeAlloc(PS_TIME_TAI); 90 time4a->sec = 5; 91 time4a->nsec = 1000; 92 timeOut4 = psTimeMath(time4a, time4b); 93 if(timeOut4->sec!=2 && timeOut4->nsec!=999997000) { 94 printf("ERROR: Incorrect time, %lld:%u. Expected 2:999997000\n",(long long int)timeOut4->sec, timeOut4->nsec); 95 } 96 printFooter(stdout, "psTime", "Test D - Subtact two times with underflow in nanoseconds", true); 97 98 99 // Test E - Delta two times 100 printPositiveTestHeader(stdout, "psTime", "Test E - Delta two times"); 101 psTime *time5a = NULL; 102 psTime *time5b = NULL; 103 psF64 timeOut5 = 0.0; 104 time5a = psTimeAlloc(PS_TIME_TAI); 105 time5b = psTimeAlloc(PS_TIME_TAI); 106 time5a->sec = 8; 107 time5a->nsec = 8000; 108 time5b->sec = 7; 109 time5b->nsec = 7000; 110 timeOut5 = psTimeDelta(time5a, time5b); 111 if(fabs(timeOut5-1.000001) > FLT_EPSILON) { 112 printf("ERROR: Incorrect delta, %lf. Expected -1.000001\n", timeOut5); 113 } 114 printFooter(stdout, "psTime", "Test E - Delta two times", true); 115 116 117 // Test F - Delta two times with underflow in microseconds 118 printPositiveTestHeader(stdout, "psTime", "Test F - Delta two times with underflow in microseconds"); 119 psTime *time6a = NULL; 120 psTime *time6b = NULL; 121 psF64 timeOut6 = 0.0; 122 time6a = psTimeAlloc(PS_TIME_TAI); 123 time6b = psTimeAlloc(PS_TIME_TAI); 124 time6a->sec = 8; 125 time6a->nsec = 1000; 126 time6b->sec = 7; 127 time6b->nsec = 7000; 128 timeOut6 = psTimeDelta(time6a, time6b); 129 if(fabs(timeOut6-0.999994) > FLT_EPSILON) { 130 printf("ERROR: Incorrect delta, %lf. Expected 0.999994\n", timeOut6); 131 } 132 printFooter(stdout, "psTime", "Test F - Delta two times with underflow in microseconds", true); 133 134 // Test F1 - Delta two times in UTC type 135 printPositiveTestHeader(stdout,"psTime","Test F1 - Delta two UTC times"); 136 psTime *time20a = NULL; 137 psTime *time20b = NULL; 138 psF64 timeOut20 = 0.0; 139 time20a = psTimeAlloc(PS_TIME_UTC); 140 time20b = psTimeAlloc(PS_TIME_UTC); 141 time20a->sec = 1090434113; 142 time20a->nsec = 272044000; 143 time20b->sec = 1090434112; 144 time20b->nsec = 272044000; 145 timeOut20 = psTimeDelta(time20a, time20b); 146 if(fabs(timeOut20-1.000000000) > FLT_EPSILON) { 147 printf("ERROR: Incorrect delta, %lf. Expected -1.00000\n",timeOut20); 148 } 149 printFooter(stdout,"psTime","Test F1 - Delta two UTC times",true); 150 151 // Test G - Add two times across leapsecond boundary 152 printPositiveTestHeader(stdout, "psTime", "Test G - Add two times across leapsecond boundary"); 153 psF64 time7b = 30.0; 154 char *out7 = NULL; 155 psTime *time7a = NULL; 156 psTime *timeOut7 = NULL; 157 time7a = psTimeFromISO("1998-12-31T23:59:45.00"); 158 time7a->type = PS_TIME_UTC; 159 timeOut7 = psTimeMath(time7a, time7b); 160 out7 = psTimeToISO(timeOut7); 161 printf("%s\n", out7); 162 printFooter(stdout, "psTime", "Test G - Add two times across leapsecond boundary", true); 163 164 165 // Test H - Find number of leapseconds added between two times 166 printPositiveTestHeader(stdout, "psTime", "Test H - Find number of leapseconds added between two times"); 167 psS64 out = 0.0; 168 psTime *time8a = NULL; 169 psTime *time8b = NULL; 170 time8a = psTimeFromISO("2004-12-18T1:00:00.00"); 171 time8b = psTimeFromISO("1972-1-1T1:00:00.00"); 172 out = psTimeLeapSecondDelta(time8a, time8b); 173 printf("%lld\n", (long long int)out); 174 printFooter(stdout, "psTime", "Test H - Find number of leapseconds added between two times", true); 175 176 // Test H1 - Error in allocating time not UTC or TAI 177 printPositiveTestHeader(stdout,"psTime","Test H1 - Verify error message in allocating invalid time type"); 178 psLogMsg(__func__,PS_LOG_INFO,"Invalid time type during allocation should generate error message"); 179 psTime *time10 = psTimeAlloc(10); 180 if(time10 != NULL) { 181 printf("ERROR: returned time should be NULL\n"); 182 } 183 printFooter(stdout,"psTime","Test H1 - Verify error message in allocating invalid time type",true); 184 185 // Test G - Free data 186 printPositiveTestHeader(stdout, "psTime", "Test I - Free data"); 192 if( !runTestSuite(stderr,"psTime",tests,argc,argv)) { 193 return 1; 194 } 195 196 // Clean up library 187 197 psLibFinalize(); 188 psFree(time1a); 189 psFree(timeOut1); 190 psFree(time2a); 191 psFree(timeOut2); 192 psFree(time3a); 193 psFree(timeOut3); 194 psFree(time4a); 195 psFree(timeOut4); 196 psFree(time5a); 197 psFree(time5b); 198 psFree(time6a); 199 psFree(time6b); 200 psFree(out7); 201 psFree(time7a); 202 psFree(timeOut7); 203 psFree(time8a); 204 psFree(time8b); 205 psFree(time20a); 206 psFree(time20b); 207 if (psMemCheckLeaks(0, NULL, stdout,false)) { 208 psError(PS_ERR_UNKNOWN,true,"Memory leaks detected."); 209 return 10; 210 } 211 psMemCheckCorruption(0); 212 psS32 nBad = psMemCheckCorruption(0); 213 if(nBad) { 214 printf("ERROR: Found %d bad memory blocks\n", nBad); 215 } 216 printFooter(stdout, "psTime", "Test I - Free data", true); 198 217 199 return 0; 218 200 } 201 202 psS32 testTimeMath(void) 203 { 204 psTime* time = NULL; 205 psTime* newTime = NULL; 206 207 // Attempt to perform math operation on NULL time 208 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL time"); 209 if(psTimeMath(time,-1.1) != NULL) { 210 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for NULL time"); 211 return 1; 212 } 213 214 // Set up input time with invalid nanoseconds 215 time = psTimeAlloc(PS_TIME_UTC); 216 time->sec = 0; 217 time->nsec = 2e9; 218 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for invalid time"); 219 if(psTimeMath(time,-1.1) != NULL) { 220 psError(PS_ERR_UNKNOWN,true,"Did not return NULL for invalid time"); 221 return 2; 222 } 223 224 // Set up input time with valid time 225 time->sec = testTime1SecondsUTC; 226 time->nsec = testTime1NanosecondsUTC; 227 newTime = psTimeMath(time,deltaTime1); 228 if(newTime == NULL) { 229 psError(PS_ERR_UNKNOWN,true,"Did not expect NULL return"); 230 return 3; 231 } 232 if(newTime->type != PS_TIME_UTC) { 233 psError(PS_ERR_UNKNOWN,true,"New time type %d not as expected %d", 234 newTime->type,PS_TIME_UTC); 235 return 4; 236 } 237 if((newTime->sec != newTestTime1SecondsUTC) || (newTime->nsec != newTestTime1NanosecondsUTC)) { 238 psError(PS_ERR_UNKNOWN,true,"UTC sec %ld nsec %d not as expected sec %ld nsec %d", 239 (long int)newTime->sec,newTime->nsec,(long int)newTestTime1SecondsUTC, 240 newTestTime1NanosecondsUTC); 241 return 5; 242 } 243 psFree(newTime); 244 245 // Set up input time with valid TAI time 246 time->sec = testTime1SecondsTAI; 247 time->nsec = testTime1NanosecondsTAI; 248 time->type = PS_TIME_TAI; 249 newTime = psTimeMath(time,deltaTime1); 250 if(newTime == NULL) { 251 psError(PS_ERR_UNKNOWN,true,"Did not expect NULL return"); 252 return 3; 253 } 254 if(newTime->type != PS_TIME_TAI) { 255 psError(PS_ERR_UNKNOWN,true,"New time type %d not as expected %d", 256 newTime->type,PS_TIME_TAI); 257 return 4; 258 } 259 if((newTime->sec != newTestTime1SecondsTAI) || (newTime->nsec != newTestTime1NanosecondsTAI)) { 260 psError(PS_ERR_UNKNOWN,true,"TAI sec %ld nsec %d not as expected sec %ld nsec %d", 261 (long int)newTime->sec,newTime->nsec,(long int)newTestTime1SecondsTAI, 262 newTestTime1NanosecondsTAI); 263 return 5; 264 } 265 psFree(newTime); 266 267 // Set up input time with valid TT time 268 time->sec = testTime1SecondsTT; 269 time->nsec = testTime1NanosecondsTT; 270 time->type = PS_TIME_TT; 271 newTime = psTimeMath(time,deltaTime2); 272 if(newTime == NULL) { 273 psError(PS_ERR_UNKNOWN,true,"Did not expect NULL return"); 274 return 3; 275 } 276 if(newTime->type != PS_TIME_TT) { 277 psError(PS_ERR_UNKNOWN,true,"New time type %d not as expected %d", 278 newTime->type,PS_TIME_TT); 279 return 4; 280 } 281 if((newTime->sec != newTestTime1SecondsTT) || (newTime->nsec != newTestTime1NanosecondsTT)) { 282 psError(PS_ERR_UNKNOWN,true,"TT sec %ld nsec %d not as expected sec %ld nsec %d", 283 (long int)newTime->sec,newTime->nsec,(long int)newTestTime1SecondsTT, 284 newTestTime1NanosecondsTT); 285 return 5; 286 } 287 psFree(newTime); 288 289 // Set up input time with valid TT time 290 time->sec = testTime1SecondsUT1; 291 time->nsec = testTime1NanosecondsUT1; 292 time->type = PS_TIME_UT1; 293 newTime = psTimeMath(time,deltaTime2); 294 if(newTime == NULL) { 295 psError(PS_ERR_UNKNOWN,true,"Did not expect NULL return"); 296 return 3; 297 } 298 if(newTime->type != PS_TIME_UT1) { 299 psError(PS_ERR_UNKNOWN,true,"New time type %d not as expected %d", 300 newTime->type,PS_TIME_UT1); 301 return 4; 302 } 303 if((newTime->sec != newTestTime1SecondsUT1) || (newTime->nsec != newTestTime1NanosecondsUT1)) { 304 psError(PS_ERR_UNKNOWN,true,"UT1 sec %ld nsec %d not as expected sec %ld nsec %d", 305 (long int)newTime->sec,newTime->nsec,(long int)newTestTime1SecondsUT1, 306 newTestTime1NanosecondsUT1); 307 return 5; 308 } 309 psFree(newTime); 310 311 // Set up input time with valid UTC time and delt which crosses leap second 312 time->sec = testTime2SecondsUTC; 313 time->nsec = testTime2NanosecondsUTC; 314 time->type = PS_TIME_UTC; 315 newTime = psTimeMath(time,deltaTime3); 316 if(newTime == NULL) { 317 psError(PS_ERR_UNKNOWN,true,"Did not expect NULL return"); 318 return 3; 319 } 320 if(newTime->type != PS_TIME_UTC) { 321 psError(PS_ERR_UNKNOWN,true,"New time type %d not as expected %d", 322 newTime->type,PS_TIME_UTC); 323 return 4; 324 } 325 if((newTime->sec != newTestTime2SecondsUTC) || (newTime->nsec != newTestTime2NanosecondsUTC)) { 326 psError(PS_ERR_UNKNOWN,true,"UTC sec %ld nsec %d not as expected sec %ld nsec %d", 327 (long int)newTime->sec,newTime->nsec,(long int)newTestTime2SecondsUTC, 328 newTestTime2NanosecondsUTC); 329 return 5; 330 } 331 psFree(newTime); 332 333 psFree(time); 334 335 return 0; 336 } 337 338 psS32 testTimeDelta(void) 339 { 340 psTime* time1 = NULL; 341 psTime* time2 = NULL; 342 psF64 delta = 0.0; 343 344 // Attempt to get delta with time1 NULL 345 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL time"); 346 delta = psTimeDelta(time1,time2); 347 if(fabs(delta-0.0) > ERROR_TOL) { 348 psError(PS_ERR_UNKNOWN,true,"Did not return 0 for NULL time argument"); 349 return 1; 350 } 351 352 // Set time 1 353 time1 = psTimeAlloc(PS_TIME_UTC); 354 355 // Attempt to get delta with time2 NULL 356 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for NULL time"); 357 delta = psTimeDelta(time1,time2); 358 if(fabs(delta-0.0) > ERROR_TOL) { 359 psError(PS_ERR_UNKNOWN,true,"Did not return 0 for NULL time argument"); 360 return 2; 361 } 362 363 // Set time 2 364 time2 = psTimeAlloc(PS_TIME_UTC); 365 366 // Set time1 invalid 367 time1->sec = 0; 368 time1->nsec = 2e9; 369 // Attempt to get delta with time1 invalid 370 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for invalid time"); 371 delta = psTimeDelta(time1,time2); 372 if(fabs(delta-0.0) > ERROR_TOL) { 373 psError(PS_ERR_UNKNOWN,true,"Did not return 0 for invalid time argument"); 374 return 3; 375 } 376 377 // Set time 1 valid 378 time1->sec = testTime1SecondsUTC; 379 time1->nsec = testTime1NanosecondsUTC; 380 381 // Set time 2 invalid 382 time2->sec = 0; 383 time2->nsec = 2e9; 384 // Attempt to get delta with time2 invalid 385 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for invalid time"); 386 delta = psTimeDelta(time1,time2); 387 if(fabs(delta-0.0) > ERROR_TOL) { 388 psError(PS_ERR_UNKNOWN,true,"Did not return 0 for invalid time argument"); 389 return 4; 390 } 391 392 // Set time 2 valid but different type 393 time2->sec = newTestTime1SecondsUTC; 394 time2->nsec = newTestTime1NanosecondsUTC; 395 time2->type = PS_TIME_TAI; 396 // Attempt to get delta with different time types 397 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for incorrect type"); 398 delta = psTimeDelta(time1,time2); 399 if(fabs(delta-0.0) > ERROR_TOL) { 400 psError(PS_ERR_UNKNOWN,true,"Did not return 0 for invalid time argument"); 401 return 5; 402 } 403 404 // Set time 2 to same as time 1 405 time2->type = PS_TIME_UTC; 406 // Attempt to get delta with valid times of the same type 407 delta = psTimeDelta(time2,time1); 408 if(fabs(delta-deltaTime1) > ERROR_TOL) { 409 psError(PS_ERR_UNKNOWN,true,"Delta %lf not as expected %lf", 410 delta,deltaTime1); 411 return 6; 412 } 413 414 // Set time 1 and 2 as different times with same type 415 time1->sec = testTime1SecondsTT; 416 time1->nsec = testTime1NanosecondsTT; 417 time1->type = PS_TIME_TT; 418 time2->sec = newTestTime1SecondsTT; 419 time2->nsec = newTestTime1NanosecondsTT; 420 time2->type = PS_TIME_TT; 421 // Attempt to get delta with valid times of the same type 422 delta = psTimeDelta(time2,time1); 423 if(fabs(delta-deltaTime2) > ERROR_TOL) { 424 psError(PS_ERR_UNKNOWN,true,"Delta %lf not as expected %lf", 425 delta,deltaTime2); 426 return 7; 427 } 428 429 // Set time 1 and 2 as different times with same type 430 time1->sec = testTime2SecondsUTC; 431 time1->nsec = testTime2NanosecondsUTC; 432 time1->type = PS_TIME_UTC; 433 time2->sec = newTestTime2SecondsUTC; 434 time2->nsec = newTestTime2NanosecondsUTC; 435 time2->type = PS_TIME_UTC; 436 // Attempt to get delta with valid times of the same type 437 delta = psTimeDelta(time2,time1); 438 if(fabs(delta-deltaTime3) > ERROR_TOL) { 439 psError(PS_ERR_UNKNOWN,true,"Delta %lf not as expected %lf", 440 delta,deltaTime3); 441 return 7; 442 } 443 444 psFree(time1); 445 psFree(time2); 446 447 return 0; 448 } 449 450 psS32 testTimeConvert1(void) 451 { 452 psTime* time = NULL; 453 char* timeStr = NULL; 454 455 for(psS32 i = 0; i < APPB_TESTS; i++) { 456 457 // Initialize time for test time B1 458 time = psTimeAlloc(PS_TIME_TAI); 459 time->sec = testTimeBSeconds[i]; 460 time->nsec = testTimeBNanoseconds[i]; 461 462 // Verify TAI ISO string 463 timeStr = psTimeToISO(time); 464 if(strcmp(timeStr,testTimeBStrTAI[i]) != 0) { 465 psError(PS_ERR_UNKNOWN,true,"TAI ISO string %s not as expected %s",timeStr,testTimeBStrTAI[i]); 466 return i+1; 467 } 468 psFree(timeStr); 469 470 time = psTimeConvert(time,PS_TIME_TT); 471 timeStr = psTimeToISO(time); 472 if(strcmp(timeStr,testTimeBStrTT[i]) != 0) { 473 psError(PS_ERR_UNKNOWN,true,"TT ISO string %s not as expected %s",timeStr,testTimeBStrTT[i]); 474 return i+10; 475 } 476 psFree(timeStr); 477 478 // Verify UTC ISO string 479 time = psTimeConvert(time,PS_TIME_UTC); 480 time->leapsecond = testTimeBLeapsecond[i]; 481 timeStr = psTimeToISO(time); 482 if(strcmp(timeStr,testTimeBStrUTC[i]) != 0) { 483 psError(PS_ERR_UNKNOWN,true,"UTC ISO string %s not as expected %s",timeStr,testTimeBStrUTC[i]); 484 return i+20; 485 } 486 psFree(timeStr); 487 488 time = psTimeConvert(time,PS_TIME_UT1); 489 timeStr = psTimeToISO(time); 490 if(strcmp(timeStr,testTimeBStrUT1[i]) != 0) { 491 psError(PS_ERR_UNKNOWN,true,"UT1 ISO string %s not as expected %s",timeStr,testTimeBStrUT1[i]); 492 return i+30; 493 } 494 psFree(timeStr); 495 496 psFree(time); 497 } 498 499 return 0; 500 } 501 -
trunk/psLib/test/astronomy/tst_psTime_04.c
r3682 r4059 13 13 * 14 14 * @author Ross Harman, MHPCC 15 * @author Eric Van Alst, MHPCC 15 16 * 16 * @version $Revision: 1.1 1$ $Name: not supported by cvs2svn $17 * @date $Date: 2005-0 4-07 20:27:41$17 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $ 18 * @date $Date: 2005-05-31 22:02:25 $ 18 19 * 19 20 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 25 26 #include "psTest.h" 26 27 28 static psS32 testTimeInit1(void); 29 static psS32 testTimeInit2(void); 30 static psS32 testTimeInit3(void); 31 static psS32 testTimeInit4(void); 32 static psS32 testTimeInit5(void); 33 static psS32 testTimeInit6(void); 27 34 28 int main(int argc, char* argv[]) 35 testDescription tests[] = { 36 {testTimeInit1,000,"p_psTimeInit",0,false}, 37 {testTimeInit2,000,"p_psTimeInit",0,false}, 38 {testTimeInit3,000,"p_psTimeInit",0,false}, 39 {testTimeInit4,000,"p_psTimeInit",0,false}, 40 {testTimeInit5,000,"p_psTimeInit",0,false}, 41 {testTimeInit6,000,"p_psTimeInit",0,false}, 42 {NULL} 43 }; 44 45 psS32 main(psS32 argc, char* argv[]) 29 46 { 30 // Test A - Initialize time 31 printPositiveTestHeader(stdout, "psTime", "Test A - Initialize time"); 32 psLibInit(true, "psTime.config"); 33 psLibFinalize(); 34 printFooter(stdout, "psTime", "Test A - Initialize time", true); 35 36 37 // Test B - Attempt to open non-existant time config file 38 printNegativeTestHeader(stdout,"psTime", "Test B - Attempt to open non-existant time config file", 39 "Failed to open file 'zzz'. Check if it exists and it has the proper permissions.", 0); 40 psLibInit(true, "zzz"); 41 printFooter(stdout, "psTime", "Test B - Attempt to open non-existant time config file", true); 42 43 44 // Test C - Attempt to open non-existant time data files 45 printNegativeTestHeader(stdout,"psTime", "Test C - Attempt to open non-existant time data files", 46 "Failed to open file 'zzz'. Check if it exists and it has the proper permissions.", 0); 47 psLibInit(true, "test.psTime.config1"); 48 psLibFinalize(); 49 printFooter(stdout, "psTime", "Test C - Attempt to open non-existant time data files", true); 50 51 52 // Test D - Attempt to read incorrect number of files 53 printNegativeTestHeader(stdout,"psTime", "Test D - Attempt to read incorrect number of files", 54 "Incorrect number of table files entered. Found: 3. Expected: 4.", 0); 55 psLibInit(true, "test.psTime.config2"); 56 psLibFinalize(); 57 printFooter(stdout, "psTime", "Test D - Attempt to read incorrect number of files", true); 58 59 60 // Test E - Attempt to read incorrect number of from values 61 printNegativeTestHeader(stdout,"psTime", "Test E - Attempt to read incorrect number of from values", 62 "Incorrect vector size. Size: 3, Expected 4.", 0); 63 psLibInit(true, "test.psTime.config3"); 64 psLibFinalize(); 65 printFooter(stdout, "psTime", "Test E - Attempt to read incorrect number of from values", true); 66 67 68 // Test F - Attempt to read data file with typo in number 69 printNegativeTestHeader(stdout,"psTime", "Test F - Attempt to read data file with typo in number", 70 "Unable to parse string, number on line 16.", 0); 71 psLibInit(true, "test.psTime.config4"); 72 psLibFinalize(); 73 printFooter(stdout, "psTime", "Test F - Attempt to read data file with typo in number", true); 74 75 76 // Test G - Free data 77 printPositiveTestHeader(stdout, "psTime", "Test G - Free data"); 78 psLibFinalize(); 79 if( psMemCheckLeaks(0, NULL, stdout,false) != 0 ) { 80 psError(PS_ERR_UNKNOWN,true,"Memory leak detected."); 81 return 10; 47 if(!runTestSuite(stderr,"psTime",tests,argc,argv)) { 48 return 1; 82 49 } 83 psMemCheckCorruption(0);84 int nBad = psMemCheckCorruption(0);85 if(nBad) {86 printf("ERROR: Found %d bad memory blocks\n", nBad);87 }88 printFooter(stdout, "psTime", "Test G - Free data", true);89 50 90 51 return 0; 91 52 } 92 53 54 psS32 testTimeInit1(void) 55 { 56 // Test A - Initialize time 57 psLibInit(true, "psTime.config"); 58 psLibFinalize(); 59 60 return 0; 61 } 62 63 psS32 testTimeInit2(void) 64 { 65 // Test B - Attempt to open non-existant time config file 66 psLibInit(true, "zzz"); 67 68 return 0; 69 } 70 71 psS32 testTimeInit3(void) 72 { 73 // Test C - Attempt to open non-existant time data files 74 psLibInit(true, "test.psTime.config1"); 75 psLibFinalize(); 76 77 return 0; 78 } 79 80 psS32 testTimeInit4(void) 81 { 82 // Test D - Attempt to read incorrect number of files 83 psLibInit(true, "test.psTime.config2"); 84 psLibFinalize(); 85 86 return 0; 87 } 88 89 psS32 testTimeInit5(void) 90 { 91 // Test E - Attempt to read incorrect number of from values 92 psLibInit(true, "test.psTime.config3"); 93 psLibFinalize(); 94 95 return 0; 96 } 97 98 psS32 testTimeInit6(void) 99 { 100 // Test F - Attempt to read data file with typo in number 101 psLibInit(true, "test.psTime.config4"); 102 psLibFinalize(); 103 104 return 0; 105 } 106 -
trunk/psLib/test/astronomy/verified/tst_psTime_01.stdout
r3712 r4059 1 /***************************** TESTPOINT ******************************************\2 * TestFile: tst_psTime_01.c *3 * TestPoint: psTime{Get current TAI time} *4 * TestType: Positive *5 \**********************************************************************************/6 7 8 ---> TESTPOINT PASSED (psTime{Get current TAI time} | tst_psTime_01.c)9 10 /***************************** TESTPOINT ******************************************\11 * TestFile: tst_psTime_01.c *12 * TestPoint: psTime{Print test time} *13 * TestType: Positive *14 \**********************************************************************************/15 16 Test time: Seconds = 1090434144 Nanoseconds = 27204400017 18 ---> TESTPOINT PASSED (psTime{Print test time} | tst_psTime_01.c)19 20 /***************************** TESTPOINT ******************************************\21 * TestFile: tst_psTime_01.c *22 * TestPoint: psTime{Convert psTime to ISO time} *23 * TestType: Positive *24 \**********************************************************************************/25 26 2004-07-21T<DATE>.272Z27 28 ---> TESTPOINT PASSED (psTime{Convert psTime to ISO time} | tst_psTime_01.c)29 30 /***************************** TESTPOINT ******************************************\31 * TestFile: tst_psTime_01.c *32 * TestPoint: psTime{Convert ISO time to psTime} *33 * TestType: Positive *34 \**********************************************************************************/35 36 psTime: Seconds = 1090434144 Nanoseconds = 27200000037 38 ---> TESTPOINT PASSED (psTime{Convert ISO time to psTime} | tst_psTime_01.c)39 40 /***************************** TESTPOINT ******************************************\41 * TestFile: tst_psTime_01.c *42 * TestPoint: psTime{Convert psTime time to UTC time} *43 * TestType: Positive *44 \**********************************************************************************/45 46 psTime: Seconds = 1090434112 Nanoseconds = 27204400047 48 ---> TESTPOINT PASSED (psTime{Convert psTime time to UTC time} | tst_psTime_01.c)49 50 /***************************** TESTPOINT ******************************************\51 * TestFile: tst_psTime_01.c *52 * TestPoint: psTime{Convert UTC time to psTime} *53 * TestType: Positive *54 \**********************************************************************************/55 56 psTime: Seconds = 1090434144 Nanoseconds = 27204400057 58 ---> TESTPOINT PASSED (psTime{Convert UTC time to psTime} | tst_psTime_01.c)59 60 /***************************** TESTPOINT ******************************************\61 * TestFile: tst_psTime_01.c *62 * TestPoint: psTime{Convert psTime to MJD time} *63 * TestType: Positive *64 \**********************************************************************************/65 66 MJD = 53207.76555967 68 ---> TESTPOINT PASSED (psTime{Convert psTime to MJD time} | tst_psTime_01.c)69 70 /***************************** TESTPOINT ******************************************\71 * TestFile: tst_psTime_01.c *72 * TestPoint: psTime{Convert MJD time to psTime} *73 * TestType: Positive *74 \**********************************************************************************/75 76 psTime: Seconds = 1090434144 Nanoseconds = 27204370477 78 ---> TESTPOINT PASSED (psTime{Convert MJD time to psTime} | tst_psTime_01.c)79 80 /***************************** TESTPOINT ******************************************\81 * TestFile: tst_psTime_01.c *82 * TestPoint: psTime{Convert psTime to JD time} *83 * TestType: Positive *84 \**********************************************************************************/85 86 JD = 2453208.26555987 88 ---> TESTPOINT PASSED (psTime{Convert psTime to JD time} | tst_psTime_01.c)89 90 /***************************** TESTPOINT ******************************************\91 * TestFile: tst_psTime_01.c *92 * TestPoint: psTime{Convert JD time to psTime} *93 * TestType: Positive *94 \**********************************************************************************/95 96 psTime: Seconds = 1090434144 Nanoseconds = 27204871197 98 ---> TESTPOINT PASSED (psTime{Convert JD time to psTime} | tst_psTime_01.c)99 100 /***************************** TESTPOINT ******************************************\101 * TestFile: tst_psTime_01.c *102 * TestPoint: psTime{Convert psTime to timeval time} *103 * TestType: Positive *104 \**********************************************************************************/105 106 timevalTime: Seconds = 1090434144 Microseconds = 272044107 108 ---> TESTPOINT PASSED (psTime{Convert psTime to timeval time} | tst_psTime_01.c)109 110 /***************************** TESTPOINT ******************************************\111 * TestFile: tst_psTime_01.c *112 * TestPoint: psTime{Convert timeval time to psTime} *113 * TestType: Positive *114 \**********************************************************************************/115 116 psTime: Seconds = 1090434144 Nanoseconds = 272044000117 118 ---> TESTPOINT PASSED (psTime{Convert timeval time to psTime} | tst_psTime_01.c)119 120 /***************************** TESTPOINT ******************************************\121 * TestFile: tst_psTime_01.c *122 * TestPoint: psTime{Convert psTime to tm time} *123 * TestType: Positive *124 \**********************************************************************************/125 126 tmTime:127 tmTime->tm_year = 104128 tmTime->tm_mon = 6129 tmTime->tm_mday = 21130 tmTime->tm_hour = 18131 tmTime->tm_min = 22132 tmTime->tm_sec = 24133 134 ---> TESTPOINT PASSED (psTime{Convert psTime to tm time} | tst_psTime_01.c)135 136 /***************************** TESTPOINT ******************************************\137 * TestFile: tst_psTime_01.c *138 * TestPoint: psTime{Convert tm time to psTime} *139 * TestType: Positive *140 \**********************************************************************************/141 142 psTime: Seconds = 1090434144 Nanoseconds = 0143 144 ---> TESTPOINT PASSED (psTime{Convert tm time to psTime} | tst_psTime_01.c)145 146 /***************************** TESTPOINT ******************************************\147 * TestFile: tst_psTime_01.c *148 * TestPoint: psTime{Convert psTime time to LST} *149 * TestType: Positive *150 \**********************************************************************************/151 152 LST (rad): 1.074588153 154 ---> TESTPOINT PASSED (psTime{Convert psTime time to LST} | tst_psTime_01.c)155 156 /***************************** TESTPOINT ******************************************\157 * TestFile: tst_psTime_01.c *158 * TestPoint: psMetadata{Test P - Free data} *159 * TestType: Positive *160 \**********************************************************************************/161 162 163 ---> TESTPOINT PASSED (psMetadata{Test P - Free data} | tst_psTime_01.c)164 -
trunk/psLib/test/astronomy/verified/tst_psTime_03.stderr
r3127 r4059 1 <DATE><TIME>|<HOST>|I|main 2 Invalid time type during allocation should generate error message 3 <DATE><TIME>|<HOST>|E|psTimeAlloc (FILE:LINENO) 4 Specified type, 10, is not supported. 1 /***************************** TESTPOINT ******************************************\ 2 * TestFile: tst_psTime_03.c * 3 * TestPoint: psTime{psTimeMath} * 4 * TestType: Positive * 5 \**********************************************************************************/ 6 7 <DATE><TIME>|<HOST>|I|testTimeMath 8 Following should generate error message for NULL time 9 <DATE><TIME>|<HOST>|E|psTimeMath (FILE:LINENO) 10 Unallowable operation: time is NULL. 11 <DATE><TIME>|<HOST>|I|testTimeMath 12 Following should generate error message for invalid time 13 <DATE><TIME>|<HOST>|E|psTimeMath (FILE:LINENO) 14 Error: time->nsec, 2000000000, is out of range. Must be between 0 and 999999999. 15 16 ---> TESTPOINT PASSED (psTime{psTimeMath} | tst_psTime_03.c) 17 18 /***************************** TESTPOINT ******************************************\ 19 * TestFile: tst_psTime_03.c * 20 * TestPoint: psTime{psTimeDelta} * 21 * TestType: Positive * 22 \**********************************************************************************/ 23 24 <DATE><TIME>|<HOST>|I|testTimeDelta 25 Following should generate error message for NULL time 26 <DATE><TIME>|<HOST>|E|psTimeDelta (FILE:LINENO) 27 Unallowable operation: time1 is NULL. 28 <DATE><TIME>|<HOST>|I|testTimeDelta 29 Following should generate error message for NULL time 30 <DATE><TIME>|<HOST>|E|psTimeDelta (FILE:LINENO) 31 Unallowable operation: time2 is NULL. 32 <DATE><TIME>|<HOST>|I|testTimeDelta 33 Following should generate error message for invalid time 34 <DATE><TIME>|<HOST>|E|psTimeDelta (FILE:LINENO) 35 Error: time1->nsec, 2000000000, is out of range. Must be between 0 and 999999999. 36 <DATE><TIME>|<HOST>|I|testTimeDelta 37 Following should generate error message for invalid time 38 <DATE><TIME>|<HOST>|E|psTimeDelta (FILE:LINENO) 39 Error: time2->nsec, 2000000000, is out of range. Must be between 0 and 999999999. 40 <DATE><TIME>|<HOST>|I|testTimeDelta 41 Following should generate error message for incorrect type 42 <DATE><TIME>|<HOST>|E|psTimeDelta (FILE:LINENO) 43 Specified type, 1, is incorrect. 44 45 ---> TESTPOINT PASSED (psTime{psTimeDelta} | tst_psTime_03.c) 46 47 /***************************** TESTPOINT ******************************************\ 48 * TestFile: tst_psTime_03.c * 49 * TestPoint: psTime{psTimeConvert} * 50 * TestType: Positive * 51 \**********************************************************************************/ 52 53 54 ---> TESTPOINT PASSED (psTime{psTimeConvert} | tst_psTime_03.c) 55 -
trunk/psLib/test/astronomy/verified/tst_psTime_03.stdout
r3712 r4059 1 /***************************** TESTPOINT ******************************************\2 * TestFile: tst_psTime_03.c *3 * TestPoint: psTime{Test A - Add two times} *4 * TestType: Positive *5 \**********************************************************************************/6 7 8 ---> TESTPOINT PASSED (psTime{Test A - Add two times} | tst_psTime_03.c)9 10 /***************************** TESTPOINT ******************************************\11 * TestFile: tst_psTime_03.c *12 * TestPoint: psTime{Test B - Add two times with overflow in microseconds} *13 * TestType: Positive *14 \**********************************************************************************/15 16 17 ---> TESTPOINT PASSED (psTime{Test B - Add two times with overflow in microseconds} | tst_psTime_03.c)18 19 /***************************** TESTPOINT ******************************************\20 * TestFile: tst_psTime_03.c *21 * TestPoint: psTime{Test C - Subtract two times} *22 * TestType: Positive *23 \**********************************************************************************/24 25 26 ---> TESTPOINT PASSED (psTime{Test C - Subtract two times} | tst_psTime_03.c)27 28 /***************************** TESTPOINT ******************************************\29 * TestFile: tst_psTime_03.c *30 * TestPoint: psTime{Test D - Subtact two times with underflow in nanoseconds} *31 * TestType: Positive *32 \**********************************************************************************/33 34 35 ---> TESTPOINT PASSED (psTime{Test D - Subtact two times with underflow in nanoseconds} | tst_psTime_03.c)36 37 /***************************** TESTPOINT ******************************************\38 * TestFile: tst_psTime_03.c *39 * TestPoint: psTime{Test E - Delta two times} *40 * TestType: Positive *41 \**********************************************************************************/42 43 44 ---> TESTPOINT PASSED (psTime{Test E - Delta two times} | tst_psTime_03.c)45 46 /***************************** TESTPOINT ******************************************\47 * TestFile: tst_psTime_03.c *48 * TestPoint: psTime{Test F - Delta two times with underflow in microseconds} *49 * TestType: Positive *50 \**********************************************************************************/51 52 53 ---> TESTPOINT PASSED (psTime{Test F - Delta two times with underflow in microseconds} | tst_psTime_03.c)54 55 /***************************** TESTPOINT ******************************************\56 * TestFile: tst_psTime_03.c *57 * TestPoint: psTime{Test F1 - Delta two UTC times} *58 * TestType: Positive *59 \**********************************************************************************/60 61 62 ---> TESTPOINT PASSED (psTime{Test F1 - Delta two UTC times} | tst_psTime_03.c)63 64 /***************************** TESTPOINT ******************************************\65 * TestFile: tst_psTime_03.c *66 * TestPoint: psTime{Test G - Add two times across leapsecond boundary} *67 * TestType: Positive *68 \**********************************************************************************/69 70 1999-01-01T<DATE>.000Z71 72 ---> TESTPOINT PASSED (psTime{Test G - Add two times across leapsecond boundary} | tst_psTime_03.c)73 74 /***************************** TESTPOINT ******************************************\75 * TestFile: tst_psTime_03.c *76 * TestPoint: psTime{Test H - Find number of leapseconds added between two times} *77 * TestType: Positive *78 \**********************************************************************************/79 80 2281 82 ---> TESTPOINT PASSED (psTime{Test H - Find number of leapseconds added between two times} | tst_psTime_03.c)83 84 /***************************** TESTPOINT ******************************************\85 * TestFile: tst_psTime_03.c *86 * TestPoint: psTime{Test H1 - Verify error message in allocating invalid time type} *87 * TestType: Positive *88 \**********************************************************************************/89 90 91 ---> TESTPOINT PASSED (psTime{Test H1 - Verify error message in allocating invalid time type} | tst_psTime_03.c)92 93 /***************************** TESTPOINT ******************************************\94 * TestFile: tst_psTime_03.c *95 * TestPoint: psTime{Test I - Free data} *96 * TestType: Positive *97 \**********************************************************************************/98 99 100 ---> TESTPOINT PASSED (psTime{Test I - Free data} | tst_psTime_03.c)101 -
trunk/psLib/test/astronomy/verified/tst_psTime_04.stderr
r3272 r4059 1 /***************************** TESTPOINT ******************************************\ 2 * TestFile: tst_psTime_04.c * 3 * TestPoint: psTime{p_psTimeInit} * 4 * TestType: Positive * 5 \**********************************************************************************/ 6 7 8 ---> TESTPOINT PASSED (psTime{p_psTimeInit} | tst_psTime_04.c) 9 10 /***************************** TESTPOINT ******************************************\ 11 * TestFile: tst_psTime_04.c * 12 * TestPoint: psTime{p_psTimeInit} * 13 * TestType: Positive * 14 \**********************************************************************************/ 15 1 16 <DATE><TIME>|<HOST>|E|psMetadataParseConfig (FILE:LINENO) 2 17 Failed to open file 'zzz'. Check if it exists and it has the proper permissions. 3 18 <DATE><TIME>|<HOST>|E|psLibInit (FILE:LINENO) 4 19 Failed to initialize psTime. 5 <DATE><TIME>|<HOST>|E|psLookupTableRead (FILE:LINENO) 6 Failed to open file bogus/ser7.dat. 7 <DATE><TIME>|<HOST>|E|psLookupTableRead (FILE:LINENO) 8 Failed to open file bogus/eopc01_1900_2004.dat. 9 <DATE><TIME>|<HOST>|E|psLookupTableRead (FILE:LINENO) 10 Failed to open file bogus/finals_all.dat. 11 <DATE><TIME>|<HOST>|E|psLookupTableRead (FILE:LINENO) 12 Failed to open file bogus/tai_utc.dat. 20 21 ---> TESTPOINT PASSED (psTime{p_psTimeInit} | tst_psTime_04.c) 22 23 /***************************** TESTPOINT ******************************************\ 24 * TestFile: tst_psTime_04.c * 25 * TestPoint: psTime{p_psTimeInit} * 26 * TestType: Positive * 27 \**********************************************************************************/ 28 13 29 <DATE><TIME>|<HOST>|E|p_psTimeInit (FILE:LINENO) 14 Incorrect number of table files entered. Found: 3. Expected: 4. 30 Failed find 'psLib.time.tables.index' in time metadata. 31 <DATE><TIME>|<HOST>|E|psLibInit (FILE:LINENO) 32 Failed to initialize psTime. 33 34 ---> TESTPOINT PASSED (psTime{p_psTimeInit} | tst_psTime_04.c) 35 36 /***************************** TESTPOINT ******************************************\ 37 * TestFile: tst_psTime_04.c * 38 * TestPoint: psTime{p_psTimeInit} * 39 * TestType: Positive * 40 \**********************************************************************************/ 41 42 <DATE><TIME>|<HOST>|E|p_psTimeInit (FILE:LINENO) 43 Failed find 'psLib.time.tables.index' in time metadata. 44 <DATE><TIME>|<HOST>|E|psLibInit (FILE:LINENO) 45 Failed to initialize psTime. 46 47 ---> TESTPOINT PASSED (psTime{p_psTimeInit} | tst_psTime_04.c) 48 49 /***************************** TESTPOINT ******************************************\ 50 * TestFile: tst_psTime_04.c * 51 * TestPoint: psTime{p_psTimeInit} * 52 * TestType: Positive * 53 \**********************************************************************************/ 54 15 55 <DATE><TIME>|<HOST>|E|p_psTimeInit (FILE:LINENO) 16 56 Incorrect vector size. Size: 3, Expected 4. 17 57 <DATE><TIME>|<HOST>|E|psLibInit (FILE:LINENO) 18 58 Failed to initialize psTime. 19 <DATE><TIME>|<HOST>|E|printError (FILE:LINENO) 20 Unable to parse string, 53yyy244 on line 16. 21 <DATE><TIME>|<HOST>|E|psLookupTableRead (FILE:LINENO) 22 Lookup table is invalid. 59 60 ---> TESTPOINT PASSED (psTime{p_psTimeInit} | tst_psTime_04.c) 61 62 /***************************** TESTPOINT ******************************************\ 63 * TestFile: tst_psTime_04.c * 64 * TestPoint: psTime{p_psTimeInit} * 65 * TestType: Positive * 66 \**********************************************************************************/ 67 68 <DATE><TIME>|<HOST>|E|p_psTimeInit (FILE:LINENO) 69 Failed find 'psLib.time.tables.index' in time metadata. 70 <DATE><TIME>|<HOST>|E|psLibInit (FILE:LINENO) 71 Failed to initialize psTime. 72 73 ---> TESTPOINT PASSED (psTime{p_psTimeInit} | tst_psTime_04.c) 74 -
trunk/psLib/test/astronomy/verified/tst_psTime_04.stdout
r3273 r4059 1 /***************************** TESTPOINT ******************************************\2 * TestFile: tst_psTime_04.c *3 * TestPoint: psTime{Test A - Initialize time} *4 * TestType: Positive *5 \**********************************************************************************/6 7 8 ---> TESTPOINT PASSED (psTime{Test A - Initialize time} | tst_psTime_04.c)9 10 /***************************** TESTPOINT ******************************************\11 * TestFile: tst_psTime_04.c *12 * TestPoint: psTime{Test B - Attempt to open non-existant time config file} *13 * TestType: Negative *14 * ExpectedErrorText: Failed to open file 'zzz'. Check if it exists and it has the proper permissions. *15 * ExpectedStatusValue: 0 *16 \**********************************************************************************/17 18 19 ---> TESTPOINT PASSED (psTime{Test B - Attempt to open non-existant time config file} | tst_psTime_04.c)20 21 /***************************** TESTPOINT ******************************************\22 * TestFile: tst_psTime_04.c *23 * TestPoint: psTime{Test C - Attempt to open non-existant time data files} *24 * TestType: Negative *25 * ExpectedErrorText: Failed to open file 'zzz'. Check if it exists and it has the proper permissions. *26 * ExpectedStatusValue: 0 *27 \**********************************************************************************/28 29 30 ---> TESTPOINT PASSED (psTime{Test C - Attempt to open non-existant time data files} | tst_psTime_04.c)31 32 /***************************** TESTPOINT ******************************************\33 * TestFile: tst_psTime_04.c *34 * TestPoint: psTime{Test D - Attempt to read incorrect number of files} *35 * TestType: Negative *36 * ExpectedErrorText: Incorrect number of table files entered. Found: 3. Expected: 4. *37 * ExpectedStatusValue: 0 *38 \**********************************************************************************/39 40 41 ---> TESTPOINT PASSED (psTime{Test D - Attempt to read incorrect number of files} | tst_psTime_04.c)42 43 /***************************** TESTPOINT ******************************************\44 * TestFile: tst_psTime_04.c *45 * TestPoint: psTime{Test E - Attempt to read incorrect number of from values} *46 * TestType: Negative *47 * ExpectedErrorText: Incorrect vector size. Size: 3, Expected 4. *48 * ExpectedStatusValue: 0 *49 \**********************************************************************************/50 51 52 ---> TESTPOINT PASSED (psTime{Test E - Attempt to read incorrect number of from values} | tst_psTime_04.c)53 54 /***************************** TESTPOINT ******************************************\55 * TestFile: tst_psTime_04.c *56 * TestPoint: psTime{Test F - Attempt to read data file with typo in number} *57 * TestType: Negative *58 * ExpectedErrorText: Unable to parse string, number on line 16. *59 * ExpectedStatusValue: 0 *60 \**********************************************************************************/61 62 63 ---> TESTPOINT PASSED (psTime{Test F - Attempt to read data file with typo in number} | tst_psTime_04.c)64 65 /***************************** TESTPOINT ******************************************\66 * TestFile: tst_psTime_04.c *67 * TestPoint: psTime{Test G - Free data} *68 * TestType: Positive *69 \**********************************************************************************/70 71 72 ---> TESTPOINT PASSED (psTime{Test G - Free data} | tst_psTime_04.c)73
Note:
See TracChangeset
for help on using the changeset viewer.
