dplayx: Tests for EnumConnections.
[wine] / dlls / dplayx / tests / dplayx.c
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 #include "wine/test.h"
21 #include <stdio.h>
22 #define INITGUID
23 #include <dplay.h>
24 #include <dplobby.h>
25
26
27 #define check(expected, result)                 \
28     ok( (expected) == (result),                 \
29         "expected=%d got=%d\n",                 \
30         expected, result );
31 #define checkHR(expected, result)                       \
32     ok( (expected) == (result),                         \
33         "expected=%s got=%s\n",                         \
34         dpResult2str(expected), dpResult2str(result) );
35 #define checkFlags(expected, result, flags)     \
36     ok( (expected) == (result),                 \
37         "expected=0x%08x(%s) got=0x%08x(%s)\n", \
38         expected, dwFlags2str(expected, flags), \
39         result, dwFlags2str(result, flags) );
40 #define checkGuid(expected, result)             \
41     ok( IsEqualGUID(expected, result),          \
42         "expected=%s got=%s\n",                 \
43         Guid2str(expected), Guid2str(result) );
44
45
46 DEFINE_GUID(appGuid, 0xbdcfe03e, 0xf0ec, 0x415b, 0x82, 0x11, 0x6f, 0x86, 0xd8, 0x19, 0x7f, 0xe1);
47 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
48
49
50 typedef struct tagCallbackData
51 {
52     LPDIRECTPLAY4 pDP;
53     UINT dwCounter1, dwCounter2;
54     DWORD dwFlags;
55     char szTrace1[1024], szTrace2[1024];
56     DPID *dpid;
57     UINT dpidSize;
58 } CallbackData, *lpCallbackData;
59
60
61 static LPSTR get_temp_buffer(void)
62 {
63     static UINT index = 0;
64     static char buff[10][256];
65
66     index = (index + 1) % 10;
67     *buff[index] = 0;
68
69     return buff[index];
70 }
71
72
73 static LPCSTR Guid2str(const GUID *guid)
74 {
75     LPSTR buffer = get_temp_buffer();
76
77     if (!guid) return "(null)";
78
79     /* Service providers */
80     if (IsEqualGUID(guid, &DPSPGUID_IPX))
81         return "DPSPGUID_IPX";
82     if (IsEqualGUID(guid, &DPSPGUID_TCPIP))
83         return "DPSPGUID_TCPIP";
84     if (IsEqualGUID(guid, &DPSPGUID_SERIAL))
85         return "DPSPGUID_SERIAL";
86     if (IsEqualGUID(guid, &DPSPGUID_MODEM))
87         return "DPSPGUID_MODEM";
88     /* DirectPlay Address ID's */
89     if (IsEqualGUID(guid, &DPAID_TotalSize))
90         return "DPAID_TotalSize";
91     if (IsEqualGUID(guid, &DPAID_ServiceProvider))
92         return "DPAID_ServiceProvider";
93     if (IsEqualGUID(guid, &DPAID_LobbyProvider))
94         return "DPAID_LobbyProvider";
95     if (IsEqualGUID(guid, &DPAID_Phone))
96         return "DPAID_Phone";
97     if (IsEqualGUID(guid, &DPAID_PhoneW))
98         return "DPAID_PhoneW";
99     if (IsEqualGUID(guid, &DPAID_Modem))
100         return "DPAID_Modem";
101     if (IsEqualGUID(guid, &DPAID_ModemW))
102         return "DPAID_ModemW";
103     if (IsEqualGUID(guid, &DPAID_INet))
104         return "DPAID_INet";
105     if (IsEqualGUID(guid, &DPAID_INetW))
106         return "DPAID_INetW";
107     if (IsEqualGUID(guid, &DPAID_INetPort))
108         return "DPAID_INetPort";
109     if (IsEqualGUID(guid, &DPAID_ComPort))
110         return "DPAID_ComPort";
111
112     sprintf( buffer, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
113              guid->Data1, guid->Data2, guid->Data3,
114              guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
115              guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
116     return buffer;
117
118 }
119
120
121 static LPCSTR dpResult2str(HRESULT hr)
122 {
123     switch (hr)
124     {
125     case DP_OK:                          return "DP_OK";
126     case DPERR_ALREADYINITIALIZED:       return "DPERR_ALREADYINITIALIZED";
127     case DPERR_ACCESSDENIED:             return "DPERR_ACCESSDENIED";
128     case DPERR_ACTIVEPLAYERS:            return "DPERR_ACTIVEPLAYERS";
129     case DPERR_BUFFERTOOSMALL:           return "DPERR_BUFFERTOOSMALL";
130     case DPERR_CANTADDPLAYER:            return "DPERR_CANTADDPLAYER";
131     case DPERR_CANTCREATEGROUP:          return "DPERR_CANTCREATEGROUP";
132     case DPERR_CANTCREATEPLAYER:         return "DPERR_CANTCREATEPLAYER";
133     case DPERR_CANTCREATESESSION:        return "DPERR_CANTCREATESESSION";
134     case DPERR_CAPSNOTAVAILABLEYET:      return "DPERR_CAPSNOTAVAILABLEYET";
135     case DPERR_EXCEPTION:                return "DPERR_EXCEPTION";
136     case DPERR_GENERIC:                  return "DPERR_GENERIC";
137     case DPERR_INVALIDFLAGS:             return "DPERR_INVALIDFLAGS";
138     case DPERR_INVALIDOBJECT:            return "DPERR_INVALIDOBJECT";
139     case DPERR_INVALIDPARAMS:            return "DPERR_INVALIDPARAMS";
140         /*           symbol with the same value: DPERR_INVALIDPARAM */
141     case DPERR_INVALIDPLAYER:            return "DPERR_INVALIDPLAYER";
142     case DPERR_INVALIDGROUP:             return "DPERR_INVALIDGROUP";
143     case DPERR_NOCAPS:                   return "DPERR_NOCAPS";
144     case DPERR_NOCONNECTION:             return "DPERR_NOCONNECTION";
145     case DPERR_NOMEMORY:                 return "DPERR_NOMEMORY";
146         /*           symbol with the same value: DPERR_OUTOFMEMORY */
147     case DPERR_NOMESSAGES:               return "DPERR_NOMESSAGES";
148     case DPERR_NONAMESERVERFOUND:        return "DPERR_NONAMESERVERFOUND";
149     case DPERR_NOPLAYERS:                return "DPERR_NOPLAYERS";
150     case DPERR_NOSESSIONS:               return "DPERR_NOSESSIONS";
151     case DPERR_PENDING:                  return "DPERR_PENDING";
152     case DPERR_SENDTOOBIG:               return "DPERR_SENDTOOBIG";
153     case DPERR_TIMEOUT:                  return "DPERR_TIMEOUT";
154     case DPERR_UNAVAILABLE:              return "DPERR_UNAVAILABLE";
155     case DPERR_UNSUPPORTED:              return "DPERR_UNSUPPORTED";
156     case DPERR_BUSY:                     return "DPERR_BUSY";
157     case DPERR_USERCANCEL:               return "DPERR_USERCANCEL";
158     case DPERR_NOINTERFACE:              return "DPERR_NOINTERFACE";
159     case DPERR_CANNOTCREATESERVER:       return "DPERR_CANNOTCREATESERVER";
160     case DPERR_PLAYERLOST:               return "DPERR_PLAYERLOST";
161     case DPERR_SESSIONLOST:              return "DPERR_SESSIONLOST";
162     case DPERR_UNINITIALIZED:            return "DPERR_UNINITIALIZED";
163     case DPERR_NONEWPLAYERS:             return "DPERR_NONEWPLAYERS";
164     case DPERR_INVALIDPASSWORD:          return "DPERR_INVALIDPASSWORD";
165     case DPERR_CONNECTING:               return "DPERR_CONNECTING";
166     case DPERR_CONNECTIONLOST:           return "DPERR_CONNECTIONLOST";
167     case DPERR_UNKNOWNMESSAGE:           return "DPERR_UNKNOWNMESSAGE";
168     case DPERR_CANCELFAILED:             return "DPERR_CANCELFAILED";
169     case DPERR_INVALIDPRIORITY:          return "DPERR_INVALIDPRIORITY";
170     case DPERR_NOTHANDLED:               return "DPERR_NOTHANDLED";
171     case DPERR_CANCELLED:                return "DPERR_CANCELLED";
172     case DPERR_ABORTED:                  return "DPERR_ABORTED";
173     case DPERR_BUFFERTOOLARGE:           return "DPERR_BUFFERTOOLARGE";
174     case DPERR_CANTCREATEPROCESS:        return "DPERR_CANTCREATEPROCESS";
175     case DPERR_APPNOTSTARTED:            return "DPERR_APPNOTSTARTED";
176     case DPERR_INVALIDINTERFACE:         return "DPERR_INVALIDINTERFACE";
177     case DPERR_NOSERVICEPROVIDER:        return "DPERR_NOSERVICEPROVIDER";
178     case DPERR_UNKNOWNAPPLICATION:       return "DPERR_UNKNOWNAPPLICATION";
179     case DPERR_NOTLOBBIED:               return "DPERR_NOTLOBBIED";
180     case DPERR_SERVICEPROVIDERLOADED:    return "DPERR_SERVICEPROVIDERLOADED";
181     case DPERR_ALREADYREGISTERED:        return "DPERR_ALREADYREGISTERED";
182     case DPERR_NOTREGISTERED:            return "DPERR_NOTREGISTERED";
183     case DPERR_AUTHENTICATIONFAILED:     return "DPERR_AUTHENTICATIONFAILED";
184     case DPERR_CANTLOADSSPI:             return "DPERR_CANTLOADSSPI";
185     case DPERR_ENCRYPTIONFAILED:         return "DPERR_ENCRYPTIONFAILED";
186     case DPERR_SIGNFAILED:               return "DPERR_SIGNFAILED";
187     case DPERR_CANTLOADSECURITYPACKAGE:  return "DPERR_CANTLOADSECURITYPACKAGE";
188     case DPERR_ENCRYPTIONNOTSUPPORTED:   return "DPERR_ENCRYPTIONNOTSUPPORTED";
189     case DPERR_CANTLOADCAPI:             return "DPERR_CANTLOADCAPI";
190     case DPERR_NOTLOGGEDIN:              return "DPERR_NOTLOGGEDIN";
191     case DPERR_LOGONDENIED:              return "DPERR_LOGONDENIED";
192     case CLASS_E_NOAGGREGATION:          return "CLASS_E_NOAGGREGATION";
193
194     default:
195     {
196         LPSTR buffer = get_temp_buffer();
197         sprintf( buffer, "%d", HRESULT_CODE(hr) );
198         return buffer;
199     }
200     }
201 }
202
203 static LPCSTR dwFlags2str(DWORD dwFlags, DWORD flagType)
204 {
205
206 #define FLAGS_DPCONNECTION     (1<<0)
207 #define FLAGS_DPENUMPLAYERS    (1<<1)
208 #define FLAGS_DPENUMGROUPS     (1<<2)
209 #define FLAGS_DPPLAYER         (1<<3)
210 #define FLAGS_DPGROUP          (1<<4)
211 #define FLAGS_DPENUMSESSIONS   (1<<5)
212 #define FLAGS_DPGETCAPS        (1<<6)
213 #define FLAGS_DPGET            (1<<7)
214 #define FLAGS_DPRECEIVE        (1<<8)
215 #define FLAGS_DPSEND           (1<<9)
216 #define FLAGS_DPSET            (1<<10)
217 #define FLAGS_DPMESSAGEQUEUE   (1<<11)
218 #define FLAGS_DPCONNECT        (1<<12)
219 #define FLAGS_DPOPEN           (1<<13)
220 #define FLAGS_DPSESSION        (1<<14)
221 #define FLAGS_DPLCONNECTION    (1<<15)
222 #define FLAGS_DPESC            (1<<16)
223 #define FLAGS_DPCAPS           (1<<17)
224
225     LPSTR flags = get_temp_buffer();
226
227     /* EnumConnections */
228
229     if (flagType & FLAGS_DPCONNECTION)
230     {
231         if (dwFlags & DPCONNECTION_DIRECTPLAY)
232             strcat(flags, "DPCONNECTION_DIRECTPLAY,");
233         if (dwFlags & DPCONNECTION_DIRECTPLAYLOBBY)
234             strcat(flags, "DPCONNECTION_DIRECTPLAYLOBBY,");
235     }
236
237     /* EnumPlayers,
238        EnumGroups */
239
240     if (flagType & FLAGS_DPENUMPLAYERS)
241     {
242         if (dwFlags == DPENUMPLAYERS_ALL)
243             strcat(flags, "DPENUMPLAYERS_ALL,");
244         if (dwFlags & DPENUMPLAYERS_LOCAL)
245             strcat(flags, "DPENUMPLAYERS_LOCAL,");
246         if (dwFlags & DPENUMPLAYERS_REMOTE)
247             strcat(flags, "DPENUMPLAYERS_REMOTE,");
248         if (dwFlags & DPENUMPLAYERS_GROUP)
249             strcat(flags, "DPENUMPLAYERS_GROUP,");
250         if (dwFlags & DPENUMPLAYERS_SESSION)
251             strcat(flags, "DPENUMPLAYERS_SESSION,");
252         if (dwFlags & DPENUMPLAYERS_SERVERPLAYER)
253             strcat(flags, "DPENUMPLAYERS_SERVERPLAYER,");
254         if (dwFlags & DPENUMPLAYERS_SPECTATOR)
255             strcat(flags, "DPENUMPLAYERS_SPECTATOR,");
256         if (dwFlags & DPENUMPLAYERS_OWNER)
257             strcat(flags, "DPENUMPLAYERS_OWNER,");
258     }
259     if (flagType & FLAGS_DPENUMGROUPS)
260     {
261         if (dwFlags == DPENUMGROUPS_ALL)
262             strcat(flags, "DPENUMGROUPS_ALL,");
263         if (dwFlags & DPENUMPLAYERS_LOCAL)
264             strcat(flags, "DPENUMGROUPS_LOCAL,");
265         if (dwFlags & DPENUMPLAYERS_REMOTE)
266             strcat(flags, "DPENUMGROUPS_REMOTE,");
267         if (dwFlags & DPENUMPLAYERS_GROUP)
268             strcat(flags, "DPENUMGROUPS_GROUP,");
269         if (dwFlags & DPENUMPLAYERS_SESSION)
270             strcat(flags, "DPENUMGROUPS_SESSION,");
271         if (dwFlags & DPENUMGROUPS_SHORTCUT)
272             strcat(flags, "DPENUMGROUPS_SHORTCUT,");
273         if (dwFlags & DPENUMGROUPS_STAGINGAREA)
274             strcat(flags, "DPENUMGROUPS_STAGINGAREA,");
275         if (dwFlags & DPENUMGROUPS_HIDDEN)
276             strcat(flags, "DPENUMGROUPS_HIDDEN,");
277     }
278
279     /* CreatePlayer */
280
281     if (flagType & FLAGS_DPPLAYER)
282     {
283         if (dwFlags & DPPLAYER_SERVERPLAYER)
284             strcat(flags, "DPPLAYER_SERVERPLAYER,");
285         if (dwFlags & DPPLAYER_SPECTATOR)
286             strcat(flags, "DPPLAYER_SPECTATOR,");
287         if (dwFlags & DPPLAYER_LOCAL)
288             strcat(flags, "DPPLAYER_LOCAL,");
289         if (dwFlags & DPPLAYER_OWNER)
290             strcat(flags, "DPPLAYER_OWNER,");
291     }
292
293     /* CreateGroup */
294
295     if (flagType & FLAGS_DPGROUP)
296     {
297         if (dwFlags & DPGROUP_STAGINGAREA)
298             strcat(flags, "DPGROUP_STAGINGAREA,");
299         if (dwFlags & DPGROUP_LOCAL)
300             strcat(flags, "DPGROUP_LOCAL,");
301         if (dwFlags & DPGROUP_HIDDEN)
302             strcat(flags, "DPGROUP_HIDDEN,");
303     }
304
305     /* EnumSessions */
306
307     if (flagType & FLAGS_DPENUMSESSIONS)
308     {
309         if (dwFlags & DPENUMSESSIONS_AVAILABLE)
310             strcat(flags, "DPENUMSESSIONS_AVAILABLE,");
311         if (dwFlags &  DPENUMSESSIONS_ALL)
312             strcat(flags, "DPENUMSESSIONS_ALL,");
313         if (dwFlags & DPENUMSESSIONS_ASYNC)
314             strcat(flags, "DPENUMSESSIONS_ASYNC,");
315         if (dwFlags & DPENUMSESSIONS_STOPASYNC)
316             strcat(flags, "DPENUMSESSIONS_STOPASYNC,");
317         if (dwFlags & DPENUMSESSIONS_PASSWORDREQUIRED)
318             strcat(flags, "DPENUMSESSIONS_PASSWORDREQUIRED,");
319         if (dwFlags & DPENUMSESSIONS_RETURNSTATUS)
320             strcat(flags, "DPENUMSESSIONS_RETURNSTATUS,");
321     }
322
323     /* GetCaps,
324        GetPlayerCaps */
325
326     if (flagType & FLAGS_DPGETCAPS)
327     {
328         if (dwFlags & DPGETCAPS_GUARANTEED)
329             strcat(flags, "DPGETCAPS_GUARANTEED,");
330     }
331
332     /* GetGroupData,
333        GetPlayerData */
334
335     if (flagType & FLAGS_DPGET)
336     {
337         if (dwFlags == DPGET_REMOTE)
338             strcat(flags, "DPGET_REMOTE,");
339         if (dwFlags & DPGET_LOCAL)
340             strcat(flags, "DPGET_LOCAL,");
341     }
342
343     /* Receive */
344
345     if (flagType & FLAGS_DPRECEIVE)
346     {
347         if (dwFlags & DPRECEIVE_ALL)
348             strcat(flags, "DPRECEIVE_ALL,");
349         if (dwFlags & DPRECEIVE_TOPLAYER)
350             strcat(flags, "DPRECEIVE_TOPLAYER,");
351         if (dwFlags & DPRECEIVE_FROMPLAYER)
352             strcat(flags, "DPRECEIVE_FROMPLAYER,");
353         if (dwFlags & DPRECEIVE_PEEK)
354             strcat(flags, "DPRECEIVE_PEEK,");
355     }
356
357     /* Send */
358
359     if (flagType & FLAGS_DPSEND)
360     {
361         /*if (dwFlags == DPSEND_NONGUARANTEED)
362           strcat(flags, "DPSEND_NONGUARANTEED,");*/
363         if (dwFlags == DPSEND_MAX_PRIORITY) /* = DPSEND_MAX_PRI */
364         {
365             strcat(flags, "DPSEND_MAX_PRIORITY,");
366         }
367         else
368         {
369             if (dwFlags & DPSEND_GUARANTEED)
370                 strcat(flags, "DPSEND_GUARANTEED,");
371             if (dwFlags & DPSEND_HIGHPRIORITY)
372                 strcat(flags, "DPSEND_HIGHPRIORITY,");
373             if (dwFlags & DPSEND_OPENSTREAM)
374                 strcat(flags, "DPSEND_OPENSTREAM,");
375             if (dwFlags & DPSEND_CLOSESTREAM)
376                 strcat(flags, "DPSEND_CLOSESTREAM,");
377             if (dwFlags & DPSEND_SIGNED)
378                 strcat(flags, "DPSEND_SIGNED,");
379             if (dwFlags & DPSEND_ENCRYPTED)
380                 strcat(flags, "DPSEND_ENCRYPTED,");
381             if (dwFlags & DPSEND_LOBBYSYSTEMMESSAGE)
382                 strcat(flags, "DPSEND_LOBBYSYSTEMMESSAGE,");
383             if (dwFlags & DPSEND_ASYNC)
384                 strcat(flags, "DPSEND_ASYNC,");
385             if (dwFlags & DPSEND_NOSENDCOMPLETEMSG)
386                 strcat(flags, "DPSEND_NOSENDCOMPLETEMSG,");
387         }
388     }
389
390     /* SetGroupData,
391        SetGroupName,
392        SetPlayerData,
393        SetPlayerName,
394        SetSessionDesc */
395
396     if (flagType & FLAGS_DPSET)
397     {
398         if (dwFlags == DPSET_REMOTE)
399             strcat(flags, "DPSET_REMOTE,");
400         if (dwFlags & DPSET_LOCAL)
401             strcat(flags, "DPSET_LOCAL,");
402         if (dwFlags & DPSET_GUARANTEED)
403             strcat(flags, "DPSET_GUARANTEED,");
404     }
405
406     /* GetMessageQueue */
407
408     if (flagType & FLAGS_DPMESSAGEQUEUE)
409     {
410         if (dwFlags & DPMESSAGEQUEUE_SEND)
411             strcat(flags, "DPMESSAGEQUEUE_SEND,");
412         if (dwFlags & DPMESSAGEQUEUE_RECEIVE)
413             strcat(flags, "DPMESSAGEQUEUE_RECEIVE,");
414     }
415
416     /* Connect */
417
418     if (flagType & FLAGS_DPCONNECT)
419     {
420         if (dwFlags & DPCONNECT_RETURNSTATUS)
421             strcat(flags, "DPCONNECT_RETURNSTATUS,");
422     }
423
424     /* Open */
425
426     if (flagType & FLAGS_DPOPEN)
427     {
428         if (dwFlags & DPOPEN_JOIN)
429             strcat(flags, "DPOPEN_JOIN,");
430         if (dwFlags & DPOPEN_CREATE)
431             strcat(flags, "DPOPEN_CREATE,");
432         if (dwFlags & DPOPEN_RETURNSTATUS)
433             strcat(flags, "DPOPEN_RETURNSTATUS,");
434     }
435
436     /* DPSESSIONDESC2 */
437
438     if (flagType & FLAGS_DPSESSION)
439     {
440         if (dwFlags & DPSESSION_NEWPLAYERSDISABLED)
441             strcat(flags, "DPSESSION_NEWPLAYERSDISABLED,");
442         if (dwFlags & DPSESSION_MIGRATEHOST)
443             strcat(flags, "DPSESSION_MIGRATEHOST,");
444         if (dwFlags & DPSESSION_NOMESSAGEID)
445             strcat(flags, "DPSESSION_NOMESSAGEID,");
446         if (dwFlags & DPSESSION_JOINDISABLED)
447             strcat(flags, "DPSESSION_JOINDISABLED,");
448         if (dwFlags & DPSESSION_KEEPALIVE)
449             strcat(flags, "DPSESSION_KEEPALIVE,");
450         if (dwFlags & DPSESSION_NODATAMESSAGES)
451             strcat(flags, "DPSESSION_NODATAMESSAGES,");
452         if (dwFlags & DPSESSION_SECURESERVER)
453             strcat(flags, "DPSESSION_SECURESERVER,");
454         if (dwFlags & DPSESSION_PRIVATE)
455             strcat(flags, "DPSESSION_PRIVATE,");
456         if (dwFlags & DPSESSION_PASSWORDREQUIRED)
457             strcat(flags, "DPSESSION_PASSWORDREQUIRED,");
458         if (dwFlags & DPSESSION_MULTICASTSERVER)
459             strcat(flags, "DPSESSION_MULTICASTSERVER,");
460         if (dwFlags & DPSESSION_CLIENTSERVER)
461             strcat(flags, "DPSESSION_CLIENTSERVER,");
462
463         if (dwFlags & DPSESSION_DIRECTPLAYPROTOCOL)
464             strcat(flags, "DPSESSION_DIRECTPLAYPROTOCOL,");
465         if (dwFlags & DPSESSION_NOPRESERVEORDER)
466             strcat(flags, "DPSESSION_NOPRESERVEORDER,");
467         if (dwFlags & DPSESSION_OPTIMIZELATENCY)
468             strcat(flags, "DPSESSION_OPTIMIZELATENCY,");
469
470     }
471
472     /* DPLCONNECTION */
473
474     if (flagType & FLAGS_DPLCONNECTION)
475     {
476         if (dwFlags & DPLCONNECTION_CREATESESSION)
477             strcat(flags, "DPLCONNECTION_CREATESESSION,");
478         if (dwFlags & DPLCONNECTION_JOINSESSION)
479             strcat(flags, "DPLCONNECTION_JOINSESSION,");
480     }
481
482     /* EnumSessionsCallback2 */
483
484     if (flagType & FLAGS_DPESC)
485     {
486         if (dwFlags & DPESC_TIMEDOUT)
487             strcat(flags, "DPESC_TIMEDOUT,");
488     }
489
490     /* GetCaps,
491        GetPlayerCaps */
492
493     if (flagType & FLAGS_DPCAPS)
494     {
495         if (dwFlags & DPCAPS_ISHOST)
496             strcat(flags, "DPCAPS_ISHOST,");
497         if (dwFlags & DPCAPS_GROUPOPTIMIZED)
498             strcat(flags, "DPCAPS_GROUPOPTIMIZED,");
499         if (dwFlags & DPCAPS_KEEPALIVEOPTIMIZED)
500             strcat(flags, "DPCAPS_KEEPALIVEOPTIMIZED,");
501         if (dwFlags & DPCAPS_GUARANTEEDOPTIMIZED)
502             strcat(flags, "DPCAPS_GUARANTEEDOPTIMIZED,");
503         if (dwFlags & DPCAPS_GUARANTEEDSUPPORTED)
504             strcat(flags, "DPCAPS_GUARANTEEDSUPPORTED,");
505         if (dwFlags & DPCAPS_SIGNINGSUPPORTED)
506             strcat(flags, "DPCAPS_SIGNINGSUPPORTED,");
507         if (dwFlags & DPCAPS_ENCRYPTIONSUPPORTED)
508             strcat(flags, "DPCAPS_ENCRYPTIONSUPPORTED,");
509         if (dwFlags & DPCAPS_ASYNCCANCELSUPPORTED)
510             strcat(flags, "DPCAPS_ASYNCCANCELSUPPORTED,");
511         if (dwFlags & DPCAPS_ASYNCCANCELALLSUPPORTED)
512             strcat(flags, "DPCAPS_ASYNCCANCELALLSUPPORTED,");
513         if (dwFlags & DPCAPS_SENDTIMEOUTSUPPORTED)
514             strcat(flags, "DPCAPS_SENDTIMEOUTSUPPORTED,");
515         if (dwFlags & DPCAPS_SENDPRIORITYSUPPORTED)
516             strcat(flags, "DPCAPS_SENDPRIORITYSUPPORTED,");
517         if (dwFlags & DPCAPS_ASYNCSUPPORTED)
518             strcat(flags, "DPCAPS_ASYNCSUPPORTED,");
519
520         if (dwFlags & DPPLAYERCAPS_LOCAL)
521             strcat(flags, "DPPLAYERCAPS_LOCAL,");
522     }
523
524     if ((strlen(flags) == 0) && (dwFlags != 0))
525         strcpy(flags, "UNKNOWN");
526     else
527         flags[strlen(flags)-1] = '\0';
528
529     return flags;
530 }
531
532
533 /* DirectPlayCreate */
534
535 static void test_DirectPlayCreate(void)
536 {
537
538     LPDIRECTPLAY pDP;
539     HRESULT hr;
540
541     /* TODO: Check how it behaves with pUnk!=NULL */
542
543     /* pDP==NULL */
544     hr = DirectPlayCreate( NULL, NULL, NULL );
545     checkHR( DPERR_INVALIDPARAMS, hr );
546     hr = DirectPlayCreate( (LPGUID) &GUID_NULL, NULL, NULL );
547     checkHR( DPERR_INVALIDPARAMS, hr );
548     hr = DirectPlayCreate( (LPGUID) &DPSPGUID_TCPIP, NULL, NULL );
549     checkHR( DPERR_INVALIDPARAMS, hr );
550
551     /* pUnk==NULL, pDP!=NULL */
552     hr = DirectPlayCreate( NULL, &pDP, NULL );
553     checkHR( DPERR_INVALIDPARAMS, hr );
554     hr = DirectPlayCreate( (LPGUID) &GUID_NULL, &pDP, NULL );
555     checkHR( DP_OK, hr );
556     if ( hr == DP_OK )
557         IDirectPlayX_Release( pDP );
558     hr = DirectPlayCreate( (LPGUID) &DPSPGUID_TCPIP, &pDP, NULL );
559     todo_wine checkHR( DP_OK, hr );
560     if ( hr == DP_OK )
561         IDirectPlayX_Release( pDP );
562
563 }
564
565 /* EnumConnections */
566
567 static BOOL FAR PASCAL EnumAddress_cb2( REFGUID guidDataType,
568                                         DWORD dwDataSize,
569                                         LPCVOID lpData,
570                                         LPVOID lpContext )
571 {
572     lpCallbackData callbackData = (lpCallbackData) lpContext;
573
574     static REFGUID types[] = { &DPAID_TotalSize,
575                                &DPAID_ServiceProvider,
576                                &GUID_NULL };
577     static DWORD sizes[] = { 4, 16, 0  };
578     static REFGUID sps[] = { &DPSPGUID_SERIAL, &DPSPGUID_MODEM,
579                              &DPSPGUID_IPX, &DPSPGUID_TCPIP };
580
581
582     checkGuid( types[ callbackData->dwCounter2 ], guidDataType );
583     check( sizes[ callbackData->dwCounter2 ], dwDataSize );
584
585     if ( IsEqualGUID( types[0], guidDataType ) )
586     {
587         todo_wine check( 80, *((LPDWORD) lpData) );
588     }
589     else if ( IsEqualGUID( types[1], guidDataType ) )
590     {
591         todo_wine checkGuid( sps[ callbackData->dwCounter1 ], (LPGUID) lpData );
592     }
593
594     callbackData->dwCounter2++;
595
596     return TRUE;
597 }
598
599 static BOOL CALLBACK EnumConnections_cb( LPCGUID lpguidSP,
600                                          LPVOID lpConnection,
601                                          DWORD dwConnectionSize,
602                                          LPCDPNAME lpName,
603                                          DWORD dwFlags,
604                                          LPVOID lpContext )
605 {
606
607     lpCallbackData callbackData = (lpCallbackData) lpContext;
608     LPDIRECTPLAYLOBBY pDPL;
609
610
611     if (!callbackData->dwFlags)
612     {
613         callbackData->dwFlags = DPCONNECTION_DIRECTPLAY;
614     }
615
616     checkFlags( callbackData->dwFlags, dwFlags, FLAGS_DPCONNECTION );
617
618     /* Get info from lpConnection */
619     CoCreateInstance( &CLSID_DirectPlayLobby, NULL, CLSCTX_ALL,
620                       &IID_IDirectPlayLobby3A, (LPVOID*) &pDPL );
621
622     callbackData->dwCounter2 = 0;
623     IDirectPlayLobby_EnumAddress( pDPL, EnumAddress_cb2,
624                                   (LPCVOID) lpConnection,
625                                   dwConnectionSize,
626                                   (LPVOID) callbackData );
627     todo_wine check( 3, callbackData->dwCounter2 );
628
629     callbackData->dwCounter1++;
630
631     return TRUE;
632 }
633
634 static void test_EnumConnections(void)
635 {
636
637     LPDIRECTPLAY4 pDP;
638     CallbackData callbackData;
639     HRESULT hr;
640
641
642     CoCreateInstance( &CLSID_DirectPlay, NULL, CLSCTX_ALL,
643                       &IID_IDirectPlay4A, (LPVOID*) &pDP );
644
645
646     callbackData.dwCounter1 = 0;
647     callbackData.dwFlags = 0;
648     hr = IDirectPlayX_EnumConnections( pDP, &appGuid, EnumConnections_cb,
649                                        (LPVOID) &callbackData,
650                                        callbackData.dwFlags );
651     checkHR( DP_OK, hr );
652     check( 4, callbackData.dwCounter1 );
653
654     callbackData.dwCounter1 = 0;
655     callbackData.dwFlags = 0;
656     hr = IDirectPlayX_EnumConnections( pDP, NULL, EnumConnections_cb,
657                                        (LPVOID) &callbackData,
658                                        callbackData.dwFlags );
659     checkHR( DP_OK, hr );
660     check( 4, callbackData.dwCounter1 );
661
662     callbackData.dwCounter1 = 0;
663     callbackData.dwFlags = 0;
664     hr = IDirectPlayX_EnumConnections( pDP, &appGuid, NULL,
665                                        (LPVOID) &callbackData,
666                                        callbackData.dwFlags );
667     checkHR( DPERR_INVALIDPARAMS, hr );
668     check( 0, callbackData.dwCounter1 );
669
670
671     /* Flag tests */
672     callbackData.dwCounter1 = 0;
673     callbackData.dwFlags = DPCONNECTION_DIRECTPLAY;
674     hr = IDirectPlayX_EnumConnections( pDP, &appGuid, EnumConnections_cb,
675                                        (LPVOID) &callbackData,
676                                        callbackData.dwFlags );
677     checkHR( DP_OK, hr );
678     check( 4, callbackData.dwCounter1 );
679
680     callbackData.dwCounter1 = 0;
681     callbackData.dwFlags = DPCONNECTION_DIRECTPLAYLOBBY;
682     hr = IDirectPlayX_EnumConnections( pDP, &appGuid, EnumConnections_cb,
683                                        (LPVOID) &callbackData,
684                                        callbackData.dwFlags );
685     checkHR( DP_OK, hr );
686     check( 0, callbackData.dwCounter1 );
687
688     callbackData.dwCounter1 = 0;
689     callbackData.dwFlags = ( DPCONNECTION_DIRECTPLAY |
690                              DPCONNECTION_DIRECTPLAYLOBBY );
691     hr = IDirectPlayX_EnumConnections( pDP, &appGuid, EnumConnections_cb,
692                                        (LPVOID) &callbackData,
693                                        callbackData.dwFlags );
694     checkHR( DP_OK, hr );
695     check( 4, callbackData.dwCounter1 );
696
697     callbackData.dwCounter1 = 0;
698     callbackData.dwFlags = ~( DPCONNECTION_DIRECTPLAY |
699                               DPCONNECTION_DIRECTPLAYLOBBY );
700     hr = IDirectPlayX_EnumConnections( pDP, &appGuid, EnumConnections_cb,
701                                        (LPVOID) &callbackData,
702                                        callbackData.dwFlags );
703     checkHR( DPERR_INVALIDFLAGS, hr );
704     check( 0, callbackData.dwCounter1 );
705
706
707     IDirectPlayX_Release( pDP );
708 }
709
710
711 START_TEST(dplayx)
712 {
713     CoInitialize( NULL );
714
715     test_DirectPlayCreate();
716     test_EnumConnections();
717
718     CoUninitialize();
719 }