1 rizwank 1.1 /*
|
2 rizwank 1.3 * Unit tests for 32-bit socket functions in Wine
|
3 rizwank 1.1 *
|
4 rizwank 1.3 * Copyright (c) 2005 Thomas Kho, Fredy Garcia, Douglas Rosenberg
|
5 rizwank 1.1 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include <stdio.h>
22
|
23 rizwank 1.3 #include <windows.h>
|
24 cs130_tom 1.4 #include <winsock.h>
25 #include <wtypes.h>
26 #include <winerror.h>
|
27 rizwank 1.1
28 #ifndef STANDALONE
29 #include "wine/test.h"
30 #else
31 #include <assert.h>
32 #define START_TEST(name) main(int argc, char **argv)
33 #define ok(condition, msg) \
34 do { \
35 if(!(condition)) \
36 { \
37 fprintf(stderr,"failed at %d\n",__LINE__); \
38 exit(0); \
39 } \
40 } while(0)
41
42 #define todo_wine
43 #endif
44
|
45 cs130_tom 1.4 #define NUM_CLIENTS 5
46
47 struct TestParams {
48 int sock;
49 int type;
50 int serverPort;
51 int clientPort[NUM_CLIENTS];
52 };
53
54 struct ClientParams {
55 struct TestParams *test;
56 int clientNum; // 1...NUM_CLIENTS
57 };
58
59 static void test_Startup(void);
60 void BlockingClient();
61 void BlockingServer();
62 static void test_ClientServerBlocking_1(void);
63 static void test_Startup(void);
|
64 rizwank 1.1
|
65 cs130_tom 1.4 void BlockingClient()
|
66 rizwank 1.1 {
|
67 cs130_tom 1.4 SOCKET sock;
68 SOCKADDR_IN client;
69
70 sock = socket(AF_INET, SOCK_DGRAM, 0);
71 if (sock == INVALID_SOCKET) {
72 ok( 0 , "Error in socket()");
73 WSACleanup();
74 exit(0);
75 }
76 trace("socket() ok\n");
77
78 client.sin_family = AF_INET;
79 client.sin_addr.s_addr = INADDR_ANY;
80 client.sin_port = htons(0);
81
82 bind(sock, (const SOCKADDR *) &client, sizeof(client));
83
84
85
|
86 rizwank 1.3 //while(1)
|
87 cs130_tom 1.4 {
88 printf("Thread 1\n");
89 }
|
90 rizwank 1.1 }
91
|
92 cs130_tom 1.4 void BlockingServer()
|
93 rizwank 1.3 {
|
94 cs130_tom 1.4 trace("blocking server\n");
|
95 rizwank 1.3 }
96
|
97 cs130_tom 1.4 static void test_ClientServerBlocking_1(void)
|
98 rizwank 1.3 {
|
99 cs130_tom 1.4 HANDLE Thread1, Thread2;
100 DWORD ThreadId1, ThreadId2;
101 Thread1 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) &BlockingClient, NULL, 0, &ThreadId1);
102 Thread2 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) &BlockingServer, NULL, 0, &ThreadId2);
103 //trace("In test_ClientServerBlocking_1\n");
|
104 rizwank 1.3 }
105
|
106 cs130_tom 1.4 static void test_Startup(void)
|
107 rizwank 1.3 {
|
108 cs130_tom 1.4 // initialize application
109 WSADATA wsaData;
110 int wsastartup_result = WSAStartup(MAKEWORD(1,1), &wsaData);
111 if ( (LOBYTE(wsaData.wVersion) != 1) && (HIBYTE(wsaData.wVersion) != 1) )
112 {
113 ok( 0 , "WSAStartup returns an incompatible sockets version");
114 WSACleanup();
115 exit(0);
116 }
117
118 ok((wsastartup_result == NO_ERROR), "Error in WSAStartup()");
|
119 rizwank 1.3 }
120
|
121 cs130_tom 1.4
|
122 rizwank 1.1 START_TEST(wsock32_main)
123 {
|
124 cs130_tom 1.4 trace("test 1 of 2:\n");
125 test_Startup();
126 trace("test 2 of 2:\n");
127 test_ClientServerBlocking_1();
128 trace("all tests done\n");
|
129 rizwank 1.1 }
|