[OLEAUT32_WINETEST] Sync with Wine 3.0. CORE-14225
[reactos.git] / modules / rostests / winetests / oleaut32 / olepicture.c
index 1b8e395..149dfc3 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#define WIN32_NO_STATUS
-#define _INC_WINDOWS
-#define COM_NO_WINDOWS_H
-
-//#include <stdarg.h>
-#include <stdio.h>
-//#include <math.h>
-//#include <float.h>
-
-#define COBJMACROS
-#define CONST_VTABLE
-#define NONAMELESSUNION
-
-#include <wine/test.h>
-//#include <windef.h>
-//#include <winbase.h>
-//#include <winuser.h>
-#include <wingdi.h>
-#include <winnls.h>
-//#include <winerror.h>
-//#include <winnt.h>
-#include <ole2.h>
-//#include <urlmon.h>
-//#include <wtypes.h>
-#include <olectl.h>
-//#include <objidl.h>
+#include "precomp.h"
 
 #define expect_eq(expr, value, type, format) { type ret = (expr); ok((value) == ret, #expr " expected " format " got " format "\n", value, ret); }
 
@@ -102,7 +77,7 @@ static const unsigned char pngimage[285] = {
 0xe7,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
 };
 
-/* 1bpp BI_RGB 1x1 pixel bmp */
+/* 1x1 pixel bmp */
 static const unsigned char bmpimage[66] = {
 0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
 0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,0x00,
@@ -111,15 +86,6 @@ static const unsigned char bmpimage[66] = {
 0x00,0x00
 };
 
-/* 8bpp BI_RLE8 1x1 pixel bmp */
-static const unsigned char bmpimage_rle8[] = {
-0x42,0x4d,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x00,0x00,0x00,0x28,0x00,
-0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x08,0x00,0x01,0x00,
-0x00,0x00,0x04,0x00,0x00,0x00,0x12,0x0b,0x00,0x00,0x12,0x0b,0x00,0x00,0x02,0x00,
-0x00,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0x00,0x00,0x01,
-0x00,0x00
-};
-
 /* 2x2 pixel gif */
 static const unsigned char gif4pixel[42] = {
 0x47,0x49,0x46,0x38,0x37,0x61,0x02,0x00,0x02,0x00,0xa1,0x00,0x00,0x00,0x00,0x00,
@@ -253,7 +219,7 @@ test_pic_with_stream(LPSTREAM stream, unsigned int imgsize)
         {
             BITMAP bmp;
             GetObjectA(UlongToHandle(handle), sizeof(BITMAP), &bmp);
-            ok(bmp.bmBits != 0, "not a dib\n");
+            todo_wine ok(bmp.bmBits != 0, "not a dib\n");
         }
 
        width = 0;
@@ -735,7 +701,8 @@ static void test_Render(void)
     HDC hdc = create_render_dc();
 
     /* test IPicture::Render return code on uninitialized picture */
-    OleCreatePictureIndirect(NULL, &IID_IPicture, TRUE, (VOID**)&pic);
+    hres = OleCreatePictureIndirect(NULL, &IID_IPicture, TRUE, (void **)&pic);
+    ok(hres == S_OK, "Failed to create a picture, hr %#x.\n", hres);
     hres = IPicture_get_Type(pic, &type);
     ok(hres == S_OK, "IPicture_get_Type does not return S_OK, but 0x%08x\n", hres);
     ok(type == PICTYPE_UNINITIALIZED, "Expected type = PICTYPE_UNINITIALIZED, got = %d\n", type);
@@ -761,14 +728,15 @@ static void test_Render(void)
 
     desc.cbSizeofstruct = sizeof(PICTDESC);
     desc.picType = PICTYPE_ICON;
-    desc.u.icon.hicon = LoadIconA(NULL, (LPCSTR)IDI_APPLICATION);
-    if(!desc.u.icon.hicon){
+    desc.icon.hicon = LoadIconA(NULL, (LPCSTR)IDI_APPLICATION);
+    if(!desc.icon.hicon){
         win_skip("LoadIcon failed. Skipping...\n");
         delete_render_dc(hdc);
         return;
     }
 
-    OleCreatePictureIndirect(&desc, &IID_IPicture, TRUE, (VOID**)&pic);
+    hres = OleCreatePictureIndirect(&desc, &IID_IPicture, TRUE, (void **)&pic);
+    ok(hres == S_OK, "Failed to create a picture, hr %#x.\n", hres);
     /* zero dimensions, PICTYPE_ICON */
     hres = picture_render(pic, hdc, 0, 0, 0, 0, 0, 0, 0, 0, NULL);
     ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE);
@@ -822,7 +790,8 @@ static void test_get_Attributes(void)
     short type;
     DWORD attr;
 
-    OleCreatePictureIndirect(NULL, &IID_IPicture, TRUE, (VOID**)&pic);
+    hres = OleCreatePictureIndirect(NULL, &IID_IPicture, TRUE, (void **)&pic);
+    ok(hres == S_OK, "Failed to create a picture, hr %#x.\n", hres);
     hres = IPicture_get_Type(pic, &type);
     ok(hres == S_OK, "IPicture_get_Type does not return S_OK, but 0x%08x\n", hres);
     ok(type == PICTYPE_UNINITIALIZED, "Expected type = PICTYPE_UNINITIALIZED, got = %d\n", type);
@@ -843,8 +812,8 @@ static void test_get_Handle(void)
     IPicture *pic;
     HRESULT hres;
 
-    OleCreatePictureIndirect(NULL, &IID_IPicture, TRUE, (VOID**)&pic);
-
+    hres = OleCreatePictureIndirect(NULL, &IID_IPicture, TRUE, (void **)&pic);
+    ok(hres == S_OK, "Failed to create a picture, hr %#x.\n", hres);
     hres = IPicture_get_Handle(pic, NULL);
     ole_expect(hres, E_POINTER);
 
@@ -856,7 +825,8 @@ static void test_get_Type(void)
     IPicture *pic;
     HRESULT hres;
 
-    OleCreatePictureIndirect(NULL, &IID_IPicture, TRUE, (VOID**)&pic);
+    hres = OleCreatePictureIndirect(NULL, &IID_IPicture, TRUE, (void **)&pic);
+    ok(hres == S_OK, "Failed to create a picture, hr %#x.\n", hres);
 
     hres = IPicture_get_Type(pic, NULL);
     ole_expect(hres, E_POINTER);
@@ -877,7 +847,6 @@ static void test_OleLoadPicturePath(void)
     HANDLE file;
     DWORD size;
     WCHAR *ptr;
-    VARIANT var;
 
     const struct
     {
@@ -944,14 +913,6 @@ static void test_OleLoadPicturePath(void)
     if (pic)
         IPicture_Release(pic);
 
-    VariantInit(&var);
-    V_VT(&var) = VT_BSTR;
-    V_BSTR(&var) = SysAllocString(temp_fileW + 8);
-    hres = OleLoadPictureFile(var, (IDispatch **)&pic);
-    ok(hres == S_OK, "OleLoadPictureFile error %#x\n", hres);
-    IPicture_Release(pic);
-    VariantClear(&var);
-
     /* Try a DOS path with tacked on "file:". */
     hres = OleLoadPicturePath(temp_fileW, NULL, 0, 0, &IID_IPicture, (void **)&pic);
     ok(hres == S_OK ||
@@ -960,13 +921,6 @@ static void test_OleLoadPicturePath(void)
     if (pic)
         IPicture_Release(pic);
 
-    VariantInit(&var);
-    V_VT(&var) = VT_BSTR;
-    V_BSTR(&var) = SysAllocString(temp_fileW);
-    hres = OleLoadPictureFile(var, (IDispatch **)&pic);
-    ok(hres == CTL_E_PATHFILEACCESSERROR, "wrong error %#x\n", hres);
-    VariantClear(&var);
-
     DeleteFileA(temp_file);
 
     /* Try with a nonexistent file. */
@@ -976,26 +930,12 @@ static void test_OleLoadPicturePath(void)
        broken(hres == E_FAIL), /*Win2k */
        "Expected OleLoadPicturePath to return INET_E_RESOURCE_NOT_FOUND, got 0x%08x\n", hres);
 
-    VariantInit(&var);
-    V_VT(&var) = VT_BSTR;
-    V_BSTR(&var) = SysAllocString(temp_fileW + 8);
-    hres = OleLoadPictureFile(var, (IDispatch **)&pic);
-    ok(hres == CTL_E_FILENOTFOUND, "wrong error %#x\n", hres);
-    VariantClear(&var);
-
     hres = OleLoadPicturePath(temp_fileW, NULL, 0, 0, &IID_IPicture, (void **)&pic);
     ok(hres == INET_E_RESOURCE_NOT_FOUND || /* XP+ */
        broken(hres == E_UNEXPECTED) || /* NT4 */
        broken(hres == E_FAIL), /* Win2k */
        "Expected OleLoadPicturePath to return INET_E_RESOURCE_NOT_FOUND, got 0x%08x\n", hres);
 
-    VariantInit(&var);
-    V_VT(&var) = VT_BSTR;
-    V_BSTR(&var) = SysAllocString(temp_fileW);
-    hres = OleLoadPictureFile(var, (IDispatch **)&pic);
-    ok(hres == CTL_E_PATHFILEACCESSERROR, "wrong error %#x\n", hres);
-    VariantClear(&var);
-
     file = CreateFileA(temp_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
                        FILE_ATTRIBUTE_NORMAL, NULL);
     WriteFile(file, bmpimage, sizeof(bmpimage), &size, NULL);
@@ -1017,13 +957,6 @@ static void test_OleLoadPicturePath(void)
     if (pic)
         IPicture_Release(pic);
 
-    VariantInit(&var);
-    V_VT(&var) = VT_BSTR;
-    V_BSTR(&var) = SysAllocString(temp_fileW);
-    hres = OleLoadPictureFile(var, (IDispatch **)&pic);
-    ok(hres == CTL_E_PATHFILEACCESSERROR, "wrong error %#x\n", hres);
-    VariantClear(&var);
-
     DeleteFileA(temp_file);
 
     /* Try with a nonexistent file. */
@@ -1032,22 +965,6 @@ static void test_OleLoadPicturePath(void)
        broken(hres == E_UNEXPECTED) || /* NT4 */
        broken(hres == E_FAIL), /* Win2k */
        "Expected OleLoadPicturePath to return INET_E_RESOURCE_NOT_FOUND, got 0x%08x\n", hres);
-
-    VariantInit(&var);
-    V_VT(&var) = VT_BSTR;
-    V_BSTR(&var) = SysAllocString(temp_fileW);
-    hres = OleLoadPictureFile(var, (IDispatch **)&pic);
-    ok(hres == CTL_E_PATHFILEACCESSERROR, "wrong error %#x\n", hres);
-    VariantClear(&var);
-
-    VariantInit(&var);
-    V_VT(&var) = VT_INT;
-    V_INT(&var) = 762;
-    hres = OleLoadPictureFile(var, (IDispatch **)&pic);
-    ok(hres == CTL_E_FILENOTFOUND, "wrong error %#x\n", hres);
-
-if (0) /* crashes under Windows */
-    hres = OleLoadPictureFile(var, NULL);
 }
 
 static void test_himetric(void)
@@ -1065,14 +982,14 @@ static void test_himetric(void)
 
     desc.cbSizeofstruct = sizeof(desc);
     desc.picType = PICTYPE_BITMAP;
-    desc.u.bmp.hpal = NULL;
+    desc.bmp.hpal = NULL;
 
     hdc = CreateCompatibleDC(0);
 
     bmp = CreateBitmap(1.9 * GetDeviceCaps(hdc, LOGPIXELSX),
                        1.9 * GetDeviceCaps(hdc, LOGPIXELSY), 1, 1, NULL);
 
-    desc.u.bmp.hbitmap = bmp;
+    desc.bmp.hbitmap = bmp;
 
     /* size in himetric units reported rounded up to next integer value */
     hr = OleCreatePictureIndirect(&desc, &IID_IPicture, FALSE, (void**)&pic);
@@ -1099,7 +1016,7 @@ static void test_himetric(void)
     ok(icon != NULL, "failed to create icon\n");
 
     desc.picType = PICTYPE_ICON;
-    desc.u.icon.hicon = icon;
+    desc.icon.hicon = icon;
 
     hr = OleCreatePictureIndirect(&desc, &IID_IPicture, FALSE, (void**)&pic);
     ok(hr == S_OK, "got 0x%08x\n", hr);
@@ -1138,8 +1055,8 @@ static void test_load_save_bmp(void)
 
     desc.cbSizeofstruct = sizeof(desc);
     desc.picType = PICTYPE_BITMAP;
-    desc.u.bmp.hpal = 0;
-    desc.u.bmp.hbitmap = CreateBitmap(1, 1, 1, 1, NULL);
+    desc.bmp.hpal = 0;
+    desc.bmp.hbitmap = CreateBitmap(1, 1, 1, 1, NULL);
     hr = OleCreatePictureIndirect(&desc, &IID_IPicture, FALSE, (void**)&pic);
     ok(hr == S_OK, "OleCreatePictureIndirect error %#x\n", hr);
 
@@ -1150,7 +1067,7 @@ static void test_load_save_bmp(void)
 
     hr = IPicture_get_Handle(pic, &handle);
     ok(hr == S_OK,"get_Handle error %#8x\n", hr);
-    ok(IntToPtr(handle) == desc.u.bmp.hbitmap, "get_Handle returned wrong handle %#x\n", handle);
+    ok(IntToPtr(handle) == desc.bmp.hbitmap, "get_Handle returned wrong handle %#x\n", handle);
 
     hmem = GlobalAlloc(GMEM_ZEROINIT, 4096);
     hr = CreateStreamOnHGlobal(hmem, FALSE, &dst_stream);
@@ -1159,14 +1076,18 @@ static void test_load_save_bmp(void)
     size = -1;
     hr = IPicture_SaveAsFile(pic, dst_stream, TRUE, &size);
     ok(hr == S_OK, "IPicture_SaveasFile error %#x\n", hr);
+todo_wine
     ok(size == 66, "expected 66, got %d\n", size);
     mem = GlobalLock(hmem);
+todo_wine
     ok(!memcmp(&mem[0], "BM", 2), "got wrong bmp header %04x\n", mem[0]);
     GlobalUnlock(hmem);
 
     size = -1;
     hr = IPicture_SaveAsFile(pic, dst_stream, FALSE, &size);
+todo_wine
     ok(hr == E_FAIL, "expected E_FAIL, got %#x\n", hr);
+todo_wine
     ok(size == -1, "expected -1, got %d\n", size);
 
     offset.QuadPart = 0;
@@ -1190,7 +1111,7 @@ static void test_load_save_bmp(void)
     GlobalUnlock(hmem);
     GlobalFree(hmem);
 
-    DeleteObject(desc.u.bmp.hbitmap);
+    DeleteObject(desc.bmp.hbitmap);
     IPicture_Release(pic);
 }
 
@@ -1210,7 +1131,7 @@ static void test_load_save_icon(void)
 
     desc.cbSizeofstruct = sizeof(desc);
     desc.picType = PICTYPE_ICON;
-    desc.u.icon.hicon = LoadIconA(NULL, (LPCSTR)IDI_APPLICATION);
+    desc.icon.hicon = LoadIconA(NULL, (LPCSTR)IDI_APPLICATION);
     hr = OleCreatePictureIndirect(&desc, &IID_IPicture, FALSE, (void**)&pic);
     ok(hr == S_OK, "OleCreatePictureIndirect error %#x\n", hr);
 
@@ -1221,7 +1142,7 @@ static void test_load_save_icon(void)
 
     hr = IPicture_get_Handle(pic, &handle);
     ok(hr == S_OK,"get_Handle error %#8x\n", hr);
-    ok(IntToPtr(handle) == desc.u.icon.hicon, "get_Handle returned wrong handle %#x\n", handle);
+    ok(IntToPtr(handle) == desc.icon.hicon, "get_Handle returned wrong handle %#x\n", handle);
 
     hmem = GlobalAlloc(GMEM_ZEROINIT, 8192);
     hr = CreateStreamOnHGlobal(hmem, FALSE, &dst_stream);
@@ -1233,12 +1154,15 @@ static void test_load_save_icon(void)
 todo_wine
     ok(size == 766, "expected 766, got %d\n", size);
     mem = GlobalLock(hmem);
+todo_wine
     ok(mem[0] == 0x00010000, "got wrong icon header %04x\n", mem[0]);
     GlobalUnlock(hmem);
 
     size = -1;
     hr = IPicture_SaveAsFile(pic, dst_stream, FALSE, &size);
+todo_wine
     ok(hr == E_FAIL, "expected E_FAIL, got %#x\n", hr);
+todo_wine
     ok(size == -1, "expected -1, got %d\n", size);
 
     offset.QuadPart = 0;
@@ -1263,7 +1187,7 @@ todo_wine
     GlobalUnlock(hmem);
     GlobalFree(hmem);
 
-    DestroyIcon(desc.u.icon.hicon);
+    DestroyIcon(desc.icon.hicon);
     IPicture_Release(pic);
 }
 
@@ -1304,11 +1228,13 @@ static void test_load_save_empty_picture(void)
     size = -1;
     hr = IPicture_SaveAsFile(pic, dst_stream, TRUE, &size);
     ok(hr == S_OK, "IPicture_SaveasFile error %#x\n", hr);
+todo_wine
     ok(size == -1, "expected -1, got %d\n", size);
 
     size = -1;
     hr = IPicture_SaveAsFile(pic, dst_stream, FALSE, &size);
     ok(hr == S_OK, "IPicture_SaveasFile error %#x\n", hr);
+todo_wine
     ok(size == -1, "expected -1, got %d\n", size);
 
     hr = IPicture_QueryInterface(pic, &IID_IPersistStream, (void **)&src_stream);
@@ -1376,89 +1302,6 @@ static void test_load_save_empty_picture(void)
     IStream_Release(stream);
 }
 
-static void test_load_save_emf(void)
-{
-    HDC hdc;
-    IPicture *pic;
-    PICTDESC desc;
-    short type;
-    OLE_HANDLE handle;
-    HGLOBAL hmem;
-    DWORD *mem;
-    ENHMETAHEADER *emh;
-    IPersistStream *src_stream;
-    IStream *dst_stream;
-    LARGE_INTEGER offset;
-    HRESULT hr;
-    LONG size;
-
-    hdc = CreateEnhMetaFileA(0, NULL, NULL, NULL);
-    ok(hdc != 0, "CreateEnhMetaFileA failed\n");
-
-    desc.cbSizeofstruct = sizeof(desc);
-    desc.picType = PICTYPE_ENHMETAFILE;
-    desc.u.emf.hemf = CloseEnhMetaFile(hdc);
-    ok(desc.u.emf.hemf != 0, "CloseEnhMetaFile failed\n");
-    hr = OleCreatePictureIndirect(&desc, &IID_IPicture, FALSE, (void**)&pic);
-    ok(hr == S_OK, "OleCreatePictureIndirect error %#x\n", hr);
-
-    type = -1;
-    hr = IPicture_get_Type(pic, &type);
-    ok(hr == S_OK,"get_Type error %#8x\n", hr);
-    ok(type == PICTYPE_ENHMETAFILE,"expected PICTYPE_ENHMETAFILE, got %d\n", type);
-
-    hr = IPicture_get_Handle(pic, &handle);
-    ok(hr == S_OK,"get_Handle error %#8x\n", hr);
-    ok(IntToPtr(handle) == desc.u.emf.hemf, "get_Handle returned wrong handle %#x\n", handle);
-
-    hmem = GlobalAlloc(GMEM_MOVEABLE, 0);
-    hr = CreateStreamOnHGlobal(hmem, FALSE, &dst_stream);
-    ok(hr == S_OK, "createstreamonhglobal error %#x\n", hr);
-
-    size = -1;
-    hr = IPicture_SaveAsFile(pic, dst_stream, TRUE, &size);
-    ok(hr == S_OK, "IPicture_SaveasFile error %#x\n", hr);
-    ok(size == 128, "expected 128, got %d\n", size);
-    emh = GlobalLock(hmem);
-if (size)
-{
-    ok(emh->iType == EMR_HEADER, "wrong iType %04x\n", emh->iType);
-    ok(emh->dSignature == ENHMETA_SIGNATURE, "wrong dSignature %08x\n", emh->dSignature);
-}
-    GlobalUnlock(hmem);
-
-    size = -1;
-    hr = IPicture_SaveAsFile(pic, dst_stream, FALSE, &size);
-    ok(hr == E_FAIL, "expected E_FAIL, got %#x\n", hr);
-    ok(size == -1, "expected -1, got %d\n", size);
-
-    offset.QuadPart = 0;
-    hr = IStream_Seek(dst_stream, offset, SEEK_SET, NULL);
-    ok(hr == S_OK, "IStream_Seek %#x\n", hr);
-
-    hr = IPicture_QueryInterface(pic, &IID_IPersistStream, (void **)&src_stream);
-    ok(hr == S_OK, "QueryInterface error %#x\n", hr);
-
-    hr = IPersistStream_Save(src_stream, dst_stream, TRUE);
-    ok(hr == S_OK, "Save error %#x\n", hr);
-
-    IPersistStream_Release(src_stream);
-    IStream_Release(dst_stream);
-
-    mem = GlobalLock(hmem);
-    ok(!memcmp(mem, "lt\0\0", 4), "got wrong stream header %04x\n", mem[0]);
-    ok(mem[1] == 128, "expected 128, got %u\n", mem[1]);
-    emh = (ENHMETAHEADER *)(mem + 2);
-    ok(emh->iType == EMR_HEADER, "wrong iType %04x\n", emh->iType);
-    ok(emh->dSignature == ENHMETA_SIGNATURE, "wrong dSignature %08x\n", emh->dSignature);
-
-    GlobalUnlock(hmem);
-    GlobalFree(hmem);
-
-    DeleteEnhMetaFile(desc.u.emf.hemf);
-    IPicture_Release(pic);
-}
-
 START_TEST(olepicture)
 {
     hOleaut32 = GetModuleHandleA("oleaut32.dll");
@@ -1474,7 +1317,6 @@ START_TEST(olepicture)
     test_pic(gifimage, sizeof(gifimage));
     test_pic(jpgimage, sizeof(jpgimage));
     test_pic(bmpimage, sizeof(bmpimage));
-    test_pic(bmpimage_rle8, sizeof(bmpimage_rle8));
     test_pic(gif4pixel, sizeof(gif4pixel));
     /* FIXME: No PNG support in Windows... */
     if (0) test_pic(pngimage, sizeof(pngimage));
@@ -1499,7 +1341,6 @@ START_TEST(olepicture)
     test_load_save_bmp();
     test_load_save_icon();
     test_load_save_empty_picture();
-    test_load_save_emf();
 }