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; }
TEST_F(buftvtotsTest, IllegalMicroseconds) { const timeval input = {0, 1100000}; // > 999 999 microseconds. l_fp actual; ASSERT_FALSE(buftvtots((const char*)(&input), &actual)); }
TEST_F(buftvtotsTest, AlwaysFalseOnWindows) { /* * Under Windows, buftvtots will just return * 0 (false). */ l_fp actual; ASSERT_FALSE(buftvtots("", &actual)); }
TEST_F(buftvtotsTest, ZeroBuffer) { const timeval input = {0, 0}; const l_fp expected = {0 + JAN_1970, 0}; l_fp actual; ASSERT_TRUE(buftvtots((const char*)(&input), &actual)); EXPECT_TRUE(IsEqual(expected, actual)); }
void test_IllegalMicroseconds() { #ifndef SYS_WINNT const struct timeval input = {0, 1100000}; // > 999 999 microseconds. l_fp actual; TEST_ASSERT_FALSE(buftvtots((const char*)(&input), &actual)); #else TEST_IGNORE_MESSAGE("Test only for Windows, skipping..."); #endif }
void test_AlwaysFalseOnWindows() { #ifdef SYS_WINNT /* * Under Windows, buftvtots will just return * 0 (false). */ l_fp actual; TEST_ASSERT_FALSE(buftvtots("", &actual)); #else TEST_IGNORE_MESSAGE("Non-Windows test, skipping..."); #endif }
void test_ZeroBuffer() { #ifndef SYS_WINNT const struct timeval input = {0, 0}; const l_fp expected = {0 + JAN_1970, 0}; l_fp actual; TEST_ASSERT_TRUE(buftvtots((const char*)(&input), &actual)); TEST_ASSERT_TRUE(IsEqual(expected, actual)); #else TEST_IGNORE_MESSAGE("Test only for Windows, skipping..."); #endif }
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); }
/* * refclock_gtraw - get next line/chunk of data * * This routine returns the raw data received from the clock in both * canonical or raw modes. The terminal interface routines map CR to LF. * In canonical mode this results in two lines, one containing data * followed by LF and another containing only LF. In raw mode the * interface routines can deliver arbitraty chunks of data from one * character to a maximum specified by the calling routine. In either * mode the routine returns the number of characters in the line * followed by a NULL character ('\0'), which is not included in the * count. * * If a timestamp is present in the timecode, as produced by the tty_clk * STREAMS module, it returns that as the timestamp; otherwise, it * returns the buffer timestamp. */ int refclock_gtraw( struct recvbuf *rbufp, /* receive buffer pointer */ char *lineptr, /* current line pointer */ int bmax, /* remaining characters in line */ l_fp *tsptr /* pointer to timestamp returned */ ) { char *dpt, *dpend, *dp; l_fp trtmp, tstmp; int i; /* * Check for the presence of a timestamp left by the tty_clock * module and, if present, use that instead of the buffer * timestamp captured by the I/O routines. We recognize a * timestamp by noting its value is earlier than the buffer * timestamp, but not more than one second earlier. */ dpt = (char *)rbufp->recv_buffer; dpend = dpt + rbufp->recv_length; trtmp = rbufp->recv_time; if (dpend >= dpt + 8) { if (buftvtots(dpend - 8, &tstmp)) { L_SUB(&trtmp, &tstmp); if (trtmp.l_ui == 0) { #ifdef DEBUG if (debug > 1) { printf( "refclock_gtlin: fd %d ldisc %s", rbufp->fd, lfptoa(&trtmp, 6)); get_systime(&trtmp); L_SUB(&trtmp, &tstmp); printf(" sigio %s\n", lfptoa(&trtmp, 6)); } #endif dpend -= 8; trtmp = tstmp; } else trtmp = rbufp->recv_time; } } /* * Copy the raw buffer to the user string. The string is padded * with a NULL, which is not included in the character count. */ if (dpend - dpt > bmax - 1) dpend = dpt + bmax - 1; for (dp = lineptr; dpt < dpend; dpt++) *dp++ = *dpt; *dp = '\0'; i = dp - lineptr; #ifdef DEBUG if (debug > 1) printf("refclock_gtraw: fd %d time %s timecode %d %s\n", rbufp->fd, ulfptoa(&trtmp, 6), i, lineptr); #endif *tsptr = trtmp; return (i); }
/* * refclock_gtlin - groom next input line and extract timestamp * * This routine processes the timecode received from the clock and * removes the parity bit and control characters. If a timestamp is * present in the timecode, as produced by the tty_clk STREAMS module, * it returns that as the timestamp; otherwise, it returns the buffer * timestamp. The routine return code is the number of characters in * the line. */ int refclock_gtlin( struct recvbuf *rbufp, /* receive buffer pointer */ char *lineptr, /* current line pointer */ int bmax, /* remaining characters in line */ l_fp *tsptr /* pointer to timestamp returned */ ) { char *dpt, *dpend, *dp; int i; l_fp trtmp, tstmp; char c; /* * Check for the presence of a timestamp left by the tty_clock * module and, if present, use that instead of the buffer * timestamp captured by the I/O routines. We recognize a * timestamp by noting its value is earlier than the buffer * timestamp, but not more than one second earlier. */ dpt = (char *)&rbufp->recv_space; dpend = dpt + rbufp->recv_length; trtmp = rbufp->recv_time; if (dpend >= dpt + 8) { if (buftvtots(dpend - 8, &tstmp)) { L_SUB(&trtmp, &tstmp); if (trtmp.l_ui == 0) { #ifdef DEBUG if (debug > 1) { printf( "refclock_gtlin: fd %d ldisc %s", rbufp->fd, lfptoa(&trtmp, 6)); get_systime(&trtmp); L_SUB(&trtmp, &tstmp); printf(" sigio %s\n", lfptoa(&trtmp, 6)); } #endif dpend -= 8; trtmp = tstmp; } else trtmp = rbufp->recv_time; } } /* * Edit timecode to remove control chars. Don't monkey with the * line buffer if the input buffer contains no ASCII printing * characters. */ if (dpend - dpt > bmax - 1) dpend = dpt + bmax - 1; for (dp = lineptr; dpt < dpend; dpt++) { c = *dpt & 0x7f; if (c >= ' ') *dp++ = c; } i = dp - lineptr; if (i > 0) *dp = '\0'; #ifdef DEBUG if (debug > 1 && i > 0) printf("refclock_gtlin: fd %d time %s timecode %d %s\n", rbufp->fd, ulfptoa(&trtmp, 6), i, lineptr); #endif *tsptr = trtmp; return (i); }