static void hexstrTest() { unsigned char buf[6] = {1, 2, 33, 255, 0, 18}; unsigned char buf2[6] = {0}; AutoFree s(_MemToHex(&buf)); utassert(str::Eq(s, "010221ff0012")); bool ok = _HexToMem(s, &buf2); utassert(ok); utassert(memeq(buf, buf2, sizeof(buf))); FILETIME ft1, ft2; GetSystemTimeAsFileTime(&ft1); s.Set(_MemToHex(&ft1)); _HexToMem(s, &ft2); DWORD diff = FileTimeDiffInSecs(ft1, ft2); utassert(0 == diff); utassert(FileTimeEq(ft1, ft2)); s.Set(str::MemToHex(nullptr, 0)); utassert(str::Eq(s, "")); ok = str::HexToMem(s, nullptr, 0); utassert(ok); }
// return t1 - t2 in seconds static int SystemTimeDiffInSecs(SYSTEMTIME& t1, SYSTEMTIME& t2) { FILETIME ft1, ft2; SystemTimeToFileTime(&t1, &ft1); SystemTimeToFileTime(&t2, &ft2); return FileTimeDiffInSecs(ft1, ft2); }