ReactOS  0.4.15-dev-489-g75a0787
CreateDIBitmap.c File Reference
#include "precomp.h"
#include "init.h"
Include dependency graph for CreateDIBitmap.c:

Go to the source code of this file.

Macros

#define CBM_CREATDIB   2
 
#define INVALID_POINTER   ((PVOID)(ULONG_PTR)0xC0000000C0000000ULL)
 

Functions

BOOL GetExpected (DWORD *pdwError, HDC hdc, const BITMAPINFOHEADER *lpbmih, DWORD fdwInit, const VOID *lpbInit, const BITMAPINFO *lpbmi, UINT fuUsage)
 
void Test_CreateDIBitmap_Params (void)
 
void Test_CreateDIBitmap_DIB_PAL_COLORS (void)
 
void Test_CreateDIBitmap1 (void)
 
void Test_CreateDIBitmap_RLE8 ()
 
void Test_CreateDIBitmap_CBM_CREATDIB (void)
 
 START_TEST (CreateDIBitmap)
 

Macro Definition Documentation

◆ CBM_CREATDIB

#define CBM_CREATDIB   2

Definition at line 12 of file CreateDIBitmap.c.

◆ INVALID_POINTER

#define INVALID_POINTER   ((PVOID)(ULONG_PTR)0xC0000000C0000000ULL)

Definition at line 14 of file CreateDIBitmap.c.

Function Documentation

◆ GetExpected()

BOOL GetExpected ( DWORD pdwError,
HDC  hdc,
const BITMAPINFOHEADER lpbmih,
DWORD  fdwInit,
const VOID lpbInit,
const BITMAPINFO lpbmi,
UINT  fuUsage 
)

Definition at line 17 of file CreateDIBitmap.c.

25 {
26  if (fuUsage > 2)
27  {
28  *pdwError = ERROR_INVALID_PARAMETER;
29  return FALSE;
30  }
31 
32  if (fuUsage != DIB_RGB_COLORS)
33  {
34  if (hdc == (HDC)-1)
35  {
36  return FALSE;
37  }
38  }
39 
40  if (fdwInit & CBM_INIT)
41  {
42  if (!lpbmih)
43  {
44  if (!lpbInit || (lpbInit == INVALID_POINTER)) return FALSE;
45  }
46  else
47  {
48  if (lpbInit)
49  {
50  if (lpbInit == INVALID_POINTER) return FALSE;
51  if (!lpbmi || (lpbmi == INVALID_POINTER)) return FALSE;
52  if (lpbmi->bmiHeader.biSize == 0) return FALSE;
53  if (fuUsage == 2) return FALSE;
54  }
55  }
56  }
57 
58 
59  if (fdwInit & CBM_CREATDIB)
60  {
61  if (fuUsage == 2) return FALSE;
62  if ((fuUsage == DIB_PAL_COLORS) && !hdc)
63  {
64  return FALSE;
65  }
66 
67  if (fdwInit & CBM_INIT)
68  {
69  if (!lpbInit || (lpbInit == INVALID_POINTER)) return FALSE;
70  }
71 
72  if ((!lpbmi) || (lpbmi == INVALID_POINTER) || (lpbmi->bmiHeader.biSize == 0))
73  {
74  return FALSE;
75  }
76  }
77  else
78  {
79 
80  if ((lpbmih == NULL) ||
81  (lpbmih == INVALID_POINTER) ||
82  (lpbmih->biSize == 0))
83  {
84  return FALSE;
85  }
86 
87  if (hdc == (HDC)-1)
88  {
89  *pdwError = ERROR_INVALID_PARAMETER;
90  return FALSE;
91  }
92 
93 
94  if (lpbmi == INVALID_POINTER) return FALSE;
95  }
96 
97  return TRUE;
98 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define TRUE
Definition: types.h:120
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1475
#define DIB_PAL_COLORS
Definition: wingdi.h:365
static HDC
Definition: imagelist.c:92
#define CBM_INIT
Definition: wingdi.h:364
smooth NULL
Definition: ftsmooth.c:416
HDC hdc
Definition: main.c:9
#define CBM_CREATDIB
#define INVALID_POINTER
#define DIB_RGB_COLORS
Definition: wingdi.h:366

Referenced by Test_CreateDIBitmap_Params().

◆ START_TEST()

START_TEST ( CreateDIBitmap  )

Definition at line 533 of file CreateDIBitmap.c.

534 {
535  InitStuff();
541 }
void Test_CreateDIBitmap_Params(void)
void Test_CreateDIBitmap1(void)
BOOL InitStuff(void)
Definition: init.c:95
void Test_CreateDIBitmap_RLE8()
void Test_CreateDIBitmap_DIB_PAL_COLORS(void)
void Test_CreateDIBitmap_CBM_CREATDIB(void)

◆ Test_CreateDIBitmap1()

void Test_CreateDIBitmap1 ( void  )

Definition at line 305 of file CreateDIBitmap.c.

306 {
307  BITMAPINFO bmi;
308  HBITMAP hbmp;
309  BITMAP bitmap;
310  ULONG bits[128] = {0};
311  BYTE rlebits[] = {2, 0, 0, 0, 2, 1, 0, 1};
312  HDC hdc;
313  int ret;
314 
315  hdc = GetDC(0);
316 
317  bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
318  bmi.bmiHeader.biWidth = 3;
319  bmi.bmiHeader.biHeight = 2;
320  bmi.bmiHeader.biPlanes = 1;
321  bmi.bmiHeader.biBitCount = 16;
323  bmi.bmiHeader.biSizeImage = 0;
324  bmi.bmiHeader.biXPelsPerMeter = 1;
325  bmi.bmiHeader.biYPelsPerMeter = 1;
326  bmi.bmiHeader.biClrUsed = 0;
327  bmi.bmiHeader.biClrImportant = 0;
328 
330  ok(hbmp != 0, "failed\n");
331 
332  ret = GetObject(hbmp, sizeof(bitmap), &bitmap);
333  ok(ret != 0, "failed\n");
334  ok(bitmap.bmType == 0, "\n");
335  ok(bitmap.bmWidth == 3, "\n");
336  ok(bitmap.bmHeight == 2, "\n");
337  ok_int(bitmap.bmWidthBytes, ((bitmap.bmWidth * bitmap.bmBitsPixel + 15) & ~15) / 8);
338  ok(bitmap.bmPlanes == 1, "\n");
339  ok(bitmap.bmBitsPixel == GetDeviceCaps(hdc, BITSPIXEL), "\n");
340  ok(bitmap.bmBits == 0, "\n");
341 
342  SetLastError(0);
344  bmi.bmiHeader.biBitCount = 8;
345  bmi.bmiHeader.biSizeImage = 8;
346  bmi.bmiHeader.biClrUsed = 1;
347  hbmp = CreateDIBitmap(hdc, &bmi.bmiHeader, CBM_INIT, rlebits, &bmi, DIB_PAL_COLORS);
348  ok(hbmp != 0, "failed\n");
349  ok(GetLastError() == 0, "GetLastError() == %ld\n", GetLastError());
350 
351  ret = GetObject(hbmp, sizeof(bitmap), &bitmap);
352  ok(ret != 0, "failed\n");
353  ok(bitmap.bmType == 0, "\n");
354  ok(bitmap.bmWidth == 3, "\n");
355  ok(bitmap.bmHeight == 2, "\n");
356  ok_int(bitmap.bmWidthBytes, ((bitmap.bmWidth * bitmap.bmBitsPixel + 15) & ~15) / 8);
357  ok(bitmap.bmPlanes == 1, "\n");
358  ok(bitmap.bmBitsPixel == GetDeviceCaps(hdc, BITSPIXEL), "\n");
359  ok(bitmap.bmBits == 0, "\n");
360 
361 
362 }
#define BITSPIXEL
Definition: wingdi.h:719
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1475
DWORD biClrImportant
Definition: amvideo.idl:40
#define DIB_PAL_COLORS
Definition: wingdi.h:365
HDC WINAPI GetDC(_In_opt_ HWND)
LONG biXPelsPerMeter
Definition: amvideo.idl:37
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
static HDC
Definition: imagelist.c:92
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
LONG biYPelsPerMeter
Definition: amvideo.idl:38
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
Definition: glext.h:10929
#define CBM_INIT
Definition: wingdi.h:364
DWORD biCompression
Definition: amvideo.idl:35
#define ok_int(expression, result)
Definition: atltest.h:134
HBITMAP hbmp
Definition: uimain.c:88
DWORD biSizeImage
Definition: amvideo.idl:36
#define SetLastError(x)
Definition: compat.h:418
#define GetObject
Definition: wingdi.h:4467
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)
int ret
HDC hdc
Definition: main.c:9
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
unsigned char BYTE
Definition: xxhash.c:193
#define ok(value,...)
Definition: atltest.h:57
Definition: bl.h:1331
unsigned int ULONG
Definition: retypes.h:1
static HBITMAP bitmap
Definition: clipboard.c:1344
static HBITMAP
Definition: button.c:44
#define DIB_RGB_COLORS
Definition: wingdi.h:366
#define BI_RLE8
Definition: wingdi.h:35
#define BI_RGB
Definition: precomp.h:47

Referenced by START_TEST().

◆ Test_CreateDIBitmap_CBM_CREATDIB()

void Test_CreateDIBitmap_CBM_CREATDIB ( void  )

Definition at line 417 of file CreateDIBitmap.c.

418 {
420  HDC hdc;
421  BITMAPINFO bmi =
422  {{sizeof(BITMAPINFOHEADER), 4, 4, 1, 8, BI_RGB, 0, 1, 1, 1, 0}, {{0,1,2,3}}};
423  BYTE ajBits[10] = {0,1,2,3,4,5,6,7,8,9};
424  BITMAP bitmap;
425  struct
426  {
427  BITMAPINFOHEADER bmiHeader;
428  WORD wColors[4];
429  } bmiRLE =
430  {
431  {sizeof(BITMAPINFOHEADER), 8, 2, 1, 8, BI_RLE8, 20, 1, 1, 4, 0},
432  {0, 1, 2, 7}
433  };
434  BYTE ajBitsRLE[] = {4,0, 0,2,0,1,0,2,3,1, 2,1, 2,2, 1,3,1,0,1,2, };
435 
436  hdc = CreateCompatibleDC(0);
437  if (hdc == NULL)
438  {
439  ok(0, "CreateCompatibleDC failed. Skipping tests!\n");
440  return;
441  }
442 
443  SetLastError(0xbadbad00);
445  ok(hbmp == 0, "CreateDIBitmap should fail.\n");
446  ok_int(GetLastError(), 0xbadbad00);
447 
449  ok(hbmp != 0, "CreateDIBitmap failed.\n");
450 
451  ok_long(GetObject(hbmp, sizeof(DIBSECTION), &bitmap), sizeof(BITMAP));
452  ok_int(bitmap.bmType, 0);
453  ok_int(bitmap.bmWidth, 4);
454  ok_int(bitmap.bmHeight, 4);
455  ok_int(bitmap.bmWidthBytes, 4);
456  ok_int(bitmap.bmPlanes, 1);
457  ok_int(bitmap.bmBitsPixel, 8);
458  ok_ptr(bitmap.bmBits, 0);
459 
461  ok(hbmpOld != NULL, "Couldn't select the bitmap.\n");
462 
463  /* Copy it on a dib section */
464  memset(gpDIB32, 0x77, sizeof(*gpDIB32));
465  ok_long(BitBlt(ghdcDIB32, 0, 0, 4, 4, hdc, 0, 0, SRCCOPY), 1);
466  ok_long((*gpDIB32)[0][0], 0x20100);
467  ok_long((*gpDIB32)[0][1], 0x20100);
468  ok_long((*gpDIB32)[0][2], 0x20100);
469  ok_long((*gpDIB32)[0][3], 0x20100);
470 
473 
475  ok(hbmp != 0, "CreateDIBitmap failed.\n");
476 
477  ok_long(GetObject(hbmp, sizeof(DIBSECTION), &bitmap), sizeof(BITMAP));
478  ok_int(bitmap.bmType, 0);
479  ok_int(bitmap.bmWidth, 4);
480  ok_int(bitmap.bmHeight, 4);
481  ok_int(bitmap.bmWidthBytes, 4);
482  ok_int(bitmap.bmPlanes, 1);
483  ok_int(bitmap.bmBitsPixel, 8);
484  ok_ptr(bitmap.bmBits, 0);
485 
486  /* Even with CBM_INIT and lpbmih != 0, pbmi is used for the dimensions */
487  hbmp = CreateDIBitmap(hdc, &bmiRLE.bmiHeader, CBM_CREATDIB | CBM_INIT, ajBits, &bmi, DIB_PAL_COLORS);
488  ok(hbmp != 0, "CreateDIBitmap failed.\n");
489 
490  ok_long(GetObject(hbmp, sizeof(DIBSECTION), &bitmap), sizeof(BITMAP));
491  ok_int(bitmap.bmType, 0);
492  ok_int(bitmap.bmWidth, 4);
493  ok_int(bitmap.bmHeight, 4);
494  ok_int(bitmap.bmWidthBytes, 4);
495  ok_int(bitmap.bmPlanes, 1);
496  ok_int(bitmap.bmBitsPixel, 8);
497  ok_ptr(bitmap.bmBits, 0);
498 
500  ok(hbmpOld != NULL, "Couldn't select the bitmap.\n");
501 
502  /* Copy it on a dib section */
503  memset(gpDIB32, 0x77, sizeof(*gpDIB32));
504  ok_long(BitBlt(ghdcDIB32, 0, 0, 4, 4, hdc, 0, 0, SRCCOPY), 1);
505 #if 0 // FIXME: fails on WHS testbot
506  ok_long((*gpDIB32)[0][0], 0);
507  ok_long((*gpDIB32)[0][1], 0);
508  ok_long((*gpDIB32)[0][2], 0);
509  ok_long((*gpDIB32)[0][3], 0);
510 #endif
511 
514 
515  hbmp = CreateDIBitmap(hdc, NULL, CBM_CREATDIB, ajBitsRLE, (PVOID)&bmiRLE, DIB_PAL_COLORS);
516  ok(hbmp == 0, "CreateDIBitmap should fail.\n");
517  hbmp = CreateDIBitmap(hdc, NULL, CBM_INIT | CBM_CREATDIB, ajBitsRLE, (PVOID)&bmiRLE, DIB_PAL_COLORS);
518  ok(hbmp == 0, "CreateDIBitmap should fail.\n");
519 
520  /* Check if a 0 pixel bitmap results in the DEFAULT_BITMAP being returned */
521  bmi.bmiHeader.biWidth = 0;
522  bmi.bmiHeader.biHeight = 4;
523  hbmp = CreateDIBitmap(hdc, &bmi.bmiHeader, CBM_CREATDIB, ajBits, &bmi, DIB_PAL_COLORS);
524  ok(hbmp == GetStockObject(21), "CreateDIBitmap didn't return the default bitmap.\n");
525  bmi.bmiHeader.biWidth = 23;
526  bmi.bmiHeader.biHeight = 0;
527  hbmp = CreateDIBitmap(hdc, &bmi.bmiHeader, CBM_CREATDIB, ajBits, &bmi, DIB_PAL_COLORS);
528  ok(hbmp == GetStockObject(21), "CreateDIBitmap didn't return the default bitmap.\n");
529 
530  DeleteDC(hdc);
531 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1475
#define DIB_PAL_COLORS
Definition: wingdi.h:365
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
static HDC
Definition: imagelist.c:92
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define ok_ptr(expression, result)
Definition: atltest.h:108
#define ok_long(expression, result)
Definition: atltest.h:133
ULONG(* gpDIB32)[8][8]
Definition: init.c:10
#define CBM_INIT
Definition: wingdi.h:364
HANDLE hbmpOld
Definition: magnifier.c:54
smooth NULL
Definition: ftsmooth.c:416
#define ok_int(expression, result)
Definition: atltest.h:134
HBITMAP hbmp
Definition: uimain.c:88
unsigned short WORD
Definition: ntddk_ex.h:93
#define SetLastError(x)
Definition: compat.h:418
#define GetObject
Definition: wingdi.h:4467
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
BOOL WINAPI DeleteDC(_In_ HDC)
#define ok(value,...)
Definition: atltest.h:57
Definition: bl.h:1331
#define CBM_CREATDIB
static HBITMAP bitmap
Definition: clipboard.c:1344
static HBITMAP
Definition: button.c:44
HDC ghdcDIB32
Definition: init.c:8
#define DIB_RGB_COLORS
Definition: wingdi.h:366
#define BI_RLE8
Definition: wingdi.h:35
#define memset(x, y, z)
Definition: compat.h:39
#define BI_RGB
Definition: precomp.h:47
#define SRCCOPY
Definition: wingdi.h:332
static VOID NTAPI BitBlt(_In_ ULONG Left, _In_ ULONG Top, _In_ ULONG Width, _In_ ULONG Height, _In_reads_bytes_(Delta *Height) PUCHAR Buffer, _In_ ULONG BitsPerPixel, _In_ ULONG Delta)
Definition: common.c:49

Referenced by START_TEST().

◆ Test_CreateDIBitmap_DIB_PAL_COLORS()

void Test_CreateDIBitmap_DIB_PAL_COLORS ( void  )

Definition at line 256 of file CreateDIBitmap.c.

257 {
258  struct
259  {
260  BITMAPINFOHEADER bmiHeader;
261  WORD bmiColors[8];
262  } bmibuffer;
263  BITMAPINFO *pbmi = (PVOID)&bmibuffer;
264  HBITMAP hbmp;
265  ULONG bits[16] = {0};
266  HDC hdc;
267  HPALETTE hpalOld;
268  USHORT i;
269 
270  hdc = CreateCompatibleDC(0);
271  ok(hdc != 0, "failed\n");
272 
273  /* Select a palette */
274  hpalOld = SelectPalette(hdc, ghpal, FALSE);
275  ok(hpalOld != NULL, "error=%ld\n", GetLastError());
276 
277  /* Initialize a BITMAPINFO */
279  pbmi->bmiHeader.biWidth = 2;
280  pbmi->bmiHeader.biHeight = -2;
281  pbmi->bmiHeader.biPlanes = 1;
287  pbmi->bmiHeader.biClrUsed = 8;
289 
290  for( i = 0; i < 8; i++ )
291  {
292  bmibuffer.bmiColors[i] = i;
293  }
294 
295  /* Create the bitmap */
297  ok(hbmp != 0, "failed\n");
298 
300 
301 
302 }
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1475
DWORD biClrImportant
Definition: amvideo.idl:40
#define DIB_PAL_COLORS
Definition: wingdi.h:365
HPALETTE ghpal
Definition: init.c:11
_In_ HBITMAP _In_ UINT _In_ UINT _Inout_ LPBITMAPINFO pbmi
Definition: ntgdi.h:2780
LONG biXPelsPerMeter
Definition: amvideo.idl:37
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
static HDC
Definition: imagelist.c:92
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
LONG biYPelsPerMeter
Definition: amvideo.idl:38
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
Definition: glext.h:10929
#define CBM_INIT
Definition: wingdi.h:364
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
DWORD biCompression
Definition: amvideo.idl:35
HPALETTE WINAPI SelectPalette(_In_ HDC, _In_ HPALETTE, _In_ BOOL)
smooth NULL
Definition: ftsmooth.c:416
void * PVOID
Definition: retypes.h:9
HBITMAP hbmp
unsigned short WORD
Definition: ntddk_ex.h:93
DWORD biSizeImage
Definition: amvideo.idl:36
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 short USHORT
Definition: pedump.c:61
#define ok(value,...)
Definition: atltest.h:57
unsigned int ULONG
Definition: retypes.h:1
static HBITMAP
Definition: button.c:44
#define BI_RGB
Definition: precomp.h:47

Referenced by START_TEST().

◆ Test_CreateDIBitmap_Params()

void Test_CreateDIBitmap_Params ( void  )

Definition at line 102 of file CreateDIBitmap.c.

103 {
104  HBITMAP hbmp;
105  HDC hdc;
106  BITMAPINFO bmi =
107  {{sizeof(BITMAPINFOHEADER), 4, 4, 1, 8, BI_RGB, 0, 1, 1, 1, 0}, {{0,0,0,0}}};
108  BITMAPINFO bmiBroken =
109  {{0, -2, -4, 55, 42, 21, 0, 1, 1, 1, 0}, {{0,0,0,0}}};
110  BYTE ajBits[10];
111 
112  hdc = CreateCompatibleDC(0);
113  ok(hdc != 0, "failed\n");
114 
115  hbmp = CreateDIBitmap(hdc, &bmi.bmiHeader, CBM_INIT, ajBits, &bmi, DIB_PAL_COLORS);
116  ok(hbmp != 0, "\n");
117 
119  ok(hbmp != 0, "\n");
120 
122  ok(hbmp != 0, "\n");
123 
125  ok(hbmp != 0, "\n");
126 
128  ok(hbmp != 0, "\n");
129 
130  hbmp = CreateDIBitmap(hdc, &bmi.bmiHeader, CBM_INIT, NULL, &bmiBroken, DIB_PAL_COLORS);
131  ok(hbmp != 0, "\n");
132 
133  hbmp = CreateDIBitmap(NULL, NULL, 2, NULL, &bmi, 0);
134  ok(hbmp != 0, "\n");
135 
136  SetLastError(0xbadbad00);
137  hbmp = CreateDIBitmap(hdc, NULL, CBM_INIT, ajBits, &bmi, DIB_PAL_COLORS);
138  ok(hbmp == 0, "\n");
140 
141  SetLastError(0xbadbad00);
143  ok(hbmp == 0, "\n");
145 
146  SetLastError(0xbadbad00);
147  hbmp = CreateDIBitmap(hdc, &bmi.bmiHeader, CBM_INIT, ajBits, &bmi, 2);
148  ok(hbmp == 0, "\n");
150 
151  SetLastError(0xbadbad00);
153  ok(hbmp == 0, "\n");
154  ok_err(0xbadbad00);
155 
156  SetLastError(0xbadbad00);
158  ok(hbmp == 0, "\n");
159  ok_err(0xbadbad00);
160 
161  SetLastError(0xbadbad00);
162  _SEH2_TRY
163  {
165  }
167  {
168  hbmp = (HBITMAP)-1;
169  }
170  _SEH2_END;
171  ok(hbmp == (HBITMAP)-1, "\n");
172  ok_err(0xbadbad00);
173 
174  SetLastError(0xbadbad00);
176  ok(hbmp == 0, "\n");
178 
179  SetLastError(0xbadbad00);
181  ok(hbmp == 0, "\n");
182  ok_err(0xbadbad00);
183 
184  SetLastError(0xbadbad00);
185  hbmp = CreateDIBitmap(hdc, &bmiBroken.bmiHeader, CBM_INIT, NULL, &bmi, DIB_PAL_COLORS);
186  ok(hbmp == 0, "\n");
188 
189  if (1)
190  {
191  ULONG i1, i2, i3, i4, i5, i6;
192  HDC ahdc[3] = {0, hdc, (HDC)-1};
193  PBITMAPINFOHEADER apbih[4] = {NULL, &bmi.bmiHeader, &bmiBroken.bmiHeader, INVALID_POINTER};
194  ULONG afInitf[12] = {0, 1, CBM_CREATDIB, 3, CBM_INIT, 5, 6, 7, 8, 0x10, 0x20};
195  PVOID apvBits[3] = {NULL, ajBits, INVALID_POINTER};
196  PBITMAPINFO apbmi[4] = {NULL, &bmi, &bmiBroken, INVALID_POINTER};
197  ULONG aiUsage[5] = {0, 1, 2, 3, 23};
198  DWORD dwExpError;
199  BOOL bExpSuccess;
200 
201  for (i1 = 0; i1 < ARRAYSIZE(ahdc); i1++)
202  {
203  for (i2 = 0; i2 < ARRAYSIZE(apbih); i2++)
204  {
205  for (i3 = 0; i3 < ARRAYSIZE(afInitf); i3++)
206  {
207  for (i4 = 0; i4 < ARRAYSIZE(apvBits); i4++)
208  {
209  for (i5 = 0; i5 < ARRAYSIZE(apbmi); i5++)
210  {
211  for (i6 = 0; i6 < ARRAYSIZE(aiUsage); i6++)
212  {
213  SetLastError(0xbadbad00);
214  dwExpError = 0xbadbad00;
215 
216  bExpSuccess = GetExpected(&dwExpError, ahdc[i1], apbih[i2], afInitf[i3], apvBits[i4], apbmi[i5], aiUsage[i6]);
217 
218  _SEH2_TRY
219  {
220  hbmp = CreateDIBitmap(ahdc[i1], apbih[i2], afInitf[i3], apvBits[i4], apbmi[i5], aiUsage[i6]);
221  }
223  {
224  hbmp = (HBITMAP)0;
225  }
226  _SEH2_END;
227 
228  if (bExpSuccess)
229  {
230  ok(hbmp != 0, "Expected success for (%ld,%ld,%ld,%ld,%ld,%ld) CreateDIBitmap(%p, %p, 0x%lx, %p, %p, %ld)\n",
231  i1, i2, i3, i4, i5, i6,
232  ahdc[i1], apbih[i2], afInitf[i3], apvBits[i4], apbmi[i5], aiUsage[i6]);
233  }
234  else
235  {
236  ok(hbmp == 0, "Expected failure for (%ld,%ld,%ld,%ld,%ld,%ld) CreateDIBitmap(%p, %p, 0x%lx, %p, %p, %ld)\n",
237  i1, i2, i3, i4, i5, i6,
238  ahdc[i1], apbih[i2], afInitf[i3], apvBits[i4], apbmi[i5], aiUsage[i6]);
239  }
240 
241  // ok(GetLastError() == dwExpError, "Expected error %ld got %ld for (%ld,%ld,%ld,%ld,%ld,%ld) CreateDIBitmap(%p, %p, 0x%lx, %p, %p, %ld)\n",
242  // dwExpError, GetLastError(), i1, i2, i3, i4, i5, i6,
243  // ahdc[i1], apbih[i2], afInitf[i3], apvBits[i4], apbmi[i5], aiUsage[i6]);
244  }
245  }
246  }
247  }
248  }
249  }
250  }
251 
252 
253 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1475
#define DIB_PAL_COLORS
Definition: wingdi.h:365
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
static HDC
Definition: imagelist.c:92
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
_SEH2_TRY
Definition: create.c:4226
#define CBM_INIT
Definition: wingdi.h:364
unsigned int BOOL
Definition: ntddk_ex.h:94
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
HBITMAP hbmp
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:418
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
#define ok_err(error)
Definition: atltest.h:124
unsigned char BYTE
Definition: xxhash.c:193
_SEH2_END
Definition: create.c:4400
#define ok(value,...)
Definition: atltest.h:57
#define CBM_CREATDIB
unsigned int ULONG
Definition: retypes.h:1
#define INVALID_POINTER
static HBITMAP
Definition: button.c:44
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
BOOL GetExpected(DWORD *pdwError, HDC hdc, const BITMAPINFOHEADER *lpbmih, DWORD fdwInit, const VOID *lpbInit, const BITMAPINFO *lpbmi, UINT fuUsage)
#define BI_RGB
Definition: precomp.h:47

Referenced by START_TEST().

◆ Test_CreateDIBitmap_RLE8()

void Test_CreateDIBitmap_RLE8 ( )

Definition at line 364 of file CreateDIBitmap.c.

365 {
366  struct
367  {
368  BITMAPINFOHEADER bmiHeader;
369  WORD wColors[4];
370  BYTE ajBuffer[20];
371  } PackedDIB =
372  {
373  {sizeof(BITMAPINFOHEADER), 4, 4, 1, 8, BI_RLE8, 20, 1, 1, 4, 0},
374  {0, 1, 2, 7},
375  {4,0, 0,2,0,1,0,2,3,1, 2,1, 2,2, 1,3,1,0,1,2, },
376  };
377  HDC hdc;
378  HBITMAP hbmp;
379 
380  hdc = CreateCompatibleDC(0);
381 
382  SetLastError(0xbadbad00);
383  hbmp = CreateDIBitmap(hdc, &PackedDIB.bmiHeader, CBM_INIT, &PackedDIB.ajBuffer, (PVOID)&PackedDIB, DIB_PAL_COLORS);
384  ok(hbmp != 0, "CreateDIBitmap failed.\n");
385  ok_err(0xbadbad00);
387 
388  PackedDIB.bmiHeader.biSizeImage = 2;
389  hbmp = CreateDIBitmap(hdc, &PackedDIB.bmiHeader, CBM_INIT, &PackedDIB.ajBuffer, (PVOID)&PackedDIB, DIB_PAL_COLORS);
390  ok(hbmp != 0, "CreateDIBitmap failed.\n");
391  ok_err(0xbadbad00);
393 
394  PackedDIB.bmiHeader.biSizeImage = 1;
395  hbmp = CreateDIBitmap(hdc, &PackedDIB.bmiHeader, CBM_INIT, &PackedDIB.ajBuffer, (PVOID)&PackedDIB, DIB_PAL_COLORS);
396  ok(hbmp != 0, "CreateDIBitmap failed.\n");
397  ok_err(0xbadbad00);
399 
400  PackedDIB.bmiHeader.biSizeImage = 0;
401  hbmp = CreateDIBitmap(hdc, &PackedDIB.bmiHeader, CBM_INIT, &PackedDIB.ajBuffer, (PVOID)&PackedDIB, DIB_PAL_COLORS);
402  ok(hbmp == 0, "CreateDIBitmap succeeded, expected failure\n");
403  ok_err(0xbadbad00);
404 
405  /* Test a line that is too long */
406  PackedDIB.bmiHeader.biSizeImage = 20;
407  PackedDIB.ajBuffer[0] = 17;
408  hbmp = CreateDIBitmap(hdc, &PackedDIB.bmiHeader, CBM_INIT, &PackedDIB.ajBuffer, (PVOID)&PackedDIB, DIB_PAL_COLORS);
409  ok(hbmp != 0, "CreateDIBitmap failed\n");
410  ok_err(0xbadbad00);
412 
413 
414 }
#define DIB_PAL_COLORS
Definition: wingdi.h:365
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
static HDC
Definition: imagelist.c:92
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define CBM_INIT
Definition: wingdi.h:364
HBITMAP hbmp
unsigned short WORD
Definition: ntddk_ex.h:93
#define SetLastError(x)
Definition: compat.h:418
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
#define ok_err(error)
Definition: atltest.h:124
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

Referenced by START_TEST().