[PATCH] d3drm/tests: Add tests for IDirect3DRM*::LoadTexture (try 5).
Aaryaman Vasishta
jem456.vasishta at gmail.com
Sun Dec 27 04:23:38 CST 2015
try 5: Add odd/even width tests and remove some more redundancies.
Added bitmap generation function to generate bitmaps at runtime.
Signed-off-by: Aaryaman Vasishta <jem456.vasishta at gmail.com>
---
dlls/d3drm/tests/Makefile.in | 2 +-
dlls/d3drm/tests/d3drm.c | 404 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 405 insertions(+), 1 deletion(-)
diff --git a/dlls/d3drm/tests/Makefile.in b/dlls/d3drm/tests/Makefile.in
index 4b39989..76613e2 100644
--- a/dlls/d3drm/tests/Makefile.in
+++ b/dlls/d3drm/tests/Makefile.in
@@ -1,5 +1,5 @@
TESTDLL = d3drm.dll
-IMPORTS = dxguid uuid d3drm ddraw user32
+IMPORTS = dxguid uuid d3drm ddraw user32 gdi32
C_SRCS = \
d3drm.c \
diff --git a/dlls/d3drm/tests/d3drm.c b/dlls/d3drm/tests/d3drm.c
index 06c2c54..f99032a 100644
--- a/dlls/d3drm/tests/d3drm.c
+++ b/dlls/d3drm/tests/d3drm.c
@@ -2,6 +2,7 @@
* Copyright 2010, 2012 Christian Costa
* Copyright 2012 André Hentschel
* Copyright 2011-2014 Henri Verbeet for CodeWeavers
+ * Copyright 2014-2015 Aaryaman Vasishta
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -3693,6 +3694,406 @@ static void test_create_device_from_d3d3(void)
DestroyWindow(window);
}
+static char *create_bitmap(const char *filename, int w, int h, BOOL palettized)
+{
+ static char path[MAX_PATH];
+ HANDLE file;
+ HBITMAP hbitmap;
+ BITMAPFILEHEADER file_header;
+ BITMAPINFOHEADER info_header;
+ BITMAPINFO *info = NULL;
+ const int bpp = palettized ? 8 : 24;
+ unsigned char *buffer = NULL;
+ DWORD written, size;
+ int i, j;
+
+ /* Calculate size of the BITMAPINFO header */
+ /* Space for 256 color palette would need to be allocated if the bitmap is 8bpp */
+ size = sizeof(BITMAPINFOHEADER);
+ if (palettized)
+ size += sizeof(RGBQUAD)* 256;
+
+ memset(&file_header, 0, sizeof(BITMAPFILEHEADER));
+ file_header.bfType = 0x4d42; /* BM */
+ file_header.bfOffBits = sizeof(BITMAPFILEHEADER)+size;
+ file_header.bfSize = ((((w * bpp + 31) & ~31) >> 3) * h) + file_header.bfOffBits;
+ memset(&info_header, 0, sizeof(BITMAPINFOHEADER));
+ info_header.biSize = sizeof(BITMAPINFOHEADER);
+ info_header.biBitCount = bpp;
+ info_header.biPlanes = 1;
+ info_header.biWidth = w;
+ info_header.biHeight = h;
+ info_header.biCompression = BI_RGB;
+
+ if (palettized)
+ {
+ info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
+ /* Create a 256 color palette for 8bpp bitmap */
+ for (i = 0; i < 256; i++)
+ {
+ info->bmiColors[i].rgbBlue = i;
+ info->bmiColors[i].rgbGreen = i;
+ info->bmiColors[i].rgbRed = i;
+ }
+ }
+ else
+ info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*info));
+ info->bmiHeader = info_header;
+
+ /* Create the bitmap file */
+ GetTempPathA(sizeof(path) / sizeof(char), path);
+ lstrcatA(path, filename);
+ file = CreateFileA(path, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
+ ok(file != INVALID_HANDLE_VALUE, "file creation failed, at %s, error %d\n", path,
+ GetLastError());
+
+ /* Write the file header, followed by the BITMAPINFO header */
+ WriteFile(file, &file_header, sizeof(BITMAPFILEHEADER), &written, NULL);
+ ok(written == sizeof(BITMAPFILEHEADER), "Couldn't write bitmap file header.\n");
+ WriteFile(file, info, size, &written, NULL);
+ ok(written == size, "Couldn't write bitmap info header.\n");
+
+ hbitmap = CreateDIBSection(NULL, info, DIB_RGB_COLORS, (void **)&buffer, 0, 0);
+ ok(hbitmap != (HBITMAP)ERROR_INVALID_PARAMETER, "Could not create bitmap.\n");
+
+ size = w * h * (bpp / 8);
+ /* Saving pixels by directly accessing bitmap buffer is faster than using SetPixel */
+ for (i = 0, j = 0; i < size;)
+ {
+ if (palettized)
+ {
+ buffer[i++] = j;
+ buffer[i++] = j;
+ buffer[i++] = j++;
+ j %= 256;
+ }
+ else
+ {
+ buffer[i] = i % 256;
+ i++;
+ buffer[i] = j % 256;
+ i++;
+ j = (j % w) + 1;
+ }
+ }
+
+ /* Finally, write the bitmap pixels */
+ size = file_header.bfSize;
+ WriteFile(file, buffer, size, &written, NULL);
+ ok(written == size, "Couldn't write bitmap pixels.\n");
+
+ CloseHandle(file);
+ DeleteObject(hbitmap);
+
+ return path;
+}
+
+static BOOL test_bitmap_data(const char *test_name, const char *file, D3DRMIMAGE *img, BOOL upside_down)
+{
+ const int w = img->width;
+ const int h = img->height;
+ int i, j, k = 0, offset, depth, expected;
+ BOOL val1, val2, val3;
+ BITMAPFILEHEADER *bmp_header = NULL;
+ BITMAPINFO *bmp_info = NULL;
+ BITMAPINFOHEADER info_header;
+ HANDLE hfile = NULL, hmapping = NULL;
+ DWORD size;
+ BOOL check;
+ unsigned char *buffer = NULL, *buffer1 = NULL, *buffer2 = NULL;
+
+ buffer1 = (unsigned char *)img->buffer1;
+ hfile = CreateFileA(file, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
+ ok(file != INVALID_HANDLE_VALUE, "Failed to open file at %s, error %d\n", file,
+ GetLastError());
+ if (hfile == INVALID_HANDLE_VALUE)
+ goto cleanup;
+
+ size = GetFileSize(hfile, NULL);
+ ok(size != INVALID_FILE_SIZE, "Failed to get file size, error %d\n", GetLastError());
+
+ hmapping = CreateFileMappingA(hfile, NULL, PAGE_READONLY, 0, 0, NULL);
+ ok(hmapping != NULL, "Cannot create file mapping (error = %d).\n", GetLastError());
+ if (hmapping == NULL)
+ goto cleanup;
+
+ buffer = MapViewOfFile(hmapping, FILE_MAP_READ, 0, 0, 0);
+ ok(buffer != NULL, "Cannot create map view of file (error = %d).\n", GetLastError());
+ if (buffer == NULL)
+ goto cleanup;
+
+ bmp_header = (BITMAPFILEHEADER *)buffer;
+ bmp_info = (BITMAPINFO *)((unsigned char *)buffer + sizeof(BITMAPFILEHEADER));
+ info_header = bmp_info->bmiHeader;
+ ok(info_header.biWidth == w, "Expected texture width == %d, got %d.\n", info_header.biWidth, w);
+ ok(info_header.biHeight == h, "Expected texture height == %d, got %d.\n", info_header.biHeight, h);
+ depth = info_header.biBitCount;
+
+ buffer2 = (unsigned char *)buffer + bmp_header->bfOffBits;
+
+ if (img->palette)
+ {
+ ok(img->depth == 8, "Expected texture bpp == 8, got %d.\n", img->depth);
+ /* d3drm aligns bytes_per_line to the nearest multiple of 4 from the texture width */
+ if (info_header.biWidth % 4 != 0)
+ expected = (info_header.biWidth & ~0x03) + 4;
+ else
+ expected = info_header.biWidth;
+ ok(expected == img->bytes_per_line, "Expected bytes per line == %d, got %d.\n", expected, img->bytes_per_line);
+ if (depth == 8)
+ {
+ for (i = 0; i < h; i++)
+ {
+ offset = upside_down ? (img->bytes_per_line * (h - i - 1)) : (img->bytes_per_line * i);
+ for (j = 0; j < img->bytes_per_line; j++)
+ {
+ if (buffer1[k++] != buffer2[offset++])
+ return FALSE;
+ }
+ }
+ }
+ else
+ {
+ /* The image is palettized if the total number of colors used is <= 256. */
+ for (i = 0; i < h; i++)
+ {
+ offset = upside_down ? (w * (h - i - 1) * 3) : (w * i * 3);
+ for (j = 0; j < w; j++)
+ {
+ val1 = img->palette[buffer1[k]].blue == buffer2[offset];
+ val2 = img->palette[buffer1[k]].green == buffer2[offset + 1];
+ val3 = img->palette[buffer1[k]].red == buffer2[offset + 2];
+ if (!(val1 && val2 && val3))
+ return FALSE;
+ k++;
+ /* Take into account padded bytes after every row for odd widths */
+ if ((w % 2 == 1) && (j == w - 1))
+ k = (k & ~0x03) + 4;
+ offset += 3;
+ }
+ }
+ }
+ }
+ else
+ {
+ /* d3drm aligns the 24bpp texture to 4 bytes in the buffer, with one bype padding from 24bpp texture. */
+ ok(img->depth == 32, "Expected texture bpp == 32, got %d.\n", img->depth);
+ expected = info_header.biWidth * 4;
+ ok(expected == img->bytes_per_line, "Expected bytes per line == %d, got %d.\n", expected, img->bytes_per_line);
+ for (i = 0; i < h; i++)
+ {
+ offset = upside_down ? (w * (h - i - 1) * 3) : (w * i * 3);
+ for (j = 0; j < w; j++)
+ {
+ val1 = buffer1[k] == buffer2[offset];
+ val2 = buffer1[k + 1] == buffer2[offset + 1];
+ val3 = buffer1[k + 2] == buffer2[offset + 2];
+ if (!(val1 && val2 && val3))
+ return FALSE;
+ k += 4;
+ offset += 3;
+ }
+ }
+ }
+
+cleanup:
+ UnmapViewOfFile(buffer);
+ CloseHandle(hmapping);
+ CloseHandle(hfile);
+ check = DeleteFileA(file);
+ ok(check, "Cannot delete image stored in %s (error = %d, test:%s).\n", file, GetLastError(), test_name);
+ return TRUE;
+}
+
+static void test_load_texture1(void)
+{
+ HRESULT hr;
+ IDirect3DRM *d3drm1 = NULL;
+ IDirect3DRMTexture *texture1 = NULL;
+ D3DRMIMAGE *d3drm_img = NULL;
+ BOOL check;
+ char *file = NULL;
+
+ hr = Direct3DRMCreate(&d3drm1);
+ ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
+
+ file = create_bitmap("8bpp.bmp", 100, 100, TRUE);
+ hr = IDirect3DRM_LoadTexture(d3drm1, file, &texture1);
+ ok(SUCCEEDED(hr), "Failed to load texture (hr = %x).\n", hr);
+ d3drm_img = IDirect3DRMTexture_GetImage(texture1);
+ todo_wine ok(d3drm_img != NULL, "Could not get a D3DRMIMAGE struct from texture.\n");
+ if (d3drm_img == NULL)
+ goto cleanup;
+ /* Test how d3drm loads bitmap textures by matching with raw bitmap contents */
+ check = test_bitmap_data("ver 1 8bpp", file, d3drm_img, FALSE);
+ ok(check, "Buffer contents do not match that of bitmap.\n");
+ IDirect3DRMTexture_Release(texture1);
+
+ file = create_bitmap("24bpp.bmp", 100, 100, FALSE);
+ hr = IDirect3DRM_LoadTexture(d3drm1, file, &texture1);
+ ok(SUCCEEDED(hr), "Failed to load texture (hr = %x).\n", hr);
+ d3drm_img = IDirect3DRMTexture_GetImage(texture1);
+ todo_wine ok(d3drm_img != NULL, "Could not get a D3DRMIMAGE struct from texture.\n");
+ check = test_bitmap_data("ver 1 24bpp", file, d3drm_img, FALSE);
+ ok(check, "Buffer contents do not match that of bitmap.\n");
+ IDirect3DRMTexture_Release(texture1);
+
+ file = create_bitmap("24bpp_palette_odd.bmp", 3, 39, FALSE);
+ hr = IDirect3DRM_LoadTexture(d3drm1, file, &texture1);
+ ok(SUCCEEDED(hr), "Failed to load texture (hr = %x).\n", hr);
+ d3drm_img = IDirect3DRMTexture_GetImage(texture1);
+ todo_wine ok(d3drm_img != NULL, "Could not get a D3DRMIMAGE struct from texture.\n");
+ check = test_bitmap_data("ver 1 24bpp_palette_odd", file, d3drm_img, FALSE);
+ ok(check, "Buffer contents do not match that of bitmap.\n");
+ IDirect3DRMTexture_Release(texture1);
+
+ file = create_bitmap("24bpp_palette_even.bmp", 4, 39, FALSE);
+ hr = IDirect3DRM_LoadTexture(d3drm1, file, &texture1);
+ ok(SUCCEEDED(hr), "Failed to load texture (hr = %x).\n", hr);
+ d3drm_img = IDirect3DRMTexture_GetImage(texture1);
+ todo_wine ok(d3drm_img != NULL, "Could not get a D3DRMIMAGE struct from texture.\n");
+ check = test_bitmap_data("ver 1 24bpp_palette_even", file, d3drm_img, FALSE);
+ ok(check, "Buffer contents do not match that of bitmap.\n");
+
+cleanup:
+ IDirect3DRMTexture_Release(texture1);
+ IDirect3DRM_Release(d3drm1);
+}
+
+static void test_load_texture2(void)
+{
+ HRESULT hr;
+ IDirect3DRM *d3drm1 = NULL;
+ IDirect3DRM2 *d3drm2 = NULL;
+ IDirect3DRMTexture2 *texture2 = NULL;
+ D3DRMIMAGE *d3drm_img = NULL;
+ BOOL check;
+ char *file;
+
+ hr = Direct3DRMCreate(&d3drm1);
+ ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
+
+ hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM2, (void **)&d3drm2);
+ ok(SUCCEEDED(hr), "Cannot get IDirect3DRM2 interface (hr = %x)\n", hr);
+
+ file = create_bitmap("8bpp.bmp", 100, 100, TRUE);
+ hr = IDirect3DRM2_LoadTexture(d3drm2, file, &texture2);
+ ok(SUCCEEDED(hr), "Failed to load texture (hr = %x).\n", hr);
+ d3drm_img = IDirect3DRMTexture2_GetImage(texture2);
+ todo_wine ok(d3drm_img != NULL, "Could not get a D3DRMIMAGE struct from texture.\n");
+ if (d3drm_img == NULL)
+ goto cleanup;
+ /* Test how d3drm loads bitmap textures by matching with raw bitmap contents */
+ check = test_bitmap_data("ver 2 8bpp", file, d3drm_img, TRUE);
+ ok(check, "Buffer contents do not match that of bitmap.\n");
+ IDirect3DRMTexture2_Release(texture2);
+
+ file = create_bitmap("24bpp.bmp", 100, 100, FALSE);
+ hr = IDirect3DRM2_LoadTexture(d3drm2, file, &texture2);
+ ok(SUCCEEDED(hr), "Failed to load texture (hr = %x).\n", hr);
+ d3drm_img = IDirect3DRMTexture2_GetImage(texture2);
+ todo_wine ok(d3drm_img != NULL, "Could not get a D3DRMIMAGE struct from texture.\n");
+ check = test_bitmap_data("ver 2 24bpp", file, d3drm_img, TRUE);
+ ok(check, "Buffer contents do not match that of bitmap.\n");
+ IDirect3DRMTexture2_Release(texture2);
+
+ file = create_bitmap("24bpp_palette_odd.bmp", 3, 39, FALSE);
+ hr = IDirect3DRM2_LoadTexture(d3drm2, file, &texture2);
+ ok(SUCCEEDED(hr), "Failed to load texture (hr = %x).\n", hr);
+ d3drm_img = IDirect3DRMTexture2_GetImage(texture2);
+ todo_wine ok(d3drm_img != NULL, "Could not get a D3DRMIMAGE struct from texture.\n");
+ check = test_bitmap_data("ver 2 24bpp_palette_odd", file, d3drm_img, TRUE);
+ ok(check, "Buffer contents do not match that of bitmap.\n");
+ IDirect3DRMTexture2_Release(texture2);
+
+ file = create_bitmap("24bpp_palette_even.bmp", 4, 39, FALSE);
+ hr = IDirect3DRM2_LoadTexture(d3drm2, file, &texture2);
+ ok(SUCCEEDED(hr), "Failed to load texture (hr = %x).\n", hr);
+ d3drm_img = IDirect3DRMTexture2_GetImage(texture2);
+ todo_wine ok(d3drm_img != NULL, "Could not get a D3DRMIMAGE struct from texture.\n");
+ check = test_bitmap_data("ver 2 24bpp_palette_even", file, d3drm_img, TRUE);
+ ok(check, "Buffer contents do not match that of bitmap.\n");
+
+cleanup:
+ IDirect3DRMTexture2_Release(texture2);
+ IDirect3DRM2_Release(d3drm2);
+ IDirect3DRM_Release(d3drm1);
+}
+
+static void test_load_texture3(void)
+{
+ HRESULT hr;
+ IDirect3DRM *d3drm1 = NULL;
+ IDirect3DRM3 *d3drm3 = NULL;
+ IDirect3DRMTexture *texture1 = NULL;
+ IDirect3DRMTexture3 *texture3 = NULL;
+ D3DRMIMAGE *d3drm_img = NULL;
+ BOOL check;
+ char *file = NULL;
+
+ hr = Direct3DRMCreate(&d3drm1);
+ ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
+
+ hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
+ ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %x)\n", hr);
+
+ file = create_bitmap("8bpp.bmp", 100, 100, TRUE);
+ hr = IDirect3DRM3_LoadTexture(d3drm3, file, &texture3);
+ ok(SUCCEEDED(hr), "Failed to load texture (hr = %x).\n", hr);
+ d3drm_img = IDirect3DRMTexture3_GetImage(texture3);
+ todo_wine ok(d3drm_img != NULL, "Could not get a D3DRMIMAGE struct from texture.\n");
+ if (d3drm_img == NULL)
+ goto cleanup;
+ /* Test how d3drm loads bitmap textures by matching with raw bitmap contents */
+ check = test_bitmap_data("ver 3 8bpp", file, d3drm_img, TRUE);
+ ok(check, "Buffer contents do not match that of bitmap.\n");
+ IDirect3DRMTexture3_Release(texture3);
+
+ file = create_bitmap("24bpp.bmp", 100, 100, FALSE);
+ hr = IDirect3DRM3_LoadTexture(d3drm3, file, &texture3);
+ ok(SUCCEEDED(hr), "Failed to load texture (hr = %x).\n", hr);
+ d3drm_img = IDirect3DRMTexture3_GetImage(texture3);
+ todo_wine ok(d3drm_img != NULL, "Could not get a D3DRMIMAGE struct from texture.\n");
+ check = test_bitmap_data("ver 3 24bpp", file, d3drm_img, TRUE);
+ ok(check, "Buffer contents do not match that of bitmap.\n");
+ IDirect3DRMTexture3_Release(texture3);
+
+ file = create_bitmap("24bpp_palette_odd.bmp", 3, 39, FALSE);
+ hr = IDirect3DRM3_LoadTexture(d3drm3, file, &texture3);
+ ok(SUCCEEDED(hr), "Failed to load texture (hr = %x).\n", hr);
+ d3drm_img = IDirect3DRMTexture3_GetImage(texture3);
+ todo_wine ok(d3drm_img != NULL, "Could not get a D3DRMIMAGE struct from texture.\n");
+ check = test_bitmap_data("ver 3 24bpp_palette_odd", file, d3drm_img, TRUE);
+ ok(check, "Buffer contents do not match that of bitmap.\n");
+ IDirect3DRMTexture3_Release(texture3);
+
+ file = create_bitmap("24bpp_palette_even.bmp", 4, 39, FALSE);
+ hr = IDirect3DRM3_LoadTexture(d3drm3, file, &texture3);
+ ok(SUCCEEDED(hr), "Failed to load texture (hr = %x).\n", hr);
+ d3drm_img = IDirect3DRMTexture3_GetImage(texture3);
+ todo_wine ok(d3drm_img != NULL, "Could not get a D3DRMIMAGE struct from texture.\n");
+ check = test_bitmap_data("ver 3 24bpp_palette_even", file, d3drm_img, TRUE);
+ ok(check, "Buffer contents do not match that of bitmap.\n");
+ IDirect3DRMTexture3_Release(texture3);
+
+ /* Test whether querying a version 1 texture from version 3 causes a change in the loading behavior */
+ file = create_bitmap("24bpp_palette.bmp", 3, 39, FALSE);
+ hr = IDirect3DRM3_LoadTexture(d3drm3, file, &texture3);
+ ok(SUCCEEDED(hr), "Failed to load texture (hr = %x).\n", hr);
+ hr = IDirect3DRMTexture3_QueryInterface(texture3, &IID_IDirect3DRMTexture, (void **)&texture1);
+ ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture interface (hr = %x)\n", hr);
+ d3drm_img = IDirect3DRMTexture_GetImage(texture1);
+ check = test_bitmap_data("ver 3->1 24bpp_palette", file, d3drm_img, TRUE);
+ ok(check, "Buffer contents do not match that of bitmap.\n");
+
+cleanup:
+ if (texture1)
+ IDirect3DRMTexture_Release(texture1);
+ IDirect3DRMTexture3_Release(texture3);
+ IDirect3DRM3_Release(d3drm3);
+ IDirect3DRM_Release(d3drm1);
+}
+
START_TEST(d3drm)
{
test_MeshBuilder();
@@ -3720,4 +4121,7 @@ START_TEST(d3drm)
test_create_device_from_d3d1();
test_create_device_from_d3d2();
test_create_device_from_d3d3();
+ test_load_texture1();
+ test_load_texture2();
+ test_load_texture3();
}
--
2.3.2 (Apple Git-55)
More information about the wine-patches
mailing list