po: Update Japanese translation.
[wine.git] / dlls / quartz / tests / memallocator.c
blob164f3af47f40e3d8fdf88f8807769b7ba9aa4b32
1 /*
2 * Memory allocator unit tests
4 * Copyright (C) 2005 Christian Costa
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
21 #define COBJMACROS
22 #include "dshow.h"
23 #include "wine/test.h"
25 static IMemAllocator *create_allocator(void)
27 IMemAllocator *allocator = NULL;
28 HRESULT hr = CoCreateInstance(&CLSID_MemoryAllocator, NULL, CLSCTX_INPROC_SERVER,
29 &IID_IMemAllocator, (void **)&allocator);
30 ok(hr == S_OK, "Got hr %#x.\n", hr);
31 return allocator;
34 static void test_properties(void)
36 ALLOCATOR_PROPERTIES req_props = {0}, ret_props;
37 IMemAllocator *allocator = create_allocator();
38 IMediaSample *sample;
39 LONG size, ret_size;
40 unsigned int i;
41 HRESULT hr;
43 static const ALLOCATOR_PROPERTIES tests[] =
45 {0, 0, 1, 0},
46 {1, 0, 1, 0},
47 {1, 1, 1, 0},
48 {1, 1, 4, 0},
49 {2, 1, 1, 0},
50 {1, 2, 4, 0},
51 {1, 1, 16, 0},
52 {1, 16, 16, 0},
53 {1, 17, 16, 0},
54 {1, 32, 16, 0},
55 {1, 1, 16, 1},
56 {1, 15, 16, 1},
57 {1, 16, 16, 1},
58 {1, 17, 16, 1},
59 {1, 0, 16, 16},
60 {1, 1, 16, 16},
61 {1, 16, 16, 16},
64 memset(&ret_props, 0xcc, sizeof(ret_props));
65 hr = IMemAllocator_GetProperties(allocator, &ret_props);
66 ok(hr == S_OK, "Got hr %#x.\n", hr);
67 ok(!ret_props.cBuffers, "Got %d buffers.\n", ret_props.cBuffers);
68 ok(!ret_props.cbBuffer, "Got size %d.\n", ret_props.cbBuffer);
69 ok(!ret_props.cbAlign, "Got align %d.\n", ret_props.cbAlign);
70 ok(!ret_props.cbPrefix, "Got prefix %d.\n", ret_props.cbPrefix);
72 hr = IMemAllocator_SetProperties(allocator, &req_props, &ret_props);
73 ok(hr == VFW_E_BADALIGN, "Got hr %#x.\n", hr);
75 for (i = 0; i < ARRAY_SIZE(tests); i++)
77 req_props = tests[i];
78 hr = IMemAllocator_SetProperties(allocator, &req_props, &ret_props);
79 ok(hr == S_OK, "Test %u: Got hr %#x.\n", i, hr);
80 ok(!memcmp(&req_props, &tests[i], sizeof(req_props)), "Test %u: Requested props should not be changed.\n", i);
81 ok(ret_props.cBuffers == req_props.cBuffers, "Test %u: Got %d buffers.\n", i, ret_props.cBuffers);
82 ok(ret_props.cbBuffer >= req_props.cbBuffer, "Test %u: Got size %d.\n", i, ret_props.cbBuffer);
83 ok(ret_props.cbAlign == req_props.cbAlign, "Test %u: Got alignment %d.\n", i, ret_props.cbAlign);
84 ok(ret_props.cbPrefix == req_props.cbPrefix, "Test %u: Got prefix %d.\n", i, ret_props.cbPrefix);
85 ret_size = ret_props.cbBuffer;
87 hr = IMemAllocator_GetProperties(allocator, &ret_props);
88 ok(hr == S_OK, "Test %u: Got hr %#x.\n", i, hr);
89 ok(ret_props.cBuffers == req_props.cBuffers, "Test %u: Got %d buffers.\n", i, ret_props.cBuffers);
90 ok(ret_props.cbBuffer == ret_size, "Test %u: Got size %d.\n", i, ret_props.cbBuffer);
91 ok(ret_props.cbAlign == req_props.cbAlign, "Test %u: Got alignment %d.\n", i, ret_props.cbAlign);
92 ok(ret_props.cbPrefix == req_props.cbPrefix, "Test %u: Got prefix %d.\n", i, ret_props.cbPrefix);
94 hr = IMemAllocator_Commit(allocator);
95 if (!req_props.cbBuffer)
97 ok(hr == VFW_E_SIZENOTSET, "Test %u: Got hr %#x.\n", i, hr);
98 continue;
100 ok(hr == S_OK, "Test %u: Got hr %#x.\n", i, hr);
102 hr = IMemAllocator_SetProperties(allocator, &req_props, &ret_props);
103 ok(hr == VFW_E_ALREADY_COMMITTED, "Test %u: Got hr %#x.\n", i, hr);
105 hr = IMemAllocator_GetBuffer(allocator, &sample, NULL, NULL, 0);
106 ok(hr == S_OK, "Test %u: Got hr %#x.\n", i, hr);
108 size = IMediaSample_GetSize(sample);
109 ok(size == ret_size, "Test %u: Got size %d.\n", i, size);
111 hr = IMemAllocator_Decommit(allocator);
112 ok(hr == S_OK, "Test %u: Got hr %#x.\n", i, hr);
114 hr = IMemAllocator_SetProperties(allocator, &req_props, &ret_props);
115 ok(hr == VFW_E_BUFFERS_OUTSTANDING, "Test %u: Got hr %#x.\n", i, hr);
117 hr = IMediaSample_Release(sample);
118 ok(hr == S_OK, "Test %u: Got hr %#x.\n", i, hr);
121 IMemAllocator_Release(allocator);
124 static void test_commit(void)
126 ALLOCATOR_PROPERTIES req_props = {2, 65536, 1, 0}, ret_props;
127 IMemAllocator *allocator = create_allocator();
128 IMediaSample *sample, *sample2;
129 HRESULT hr;
130 BYTE *data;
132 hr = IMemAllocator_SetProperties(allocator, &req_props, &ret_props);
133 ok(hr == S_OK, "Got hr %#x.\n", hr);
135 hr = IMemAllocator_GetBuffer(allocator, &sample, NULL, NULL, 0);
136 ok(hr == VFW_E_NOT_COMMITTED, "Got hr %#x.\n", hr);
138 hr = IMemAllocator_Commit(allocator);
139 ok(hr == S_OK, "Got hr %#x.\n", hr);
140 hr = IMemAllocator_Commit(allocator);
141 ok(hr == S_OK, "Got hr %#x.\n", hr);
143 hr = IMemAllocator_GetBuffer(allocator, &sample, NULL, NULL, 0);
144 ok(hr == S_OK, "Got hr %#x.\n", hr);
145 IMediaSample_Release(sample);
147 hr = IMemAllocator_Decommit(allocator);
148 ok(hr == S_OK, "Got hr %#x.\n", hr);
149 hr = IMemAllocator_Decommit(allocator);
150 ok(hr == S_OK, "Got hr %#x.\n", hr);
152 /* Extant samples remain valid even after Decommit() is called. */
153 hr = IMemAllocator_Commit(allocator);
154 ok(hr == S_OK, "Got hr %#x.\n", hr);
156 hr = IMemAllocator_GetBuffer(allocator, &sample, NULL, NULL, 0);
157 ok(hr == S_OK, "Got hr %#x.\n", hr);
159 hr = IMediaSample_GetPointer(sample, &data);
160 ok(hr == S_OK, "Got hr %#x.\n", hr);
162 hr = IMemAllocator_Decommit(allocator);
163 ok(hr == S_OK, "Got hr %#x.\n", hr);
165 memset(data, 0xcc, 65536);
167 hr = IMemAllocator_GetBuffer(allocator, &sample2, NULL, NULL, 0);
168 ok(hr == VFW_E_NOT_COMMITTED, "Got hr %#x.\n", hr);
170 IMediaSample_Release(sample);
171 IMemAllocator_Release(allocator);
174 static void test_sample_time(void)
176 ALLOCATOR_PROPERTIES req_props = {1, 65536, 1, 0}, ret_props;
177 IMemAllocator *allocator = create_allocator();
178 AM_SAMPLE2_PROPERTIES props = {sizeof(props)};
179 REFERENCE_TIME start, end;
180 IMediaSample2 *sample2;
181 IMediaSample *sample;
182 HRESULT hr;
184 hr = IMemAllocator_SetProperties(allocator, &req_props, &ret_props);
185 ok(hr == S_OK, "Got hr %#x.\n", hr);
186 hr = IMemAllocator_Commit(allocator);
187 ok(hr == S_OK, "Got hr %#x.\n", hr);
188 hr = IMemAllocator_GetBuffer(allocator, &sample, NULL, NULL, 0);
189 ok(hr == S_OK, "Got hr %#x.\n", hr);
190 hr = IMediaSample_QueryInterface(sample, &IID_IMediaSample2, (void **)&sample2);
191 ok(hr == S_OK, "Got hr %#x.\n", hr);
193 start = 0xdeadbeef;
194 end = 0xdeadf00d;
195 hr = IMediaSample_GetTime(sample, &start, &end);
196 ok(hr == VFW_E_SAMPLE_TIME_NOT_SET, "Got hr %#x.\n", hr);
197 ok(start == 0xdeadbeef, "Got start %s.\n", wine_dbgstr_longlong(start));
198 ok(end == 0xdeadf00d, "Got end %s.\n", wine_dbgstr_longlong(end));
200 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
201 ok(hr == S_OK, "Got hr %#x.\n", hr);
202 ok(!props.dwSampleFlags, "Got flags %#x.\n", props.dwSampleFlags);
204 hr = IMediaSample_SetTime(sample, NULL, NULL);
205 ok(hr == S_OK, "Got hr %#x.\n", hr);
207 hr = IMediaSample_GetTime(sample, &start, &end);
208 ok(hr == VFW_E_SAMPLE_TIME_NOT_SET, "Got hr %#x.\n", hr);
210 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
211 ok(hr == S_OK, "Got hr %#x.\n", hr);
212 ok(!props.dwSampleFlags, "Got flags %#x.\n", props.dwSampleFlags);
214 start = 0x123;
215 hr = IMediaSample_SetTime(sample, &start, NULL);
216 ok(hr == S_OK, "Got hr %#x.\n", hr);
218 start = end = 0;
219 hr = IMediaSample_GetTime(sample, &start, &end);
220 ok(hr == VFW_S_NO_STOP_TIME, "Got hr %#x.\n", hr);
221 ok(start == 0x123, "Got start %s.\n", wine_dbgstr_longlong(start));
222 ok(end == 0x124, "Got end %s.\n", wine_dbgstr_longlong(end));
224 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
225 ok(hr == S_OK, "Got hr %#x.\n", hr);
226 ok(props.dwSampleFlags == AM_SAMPLE_TIMEVALID, "Got flags %#x.\n", props.dwSampleFlags);
227 ok(props.tStart == 0x123, "Got start %s.\n", wine_dbgstr_longlong(props.tStart));
229 hr = IMediaSample_SetTime(sample, NULL, NULL);
230 ok(hr == S_OK, "Got hr %#x.\n", hr);
232 hr = IMediaSample_GetTime(sample, &start, &end);
233 ok(hr == VFW_E_SAMPLE_TIME_NOT_SET, "Got hr %#x.\n", hr);
235 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
236 ok(hr == S_OK, "Got hr %#x.\n", hr);
237 ok(!props.dwSampleFlags, "Got flags %#x.\n", props.dwSampleFlags);
239 end = 0x321;
240 hr = IMediaSample_SetTime(sample, NULL, &end);
241 ok(hr == S_OK, "Got hr %#x.\n", hr);
243 hr = IMediaSample_GetTime(sample, &start, &end);
244 ok(hr == VFW_E_SAMPLE_TIME_NOT_SET, "Got hr %#x.\n", hr);
246 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
247 ok(hr == S_OK, "Got hr %#x.\n", hr);
248 ok(!props.dwSampleFlags, "Got flags %#x.\n", props.dwSampleFlags);
250 start = 0x123;
251 end = 0x321;
252 hr = IMediaSample_SetTime(sample, &start, &end);
253 ok(hr == S_OK, "Got hr %#x.\n", hr);
255 start = end = 0;
256 hr = IMediaSample_GetTime(sample, &start, &end);
257 ok(hr == S_OK, "Got hr %#x.\n", hr);
258 ok(start == 0x123, "Got start %s.\n", wine_dbgstr_longlong(start));
259 ok(end == 0x321, "Got end %s.\n", wine_dbgstr_longlong(end));
261 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
262 ok(hr == S_OK, "Got hr %#x.\n", hr);
263 ok(props.dwSampleFlags == (AM_SAMPLE_TIMEVALID | AM_SAMPLE_STOPVALID),
264 "Got flags %#x.\n", props.dwSampleFlags);
265 ok(props.tStart == 0x123, "Got start %s.\n", wine_dbgstr_longlong(props.tStart));
266 ok(props.tStop == 0x321, "Got end %s.\n", wine_dbgstr_longlong(props.tStop));
268 props.dwSampleFlags = 0;
269 hr = IMediaSample2_SetProperties(sample2, sizeof(props), (BYTE *)&props);
270 ok(hr == S_OK, "Got hr %#x.\n", hr);
272 hr = IMediaSample_GetTime(sample, &start, &end);
273 ok(hr == VFW_E_SAMPLE_TIME_NOT_SET, "Got hr %#x.\n", hr);
275 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
276 ok(hr == S_OK, "Got hr %#x.\n", hr);
277 ok(!props.dwSampleFlags, "Got flags %#x.\n", props.dwSampleFlags);
279 props.dwSampleFlags = AM_SAMPLE_TIMEVALID;
280 props.tStart = 0x123;
281 hr = IMediaSample2_SetProperties(sample2, sizeof(props), (BYTE *)&props);
282 ok(hr == S_OK, "Got hr %#x.\n", hr);
284 start = end = 0;
285 hr = IMediaSample_GetTime(sample, &start, &end);
286 ok(hr == VFW_S_NO_STOP_TIME, "Got hr %#x.\n", hr);
287 ok(start == 0x123, "Got start %s.\n", wine_dbgstr_longlong(start));
288 ok(end == 0x124, "Got end %s.\n", wine_dbgstr_longlong(end));
290 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
291 ok(hr == S_OK, "Got hr %#x.\n", hr);
292 ok(props.dwSampleFlags == AM_SAMPLE_TIMEVALID, "Got flags %#x.\n", props.dwSampleFlags);
293 ok(props.tStart == 0x123, "Got start %s.\n", wine_dbgstr_longlong(props.tStart));
295 props.dwSampleFlags = AM_SAMPLE_TIMEVALID | AM_SAMPLE_STOPVALID;
296 props.tStart = 0x1234;
297 props.tStop = 0x4321;
298 hr = IMediaSample2_SetProperties(sample2, sizeof(props), (BYTE *)&props);
299 ok(hr == S_OK, "Got hr %#x.\n", hr);
301 start = end = 0;
302 hr = IMediaSample_GetTime(sample, &start, &end);
303 ok(hr == S_OK, "Got hr %#x.\n", hr);
304 ok(start == 0x1234, "Got start %s.\n", wine_dbgstr_longlong(start));
305 ok(end == 0x4321, "Got end %s.\n", wine_dbgstr_longlong(end));
307 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
308 ok(hr == S_OK, "Got hr %#x.\n", hr);
309 ok(props.dwSampleFlags == (AM_SAMPLE_TIMEVALID | AM_SAMPLE_STOPVALID),
310 "Got flags %#x.\n", props.dwSampleFlags);
311 ok(props.tStart == 0x1234, "Got start %s.\n", wine_dbgstr_longlong(props.tStart));
312 ok(props.tStop == 0x4321, "Got end %s.\n", wine_dbgstr_longlong(props.tStop));
314 IMediaSample2_Release(sample2);
315 IMediaSample_Release(sample);
317 start = 0x123;
318 end = 0x321;
319 hr = IMemAllocator_GetBuffer(allocator, &sample, &start, &end, 0);
320 ok(hr == S_OK, "Got hr %#x.\n", hr);
321 hr = IMediaSample_QueryInterface(sample, &IID_IMediaSample2, (void **)&sample2);
322 ok(hr == S_OK, "Got hr %#x.\n", hr);
324 start = 0xdeadbeef;
325 end = 0xdeadf00d;
326 hr = IMediaSample_GetTime(sample, &start, &end);
327 ok(hr == VFW_E_SAMPLE_TIME_NOT_SET, "Got hr %#x.\n", hr);
328 ok(start == 0xdeadbeef, "Got start %s.\n", wine_dbgstr_longlong(start));
329 ok(end == 0xdeadf00d, "Got end %s.\n", wine_dbgstr_longlong(end));
331 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
332 ok(hr == S_OK, "Got hr %#x.\n", hr);
333 ok(!props.dwSampleFlags, "Got flags %#x.\n", props.dwSampleFlags);
335 start = 0x123;
336 end = 0x321;
337 hr = IMediaSample_SetMediaTime(sample, &start, &end);
338 ok(hr == S_OK, "Got hr %#x.\n", hr);
340 hr = IMediaSample_GetTime(sample, &start, &end);
341 ok(hr == VFW_E_SAMPLE_TIME_NOT_SET, "Got hr %#x.\n", hr);
343 IMediaSample2_Release(sample2);
344 IMediaSample_Release(sample);
345 IMemAllocator_Release(allocator);
348 static void test_media_time(void)
350 ALLOCATOR_PROPERTIES req_props = {1, 65536, 1, 0}, ret_props;
351 IMemAllocator *allocator = create_allocator();
352 AM_SAMPLE2_PROPERTIES props = {sizeof(props)};
353 IMediaSample *sample;
354 LONGLONG start, end;
355 HRESULT hr;
357 hr = IMemAllocator_SetProperties(allocator, &req_props, &ret_props);
358 ok(hr == S_OK, "Got hr %#x.\n", hr);
359 hr = IMemAllocator_Commit(allocator);
360 ok(hr == S_OK, "Got hr %#x.\n", hr);
361 hr = IMemAllocator_GetBuffer(allocator, &sample, NULL, NULL, 0);
362 ok(hr == S_OK, "Got hr %#x.\n", hr);
364 start = 0xdeadbeef;
365 end = 0xdeadf00d;
366 hr = IMediaSample_GetMediaTime(sample, &start, &end);
367 ok(hr == VFW_E_MEDIA_TIME_NOT_SET, "Got hr %#x.\n", hr);
368 ok(start == 0xdeadbeef, "Got start %s.\n", wine_dbgstr_longlong(start));
369 ok(end == 0xdeadf00d, "Got end %s.\n", wine_dbgstr_longlong(end));
371 hr = IMediaSample_SetMediaTime(sample, NULL, NULL);
372 ok(hr == S_OK, "Got hr %#x.\n", hr);
374 hr = IMediaSample_GetMediaTime(sample, &start, &end);
375 ok(hr == VFW_E_MEDIA_TIME_NOT_SET, "Got hr %#x.\n", hr);
377 /* This crashes on quartz.dll < 6.6. */
378 if (0)
380 start = 0x123;
381 hr = IMediaSample_SetMediaTime(sample, &start, NULL);
382 ok(hr == E_POINTER, "Got hr %#x.\n", hr);
385 end = 0x321;
386 hr = IMediaSample_SetMediaTime(sample, NULL, &end);
387 ok(hr == S_OK, "Got hr %#x.\n", hr);
389 hr = IMediaSample_GetMediaTime(sample, &start, &end);
390 ok(hr == VFW_E_MEDIA_TIME_NOT_SET, "Got hr %#x.\n", hr);
392 start = 0x123;
393 end = 0x321;
394 hr = IMediaSample_SetMediaTime(sample, &start, &end);
395 ok(hr == S_OK, "Got hr %#x.\n", hr);
397 start = end = 0;
398 hr = IMediaSample_GetMediaTime(sample, &start, &end);
399 ok(hr == S_OK, "Got hr %#x.\n", hr);
400 ok(start == 0x123, "Got start %s.\n", wine_dbgstr_longlong(start));
401 ok(end == 0x321, "Got end %s.\n", wine_dbgstr_longlong(end));
403 IMediaSample_Release(sample);
405 start = 0x123;
406 end = 0x321;
407 hr = IMemAllocator_GetBuffer(allocator, &sample, &start, &end, 0);
408 ok(hr == S_OK, "Got hr %#x.\n", hr);
410 start = 0xdeadbeef;
411 end = 0xdeadf00d;
412 hr = IMediaSample_GetMediaTime(sample, &start, &end);
413 ok(hr == VFW_E_MEDIA_TIME_NOT_SET, "Got hr %#x.\n", hr);
414 ok(start == 0xdeadbeef, "Got start %s.\n", wine_dbgstr_longlong(start));
415 ok(end == 0xdeadf00d, "Got end %s.\n", wine_dbgstr_longlong(end));
417 start = 0x123;
418 end = 0x321;
419 hr = IMediaSample_SetTime(sample, &start, &end);
420 ok(hr == S_OK, "Got hr %#x.\n", hr);
422 hr = IMediaSample_GetMediaTime(sample, &start, &end);
423 ok(hr == VFW_E_MEDIA_TIME_NOT_SET, "Got hr %#x.\n", hr);
425 start = 0x123;
426 end = 0x321;
427 hr = IMediaSample_SetMediaTime(sample, &start, &end);
428 ok(hr == S_OK, "Got hr %#x.\n", hr);
430 IMediaSample_Release(sample);
432 hr = IMemAllocator_GetBuffer(allocator, &sample, NULL, NULL, 0);
433 ok(hr == S_OK, "Got hr %#x.\n", hr);
435 hr = IMediaSample_GetMediaTime(sample, &start, &end);
436 ok(hr == VFW_E_MEDIA_TIME_NOT_SET, "Got hr %#x.\n", hr);
438 IMediaSample_Release(sample);
439 IMemAllocator_Release(allocator);
442 static void test_sample_properties(void)
444 ALLOCATOR_PROPERTIES req_props = {1, 65536, 1, 0}, ret_props;
445 IMemAllocator *allocator = create_allocator();
446 AM_SAMPLE2_PROPERTIES props = {sizeof(props)};
447 AM_MEDIA_TYPE *mt, expect_mt;
448 IMediaSample2 *sample2;
449 IMediaSample *sample;
450 HRESULT hr;
451 BYTE *data;
452 LONG len;
454 memset(&expect_mt, 0xcc, sizeof(expect_mt));
455 expect_mt.pUnk = NULL;
456 expect_mt.cbFormat = 0;
457 expect_mt.pbFormat = NULL;
459 hr = IMemAllocator_SetProperties(allocator, &req_props, &ret_props);
460 ok(hr == S_OK, "Got hr %#x.\n", hr);
461 hr = IMemAllocator_Commit(allocator);
462 ok(hr == S_OK, "Got hr %#x.\n", hr);
463 hr = IMemAllocator_GetBuffer(allocator, &sample, NULL, NULL, 0);
464 ok(hr == S_OK, "Got hr %#x.\n", hr);
465 hr = IMediaSample_QueryInterface(sample, &IID_IMediaSample2, (void **)&sample2);
466 ok(hr == S_OK, "Got hr %#x.\n", hr);
468 hr = IMediaSample_GetPointer(sample, &data);
469 ok(hr == S_OK, "Got hr %#x.\n", hr);
471 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
472 ok(hr == S_OK, "Got hr %#x.\n", hr);
473 ok(!props.dwTypeSpecificFlags, "Got type-specific flags %#x.\n", props.dwTypeSpecificFlags);
474 ok(!props.dwSampleFlags, "Got flags %#x.\n", props.dwSampleFlags);
475 ok(props.lActual == 65536, "Got actual length %d.\n", props.lActual);
476 ok(!props.tStart, "Got sample start %s.\n", wine_dbgstr_longlong(props.tStart));
477 ok(!props.dwStreamId, "Got stream ID %#x.\n", props.dwStreamId);
478 ok(!props.pMediaType, "Got media type %p.\n", props.pMediaType);
479 ok(props.pbBuffer == data, "Expected pointer %p, got %p.\n", data, props.pbBuffer);
480 ok(props.cbBuffer == 65536, "Got buffer length %d.\n", props.cbBuffer);
482 /* media type */
484 mt = (AM_MEDIA_TYPE *)0xdeadbeef;
485 hr = IMediaSample_GetMediaType(sample, &mt);
486 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
487 ok(!mt, "Got media type %p.\n", mt);
489 hr = IMediaSample_SetMediaType(sample, NULL);
490 ok(hr == S_OK, "Got hr %#x.\n", hr);
492 mt = (AM_MEDIA_TYPE *)0xdeadbeef;
493 hr = IMediaSample_GetMediaType(sample, &mt);
494 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
495 ok(!mt, "Got media type %p.\n", mt);
497 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
498 ok(hr == S_OK, "Got hr %#x.\n", hr);
499 ok(!props.dwSampleFlags, "Got flags %#x.\n", props.dwSampleFlags);
500 ok(!props.pMediaType, "Got media type %p.\n", props.pMediaType);
502 hr = IMediaSample_SetMediaType(sample, &expect_mt);
503 ok(hr == S_OK, "Got hr %#x.\n", hr);
505 hr = IMediaSample_GetMediaType(sample, &mt);
506 ok(hr == S_OK, "Got hr %#x.\n", hr);
507 ok(!memcmp(mt, &expect_mt, sizeof(AM_MEDIA_TYPE)), "Media types didn't match.\n");
508 CoTaskMemFree(mt);
510 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
511 ok(hr == S_OK, "Got hr %#x.\n", hr);
512 ok(props.dwSampleFlags == AM_SAMPLE_TYPECHANGED, "Got flags %#x.\n", props.dwSampleFlags);
513 ok(!memcmp(props.pMediaType, &expect_mt, sizeof(AM_MEDIA_TYPE)), "Media types didn't match.\n");
515 hr = IMediaSample_SetMediaType(sample, NULL);
516 ok(hr == S_OK, "Got hr %#x.\n", hr);
518 mt = (AM_MEDIA_TYPE *)0xdeadbeef;
519 hr = IMediaSample_GetMediaType(sample, &mt);
520 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
521 ok(!mt, "Got media type %p.\n", mt);
523 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
524 ok(hr == S_OK, "Got hr %#x.\n", hr);
525 ok(!props.dwSampleFlags, "Got flags %#x.\n", props.dwSampleFlags);
526 ok(!props.pMediaType, "Got media type %p.\n", props.pMediaType);
528 /* actual length */
530 len = IMediaSample_GetActualDataLength(sample);
531 ok(len == 65536, "Got length %d.\n", len);
533 hr = IMediaSample_SetActualDataLength(sample, 65537);
534 ok(hr == VFW_E_BUFFER_OVERFLOW, "Got hr %#x.\n", hr);
535 hr = IMediaSample_SetActualDataLength(sample, -1);
536 ok(hr == VFW_E_BUFFER_OVERFLOW || broken(hr == S_OK), "Got hr %#x.\n", hr);
537 hr = IMediaSample_SetActualDataLength(sample, 65536);
538 ok(hr == S_OK, "Got hr %#x.\n", hr);
539 hr = IMediaSample_SetActualDataLength(sample, 0);
540 ok(hr == S_OK, "Got hr %#x.\n", hr);
542 len = IMediaSample_GetActualDataLength(sample);
543 ok(len == 0, "Got length %d.\n", len);
545 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
546 ok(hr == S_OK, "Got hr %#x.\n", hr);
547 ok(props.lActual == 0, "Got actual length %d.\n", props.lActual);
549 props.lActual = 123;
550 hr = IMediaSample2_SetProperties(sample2, sizeof(props), (BYTE *)&props);
551 ok(hr == S_OK, "Got hr %#x.\n", hr);
553 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
554 ok(hr == S_OK, "Got hr %#x.\n", hr);
555 ok(props.lActual == 123, "Got actual length %d.\n", props.lActual);
557 len = IMediaSample_GetActualDataLength(sample);
558 ok(len == 123, "Got length %d.\n", len);
560 /* boolean flags */
562 hr = IMediaSample_IsPreroll(sample);
563 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
564 hr = IMediaSample_SetPreroll(sample, TRUE);
565 ok(hr == S_OK, "Got hr %#x.\n", hr);
566 hr = IMediaSample_IsPreroll(sample);
567 ok(hr == S_OK, "Got hr %#x.\n", hr);
568 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
569 ok(hr == S_OK, "Got hr %#x.\n", hr);
570 ok(props.dwSampleFlags == AM_SAMPLE_PREROLL, "Got flags %#x.\n", props.dwSampleFlags);
571 hr = IMediaSample_SetPreroll(sample, FALSE);
572 ok(hr == S_OK, "Got hr %#x.\n", hr);
573 hr = IMediaSample_IsPreroll(sample);
574 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
575 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
576 ok(hr == S_OK, "Got hr %#x.\n", hr);
577 ok(!props.dwSampleFlags, "Got flags %#x.\n", props.dwSampleFlags);
579 hr = IMediaSample_IsDiscontinuity(sample);
580 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
581 hr = IMediaSample_SetDiscontinuity(sample, TRUE);
582 ok(hr == S_OK, "Got hr %#x.\n", hr);
583 hr = IMediaSample_IsDiscontinuity(sample);
584 ok(hr == S_OK, "Got hr %#x.\n", hr);
585 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
586 ok(hr == S_OK, "Got hr %#x.\n", hr);
587 ok(props.dwSampleFlags == AM_SAMPLE_DATADISCONTINUITY, "Got flags %#x.\n", props.dwSampleFlags);
588 hr = IMediaSample_SetDiscontinuity(sample, FALSE);
589 ok(hr == S_OK, "Got hr %#x.\n", hr);
590 hr = IMediaSample_IsDiscontinuity(sample);
591 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
592 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
593 ok(hr == S_OK, "Got hr %#x.\n", hr);
594 ok(!props.dwSampleFlags, "Got flags %#x.\n", props.dwSampleFlags);
596 hr = IMediaSample_IsSyncPoint(sample);
597 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
598 hr = IMediaSample_SetSyncPoint(sample, TRUE);
599 ok(hr == S_OK, "Got hr %#x.\n", hr);
600 hr = IMediaSample_IsSyncPoint(sample);
601 ok(hr == S_OK, "Got hr %#x.\n", hr);
602 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
603 ok(hr == S_OK, "Got hr %#x.\n", hr);
604 ok(props.dwSampleFlags == AM_SAMPLE_SPLICEPOINT, "Got flags %#x.\n", props.dwSampleFlags);
605 hr = IMediaSample_SetSyncPoint(sample, FALSE);
606 ok(hr == S_OK, "Got hr %#x.\n", hr);
607 hr = IMediaSample_IsSyncPoint(sample);
608 ok(hr == S_FALSE, "Got hr %#x.\n", hr);
609 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
610 ok(hr == S_OK, "Got hr %#x.\n", hr);
611 ok(!props.dwSampleFlags, "Got flags %#x.\n", props.dwSampleFlags);
613 props.dwSampleFlags = (AM_SAMPLE_PREROLL | AM_SAMPLE_DATADISCONTINUITY | AM_SAMPLE_SPLICEPOINT);
614 hr = IMediaSample2_SetProperties(sample2, sizeof(props), (BYTE *)&props);
615 ok(hr == S_OK, "Got hr %#x.\n", hr);
616 hr = IMediaSample_IsPreroll(sample);
617 ok(hr == S_OK, "Got hr %#x.\n", hr);
618 hr = IMediaSample_IsDiscontinuity(sample);
619 ok(hr == S_OK, "Got hr %#x.\n", hr);
620 hr = IMediaSample_IsSyncPoint(sample);
621 ok(hr == S_OK, "Got hr %#x.\n", hr);
622 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
623 ok(hr == S_OK, "Got hr %#x.\n", hr);
624 ok(props.dwSampleFlags == (AM_SAMPLE_PREROLL | AM_SAMPLE_DATADISCONTINUITY | AM_SAMPLE_SPLICEPOINT),
625 "Got flags %#x.\n", props.dwSampleFlags);
627 hr = IMediaSample_SetMediaType(sample, &expect_mt);
628 ok(hr == S_OK, "Got hr %#x.\n", hr);
630 IMediaSample2_Release(sample2);
631 IMediaSample_Release(sample);
633 hr = IMemAllocator_GetBuffer(allocator, &sample, NULL, NULL, 0);
634 ok(hr == S_OK, "Got hr %#x.\n", hr);
635 hr = IMediaSample_QueryInterface(sample, &IID_IMediaSample2, (void **)&sample2);
636 ok(hr == S_OK, "Got hr %#x.\n", hr);
638 hr = IMediaSample2_GetProperties(sample2, sizeof(props), (BYTE *)&props);
639 ok(hr == S_OK, "Got hr %#x.\n", hr);
640 ok(!props.dwTypeSpecificFlags, "Got type-specific flags %#x.\n", props.dwTypeSpecificFlags);
641 ok(!props.dwSampleFlags, "Got flags %#x.\n", props.dwSampleFlags);
642 ok(props.lActual == 123, "Got actual length %d.\n", props.lActual);
643 ok(!props.tStart, "Got sample start %s.\n", wine_dbgstr_longlong(props.tStart));
644 ok(!props.dwStreamId, "Got stream ID %#x.\n", props.dwStreamId);
645 ok(!props.pMediaType, "Got media type %p.\n", props.pMediaType);
646 ok(props.cbBuffer == 65536, "Got buffer length %d.\n", props.cbBuffer);
648 IMediaSample2_Release(sample2);
649 IMediaSample_Release(sample);
650 IMemAllocator_Release(allocator);
653 START_TEST(memallocator)
655 CoInitialize(NULL);
657 test_properties();
658 test_commit();
659 test_sample_time();
660 test_media_time();
661 test_sample_properties();
663 CoUninitialize();