From: Harlan Stenn Date: Wed, 25 Nov 2015 12:23:40 +0000 (+0000) Subject: Unity test cleanup. Harlan Stenn. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d41f9b025d9c3ae253052c0d008614706de9858f;p=thirdparty%2Fntp.git Unity test cleanup. Harlan Stenn. bk: 5655a84c2EcEdGPmoM8TRfzkjAIyww --- diff --git a/tests/ntpd/run-t-ntp_signd.c b/tests/ntpd/run-t-ntp_signd.c index c0979b05e..5226f7f85 100644 --- a/tests/ntpd/run-t-ntp_signd.c +++ b/tests/ntpd/run-t-ntp_signd.c @@ -55,12 +55,12 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("t-ntp_signd.c"); - RUN_TEST(test_connect_incorrect_socket, 53); - RUN_TEST(test_connect_correct_socket, 54); - RUN_TEST(test_write_all, 55); - RUN_TEST(test_send_packet, 56); - RUN_TEST(test_recv_packet, 57); - RUN_TEST(test_send_via_ntp_signd, 58); + RUN_TEST(test_connect_incorrect_socket, 67); + RUN_TEST(test_connect_correct_socket, 68); + RUN_TEST(test_write_all, 69); + RUN_TEST(test_send_packet, 70); + RUN_TEST(test_recv_packet, 71); + RUN_TEST(test_send_via_ntp_signd, 72); return (UnityEnd()); } diff --git a/tests/ntpd/t-ntp_signd.c b/tests/ntpd/t-ntp_signd.c index a7c2f82cb..d9c03f485 100644 --- a/tests/ntpd/t-ntp_signd.c +++ b/tests/ntpd/t-ntp_signd.c @@ -25,19 +25,33 @@ connect(int socket, const struct sockaddr *address, socklen_t address_len) return 1; } -//mocked write will only send 4 bytes at a time. This is so write_all can be properly tested +/* +** Mocked read() and write() calls. +** +** These will only operate 4 bytes at a time. +** +** This is so write_all can be properly tested. +*/ + +static char rw_buf[4]; + ssize_t write(int fd, void const * buf, size_t len) { - if (len >= 4) {return 4;} - else return len; + REQUIRE(0 <= len); + if (len >= 4) len = 4; /* 4 bytes, max */ + (void)memcpy(rw_buf, buf, len); + + return len; } ssize_t read(int fd, void * buf, size_t len) { - if (len >= 4) {return 4;} - else return len; + REQUIRE(0 <= len); + if (len >= 4) len = 4; + (void)memcpy(buf, rw_buf, len); + return len; }