]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
t-ntp_signd.c:
authorDamir Tomic <viperus@ntp.org>
Mon, 17 Aug 2015 10:15:56 +0000 (12:15 +0200)
committerDamir Tomic <viperus@ntp.org>
Mon, 17 Aug 2015 10:15:56 +0000 (12:15 +0200)
  adding more tests , added mocked functinos section

bk: 55d1b45cHXPPcxWBD8MA6DPnXsKcdQ

tests/ntpd/t-ntp_signd.c

index 973dbff9d9d10fb685b751d4d57749309b220566..09a75c86d008f21758a1e1a34e5ff1e8e27195ce 100644 (file)
@@ -8,6 +8,8 @@
 
 #include "test-libntp.h"
 
+
+
 #define HAVE_NTP_SIGND
 
 #include "ntp_signd.c"
 extern int ux_socket_connect(const char *name);
 
 
+//MOCKED FUNCTIONS
+
 //this connect function overrides/mocks connect() from  <sys/socket.h>
 int 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
+ssize_t write(int fd, void const * buf, size_t len){
+       if(len >= 4){return 4;}
+       else return len;
+}
+
+ssize_t read(int fd, void * buf, size_t len){
+       if(len >= 4){return 4;}
+       else return len;
+}
+
+
+//END OF MOCKED FUNCTIONS
+
 int isGE(int a,int b){ 
        if(a >= b) {return 1;}
        else {return 0;}
@@ -63,5 +81,21 @@ test_connect_correct_socket(void){
 
 void
 test_write_all(void){
+       int fd = ux_socket_connect("/socket");
+       TEST_ASSERT_TRUE(isGE(fd,0));
+       char * str = "TEST123";
+       int temp = write_all(fd, str,strlen(str));
+       TEST_ASSERT_EQUAL(strlen(str),temp);
+
+       
 
 }
+
+
+void
+test_send_packet(void){
+       int fd = ux_socket_connect("/socket");
+       char * str2 = "PACKET12345";
+       int temp = send_packet(fd, str2, strlen(str2));
+       TEST_ASSERT_EQUAL(0,temp);
+}