ReactOS  0.4.15-dev-994-ga9f6032
CreateDIBPatternBrush.c File Reference
#include "precomp.h"
#include "init.h"
Include dependency graph for CreateDIBPatternBrush.c:

Go to the source code of this file.

Macros

#define DIB_PAL_INDICES   2
 

Functions

void Test_CreateDIBPatternBrush ()
 
void Test_CreateDIBPatternBrushPt ()
 
void Test_CreateDIBPatternBrushPt_RLE8 ()
 
 START_TEST (CreateDIBPatternBrush)
 

Macro Definition Documentation

◆ DIB_PAL_INDICES

#define DIB_PAL_INDICES   2

Definition at line 13 of file CreateDIBPatternBrush.c.

Function Documentation

◆ START_TEST()

START_TEST ( CreateDIBPatternBrush  )

Definition at line 181 of file CreateDIBPatternBrush.c.

182 {
183  InitStuff();
184 
187  //Test_CreateDIBPatternBrushPt_RLE8(); broken
188 }
BOOL InitStuff(void)
Definition: init.c:95
void Test_CreateDIBPatternBrushPt()
void Test_CreateDIBPatternBrush()

◆ Test_CreateDIBPatternBrush()

void Test_CreateDIBPatternBrush ( )

Definition at line 15 of file CreateDIBPatternBrush.c.

16 {
17 
18 }

Referenced by START_TEST().

◆ Test_CreateDIBPatternBrushPt()

void Test_CreateDIBPatternBrushPt ( )

Definition at line 20 of file CreateDIBPatternBrush.c.

21 {
22  struct
23  {
24  BITMAPINFOHEADER bmiHeader;
25  WORD wColors[4];
26  BYTE ajBuffer[16];
27  } PackedDIB =
28  {
29  {sizeof(BITMAPINFOHEADER), 4, -4, 1, 8, BI_RGB, 0, 1, 1, 4, 0},
30  {0, 1, 2, 7},
31  {0,1,2,3, 1,2,3,0, 2,3,0,1, 3,0,1,2},
32  };
33  HBRUSH hbr, hbrOld;
34  HPALETTE hpalOld;
35  LOGBRUSH logbrush;
36 
37  SetLastError(0);
42  ok_err(0);
43 
44  hbr = CreateDIBPatternBrushPt(&PackedDIB, 0);
45  ok(hbr != 0, "Expected success\n");
46  DeleteObject(hbr);
47  hbr = CreateDIBPatternBrushPt(&PackedDIB, 2);
48  ok(hbr != 0, "Expected success\n");
49  DeleteObject(hbr);
50 
51  SetLastError(0);
52  hbr = CreateDIBPatternBrushPt(&PackedDIB, 3);
53  ok(hbr == 0, "Expected failure\n");
55  SetLastError(0);
56  hbr = CreateDIBPatternBrushPt(&PackedDIB, 10);
57  ok(hbr == 0, "Expected failure\n");
59 
60  /* Create a DIB brush with palette indices */
61  hbr = CreateDIBPatternBrushPt(&PackedDIB, DIB_PAL_COLORS);
62  ok(hbr != 0, "CreateDIBPatternBrushPt failed, skipping tests.\n");
63  if (!hbr) return;
64 
65  /* Check the logbrush */
66  ok(GetObject(hbr, sizeof(logbrush), &logbrush), "GetObject() failed\n");
67  ok_int(logbrush.lbStyle, BS_DIBPATTERN);
68  ok_hex(logbrush.lbColor, 0);
69  ok(logbrush.lbHatch == (ULONG_PTR)&PackedDIB,
70  "invalid lbHatch. Got %p, expected %p\n", (PVOID)logbrush.lbHatch, &PackedDIB);
71 
72  /* Select the brush into the dc */
73  hbrOld = SelectObject(ghdcDIB32, hbr);
74 
75  /* Copy it on the dib section */
76  ok_long(PatBlt(ghdcDIB32, 0, 0, 4, 4, PATCOPY), 1);
77  ok_long((*gpDIB32)[0][0], 0x000000); // 0
78  ok_long((*gpDIB32)[0][1], 0x800000); // 1
79  ok_long((*gpDIB32)[0][2], 0x008000); // 2
80  ok_long((*gpDIB32)[0][3], 0xc0c0c0); // 7
81 
82  /* Select a logical palette into the DC */
83  hpalOld = SelectPalette(ghdcDIB32, ghpal, FALSE);
84  ok(hpalOld != 0, "Expected success, error %ld\n", GetLastError());
85 
86  /* Copy it on the dib section */
87  ok_long(PatBlt(ghdcDIB32, 0, 0, 4, 4, PATCOPY), 1);
88  ok_long((*gpDIB32)[0][0], 0x102030); // 0
89  ok_long((*gpDIB32)[0][1], 0x203040); // 1
90  ok_long((*gpDIB32)[0][2], 0x304050); // 2
91  ok_long((*gpDIB32)[0][3], 0x8090a0); // 7
92 
93  /* Select back old palette and destroy the DIB data */
94  SelectPalette(ghdcDIB32, hpalOld, FALSE);
95  memset(gpDIB32, 0x77, sizeof(*gpDIB32));
96 
97  /* Copy it on the dib section */
98  ok_long(PatBlt(ghdcDIB32, 0, 0, 4, 4, PATCOPY), 1);
99  ok_long((*gpDIB32)[0][0], 0x000000); // 0
100  ok_long((*gpDIB32)[0][1], 0x800000); // 1
101  ok_long((*gpDIB32)[0][2], 0x008000); // 2
102  ok_long((*gpDIB32)[0][3], 0xc0c0c0); // 7
103 
104  SelectObject(ghdcDIB32, hbrOld);
105  DeleteObject(hbr);
106 
107  /* Set some different values */
108  PackedDIB.ajBuffer[0] = 3;
109  PackedDIB.ajBuffer[1] = 2;
110  PackedDIB.ajBuffer[2] = 1;
111  PackedDIB.ajBuffer[3] = 0;
112 
113  /* Create a DIB brush with DIB_PAL_INDICES */
114  hbr = CreateDIBPatternBrushPt(&PackedDIB, DIB_PAL_INDICES);
115  ok(hbr != 0, "CreateSolidBrush failed, skipping tests.\n");
116  if (!hbr) return;
117 
118  /* Check the logbrush */
119  ok(GetObject(hbr, sizeof(logbrush), &logbrush), "GetObject() failed\n");
120  ok_int(logbrush.lbStyle, BS_DIBPATTERN);
121  ok_hex(logbrush.lbColor, 0);
122  ok(logbrush.lbHatch == (ULONG_PTR)&PackedDIB,
123  "invalid lbHatch. Got %p, expected %p\n", (PVOID)logbrush.lbHatch, &PackedDIB);
124 
125  /* Select the brush into the dc */
126  hbrOld = SelectObject(ghdcDIB32, hbr);
127  ok(hbrOld != 0, "CreateSolidBrush failed, skipping tests.\n");
128 
129  /* Copy it on a dib section */
130  memset(gpDIB32, 0x77, sizeof(*gpDIB32));
131  ok_long(PatBlt(ghdcDIB32, 0, 0, 4, 4, PATCOPY), 1);
132  ok_long((*gpDIB32)[0][0], 0x77777777);
133  ok_long((*gpDIB32)[0][1], 0x77777777);
134  ok_long((*gpDIB32)[0][2], 0x77777777);
135  ok_long((*gpDIB32)[0][3], 0x77777777);
136 
137  /* Select a logical palette into the DC */
138  hpalOld = SelectPalette(ghdcDIB32, ghpal, FALSE);
139  ok(hpalOld != 0, "Expected success, error %ld\n", GetLastError());
140 
141  /* Copy it on a dib section */
142  ok_long(PatBlt(ghdcDIB32, 0, 0, 4, 4, PATCOPY), 1);
143  ok_long((*gpDIB32)[0][0], 0x77777777);
144  ok_long((*gpDIB32)[0][1], 0x77777777);
145  ok_long((*gpDIB32)[0][2], 0x77777777);
146  ok_long((*gpDIB32)[0][3], 0x77777777);
147 
148  SelectPalette(ghdcDIB32, hpalOld, FALSE);
149  SelectObject(ghdcDIB32, hbrOld);
150  DeleteObject(hbr);
151 
152 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define BS_DIBPATTERN
Definition: wingdi.h:1091
#define DIB_PAL_COLORS
Definition: wingdi.h:365
UINT lbStyle
Definition: wingdi.h:1746
HPALETTE ghpal
Definition: init.c:11
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
ULONG_PTR lbHatch
Definition: wingdi.h:1748
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1499
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define ok_long(expression, result)
Definition: atltest.h:133
#define ok_hdl
Definition: atltest.h:136
#define ok_hex(expression, result)
Definition: atltest.h:94
uint32_t ULONG_PTR
Definition: typedefs.h:65
ULONG(* gpDIB32)[8][8]
Definition: init.c:10
BOOL WINAPI PatBlt(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD)
#define FALSE
Definition: types.h:117
HPALETTE WINAPI SelectPalette(_In_ HDC, _In_ HPALETTE, _In_ BOOL)
smooth NULL
Definition: ftsmooth.c:416
#define ok_int(expression, result)
Definition: atltest.h:134
COLORREF lbColor
Definition: wingdi.h:1747
unsigned short WORD
Definition: ntddk_ex.h:93
#define SetLastError(x)
Definition: compat.h:500
#define GetObject
Definition: wingdi.h:4467
#define ok_err(error)
Definition: atltest.h:124
unsigned char BYTE
Definition: xxhash.c:193
#define PATCOPY
Definition: wingdi.h:334
#define ok(value,...)
Definition: atltest.h:57
#define DIB_PAL_INDICES
HDC ghdcDIB32
Definition: init.c:8
#define memset(x, y, z)
Definition: compat.h:39
HBRUSH WINAPI CreateDIBPatternBrushPt(_In_ const VOID *pvPackedDIB, _In_ UINT uUsage)
#define BI_RGB
Definition: precomp.h:47

Referenced by START_TEST().

◆ Test_CreateDIBPatternBrushPt_RLE8()

void Test_CreateDIBPatternBrushPt_RLE8 ( )

Definition at line 154 of file CreateDIBPatternBrush.c.

155 {
156  struct
157  {
158  BITMAPINFOHEADER bmiHeader;
159  WORD wColors[4];
160  BYTE ajBuffer[20];
161  } PackedDIB =
162  {
163  {sizeof(BITMAPINFOHEADER), 4, 4, 1, 8, BI_RLE8, 20, 1, 1, 4, 0},
164  {0, 1, 2, 7},
165  {4,0, 0,2,0,1,0,2,3,1, 2,1, 2,2, 1,3,1,0,1,2, },
166  };
167  HBRUSH hbr;
168 
170  HBITMAP hbmp = CreateDIBitmap(hdc, &PackedDIB.bmiHeader, CBM_INIT, &PackedDIB.ajBuffer, (PVOID)&PackedDIB, DIB_PAL_COLORS);
171  ok(hbmp != 0, "CreateDIBitmap failed, skipping tests.\n");
172 
173  /* Create a DIB brush with palette indices */
174  hbr = CreateDIBPatternBrushPt(&PackedDIB, DIB_PAL_COLORS);
175  ok(hbr == 0, "CreateDIBPatternBrushPt should fail.\n");
176 
177 
178 }
#define DIB_PAL_COLORS
Definition: wingdi.h:365
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
static HDC
Definition: imagelist.c:92
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define CBM_INIT
Definition: wingdi.h:364
HBITMAP hbmp
unsigned short WORD
Definition: ntddk_ex.h:93
HBITMAP WINAPI CreateDIBitmap(_In_ HDC hdc, _In_opt_ const BITMAPINFOHEADER *pbmih, _In_ DWORD fdwInit, _In_opt_ const VOID *pvInit, _In_opt_ const BITMAPINFO *pbmi, _In_ UINT uUsage)
HDC hdc
Definition: main.c:9
unsigned char BYTE
Definition: xxhash.c:193
#define ok(value,...)
Definition: atltest.h:57
static HBITMAP
Definition: button.c:44
#define BI_RLE8
Definition: wingdi.h:35
HBRUSH WINAPI CreateDIBPatternBrushPt(_In_ const VOID *pvPackedDIB, _In_ UINT uUsage)