ReactOS 0.4.16-dev-306-g647d351
dplayx.c
Go to the documentation of this file.
1/* DirectPlay Conformance Tests
2 *
3 * Copyright 2007 - Alessandro Pignotti
4 *
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.
9 *
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.
14 *
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
18 */
19
20#define COBJMACROS
21#include "wine/test.h"
22#include <stdio.h>
23#define INITGUID
24#include <dplay.h>
25#include <dplobby.h>
26#include <netfw.h>
27
28static HRESULT (WINAPI *pDirectPlayEnumerateA)( LPDPENUMDPCALLBACKA, void* );
29static HRESULT (WINAPI *pDirectPlayEnumerateW)( LPDPENUMDPCALLBACKW, void* );
30static HRESULT (WINAPI *pDirectPlayCreate)( GUID *GUID, LPDIRECTPLAY *lplpDP, IUnknown *pUnk );
31
32#define check(expected, result) \
33 ok( (expected) == (result), \
34 "expected=%d got=%d\n", \
35 (int)(expected), (int)(result) );
36#define checkLP(expected, result) \
37 ok( (expected) == (result), \
38 "expected=%p got=%p\n", \
39 expected, result );
40#define checkHR(expected, result) \
41 ok( (expected) == (result), \
42 "expected=%s got=%s\n", \
43 dpResult2str(expected), dpResult2str(result) );
44#define checkStr(expected, result) \
45 ok( (result != NULL) && (!strcmp(expected, result)), \
46 "expected=%s got=%s\n", \
47 expected, result );
48#define checkFlags(expected, result, flags) \
49 ok( (expected) == (result), \
50 "expected=0x%08x(%s) got=0x%08x(%s)\n", \
51 expected, dwFlags2str(expected, flags), \
52 result, dwFlags2str(result, flags) );
53#define checkGuid(expected, result) \
54 ok( IsEqualGUID(expected, result), \
55 "expected=%s got=%s\n", \
56 Guid2str(expected), Guid2str(result) );
57#define checkConv(expected, result, function) \
58 ok( (expected) == (result), \
59 "expected=0x%08x(%s) got=0x%08x(%s)\n", \
60 expected, function(expected), \
61 result, function(result) );
62
63
64DEFINE_GUID(appGuid, 0xbdcfe03e, 0xf0ec, 0x415b, 0x82, 0x11, 0x6f, 0x86, 0xd8, 0x19, 0x7f, 0xe1);
65DEFINE_GUID(appGuid2, 0x93417d3f, 0x7d26, 0x46ba, 0xb5, 0x76, 0xfe, 0x4b, 0x20, 0xbb, 0xad, 0x70);
66DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
67DEFINE_GUID(invalid_guid, 0x7b48b707, 0x0034, 0xc000, 0x02, 0x00, 0x00, 0x00, 0xec, 0xf6, 0x32, 0x00);
68
69
70typedef struct tagCallbackData
71{
72 IDirectPlay4 *pDP;
75 char szTrace1[1024], szTrace2[1024];
79
81{
86};
87
89{
90 static UINT index = 0;
91 static char buff[10][256];
92
93 index = (index + 1) % 10;
94 *buff[index] = 0;
95
96 return buff[index];
97}
98
99
100static LPCSTR Guid2str(const GUID *guid)
101{
102 if (!guid) return "(null)";
103
104 /* Service providers */
105 if (IsEqualGUID(guid, &DPSPGUID_IPX))
106 return "DPSPGUID_IPX";
107 if (IsEqualGUID(guid, &DPSPGUID_TCPIP))
108 return "DPSPGUID_TCPIP";
109 if (IsEqualGUID(guid, &DPSPGUID_SERIAL))
110 return "DPSPGUID_SERIAL";
111 if (IsEqualGUID(guid, &DPSPGUID_MODEM))
112 return "DPSPGUID_MODEM";
113 /* DirectPlay Address IDs */
114 if (IsEqualGUID(guid, &DPAID_TotalSize))
115 return "DPAID_TotalSize";
116 if (IsEqualGUID(guid, &DPAID_ServiceProvider))
117 return "DPAID_ServiceProvider";
118 if (IsEqualGUID(guid, &DPAID_LobbyProvider))
119 return "DPAID_LobbyProvider";
120 if (IsEqualGUID(guid, &DPAID_Phone))
121 return "DPAID_Phone";
122 if (IsEqualGUID(guid, &DPAID_PhoneW))
123 return "DPAID_PhoneW";
124 if (IsEqualGUID(guid, &DPAID_Modem))
125 return "DPAID_Modem";
126 if (IsEqualGUID(guid, &DPAID_ModemW))
127 return "DPAID_ModemW";
128 if (IsEqualGUID(guid, &DPAID_INet))
129 return "DPAID_INet";
130 if (IsEqualGUID(guid, &DPAID_INetW))
131 return "DPAID_INetW";
132 if (IsEqualGUID(guid, &DPAID_INetPort))
133 return "DPAID_INetPort";
134 if (IsEqualGUID(guid, &DPAID_ComPort))
135 return "DPAID_ComPort";
136
137 return wine_dbgstr_guid(guid);
138}
139
140
142{
143 switch (hr)
144 {
145 case DP_OK: return "DP_OK";
146 case DPERR_ALREADYINITIALIZED: return "DPERR_ALREADYINITIALIZED";
147 case DPERR_ACCESSDENIED: return "DPERR_ACCESSDENIED";
148 case DPERR_ACTIVEPLAYERS: return "DPERR_ACTIVEPLAYERS";
149 case DPERR_BUFFERTOOSMALL: return "DPERR_BUFFERTOOSMALL";
150 case DPERR_CANTADDPLAYER: return "DPERR_CANTADDPLAYER";
151 case DPERR_CANTCREATEGROUP: return "DPERR_CANTCREATEGROUP";
152 case DPERR_CANTCREATEPLAYER: return "DPERR_CANTCREATEPLAYER";
153 case DPERR_CANTCREATESESSION: return "DPERR_CANTCREATESESSION";
154 case DPERR_CAPSNOTAVAILABLEYET: return "DPERR_CAPSNOTAVAILABLEYET";
155 case DPERR_EXCEPTION: return "DPERR_EXCEPTION";
156 case DPERR_GENERIC: return "DPERR_GENERIC";
157 case DPERR_INVALIDFLAGS: return "DPERR_INVALIDFLAGS";
158 case DPERR_INVALIDOBJECT: return "DPERR_INVALIDOBJECT";
159 case DPERR_INVALIDPARAMS: return "DPERR_INVALIDPARAMS";
160 /* symbol with the same value: DPERR_INVALIDPARAM */
161 case DPERR_INVALIDPLAYER: return "DPERR_INVALIDPLAYER";
162 case DPERR_INVALIDGROUP: return "DPERR_INVALIDGROUP";
163 case DPERR_NOCAPS: return "DPERR_NOCAPS";
164 case DPERR_NOCONNECTION: return "DPERR_NOCONNECTION";
165 case DPERR_NOMEMORY: return "DPERR_NOMEMORY";
166 /* symbol with the same value: DPERR_OUTOFMEMORY */
167 case DPERR_NOMESSAGES: return "DPERR_NOMESSAGES";
168 case DPERR_NONAMESERVERFOUND: return "DPERR_NONAMESERVERFOUND";
169 case DPERR_NOPLAYERS: return "DPERR_NOPLAYERS";
170 case DPERR_NOSESSIONS: return "DPERR_NOSESSIONS";
171 case DPERR_PENDING: return "DPERR_PENDING";
172 case DPERR_SENDTOOBIG: return "DPERR_SENDTOOBIG";
173 case DPERR_TIMEOUT: return "DPERR_TIMEOUT";
174 case DPERR_UNAVAILABLE: return "DPERR_UNAVAILABLE";
175 case DPERR_UNSUPPORTED: return "DPERR_UNSUPPORTED";
176 case DPERR_BUSY: return "DPERR_BUSY";
177 case DPERR_USERCANCEL: return "DPERR_USERCANCEL";
178 case DPERR_NOINTERFACE: return "DPERR_NOINTERFACE";
179 case DPERR_CANNOTCREATESERVER: return "DPERR_CANNOTCREATESERVER";
180 case DPERR_PLAYERLOST: return "DPERR_PLAYERLOST";
181 case DPERR_SESSIONLOST: return "DPERR_SESSIONLOST";
182 case DPERR_UNINITIALIZED: return "DPERR_UNINITIALIZED";
183 case DPERR_NONEWPLAYERS: return "DPERR_NONEWPLAYERS";
184 case DPERR_INVALIDPASSWORD: return "DPERR_INVALIDPASSWORD";
185 case DPERR_CONNECTING: return "DPERR_CONNECTING";
186 case DPERR_CONNECTIONLOST: return "DPERR_CONNECTIONLOST";
187 case DPERR_UNKNOWNMESSAGE: return "DPERR_UNKNOWNMESSAGE";
188 case DPERR_CANCELFAILED: return "DPERR_CANCELFAILED";
189 case DPERR_INVALIDPRIORITY: return "DPERR_INVALIDPRIORITY";
190 case DPERR_NOTHANDLED: return "DPERR_NOTHANDLED";
191 case DPERR_CANCELLED: return "DPERR_CANCELLED";
192 case DPERR_ABORTED: return "DPERR_ABORTED";
193 case DPERR_BUFFERTOOLARGE: return "DPERR_BUFFERTOOLARGE";
194 case DPERR_CANTCREATEPROCESS: return "DPERR_CANTCREATEPROCESS";
195 case DPERR_APPNOTSTARTED: return "DPERR_APPNOTSTARTED";
196 case DPERR_INVALIDINTERFACE: return "DPERR_INVALIDINTERFACE";
197 case DPERR_NOSERVICEPROVIDER: return "DPERR_NOSERVICEPROVIDER";
198 case DPERR_UNKNOWNAPPLICATION: return "DPERR_UNKNOWNAPPLICATION";
199 case DPERR_NOTLOBBIED: return "DPERR_NOTLOBBIED";
200 case DPERR_SERVICEPROVIDERLOADED: return "DPERR_SERVICEPROVIDERLOADED";
201 case DPERR_ALREADYREGISTERED: return "DPERR_ALREADYREGISTERED";
202 case DPERR_NOTREGISTERED: return "DPERR_NOTREGISTERED";
203 case DPERR_AUTHENTICATIONFAILED: return "DPERR_AUTHENTICATIONFAILED";
204 case DPERR_CANTLOADSSPI: return "DPERR_CANTLOADSSPI";
205 case DPERR_ENCRYPTIONFAILED: return "DPERR_ENCRYPTIONFAILED";
206 case DPERR_SIGNFAILED: return "DPERR_SIGNFAILED";
207 case DPERR_CANTLOADSECURITYPACKAGE: return "DPERR_CANTLOADSECURITYPACKAGE";
208 case DPERR_ENCRYPTIONNOTSUPPORTED: return "DPERR_ENCRYPTIONNOTSUPPORTED";
209 case DPERR_CANTLOADCAPI: return "DPERR_CANTLOADCAPI";
210 case DPERR_NOTLOGGEDIN: return "DPERR_NOTLOGGEDIN";
211 case DPERR_LOGONDENIED: return "DPERR_LOGONDENIED";
212 case CLASS_E_NOAGGREGATION: return "CLASS_E_NOAGGREGATION";
213
214 default:
215 {
217 sprintf( buffer, "%d", HRESULT_CODE(hr) );
218 return buffer;
219 }
220 }
221}
222
224{
225 switch(dwType)
226 {
227 case DPSYS_CREATEPLAYERORGROUP: return "DPSYS_CREATEPLAYERORGROUP";
228 case DPSYS_DESTROYPLAYERORGROUP: return "DPSYS_DESTROYPLAYERORGROUP";
229 case DPSYS_ADDPLAYERTOGROUP: return "DPSYS_ADDPLAYERTOGROUP";
230 case DPSYS_DELETEPLAYERFROMGROUP: return "DPSYS_DELETEPLAYERFROMGROUP";
231 case DPSYS_SESSIONLOST: return "DPSYS_SESSIONLOST";
232 case DPSYS_HOST: return "DPSYS_HOST";
233 case DPSYS_SETPLAYERORGROUPDATA: return "DPSYS_SETPLAYERORGROUPDATA";
234 case DPSYS_SETPLAYERORGROUPNAME: return "DPSYS_SETPLAYERORGROUPNAME";
235 case DPSYS_SETSESSIONDESC: return "DPSYS_SETSESSIONDESC";
236 case DPSYS_ADDGROUPTOGROUP: return "DPSYS_ADDGROUPTOGROUP";
237 case DPSYS_DELETEGROUPFROMGROUP: return "DPSYS_DELETEGROUPFROMGROUP";
238 case DPSYS_SECUREMESSAGE: return "DPSYS_SECUREMESSAGE";
239 case DPSYS_STARTSESSION: return "DPSYS_STARTSESSION";
240 case DPSYS_CHAT: return "DPSYS_DPSYS_CHAT";
241 case DPSYS_SETGROUPOWNER: return "DPSYS_SETGROUPOWNER";
242 case DPSYS_SENDCOMPLETE: return "DPSYS_SENDCOMPLETE";
243
244 default: return "UNKNOWN";
245 }
246}
247
249{
250
251#define FLAGS_DPCONNECTION (1<<0)
252#define FLAGS_DPENUMPLAYERS (1<<1)
253#define FLAGS_DPENUMGROUPS (1<<2)
254#define FLAGS_DPPLAYER (1<<3)
255#define FLAGS_DPGROUP (1<<4)
256#define FLAGS_DPENUMSESSIONS (1<<5)
257#define FLAGS_DPGETCAPS (1<<6)
258#define FLAGS_DPGET (1<<7)
259#define FLAGS_DPRECEIVE (1<<8)
260#define FLAGS_DPSEND (1<<9)
261#define FLAGS_DPSET (1<<10)
262#define FLAGS_DPMESSAGEQUEUE (1<<11)
263#define FLAGS_DPCONNECT (1<<12)
264#define FLAGS_DPOPEN (1<<13)
265#define FLAGS_DPSESSION (1<<14)
266#define FLAGS_DPLCONNECTION (1<<15)
267#define FLAGS_DPESC (1<<16)
268#define FLAGS_DPCAPS (1<<17)
269
271
272 /* EnumConnections */
273
274 if (flagType & FLAGS_DPCONNECTION)
275 {
277 strcat(flags, "DPCONNECTION_DIRECTPLAY,");
279 strcat(flags, "DPCONNECTION_DIRECTPLAYLOBBY,");
280 }
281
282 /* EnumPlayers,
283 EnumGroups */
284
285 if (flagType & FLAGS_DPENUMPLAYERS)
286 {
288 strcat(flags, "DPENUMPLAYERS_ALL,");
290 strcat(flags, "DPENUMPLAYERS_LOCAL,");
292 strcat(flags, "DPENUMPLAYERS_REMOTE,");
294 strcat(flags, "DPENUMPLAYERS_GROUP,");
296 strcat(flags, "DPENUMPLAYERS_SESSION,");
298 strcat(flags, "DPENUMPLAYERS_SERVERPLAYER,");
300 strcat(flags, "DPENUMPLAYERS_SPECTATOR,");
302 strcat(flags, "DPENUMPLAYERS_OWNER,");
303 }
304 if (flagType & FLAGS_DPENUMGROUPS)
305 {
307 strcat(flags, "DPENUMGROUPS_ALL,");
309 strcat(flags, "DPENUMGROUPS_LOCAL,");
311 strcat(flags, "DPENUMGROUPS_REMOTE,");
313 strcat(flags, "DPENUMGROUPS_GROUP,");
315 strcat(flags, "DPENUMGROUPS_SESSION,");
317 strcat(flags, "DPENUMGROUPS_SHORTCUT,");
319 strcat(flags, "DPENUMGROUPS_STAGINGAREA,");
321 strcat(flags, "DPENUMGROUPS_HIDDEN,");
322 }
323
324 /* CreatePlayer */
325
326 if (flagType & FLAGS_DPPLAYER)
327 {
329 strcat(flags, "DPPLAYER_SERVERPLAYER,");
331 strcat(flags, "DPPLAYER_SPECTATOR,");
333 strcat(flags, "DPPLAYER_LOCAL,");
335 strcat(flags, "DPPLAYER_OWNER,");
336 }
337
338 /* CreateGroup */
339
340 if (flagType & FLAGS_DPGROUP)
341 {
343 strcat(flags, "DPGROUP_STAGINGAREA,");
345 strcat(flags, "DPGROUP_LOCAL,");
347 strcat(flags, "DPGROUP_HIDDEN,");
348 }
349
350 /* EnumSessions */
351
352 if (flagType & FLAGS_DPENUMSESSIONS)
353 {
355 strcat(flags, "DPENUMSESSIONS_AVAILABLE,");
357 strcat(flags, "DPENUMSESSIONS_ALL,");
359 strcat(flags, "DPENUMSESSIONS_ASYNC,");
361 strcat(flags, "DPENUMSESSIONS_STOPASYNC,");
363 strcat(flags, "DPENUMSESSIONS_PASSWORDREQUIRED,");
365 strcat(flags, "DPENUMSESSIONS_RETURNSTATUS,");
366 }
367
368 /* GetCaps,
369 GetPlayerCaps */
370
371 if (flagType & FLAGS_DPGETCAPS)
372 {
374 strcat(flags, "DPGETCAPS_GUARANTEED,");
375 }
376
377 /* GetGroupData,
378 GetPlayerData */
379
380 if (flagType & FLAGS_DPGET)
381 {
382 if (dwFlags == DPGET_REMOTE)
383 strcat(flags, "DPGET_REMOTE,");
384 if (dwFlags & DPGET_LOCAL)
385 strcat(flags, "DPGET_LOCAL,");
386 }
387
388 /* Receive */
389
390 if (flagType & FLAGS_DPRECEIVE)
391 {
393 strcat(flags, "DPRECEIVE_ALL,");
395 strcat(flags, "DPRECEIVE_TOPLAYER,");
397 strcat(flags, "DPRECEIVE_FROMPLAYER,");
399 strcat(flags, "DPRECEIVE_PEEK,");
400 }
401
402 /* Send */
403
404 if (flagType & FLAGS_DPSEND)
405 {
406 /*if (dwFlags == DPSEND_NONGUARANTEED)
407 strcat(flags, "DPSEND_NONGUARANTEED,");*/
408 if (dwFlags == DPSEND_MAX_PRIORITY) /* = DPSEND_MAX_PRI */
409 {
410 strcat(flags, "DPSEND_MAX_PRIORITY,");
411 }
412 else
413 {
415 strcat(flags, "DPSEND_GUARANTEED,");
417 strcat(flags, "DPSEND_HIGHPRIORITY,");
419 strcat(flags, "DPSEND_OPENSTREAM,");
421 strcat(flags, "DPSEND_CLOSESTREAM,");
423 strcat(flags, "DPSEND_SIGNED,");
425 strcat(flags, "DPSEND_ENCRYPTED,");
427 strcat(flags, "DPSEND_LOBBYSYSTEMMESSAGE,");
428 if (dwFlags & DPSEND_ASYNC)
429 strcat(flags, "DPSEND_ASYNC,");
431 strcat(flags, "DPSEND_NOSENDCOMPLETEMSG,");
432 }
433 }
434
435 /* SetGroupData,
436 SetGroupName,
437 SetPlayerData,
438 SetPlayerName,
439 SetSessionDesc */
440
441 if (flagType & FLAGS_DPSET)
442 {
443 if (dwFlags == DPSET_REMOTE)
444 strcat(flags, "DPSET_REMOTE,");
445 if (dwFlags & DPSET_LOCAL)
446 strcat(flags, "DPSET_LOCAL,");
448 strcat(flags, "DPSET_GUARANTEED,");
449 }
450
451 /* GetMessageQueue */
452
453 if (flagType & FLAGS_DPMESSAGEQUEUE)
454 {
456 strcat(flags, "DPMESSAGEQUEUE_SEND,");
458 strcat(flags, "DPMESSAGEQUEUE_RECEIVE,");
459 }
460
461 /* Connect */
462
463 if (flagType & FLAGS_DPCONNECT)
464 {
466 strcat(flags, "DPCONNECT_RETURNSTATUS,");
467 }
468
469 /* Open */
470
471 if (flagType & FLAGS_DPOPEN)
472 {
473 if (dwFlags & DPOPEN_JOIN)
474 strcat(flags, "DPOPEN_JOIN,");
476 strcat(flags, "DPOPEN_CREATE,");
478 strcat(flags, "DPOPEN_RETURNSTATUS,");
479 }
480
481 /* DPSESSIONDESC2 */
482
483 if (flagType & FLAGS_DPSESSION)
484 {
486 strcat(flags, "DPSESSION_NEWPLAYERSDISABLED,");
488 strcat(flags, "DPSESSION_MIGRATEHOST,");
490 strcat(flags, "DPSESSION_NOMESSAGEID,");
492 strcat(flags, "DPSESSION_JOINDISABLED,");
494 strcat(flags, "DPSESSION_KEEPALIVE,");
496 strcat(flags, "DPSESSION_NODATAMESSAGES,");
498 strcat(flags, "DPSESSION_SECURESERVER,");
500 strcat(flags, "DPSESSION_PRIVATE,");
502 strcat(flags, "DPSESSION_PASSWORDREQUIRED,");
504 strcat(flags, "DPSESSION_MULTICASTSERVER,");
506 strcat(flags, "DPSESSION_CLIENTSERVER,");
507
509 strcat(flags, "DPSESSION_DIRECTPLAYPROTOCOL,");
511 strcat(flags, "DPSESSION_NOPRESERVEORDER,");
513 strcat(flags, "DPSESSION_OPTIMIZELATENCY,");
514
515 }
516
517 /* DPLCONNECTION */
518
519 if (flagType & FLAGS_DPLCONNECTION)
520 {
522 strcat(flags, "DPLCONNECTION_CREATESESSION,");
524 strcat(flags, "DPLCONNECTION_JOINSESSION,");
525 }
526
527 /* EnumSessionsCallback2 */
528
529 if (flagType & FLAGS_DPESC)
530 {
532 strcat(flags, "DPESC_TIMEDOUT,");
533 }
534
535 /* GetCaps,
536 GetPlayerCaps */
537
538 if (flagType & FLAGS_DPCAPS)
539 {
541 strcat(flags, "DPCAPS_ISHOST,");
543 strcat(flags, "DPCAPS_GROUPOPTIMIZED,");
545 strcat(flags, "DPCAPS_KEEPALIVEOPTIMIZED,");
547 strcat(flags, "DPCAPS_GUARANTEEDOPTIMIZED,");
549 strcat(flags, "DPCAPS_GUARANTEEDSUPPORTED,");
551 strcat(flags, "DPCAPS_SIGNINGSUPPORTED,");
553 strcat(flags, "DPCAPS_ENCRYPTIONSUPPORTED,");
555 strcat(flags, "DPCAPS_ASYNCCANCELSUPPORTED,");
557 strcat(flags, "DPCAPS_ASYNCCANCELALLSUPPORTED,");
559 strcat(flags, "DPCAPS_SENDTIMEOUTSUPPORTED,");
561 strcat(flags, "DPCAPS_SENDPRIORITYSUPPORTED,");
563 strcat(flags, "DPCAPS_ASYNCSUPPORTED,");
564
566 strcat(flags, "DPPLAYERCAPS_LOCAL,");
567 }
568
569 if ((strlen(flags) == 0) && (dwFlags != 0))
570 strcpy(flags, "UNKNOWN");
571 else
572 flags[strlen(flags)-1] = '\0';
573
574 return flags;
575}
576
577static char dpid2char(DPID* dpid, DWORD dpidSize, DPID idPlayer)
578{
579 UINT i;
580 if ( idPlayer == DPID_SYSMSG )
581 return 'S';
582 for (i=0; i<dpidSize; i++)
583 {
584 if ( idPlayer == dpid[i] )
585 return (char)(i+48);
586 }
587 return '?';
588}
589
590static void check_messages( IDirectPlay4 *pDP, DPID *dpid, DWORD dpidSize,
591 lpCallbackData callbackData )
592{
593 /* Retrieves all messages from the queue of pDP, performing tests
594 * to check if we are receiving what we expect.
595 *
596 * Information about the messages is stores in callbackData:
597 *
598 * callbackData->dwCounter1: Number of messages received.
599 * callbackData->szTrace1: Traces for sender and receiver.
600 * We store the position a dpid holds in the dpid array.
601 * Example:
602 *
603 * trace string: "01,02,03,14"
604 * expanded: [ '01', '02', '03', '14' ]
605 * \ \ \ \
606 * \ \ \ ) message 3: from 1 to 4
607 * \ \ ) message 2: from 0 to 3
608 * \ ) message 1: from 0 to 2
609 * ) message 0: from 0 to 1
610 *
611 * In general terms:
612 * sender of message i = character in place 3*i of the array
613 * receiver of message i = character in place 3*i+1 of the array
614 *
615 * A sender value of 'S' means DPID_SYSMSG, this is, a system message.
616 *
617 * callbackData->szTrace2: Traces for message sizes.
618 */
619
620 DPID idFrom, idTo;
621 UINT i;
622 DWORD dwDataSize = 1024;
623 LPVOID lpData = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwDataSize );
624 HRESULT hr;
625 char temp[5];
626
627 callbackData->szTrace2[0] = '\0';
628
629 i = 0;
630 while ( DP_OK == (hr = IDirectPlayX_Receive( pDP, &idFrom, &idTo, 0,
631 lpData, &dwDataSize )) )
632 {
633
634 callbackData->szTrace1[ 3*i ] = dpid2char( dpid, dpidSize, idFrom );
635 callbackData->szTrace1[ 3*i+1 ] = dpid2char( dpid, dpidSize, idTo );
636 callbackData->szTrace1[ 3*i+2 ] = ',';
637
638 sprintf( temp, "%d,", dwDataSize );
639 strcat( callbackData->szTrace2, temp );
640
641 dwDataSize = 1024;
642 ++i;
643 }
644
646
647 callbackData->szTrace1[ 3*i ] = '\0';
648 callbackData->dwCounter1 = i;
649
650
651 HeapFree( GetProcessHeap(), 0, lpData );
652}
653
654static void init_TCPIP_provider( IDirectPlay4 *pDP, LPCSTR strIPAddressString, WORD port )
655{
656
657 DPCOMPOUNDADDRESSELEMENT addressElements[3];
658 LPVOID pAddress = NULL;
659 DWORD dwAddressSize = 0;
660 IDirectPlayLobby3 *pDPL;
661 HRESULT hr;
662
663 hr = CoCreateInstance( &CLSID_DirectPlayLobby, NULL, CLSCTX_ALL,
664 &IID_IDirectPlayLobby3A, (LPVOID*) &pDPL );
665 ok (SUCCEEDED (hr), "CCI of CLSID_DirectPlayLobby / IID_IDirectPlayLobby3A failed\n");
666 if (FAILED (hr)) return;
667
668 /* Service provider */
669 addressElements[0].guidDataType = DPAID_ServiceProvider;
670 addressElements[0].dwDataSize = sizeof(GUID);
671 addressElements[0].lpData = (LPVOID) &DPSPGUID_TCPIP;
672
673 /* IP address string */
674 addressElements[1].guidDataType = DPAID_INet;
675 addressElements[1].dwDataSize = lstrlenA(strIPAddressString) + 1;
676 addressElements[1].lpData = (LPVOID) strIPAddressString;
677
678 /* Optional Port number */
679 if( port > 0 )
680 {
681 addressElements[2].guidDataType = DPAID_INetPort;
682 addressElements[2].dwDataSize = sizeof(WORD);
683 addressElements[2].lpData = &port;
684 }
685
686
687 hr = IDirectPlayLobby_CreateCompoundAddress( pDPL, addressElements, 2,
688 NULL, &dwAddressSize );
690
691 if( hr == DPERR_BUFFERTOOSMALL )
692 {
693 pAddress = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwAddressSize );
694 hr = IDirectPlayLobby_CreateCompoundAddress( pDPL, addressElements, 2,
695 pAddress, &dwAddressSize );
696 checkHR( DP_OK, hr );
697 }
698
699 hr = IDirectPlayX_InitializeConnection( pDP, pAddress, 0 );
700 checkHR( DP_OK, hr );
701
702 HeapFree( GetProcessHeap(), 0, pAddress );
704}
705
707 LPDWORD lpdwTimeOut,
709 LPVOID lpContext )
710{
711 IDirectPlay4 *pDP = lpContext;
712 DPSESSIONDESC2 dpsd;
713 HRESULT hr;
714
716 {
717 return FALSE;
718 }
719
720 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
721 dpsd.dwSize = sizeof(DPSESSIONDESC2);
722 dpsd.guidApplication = appGuid;
723 dpsd.guidInstance = lpThisSD->guidInstance;
724
725 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_JOIN );
726 checkHR( DP_OK, hr );
727
728 return TRUE;
729}
730
731
732/* DirectPlayCreate */
733
734static void test_DirectPlayCreate(void)
735{
736
737 IDirectPlay *pDP;
738 HRESULT hr;
739
740 /* TODO: Check how it behaves with pUnk!=NULL */
741
742 /* pDP==NULL */
743 hr = pDirectPlayCreate( NULL, NULL, NULL );
745 hr = pDirectPlayCreate( (LPGUID) &GUID_NULL, NULL, NULL );
747 hr = pDirectPlayCreate( (LPGUID) &DPSPGUID_TCPIP, NULL, NULL );
749
750 /* pUnk==NULL, pDP!=NULL */
751 hr = pDirectPlayCreate( NULL, &pDP, NULL );
753 hr = pDirectPlayCreate( (LPGUID) &GUID_NULL, &pDP, NULL );
754 checkHR( DP_OK, hr );
755 if ( hr == DP_OK )
757 hr = pDirectPlayCreate( (LPGUID) &DPSPGUID_TCPIP, &pDP, NULL );
758 checkHR( DP_OK, hr );
759 if ( hr == DP_OK )
761
762}
763
765{
766 struct provider_data *prov = arg;
767
768 if (!prov) return TRUE;
769
770 if (prov->call_count < ARRAY_SIZE(prov->guid_data))
771 {
772 prov->guid_ptr[prov->call_count] = guid;
773 prov->guid_data[prov->call_count] = *guid;
774
775 prov->call_count++;
776 }
777
778 if (prov->ret_value) /* Only trace when looping all providers */
779 trace("Provider #%d '%s' (%d.%d)\n", prov->call_count, name, major, minor);
780 return prov->ret_value;
781}
782
784{
785 struct provider_data *prov = arg;
786
787 if (!prov) return TRUE;
788
789 if (prov->call_count < ARRAY_SIZE(prov->guid_data))
790 {
791 prov->guid_ptr[prov->call_count] = guid;
792 prov->guid_data[prov->call_count] = *guid;
793
794 prov->call_count++;
795 }
796
797 return prov->ret_value;
798}
799
800static void test_EnumerateProviders(void)
801{
802 HRESULT hr;
803 int i;
804 struct provider_data arg;
805
806 memset(&arg, 0, sizeof(arg));
807 arg.ret_value = TRUE;
808
809 hr = pDirectPlayEnumerateA(callback_providersA, NULL);
810 ok(SUCCEEDED(hr), "DirectPlayEnumerateA failed\n");
811
812 SetLastError(0xdeadbeef);
813 hr = pDirectPlayEnumerateA(NULL, &arg);
814 ok(FAILED(hr), "DirectPlayEnumerateA expected to fail\n");
815 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got 0x%x\n", GetLastError());
816
817 SetLastError(0xdeadbeef);
818 hr = pDirectPlayEnumerateA(NULL, NULL);
819 ok(FAILED(hr), "DirectPlayEnumerateA expected to fail\n");
820 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got 0x%x\n", GetLastError());
821
822 hr = pDirectPlayEnumerateA(callback_providersA, &arg);
823 ok(SUCCEEDED(hr), "DirectPlayEnumerateA failed\n");
824 ok(arg.call_count > 0, "Expected at least one valid provider\n");
825 trace("Found %d providers\n", arg.call_count);
826
827 /* The returned GUID values must have persisted after enumeration (bug 37185) */
828 for(i = 0; i < arg.call_count; i++)
829 {
830 ok(IsEqualGUID(arg.guid_ptr[i], &arg.guid_data[i]), "#%d Expected equal GUID values\n", i);
831 }
832
833 memset(&arg, 0, sizeof(arg));
834 arg.ret_value = FALSE;
835 hr = pDirectPlayEnumerateA(callback_providersA, &arg);
836 ok(SUCCEEDED(hr), "DirectPlayEnumerateA failed\n");
837 ok(arg.call_count == 1, "Expected 1, got %d\n", arg.call_count);
838
839 hr = pDirectPlayEnumerateW(callback_providersW, NULL);
840 ok(SUCCEEDED(hr), "DirectPlayEnumerateW failed\n");
841
842 SetLastError(0xdeadbeef);
843 hr = pDirectPlayEnumerateW(NULL, &arg);
844 ok(FAILED(hr), "DirectPlayEnumerateW expected to fail\n");
845 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got 0x%x\n", GetLastError());
846
847 SetLastError(0xdeadbeef);
848 hr = pDirectPlayEnumerateW(NULL, NULL);
849 ok(FAILED(hr), "DirectPlayEnumerateW expected to fail\n");
850 ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got 0x%x\n", GetLastError());
851
852 memset(&arg, 0, sizeof(arg));
853 arg.ret_value = TRUE;
854 hr = pDirectPlayEnumerateW(callback_providersW, &arg);
855 ok(SUCCEEDED(hr), "DirectPlayEnumerateW failed\n");
856 ok(arg.call_count > 0, "Expected at least one valid provider\n");
857
858 /* The returned GUID values must have persisted after enumeration (bug 37185) */
859 for(i = 0; i < arg.call_count; i++)
860 {
861 ok(IsEqualGUID(arg.guid_ptr[i], &arg.guid_data[i]), "#%d Expected equal GUID values\n", i);
862 }
863
864 memset(&arg, 0, sizeof(arg));
865 arg.ret_value = FALSE;
866 hr = pDirectPlayEnumerateW(callback_providersW, &arg);
867 ok(SUCCEEDED(hr), "DirectPlayEnumerateW failed\n");
868 ok(arg.call_count == 1, "Expected 1, got %d\n", arg.call_count);
869}
870
871/* EnumConnections */
872
874 DWORD dwDataSize,
875 LPCVOID lpData,
876 LPVOID lpContext )
877{
878 lpCallbackData callbackData = lpContext;
879
880 static REFGUID types[] = { &DPAID_TotalSize,
881 &DPAID_ServiceProvider,
882 &GUID_NULL };
883 static DWORD sizes[] = { 4, 16, 0 };
884 static REFGUID sps[] = { &DPSPGUID_SERIAL, &DPSPGUID_MODEM,
885 &DPSPGUID_IPX, &DPSPGUID_TCPIP };
886
887
888 checkGuid( types[ callbackData->dwCounter2 ], guidDataType );
889 check( sizes[ callbackData->dwCounter2 ], dwDataSize );
890
891 if ( IsEqualGUID( types[0], guidDataType ) )
892 {
893 todo_wine check( 80, *((LPDWORD) lpData) );
894 }
895 else if ( IsEqualGUID( types[1], guidDataType ) )
896 {
897 BOOL found = FALSE;
898 int i;
899 for( i=0; i < ARRAY_SIZE(sps) && !found; i++ )
900 found = IsEqualGUID( sps[i], lpData );
901 ok( found, "Unknown Address type found %s\n", wine_dbgstr_guid(lpData) );
902 }
903
904 callbackData->dwCounter2++;
905
906 return TRUE;
907}
908
910 LPVOID lpConnection,
911 DWORD dwConnectionSize,
914 LPVOID lpContext )
915{
916
917 lpCallbackData callbackData = lpContext;
918 IDirectPlayLobby *pDPL;
919 HRESULT hr;
920
921
922 if (!callbackData->dwFlags)
923 {
924 callbackData->dwFlags = DPCONNECTION_DIRECTPLAY;
925 }
926
927 checkFlags( callbackData->dwFlags, dwFlags, FLAGS_DPCONNECTION );
928
929 /* Get info from lpConnection */
930 hr = CoCreateInstance( &CLSID_DirectPlayLobby, NULL, CLSCTX_ALL,
931 &IID_IDirectPlayLobby3A, (LPVOID*) &pDPL );
932 ok( SUCCEEDED(hr), "CCI of CLSID_DirectPlayLobby / IID_IDirectPlayLobby3A failed\n");
933 if (FAILED(hr))
934 return FALSE;
935
936 callbackData->dwCounter2 = 0;
938 dwConnectionSize, callbackData );
939 todo_wine check( 3, callbackData->dwCounter2 );
940
941 callbackData->dwCounter1++;
942
944
945 return TRUE;
946}
947
948static void test_EnumConnections(void)
949{
950
951 IDirectPlay4 *pDP;
952 CallbackData callbackData;
953 HRESULT hr;
954
955
956 hr = CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
957 &IID_IDirectPlay4A, (LPVOID*) &pDP );
958
959 ok (SUCCEEDED(hr), "CCI of CLSID_DirectPlay / IID_IDirectPlay4A failed\n");
960 if (FAILED(hr)) return;
961
962 callbackData.dwCounter1 = 0;
963 callbackData.dwFlags = 0;
965 &callbackData, callbackData.dwFlags );
966 checkHR( DP_OK, hr );
967 ok( callbackData.dwCounter1 == 4 || callbackData.dwCounter1 == 3, "got=%d\n", callbackData.dwCounter1 );
968
969 callbackData.dwCounter1 = 0;
970 callbackData.dwFlags = 0;
972 &callbackData, callbackData.dwFlags );
973 checkHR( DP_OK, hr );
974 ok( callbackData.dwCounter1 == 4 || callbackData.dwCounter1 == 3, "got=%d\n", callbackData.dwCounter1 );
975
976 callbackData.dwCounter1 = 0;
977 callbackData.dwFlags = 0;
978 hr = IDirectPlayX_EnumConnections( pDP, &appGuid, NULL,
979 &callbackData, callbackData.dwFlags );
981 check( 0, callbackData.dwCounter1 );
982
983
984 /* Flag tests */
985 callbackData.dwCounter1 = 0;
986 callbackData.dwFlags = DPCONNECTION_DIRECTPLAY;
988 &callbackData, callbackData.dwFlags );
989 checkHR( DP_OK, hr );
990 ok( callbackData.dwCounter1 == 4 || callbackData.dwCounter1 == 3, "got=%d\n", callbackData.dwCounter1 );
991
992 callbackData.dwCounter1 = 0;
995 &callbackData, callbackData.dwFlags );
996 checkHR( DP_OK, hr );
997 check( 0, callbackData.dwCounter1 );
998
999 callbackData.dwCounter1 = 0;
1000 callbackData.dwFlags = ( DPCONNECTION_DIRECTPLAY |
1003 &callbackData, callbackData.dwFlags );
1004 checkHR( DP_OK, hr );
1005 ok( callbackData.dwCounter1 == 4 || callbackData.dwCounter1 == 3, "got=%d\n", callbackData.dwCounter1 );
1006
1007 callbackData.dwCounter1 = 0;
1008 callbackData.dwFlags = ~( DPCONNECTION_DIRECTPLAY |
1011 &callbackData, callbackData.dwFlags );
1013 check( 0, callbackData.dwCounter1 );
1014
1015
1016 IDirectPlayX_Release( pDP );
1017}
1018
1019/* InitializeConnection */
1020
1022 LPVOID lpConnection,
1023 DWORD dwConnectionSize,
1025 DWORD dwFlags,
1026 LPVOID lpContext )
1027{
1028 IDirectPlay4 *pDP = lpContext;
1029 HRESULT hr;
1030
1031 /* Incorrect parameters */
1034 hr = IDirectPlayX_InitializeConnection( pDP, lpConnection, 1 );
1036
1037 /* Normal operation.
1038 We're only interested in ensuring that the TCP/IP provider works */
1039
1040 if( IsEqualGUID(lpguidSP, &DPSPGUID_TCPIP) )
1041 {
1042 hr = IDirectPlayX_InitializeConnection( pDP, lpConnection, 0 );
1043 checkHR( DP_OK, hr );
1044 hr = IDirectPlayX_InitializeConnection( pDP, lpConnection, 0 );
1046 }
1047
1048 return TRUE;
1049}
1050
1052{
1053
1054 IDirectPlay4 *pDP;
1055 HRESULT hr;
1056
1057 hr = CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
1058 &IID_IDirectPlay4A, (LPVOID*) &pDP );
1059
1060 ok (SUCCEEDED(hr), "CCI of CLSID_DirectPlay / IID_IDirectPlay4A failed\n");
1061 if (FAILED(hr)) return;
1062
1063 IDirectPlayX_EnumConnections( pDP, &appGuid, EnumConnections_cb2, pDP, 0 );
1064
1065 IDirectPlayX_Release( pDP );
1066}
1067
1068/* GetCaps */
1069
1070static void test_GetCaps(void)
1071{
1072
1073 IDirectPlay4 *pDP;
1074 DPCAPS dpcaps;
1075 DWORD dwFlags;
1076 HRESULT hr;
1077
1078
1079 hr = CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
1080 &IID_IDirectPlay4A, (LPVOID*) &pDP );
1081 ok (SUCCEEDED(hr), "CCI of CLSID_DirectPlay / IID_IDirectPlay4A failed\n");
1082 if (FAILED(hr)) return;
1083
1084 ZeroMemory( &dpcaps, sizeof(DPCAPS) );
1085
1086 /* Service provider not ininitialized */
1087 hr = IDirectPlayX_GetCaps( pDP, &dpcaps, 0 );
1089
1090 init_TCPIP_provider( pDP, "127.0.0.1", 0 );
1091
1092 /* dpcaps not ininitialized */
1093 hr = IDirectPlayX_GetCaps( pDP, &dpcaps, 0 );
1095
1096 dpcaps.dwSize = sizeof(DPCAPS);
1097
1098 for (dwFlags=0;
1101 {
1102
1103 hr = IDirectPlayX_GetCaps( pDP, &dpcaps, dwFlags );
1104 checkHR( DP_OK, hr );
1105 check( sizeof(DPCAPS), dpcaps.dwSize );
1109 dpcaps.dwFlags );
1110 check( 0, dpcaps.dwMaxQueueSize );
1111 check( 0, dpcaps.dwHundredBaud );
1112 check( 500, dpcaps.dwLatency );
1113 check( 65536, dpcaps.dwMaxLocalPlayers );
1114 check( 20, dpcaps.dwHeaderLength );
1115 check( 5000, dpcaps.dwTimeout );
1116
1117 switch (dwFlags)
1118 {
1119 case 0:
1120 check( 65479, dpcaps.dwMaxBufferSize );
1121 check( 65536, dpcaps.dwMaxPlayers );
1122 break;
1124 check( 1048547, dpcaps.dwMaxBufferSize );
1125 check( 64, dpcaps.dwMaxPlayers );
1126 break;
1127 default: break;
1128 }
1129 }
1130
1131 IDirectPlayX_Release( pDP );
1132}
1133
1134static void test_EnumAddressTypes(void)
1135{
1136 IDirectPlay4 *pDP;
1137 HRESULT hr;
1138 DPCOMPOUNDADDRESSELEMENT addressElements[2];
1139 LPVOID pAddress = NULL;
1140 DWORD dwAddressSize = 0;
1141 IDirectPlayLobby3 *pDPL;
1142 WORD port = 6001;
1143
1144 hr = CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
1145 &IID_IDirectPlay4A, (LPVOID*) &pDP );
1146 ok( SUCCEEDED(hr), "CCI of CLSID_DirectPlay / IID_IDirectPlay4A failed\n" );
1147 if (FAILED(hr))
1148 return;
1149
1150 hr = CoCreateInstance( &CLSID_DirectPlayLobby, NULL, CLSCTX_ALL,
1151 &IID_IDirectPlayLobby3A, (LPVOID*) &pDPL );
1152 ok (SUCCEEDED (hr), "CCI of CLSID_DirectPlayLobby / IID_IDirectPlayLobby3A failed\n");
1153 if (FAILED (hr)) return;
1154
1155 addressElements[0].guidDataType = DPAID_ServiceProvider;
1156 addressElements[0].dwDataSize = sizeof(GUID);
1157 addressElements[0].lpData = (void*) &DPSPGUID_TCPIP;
1158
1159 addressElements[1].guidDataType = invalid_guid;
1160 addressElements[1].dwDataSize = sizeof(WORD);
1161 addressElements[1].lpData = &port;
1162
1163 hr = IDirectPlayLobby_CreateCompoundAddress( pDPL, addressElements, 2, NULL, &dwAddressSize );
1165
1166 if( hr == DPERR_BUFFERTOOSMALL )
1167 {
1168 pAddress = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwAddressSize );
1169 hr = IDirectPlayLobby_CreateCompoundAddress( pDPL, addressElements, 2,
1170 pAddress, &dwAddressSize );
1171 checkHR( DP_OK, hr );
1172 }
1173
1174 IDirectPlayX_Close(pDP);
1177
1178 HeapFree( GetProcessHeap(), 0, pAddress );
1179}
1180
1181/* Open */
1182
1184 LPDWORD lpdwTimeOut,
1185 DWORD dwFlags,
1186 LPVOID lpContext )
1187{
1188 IDirectPlay4 *pDP = lpContext;
1189 DPSESSIONDESC2 dpsd;
1190 HRESULT hr;
1191
1192 if (dwFlags & DPESC_TIMEDOUT)
1193 return FALSE;
1194
1195
1196 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
1197 dpsd.dwSize = sizeof(DPSESSIONDESC2);
1198 dpsd.guidApplication = appGuid;
1199 dpsd.guidInstance = lpThisSD->guidInstance;
1200
1201 if ( lpThisSD->dwFlags & DPSESSION_PASSWORDREQUIRED )
1202 {
1203 /* Incorrect password */
1204 U2(dpsd).lpszPasswordA = (LPSTR) "sonic boom";
1205 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_JOIN );
1207
1208 /* Correct password */
1209 U2(dpsd).lpszPasswordA = (LPSTR) "hadouken";
1210 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_JOIN );
1211 checkHR( DP_OK, hr );
1212 }
1213 else
1214 {
1215 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_JOIN );
1216 checkHR( DP_OK, hr );
1217 }
1218
1219 hr = IDirectPlayX_Close( pDP );
1220 checkHR( DP_OK, hr );
1221
1222 return TRUE;
1223}
1224
1225static void test_Open(void)
1226{
1227
1228 IDirectPlay4 *pDP, *pDP_server;
1229 DPSESSIONDESC2 dpsd, dpsd_server;
1230 HRESULT hr;
1231
1232
1233 hr = CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
1234 &IID_IDirectPlay4A, (LPVOID*) &pDP_server );
1235 ok( SUCCEEDED(hr), "CCI of CLSID_DirectPlay / IID_IDirectPlay4A failed\n" );
1236 if (FAILED(hr)) return;
1237
1238 hr = CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
1239 &IID_IDirectPlay4A, (LPVOID*) &pDP );
1240 ok( SUCCEEDED(hr), "CCI of CLSID_DirectPlay / IID_IDirectPlay4A failed\n" );
1241 if (FAILED(hr)) return;
1242
1243 ZeroMemory( &dpsd_server, sizeof(DPSESSIONDESC2) );
1244 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
1245
1246 /* Service provider not initialized */
1247 hr = IDirectPlayX_Open( pDP_server, &dpsd_server, DPOPEN_CREATE );
1249
1250 init_TCPIP_provider( pDP_server, "127.0.0.1", 0 );
1251 init_TCPIP_provider( pDP, "127.0.0.1", 0 );
1252
1253 /* Uninitialized dpsd */
1254 hr = IDirectPlayX_Open( pDP_server, &dpsd_server, DPOPEN_CREATE );
1256
1257
1258 dpsd_server.dwSize = sizeof(DPSESSIONDESC2);
1259 dpsd_server.guidApplication = appGuid;
1260 dpsd_server.dwMaxPlayers = 10;
1261
1262
1263 /* Regular operation */
1264 hr = IDirectPlayX_Open( pDP_server, &dpsd_server, DPOPEN_CREATE );
1266
1267 /* Opening twice */
1268 hr = IDirectPlayX_Open( pDP_server, &dpsd_server, DPOPEN_CREATE );
1270
1271 /* Session flags */
1272 IDirectPlayX_Close( pDP_server );
1273
1275 hr = IDirectPlayX_Open( pDP_server, &dpsd_server, DPOPEN_CREATE );
1277
1279 hr = IDirectPlayX_Open( pDP_server, &dpsd_server, DPOPEN_CREATE );
1281
1283 hr = IDirectPlayX_Open( pDP_server, &dpsd_server, DPOPEN_CREATE );
1285
1286
1287 /* Joining sessions */
1288 /* - Checking how strict dplay is with sizes */
1289 dpsd.dwSize = 0;
1290 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_JOIN );
1292
1293 dpsd.dwSize = sizeof(DPSESSIONDESC2)-1;
1294 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_JOIN );
1296
1297 dpsd.dwSize = sizeof(DPSESSIONDESC2)+1;
1298 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_JOIN );
1300
1301 dpsd.dwSize = sizeof(DPSESSIONDESC2);
1302 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_JOIN );
1303 todo_wine checkHR( DPERR_NOSESSIONS, hr ); /* Only checks for size, not guids */
1304
1305
1306 dpsd.guidApplication = appGuid;
1307 dpsd.guidInstance = appGuid;
1308
1309
1310 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_JOIN );
1312 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_JOIN | DPOPEN_CREATE );
1313 todo_wine checkHR( DPERR_NOSESSIONS, hr ); /* Second flag is ignored */
1314
1315 dpsd_server.dwFlags = 0;
1316
1317
1318 /* Join to normal session */
1319 hr = IDirectPlayX_Open( pDP_server, &dpsd_server, DPOPEN_CREATE );
1321
1322 IDirectPlayX_EnumSessions( pDP, &dpsd, 0, EnumSessions_cb2, pDP, 0 );
1323
1324
1325 /* Already initialized session */
1326 hr = IDirectPlayX_Open( pDP_server, &dpsd_server, DPOPEN_CREATE );
1328
1329
1330 /* Checking which is the error checking order */
1331 dpsd_server.dwSize = 0;
1332
1333 hr = IDirectPlayX_Open( pDP_server, &dpsd_server, DPOPEN_CREATE );
1335
1336 dpsd_server.dwSize = sizeof(DPSESSIONDESC2);
1337
1338
1339 /* Join to protected session */
1340 IDirectPlayX_Close( pDP_server );
1341 U2(dpsd_server).lpszPasswordA = (LPSTR) "hadouken";
1342 hr = IDirectPlayX_Open( pDP_server, &dpsd_server, DPOPEN_CREATE );
1344
1347
1348
1349 IDirectPlayX_Release( pDP );
1350 IDirectPlayX_Release( pDP_server );
1351
1352}
1353
1354/* EnumSessions */
1355
1357 LPDWORD lpdwTimeOut,
1358 DWORD dwFlags,
1359 LPVOID lpContext )
1360{
1361 lpCallbackData callbackData = lpContext;
1362 callbackData->dwCounter1++;
1363
1364 if ( dwFlags & DPESC_TIMEDOUT )
1365 {
1366 check( TRUE, lpThisSD == NULL );
1367 return FALSE;
1368 }
1369 check( FALSE, lpThisSD == NULL );
1370
1371
1372 if ( U2(*lpThisSD).lpszPasswordA != NULL )
1373 {
1374 check( TRUE, (lpThisSD->dwFlags & DPSESSION_PASSWORDREQUIRED) != 0 );
1375 }
1376
1377 if ( lpThisSD->dwFlags & DPSESSION_NEWPLAYERSDISABLED )
1378 {
1379 check( 0, lpThisSD->dwCurrentPlayers );
1380 }
1381
1382 check( sizeof(*lpThisSD), lpThisSD->dwSize );
1383 checkLP( NULL, U2(*lpThisSD).lpszPasswordA );
1384
1385 return TRUE;
1386}
1387
1388static IDirectPlay4 *create_session(DPSESSIONDESC2 *lpdpsd)
1389{
1390
1391 IDirectPlay4 *pDP;
1392 DPNAME name;
1393 DPID dpid;
1394 HRESULT hr;
1395
1396 hr = CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
1397 &IID_IDirectPlay4A, (LPVOID*) &pDP );
1398 ok( SUCCEEDED(hr), "CCI of CLSID_DirectPlay / IID_IDirectPlay4A failed\n" );
1399 if (FAILED(hr)) return NULL;
1400
1401 init_TCPIP_provider( pDP, "127.0.0.1", 0 );
1402
1403 hr = IDirectPlayX_Open( pDP, lpdpsd, DPOPEN_CREATE );
1405
1406 if ( ! (lpdpsd->dwFlags & DPSESSION_NEWPLAYERSDISABLED) )
1407 {
1408 ZeroMemory( &name, sizeof(DPNAME) );
1409 name.dwSize = sizeof(DPNAME);
1410 U1(name).lpszShortNameA = (LPSTR) "bofh";
1411
1412 hr = IDirectPlayX_CreatePlayer( pDP, &dpid, &name, NULL, NULL,
1415 }
1416
1417 return pDP;
1418
1419}
1420
1421static void test_EnumSessions(void)
1422{
1423
1424#define N_SESSIONS 6
1425
1426 IDirectPlay4 *pDP, *pDPserver[N_SESSIONS];
1427 DPSESSIONDESC2 dpsd, dpsd_server[N_SESSIONS];
1428 CallbackData callbackData;
1429 HRESULT hr;
1430 UINT i;
1431
1432
1433 hr = CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
1434 &IID_IDirectPlay4A, (LPVOID*) &pDP );
1435 ok( SUCCEEDED(hr), "CCI of CLSID_DirectPlay / IID_IDirectPlay4A failed\n" );
1436 if (FAILED(hr)) return;
1437
1438 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
1439 callbackData.dwCounter1 = -1; /* So that after a call to EnumSessions
1440 we get the exact number of sessions */
1441 callbackData.dwFlags = 0;
1442
1443
1444 /* Service provider not initialized */
1446 &callbackData, 0 );
1448
1449
1450 init_TCPIP_provider( pDP, "127.0.0.1", 0 );
1451
1452
1453 /* Session with no size */
1455 &callbackData, 0 );
1457
1458 if ( hr == DPERR_UNINITIALIZED )
1459 {
1460 todo_wine win_skip( "EnumSessions not implemented\n" );
1461 return;
1462 }
1463
1464 dpsd.dwSize = sizeof(DPSESSIONDESC2);
1465
1466
1467 /* No sessions */
1468 callbackData.dwCounter1 = -1;
1470 &callbackData, 0 );
1471 checkHR( DP_OK, hr );
1472 check( 0, callbackData.dwCounter1 );
1473
1474
1475 dpsd.guidApplication = appGuid;
1476
1477 /* Set up sessions */
1478 for (i=0; i<N_SESSIONS; i++)
1479 {
1480 memcpy( &dpsd_server[i], &dpsd, sizeof(DPSESSIONDESC2) );
1481 }
1482
1483 U1(dpsd_server[0]).lpszSessionNameA = (LPSTR) "normal";
1484 dpsd_server[0].dwFlags = ( DPSESSION_CLIENTSERVER |
1486 dpsd_server[0].dwMaxPlayers = 10;
1487
1488 U1(dpsd_server[1]).lpszSessionNameA = (LPSTR) "full";
1489 dpsd_server[1].dwFlags = ( DPSESSION_CLIENTSERVER |
1491 dpsd_server[1].dwMaxPlayers = 1;
1492
1493 U1(dpsd_server[2]).lpszSessionNameA = (LPSTR) "no new";
1494 dpsd_server[2].dwFlags = ( DPSESSION_CLIENTSERVER |
1497 dpsd_server[2].dwMaxPlayers = 10;
1498
1499 U1(dpsd_server[3]).lpszSessionNameA = (LPSTR) "no join";
1500 dpsd_server[3].dwFlags = ( DPSESSION_CLIENTSERVER |
1503 dpsd_server[3].dwMaxPlayers = 10;
1504
1505 U1(dpsd_server[4]).lpszSessionNameA = (LPSTR) "private";
1506 dpsd_server[4].dwFlags = ( DPSESSION_CLIENTSERVER |
1509 dpsd_server[4].dwMaxPlayers = 10;
1510 U2(dpsd_server[4]).lpszPasswordA = (LPSTR) "password";
1511
1512 U1(dpsd_server[5]).lpszSessionNameA = (LPSTR) "protected";
1513 dpsd_server[5].dwFlags = ( DPSESSION_CLIENTSERVER |
1516 dpsd_server[5].dwMaxPlayers = 10;
1517 U2(dpsd_server[5]).lpszPasswordA = (LPSTR) "password";
1518
1519
1520 for (i=0; i<N_SESSIONS; i++)
1521 {
1522 pDPserver[i] = create_session( &dpsd_server[i] );
1523 if (!pDPserver[i]) return;
1524 }
1525
1526
1527 /* Invalid params */
1528 callbackData.dwCounter1 = -1;
1530 &callbackData, -1 );
1532
1534 &callbackData, 0 );
1536
1537 check( -1, callbackData.dwCounter1 );
1538
1539
1540 /* Flag tests */
1541 callbackData.dwFlags = DPENUMSESSIONS_ALL; /* Doesn't list private,
1542 protected */
1543 callbackData.dwCounter1 = -1;
1545 &callbackData, callbackData.dwFlags );
1546 checkHR( DP_OK, hr );
1547 check( N_SESSIONS-2, callbackData.dwCounter1 );
1548
1549 /* Doesn't list private */
1550 callbackData.dwFlags = ( DPENUMSESSIONS_ALL |
1552 callbackData.dwCounter1 = -1;
1554 &callbackData, callbackData.dwFlags );
1555 checkHR( DP_OK, hr );
1556 check( N_SESSIONS-1, callbackData.dwCounter1 );
1557
1558 /* Doesn't list full, no new, no join, private, protected */
1559 callbackData.dwFlags = DPENUMSESSIONS_AVAILABLE;
1560 callbackData.dwCounter1 = -1;
1562 &callbackData, callbackData.dwFlags );
1563 checkHR( DP_OK, hr );
1564 check( N_SESSIONS-5, callbackData.dwCounter1 );
1565
1566 /* Like with DPENUMSESSIONS_AVAILABLE */
1567 callbackData.dwFlags = 0;
1568 callbackData.dwCounter1 = -1;
1570 &callbackData, callbackData.dwFlags );
1571 checkHR( DP_OK, hr );
1572 check( N_SESSIONS-5, callbackData.dwCounter1 );
1573
1574 /* Doesn't list full, no new, no join, private */
1576 callbackData.dwCounter1 = -1;
1578 &callbackData, callbackData.dwFlags );
1579 checkHR( DP_OK, hr );
1580 check( N_SESSIONS-4, callbackData.dwCounter1 );
1581
1582
1583 /* Async enumeration */
1584 callbackData.dwFlags = DPENUMSESSIONS_ASYNC;
1585 callbackData.dwCounter1 = -1;
1587 &callbackData, callbackData.dwFlags );
1588 checkHR( DP_OK, hr );
1589 check( N_SESSIONS-4, callbackData.dwCounter1 ); /* Read cache of last
1590 sync enumeration */
1591
1592 callbackData.dwFlags = DPENUMSESSIONS_STOPASYNC;
1593 callbackData.dwCounter1 = -1;
1595 &callbackData, callbackData.dwFlags );
1596 checkHR( DP_OK, hr );
1597 check( 0, callbackData.dwCounter1 ); /* Stop enumeration */
1598
1599 callbackData.dwFlags = DPENUMSESSIONS_ASYNC;
1600 callbackData.dwCounter1 = -1;
1602 &callbackData, callbackData.dwFlags );
1603 checkHR( DP_OK, hr );
1604 check( 0, callbackData.dwCounter1 ); /* Start enumeration */
1605
1606 Sleep(500); /* Give time to fill the cache */
1607
1608 callbackData.dwFlags = DPENUMSESSIONS_ASYNC;
1609 callbackData.dwCounter1 = -1;
1611 &callbackData, callbackData.dwFlags );
1612 checkHR( DP_OK, hr );
1613 check( N_SESSIONS-5, callbackData.dwCounter1 ); /* Retrieve results */
1614
1615 callbackData.dwFlags = DPENUMSESSIONS_STOPASYNC;
1616 callbackData.dwCounter1 = -1;
1618 &callbackData, callbackData.dwFlags );
1619 checkHR( DP_OK, hr );
1620 check( 0, callbackData.dwCounter1 ); /* Stop enumeration */
1621
1622
1623 /* Specific tests for passworded sessions */
1624
1625 for (i=0; i<N_SESSIONS; i++)
1626 {
1627 IDirectPlayX_Release( pDPserver[i] );
1628 }
1629
1630 /* - Only session password set */
1631 for (i=4;i<=5;i++)
1632 {
1633 U2(dpsd_server[i]).lpszPasswordA = (LPSTR) "password";
1634 dpsd_server[i].dwFlags = 0;
1635 pDPserver[i] = create_session( &dpsd_server[i] );
1636 }
1637
1638 callbackData.dwFlags = 0;
1639 callbackData.dwCounter1 = -1;
1641 &callbackData, callbackData.dwFlags );
1642 checkHR( DP_OK, hr );
1643 check( 0, callbackData.dwCounter1 );
1644
1646 callbackData.dwCounter1 = -1;
1648 &callbackData, callbackData.dwFlags );
1649 checkHR( DP_OK, hr );
1650 check( 2, callbackData.dwCounter1 ); /* Both sessions automatically
1651 set DPSESSION_PASSWORDREQUIRED */
1652
1653 /* - Only session flag set */
1654 for (i=4; i<=5; i++)
1655 {
1656 IDirectPlayX_Release( pDPserver[i] );
1657 U2(dpsd_server[i]).lpszPasswordA = NULL;
1658 }
1659 dpsd_server[4].dwFlags = DPSESSION_PRIVATE;
1660 dpsd_server[5].dwFlags = DPSESSION_PASSWORDREQUIRED;
1661 for (i=4; i<=5; i++)
1662 {
1663 pDPserver[i] = create_session( &dpsd_server[i] );
1664 }
1665
1666 callbackData.dwFlags = 0;
1667 callbackData.dwCounter1 = -1;
1669 &callbackData, callbackData.dwFlags );
1670 checkHR( DP_OK, hr );
1671 check( 2, callbackData.dwCounter1 ); /* Without password,
1672 the flag is ignored */
1673
1674 /* - Both session flag and password set */
1675 for (i=4; i<=5; i++)
1676 {
1677 IDirectPlayX_Release( pDPserver[i] );
1678 U2(dpsd_server[i]).lpszPasswordA = (LPSTR) "password";
1679 }
1680 dpsd_server[4].dwFlags = DPSESSION_PRIVATE;
1681 dpsd_server[5].dwFlags = DPSESSION_PASSWORDREQUIRED;
1682 for (i=4; i<=5; i++)
1683 {
1684 pDPserver[i] = create_session( &dpsd_server[i] );
1685 }
1686
1687 /* - Listing without password */
1688 callbackData.dwCounter1 = -1;
1690 &callbackData, callbackData.dwFlags );
1691 checkHR( DP_OK, hr );
1692 check( 0, callbackData.dwCounter1 );
1693
1695 callbackData.dwCounter1 = -1;
1697 &callbackData, callbackData.dwFlags );
1698 checkHR( DP_OK, hr );
1699 check( 1, callbackData.dwCounter1 );
1700
1701 /* - Listing with incorrect password */
1702 U2(dpsd).lpszPasswordA = (LPSTR) "bad_password";
1703 callbackData.dwFlags = 0;
1704 callbackData.dwCounter1 = -1;
1706 &callbackData, callbackData.dwFlags );
1707 checkHR( DP_OK, hr );
1708 check( 0, callbackData.dwCounter1 );
1709
1711 callbackData.dwCounter1 = -1;
1713 &callbackData, callbackData.dwFlags );
1714 checkHR( DP_OK, hr );
1715 check( 1, callbackData.dwCounter1 );
1716
1717 /* - Listing with correct password */
1718 U2(dpsd).lpszPasswordA = (LPSTR) "password";
1719 callbackData.dwCounter1 = -1;
1721 &callbackData, callbackData.dwFlags );
1722 checkHR( DP_OK, hr );
1723 check( 2, callbackData.dwCounter1 );
1724
1725
1726 U2(dpsd).lpszPasswordA = NULL;
1727 callbackData.dwFlags = DPENUMSESSIONS_ASYNC;
1728 callbackData.dwCounter1 = -1;
1730 &callbackData, callbackData.dwFlags );
1731 checkHR( DP_OK, hr );
1732 check( 2, callbackData.dwCounter1 ); /* Read cache of last sync enumeration,
1733 even private sessions */
1734
1735
1736 /* GUID tests */
1737
1738 /* - Creating two servers with different application GUIDs */
1739 for (i=4; i<=5; i++)
1740 {
1741 IDirectPlayX_Release( pDPserver[i] );
1742 dpsd_server[i].dwFlags = ( DPSESSION_CLIENTSERVER |
1744 U2(dpsd_server[i]).lpszPasswordA = NULL;
1745 dpsd_server[i].dwMaxPlayers = 10;
1746 }
1747 U1(dpsd_server[4]).lpszSessionNameA = (LPSTR) "normal1";
1748 dpsd_server[4].guidApplication = appGuid;
1749 U1(dpsd_server[5]).lpszSessionNameA = (LPSTR) "normal2";
1750 dpsd_server[5].guidApplication = appGuid2;
1751 for (i=4; i<=5; i++)
1752 {
1753 pDPserver[i] = create_session( &dpsd_server[i] );
1754 }
1755
1756 callbackData.dwFlags = 0;
1757
1758 dpsd.guidApplication = appGuid2;
1759 callbackData.dwCounter1 = -1;
1761 &callbackData, callbackData.dwFlags );
1762 checkHR( DP_OK, hr );
1763 check( 1, callbackData.dwCounter1 ); /* Only one of the sessions */
1764
1765 dpsd.guidApplication = appGuid;
1766 callbackData.dwCounter1 = -1;
1768 &callbackData, callbackData.dwFlags );
1769 checkHR( DP_OK, hr );
1770 check( 1, callbackData.dwCounter1 ); /* The other session */
1771 /* FIXME:
1772 For some reason, if we enum 1st with appGuid and 2nd with appGuid2,
1773 in the second enum we get the 2 sessions. Dplay fault? Elves? */
1774
1776 callbackData.dwCounter1 = -1;
1778 &callbackData, callbackData.dwFlags );
1779 checkHR( DP_OK, hr );
1780 check( 2, callbackData.dwCounter1 ); /* Both sessions */
1781
1782 for (i=4; i<=5; i++)
1783 {
1784 IDirectPlayX_Release( pDPserver[i] );
1785 }
1786 IDirectPlayX_Release( pDP );
1787
1788}
1789
1790/* SetSessionDesc
1791 GetSessionDesc */
1792
1793static void test_SessionDesc(void)
1794{
1795
1796 IDirectPlay4 *pDP[2];
1797 DPSESSIONDESC2 dpsd;
1798 LPDPSESSIONDESC2 lpData[2];
1799 LPVOID lpDataMsg;
1800 DPID dpid[2];
1801 DWORD dwDataSize;
1802 HRESULT hr;
1803 UINT i;
1804 CallbackData callbackData;
1805
1806
1807 for (i=0; i<2; i++)
1808 {
1809 hr = CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
1810 &IID_IDirectPlay4A, (LPVOID*) &pDP[i] );
1811 ok( SUCCEEDED(hr), "CCI of CLSID_DirectPlay / IID_IDirectPlay4A failed\n" );
1812 if (FAILED(hr)) return;
1813 }
1814 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
1815
1816 /* Service provider not initialized */
1817 hr = IDirectPlayX_SetSessionDesc( pDP[0], NULL, 0 );
1819
1822
1823
1824 init_TCPIP_provider( pDP[0], "127.0.0.1", 0 );
1825 init_TCPIP_provider( pDP[1], "127.0.0.1", 0 );
1826
1827
1828 /* No sessions open */
1829 hr = IDirectPlayX_SetSessionDesc( pDP[0], NULL, 0 );
1831
1832 if ( hr == DPERR_UNINITIALIZED )
1833 {
1834 todo_wine win_skip("Get/SetSessionDesc not implemented\n");
1835 return;
1836 }
1837
1840
1841
1842 dpsd.dwSize = sizeof(DPSESSIONDESC2);
1843 dpsd.guidApplication = appGuid;
1844 dpsd.dwMaxPlayers = 10;
1845
1846
1847 /* Host */
1848 IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE );
1849 /* Peer */
1851 pDP[1], 0 );
1852
1853 for (i=0; i<2; i++)
1854 {
1855 /* Players, only to receive messages */
1856 IDirectPlayX_CreatePlayer( pDP[i], &dpid[i], NULL, NULL, NULL, 0, 0 );
1857
1858 lpData[i] = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 1024 );
1859 }
1860 lpDataMsg = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 1024 );
1861
1862
1863 /* Incorrect parameters */
1864 hr = IDirectPlayX_SetSessionDesc( pDP[0], NULL, 0 );
1868if(0)
1869{
1870 /* Crashes under Win7 */
1871 hr = IDirectPlayX_GetSessionDesc( pDP[0], lpData[0], NULL );
1873 dwDataSize=-1;
1874 hr = IDirectPlayX_GetSessionDesc( pDP[0], lpData[0], &dwDataSize );
1876 check( -1, dwDataSize );
1877}
1878
1879 /* Get: Insufficient buffer size */
1880 dwDataSize=0;
1881 hr = IDirectPlayX_GetSessionDesc( pDP[0], lpData[0], &dwDataSize );
1883 check( dpsd.dwSize, dwDataSize );
1884 dwDataSize=4;
1885 hr = IDirectPlayX_GetSessionDesc( pDP[0], lpData[0], &dwDataSize );
1887 check( dpsd.dwSize, dwDataSize );
1888 dwDataSize=1024;
1889 hr = IDirectPlayX_GetSessionDesc( pDP[0], NULL, &dwDataSize );
1891 check( dpsd.dwSize, dwDataSize );
1892
1893 /* Get: Regular operation
1894 * i=0: Local session
1895 * i=1: Remote session */
1896 for (i=0; i<2; i++)
1897 {
1898 hr = IDirectPlayX_GetSessionDesc( pDP[i], lpData[i], &dwDataSize );
1899 checkHR( DP_OK, hr );
1900 check( sizeof(DPSESSIONDESC2), dwDataSize );
1901 check( sizeof(DPSESSIONDESC2), lpData[i]->dwSize );
1902 checkGuid( &appGuid, &lpData[i]->guidApplication );
1903 check( dpsd.dwMaxPlayers, lpData[i]->dwMaxPlayers );
1904 }
1905
1906 checkGuid( &lpData[0]->guidInstance, &lpData[1]->guidInstance );
1907
1908 /* Set: Regular operation */
1909 U1(dpsd).lpszSessionNameA = (LPSTR) "Wahaa";
1910 hr = IDirectPlayX_SetSessionDesc( pDP[0], &dpsd, 0 );
1911 checkHR( DP_OK, hr );
1912
1913 dwDataSize = 1024;
1914 hr = IDirectPlayX_GetSessionDesc( pDP[1], lpData[1], &dwDataSize );
1915 checkHR( DP_OK, hr );
1916 checkStr( U1(dpsd).lpszSessionNameA, U1(*lpData[1]).lpszSessionNameA );
1917
1918
1919 /* Set: Failing to modify a remote session */
1920 hr = IDirectPlayX_SetSessionDesc( pDP[1], &dpsd, 0 );
1922
1923 /* Trying to change immutable properties */
1924 /* Flags */
1925 hr = IDirectPlayX_SetSessionDesc( pDP[0], &dpsd, 0 );
1926 checkHR( DP_OK, hr );
1928 hr = IDirectPlayX_SetSessionDesc( pDP[0], &dpsd, 0 );
1930 dpsd.dwFlags = 0;
1931 hr = IDirectPlayX_SetSessionDesc( pDP[0], &dpsd, 0 );
1932 checkHR( DP_OK, hr );
1933 /* Size */
1934 dpsd.dwSize = 2048;
1935 hr = IDirectPlayX_SetSessionDesc( pDP[0], &dpsd, 0 );
1937 dpsd.dwSize = sizeof(DPSESSIONDESC2);
1938 hr = IDirectPlayX_SetSessionDesc( pDP[0], &dpsd, 0 );
1939 checkHR( DP_OK, hr );
1940
1941 /* Changing the GUIDs and size is ignored */
1942 dpsd.guidApplication = appGuid2;
1943 hr = IDirectPlayX_SetSessionDesc( pDP[0], &dpsd, 0 );
1944 checkHR( DP_OK, hr );
1945 dpsd.guidInstance = appGuid2;
1946 hr = IDirectPlayX_SetSessionDesc( pDP[0], &dpsd, 0 );
1947 checkHR( DP_OK, hr );
1948
1949 hr = IDirectPlayX_GetSessionDesc( pDP[0], lpData[0], &dwDataSize );
1950 checkHR( DP_OK, hr );
1951 checkGuid( &appGuid, &lpData[0]->guidApplication );
1952 checkGuid( &lpData[1]->guidInstance, &lpData[0]->guidInstance );
1953 check( sizeof(DPSESSIONDESC2), lpData[0]->dwSize );
1954
1955
1956 /* Checking system messages */
1957 check_messages( pDP[0], dpid, 2, &callbackData );
1958 checkStr( "S0,S0,S0,S0,S0,S0,S0,", callbackData.szTrace1 );
1959 checkStr( "48,90,90,90,90,90,90,", callbackData.szTrace2 );
1960 check_messages( pDP[1], dpid, 2, &callbackData );
1961 checkStr( "S1,S1,S1,S1,S1,S1,", callbackData.szTrace1 );
1962 checkStr( "90,90,90,90,90,90,", callbackData.szTrace2 );
1963
1964 HeapFree( GetProcessHeap(), 0, lpDataMsg );
1965 for (i=0; i<2; i++)
1966 {
1967 HeapFree( GetProcessHeap(), 0, lpData[i] );
1968 IDirectPlayX_Release( pDP[i] );
1969 }
1970
1971}
1972
1973/* CreatePlayer */
1974
1975static void test_CreatePlayer(void)
1976{
1977
1978 IDirectPlay4 *pDP[2];
1979 DPSESSIONDESC2 dpsd;
1980 DPNAME name;
1981 DPID dpid;
1982 HRESULT hr;
1983
1984
1985 hr = CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
1986 &IID_IDirectPlay4A, (LPVOID*) &pDP[0] );
1987 ok( SUCCEEDED(hr), "CCI of CLSID_DirectPlay / IID_IDirectPlay4A failed\n" );
1988 if (FAILED(hr)) return;
1989
1990 hr = CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
1991 &IID_IDirectPlay4A, (LPVOID*) &pDP[1] );
1992 ok( SUCCEEDED(hr), "CCI of CLSID_DirectPlay / IID_IDirectPlay4A failed\n" );
1993 if (FAILED(hr)) return;
1994
1995 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
1996 ZeroMemory( &name, sizeof(DPNAME) );
1997
1998
1999 /* Connection not initialized */
2000 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL, 0, 0 );
2002
2003
2004 init_TCPIP_provider( pDP[0], "127.0.0.1", 0 );
2005 init_TCPIP_provider( pDP[1], "127.0.0.1", 0 );
2006
2007
2008 /* Session not open */
2009 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL, 0, 0 );
2011
2012 if ( hr == DPERR_UNINITIALIZED )
2013 {
2014 todo_wine win_skip( "CreatePlayer not implemented\n" );
2015 return;
2016 }
2017
2018 dpsd.dwSize = sizeof(DPSESSIONDESC2);
2019 dpsd.guidApplication = appGuid;
2020 IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE );
2021
2022
2023 /* Player name */
2024 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL, 0, 0 );
2025 checkHR( DP_OK, hr );
2026
2027
2028 name.dwSize = -1;
2029
2030
2031 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, &name, NULL, NULL, 0, 0 );
2032 checkHR( DP_OK, hr );
2033
2034
2035 name.dwSize = sizeof(DPNAME);
2036 U1(name).lpszShortNameA = (LPSTR) "test";
2037 U2(name).lpszLongNameA = NULL;
2038
2039
2040 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, &name, NULL, NULL,
2041 0, 0 );
2042 checkHR( DP_OK, hr );
2043
2044
2045 /* Null dpid */
2047 0, 0 );
2049
2050
2051 /* There can only be one server player */
2052 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
2054 checkHR( DP_OK, hr );
2055 check( DPID_SERVERPLAYER, dpid );
2056
2057 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
2060
2061 IDirectPlayX_DestroyPlayer( pDP[0], dpid );
2062
2063 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
2065 checkHR( DP_OK, hr );
2066 check( DPID_SERVERPLAYER, dpid );
2067 IDirectPlayX_DestroyPlayer( pDP[0], dpid );
2068
2069
2070 /* Flags */
2071 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
2072 0, 0 );
2073 checkHR( DP_OK, hr );
2074
2075 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
2077 checkHR( DP_OK, hr );
2078 check( DPID_SERVERPLAYER, dpid );
2079 IDirectPlayX_DestroyPlayer( pDP[0], dpid );
2080
2081 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
2082 0, DPPLAYER_SPECTATOR );
2083 checkHR( DP_OK, hr );
2084
2085 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
2088 checkHR( DP_OK, hr );
2089 check( DPID_SERVERPLAYER, dpid );
2090 IDirectPlayX_DestroyPlayer( pDP[0], dpid );
2091
2092
2093 /* Session with DPSESSION_NEWPLAYERSDISABLED */
2094 IDirectPlayX_Close( pDP[0] );
2096 hr = IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE );
2097 checkHR( DP_OK, hr );
2098
2099
2100 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
2101 0, 0 );
2103
2104 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
2107
2108 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
2109 0, DPPLAYER_SPECTATOR );
2111
2112
2113 /* Creating players in a Client/Server session */
2114 IDirectPlayX_Close( pDP[0] );
2116 hr = IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE );
2117 checkHR( DP_OK, hr );
2119 pDP[1], 0 );
2120 checkHR( DP_OK, hr );
2121
2122
2123 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
2124 0, 0 );
2126
2127 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid, NULL, NULL, NULL,
2129 checkHR( DP_OK, hr );
2130 check( DPID_SERVERPLAYER, dpid );
2131
2132 hr = IDirectPlayX_CreatePlayer( pDP[1], &dpid, NULL, NULL, NULL,
2135
2136 hr = IDirectPlayX_CreatePlayer( pDP[1], &dpid, NULL, NULL, NULL,
2137 0, 0 );
2138 checkHR( DP_OK, hr );
2139
2140
2141 IDirectPlayX_Release( pDP[0] );
2142 IDirectPlayX_Release( pDP[1] );
2143
2144}
2145
2146/* GetPlayerCaps */
2147
2148static void test_GetPlayerCaps(void)
2149{
2150
2151 IDirectPlay4 *pDP[2];
2152 DPSESSIONDESC2 dpsd;
2153 DPID dpid[2];
2154 HRESULT hr;
2155 UINT i;
2156
2157 DPCAPS playerCaps;
2158 DWORD dwFlags;
2159
2160
2161 for (i=0; i<2; i++)
2162 {
2163 hr= CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
2164 &IID_IDirectPlay4A, (LPVOID*) &pDP[i] );
2165 ok( SUCCEEDED(hr), "CCI of CLSID_DirectPlay / IID_IDirectPlay4A failed\n" );
2166 if (FAILED(hr)) return;
2167 }
2168 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
2169 dpsd.dwSize = sizeof(DPSESSIONDESC2);
2170 dpsd.guidApplication = appGuid;
2171 dpsd.dwMaxPlayers = 10;
2172
2173 ZeroMemory( &playerCaps, sizeof(DPCAPS) );
2174
2175
2176 /* Uninitialized service provider */
2177 playerCaps.dwSize = 0;
2178 hr = IDirectPlayX_GetPlayerCaps( pDP[0], 0, &playerCaps, 0 );
2180
2181 playerCaps.dwSize = sizeof(DPCAPS);
2182 hr = IDirectPlayX_GetPlayerCaps( pDP[0], 0, &playerCaps, 0 );
2184
2185
2186 init_TCPIP_provider( pDP[0], "127.0.0.1", 0 );
2187 init_TCPIP_provider( pDP[1], "127.0.0.1", 0 );
2188
2189
2190 /* No session */
2191 playerCaps.dwSize = 0;
2192
2193 hr = IDirectPlayX_GetPlayerCaps( pDP[0], 0, &playerCaps, 0 );
2195
2196 if ( hr == DPERR_UNINITIALIZED )
2197 {
2198 todo_wine win_skip( "GetPlayerCaps not implemented\n" );
2199 return;
2200 }
2201
2202 playerCaps.dwSize = sizeof(DPCAPS);
2203
2204 hr = IDirectPlayX_GetPlayerCaps( pDP[0], 0, &playerCaps, 0 );
2206
2207 hr = IDirectPlayX_GetPlayerCaps( pDP[0], 2, &playerCaps, 0 );
2209
2210
2211 hr = IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE );
2212 checkHR( DP_OK, hr );
2214 pDP[1], 0 );
2215 checkHR( DP_OK, hr );
2216
2217 for (i=0; i<2; i++)
2218 {
2219 hr = IDirectPlayX_CreatePlayer( pDP[i], &dpid[i],
2220 NULL, NULL, NULL, 0, 0 );
2221 checkHR( DP_OK, hr );
2222 }
2223
2224
2225 /* Uninitialized playerCaps */
2226 playerCaps.dwSize = 0;
2227
2228 hr = IDirectPlayX_GetPlayerCaps( pDP[0], 0, &playerCaps, 0 );
2230
2231 hr = IDirectPlayX_GetPlayerCaps( pDP[0], 2, &playerCaps, 0 );
2233
2234 hr = IDirectPlayX_GetPlayerCaps( pDP[0], dpid[0], &playerCaps, 0 );
2236
2237 /* Invalid player */
2238 playerCaps.dwSize = sizeof(DPCAPS);
2239
2240 hr = IDirectPlayX_GetPlayerCaps( pDP[0], 0, &playerCaps, 0 );
2242
2243 hr = IDirectPlayX_GetPlayerCaps( pDP[0], 2, &playerCaps, 0 );
2245
2246 hr = IDirectPlayX_GetPlayerCaps( pDP[0], dpid[0], &playerCaps, 0 );
2247 checkHR( DP_OK, hr );
2248
2249 hr = IDirectPlayX_GetPlayerCaps( pDP[0], dpid[0], NULL, 0 );
2251
2252 /* Regular parameters */
2253 for (i=0; i<2; i++)
2254 {
2255 for (dwFlags=0;
2258 {
2259
2260 hr = IDirectPlayX_GetPlayerCaps( pDP[0], dpid[i],
2261 &playerCaps, dwFlags );
2262 checkHR( DP_OK, hr );
2263
2264
2265 check( sizeof(DPCAPS), playerCaps.dwSize );
2266 check( 40, playerCaps.dwSize );
2267 check( 0, playerCaps.dwMaxQueueSize );
2268 check( 0, playerCaps.dwHundredBaud );
2269 check( 0, playerCaps.dwLatency );
2270 check( 65536, playerCaps.dwMaxLocalPlayers );
2271 check( 20, playerCaps.dwHeaderLength );
2272
2273 if ( i == 0 )
2274 {
2280 playerCaps.dwFlags, FLAGS_DPCAPS );
2281 }
2282 else
2287 playerCaps.dwFlags, FLAGS_DPCAPS );
2288
2290 {
2291 check( 1048547, playerCaps.dwMaxBufferSize );
2292 check( 64, playerCaps.dwMaxPlayers );
2293 }
2294 else
2295 {
2296 check( 65479, playerCaps.dwMaxBufferSize );
2297 check( 65536, playerCaps.dwMaxPlayers );
2298 }
2299
2300 }
2301 }
2302
2303
2304 IDirectPlayX_Release( pDP[0] );
2305 IDirectPlayX_Release( pDP[1] );
2306
2307}
2308
2309/* SetPlayerData
2310 GetPlayerData */
2311
2312static void test_PlayerData(void)
2313{
2314 IDirectPlay4 *pDP;
2315 DPSESSIONDESC2 dpsd;
2316 DPID dpid;
2317 HRESULT hr;
2318
2319 /* lpDataFake has to be bigger than the rest, limits lpDataGet size */
2320 LPCSTR lpDataFake = "big_fake_data_chunk";
2321 DWORD dwDataSizeFake = strlen(lpDataFake)+1;
2322
2323 LPCSTR lpData = "remote_data";
2324 DWORD dwDataSize = strlen(lpData)+1;
2325
2326 LPCSTR lpDataLocal = "local_data";
2327 DWORD dwDataSizeLocal = strlen(lpDataLocal)+1;
2328
2330 dwDataSizeFake );
2331 DWORD dwDataSizeGet = dwDataSizeFake;
2332
2333
2334 hr = CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
2335 &IID_IDirectPlay4A, (LPVOID*) &pDP );
2336 ok( SUCCEEDED(hr), "CCI of CLSID_DirectPlay / IID_IDirectPlay4A failed\n" );
2337 if (FAILED(hr)) return;
2338
2339 /* No service provider */
2340 hr = IDirectPlayX_SetPlayerData( pDP, 0, (LPVOID) lpData,
2341 dwDataSize, 0 );
2343
2344 hr = IDirectPlayX_GetPlayerData( pDP, 0, lpDataGet, &dwDataSizeGet, 0 );
2346
2347
2348 init_TCPIP_provider( pDP, "127.0.0.1", 0 );
2349
2350 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
2351 dpsd.dwSize = sizeof(DPSESSIONDESC2);
2352 dpsd.guidApplication = appGuid;
2353 IDirectPlayX_Open( pDP, &dpsd, DPOPEN_CREATE );
2354
2355
2356 /* Invalid player */
2357 hr = IDirectPlayX_SetPlayerData( pDP, 0, (LPVOID) lpData,
2358 dwDataSize, 0 );
2360
2361 hr = IDirectPlayX_GetPlayerData( pDP, 0, lpDataGet, &dwDataSizeGet, 0 );
2363
2364 if ( hr == DPERR_UNINITIALIZED )
2365 {
2366 todo_wine win_skip( "Get/SetPlayerData not implemented\n" );
2367 return;
2368 }
2369
2370 /* Create the player */
2371 /* By default, the data is remote */
2372 hr = IDirectPlayX_CreatePlayer( pDP, &dpid, NULL, NULL, (LPVOID) lpData,
2373 dwDataSize, 0 );
2374 checkHR( DP_OK, hr );
2375
2376 /* Invalid parameters */
2377 hr = IDirectPlayX_SetPlayerData( pDP, dpid, NULL, dwDataSize, 0 );
2379 hr = IDirectPlayX_SetPlayerData( pDP, dpid, lpDataGet, -1, 0 );
2381
2382 hr = IDirectPlayX_GetPlayerData( pDP, dpid, lpDataGet, NULL, 0 );
2384
2385
2386 /*
2387 * Remote data (default)
2388 */
2389
2390
2391 /* Buffer redimension */
2392 dwDataSizeGet = dwDataSizeFake;
2393 strcpy(lpDataGet, lpDataFake);
2394 hr = IDirectPlayX_GetPlayerData( pDP, dpid, NULL,
2395 &dwDataSizeGet, 0 );
2397 check( dwDataSize, dwDataSizeGet );
2398 checkStr( lpDataFake, lpDataGet );
2399
2400 dwDataSizeGet = 2;
2401 strcpy(lpDataGet, lpDataFake);
2402 hr = IDirectPlayX_GetPlayerData( pDP, dpid, lpDataGet, &dwDataSizeGet, 0 );
2404 check( dwDataSize, dwDataSizeGet );
2405
2406 strcpy(lpDataGet, lpDataFake);
2407 hr = IDirectPlayX_GetPlayerData( pDP, dpid, lpDataGet, &dwDataSizeGet, 0 );
2408 checkHR( DP_OK, hr );
2409 check( dwDataSize, dwDataSizeGet );
2410 checkStr( lpData, lpDataGet );
2411
2412 /* Normal operation */
2413 dwDataSizeGet = dwDataSizeFake;
2414 strcpy(lpDataGet, lpDataFake);
2415 hr = IDirectPlayX_GetPlayerData( pDP, dpid, lpDataGet, &dwDataSizeGet, 0 );
2416 checkHR( DP_OK, hr );
2417 check( dwDataSize, dwDataSizeGet );
2418 checkStr( lpData, lpDataGet );
2419
2420 /* Flag tests */
2421 dwDataSizeGet = dwDataSizeFake;
2422 strcpy(lpDataGet, lpDataFake);
2423 hr = IDirectPlayX_GetPlayerData( pDP, dpid, lpDataGet, &dwDataSizeGet, 0 );
2424 checkHR( DP_OK, hr );
2425 check( dwDataSize, dwDataSizeGet ); /* Remote: works as expected */
2426 checkStr( lpData, lpDataGet );
2427
2428 dwDataSizeGet = dwDataSizeFake;
2429 strcpy(lpDataGet, lpDataFake);
2430 hr = IDirectPlayX_GetPlayerData( pDP, dpid, lpDataGet, &dwDataSizeGet,
2431 DPGET_REMOTE );
2432 checkHR( DP_OK, hr );
2433 check( dwDataSize, dwDataSizeGet ); /* Same behaviour as in previous test */
2434 checkStr( lpData, lpDataGet );
2435
2436 dwDataSizeGet = dwDataSizeFake;
2437 strcpy(lpDataGet, lpDataFake);
2438 hr = IDirectPlayX_GetPlayerData( pDP, dpid, lpDataGet, &dwDataSizeGet,
2439 DPGET_LOCAL );
2440 checkHR( DP_OK, hr );
2441 check( 0, dwDataSizeGet ); /* Sets size to 0 (as local data doesn't exist) */
2442 checkStr( lpDataFake, lpDataGet );
2443
2444 dwDataSizeGet = dwDataSizeFake;
2445 strcpy(lpDataGet, lpDataFake);
2446 hr = IDirectPlayX_GetPlayerData( pDP, dpid, lpDataGet, &dwDataSizeGet,
2448 checkHR( DP_OK, hr );
2449 check( 0, dwDataSizeGet ); /* Same behaviour as in previous test */
2450 checkStr( lpDataFake, lpDataGet );
2451
2452 /* Getting local data (which doesn't exist), buffer size is ignored */
2453 dwDataSizeGet = 0;
2454 strcpy(lpDataGet, lpDataFake);
2455 hr = IDirectPlayX_GetPlayerData( pDP, dpid, lpDataGet, &dwDataSizeGet,
2456 DPGET_LOCAL );
2457 checkHR( DP_OK, hr );
2458 check( 0, dwDataSizeGet ); /* Sets size to 0 */
2459 checkStr( lpDataFake, lpDataGet );
2460
2461 dwDataSizeGet = dwDataSizeFake;
2462 strcpy(lpDataGet, lpDataFake);
2463 hr = IDirectPlayX_GetPlayerData( pDP, dpid, NULL, &dwDataSizeGet,
2464 DPGET_LOCAL );
2465 checkHR( DP_OK, hr );
2466 check( 0, dwDataSizeGet ); /* Sets size to 0 */
2467 checkStr( lpDataFake, lpDataGet );
2468
2469
2470 /*
2471 * Local data
2472 */
2473
2474
2475 /* Invalid flags */
2476 hr = IDirectPlayX_SetPlayerData( pDP, dpid, (LPVOID) lpDataLocal,
2477 dwDataSizeLocal,
2480
2481 /* Correct parameters */
2482 hr = IDirectPlayX_SetPlayerData( pDP, dpid, (LPVOID) lpDataLocal,
2483 dwDataSizeLocal, DPSET_LOCAL );
2484 checkHR( DP_OK, hr );
2485
2486 /* Flag tests (again) */
2487 dwDataSizeGet = dwDataSizeFake;
2488 strcpy(lpDataGet, lpDataFake);
2489 hr = IDirectPlayX_GetPlayerData( pDP, dpid, lpDataGet, &dwDataSizeGet, 0 );
2490 checkHR( DP_OK, hr );
2491 check( dwDataSize, dwDataSizeGet ); /* Remote: works as expected */
2492 checkStr( lpData, lpDataGet );
2493
2494 dwDataSizeGet = dwDataSizeFake;
2495 strcpy(lpDataGet, lpDataFake);
2496 hr = IDirectPlayX_GetPlayerData( pDP, dpid, lpDataGet, &dwDataSizeGet,
2497 DPGET_REMOTE );
2498 checkHR( DP_OK, hr );
2499 check( dwDataSize, dwDataSizeGet ); /* Like in previous test */
2500 checkStr( lpData, lpDataGet );
2501
2502 dwDataSizeGet = dwDataSizeFake;
2503 strcpy(lpDataGet, lpDataFake);
2504 hr = IDirectPlayX_GetPlayerData( pDP, dpid, lpDataGet, &dwDataSizeGet,
2505 DPGET_LOCAL );
2506 checkHR( DP_OK, hr );
2507 check( dwDataSizeLocal, dwDataSizeGet ); /* Local: works as expected */
2508 checkStr( lpDataLocal, lpDataGet );
2509
2510 dwDataSizeGet = dwDataSizeFake;
2511 strcpy(lpDataGet, lpDataFake);
2512 hr = IDirectPlayX_GetPlayerData( pDP, dpid, lpDataGet, &dwDataSizeGet,
2514 checkHR( DP_OK, hr );
2515 check( dwDataSizeLocal, dwDataSizeGet ); /* Like in previous test */
2516 checkStr( lpDataLocal, lpDataGet );
2517
2518 /* Small buffer works as expected again */
2519 dwDataSizeGet = 0;
2520 strcpy(lpDataGet, lpDataFake);
2521 hr = IDirectPlayX_GetPlayerData( pDP, dpid, lpDataGet, &dwDataSizeGet,
2522 DPGET_LOCAL );
2524 check( dwDataSizeLocal, dwDataSizeGet );
2525 checkStr( lpDataFake, lpDataGet );
2526
2527 dwDataSizeGet = dwDataSizeFake;
2528 strcpy(lpDataGet, lpDataFake);
2529 hr = IDirectPlayX_GetPlayerData( pDP, dpid, NULL,
2530 &dwDataSizeGet, DPGET_LOCAL );
2532 check( dwDataSizeLocal, dwDataSizeGet );
2533 checkStr( lpDataFake, lpDataGet );
2534
2535
2536 /*
2537 * Changing remote data
2538 */
2539
2540
2541 /* Remote data := local data */
2542 hr = IDirectPlayX_SetPlayerData( pDP, dpid, (LPVOID) lpDataLocal,
2543 dwDataSizeLocal,
2545 checkHR( DP_OK, hr );
2546 hr = IDirectPlayX_SetPlayerData( pDP, dpid, (LPVOID) lpDataLocal,
2547 dwDataSizeLocal, 0 );
2548 checkHR( DP_OK, hr );
2549
2550 dwDataSizeGet = dwDataSizeFake;
2551 strcpy(lpDataGet, lpDataFake);
2552 hr = IDirectPlayX_GetPlayerData( pDP, dpid, lpDataGet, &dwDataSizeGet, 0 );
2553 checkHR( DP_OK, hr );
2554 check( dwDataSizeLocal, dwDataSizeGet );
2555 checkStr( lpDataLocal, lpDataGet );
2556
2557 /* Remote data := fake data */
2558 hr = IDirectPlayX_SetPlayerData( pDP, dpid, (LPVOID) lpDataFake,
2559 dwDataSizeFake, DPSET_REMOTE );
2560 checkHR( DP_OK, hr );
2561
2562 dwDataSizeGet = dwDataSizeFake + 1;
2563 strcpy(lpDataGet, lpData);
2564 hr = IDirectPlayX_GetPlayerData( pDP, dpid, lpDataGet, &dwDataSizeGet, 0 );
2565 checkHR( DP_OK, hr );
2566 check( dwDataSizeFake, dwDataSizeGet );
2567 checkStr( lpDataFake, lpDataGet );
2568
2569
2570 HeapFree( GetProcessHeap(), 0, lpDataGet );
2571 IDirectPlayX_Release( pDP );
2572}
2573
2574/* GetPlayerName
2575 SetPlayerName */
2576
2577static void test_PlayerName(void)
2578{
2579
2580 IDirectPlay4 *pDP[2];
2581 DPSESSIONDESC2 dpsd;
2582 DPID dpid[2];
2583 HRESULT hr;
2584 UINT i;
2585
2586 DPNAME playerName;
2587 DWORD dwDataSize = 1024;
2588 LPVOID lpData = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwDataSize );
2589 CallbackData callbackData;
2590
2591
2592 for (i=0; i<2; i++)
2593 {
2594 hr= CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
2595 &IID_IDirectPlay4A, (LPVOID*) &pDP[i] );
2596 ok( SUCCEEDED(hr), "CCI of CLSID_DirectPlay / IID_IDirectPlay4A failed\n" );
2597 if (FAILED(hr)) return;
2598 }
2599 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
2600 ZeroMemory( &playerName, sizeof(DPNAME) );
2601
2602
2603 /* Service provider not initialized */
2604 hr = IDirectPlayX_SetPlayerName( pDP[0], 0, &playerName, 0 );
2606
2607 dwDataSize = 1024;
2608 hr = IDirectPlayX_GetPlayerName( pDP[0], 0, lpData, &dwDataSize );
2610 check( 1024, dwDataSize );
2611
2612
2613 init_TCPIP_provider( pDP[0], "127.0.0.1", 0 );
2614 init_TCPIP_provider( pDP[1], "127.0.0.1", 0 );
2615
2616
2617 /* Session not initialized */
2618 hr = IDirectPlayX_SetPlayerName( pDP[0], 0, &playerName, 0 );
2620
2621 if ( hr == DPERR_UNINITIALIZED )
2622 {
2623 todo_wine win_skip( "Get/SetPlayerName not implemented\n" );
2624 return;
2625 }
2626
2627 dwDataSize = 1024;
2628 hr = IDirectPlayX_GetPlayerName( pDP[0], 0, lpData, &dwDataSize );
2630 check( 1024, dwDataSize );
2631
2632
2633 dpsd.dwSize = sizeof(DPSESSIONDESC2);
2634 dpsd.guidApplication = appGuid;
2635 dpsd.dwMaxPlayers = 10;
2636 IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE );
2638 pDP[1], 0 );
2639
2640 IDirectPlayX_CreatePlayer( pDP[0], &dpid[0], NULL, NULL, NULL, 0, 0 );
2641 IDirectPlayX_CreatePlayer( pDP[1], &dpid[1], NULL, NULL, NULL, 0, 0 );
2642
2643
2644 /* Name not initialized */
2645 playerName.dwSize = -1;
2646 hr = IDirectPlayX_SetPlayerName( pDP[0], dpid[0], &playerName, 0 );
2647 checkHR( DP_OK, hr );
2648
2649 dwDataSize = 1024;
2650 hr = IDirectPlayX_GetPlayerName( pDP[0], 0, lpData, &dwDataSize );
2652 check( 1024, dwDataSize );
2653
2654
2655 playerName.dwSize = sizeof(DPNAME);
2656 U1(playerName).lpszShortNameA = (LPSTR) "player_name";
2657 U2(playerName).lpszLongNameA = (LPSTR) "player_long_name";
2658
2659
2660 /* Invalid parameters */
2661 hr = IDirectPlayX_SetPlayerName( pDP[0], -1, &playerName, 0 );
2663 hr = IDirectPlayX_SetPlayerName( pDP[0], 0, &playerName, 0 );
2665 hr = IDirectPlayX_SetPlayerName( pDP[0], dpid[0], &playerName, -1 );
2667
2668 dwDataSize = 1024;
2669 hr = IDirectPlayX_GetPlayerName( pDP[0], 0, lpData, &dwDataSize );
2671 check( 1024, dwDataSize );
2672
2673if(0)
2674{
2675 /* Crashes under Win7 */
2676 dwDataSize = -1;
2677 hr = IDirectPlayX_GetPlayerName( pDP[0], dpid[0], lpData, &dwDataSize );
2679 check( -1, dwDataSize );
2680}
2681
2682 hr = IDirectPlayX_GetPlayerName( pDP[0], dpid[0], lpData, NULL );
2684
2685 /* Trying to modify remote player */
2686 hr = IDirectPlayX_SetPlayerName( pDP[0], dpid[1], &playerName, 0 );
2688
2689
2690 /* Regular operation */
2691 hr = IDirectPlayX_SetPlayerName( pDP[0], dpid[0], &playerName, 0 );
2692 checkHR( DP_OK, hr );
2693 dwDataSize = 1024;
2694 hr = IDirectPlayX_GetPlayerName( pDP[0], dpid[0], lpData, &dwDataSize );
2695 checkHR( DP_OK, hr );
2696 check( 45, dwDataSize );
2697 checkStr( U1(playerName).lpszShortNameA, U1(*(LPDPNAME)lpData).lpszShortNameA );
2698 checkStr( U2(playerName).lpszLongNameA, U2(*(LPDPNAME)lpData).lpszLongNameA );
2699 check( 0, ((LPDPNAME)lpData)->dwFlags );
2700
2701 hr = IDirectPlayX_SetPlayerName( pDP[0], dpid[0], NULL, 0 );
2702 checkHR( DP_OK, hr );
2703 dwDataSize = 1024;
2704 hr = IDirectPlayX_GetPlayerName( pDP[0], dpid[0], lpData, &dwDataSize );
2705 checkHR( DP_OK, hr );
2706 check( 16, dwDataSize );
2707 checkLP( NULL, U1(*(LPDPNAME)lpData).lpszShortNameA );
2708 checkLP( NULL, U2(*(LPDPNAME)lpData).lpszLongNameA );
2709 check( 0, ((LPDPNAME)lpData)->dwFlags );
2710
2711
2712 /* Small buffer in get operation */
2713 dwDataSize = 1024;
2714 hr = IDirectPlayX_GetPlayerName( pDP[0], dpid[0], NULL, &dwDataSize );
2716 check( 16, dwDataSize );
2717
2718 dwDataSize = 0;
2719 hr = IDirectPlayX_GetPlayerName( pDP[0], dpid[0], lpData, &dwDataSize );
2721 check( 16, dwDataSize );
2722
2723 hr = IDirectPlayX_GetPlayerName( pDP[0], dpid[0], lpData, &dwDataSize );
2724 checkHR( DP_OK, hr );
2725 check( 16, dwDataSize );
2726 checkLP( NULL, U1(*(LPDPNAME)lpData).lpszShortNameA );
2727 checkLP( NULL, U2(*(LPDPNAME)lpData).lpszLongNameA );
2728 check( 0, ((LPDPNAME)lpData)->dwFlags );
2729
2730
2731 /* Flags */
2732 hr = IDirectPlayX_SetPlayerName( pDP[0], dpid[0], &playerName,
2734 checkHR( DP_OK, hr );
2735 dwDataSize = 1024;
2736 hr = IDirectPlayX_GetPlayerName( pDP[0], dpid[0], lpData, &dwDataSize );
2737 checkHR( DP_OK, hr );
2738 check( 45, dwDataSize );
2739 checkStr( U1(playerName).lpszShortNameA, U1(*(LPDPNAME)lpData).lpszShortNameA );
2740 checkStr( U2(playerName).lpszLongNameA, U2(*(LPDPNAME)lpData).lpszLongNameA );
2741 check( 0, ((LPDPNAME)lpData)->dwFlags );
2742
2743 /* - Local (no propagation) */
2744 U1(playerName).lpszShortNameA = (LPSTR) "no_propagation";
2745 hr = IDirectPlayX_SetPlayerName( pDP[0], dpid[0], &playerName,
2746 DPSET_LOCAL );
2747 checkHR( DP_OK, hr );
2748
2749 dwDataSize = 1024;
2750 hr = IDirectPlayX_GetPlayerName( pDP[0], dpid[0],
2751 lpData, &dwDataSize ); /* Local fetch */
2752 checkHR( DP_OK, hr );
2753 check( 48, dwDataSize );
2754 checkStr( "no_propagation", U1(*(LPDPNAME)lpData).lpszShortNameA );
2755
2756 dwDataSize = 1024;
2757 hr = IDirectPlayX_GetPlayerName( pDP[1], dpid[0],
2758 lpData, &dwDataSize ); /* Remote fetch */
2759 checkHR( DP_OK, hr );
2760 check( 45, dwDataSize );
2761 checkStr( "player_name", U1(*(LPDPNAME)lpData).lpszShortNameA );
2762
2763 /* -- 2 */
2764
2765 U1(playerName).lpszShortNameA = (LPSTR) "no_propagation_2";
2766 hr = IDirectPlayX_SetPlayerName( pDP[0], dpid[0], &playerName,
2768 checkHR( DP_OK, hr );
2769
2770 dwDataSize = 1024;
2771 hr = IDirectPlayX_GetPlayerName( pDP[0], dpid[0],
2772 lpData, &dwDataSize ); /* Local fetch */
2773 checkHR( DP_OK, hr );
2774 check( 50, dwDataSize );
2775 checkStr( "no_propagation_2", U1(*(LPDPNAME)lpData).lpszShortNameA );
2776
2777 dwDataSize = 1024;
2778 hr = IDirectPlayX_GetPlayerName( pDP[1], dpid[0],
2779 lpData, &dwDataSize ); /* Remote fetch */
2780 checkHR( DP_OK, hr );
2781 check( 45, dwDataSize );
2782 checkStr( "player_name", U1(*(LPDPNAME)lpData).lpszShortNameA );
2783
2784 /* - Remote (propagation, default) */
2785 U1(playerName).lpszShortNameA = (LPSTR) "propagation";
2786 hr = IDirectPlayX_SetPlayerName( pDP[0], dpid[0], &playerName,
2787 DPSET_REMOTE );
2788 checkHR( DP_OK, hr );
2789
2790 dwDataSize = 1024;
2791 hr = IDirectPlayX_GetPlayerName( pDP[1], dpid[0],
2792 lpData, &dwDataSize ); /* Remote fetch */
2793 checkHR( DP_OK, hr );
2794 check( 45, dwDataSize );
2795 checkStr( "propagation", U1(*(LPDPNAME)lpData).lpszShortNameA );
2796
2797 /* -- 2 */
2798 U1(playerName).lpszShortNameA = (LPSTR) "propagation_2";
2799 hr = IDirectPlayX_SetPlayerName( pDP[0], dpid[0], &playerName,
2800 0 );
2801 checkHR( DP_OK, hr );
2802
2803 dwDataSize = 1024;
2804 hr = IDirectPlayX_GetPlayerName( pDP[1], dpid[0],
2805 lpData, &dwDataSize ); /* Remote fetch */
2806 checkHR( DP_OK, hr );
2807 check( 47, dwDataSize );
2808 checkStr( "propagation_2", U1(*(LPDPNAME)lpData).lpszShortNameA );
2809
2810
2811 /* Checking system messages */
2812 check_messages( pDP[0], dpid, 2, &callbackData );
2813 checkStr( "S0,S0,S0,S0,S0,S0,S0,", callbackData.szTrace1 );
2814 checkStr( "48,28,57,28,57,57,59,", callbackData.szTrace2 );
2815 check_messages( pDP[1], dpid, 2, &callbackData );
2816 checkStr( "S1,S1,S1,S1,S1,S1,", callbackData.szTrace1 );
2817 checkStr( "28,57,28,57,57,59,", callbackData.szTrace2 );
2818
2819
2820 HeapFree( GetProcessHeap(), 0, lpData );
2821 IDirectPlayX_Release( pDP[0] );
2822 IDirectPlayX_Release( pDP[1] );
2823
2824}
2825
2826/* GetPlayerAccount */
2827
2829 LPDWORD lpdwTimeOut,
2830 DWORD dwFlags,
2831 LPVOID lpContext )
2832{
2833 IDirectPlay4 *pDP = lpContext;
2834 DPSESSIONDESC2 dpsd;
2835 DPCREDENTIALS dpCredentials;
2836 HRESULT hr;
2837
2838 if (dwFlags & DPESC_TIMEDOUT)
2839 {
2840 return FALSE;
2841 }
2842
2844
2845 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
2846 dpsd.dwSize = sizeof(DPSESSIONDESC2);
2847 dpsd.guidApplication = appGuid;
2848 dpsd.guidInstance = lpThisSD->guidInstance;
2849
2850 ZeroMemory( &dpCredentials, sizeof(DPCREDENTIALS) );
2851 dpCredentials.dwSize = sizeof(DPCREDENTIALS);
2852 U1(dpCredentials).lpszUsernameA = (LPSTR) "user";
2853 U2(dpCredentials).lpszPasswordA = (LPSTR) "pass";
2854 hr = IDirectPlayX_SecureOpen( pDP, &dpsd, DPOPEN_JOIN,
2855 NULL, &dpCredentials );
2856 checkHR( DPERR_LOGONDENIED, hr ); /* TODO: Make this work */
2857
2858 return TRUE;
2859}
2860
2861static void test_GetPlayerAccount(void)
2862{
2863
2864 IDirectPlay4 *pDP[2];
2865 DPSESSIONDESC2 dpsd;
2866 DPID dpid[2];
2867 HRESULT hr;
2868 UINT i;
2869
2870 DWORD dwDataSize = 1024;
2871 LPVOID lpData = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwDataSize );
2872
2873
2874 for (i=0; i<2; i++)
2875 {
2876 hr = CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
2877 &IID_IDirectPlay4A, (LPVOID*) &pDP[i] );
2878 ok( SUCCEEDED(hr), "CCI of CLSID_DirectPlay / IID_IDirectPlay4A failed\n" );
2879 if (FAILED(hr)) return;
2880 }
2881 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
2882 dpsd.dwSize = sizeof(DPSESSIONDESC2);
2883 dpsd.guidApplication = appGuid;
2884 dpsd.dwMaxPlayers = 10;
2885
2886 /* Uninitialized service provider */
2887 hr = IDirectPlayX_GetPlayerAccount( pDP[0], 0, 0, lpData, &dwDataSize );
2889
2890 if ( hr == DP_OK )
2891 {
2892 todo_wine win_skip( "GetPlayerAccount not implemented\n" );
2893 return;
2894 }
2895
2896
2897 init_TCPIP_provider( pDP[0], "127.0.0.1", 0 );
2898 init_TCPIP_provider( pDP[1], "127.0.0.1", 0 );
2899
2900
2901 /* No session */
2902 hr = IDirectPlayX_GetPlayerAccount( pDP[0], 0, 0, lpData, &dwDataSize );
2904
2905
2906 IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE );
2908 pDP[1], 0 );
2909
2910 for (i=0; i<2; i++)
2911 {
2912 hr = IDirectPlayX_CreatePlayer( pDP[i], &dpid[i], NULL, NULL, NULL,
2913 0, 0 );
2914 checkHR( DP_OK, hr );
2915 }
2916
2917
2918 /* Session is not secure */
2919 dwDataSize = 1024;
2920 hr = IDirectPlayX_GetPlayerAccount( pDP[0], dpid[0], 0,
2921 lpData, &dwDataSize );
2923 check( 1024, dwDataSize );
2924
2925
2926 /* Open a secure session */
2927 for (i=0; i<2; i++)
2928 {
2929 hr = IDirectPlayX_Close( pDP[i] );
2930 checkHR( DP_OK, hr );
2931 }
2932
2934 hr = IDirectPlayX_SecureOpen( pDP[0], &dpsd, DPOPEN_CREATE, NULL, NULL );
2935 checkHR( DP_OK, hr );
2936
2937 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid[0],
2938 NULL, NULL, NULL, 0, 0 );
2939 checkHR( DP_OK, hr );
2940
2941 hr = IDirectPlayX_EnumSessions( pDP[1], &dpsd, 0,
2942 EnumSessions_cb_join_secure, pDP[1], 0 );
2943 checkHR( DP_OK, hr );
2944
2945 hr = IDirectPlayX_CreatePlayer( pDP[1], &dpid[1],
2946 NULL, NULL, NULL, 0, 0 );
2948
2949 /* TODO: Player creation so that this works */
2950
2951 /* Invalid player */
2952 dwDataSize = 1024;
2953 hr = IDirectPlayX_GetPlayerAccount( pDP[0], 0, 0,
2954 lpData, &dwDataSize );
2956 check( 1024, dwDataSize );
2957
2958 /* Invalid flags */
2959 dwDataSize = 1024;
2960 hr = IDirectPlayX_GetPlayerAccount( pDP[0], dpid[0], -1,
2961 lpData, &dwDataSize );
2963 check( 1024, dwDataSize );
2964
2965 dwDataSize = 1024;
2966 hr = IDirectPlayX_GetPlayerAccount( pDP[0], dpid[0], 1,
2967 lpData, &dwDataSize );
2969 check( 1024, dwDataSize );
2970
2971 /* Small buffer */
2972 dwDataSize = 1024;
2973 hr = IDirectPlayX_GetPlayerAccount( pDP[0], dpid[0], 0,
2974 NULL, &dwDataSize );
2976 check( 0, dwDataSize );
2977
2978 dwDataSize = 0;
2979 hr = IDirectPlayX_GetPlayerAccount( pDP[0], dpid[0], 0,
2980 lpData, &dwDataSize );
2982 check( 0, dwDataSize );
2983
2984 hr = IDirectPlayX_GetPlayerAccount( pDP[0], dpid[0], 0,
2985 lpData, &dwDataSize );
2987 check( 0, dwDataSize );
2988
2989 /* Normal operation */
2990 dwDataSize = 1024;
2991 hr = IDirectPlayX_GetPlayerAccount( pDP[0], dpid[0], 0,
2992 lpData, &dwDataSize );
2994 check( 1024, dwDataSize );
2995
2996
2997 HeapFree( GetProcessHeap(), 0, lpData );
2998 IDirectPlayX_Release( pDP[0] );
2999 IDirectPlayX_Release( pDP[1] );
3000
3001}
3002
3003/* GetPlayerAddress */
3004
3006 DWORD dwDataSize,
3007 LPCVOID lpData,
3008 LPVOID lpContext )
3009{
3010 lpCallbackData callbackData = lpContext;
3011 static REFGUID types[] = { &DPAID_TotalSize,
3012 &DPAID_ServiceProvider,
3013 &DPAID_INet,
3014 &DPAID_INetW };
3015 static DWORD sizes[] = { 4, 16, 12, 24, 4, 16, 10, 20 };
3016
3017
3018 checkGuid( types[callbackData->dwCounter1%4], guidDataType );
3019 check( sizes[callbackData->dwCounter1], dwDataSize );
3020
3021 switch(callbackData->dwCounter1)
3022 {
3023 case 0:
3024 check( 136, *(LPDWORD) lpData );
3025 break;
3026 case 4:
3027 check( 130, *(LPDWORD) lpData );
3028 break;
3029 case 1:
3030 case 5:
3031 checkGuid( &DPSPGUID_TCPIP, lpData );
3032 break;
3033 case 6:
3034 checkStr( "127.0.0.1", (LPSTR) lpData );
3035 break;
3036 default: break;
3037 }
3038
3039
3040 callbackData->dwCounter1++;
3041
3042 return TRUE;
3043}
3044
3045static void test_GetPlayerAddress(void)
3046{
3047
3048 IDirectPlay4 *pDP[2];
3049 IDirectPlayLobby3 *pDPL;
3050 DPSESSIONDESC2 dpsd;
3051 DPID dpid[2];
3052 CallbackData callbackData;
3053 HRESULT hr;
3054 UINT i;
3055
3056 DWORD dwDataSize = 1024;
3057 LPVOID lpData = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwDataSize );
3058
3059
3060 for (i=0; i<2; i++)
3061 {
3062 hr = CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
3063 &IID_IDirectPlay4A, (LPVOID*) &pDP[i] );
3064 ok( SUCCEEDED(hr), "CCI of CLSID_DirectPlay / IID_IDirectPlay4A failed\n" );
3065 if (FAILED(hr)) return;
3066 }
3067 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
3068 hr = CoCreateInstance( &CLSID_DirectPlayLobby, NULL, CLSCTX_ALL,
3069 &IID_IDirectPlayLobby3A, (LPVOID*) &pDPL );
3070 ok( SUCCEEDED(hr), "CCI of CLSID_DirectPlayLobby / IID_IDirectPlayLobby3A failed\n" );
3071 if (FAILED(hr)) return;
3072
3073 /* Uninitialized service provider */
3074 hr = IDirectPlayX_GetPlayerAddress( pDP[0], 0, lpData, &dwDataSize );
3076
3077 if ( hr == DP_OK )
3078 {
3079 todo_wine win_skip( "GetPlayerAddress not implemented\n" );
3080 goto cleanup;
3081 }
3082
3083 init_TCPIP_provider( pDP[0], "127.0.0.1", 0 );
3084 init_TCPIP_provider( pDP[1], "127.0.0.1", 0 );
3085
3086
3087 /* No session */
3088 dwDataSize = 1024;
3089 hr = IDirectPlayX_GetPlayerAddress( pDP[0], 0, lpData, &dwDataSize );
3091 check( 1024, dwDataSize );
3092
3093 dwDataSize = 1024;
3094 hr = IDirectPlayX_GetPlayerAddress( pDP[0], 1, lpData, &dwDataSize );
3096 check( 1024, dwDataSize );
3097
3098
3099 dpsd.dwSize = sizeof(DPSESSIONDESC2);
3100 dpsd.guidApplication = appGuid;
3101 dpsd.dwMaxPlayers = 10;
3102 IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE );
3104 pDP[1], 0 );
3105
3106 for (i=0; i<2; i++)
3107 {
3108 hr = IDirectPlayX_CreatePlayer( pDP[i], &dpid[i], NULL, NULL, NULL,
3109 0, 0 );
3110 checkHR( DP_OK, hr );
3111 }
3112
3113 /* Invalid player */
3114 dwDataSize = 1024;
3115 hr = IDirectPlayX_GetPlayerAddress( pDP[0], 0,
3116 lpData, &dwDataSize );
3118 check( 1024, dwDataSize );
3119
3120 dwDataSize = 1024;
3121 hr = IDirectPlayX_GetPlayerAddress( pDP[0], 1,
3122 lpData, &dwDataSize );
3124 check( 1024, dwDataSize );
3125
3126 /* Small buffer */
3127 dwDataSize = 1024;
3128 hr = IDirectPlayX_GetPlayerAddress( pDP[0], dpid[0],
3129 NULL, &dwDataSize );
3131 check( 136, dwDataSize );
3132
3133 dwDataSize = 0;
3134 hr = IDirectPlayX_GetPlayerAddress( pDP[0], dpid[0],
3135 lpData, &dwDataSize );
3137 check( 136, dwDataSize );
3138
3139 hr = IDirectPlayX_GetPlayerAddress( pDP[0], dpid[0],
3140 lpData, &dwDataSize );
3141 checkHR( DP_OK, hr );
3142 check( 136, dwDataSize );
3143
3144
3145 /* Regular parameters */
3146 callbackData.dwCounter1 = 0;
3147
3148 /* - Local */
3149 dwDataSize = 1024;
3150 hr = IDirectPlayX_GetPlayerAddress( pDP[0], dpid[0],
3151 lpData, &dwDataSize );
3152 checkHR( DP_OK, hr );
3153 check( 136, dwDataSize );
3154
3155 hr = IDirectPlayLobby_EnumAddress( pDPL, EnumAddress_cb, lpData, dwDataSize,
3156 &callbackData );
3157 checkHR( DP_OK, hr );
3158
3159 check( 4, callbackData.dwCounter1 );
3160
3161 /* - Remote */
3162 dwDataSize = 1024;
3163 hr = IDirectPlayX_GetPlayerAddress( pDP[0], dpid[1],
3164 lpData, &dwDataSize );
3165 checkHR( DP_OK, hr );
3166 check( 130, dwDataSize );
3167
3168 hr = IDirectPlayLobby_EnumAddress( pDPL, EnumAddress_cb, lpData, dwDataSize,
3169 &callbackData );
3170 checkHR( DP_OK, hr );
3171
3172 check( 8, callbackData.dwCounter1 );
3173
3174
3175 HeapFree( GetProcessHeap(), 0, lpData );
3176
3177cleanup:
3178 IDirectPlayX_Release( pDP[0] );
3179 IDirectPlayX_Release( pDP[1] );
3181}
3182
3183/* GetPlayerFlags */
3184
3185static void test_GetPlayerFlags(void)
3186{
3187
3188 IDirectPlay4 *pDP[2];
3189 DPSESSIONDESC2 dpsd;
3190 DPID dpid[4];
3191 HRESULT hr;
3192 UINT i;
3193
3194 DWORD dwFlags = 0;
3195
3196
3197 for (i=0; i<2; i++)
3198 {
3199 hr= CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
3200 &IID_IDirectPlay4A, (LPVOID*) &pDP[i] );
3201 ok( SUCCEEDED(hr), "CCI of CLSID_DirectPlay / IID_IDirectPlay4A failed\n" );
3202 if (FAILED(hr)) return;
3203 }
3204 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
3205 dpsd.dwSize = sizeof(DPSESSIONDESC2);
3206 dpsd.guidApplication = appGuid;
3207 dpsd.dwMaxPlayers = 10;
3208
3209 /* Uninitialized service provider */
3210 hr = IDirectPlayX_GetPlayerFlags( pDP[0], 0, &dwFlags );
3212
3213 if ( hr == DP_OK )
3214 {
3215 todo_wine win_skip( "GetPlayerFlags not implemented\n" );
3216 return;
3217 }
3218
3219 init_TCPIP_provider( pDP[0], "127.0.0.1", 0 );
3220 init_TCPIP_provider( pDP[1], "127.0.0.1", 0 );
3221
3222
3223 /* No session */
3224 hr = IDirectPlayX_GetPlayerFlags( pDP[0], 0, &dwFlags );
3226
3227 hr = IDirectPlayX_GetPlayerFlags( pDP[0], 1, &dwFlags );
3229
3230
3231 IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE );
3233 pDP[1], 0 );
3234
3235 for (i=0; i<2; i++)
3236 {
3237 hr = IDirectPlayX_CreatePlayer( pDP[i], &dpid[i],
3238 NULL, NULL, NULL, 0, 0 );
3239 checkHR( DP_OK, hr );
3240 }
3241 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid[2],
3242 NULL, NULL, NULL,
3243 0, DPPLAYER_SPECTATOR );
3244 checkHR( DP_OK, hr );
3245 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid[3],
3246 NULL, NULL, NULL,
3248 checkHR( DP_OK, hr );
3249
3250
3251 /* Invalid player */
3252 hr = IDirectPlayX_GetPlayerFlags( pDP[0], 0, &dwFlags );
3254
3255 hr = IDirectPlayX_GetPlayerFlags( pDP[0], 2, &dwFlags );
3257
3258 /* Invalid parameters */
3259 hr = IDirectPlayX_GetPlayerFlags( pDP[0], dpid[0], NULL );
3261
3262
3263 /* Regular parameters */
3264 hr = IDirectPlayX_GetPlayerFlags( pDP[0], dpid[0], &dwFlags );
3265 checkHR( DP_OK, hr );
3267
3268 hr = IDirectPlayX_GetPlayerFlags( pDP[1], dpid[1], &dwFlags );
3269 checkHR( DP_OK, hr );
3271
3272 hr = IDirectPlayX_GetPlayerFlags( pDP[0], dpid[1], &dwFlags );
3273 checkHR( DP_OK, hr );
3275
3276 hr = IDirectPlayX_GetPlayerFlags( pDP[0], dpid[2], &dwFlags );
3277 checkHR( DP_OK, hr );
3279
3280 hr = IDirectPlayX_GetPlayerFlags( pDP[1], dpid[3], &dwFlags );
3281 checkHR( DP_OK, hr );
3283
3284
3285 IDirectPlayX_Release( pDP[0] );
3286 IDirectPlayX_Release( pDP[1] );
3287
3288}
3289
3290/* CreateGroup
3291 CreateGroupInGroup */
3292
3293static void test_CreateGroup(void)
3294{
3295
3296 IDirectPlay4 *pDP;
3297 DPSESSIONDESC2 dpsd;
3298 DPID idFrom, idTo, dpid, idGroup, idGroupParent;
3299 DPNAME groupName;
3300 HRESULT hr;
3301 UINT i;
3302
3303 LPCSTR lpData = "data";
3304 DWORD dwDataSize = strlen(lpData)+1;
3307 1024 );
3308 DWORD dwDataSizeGet = 1024;
3309 CallbackData callbackData;
3310
3311
3312 hr= CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
3313 &IID_IDirectPlay4A, (LPVOID*) &pDP );
3314 ok( SUCCEEDED(hr), "CCI of CLSID_DirectPlay / IID_IDirectPlay4A failed\n" );
3315 if (FAILED(hr)) return;
3316 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
3317 dpsd.dwSize = sizeof(DPSESSIONDESC2);
3318 dpsd.guidApplication = appGuid;
3319 dpsd.dwMaxPlayers = 10;
3320 ZeroMemory( &groupName, sizeof(DPNAME) );
3321
3322
3323 /* No service provider */
3324 hr = IDirectPlayX_CreateGroup( pDP, &idGroup, NULL, NULL, 0, 0 );
3326
3327 hr = IDirectPlayX_CreateGroupInGroup( pDP, 0, &idGroup, NULL, NULL, 0, 0 );
3329
3330
3331
3332 init_TCPIP_provider( pDP, "127.0.0.1", 0 );
3333
3334
3335 /* No session */
3336 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3337 NULL, NULL, 0, 0 );
3339
3340 if ( hr == DPERR_UNINITIALIZED )
3341 {
3342 todo_wine win_skip( "CreateGroup not implemented\n" );
3343 return;
3344 }
3345
3346 hr = IDirectPlayX_CreateGroupInGroup( pDP, 0, &idGroup,
3347 NULL, NULL, 0, 0 );
3349
3350 hr = IDirectPlayX_CreateGroupInGroup( pDP, 2, &idGroup,
3351 NULL, NULL, 0, 0 );
3353
3354
3355 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_CREATE );
3356 checkHR( DP_OK, hr );
3357 IDirectPlayX_CreatePlayer( pDP, &dpid,
3358 NULL, NULL, NULL, 0, 0 );
3359
3360
3361
3362 /* With name */
3363 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3364 NULL, NULL, 0, 0 );
3365 checkHR( DP_OK, hr );
3366
3367 hr = IDirectPlayX_CreateGroupInGroup( pDP, idGroup, &idGroup,
3368 NULL, NULL, 0, 0 );
3369 checkHR( DP_OK, hr );
3370
3371 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3372 &groupName, NULL, 0, 0 );
3373 checkHR( DP_OK, hr );
3374
3375 hr = IDirectPlayX_CreateGroupInGroup( pDP, idGroup, &idGroup,
3376 &groupName, NULL, 0, 0 );
3377 checkHR( DP_OK, hr );
3378
3379
3380 groupName.dwSize = sizeof(DPNAME);
3381 U1(groupName).lpszShortNameA = (LPSTR) lpData;
3382
3383
3384 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3385 &groupName, NULL, 0, 0 );
3386 checkHR( DP_OK, hr );
3387
3388 hr = IDirectPlayX_CreateGroupInGroup( pDP, idGroup, &idGroup,
3389 &groupName, NULL, 0, 0 );
3390 checkHR( DP_OK, hr );
3391
3392
3393 /* Message checking */
3394 for (i=0; i<6; i++)
3395 {
3396 dwDataSizeGet = 1024;
3397 hr = IDirectPlayX_Receive( pDP, &idFrom, &idTo, 0, lpDataGet,
3398 &dwDataSizeGet );
3399 checkHR( DP_OK, hr );
3400 if ( NULL == U1(lpDataGet->dpnName).lpszShortNameA )
3401 {
3402 check( 48, dwDataSizeGet );
3403 }
3404 else
3405 {
3406 check( 48 + dwDataSize, dwDataSizeGet );
3407 checkStr( lpData, U1(lpDataGet->dpnName).lpszShortNameA );
3408 }
3409 check( DPID_SYSMSG, idFrom );
3411 check( DPPLAYERTYPE_GROUP, lpDataGet->dwPlayerType );
3413 }
3414 check_messages( pDP, &dpid, 1, &callbackData );
3415 checkStr( "", callbackData.szTrace1 );
3416
3417
3418 /* With data */
3419 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3420 NULL, (LPVOID) lpData, -1, 0 );
3422
3423 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3424 NULL, (LPVOID) lpData, 0, 0 );
3425 checkHR( DP_OK, hr );
3426
3427 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3428 NULL, NULL, dwDataSize, 0 );
3430
3431 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3432 NULL, (LPVOID) lpData, dwDataSize, 0 );
3433 checkHR( DP_OK, hr );
3434
3435
3436 hr = IDirectPlayX_CreateGroupInGroup( pDP, idGroup, &idGroup,
3437 NULL, (LPVOID) lpData, -1, 0 );
3439
3440 hr = IDirectPlayX_CreateGroupInGroup( pDP, idGroup, &idGroup,
3441 NULL, (LPVOID) lpData, 0, 0 );
3442 checkHR( DP_OK, hr );
3443
3444 hr = IDirectPlayX_CreateGroupInGroup( pDP, idGroup, &idGroup,
3445 NULL, NULL, dwDataSize, 0 );
3447
3448 hr = IDirectPlayX_CreateGroupInGroup( pDP, idGroup, &idGroup,
3449 NULL, (LPVOID)lpData, dwDataSize, 0 );
3450 checkHR( DP_OK, hr );
3451
3452
3453 hr = IDirectPlayX_CreateGroup( pDP, &idGroupParent,
3454 NULL, NULL, 0, 0 );
3455 checkHR( DP_OK, hr );
3456
3457
3458 /* Message checking */
3459 for (i=0; i<5; i++)
3460 {
3461 dwDataSizeGet = 1024;
3462 hr = IDirectPlayX_Receive( pDP, &idFrom, &idTo, 0, lpDataGet,
3463 &dwDataSizeGet );
3464 checkHR( DP_OK, hr );
3465 check( 48 + lpDataGet->dwDataSize, dwDataSizeGet );
3466 check( DPID_SYSMSG, idFrom );
3468 check( DPPLAYERTYPE_GROUP, lpDataGet->dwPlayerType );
3470 }
3471 check_messages( pDP, &dpid, 1, &callbackData );
3472 checkStr( "", callbackData.szTrace1 );
3473
3474
3475 /* Flags and idGroupParent */
3476 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3477 NULL, NULL, 0, 0 );
3478 checkHR( DP_OK, hr );
3479
3480 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3481 NULL, NULL, 0, DPGROUP_HIDDEN );
3482 checkHR( DP_OK, hr );
3483
3484 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3486 checkHR( DP_OK, hr );
3487
3488 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3489 NULL, NULL, 0,
3491 checkHR( DP_OK, hr );
3492
3493
3494 hr = IDirectPlayX_CreateGroupInGroup( pDP, idGroupParent, &idGroup,
3495 NULL, NULL, 0, 0 );
3496 checkHR( DP_OK, hr );
3497
3498 hr = IDirectPlayX_CreateGroupInGroup( pDP, idGroupParent, &idGroup,
3499 NULL, NULL, 0, DPGROUP_HIDDEN );
3500 checkHR( DP_OK, hr );
3501
3502 hr = IDirectPlayX_CreateGroupInGroup( pDP, idGroupParent, &idGroup,
3504 checkHR( DP_OK, hr );
3505
3506 hr = IDirectPlayX_CreateGroupInGroup( pDP, idGroupParent, &idGroup,
3507 NULL, NULL, 0,
3510 checkHR( DP_OK, hr );
3511
3512
3513 /* Message checking */
3514 for (i=0; i<8; i++)
3515 {
3516 dwDataSizeGet = 1024;
3517 hr = IDirectPlayX_Receive( pDP, &idFrom, &idTo, 0, lpDataGet,
3518 &dwDataSizeGet );
3519 checkHR( DP_OK, hr );
3520 check( 48, dwDataSizeGet );
3521 check( DPID_SYSMSG, idFrom );
3523 check( DPPLAYERTYPE_GROUP, lpDataGet->dwPlayerType );
3524
3525 if ( lpDataGet->dpIdParent != 0 )
3526 {
3527 check( idGroupParent, lpDataGet->dpIdParent );
3528 }
3529
3530 switch (i%4)
3531 {
3532 case 0:
3534 lpDataGet->dwFlags, FLAGS_DPGROUP );
3535 break;
3536 case 1:
3538 lpDataGet->dwFlags, FLAGS_DPGROUP );
3539 break;
3540 case 2:
3542 lpDataGet->dwFlags, FLAGS_DPGROUP );
3543 break;
3544 case 3:
3546 lpDataGet->dwFlags, FLAGS_DPGROUP );
3547 break;
3548 default: break;
3549 }
3550 }
3551 check_messages( pDP, &dpid, 1, &callbackData );
3552 checkStr( "", callbackData.szTrace1 );
3553
3554
3555 /* If a group is created in C/S mode, no messages are sent */
3556
3557 /* - Peer 2 peer */
3558 IDirectPlayX_Close( pDP );
3559
3560 dpsd.dwFlags = 0;
3561 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_CREATE );
3562 checkHR( DP_OK, hr );
3563 hr = IDirectPlayX_CreatePlayer( pDP, &dpid, NULL, NULL, NULL, 0, 0 );
3564 checkHR( DP_OK, hr );
3565
3566 hr = IDirectPlayX_CreateGroup( pDP, &idGroup, NULL, NULL, 0, 0 );
3567 checkHR( DP_OK, hr );
3568
3569 /* Messages are received */
3570 check_messages( pDP, &dpid, 1, &callbackData );
3571 checkStr( "S0,", callbackData.szTrace1 );
3572
3573
3574 /* - Client/Server */
3575 IDirectPlayX_Close( pDP );
3576
3578 hr = IDirectPlayX_Open( pDP, &dpsd, DPOPEN_CREATE );
3579 checkHR( DP_OK, hr );
3580 hr = IDirectPlayX_CreatePlayer( pDP, &dpid,
3581 NULL, NULL, NULL, 0,
3583 checkHR( DP_OK, hr );
3584
3585 hr = IDirectPlayX_CreateGroup( pDP, &idGroup,
3586 NULL, NULL, 0, 0 );
3587 checkHR( DP_OK, hr );
3588
3589 /* No messages */
3590 check_messages( pDP, &dpid, 1, &callbackData );
3591 checkStr( "S0,", callbackData.szTrace1 ); /* Or at least there
3592 shouldn't be messages... */
3593
3594
3595 HeapFree( GetProcessHeap(), 0, lpDataGet );
3596 IDirectPlayX_Release( pDP );
3597
3598}
3599
3600/* GroupOwner */
3601
3602static void test_GroupOwner(void)
3603{
3604
3605 IDirectPlay4 *pDP[2];
3606 DPSESSIONDESC2 dpsd;
3607 DPID dpid[2], idGroup, idOwner;
3608 HRESULT hr;
3609 UINT i;
3610
3611
3612 for (i=0; i<2; i++)
3613 {
3614 hr = CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
3615 &IID_IDirectPlay4A, (LPVOID*) &pDP[i] );
3616 ok( SUCCEEDED(hr), "CCI of CLSID_DirectPlay / IID_IDirectPlay4A failed\n" );
3617 if (FAILED(hr)) return;
3618 }
3619 ZeroMemory( &dpsd, sizeof(DPSESSIONDESC2) );
3620 dpsd.dwSize = sizeof(DPSESSIONDESC2);
3621 dpsd.guidApplication = appGuid;
3622 dpsd.dwMaxPlayers = 10;
3623 idGroup = 0;
3624 idOwner = 0;
3625
3626 /* Service provider not initialized */
3627 hr = IDirectPlayX_GetGroupOwner( pDP[0], idGroup, &idOwner );
3629 check( 0, idOwner );
3630
3631 if ( hr == DP_OK )
3632 {
3633 todo_wine win_skip( "GetGroupOwner not implemented\n" );
3634 return;
3635 }
3636
3637
3638 for (i=0; i<2; i++)
3639 init_TCPIP_provider( pDP[i], "127.0.0.1", 0 );
3640
3641 hr = IDirectPlayX_Open( pDP[0], &dpsd, DPOPEN_CREATE );
3642 checkHR( DP_OK, hr );
3644 pDP[1], 0 );
3645 checkHR( DP_OK, hr );
3646
3647 for (i=0; i<2; i++)
3648 {
3649 hr = IDirectPlayX_CreatePlayer( pDP[i], &dpid[i],
3650 NULL, NULL, NULL, 0, 0 );
3651 checkHR( DP_OK, hr );
3652 }
3653
3654 /* Invalid group */
3655 hr = IDirectPlayX_GetGroupOwner( pDP[0], idGroup, &idOwner );
3657
3658 hr = IDirectPlayX_CreateGroup( pDP[0], &idGroup, NULL, NULL, 0, 0 );
3659 checkHR( DP_OK, hr );
3660
3661 /* Fails, because we need a lobby session */
3662 hr = IDirectPlayX_GetGroupOwner( pDP[0], idGroup, &idOwner );
3664
3665
3666 /* TODO:
3667 * - Make this work
3668 * - Check migration of the ownership of a group
3669 * when the owner leaves
3670 */
3671
3672
3673 IDirectPlayX_Release( pDP[0] );
3674 IDirectPlayX_Release( pDP[1] );
3675
3676}
3677
3678/* EnumPlayers */
3679
3681 DWORD dwPlayerType,
3683 DWORD dwFlags,
3684 LPVOID lpContext )
3685{
3686 lpCallbackData callbackData = lpContext;
3687 char playerIndex = dpid2char( callbackData->dpid,
3688 callbackData->dpidSize,
3689 dpId );
3690
3691
3692 /* Trace to study player ids */
3693 callbackData->szTrace1[ callbackData->dwCounter1 ] = playerIndex;
3694 callbackData->dwCounter1++;
3695 callbackData->szTrace1[ callbackData->dwCounter1 ] = '\0';
3696
3697 /* Trace to study flags received */
3698 strcat( callbackData->szTrace2,
3700 strlen("DPENUMPLAYERS_") ) );
3701 strcat( callbackData->szTrace2, ":" );
3702
3703
3704 if ( playerIndex < '5' )
3705 {
3706 check( DPPLAYERTYPE_PLAYER, dwPlayerType );
3707 }
3708 else
3709 {
3710 check( DPPLAYERTYPE_GROUP, dwPlayerType );
3711 }
3712
3713 return TRUE;
3714
3715}
3716
3718 LPDWORD lpdwTimeOut,
3719 DWORD dwFlags,
3720 LPVOID lpContext )
3721{
3722 lpCallbackData callbackData = lpContext;
3723 HRESULT hr;
3724
3725 if (dwFlags & DPESC_TIMEDOUT)
3726 {
3727 return FALSE;
3728 }
3729
3730 /* guid = NULL */
3731 callbackData->dwCounter1 = 0;
3733 &callbackData, 0 );
3735 check( 0, callbackData->dwCounter1 );
3736
3737 /* guid = appGuid */
3738 callbackData->dwCounter1 = 0;
3739 hr = IDirectPlayX_EnumPlayers( callbackData->pDP, (LPGUID) &appGuid,
3740 EnumPlayers_cb, &callbackData, 0 );
3742 check( 0, callbackData->dwCounter1 );
3743
3744 callbackData->dwCounter1 = 0;
3745 hr = IDirectPlayX_EnumPlayers( callbackData->pDP, (LPGUID) &appGuid,
3746 EnumPlayers_cb, &callbackData,
3749 check( 0, callbackData->dwCounter1 );
3750
3751 /* guid = guidInstance */
3752 callbackData->dwCounter1 = 0;
3753 hr = IDirectPlayX_EnumPlayers( callbackData->pDP,
3754 (LPGUID) &lpThisSD->guidInstance,
3755 EnumPlayers_cb, &callbackData, 0 );
3757 check( 0, callbackData->dwCounter1 );
3758
3759 callbackData->dwCounter1 = 0;
3760 hr = IDirectPlayX_EnumPlayers( callbackData->pDP,
3761 (LPGUID) &lpThisSD->guidInstance,
3762 EnumPlayers_cb, &callbackData,
3764 checkHR( DPERR_GENERIC, hr ); /* Why? */
3765 check( 0, callbackData->dwCounter1 );
3766
3767 return TRUE;
3768
3769}
3770
3771static void test_EnumPlayers(void)
3772{
3773 IDirectPlay4 *pDP[3];
3774 DPSESSIONDESC2 dpsd[3];
3775 DPID dpid[5+2]; /* 5 players, 2 groups */
3776 CallbackData callbackData;
3777 HRESULT hr;
3778 UINT i;
3779
3780
3781 for (i=0; i<3; i++)
3782 {
3783 hr = CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
3784 &IID_IDirectPlay4A, (LPVOID*) &pDP[i] );
3785 ok( SUCCEEDED(hr), "CCI of CLSID_DirectPlay / IID_IDirectPlay4A failed\n" );
3786 if (FAILED(hr)) return;
3787
3788 ZeroMemory( &dpsd[i], sizeof(DPSESSIONDESC2) );
3789 dpsd[i].dwSize = sizeof(DPSESSIONDESC2);
3790 }
3791
3792 dpsd[0].guidApplication = appGuid;
3793 dpsd[1].guidApplication = appGuid2;
3794 dpsd[2].guidApplication = GUID_NULL;
3795
3796 callbackData.dpid = dpid;
3797 callbackData.dpidSize = 5+2;
3798
3799
3800 /* Uninitialized service provider */
3801 callbackData.dwCounter1 = 0;
3802 hr = IDirectPlayX_EnumPlayers( pDP[0], (LPGUID) &appGuid, NULL,
3803 &callbackData, 0 );
3805 check( 0, callbackData.dwCounter1 );
3806
3807
3808 init_TCPIP_provider( pDP[0], "127.0.0.1", 0 );
3809 init_TCPIP_provider( pDP[1], "127.0.0.1", 0 );
3810 init_TCPIP_provider( pDP[2], "127.0.0.1", 0 );
3811
3812
3813 /* No session */
3814 callbackData.dwCounter1 = 0;
3816 &callbackData, 0 );
3818 check( 0, callbackData.dwCounter1 );
3819
3820 if ( hr == DPERR_UNINITIALIZED )
3821 {
3822 todo_wine win_skip( "EnumPlayers not implemented\n" );
3823 return;
3824 }
3825
3826 callbackData.dwCounter1 = 0;
3827 hr = IDirectPlayX_EnumPlayers( pDP[0], (LPGUID) &appGuid, EnumPlayers_cb,
3828 &callbackData, 0 );
3830 check( 0, callbackData.dwCounter1 );
3831
3832 callbackData.dwCounter1 = 0;
3833 hr = IDirectPlayX_EnumPlayers( pDP[0], (LPGUID) &appGuid, EnumPlayers_cb,
3834 &callbackData, DPENUMPLAYERS_SESSION );
3836 check( 0, callbackData.dwCounter1 );
3837
3838
3839 hr = IDirectPlayX_Open( pDP[0], &dpsd[0], DPOPEN_CREATE );
3840 checkHR( DP_OK, hr );
3841 hr = IDirectPlayX_Open( pDP[1], &dpsd[1], DPOPEN_CREATE );
3842 checkHR( DP_OK, hr );
3843
3844
3845 /* No players */
3846 callbackData.dwCounter1 = 0;
3848 &callbackData, 0 );
3849 checkHR( DP_OK, hr );
3850 check( 0, callbackData.dwCounter1 );
3851
3852
3853 /* Create players */
3854 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid[0],
3855 NULL, NULL, NULL, 0,
3857 checkHR( DP_OK, hr );
3858 hr = IDirectPlayX_CreatePlayer( pDP[1], &dpid[1],
3859 NULL, NULL, NULL, 0,
3860 0 );
3861 checkHR( DP_OK, hr );
3862
3863 hr = IDirectPlayX_CreatePlayer( pDP[0], &dpid[2],
3864 NULL, NULL, NULL, 0,
3865 0 );
3866 checkHR( DP_OK, hr );
3867 hr = IDirectPlayX_CreateGroup( pDP[0], &dpid[5],
3868 NULL, NULL, 0, 0 );
3869 checkHR( DP_OK, hr );
3870
3871
3872 /* Invalid parameters */
3873 callbackData.dwCounter1 = 0;
3874 hr = IDirectPlayX_EnumPlayers( pDP[0], (LPGUID) &appGuid, NULL,
3875 &callbackData, 0 );
3877 check( 0, callbackData.dwCounter1 );
3878
3879 callbackData.dwCounter1 = 0;
3881 &callbackData, DPENUMPLAYERS_SESSION );
3883 check( 0, callbackData.dwCounter1 );
3884
3885
3886 /* Regular operation */
3887 callbackData.dwCounter1 = 0;
3888 callbackData.szTrace2[0] = 0;
3890 &callbackData, 0 );
3891 checkHR( DP_OK, hr );
3892 check( 2, callbackData.dwCounter1 );
3893 checkStr( "20", callbackData.szTrace1 );
3894 checkStr( "ALL:SERVERPLAYER:", callbackData.szTrace2 );
3895
3896 callbackData.dwCounter1 = 0;
3897 callbackData.szTrace2[0] = 0;
3899 &callbackData, 0 );
3900 checkHR( DP_OK, hr );
3901 check( 1, callbackData.dwCounter1 );
3902 checkStr( "1", callbackData.szTrace1 );
3903 checkStr( "ALL:", callbackData.szTrace2 );
3904
3905 callbackData.dwCounter1 = 0;
3906 callbackData.szTrace2[0] = 0;
3907 hr = IDirectPlayX_EnumPlayers( pDP[0], (LPGUID) &appGuid, EnumPlayers_cb,
3908 &callbackData, 0 );
3909 checkHR( DP_OK, hr );
3910 check( 2, callbackData.dwCounter1 ); /* Guid is ignored */
3911 checkStr( "20", callbackData.szTrace1 );
3912 checkStr( "ALL:SERVERPLAYER:", callbackData.szTrace2 );
3913
3914
3915 /* Enumerating from a remote session */
3916 /* - Session not open */
3917 callbackData.pDP = pDP[2];
3918 hr = IDirectPlayX_EnumSessions( pDP[2], &dpsd[2], 0,
3920 &callbackData, 0 );
3921 checkHR( DP_OK, hr );
3922
3923
3924 /* - Open session */
3925 callbackData.pDP = pDP[2];
3926 hr = IDirectPlayX_EnumSessions( pDP[2], &dpsd[0], 0, EnumSessions_cb_join,
3927 pDP[2], 0 );
3928 checkHR( DP_OK, hr );
3929 hr = IDirectPlayX_CreatePlayer( pDP[2], &dpid[3],
3930 NULL, NULL, NULL, 0,
3932 checkHR( DP_OK, hr );
3933 hr =