From: Damir Tomic Date: Mon, 17 Aug 2015 09:28:21 +0000 (+0200) Subject: t-ntp_signd.c: X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f7a734393bddf6e47a4af3c6f063f219c185a8b;p=thirdparty%2Fntp.git t-ntp_signd.c: new tests added run-t-ntp_signd.c: I had some issues with bk and this file t-ntp_signd.c: basic mocking concept added. connect() is mocked, and always returns 1 bk: 55d1a935ccetJJY2PYcnDPA7utwJ3w --- diff --git a/tests/ntpd/run-t-ntp_signd.c b/tests/ntpd/run-t-ntp_signd.c index 55534d78e..0ab7862df 100644 --- a/tests/ntpd/run-t-ntp_signd.c +++ b/tests/ntpd/run-t-ntp_signd.c @@ -31,7 +31,8 @@ //=======External Functions This Runner Calls===== extern void setUp(void); extern void tearDown(void); -extern void test_ux_socket_connect(void); +extern void test_connect_incorrect_socket(void); +extern void test_connect_correct_socket(void); extern void test_write_all(void); @@ -51,7 +52,8 @@ int main(int argc, char *argv[]) { progname = argv[0]; UnityBegin("ntp_signd.c"); - RUN_TEST(test_ux_socket_connect, 12); + RUN_TEST(test_connect_incorrect_socket, 12); + RUN_TEST(test_connect_correct_socket, 12); RUN_TEST(test_write_all, 23); return (UnityEnd()); diff --git a/tests/ntpd/t-ntp_signd.c b/tests/ntpd/t-ntp_signd.c index 1f033e109..973dbff9d 100644 --- a/tests/ntpd/t-ntp_signd.c +++ b/tests/ntpd/t-ntp_signd.c @@ -15,8 +15,25 @@ extern int ux_socket_connect(const char *name); +//this connect function overrides/mocks connect() from +int connect(int socket, const struct sockaddr *address, +socklen_t address_len){ + return 1; +} + +int isGE(int a,int b){ + if(a >= b) {return 1;} + else {return 0;} +} + + +void +test_connect_incorrect_socket(void){ + TEST_ASSERT_EQUAL(-1, ux_socket_connect(NULL)); +} + void -test_ux_socket_connect(void){ +test_connect_correct_socket(void){ //send_via_ntp_signd(NULL,NULL,NULL,NULL,NULL); /* @@ -27,16 +44,23 @@ test_ux_socket_connect(void){ int flags, struct pkt *xpkt) */ - TEST_ASSERT_EQUAL(-1, ux_socket_connect(NULL)); - //TEST_ASSERT_EQUAL(-1, ux_socket_connect("127.0.0.1:123")); - TEST_ASSERT_EQUAL(-1, ux_socket_connect("/socket")); + + int temp = ux_socket_connect("/socket"); + + //risky, what if something is listening on :123, or localhost isnt 127.0.0.1? + //TEST_ASSERT_EQUAL(-1, ux_socket_connect("127.0.0.1:123")); - //write_all() - char *socketName = "Random_Socket_Name"; - int length = strlen(socketName); + //printf("%d\n",temp); + TEST_ASSERT_TRUE(isGE(temp,0)); + + //write_all(); + //char *socketName = "Random_Socket_Name"; + //int length = strlen(socketName); } + + void test_write_all(void){