1*c2c66affSColin Finck typedef struct
2*c2c66affSColin Finck {
3*c2c66affSColin Finck 	INT* passed;
4*c2c66affSColin Finck 	INT* failed;
5*c2c66affSColin Finck 	LPDIRECTDRAW7 DirectDraw;
6*c2c66affSColin Finck } ENUMCONTEXT;
7*c2c66affSColin Finck 
8*c2c66affSColin Finck BOOL Test_GetMonitorFrequency (INT* passed, INT* failed);
9*c2c66affSColin Finck 
DummyEnumDisplayModes(LPDDSURFACEDESC2 pDDSD,ENUMCONTEXT * Context)10*c2c66affSColin Finck HRESULT CALLBACK DummyEnumDisplayModes( LPDDSURFACEDESC2 pDDSD, ENUMCONTEXT* Context )
11*c2c66affSColin Finck {
12*c2c66affSColin Finck 	return DDENUMRET_OK;
13*c2c66affSColin Finck }
14*c2c66affSColin Finck 
EnumDisplayModes(LPDDSURFACEDESC2 pDDSD,ENUMCONTEXT * Context)15*c2c66affSColin Finck HRESULT CALLBACK EnumDisplayModes( LPDDSURFACEDESC2 pDDSD, ENUMCONTEXT* Context )
16*c2c66affSColin Finck {
17*c2c66affSColin Finck 	static int setcout = 0;
18*c2c66affSColin Finck 	if(setcout >= 5)
19*c2c66affSColin Finck 		return DDENUMRET_OK;
20*c2c66affSColin Finck 
21*c2c66affSColin Finck 	DWORD lpdwFrequency = 0;
22*c2c66affSColin Finck 	INT* passed = Context->passed;
23*c2c66affSColin Finck 	INT* failed = Context->failed;
24*c2c66affSColin Finck 	DDSURFACEDESC2 DisplayMode = {0};
25*c2c66affSColin Finck 	DisplayMode.dwSize = sizeof(DDSURFACEDESC2);
26*c2c66affSColin Finck 
27*c2c66affSColin Finck 	TEST ( pDDSD->dwFlags == (DDSD_HEIGHT | DDSD_WIDTH | DDSD_PITCH | DDSD_PIXELFORMAT | DDSD_REFRESHRATE));
28*c2c66affSColin Finck 	TEST ( pDDSD->ddpfPixelFormat.dwFlags == (DDPF_RGB | DDPF_PALETTEINDEXED8) || pDDSD->ddpfPixelFormat.dwFlags == DDPF_RGB );
29*c2c66affSColin Finck 	TEST ( Context->DirectDraw->SetDisplayMode (pDDSD->dwWidth, pDDSD->dwHeight, pDDSD->ddpfPixelFormat.dwRGBBitCount, pDDSD->dwRefreshRate, 0) == DD_OK);
30*c2c66affSColin Finck 	TEST ( Context->DirectDraw->GetMonitorFrequency (&lpdwFrequency) == DD_OK && lpdwFrequency == pDDSD->dwRefreshRate);
31*c2c66affSColin Finck 	TEST ( Context->DirectDraw->GetDisplayMode (&DisplayMode) == DD_OK
32*c2c66affSColin Finck 		&& pDDSD->dwHeight == DisplayMode.dwHeight
33*c2c66affSColin Finck 		&& pDDSD->dwWidth == DisplayMode.dwWidth
34*c2c66affSColin Finck 		&& pDDSD->dwRefreshRate == DisplayMode.dwRefreshRate
35*c2c66affSColin Finck 		&& pDDSD->ddpfPixelFormat.dwRGBBitCount == DisplayMode.ddpfPixelFormat.dwRGBBitCount
36*c2c66affSColin Finck 		&& DisplayMode.dwFlags == (DDSD_HEIGHT | DDSD_WIDTH | DDSD_PITCH | DDSD_PIXELFORMAT | DDSD_REFRESHRATE) );
37*c2c66affSColin Finck 
38*c2c66affSColin Finck 	setcout++;
39*c2c66affSColin Finck 	return DDENUMRET_OK;
40*c2c66affSColin Finck }
41*c2c66affSColin Finck 
Test_DisplayModes(INT * passed,INT * failed)42*c2c66affSColin Finck BOOL Test_DisplayModes (INT* passed, INT* failed)
43*c2c66affSColin Finck {
44*c2c66affSColin Finck 	/*** FIXME: Also test with surface as parameter; try busy/locked surface as well ***/
45*c2c66affSColin Finck 	LPDIRECTDRAW7 DirectDraw;
46*c2c66affSColin Finck 
47*c2c66affSColin Finck 	/* Preparations */
48*c2c66affSColin Finck 	if (DirectDrawCreateEx(NULL, (VOID**)&DirectDraw, IID_IDirectDraw7, NULL) != DD_OK)
49*c2c66affSColin Finck 	{
50*c2c66affSColin Finck 		printf("ERROR: Failed to set up ddraw\n");
51*c2c66affSColin Finck 		return FALSE;
52*c2c66affSColin Finck 	}
53*c2c66affSColin Finck 
54*c2c66affSColin Finck 	ENUMCONTEXT Context = {passed, failed, DirectDraw};
55*c2c66affSColin Finck 
56*c2c66affSColin Finck 	/* The Test */
57*c2c66affSColin Finck 
58*c2c66affSColin Finck     Test_GetMonitorFrequency(passed, failed);
59*c2c66affSColin Finck 
60*c2c66affSColin Finck 	/* First try with some generic display modes */
61*c2c66affSColin Finck 	TEST ( DirectDraw->SetDisplayMode (1586, 895, 0, 0, 0) == DDERR_UNSUPPORTED );
62*c2c66affSColin Finck 	TEST ( DirectDraw->SetDisplayMode (0, 0, 0, 0, 0x123) == DDERR_INVALIDPARAMS );
63*c2c66affSColin Finck 
64*c2c66affSColin Finck 	// does this change the display mode to DDSCL_EXCLUSIVE ?
65*c2c66affSColin Finck 	TEST ( DirectDraw->SetDisplayMode (0, 0, 0, 0, 0) == DD_OK );
66*c2c66affSColin Finck 	TEST ( DirectDraw->SetDisplayMode (800, 600, 0, 0, 0) == DD_OK );
67*c2c66affSColin Finck 	TEST ( DirectDraw->SetDisplayMode (0, 0, 16, 0, 0) == DD_OK );
68*c2c66affSColin Finck 
69*c2c66affSColin Finck 	TEST ( DirectDraw->GetDisplayMode (NULL) == DDERR_INVALIDPARAMS );
70*c2c66affSColin Finck 	DDSURFACEDESC2 DisplayMode = {0};
71*c2c66affSColin Finck 	TEST ( DirectDraw->GetDisplayMode (&DisplayMode) == DDERR_INVALIDPARAMS );
72*c2c66affSColin Finck 
73*c2c66affSColin Finck 	//* Now try getting vaild modes from drive */
74*c2c66affSColin Finck 	TEST (DirectDraw->EnumDisplayModes(DDEDM_STANDARDVGAMODES, NULL, (PVOID)&Context, NULL) == DDERR_INVALIDPARAMS);
75*c2c66affSColin Finck 	TEST (DirectDraw->EnumDisplayModes(0, NULL, (PVOID)&Context, (LPDDENUMMODESCALLBACK2)DummyEnumDisplayModes) == DD_OK );
76*c2c66affSColin Finck 	TEST (DirectDraw->EnumDisplayModes(DDEDM_REFRESHRATES, NULL, (PVOID)&Context, (LPDDENUMMODESCALLBACK2)DummyEnumDisplayModes) == DD_OK );
77*c2c66affSColin Finck 	TEST (DirectDraw->EnumDisplayModes(DDEDM_STANDARDVGAMODES, NULL, (PVOID)&Context, (LPDDENUMMODESCALLBACK2)DummyEnumDisplayModes) == DD_OK );
78*c2c66affSColin Finck 	TEST (DirectDraw->EnumDisplayModes(DDEDM_STANDARDVGAMODES|DDEDM_REFRESHRATES, NULL, (PVOID)&Context, (LPDDENUMMODESCALLBACK2)EnumDisplayModes) == DD_OK);
79*c2c66affSColin Finck 
80*c2c66affSColin Finck 	TEST (DirectDraw->RestoreDisplayMode() == DD_OK);
81*c2c66affSColin Finck 
82*c2c66affSColin Finck 	DirectDraw->Release();
83*c2c66affSColin Finck 
84*c2c66affSColin Finck 	return TRUE;
85*c2c66affSColin Finck }
86*c2c66affSColin Finck 
Test_GetMonitorFrequency(INT * passed,INT * failed)87*c2c66affSColin Finck BOOL Test_GetMonitorFrequency (INT* passed, INT* failed)
88*c2c66affSColin Finck {
89*c2c66affSColin Finck 	LPDIRECTDRAW7 DirectDraw;
90*c2c66affSColin Finck 	LPDDRAWI_DIRECTDRAW_INT This;
91*c2c66affSColin Finck 
92*c2c66affSColin Finck 	/* Preparations */
93*c2c66affSColin Finck 	if (DirectDrawCreateEx(NULL, (VOID**)&DirectDraw, IID_IDirectDraw7, NULL) != DD_OK)
94*c2c66affSColin Finck 	{
95*c2c66affSColin Finck 		printf("ERROR: Failed to set up ddraw\n");
96*c2c66affSColin Finck 		return FALSE;
97*c2c66affSColin Finck 	}
98*c2c66affSColin Finck 	This = (LPDDRAWI_DIRECTDRAW_INT)DirectDraw;
99*c2c66affSColin Finck 
100*c2c66affSColin Finck 	/* Here we go */
101*c2c66affSColin Finck 	DWORD lpFreq;
102*c2c66affSColin Finck 	DWORD temp;
103*c2c66affSColin Finck 	HRESULT retVal;
104*c2c66affSColin Finck 	TEST (DirectDraw->GetMonitorFrequency((PDWORD)0xdeadbeef) == DDERR_INVALIDPARAMS);
105*c2c66affSColin Finck 	TEST (DirectDraw->GetMonitorFrequency(NULL) == DDERR_INVALIDPARAMS);
106*c2c66affSColin Finck 
107*c2c66affSColin Finck 	// result depends on our graphices card
108*c2c66affSColin Finck 	retVal = DirectDraw->GetMonitorFrequency((PDWORD)&lpFreq);
109*c2c66affSColin Finck 	TEST ( retVal == DD_OK || retVal == DDERR_UNSUPPORTED);
110*c2c66affSColin Finck 
111*c2c66affSColin Finck 	/* Test by hacking interal structures */
112*c2c66affSColin Finck 
113*c2c66affSColin Finck 	// should return DDERR_UNSUPPORTED
114*c2c66affSColin Finck 	This->lpLcl->lpGbl->dwMonitorFrequency = 0;
115*c2c66affSColin Finck 	TEST (DirectDraw->GetMonitorFrequency(&temp) == DDERR_UNSUPPORTED);
116*c2c66affSColin Finck 
117*c2c66affSColin Finck 	// should return DD_OK
118*c2c66affSColin Finck 	This->lpLcl->lpGbl->dwMonitorFrequency = 85;
119*c2c66affSColin Finck 	TEST (DirectDraw->GetMonitorFrequency(&temp) == DD_OK);
120*c2c66affSColin Finck 
121*c2c66affSColin Finck 	/* Restore */
122*c2c66affSColin Finck 	This->lpLcl->lpGbl->dwMonitorFrequency =  lpFreq;
123*c2c66affSColin Finck 
124*c2c66affSColin Finck 	DirectDraw->Release();
125*c2c66affSColin Finck 
126*c2c66affSColin Finck 	return TRUE;
127*c2c66affSColin Finck }
128