4 #include "ntp_calendar.h"
5 #include "ntp_stdlib.h"
9 #include "test-libntp.h"
13 #define HAVE_NTP_SIGND
15 #include "ntp_signd.c"
17 extern int ux_socket_connect(const char *name);
22 //this connect function overrides/mocks connect() from <sys/socket.h>
23 int connect(int socket, const struct sockaddr *address,
24 socklen_t address_len){
28 //mocked write will only send 4 bytes at a time. This is so write_all can be properly tested
29 ssize_t write(int fd, void const * buf, size_t len){
30 if(len >= 4){return 4;}
34 ssize_t read(int fd, void * buf, size_t len){
35 if(len >= 4){return 4;}
40 //END OF MOCKED FUNCTIONS
42 int isGE(int a,int b){
43 if(a >= b) {return 1;}
49 test_connect_incorrect_socket(void){
50 TEST_ASSERT_EQUAL(-1, ux_socket_connect(NULL));
54 test_connect_correct_socket(void){
58 int temp = ux_socket_connect("/socket");
60 //risky, what if something is listening on :123, or localhost isnt 127.0.0.1?
61 //TEST_ASSERT_EQUAL(-1, ux_socket_connect("127.0.0.1:123"));
63 //printf("%d\n",temp);
64 TEST_ASSERT_TRUE(isGE(temp,0));
67 //char *socketName = "Random_Socket_Name";
68 //int length = strlen(socketName);
75 int fd = ux_socket_connect("/socket");
76 TEST_ASSERT_TRUE(isGE(fd,0));
77 char * str = "TEST123";
78 int temp = write_all(fd, str,strlen(str));
79 TEST_ASSERT_EQUAL(strlen(str),temp);
84 test_send_packet(void){
85 int fd = ux_socket_connect("/socket");
86 char * str2 = "PACKET12345";
87 int temp = send_packet(fd, str2, strlen(str2));
88 TEST_ASSERT_EQUAL(0,temp);
93 test_recv_packet(void){
94 int fd = ux_socket_connect("/socket");
98 int temp = recv_packet(fd, &str, &size);
99 send_packet(fd, str, strlen(str));
100 TEST_ASSERT_EQUAL(0,temp); //0 because nobody sent us anything (yet!)
104 test_send_via_ntp_signd(){
106 struct recvbuf *rbufp = (struct recvbuf *) malloc(sizeof(struct recvbuf));
108 keyid_t xkeyid = 12345;
110 struct pkt *xpkt = (struct pkt *) malloc(sizeof(struct pkt)); //defined in ntp.h
112 //send_via_ntp_signd(NULL,NULL,NULL,NULL,NULL); //doesn't work
113 send_via_ntp_signd(rbufp,xmode,xkeyid,flags,xpkt);