Changeset 4058
- Timestamp:
- May 31, 2005, 11:57:29 AM (21 years ago)
- Location:
- trunk/psLib/test/astronomy
- Files:
-
- 3 edited
-
tst_psTime_02.c (modified) (2 diffs)
-
verified/tst_psTime_02.stderr (modified) (1 diff)
-
verified/tst_psTime_02.stdout (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/astronomy/tst_psTime_02.c
r3705 r4058 4 4 * 5 5 * This test driver contains the following tests for psTime: 6 * A) Incorrect ISO time data 7 * B) Attempt to use null timeval 8 * C) Free data 6 * 1) Convert psTime to Local Mean Sidereal Time (LMST) 7 * 2) Calculate leap second delta between times 8 * 3) Creation of psTime of type TT 9 * 4) Creation of psTime of type UTC 9 10 * 10 11 * @author Ross Harman, MHPCC 11 * 12 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $ 13 * @date $Date: 2005-04-18 23:30:54 $ 12 * @author Eric Van Alst, MHPCC 13 * 14 * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2005-05-31 21:57:22 $ 14 16 * 15 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 20 22 #include "psTest.h" 21 23 24 #define ERROR_TOL 0.001 25 26 static psS32 testTimeLMST(void); 27 static psS32 testTimeLeapSecondDelta(void); 28 static psS32 testTimeIsLeapSecond(void); 29 static psS32 testTimeFromTT(void); 30 static psS32 testTimeFromUTC(void); 31 32 // Test Time 1 : May 9, 2005 00:00:00,0 33 // MJD = 53499.000 34 // JD = 2453499.5 35 // UTC Test Time 1 36 const psS64 testTime1SecondsUTC = 1115596900; 37 const psU32 testTime1NanosecondsUTC = 0; 38 // Expected LMST 15:09:18 39 const psF64 testTime1LMST0 = 3.967604; 40 41 // Test Time 2 : May 9, 1995 00:00:00,0 42 // MJD = 49846.00 43 // JD = 2449846.5 44 // UTC Test Time 2 45 const psS64 testTime2SecondsUTC = 799977600; 46 const psU32 testTime2NanosecondsUTC = 0; 47 // Expected leap second delta 48 const psS64 testTimeLeapSecondDelta1 = 3; 49 50 // Test Time 3: Jan 1, 1999 00:00:00,0 51 // MJD = 51179 52 // JD = 2451179.5 53 const psS64 testTime3SecondsUTC = 915148800; 54 const psU32 testTime3NanosecondsUTC = 0; 55 56 testDescription tests[] = { 57 {testTimeLMST,000,"psTimeToLMST",0,false}, 58 {testTimeLeapSecondDelta,000,"psTimeLeapSecondDelta",0,false}, 59 {testTimeIsLeapSecond,000,"psTimeIsLeapSecond",0,false}, 60 {testTimeFromTT,000,"psTimeFromTT",0,false}, 61 {testTimeFromUTC,000,"psTimeFromUTC",0,false}, 62 {NULL} 63 }; 22 64 psS32 main(psS32 argc, char* argv[]) 23 65 { 24 25 // Test A - Incorrect ISO time data 26 printNegativeTestHeader(stdout,"psTime", "Incorrect ISO time data", "Time not allowed", 0); 27 psTimeFromISO("2004-99-21T18:22:24.272Z"); 28 psTimeFromISO("2004-07-99T18:22:24.272Z"); 29 psTimeFromISO("2004-07-21T99:22:24.272Z"); 30 psTimeFromISO("2004-07-21T18:99:24.272Z"); 31 psTimeFromISO("2004-07-21T18:22:99.272Z"); 32 psTimeFromISO("2004-07-21T18:22:24.-999Z"); 33 printFooter(stdout, "psTime", "Incorrect ISO time data", true); 34 35 36 // Test B - Attempt to use null timeval 37 printNegativeTestHeader(stdout,"psTime", "Attempt to use null timeval", "Null value for timeval arg not allowed", 0); 38 psTimeFromTimeval(NULL); 39 printFooter(stdout, "psTime", "Attempt to use null timeval", true); 40 41 42 // Test C - Free data 43 printPositiveTestHeader(stdout, "psTime", "Test C - Free data"); 44 if ( psMemCheckLeaks(0, NULL, stdout,false) != 0) { 45 psError(PS_ERR_UNKNOWN,true,"Memory leaks detected"); 46 return 10; 47 } 48 psMemCheckCorruption(0); 49 psS32 nBad = psMemCheckCorruption(0); 50 if(nBad) { 51 printf("ERROR: Found %d bad memory blocks\n", nBad); 52 } 53 printFooter(stdout, "psTime", "Test C - Free data", true); 54 55 return 0; 56 } 66 psLogSetLevel(PS_LOG_INFO); 67 68 // Initialize library internal structures 69 psLibInit(true,"psTime.config"); 70 71 if( !runTestSuite(stderr,"psTime",tests,argc,argv)) { 72 return 1; 73 } 74 75 // Clean up library 76 psLibFinalize(); 77 78 return 0; 79 } 80 81 psS32 testTimeLMST(void) 82 { 83 psTime* time = NULL; 84 psF64 lmst = 0.0; 85 86 // Attempt to get LMST with NULL time 87 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL time"); 88 lmst = psTimeToLMST(time,0); 89 if(!isnan(lmst)) { 90 psError(PS_ERR_UNKNOWN,true,"Did not return NaN as expected %lf",lmst); 91 return 1; 92 } 93 94 // Attempt to get LMST with valid test time 95 // Allocate test time 96 time = psTimeAlloc(PS_TIME_UTC); 97 time->sec = testTime1SecondsUTC; 98 time->nsec = testTime1NanosecondsUTC; 99 time->leapsecond = false; 100 lmst = psTimeToLMST(time,0.0); 101 if(fabs(lmst-testTime1LMST0) > ERROR_TOL) { 102 psError(PS_ERR_UNKNOWN,true,"LMST %lf not as expected %lf",lmst,testTime1LMST0); 103 return 2; 104 } 105 106 // Attempt to get LMST with invalid input time UT1 107 psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message for incorrect type"); 108 time->type = PS_TIME_UT1; 109 lmst = psTimeToLMST(time,0.0); 110 if(!isnan(lmst)) { 111 psError(PS_ERR_UNKNOWN,true,"Did not return NaN as expected %lf",lmst); 112 return 3; 113 } 114 psFree(time); 115 116 return 0; 117 } 118 119 psS32 testTimeLeapSecondDelta(void) 120 { 121 psTime* time1 = NULL; 122 psTime* time2 = NULL; 123 psS64 delta = 0; 124 125 // Attempt to get delta with NULL time1 argument 126 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL time"); 127 delta = psTimeLeapSecondDelta(time1,time2); 128 if(delta != 0) { 129 psError(PS_ERR_UNKNOWN,true,"Delta of %ld not as expected 0",(long int)delta); 130 return 1; 131 } 132 133 // Set test time 1 134 time1 = psTimeAlloc(PS_TIME_UTC); 135 time1->sec = testTime1SecondsUTC; 136 time1->nsec = testTime1NanosecondsUTC; 137 time1->leapsecond = false; 138 139 // Attempt to get delta with NULL time2 argument 140 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL time"); 141 delta = psTimeLeapSecondDelta(time1,time2); 142 if(delta != 0) { 143 psError(PS_ERR_UNKNOWN,true,"Delta of %ld not as expected 0",(long int)delta); 144 return 2; 145 } 146 147 // Set test time 2 with invalid time 148 time2 = psTimeAlloc(PS_TIME_UTC); 149 time2->sec = 0; 150 time2->nsec = 2e9; 151 time2->leapsecond = false; 152 153 // Attempt to get delta with invalid time2 154 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time"); 155 delta = psTimeLeapSecondDelta(time1,time2); 156 if(delta != 0) { 157 psError(PS_ERR_UNKNOWN,true,"Delta of %ld not as expected 0",(long int)delta); 158 return 3; 159 } 160 161 // Set test time 2 valid 162 time2->sec = testTime2SecondsUTC; 163 time2->nsec = testTime2NanosecondsUTC; 164 165 // Set test time 1 invalid 166 time1->sec = 0; 167 time1->nsec = 2e9; 168 169 // Attempt to get delta with invalid time1 170 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time"); 171 delta = psTimeLeapSecondDelta(time1,time2); 172 if(delta != 0) { 173 psError(PS_ERR_UNKNOWN,true,"Delta of %ld not as expected 0",(long int)delta); 174 return 4; 175 } 176 177 // Set test time 1 to greater time 178 time1->sec = testTime1SecondsUTC; 179 time1->nsec = testTime1NanosecondsUTC; 180 delta = psTimeLeapSecondDelta(time1,time2); 181 if(delta != testTimeLeapSecondDelta1) { 182 psError(PS_ERR_UNKNOWN,true,"Delta %ld not as expected %ld", 183 (long int)delta,(long int)testTimeLeapSecondDelta1); 184 return 5; 185 } 186 187 // Set test time 1 to lesser time 188 delta = psTimeLeapSecondDelta(time2,time1); 189 if(delta != testTimeLeapSecondDelta1) { 190 psError(PS_ERR_UNKNOWN,true,"Delta %ld not as expected %ld", 191 (long int)delta,(long int)testTimeLeapSecondDelta1); 192 return 6; 193 } 194 195 // Attempt to get delta with times equal 196 delta = psTimeLeapSecondDelta(time1,time1); 197 if(delta != 0) { 198 psError(PS_ERR_UNKNOWN,true,"Delta %ld not as expected 0",(long int)delta); 199 return 7; 200 } 201 202 psFree(time2); 203 psFree(time1); 204 205 return 0; 206 } 207 208 psS32 testTimeIsLeapSecond(void) 209 { 210 psTime* time = NULL; 211 psBool leapsecond = false; 212 213 // Attempt to determine if leap second with NULL time 214 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL time"); 215 leapsecond = psTimeIsLeapSecond(time); 216 if(leapsecond) { 217 psError(PS_ERR_UNKNOWN,true,"Leapsecond flag %d not as expected 0",leapsecond); 218 return 1; 219 } 220 221 // Set time 222 time = psTimeAlloc(PS_TIME_TAI); 223 time->sec = testTime1SecondsUTC; 224 time->nsec = testTime1NanosecondsUTC; 225 time->leapsecond = false; 226 227 // Attempt to determine if leap second with non-UTC time 228 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid type"); 229 leapsecond = psTimeIsLeapSecond(time); 230 if(leapsecond) { 231 psError(PS_ERR_UNKNOWN,true,"Leapsecond flag %d not as expected 0",leapsecond); 232 return 2; 233 } 234 235 // Set time to UTC 236 time->type = PS_TIME_UTC; 237 238 // Attempt to determine if leap second with valid time 239 leapsecond = psTimeIsLeapSecond(time); 240 if(leapsecond) { 241 psError(PS_ERR_UNKNOWN,true,"Leapsecond flag %d not a expected 0",leapsecond); 242 return 3; 243 } 244 245 // Set time to UTC with leap second 246 time->sec = testTime3SecondsUTC; 247 time->nsec = testTime3NanosecondsUTC; 248 leapsecond = psTimeIsLeapSecond(time); 249 if(!leapsecond) { 250 psError(PS_ERR_UNKNOWN,true,"Leapsecond flag %d not a expected 1",leapsecond); 251 return 4; 252 } 253 254 // Set time to 1 second before a known leap second 255 time->sec--; 256 leapsecond = psTimeIsLeapSecond(time); 257 if(leapsecond) { 258 psError(PS_ERR_UNKNOWN,true,"Leapsecond flag %d not as expected 0",leapsecond); 259 return 5; 260 } 261 262 // Set time to 1 second after a known leap second 263 time->sec +=2; 264 leapsecond = psTimeIsLeapSecond(time); 265 if(leapsecond) { 266 psError(PS_ERR_UNKNOWN,true,"Leapsecond flag %d not as expected 0",leapsecond); 267 return 6; 268 } 269 270 psFree(time); 271 272 return 0; 273 } 274 275 psS32 testTimeFromTT(void) 276 { 277 psTime* time = NULL; 278 279 // Attempt to create psTime with invalid time 280 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time"); 281 time = psTimeFromTT(0,2e9); 282 if(time != NULL) { 283 psError(PS_ERR_UNKNOWN,true,"Did not return NULL as expected"); 284 return 1; 285 } 286 287 // Attempt to create psTime with valid time 288 time = psTimeFromTT(testTime1SecondsUTC,testTime1NanosecondsUTC); 289 if(time == NULL) { 290 psError(PS_ERR_UNKNOWN,true,"Return NULL when not expected"); 291 return 2; 292 } 293 if(time->type != PS_TIME_TT) { 294 psError(PS_ERR_UNKNOWN,true,"Type of time object %d not as expected %d", 295 time->type,PS_TIME_TT); 296 return 3; 297 } 298 if((time->sec != testTime1SecondsUTC) || (time->nsec != testTime1NanosecondsUTC)) { 299 psError(PS_ERR_UNKNOWN,true,"Seconds %ld nanoseconds %d not as expected seconds %ld nanoseconds %d", 300 (long int)time->sec,time->nsec,(long int)testTime1SecondsUTC,testTime1NanosecondsUTC); 301 return 4; 302 } 303 psFree(time); 304 305 return 0; 306 } 307 308 psS32 testTimeFromUTC(void) 309 { 310 psTime* time = NULL; 311 312 // Attempt to create psTime with invalid time 313 psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid time"); 314 time = psTimeFromUTC(0,2e9,true); 315 if(time != NULL) { 316 psError(PS_ERR_UNKNOWN,true,"Did not return NULL as expected"); 317 return 1; 318 } 319 320 // Attempt to create psTime with valid non-leapsecond time and leapsecond flag true 321 time = psTimeFromUTC(testTime1SecondsUTC,testTime1NanosecondsUTC,true); 322 if(time == NULL) { 323 psError(PS_ERR_UNKNOWN,true,"Return NULL when not expected"); 324 return 2; 325 } 326 if(time->type != PS_TIME_UTC) { 327 psError(PS_ERR_UNKNOWN,true,"Type of time object %d not as expected %d", 328 time->type,PS_TIME_UTC); 329 return 3; 330 } 331 if((time->sec != testTime1SecondsUTC) || (time->nsec != testTime1NanosecondsUTC)) { 332 psError(PS_ERR_UNKNOWN,true,"Seconds %ld nanoseconds %d not as expected seconds %ld nanoseconds %d", 333 (long int)time->sec,time->nsec,(long int)testTime1SecondsUTC,testTime1NanosecondsUTC); 334 return 4; 335 } 336 if(time->leapsecond) { 337 psError(PS_ERR_UNKNOWN,true,"Leapsecond flag %d not as expected 0",time->leapsecond); 338 return 5; 339 } 340 psFree(time); 341 342 // Attempt to create psTime with valid leapsecond time but leapsecond flag false 343 time = psTimeFromUTC(testTime3SecondsUTC,testTime3NanosecondsUTC,false); 344 if(time == NULL) { 345 psError(PS_ERR_UNKNOWN,true,"Return NULL when not expected"); 346 return 6; 347 } 348 if(time->type != PS_TIME_UTC) { 349 psError(PS_ERR_UNKNOWN,true,"Type of time object %d not as expected %d", 350 time->type,PS_TIME_UTC); 351 return 7; 352 } 353 if((time->sec != testTime3SecondsUTC) || (time->nsec != testTime3NanosecondsUTC)) { 354 psError(PS_ERR_UNKNOWN,true,"Seconds %ld nanoseconds %d not as expected seconds %ld nanoseconds %d", 355 (long int)time->sec,time->nsec,(long int)testTime1SecondsUTC,testTime1NanosecondsUTC); 356 return 8; 357 } 358 if(!time->leapsecond) { 359 psError(PS_ERR_UNKNOWN,true,"Leapsecond flag %d not as expected 1",time->leapsecond); 360 return 9; 361 } 362 363 364 psFree(time); 365 366 return 0; 367 } 368 -
trunk/psLib/test/astronomy/verified/tst_psTime_02.stderr
r3705 r4058 1 <DATE><TIME>|<HOST>|E|psTimeFromISO (FILE:LINENO) 2 Error: tmTime.tm_mon, 99, is out of range. Must be between 1 and 12. 3 <DATE><TIME>|<HOST>|E|psTimeFromISO (FILE:LINENO) 4 Error: tmTime.tm_mday, 99, is out of range. Must be between 1 and 31. 5 <DATE><TIME>|<HOST>|E|psTimeFromISO (FILE:LINENO) 6 Error: tmTime.tm_hour, 99, is out of range. Must be between 0 and 23. 7 <DATE><TIME>|<HOST>|E|psTimeFromISO (FILE:LINENO) 8 Error: tmTime.tm_min, 99, is out of range. Must be between 0 and 59. 9 <DATE><TIME>|<HOST>|E|psTimeFromISO (FILE:LINENO) 10 Error: tmTime.tm_sec, 99, is out of range. Must be between 0 and 59. 11 <DATE><TIME>|<HOST>|E|psTimeFromISO (FILE:LINENO) 12 Error: millisecond, -999, is out of range. Must be between 0 and 999. 13 <DATE><TIME>|<HOST>|E|psTimeFromTimeval (FILE:LINENO) 1 /***************************** TESTPOINT ******************************************\ 2 * TestFile: tst_psTime_02.c * 3 * TestPoint: psTime{psTimeToLMST} * 4 * TestType: Positive * 5 \**********************************************************************************/ 6 7 <DATE><TIME>|<HOST>|I|testTimeLMST 8 Following should generate an error message for NULL time 9 <DATE><TIME>|<HOST>|E|psTimeToLMST (FILE:LINENO) 14 10 Unallowable operation: time is NULL. 11 <DATE><TIME>|<HOST>|I|testTimeLMST 12 Following should generate error message for incorrect type 13 <DATE><TIME>|<HOST>|E|psTimeToLMST (FILE:LINENO) 14 Specified type, 2, is incorrect. 15 16 ---> TESTPOINT PASSED (psTime{psTimeToLMST} | tst_psTime_02.c) 17 18 /***************************** TESTPOINT ******************************************\ 19 * TestFile: tst_psTime_02.c * 20 * TestPoint: psTime{psTimeLeapSecondDelta} * 21 * TestType: Positive * 22 \**********************************************************************************/ 23 24 <DATE><TIME>|<HOST>|I|testTimeLeapSecondDelta 25 Following should generate an error message for NULL time 26 <DATE><TIME>|<HOST>|E|psTimeLeapSecondDelta (FILE:LINENO) 27 Unallowable operation: time1 is NULL. 28 <DATE><TIME>|<HOST>|I|testTimeLeapSecondDelta 29 Following should generate an error message for NULL time 30 <DATE><TIME>|<HOST>|E|psTimeLeapSecondDelta (FILE:LINENO) 31 Unallowable operation: time2 is NULL. 32 <DATE><TIME>|<HOST>|I|testTimeLeapSecondDelta 33 Following should generate an error message for invalid time 34 <DATE><TIME>|<HOST>|E|psTimeLeapSecondDelta (FILE:LINENO) 35 Error: time2->nsec, 2000000000, is out of range. Must be between 0 and 999999999. 36 <DATE><TIME>|<HOST>|I|testTimeLeapSecondDelta 37 Following should generate an error message for invalid time 38 <DATE><TIME>|<HOST>|E|psTimeLeapSecondDelta (FILE:LINENO) 39 Error: time1->nsec, 2000000000, is out of range. Must be between 0 and 999999999. 40 41 ---> TESTPOINT PASSED (psTime{psTimeLeapSecondDelta} | tst_psTime_02.c) 42 43 /***************************** TESTPOINT ******************************************\ 44 * TestFile: tst_psTime_02.c * 45 * TestPoint: psTime{psTimeIsLeapSecond} * 46 * TestType: Positive * 47 \**********************************************************************************/ 48 49 <DATE><TIME>|<HOST>|I|testTimeIsLeapSecond 50 Following should generate an error message for NULL time 51 <DATE><TIME>|<HOST>|E|psTimeIsLeapSecond (FILE:LINENO) 52 Unallowable operation: utc is NULL. 53 <DATE><TIME>|<HOST>|I|testTimeIsLeapSecond 54 Following should generate an error message for invalid type 55 <DATE><TIME>|<HOST>|E|psTimeIsLeapSecond (FILE:LINENO) 56 Specified type, 0, is incorrect. 57 58 ---> TESTPOINT PASSED (psTime{psTimeIsLeapSecond} | tst_psTime_02.c) 59 60 /***************************** TESTPOINT ******************************************\ 61 * TestFile: tst_psTime_02.c * 62 * TestPoint: psTime{psTimeFromTT} * 63 * TestType: Positive * 64 \**********************************************************************************/ 65 66 <DATE><TIME>|<HOST>|I|testTimeFromTT 67 Following should generate an error message for invalid time 68 <DATE><TIME>|<HOST>|E|psTimeFromTT (FILE:LINENO) 69 Error: nsec, 2000000000, is out of range. Must be between 0 and 999999999. 70 71 ---> TESTPOINT PASSED (psTime{psTimeFromTT} | tst_psTime_02.c) 72 73 /***************************** TESTPOINT ******************************************\ 74 * TestFile: tst_psTime_02.c * 75 * TestPoint: psTime{psTimeFromUTC} * 76 * TestType: Positive * 77 \**********************************************************************************/ 78 79 <DATE><TIME>|<HOST>|I|testTimeFromUTC 80 Following should generate an error message for invalid time 81 <DATE><TIME>|<HOST>|E|psTimeFromUTC (FILE:LINENO) 82 Error: nsec, 2000000000, is out of range. Must be between 0 and 999999999. 83 84 ---> TESTPOINT PASSED (psTime{psTimeFromUTC} | tst_psTime_02.c) 85 -
trunk/psLib/test/astronomy/verified/tst_psTime_02.stdout
r2178 r4058 1 /***************************** TESTPOINT ******************************************\2 * TestFile: tst_psTime_02.c *3 * TestPoint: psTime{Incorrect ISO time data} *4 * TestType: Negative *5 * ExpectedErrorText: Time not allowed *6 * ExpectedStatusValue: 0 *7 \**********************************************************************************/8 9 10 ---> TESTPOINT PASSED (psTime{Incorrect ISO time data} | tst_psTime_02.c)11 12 /***************************** TESTPOINT ******************************************\13 * TestFile: tst_psTime_02.c *14 * TestPoint: psTime{Attempt to use null timeval} *15 * TestType: Negative *16 * ExpectedErrorText: Null value for timeval arg not allowed *17 * ExpectedStatusValue: 0 *18 \**********************************************************************************/19 20 21 ---> TESTPOINT PASSED (psTime{Attempt to use null timeval} | tst_psTime_02.c)22 23 /***************************** TESTPOINT ******************************************\24 * TestFile: tst_psTime_02.c *25 * TestPoint: psTime{Test C - Free data} *26 * TestType: Positive *27 \**********************************************************************************/28 29 30 ---> TESTPOINT PASSED (psTime{Test C - Free data} | tst_psTime_02.c)31
Note:
See TracChangeset
for help on using the changeset viewer.
