diff options
author | Jun Chen <chen> | 2007-07-26 15:50:04 +0000 |
---|---|---|
committer | Jun Chen <chen> | 2007-07-26 15:50:04 +0000 |
commit | 6dc1c28d958cea275c568cac7015f526ccf76719 (patch) | |
tree | 49eb088a5598f89fe4a6017162741f2d27e9e8fd | |
parent | ef1e87ddb63443acaa43412512ee676b1e977538 (diff) |
Added test programs for tnt_bind.
-rw-r--r-- | test/Makefile | 14 | ||||
-rw-r--r-- | test/etp_test/Makefile | 21 | ||||
-rw-r--r-- | test/etp_test/etp_svr.c | 49 | ||||
-rw-r--r-- | test/etp_test/etp_test.c | 38 | ||||
-rw-r--r-- | test/tcp_test/Makefile | 16 | ||||
-rw-r--r-- | test/tcp_test/test_srv.c | 73 | ||||
-rw-r--r-- | test/test.c | 37 | ||||
-rw-r--r-- | test/test2.c | 45 | ||||
-rw-r--r-- | test/test3.c | 44 |
9 files changed, 140 insertions, 197 deletions
diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..f4dc032 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,14 @@ +CC = gcc +CFLAGS = -g -O2 -Wall -Wmissing-prototypes -Wstrict-prototypes \ + -I ../libtnt -I ../libetp -I ../libtnttk/include +LDFLAGS = -L ../libtnt -L ../libetp -L ../libtnttk +LDLIBS = -ltnt -letp -ltnttk -lpthread + +BINARIES = test test2 test3 + +.PHONY: clean + +all: $(BINARIES) + +clean: + rm -f $(BINARIES) *.o diff --git a/test/etp_test/Makefile b/test/etp_test/Makefile deleted file mode 100644 index 50b4c84..0000000 --- a/test/etp_test/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -CC = gcc -CFLAGS = -g -O2 -Wall -Wmissing-prototypes -Wstrict-prototypes \ - -I ../../libetp -I ../../libtnttk/include -LDFLAGS = -L ../../libetp -L ../../libtnttk -LIBS = -letp -ltnttk - -.PHONY: all clean - -all: etp_test etp_svr - -etp_test: etp_test.o - $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) - -etp_svr: etp_svr.o - $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) - -%.o: %.c - $(CC) $(CFLAGS) -c -o $@ $< - -clean: - rm -f etp_test etp_svr *.o diff --git a/test/etp_test/etp_svr.c b/test/etp_test/etp_svr.c deleted file mode 100644 index 64bec61..0000000 --- a/test/etp_test/etp_svr.c +++ /dev/null @@ -1,49 +0,0 @@ -#include <stdio.h> - -#include <etp.h> - -int -main(int argc, char *argv[]) -{ - etp_error_t error; - etp_msg_t msg; - int id; - - error = etp_init("/tmp/etp_test.sock", ETP_MODE_SERVER); - - if (error) - { - fprintf(stderr, "Unable to initialize libetp (error = %d)\n", error); - return 1; - } - - error = etp_accept(&id); - - if (error) - { - fprintf(stderr, "Unable to accept client (error = %d)\n", error); - return 1; - } - - error = etp_msg_recvfrom(&msg, id); - - if (error) - { - fprintf(stderr, "Unable to receive message (error = %d)\n", error); - return 1; - } - -#if 0 - error = etp_msg_get_ie(msg, name, data, &data_size); - - if (error) - { - fprintf(stderr, "Unable to get_ie libetp (error = %d)\n", error); - return 1; - } -#endif - - etp_close(id); - etp_terminate(); - return 0; -} diff --git a/test/etp_test/etp_test.c b/test/etp_test/etp_test.c deleted file mode 100644 index a8d3fd1..0000000 --- a/test/etp_test/etp_test.c +++ /dev/null @@ -1,38 +0,0 @@ -#include <stdio.h> - -#include <etp.h> - -int -main(int argc, char *argv[]) -{ - etp_error_t error; - etp_msg_t msg; - - error = etp_init("/tmp/etp_test.sock", ETP_MODE_CLIENT); - - if (error) - { - fprintf(stderr, "Unable to initialize libetp (error = %d)\n", error); - return 1; - } - - msg = etp_msg_create(123); - - if (msg == ETP_MSG_NULL) - { - fprintf(stderr, "Unable to create message\n"); - return 1; - } - - error = etp_msg_send(msg); - - if (error) - { - fprintf(stderr, "Unable to send message (error = %d)\n", error); - return 1; - } - - etp_msg_destroy(msg); - etp_terminate(); - return 0; -} diff --git a/test/tcp_test/Makefile b/test/tcp_test/Makefile deleted file mode 100644 index b763b0e..0000000 --- a/test/tcp_test/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -CC = gcc -CFLAGS = -g -O2 -Wall -Wmissing-prototypes -Wstrict-prototypes \ - -I ../../libtnttk/include -LDFLAGS = -L ../../libtnttk -LIBS = -ltnttk - -.PHONY: clean - -test_srv: test_srv.o - $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) - -%.o: %.c - $(CC) $(CFLAGS) -c -o $@ $< - -clean: - rm -f test_srv *.o diff --git a/test/tcp_test/test_srv.c b/test/tcp_test/test_srv.c deleted file mode 100644 index 4e97910..0000000 --- a/test/tcp_test/test_srv.c +++ /dev/null @@ -1,73 +0,0 @@ - -#include<sys/socket.h> -#include<netinet/in.h> -#include<arpa/inet.h> -#include<sys/types.h> -#include<sys/wait.h> -#include<signal.h> -#include<errno.h> - -void attente(int i) - { - while(waitpid(-1,NULL,WNOHANG)); - signal(SIGCHLD,attente); - } - -void traitementclient(int commfd) - { - char buff[50]; - char repond[50]="reussir"; - snprintf(buff,sizeof(buff),"%.24s\n",repond); - sleep(10); - write(commfd,buff,sizeof(buff)); - } - - -main() - { - int listenfd, commfd; - socklen_t len; - struct sockaddr_in servaddr, cliaddr; - char buff[50]; - - signal(SIGCHLD,attente); - - listenfd=socket(AF_INET,SOCK_STREAM,0); - bzero(&servaddr,sizeof(servaddr)); - servaddr.sin_family=AF_INET; - servaddr.sin_addr.s_addr=htonl(INADDR_ANY); - servaddr.sin_port=htons(9000); - - bind(listenfd,(struct sockaddr *)&servaddr,sizeof(servaddr)); - listen(listenfd,10); - - for(;;) - { - len=sizeof(cliaddr); - if((commfd=accept(listenfd,(struct sockaddr*)&cliaddr,&len))<0) - { - if(errno==EINTR) - { - continue; - } - else - { - printf("accept error\n"); - exit(-1); - } - } - -// printf("connexion %d\n",inet_ntop(AF_INET,&cliaddr.sin_addr,buff,sizeof(buff)),ntohs(cliaddr.sin_port)); - - if(fork()==0) - { - close(listenfd); - printf("connexion %d\n",inet_ntop(AF_INET,&cliaddr.sin_addr,buff,sizeof(buff)),ntohs(cliaddr.sin_port)); - traitementclient(commfd); - close(commfd); - exit(0); - } - close(commfd); - } -} - diff --git a/test/test.c b/test/test.c new file mode 100644 index 0000000..ef7f739 --- /dev/null +++ b/test/test.c @@ -0,0 +1,37 @@ +#include <stdio.h> +#include <stdlib.h> +#include <sys/socket.h> +#include <sys/types.h> +#include <netinet/in.h> +#include <unistd.h> + + +#include <tnt.h> + +int main() +{ + int sd; + int res; + struct sockaddr_in sock; + + sd = tnt_socket(AF_INET,SOCK_STREAM,0); + + if(sd == -1) + { + perror("tnt_socket"); + return EXIT_FAILURE; + } + + bzero(&sock,sizeof(sock)); + sock.sin_family = AF_INET; + sock.sin_port = htons(1234); + sock.sin_addr.s_addr = htonl(INADDR_ANY); + + res = tnt_bind(sd, &sock, sizeof(sock)); + + if(res > 0) + { + printf("Correct!"); + } + +} diff --git a/test/test2.c b/test/test2.c new file mode 100644 index 0000000..84bcb67 --- /dev/null +++ b/test/test2.c @@ -0,0 +1,45 @@ + + +#include<stdio.h> +#include<stdlib.h> +#include<sys/socket.h> +#include<sys/types.h> + +#include<etp.h> + +#include "tnt.h" + +int main() +{ + int sd; + int res; + struct sockaddr_in sock; + + sd = tnt_socket(AF_INET,SOCK_STREAM,0); + + if(sd == -1) + { + perror("tnt_socket"); + return EXIT_FAILURE; + } + + bzero(&sock,sizeof(sock)); + sock.sin_family = AF_INET; + sock.sin_port = htons(1234); + sock.sin_addr.s_addr = htonl("192.168.0.1.1"); + + res = tnt_bind(sd, &sock, sizeof(sock)); + + if(res > 0) + { + perror("tnt_bind"); + } + else + { + if(errno == EINVAL) + printf(" tnt_bind est Correct"); + else + perror("tnt_bind"); + } + +} diff --git a/test/test3.c b/test/test3.c new file mode 100644 index 0000000..cfd54eb --- /dev/null +++ b/test/test3.c @@ -0,0 +1,44 @@ + + +#include<stdio.h> +#include<stdlib.h> +#include<sys/socket.h> +#include<sys/types.h> +#include<errno.h> +#include<unistd.h> +#include<netinet/in.h> +#include<arpa/inet.h> + + +#include "../../libtnt/tnt.h" + + + +int main() +{ + int sd; + int res; + struct sockaddr_in sock; + + sd = -1; + + bzero(&sock,sizeof(sock)); + sock.sin_family = AF_INET; + sock.sin_port = htons(1234); + sock.sin_addr.s_addr = htonl(INADDR_ANY); + + res = tnt_bind(sd, &sock, sizeof(sock)); + + if(res > 0) + { + perror("tnt_bind"); + } + else + { + if(errno == EBADF) + printf(" tnt_bind est Correct"); + else + perror("tnt_bind"); + } + +} |