msctf/tests: Fix failures on Win7 and East-Asian machines.

This commit is contained in:
Greg Geldorp 2011-01-15 22:54:20 +01:00 committed by Alexandre Julliard
parent c63cf7014b
commit e8ac427143
1 changed files with 92 additions and 23 deletions

View File

@ -46,6 +46,7 @@ static ITextStoreACPSink *ACPSink;
#define SINK_FIRED 2
#define SINK_IGNORE 3
#define SINK_OPTIONAL 4
#define SINK_SAVE 5
#define SINK_ACTION_MASK 0xff
#define SINK_OPTION_MASK 0xff00
@ -54,6 +55,7 @@ static ITextStoreACPSink *ACPSink;
#define SINK_OPTION_TODO 0x0100
#define FOCUS_IGNORE (ITfDocumentMgr*)0xffffffff
#define FOCUS_SAVE (ITfDocumentMgr*)0xfffffffe
static BOOL test_ShouldActivate = FALSE;
static BOOL test_ShouldDeactivate = FALSE;
@ -63,6 +65,8 @@ static DWORD tmSinkRefCount;
static DWORD documentStatus;
static ITfDocumentMgr *test_CurrentFocus = NULL;
static ITfDocumentMgr *test_PrevFocus = NULL;
static ITfDocumentMgr *test_LastCurrentFocus = FOCUS_SAVE;
static ITfDocumentMgr *test_FirstPrevFocus = FOCUS_SAVE;
static INT test_OnSetFocus = SINK_UNEXPECTED;
static INT test_OnInitDocumentMgr = SINK_UNEXPECTED;
static INT test_OnPushContext = SINK_UNEXPECTED;
@ -108,6 +112,10 @@ static inline void _sink_fire_ok(INT *sink, const CHAR* name)
case SINK_IGNORE:
winetest_trace("Ignoring %s\n",name);
return;
case SINK_SAVE:
count = expected_count(sink) + 1;
*sink = (*sink & ~SINK_EXPECTED_COUNT_MASK) + (count << 16);
return;
default:
if (todo)
todo_wine winetest_ok(0, "Unexpected %s sink\n",name);
@ -123,6 +131,7 @@ static inline void _sink_check_ok(INT *sink, const CHAR* name)
{
int action = *sink & SINK_ACTION_MASK;
int todo = *sink & SINK_OPTION_TODO;
int count = expected_count(sink);
switch (action)
{
@ -133,6 +142,10 @@ static inline void _sink_check_ok(INT *sink, const CHAR* name)
break;
case SINK_IGNORE:
return;
case SINK_SAVE:
if (count == 0 && winetest_interactive)
winetest_trace("optional sink %s not fired\n",name);
break;
default:
if (todo)
todo_wine winetest_ok(0, "%s not fired as expected, in state %x\n",name,*sink);
@ -144,6 +157,20 @@ static inline void _sink_check_ok(INT *sink, const CHAR* name)
#define sink_check_ok(a,b) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _sink_check_ok(a,b)
static inline void _sink_check_saved(INT *sink, ITfDocumentMgr *PrevFocus, ITfDocumentMgr *CurrentFocus, const CHAR* name)
{
int count = expected_count(sink);
_sink_check_ok(sink, name);
if (PrevFocus != FOCUS_IGNORE && count != 0)
winetest_ok(PrevFocus == test_FirstPrevFocus, "%s expected prev focus %p got %p\n", name, PrevFocus, test_FirstPrevFocus);
if (CurrentFocus != FOCUS_IGNORE && count != 0)
winetest_ok(CurrentFocus == test_LastCurrentFocus, "%s expected current focus %p got %p\n", name, CurrentFocus, test_LastCurrentFocus);
test_FirstPrevFocus = FOCUS_SAVE;
test_LastCurrentFocus = FOCUS_SAVE;
}
#define sink_check_saved(s,p,c,n) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _sink_check_saved(s,p,c,n)
/**********************************************************************
* ITextStoreACP
**********************************************************************/
@ -509,9 +536,16 @@ static HRESULT WINAPI ThreadMgrEventSink_OnSetFocus(ITfThreadMgrEventSink *iface
ITfDocumentMgr *pdimFocus, ITfDocumentMgr *pdimPrevFocus)
{
sink_fire_ok(&test_OnSetFocus,"ThreadMgrEventSink_OnSetFocus");
if (test_CurrentFocus != FOCUS_IGNORE)
if (test_CurrentFocus == FOCUS_SAVE)
test_LastCurrentFocus = pdimFocus;
else if (test_CurrentFocus != FOCUS_IGNORE)
ok(pdimFocus == test_CurrentFocus,"Sink reports wrong focus\n");
if (test_PrevFocus != FOCUS_IGNORE)
if (test_PrevFocus == FOCUS_SAVE)
{
if (test_FirstPrevFocus == FOCUS_SAVE)
test_FirstPrevFocus = pdimPrevFocus;
}
else if (test_PrevFocus != FOCUS_IGNORE)
ok(pdimPrevFocus == test_PrevFocus,"Sink reports wrong previous focus\n");
return S_OK;
}
@ -1201,8 +1235,10 @@ static void test_Activate(void)
{
HRESULT hr;
test_ShouldActivate = TRUE; /* Win7 */
hr = ITfInputProcessorProfiles_ActivateLanguageProfile(g_ipp,&CLSID_FakeService,gLangid,&CLSID_FakeService);
ok(SUCCEEDED(hr),"Failed to Activate text service\n");
test_ShouldActivate = FALSE;
}
@ -1408,7 +1444,7 @@ static void test_startSession(void)
test_CurrentFocus = g_dm;
test_PrevFocus = NULL;
test_OnSetFocus = SINK_EXPECTED;
test_OnSetFocus = SINK_OPTIONAL; /* Doesn't always fire on Win7 */
hr = ITfThreadMgr_SetFocus(g_tm,g_dm);
ok(SUCCEEDED(hr),"SetFocus Failed\n");
sink_check_ok(&test_OnSetFocus,"OnSetFocus");
@ -1418,7 +1454,6 @@ static void test_startSession(void)
ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
cnt = ITfDocumentMgr_Release(g_dm);
ok(cnt == 2,"DocumentMgr refcount not expected (2 vs %i)\n",cnt);
hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
ok(SUCCEEDED(hr),"GetFocus Failed\n");
@ -1553,7 +1588,7 @@ static void test_endSession(void)
test_ShouldDeactivate = TRUE;
test_CurrentFocus = NULL;
test_PrevFocus = g_dm;
test_OnSetFocus = SINK_EXPECTED;
test_OnSetFocus = SINK_OPTIONAL; /* Doesn't fire on Win7 */
hr = ITfThreadMgr_Deactivate(g_tm);
ok(SUCCEEDED(hr),"Failed to Deactivate\n");
sink_check_ok(&test_OnSetFocus,"OnSetFocus");
@ -1970,9 +2005,11 @@ static void test_AssociateFocus(void)
ITfThreadMgr_GetFocus(g_tm, &dmorig);
test_CurrentFocus = NULL;
test_PrevFocus = dmorig;
test_OnSetFocus = SINK_EXPECTED;
test_OnSetFocus = SINK_OPTIONAL; /* Doesn't always fire on Win7 */
test_ACP_GetStatus = SINK_OPTIONAL;
hr = ITfThreadMgr_SetFocus(g_tm,NULL);
sink_check_ok(&test_OnSetFocus,"OnSetFocus");
test_ACP_GetStatus = SINK_UNEXPECTED;
ITfDocumentMgr_Release(dmorig);
hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&dm1);
@ -1992,30 +2029,52 @@ static void test_AssociateFocus(void)
test_OnInitDocumentMgr = SINK_OPTIONAL; /* Vista and greater */
test_OnPushContext = SINK_OPTIONAL; /* Vista and greater */
test_OnSetFocus = SINK_OPTIONAL; /* Win7 */
test_PrevFocus = NULL;
test_CurrentFocus = FOCUS_IGNORE;
ShowWindow(wnd1,SW_SHOWNORMAL);
test_OnSetFocus = SINK_UNEXPECTED;
SetFocus(wnd1);
sink_check_ok(&test_OnInitDocumentMgr,"OnInitDocumentMgr");
sink_check_ok(&test_OnPushContext,"OnPushContext");
test_OnSetFocus = SINK_OPTIONAL; /* Vista and greater */
test_ACP_RequestLock = SINK_OPTIONAL; /* Win7 x64 */
test_ACP_GetSelection = SINK_OPTIONAL; /* Win7 x64 */
ITfThreadMgr_GetFocus(g_tm, &test_PrevFocus);
test_CurrentFocus = FOCUS_IGNORE; /* This is a default system context */
processPendingMessages();
sink_check_ok(&test_OnSetFocus,"OnSetFocus");
test_ACP_RequestLock = SINK_UNEXPECTED;
test_ACP_GetSelection = SINK_UNEXPECTED;
test_CurrentFocus = dm1;
test_PrevFocus = FOCUS_IGNORE;
test_OnSetFocus = SINK_EXPECTED;
test_OnSetFocus = SINK_OPTIONAL;
test_ShouldDeactivate = SINK_OPTIONAL;
hr = ITfThreadMgr_AssociateFocus(g_tm,wnd1,dm1,&olddm);
ok(SUCCEEDED(hr),"AssociateFocus failed\n");
sink_check_ok(&test_OnSetFocus,"OnSetFocus");
test_ShouldDeactivate = SINK_UNEXPECTED;
processPendingMessages();
ITfThreadMgr_GetFocus(g_tm, &dmcheck);
ok(dmcheck == dm1, "Expected DocumentMgr not focused\n");
ITfDocumentMgr_Release(dmcheck);
if (dmcheck != NULL)
{
ok(dmcheck == dm1, "Expected DocumentMgr not focused\n");
ITfDocumentMgr_Release(dmcheck);
}
else
{
/* Sometimes we need to explicitly set focus on Win7 */
test_CurrentFocus = dm1;
test_PrevFocus = FOCUS_IGNORE;
test_OnSetFocus = SINK_EXPECTED;
ITfThreadMgr_SetFocus(g_tm, dm1);
sink_check_ok(&test_OnSetFocus,"OnSetFocus");
}
hr = ITfThreadMgr_AssociateFocus(g_tm,wnd2,dm2,&olddm);
ok(SUCCEEDED(hr),"AssociateFocus failed\n");
@ -2031,12 +2090,12 @@ static void test_AssociateFocus(void)
ok(dmcheck == dm1, "Expected DocumentMgr not focused\n");
ITfDocumentMgr_Release(dmcheck);
test_CurrentFocus = dm2;
test_PrevFocus = dm1;
test_OnSetFocus = SINK_OPTIONAL; /* wine and Winxp */
test_CurrentFocus = FOCUS_SAVE;
test_PrevFocus = FOCUS_SAVE;
test_OnSetFocus = SINK_SAVE;
ShowWindow(wnd2,SW_SHOWNORMAL);
SetFocus(wnd2);
sink_check_ok(&test_OnSetFocus,"OnSetFocus");
sink_check_saved(&test_OnSetFocus,dm1,dm2,"OnSetFocus");
test_CurrentFocus = FOCUS_IGNORE; /* occasional wine race */
test_PrevFocus = FOCUS_IGNORE; /* occasional wine race */
test_OnSetFocus = SINK_IGNORE; /* occasional wine race */
@ -2046,12 +2105,12 @@ static void test_AssociateFocus(void)
SetFocus(wnd3);
processPendingMessages();
test_CurrentFocus = dm1;
test_PrevFocus = dm2;
test_OnSetFocus = SINK_EXPECTED;
test_CurrentFocus = FOCUS_SAVE;
test_PrevFocus = FOCUS_SAVE;
test_OnSetFocus = SINK_SAVE;
SetFocus(wnd1);
processPendingMessages();
sink_check_ok(&test_OnSetFocus,"OnSetFocus");
sink_check_saved(&test_OnSetFocus,dm2,dm1,"OnSetFocus");
hr = ITfThreadMgr_AssociateFocus(g_tm,wnd3,NULL,&olddm);
ok(SUCCEEDED(hr),"AssociateFocus failed\n");
@ -2061,16 +2120,16 @@ static void test_AssociateFocus(void)
test_CurrentFocus = dmorig;
test_PrevFocus = dm1;
test_OnSetFocus = SINK_EXPECTED;
test_ACP_GetStatus = SINK_EXPECTED;
test_ACP_GetStatus = SINK_IGNORE;
ITfThreadMgr_SetFocus(g_tm,dmorig);
sink_check_ok(&test_OnSetFocus,"OnSetFocus");
test_CurrentFocus = FOCUS_IGNORE; /* NULL on XP, system default on Vista */
test_PrevFocus = dmorig;
test_OnSetFocus = SINK_EXPECTED;
test_CurrentFocus = FOCUS_SAVE;
test_PrevFocus = FOCUS_SAVE;
test_OnSetFocus = SINK_SAVE;
SetFocus(wnd3);
processPendingMessages();
sink_check_ok(&test_OnSetFocus,"OnSetFocus");
sink_check_saved(&test_OnSetFocus,dmorig,FOCUS_IGNORE,"OnSetFocus"); /* CurrentFocus NULL on XP, system default on Vista */
hr = ITfThreadMgr_AssociateFocus(g_tm,wnd2,NULL,&olddm);
ok(SUCCEEDED(hr),"AssociateFocus failed\n");
@ -2081,28 +2140,38 @@ static void test_AssociateFocus(void)
ok(olddm == dm1, "incorrect old DocumentMgr returned\n");
ITfDocumentMgr_Release(olddm);
test_OnSetFocus = SINK_IGNORE; /* OnSetFocus fires a couple of times on Win7 */
test_CurrentFocus = FOCUS_IGNORE;
test_PrevFocus = FOCUS_IGNORE;
SetFocus(wnd2);
processPendingMessages();
SetFocus(wnd1);
processPendingMessages();
test_OnSetFocus = SINK_UNEXPECTED;
ITfDocumentMgr_Release(dm1);
ITfDocumentMgr_Release(dm2);
test_CurrentFocus = dmorig;
test_PrevFocus = FOCUS_IGNORE;
test_OnSetFocus = SINK_EXPECTED;
test_OnSetFocus = SINK_OPTIONAL;
test_ACP_GetStatus = SINK_IGNORE;
ITfThreadMgr_SetFocus(g_tm,dmorig);
sink_check_ok(&test_OnSetFocus,"OnSetFocus");
test_OnSetFocus = SINK_IGNORE; /* OnSetFocus fires a couple of times on Win7 */
test_CurrentFocus = FOCUS_IGNORE;
test_PrevFocus = FOCUS_IGNORE;
DestroyWindow(wnd1);
DestroyWindow(wnd2);
test_OnSetFocus = SINK_UNEXPECTED;
test_OnPopContext = SINK_OPTIONAL; /* Vista and greater */
test_OnSetFocus = SINK_OPTIONAL; /* Vista and greater */
ITfThreadMgr_GetFocus(g_tm, &test_PrevFocus);
test_CurrentFocus = NULL;
test_ShouldDeactivate = TRUE; /* Win7 */
DestroyWindow(wnd3);
test_ShouldDeactivate = FALSE;
sink_check_ok(&test_OnSetFocus,"OnSetFocus");
sink_check_ok(&test_OnPopContext,"OnPopContext");
}