Esempio n. 1
0
void
test_IntegerAndFractionalBuffer(void)
{
#ifndef SYS_WINNT
	const struct timeval input = {5, 500000}; /* 5.5 */
	const l_fp expected = {{5 + JAN_1970}, HALF};
	double expectedDouble, actualDouble;
	l_fp actual;

	TEST_ASSERT_TRUE(buftvtots((const char*)(&input), &actual));

	/* Compare the fractional part with an absolute error given. */
	TEST_ASSERT_EQUAL(expected.l_ui, actual.l_ui);

	M_LFPTOD(0, expected.l_uf, expectedDouble);
	M_LFPTOD(0, actual.l_uf, actualDouble);

	/* The error should be less than 0.5 us */
	TEST_ASSERT_DOUBLE_WITHIN(0.0000005, expectedDouble, actualDouble);
#else
	TEST_IGNORE_MESSAGE("Test only for Windows, skipping...");
#endif

	return;
}
Esempio n. 2
0
TEST_F(buftvtotsTest, IntegerAndFractionalBuffer) {
	const timeval input = {5, 500000}; // 5.5
	const l_fp expected = {5 + JAN_1970, HALF};

	l_fp actual;

	ASSERT_TRUE(buftvtots((const char*)(&input), &actual));

	// Compare the fractional part with an absolute error given.
	EXPECT_EQ(expected.l_ui, actual.l_ui);

	double expectedDouble, actualDouble;
	M_LFPTOD(0, expected.l_uf, expectedDouble);
	M_LFPTOD(0, actual.l_uf, actualDouble);

	// The error should be less than 0.5 us
	EXPECT_NEAR(expectedDouble, actualDouble, 0.0000005);
}
Esempio n. 3
0
void
test_MicrosecondsExact(void)
{
	/* 0.5 can be represented exact in both l_fp and timeval. */
	const struct timeval input = {10, 500000}; /* 0.5 exact */
	const l_fp expected = {{10}, HALF};        /* 0.5 exact */
	l_fp actual;

	TVTOTS(&input, &actual);

	/* Compare the fractional part with an absolute error given. */
	TEST_ASSERT_EQUAL_UINT(expected.l_ui, actual.l_ui);

	double expectedDouble, actualDouble;
	M_LFPTOD(0, expected.l_uf, expectedDouble);
	M_LFPTOD(0, actual.l_uf, actualDouble);

	/* The error should be less than 0.5 us */
	TEST_ASSERT_DOUBLE_WITHIN(0.0000005, expectedDouble, actualDouble);
}