ole32: Add framework in the ole2 tests for having optionally called methods.

This commit is contained in:
Rob Shearman 2009-02-08 18:03:13 +00:00 committed by Alexandre Julliard
parent db851a1d2a
commit d26250fd08
1 changed files with 162 additions and 144 deletions

View File

@ -44,7 +44,15 @@ static const CLSID CLSID_WineTest =
{0xbc, 0x13, 0x51, 0x6e, 0x92, 0x39, 0xac, 0xe0} {0xbc, 0x13, 0x51, 0x6e, 0x92, 0x39, 0xac, 0xe0}
}; };
static char const * const *expected_method_list; #define TEST_OPTIONAL 0x1
struct expected_method
{
const char *method;
unsigned int flags;
};
static const struct expected_method *expected_method_list;
BOOL g_showRunnable = TRUE; BOOL g_showRunnable = TRUE;
BOOL g_isRunning = TRUE; BOOL g_isRunning = TRUE;
@ -52,15 +60,25 @@ BOOL g_isRunning = TRUE;
#define CHECK_EXPECTED_METHOD(method_name) \ #define CHECK_EXPECTED_METHOD(method_name) \
do { \ do { \
trace("%s\n", method_name); \ trace("%s\n", method_name); \
ok(*expected_method_list != NULL, "Extra method %s called\n", method_name); \ ok(expected_method_list->method != NULL, "Extra method %s called\n", method_name); \
if (*expected_method_list) \ if (expected_method_list->method) \
{ \ { \
ok(!strcmp(*expected_method_list, method_name), "Expected %s to be called instead of %s\n", \ while (expected_method_list->flags & TEST_OPTIONAL && \
*expected_method_list, method_name); \ strcmp(expected_method_list->method, method_name) != 0) \
expected_method_list++; \
ok(!strcmp(expected_method_list->method, method_name), "Expected %s to be called instead of %s\n", \
expected_method_list->method, method_name); \
expected_method_list++; \ expected_method_list++; \
} \ } \
} while(0) } while(0)
#define CHECK_NO_EXTRA_METHODS() \
do { \
while (expected_method_list->flags & TEST_OPTIONAL) \
expected_method_list++; \
ok(!expected_method_list->method, "Method sequence starting from %s not called\n", expected_method_list->method); \
} while (0)
static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv) static HRESULT WINAPI OleObject_QueryInterface(IOleObject *iface, REFIID riid, void **ppv)
{ {
CHECK_EXPECTED_METHOD("OleObject_QueryInterface"); CHECK_EXPECTED_METHOD("OleObject_QueryInterface");
@ -660,102 +678,102 @@ static void test_OleCreate(IStorage *pStorage)
HRESULT hr; HRESULT hr;
IOleObject *pObject; IOleObject *pObject;
FORMATETC formatetc; FORMATETC formatetc;
static const char *methods_olerender_none[] = static const struct expected_method methods_olerender_none[] =
{ {
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObject_AddRef", { "OleObject_AddRef", 0 },
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObjectPersistStg_AddRef", { "OleObjectPersistStg_AddRef", 0 },
"OleObjectPersistStg_InitNew", { "OleObjectPersistStg_InitNew", 0 },
"OleObjectPersistStg_Release", { "OleObjectPersistStg_Release", 0 },
"OleObject_Release", { "OleObject_Release", 0 },
NULL { NULL, 0 }
}; };
static const char *methods_olerender_draw[] = static const struct expected_method methods_olerender_draw[] =
{ {
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObject_AddRef", { "OleObject_AddRef", 0 },
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObjectPersistStg_AddRef", { "OleObjectPersistStg_AddRef", 0 },
"OleObjectPersistStg_InitNew", { "OleObjectPersistStg_InitNew", 0 },
"OleObjectPersistStg_Release", { "OleObjectPersistStg_Release", 0 },
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObjectRunnable_AddRef", { "OleObjectRunnable_AddRef", 0 },
"OleObjectRunnable_Run", { "OleObjectRunnable_Run", 0 },
"OleObjectRunnable_Release", { "OleObjectRunnable_Release", 0 },
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObjectCache_AddRef", { "OleObjectCache_AddRef", 0 },
"OleObjectCache_Cache", { "OleObjectCache_Cache", 0 },
"OleObjectCache_Release", { "OleObjectCache_Release", 0 },
"OleObject_Release", { "OleObject_Release", 0 },
NULL { NULL, 0 }
}; };
static const char *methods_olerender_format[] = static const struct expected_method methods_olerender_format[] =
{ {
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObject_AddRef", { "OleObject_AddRef", 0 },
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObject_AddRef", { "OleObject_AddRef", 0 },
"OleObject_GetMiscStatus", { "OleObject_GetMiscStatus", 0 },
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObjectPersistStg_AddRef", { "OleObjectPersistStg_AddRef", 0 },
"OleObjectPersistStg_InitNew", { "OleObjectPersistStg_InitNew", 0 },
"OleObjectPersistStg_Release", { "OleObjectPersistStg_Release", 0 },
"OleObject_SetClientSite", { "OleObject_SetClientSite", 0 },
"OleObject_Release", { "OleObject_Release", 0 },
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObjectRunnable_AddRef", { "OleObjectRunnable_AddRef", 0 },
"OleObjectRunnable_Run", { "OleObjectRunnable_Run", 0 },
"OleObjectRunnable_Release", { "OleObjectRunnable_Release", 0 },
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObjectCache_AddRef", { "OleObjectCache_AddRef", 0 },
"OleObjectCache_Cache", { "OleObjectCache_Cache", 0 },
"OleObjectCache_Release", { "OleObjectCache_Release", 0 },
"OleObject_Release", { "OleObject_Release", 0 },
NULL { NULL, 0 }
}; };
static const char *methods_olerender_asis[] = static const struct expected_method methods_olerender_asis[] =
{ {
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObject_AddRef", { "OleObject_AddRef", 0 },
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObjectPersistStg_AddRef", { "OleObjectPersistStg_AddRef", 0 },
"OleObjectPersistStg_InitNew", { "OleObjectPersistStg_InitNew", 0 },
"OleObjectPersistStg_Release", { "OleObjectPersistStg_Release", 0 },
"OleObject_Release", { "OleObject_Release", 0 },
NULL { NULL, 0 }
}; };
static const char *methods_olerender_draw_no_runnable[] = static const struct expected_method methods_olerender_draw_no_runnable[] =
{ {
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObject_AddRef", { "OleObject_AddRef", 0 },
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObjectPersistStg_AddRef", { "OleObjectPersistStg_AddRef", 0 },
"OleObjectPersistStg_InitNew", { "OleObjectPersistStg_InitNew", 0 },
"OleObjectPersistStg_Release", { "OleObjectPersistStg_Release", 0 },
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObjectCache_AddRef", { "OleObjectCache_AddRef", 0 },
"OleObjectCache_Cache", { "OleObjectCache_Cache", 0 },
"OleObjectCache_Release", { "OleObjectCache_Release", 0 },
"OleObject_Release", { "OleObject_Release", 0 },
NULL { NULL, 0 },
}; };
static const char *methods_olerender_draw_no_cache[] = static const struct expected_method methods_olerender_draw_no_cache[] =
{ {
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObject_AddRef", { "OleObject_AddRef", 0 },
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObjectPersistStg_AddRef", { "OleObjectPersistStg_AddRef", 0 },
"OleObjectPersistStg_InitNew", { "OleObjectPersistStg_InitNew", 0 },
"OleObjectPersistStg_Release", { "OleObjectPersistStg_Release", 0 },
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObjectRunnable_AddRef", { "OleObjectRunnable_AddRef", 0 },
"OleObjectRunnable_Run", { "OleObjectRunnable_Run", 0 },
"OleObjectRunnable_Release", { "OleObjectRunnable_Release", 0 },
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObject_Release", { "OleObject_Release", 0 },
NULL { NULL, 0 }
}; };
runnable = &OleObjectRunnable; runnable = &OleObjectRunnable;
@ -765,14 +783,14 @@ static void test_OleCreate(IStorage *pStorage)
hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_NONE, NULL, NULL, pStorage, (void **)&pObject); hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_NONE, NULL, NULL, pStorage, (void **)&pObject);
ok_ole_success(hr, "OleCreate"); ok_ole_success(hr, "OleCreate");
IOleObject_Release(pObject); IOleObject_Release(pObject);
ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list); CHECK_NO_EXTRA_METHODS();
expected_method_list = methods_olerender_draw; expected_method_list = methods_olerender_draw;
trace("OleCreate with OLERENDER_DRAW:\n"); trace("OleCreate with OLERENDER_DRAW:\n");
hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject); hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
ok_ole_success(hr, "OleCreate"); ok_ole_success(hr, "OleCreate");
IOleObject_Release(pObject); IOleObject_Release(pObject);
ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list); CHECK_NO_EXTRA_METHODS();
formatetc.cfFormat = CF_TEXT; formatetc.cfFormat = CF_TEXT;
formatetc.ptd = NULL; formatetc.ptd = NULL;
@ -788,7 +806,7 @@ static void test_OleCreate(IStorage *pStorage)
if (pObject) if (pObject)
{ {
IOleObject_Release(pObject); IOleObject_Release(pObject);
ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list); CHECK_NO_EXTRA_METHODS();
} }
expected_method_list = methods_olerender_asis; expected_method_list = methods_olerender_asis;
@ -796,7 +814,7 @@ static void test_OleCreate(IStorage *pStorage)
hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_ASIS, NULL, NULL, pStorage, (void **)&pObject); hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_ASIS, NULL, NULL, pStorage, (void **)&pObject);
ok_ole_success(hr, "OleCreate"); ok_ole_success(hr, "OleCreate");
IOleObject_Release(pObject); IOleObject_Release(pObject);
ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list); CHECK_NO_EXTRA_METHODS();
runnable = NULL; runnable = NULL;
expected_method_list = methods_olerender_draw_no_runnable; expected_method_list = methods_olerender_draw_no_runnable;
@ -804,7 +822,7 @@ static void test_OleCreate(IStorage *pStorage)
hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject); hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
ok_ole_success(hr, "OleCreate"); ok_ole_success(hr, "OleCreate");
IOleObject_Release(pObject); IOleObject_Release(pObject);
ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list); CHECK_NO_EXTRA_METHODS();
runnable = &OleObjectRunnable; runnable = &OleObjectRunnable;
cache = NULL; cache = NULL;
@ -813,7 +831,7 @@ static void test_OleCreate(IStorage *pStorage)
hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject); hr = OleCreate(&CLSID_Equation3, &IID_IOleObject, OLERENDER_DRAW, NULL, NULL, pStorage, (void **)&pObject);
ok_ole_success(hr, "OleCreate"); ok_ole_success(hr, "OleCreate");
IOleObject_Release(pObject); IOleObject_Release(pObject);
ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list); CHECK_NO_EXTRA_METHODS();
trace("end\n"); trace("end\n");
} }
@ -822,22 +840,22 @@ static void test_OleLoad(IStorage *pStorage)
HRESULT hr; HRESULT hr;
IOleObject *pObject; IOleObject *pObject;
static const char *methods_oleload[] = static const struct expected_method methods_oleload[] =
{ {
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObject_AddRef", { "OleObject_AddRef", 0 },
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObject_AddRef", { "OleObject_AddRef", 0 },
"OleObject_GetMiscStatus", { "OleObject_GetMiscStatus", 0 },
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObjectPersistStg_AddRef", { "OleObjectPersistStg_AddRef", 0 },
"OleObjectPersistStg_Load", { "OleObjectPersistStg_Load", 0 },
"OleObjectPersistStg_Release", { "OleObjectPersistStg_Release", 0 },
"OleObject_SetClientSite", { "OleObject_SetClientSite", 0 },
"OleObject_Release", { "OleObject_Release", 0 },
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObject_Release", { "OleObject_Release", 0 },
NULL { NULL, 0 }
}; };
expected_method_list = methods_oleload; expected_method_list = methods_oleload;
@ -849,7 +867,7 @@ static void test_OleLoad(IStorage *pStorage)
if (pObject) if (pObject)
{ {
IOleObject_Release(pObject); IOleObject_Release(pObject);
ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list); CHECK_NO_EXTRA_METHODS();
} }
} }
@ -1074,27 +1092,27 @@ static void test_data_cache(void)
WCHAR wszPath[MAX_PATH]; WCHAR wszPath[MAX_PATH];
static const WCHAR wszShell32[] = {'\\','s','h','e','l','l','3','2','.','d','l','l',0}; static const WCHAR wszShell32[] = {'\\','s','h','e','l','l','3','2','.','d','l','l',0};
static const char *methods_cacheinitnew[] = static const struct expected_method methods_cacheinitnew[] =
{ {
"AdviseSink_OnViewChange", { "AdviseSink_OnViewChange", 0 },
"AdviseSink_OnViewChange", { "AdviseSink_OnViewChange", 0 },
"draw_continue", { "draw_continue", 0 },
"DataObject_DAdvise", { "DataObject_DAdvise", 0 },
"DataObject_DAdvise", { "DataObject_DAdvise", 0 },
"DataObject_DUnadvise", { "DataObject_DUnadvise", 0 },
"DataObject_DUnadvise", { "DataObject_DUnadvise", 0 },
NULL { NULL, 0 }
}; };
static const char *methods_cacheload[] = static const struct expected_method methods_cacheload[] =
{ {
"AdviseSink_OnViewChange", { "AdviseSink_OnViewChange", 0 },
"draw_continue", { "draw_continue", 0 },
"draw_continue", { "draw_continue", 0 },
"draw_continue", { "draw_continue", 0 },
"DataObject_GetData", { "DataObject_GetData", 0 },
"DataObject_GetData", { "DataObject_GetData", 0 },
"DataObject_GetData", { "DataObject_GetData", 0 },
NULL { NULL, 0 }
}; };
GetSystemDirectory(szSystemDir, sizeof(szSystemDir)/sizeof(szSystemDir[0])); GetSystemDirectory(szSystemDir, sizeof(szSystemDir)/sizeof(szSystemDir[0]));
@ -1252,7 +1270,7 @@ static void test_data_cache(void)
IOleCacheControl_Release(pOleCacheControl); IOleCacheControl_Release(pOleCacheControl);
todo_wine { todo_wine {
ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list); CHECK_NO_EXTRA_METHODS();
} }
/* Test with loaded data */ /* Test with loaded data */
@ -1324,7 +1342,7 @@ static void test_data_cache(void)
IOleCache_Release(pOleCache); IOleCache_Release(pOleCache);
todo_wine { todo_wine {
ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list); CHECK_NO_EXTRA_METHODS();
} }
IStorage_Release(pStorage); IStorage_Release(pStorage);
@ -1483,36 +1501,36 @@ static void test_default_handler(void)
static void test_runnable(void) static void test_runnable(void)
{ {
static const char *methods_query_runnable[] = static const struct expected_method methods_query_runnable[] =
{ {
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
"OleObjectRunnable_AddRef", { "OleObjectRunnable_AddRef", 0 },
"OleObjectRunnable_IsRunning", { "OleObjectRunnable_IsRunning", 0 },
"OleObjectRunnable_Release", { "OleObjectRunnable_Release", 0 },
NULL { NULL, 0 }
}; };
static const char *methods_no_runnable[] = static const struct expected_method methods_no_runnable[] =
{ {
"OleObject_QueryInterface", { "OleObject_QueryInterface", 0 },
NULL { NULL, 0 }
}; };
IOleObject *object = &OleObject; IOleObject *object = &OleObject;
expected_method_list = methods_query_runnable; expected_method_list = methods_query_runnable;
ok(OleIsRunning(object), "Object should be running\n"); ok(OleIsRunning(object), "Object should be running\n");
ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list); CHECK_NO_EXTRA_METHODS();
g_isRunning = FALSE; g_isRunning = FALSE;
expected_method_list = methods_query_runnable; expected_method_list = methods_query_runnable;
ok(OleIsRunning(object) == FALSE, "Object should not be running\n"); ok(OleIsRunning(object) == FALSE, "Object should not be running\n");
ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list); CHECK_NO_EXTRA_METHODS();
g_showRunnable = FALSE; /* QueryInterface(IID_IRunnableObject, ...) will fail */ g_showRunnable = FALSE; /* QueryInterface(IID_IRunnableObject, ...) will fail */
expected_method_list = methods_no_runnable; expected_method_list = methods_no_runnable;
ok(OleIsRunning(object), "Object without IRunnableObject should be running\n"); ok(OleIsRunning(object), "Object without IRunnableObject should be running\n");
ok(!*expected_method_list, "Method sequence starting from %s not called\n", *expected_method_list); CHECK_NO_EXTRA_METHODS();
g_isRunning = TRUE; g_isRunning = TRUE;
g_showRunnable = TRUE; g_showRunnable = TRUE;