dinput: Silence incorrect warning and move it to a valid place.
[wine] / dlls / inetcomm / tests / mimeole.c
1 /*
2  * MimeOle tests
3  *
4  * Copyright 2007 Huw Davies
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #define COBJMACROS
22
23 #include "windows.h"
24 #include "ole2.h"
25 #include "ocidl.h"
26
27 #include "initguid.h"
28 #include "mimeole.h"
29
30 #include <stdio.h>
31 #include <assert.h>
32
33 #include "wine/test.h"
34
35 static char msg1[] =
36     "MIME-Version: 1.0\r\n"
37     "Content-Type: multipart/mixed;\r\n"
38     " boundary=\"------------1.5.0.6\";\r\n"
39     " stuff=\"du;nno\";\r\n"
40     " morestuff=\"so\\\\me\\\"thing\\\"\"\r\n"
41     "foo: bar\r\n"
42     "From: Huw Davies <huw@codeweavers.com>\r\n"
43     "From: Me <xxx@codeweavers.com>\r\n"
44     "To: wine-patches <wine-patches@winehq.org>\r\n"
45     "Cc: Huw Davies <huw@codeweavers.com>,\r\n"
46     "    \"Fred Bloggs\"   <fred@bloggs.com>\r\n"
47     "foo: baz\r\n"
48     "bar: fum\r\n"
49     "\r\n"
50     "This is a multi-part message in MIME format.\r\n"
51     "--------------1.5.0.6\r\n"
52     "Content-Type: text/plain; format=fixed; charset=UTF-8\r\n"
53     "Content-Transfer-Encoding: 8bit\r\n"
54     "\r\n"
55     "Stuff\r\n"
56     "--------------1.5.0.6\r\n"
57     "Content-Type: text/plain; charset=\"us-ascii\"\r\n"
58     "Content-Transfer-Encoding: 7bit\r\n"
59     "\r\n"
60     "More stuff\r\n"
61     "--------------1.5.0.6--\r\n";
62
63 static void test_CreateVirtualStream(void)
64 {
65     HRESULT hr;
66     IStream *pstm;
67
68     hr = MimeOleCreateVirtualStream(&pstm);
69     ok(hr == S_OK, "ret %08x\n", hr);
70
71     IStream_Release(pstm);
72 }
73
74 static void test_CreateSecurity(void)
75 {
76     HRESULT hr;
77     IMimeSecurity *sec;
78
79     hr = MimeOleCreateSecurity(&sec);
80     ok(hr == S_OK, "ret %08x\n", hr);
81
82     IMimeSecurity_Release(sec);
83 }
84
85 static void test_CreateBody(void)
86 {
87     HRESULT hr;
88     IMimeBody *body;
89     HBODY handle = (void *)0xdeadbeef;
90     IStream *in;
91     LARGE_INTEGER off;
92     ULARGE_INTEGER pos;
93     ENCODINGTYPE enc;
94     ULONG count, found_param, i;
95     MIMEPARAMINFO *param_info;
96     IMimeAllocator *alloc;
97     BODYOFFSETS offsets;
98
99     hr = CoCreateInstance(&CLSID_IMimeBody, NULL, CLSCTX_INPROC_SERVER, &IID_IMimeBody, (void**)&body);
100     ok(hr == S_OK, "ret %08x\n", hr);
101
102     hr = IMimeBody_GetHandle(body, &handle);
103     ok(hr == MIME_E_NO_DATA, "ret %08x\n", hr);
104     ok(handle == NULL, "handle %p\n", handle);
105
106     hr = CreateStreamOnHGlobal(NULL, TRUE, &in);
107     ok(hr == S_OK, "ret %08x\n", hr);
108     IStream_Write(in, msg1, sizeof(msg1) - 1, NULL);
109     off.QuadPart = 0;
110     IStream_Seek(in, off, STREAM_SEEK_SET, NULL);
111
112     /* Need to call InitNew before Load otherwise Load crashes with native inetcomm */
113     hr = IMimeBody_InitNew(body);
114     ok(hr == S_OK, "ret %08x\n", hr);
115
116     hr = IMimeBody_GetCurrentEncoding(body, &enc);
117     ok(hr == S_OK, "ret %08x\n", hr);
118     ok(enc == IET_7BIT, "encoding %d\n", enc);
119
120     hr = IMimeBody_Load(body, in);
121     ok(hr == S_OK, "ret %08x\n", hr);
122     off.QuadPart = 0;
123     IStream_Seek(in, off, STREAM_SEEK_CUR, &pos);
124     ok(pos.u.LowPart == 359, "pos %u\n", pos.u.LowPart);
125
126     hr = IMimeBody_IsContentType(body, "multipart", "mixed");
127     ok(hr == S_OK, "ret %08x\n", hr);
128     hr = IMimeBody_IsContentType(body, "text", "plain");
129     ok(hr == S_FALSE, "ret %08x\n", hr);
130     hr = IMimeBody_IsContentType(body, NULL, "mixed");
131     ok(hr == S_OK, "ret %08x\n", hr);
132
133     hr = IMimeBody_SetData(body, IET_8BIT, "text", "plain", &IID_IStream, in);
134     ok(hr == S_OK, "ret %08x\n", hr);
135     hr = IMimeBody_IsContentType(body, "text", "plain");
136     todo_wine
137         ok(hr == S_OK, "ret %08x\n", hr);
138     hr = IMimeBody_GetCurrentEncoding(body, &enc);
139     ok(hr == S_OK, "ret %08x\n", hr);
140     ok(enc == IET_8BIT, "encoding %d\n", enc);
141
142     memset(&offsets, 0xcc, sizeof(offsets));
143     hr = IMimeBody_GetOffsets(body, &offsets);
144     ok(hr == MIME_E_NO_DATA, "ret %08x\n", hr);
145     ok(offsets.cbBoundaryStart == 0, "got %d\n", offsets.cbBoundaryStart);
146     ok(offsets.cbHeaderStart == 0, "got %d\n", offsets.cbHeaderStart);
147     ok(offsets.cbBodyStart == 0, "got %d\n", offsets.cbBodyStart);
148     ok(offsets.cbBodyEnd == 0, "got %d\n", offsets.cbBodyEnd);
149
150     hr = MimeOleGetAllocator(&alloc);
151     ok(hr == S_OK, "ret %08x\n", hr);
152
153     hr = IMimeBody_GetParameters(body, "nothere", &count, &param_info);
154     ok(hr == MIME_E_NOT_FOUND, "ret %08x\n", hr);
155     ok(count == 0, "got %d\n", count);
156     ok(!param_info, "got %p\n", param_info);
157
158     hr = IMimeBody_GetParameters(body, "bar", &count, &param_info);
159     ok(hr == S_OK, "ret %08x\n", hr);
160     ok(count == 0, "got %d\n", count);
161     ok(!param_info, "got %p\n", param_info);
162
163     hr = IMimeBody_GetParameters(body, "Content-Type", &count, &param_info);
164     ok(hr == S_OK, "ret %08x\n", hr);
165     todo_wine  /* native adds a charset parameter */
166         ok(count == 4, "got %d\n", count);
167     ok(param_info != NULL, "got %p\n", param_info);
168
169     found_param = 0;
170     for(i = 0; i < count; i++)
171     {
172         if(!strcmp(param_info[i].pszName, "morestuff"))
173         {
174             found_param++;
175             ok(!strcmp(param_info[i].pszData, "so\\me\"thing\""),
176                "got %s\n", param_info[i].pszData);
177         }
178         else if(!strcmp(param_info[i].pszName, "stuff"))
179         {
180             found_param++;
181             ok(!strcmp(param_info[i].pszData, "du;nno"),
182                "got %s\n", param_info[i].pszData);
183         }
184     }
185     ok(found_param == 2, "matched %d params\n", found_param);
186
187     hr = IMimeAllocator_FreeParamInfoArray(alloc, count, param_info, TRUE);
188     ok(hr == S_OK, "ret %08x\n", hr);
189     IMimeAllocator_Release(alloc);
190
191     IStream_Release(in);
192     IMimeBody_Release(body);
193 }
194
195 static void test_Allocator(void)
196 {
197     HRESULT hr;
198     IMimeAllocator *alloc;
199
200     hr = MimeOleGetAllocator(&alloc);
201     ok(hr == S_OK, "ret %08x\n", hr);
202     IMimeAllocator_Release(alloc);
203 }
204
205 START_TEST(mimeole)
206 {
207     OleInitialize(NULL);
208     test_CreateVirtualStream();
209     test_CreateSecurity();
210     test_CreateBody();
211     test_Allocator();
212     OleUninitialize();
213 }