Fixes for -Wmissing-declaration and -Wwrite-string warnings.
[wine] / dlls / ddraw / tests / dsurface.c
1 /*
2  * Unit tests for (a few) ddraw surface functions
3  *
4  * Copyright (C) 2005 Antoine Chavasse (a.chavasse@gmail.com)
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <assert.h>
22 #include "wine/test.h"
23 #include "ddraw.h"
24
25 static LPDIRECTDRAW lpDD = NULL;
26
27 static void CreateDirectDraw()
28 {
29     HRESULT rc;
30
31     rc = DirectDrawCreate(NULL, &lpDD, NULL);
32     ok(rc==DD_OK,"DirectDrawCreate returned: %lx\n",rc);
33
34     rc = IDirectDraw_SetCooperativeLevel(lpDD, NULL, DDSCL_NORMAL);
35     ok(rc==DD_OK,"SetCooperativeLevel returned: %lx\n",rc);
36 }
37
38
39 static void ReleaseDirectDraw()
40 {
41     if( lpDD != NULL )
42     {
43         IDirectDraw_Release(lpDD);
44         lpDD = NULL;
45     }
46 }
47
48 static void MipMapCreationTest()
49 {
50     LPDIRECTDRAWSURFACE lpDDSMipMapTest;
51     DDSURFACEDESC ddsd;
52     HRESULT rc;
53
54     /* First mipmap creation test: create a surface with DDSCAPS_COMPLEX,
55        DDSCAPS_MIPMAP, and DDSD_MIPMAPCOUNT. This create the number of
56         requested mipmap levels. */
57     ddsd.dwSize = sizeof(ddsd);
58     ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_MIPMAPCOUNT;
59     ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
60     U2(ddsd).dwMipMapCount = 3;
61     ddsd.dwWidth = 128;
62     ddsd.dwHeight = 32;
63     rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
64     ok(rc==DD_OK,"CreateSurface returned: %lx\n",rc);
65
66     /* Check the number of created mipmaps */
67     memset(&ddsd, 0, sizeof(DDSURFACEDESC));
68     ddsd.dwSize = sizeof(ddsd);
69     rc = IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest, &ddsd);
70     ok(rc==DD_OK,"GetSurfaceDesc returned: %lx\n",rc);
71     ok(ddsd.dwFlags & DDSD_MIPMAPCOUNT,
72         "GetSurfaceDesc returned no mipmapcount.\n");
73     ok(U2(ddsd).dwMipMapCount == 3, "Incorrect mipmap count: %ld.\n",
74         U2(ddsd).dwMipMapCount);
75
76     /* Destroy the surface. */
77     IDirectDrawSurface_Release(lpDDSMipMapTest);
78
79
80     /* Second mipmap creation test: create a surface without a mipmap
81        count, with DDSCAPS_MIPMAP and without DDSCAPS_COMPLEX.
82        This creates a single mipmap level. */
83     memset(&ddsd, 0, sizeof(DDSURFACEDESC));
84     ddsd.dwSize = sizeof(ddsd);
85     ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
86     ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_MIPMAP;
87     ddsd.dwWidth = 128;
88     ddsd.dwHeight = 32;
89     rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
90     ok(rc==DD_OK,"CreateSurface returned: %lx\n",rc);
91
92     /* Check the number of created mipmaps */
93     memset(&ddsd, 0, sizeof(DDSURFACEDESC));
94     ddsd.dwSize = sizeof(ddsd);
95     rc = IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest, &ddsd);
96     ok(rc==DD_OK,"GetSurfaceDesc returned: %lx\n",rc);
97     ok(ddsd.dwFlags & DDSD_MIPMAPCOUNT,
98         "GetSurfaceDesc returned no mipmapcount.\n");
99     ok(U2(ddsd).dwMipMapCount == 1, "Incorrect mipmap count: %ld.\n",
100         U2(ddsd).dwMipMapCount);
101
102
103     /* Third mipmap creation test: create a surface with DDSCAPS_MIPMAP,
104         DDSCAPS_COMPLEX and without DDSD_MIPMAPCOUNT.
105        It's an undocumented features where a chain of mipmaps, starting from
106        he specified size and down to the smallest size, is automatically
107        created.
108        Anarchy Online needs this feature to work. */
109     memset(&ddsd, 0, sizeof(DDSURFACEDESC));
110     ddsd.dwSize = sizeof(ddsd);
111     ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
112     ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
113     ddsd.dwWidth = 128;
114     ddsd.dwHeight = 32;
115     rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
116     ok(rc==DD_OK,"CreateSurface returned: %lx\n",rc);
117
118     /* Check the number of created mipmaps */
119     memset(&ddsd, 0, sizeof(DDSURFACEDESC));
120     ddsd.dwSize = sizeof(ddsd);
121     rc = IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest, &ddsd);
122     ok(rc==DD_OK,"GetSurfaceDesc returned: %lx\n",rc);
123     ok(ddsd.dwFlags & DDSD_MIPMAPCOUNT,
124         "GetSurfaceDesc returned no mipmapcount.\n");
125     ok(U2(ddsd).dwMipMapCount == 6, "Incorrect mipmap count: %ld.\n",
126         U2(ddsd).dwMipMapCount);
127
128
129     /* Fourth mipmap creation test: same as above with a different texture
130        size.
131        The purpose is to verify that the number of generated mipmaps is
132        dependant on the smallest dimension. */
133     memset(&ddsd, 0, sizeof(DDSURFACEDESC));
134     ddsd.dwSize = sizeof(ddsd);
135     ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
136     ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX | DDSCAPS_MIPMAP;
137     ddsd.dwWidth = 32;
138     ddsd.dwHeight = 64;
139     rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSMipMapTest, NULL);
140     ok(rc==DD_OK,"CreateSurface returned: %lx\n",rc);
141
142     /* Check the number of created mipmaps */
143     memset(&ddsd, 0, sizeof(DDSURFACEDESC));
144     ddsd.dwSize = sizeof(ddsd);
145     rc = IDirectDrawSurface_GetSurfaceDesc(lpDDSMipMapTest, &ddsd);
146     ok(rc==DD_OK,"GetSurfaceDesc returned: %lx\n",rc);
147     ok(ddsd.dwFlags & DDSD_MIPMAPCOUNT,
148         "GetSurfaceDesc returned no mipmapcount.\n");
149     ok(U2(ddsd).dwMipMapCount == 6, "Incorrect mipmap count: %ld.\n",
150         U2(ddsd).dwMipMapCount);
151
152     /* Destroy the surface. */
153     IDirectDrawSurface_Release(lpDDSMipMapTest);
154 }
155
156
157 START_TEST(dsurface)
158 {
159     CreateDirectDraw();
160     MipMapCreationTest();
161     ReleaseDirectDraw();
162 }