giuliomoro@44: #include "../../include/UdpServer.h" giuliomoro@44: #include "../../include/UdpClient.h" giuliomoro@44: #include giuliomoro@44: giuliomoro@44: int test1(UdpServer *server, UdpClient *client){ giuliomoro@44: int buffer; giuliomoro@44: int tot=100; giuliomoro@44: int errors=0; giuliomoro@44: for(int n=0; nsend(&n,sizeof(int)); giuliomoro@44: for(int n=0; nread(&buffer,sizeof(int)); giuliomoro@44: if(n!=buffer){ giuliomoro@44: printf("error: %d!=%d\n",n,buffer); giuliomoro@44: errors++; giuliomoro@44: } giuliomoro@44: } giuliomoro@44: int n=server->emptySocket(); giuliomoro@44: if(n!=0) giuliomoro@44: printf("Error: the socket had %d bytes",n); giuliomoro@44: return errors; giuliomoro@44: } giuliomoro@44: int compareStrings(char * str1, char * str2){ giuliomoro@44: if(strlen(str1)!=strlen(str2)) giuliomoro@44: return -1; giuliomoro@44: for(int n=0; nsend(&buffer,sizeof(char)*(num+1)); giuliomoro@44: } giuliomoro@44: char auxBuffer[100]; giuliomoro@44: for(int n=0; nread(&buffer,num*sizeof(char)); giuliomoro@44: if(compareStrings(auxBuffer,buffer)==-1){ giuliomoro@44: printf("error: %s!=%s\n",auxBuffer,buffer); giuliomoro@44: errors++; giuliomoro@44: } giuliomoro@44: } giuliomoro@44: giuliomoro@44: return errors; giuliomoro@44: } giuliomoro@44: giuliomoro@44: int test3(UdpServer *server, UdpClient *client){ giuliomoro@44: char buffer[1000]; giuliomoro@44: int tot=100; giuliomoro@44: int errors=0; giuliomoro@44: int totNum=0; giuliomoro@44: for(int n=0; nsend(&buffer,sizeof(char)*(num+1)); giuliomoro@44: totNum+=1+num; giuliomoro@44: } giuliomoro@44: int n=server->emptySocket(); giuliomoro@44: if(n!=totNum){ giuliomoro@44: errors=1; giuliomoro@44: printf("retrieved bytes differs from sent bytes: %d!=%d\n",n,totNum); giuliomoro@44: } giuliomoro@44: return errors; giuliomoro@44: } giuliomoro@44: giuliomoro@44: giuliomoro@44: int main(){ giuliomoro@44: int port=1234; giuliomoro@44: UdpServer server(port); giuliomoro@44: UdpClient client(port,"127.0.0.1"); giuliomoro@44: int errors=0; giuliomoro@44: int ret; giuliomoro@44: ret=test1(&server,&client); giuliomoro@44: errors+=ret; giuliomoro@44: if(ret) giuliomoro@44: printf("test1 failed with %d errors\n", ret); giuliomoro@44: else giuliomoro@44: printf("test1 passed\n"); giuliomoro@44: giuliomoro@44: ret=test2(&server,&client); giuliomoro@44: errors+=ret; giuliomoro@44: if(ret) giuliomoro@44: printf("test2 failed with %d errors\n", ret); giuliomoro@44: else giuliomoro@44: printf("test2 passed\n"); giuliomoro@44: giuliomoro@44: ret=test3(&server,&client); giuliomoro@44: errors+=ret; giuliomoro@44: if(ret) giuliomoro@44: printf("test3 failed with %d errors\n", ret); giuliomoro@44: else giuliomoro@44: printf("test3 passed\n"); giuliomoro@44: giuliomoro@44: return errors; giuliomoro@44: }