dinput: Fix printing NULL strings.
[wine] / dlls / dpnet / tests / peer.c
1 /*
2  * Copyright 2011 Louis Lenders
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #define INITGUID
20 #define WIN32_LEAN_AND_MEAN
21 #include <stdio.h>
22
23 #include <dplay8.h>
24 #include "wine/test.h"
25
26 static char *show_guid(const GUID *guid, char *buf)
27 {
28     sprintf(buf,
29         "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
30         guid->Data1, guid->Data2, guid->Data3,
31         guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
32         guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
33
34     return buf;
35 }
36
37 static IDirectPlay8Peer* peer = NULL;
38
39 static HRESULT WINAPI DirectPlayMessageHandler(PVOID context, DWORD message_id, PVOID buffer)
40 {
41     return S_OK;
42 }
43
44 static void test_init_dp(void)
45 {
46     HRESULT hr;
47
48     hr = CoInitialize(0);
49     ok(hr == S_OK, "CoInitialize failed with %x\n", hr);
50
51     hr = CoCreateInstance(&CLSID_DirectPlay8Peer, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectPlay8Peer, (void **)&peer);
52     ok(hr == S_OK, "CoCreateInstance failed with 0x%x\n", hr);
53
54     hr = IDirectPlay8Peer_Initialize(peer, NULL, DirectPlayMessageHandler, 0);
55     ok(hr == S_OK, "IDirectPlay8Peer_Initialize failed with %x\n", hr);
56 }
57
58 static void test_enum_service_providers(void)
59 {
60     DPN_SERVICE_PROVIDER_INFO *serv_prov_info;
61     DWORD items, size;
62     DWORD i;
63     HRESULT hr;
64     char guid[39] ;
65
66     size = 0;
67     items = 0;
68
69     hr = IDirectPlay8Peer_EnumServiceProviders(peer, NULL, NULL, NULL, &size, &items, 0);
70     todo_wine ok(hr == DPNERR_BUFFERTOOSMALL, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);
71     todo_wine ok(size != 0, "size is unexpectedly 0\n");
72
73     serv_prov_info = (DPN_SERVICE_PROVIDER_INFO*) HeapAlloc(GetProcessHeap(), 0, size);
74
75     hr = IDirectPlay8Peer_EnumServiceProviders(peer, NULL, NULL, serv_prov_info, &size, &items, 0);
76     todo_wine ok(hr == S_OK, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);
77     todo_wine ok(items != 0, "Found unexpectedly no service providers\n");
78
79     trace("number of items found: %d\n", items);
80
81     for (i=0;i<items;i++)
82     {
83         trace("Found Service Provider: %s\n", wine_dbgstr_w(serv_prov_info->pwszName));
84         trace("Found guid: %s\n", show_guid(&serv_prov_info->guid, guid));
85
86         serv_prov_info++;
87     }
88
89     serv_prov_info -= items; /* set pointer back */
90     ok(HeapFree(GetProcessHeap(), 0, serv_prov_info), "Failed freeing server provider info\n");
91
92     size = 0;
93     items = 0;
94
95     hr = IDirectPlay8Peer_EnumServiceProviders(peer, &CLSID_DP8SP_TCPIP, NULL, NULL, &size, &items, 0);
96     todo_wine ok(hr == DPNERR_BUFFERTOOSMALL, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);
97     todo_wine ok(size != 0, "size is unexpectedly 0\n");
98
99     serv_prov_info = (DPN_SERVICE_PROVIDER_INFO*) HeapAlloc(GetProcessHeap(), 0, size);
100
101     hr = IDirectPlay8Peer_EnumServiceProviders(peer, &CLSID_DP8SP_TCPIP, NULL, serv_prov_info, &size, &items, 0);
102     todo_wine ok(hr == S_OK, "IDirectPlay8Peer_EnumServiceProviders failed with %x\n", hr);
103     todo_wine ok(items != 0, "Found unexpectedly no adapter\n");
104
105     for (i=0;i<items;i++)
106     {
107         trace("Found adapter: %s\n", wine_dbgstr_w(serv_prov_info->pwszName));
108         trace("Found adapter guid: %s\n", show_guid(&serv_prov_info->guid, guid));
109
110         serv_prov_info++;
111     }
112
113     serv_prov_info -= items; /* set pointer back */
114     ok(HeapFree(GetProcessHeap(), 0, serv_prov_info), "Failed freeing server provider info\n");
115 }
116
117 static void test_cleanup_dp(void)
118 {
119     HRESULT hr;
120
121     hr = IDirectPlay8Peer_Close(peer, 0);
122     ok(hr == S_OK, "IDirectPlay8Peer_Close failed with %x\n", hr);
123
124     hr = IDirectPlay8Peer_Release(peer);
125     ok(hr == S_OK, "IDirectPlay8Peer_Release failed with %x\n", hr);
126
127     CoUninitialize();
128 }
129
130 START_TEST(peer)
131 {
132     test_init_dp();
133     test_enum_service_providers();
134     test_cleanup_dp();
135 }