Signed-off-by: Sergio Gómez Del Real sdelreal@codeweavers.com --- dlls/ole32/tests/ole2.c | 165 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 145 insertions(+), 20 deletions(-)
diff --git a/dlls/ole32/tests/ole2.c b/dlls/ole32/tests/ole2.c index 3bd4acce92..da9c5ff070 100644 --- a/dlls/ole32/tests/ole2.c +++ b/dlls/ole32/tests/ole2.c @@ -4078,6 +4078,74 @@ static void check_storage_contents(IStorage *stg, const struct storage_def *stg_ } }
+static HRESULT check_medium_contents(const STGMEDIUM *stgmed_def, STGMEDIUM *stgmed_ld, FORMATETC *fmt) +{ + BYTE *data_def, *data_ld; + int i; + int data_size = 0, data_size_def, data_size_ld; + + if (stgmed_def->tymed != stgmed_ld->tymed) + return E_FAIL; + + if (fmt->cfFormat == CF_METAFILEPICT) + { + 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 (fmt->cfFormat == CF_ENHMETAFILE) + { + 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 (fmt->cfFormat == CF_DIB) + { + data_def = GlobalLock(stgmed_def->hGlobal); + data_ld = GlobalLock(stgmed_ld->hGlobal); + data_size = sizeof(dib); + } + else + return E_NOTIMPL; + + for (i = 0; i < data_size; i++) + { + if (data_def[i] != data_ld[i]) return E_FAIL; + } + + if (fmt->cfFormat == CF_DIB) + { + GlobalUnlock(stgmed_def->hGlobal); + GlobalUnlock(stgmed_ld->hGlobal); + } + else if (fmt->cfFormat == CF_METAFILEPICT) + { + 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,6 +4318,7 @@ static void test_data_cache_save_data(void) IStorage *doc; IOleCache2 *cache; IPersistStorage *persist; + IDataObject *odata; int enumerated_streams, matched_streams, i; DWORD dummy; struct tests_data_cache @@ -4258,6 +4327,7 @@ static void test_data_cache_save_data(void) int num_fmts, num_set; const CLSID *clsid; struct storage_def stg_def; + STGMEDIUM stgmed_def[MAX_FMTS]; };
static struct tests_data_cache *pdata, data[] = @@ -4274,8 +4344,9 @@ 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 } }, + }, + { { 0 } } }, /* without setting data */ { @@ -4288,8 +4359,9 @@ 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 } }, + }, + { { 0 } } }, /* static picture clsids */ { @@ -4298,8 +4370,9 @@ 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 } }, + }, + { { 0 } } }, { { @@ -4307,8 +4380,9 @@ 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 } }, + }, + { { 0 } } }, { { @@ -4316,8 +4390,9 @@ 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 } }, + }, + { { 0 } } }, /* static picture clsids without setting any data */ { @@ -4326,8 +4401,9 @@ 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 } }, + }, + { { 0 } } }, { { @@ -4335,8 +4411,9 @@ 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 } }, + }, + { { 0 } } }, { { @@ -4344,8 +4421,9 @@ 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 } }, + }, + { { 0 } } }, { { @@ -4366,9 +4444,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, &pdata->stgmed_def[i]); + get_stgdef(&pdata->stg_def, pdata->fmts[i].cfFormat, &pdata->stgmed_def[i], i); + hr = IOleCache2_SetData(cache, &pdata->fmts[i], &pdata->stgmed_def[i], FALSE); ok(hr == S_OK, "unexpected %#x\n", hr); } } @@ -4399,12 +4477,59 @@ 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); + for (i = 0; i < pdata->num_fmts; i++) + { + hr = IOleCache2_Cache(cache, &pdata->fmts[i], 0, &dummy); + ok(SUCCEEDED(hr), "unexpected %#x\n", hr); + } + + if (IsEqualCLSID(pdata->clsid, &CLSID_Picture_Dib)) + { + hr = IStorage_SetClass(doc, &CLSID_Picture_Dib); + ok(hr == S_OK, "unexpected %#x\n", hr); + } + else if (IsEqualCLSID(pdata->clsid, &CLSID_Picture_Metafile)) + { + hr = IStorage_SetClass(doc, &CLSID_Picture_Metafile); + ok(hr == S_OK, "unexpected %#x\n", hr); + } + else if (IsEqualCLSID(pdata->clsid, &CLSID_Picture_EnhMetafile)) + { + hr = IStorage_SetClass(doc, &CLSID_Picture_EnhMetafile); + 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 = check_medium_contents(&pdata->stgmed_def[i], &stgmed, &pdata->fmts[i]); + ok(hr == S_OK, "unexpected %#x\n", hr); + ReleaseStgMedium(&stgmed); + ReleaseStgMedium(&pdata->stgmed_def[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); + } }