diff --git a/src/libCom/test/epicsTimeTest.cpp b/src/libCom/test/epicsTimeTest.cpp index fe7ac7887..c66718735 100644 --- a/src/libCom/test/epicsTimeTest.cpp +++ b/src/libCom/test/epicsTimeTest.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "epicsTime.h" #include "epicsThread.h" @@ -23,6 +24,31 @@ extern "C" { int epicsTimeTest (void); } +void invalidFormatTest () +{ + epicsTime ts ( epicsTime::getCurrent () ); + char bigBuf [512]; + char buf [32]; + memset ( bigBuf, '\a', sizeof ( bigBuf ) ); + bigBuf [ sizeof ( bigBuf ) - 1 ] = '\0'; + ts.strftime ( buf, sizeof ( buf ), bigBuf ); + printf ("A huge strftime format produces this result \"%s\"\n", buf ); +} + +void badNanosecTest () +{ + static const char * pFormat = "%a %b %d %Y %H:%M:%S.%4f"; + try { + const epicsTimeStamp ets = { 1, 1000000000 }; + epicsTime ts ( ets ); + char buf [32]; + ts.strftime ( buf, sizeof ( buf ), pFormat ); + printf ("A nano-sec overflow produces this result \"%s\"\n", buf ); + } + catch ( ... ) { + } +} + struct l_fp { /* NTP time stamp */ epicsUInt32 l_ui; /* sec past NTP epoch */ epicsUInt32 l_uf; /* fractional seconds */ @@ -82,6 +108,9 @@ int epicsTimeTest (void) static const double precisionEPICS = 1.0 / nSecPerSec; assert ( diff <= precisionEPICS + precisionNTP ); } + + invalidFormatTest (); + badNanosecTest (); printf ("epicsTime Test (%3d loops)\n========================\n\n", nTimes); @@ -216,7 +245,7 @@ int epicsTimeTest (void) sum_errloops += 1; } } - + printf ("epicsTime test complete. Summary: %d errors found " "in %d out of %d loops.\n", sum_errors, sum_errloops, nTimes);