Changeset 4059 for trunk/psLib/test/astronomy/tst_psTime_03.c
- Timestamp:
- May 31, 2005, 12:02:28 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/astronomy/tst_psTime_03.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.
