TEST(vi64ops, ParseVUI64_case) { vint64 act, exp; const char *sp; char *ep; sp = "0123456789AbCdEf"; exp.D_s.hi = 0x01234567; exp.D_s.lo = 0x89ABCDEF; act = strtouv64(sp, &ep, 16); TEST_ASSERT_TRUE(IsEqual(&exp, &act)); TEST_ASSERT_EQUAL(*ep, '\0'); }
TEST(vi64ops, ParseVUI64_neg) { vint64 act, exp; const char *sp; char *ep; sp = "-1234x"; exp.D_s.hi = ~0; exp.D_s.lo = -1234; act = strtouv64(sp, &ep, 0); TEST_ASSERT_TRUE(IsEqual(&exp, &act)); TEST_ASSERT_EQUAL(*ep, 'x'); }
TEST_F(vi64Test, ParseVUI64_case) { vint64 act, exp; const char *sp; char *ep; sp = "0123456789AbCdEf"; exp.D_s.hi = 0x01234567; exp.D_s.lo = 0x89ABCDEF; act = strtouv64(sp, &ep, 16); EXPECT_TRUE(IsEqual(exp, act)); EXPECT_EQ(*ep, '\0'); }
TEST_F(vi64Test, ParseVUI64_neg) { vint64 act, exp; const char *sp; char *ep; sp = "-1234x"; exp.D_s.hi = ~0; exp.D_s.lo = -1234; act = strtouv64(sp, &ep, 0); EXPECT_TRUE(IsEqual(exp, act)); EXPECT_EQ(*ep, 'x'); }
// ---------------------------------------------------------------------- // test number parser void test_ParseVUI64_pos() { vint64 act, exp; const char *sp; char *ep; sp = "1234x"; exp.D_s.hi = 0; exp.D_s.lo = 1234; act = strtouv64(sp, &ep, 0); TEST_ASSERT_TRUE(IsEqual(exp, act)); TEST_ASSERT_EQUAL(*ep, 'x'); }
/* --------------------------------------------------------------------- * Load a leap second file and check expiration on the go */ int/*BOOL*/ leapsec_load( leap_table_t * pt , leapsec_reader func, void * farg, int use_build_limit) { char *cp, *ep, linebuf[50]; vint64 ttime, limit; long taiof; struct calendar build; leapsec_clear(pt); if (use_build_limit && ntpcal_get_build_date(&build)) limit = ntpcal_date_to_ntp64(&build); else memset(&limit, 0, sizeof(limit)); while (get_line(func, farg, linebuf, sizeof(linebuf))) { cp = linebuf; if (*cp == '#') { cp++; if (*cp == '@') { cp = skipws(cp+1); pt->head.expire = strtouv64(cp, &ep, 10); if (parsefail(cp, ep)) goto fail_read; pt->lsig.etime = pt->head.expire.D_s.lo; } else if (*cp == '$') { cp = skipws(cp+1); pt->head.update = strtouv64(cp, &ep, 10); if (parsefail(cp, ep)) goto fail_read; } } else if (isdigit((u_char)*cp)) { ttime = strtouv64(cp, &ep, 10); if (parsefail(cp, ep)) goto fail_read; cp = skipws(ep); taiof = strtol(cp, &ep, 10); if ( parsefail(cp, ep) || taiof > SHRT_MAX || taiof < SHRT_MIN) goto fail_read; if (ucmpv64(&ttime, &limit) >= 0) { if (!leapsec_raw(pt, &ttime, taiof, FALSE)) goto fail_insn; } else { pt->head.base_tai = (int16_t)taiof; } pt->lsig.ttime = ttime.D_s.lo; pt->lsig.taiof = (int16_t)taiof; } } return TRUE; fail_read: errno = EILSEQ; fail_insn: leapsec_clear(pt); return FALSE; }