d3d8: Port the d3d9 stateblock tests to d3d8.
[wine] / dlls / quartz / tests / memallocator.c
1 /*
2  * Unit tests for Direct Show functions
3  *
4  * Copyright (C) 2005 Christian Costa
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 #include <assert.h>
22
23 #define COBJMACROS
24
25 #include "wine/test.h"
26 #include "uuids.h"
27 #include "dshow.h"
28 #include "control.h"
29
30 static void CommitDecommitTest(void)
31 {
32     IMemAllocator* pMemAllocator;
33     HRESULT hr;
34
35     hr = CoCreateInstance(&CLSID_MemoryAllocator, NULL, CLSCTX_INPROC_SERVER, &IID_IMemAllocator, (LPVOID*)&pMemAllocator);
36     ok(hr==S_OK, "Unable to create memory allocator %x\n", hr);
37
38     if (hr == S_OK)
39     {
40         ALLOCATOR_PROPERTIES RequestedProps;
41         ALLOCATOR_PROPERTIES ActualProps;
42
43         IMediaSample *sample = NULL, *sample2 = NULL;
44
45         RequestedProps.cBuffers = 2;
46         RequestedProps.cbBuffer = 65536;
47         RequestedProps.cbAlign = 1;
48         RequestedProps.cbPrefix = 0;
49
50         hr = IMemAllocator_SetProperties(pMemAllocator, &RequestedProps, &ActualProps);
51         ok(hr==S_OK, "SetProperties returned: %x\n", hr);
52
53         hr = IMemAllocator_Commit(pMemAllocator);
54         ok(hr==S_OK, "Commit returned: %x\n", hr);
55         hr = IMemAllocator_Commit(pMemAllocator);
56         ok(hr==S_OK, "Commit returned: %x\n", hr);
57
58         hr = IMemAllocator_GetBuffer(pMemAllocator, &sample, NULL, NULL, 0);
59         ok(hr==S_OK, "Could not get a buffer: %x\n", hr);
60
61         hr = IMemAllocator_Decommit(pMemAllocator);
62         ok(hr==S_OK, "Decommit returned: %x\n", hr);
63         hr = IMemAllocator_Decommit(pMemAllocator);
64         ok(hr==S_OK, "Cecommit returned: %x\n", hr);
65
66         /* Decommit and recommit while holding a sample */
67         if (sample)
68         {
69             hr = IMemAllocator_Commit(pMemAllocator);
70             ok(hr==S_OK, "Commit returned: %x\n", hr);
71
72             hr = IMemAllocator_GetBuffer(pMemAllocator, &sample2, NULL, NULL, 0);
73             ok(hr==S_OK, "Could not get a buffer: %x\n", hr);
74             IUnknown_Release(sample);
75             if (sample2)
76                 IUnknown_Release(sample2);
77
78             hr = IMemAllocator_Decommit(pMemAllocator);
79             ok(hr==S_OK, "Cecommit returned: %x\n", hr);
80         }
81         IMemAllocator_Release(pMemAllocator);
82     }
83 }
84
85 START_TEST(memallocator)
86 {
87     CoInitialize(NULL);
88
89     CommitDecommitTest();
90
91     CoUninitialize();
92 }