[PATCH] d3drm/tests: Add tests for IDirect3DRM*::LoadTexture.

Stefan Dösinger stefandoesinger at gmail.com
Tue Dec 15 15:30:11 CST 2015


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Hi,

Cool to see that you're still working on this :-) .

Am 2015-12-15 um 16:41 schrieb Aaryaman Vasishta:

> + * Copyright 2015 Aaryaman Vasishta
I think you can make this 2014-2015.

> +static char *create_testbitmap(const char *filename, LPCSTR resource)
LPCSTR -> const char * is better IMO.
> +{
> +    static char path[MAX_PATH];
> +    DWORD written;
> +    HANDLE file;
> +    HRSRC res;
> +    void *ptr;
> +
> +    GetTempPathA(sizeof(path)/sizeof(WCHAR), path);
Why sizeof(WCHAR)?

> +    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());
> +
> +    res = FindResourceA(GetModuleHandleA(NULL), resource, (LPCSTR)RT_RCDATA);
const char *

> +    ok( res != 0, "couldn't find resource\n" );
> +    ptr = LockResource( LoadResource( GetModuleHandleA(NULL), res ));
> +    WriteFile( file, ptr, SizeofResource( GetModuleHandleA(NULL), res ), &written, NULL );
> +    ok( written == SizeofResource( GetModuleHandleA(NULL), res ), "couldn't write resource\n" );
> +    CloseHandle( file );
You have inconsistent style here. ok(foo, "bar\n"); vs ok( foo, "bar\n" );

> +static BOOL test_bitmap_data1(unsigned char *buffer1, unsigned char *buffer2, D3DRMIMAGE *img, int w, int h, int depth)
afaics you can make buffer1 and buffer2 const, probably applies to img as well.

> +    if (img->palette)
> +    {
> +        if (depth == 8)
> +        {
> +            for (i = 0; i < size; i++)
> +            {
> +                if (buffer1[i] != buffer2[i])
> +                    return FALSE;
> +            }
> +        }
> +        else
> +        {
> +            /* d3drm aligns the 24bpp texture to 4 bytes in the buffer, with one bype padding from 24bpp texture. */
> +            /* The image is palettized if the total number of colors used is < 256. */
Does this ever happen? A palettized image with != 8 bpp?

> +                for (i = 0, j = 0; i < w * h; i += 3, j++)
> +                {
> +                    val1 = img->palette[buffer1[j]].blue == buffer2[i];
> +                    val2 = img->palette[buffer1[j]].green == buffer2[i + 1];
> +                    val3 = img->palette[buffer1[j]].red == buffer2[i + 2];
> +                    if (!(val1 && val2 && val3))
> +                        return FALSE;
> +                }
> +        }
Your indentation is wrong here.

> +        for (i = 0, j = 0; i < w * h; i += 4, j += 3)
> +        {
> +            val1 = buffer1[i] == buffer2[j];
> +            val2 = buffer1[i + 1] == buffer2[j + 1];
> +            val3 = buffer1[i + 2] == buffer2[j + 2];
> +            if (!(val1 && val2 && val3))
> +                return FALSE;
> +        }
I think you're supposed to use img->bytes_per_line to advance from one line to another. See e.g. how lPitch is handled in ddraw tests.

> +static void test_load_texture1(void)
> +{
> +    HRESULT hr;
> +    IDirect3DRM *d3drm1 = NULL;
> +    IDirect3DRMTexture *texture1 = NULL;
> +    D3DRMIMAGE *d3drm_img = NULL;
> +    HWND window;
> +    HBITMAP hbm = NULL;
> +    BITMAP bm;
> +    BITMAPFILEHEADER *bmp_header = NULL;
> +    BITMAPINFO *bmp_info = NULL;
> +    HANDLE hfile, hmapping = NULL;
> +    BOOL check;
> +    DWORD size;
> +    char *file = NULL;
> +    unsigned char *buffer = NULL, *buffer1 = NULL, *buffer2 = NULL;
> +    HDC mem_dc = NULL;
> +
> +    window = CreateWindowA("static", "d3drm_test", WS_OVERLAPPEDWINDOW, 0, 0, 300, 200, 0, 0, 0, 0);
> +    file = create_testbitmap("8bpp.bmp", (LPCSTR)MAKEINTRESOURCE(IDD_BITMAPDATA_8BPP));
> +
> +    hbm = LoadImageA(NULL, file, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
> +    ok(hbm != NULL, "Cannot load image %s (error = %x).\n", file, GetLastError());
> +
> +    mem_dc = CreateCompatibleDC(NULL);
> +    ok(mem_dc != NULL, "Cannot create memory device context.\n");
> +
> +    SelectObject(mem_dc, hbm);
> +    GetObjectA(hbm, sizeof(bm), &bm);
> +
> +
> +    /* Test if image information matches that from the header by loading the bitmap seperately. */
Two newlines.

> +    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());
> +    if (size == INVALID_FILE_SIZE)
> +        goto cleanup;
> +
> +    hmapping = CreateFileMappingA(hfile, NULL, PAGE_READONLY, 0, 0, NULL);
> +    ok(hmapping != NULL, "Cannot create file mapping (error = %x).\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 = %x).\n", GetLastError());
> +    if (buffer == NULL)
> +        goto cleanup;
> +
> +    bmp_header = (BITMAPFILEHEADER *)buffer;
> +    bmp_info = (BITMAPINFO *)((unsigned char *)buffer + sizeof(BITMAPFILEHEADER));
> +    buffer1 = ((unsigned char *)buffer + bmp_header->bfOffBits);
This seems a bit unelegant to me, but I don't have a better solution available right now. I guess something along the lines of copying the image into a DIB section with BitBlt may work.

> +    hr = Direct3DRMCreate(&d3drm1);
> +    ok(hr == D3DRM_OK, "Cannot get IDirect3DRM interface (hr = %x)\n", hr);
> +
> +    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;
> +    ok(bmp_info->bmiHeader.biWidth == d3drm_img->width, "Expected texture width == %d, got %d.\n", bmp_info->bmiHeader.biWidth, d3drm_img->width);
> +    ok(bmp_info->bmiHeader.biHeight == d3drm_img->height, "Expected texture height == %d, got %d.\n", bmp_info->bmiHeader.biHeight, d3drm_img->height);
> +    buffer2 = (unsigned char *)d3drm_img->buffer1;
> +    check = test_bitmap_data1(buffer2, buffer1, d3drm_img, bm.bmWidth, bm.bmHeight, bmp_info->bmiHeader.biBitCount);
> +    ok(check, "Buffer contents do not match that of bitmap.\n");
> +
> +cleanup:
> +    UnmapViewOfFile(buffer);
> +    CloseHandle(hmapping);
> +    CloseHandle(hfile);
> +    DeleteDC(mem_dc);
> +    DeleteObject(hbm);
> +    IDirect3DRMTexture_Release(texture1);
> +    IDirect3DRM_Release(d3drm1);
> +    check = DeleteFileA(file);
> +    ok(check, "Cannot delete image stored in %s (error = %x).\n", file, GetLastError());
> +    DestroyWindow(window);
> +}
> +
> +static BOOL test_bitmap_data2(unsigned char *buffer1, unsigned char *buffer2, D3DRMIMAGE *img, int w, int h, int depth)
If I understand it right and remember it properly from our chat, the difference is that version 2 is upside down. I think that can be handled via a parameter and without duplicating the function.

Cheers,
Stefan

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCAAGBQJWcIZjAAoJEN0/YqbEcdMw2ZcP/3h4HmIjK2ENd0nhkj4Zae34
XgMQe9gXTRtdmsjIHgcFRDwIfxbjA0XX5CazCFAsL0cz58zzNtMUuugXBeraDzeR
7CTUNPdivsHzVm3V8hRjCDWuGSGZmVHiBNJE2OL0GKVdzYOmRWC3FOMy5ICD/ZdR
GDrut5zr59vTieRZieov0Mx3jfAtWkeHLU/MVEFFljCBcUVRj1FIvClrGZDXk3Xn
DW82LQrv8QXRtPh8ruLySFgeBDG0iTZ+4N6iIJwWPvd6qbg5Ku0MQOx3K8VsnQi8
7OlcQ8wzIvX8QxXsu1zBQwVNbJBQCup3zC8rqeqg27EoEYPZvQLwIAL/U7xd83Ul
s8tFatOV9WD/sBmSa4XY4A1hMkgDqyhNIWrcOd6mm4hUaAbLac60NwNG6cAPtj0w
fxlhIegqJ9B7Cs7xhGjFtsO5TqIeLUd0f5k6IWsgEAKv4KVz6pVYKGlrB5PM9jLw
Xv8b3usjk9c3eoB5KExb/VhU6ea+sacc6XBGkEJEyu2b5r4gFNfrBRrxvOzKHJ1x
xkvle6mmHSn3lxZXmvuEKHZBZPvRNDszvLX4BCuGPRRCpU4JNLY3/aF1kXpX3ks1
RwHYJU/ufJgDvLtYRnBeQOjK4cNdkZyhbH0lrkkcBig38F4xPcjjym+jdPro0X1N
voYrN8i/7cKq/ASKNWAD
=3KSr
-----END PGP SIGNATURE-----



More information about the wine-devel mailing list