4 * Copyright 2007 Huw Davies
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.
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.
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
33 #include "wine/test.h"
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"
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"
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"
56 "--------------1.5.0.6\r\n"
57 "Content-Type: text/plain; charset=\"us-ascii\"\r\n"
58 "Content-Transfer-Encoding: 7bit\r\n"
61 "--------------1.5.0.6--\r\n";
63 static void test_CreateVirtualStream(void)
68 hr = MimeOleCreateVirtualStream(&pstm);
69 ok(hr == S_OK, "ret %08x\n", hr);
71 IStream_Release(pstm);
74 static void test_CreateSecurity(void)
79 hr = MimeOleCreateSecurity(&sec);
80 ok(hr == S_OK, "ret %08x\n", hr);
82 IMimeSecurity_Release(sec);
85 static void test_CreateBody(void)
89 HBODY handle = (void *)0xdeadbeef;
94 ULONG count, found_param, i;
95 MIMEPARAMINFO *param_info;
96 IMimeAllocator *alloc;
99 hr = CoCreateInstance(&CLSID_IMimeBody, NULL, CLSCTX_INPROC_SERVER, &IID_IMimeBody, (void**)&body);
100 ok(hr == S_OK, "ret %08x\n", hr);
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);
106 hr = CreateStreamOnHGlobal(NULL, TRUE, &in);
107 ok(hr == S_OK, "ret %08x\n", hr);
108 IStream_Write(in, msg1, sizeof(msg1) - 1, NULL);
110 IStream_Seek(in, off, STREAM_SEEK_SET, NULL);
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);
116 hr = IMimeBody_GetCurrentEncoding(body, &enc);
117 ok(hr == S_OK, "ret %08x\n", hr);
118 ok(enc == IET_7BIT, "encoding %d\n", enc);
120 hr = IMimeBody_Load(body, in);
121 ok(hr == S_OK, "ret %08x\n", hr);
123 IStream_Seek(in, off, STREAM_SEEK_CUR, &pos);
124 ok(pos.u.LowPart == 359, "pos %u\n", pos.u.LowPart);
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);
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");
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);
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);
150 hr = MimeOleGetAllocator(&alloc);
151 ok(hr == S_OK, "ret %08x\n", hr);
153 hr = IMimeBody_GetParameters(body, "nothere", &count, ¶m_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);
158 hr = IMimeBody_GetParameters(body, "bar", &count, ¶m_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);
163 hr = IMimeBody_GetParameters(body, "Content-Type", &count, ¶m_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);
170 for(i = 0; i < count; i++)
172 if(!strcmp(param_info[i].pszName, "morestuff"))
175 ok(!strcmp(param_info[i].pszData, "so\\me\"thing\""),
176 "got %s\n", param_info[i].pszData);
178 else if(!strcmp(param_info[i].pszName, "stuff"))
181 ok(!strcmp(param_info[i].pszData, "du;nno"),
182 "got %s\n", param_info[i].pszData);
185 ok(found_param == 2, "matched %d params\n", found_param);
187 hr = IMimeAllocator_FreeParamInfoArray(alloc, count, param_info, TRUE);
188 ok(hr == S_OK, "ret %08x\n", hr);
189 IMimeAllocator_Release(alloc);
192 IMimeBody_Release(body);
195 static void test_Allocator(void)
198 IMimeAllocator *alloc;
200 hr = MimeOleGetAllocator(&alloc);
201 ok(hr == S_OK, "ret %08x\n", hr);
202 IMimeAllocator_Release(alloc);
208 test_CreateVirtualStream();
209 test_CreateSecurity();