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