try 10: Fix XP test failures.
Added bitmap generation function to generate bitmaps at runtime.
Signed-off-by: Aaryaman Vasishta <jem456.vasishta@gmail.com>
---
��dlls/d3drm/tests/Makefile.in |�� ��2 +-
��dlls/d3drm/tests/d3drm.c�� �� ��| 320 +++++++++++++++++++++++++++++++++++++++++++
��2 files changed, 321 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..9cabbe6 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,324 @@ 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;
+�� �� 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");
+
+�� �� size = file_header.bfSize;
+�� �� buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
+
+�� �� /* Saving pixels by directly accessing bitmap buffer is faster than using SetPixel */
+�� �� for (i = 0, j = 0; i < size;)
+�� �� {
+�� �� �� �� if (palettized)
+�� �� �� �� {
+�� �� �� �� �� �� buffer[i++] = j++;
+�� �� �� �� �� �� j %= 256;
+�� �� �� �� }
+�� �� �� �� else
+�� �� �� �� {
+�� �� �� �� �� �� buffer[i++] = j % 251;
+�� �� �� �� �� �� buffer[i++] = j % 239;
+�� �� �� �� �� �� buffer[i++] = j++ % 247;
+�� �� �� �� }
+�� �� }
+
+�� �� /* Finally, write the bitmap pixels */
+�� �� WriteFile(file, buffer, size, &written, NULL);
+�� �� ok(written == size, "Couldn't write bitmap pixels.\n");
+
+�� �� CloseHandle(file);
+�� �� HeapFree(GetProcessHeap(), 0, buffer);
+
+�� �� return path;
+}
+
+static BOOL test_bitmap_data(const int test_num, 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, ret = TRUE;
+�� �� 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 (test %d)\n", file,
+�� �� �� �� GetLastError(), test_num);
+�� �� if (hfile == INVALID_HANDLE_VALUE)
+�� �� �� �� goto cleanup;
+
+�� �� size = GetFileSize(hfile, NULL);
+�� �� ok(size != INVALID_FILE_SIZE, "Failed to get file size, error %d (test %d)\n", GetLastError(), test_num);
+
+�� �� hmapping = CreateFileMappingA(hfile, NULL, PAGE_READONLY, 0, 0, NULL);
+�� �� ok(hmapping != NULL, "Cannot create file mapping (error = %d, test %d).\n", GetLastError(), test_num);
+�� �� 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, test %d).\n", GetLastError(), test_num);
+�� �� 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 (test %d).\n", info_header.biWidth, w, test_num);
+�� �� ok(info_header.biHeight == h, "Expected texture height == %d, got %d (test %d).\n", info_header.biHeight, h, test_num);
+�� �� depth = info_header.biBitCount;
+
+�� �� buffer2 = (unsigned char *)buffer + bmp_header->bfOffBits;
+
+�� �� if (img->palette)
+�� �� {
+�� �� �� �� ok(img->depth == 8, "Expected texture bpp == 8, got %d (test %d).\n", img->depth, test_num);
+�� �� �� �� if (depth == 8)
+�� �� �� �� {
+�� �� �� �� �� �� /* bytes_per_line is not always aligned by d3drm depending on the format */
+�� �� �� �� �� �� expected = info_header.biWidth;
+�� �� �� �� �� �� ok(expected == img->bytes_per_line, "Expected bytes per line == %d, got %d (test %d).\n", expected, img->bytes_per_line, test_num);
+�� �� �� �� �� �� 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 < w; j++)
+�� �� �� �� �� �� �� �� {
+�� �� �� �� �� �� �� �� �� �� if (buffer1[k++] != buffer2[offset++])
+�� �� �� �� �� �� �� �� �� �� {
+�� �� �� �� �� �� �� �� �� �� �� �� ret = FALSE;
+�� �� �� �� �� �� �� �� �� �� �� �� goto cleanup;
+�� �� �� �� �� �� �� �� �� �� }
+�� �� �� �� �� �� �� �� }
+�� �� �� �� �� �� }
+�� �� �� �� }
+�� �� �� �� else
+�� �� �� �� {
+�� �� �� �� �� �� /* In this case, bytes_per_line is aligned to the nearest multiple of 4 from width */
+�� �� �� �� �� �� expected = (info_header.biWidth + 3) & ~3;
+�� �� �� �� �� �� ok(expected == img->bytes_per_line, "Expected bytes per line == %d, got %d (test %d).\n", expected, img->bytes_per_line, test_num);
+�� �� �� �� �� �� /* 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 + j]].blue == buffer2[offset];
+�� �� �� �� �� �� �� �� �� �� val2 = img->palette[buffer1[k + j]].green == buffer2[offset + 1];
+�� �� �� �� �� �� �� �� �� �� val3 = img->palette[buffer1[k + j]].red == buffer2[offset + 2];
+�� �� �� �� �� �� �� �� �� �� if (!(val1 && val2 && val3))
+�� �� �� �� �� �� �� �� �� �� {
+�� �� �� �� �� �� �� �� �� �� �� �� ret = FALSE;
+�� �� �� �� �� �� �� �� �� �� �� �� goto cleanup;
+�� �� �� �� �� �� �� �� �� �� }
+�� �� �� �� �� �� �� �� �� �� offset += 3;
+�� �� �� �� �� �� �� �� }
+�� �� �� �� �� �� �� �� k += img->bytes_per_line;
+�� �� �� �� �� �� }
+�� �� �� �� }
+�� �� }
+�� �� 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 (test %d).\n", img->depth, test_num);
+�� �� �� �� expected = info_header.biWidth * 4;
+�� �� �� �� ok(expected == img->bytes_per_line, "Expected bytes per line == %d, got %d (test %d).\n", expected, img->bytes_per_line, test_num);
+�� �� �� �� 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))
+�� �� �� �� �� �� �� �� {
+�� �� �� �� �� �� �� �� �� �� ret = FALSE;
+�� �� �� �� �� �� �� �� �� �� goto cleanup;
+�� �� �� �� �� �� �� �� }
+�� �� �� �� �� �� �� �� 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 %d).\n", file, GetLastError(), test_num);
+�� �� return ret;
+}
+
+static void test_load_texture(void)
+{
+�� �� struct texture_test
+�� �� {
+�� �� �� �� int version;
+�� �� �� �� int w;
+�� �� �� �� int h;
+�� �� �� �� BOOL palettized;
+�� �� };
+�� �� static const struct texture_test tests[] =
+�� �� {
+�� �� �� �� { 1,�� �� ��100, 100, TRUE�� },
+�� �� �� �� { 1,�� �� ��99,�� 100, TRUE�� },
+�� �� �� �� { 1,�� �� ��100, 100, FALSE },
+�� �� �� �� { 1,�� �� ��99,�� 100, FALSE },
+�� �� �� �� { 1,�� �� ��3,�� ��39,�� FALSE },
+�� �� �� �� { 2,�� �� ��100, 100, TRUE�� },
+�� �� �� �� { 2,�� �� ��99,�� 100, TRUE�� },
+�� �� �� �� { 2,�� �� ��100, 100, FALSE },
+�� �� �� �� { 2,�� �� ��99,�� 100, FALSE },
+�� �� �� �� { 2,�� �� ��3,�� ��39,�� FALSE },
+�� �� �� �� { 3,�� �� ��100, 100, TRUE�� },
+�� �� �� �� { 3,�� �� ��99,�� 100, TRUE�� },
+�� �� �� �� { 3,�� �� ��100, 100, FALSE },
+�� �� �� �� { 3,�� �� ��99,�� 100, FALSE },
+�� �� �� �� { 3,�� �� ��3,�� ��39,�� FALSE },
+�� �� };
+�� �� HRESULT hr;
+�� �� IDirect3DRM *d3drm1 = NULL;
+�� �� IDirect3DRM2 *d3drm2 = NULL;
+�� �� IDirect3DRM3 *d3drm3 = NULL;
+�� �� IDirect3DRMTexture *texture1 = NULL;
+�� �� IDirect3DRMTexture2 *texture2 = NULL;
+�� �� IDirect3DRMTexture3 *texture3 = NULL;
+�� �� D3DRMIMAGE *d3drm_img = NULL;
+�� �� BOOL check;
+�� �� char *file = NULL;
+�� �� const int num_tests = sizeof(tests) / sizeof(*tests);
+�� �� int i;
+
+�� �� 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);
+�� �� hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
+�� �� ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %x)\n", hr);
+
+�� �� for (i = 0; i < num_tests; i++)
+�� �� {
+�� �� �� �� switch (tests[i].version)
+�� �� �� �� {
+�� �� �� �� �� �� case 1:
+�� �� �� �� �� �� �� �� file = create_bitmap("test.bmp", tests[i].w, tests[i].h, tests[i].palettized);
+�� �� �� �� �� �� �� �� 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)
+�� �� �� �� �� �� �� �� {
+�� �� �� �� �� �� �� �� �� �� IDirect3DRMTexture_Release(texture1);
+�� �� �� �� �� �� �� �� �� �� goto cleanup;
+�� �� �� �� �� �� �� �� }
+�� �� �� �� �� �� �� �� check = test_bitmap_data(i, file, d3drm_img, FALSE);
+�� �� �� �� �� �� �� �� ok(check, "Buffer contents do not match that of bitmap (test %d).\n", i);
+�� �� �� �� �� �� �� �� IDirect3DRMTexture_Release(texture1);
+�� �� �� �� �� �� �� �� break;
+�� �� �� �� �� �� case 2:
+�� �� �� �� �� �� �� �� file = create_bitmap("test.bmp", tests[i].w, tests[i].h, tests[i].palettized);
+�� �� �� �� �� �� �� �� 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(i, file, d3drm_img, TRUE);
+�� �� �� �� �� �� �� �� ok(check, "Buffer contents do not match that of bitmap (test %d).\n", i);
+�� �� �� �� �� �� �� �� IDirect3DRMTexture2_Release(texture2);
+�� �� �� �� �� �� �� �� break;
+�� �� �� �� �� �� case 3:
+�� �� �� �� �� �� �� �� file = create_bitmap("test.bmp", tests[i].w, tests[i].h, tests[i].palettized);
+�� �� �� �� �� �� �� �� 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(i, file, d3drm_img, TRUE);
+�� �� �� �� �� �� �� �� ok(check, "Buffer contents do not match that of bitmap (test %d).\n", i);
+�� �� �� �� �� �� �� �� IDirect3DRMTexture3_Release(texture3);
+�� �� �� �� �� �� �� �� break;
+�� �� �� �� }
+�� �� }
+
+�� �� /* Test whether querying a version 1 texture from version 3 causes a change in the loading behavior */
+�� �� file = create_bitmap("test.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(num_tests + 1, file, d3drm_img, TRUE);
+�� �� ok(check, "Buffer contents do not match that of bitmap (test %d).\n", num_tests + 1);
+�� �� IDirect3DRMTexture_Release(texture1);
+�� �� IDirect3DRMTexture3_Release(texture3);
+
+cleanup:
+�� �� IDirect3DRM3_Release(d3drm3);
+�� �� IDirect3DRM2_Release(d3drm2);
+�� �� IDirect3DRM_Release(d3drm1);
+}
+
��START_TEST(d3drm)
��{
�� �� ��test_MeshBuilder();
@@ -3720,4 +4039,5 @@ START_TEST(d3drm)
�� �� ��test_create_device_from_d3d1();
�� �� ��test_create_device_from_d3d2();
�� �� ��test_create_device_from_d3d3();
+�� �� test_load_texture();
��}
--
2.3.2 (Apple Git-55)