dplayx: Tests for GroupOwner.
[wine.git] / dlls / dplayx / tests / dplayx.c
blob020599476ce29f3ade754c05796a9cf75906230b
1 /* DirectPlay Conformance Tests
3 * Copyright 2007 - Alessandro Pignotti
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "wine/test.h"
21 #include <stdio.h>
22 #define INITGUID
23 #include <dplay.h>
24 #include <dplobby.h>
27 #define check(expected, result) \
28 ok( (expected) == (result), \
29 "expected=%d got=%d\n", \
30 expected, result );
31 #define checkLP(expected, result) \
32 ok( (expected) == (result), \
33 "expected=%p got=%p\n", \
34 expected, result );
35 #define checkHR(expected, result) \
36 ok( (expected) == (result), \
37 "expected=%s got=%s\n", \
38 dpResult2str(expected), dpResult2str(result) );
39 #define checkStr(expected, result) \
40 ok( (result != NULL) && (!strcmp(expected, result)), \
41 "expected=%s got=%s\n", \
42 expected, result );
43 #define checkFlags(expected, result, flags) \
44 ok( (expected) == (result), \
45 "expected=0x%08x(%s) got=0x%08x(%s)\n", \
46 expected, dwFlags2str(expected, flags), \
47 result, dwFlags2str(result, flags) );
48 #define checkGuid(expected, result) \
49 ok( IsEqualGUID(expected, result), \
50 "expected=%s got=%s\n", \
51 Guid2str(expected), Guid2str(result) );
52 #define checkConv(expected, result, function) \
53 ok( (expected) == (result), \
54 "expected=0x%08x(%s) got=0x%08x(%s)\n", \
55 expected, function(expected), \
56 result, function(result) );
59 DEFINE_GUID(appGuid, 0xbdcfe03e, 0xf0ec, 0x415b, 0x82, 0x11, 0x6f, 0x86, 0xd8, 0x19, 0x7f, 0xe1);
60 DEFINE_GUID(appGuid2, 0x93417d3f, 0x7d26, 0x46ba, 0xb5, 0x76, 0xfe, 0x4b, 0x20, 0xbb, 0xad, 0x70);
61 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
64 typedef struct tagCallbackData
66 LPDIRECTPLAY4 pDP;
67 UINT dwCounter1, dwCounter2;
68 DWORD dwFlags;
69 char szTrace1[1024], szTrace2[1024];
70 DPID *dpid;
71 UINT dpidSize;
72 } CallbackData, *lpCallbackData;
75 static LPSTR get_temp_buffer(void)
77 static UINT index = 0;
78 static char buff[10][256];
80 index = (index + 1) % 10;
81 *buff[index] = 0;
83 return buff[index];
87 static LPCSTR Guid2str(const GUID *guid)
89 LPSTR buffer = get_temp_buffer();
91 if (!guid) return "(null)";
93 /* Service providers */
94 if (IsEqualGUID(guid, &DPSPGUID_IPX))
95 return "DPSPGUID_IPX";
96 if (IsEqualGUID(guid, &DPSPGUID_TCPIP))
97 return "DPSPGUID_TCPIP";
98 if (IsEqualGUID(guid, &DPSPGUID_SERIAL))
99 return "DPSPGUID_SERIAL";
100 if (IsEqualGUID(guid, &DPSPGUID_MODEM))
101 return "DPSPGUID_MODEM";
102 /* DirectPlay Address ID's */
103 if (IsEqualGUID(guid, &DPAID_TotalSize))
104 return "DPAID_TotalSize";
105 if (IsEqualGUID(guid, &DPAID_ServiceProvider))
106 return "DPAID_ServiceProvider";
107 if (IsEqualGUID(guid, &DPAID_LobbyProvider))
108 return "DPAID_LobbyProvider";
109 if (IsEqualGUID(guid, &DPAID_Phone))
110 return "DPAID_Phone";
111 if (IsEqualGUID(guid, &DPAID_PhoneW))
112 return "DPAID_PhoneW";
113 if (IsEqualGUID(guid, &DPAID_Modem))
114 return "DPAID_Modem";
115 if (IsEqualGUID(guid, &DPAID_ModemW))
116 return "DPAID_ModemW";
117 if (IsEqualGUID(guid, &DPAID_INet))
118 return "DPAID_INet";
119 if (IsEqualGUID(guid, &DPAID_INetW))
120 return "DPAID_INetW";
121 if (IsEqualGUID(guid, &DPAID_INetPort))
122 return "DPAID_INetPort";
123 if (IsEqualGUID(guid, &DPAID_ComPort))
124 return "DPAID_ComPort";
126 sprintf( buffer, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
127 guid->Data1, guid->Data2, guid->Data3,
128 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
129 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
130 return buffer;
135 static LPCSTR dpResult2str(HRESULT hr)
137 switch (hr)
139 case DP_OK: return "DP_OK";
140 case DPERR_ALREADYINITIALIZED: return "DPERR_ALREADYINITIALIZED";
141 case DPERR_ACCESSDENIED: return "DPERR_ACCESSDENIED";
142 case DPERR_ACTIVEPLAYERS: return "DPERR_ACTIVEPLAYERS";
143 case DPERR_BUFFERTOOSMALL: return "DPERR_BUFFERTOOSMALL";
144 case DPERR_CANTADDPLAYER: return "DPERR_CANTADDPLAYER";
145 case DPERR_CANTCREATEGROUP: return "DPERR_CANTCREATEGROUP";
146 case DPERR_CANTCREATEPLAYER: return "DPERR_CANTCREATEPLAYER";
147 case DPERR_CANTCREATESESSION: return "DPERR_CANTCREATESESSION";
148 case DPERR_CAPSNOTAVAILABLEYET: return "DPERR_CAPSNOTAVAILABLEYET";
149 case DPERR_EXCEPTION: return "DPERR_EXCEPTION";
150 case DPERR_GENERIC: return "DPERR_GENERIC";
151 case DPERR_INVALIDFLAGS: return "DPERR_INVALIDFLAGS";
152 case DPERR_INVALIDOBJECT: return "DPERR_INVALIDOBJECT";
153 case DPERR_INVALIDPARAMS: return "DPERR_INVALIDPARAMS";
154 /* symbol with the same value: DPERR_INVALIDPARAM */
155 case DPERR_INVALIDPLAYER: return "DPERR_INVALIDPLAYER";
156 case DPERR_INVALIDGROUP: return "DPERR_INVALIDGROUP";
157 case DPERR_NOCAPS: return "DPERR_NOCAPS";
158 case DPERR_NOCONNECTION: return "DPERR_NOCONNECTION";
159 case DPERR_NOMEMORY: return "DPERR_NOMEMORY";
160 /* symbol with the same value: DPERR_OUTOFMEMORY */
161 case DPERR_NOMESSAGES: return "DPERR_NOMESSAGES";
162 case DPERR_NONAMESERVERFOUND: return "DPERR_NONAMESERVERFOUND";
163 case DPERR_NOPLAYERS: return "DPERR_NOPLAYERS";
164 case DPERR_NOSESSIONS: return "DPERR_NOSESSIONS";
165 case DPERR_PENDING: return "DPERR_PENDING";
166 case DPERR_SENDTOOBIG: return "DPERR_SENDTOOBIG";
167 case DPERR_TIMEOUT: return "DPERR_TIMEOUT";
168 case DPERR_UNAVAILABLE: return "DPERR_UNAVAILABLE";
169 case DPERR_UNSUPPORTED: return "DPERR_UNSUPPORTED";
170 case DPERR_BUSY: return "DPERR_BUSY";
171 case DPERR_USERCANCEL: return "DPERR_USERCANCEL";
172 case DPERR_NOINTERFACE: return "DPERR_NOINTERFACE";
173 case DPERR_CANNOTCREATESERVER: return "DPERR_CANNOTCREATESERVER";
174 case DPERR_PLAYERLOST: return "DPERR_PLAYERLOST";
175 case DPERR_SESSIONLOST: return "DPERR_SESSIONLOST";
176 case DPERR_UNINITIALIZED: return "DPERR_UNINITIALIZED";
177 case DPERR_NONEWPLAYERS: return "DPERR_NONEWPLAYERS";
178 case DPERR_INVALIDPASSWORD: return "DPERR_INVALIDPASSWORD";
179 case DPERR_CONNECTING: return "DPERR_CONNECTING";
180 case DPERR_CONNECTIONLOST: return "DPERR_CONNECTIONLOST";
181 case DPERR_UNKNOWNMESSAGE: return "DPERR_UNKNOWNMESSAGE";
182 case DPERR_CANCELFAILED: return "DPERR_CANCELFAILED";
183 case DPERR_INVALIDPRIORITY: return "DPERR_INVALIDPRIORITY";
184 case DPERR_NOTHANDLED: return "DPERR_NOTHANDLED";
185 case DPERR_CANCELLED: return "DPERR_CANCELLED";
186 case DPERR_ABORTED: return "DPERR_ABORTED";
187 case DPERR_BUFFERTOOLARGE: return "DPERR_BUFFERTOOLARGE";
188 case DPERR_CANTCREATEPROCESS: return "DPERR_CANTCREATEPROCESS";
189 case DPERR_APPNOTSTARTED: return "DPERR_APPNOTSTARTED";
190 case DPERR_INVALIDINTERFACE: return "DPERR_INVALIDINTERFACE";
191 case DPERR_NOSERVICEPROVIDER: return "DPERR_NOSERVICEPROVIDER";
192 case DPERR_UNKNOWNAPPLICATION: return "DPERR_UNKNOWNAPPLICATION";
193 case DPERR_NOTLOBBIED: return "DPERR_NOTLOBBIED";
194 case DPERR_SERVICEPROVIDERLOADED: return "DPERR_SERVICEPROVIDERLOADED";
195 case DPERR_ALREADYREGISTERED: return "DPERR_ALREADYREGISTERED";
196 case DPERR_NOTREGISTERED: return "DPERR_NOTREGISTERED";
197 case DPERR_AUTHENTICATIONFAILED: return "DPERR_AUTHENTICATIONFAILED";
198 case DPERR_CANTLOADSSPI: return "DPERR_CANTLOADSSPI";
199 case DPERR_ENCRYPTIONFAILED: return "DPERR_ENCRYPTIONFAILED";
200 case DPERR_SIGNFAILED: return "DPERR_SIGNFAILED";
201 case DPERR_CANTLOADSECURITYPACKAGE: return "DPERR_CANTLOADSECURITYPACKAGE";
202 case DPERR_ENCRYPTIONNOTSUPPORTED: return "DPERR_ENCRYPTIONNOTSUPPORTED";
203 case DPERR_CANTLOADCAPI: return "DPERR_CANTLOADCAPI";
204 case DPERR_NOTLOGGEDIN: return "DPERR_NOTLOGGEDIN";
205 case DPERR_LOGONDENIED: return "DPERR_LOGONDENIED";
206 case CLASS_E_NOAGGREGATION: return "CLASS_E_NOAGGREGATION";
208 default:
210 LPSTR buffer = get_temp_buffer();
211 sprintf( buffer, "%d", HRESULT_CODE(hr) );
212 return buffer;
217 static LPCSTR dpMsgType2str(DWORD dwType)
219 switch(dwType)
221 case DPSYS_CREATEPLAYERORGROUP: return "DPSYS_CREATEPLAYERORGROUP";
222 case DPSYS_DESTROYPLAYERORGROUP: return "DPSYS_DESTROYPLAYERORGROUP";
223 case DPSYS_ADDPLAYERTOGROUP: return "DPSYS_ADDPLAYERTOGROUP";
224 case DPSYS_DELETEPLAYERFROMGROUP: return "DPSYS_DELETEPLAYERFROMGROUP";
225 case DPSYS_SESSIONLOST: return "DPSYS_SESSIONLOST";
226 case DPSYS_HOST: return "DPSYS_HOST";
227 case DPSYS_SETPLAYERORGROUPDATA: return "DPSYS_SETPLAYERORGROUPDATA";
228 case DPSYS_SETPLAYERORGROUPNAME: return "DPSYS_SETPLAYERORGROUPNAME";
229 case DPSYS_SETSESSIONDESC: return "DPSYS_SETSESSIONDESC";
230 case DPSYS_ADDGROUPTOGROUP: return "DPSYS_ADDGROUPTOGROUP";
231 case DPSYS_DELETEGROUPFROMGROUP: return "DPSYS_DELETEGROUPFROMGROUP";
232 case DPSYS_SECUREMESSAGE: return "DPSYS_SECUREMESSAGE";
233 case DPSYS_STARTSESSION: return "DPSYS_STARTSESSION";
234 case DPSYS_CHAT: return "DPSYS_DPSYS_CHAT";
235 case DPSYS_SETGROUPOWNER: return "DPSYS_SETGROUPOWNER";
236 case DPSYS_SENDCOMPLETE: return "DPSYS_SENDCOMPLETE";
238 default: return "UNKNOWN";
242 static LPCSTR dwFlags2str(DWORD dwFlags, DWORD flagType)
245 #define FLAGS_DPCONNECTION (1<<0)
246 #define FLAGS_DPENUMPLAYERS (1<<1)
247 #define FLAGS_DPENUMGROUPS (1<<2)
248 #define FLAGS_DPPLAYER (1<<3)
249 #define FLAGS_DPGROUP (1<<4)
250 #define FLAGS_DPENUMSESSIONS (1<<5)
251 #define FLAGS_DPGETCAPS (1<<6)
252 #define FLAGS_DPGET (1<<7)
253 #define FLAGS_DPRECEIVE (1<<8)
254 #define FLAGS_DPSEND (1<<9)
255 #define FLAGS_DPSET (1<<10)
256 #define FLAGS_DPMESSAGEQUEUE (1<<11)
257 #define FLAGS_DPCONNECT (1<<12)
258 #define FLAGS_DPOPEN (1<<13)
259 #define FLAGS_DPSESSION (1<<14)
260 #define FLAGS_DPLCONNECTION (1<<15)
261 #define FLAGS_DPESC (1<<16)
262 #define FLAGS_DPCAPS (1<<17)
264 LPSTR flags = get_temp_buffer();
266 /* EnumConnections */
268 if (flagType & FLAGS_DPCONNECTION)
270 if (dwFlags & DPCONNECTION_DIRECTPLAY)
271 strcat(flags, "DPCONNECTION_DIRECTPLAY,");
272 if (dwFlags & DPCONNECTION_DIRECTPLAYLOBBY)
273 strcat(flags, "DPCONNECTION_DIRECTPLAYLOBBY,");
276 /* EnumPlayers,
277 EnumGroups */
279 if (flagType & FLAGS_DPENUMPLAYERS)
281 if (dwFlags == DPENUMPLAYERS_ALL)
282 strcat(flags, "DPENUMPLAYERS_ALL,");
283 if (dwFlags & DPENUMPLAYERS_LOCAL)
284 strcat(flags, "DPENUMPLAYERS_LOCAL,");
285 if (dwFlags & DPENUMPLAYERS_REMOTE)
286 strcat(flags, "DPENUMPLAYERS_REMOTE,");
287 if (dwFlags & DPENUMPLAYERS_GROUP)
288 strcat(flags, "DPENUMPLAYERS_GROUP,");
289 if (dwFlags & DPENUMPLAYERS_SESSION)
290 strcat(flags, "DPENUMPLAYERS_SESSION,");
291 if (dwFlags & DPENUMPLAYERS_SERVERPLAYER)
292 strcat(flags, "DPENUMPLAYERS_SERVERPLAYER,");
293 if (dwFlags & DPENUMPLAYERS_SPECTATOR)
294 strcat(flags, "DPENUMPLAYERS_SPECTATOR,");
295 if (dwFlags & DPENUMPLAYERS_OWNER)
296 strcat(flags, "DPENUMPLAYERS_OWNER,");
298 if (flagType & FLAGS_DPENUMGROUPS)
300 if (dwFlags == DPENUMGROUPS_ALL)
301 strcat(flags, "DPENUMGROUPS_ALL,");
302 if (dwFlags & DPENUMPLAYERS_LOCAL)
303 strcat(flags, "DPENUMGROUPS_LOCAL,");
304 if (dwFlags & DPENUMPLAYERS_REMOTE)
305 strcat(flags, "DPENUMGROUPS_REMOTE,");
306 if (dwFlags & DPENUMPLAYERS_GROUP)
307 strcat(flags, "DPENUMGROUPS_GROUP,");
308 if (dwFlags & DPENUMPLAYERS_SESSION)
309 strcat(flags, "DPENUMGROUPS_SESSION,");
310 if (dwFlags & DPENUMGROUPS_SHORTCUT)
311 strcat(flags, "DPENUMGROUPS_SHORTCUT,");
312 if (dwFlags & DPENUMGROUPS_STAGINGAREA)
313 strcat(flags, "DPENUMGROUPS_STAGINGAREA,");
314 if (dwFlags & DPENUMGROUPS_HIDDEN)
315 strcat(flags, "DPENUMGROUPS_HIDDEN,");
318 /* CreatePlayer */
320 if (flagType & FLAGS_DPPLAYER)
322 if (dwFlags & DPPLAYER_SERVERPLAYER)
323 strcat(flags, "DPPLAYER_SERVERPLAYER,");
324 if (dwFlags & DPPLAYER_SPECTATOR)
325 strcat(flags, "DPPLAYER_SPECTATOR,");
326 if (dwFlags & DPPLAYER_LOCAL)
327 strcat(flags, "DPPLAYER_LOCAL,");
328 if (dwFlags & DPPLAYER_OWNER)
329 strcat(flags, "DPPLAYER_OWNER,");
332 /* CreateGroup */
334 if (flagType & FLAGS_DPGROUP)
336 if (dwFlags & DPGROUP_STAGINGAREA)
337 strcat(flags, "DPGROUP_STAGINGAREA,");
338 if (dwFlags & DPGROUP_LOCAL)
339 strcat(flags, "DPGROUP_LOCAL,");
340 if (dwFlags & DPGROUP_HIDDEN)
341 strcat(flags, "DPGROUP_HIDDEN,");
344 /* EnumSessions */
346 if (flagType & FLAGS_DPENUMSESSIONS)
348 if (dwFlags & DPENUMSESSIONS_AVAILABLE)
349 strcat(flags, "DPENUMSESSIONS_AVAILABLE,");
350 if (dwFlags & DPENUMSESSIONS_ALL)
351 strcat(flags, "DPENUMSESSIONS_ALL,");
352 if (dwFlags & DPENUMSESSIONS_ASYNC)
353 strcat(flags, "DPENUMSESSIONS_ASYNC,");
354 if (dwFlags & DPENUMSESSIONS_STOPASYNC)
355 strcat(flags, "DPENUMSESSIONS_STOPASYNC,");
356 if (dwFlags & DPENUMSESSIONS_PASSWORDREQUIRED)
357 strcat(flags, "DPENUMSESSIONS_PASSWORDREQUIRED,");
358 if (dwFlags & DPENUMSESSIONS_RETURNSTATUS)
359 strcat(flags, "DPENUMSESSIONS_RETURNSTATUS,");
362 /* GetCaps,
363 GetPlayerCaps */
365 if (flagType & FLAGS_DPGETCAPS)
367 if (dwFlags & DPGETCAPS_GUARANTEED)
368 strcat(flags, "DPGETCAPS_GUARANTEED,");
371 /* GetGroupData,
372 GetPlayerData */
374 if (flagType & FLAGS_DPGET)
376 if (dwFlags == DPGET_REMOTE)
377 strcat(flags, "DPGET_REMOTE,");
378 if (dwFlags & DPGET_LOCAL)
379 strcat(flags, "DPGET_LOCAL,");
382 /* Receive */
384 if (flagType & FLAGS_DPRECEIVE)
386 if (dwFlags & DPRECEIVE_ALL)
387 strcat(flags, "DPRECEIVE_ALL,");
388 if (dwFlags & DPRECEIVE_TOPLAYER)
389 strcat(flags, "DPRECEIVE_TOPLAYER,");
390 if (dwFlags & DPRECEIVE_FROMPLAYER)
391 strcat(flags, "DPRECEIVE_FROMPLAYER,");
392 if (dwFlags & DPRECEIVE_PEEK)
393 strcat(flags, "DPRECEIVE_PEEK,");
396 /* Send */
398 if (flagType & FLAGS_DPSEND)
400 /*if (dwFlags == DPSEND_NONGUARANTEED)
401 strcat(flags, "DPSEND_NONGUARANTEED,");*/
402 if (dwFlags == DPSEND_MAX_PRIORITY) /* = DPSEND_MAX_PRI */
404 strcat(flags, "DPSEND_MAX_PRIORITY,");
406 else
408 if (dwFlags & DPSEND_GUARANTEED)
409 strcat(flags, "DPSEND_GUARANTEED,");
410 if (dwFlags & DPSEND_HIGHPRIORITY)
411 strcat(flags, "DPSEND_HIGHPRIORITY,");
412 if (dwFlags & DPSEND_OPENSTREAM)
413 strcat(flags, "DPSEND_OPENSTREAM,");
414 if (dwFlags & DPSEND_CLOSESTREAM)
415 strcat(flags, "DPSEND_CLOSESTREAM,");
416 if (dwFlags & DPSEND_SIGNED)
417 strcat(flags, "DPSEND_SIGNED,");
418 if (dwFlags & DPSEND_ENCRYPTED)
419 strcat(flags, "DPSEND_ENCRYPTED,");
420 if (dwFlags & DPSEND_LOBBYSYSTEMMESSAGE)
421 strcat(flags, "DPSEND_LOBBYSYSTEMMESSAGE,");
422 if (dwFlags & DPSEND_ASYNC)
423 strcat(flags, "DPSEND_ASYNC,");
424 if (dwFlags & DPSEND_NOSENDCOMPLETEMSG)
425 strcat(flags, "DPSEND_NOSENDCOMPLETEMSG,");
429 /* SetGroupData,
430 SetGroupName,
431 SetPlayerData,
432 SetPlayerName,
433 SetSessionDesc */
435 if (flagType & FLAGS_DPSET)
437 if (dwFlags == DPSET_REMOTE)
438 strcat(flags, "DPSET_REMOTE,");
439 if (dwFlags & DPSET_LOCAL)
440 strcat(flags, "DPSET_LOCAL,");
441 if (dwFlags & DPSET_GUARANTEED)
442 strcat(flags, "DPSET_GUARANTEED,");
445 /* GetMessageQueue */
447 if (flagType & FLAGS_DPMESSAGEQUEUE)
449 if (dwFlags & DPMESSAGEQUEUE_SEND)
450 strcat(flags, "DPMESSAGEQUEUE_SEND,");
451 if (dwFlags & DPMESSAGEQUEUE_RECEIVE)
452 strcat(flags, "DPMESSAGEQUEUE_RECEIVE,");
455 /* Connect */
457 if (flagType & FLAGS_DPCONNECT)
459 if (dwFlags & DPCONNECT_RETURNSTATUS)
460 strcat(flags, "DPCONNECT_RETURNSTATUS,");
463 /* Open */
465 if (flagType & FLAGS_DPOPEN)
467 if (dwFlags & DPOPEN_JOIN)
468 strcat(flags, "DPOPEN_JOIN,");
469 if (dwFlags & DPOPEN_CREATE)
470 strcat(flags, "DPOPEN_CREATE,");
471 if (dwFlags & DPOPEN_RETURNSTATUS)
472 strcat(flags, "DPOPEN_RETURNSTATUS,");
475 /* DPSESSIONDESC2 */
477 if (flagType & FLAGS_DPSESSION)
479 if (dwFlags & DPSESSION_NEWPLAYERSDISABLED)
480 strcat(flags, "DPSESSION_NEWPLAYERSDISABLED,");
481 if (dwFlags & DPSESSION_MIGRATEHOST)
482 strcat(flags, "DPSESSION_MIGRATEHOST,");
483 if (dwFlags & DPSESSION_NOMESSAGEID)
484 strcat(flags, "DPSESSION_NOMESSAGEID,");
485 if (dwFlags & DPSESSION_JOINDISABLED)
486 strcat(flags, "DPSESSION_JOINDISABLED,");
487 if (dwFlags & DPSESSION_KEEPALIVE)
488 strcat(flags, "DPSESSION_KEEPALIVE,");
489 if (dwFlags & DPSESSION_NODATAMESSAGES)
490 strcat(flags, "DPSESSION_NODATAMESSAGES,");
491 if (dwFlags & DPSESSION_SECURESERVER)
492 strcat(flags, "DPSESSION_SECURESERVER,");
493 if (dwFlags & DPSESSION_PRIVATE)
494 strcat(flags, "DPSESSION_PRIVATE,");
495 if (dwFlags & DPSESSION_PASSWORDREQUIRED)
496 strcat(flags, "DPSESSION_PASSWORDREQUIRED,");
497 if (dwFlags & DPSESSION_MULTICASTSERVER)
498 strcat(flags, "DPSESSION_MULTICASTSERVER,");
499 if (dwFlags & DPSESSION_CLIENTSERVER)
500 strcat(flags, "DPSESSION_CLIENTSERVER,");
502 if (dwFlags & DPSESSION_DIRECTPLAYPROTOCOL)
503 strcat(flags, "DPSESSION_DIRECTPLAYPROTOCOL,");
504 if (dwFlags & DPSESSION_NOPRESERVEORDER)
505 strcat(flags, "DPSESSION_NOPRESERVEORDER,");
506 if (dwFlags & DPSESSION_OPTIMIZELATENCY)
507 strcat(flags, "DPSESSION_OPTIMIZELATENCY,");
511 /* DPLCONNECTION */
513 if (flagType & FLAGS_DPLCONNECTION)
515 if (dwFlags & DPLCONNECTION_CREATESESSION)
516 strcat(flags, "DPLCONNECTION_CREATESESSION,");
517 if (dwFlags & DPLCONNECTION_JOINSESSION)
518 strcat(flags, "DPLCONNECTION_JOINSESSION,");
521 /* EnumSessionsCallback2 */
523 if (flagType & FLAGS_DPESC)
525 if (dwFlags & DPESC_TIMEDOUT)
526 strcat(flags, "DPESC_TIMEDOUT,");
529 /* GetCaps,
530 GetPlayerCaps */
532 if (flagType & FLAGS_DPCAPS)
534 if (dwFlags & DPCAPS_ISHOST)
535 strcat(flags, "DPCAPS_ISHOST,");
536 if (dwFlags & DPCAPS_GROUPOPTIMIZED)
537 strcat(flags, "DPCAPS_GROUPOPTIMIZED,");
538 if (dwFlags & DPCAPS_KEEPALIVEOPTIMIZED)
539 strcat(flags, "DPCAPS_KEEPALIVEOPTIMIZED,");
540 if (dwFlags & DPCAPS_GUARANTEEDOPTIMIZED)
541 strcat(flags, "DPCAPS_GUARANTEEDOPTIMIZED,");
542 if (dwFlags & DPCAPS_GUARANTEEDSUPPORTED)
543 strcat(flags, "DPCAPS_GUARANTEEDSUPPORTED,");
544 if (dwFlags & DPCAPS_SIGNINGSUPPORTED)
545 strcat(flags, "DPCAPS_SIGNINGSUPPORTED,");
546 if (dwFlags & DPCAPS_ENCRYPTIONSUPPORTED)
547 strcat(flags, "DPCAPS_ENCRYPTIONSUPPORTED,");
548 if (dwFlags & DPCAPS_ASYNCCANCELSUPPORTED)
549 strcat(flags, "DPCAPS_ASYNCCANCELSUPPORTED,");
550 if (dwFlags & DPCAPS_ASYNCCANCELALLSUPPORTED)
551 strcat(flags, "DPCAPS_ASYNCCANCELALLSUPPORTED,");
552 if (dwFlags & DPCAPS_SENDTIMEOUTSUPPORTED)
553 strcat(flags, "DPCAPS_SENDTIMEOUTSUPPORTED,");
554 if (dwFlags & DPCAPS_SENDPRIORITYSUPPORTED)
555 strcat(flags, "DPCAPS_SENDPRIORITYSUPPORTED,");
556 if (dwFlags & DPCAPS_ASYNCSUPPORTED)
557 strcat(flags, "DPCAPS_ASYNCSUPPORTED,");
559 if (dwFlags & DPPLAYERCAPS_LOCAL)
560 strcat(flags, "DPPLAYERCAPS_LOCAL,");
563 if ((strlen(flags) == 0) && (dwFlags != 0))
564 strcpy(flags, "UNKNOWN");
565 else
566 flags[strlen(flags)-1] = '\0';
568 return flags;
571 static char dpid2char(DPID* dpid, DWORD dpidSize, DPID idPlayer)
573 UINT i;
574 if ( idPlayer == DPID_SYSMSG )
575 return 'S';
576 for (i=0; i<dpidSize; i++)
578 if ( idPlayer == dpid[i] )
579 return (char)(i+48);
581 return '?';
584 static void check_messages( LPDIRECTPLAY4 pDP,
585 DPID *dpid,
586 DWORD dpidSize,
587 lpCallbackData callbackData )
589 /* Retrieves all messages from the queue of pDP, performing tests
590 * to check if we are receiving what we expect.
592 * Information about the messages is stores in callbackData:
594 * callbackData->dwCounter1: Number of messages received.
595 * callbackData->szTrace1: Traces for sender and receiver.
596 * We store the position a dpid holds in the dpid array.
597 * Example:
599 * trace string: "01,02,03,14"
600 * expanded: [ '01', '02', '03', '14' ]
601 * \ \ \ \
602 * \ \ \ ) message 3: from 1 to 4
603 * \ \ ) message 2: from 0 to 3
604 * \ ) message 1: from 0 to 2
605 * ) message 0: from 0 to 1
607 * In general terms:
608 * sender of message i = character in place 3*i of the array
609 * receiver of message i = character in place 3*i+1 of the array
611 * A sender value of 'S' means DPID_SYSMSG, this is, a system message.
613 * callbackData->szTrace2: Traces for message sizes.
616 DPID idFrom, idTo;
617 UINT i;
618 DWORD dwDataSize = 1024;
619 LPVOID lpData = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwDataSize );
620 HRESULT hr;
621 char temp[5];
623 callbackData->szTrace2[0] = '\0';
625 i = 0;
626 while ( DP_OK == (hr = IDirectPlayX_Receive( pDP, &idFrom, &idTo, 0,
627 lpData, &dwDataSize )) )
630 callbackData->szTrace1[ 3*i ] = dpid2char( dpid, dpidSize, idFrom );
631 callbackData->szTrace1[ 3*i+1 ] = dpid2char( dpid, dpidSize, idTo );
632 callbackData->szTrace1[ 3*i+2 ] = ',';
634 sprintf( temp, "%d,", dwDataSize );
635 strcat( callbackData->szTrace2, temp );
637 dwDataSize = 1024;
638 ++i;
641 checkHR( DPERR_NOMESSAGES, hr );
643 callbackData->szTrace1[ 3*i ] = '\0';
644 callbackData->dwCounter1 = i;
647 HeapFree( GetProcessHeap(), 0, lpData );
650 static void init_TCPIP_provider( LPDIRECTPLAY4 pDP,
651 LPCSTR strIPAddressString,
652 WORD port )
655 DPCOMPOUNDADDRESSELEMENT addressElements[3];
656 LPVOID pAddress = NULL;
657 DWORD dwAddressSize = 0;
658 LPDIRECTPLAYLOBBY3 pDPL;
659 HRESULT hr;
661 CoCreateInstance( &CLSID_DirectPlayLobby, NULL, CLSCTX_ALL,
662 &IID_IDirectPlayLobby3A, (LPVOID*) &pDPL );
664 /* Service provider */
665 addressElements[0].guidDataType = DPAID_ServiceProvider;
666 addressElements[0].dwDataSize = sizeof(GUID);
667 addressElements[0].lpData = (LPVOID) &DPSPGUID_TCPIP;
669 /* IP address string */
670 addressElements[1].guidDataType = DPAID_INet;
671 addressElements[1].dwDataSize = lstrlen(strIPAddressString) + 1;
672 addressElements[1].lpData = (LPVOID) strIPAddressString;
674 /* Optional Port number */
675 if( port > 0 )
677 addressElements[2].guidDataType = DPAID_INetPort;
678 addressElements[2].dwDataSize = sizeof(WORD);
679 addressElements[2].lpData = &port;
683 hr = IDirectPlayLobby_CreateCompoundAddress( pDPL, addressElements, 2,
684 NULL, &dwAddressSize );
685 checkHR( DPERR_BUFFERTOOSMALL, hr );
687 if( hr == DPERR_BUFFERTOOSMALL )
689 pAddress = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwAddressSize );
690 hr = IDirectPlayLobby_CreateCompoundAddress( pDPL, addressElements, 2,
691 pAddress, &dwAddressSize );
692 checkHR( DP_OK, hr );
695 hr = IDirectPlayX_InitializeConnection( pDP, pAddress, 0 );
696 todo_wine checkHR( DP_OK, hr );
700 static BOOL FAR PASCAL EnumSessions_cb_join( LPCDPSESSIONDESC2 lpThisSD,
701 LPDWORD lpdwTimeOut,
702 DWORD dwFlags,
703 LPVOID lpContext )
705 LPDIRECTPLAY4 pDP = (LPDIRECTPLAY4) lpContext;
706 DPSESSIONDESC2 dpsd;
707 HRESULT hr;
709 if (dwFlags & DPESC_TIMEDOUT)
711 return FALSE;
714 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
715 dpsd.dwSize = sizeof(DPSESSIONDESC2);
716 dpsd.guidApplication = appGuid;
717 dpsd.guidInstance = lpThisSD->guidInstance;
719 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_JOIN );
720 checkHR( DP_OK, hr );
722 return TRUE;
726 /* DirectPlayCreate */
728 static void test_DirectPlayCreate(void)
731 LPDIRECTPLAY pDP;
732 HRESULT hr;
734 /* TODO: Check how it behaves with pUnk!=NULL */
736 /* pDP==NULL */
737 hr = DirectPlayCreate( NULL, NULL, NULL );
738 checkHR( DPERR_INVALIDPARAMS, hr );
739 hr = DirectPlayCreate( (LPGUID) &GUID_NULL, NULL, NULL );
740 checkHR( DPERR_INVALIDPARAMS, hr );
741 hr = DirectPlayCreate( (LPGUID) &DPSPGUID_TCPIP, NULL, NULL );
742 checkHR( DPERR_INVALIDPARAMS, hr );
744 /* pUnk==NULL, pDP!=NULL */
745 hr = DirectPlayCreate( NULL, &pDP, NULL );
746 checkHR( DPERR_INVALIDPARAMS, hr );
747 hr = DirectPlayCreate( (LPGUID) &GUID_NULL, &pDP, NULL );
748 checkHR( DP_OK, hr );
749 if ( hr == DP_OK )
750 IDirectPlayX_Release( pDP );
751 hr = DirectPlayCreate( (LPGUID) &DPSPGUID_TCPIP, &pDP, NULL );
752 todo_wine checkHR( DP_OK, hr );
753 if ( hr == DP_OK )
754 IDirectPlayX_Release( pDP );
758 /* EnumConnections */
760 static BOOL FAR PASCAL EnumAddress_cb2( REFGUID guidDataType,
761 DWORD dwDataSize,
762 LPCVOID lpData,
763 LPVOID lpContext )
765 lpCallbackData callbackData = (lpCallbackData) lpContext;
767 static REFGUID types[] = { &DPAID_TotalSize,
768 &DPAID_ServiceProvider,
769 &GUID_NULL };
770 static DWORD sizes[] = { 4, 16, 0 };
771 static REFGUID sps[] = { &DPSPGUID_SERIAL, &DPSPGUID_MODEM,
772 &DPSPGUID_IPX, &DPSPGUID_TCPIP };
775 checkGuid( types[ callbackData->dwCounter2 ], guidDataType );
776 check( sizes[ callbackData->dwCounter2 ], dwDataSize );
778 if ( IsEqualGUID( types[0], guidDataType ) )
780 todo_wine check( 80, *((LPDWORD) lpData) );
782 else if ( IsEqualGUID( types[1], guidDataType ) )
784 todo_wine checkGuid( sps[ callbackData->dwCounter1 ], (LPGUID) lpData );
787 callbackData->dwCounter2++;
789 return TRUE;
792 static BOOL CALLBACK EnumConnections_cb( LPCGUID lpguidSP,
793 LPVOID lpConnection,
794 DWORD dwConnectionSize,
795 LPCDPNAME lpName,
796 DWORD dwFlags,
797 LPVOID lpContext )
800 lpCallbackData callbackData = (lpCallbackData) lpContext;
801 LPDIRECTPLAYLOBBY pDPL;
804 if (!callbackData->dwFlags)
806 callbackData->dwFlags = DPCONNECTION_DIRECTPLAY;
809 checkFlags( callbackData->dwFlags, dwFlags, FLAGS_DPCONNECTION );
811 /* Get info from lpConnection */
812 CoCreateInstance( &CLSID_DirectPlayLobby, NULL, CLSCTX_ALL,
813 &IID_IDirectPlayLobby3A, (LPVOID*) &pDPL );
815 callbackData->dwCounter2 = 0;
816 IDirectPlayLobby_EnumAddress( pDPL, EnumAddress_cb2,
817 (LPCVOID) lpConnection,
818 dwConnectionSize,
819 (LPVOID) callbackData );
820 todo_wine check( 3, callbackData->dwCounter2 );
822 callbackData->dwCounter1++;
824 return TRUE;
827 static void test_EnumConnections(void)
830 LPDIRECTPLAY4 pDP;
831 CallbackData callbackData;
832 HRESULT hr;
835 CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
836 &IID_IDirectPlay4A, (LPVOID*) &pDP );
839 callbackData.dwCounter1 = 0;
840 callbackData.dwFlags = 0;
841 hr = IDirectPlayX_EnumConnections( pDP, &appGuid, EnumConnections_cb,
842 (LPVOID) &callbackData,
843 callbackData.dwFlags );
844 checkHR( DP_OK, hr );
845 check( 4, callbackData.dwCounter1 );
847 callbackData.dwCounter1 = 0;
848 callbackData.dwFlags = 0;
849 hr = IDirectPlayX_EnumConnections( pDP, NULL, EnumConnections_cb,
850 (LPVOID) &callbackData,
851 callbackData.dwFlags );
852 checkHR( DP_OK, hr );
853 check( 4, callbackData.dwCounter1 );
855 callbackData.dwCounter1 = 0;
856 callbackData.dwFlags = 0;
857 hr = IDirectPlayX_EnumConnections( pDP, &appGuid, NULL,
858 (LPVOID) &callbackData,
859 callbackData.dwFlags );
860 checkHR( DPERR_INVALIDPARAMS, hr );
861 check( 0, callbackData.dwCounter1 );
864 /* Flag tests */
865 callbackData.dwCounter1 = 0;
866 callbackData.dwFlags = DPCONNECTION_DIRECTPLAY;
867 hr = IDirectPlayX_EnumConnections( pDP, &appGuid, EnumConnections_cb,
868 (LPVOID) &callbackData,
869 callbackData.dwFlags );
870 checkHR( DP_OK, hr );
871 check( 4, callbackData.dwCounter1 );
873 callbackData.dwCounter1 = 0;
874 callbackData.dwFlags = DPCONNECTION_DIRECTPLAYLOBBY;
875 hr = IDirectPlayX_EnumConnections( pDP, &appGuid, EnumConnections_cb,
876 (LPVOID) &callbackData,
877 callbackData.dwFlags );
878 checkHR( DP_OK, hr );
879 check( 0, callbackData.dwCounter1 );
881 callbackData.dwCounter1 = 0;
882 callbackData.dwFlags = ( DPCONNECTION_DIRECTPLAY |
883 DPCONNECTION_DIRECTPLAYLOBBY );
884 hr = IDirectPlayX_EnumConnections( pDP, &appGuid, EnumConnections_cb,
885 (LPVOID) &callbackData,
886 callbackData.dwFlags );
887 checkHR( DP_OK, hr );
888 check( 4, callbackData.dwCounter1 );
890 callbackData.dwCounter1 = 0;
891 callbackData.dwFlags = ~( DPCONNECTION_DIRECTPLAY |
892 DPCONNECTION_DIRECTPLAYLOBBY );
893 hr = IDirectPlayX_EnumConnections( pDP, &appGuid, EnumConnections_cb,
894 (LPVOID) &callbackData,
895 callbackData.dwFlags );
896 checkHR( DPERR_INVALIDFLAGS, hr );
897 check( 0, callbackData.dwCounter1 );
900 IDirectPlayX_Release( pDP );
903 /* InitializeConnection */
905 static BOOL CALLBACK EnumConnections_cb2( LPCGUID lpguidSP,
906 LPVOID lpConnection,
907 DWORD dwConnectionSize,
908 LPCDPNAME lpName,
909 DWORD dwFlags,
910 LPVOID lpContext )
912 LPDIRECTPLAY4 pDP = (LPDIRECTPLAY4) lpContext;
913 HRESULT hr;
915 /* Incorrect parameters */
916 hr = IDirectPlayX_InitializeConnection( pDP, NULL, 1 );
917 checkHR( DPERR_INVALIDPARAMS, hr );
918 hr = IDirectPlayX_InitializeConnection( pDP, lpConnection, 1 );
919 checkHR( DPERR_INVALIDFLAGS, hr );
921 /* Normal operation.
922 We're only interested in ensuring that the TCP/IP provider works */
924 if( IsEqualGUID(lpguidSP, &DPSPGUID_TCPIP) )
926 hr = IDirectPlayX_InitializeConnection( pDP, lpConnection, 0 );
927 todo_wine checkHR( DP_OK, hr );
928 hr = IDirectPlayX_InitializeConnection( pDP, lpConnection, 0 );
929 todo_wine checkHR( DPERR_ALREADYINITIALIZED, hr );
932 return TRUE;
935 static void test_InitializeConnection(void)
938 LPDIRECTPLAY4 pDP;
940 CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
941 &IID_IDirectPlay4A, (LPVOID*) &pDP );
943 IDirectPlayX_EnumConnections( pDP, &appGuid, EnumConnections_cb2,
944 (LPVOID) pDP, 0 );
946 IDirectPlayX_Release( pDP );
949 /* GetCaps */
951 static void test_GetCaps(void)
954 LPDIRECTPLAY4 pDP;
955 DPCAPS dpcaps;
956 DWORD dwFlags;
957 HRESULT hr;
960 CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
961 &IID_IDirectPlay4A, (LPVOID*) &pDP );
962 ZeroMemory( &dpcaps, sizeof(DPCAPS) );
964 /* Service provider not ininitialized */
965 hr = IDirectPlayX_GetCaps( pDP, &dpcaps, 0 );
966 checkHR( DPERR_UNINITIALIZED, hr );
968 init_TCPIP_provider( pDP, "127.0.0.1", 0 );
970 /* dpcaps not ininitialized */
971 hr = IDirectPlayX_GetCaps( pDP, &dpcaps, 0 );
972 todo_wine checkHR( DPERR_INVALIDPARAMS, hr );
974 dpcaps.dwSize = sizeof(DPCAPS);
976 for (dwFlags=0;
977 dwFlags<=DPGETCAPS_GUARANTEED;
978 dwFlags+=DPGETCAPS_GUARANTEED)
981 hr = IDirectPlayX_GetCaps( pDP, &dpcaps, dwFlags );
982 todo_wine checkHR( DP_OK, hr );
985 if ( hr == DP_OK )
987 check( sizeof(DPCAPS), dpcaps.dwSize );
988 check( DPCAPS_ASYNCSUPPORTED |
989 DPCAPS_GUARANTEEDOPTIMIZED |
990 DPCAPS_GUARANTEEDSUPPORTED,
991 dpcaps.dwFlags );
992 check( 0, dpcaps.dwMaxQueueSize );
993 check( 0, dpcaps.dwHundredBaud );
994 check( 500, dpcaps.dwLatency );
995 check( 65536, dpcaps.dwMaxLocalPlayers );
996 check( 20, dpcaps.dwHeaderLength );
997 check( 5000, dpcaps.dwTimeout );
999 switch (dwFlags)
1001 case 0:
1002 check( 65479, dpcaps.dwMaxBufferSize );
1003 check( 65536, dpcaps.dwMaxPlayers );
1004 break;
1005 case DPGETCAPS_GUARANTEED:
1006 check( 1048547, dpcaps.dwMaxBufferSize );
1007 check( 64, dpcaps.dwMaxPlayers );
1008 break;
1009 default: break;
1014 IDirectPlayX_Release( pDP );
1017 /* Open */
1019 static BOOL FAR PASCAL EnumSessions_cb2( LPCDPSESSIONDESC2 lpThisSD,
1020 LPDWORD lpdwTimeOut,
1021 DWORD dwFlags,
1022 LPVOID lpContext )
1024 LPDIRECTPLAY4 pDP = (LPDIRECTPLAY4) lpContext;
1025 DPSESSIONDESC2 dpsd;
1026 HRESULT hr;
1028 if (dwFlags & DPESC_TIMEDOUT)
1029 return FALSE;
1032 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
1033 dpsd.dwSize = sizeof(DPSESSIONDESC2);
1034 dpsd.guidApplication = appGuid;
1035 dpsd.guidInstance = lpThisSD->guidInstance;
1037 if ( lpThisSD->dwFlags & DPSESSION_PASSWORDREQUIRED )
1039 /* Incorrect password */
1040 U2(dpsd).lpszPasswordA = (LPSTR) "sonic boom";
1041 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_JOIN );
1042 checkHR( DPERR_INVALIDPASSWORD, hr );
1044 /* Correct password */
1045 U2(dpsd).lpszPasswordA = (LPSTR) "hadouken";
1046 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_JOIN );
1047 checkHR( DP_OK, hr );
1049 else
1051 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_JOIN );
1052 checkHR( DP_OK, hr );
1055 hr = IDirectPlayX_Close( pDP );
1056 checkHR( DP_OK, hr );
1058 return TRUE;
1061 static void test_Open(void)
1064 LPDIRECTPLAY4 pDP, pDP_server;
1065 DPSESSIONDESC2 dpsd, dpsd_server;
1066 HRESULT hr;
1069 CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
1070 &IID_IDirectPlay4A, (LPVOID*) &pDP_server );
1071 CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
1072 &IID_IDirectPlay4A, (LPVOID*) &pDP );
1073 ZeroMemory( &dpsd_server, sizeof(DPSESSIONDESC2) );
1074 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
1076 /* Service provider not initialized */
1077 hr = IDirectPlayX_Open( pDP_server, &dpsd_server, DPOPEN_CREATE );
1078 todo_wine checkHR( DPERR_INVALIDPARAMS, hr );
1080 init_TCPIP_provider( pDP_server, "127.0.0.1", 0 );
1081 init_TCPIP_provider( pDP, "127.0.0.1", 0 );
1083 /* Uninitialized dpsd */
1084 hr = IDirectPlayX_Open( pDP_server, &dpsd_server, DPOPEN_CREATE );
1085 todo_wine checkHR( DPERR_INVALIDPARAMS, hr );
1088 dpsd_server.dwSize = sizeof(DPSESSIONDESC2);
1089 dpsd_server.guidApplication = appGuid;
1090 dpsd_server.dwMaxPlayers = 10;
1093 /* Regular operation */
1094 hr = IDirectPlayX_Open( pDP_server, &dpsd_server, DPOPEN_CREATE );
1095 todo_wine checkHR( DP_OK, hr );
1097 /* Opening twice */
1098 hr = IDirectPlayX_Open( pDP_server, &dpsd_server, DPOPEN_CREATE );
1099 todo_wine checkHR( DPERR_ALREADYINITIALIZED, hr );
1101 /* Session flags */
1102 IDirectPlayX_Close( pDP_server );
1104 dpsd_server.dwFlags = DPSESSION_CLIENTSERVER | DPSESSION_MIGRATEHOST;
1105 hr = IDirectPlayX_Open( pDP_server, &dpsd_server, DPOPEN_CREATE );
1106 todo_wine checkHR( DPERR_INVALIDFLAGS, hr );
1108 dpsd_server.dwFlags = DPSESSION_MULTICASTSERVER | DPSESSION_MIGRATEHOST;
1109 hr = IDirectPlayX_Open( pDP_server, &dpsd_server, DPOPEN_CREATE );
1110 todo_wine checkHR( DPERR_INVALIDFLAGS, hr );
1112 dpsd_server.dwFlags = DPSESSION_SECURESERVER | DPSESSION_MIGRATEHOST;
1113 hr = IDirectPlayX_Open( pDP_server, &dpsd_server, DPOPEN_CREATE );
1114 todo_wine checkHR( DPERR_INVALIDFLAGS, hr );
1117 /* Joining sessions */
1118 /* - Checking how strict dplay is with sizes */
1119 dpsd.dwSize = 0;
1120 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_JOIN );
1121 todo_wine checkHR( DPERR_INVALIDPARAMS, hr );
1123 dpsd.dwSize = sizeof(DPSESSIONDESC2)-1;
1124 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_JOIN );
1125 todo_wine checkHR( DPERR_INVALIDPARAMS, hr );
1127 dpsd.dwSize = sizeof(DPSESSIONDESC2)+1;
1128 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_JOIN );
1129 todo_wine checkHR( DPERR_INVALIDPARAMS, hr );
1131 dpsd.dwSize = sizeof(DPSESSIONDESC2);
1132 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_JOIN );
1133 todo_wine checkHR( DPERR_NOSESSIONS, hr ); /* Only checks for size, not guids */
1136 dpsd.guidApplication = appGuid;
1137 dpsd.guidInstance = appGuid;
1140 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_JOIN );
1141 todo_wine checkHR( DPERR_NOSESSIONS, hr );
1142 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_JOIN | DPOPEN_CREATE );
1143 todo_wine checkHR( DPERR_NOSESSIONS, hr ); /* Second flag is ignored */
1145 dpsd_server.dwFlags = 0;
1148 /* Join to normal session */
1149 hr = IDirectPlayX_Open( pDP_server, &dpsd_server, DPOPEN_CREATE );
1150 todo_wine checkHR( DP_OK, hr );
1152 IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb2, pDP, 0 );
1155 /* Already initialized session */
1156 hr = IDirectPlayX_Open( pDP_server, &dpsd_server, DPOPEN_CREATE );
1157 todo_wine checkHR( DPERR_ALREADYINITIALIZED, hr );
1160 /* Checking which is the error checking order */
1161 dpsd_server.dwSize = 0;
1163 hr = IDirectPlayX_Open( pDP_server, &dpsd_server, DPOPEN_CREATE );
1164 todo_wine checkHR( DPERR_INVALIDPARAMS, hr );
1166 dpsd_server.dwSize = sizeof(DPSESSIONDESC2);
1169 /* Join to protected session */
1170 IDirectPlayX_Close( pDP_server );
1171 U2(dpsd_server).lpszPasswordA = (LPSTR) "hadouken";
1172 hr = IDirectPlayX_Open( pDP_server, &dpsd_server, DPOPEN_CREATE );
1173 todo_wine checkHR( DP_OK, hr );
1175 IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb2,
1176 pDP, DPENUMSESSIONS_PASSWORDREQUIRED );
1179 IDirectPlayX_Release( pDP );
1180 IDirectPlayX_Release( pDP_server );
1184 /* EnumSessions */
1186 static BOOL FAR PASCAL EnumSessions_cb( LPCDPSESSIONDESC2 lpThisSD,
1187 LPDWORD lpdwTimeOut,
1188 DWORD dwFlags,
1189 LPVOID lpContext )
1191 lpCallbackData callbackData = (lpCallbackData) lpContext;
1192 callbackData->dwCounter1++;
1194 if ( dwFlags & DPESC_TIMEDOUT )
1196 check( TRUE, lpThisSD == NULL );
1197 return FALSE;
1199 check( FALSE, lpThisSD == NULL );
1202 if ( U2(*lpThisSD).lpszPasswordA != NULL )
1204 check( TRUE, (lpThisSD->dwFlags & DPSESSION_PASSWORDREQUIRED) != 0 );
1207 if ( lpThisSD->dwFlags & DPSESSION_NEWPLAYERSDISABLED )
1209 check( 0, lpThisSD->dwCurrentPlayers );
1212 check( sizeof(*lpThisSD), lpThisSD->dwSize );
1213 checkLP( NULL, U2(*lpThisSD).lpszPasswordA );
1215 return TRUE;
1218 static LPDIRECTPLAY4 create_session(DPSESSIONDESC2 *lpdpsd)
1221 LPDIRECTPLAY4 pDP;
1222 DPNAME name;
1223 DPID dpid;
1224 HRESULT hr;
1226 CoInitialize(NULL);
1228 CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
1229 &IID_IDirectPlay4A, (LPVOID*) &pDP );
1231 init_TCPIP_provider( pDP, "127.0.0.1", 0 );
1233 hr = IDirectPlayX_Open( pDP, lpdpsd, DPOPEN_CREATE );
1234 todo_wine checkHR( DP_OK, hr );
1236 if ( ! (lpdpsd->dwFlags & DPSESSION_NEWPLAYERSDISABLED) )
1238 ZeroMemory( &name, sizeof(DPNAME) );
1239 name.dwSize = sizeof(DPNAME);
1240 U1(name).lpszShortNameA = (LPSTR) "bofh";
1242 hr = IDirectPlayX_CreatePlayer( pDP, &dpid, &name, NULL, NULL,
1243 0, DPPLAYER_SERVERPLAYER );
1244 todo_wine checkHR( DP_OK, hr );
1247 return pDP;
1251 static void test_EnumSessions(void)
1254 #define N_SESSIONS 6
1256 LPDIRECTPLAY4 pDP, pDPserver[N_SESSIONS];
1257 DPSESSIONDESC2 dpsd, dpsd_server[N_SESSIONS];
1258 CallbackData callbackData;
1259 HRESULT hr;
1260 UINT i;
1263 CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
1264 &IID_IDirectPlay4A, (LPVOID*) &pDP );
1265 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
1266 callbackData.dwCounter1 = -1; /* So that after a call to EnumSessions
1267 we get the exact number of sessions */
1268 callbackData.dwFlags = 0;
1271 /* Service provider not initialized */
1272 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1273 (LPVOID) &callbackData, 0 );
1274 checkHR( DPERR_UNINITIALIZED, hr );
1277 init_TCPIP_provider( pDP, "127.0.0.1", 0 );
1280 /* Session with no size */
1281 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1282 (LPVOID) &callbackData, 0 );
1283 todo_wine checkHR( DPERR_INVALIDPARAMS, hr );
1285 if ( hr == DPERR_UNINITIALIZED )
1287 skip( "EnumSessions not implemented\n" );
1288 return;
1291 dpsd.dwSize = sizeof(DPSESSIONDESC2);
1294 /* No sessions */
1295 callbackData.dwCounter1 = -1;
1296 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1297 (LPVOID) &callbackData, 0 );
1298 checkHR( DP_OK, hr );
1299 check( 0, callbackData.dwCounter1 );
1302 dpsd.guidApplication = appGuid;
1304 /* Set up sessions */
1305 for (i=0; i<N_SESSIONS; i++)
1307 memcpy( &dpsd_server[i], &dpsd, sizeof(DPSESSIONDESC2) );
1310 U1(dpsd_server[0]).lpszSessionNameA = (LPSTR) "normal";
1311 dpsd_server[0].dwFlags = ( DPSESSION_CLIENTSERVER |
1312 DPSESSION_DIRECTPLAYPROTOCOL );
1313 dpsd_server[0].dwMaxPlayers = 10;
1315 U1(dpsd_server[1]).lpszSessionNameA = (LPSTR) "full";
1316 dpsd_server[1].dwFlags = ( DPSESSION_CLIENTSERVER |
1317 DPSESSION_DIRECTPLAYPROTOCOL );
1318 dpsd_server[1].dwMaxPlayers = 1;
1320 U1(dpsd_server[2]).lpszSessionNameA = (LPSTR) "no new";
1321 dpsd_server[2].dwFlags = ( DPSESSION_CLIENTSERVER |
1322 DPSESSION_DIRECTPLAYPROTOCOL |
1323 DPSESSION_NEWPLAYERSDISABLED );
1324 dpsd_server[2].dwMaxPlayers = 10;
1326 U1(dpsd_server[3]).lpszSessionNameA = (LPSTR) "no join";
1327 dpsd_server[3].dwFlags = ( DPSESSION_CLIENTSERVER |
1328 DPSESSION_DIRECTPLAYPROTOCOL |
1329 DPSESSION_JOINDISABLED );
1330 dpsd_server[3].dwMaxPlayers = 10;
1332 U1(dpsd_server[4]).lpszSessionNameA = (LPSTR) "private";
1333 dpsd_server[4].dwFlags = ( DPSESSION_CLIENTSERVER |
1334 DPSESSION_DIRECTPLAYPROTOCOL |
1335 DPSESSION_PRIVATE );
1336 dpsd_server[4].dwMaxPlayers = 10;
1337 U2(dpsd_server[4]).lpszPasswordA = (LPSTR) "password";
1339 U1(dpsd_server[5]).lpszSessionNameA = (LPSTR) "protected";
1340 dpsd_server[5].dwFlags = ( DPSESSION_CLIENTSERVER |
1341 DPSESSION_DIRECTPLAYPROTOCOL |
1342 DPSESSION_PASSWORDREQUIRED );
1343 dpsd_server[5].dwMaxPlayers = 10;
1344 U2(dpsd_server[5]).lpszPasswordA = (LPSTR) "password";
1347 for (i=0; i<N_SESSIONS; i++)
1349 pDPserver[i] = create_session( &dpsd_server[i] );
1353 /* Invalid params */
1354 callbackData.dwCounter1 = -1;
1355 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1356 (LPVOID) &callbackData, -1 );
1357 checkHR( DPERR_INVALIDPARAMS, hr );
1359 hr = IDirectPlayX_EnumSessions( pDP, NULL, 0, EnumSessions_cb,
1360 (LPVOID) &callbackData, 0 );
1361 checkHR( DPERR_INVALIDPARAMS, hr );
1363 check( -1, callbackData.dwCounter1 );
1366 /* Flag tests */
1367 callbackData.dwFlags = DPENUMSESSIONS_ALL; /* Doesn't list private,
1368 protected */
1369 callbackData.dwCounter1 = -1;
1370 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1371 (LPVOID) &callbackData,
1372 callbackData.dwFlags );
1373 check( N_SESSIONS-2, callbackData.dwCounter1 );
1375 /* Doesn't list private */
1376 callbackData.dwFlags = ( DPENUMSESSIONS_ALL |
1377 DPENUMSESSIONS_PASSWORDREQUIRED );
1378 callbackData.dwCounter1 = -1;
1379 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1380 (LPVOID) &callbackData,
1381 callbackData.dwFlags );
1382 check( N_SESSIONS-1, callbackData.dwCounter1 );
1384 /* Doesn't list full, no new, no join, private, protected */
1385 callbackData.dwFlags = DPENUMSESSIONS_AVAILABLE;
1386 callbackData.dwCounter1 = -1;
1387 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1388 (LPVOID) &callbackData,
1389 callbackData.dwFlags );
1390 check( N_SESSIONS-5, callbackData.dwCounter1 );
1392 /* Like with DPENUMSESSIONS_AVAILABLE */
1393 callbackData.dwFlags = 0;
1394 callbackData.dwCounter1 = -1;
1395 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1396 (LPVOID) &callbackData,
1397 callbackData.dwFlags );
1398 check( N_SESSIONS-5, callbackData.dwCounter1 );
1400 /* Doesn't list full, no new, no join, private */
1401 callbackData.dwFlags = DPENUMSESSIONS_PASSWORDREQUIRED;
1402 callbackData.dwCounter1 = -1;
1403 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1404 (LPVOID) &callbackData,
1405 callbackData.dwFlags );
1406 check( N_SESSIONS-4, callbackData.dwCounter1 );
1409 /* Async enumeration */
1410 callbackData.dwFlags = DPENUMSESSIONS_ASYNC;
1411 callbackData.dwCounter1 = -1;
1412 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1413 (LPVOID) &callbackData,
1414 callbackData.dwFlags );
1415 check( N_SESSIONS-4, callbackData.dwCounter1 ); /* Read cache of last
1416 sync enumeration */
1418 callbackData.dwFlags = DPENUMSESSIONS_STOPASYNC;
1419 callbackData.dwCounter1 = -1;
1420 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1421 (LPVOID) &callbackData,
1422 callbackData.dwFlags );
1423 check( 0, callbackData.dwCounter1 ); /* Stop enumeration */
1425 callbackData.dwFlags = DPENUMSESSIONS_ASYNC;
1426 callbackData.dwCounter1 = -1;
1427 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1428 (LPVOID) &callbackData,
1429 callbackData.dwFlags );
1430 check( 0, callbackData.dwCounter1 ); /* Start enumeration */
1432 Sleep(500); /* Give time to fill the cache */
1434 callbackData.dwFlags = DPENUMSESSIONS_ASYNC;
1435 callbackData.dwCounter1 = -1;
1436 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1437 (LPVOID) &callbackData,
1438 callbackData.dwFlags );
1439 check( N_SESSIONS-5, callbackData.dwCounter1 ); /* Retrieve results */
1441 callbackData.dwFlags = DPENUMSESSIONS_STOPASYNC;
1442 callbackData.dwCounter1 = -1;
1443 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1444 (LPVOID) &callbackData,
1445 callbackData.dwFlags );
1446 check( 0, callbackData.dwCounter1 ); /* Stop enumeration */
1449 /* Specific tests for passworded sessions */
1451 for (i=0; i<N_SESSIONS; i++)
1453 IDirectPlayX_Release( pDPserver[i] );
1456 /* - Only session password set */
1457 for (i=4;i<=5;i++)
1459 U2(dpsd_server[i]).lpszPasswordA = (LPSTR) "password";
1460 dpsd_server[i].dwFlags = 0;
1461 pDPserver[i] = create_session( &dpsd_server[i] );
1464 callbackData.dwFlags = 0;
1465 callbackData.dwCounter1 = -1;
1466 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1467 (LPVOID) &callbackData,
1468 callbackData.dwFlags );
1469 check( 0, callbackData.dwCounter1 );
1471 callbackData.dwFlags = DPENUMSESSIONS_PASSWORDREQUIRED;
1472 callbackData.dwCounter1 = -1;
1473 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1474 (LPVOID) &callbackData,
1475 callbackData.dwFlags );
1476 check( 2, callbackData.dwCounter1 ); /* Both sessions automatically
1477 set DPSESSION_PASSWORDREQUIRED */
1479 /* - Only session flag set */
1480 for (i=4; i<=5; i++)
1482 IDirectPlayX_Release( pDPserver[i] );
1483 U2(dpsd_server[i]).lpszPasswordA = NULL;
1485 dpsd_server[4].dwFlags = DPSESSION_PRIVATE;
1486 dpsd_server[5].dwFlags = DPSESSION_PASSWORDREQUIRED;
1487 for (i=4; i<=5; i++)
1489 pDPserver[i] = create_session( &dpsd_server[i] );
1492 callbackData.dwFlags = 0;
1493 callbackData.dwCounter1 = -1;
1494 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1495 (LPVOID) &callbackData,
1496 callbackData.dwFlags );
1497 check( 2, callbackData.dwCounter1 ); /* Without password,
1498 the flag is ignored */
1500 /* - Both session flag and password set */
1501 for (i=4; i<=5; i++)
1503 IDirectPlayX_Release( pDPserver[i] );
1504 U2(dpsd_server[i]).lpszPasswordA = (LPSTR) "password";
1506 dpsd_server[4].dwFlags = DPSESSION_PRIVATE;
1507 dpsd_server[5].dwFlags = DPSESSION_PASSWORDREQUIRED;
1508 for (i=4; i<=5; i++)
1510 pDPserver[i] = create_session( &dpsd_server[i] );
1513 /* - Listing without password */
1514 callbackData.dwCounter1 = -1;
1515 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1516 (LPVOID) &callbackData,
1517 callbackData.dwFlags );
1518 check( 0, callbackData.dwCounter1 );
1520 callbackData.dwFlags = DPENUMSESSIONS_PASSWORDREQUIRED;
1521 callbackData.dwCounter1 = -1;
1522 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1523 (LPVOID) &callbackData,
1524 callbackData.dwFlags );
1525 check( 1, callbackData.dwCounter1 );
1527 /* - Listing with incorrect password */
1528 U2(dpsd).lpszPasswordA = (LPSTR) "bad_password";
1529 callbackData.dwFlags = 0;
1530 callbackData.dwCounter1 = -1;
1531 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1532 (LPVOID) &callbackData,
1533 callbackData.dwFlags );
1534 check( 0, callbackData.dwCounter1 );
1536 callbackData.dwFlags = DPENUMSESSIONS_PASSWORDREQUIRED;
1537 callbackData.dwCounter1 = -1;
1538 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1539 (LPVOID) &callbackData,
1540 callbackData.dwFlags );
1541 check( 1, callbackData.dwCounter1 );
1543 /* - Listing with correct password */
1544 U2(dpsd).lpszPasswordA = (LPSTR) "password";
1545 callbackData.dwCounter1 = -1;
1546 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1547 (LPVOID) &callbackData,
1548 callbackData.dwFlags );
1549 check( 2, callbackData.dwCounter1 );
1552 U2(dpsd).lpszPasswordA = NULL;
1553 callbackData.dwFlags = DPENUMSESSIONS_ASYNC;
1554 callbackData.dwCounter1 = -1;
1555 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1556 (LPVOID) &callbackData,
1557 callbackData.dwFlags );
1558 check( 2, callbackData.dwCounter1 ); /* Read cache of last sync enumeration,
1559 even private sessions */
1562 /* GUID tests */
1564 /* - Creating two servers with different application GUIDs */
1565 for (i=4; i<=5; i++)
1567 IDirectPlayX_Release( pDPserver[i] );
1568 dpsd_server[i].dwFlags = ( DPSESSION_CLIENTSERVER |
1569 DPSESSION_DIRECTPLAYPROTOCOL );
1570 U2(dpsd_server[i]).lpszPasswordA = NULL;
1571 dpsd_server[i].dwMaxPlayers = 10;
1573 U1(dpsd_server[4]).lpszSessionNameA = (LPSTR) "normal1";
1574 dpsd_server[4].guidApplication = appGuid;
1575 U1(dpsd_server[5]).lpszSessionNameA = (LPSTR) "normal2";
1576 dpsd_server[5].guidApplication = appGuid2;
1577 for (i=4; i<=5; i++)
1579 pDPserver[i] = create_session( &dpsd_server[i] );
1582 callbackData.dwFlags = 0;
1584 dpsd.guidApplication = appGuid2;
1585 callbackData.dwCounter1 = -1;
1586 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1587 (LPVOID) &callbackData,
1588 callbackData.dwFlags );
1589 check( 1, callbackData.dwCounter1 ); /* Only one of the sessions */
1591 dpsd.guidApplication = appGuid;
1592 callbackData.dwCounter1 = -1;
1593 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1594 (LPVOID) &callbackData,
1595 callbackData.dwFlags );
1596 check( 1, callbackData.dwCounter1 ); /* The other session */
1597 /* FIXME:
1598 For some reason, if we enum 1st with appGuid and 2nd with appGuid2,
1599 in the second enum we get the 2 sessions. Dplay fault? Elves? */
1601 dpsd.guidApplication = GUID_NULL;
1602 callbackData.dwCounter1 = -1;
1603 hr = IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb,
1604 (LPVOID) &callbackData,
1605 callbackData.dwFlags );
1606 check( 2, callbackData.dwCounter1 ); /* Both sessions */
1608 for (i=4; i<=5; i++)
1610 IDirectPlayX_Release( pDPserver[i] );
1612 IDirectPlayX_Release( pDP );
1616 /* SetSessionDesc
1617 GetSessionDesc */
1619 static void test_SessionDesc(void)
1622 LPDIRECTPLAY4 pDP[2];
1623 DPSESSIONDESC2 dpsd;
1624 LPDPSESSIONDESC2 lpData[2];
1625 LPVOID lpDataMsg;
1626 DPID dpid[2];
1627 DWORD dwDataSize;
1628 HRESULT hr;
1629 UINT i;
1630 CallbackData callbackData;
1633 for (i=0; i<2; i++)
1635 CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
1636 &IID_IDirectPlay4A, (LPVOID*) &pDP[i] );
1638 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
1640 /* Service provider not initialized */
1641 hr = IDirectPlayX_SetSessionDesc( pDP[0], NULL, 0 );
1642 checkHR( DPERR_UNINITIALIZED, hr );
1644 hr = IDirectPlayX_GetSessionDesc( pDP[0], NULL, NULL );
1645 checkHR( DPERR_UNINITIALIZED, hr );
1648 init_TCPIP_provider( pDP[0], "127.0.0.1", 0 );
1649 init_TCPIP_provider( pDP[1], "127.0.0.1", 0 );
1652 /* No sessions open */
1653 hr = IDirectPlayX_SetSessionDesc( pDP[0], NULL, 0 );
1654 todo_wine checkHR( DPERR_NOSESSIONS, hr );
1656 if ( hr == DPERR_UNINITIALIZED )
1658 skip("Get/SetSessionDesc not implemented\n");
1659 return;
1662 hr = IDirectPlayX_GetSessionDesc( pDP[0], NULL, NULL );
1663 checkHR( DPERR_NOSESSIONS, hr );
1666 dpsd.dwSize = sizeof(DPSESSIONDESC2);
1667 dpsd.guidApplication = appGuid;
1668 dpsd.dwMaxPlayers = 10;
1671 /* Host */
1672 IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE );
1673 /* Peer */
1674 IDirectPlayX_EnumSessions( pDP[1], &dpsd, 0, EnumSessions_cb_join,
1675 (LPVOID)pDP[1], 0 );
1677 for (i=0; i<2; i++)
1679 /* Players, only to receive messages */
1680 IDirectPlayX_CreatePlayer( pDP[i], &dpid[i], NULL, NULL, NULL, 0, 0 );
1682 lpData[i] = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 1024 );
1684 lpDataMsg = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 1024 );
1687 /* Incorrect parameters */
1688 hr = IDirectPlayX_SetSessionDesc( pDP[0], NULL, 0 );
1689 checkHR( DPERR_INVALIDPARAMS, hr );
1690 hr = IDirectPlayX_GetSessionDesc( pDP[0], NULL, NULL );
1691 checkHR( DPERR_INVALIDPARAM, hr );
1692 hr = IDirectPlayX_GetSessionDesc( pDP[0], lpData[0], NULL );
1693 checkHR( DPERR_INVALIDPARAM, hr );
1694 dwDataSize=-1;
1695 hr = IDirectPlayX_GetSessionDesc( pDP[0], lpData[0], &dwDataSize );
1696 checkHR( DPERR_INVALIDPARAMS, hr );
1697 check( -1, dwDataSize );
1699 /* Get: Insufficient buffer size */
1700 dwDataSize=0;
1701 hr = IDirectPlayX_GetSessionDesc( pDP[0], lpData[0], &dwDataSize );
1702 checkHR( DPERR_BUFFERTOOSMALL, hr );
1703 check( dpsd.dwSize, dwDataSize );
1704 dwDataSize=4;
1705 hr = IDirectPlayX_GetSessionDesc( pDP[0], lpData[0], &dwDataSize );
1706 checkHR( DPERR_BUFFERTOOSMALL, hr );
1707 check( dpsd.dwSize, dwDataSize );
1708 dwDataSize=1024;
1709 hr = IDirectPlayX_GetSessionDesc( pDP[0], NULL, &dwDataSize );
1710 checkHR( DPERR_BUFFERTOOSMALL, hr );
1711 check( dpsd.dwSize, dwDataSize );
1713 /* Get: Regular operation
1714 * i=0: Local session
1715 * i=1: Remote session */
1716 for (i=0; i<2; i++)
1718 hr = IDirectPlayX_GetSessionDesc( pDP[i], lpData[i], &dwDataSize );
1719 checkHR( DP_OK, hr );
1720 check( sizeof(DPSESSIONDESC2), dwDataSize );
1721 check( sizeof(DPSESSIONDESC2), lpData[i]->dwSize );
1722 checkGuid( &appGuid, &lpData[i]->guidApplication );
1723 check( dpsd.dwMaxPlayers, lpData[i]->dwMaxPlayers );
1726 checkGuid( &lpData[0]->guidInstance, &lpData[1]->guidInstance );
1728 /* Set: Regular operation */
1729 U1(dpsd).lpszSessionNameA = (LPSTR) "Wahaa";
1730 hr = IDirectPlayX_SetSessionDesc( pDP[0], &dpsd, 0 );
1731 checkHR( DP_OK, hr );
1733 dwDataSize = 1024;
1734 hr = IDirectPlayX_GetSessionDesc( pDP[1], lpData[1], &dwDataSize );
1735 checkHR( DP_OK, hr );
1736 checkStr( U1(dpsd).lpszSessionNameA, U1(*lpData[1]).lpszSessionNameA );
1739 /* Set: Failing to modify a remote session */
1740 hr = IDirectPlayX_SetSessionDesc( pDP[1], &dpsd, 0 );
1741 checkHR( DPERR_ACCESSDENIED, hr );
1743 /* Trying to change inmutable properties */
1744 /* Flags */
1745 hr = IDirectPlayX_SetSessionDesc( pDP[0], &dpsd, 0 );
1746 checkHR( DP_OK, hr );
1747 dpsd.dwFlags = DPSESSION_SECURESERVER;
1748 hr = IDirectPlayX_SetSessionDesc( pDP[0], &dpsd, 0 );
1749 checkHR( DPERR_INVALIDPARAMS, hr );
1750 dpsd.dwFlags = 0;
1751 hr = IDirectPlayX_SetSessionDesc( pDP[0], &dpsd, 0 );
1752 checkHR( DP_OK, hr );
1753 /* Size */
1754 dpsd.dwSize = 2048;
1755 hr = IDirectPlayX_SetSessionDesc( pDP[0], &dpsd, 0 );
1756 checkHR( DPERR_INVALIDPARAMS, hr );
1757 dpsd.dwSize = sizeof(DPSESSIONDESC2);
1758 hr = IDirectPlayX_SetSessionDesc( pDP[0], &dpsd, 0 );
1759 checkHR( DP_OK, hr );
1761 /* Changing the GUIDs and size is ignored */
1762 dpsd.guidApplication = appGuid2;
1763 hr = IDirectPlayX_SetSessionDesc( pDP[0], &dpsd, 0 );
1764 checkHR( DP_OK, hr );
1765 dpsd.guidInstance = appGuid2;
1766 hr = IDirectPlayX_SetSessionDesc( pDP[0], &dpsd, 0 );
1767 checkHR( DP_OK, hr );
1769 hr = IDirectPlayX_GetSessionDesc( pDP[0], lpData[0], &dwDataSize );
1770 checkHR( DP_OK, hr );
1771 checkGuid( &appGuid, &lpData[0]->guidApplication );
1772 checkGuid( &lpData[1]->guidInstance, &lpData[0]->guidInstance );
1773 check( sizeof(DPSESSIONDESC2), lpData[0]->dwSize );
1776 /* Checking system messages */
1777 check_messages( pDP[0], dpid, 2, &callbackData );
1778 checkStr( "S0,S0,S0,S0,S0,S0,S0,", callbackData.szTrace1 );
1779 checkStr( "48,90,90,90,90,90,90,", callbackData.szTrace2 );
1780 check_messages( pDP[1], dpid, 2, &callbackData );
1781 checkStr( "S1,S1,S1,S1,S1,S1,", callbackData.szTrace1 );
1782 checkStr( "90,90,90,90,90,90,", callbackData.szTrace2 );
1784 for (i=0; i<2; i++)
1786 HeapFree( GetProcessHeap(), 0, lpData[i] );
1787 IDirectPlayX_Release( pDP[i] );
1792 /* CreatePlayer */
1794 static void test_CreatePlayer(void)
1797 LPDIRECTPLAY4 pDP[2];
1798 DPSESSIONDESC2 dpsd;
1799 DPNAME name;
1800 DPID dpid;
1801 HRESULT hr;
1804 CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
1805 &IID_IDirectPlay4A, (LPVOID*) &pDP[0] );
1806 CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
1807 &IID_IDirectPlay4A, (LPVOID*) &pDP[1] );
1808 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
1809 ZeroMemory( &name, sizeof(DPNAME) );
1812 /* Connection not initialized */
1813 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL, 0, 0 );
1814 checkHR( DPERR_UNINITIALIZED, hr );
1817 init_TCPIP_provider( pDP[0], "127.0.0.1", 0 );
1818 init_TCPIP_provider( pDP[1], "127.0.0.1", 0 );
1821 /* Session not open */
1822 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL, 0, 0 );
1823 todo_wine checkHR( DPERR_INVALIDPARAMS, hr );
1825 if ( hr == DPERR_UNINITIALIZED )
1827 skip( "CreatePlayer not implemented\n" );
1828 return;
1831 dpsd.dwSize = sizeof(DPSESSIONDESC2);
1832 dpsd.guidApplication = appGuid;
1833 IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE );
1836 /* Player name */
1837 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL, 0, 0 );
1838 checkHR( DP_OK, hr );
1841 name.dwSize = -1;
1844 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, &name, NULL, NULL, 0, 0 );
1845 checkHR( DP_OK, hr );
1848 name.dwSize = sizeof(DPNAME);
1849 U1(name).lpszShortNameA = (LPSTR) "test";
1850 U2(name).lpszLongNameA = NULL;
1853 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, &name, NULL, NULL,
1854 0, 0 );
1855 checkHR( DP_OK, hr );
1858 /* Null dpid */
1859 hr = IDirectPlayX_CreatePlayer( pDP[0], NULL, NULL, NULL, NULL,
1860 0, 0 );
1861 checkHR( DPERR_INVALIDPARAMS, hr );
1864 /* There can only be one server player */
1865 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
1866 0, DPPLAYER_SERVERPLAYER );
1867 checkHR( DP_OK, hr );
1868 check( DPID_SERVERPLAYER, dpid );
1870 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
1871 0, DPPLAYER_SERVERPLAYER );
1872 checkHR( DPERR_CANTCREATEPLAYER, hr );
1874 IDirectPlayX_DestroyPlayer( pDP[0], dpid );
1876 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
1877 0, DPPLAYER_SERVERPLAYER );
1878 checkHR( DP_OK, hr );
1879 check( DPID_SERVERPLAYER, dpid );
1880 IDirectPlayX_DestroyPlayer( pDP[0], dpid );
1883 /* Flags */
1884 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
1885 0, 0 );
1886 checkHR( DP_OK, hr );
1888 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
1889 0, DPPLAYER_SERVERPLAYER );
1890 checkHR( DP_OK, hr );
1891 check( DPID_SERVERPLAYER, dpid );
1892 IDirectPlayX_DestroyPlayer( pDP[0], dpid );
1894 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
1895 0, DPPLAYER_SPECTATOR );
1896 checkHR( DP_OK, hr );
1898 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
1899 0, ( DPPLAYER_SERVERPLAYER |
1900 DPPLAYER_SPECTATOR ) );
1901 checkHR( DP_OK, hr );
1902 check( DPID_SERVERPLAYER, dpid );
1903 IDirectPlayX_DestroyPlayer( pDP[0], dpid );
1906 /* Session with DPSESSION_NEWPLAYERSDISABLED */
1907 IDirectPlayX_Close( pDP[0] );
1908 dpsd.dwFlags = DPSESSION_NEWPLAYERSDISABLED;
1909 hr = IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE );
1910 checkHR( DP_OK, hr );
1913 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
1914 0, 0 );
1915 checkHR( DPERR_CANTCREATEPLAYER, hr );
1917 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
1918 0, DPPLAYER_SERVERPLAYER );
1919 checkHR( DPERR_CANTCREATEPLAYER, hr );
1921 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
1922 0, DPPLAYER_SPECTATOR );
1923 checkHR( DPERR_CANTCREATEPLAYER, hr );
1926 /* Creating players in a Client/Server session */
1927 IDirectPlayX_Close( pDP[0] );
1928 dpsd.dwFlags = DPSESSION_CLIENTSERVER;
1929 hr = IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE );
1930 checkHR( DP_OK, hr );
1931 hr = IDirectPlayX_EnumSessions( pDP[1], &dpsd, 0, EnumSessions_cb_join,
1932 (LPVOID) pDP[1], 0 );
1933 checkHR( DP_OK, hr );
1936 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
1937 0, 0 );
1938 checkHR( DPERR_ACCESSDENIED, hr );
1940 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
1941 0, DPPLAYER_SERVERPLAYER );
1942 checkHR( DP_OK, hr );
1943 check( DPID_SERVERPLAYER, dpid );
1945 hr = IDirectPlayX_CreatePlayer( pDP[1], &dpid, NULL, NULL, NULL,
1946 0, DPPLAYER_SERVERPLAYER );
1947 checkHR( DPERR_INVALIDFLAGS, hr );
1949 hr = IDirectPlayX_CreatePlayer( pDP[1], &dpid, NULL, NULL, NULL,
1950 0, 0 );
1951 checkHR( DP_OK, hr );
1954 IDirectPlayX_Release( pDP[0] );
1955 IDirectPlayX_Release( pDP[1] );
1959 /* GetPlayerCaps */
1961 static void test_GetPlayerCaps(void)
1964 LPDIRECTPLAY4 pDP[2];
1965 DPSESSIONDESC2 dpsd;
1966 DPID dpid[2];
1967 HRESULT hr;
1968 UINT i;
1970 DPCAPS playerCaps;
1971 DWORD dwFlags;
1974 for (i=0; i<2; i++)
1976 CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
1977 &IID_IDirectPlay4A, (LPVOID*) &pDP[i] );
1979 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
1980 dpsd.dwSize = sizeof(DPSESSIONDESC2);
1981 dpsd.guidApplication = appGuid;
1982 dpsd.dwMaxPlayers = 10;
1984 ZeroMemory( &playerCaps, sizeof(DPCAPS) );
1987 /* Uninitialized service provider */
1988 playerCaps.dwSize = 0;
1989 hr = IDirectPlayX_GetPlayerCaps( pDP[0], 0, &playerCaps, 0 );
1990 checkHR( DPERR_UNINITIALIZED, hr );
1992 playerCaps.dwSize = sizeof(DPCAPS);
1993 hr = IDirectPlayX_GetPlayerCaps( pDP[0], 0, &playerCaps, 0 );
1994 checkHR( DPERR_UNINITIALIZED, hr );
1997 init_TCPIP_provider( pDP[0], "127.0.0.1", 0 );
1998 init_TCPIP_provider( pDP[1], "127.0.0.1", 0 );
2001 /* No session */
2002 playerCaps.dwSize = 0;
2004 hr = IDirectPlayX_GetPlayerCaps( pDP[0], 0, &playerCaps, 0 );
2005 todo_wine checkHR( DPERR_INVALIDPARAMS, hr );
2007 if ( hr == DPERR_UNINITIALIZED )
2009 skip( "GetPlayerCaps not implemented\n" );
2010 return;
2013 playerCaps.dwSize = sizeof(DPCAPS);
2015 hr = IDirectPlayX_GetPlayerCaps( pDP[0], 0, &playerCaps, 0 );
2016 checkHR( DPERR_INVALIDPLAYER, hr );
2018 hr = IDirectPlayX_GetPlayerCaps( pDP[0], 2, &playerCaps, 0 );
2019 checkHR( DPERR_INVALIDPLAYER, hr );
2022 hr = IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE );
2023 checkHR( DP_OK, hr );
2024 hr = IDirectPlayX_EnumSessions( pDP[1], &dpsd, 0, EnumSessions_cb_join,
2025 (LPVOID) pDP[1], 0 );
2026 checkHR( DP_OK, hr );
2028 for (i=0; i<2; i++)
2030 hr = IDirectPlayX_CreatePlayer( pDP[i], &dpid[i],
2031 NULL, NULL, NULL, 0, 0 );
2032 checkHR( DP_OK, hr );
2036 /* Uninitialized playerCaps */
2037 playerCaps.dwSize = 0;
2039 hr = IDirectPlayX_GetPlayerCaps( pDP[0], 0, &playerCaps, 0 );
2040 checkHR( DPERR_INVALIDPARAMS, hr );
2042 hr = IDirectPlayX_GetPlayerCaps( pDP[0], 2, &playerCaps, 0 );
2043 checkHR( DPERR_INVALIDPARAMS, hr );
2045 hr = IDirectPlayX_GetPlayerCaps( pDP[0], dpid[0], &playerCaps, 0 );
2046 checkHR( DPERR_INVALIDPARAMS, hr );
2049 /* Invalid player */
2050 playerCaps.dwSize = sizeof(DPCAPS);
2052 hr = IDirectPlayX_GetPlayerCaps( pDP[0], 0, &playerCaps, 0 );
2053 checkHR( DPERR_INVALIDPLAYER, hr );
2055 hr = IDirectPlayX_GetPlayerCaps( pDP[0], 2, &playerCaps, 0 );
2056 checkHR( DPERR_INVALIDPLAYER, hr );
2058 hr = IDirectPlayX_GetPlayerCaps( pDP[0], dpid[0], &playerCaps, 0 );
2059 checkHR( DP_OK, hr );
2062 /* Regular parameters */
2063 for (i=0; i<2; i++)
2065 for (dwFlags=0;
2066 dwFlags<=DPGETCAPS_GUARANTEED;
2067 dwFlags+=DPGETCAPS_GUARANTEED)
2070 hr = IDirectPlayX_GetPlayerCaps( pDP[0], dpid[i],
2071 &playerCaps, dwFlags );
2072 checkHR( DP_OK, hr );
2075 check( sizeof(DPCAPS), playerCaps.dwSize );
2076 check( 40, playerCaps.dwSize );
2077 check( 0, playerCaps.dwMaxQueueSize );
2078 check( 0, playerCaps.dwHundredBaud );
2079 check( 0, playerCaps.dwLatency );
2080 check( 65536, playerCaps.dwMaxLocalPlayers );
2081 check( 20, playerCaps.dwHeaderLength );
2083 if ( i == 0 )
2085 checkFlags( DPCAPS_ISHOST |
2086 DPCAPS_GUARANTEEDOPTIMIZED |
2087 DPCAPS_GUARANTEEDSUPPORTED |
2088 DPCAPS_ASYNCSUPPORTED |
2089 DPPLAYERCAPS_LOCAL,
2090 playerCaps.dwFlags, FLAGS_DPCAPS );
2092 else
2093 checkFlags( DPCAPS_ISHOST |
2094 DPCAPS_GUARANTEEDOPTIMIZED |
2095 DPCAPS_GUARANTEEDSUPPORTED |
2096 DPCAPS_ASYNCSUPPORTED,
2097 playerCaps.dwFlags, FLAGS_DPCAPS );
2099 if ( dwFlags == DPGETCAPS_GUARANTEED )
2101 check( 1048547, playerCaps.dwMaxBufferSize );
2102 check( 64, playerCaps.dwMaxPlayers );
2104 else
2106 check( 65479, playerCaps.dwMaxBufferSize );
2107 check( 65536, playerCaps.dwMaxPlayers );
2114 IDirectPlayX_Release( pDP[0] );
2115 IDirectPlayX_Release( pDP[1] );
2119 /* SetPlayerData
2120 GetPlayerData */
2122 static void test_PlayerData(void)
2124 LPDIRECTPLAY4 pDP;
2125 DPSESSIONDESC2 dpsd;
2126 DPID dpid;
2127 HRESULT hr;
2129 /* lpDataFake has to be bigger than the rest, limits lpDataGet size */
2130 LPCSTR lpDataFake = "big_fake_data_chunk";
2131 DWORD dwDataSizeFake = strlen(lpDataFake)+1;
2133 LPCSTR lpData = "remote_data";
2134 DWORD dwDataSize = strlen(lpData)+1;
2136 LPCSTR lpDataLocal = "local_data";
2137 DWORD dwDataSizeLocal = strlen(lpDataLocal)+1;
2139 LPSTR lpDataGet = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
2140 dwDataSizeFake );
2141 DWORD dwDataSizeGet = dwDataSizeFake;
2144 CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
2145 &IID_IDirectPlay4A, (LPVOID*) &pDP );
2147 /* No service provider */
2148 hr = IDirectPlayX_SetPlayerData( pDP, 0, (LPVOID) lpData,
2149 dwDataSize, 0 );
2150 checkHR( DPERR_UNINITIALIZED, hr );
2152 hr = IDirectPlayX_GetPlayerData( pDP, 0, (LPVOID) lpDataGet,
2153 &dwDataSizeGet, 0 );
2154 checkHR( DPERR_UNINITIALIZED, hr );
2157 init_TCPIP_provider( pDP, "127.0.0.1", 0 );
2159 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
2160 dpsd.dwSize = sizeof(DPSESSIONDESC2);
2161 dpsd.guidApplication = appGuid;
2162 IDirectPlayX_Open( pDP, &dpsd, DPOPEN_CREATE );
2165 /* Invalid player */
2166 hr = IDirectPlayX_SetPlayerData( pDP, 0, (LPVOID) lpData,
2167 dwDataSize, 0 );
2168 todo_wine checkHR( DPERR_INVALIDPLAYER, hr );
2170 hr = IDirectPlayX_GetPlayerData( pDP, 0, (LPVOID) lpDataGet,
2171 &dwDataSizeGet, 0 );
2172 todo_wine checkHR( DPERR_INVALIDPLAYER, hr );
2174 if ( hr == DPERR_UNINITIALIZED )
2176 skip( "Get/SetPlayerData not implemented\n" );
2177 return;
2180 /* Create the player */
2181 /* By default, the data is remote */
2182 hr = IDirectPlayX_CreatePlayer( pDP, &dpid, NULL, NULL, (LPVOID) lpData,
2183 dwDataSize, 0 );
2184 checkHR( DP_OK, hr );
2186 /* Invalid parameters */
2187 hr = IDirectPlayX_SetPlayerData( pDP, dpid, NULL,
2188 dwDataSize, 0 );
2189 checkHR( DPERR_INVALIDPARAMS, hr );
2190 hr = IDirectPlayX_SetPlayerData( pDP, dpid, (LPVOID) lpDataGet,
2191 -1, 0 );
2192 checkHR( DPERR_INVALIDPARAMS, hr );
2194 hr = IDirectPlayX_GetPlayerData( pDP, dpid, (LPVOID) lpDataGet,
2195 NULL, 0 );
2196 checkHR( DPERR_INVALIDPARAMS, hr );
2200 * Remote data (default)
2204 /* Buffer redimension */
2205 dwDataSizeGet = dwDataSizeFake;
2206 strcpy(lpDataGet, lpDataFake);
2207 hr = IDirectPlayX_GetPlayerData( pDP, dpid, NULL,
2208 &dwDataSizeGet, 0 );
2209 check( DPERR_BUFFERTOOSMALL, hr );
2210 check( dwDataSize, dwDataSizeGet );
2211 checkStr( lpDataFake, lpDataGet );
2213 dwDataSizeGet = 2;
2214 strcpy(lpDataGet, lpDataFake);
2215 hr = IDirectPlayX_GetPlayerData( pDP, dpid, (LPVOID) lpDataGet,
2216 &dwDataSizeGet, 0 );
2217 check( DPERR_BUFFERTOOSMALL, hr );
2218 check( dwDataSize, dwDataSizeGet );
2220 strcpy(lpDataGet, lpDataFake);
2221 hr = IDirectPlayX_GetPlayerData( pDP, dpid, (LPVOID) lpDataGet,
2222 &dwDataSizeGet, 0 );
2223 checkHR( DP_OK, hr );
2224 check( dwDataSize, dwDataSizeGet );
2225 checkStr( lpData, lpDataGet );
2227 /* Normal operation */
2228 dwDataSizeGet = dwDataSizeFake;
2229 strcpy(lpDataGet, lpDataFake);
2230 hr = IDirectPlayX_GetPlayerData( pDP, dpid, (LPVOID) lpDataGet,
2231 &dwDataSizeGet, 0 );
2232 checkHR( DP_OK, hr );
2233 check( dwDataSize, dwDataSizeGet );
2234 checkStr( lpData, lpDataGet );
2236 /* Flag tests */
2237 dwDataSizeGet = dwDataSizeFake;
2238 strcpy(lpDataGet, lpDataFake);
2239 hr = IDirectPlayX_GetPlayerData( pDP, dpid, (LPVOID) lpDataGet,
2240 &dwDataSizeGet, 0 );
2241 checkHR( DP_OK, hr );
2242 check( dwDataSize, dwDataSizeGet ); /* Remote: works as expected */
2243 checkStr( lpData, lpDataGet );
2245 dwDataSizeGet = dwDataSizeFake;
2246 strcpy(lpDataGet, lpDataFake);
2247 hr = IDirectPlayX_GetPlayerData( pDP, dpid, (LPVOID) lpDataGet,
2248 &dwDataSizeGet, DPGET_REMOTE );
2249 checkHR( DP_OK, hr );
2250 check( dwDataSize, dwDataSizeGet ); /* Same behaviour as in previous test */
2251 checkStr( lpData, lpDataGet );
2253 dwDataSizeGet = dwDataSizeFake;
2254 strcpy(lpDataGet, lpDataFake);
2255 hr = IDirectPlayX_GetPlayerData( pDP, dpid, (LPVOID) lpDataGet,
2256 &dwDataSizeGet, DPGET_LOCAL );
2257 checkHR( DP_OK, hr );
2258 check( 0, dwDataSizeGet ); /* Sets size to 0 (as local data doesn't exist) */
2259 checkStr( lpDataFake, lpDataGet );
2261 dwDataSizeGet = dwDataSizeFake;
2262 strcpy(lpDataGet, lpDataFake);
2263 hr = IDirectPlayX_GetPlayerData( pDP, dpid, (LPVOID) lpDataGet,
2264 &dwDataSizeGet,
2265 DPGET_LOCAL | DPGET_REMOTE );
2266 checkHR( DP_OK, hr );
2267 check( 0, dwDataSizeGet ); /* Same behaviour as in previous test */
2268 checkStr( lpDataFake, lpDataGet );
2270 /* Getting local data (which doesn't exist), buffer size is ignored */
2271 dwDataSizeGet = 0;
2272 strcpy(lpDataGet, lpDataFake);
2273 hr = IDirectPlayX_GetPlayerData( pDP, dpid, (LPVOID) lpDataGet,
2274 &dwDataSizeGet, DPGET_LOCAL );
2275 checkHR( DP_OK, hr );
2276 check( 0, dwDataSizeGet ); /* Sets size to 0 */
2277 checkStr( lpDataFake, lpDataGet );
2279 dwDataSizeGet = dwDataSizeFake;
2280 strcpy(lpDataGet, lpDataFake);
2281 hr = IDirectPlayX_GetPlayerData( pDP, dpid, NULL,
2282 &dwDataSizeGet, DPGET_LOCAL );
2283 checkHR( DP_OK, hr );
2284 check( 0, dwDataSizeGet ); /* Sets size to 0 */
2285 checkStr( lpDataFake, lpDataGet );
2289 * Local data
2293 /* Invalid flags */
2294 hr = IDirectPlayX_SetPlayerData( pDP, dpid, (LPVOID) lpDataLocal,
2295 dwDataSizeLocal,
2296 DPSET_LOCAL | DPSET_GUARANTEED );
2297 checkHR( DPERR_INVALIDPARAMS, hr );
2299 /* Correct parameters */
2300 hr = IDirectPlayX_SetPlayerData( pDP, dpid, (LPVOID) lpDataLocal,
2301 dwDataSizeLocal, DPSET_LOCAL );
2302 checkHR( DP_OK, hr );
2304 /* Flag tests (again) */
2305 dwDataSizeGet = dwDataSizeFake;
2306 strcpy(lpDataGet, lpDataFake);
2307 hr = IDirectPlayX_GetPlayerData( pDP, dpid, (LPVOID) lpDataGet,
2308 &dwDataSizeGet, 0 );
2309 checkHR( DP_OK, hr );
2310 check( dwDataSize, dwDataSizeGet ); /* Remote: works as expected */
2311 checkStr( lpData, lpDataGet );
2313 dwDataSizeGet = dwDataSizeFake;
2314 strcpy(lpDataGet, lpDataFake);
2315 hr = IDirectPlayX_GetPlayerData( pDP, dpid, (LPVOID) lpDataGet,
2316 &dwDataSizeGet, DPGET_REMOTE );
2317 checkHR( DP_OK, hr );
2318 check( dwDataSize, dwDataSizeGet ); /* Like in previous test */
2319 checkStr( lpData, lpDataGet );
2321 dwDataSizeGet = dwDataSizeFake;
2322 strcpy(lpDataGet, lpDataFake);
2323 hr = IDirectPlayX_GetPlayerData( pDP, dpid, (LPVOID) lpDataGet,
2324 &dwDataSizeGet, DPGET_LOCAL );
2325 checkHR( DP_OK, hr );
2326 check( dwDataSizeLocal, dwDataSizeGet ); /* Local: works as expected */
2327 checkStr( lpDataLocal, lpDataGet );
2329 dwDataSizeGet = dwDataSizeFake;
2330 strcpy(lpDataGet, lpDataFake);
2331 hr = IDirectPlayX_GetPlayerData( pDP, dpid, (LPVOID) lpDataGet,
2332 &dwDataSizeGet,
2333 DPGET_LOCAL | DPGET_REMOTE );
2334 checkHR( DP_OK, hr );
2335 check( dwDataSizeLocal, dwDataSizeGet ); /* Like in previous test */
2336 checkStr( lpDataLocal, lpDataGet );
2338 /* Small buffer works as expected again */
2339 dwDataSizeGet = 0;
2340 strcpy(lpDataGet, lpDataFake);
2341 hr = IDirectPlayX_GetPlayerData( pDP, dpid, (LPVOID) lpDataGet,
2342 &dwDataSizeGet, DPGET_LOCAL );
2343 checkHR( DPERR_BUFFERTOOSMALL, hr );
2344 check( dwDataSizeLocal, dwDataSizeGet );
2345 checkStr( lpDataFake, lpDataGet );
2347 dwDataSizeGet = dwDataSizeFake;
2348 strcpy(lpDataGet, lpDataFake);
2349 hr = IDirectPlayX_GetPlayerData( pDP, dpid, NULL,
2350 &dwDataSizeGet, DPGET_LOCAL );
2351 check( DPERR_BUFFERTOOSMALL, hr );
2352 check( dwDataSizeLocal, dwDataSizeGet );
2353 checkStr( lpDataFake, lpDataGet );
2357 * Changing remote data
2361 /* Remote data := local data */
2362 hr = IDirectPlayX_SetPlayerData( pDP, dpid, (LPVOID) lpDataLocal,
2363 dwDataSizeLocal,
2364 DPSET_GUARANTEED | DPSET_REMOTE );
2365 checkHR( DP_OK, hr );
2366 hr = IDirectPlayX_SetPlayerData( pDP, dpid, (LPVOID) lpDataLocal,
2367 dwDataSizeLocal, 0 );
2368 checkHR( DP_OK, hr );
2370 dwDataSizeGet = dwDataSizeFake;
2371 strcpy(lpDataGet, lpDataFake);
2372 hr = IDirectPlayX_GetPlayerData( pDP, dpid, (LPVOID) lpDataGet,
2373 &dwDataSizeGet, 0 );
2374 checkHR( DP_OK, hr );
2375 check( dwDataSizeLocal, dwDataSizeGet );
2376 checkStr( lpDataLocal, lpDataGet );
2378 /* Remote data := fake data */
2379 hr = IDirectPlayX_SetPlayerData( pDP, dpid, (LPVOID) lpDataFake,
2380 dwDataSizeFake, DPSET_REMOTE );
2381 checkHR( DP_OK, hr );
2383 dwDataSizeGet = dwDataSizeFake + 1;
2384 strcpy(lpDataGet, lpData);
2385 hr = IDirectPlayX_GetPlayerData( pDP, dpid, (LPVOID) lpDataGet,
2386 &dwDataSizeGet, 0 );
2387 checkHR( DP_OK, hr );
2388 check( dwDataSizeFake, dwDataSizeGet );
2389 checkStr( lpDataFake, lpDataGet );
2392 HeapFree( GetProcessHeap(), 0, lpDataGet );
2393 IDirectPlayX_Release( pDP );
2396 /* GetPlayerName
2397 SetPlayerName */
2399 static void test_PlayerName(void)
2402 LPDIRECTPLAY4 pDP[2];
2403 DPSESSIONDESC2 dpsd;
2404 DPID dpid[2];
2405 HRESULT hr;
2406 UINT i;
2408 DPNAME playerName;
2409 DWORD dwDataSize = 1024;
2410 LPVOID lpData = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwDataSize );
2411 CallbackData callbackData;
2414 for (i=0; i<2; i++)
2416 CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
2417 &IID_IDirectPlay4A, (LPVOID*) &pDP[i] );
2419 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
2420 ZeroMemory( &playerName, sizeof(DPNAME) );
2423 /* Service provider not initialized */
2424 hr = IDirectPlayX_SetPlayerName( pDP[0], 0, &playerName, 0 );
2425 checkHR( DPERR_UNINITIALIZED, hr );
2427 dwDataSize = 1024;
2428 hr = IDirectPlayX_GetPlayerName( pDP[0], 0, lpData, &dwDataSize );
2429 checkHR( DPERR_UNINITIALIZED, hr );
2430 check( 1024, dwDataSize );
2433 init_TCPIP_provider( pDP[0], "127.0.0.1", 0 );
2434 init_TCPIP_provider( pDP[1], "127.0.0.1", 0 );
2437 /* Session not initialized */
2438 hr = IDirectPlayX_SetPlayerName( pDP[0], 0, &playerName, 0 );
2439 todo_wine checkHR( DPERR_INVALIDPLAYER, hr );
2441 if ( hr == DPERR_UNINITIALIZED )
2443 skip( "Get/SetPlayerName not implemented\n" );
2444 return;
2447 dwDataSize = 1024;
2448 hr = IDirectPlayX_GetPlayerName( pDP[0], 0, lpData, &dwDataSize );
2449 checkHR( DPERR_INVALIDPLAYER, hr );
2450 check( 1024, dwDataSize );
2453 dpsd.dwSize = sizeof(DPSESSIONDESC2);
2454 dpsd.guidApplication = appGuid;
2455 dpsd.dwMaxPlayers = 10;
2456 IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE );
2457 IDirectPlayX_EnumSessions( pDP[1], &dpsd, 0, EnumSessions_cb_join,
2458 (LPVOID) pDP[1], 0 );
2460 IDirectPlayX_CreatePlayer( pDP[0], &dpid[0], NULL, NULL, NULL, 0, 0 );
2461 IDirectPlayX_CreatePlayer( pDP[1], &dpid[1], NULL, NULL, NULL, 0, 0 );
2464 /* Name not initialized */
2465 playerName.dwSize = -1;
2466 hr = IDirectPlayX_SetPlayerName( pDP[0], dpid[0], &playerName, 0 );
2467 checkHR( DP_OK, hr );
2469 dwDataSize = 1024;
2470 hr = IDirectPlayX_GetPlayerName( pDP[0], 0, lpData, &dwDataSize );
2471 checkHR( DPERR_INVALIDPLAYER, hr );
2472 check( 1024, dwDataSize );
2475 playerName.dwSize = sizeof(DPNAME);
2476 U1(playerName).lpszShortNameA = (LPSTR) "player_name";
2477 U2(playerName).lpszLongNameA = (LPSTR) "player_long_name";
2480 /* Invalid parameters */
2481 hr = IDirectPlayX_SetPlayerName( pDP[0], -1, &playerName, 0 );
2482 checkHR( DPERR_INVALIDPLAYER, hr );
2483 hr = IDirectPlayX_SetPlayerName( pDP[0], 0, &playerName, 0 );
2484 checkHR( DPERR_INVALIDPLAYER, hr );
2485 hr = IDirectPlayX_SetPlayerName( pDP[0], dpid[0], &playerName, -1 );
2486 checkHR( DPERR_INVALIDPARAMS, hr );
2488 dwDataSize = 1024;
2489 hr = IDirectPlayX_GetPlayerName( pDP[0], 0, lpData, &dwDataSize );
2490 checkHR( DPERR_INVALIDPLAYER, hr );
2491 check( 1024, dwDataSize );
2493 dwDataSize = -1;
2494 hr = IDirectPlayX_GetPlayerName( pDP[0], dpid[0], lpData, &dwDataSize );
2495 checkHR( DPERR_INVALIDPARAMS, hr );
2496 check( -1, dwDataSize );
2498 hr = IDirectPlayX_GetPlayerName( pDP[0], dpid[0], lpData, NULL );
2499 checkHR( DPERR_INVALIDPARAMS, hr );
2501 /* Trying to modify remote player */
2502 hr = IDirectPlayX_SetPlayerName( pDP[0], dpid[1], &playerName, 0 );
2503 checkHR( DPERR_ACCESSDENIED, hr );
2506 /* Regular operation */
2507 hr = IDirectPlayX_SetPlayerName( pDP[0], dpid[0], &playerName, 0 );
2509 dwDataSize = 1024;
2510 hr = IDirectPlayX_GetPlayerName( pDP[0], dpid[0], lpData, &dwDataSize );
2511 checkHR( DP_OK, hr );
2512 check( 45, dwDataSize );
2513 checkStr( U1(playerName).lpszShortNameA, U1(*(LPDPNAME)lpData).lpszShortNameA );
2514 checkStr( U2(playerName).lpszLongNameA, U2(*(LPDPNAME)lpData).lpszLongNameA );
2515 check( 0, ((LPDPNAME)lpData)->dwFlags );
2517 hr = IDirectPlayX_SetPlayerName( pDP[0], dpid[0], NULL, 0 );
2519 dwDataSize = 1024;
2520 hr = IDirectPlayX_GetPlayerName( pDP[0], dpid[0], lpData, &dwDataSize );
2521 checkHR( DP_OK, hr );
2522 check( 16, dwDataSize );
2523 checkLP( NULL, U1(*(LPDPNAME)lpData).lpszShortNameA );
2524 checkLP( NULL, U2(*(LPDPNAME)lpData).lpszLongNameA );
2525 check( 0, ((LPDPNAME)lpData)->dwFlags );
2528 /* Small buffer in get operation */
2529 dwDataSize = 1024;
2530 hr = IDirectPlayX_GetPlayerName( pDP[0], dpid[0], NULL, &dwDataSize );
2531 checkHR( DPERR_BUFFERTOOSMALL, hr );
2532 check( 16, dwDataSize );
2534 dwDataSize = 0;
2535 hr = IDirectPlayX_GetPlayerName( pDP[0], dpid[0], lpData, &dwDataSize );
2536 checkHR( DPERR_BUFFERTOOSMALL, hr );
2537 check( 16, dwDataSize );
2539 hr = IDirectPlayX_GetPlayerName( pDP[0], dpid[0], lpData, &dwDataSize );
2540 checkHR( DP_OK, hr );
2541 check( 16, dwDataSize );
2542 checkLP( NULL, U1(*(LPDPNAME)lpData).lpszShortNameA );
2543 checkLP( NULL, U2(*(LPDPNAME)lpData).lpszLongNameA );
2544 check( 0, ((LPDPNAME)lpData)->dwFlags );
2547 /* Flags */
2548 hr = IDirectPlayX_SetPlayerName( pDP[0], dpid[0], &playerName,
2549 DPSET_GUARANTEED );
2550 checkHR( DP_OK, hr );
2552 /* - Local (no propagation) */
2553 U1(playerName).lpszShortNameA = (LPSTR) "no_propagation";
2554 hr = IDirectPlayX_SetPlayerName( pDP[0], dpid[0], &playerName,
2555 DPSET_LOCAL );
2556 checkHR( DP_OK, hr );
2558 dwDataSize = 1024;
2559 hr = IDirectPlayX_GetPlayerName( pDP[0], dpid[0],
2560 lpData, &dwDataSize ); /* Local fetch */
2561 checkHR( DP_OK, hr );
2562 check( 48, dwDataSize );
2563 checkStr( "no_propagation", U1(*(LPDPNAME)lpData).lpszShortNameA );
2565 dwDataSize = 1024;
2566 hr = IDirectPlayX_GetPlayerName( pDP[1], dpid[0],
2567 lpData, &dwDataSize ); /* Remote fetch */
2568 checkHR( DP_OK, hr );
2569 check( 45, dwDataSize );
2570 checkStr( "player_name", U1(*(LPDPNAME)lpData).lpszShortNameA );
2572 /* -- 2 */
2574 U1(playerName).lpszShortNameA = (LPSTR) "no_propagation_2";
2575 hr = IDirectPlayX_SetPlayerName( pDP[0], dpid[0], &playerName,
2576 DPSET_LOCAL | DPSET_REMOTE );
2577 checkHR( DP_OK, hr );
2579 dwDataSize = 1024;
2580 hr = IDirectPlayX_GetPlayerName( pDP[0], dpid[0],
2581 lpData, &dwDataSize ); /* Local fetch */
2582 checkHR( DP_OK, hr );
2583 check( 50, dwDataSize );
2584 checkStr( "no_propagation_2", U1(*(LPDPNAME)lpData).lpszShortNameA );
2586 dwDataSize = 1024;
2587 hr = IDirectPlayX_GetPlayerName( pDP[1], dpid[0],
2588 lpData, &dwDataSize ); /* Remote fetch */
2589 checkHR( DP_OK, hr );
2590 check( 45, dwDataSize );
2591 checkStr( "player_name", U1(*(LPDPNAME)lpData).lpszShortNameA );
2593 /* - Remote (propagation, default) */
2594 U1(playerName).lpszShortNameA = (LPSTR) "propagation";
2595 hr = IDirectPlayX_SetPlayerName( pDP[0], dpid[0], &playerName,
2596 DPSET_REMOTE );
2597 checkHR( DP_OK, hr );
2599 dwDataSize = 1024;
2600 hr = IDirectPlayX_GetPlayerName( pDP[1], dpid[0],
2601 lpData, &dwDataSize ); /* Remote fetch */
2602 checkHR( DP_OK, hr );
2603 check( 45, dwDataSize );
2604 checkStr( "propagation", U1(*(LPDPNAME)lpData).lpszShortNameA );
2606 /* -- 2 */
2607 U1(playerName).lpszShortNameA = (LPSTR) "propagation_2";
2608 hr = IDirectPlayX_SetPlayerName( pDP[0], dpid[0], &playerName,
2609 0 );
2610 checkHR( DP_OK, hr );
2612 dwDataSize = 1024;
2613 hr = IDirectPlayX_GetPlayerName( pDP[1], dpid[0],
2614 lpData, &dwDataSize ); /* Remote fetch */
2615 checkHR( DP_OK, hr );
2616 check( 47, dwDataSize );
2617 checkStr( "propagation_2", U1(*(LPDPNAME)lpData).lpszShortNameA );
2620 /* Checking system messages */
2621 check_messages( pDP[0], dpid, 2, &callbackData );
2622 checkStr( "S0,S0,S0,S0,S0,S0,S0,", callbackData.szTrace1 );
2623 checkStr( "48,28,57,28,57,57,59,", callbackData.szTrace2 );
2624 check_messages( pDP[1], dpid, 2, &callbackData );
2625 checkStr( "S1,S1,S1,S1,S1,S1,", callbackData.szTrace1 );
2626 checkStr( "28,57,28,57,57,59,", callbackData.szTrace2 );
2629 HeapFree( GetProcessHeap(), 0, lpData );
2630 IDirectPlayX_Release( pDP[0] );
2631 IDirectPlayX_Release( pDP[1] );
2635 /* GetPlayerAccount */
2637 static BOOL FAR PASCAL EnumSessions_cb_join_secure( LPCDPSESSIONDESC2 lpThisSD,
2638 LPDWORD lpdwTimeOut,
2639 DWORD dwFlags,
2640 LPVOID lpContext )
2642 LPDIRECTPLAY4 pDP = (LPDIRECTPLAY4) lpContext;
2643 DPSESSIONDESC2 dpsd;
2644 DPCREDENTIALS dpCredentials;
2645 HRESULT hr;
2647 if (dwFlags & DPESC_TIMEDOUT)
2649 return FALSE;
2652 checkFlags( DPSESSION_SECURESERVER, lpThisSD->dwFlags, FLAGS_DPSESSION );
2654 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
2655 dpsd.dwSize = sizeof(DPSESSIONDESC2);
2656 dpsd.guidApplication = appGuid;
2657 dpsd.guidInstance = lpThisSD->guidInstance;
2659 ZeroMemory( &dpCredentials, sizeof(DPCREDENTIALS) );
2660 dpCredentials.dwSize = sizeof(DPCREDENTIALS);
2661 U1(dpCredentials).lpszUsernameA = (LPSTR) "user";
2662 U2(dpCredentials).lpszPasswordA = (LPSTR) "pass";
2663 hr = IDirectPlayX_SecureOpen( pDP, &dpsd, DPOPEN_JOIN,
2664 NULL, &dpCredentials );
2665 checkHR( DPERR_LOGONDENIED, hr ); /* TODO: Make this work */
2667 return TRUE;
2670 static void test_GetPlayerAccount(void)
2673 LPDIRECTPLAY4 pDP[2];
2674 DPSESSIONDESC2 dpsd;
2675 DPID dpid[2];
2676 HRESULT hr;
2677 UINT i;
2679 DWORD dwDataSize = 1024;
2680 LPVOID lpData = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwDataSize );
2683 for (i=0; i<2; i++)
2685 CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
2686 &IID_IDirectPlay4A, (LPVOID*) &pDP[i] );
2688 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
2689 dpsd.dwSize = sizeof(DPSESSIONDESC2);
2690 dpsd.guidApplication = appGuid;
2691 dpsd.dwMaxPlayers = 10;
2693 /* Uninitialized service provider */
2694 hr = IDirectPlayX_GetPlayerAccount( pDP[0], 0, 0, lpData, &dwDataSize );
2695 todo_wine checkHR( DPERR_UNINITIALIZED, hr );
2697 if ( hr == DP_OK )
2699 skip( "GetPlayerAccount not implemented\n" );
2700 return;
2704 init_TCPIP_provider( pDP[0], "127.0.0.1", 0 );
2705 init_TCPIP_provider( pDP[1], "127.0.0.1", 0 );
2708 /* No session */
2709 hr = IDirectPlayX_GetPlayerAccount( pDP[0], 0, 0, lpData, &dwDataSize );
2710 checkHR( DPERR_NOSESSIONS, hr );
2713 IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE );
2714 IDirectPlayX_EnumSessions( pDP[1], &dpsd, 0, EnumSessions_cb_join,
2715 (LPVOID) pDP[1], 0 );
2717 for (i=0; i<2; i++)
2719 hr = IDirectPlayX_CreatePlayer( pDP[i], &dpid[i], NULL, NULL, NULL,
2720 0, 0 );
2721 checkHR( DP_OK, hr );
2725 /* Session is not secure */
2726 dwDataSize = 1024;
2727 hr = IDirectPlayX_GetPlayerAccount( pDP[0], dpid[0], 0,
2728 lpData, &dwDataSize );
2729 checkHR( DPERR_UNSUPPORTED, hr );
2730 check( 1024, dwDataSize );
2733 /* Open a secure session */
2734 for (i=0; i<2; i++)
2736 hr = IDirectPlayX_Close( pDP[i] );
2737 checkHR( DP_OK, hr );
2740 dpsd.dwFlags = DPSESSION_SECURESERVER;
2741 hr = IDirectPlayX_SecureOpen( pDP[0], &dpsd, DPOPEN_CREATE, NULL, NULL );
2742 checkHR( DP_OK, hr );
2744 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid[0],
2745 NULL, NULL, NULL, 0, 0 );
2746 checkHR( DP_OK, hr );
2748 hr = IDirectPlayX_EnumSessions( pDP[1], &dpsd, 0,
2749 EnumSessions_cb_join_secure,
2750 (LPVOID) pDP[1], 0 );
2751 checkHR( DP_OK, hr );
2753 hr = IDirectPlayX_CreatePlayer( pDP[1], &dpid[1],
2754 NULL, NULL, NULL, 0, 0 );
2755 checkHR( DPERR_INVALIDPARAMS, hr );
2757 /* TODO: Player creation so that this works */
2759 /* Invalid player */
2760 dwDataSize = 1024;
2761 hr = IDirectPlayX_GetPlayerAccount( pDP[0], 0, 0,
2762 lpData, &dwDataSize );
2763 checkHR( DPERR_INVALIDPLAYER, hr );
2764 check( 1024, dwDataSize );
2766 /* Invalid flags */
2767 dwDataSize = 1024;
2768 hr = IDirectPlayX_GetPlayerAccount( pDP[0], dpid[0], -1,
2769 lpData, &dwDataSize );
2770 checkHR( DPERR_INVALIDFLAGS, hr );
2771 check( 1024, dwDataSize );
2773 dwDataSize = 1024;
2774 hr = IDirectPlayX_GetPlayerAccount( pDP[0], dpid[0], 1,
2775 lpData, &dwDataSize );
2776 checkHR( DPERR_INVALIDFLAGS, hr );
2777 check( 1024, dwDataSize );
2779 /* Small buffer */
2780 dwDataSize = 1024;
2781 hr = IDirectPlayX_GetPlayerAccount( pDP[0], dpid[0], 0,
2782 NULL, &dwDataSize );
2783 checkHR( DPERR_INVALIDPLAYER, hr );
2784 check( 0, dwDataSize );
2786 dwDataSize = 0;
2787 hr = IDirectPlayX_GetPlayerAccount( pDP[0], dpid[0], 0,
2788 lpData, &dwDataSize );
2789 checkHR( DPERR_INVALIDPLAYER, hr );
2790 check( 0, dwDataSize );
2792 hr = IDirectPlayX_GetPlayerAccount( pDP[0], dpid[0], 0,
2793 lpData, &dwDataSize );
2794 checkHR( DPERR_INVALIDPLAYER, hr );
2795 check( 0, dwDataSize );
2797 /* Normal operation */
2798 dwDataSize = 1024;
2799 hr = IDirectPlayX_GetPlayerAccount( pDP[0], dpid[0], 0,
2800 lpData, &dwDataSize );
2801 checkHR( DPERR_INVALIDPLAYER, hr );
2802 check( 1024, dwDataSize );
2805 HeapFree( GetProcessHeap(), 0, lpData );
2806 IDirectPlayX_Release( pDP[0] );
2807 IDirectPlayX_Release( pDP[1] );
2811 /* GetPlayerAddress */
2813 static BOOL FAR PASCAL EnumAddress_cb( REFGUID guidDataType,
2814 DWORD dwDataSize,
2815 LPCVOID lpData,
2816 LPVOID lpContext )
2818 lpCallbackData callbackData = (lpCallbackData) lpContext;
2819 static REFGUID types[] = { &DPAID_TotalSize,
2820 &DPAID_ServiceProvider,
2821 &DPAID_INet,
2822 &DPAID_INetW };
2823 static DWORD sizes[] = { 4, 16, 12, 24, 4, 16, 10, 20 };
2826 checkGuid( types[callbackData->dwCounter1%4], guidDataType );
2827 check( sizes[callbackData->dwCounter1], dwDataSize );
2829 switch(callbackData->dwCounter1)
2831 case 0:
2832 check( 136, *(LPDWORD) lpData );
2833 break;
2834 case 4:
2835 check( 130, *(LPDWORD) lpData );
2836 break;
2837 case 1:
2838 case 5:
2839 checkGuid( &DPSPGUID_TCPIP, (LPGUID) lpData );
2840 break;
2841 case 6:
2842 checkStr( "127.0.0.1", (LPSTR) lpData );
2843 break;
2844 default: break;
2848 callbackData->dwCounter1++;
2850 return TRUE;
2853 static void test_GetPlayerAddress(void)
2856 LPDIRECTPLAY4 pDP[2];
2857 LPDIRECTPLAYLOBBY3 pDPL;
2858 DPSESSIONDESC2 dpsd;
2859 DPID dpid[2];
2860 CallbackData callbackData;
2861 HRESULT hr;
2862 UINT i;
2864 DWORD dwDataSize = 1024;
2865 LPVOID lpData = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwDataSize );
2868 for (i=0; i<2; i++)
2870 CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
2871 &IID_IDirectPlay4A, (LPVOID*) &pDP[i] );
2873 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
2874 CoCreateInstance( &CLSID_DirectPlayLobby, NULL, CLSCTX_ALL,
2875 &IID_IDirectPlayLobby3A, (LPVOID*) &pDPL );
2878 /* Uninitialized service provider */
2879 hr = IDirectPlayX_GetPlayerAddress( pDP[0], 0, lpData, &dwDataSize );
2880 todo_wine checkHR( DPERR_UNINITIALIZED, hr );
2882 if ( hr == DP_OK )
2884 skip( "GetPlayerAddress not implemented\n" );
2885 return;
2888 init_TCPIP_provider( pDP[0], "127.0.0.1", 0 );
2889 init_TCPIP_provider( pDP[1], "127.0.0.1", 0 );
2892 /* No session */
2893 dwDataSize = 1024;
2894 hr = IDirectPlayX_GetPlayerAddress( pDP[0], 0, lpData, &dwDataSize );
2895 checkHR( DPERR_UNSUPPORTED, hr );
2896 check( 1024, dwDataSize );
2898 dwDataSize = 1024;
2899 hr = IDirectPlayX_GetPlayerAddress( pDP[0], 1, lpData, &dwDataSize );
2900 checkHR( DPERR_INVALIDPLAYER, hr );
2901 check( 1024, dwDataSize );
2904 dpsd.dwSize = sizeof(DPSESSIONDESC2);
2905 dpsd.guidApplication = appGuid;
2906 dpsd.dwMaxPlayers = 10;
2907 IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE );
2908 IDirectPlayX_EnumSessions( pDP[1], &dpsd, 0, EnumSessions_cb_join,
2909 (LPVOID) pDP[1], 0 );
2911 for (i=0; i<2; i++)
2913 hr = IDirectPlayX_CreatePlayer( pDP[i], &dpid[i], NULL, NULL, NULL,
2914 0, 0 );
2915 checkHR( DP_OK, hr );
2918 /* Invalid player */
2919 dwDataSize = 1024;
2920 hr = IDirectPlayX_GetPlayerAddress( pDP[0], 0,
2921 lpData, &dwDataSize );
2922 checkHR( DPERR_UNSUPPORTED, hr );
2923 check( 1024, dwDataSize );
2925 dwDataSize = 1024;
2926 hr = IDirectPlayX_GetPlayerAddress( pDP[0], 1,
2927 lpData, &dwDataSize );
2928 checkHR( DPERR_INVALIDPLAYER, hr );
2929 check( 1024, dwDataSize );
2931 /* Small buffer */
2932 dwDataSize = 1024;
2933 hr = IDirectPlayX_GetPlayerAddress( pDP[0], dpid[0],
2934 NULL, &dwDataSize );
2935 checkHR( DPERR_BUFFERTOOSMALL, hr );
2936 check( 136, dwDataSize );
2938 dwDataSize = 0;
2939 hr = IDirectPlayX_GetPlayerAddress( pDP[0], dpid[0],
2940 lpData, &dwDataSize );
2941 checkHR( DPERR_BUFFERTOOSMALL, hr );
2942 check( 136, dwDataSize );
2944 hr = IDirectPlayX_GetPlayerAddress( pDP[0], dpid[0],
2945 lpData, &dwDataSize );
2946 checkHR( DP_OK, hr );
2947 check( 136, dwDataSize );
2950 /* Regular parameters */
2951 callbackData.dwCounter1 = 0;
2953 /* - Local */
2954 dwDataSize = 1024;
2955 hr = IDirectPlayX_GetPlayerAddress( pDP[0], dpid[0],
2956 lpData, &dwDataSize );
2957 checkHR( DP_OK, hr );
2958 check( 136, dwDataSize );
2960 hr = IDirectPlayLobby_EnumAddress( pDPL, EnumAddress_cb,
2961 (LPCVOID) lpData, dwDataSize,
2962 (LPVOID) &callbackData );
2963 checkHR( DP_OK, hr );
2965 check( 4, callbackData.dwCounter1 );
2967 /* - Remote */
2968 dwDataSize = 1024;
2969 hr = IDirectPlayX_GetPlayerAddress( pDP[0], dpid[1],
2970 lpData, &dwDataSize );
2971 checkHR( DP_OK, hr );
2972 check( 130, dwDataSize );
2974 hr = IDirectPlayLobby_EnumAddress( pDPL, EnumAddress_cb,
2975 (LPCVOID) lpData, dwDataSize,
2976 (LPVOID) &callbackData );
2977 checkHR( DP_OK, hr );
2979 check( 8, callbackData.dwCounter1 );
2982 HeapFree( GetProcessHeap(), 0, lpData );
2983 IDirectPlayX_Release( pDP[0] );
2984 IDirectPlayX_Release( pDP[1] );
2988 /* GetPlayerFlags */
2990 static void test_GetPlayerFlags(void)
2993 LPDIRECTPLAY4 pDP[2];
2994 DPSESSIONDESC2 dpsd;
2995 DPID dpid[4];
2996 HRESULT hr;
2997 UINT i;
2999 DWORD dwFlags = 0;
3002 for (i=0; i<2; i++)
3004 CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
3005 &IID_IDirectPlay4A, (LPVOID*) &pDP[i] );
3007 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
3008 dpsd.dwSize = sizeof(DPSESSIONDESC2);
3009 dpsd.guidApplication = appGuid;
3010 dpsd.dwMaxPlayers = 10;
3012 /* Uninitialized service provider */
3013 hr = IDirectPlayX_GetPlayerFlags( pDP[0], 0, &dwFlags );
3014 todo_wine checkHR( DPERR_UNINITIALIZED, hr );
3016 if ( hr == DP_OK )
3018 skip( "GetPlayerFlags not implemented\n" );
3019 return;
3022 init_TCPIP_provider( pDP[0], "127.0.0.1", 0 );
3023 init_TCPIP_provider( pDP[1], "127.0.0.1", 0 );
3026 /* No session */
3027 hr = IDirectPlayX_GetPlayerFlags( pDP[0], 0, &dwFlags );
3028 checkHR( DPERR_INVALIDPLAYER, hr );
3030 hr = IDirectPlayX_GetPlayerFlags( pDP[0], 1, &dwFlags );
3031 checkHR( DPERR_INVALIDPLAYER, hr );
3034 IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE );
3035 IDirectPlayX_EnumSessions( pDP[1], &dpsd, 0, EnumSessions_cb_join,
3036 (LPVOID) pDP[1], 0 );
3038 for (i=0; i<2; i++)
3040 hr = IDirectPlayX_CreatePlayer( pDP[i], &dpid[i],
3041 NULL, NULL, NULL, 0, 0 );
3042 checkHR( DP_OK, hr );
3044 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid[2],
3045 NULL, NULL, NULL,
3046 0, DPPLAYER_SPECTATOR );
3047 checkHR( DP_OK, hr );
3048 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid[3],
3049 NULL, NULL, NULL,
3050 0, DPPLAYER_SERVERPLAYER );
3051 checkHR( DP_OK, hr );
3054 /* Invalid player */
3055 hr = IDirectPlayX_GetPlayerFlags( pDP[0], 0, &dwFlags );
3056 checkHR( DPERR_INVALIDPLAYER, hr );
3058 hr = IDirectPlayX_GetPlayerFlags( pDP[0], 2, &dwFlags );
3059 checkHR( DPERR_INVALIDPLAYER, hr );
3061 /* Invalid parameters */
3062 hr = IDirectPlayX_GetPlayerFlags( pDP[0], dpid[0], NULL );
3063 checkHR( DPERR_INVALIDPARAMS, hr );
3066 /* Regular parameters */
3067 hr = IDirectPlayX_GetPlayerFlags( pDP[0], dpid[0], &dwFlags );
3068 checkHR( DP_OK, hr );
3069 checkFlags( dwFlags, DPPLAYER_LOCAL, FLAGS_DPPLAYER );
3071 hr = IDirectPlayX_GetPlayerFlags( pDP[1], dpid[1], &dwFlags );
3072 checkHR( DP_OK, hr );
3073 checkFlags( dwFlags, DPPLAYER_LOCAL, FLAGS_DPPLAYER );
3075 hr = IDirectPlayX_GetPlayerFlags( pDP[0], dpid[1], &dwFlags );
3076 checkHR( DP_OK, hr );
3077 checkFlags( dwFlags, 0, FLAGS_DPPLAYER );
3079 hr = IDirectPlayX_GetPlayerFlags( pDP[0], dpid[2], &dwFlags );
3080 checkHR( DP_OK, hr );
3081 checkFlags( dwFlags, DPPLAYER_SPECTATOR | DPPLAYER_LOCAL, FLAGS_DPPLAYER );
3083 hr = IDirectPlayX_GetPlayerFlags( pDP[1], dpid[3], &dwFlags );
3084 checkHR( DP_OK, hr );
3085 checkFlags( dwFlags, DPPLAYER_SERVERPLAYER, FLAGS_DPPLAYER );
3088 IDirectPlayX_Release( pDP[0] );
3089 IDirectPlayX_Release( pDP[1] );
3093 /* CreateGroup
3094 CreateGroupInGroup */
3096 static void test_CreateGroup(void)
3099 LPDIRECTPLAY4 pDP;
3100 DPSESSIONDESC2 dpsd;
3101 DPID idFrom, idTo, dpid, idGroup, idGroupParent;
3102 DPNAME groupName;
3103 HRESULT hr;
3104 UINT i;
3106 LPCSTR lpData = "data";
3107 DWORD dwDataSize = strlen(lpData)+1;
3108 LPDPMSG_CREATEPLAYERORGROUP lpDataGet = HeapAlloc( GetProcessHeap(),
3109 HEAP_ZERO_MEMORY,
3110 1024 );
3111 DWORD dwDataSizeGet = 1024;
3112 CallbackData callbackData;
3115 CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
3116 &IID_IDirectPlay4A, (LPVOID*) &pDP );
3117 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
3118 dpsd.dwSize = sizeof(DPSESSIONDESC2);
3119 dpsd.guidApplication = appGuid;
3120 dpsd.dwMaxPlayers = 10;
3121 ZeroMemory( &groupName, sizeof(DPNAME) );
3124 /* No service provider */
3125 hr = IDirectPlayX_CreateGroup( pDP, &idGroup, NULL, NULL, 0, 0 );
3126 checkHR( DPERR_UNINITIALIZED, hr );
3128 hr = IDirectPlayX_CreateGroupInGroup( pDP, 0, &idGroup, NULL, NULL, 0, 0 );
3129 checkHR( DPERR_UNINITIALIZED, hr );
3133 init_TCPIP_provider( pDP, "127.0.0.1", 0 );
3136 /* No session */
3137 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3138 NULL, NULL, 0, 0 );
3139 todo_wine checkHR( DPERR_INVALIDPARAMS, hr );
3141 if ( hr == DPERR_UNINITIALIZED )
3143 skip( "CreateGroup not implemented\n" );
3144 return;
3147 hr = IDirectPlayX_CreateGroupInGroup( pDP, 0, &idGroup,
3148 NULL, NULL, 0, 0 );
3149 checkHR( DPERR_INVALIDGROUP, hr );
3151 hr = IDirectPlayX_CreateGroupInGroup( pDP, 2, &idGroup,
3152 NULL, NULL, 0, 0 );
3153 checkHR( DPERR_INVALIDGROUP, hr );
3156 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_CREATE );
3157 checkHR( DP_OK, hr );
3158 IDirectPlayX_CreatePlayer( pDP, &dpid,
3159 NULL, NULL, NULL, 0, 0 );
3163 /* With name */
3164 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3165 NULL, NULL, 0, 0 );
3166 checkHR( DP_OK, hr );
3168 hr = IDirectPlayX_CreateGroupInGroup( pDP, idGroup, &idGroup,
3169 NULL, NULL, 0, 0 );
3170 checkHR( DP_OK, hr );
3172 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3173 &groupName, NULL, 0, 0 );
3174 checkHR( DP_OK, hr );
3176 hr = IDirectPlayX_CreateGroupInGroup( pDP, idGroup, &idGroup,
3177 &groupName, NULL, 0, 0 );
3178 checkHR( DP_OK, hr );
3181 groupName.dwSize = sizeof(DPNAME);
3182 groupName.lpszShortNameA = (LPSTR) lpData;
3185 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3186 &groupName, NULL, 0, 0 );
3187 checkHR( DP_OK, hr );
3189 hr = IDirectPlayX_CreateGroupInGroup( pDP, idGroup, &idGroup,
3190 &groupName, NULL, 0, 0 );
3191 checkHR( DP_OK, hr );
3194 /* Message checking */
3195 for (i=0; i<6; i++)
3197 dwDataSizeGet = 1024;
3198 hr = IDirectPlayX_Receive( pDP, &idFrom, &idTo, 0,
3199 (LPVOID) lpDataGet, &dwDataSizeGet );
3200 checkHR( DP_OK, hr );
3201 if ( NULL == lpDataGet->dpnName.lpszShortNameA )
3203 check( 48, dwDataSizeGet );
3205 else
3207 check( 48 + dwDataSize, dwDataSizeGet );
3208 checkStr( lpData, lpDataGet->dpnName.lpszShortNameA );
3210 check( DPID_SYSMSG, idFrom );
3211 checkConv( DPSYS_CREATEPLAYERORGROUP, lpDataGet->dwType, dpMsgType2str );
3212 check( DPPLAYERTYPE_GROUP, lpDataGet->dwPlayerType );
3213 checkFlags( DPGROUP_LOCAL, lpDataGet->dwFlags, FLAGS_DPGROUP );
3215 check_messages( pDP, &dpid, 1, &callbackData );
3216 checkStr( "", callbackData.szTrace1 );
3219 /* With data */
3220 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3221 NULL, (LPVOID) lpData, -1, 0 );
3222 checkHR( DPERR_INVALIDPARAMS, hr );
3224 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3225 NULL, (LPVOID) lpData, 0, 0 );
3226 checkHR( DP_OK, hr );
3228 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3229 NULL, NULL, dwDataSize, 0 );
3230 checkHR( DPERR_INVALIDPARAMS, hr );
3232 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3233 NULL, (LPVOID) lpData, dwDataSize, 0 );
3234 checkHR( DP_OK, hr );
3237 hr = IDirectPlayX_CreateGroupInGroup( pDP, idGroup, &idGroup,
3238 NULL, (LPVOID) lpData, -1, 0 );
3239 checkHR( DPERR_INVALIDPARAMS, hr );
3241 hr = IDirectPlayX_CreateGroupInGroup( pDP, idGroup, &idGroup,
3242 NULL, (LPVOID) lpData, 0, 0 );
3243 checkHR( DP_OK, hr );
3245 hr = IDirectPlayX_CreateGroupInGroup( pDP, idGroup, &idGroup,
3246 NULL, NULL, dwDataSize, 0 );
3247 checkHR( DPERR_INVALIDPARAMS, hr );
3249 hr = IDirectPlayX_CreateGroupInGroup( pDP, idGroup, &idGroup,
3250 NULL, (LPVOID)lpData, dwDataSize, 0 );
3251 checkHR( DP_OK, hr );
3254 hr = IDirectPlayX_CreateGroup( pDP, &idGroupParent,
3255 NULL, NULL, 0, 0 );
3256 checkHR( DP_OK, hr );
3259 /* Message checking */
3260 for (i=0; i<5; i++)
3262 dwDataSizeGet = 1024;
3263 hr = IDirectPlayX_Receive( pDP, &idFrom, &idTo, 0,
3264 (LPVOID) lpDataGet, &dwDataSizeGet );
3265 checkHR( DP_OK, hr );
3266 check( 48 + lpDataGet->dwDataSize, dwDataSizeGet );
3267 check( DPID_SYSMSG, idFrom );
3268 checkConv( DPSYS_CREATEPLAYERORGROUP, lpDataGet->dwType, dpMsgType2str );
3269 check( DPPLAYERTYPE_GROUP, lpDataGet->dwPlayerType );
3270 checkFlags( DPGROUP_LOCAL, lpDataGet->dwFlags, FLAGS_DPGROUP );
3272 check_messages( pDP, &dpid, 1, &callbackData );
3273 checkStr( "", callbackData.szTrace1 );
3276 /* Flags and idGroupParent */
3277 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3278 NULL, NULL, 0, 0 );
3279 checkHR( DP_OK, hr );
3281 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3282 NULL, NULL, 0, DPGROUP_HIDDEN );
3283 checkHR( DP_OK, hr );
3285 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3286 NULL, NULL, 0, DPGROUP_STAGINGAREA );
3287 checkHR( DP_OK, hr );
3289 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3290 NULL, NULL, 0,
3291 DPGROUP_HIDDEN | DPGROUP_STAGINGAREA );
3292 checkHR( DP_OK, hr );
3295 hr = IDirectPlayX_CreateGroupInGroup( pDP, idGroupParent, &idGroup,
3296 NULL, NULL, 0, 0 );
3297 checkHR( DP_OK, hr );
3299 hr = IDirectPlayX_CreateGroupInGroup( pDP, idGroupParent, &idGroup,
3300 NULL, NULL, 0, DPGROUP_HIDDEN );
3301 checkHR( DP_OK, hr );
3303 hr = IDirectPlayX_CreateGroupInGroup( pDP, idGroupParent, &idGroup,
3304 NULL, NULL, 0, DPGROUP_STAGINGAREA );
3305 checkHR( DP_OK, hr );
3307 hr = IDirectPlayX_CreateGroupInGroup( pDP, idGroupParent, &idGroup,
3308 NULL, NULL, 0,
3309 DPGROUP_HIDDEN |
3310 DPGROUP_STAGINGAREA );
3311 checkHR( DP_OK, hr );
3314 /* Message checking */
3315 for (i=0; i<8; i++)
3317 dwDataSizeGet = 1024;
3318 hr = IDirectPlayX_Receive( pDP, &idFrom, &idTo, 0,
3319 (LPVOID) lpDataGet, &dwDataSizeGet );
3320 checkHR( DP_OK, hr );
3321 check( 48, dwDataSizeGet );
3322 check( DPID_SYSMSG, idFrom );
3323 checkConv( DPSYS_CREATEPLAYERORGROUP, lpDataGet->dwType, dpMsgType2str );
3324 check( DPPLAYERTYPE_GROUP, lpDataGet->dwPlayerType );
3326 if ( lpDataGet->dpIdParent != 0 )
3328 check( idGroupParent, lpDataGet->dpIdParent );
3331 switch (i%4)
3333 case 0:
3334 checkFlags( DPGROUP_LOCAL,
3335 lpDataGet->dwFlags, FLAGS_DPGROUP );
3336 break;
3337 case 1:
3338 checkFlags( DPGROUP_LOCAL | DPGROUP_HIDDEN,
3339 lpDataGet->dwFlags, FLAGS_DPGROUP );
3340 break;
3341 case 2:
3342 checkFlags( DPGROUP_STAGINGAREA | DPGROUP_LOCAL,
3343 lpDataGet->dwFlags, FLAGS_DPGROUP );
3344 break;
3345 case 3:
3346 checkFlags( DPGROUP_STAGINGAREA | DPGROUP_LOCAL | DPGROUP_HIDDEN,
3347 lpDataGet->dwFlags, FLAGS_DPGROUP );
3348 break;
3349 default: break;
3352 check_messages( pDP, &dpid, 1, &callbackData );
3353 checkStr( "", callbackData.szTrace1 );
3356 /* If a group is created in C/S mode, no messages are sent */
3358 /* - Peer 2 peer */
3359 IDirectPlayX_Close( pDP );
3361 dpsd.dwFlags = 0;
3362 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_CREATE );
3363 checkHR( DP_OK, hr );
3364 hr = IDirectPlayX_CreatePlayer( pDP, &dpid, NULL, NULL, NULL, 0, 0 );
3365 checkHR( DP_OK, hr );
3367 hr = IDirectPlayX_CreateGroup( pDP, &idGroup, NULL, NULL, 0, 0 );
3368 checkHR( DP_OK, hr );
3370 /* Messages are received */
3371 check_messages( pDP, &dpid, 1, &callbackData );
3372 checkStr( "S0,", callbackData.szTrace1 );
3375 /* - Client/Server */
3376 IDirectPlayX_Close( pDP );
3378 dpsd.dwFlags = DPSESSION_CLIENTSERVER;
3379 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_CREATE );
3380 checkHR( DP_OK, hr );
3381 hr = IDirectPlayX_CreatePlayer( pDP, &dpid,
3382 NULL, NULL, NULL, 0,
3383 DPPLAYER_SERVERPLAYER );
3384 checkHR( DP_OK, hr );
3386 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3387 NULL, NULL, 0, 0 );
3388 checkHR( DP_OK, hr );
3390 /* No messages */
3391 check_messages( pDP, &dpid, 1, &callbackData );
3392 checkStr( "S0,", callbackData.szTrace1 ); /* Or at least there
3393 shouldn't be messages... */
3396 HeapFree( GetProcessHeap(), 0, lpDataGet );
3397 IDirectPlayX_Release( pDP );
3401 /* GroupOwner */
3403 static void test_GroupOwner(void)
3406 LPDIRECTPLAY4 pDP[2];
3407 DPSESSIONDESC2 dpsd;
3408 DPID dpid[2], idGroup, idOwner;
3409 HRESULT hr;
3410 UINT i;
3413 for (i=0; i<2; i++)
3415 CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
3416 &IID_IDirectPlay4A, (LPVOID*) &pDP[i] );
3418 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
3419 dpsd.dwSize = sizeof(DPSESSIONDESC2);
3420 dpsd.guidApplication = appGuid;
3421 dpsd.dwMaxPlayers = 10;
3422 idGroup = 0;
3423 idOwner = 0;
3425 /* Service provider not initialized */
3426 hr = IDirectPlayX_GetGroupOwner( pDP[0], idGroup, &idOwner );
3427 todo_wine checkHR( DPERR_UNINITIALIZED, hr );
3428 check( 0, idOwner );
3430 if ( hr == DP_OK )
3432 skip( "GetGroupOwner not implemented\n" );
3433 return;
3437 for (i=0; i<2; i++)
3438 init_TCPIP_provider( pDP[i], "127.0.0.1", 0 );
3440 hr = IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE );
3441 checkHR( DP_OK, hr );
3442 hr = IDirectPlayX_EnumSessions( pDP[1], &dpsd, 0, EnumSessions_cb_join,
3443 (LPVOID) pDP[1], 0 );
3444 checkHR( DP_OK, hr );
3446 for (i=0; i<2; i++)
3448 hr = IDirectPlayX_CreatePlayer( pDP[i], &dpid[i],
3449 NULL, NULL, NULL, 0, 0 );
3450 checkHR( DP_OK, hr );
3453 /* Invalid group */
3454 hr = IDirectPlayX_GetGroupOwner( pDP[0], idGroup, &idOwner );
3455 checkHR( DPERR_INVALIDGROUP, hr );
3457 hr = IDirectPlayX_CreateGroup( pDP[0], &idGroup, NULL, NULL, 0, 0 );
3458 checkHR( DP_OK, hr );
3460 /* Fails, because we need a lobby session */
3461 hr = IDirectPlayX_GetGroupOwner( pDP[0], idGroup, &idOwner );
3462 checkHR( DPERR_UNSUPPORTED, hr );
3465 /* TODO:
3466 * - Make this work
3467 * - Check migration of the ownership of a group
3468 * when the owner leaves
3472 IDirectPlayX_Release( pDP[0] );
3473 IDirectPlayX_Release( pDP[1] );
3478 START_TEST(dplayx)
3480 CoInitialize( NULL );
3482 test_DirectPlayCreate();
3483 test_EnumConnections();
3484 test_InitializeConnection();
3486 test_GetCaps();
3487 test_Open();
3488 test_EnumSessions();
3489 test_SessionDesc();
3491 test_CreatePlayer();
3492 test_GetPlayerCaps();
3493 test_PlayerData();
3494 test_PlayerName();
3495 test_GetPlayerAccount();
3496 test_GetPlayerAddress();
3497 test_GetPlayerFlags();
3499 test_CreateGroup();
3500 test_GroupOwner();
3502 CoUninitialize();