int main();
static void setup_sockets();
static void net_cache_basic_test();
+static void net_queue_basic_test();
static void net_send_basic_test();
static void net_wait_basic_test();
setup_env();
net_cache_basic_test();
+ net_queue_basic_test();
net_send_basic_test();
net_wait_basic_test();
free(p1);
}
+static void net_queue_basic_test() {
+ int epoll_fd;
+ int sock;
+ struct peer *info;
+
+ assert(1==peer_init(&info));
+
+ epoll_fd = epoll_create1(0);
+ assert(epoll_fd!=-1);
+
+ sock = 0;
+
+ assert(-1==net_queue(-1,-1,NULL));
+ assert(-1==net_queue(epoll_fd,-1,NULL));
+ assert(-1==net_queue(epoll_fd,sock,NULL));
+
+ assert(1==net_queue(epoll_fd,sock,info));
+
+ peer_free(info);
+ close(epoll_fd);
+}
+
static void net_send_basic_test() {
struct peer *info;
char buf[100];
struct peer *info;
char buf[100];
char expected[100];
+ int i, increment;
setup_sockets();
assert(1==net_wait(read_sock,info,buf,100));
assert(info->in==NULL);
assert(memcmp(buf,expected,100)==0);
+
+ i = 0;
+ info->in_size = 0;
+ while(i<99) {
+ assert(0==net_wait(read_sock,info,buf,100));
+ increment = rand()%2;
+ i += increment;
+ assert(((increment>0)?1:0)==write(write_sock,expected,increment));
+ assert(0==net_wait(read_sock,info,buf,100));
+ assert(info->in_size==i);
+ }
+
+ assert(1==write(write_sock,expected,1));
+ assert(1==net_wait(read_sock,info,buf,100));
+ assert(info->in==NULL);
+ assert(memcmp(buf,expected,100)==0);
close(read_sock);
close(write_sock);