3b06a250acf4ae23756358a732e8b54772ce4fd1
[reactos.git] / rostests / dxtest / ddraw / tests / CreateDDraw.cpp
1 #include "ddrawtest.h"
2
3 HWND CreateBasicWindow (VOID);
4
5 BOOL Test_CreateDDraw (INT* passed, INT* failed)
6 {
7 LPDIRECTDRAW7 DirectDraw;
8 IDirectDraw* DirectDraw2;
9
10 /*** FIXME: Test first parameter using EnumDisplayDrivers ***/
11 DirectDrawCreateEx(NULL, (VOID**)&DirectDraw, IID_IDirectDraw7, NULL);
12
13 TEST (DirectDrawCreateEx(NULL, (VOID**)&DirectDraw, IID_IDirectDraw7, (IUnknown*)0xdeadbeef) == CLASS_E_NOAGGREGATION);
14 TEST (DirectDrawCreateEx(NULL, (VOID**)&DirectDraw, IID_IDirectDraw4, NULL) == DDERR_INVALIDPARAMS);
15 TEST (DirectDrawCreateEx(NULL, NULL, IID_IDirectDraw7, NULL) == DDERR_INVALIDPARAMS);
16
17 DirectDraw = NULL;
18 TEST (DirectDrawCreateEx(NULL, (VOID**)&DirectDraw, IID_IDirectDraw7, NULL) == DD_OK);
19 if(DirectDraw)
20 {
21 TEST (DirectDraw->Initialize(NULL) == DDERR_ALREADYINITIALIZED);
22 TEST (DirectDraw->Release() == 0);
23 }
24
25 DirectDraw2 = NULL;
26 TEST (DirectDrawCreate(NULL ,&DirectDraw2, NULL) == DD_OK);
27 if(DirectDraw2)
28 {
29 TEST (DirectDraw2->QueryInterface(IID_IDirectDraw7, (PVOID*)&DirectDraw) == 0);
30 TEST (DirectDraw2->AddRef() == 2);
31 TEST (DirectDraw->AddRef() == 2);
32 TEST (DirectDraw->Release() == 1);
33 TEST (DirectDraw->Release() == 0);
34 TEST (DirectDraw2->Release() == 1);
35 TEST (DirectDraw2->Release() == 0);
36 }
37
38 return TRUE;
39 }
40
41 BOOL Test_SetCooperativeLevel (INT* passed, INT* failed)
42 {
43 HWND hwnd;
44 LPDIRECTDRAW7 DirectDraw;
45
46 /* Preparations */
47 if (DirectDrawCreateEx(NULL, (VOID**)&DirectDraw, IID_IDirectDraw7, NULL) != DD_OK)
48 {
49 printf("ERROR: Failed to set up ddraw\n");
50 return FALSE;
51 }
52
53 if(!( hwnd = CreateBasicWindow() ))
54 {
55 printf("ERROR: Failed to create window\n");
56 DirectDraw->Release();
57 return FALSE;
58 }
59
60 /* The Test */
61 TEST ( DirectDraw->SetCooperativeLevel (NULL, DDSCL_FULLSCREEN) == DDERR_INVALIDPARAMS );
62 TEST ( DirectDraw->SetCooperativeLevel (hwnd, DDSCL_FULLSCREEN) == DDERR_INVALIDPARAMS );
63 TEST ( DirectDraw->SetCooperativeLevel (NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE) == DDERR_INVALIDPARAMS );
64 TEST ( DirectDraw->SetCooperativeLevel (hwnd, DDSCL_FULLSCREEN) == DDERR_INVALIDPARAMS);
65 TEST ( DirectDraw->SetCooperativeLevel (hwnd, DDSCL_NORMAL | DDSCL_ALLOWMODEX) == DDERR_INVALIDPARAMS );
66 TEST ( DirectDraw->SetCooperativeLevel ((HWND)0xdeadbeef, DDSCL_NORMAL) == DDERR_INVALIDPARAMS);
67
68 TEST ( DirectDraw->SetCooperativeLevel (hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE) == DD_OK);
69 TEST ( DirectDraw->Compact() == DD_OK );
70 TEST ( DirectDraw->SetCooperativeLevel (hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWMODEX) == DD_OK);
71 TEST ( DirectDraw->SetCooperativeLevel (NULL, DDSCL_NORMAL) == DD_OK );
72 TEST ( DirectDraw->SetCooperativeLevel (hwnd, DDSCL_NORMAL) == DD_OK );
73 TEST ( DirectDraw->Compact() == DDERR_NOEXCLUSIVEMODE );
74
75 TEST ( DirectDraw->TestCooperativeLevel() == DD_OK ); // I do not get what this API does it always seems to return DD_OK
76
77 DirectDraw->Release();
78
79 return TRUE;
80 }
81
82 BOOL Test_GetAvailableVidMem (INT* passed, INT* failed)
83 {
84 LPDIRECTDRAW7 DirectDraw;
85
86 /* Preparations */
87 if (DirectDrawCreateEx(NULL, (VOID**)&DirectDraw, IID_IDirectDraw7, NULL) != DD_OK)
88 {
89 printf("ERROR: Failed to set up ddraw\n");
90 return FALSE;
91 }
92
93 /* Here we go */
94 DWORD Total, Free;
95 DDSCAPS2 Caps = { 0 };
96 TEST (DirectDraw->GetAvailableVidMem(&Caps, NULL, NULL) == DDERR_INVALIDPARAMS);
97 TEST (DirectDraw->GetAvailableVidMem(NULL, &Total, &Free) == DDERR_INVALIDPARAMS);
98 TEST (DirectDraw->GetAvailableVidMem(&Caps, &Total, &Free) == DD_OK && Total == 0 && Free == 0 );
99
100 Caps.dwCaps = DDSCAPS_VIDEOMEMORY;
101 TEST (DirectDraw->GetAvailableVidMem(&Caps, &Total, &Free) == DD_OK );
102
103 DirectDraw->Release();
104
105 return TRUE;
106 }
107
108 LONG WINAPI BasicWindowProc (HWND hwnd, UINT message, UINT wParam, LONG lParam)
109 {
110 switch (message)
111 {
112 case WM_DESTROY:
113 {
114 PostQuitMessage (0);
115 return 0;
116 } break;
117 }
118
119 return DefWindowProc (hwnd, message, wParam, lParam);
120 }
121
122 HWND CreateBasicWindow (VOID)
123 {
124 WNDCLASS wndclass = {0};
125 wndclass.lpfnWndProc = BasicWindowProc;
126 wndclass.hInstance = GetModuleHandle(NULL);
127 wndclass.lpszClassName = "DDrawTest";
128 RegisterClass(&wndclass);
129
130 return CreateWindow("DDrawTest", "ReactOS DirectDraw Test", WS_POPUP, 0, 0, 10, 10, NULL, NULL, GetModuleHandle(NULL), NULL);
131 }