]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
t-ntp_signd.c:
authorDamir Tomic <viperus@ntp.org>
Mon, 17 Aug 2015 09:28:21 +0000 (11:28 +0200)
committerDamir Tomic <viperus@ntp.org>
Mon, 17 Aug 2015 09:28:21 +0000 (11:28 +0200)
  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

tests/ntpd/run-t-ntp_signd.c
tests/ntpd/t-ntp_signd.c

index 55534d78e63da4766e7ecf9ea9639b17f3e881b6..0ab7862dff589cb4906277ba9c1c737351933024 100644 (file)
@@ -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());
index 1f033e109511d19cf44ba358742a6edb6862c7cb..973dbff9d9d10fb685b751d4d57749309b220566 100644 (file)
 extern int ux_socket_connect(const char *name);
 
 
+//this connect function overrides/mocks connect() from  <sys/socket.h>
+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){