Signed-off-by: Sergio Gómez Del Real sdelreal@codeweavers.com --- dlls/ole32/tests/ole2.c | 136 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 116 insertions(+), 20 deletions(-)
diff --git a/dlls/ole32/tests/ole2.c b/dlls/ole32/tests/ole2.c index 3bd4acce92..1d388bbc5d 100644 --- a/dlls/ole32/tests/ole2.c +++ b/dlls/ole32/tests/ole2.c @@ -4078,6 +4078,71 @@ static void check_storage_contents(IStorage *stg, const struct storage_def *stg_ } }
+static HRESULT stgmedium_cmp(const STGMEDIUM *stgmed_def, const STGMEDIUM *stgmed_ld) +{ + BYTE *data_def, *data_ld; + int data_size = 0, data_size_def, data_size_ld; + + if (stgmed_def->tymed != stgmed_ld->tymed) + return E_FAIL; + + if (stgmed_def->tymed == TYMED_MFPICT) + { + METAFILEPICT *mfpict_def = GlobalLock(U(stgmed_def)->hMetaFilePict); + METAFILEPICT *mfpict_ld = GlobalLock(U(stgmed_ld)->hMetaFilePict); + + data_size_def = GetMetaFileBitsEx(mfpict_def->hMF, 0, NULL); + data_size_ld = GetMetaFileBitsEx(mfpict_ld->hMF, 0, NULL); + if (data_size_def == data_size_ld) + { + data_def = HeapAlloc(GetProcessHeap(), 0, data_size_def); + data_ld = HeapAlloc(GetProcessHeap(), 0, data_size_ld); + GetMetaFileBitsEx(mfpict_def->hMF, data_size_def, data_def); + GetMetaFileBitsEx(mfpict_ld->hMF, data_size_ld, data_ld); + data_size = data_size_def; + } + else return E_FAIL; + } + else if (stgmed_def->tymed == TYMED_ENHMF) + { + data_size_def = GetEnhMetaFileBits(stgmed_def->hEnhMetaFile, 0, NULL); + data_size_ld = GetEnhMetaFileBits(stgmed_ld->hEnhMetaFile, 0, NULL); + if (data_size_def == data_size_ld) + { + data_def = HeapAlloc(GetProcessHeap(), 0, data_size_def); + data_ld = HeapAlloc(GetProcessHeap(), 0, data_size_ld); + GetEnhMetaFileBits(stgmed_def->hEnhMetaFile, data_size_def, data_def); + GetEnhMetaFileBits(stgmed_ld->hEnhMetaFile, data_size_ld, data_ld); + data_size = data_size_def; + } + else return E_FAIL; + } + else if (stgmed_def->tymed == TYMED_HGLOBAL) + { + data_def = GlobalLock(stgmed_def->hGlobal); + data_ld = GlobalLock(stgmed_ld->hGlobal); + data_size = sizeof(dib); + } + else + return E_NOTIMPL; + + if (memcmp(data_def, data_ld, data_size) != 0) + return E_FAIL; + + if (stgmed_def->tymed == TYMED_HGLOBAL) + { + GlobalUnlock(stgmed_def->hGlobal); + GlobalUnlock(stgmed_ld->hGlobal); + } + else if (stgmed_def->tymed == TYMED_MFPICT) + { + GlobalUnlock(U(stgmed_def)->hMetaFilePict); + GlobalUnlock(U(stgmed_ld)->hMetaFilePict); + } + + return S_OK; +} + static IStorage *create_storage_from_def(const struct storage_def *stg_def) { HRESULT hr; @@ -4250,8 +4315,10 @@ static void test_data_cache_save_data(void) IStorage *doc; IOleCache2 *cache; IPersistStorage *persist; + IDataObject *odata; int enumerated_streams, matched_streams, i; DWORD dummy; + STGMEDIUM stgmeds[MAX_FMTS]; struct tests_data_cache { FORMATETC fmts[MAX_FMTS]; @@ -4274,8 +4341,8 @@ static void test_data_cache_save_data(void) &CLSID_WineTestOld, 4, { { "\2OlePres000", CF_DIB, DVASPECT_CONTENT, 0, NULL, 0 }, { "\2OlePres001", CF_METAFILEPICT, DVASPECT_CONTENT, 0, NULL, 0 }, { "\2OlePres002", CF_ENHMETAFILE, DVASPECT_CONTENT, 0, NULL, 0 }, - { "\2OlePres003", 0, DVASPECT_DOCPRINT, 0, NULL, 0 } } - } + { "\2OlePres003", 0, DVASPECT_DOCPRINT, 0, NULL, 0 } }, + }, }, /* without setting data */ { @@ -4288,8 +4355,8 @@ static void test_data_cache_save_data(void) { &CLSID_WineTestOld, 3, { { "\2OlePres000", CF_DIB, DVASPECT_CONTENT, 0, NULL, 0 }, { "\2OlePres001", CF_METAFILEPICT, DVASPECT_CONTENT, 0, NULL, 0 }, - { "\2OlePres002", CF_ENHMETAFILE, DVASPECT_CONTENT, 0, NULL, 0 } } - } + { "\2OlePres002", CF_ENHMETAFILE, DVASPECT_CONTENT, 0, NULL, 0 } }, + }, }, /* static picture clsids */ { @@ -4298,8 +4365,8 @@ static void test_data_cache_save_data(void) }, 1, 1, &CLSID_Picture_Dib, { - &CLSID_WineTestOld, 1, { { "CONTENTS", -1, 0, 0, NULL, 0 } } - } + &CLSID_WineTestOld, 1, { { "CONTENTS", -1, 0, 0, NULL, 0 } }, + }, }, { { @@ -4307,8 +4374,8 @@ static void test_data_cache_save_data(void) }, 1, 1, &CLSID_Picture_Metafile, { - &CLSID_WineTestOld, 1, { { "CONTENTS", -1, 0, 0, NULL, 0 } } - } + &CLSID_WineTestOld, 1, { { "CONTENTS", -1, 0, 0, NULL, 0 } }, + }, }, { { @@ -4316,8 +4383,8 @@ static void test_data_cache_save_data(void) }, 1, 1, &CLSID_Picture_EnhMetafile, { - &CLSID_WineTestOld, 1, { { "CONTENTS", -1, 0, 0, NULL, 0 } } - } + &CLSID_WineTestOld, 1, { { "CONTENTS", -1, 0, 0, NULL, 0 } }, + }, }, /* static picture clsids without setting any data */ { @@ -4326,8 +4393,8 @@ static void test_data_cache_save_data(void) }, 1, 0, &CLSID_Picture_Dib, { - &CLSID_WineTestOld, 1, { { "CONTENTS", -1, 0, 0, NULL, 0 } } - } + &CLSID_WineTestOld, 1, { { "CONTENTS", -1, 0, 0, NULL, 0 } }, + }, }, { { @@ -4335,8 +4402,8 @@ static void test_data_cache_save_data(void) }, 1, 0, &CLSID_Picture_Metafile, { - &CLSID_WineTestOld, 1, { { "CONTENTS", -1, 0, 0, NULL, 0 } } - } + &CLSID_WineTestOld, 1, { { "CONTENTS", -1, 0, 0, NULL, 0 } }, + }, }, { { @@ -4344,8 +4411,8 @@ static void test_data_cache_save_data(void) }, 1, 0, &CLSID_Picture_EnhMetafile, { - &CLSID_WineTestOld, 1, { { "CONTENTS", -1, 0, 0, NULL, 0 } } - } + &CLSID_WineTestOld, 1, { { "CONTENTS", -1, 0, 0, NULL, 0 } }, + }, }, { { @@ -4366,9 +4433,9 @@ static void test_data_cache_save_data(void) ok(SUCCEEDED(hr), "unexpected %#x\n", hr); if (i < pdata->num_set) { - get_stgmedium(pdata->fmts[i].cfFormat, &stgmed); - get_stgdef(&pdata->stg_def, pdata->fmts[i].cfFormat, &stgmed, i); - hr = IOleCache2_SetData(cache, &pdata->fmts[i], &stgmed, TRUE); + get_stgmedium(pdata->fmts[i].cfFormat, &stgmeds[i]); + get_stgdef(&pdata->stg_def, pdata->fmts[i].cfFormat, &stgmeds[i], i); + hr = IOleCache2_SetData(cache, &pdata->fmts[i], &stgmeds[i], FALSE); ok(hr == S_OK, "unexpected %#x\n", hr); } } @@ -4399,12 +4466,41 @@ static void test_data_cache_save_data(void) ok(enumerated_streams == pdata->stg_def.stream_count, "created %d != def streams %d\n", enumerated_streams, pdata->stg_def.stream_count);
+ IPersistStorage_Release(persist); + IOleCache2_Release(cache); + + /* now test _Load/_GetData using the storage we used for _Save */ + hr = CreateDataCache(NULL, pdata->clsid, &IID_IOleCache2, (void **)&cache); + ok(hr == S_OK, "unexpected %#x\n", hr); + hr = IOleCache2_QueryInterface(cache, &IID_IPersistStorage, (void **)&persist); + ok(hr == S_OK, "unexpected %#x\n", hr); + + hr = IStorage_SetClass(doc, pdata->clsid); + ok(hr == S_OK, "unexpected %#x\n", hr); + trace("IPersistStorage_Load\n"); + hr = IPersistStorage_Load(persist, doc); + ok(hr == S_OK, "unexpected %#x\n", hr); + + hr = IOleCache2_QueryInterface(cache, &IID_IDataObject, (void **)&odata); + ok(hr == S_OK, "unexpected %#x\n", hr); for (i = 0; i < pdata->num_set; i++) - HeapFree(GetProcessHeap(), 0, (void *)pdata->stg_def.stream[i].data); + { + hr = IDataObject_GetData(odata, &pdata->fmts[i], &stgmed); + ok(hr == S_OK, "unexpected %#x\n", hr);
+ hr = stgmedium_cmp(&stgmeds[i], &stgmed); + ok(hr == S_OK, "unexpected %#x\n", hr); + ReleaseStgMedium(&stgmed); + ReleaseStgMedium(&stgmeds[i]); + } + + IDataObject_Release(odata); IPersistStorage_Release(persist); IStorage_Release(doc); IOleCache2_Release(cache); + for (i = 0; i < pdata->num_set; i++) + HeapFree(GetProcessHeap(), 0, (void *)pdata->stg_def.stream[i].data); + } }