timeconv_test succeed

This commit is contained in:
Kolan Sh 2011-12-08 10:56:16 +03:00
parent 9373263f27
commit 9c742c0137
1 changed files with 38 additions and 17 deletions

View File

@ -5,12 +5,16 @@
#include "timeconv.h"
void usec_test()
void conv_test()
{
struct tm t;
struct timeval tv;
uint64_t usec = 0;
struct timespec ts;
struct timecent tc;
struct timemil tl;
uint64_t pack64 = 0;
char buf[256];
size_t i = 0;
putenv("TZ=GMT+0");
@ -22,26 +26,43 @@ void usec_test()
t.tm_year = 2011-1900;
t.tm_isdst = 0;
tv.tv_sec = mktime(&t);
tv.tv_usec = 798431;
for (i = 0; i < 4; i++) {
tv.tv_sec = mktime(&t);
ts.tv_sec = mktime(&t);
tc.tv_sec = mktime(&t);
tl.tv_sec = mktime(&t);
usec = usec_from_timeval(tv);
memset(&tv, 0, sizeof(tv));
tv = timeval_from_usec(usec);
memset(&t, 0, sizeof(t));
t = *gmtime(&tv.tv_sec);
strftime(buf, sizeof(buf), "%Y.%m.%d %H:%M:%S", &t);
printf("%s\n", buf);
switch (i) {
case 0: pack64 = usec_from_timeval(tv);
tv.tv_usec = 798431;
memset(&tv, 0, sizeof(tv));
tv = timeval_from_usec(pack64);
break;
case 1: pack64 = nsec_from_timespec(ts);
ts.tv_nsec = 798431;
memset(&ts, 0, sizeof(ts));
ts = timespec_from_nsec(pack64);
break;
case 2: pack64 = csec_from_timecent(tc);
tc.tv_csec = 798431;
memset(&tc, 0, sizeof(tc));
tc = timecent_from_csec(pack64);
break;
case 3: pack64 = msec_from_timemil(tl);
tl.tv_msec = 798431;
memset(&tl, 0, sizeof(tl));
tl = timemil_from_msec(pack64);
break;
default:;
}
strftime(buf, sizeof(buf), "%Y.%m.%d %H:%M:%S", gmtime(&tv.tv_sec));
printf("%s\n", buf);
}
}
int main(int argc, char *argv[])
{
usec_test();
conv_test();
return 0;
}