4 #include "ntp_calendar.h"
5 #include "ntp_stdlib.h"
9 #include "test-libntp.h"
12 #define HAVE_NTP_SIGND
14 #include "ntp_signd.c"
16 extern int ux_socket_connect(const char *name);
21 //this connect function overrides/mocks connect() from <sys/socket.h>
23 connect(int socket, const struct sockaddr *address, socklen_t address_len)
29 ** Mocked read() and write() calls.
31 ** These will only operate 4 bytes at a time.
33 ** This is so write_all can be properly tested.
36 static char rw_buf[4];
39 write(int fd, void const * buf, size_t len)
42 if (len >= 4) len = 4; /* 4 bytes, max */
43 (void)memcpy(rw_buf, buf, len);
49 read(int fd, void * buf, size_t len)
52 if (len >= 4) len = 4;
53 (void)memcpy(buf, rw_buf, len);
58 //END OF MOCKED FUNCTIONS
63 if (a >= b) {return 1;}
67 extern void test_connect_incorrect_socket(void);
68 extern void test_connect_correct_socket(void);
69 extern void test_write_all(void);
70 extern void test_send_packet(void);
71 extern void test_recv_packet(void);
72 extern void test_send_via_ntp_signd(void);
76 test_connect_incorrect_socket(void)
78 TEST_ASSERT_EQUAL(-1, ux_socket_connect(NULL));
84 test_connect_correct_socket(void)
86 int temp = ux_socket_connect("/socket");
88 //risky, what if something is listening on :123, or localhost isnt 127.0.0.1?
89 //TEST_ASSERT_EQUAL(-1, ux_socket_connect("127.0.0.1:123"));
91 //printf("%d\n",temp);
92 TEST_ASSERT_TRUE(isGE(temp,0));
95 //char *socketName = "Random_Socket_Name";
96 //int length = strlen(socketName);
105 int fd = ux_socket_connect("/socket");
107 TEST_ASSERT_TRUE(isGE(fd, 0));
109 char * str = "TEST123";
110 int temp = write_all(fd, str,strlen(str));
111 TEST_ASSERT_EQUAL(strlen(str), temp);
119 test_send_packet(void)
121 int fd = ux_socket_connect("/socket");
123 TEST_ASSERT_TRUE(isGE(fd, 0));
125 char * str2 = "PACKET12345";
126 int temp = send_packet(fd, str2, strlen(str2));
128 TEST_ASSERT_EQUAL(0,temp);
136 ** HMS: What's going on here?
137 ** Looks like this needs more work.
140 test_recv_packet(void)
143 int fd = ux_socket_connect("/socket");
145 TEST_ASSERT_TRUE(isGE(fd, 0));
149 int temp = recv_packet(fd, &str, &size);
151 send_packet(fd, str, strlen(str));
153 TEST_ASSERT_EQUAL(0,temp); //0 because nobody sent us anything (yet!)
157 TEST_IGNORE_MESSAGE("test_recv_packet() needs work");
163 test_send_via_ntp_signd(void)
165 struct recvbuf *rbufp = (struct recvbuf *) malloc(sizeof(struct recvbuf));
167 keyid_t xkeyid = 12345;
169 struct pkt *xpkt = (struct pkt *) malloc(sizeof(struct pkt)); //defined in ntp.h
171 TEST_ASSERT_NOT_NULL(rbufp);
172 TEST_ASSERT_NOT_NULL(xpkt);
173 memset(xpkt, 0, sizeof(struct pkt));
175 //send_via_ntp_signd(NULL,NULL,NULL,NULL,NULL); //doesn't work
177 ** Send the xpkt to Samba, read the response back in rbufp
179 send_via_ntp_signd(rbufp,xmode,xkeyid,flags,xpkt);