Something went wrong. Try again.
Reactos
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917/* * Component Object Tests * * Copyright 2005 Robert Shearman * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
#define COBJMACROS#define CONST_VTABLE
#include <stdarg.h>#include <stdio.h>
#include "windef.h"#include "winbase.h"#define USE_COM_CONTEXT_DEF#include "objbase.h"#include "shlguid.h"#include "urlmon.h" /* for CLSID_FileProtocol */#include "dde.h"#include "cguid.h"
#include "ctxtcall.h"
#include "wine/test.h"#include "initguid.h"
#define DEFINE_EXPECT(func) \ static BOOL expect_ ## func = FALSE; static unsigned int called_ ## func = 0
#define SET_EXPECT(func) \ expect_ ## func = TRUE
#define CHECK_EXPECT2(func) \ do { \ ok(expect_ ##func, "unexpected call " #func "\n"); \ called_ ## func++; \ }while(0)
#define CHECK_EXPECT(func) \ do { \ CHECK_EXPECT2(func); \ expect_ ## func = FALSE; \ }while(0)
#define CHECK_CALLED(func, n) \ do { \ ok(called_ ## func == n, "expected " #func " called %u times, got %u\n", n, called_ ## func); \ expect_ ## func = FALSE; \ called_ ## func = 0; \ }while(0)
DEFINE_EXPECT(CreateStub);DEFINE_EXPECT(PreInitialize);DEFINE_EXPECT(PostInitialize);DEFINE_EXPECT(PreUninitialize);DEFINE_EXPECT(PostUninitialize);
/* functions that are not present on all versions of Windows */static HRESULT (WINAPI * pCoInitializeEx)(LPVOID lpReserved, DWORD dwCoInit);static HRESULT (WINAPI * pCoGetObjectContext)(REFIID riid, LPVOID *ppv);static HRESULT (WINAPI * pCoSwitchCallContext)(IUnknown *pObject, IUnknown **ppOldObject);static HRESULT (WINAPI * pCoGetTreatAsClass)(REFCLSID clsidOld, LPCLSID pClsidNew);static HRESULT (WINAPI * pCoTreatAsClass)(REFCLSID clsidOld, REFCLSID pClsidNew);static HRESULT (WINAPI * pCoGetContextToken)(ULONG_PTR *token);static HRESULT (WINAPI * pCoGetApartmentType)(APTTYPE *type, APTTYPEQUALIFIER *qualifier);static LONG (WINAPI * pRegDeleteKeyExA)(HKEY, LPCSTR, REGSAM, DWORD);static LONG (WINAPI * pRegOverridePredefKey)(HKEY key, HKEY override);
static BOOL (WINAPI *pActivateActCtx)(HANDLE,ULONG_PTR*);static HANDLE (WINAPI *pCreateActCtxW)(PCACTCTXW);static BOOL (WINAPI *pDeactivateActCtx)(DWORD,ULONG_PTR);static BOOL (WINAPI *pIsWow64Process)(HANDLE, LPBOOL);static void (WINAPI *pReleaseActCtx)(HANDLE);
#define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)#define ok_more_than_one_lock() ok(cLocks > 0, "Number of locks should be > 0, but actually is %d\n", cLocks)#define ok_no_locks() ok(cLocks == 0, "Number of locks should be 0, but actually is %d\n", cLocks)
static const CLSID CLSID_non_existent = { 0x12345678, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };static const CLSID CLSID_StdFont = { 0x0be35203, 0x8f91, 0x11ce, { 0x9d, 0xe3, 0x00, 0xaa, 0x00, 0x4b, 0xb8, 0x51 } };static const GUID IID_Testiface = { 0x22222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };static const GUID IID_Testiface2 = { 0x32222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };static const GUID IID_Testiface3 = { 0x42222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };static const GUID IID_Testiface4 = { 0x52222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };static const GUID IID_Testiface5 = { 0x62222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };static const GUID IID_Testiface6 = { 0x72222222, 0x1234, 0x1234, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0 } };static const GUID IID_TestPS = { 0x66666666, 0x8888, 0x7777, { 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 } };
DEFINE_GUID(CLSID_testclsid, 0xacd014c7,0x9535,0x4fac,0x8b,0x53,0xa4,0x8c,0xa7,0xf4,0xd7,0x26);
static const WCHAR stdfont[] = {'S','t','d','F','o','n','t',0};static const WCHAR wszNonExistent[] = {'N','o','n','E','x','i','s','t','e','n','t',0};static const WCHAR wszCLSID_StdFont[] ={ '{','0','b','e','3','5','2','0','3','-','8','f','9','1','-','1','1','c','e','-', '9','d','e','3','-','0','0','a','a','0','0','4','b','b','8','5','1','}',0};static const WCHAR progidW[] = {'P','r','o','g','I','d','.','P','r','o','g','I','d',0};static const WCHAR cf_brokenW[] = {'{','0','0','0','0','0','0','0','1','-','0','0','0','0','-','0','0','0','0','-', 'c','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}','a',0};
DEFINE_GUID(IID_IWineTest, 0x5201163f, 0x8164, 0x4fd0, 0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd);DEFINE_GUID(CLSID_WineOOPTest, 0x5201163f, 0x8164, 0x4fd0, 0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd);
static LONG cLocks;
static void LockModule(void){ InterlockedIncrement(&cLocks);}
static void UnlockModule(void){ InterlockedDecrement(&cLocks);}
static HRESULT WINAPI Test_IClassFactory_QueryInterface( LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj){ if (ppvObj == NULL) return E_POINTER;
if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IClassFactory)) { *ppvObj = iface; IClassFactory_AddRef(iface); return S_OK; }
*ppvObj = NULL; return E_NOINTERFACE;}
static ULONG WINAPI Test_IClassFactory_AddRef(LPCLASSFACTORY iface){ LockModule(); return 2; /* non-heap-based object */}
static ULONG WINAPI Test_IClassFactory_Release(LPCLASSFACTORY iface){ UnlockModule(); return 1; /* non-heap-based object */}
static IID create_instance_iid;static HRESULT WINAPI Test_IClassFactory_CreateInstance( LPCLASSFACTORY iface, IUnknown *pUnkOuter, REFIID riid, LPVOID *ppvObj){ *ppvObj = NULL; create_instance_iid = *riid; if (pUnkOuter) return CLASS_E_NOAGGREGATION; return E_NOINTERFACE;}
static HRESULT WINAPI Test_IClassFactory_LockServer( LPCLASSFACTORY iface, BOOL fLock){ return S_OK;}
static const IClassFactoryVtbl TestClassFactory_Vtbl ={ Test_IClassFactory_QueryInterface, Test_IClassFactory_AddRef, Test_IClassFactory_Release, Test_IClassFactory_CreateInstance, Test_IClassFactory_LockServer};
static IClassFactory Test_ClassFactory = { &TestClassFactory_Vtbl };
static WCHAR manifest_path[MAX_PATH];
static BOOL create_manifest_file(const char *filename, const char *manifest){ int manifest_len; DWORD size; HANDLE file; WCHAR path[MAX_PATH];
MultiByteToWideChar( CP_ACP, 0, filename, -1, path, MAX_PATH ); GetFullPathNameW(path, ARRAY_SIZE(manifest_path), manifest_path, NULL);
manifest_len = strlen(manifest); file = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError()); if(file == INVALID_HANDLE_VALUE) return FALSE; WriteFile(file, manifest, manifest_len, &size, NULL); CloseHandle(file);
return TRUE;}
static HANDLE activate_context(const char *manifest, ULONG_PTR *cookie){ WCHAR path[MAX_PATH]; ACTCTXW actctx; HANDLE handle; BOOL ret;
if (!pCreateActCtxW) return NULL;
create_manifest_file("file.manifest", manifest);
MultiByteToWideChar( CP_ACP, 0, "file.manifest", -1, path, MAX_PATH ); memset(&actctx, 0, sizeof(ACTCTXW)); actctx.cbSize = sizeof(ACTCTXW); actctx.lpSource = path;
handle = pCreateActCtxW(&actctx); ok(handle != INVALID_HANDLE_VALUE || broken(handle == INVALID_HANDLE_VALUE) /* some old XP/2k3 versions */, "handle == INVALID_HANDLE_VALUE, error %u\n", GetLastError()); if (handle == INVALID_HANDLE_VALUE) { win_skip("activation context generation failed, some tests will be skipped\n"); handle = NULL; }
ok(actctx.cbSize == sizeof(ACTCTXW), "actctx.cbSize=%d\n", actctx.cbSize); ok(actctx.dwFlags == 0, "actctx.dwFlags=%d\n", actctx.dwFlags); ok(actctx.lpSource == path, "actctx.lpSource=%p\n", actctx.lpSource); ok(actctx.wProcessorArchitecture == 0, "actctx.wProcessorArchitecture=%d\n", actctx.wProcessorArchitecture); ok(actctx.wLangId == 0, "actctx.wLangId=%d\n", actctx.wLangId); ok(actctx.lpAssemblyDirectory == NULL, "actctx.lpAssemblyDirectory=%p\n", actctx.lpAssemblyDirectory); ok(actctx.lpResourceName == NULL, "actctx.lpResourceName=%p\n", actctx.lpResourceName); ok(actctx.lpApplicationName == NULL, "actctx.lpApplicationName=%p\n", actctx.lpApplicationName); ok(actctx.hModule == NULL, "actctx.hModule=%p\n", actctx.hModule);
DeleteFileA("file.manifest");
if (handle) { ret = pActivateActCtx(handle, cookie); ok(ret, "ActivateActCtx failed: %u\n", GetLastError()); }
return handle;}
static const char actctx_manifest[] ="<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">""<assemblyIdentity version=\"1.2.3.4\" name=\"Wine.Test\" type=\"win32\""" publicKeyToken=\"6595b6414666f1df\" />""<file name=\"testlib.dll\">"" <comClass"" clsid=\"{0000033a-0000-0000-c000-000000000046}\""" progid=\"FTMarshal\""" />"" <comClass"" clsid=\"{5201163f-8164-4fd0-a1a2-5d5a3654d3bd}\""" progid=\"WineOOPTest\""" />"" <comClass description=\"Test com class\""" clsid=\"{12345678-1234-1234-1234-56789abcdef0}\""" progid=\"ProgId.ProgId\""" miscStatusIcon=\"recomposeonresize\""" />"" <comClass description=\"CustomFont Description\" clsid=\"{0be35203-8f91-11ce-9de3-00aa004bb851}\""" progid=\"CustomFont\""" miscStatusIcon=\"recomposeonresize\""" miscStatusContent=\"insideout\""" />"" <comClass description=\"StdFont Description\" clsid=\"{0be35203-8f91-11ce-9de3-00aa004bb852}\""" progid=\"StdFont\""" />"" <comClass clsid=\"{62222222-1234-1234-1234-56789abcdef0}\" >"" <progid>ProgId.ProgId.1</progid>"" </comClass>"" <comInterfaceProxyStub "" name=\"Iifaceps\""" iid=\"{22222222-1234-1234-1234-56789abcdef0}\""" proxyStubClsid32=\"{66666666-8888-7777-6666-555555555555}\""" />""</file>"" <comInterfaceExternalProxyStub "" name=\"Iifaceps2\""" iid=\"{32222222-1234-1234-1234-56789abcdef0}\""" />"" <comInterfaceExternalProxyStub "" name=\"Iifaceps3\""" iid=\"{42222222-1234-1234-1234-56789abcdef0}\""" proxyStubClsid32=\"{66666666-8888-7777-6666-555555555555}\""" />"" <comInterfaceExternalProxyStub "" name=\"Iifaceps4\""" iid=\"{52222222-1234-1234-1234-56789abcdef0}\""" proxyStubClsid32=\"{00000000-0000-0000-0000-000000000000}\""" />"" <clrClass "" clsid=\"{72222222-1234-1234-1234-56789abcdef0}\""" name=\"clrclass\""" >"" <progid>clrprogid.1</progid>"" </clrClass>""</assembly>";
DEFINE_GUID(CLSID_Testclass, 0x12345678, 0x1234, 0x1234, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0);
static void test_ProgIDFromCLSID(void){ ULONG_PTR cookie = 0; LPWSTR progid; HANDLE handle; HRESULT hr;
hr = ProgIDFromCLSID(&CLSID_StdFont, &progid); ok(hr == S_OK, "ProgIDFromCLSID failed with error 0x%08x\n", hr); if (hr == S_OK) { ok(!lstrcmpiW(progid, stdfont), "Didn't get expected prog ID\n"); CoTaskMemFree(progid); }
progid = (LPWSTR)0xdeadbeef; hr = ProgIDFromCLSID(&CLSID_non_existent, &progid); ok(hr == REGDB_E_CLASSNOTREG, "ProgIDFromCLSID returned %08x\n", hr); ok(progid == NULL, "ProgIDFromCLSID returns with progid %p\n", progid);
hr = ProgIDFromCLSID(&CLSID_StdFont, NULL); ok(hr == E_INVALIDARG, "ProgIDFromCLSID should return E_INVALIDARG instead of 0x%08x\n", hr);
if ((handle = activate_context(actctx_manifest, &cookie))) { static const WCHAR customfontW[] = {'C','u','s','t','o','m','F','o','n','t',0};
hr = ProgIDFromCLSID(&CLSID_non_existent, &progid); ok(hr == S_OK, "got 0x%08x\n", hr); ok(!lstrcmpiW(progid, progidW), "got %s\n", wine_dbgstr_w(progid)); CoTaskMemFree(progid);
/* try something registered and redirected */ progid = NULL; hr = ProgIDFromCLSID(&CLSID_StdFont, &progid); ok(hr == S_OK, "got 0x%08x\n", hr); ok(!lstrcmpiW(progid, customfontW), "got wrong progid %s\n", wine_dbgstr_w(progid)); CoTaskMemFree(progid);
/* classes without default progid, progid list is not used */ progid = (void *)0xdeadbeef; hr = ProgIDFromCLSID(&IID_Testiface5, &progid); ok(hr == REGDB_E_CLASSNOTREG && progid == NULL, "got 0x%08x, progid %p\n", hr, progid);
progid = (void *)0xdeadbeef; hr = ProgIDFromCLSID(&IID_Testiface6, &progid); ok(hr == REGDB_E_CLASSNOTREG && progid == NULL, "got 0x%08x, progid %p\n", hr, progid);
pDeactivateActCtx(0, cookie); pReleaseActCtx(handle); }}
static void test_CLSIDFromProgID(void){ ULONG_PTR cookie = 0; HANDLE handle; CLSID clsid; HRESULT hr = CLSIDFromProgID(stdfont, &clsid); ok(hr == S_OK, "CLSIDFromProgID failed with error 0x%08x\n", hr); ok(IsEqualCLSID(&clsid, &CLSID_StdFont), "clsid wasn't equal to CLSID_StdFont\n");
hr = CLSIDFromString(stdfont, &clsid); ok_ole_success(hr, "CLSIDFromString"); ok(IsEqualCLSID(&clsid, &CLSID_StdFont), "clsid wasn't equal to CLSID_StdFont\n");
/* test some failure cases */
hr = CLSIDFromProgID(wszNonExistent, NULL); ok(hr == E_INVALIDARG, "CLSIDFromProgID should have returned E_INVALIDARG instead of 0x%08x\n", hr);
hr = CLSIDFromProgID(NULL, &clsid); ok(hr == E_INVALIDARG, "CLSIDFromProgID should have returned E_INVALIDARG instead of 0x%08x\n", hr);
memset(&clsid, 0xcc, sizeof(clsid)); hr = CLSIDFromProgID(wszNonExistent, &clsid); ok(hr == CO_E_CLASSSTRING, "CLSIDFromProgID on nonexistent ProgID should have returned CO_E_CLASSSTRING instead of 0x%08x\n", hr); ok(IsEqualCLSID(&clsid, &CLSID_NULL), "CLSIDFromProgID should have set clsid to all-zeros on failure\n");
/* fails without proper context */ memset(&clsid, 0xcc, sizeof(clsid)); hr = CLSIDFromProgID(progidW, &clsid); ok(hr == CO_E_CLASSSTRING, "got 0x%08x\n", hr); ok(IsEqualCLSID(&clsid, &CLSID_NULL), "wrong clsid\n");
if ((handle = activate_context(actctx_manifest, &cookie))) { GUID clsid1;
memset(&clsid, 0xcc, sizeof(clsid)); hr = CLSIDFromProgID(wszNonExistent, &clsid); ok(hr == CO_E_CLASSSTRING, "got 0x%08x\n", hr); ok(IsEqualCLSID(&clsid, &CLSID_NULL), "should have zero CLSID on failure\n");
/* CLSIDFromString() doesn't check activation context */ hr = CLSIDFromString(progidW, &clsid); ok(hr == CO_E_CLASSSTRING, "got 0x%08x\n", hr);
clsid = CLSID_NULL; hr = CLSIDFromProgID(progidW, &clsid); ok(hr == S_OK, "got 0x%08x\n", hr); /* it returns generated CLSID here */ ok(!IsEqualCLSID(&clsid, &CLSID_non_existent) && !IsEqualCLSID(&clsid, &CLSID_NULL), "got wrong clsid %s\n", wine_dbgstr_guid(&clsid));
/* duplicate progid present in context - returns generated guid here too */ clsid = CLSID_NULL; hr = CLSIDFromProgID(stdfont, &clsid); ok(hr == S_OK, "got 0x%08x\n", hr); clsid1 = CLSID_StdFont; /* that's where it differs from StdFont */ clsid1.Data4[7] = 0x52; ok(!IsEqualCLSID(&clsid, &CLSID_StdFont) && !IsEqualCLSID(&clsid, &CLSID_NULL) && !IsEqualCLSID(&clsid, &clsid1), "got %s\n", wine_dbgstr_guid(&clsid));
pDeactivateActCtx(0, cookie); pReleaseActCtx(handle); }}
static void test_CLSIDFromString(void){ CLSID clsid; WCHAR wszCLSID_Broken[50]; UINT i;
HRESULT hr = CLSIDFromString(wszCLSID_StdFont, &clsid); ok_ole_success(hr, "CLSIDFromString"); ok(IsEqualCLSID(&clsid, &CLSID_StdFont), "clsid wasn't equal to CLSID_StdFont\n");
memset(&clsid, 0xab, sizeof(clsid)); hr = CLSIDFromString(NULL, &clsid); ok(hr == S_OK, "got 0x%08x\n", hr); ok(IsEqualCLSID(&clsid, &CLSID_NULL), "clsid wasn't equal to CLSID_NULL\n");
/* string is longer, but starts with a valid CLSID */ memset(&clsid, 0, sizeof(clsid)); hr = CLSIDFromString(cf_brokenW, &clsid); ok(hr == CO_E_CLASSSTRING, "got 0x%08x\n", hr); ok(IsEqualCLSID(&clsid, &IID_IClassFactory), "got %s\n", wine_dbgstr_guid(&clsid));
lstrcpyW(wszCLSID_Broken, wszCLSID_StdFont); for(i = lstrlenW(wszCLSID_StdFont); i < 49; i++) wszCLSID_Broken[i] = 'A'; wszCLSID_Broken[i] = '\0';
memset(&clsid, 0, sizeof(CLSID)); hr = CLSIDFromString(wszCLSID_Broken, &clsid); ok(hr == CO_E_CLASSSTRING, "Got %08x\n", hr); ok(IsEqualCLSID(&clsid, &CLSID_StdFont), "clsid wasn't equal to CLSID_StdFont\n");
wszCLSID_Broken[lstrlenW(wszCLSID_StdFont)-1] = 'A'; memset(&clsid, 0, sizeof(CLSID)); hr = CLSIDFromString(wszCLSID_Broken, &clsid); ok(hr == CO_E_CLASSSTRING, "Got %08x\n", hr); ok(IsEqualCLSID(&clsid, &CLSID_StdFont), "clsid wasn't equal to CLSID_StdFont\n");
wszCLSID_Broken[lstrlenW(wszCLSID_StdFont)] = '\0'; memset(&clsid, 0, sizeof(CLSID)); hr = CLSIDFromString(wszCLSID_Broken, &clsid); ok(hr == CO_E_CLASSSTRING, "Got %08x\n", hr); ok(IsEqualCLSID(&clsid, &CLSID_StdFont), "clsid wasn't equal to CLSID_StdFont\n");
wszCLSID_Broken[lstrlenW(wszCLSID_StdFont)-1] = '\0'; memset(&clsid, 0, sizeof(CLSID)); hr = CLSIDFromString(wszCLSID_Broken, &clsid); ok(hr == CO_E_CLASSSTRING, "Got %08x\n", hr); ok(IsEqualCLSID(&clsid, &CLSID_StdFont), "clsid wasn't equal to CLSID_StdFont\n");
memset(&clsid, 0xcc, sizeof(CLSID)); hr = CLSIDFromString(wszCLSID_Broken+1, &clsid); ok(hr == CO_E_CLASSSTRING, "Got %08x\n", hr); ok(IsEqualCLSID(&clsid, &CLSID_NULL), "clsid wasn't equal to CLSID_NULL\n");
wszCLSID_Broken[9] = '*'; memset(&clsid, 0xcc, sizeof(CLSID)); hr = CLSIDFromString(wszCLSID_Broken, &clsid); ok(hr == CO_E_CLASSSTRING, "Got %08x\n", hr); ok(clsid.Data1 == CLSID_StdFont.Data1, "Got %08x\n", clsid.Data1); ok(clsid.Data2 == 0xcccc, "Got %04x\n", clsid.Data2);
wszCLSID_Broken[3] = '*'; memset(&clsid, 0xcc, sizeof(CLSID)); hr = CLSIDFromString(wszCLSID_Broken, &clsid); ok(hr == CO_E_CLASSSTRING, "Got %08x\n", hr); ok(clsid.Data1 == 0xb, "Got %08x\n", clsid.Data1); ok(clsid.Data2 == 0xcccc, "Got %04x\n", clsid.Data2);
wszCLSID_Broken[3] = '\0'; memset(&clsid, 0xcc, sizeof(CLSID)); hr = CLSIDFromString(wszCLSID_Broken, &clsid); ok(hr == CO_E_CLASSSTRING, "Got %08x\n", hr); ok(clsid.Data1 == 0xb, "Got %08x\n", clsid.Data1); ok(clsid.Data2 == 0xcccc, "Got %04x\n", clsid.Data2);}
static void test_IIDFromString(void){ static const WCHAR cfW[] = {'{','0','0','0','0','0','0','0','1','-','0','0','0','0','-','0','0','0','0','-', 'c','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0}; static const WCHAR brokenW[] = {'{','0','0','0','0','0','0','0','1','-','0','0','0','0','-','0','0','0','0','-', 'g','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0}; static const WCHAR broken2W[] = {'{','0','0','0','0','0','0','0','1','=','0','0','0','0','-','0','0','0','0','-', 'g','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0}; static const WCHAR broken3W[] = {'b','r','o','k','e','n','0','0','1','=','0','0','0','0','-','0','0','0','0','-', 'g','0','0','0','-','0','0','0','0','0','0','0','0','0','0','4','6','}',0}; HRESULT hr; IID iid;
hr = IIDFromString(wszCLSID_StdFont, &iid); ok(hr == S_OK, "got 0x%08x\n", hr); ok(IsEqualIID(&iid, &CLSID_StdFont), "got iid %s\n", wine_dbgstr_guid(&iid));
memset(&iid, 0xab, sizeof(iid)); hr = IIDFromString(NULL, &iid); ok(hr == S_OK, "got 0x%08x\n", hr); ok(IsEqualIID(&iid, &CLSID_NULL), "got iid %s\n", wine_dbgstr_guid(&iid));
hr = IIDFromString(cfW, &iid); ok(hr == S_OK, "got 0x%08x\n", hr); ok(IsEqualIID(&iid, &IID_IClassFactory), "got iid %s\n", wine_dbgstr_guid(&iid));
/* string starts with a valid IID but is longer */ memset(&iid, 0xab, sizeof(iid)); hr = IIDFromString(cf_brokenW, &iid); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); ok(iid.Data1 == 0xabababab, "Got %08x\n", iid.Data1);
/* invalid IID in a valid format */ memset(&iid, 0xab, sizeof(iid)); hr = IIDFromString(brokenW, &iid); ok(hr == CO_E_IIDSTRING, "got 0x%08x\n", hr); ok(iid.Data1 == 0x00000001, "Got %08x\n", iid.Data1);
memset(&iid, 0xab, sizeof(iid)); hr = IIDFromString(broken2W, &iid); ok(hr == CO_E_IIDSTRING, "got 0x%08x\n", hr); ok(iid.Data1 == 0x00000001, "Got %08x\n", iid.Data1);
/* format is broken, but string length is okay */ memset(&iid, 0xab, sizeof(iid)); hr = IIDFromString(broken3W, &iid); ok(hr == CO_E_IIDSTRING, "got 0x%08x\n", hr); ok(iid.Data1 == 0xabababab, "Got %08x\n", iid.Data1);
/* invalid string */ memset(&iid, 0xab, sizeof(iid)); hr = IIDFromString(wszNonExistent, &iid); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); ok(iid.Data1 == 0xabababab, "Got %08x\n", iid.Data1);
/* valid ProgID */ memset(&iid, 0xab, sizeof(iid)); hr = IIDFromString(stdfont, &iid); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); ok(iid.Data1 == 0xabababab, "Got %08x\n", iid.Data1);}
static void test_StringFromGUID2(void){ WCHAR str[50]; int len;
/* invalid pointer */ SetLastError(0xdeadbeef); len = StringFromGUID2(NULL,str,50); ok(len == 0, "len: %d (expected 0)\n", len); ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %x\n", GetLastError());
/* Test corner cases for buffer size */ len = StringFromGUID2(&CLSID_StdFont,str,50); ok(len == 39, "len: %d (expected 39)\n", len); ok(!lstrcmpiW(str, wszCLSID_StdFont),"string wasn't equal for CLSID_StdFont\n");
memset(str,0,sizeof str); len = StringFromGUID2(&CLSID_StdFont,str,39); ok(len == 39, "len: %d (expected 39)\n", len); ok(!lstrcmpiW(str, wszCLSID_StdFont),"string wasn't equal for CLSID_StdFont\n");
len = StringFromGUID2(&CLSID_StdFont,str,38); ok(len == 0, "len: %d (expected 0)\n", len);
len = StringFromGUID2(&CLSID_StdFont,str,30); ok(len == 0, "len: %d (expected 0)\n", len);}
#define test_apt_type(t, q) _test_apt_type(t, q, __LINE__)static void _test_apt_type(APTTYPE expected_type, APTTYPEQUALIFIER expected_qualifier, int line){ APTTYPEQUALIFIER qualifier = ~0u; APTTYPE type = ~0u; HRESULT hr;
if (!pCoGetApartmentType) return;
hr = pCoGetApartmentType(&type, &qualifier); ok_(__FILE__, line)(hr == S_OK || hr == CO_E_NOTINITIALIZED, "Unexpected return code: 0x%08x\n", hr); ok_(__FILE__, line)(type == expected_type, "Wrong apartment type %d, expected %d\n", type, expected_type); ok_(__FILE__, line)(qualifier == expected_qualifier, "Wrong apartment qualifier %d, expected %d\n", qualifier, expected_qualifier);}
static void test_CoCreateInstance(void){ HRESULT hr; IUnknown *pUnk; REFCLSID rclsid = &CLSID_InternetZoneManager;
pUnk = (IUnknown *)0xdeadbeef; hr = CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&pUnk); ok(hr == CO_E_NOTINITIALIZED, "CoCreateInstance should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr); ok(pUnk == NULL, "CoCreateInstance should have changed the passed in pointer to NULL, instead of %p\n", pUnk);
OleInitialize(NULL);
/* test errors returned for non-registered clsids */ hr = CoCreateInstance(&CLSID_non_existent, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&pUnk); ok(hr == REGDB_E_CLASSNOTREG, "CoCreateInstance for non-registered inproc server should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr); hr = CoCreateInstance(&CLSID_non_existent, NULL, CLSCTX_INPROC_HANDLER, &IID_IUnknown, (void **)&pUnk); ok(hr == REGDB_E_CLASSNOTREG, "CoCreateInstance for non-registered inproc handler should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr); hr = CoCreateInstance(&CLSID_non_existent, NULL, CLSCTX_LOCAL_SERVER, &IID_IUnknown, (void **)&pUnk); ok(hr == REGDB_E_CLASSNOTREG, "CoCreateInstance for non-registered local server should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr); hr = CoCreateInstance(&CLSID_non_existent, NULL, CLSCTX_REMOTE_SERVER, &IID_IUnknown, (void **)&pUnk); ok(hr == REGDB_E_CLASSNOTREG, "CoCreateInstance for non-registered remote server should have returned REGDB_E_CLASSNOTREG instead of 0x%08x\n", hr);
hr = CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&pUnk); if(hr == REGDB_E_CLASSNOTREG) { skip("IE not installed so can't test CoCreateInstance\n"); OleUninitialize(); return; }
ok_ole_success(hr, "CoCreateInstance"); if(pUnk) IUnknown_Release(pUnk); OleUninitialize();
hr = CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&pUnk); ok(hr == CO_E_NOTINITIALIZED, "CoCreateInstance should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr);
test_apt_type(APTTYPE_CURRENT, APTTYPEQUALIFIER_NONE);}
static void test_CoGetClassObject(void){ HRESULT hr; HANDLE handle; ULONG_PTR cookie; IUnknown *pUnk; REFCLSID rclsid = &CLSID_InternetZoneManager; HKEY hkey; LONG res;
hr = CoGetClassObject(rclsid, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void **)&pUnk); ok(hr == CO_E_NOTINITIALIZED, "CoGetClassObject should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr); ok(pUnk == NULL, "CoGetClassObject should have changed the passed in pointer to NULL, instead of %p\n", pUnk);
hr = CoGetClassObject(rclsid, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, NULL); ok(hr == E_INVALIDARG || broken(hr == CO_E_NOTINITIALIZED), /* win9x */ "CoGetClassObject should have returned E_INVALIDARG instead of 0x%08x\n", hr);
test_apt_type(APTTYPE_CURRENT, APTTYPEQUALIFIER_NONE);
if (!pRegOverridePredefKey) { win_skip("RegOverridePredefKey not available\n"); return; }
pCoInitializeEx(NULL, COINIT_MULTITHREADED);
hr = CoGetClassObject(rclsid, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void **)&pUnk); if (hr == S_OK) { IUnknown_Release(pUnk);
res = RegCreateKeyExA(HKEY_CURRENT_USER, "Software\\Classes", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, NULL); ok(!res, "RegCreateKeyEx returned %d\n", res);
res = pRegOverridePredefKey(HKEY_CLASSES_ROOT, hkey); ok(!res, "RegOverridePredefKey returned %d\n", res);
hr = CoGetClassObject(rclsid, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void **)&pUnk); ok(hr == S_OK, "CoGetClassObject should have returned S_OK instead of 0x%08x\n", hr);
res = pRegOverridePredefKey(HKEY_CLASSES_ROOT, NULL); ok(!res, "RegOverridePredefKey returned %d\n", res);
if (hr == S_OK) IUnknown_Release(pUnk); RegCloseKey(hkey); }
hr = CoGetClassObject(&CLSID_InProcFreeMarshaler, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void **)&pUnk); ok(hr == S_OK, "got 0x%08x\n", hr); IUnknown_Release(pUnk);
/* context redefines FreeMarshaler CLSID */ if ((handle = activate_context(actctx_manifest, &cookie))) { hr = CoGetClassObject(&CLSID_InProcFreeMarshaler, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void **)&pUnk); ok(hr == S_OK, "got 0x%08x\n", hr); IUnknown_Release(pUnk);
pDeactivateActCtx(0, cookie); pReleaseActCtx(handle); }
CoUninitialize();}
static void test_CoCreateInstanceEx(void){ MULTI_QI qi_res = { &IID_IMoniker }; DWORD cookie; HRESULT hr;
CoInitialize(NULL);
hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &cookie); ok_ole_success(hr, "CoRegisterClassObject");
create_instance_iid = IID_NULL; hr = CoCreateInstanceEx(&CLSID_WineOOPTest, NULL, CLSCTX_INPROC_SERVER, NULL, 1, &qi_res); ok(hr == E_NOINTERFACE, "CoCreateInstanceEx failed: %08x\n", hr); ok(IsEqualGUID(&create_instance_iid, qi_res.pIID), "Unexpected CreateInstance iid %s\n", wine_dbgstr_guid(&create_instance_iid));
hr = CoRevokeClassObject(cookie); ok_ole_success(hr, "CoRevokeClassObject");
CoUninitialize();}
static ATOM register_dummy_class(void){ WNDCLASSA wc = { 0, DefWindowProcA, 0, 0, GetModuleHandleA(NULL), NULL, LoadCursorA(NULL, (LPSTR)IDC_ARROW), (HBRUSH)(COLOR_BTNFACE+1), NULL, "WineOleTestClass", };
return RegisterClassA(&wc);}
static void test_ole_menu(void){ HWND hwndFrame; HRESULT hr;
hwndFrame = CreateWindowA((LPCSTR)MAKEINTATOM(register_dummy_class()), "Test", 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, NULL, NULL); hr = OleSetMenuDescriptor(NULL, hwndFrame, NULL, NULL, NULL); todo_wine ok_ole_success(hr, "OleSetMenuDescriptor");
DestroyWindow(hwndFrame);}
static HRESULT WINAPI MessageFilter_QueryInterface(IMessageFilter *iface, REFIID riid, void ** ppvObj){ if (ppvObj == NULL) return E_POINTER;
if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_IMessageFilter)) { *ppvObj = iface; IMessageFilter_AddRef(iface); return S_OK; }
return E_NOINTERFACE;}
static ULONG WINAPI MessageFilter_AddRef(IMessageFilter *iface){ return 2; /* non-heap object */}
static ULONG WINAPI MessageFilter_Release(IMessageFilter *iface){ return 1; /* non-heap object */}
static DWORD WINAPI MessageFilter_HandleInComingCall( IMessageFilter *iface, DWORD dwCallType, HTASK threadIDCaller, DWORD dwTickCount, LPINTERFACEINFO lpInterfaceInfo){ trace("HandleInComingCall\n"); return SERVERCALL_ISHANDLED;}
static DWORD WINAPI MessageFilter_RetryRejectedCall( IMessageFilter *iface, HTASK threadIDCallee, DWORD dwTickCount, DWORD dwRejectType){ trace("RetryRejectedCall\n"); return 0;}
static DWORD WINAPI MessageFilter_MessagePending( IMessageFilter *iface, HTASK threadIDCallee, DWORD dwTickCount, DWORD dwPendingType){ trace("MessagePending\n"); ros_skip_flaky todo_wine ok(0, "unexpected call\n"); return PENDINGMSG_WAITNOPROCESS;}
static const IMessageFilterVtbl MessageFilter_Vtbl ={ MessageFilter_QueryInterface, MessageFilter_AddRef, MessageFilter_Release, MessageFilter_HandleInComingCall, MessageFilter_RetryRejectedCall, MessageFilter_MessagePending};
static IMessageFilter MessageFilter = { &MessageFilter_Vtbl };
static void test_CoRegisterMessageFilter(void){ HRESULT hr; IMessageFilter *prev_filter;
hr = CoRegisterMessageFilter(&MessageFilter, &prev_filter); ok(hr == CO_E_NOT_SUPPORTED, "CoRegisterMessageFilter should have failed with CO_E_NOT_SUPPORTED instead of 0x%08x\n", hr);
pCoInitializeEx(NULL, COINIT_MULTITHREADED); prev_filter = (IMessageFilter *)0xdeadbeef; hr = CoRegisterMessageFilter(&MessageFilter, &prev_filter); ok(hr == CO_E_NOT_SUPPORTED, "CoRegisterMessageFilter should have failed with CO_E_NOT_SUPPORTED instead of 0x%08x\n", hr); ok(prev_filter == (IMessageFilter *)0xdeadbeef, "prev_filter should have been set to %p\n", prev_filter); CoUninitialize();
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
hr = CoRegisterMessageFilter(NULL, NULL); ok_ole_success(hr, "CoRegisterMessageFilter");
prev_filter = (IMessageFilter *)0xdeadbeef; hr = CoRegisterMessageFilter(NULL, &prev_filter); ok_ole_success(hr, "CoRegisterMessageFilter"); ok(prev_filter == NULL, "prev_filter should have been set to NULL instead of %p\n", prev_filter);
hr = CoRegisterMessageFilter(&MessageFilter, &prev_filter); ok_ole_success(hr, "CoRegisterMessageFilter"); ok(prev_filter == NULL, "prev_filter should have been set to NULL instead of %p\n", prev_filter);
hr = CoRegisterMessageFilter(NULL, NULL); ok_ole_success(hr, "CoRegisterMessageFilter");
CoUninitialize();}
static IUnknown Test_Unknown;
static HRESULT WINAPI EnumOLEVERB_QueryInterface(IEnumOLEVERB *iface, REFIID riid, void **ppv){ return IUnknown_QueryInterface(&Test_Unknown, riid, ppv);}
static ULONG WINAPI EnumOLEVERB_AddRef(IEnumOLEVERB *iface){ return 2;}
static ULONG WINAPI EnumOLEVERB_Release(IEnumOLEVERB *iface){ return 1;}
static HRESULT WINAPI EnumOLEVERB_Next(IEnumOLEVERB *iface, ULONG celt, OLEVERB *rgelt, ULONG *fetched){ ok(0, "unexpected call\n"); return E_NOTIMPL;}
static HRESULT WINAPI EnumOLEVERB_Skip(IEnumOLEVERB *iface, ULONG celt){ ok(0, "unexpected call\n"); return E_NOTIMPL;}
static HRESULT WINAPI EnumOLEVERB_Reset(IEnumOLEVERB *iface){ ok(0, "unexpected call\n"); return E_NOTIMPL;}
static HRESULT WINAPI EnumOLEVERB_Clone(IEnumOLEVERB *iface, IEnumOLEVERB **ppenum){ ok(0, "unexpected call\n"); return E_NOTIMPL;}
static const IEnumOLEVERBVtbl EnumOLEVERBVtbl = { EnumOLEVERB_QueryInterface, EnumOLEVERB_AddRef, EnumOLEVERB_Release, EnumOLEVERB_Next, EnumOLEVERB_Skip, EnumOLEVERB_Reset, EnumOLEVERB_Clone};
static IEnumOLEVERB EnumOLEVERB = { &EnumOLEVERBVtbl };
static HRESULT WINAPI Test_IUnknown_QueryInterface( IUnknown *iface, REFIID riid, LPVOID *ppvObj){ if (ppvObj == NULL) return E_POINTER;
if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IWineTest)) { *ppvObj = iface; }else if(IsEqualIID(riid, &IID_IEnumOLEVERB)) { *ppvObj = &EnumOLEVERB; }else { *ppvObj = NULL; return E_NOINTERFACE; }
IUnknown_AddRef((IUnknown*)*ppvObj); return S_OK;}
static ULONG WINAPI Test_IUnknown_AddRef(IUnknown *iface){ return 2; /* non-heap-based object */}
static ULONG WINAPI Test_IUnknown_Release(IUnknown *iface){ return 1; /* non-heap-based object */}
static const IUnknownVtbl TestUnknown_Vtbl ={ Test_IUnknown_QueryInterface, Test_IUnknown_AddRef, Test_IUnknown_Release,};
static IUnknown Test_Unknown = { &TestUnknown_Vtbl };
static IPSFactoryBuffer *ps_factory_buffer;
static HRESULT WINAPI PSFactoryBuffer_QueryInterface( IPSFactoryBuffer * This, /* [in] */ REFIID riid, /* [iid_is][out] */ void **ppvObject){ if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IPSFactoryBuffer)) { *ppvObject = This; IPSFactoryBuffer_AddRef(This); return S_OK; } return E_NOINTERFACE;}
static ULONG WINAPI PSFactoryBuffer_AddRef( IPSFactoryBuffer * This){ return 2;}
static ULONG WINAPI PSFactoryBuffer_Release( IPSFactoryBuffer * This){ return 1;}
static HRESULT WINAPI PSFactoryBuffer_CreateProxy( IPSFactoryBuffer * This, /* [in] */ IUnknown *pUnkOuter, /* [in] */ REFIID riid, /* [out] */ IRpcProxyBuffer **ppProxy, /* [out] */ void **ppv){ return E_NOTIMPL;}
static HRESULT WINAPI PSFactoryBuffer_CreateStub( IPSFactoryBuffer * This, /* [in] */ REFIID riid, /* [unique][in] */ IUnknown *pUnkServer, /* [out] */ IRpcStubBuffer **ppStub){ CHECK_EXPECT(CreateStub);
ok(pUnkServer == &Test_Unknown, "unexpected pUnkServer %p\n", pUnkServer); if(!ps_factory_buffer) return E_NOTIMPL;
return IPSFactoryBuffer_CreateStub(ps_factory_buffer, &IID_IEnumOLEVERB, pUnkServer, ppStub);}
static IPSFactoryBufferVtbl PSFactoryBufferVtbl ={ PSFactoryBuffer_QueryInterface, PSFactoryBuffer_AddRef, PSFactoryBuffer_Release, PSFactoryBuffer_CreateProxy, PSFactoryBuffer_CreateStub};
static IPSFactoryBuffer PSFactoryBuffer = { &PSFactoryBufferVtbl };
static const CLSID CLSID_WineTestPSFactoryBuffer ={ 0x52011640, 0x8164, 0x4fd0, {0xa1, 0xa2, 0x5d, 0x5a, 0x36, 0x54, 0xd3, 0xbd}}; /* 52011640-8164-4fd0-a1a2-5d5a3654d3bd */
static DWORD CALLBACK register_ps_clsid_thread(void *context){ HRESULT hr; CLSID clsid = {0};
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
hr = CoGetPSClsid(&IID_IWineTest, &clsid); ok_ole_success(hr, "CoGetPSClsid"); ok(IsEqualGUID(&clsid, &CLSID_WineTestPSFactoryBuffer), "expected %s, got %s\n", wine_dbgstr_guid(&CLSID_WineTestPSFactoryBuffer), wine_dbgstr_guid(&clsid));
/* test registering a PSClsid in an apartment which is then destroyed */ hr = CoRegisterPSClsid(&IID_TestPS, &clsid); ok_ole_success(hr, "CoRegisterPSClsid");
CoUninitialize();
return hr;}
static void test_CoRegisterPSClsid(void){ HRESULT hr; DWORD dwRegistrationKey; IStream *stream; CLSID clsid; HANDLE thread; DWORD tid;
hr = CoRegisterPSClsid(&IID_IWineTest, &CLSID_WineTestPSFactoryBuffer); ok(hr == CO_E_NOTINITIALIZED, "CoRegisterPSClsid should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr);
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
hr = CoRegisterClassObject(&CLSID_WineTestPSFactoryBuffer, (IUnknown *)&PSFactoryBuffer, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &dwRegistrationKey); ok_ole_success(hr, "CoRegisterClassObject");
hr = CoRegisterPSClsid(&IID_IWineTest, &CLSID_WineTestPSFactoryBuffer); ok_ole_success(hr, "CoRegisterPSClsid");
hr = CoGetPSClsid(&IID_IWineTest, &clsid); ok_ole_success(hr, "CoGetPSClsid"); ok(IsEqualGUID(&clsid, &CLSID_WineTestPSFactoryBuffer), "expected %s, got %s\n", wine_dbgstr_guid(&CLSID_WineTestPSFactoryBuffer), wine_dbgstr_guid(&clsid));
thread = CreateThread(NULL, 0, register_ps_clsid_thread, NULL, 0, &tid); ok(thread != NULL, "CreateThread failed with error %d\n", GetLastError()); ok(!WaitForSingleObject(thread, 10000), "wait timed out\n"); CloseHandle(thread);
hr = CoGetPSClsid(&IID_TestPS, &clsid); ok_ole_success(hr, "CoGetPSClsid"); ok(IsEqualGUID(&clsid, &CLSID_WineTestPSFactoryBuffer), "expected %s, got %s\n", wine_dbgstr_guid(&CLSID_WineTestPSFactoryBuffer), wine_dbgstr_guid(&clsid));
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream); ok_ole_success(hr, "CreateStreamOnHGlobal");
SET_EXPECT(CreateStub); hr = CoMarshalInterface(stream, &IID_IWineTest, &Test_Unknown, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL); ok(hr == E_NOTIMPL, "CoMarshalInterface should have returned E_NOTIMPL instead of 0x%08x\n", hr); CHECK_CALLED(CreateStub, 1);
hr = CoGetPSClsid(&IID_IEnumOLEVERB, &clsid); ok_ole_success(hr, "CoGetPSClsid");
hr = CoGetClassObject(&clsid, CLSCTX_INPROC_SERVER, NULL, &IID_IPSFactoryBuffer, (void **)&ps_factory_buffer); ok_ole_success(hr, "CoGetClassObject");
hr = CoRegisterPSClsid(&IID_IEnumOLEVERB, &CLSID_WineTestPSFactoryBuffer); ok_ole_success(hr, "CoRegisterPSClsid");
SET_EXPECT(CreateStub); hr = CoMarshalInterface(stream, &IID_IEnumOLEVERB, (IUnknown*)&EnumOLEVERB, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL); ok(hr == S_OK, "CoMarshalInterface should have returned S_OK instead of 0x%08x\n", hr); CHECK_CALLED(CreateStub, 1);
hr = CoMarshalInterface(stream, &IID_IEnumOLEVERB, &Test_Unknown, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL); ok(hr == S_OK, "CoMarshalInterface should have returned S_OK instead of 0x%08x\n", hr);
IStream_Release(stream); IPSFactoryBuffer_Release(ps_factory_buffer); ps_factory_buffer = NULL;
hr = CoRevokeClassObject(dwRegistrationKey); ok_ole_success(hr, "CoRevokeClassObject");
CoUninitialize();
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
hr = CoGetPSClsid(&IID_IWineTest, &clsid); ok(hr == REGDB_E_IIDNOTREG, "CoGetPSClsid should have returned REGDB_E_IIDNOTREG instead of 0x%08x\n", hr);
hr = CoGetPSClsid(&IID_TestPS, &clsid); ok(hr == REGDB_E_IIDNOTREG, "CoGetPSClsid should have returned REGDB_E_IIDNOTREG instead of 0x%08x\n", hr);
CoUninitialize();
pCoInitializeEx(NULL, COINIT_MULTITHREADED);
hr = CoRegisterPSClsid(&IID_IWineTest, &CLSID_WineTestPSFactoryBuffer); ok_ole_success(hr, "CoRegisterPSClsid");
hr = CoGetPSClsid(&IID_IWineTest, &clsid); ok_ole_success(hr, "CoGetPSClsid"); ok(IsEqualGUID(&clsid, &CLSID_WineTestPSFactoryBuffer), "expected %s, got %s\n", wine_dbgstr_guid(&CLSID_WineTestPSFactoryBuffer), wine_dbgstr_guid(&clsid));
thread = CreateThread(NULL, 0, register_ps_clsid_thread, NULL, 0, &tid); ok(thread != NULL, "CreateThread failed with error %d\n", GetLastError()); ok(!WaitForSingleObject(thread, 10000), "wait timed out\n"); CloseHandle(thread);
hr = CoGetPSClsid(&IID_TestPS, &clsid); ok_ole_success(hr, "CoGetPSClsid"); ok(IsEqualGUID(&clsid, &CLSID_WineTestPSFactoryBuffer), "expected %s, got %s\n", wine_dbgstr_guid(&CLSID_WineTestPSFactoryBuffer), wine_dbgstr_guid(&clsid));
CoUninitialize();}
static void test_CoGetPSClsid(void){ ULONG_PTR cookie; HANDLE handle; HRESULT hr; CLSID clsid; HKEY hkey; LONG res; const BOOL is_win64 = (sizeof(void*) != sizeof(int)); BOOL is_wow64 = FALSE;
hr = CoGetPSClsid(&IID_IClassFactory, &clsid); ok(hr == CO_E_NOTINITIALIZED, "CoGetPSClsid should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr);
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
hr = CoGetPSClsid(&IID_IClassFactory, &clsid); ok_ole_success(hr, "CoGetPSClsid");
hr = CoGetPSClsid(&IID_IWineTest, &clsid); ok(hr == REGDB_E_IIDNOTREG, "CoGetPSClsid for random IID returned 0x%08x instead of REGDB_E_IIDNOTREG\n", hr);
hr = CoGetPSClsid(&IID_IClassFactory, NULL); ok(hr == E_INVALIDARG, "CoGetPSClsid for null clsid returned 0x%08x instead of E_INVALIDARG\n", hr);
if (!pRegOverridePredefKey) { win_skip("RegOverridePredefKey not available\n"); CoUninitialize(); return; } hr = CoGetPSClsid(&IID_IClassFactory, &clsid); ok_ole_success(hr, "CoGetPSClsid");
res = RegCreateKeyExA(HKEY_CURRENT_USER, "Software\\Classes", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, NULL); ok(!res, "RegCreateKeyEx returned %d\n", res);
res = pRegOverridePredefKey(HKEY_CLASSES_ROOT, hkey); ok(!res, "RegOverridePredefKey returned %d\n", res);
hr = CoGetPSClsid(&IID_IClassFactory, &clsid); ok_ole_success(hr, "CoGetPSClsid");
res = pRegOverridePredefKey(HKEY_CLASSES_ROOT, NULL); ok(!res, "RegOverridePredefKey returned %d\n", res);
RegCloseKey(hkey);
/* not registered CLSID */ hr = CoGetPSClsid(&IID_Testiface, &clsid); ok(hr == REGDB_E_IIDNOTREG, "got 0x%08x\n", hr);
if ((handle = activate_context(actctx_manifest, &cookie))) { memset(&clsid, 0, sizeof(clsid)); hr = CoGetPSClsid(&IID_Testiface, &clsid); ok(hr == S_OK, "got 0x%08x\n", hr); ok(IsEqualGUID(&clsid, &IID_Testiface), "got clsid %s\n", wine_dbgstr_guid(&clsid));
memset(&clsid, 0, sizeof(clsid)); hr = CoGetPSClsid(&IID_Testiface2, &clsid); ok(hr == S_OK, "got 0x%08x\n", hr); ok(IsEqualGUID(&clsid, &IID_Testiface2), "got clsid %s\n", wine_dbgstr_guid(&clsid));
memset(&clsid, 0, sizeof(clsid)); hr = CoGetPSClsid(&IID_Testiface3, &clsid); ok(hr == S_OK, "got 0x%08x\n", hr); ok(IsEqualGUID(&clsid, &IID_TestPS), "got clsid %s\n", wine_dbgstr_guid(&clsid));
memset(&clsid, 0xaa, sizeof(clsid)); hr = CoGetPSClsid(&IID_Testiface4, &clsid); ok(hr == S_OK, "got 0x%08x\n", hr); ok(IsEqualGUID(&clsid, &GUID_NULL), "got clsid %s\n", wine_dbgstr_guid(&clsid));
/* register same interface and try to get CLSID back */ hr = CoRegisterPSClsid(&IID_Testiface, &IID_Testiface4); ok(hr == S_OK, "got 0x%08x\n", hr); memset(&clsid, 0, sizeof(clsid)); hr = CoGetPSClsid(&IID_Testiface, &clsid); ok(hr == S_OK, "got 0x%08x\n", hr); ok(IsEqualGUID(&clsid, &IID_Testiface4), "got clsid %s\n", wine_dbgstr_guid(&clsid));
pDeactivateActCtx(0, cookie); pReleaseActCtx(handle); }
if (pRegDeleteKeyExA && (is_win64 || (pIsWow64Process && pIsWow64Process(GetCurrentProcess(), &is_wow64) && is_wow64))) { static GUID IID_DeadBeef = {0xdeadbeef,0xdead,0xbeef,{0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}}; static const char clsidDeadBeef[] = "{deadbeef-dead-beef-dead-beefdeadbeef}"; static const char clsidA[] = "{66666666-8888-7777-6666-555555555555}"; HKEY hkey_iface, hkey_psclsid; REGSAM opposite = is_win64 ? KEY_WOW64_32KEY : KEY_WOW64_64KEY;
hr = CoGetPSClsid(&IID_DeadBeef, &clsid); ok(hr == REGDB_E_IIDNOTREG, "got 0x%08x\n", hr);
res = RegCreateKeyExA(HKEY_CLASSES_ROOT, "Interface", 0, NULL, 0, KEY_ALL_ACCESS | opposite, NULL, &hkey_iface, NULL); ok(!res, "RegCreateKeyEx returned %d\n", res); res = RegCreateKeyExA(hkey_iface, clsidDeadBeef, 0, NULL, 0, KEY_ALL_ACCESS | opposite, NULL, &hkey, NULL); if (res == ERROR_ACCESS_DENIED) { win_skip("Failed to create a key, skipping some of CoGetPSClsid() tests\n"); goto cleanup; }
ok(!res, "RegCreateKeyEx returned %d\n", res); res = RegCreateKeyExA(hkey, "ProxyStubClsid32", 0, NULL, 0, KEY_ALL_ACCESS | opposite, NULL, &hkey_psclsid, NULL); ok(!res, "RegCreateKeyEx returned %d\n", res); res = RegSetValueExA(hkey_psclsid, NULL, 0, REG_SZ, (const BYTE *)clsidA, strlen(clsidA)+1); ok(!res, "RegSetValueEx returned %d\n", res); RegCloseKey(hkey_psclsid);
hr = CoGetPSClsid(&IID_DeadBeef, &clsid); ok_ole_success(hr, "CoGetPSClsid"); ok(IsEqualGUID(&clsid, &IID_TestPS), "got clsid %s\n", wine_dbgstr_guid(&clsid));
res = pRegDeleteKeyExA(hkey, "ProxyStubClsid32", opposite, 0); ok(!res, "RegDeleteKeyEx returned %d\n", res); RegCloseKey(hkey); res = pRegDeleteKeyExA(hkey_iface, clsidDeadBeef, opposite, 0); ok(!res, "RegDeleteKeyEx returned %d\n", res);
cleanup: RegCloseKey(hkey_iface); }
CoUninitialize();}
/* basic test, mainly for invalid arguments. see marshal.c for more */static void test_CoUnmarshalInterface(void){ IUnknown *pProxy; IStream *pStream; HRESULT hr;
hr = CoUnmarshalInterface(NULL, &IID_IUnknown, (void **)&pProxy); ok(hr == E_INVALIDARG, "CoUnmarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr);
hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream); ok_ole_success(hr, "CreateStreamOnHGlobal");
hr = CoUnmarshalInterface(pStream, &IID_IUnknown, (void **)&pProxy); todo_wine ok(hr == CO_E_NOTINITIALIZED, "CoUnmarshalInterface should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr);
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
hr = CoUnmarshalInterface(pStream, &IID_IUnknown, (void **)&pProxy); ok(hr == STG_E_READFAULT, "CoUnmarshalInterface should have returned STG_E_READFAULT instead of 0x%08x\n", hr);
CoUninitialize();
hr = CoUnmarshalInterface(pStream, &IID_IUnknown, NULL); ok(hr == E_INVALIDARG, "CoUnmarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr);
IStream_Release(pStream);}
static void test_CoGetInterfaceAndReleaseStream(void){ HRESULT hr; IUnknown *pUnk;
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
hr = CoGetInterfaceAndReleaseStream(NULL, &IID_IUnknown, (void**)&pUnk); ok(hr == E_INVALIDARG, "hr %08x\n", hr);
CoUninitialize();}
/* basic test, mainly for invalid arguments. see marshal.c for more */static void test_CoMarshalInterface(void){ IStream *pStream; HRESULT hr; static const LARGE_INTEGER llZero;
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
hr = CreateStreamOnHGlobal(NULL, TRUE, &pStream); ok_ole_success(hr, "CreateStreamOnHGlobal");
hr = CoMarshalInterface(pStream, &IID_IUnknown, NULL, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL); ok(hr == E_INVALIDARG, "CoMarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr);
hr = CoMarshalInterface(NULL, &IID_IUnknown, (IUnknown *)&Test_ClassFactory, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL); ok(hr == E_INVALIDARG, "CoMarshalInterface should have returned E_INVALIDARG instead of 0x%08x\n", hr);
hr = CoMarshalInterface(pStream, &IID_IUnknown, (IUnknown *)&Test_ClassFactory, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL); ok_ole_success(hr, "CoMarshalInterface");
/* stream not rewound */ hr = CoReleaseMarshalData(pStream); ok(hr == STG_E_READFAULT, "CoReleaseMarshalData should have returned STG_E_READFAULT instead of 0x%08x\n", hr);
hr = IStream_Seek(pStream, llZero, STREAM_SEEK_SET, NULL); ok_ole_success(hr, "IStream_Seek");
hr = CoReleaseMarshalData(pStream); ok_ole_success(hr, "CoReleaseMarshalData");
IStream_Release(pStream);
CoUninitialize();}
static void test_CoMarshalInterThreadInterfaceInStream(void){ IStream *pStream; HRESULT hr; IClassFactory *pProxy;
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
cLocks = 0;
hr = CoMarshalInterThreadInterfaceInStream(&IID_IUnknown, (IUnknown *)&Test_ClassFactory, NULL); ok(hr == E_INVALIDARG, "CoMarshalInterThreadInterfaceInStream should have returned E_INVALIDARG instead of 0x%08x\n", hr);
hr = CoMarshalInterThreadInterfaceInStream(&IID_IUnknown, NULL, &pStream); ok(hr == E_INVALIDARG, "CoMarshalInterThreadInterfaceInStream should have returned E_INVALIDARG instead of 0x%08x\n", hr);
ok_no_locks();
hr = CoMarshalInterThreadInterfaceInStream(&IID_IUnknown, (IUnknown *)&Test_ClassFactory, &pStream); ok_ole_success(hr, "CoMarshalInterThreadInterfaceInStream");
ok_more_than_one_lock();
hr = CoUnmarshalInterface(pStream, &IID_IClassFactory, (void **)&pProxy); ok_ole_success(hr, "CoUnmarshalInterface");
IClassFactory_Release(pProxy); IStream_Release(pStream);
ok_no_locks();
CoUninitialize();}
static void test_CoRegisterClassObject(void){ ULONG_PTR ctxcookie; HANDLE handle; DWORD cookie; HRESULT hr; IClassFactory *pcf;
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
/* CLSCTX_INPROC_SERVER */ hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory, CLSCTX_INPROC_SERVER, REGCLS_SINGLEUSE, &cookie); ok_ole_success(hr, "CoRegisterClassObject"); hr = CoRevokeClassObject(cookie); ok_ole_success(hr, "CoRevokeClassObject");
hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &cookie); ok_ole_success(hr, "CoRegisterClassObject"); hr = CoRevokeClassObject(cookie); ok_ole_success(hr, "CoRevokeClassObject");
hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory, CLSCTX_INPROC_SERVER, REGCLS_MULTI_SEPARATE, &cookie); ok_ole_success(hr, "CoRegisterClassObject"); hr = CoRevokeClassObject(cookie); ok_ole_success(hr, "CoRevokeClassObject");
/* CLSCTX_LOCAL_SERVER */ hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory, CLSCTX_LOCAL_SERVER, REGCLS_SINGLEUSE, &cookie); ok_ole_success(hr, "CoRegisterClassObject"); hr = CoRevokeClassObject(cookie); ok_ole_success(hr, "CoRevokeClassObject");
hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory, CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, &cookie); ok_ole_success(hr, "CoRegisterClassObject"); hr = CoRevokeClassObject(cookie); ok_ole_success(hr, "CoRevokeClassObject");
hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory, CLSCTX_LOCAL_SERVER, REGCLS_MULTI_SEPARATE, &cookie); ok_ole_success(hr, "CoRegisterClassObject"); hr = CoRevokeClassObject(cookie); ok_ole_success(hr, "CoRevokeClassObject");
/* CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER */ hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory, CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER, REGCLS_SINGLEUSE, &cookie); ok_ole_success(hr, "CoRegisterClassObject"); hr = CoRevokeClassObject(cookie); ok_ole_success(hr, "CoRevokeClassObject");
/* test whether an object that doesn't support IClassFactory can be * registered for CLSCTX_LOCAL_SERVER */ hr = CoRegisterClassObject(&CLSID_WineOOPTest, &Test_Unknown, CLSCTX_LOCAL_SERVER, REGCLS_SINGLEUSE, &cookie); ok_ole_success(hr, "CoRegisterClassObject"); hr = CoRevokeClassObject(cookie); ok_ole_success(hr, "CoRevokeClassObject");
/* test whether registered class becomes invalid when apartment is destroyed */ hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory, CLSCTX_INPROC_SERVER, REGCLS_SINGLEUSE, &cookie); ok_ole_success(hr, "CoRegisterClassObject");
CoUninitialize(); pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
hr = CoGetClassObject(&CLSID_WineOOPTest, CLSCTX_INPROC_SERVER, NULL, &IID_IClassFactory, (void **)&pcf); ok(hr == REGDB_E_CLASSNOTREG, "object registered in an apartment shouldn't accessible after it is destroyed\n");
/* crashes with at least win9x DCOM! */ if (0) CoRevokeClassObject(cookie);
/* test that object is accessible */ hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &cookie); ok(hr == S_OK, "got 0x%08x\n", hr);
hr = CoGetClassObject(&CLSID_WineOOPTest, CLSCTX_INPROC_SERVER, NULL, &IID_IClassFactory, (void**)&pcf); ok(hr == S_OK, "got 0x%08x\n", hr); IClassFactory_Release(pcf);
/* context now contains CLSID_WineOOPTest, test if registered one could still be used */ if ((handle = activate_context(actctx_manifest, &ctxcookie))) { hr = CoGetClassObject(&CLSID_WineOOPTest, CLSCTX_INPROC_SERVER, NULL, &IID_IClassFactory, (void**)&pcf);todo_wine ok(hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND), "got 0x%08x\n", hr);
pDeactivateActCtx(0, ctxcookie); pReleaseActCtx(handle); }
hr = CoGetClassObject(&CLSID_WineOOPTest, CLSCTX_INPROC_SERVER, NULL, &IID_IClassFactory, (void**)&pcf); ok(hr == S_OK, "got 0x%08x\n", hr); IClassFactory_Release(pcf);
hr = CoRevokeClassObject(cookie); ok(hr == S_OK, "got 0x%08x\n", hr);
CoUninitialize();}
static HRESULT get_class_object(CLSCTX clsctx){ HRESULT hr; IClassFactory *pcf;
hr = CoGetClassObject(&CLSID_WineOOPTest, clsctx, NULL, &IID_IClassFactory, (void **)&pcf);
if (SUCCEEDED(hr)) IClassFactory_Release(pcf);
return hr;}
static DWORD CALLBACK get_class_object_thread(LPVOID pv){ CLSCTX clsctx = (CLSCTX)(DWORD_PTR)pv; HRESULT hr;
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
hr = get_class_object(clsctx);
CoUninitialize();
return hr;}
static DWORD CALLBACK get_class_object_proxy_thread(LPVOID pv){ CLSCTX clsctx = (CLSCTX)(DWORD_PTR)pv; HRESULT hr; IClassFactory *pcf; IMultiQI *pMQI;
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
hr = CoGetClassObject(&CLSID_WineOOPTest, clsctx, NULL, &IID_IClassFactory, (void **)&pcf);
if (SUCCEEDED(hr)) { hr = IClassFactory_QueryInterface(pcf, &IID_IMultiQI, (void **)&pMQI); if (SUCCEEDED(hr)) IMultiQI_Release(pMQI); IClassFactory_Release(pcf); }
CoUninitialize();
return hr;}
static DWORD CALLBACK register_class_object_thread(LPVOID pv){ HRESULT hr; DWORD cookie;
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory, CLSCTX_INPROC_SERVER, REGCLS_SINGLEUSE, &cookie);
CoUninitialize();
return hr;}
static DWORD CALLBACK revoke_class_object_thread(LPVOID pv){ DWORD cookie = (DWORD_PTR)pv; HRESULT hr;
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
hr = CoRevokeClassObject(cookie);
CoUninitialize();
return hr;}
static void test_registered_object_thread_affinity(void){ HRESULT hr; DWORD cookie; HANDLE thread; DWORD tid; DWORD exitcode;
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
/* CLSCTX_INPROC_SERVER */
hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory, CLSCTX_INPROC_SERVER, REGCLS_SINGLEUSE, &cookie); ok_ole_success(hr, "CoRegisterClassObject");
thread = CreateThread(NULL, 0, get_class_object_thread, (LPVOID)CLSCTX_INPROC_SERVER, 0, &tid); ok(thread != NULL, "CreateThread failed with error %d\n", GetLastError()); ok( !WaitForSingleObject(thread, 10000), "wait timed out\n" ); GetExitCodeThread(thread, &exitcode); hr = exitcode; ok(hr == REGDB_E_CLASSNOTREG, "CoGetClassObject on inproc object " "registered in different thread should return REGDB_E_CLASSNOTREG " "instead of 0x%08x\n", hr);
hr = get_class_object(CLSCTX_INPROC_SERVER); ok(hr == S_OK, "CoGetClassObject on inproc object registered in same " "thread should return S_OK instead of 0x%08x\n", hr);
thread = CreateThread(NULL, 0, register_class_object_thread, NULL, 0, &tid); ok(thread != NULL, "CreateThread failed with error %d\n", GetLastError()); ok ( !WaitForSingleObject(thread, 10000), "wait timed out\n" ); GetExitCodeThread(thread, &exitcode); hr = exitcode; ok(hr == S_OK, "CoRegisterClassObject with same CLSID but in different thread should return S_OK instead of 0x%08x\n", hr);
hr = CoRevokeClassObject(cookie); ok_ole_success(hr, "CoRevokeClassObject");
/* CLSCTX_LOCAL_SERVER */
hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory, CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, &cookie); ok_ole_success(hr, "CoRegisterClassObject");
thread = CreateThread(NULL, 0, get_class_object_proxy_thread, (LPVOID)CLSCTX_LOCAL_SERVER, 0, &tid); ok(thread != NULL, "CreateThread failed with error %d\n", GetLastError()); while (MsgWaitForMultipleObjects(1, &thread, FALSE, 10000, QS_ALLINPUT) == WAIT_OBJECT_0 + 1) { MSG msg; while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessageA(&msg); } } GetExitCodeThread(thread, &exitcode); hr = exitcode; ok(hr == S_OK, "CoGetClassObject on local server object " "registered in different thread should return S_OK " "instead of 0x%08x\n", hr);
hr = get_class_object(CLSCTX_LOCAL_SERVER); ok(hr == S_OK, "CoGetClassObject on local server object registered in same " "thread should return S_OK instead of 0x%08x\n", hr);
thread = CreateThread(NULL, 0, revoke_class_object_thread, (LPVOID)(DWORD_PTR)cookie, 0, &tid); ok(thread != NULL, "CreateThread failed with error %d\n", GetLastError()); ok( !WaitForSingleObject(thread, 10000), "wait timed out\n" ); GetExitCodeThread(thread, &exitcode); hr = exitcode; ok(hr == RPC_E_WRONG_THREAD || broken(hr == S_OK) /* win8 */, "CoRevokeClassObject called from different " "thread to where registered should return RPC_E_WRONG_THREAD instead of 0x%08x\n", hr);
thread = CreateThread(NULL, 0, register_class_object_thread, NULL, 0, &tid); ok(thread != NULL, "CreateThread failed with error %d\n", GetLastError()); ok( !WaitForSingleObject(thread, 10000), "wait timed out\n" ); GetExitCodeThread(thread, &exitcode); hr = exitcode; ok(hr == S_OK, "CoRegisterClassObject with same CLSID but in different " "thread should return S_OK instead of 0x%08x\n", hr);
hr = CoRevokeClassObject(cookie); ok_ole_success(hr, "CoRevokeClassObject");
CoUninitialize();}
static DWORD CALLBACK free_libraries_thread(LPVOID p){ CoFreeUnusedLibraries(); return 0;}
static inline BOOL is_module_loaded(const char *module){ return GetModuleHandleA(module) != 0;}
static void test_CoFreeUnusedLibraries(void){ HRESULT hr; IUnknown *pUnk; DWORD tid; HANDLE thread;
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
ok(!is_module_loaded("urlmon.dll"), "urlmon.dll shouldn't be loaded\n");
hr = CoCreateInstance(&CLSID_FileProtocol, NULL, CLSCTX_INPROC_SERVER, &IID_IInternetProtocol, (void **)&pUnk); if (hr == REGDB_E_CLASSNOTREG) { skip("IE not installed so can't run CoFreeUnusedLibraries test\n"); CoUninitialize(); return; } ok_ole_success(hr, "CoCreateInstance");
ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
ok(pUnk != NULL || broken(pUnk == NULL), /* win9x */ "Expected a valid pointer\n"); if (pUnk) IUnknown_Release(pUnk);
ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
thread = CreateThread(NULL, 0, free_libraries_thread, NULL, 0, &tid); ok( !WaitForSingleObject(thread, 10000), "wait timed out\n" ); CloseHandle(thread);
ok(is_module_loaded("urlmon.dll"), "urlmon.dll should be loaded\n");
CoFreeUnusedLibraries();
ok(!is_module_loaded("urlmon.dll"), "urlmon.dll shouldn't be loaded\n");
CoUninitialize();}
static void test_CoGetObjectContext(void){ HRESULT hr; ULONG refs; IComThreadingInfo *pComThreadingInfo, *threadinginfo2; IContextCallback *pContextCallback; IObjContext *pObjContext; APTTYPE apttype; THDTYPE thdtype; GUID id, id2;
if (!pCoGetObjectContext) { win_skip("CoGetObjectContext not present\n"); return; }
hr = pCoGetObjectContext(&IID_IComThreadingInfo, (void **)&pComThreadingInfo); ok(hr == CO_E_NOTINITIALIZED, "CoGetObjectContext should have returned CO_E_NOTINITIALIZED instead of 0x%08x\n", hr); ok(pComThreadingInfo == NULL, "pComThreadingInfo should have been set to NULL\n");
pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
test_apt_type(APTTYPE_MAINSTA, APTTYPEQUALIFIER_NONE);
hr = pCoGetObjectContext(&IID_IComThreadingInfo, (void **)&pComThreadingInfo); ok_ole_success(hr, "CoGetObjectContext");
threadinginfo2 = NULL; hr = pCoGetObjectContext(&IID_IComThreadingInfo, (void **)&threadinginfo2); ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", hr); ok(pComThreadingInfo == threadinginfo2, "got different instance\n"); IComThreadingInfo_Release(threadinginfo2);
hr = IComThreadingInfo_GetCurrentLogicalThreadId(pComThreadingInfo, NULL); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
id = id2 = GUID_NULL; hr = IComThreadingInfo_GetCurrentLogicalThreadId(pComThreadingInfo, &id); ok(hr == S_OK, "got 0x%08x\n", hr);
hr = CoGetCurrentLogicalThreadId(&id2); ok(IsEqualGUID(&id, &id2), "got %s, expected %s\n", wine_dbgstr_guid(&id), wine_dbgstr_guid(&id2));
hr = IComThreadingInfo_GetCurrentApartmentType(pComThreadingInfo, &apttype); ok_ole_success(hr, "IComThreadingInfo_GetCurrentApartmentType"); ok(apttype == APTTYPE_MAINSTA, "apartment type should be APTTYPE_MAINSTA instead of %d\n", apttype);
hr = IComThreadingInfo_GetCurrentThreadType(pComThreadingInfo, &thdtype); ok_ole_success(hr, "IComThreadingInfo_GetCurrentThreadType"); ok(thdtype == THDTYPE_PROCESSMESSAGES, "thread type should be THDTYPE_PROCESSMESSAGES instead of %d\n", thdtype);
refs = IComThreadingInfo_Release(pComThreadingInfo); ok(refs == 0, "pComThreadingInfo should have 0 refs instead of %d refs\n", refs);
hr = pCoGetObjectContext(&IID_IContextCallback, (void **)&pContextCallback); ok_ole_success(hr, "CoGetObjectContext(ContextCallback)");
refs = IContextCallback_Release(pContextCallback); ok(refs == 0, "pContextCallback should have 0 refs instead of %d refs\n", refs);
CoUninitialize();
pCoInitializeEx(NULL, COINIT_MULTITHREADED);
hr = pCoGetObjectContext(&IID_IComThreadingInfo, (void **)&pComThreadingInfo); ok_ole_success(hr, "CoGetObjectContext");
hr = IComThreadingInfo_GetCurrentApartmentType(pComThreadingInfo, &apttype); ok_ole_success(hr, "IComThreadingInfo_GetCurrentApartmentType"); ok(apttype == APTTYPE_MTA, "apartment type should be APTTYPE_MTA instead of %d\n", apttype);
hr = IComThreadingInfo_GetCurrentThreadType(pComThreadingInfo, &thdtype); ok_ole_success(hr, "IComThreadingInfo_GetCurrentThreadType"); ok(thdtype == THDTYPE_BLOCKMESSAGES, "thread type should be THDTYPE_BLOCKMESSAGES instead of %d\n", thdtype);
refs = IComThreadingInfo_Release(pComThreadingInfo); ok(refs == 0, "pComThreadingInfo should have 0 refs instead of %d refs\n", refs);
hr = pCoGetObjectContext(&IID_IContextCallback, (void **)&pContextCallback); ok_ole_success(hr, "CoGetObjectContext(ContextCallback)");
refs = IContextCallback_Release(pContextCallback); ok(refs == 0, "pContextCallback should have 0 refs instead of %d refs\n", refs);
hr = pCoGetObjectContext(&IID_IObjContext, (void **)&pObjContext); ok_ole_success(hr, "CoGetObjectContext");
refs = IObjContext_Release(pObjContext); ok(refs == 0, "pObjContext should have 0 refs instead of %d refs\n", refs);
CoUninitialize();}
typedef struct { IUnknown IUnknown_iface; LONG refs;} Test_CallContext;
static inline Test_CallContext *impl_from_IUnknown(IUnknown *iface){ return CONTAINING_RECORD(iface, Test_CallContext, IUnknown_iface);}
static HRESULT WINAPI Test_CallContext_QueryInterface( IUnknown *iface, REFIID riid, LPVOID *ppvObj){ if (ppvObj == NULL) return E_POINTER;
if (IsEqualGUID(riid, &IID_IUnknown)) { *ppvObj = iface; IUnknown_AddRef(iface); return S_OK; }
*ppvObj = NULL; return E_NOINTERFACE;}
static ULONG WINAPI Test_CallContext_AddRef(IUnknown *iface){ Test_CallContext *This = impl_from_IUnknown(iface); return InterlockedIncrement(&This->refs);}
static ULONG WINAPI Test_CallContext_Release(IUnknown *iface){ Test_CallContext *This = impl_from_IUnknown(iface); ULONG refs = InterlockedDecrement(&This->refs); if (!refs) HeapFree(GetProcessHeap(), 0, This); return refs;}
static const IUnknownVtbl TestCallContext_Vtbl ={ Test_CallContext_QueryInterface, Test_CallContext_AddRef, Test_CallContext_Release};
static void test_CoGetCallContext(void){ HRESULT hr; ULONG refs; IUnknown *pUnk; Test_CallContext *test_object;
if (!pCoSwitchCallContext) { skip("CoSwitchCallContext not present\n"); return; }
CoInitialize(NULL);
test_object = HeapAlloc(GetProcessHeap(), 0, sizeof(Test_CallContext)); test_object->IUnknown_iface.lpVtbl = &TestCallContext_Vtbl; test_object->refs = 1;
hr = CoGetCallContext(&IID_IUnknown, (void**)&pUnk); ok(hr == RPC_E_CALL_COMPLETE, "Expected RPC_E_CALL_COMPLETE, got 0x%08x\n", hr);
pUnk = (IUnknown*)0xdeadbeef; hr = pCoSwitchCallContext(&test_object->IUnknown_iface, &pUnk); ok_ole_success(hr, "CoSwitchCallContext"); ok(pUnk == NULL, "expected NULL, got %p\n", pUnk); refs = IUnknown_AddRef(&test_object->IUnknown_iface); ok(refs == 2, "Expected refcount 2, got %d\n", refs); IUnknown_Release(&test_object->IUnknown_iface);
pUnk = (IUnknown*)0xdeadbeef; hr = CoGetCallContext(&IID_IUnknown, (void**)&pUnk); ok_ole_success(hr, "CoGetCallContext"); ok(pUnk == &test_object->IUnknown_iface, "expected %p, got %p\n", &test_object->IUnknown_iface, pUnk); refs = IUnknown_AddRef(&test_object->IUnknown_iface); ok(refs == 3, "Expected refcount 3, got %d\n", refs); IUnknown_Release(&test_object->IUnknown_iface); IUnknown_Release(pUnk);
pUnk = (IUnknown*)0xdeadbeef; hr = pCoSwitchCallContext(NULL, &pUnk); ok_ole_success(hr, "CoSwitchCallContext"); ok(pUnk == &test_object->IUnknown_iface, "expected %p, got %p\n", &test_object->IUnknown_iface, pUnk); refs = IUnknown_AddRef(&test_object->IUnknown_iface); ok(refs == 2, "Expected refcount 2, got %d\n", refs); IUnknown_Release(&test_object->IUnknown_iface);
hr = CoGetCallContext(&IID_IUnknown, (void**)&pUnk); ok(hr == RPC_E_CALL_COMPLETE, "Expected RPC_E_CALL_COMPLETE, got 0x%08x\n", hr);
IUnknown_Release(&test_object->IUnknown_iface);
CoUninitialize();}
static void test_CoGetContextToken(void){ HRESULT hr; ULONG refs; ULONG_PTR token, token2; IObjContext *ctx;
if (!pCoGetContextToken) { win_skip("CoGetContextToken not present\n"); return; }
token = 0xdeadbeef; hr = pCoGetContextToken(&token); ok(hr == CO_E_NOTINITIALIZED, "Expected CO_E_NOTINITIALIZED, got 0x%08x\n", hr); ok(token == 0xdeadbeef, "Expected 0, got 0x%lx\n", token);
test_apt_type(APTTYPE_CURRENT, APTTYPEQUALIFIER_NONE);
CoInitialize(NULL);
test_apt_type(APTTYPE_MAINSTA, APTTYPEQUALIFIER_NONE);
hr = pCoGetContextToken(NULL); ok(hr == E_POINTER, "Expected E_POINTER, got 0x%08x\n", hr);
token = 0; hr = pCoGetContextToken(&token); ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", hr); ok(token, "Expected token != 0\n");
token2 = 0; hr = pCoGetContextToken(&token2); ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", hr); ok(token2 == token, "got different token\n");
refs = IUnknown_AddRef((IUnknown *)token); ok(refs == 1, "Expected 1, got %u\n", refs);
hr = pCoGetObjectContext(&IID_IObjContext, (void **)&ctx); ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", hr); ok(ctx == (IObjContext *)token, "Expected interface pointers to be the same\n");
refs = IObjContext_AddRef(ctx); ok(refs == 3, "Expected 3, got %u\n", refs);
refs = IObjContext_Release(ctx); ok(refs == 2, "Expected 2, got %u\n", refs);
refs = IUnknown_Release((IUnknown *)token); ok(refs == 1, "Expected 1, got %u\n", refs);
/* CoGetContextToken does not add a reference */ token = 0; hr = pCoGetContextToken(&token); ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", hr); ok(token, "Expected token != 0\n"); ok(ctx == (IObjContext *)token, "Expected interface pointers to be the same\n");
refs = IObjContext_AddRef(ctx); ok(refs == 2, "Expected 1, got %u\n", refs);
refs = IObjContext_Release(ctx); ok(refs == 1, "Expected 0, got %u\n", refs);
refs = IObjContext_Release(ctx); ok(refs == 0, "Expected 0, got %u\n", refs);
CoUninitialize();}
static void test_TreatAsClass(void){ HRESULT hr; CLSID out; static GUID deadbeef = {0xdeadbeef,0xdead,0xbeef,{0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef}}; static const char deadbeefA[] = "{DEADBEEF-DEAD-BEEF-DEAD-BEEFDEADBEEF}"; IInternetProtocol *pIP = NULL; HKEY clsidkey, deadbeefkey; LONG lr;
if (!pCoGetTreatAsClass) { win_skip("CoGetTreatAsClass not present\n"); return; }
hr = pCoGetTreatAsClass(&deadbeef,&out); ok (hr == S_FALSE, "expected S_FALSE got %x\n",hr); ok (IsEqualGUID(&out,&deadbeef), "expected to get same clsid back\n");
hr = pCoGetTreatAsClass(NULL, &out); ok(hr == E_INVALIDARG, "expected E_INVALIDARG got %08x\n", hr); ok(IsEqualGUID(&out, &deadbeef), "expected no change to the clsid\n");
hr = pCoGetTreatAsClass(&deadbeef, NULL); ok(hr == E_INVALIDARG, "expected E_INVALIDARG got %08x\n", hr);
lr = RegOpenKeyExA(HKEY_CLASSES_ROOT, "CLSID", 0, KEY_READ, &clsidkey); ok(!lr, "Couldn't open CLSID key, error %d\n", lr);
lr = RegCreateKeyExA(clsidkey, deadbeefA, 0, NULL, 0, KEY_WRITE, NULL, &deadbeefkey, NULL); if (lr) { win_skip("CoGetTreatAsClass() tests will be skipped (failed to create a test key, error %d)\n", lr); RegCloseKey(clsidkey); return; }
hr = pCoTreatAsClass(&deadbeef, &deadbeef); ok(hr == REGDB_E_WRITEREGDB, "CoTreatAsClass gave wrong error: %08x\n", hr);
hr = pCoTreatAsClass(&deadbeef, &CLSID_FileProtocol); if(hr == REGDB_E_WRITEREGDB){ win_skip("Insufficient privileges to use CoTreatAsClass\n"); goto exit; } ok(hr == S_OK, "CoTreatAsClass failed: %08x\n", hr);
hr = pCoGetTreatAsClass(&deadbeef, &out); ok(hr == S_OK, "CoGetTreatAsClass failed: %08x\n",hr); ok(IsEqualGUID(&out, &CLSID_FileProtocol), "expected to get substituted clsid\n");
OleInitialize(NULL);
hr = CoCreateInstance(&deadbeef, NULL, CLSCTX_INPROC_SERVER, &IID_IInternetProtocol, (void **)&pIP); if(hr == REGDB_E_CLASSNOTREG) { win_skip("IE not installed so can't test CoCreateInstance\n"); goto exit; }
ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr); if(pIP){ IInternetProtocol_Release(pIP); pIP = NULL; }
hr = pCoTreatAsClass(&deadbeef, &CLSID_NULL); ok(hr == S_OK, "CoTreatAsClass failed: %08x\n", hr);
hr = pCoGetTreatAsClass(&deadbeef, &out); ok(hr == S_FALSE, "expected S_FALSE got %08x\n", hr); ok(IsEqualGUID(&out, &deadbeef), "expected to get same clsid back\n");
/* bizarrely, native's CoTreatAsClass takes some time to take effect in CoCreateInstance */ Sleep(200);
hr = CoCreateInstance(&deadbeef, NULL, CLSCTX_INPROC_SERVER, &IID_IInternetProtocol, (void **)&pIP); ok(hr == REGDB_E_CLASSNOTREG, "CoCreateInstance gave wrong error: %08x\n", hr);
if(pIP) IInternetProtocol_Release(pIP);
exit: OleUninitialize(); RegCloseKey(deadbeefkey); RegDeleteKeyA(clsidkey, deadbeefA); RegCloseKey(clsidkey);}
static void test_CoInitializeEx(void){ HRESULT hr;
hr = pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED); ok(hr == S_OK, "CoInitializeEx failed with error 0x%08x\n", hr);
/* Calling OleInitialize for the first time should yield S_OK even with * apartment already initialized by previous CoInitialize(Ex) calls. */ hr = OleInitialize(NULL); ok(hr == S_OK, "OleInitialize failed with error 0x%08x\n", hr);
/* Subsequent calls to OleInitialize should return S_FALSE */ hr = OleInitialize(NULL); ok(hr == S_FALSE, "Expected S_FALSE, hr = 0x%08x\n", hr);
/* Cleanup */ CoUninitialize(); OleUninitialize(); OleUninitialize();}
static void test_OleInitialize_InitCounting(void){ HRESULT hr; IUnknown *pUnk; REFCLSID rclsid = &CLSID_InternetZoneManager;
/* 1. OleInitialize fails but OleUninitialize is still called: apartment stays initialized */ hr = pCoInitializeEx(NULL, COINIT_MULTITHREADED); ok(hr == S_OK, "CoInitializeEx(COINIT_MULTITHREADED) failed with error 0x%08x\n", hr);
hr = OleInitialize(NULL); ok(hr == RPC_E_CHANGED_MODE, "OleInitialize should have returned 0x%08x instead of 0x%08x\n", RPC_E_CHANGED_MODE, hr); OleUninitialize();
pUnk = (IUnknown *)0xdeadbeef; hr = CoCreateInstance(rclsid, NULL, 0x17, &IID_IUnknown, (void **)&pUnk); ok(hr == S_OK, "CoCreateInstance should have returned 0x%08x instead of 0x%08x\n", S_OK, hr); if (pUnk) IUnknown_Release(pUnk);
CoUninitialize();
/* 2. Extra multiple OleUninitialize: apartment stays initialized until CoUninitialize */ hr = CoInitialize(NULL); ok(hr == S_OK, "CoInitialize() failed with error 0x%08x\n", hr);
hr = OleInitialize(NULL); ok(hr == S_OK, "OleInitialize should have returned 0x%08x instead of 0x%08x\n", S_OK, hr); OleUninitialize(); OleUninitialize(); OleUninitialize();
pUnk = (IUnknown *)0xdeadbeef; hr = CoCreateInstance(rclsid, NULL, 0x17, &IID_IUnknown, (void **)&pUnk); ok(hr == S_OK, "CoCreateInstance should have returned 0x%08x instead of 0x%08x\n", S_OK, hr); if (pUnk) IUnknown_Release(pUnk);
CoUninitialize();
pUnk = (IUnknown *)0xdeadbeef; hr = CoCreateInstance(rclsid, NULL, 0x17, &IID_IUnknown, (void **)&pUnk); ok(hr == CO_E_NOTINITIALIZED, "CoCreateInstance should have returned 0x%08x instead of 0x%08x\n", CO_E_NOTINITIALIZED, hr); if (pUnk) IUnknown_Release(pUnk);
/* 3. CoUninitialize does not formally deinit Ole */ hr = CoInitialize(NULL); ok(hr == S_OK, "CoInitialize() failed with error 0x%08x\n", hr);
hr = OleInitialize(NULL); ok(hr == S_OK, "OleInitialize should have returned 0x%08x instead of 0x%08x\n", S_OK, hr);
CoUninitialize(); CoUninitialize();
pUnk = (IUnknown *)0xdeadbeef; hr = CoCreateInstance(rclsid, NULL, 0x17, &IID_IUnknown, (void **)&pUnk); ok(hr == CO_E_NOTINITIALIZED, "CoCreateInstance should have returned 0x%08x instead of 0x%08x\n", CO_E_NOTINITIALIZED, hr); /* COM is not initialized anymore */ if (pUnk) IUnknown_Release(pUnk);
hr = OleInitialize(NULL); ok(hr == S_FALSE, "OleInitialize should have returned 0x%08x instead of 0x%08x\n", S_FALSE, hr); /* ... but native OleInit returns S_FALSE as if Ole is considered initialized */
OleUninitialize();
}
static void test_OleRegGetMiscStatus(void){ ULONG_PTR cookie; HANDLE handle; DWORD status; HRESULT hr;
hr = OleRegGetMiscStatus(&CLSID_Testclass, DVASPECT_ICON, NULL); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
status = 0xdeadbeef; hr = OleRegGetMiscStatus(&CLSID_Testclass, DVASPECT_ICON, &status); ok(hr == REGDB_E_CLASSNOTREG, "got 0x%08x\n", hr); ok(status == 0, "got 0x%08x\n", status);
status = -1; hr = OleRegGetMiscStatus(&CLSID_StdFont, DVASPECT_ICON, &status); ok(hr == S_OK, "got 0x%08x\n", hr); ok(status == 0, "got 0x%08x\n", status);
if ((handle = activate_context(actctx_manifest, &cookie))) { status = 0; hr = OleRegGetMiscStatus(&CLSID_Testclass, DVASPECT_ICON, &status); ok(hr == S_OK, "got 0x%08x\n", hr); ok(status == OLEMISC_RECOMPOSEONRESIZE, "got 0x%08x\n", status);
/* context data takes precedence over registration info */ status = 0; hr = OleRegGetMiscStatus(&CLSID_StdFont, DVASPECT_ICON, &status); ok(hr == S_OK, "got 0x%08x\n", hr); ok(status == OLEMISC_RECOMPOSEONRESIZE, "got 0x%08x\n", status);
/* there's no such attribute in context */ status = -1; hr = OleRegGetMiscStatus(&CLSID_Testclass, DVASPECT_DOCPRINT, &status); ok(hr == S_OK, "got 0x%08x\n", hr); ok(status == 0, "got 0x%08x\n", status);
pDeactivateActCtx(0, cookie); pReleaseActCtx(handle); }}
static void test_OleRegGetUserType(void){ static const WCHAR stdfont_usertypeW[] = {'S','t','a','n','d','a','r','d',' ','F','o','n','t',0}; static const WCHAR stdfont2_usertypeW[] = {'C','L','S','I','D','_','S','t','d','F','o','n','t',0}; static const WCHAR clsidkeyW[] = {'C','L','S','I','D',0}; static const WCHAR defvalueW[] = {'D','e','f','a','u','l','t',' ','N','a','m','e',0}; static const WCHAR auxvalue0W[] = {'A','u','x',' ','N','a','m','e',' ','0',0}; static const WCHAR auxvalue2W[] = {'A','u','x',' ','N','a','m','e',' ','2',0}; static const WCHAR auxvalue3W[] = {'A','u','x',' ','N','a','m','e',' ','3',0}; static const WCHAR auxvalue4W[] = {'A','u','x',' ','N','a','m','e',' ','4',0};
static const char auxvalues[][16] = { "Aux Name 0", "Aux Name 1", "Aux Name 2", "Aux Name 3", "Aux Name 4" };
HKEY clsidhkey, hkey, auxhkey, classkey; DWORD form, ret, disposition; WCHAR clsidW[39]; ULONG_PTR cookie; HANDLE handle; HRESULT hr; WCHAR *str; int i;
for (form = 0; form <= USERCLASSTYPE_APPNAME+1; form++) { hr = OleRegGetUserType(&CLSID_Testclass, form, NULL); ok(hr == E_INVALIDARG, "form %u: got 0x%08x\n", form, hr);
str = (void*)0xdeadbeef; hr = OleRegGetUserType(&CLSID_Testclass, form, &str); ok(hr == REGDB_E_CLASSNOTREG, "form %u: got 0x%08x\n", form, hr); ok(str == NULL, "form %u: got %p\n", form, str);
/* same string returned for StdFont for all form types */ str = NULL; hr = OleRegGetUserType(&CLSID_StdFont, form, &str); ok(hr == S_OK, "form %u: got 0x%08x\n", form, hr); ok(!lstrcmpW(str, stdfont_usertypeW) || !lstrcmpW(str, stdfont2_usertypeW) /* winxp */, "form %u, got %s\n", form, wine_dbgstr_w(str)); CoTaskMemFree(str); }
if ((handle = activate_context(actctx_manifest, &cookie))) { for (form = 0; form <= USERCLASSTYPE_APPNAME+1; form++) { str = (void*)0xdeadbeef; hr = OleRegGetUserType(&CLSID_Testclass, form, &str); ok(hr == REGDB_E_CLASSNOTREG, "form %u: got 0x%08x\n", form, hr); ok(str == NULL, "form %u: got %s\n", form, wine_dbgstr_w(str));
/* same string returned for StdFont for all form types */ str = NULL; hr = OleRegGetUserType(&CLSID_StdFont, form, &str); ok(hr == S_OK, "form %u: got 0x%08x\n", form, hr); ok(!lstrcmpW(str, stdfont_usertypeW) || !lstrcmpW(str, stdfont2_usertypeW) /* winxp */, "form %u, got %s\n", form, wine_dbgstr_w(str)); CoTaskMemFree(str); }
pDeactivateActCtx(0, cookie); pReleaseActCtx(handle); }
/* test using registered CLSID */ StringFromGUID2(&CLSID_non_existent, clsidW, ARRAY_SIZE(clsidW));
ret = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsidkeyW, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &clsidhkey, &disposition); if (!ret) { ret = RegCreateKeyExW(clsidhkey, clsidW, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &classkey, NULL); if (ret) RegCloseKey(clsidhkey); }
if (ret == ERROR_ACCESS_DENIED) { win_skip("Failed to create test key, skipping some of OleRegGetUserType() tests.\n"); return; }
ok(!ret, "failed to create a key, error %d\n", ret);
ret = RegSetValueExW(classkey, NULL, 0, REG_SZ, (const BYTE*)defvalueW, sizeof(defvalueW)); ok(!ret, "got error %d\n", ret);
ret = RegCreateKeyExA(classkey, "AuxUserType", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &auxhkey, NULL); ok(!ret, "got error %d\n", ret);
/* populate AuxUserType */ for (i = 0; i <= 4; i++) { char name[16];
sprintf(name, "AuxUserType\\%d", i); ret = RegCreateKeyExA(classkey, name, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, NULL); ok(!ret, "got error %d\n", ret);
ret = RegSetValueExA(hkey, NULL, 0, REG_SZ, (const BYTE*)auxvalues[i], strlen(auxvalues[i])); ok(!ret, "got error %d\n", ret); RegCloseKey(hkey); }
str = NULL; hr = OleRegGetUserType(&CLSID_non_existent, 0, &str); ok(hr == S_OK, "got 0x%08x\n", hr); ok(!lstrcmpW(str, auxvalue0W), "got %s\n", wine_dbgstr_w(str)); CoTaskMemFree(str);
str = NULL; hr = OleRegGetUserType(&CLSID_non_existent, USERCLASSTYPE_FULL, &str); ok(hr == S_OK, "got 0x%08x\n", hr); ok(!lstrcmpW(str, defvalueW), "got %s\n", wine_dbgstr_w(str)); CoTaskMemFree(str);
str = NULL; hr = OleRegGetUserType(&CLSID_non_existent, USERCLASSTYPE_SHORT, &str); ok(hr == S_OK, "got 0x%08x\n", hr); ok(!lstrcmpW(str, auxvalue2W), "got %s\n", wine_dbgstr_w(str)); CoTaskMemFree(str);
str = NULL; hr = OleRegGetUserType(&CLSID_non_existent, USERCLASSTYPE_APPNAME, &str); ok(hr == S_OK, "got 0x%08x\n", hr); ok(!lstrcmpW(str, auxvalue3W), "got %s\n", wine_dbgstr_w(str)); CoTaskMemFree(str);
str = NULL; hr = OleRegGetUserType(&CLSID_non_existent, USERCLASSTYPE_APPNAME+1, &str); ok(hr == S_OK, "got 0x%08x\n", hr); ok(!lstrcmpW(str, auxvalue4W), "got %s\n", wine_dbgstr_w(str)); CoTaskMemFree(str);
str = NULL; hr = OleRegGetUserType(&CLSID_non_existent, USERCLASSTYPE_APPNAME+2, &str); ok(hr == S_OK, "got 0x%08x\n", hr); ok(!lstrcmpW(str, defvalueW), "got %s\n", wine_dbgstr_w(str)); CoTaskMemFree(str);
/* registry cleanup */ for (i = 0; i <= 4; i++) { char name[2]; sprintf(name, "%d", i); RegDeleteKeyA(auxhkey, name); } RegCloseKey(auxhkey); RegDeleteKeyA(classkey, "AuxUserType"); RegCloseKey(classkey); RegDeleteKeyW(clsidhkey, clsidW); RegCloseKey(clsidhkey); if (disposition == REG_CREATED_NEW_KEY) RegDeleteKeyA(HKEY_CLASSES_ROOT, "CLSID");}
static void test_CoCreateGuid(void){ HRESULT hr;
hr = CoCreateGuid(NULL); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);}
static void CALLBACK apc_test_proc(ULONG_PTR param){ /* nothing */}
static DWORD CALLBACK release_semaphore_thread( LPVOID arg ){ HANDLE handle = arg; if (WaitForSingleObject(handle, 200) == WAIT_TIMEOUT) ReleaseSemaphore(handle, 1, NULL); return 0;}
static DWORD CALLBACK send_message_thread(LPVOID arg){ HWND hWnd = arg; Sleep(50); SendMessageA(hWnd, WM_DDE_FIRST, 0, 0); return 0;}
static DWORD CALLBACK send_and_post_user_message_thread(void *arg){ HWND hwnd = arg; Sleep(30); SendMessageA(hwnd, WM_USER, 0, 0); PostMessageA(hwnd, WM_USER, 0, 0); return 0;}
static DWORD CALLBACK post_message_thread(LPVOID arg){ HWND hWnd = arg; Sleep(50); PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); return 0;}
static const char cls_name[] = "cowait_test_class";
static UINT cowait_msgs[100], cowait_msgs_first, cowait_msgs_last;
static void cowait_msgs_reset(void){ cowait_msgs_first = cowait_msgs_last = 0;}
#define cowait_msgs_expect_empty() _cowait_msgs_expect_empty(__LINE__)static void _cowait_msgs_expect_empty(unsigned line){ while(cowait_msgs_first < cowait_msgs_last) { ok_(__FILE__,line)(0, "unexpected message %u\n", cowait_msgs[cowait_msgs_first]); cowait_msgs_first++; } cowait_msgs_reset();}
#define cowait_msgs_expect_notified(a) _cowait_msgs_expect_notified(__LINE__,a)static void _cowait_msgs_expect_notified(unsigned line, UINT expected_msg){ if(cowait_msgs_first == cowait_msgs_last) { ok_(__FILE__,line)(0, "expected message %u, received none\n", expected_msg); }else { ok_(__FILE__,line)(cowait_msgs[cowait_msgs_first] == expected_msg, "expected message %u, received %u \n", expected_msg, cowait_msgs[cowait_msgs_first]); cowait_msgs_first++; }}
#define cowait_msgs_expect_queued(a,b) _cowait_msgs_expect_queued(__LINE__,a,b)static void _cowait_msgs_expect_queued(unsigned line, HWND hwnd, UINT expected_msg){ MSG msg; BOOL success;
success = PeekMessageA(&msg, hwnd, expected_msg, expected_msg, PM_REMOVE); ok_(__FILE__,line)(success, "PeekMessageA failed: %u\n", GetLastError()); if(success) ok_(__FILE__,line)(msg.message == expected_msg, "unexpected message %u, expected %u\n", msg.message, expected_msg);}
static void flush_messages(void){ MSG msg; while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE ));}
static LRESULT CALLBACK cowait_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam){ if(cowait_msgs_last < ARRAY_SIZE(cowait_msgs)) cowait_msgs[cowait_msgs_last++] = msg; if(msg == WM_DDE_FIRST) return 6; return DefWindowProcA(hwnd, msg, wparam, lparam);}
static DWORD CALLBACK cowait_unmarshal_thread(void *arg){ IStream *stream = arg; IEnumOLEVERB *enum_verb; LARGE_INTEGER zero; IUnknown *unk; HRESULT hr;
CoInitialize(NULL);
zero.QuadPart = 0; hr = IStream_Seek(stream, zero, STREAM_SEEK_SET, NULL); ok(hr == S_OK, "Seek failed: %08x\n", hr);
hr = CoUnmarshalInterface(stream, &IID_IUnknown, (void**)&unk); ok(hr == S_OK, "CoUnmarshalInterface failed: %08x\n", hr);
hr = IUnknown_QueryInterface(unk, &IID_IEnumOLEVERB, (void**)&enum_verb); ok(hr == S_OK, "QueryInterface failed: %08x\n", hr);
IEnumOLEVERB_Release(enum_verb); IUnknown_Release(unk);
CoUninitialize(); return 0;}
static DWORD CALLBACK test_CoWaitForMultipleHandles_thread(LPVOID arg){ HANDLE *handles = arg, event, thread; IStream *stream; BOOL success; DWORD index, tid; HRESULT hr; HWND hWnd; UINT uMSG = 0xc065; MSG msg; int ret;
hr = pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED); ok(hr == S_OK, "CoInitializeEx failed with error 0x%08x\n", hr);
hWnd = CreateWindowExA(0, cls_name, "Test (thread)", WS_TILEDWINDOW, 0, 0, 640, 480, 0, 0, 0, 0); ok(hWnd != 0, "CreateWindowExA failed %u\n", GetLastError());
index = 0xdeadbeef; PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); hr = CoWaitForMultipleHandles(0, 50, 2, handles, &index); ok(hr == RPC_S_CALLPENDING, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr); ok(index==0 || index==0xdeadbeef/* Win 8 */, "expected index 0, got %u\n", index); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(!success, "CoWaitForMultipleHandles didn't pump any messages\n");
index = 0xdeadbeef; PostMessageA(hWnd, WM_USER, 0, 0); hr = CoWaitForMultipleHandles(0, 50, 2, handles, &index); ok(hr == RPC_S_CALLPENDING, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr); ok(index==0 || index==0xdeadbeef/* Win 8 */, "expected index 0, got %u\n", index); success = PeekMessageA(&msg, hWnd, WM_USER, WM_USER, PM_REMOVE); ok(success, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
/* Even if CoWaitForMultipleHandles does not pump a message it peeks * at ALL of them */ index = 0xdeadbeef; PostMessageA(NULL, uMSG, 0, 0);
hr = CoWaitForMultipleHandles(COWAIT_ALERTABLE, 50, 2, handles, &index); ok(hr == RPC_S_CALLPENDING, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr); ok(index == 0 || broken(index == 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index);
/* Make sure message was peeked at */ ret = MsgWaitForMultipleObjectsEx(0, NULL, 2, QS_ALLPOSTMESSAGE, MWMO_ALERTABLE); ok(ret == WAIT_TIMEOUT, "MsgWaitForMultipleObjects returned %x\n", ret);
/* But not pumped */ success = PeekMessageA(&msg, NULL, uMSG, uMSG, PM_REMOVE); ok(success, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
DestroyWindow(hWnd); CoUninitialize();
hr = pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED); ok(hr == S_OK, "CoInitializeEx failed with error 0x%08x\n", hr);
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream); ok(hr == S_OK, "CreateStreamOnHGlobal failed: %08x\n", hr);
hr = CoMarshalInterface(stream, &IID_IUnknown, &Test_Unknown, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL); ok(hr == S_OK, "CoMarshalInterface should have returned S_OK instead of 0x%08x\n", hr);
event = CreateEventW(NULL, TRUE, FALSE, NULL);
PostQuitMessage(66); PostThreadMessageW(GetCurrentThreadId(), WM_QUIT, 0, 0);
hr = CoRegisterMessageFilter(&MessageFilter, NULL); ok(hr == S_OK, "CoRegisterMessageFilter failed: %08x\n", hr);
thread = CreateThread(NULL, 0, cowait_unmarshal_thread, stream, 0, &tid); ok(thread != NULL, "CreateThread failed, error %u\n", GetLastError()); hr = CoWaitForMultipleHandles(0, 50, 1, &event, &index); ok(hr == RPC_S_CALLPENDING, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr); index = WaitForSingleObject(thread, 200); ok(index == WAIT_OBJECT_0, "WaitForSingleObject failed\n"); CloseHandle(thread);
hr = CoRegisterMessageFilter(NULL, NULL); ok(hr == S_OK, "CoRegisterMessageFilter failed: %08x\n", hr);
IStream_Release(stream);
CloseHandle(event); CoUninitialize(); return 0;}
static void test_CoWaitForMultipleHandles(void){ HANDLE handles[2], thread; DWORD index, tid; WNDCLASSEXA wc; BOOL success; HRESULT hr; HWND hWnd; MSG msg;
hr = pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED); ok(hr == S_OK, "CoInitializeEx failed with error 0x%08x\n", hr);
memset(&wc, 0, sizeof(wc)); wc.cbSize = sizeof(wc); wc.style = CS_VREDRAW | CS_HREDRAW; wc.hInstance = GetModuleHandleA(0); wc.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW); wc.hbrBackground = NULL; wc.lpszClassName = cls_name; wc.lpfnWndProc = cowait_window_proc; success = RegisterClassExA(&wc) != 0; ok(success, "RegisterClassExA failed %u\n", GetLastError());
hWnd = CreateWindowExA(0, cls_name, "Test", WS_TILEDWINDOW, 0, 0, 640, 480, 0, 0, 0, 0); ok(hWnd != 0, "CreateWindowExA failed %u\n", GetLastError()); handles[0] = CreateSemaphoreA(NULL, 1, 1, NULL); ok(handles[0] != 0, "CreateSemaphoreA failed %u\n", GetLastError()); handles[1] = CreateSemaphoreA(NULL, 1, 1, NULL); ok(handles[1] != 0, "CreateSemaphoreA failed %u\n", GetLastError());
/* test without flags */
PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); hr = CoWaitForMultipleHandles(0, 50, 0, handles, NULL); ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(success, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
index = 0xdeadbeef; PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); hr = CoWaitForMultipleHandles(0, 50, 0, NULL, &index); ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr); ok(index == 0, "expected index 0, got %u\n", index); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(success, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
index = 0xdeadbeef; PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); hr = CoWaitForMultipleHandles(0, 50, 0, handles, &index); ok(hr == RPC_E_NO_SYNC, "expected RPC_E_NO_SYNC, got 0x%08x\n", hr); ok(index == 0, "expected index 0, got %u\n", index); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(success, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
index = 0xdeadbeef; PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); hr = CoWaitForMultipleHandles(0, 50, 1, handles, &index); ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr); ok(index == 0, "expected index 0, got %u\n", index); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(success, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
index = 0xdeadbeef; PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); hr = CoWaitForMultipleHandles(0, 50, 2, handles, &index); ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr); ok(index == 1, "expected index 1, got %u\n", index); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(success, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
index = 0xdeadbeef; PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); hr = CoWaitForMultipleHandles(0, 50, 2, handles, &index); ok(hr == RPC_S_CALLPENDING, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr); ok(index == 0 || broken(index == 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(!success, "CoWaitForMultipleHandles didn't pump any messages\n");
/* test PostMessageA/SendMessageA from a different thread */
index = 0xdeadbeef; thread = CreateThread(NULL, 0, post_message_thread, hWnd, 0, &tid); ok(thread != NULL, "CreateThread failed, error %u\n", GetLastError()); hr = CoWaitForMultipleHandles(0, 100, 2, handles, &index); ok(hr == RPC_S_CALLPENDING, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr); ok(index == 0 || broken(index == 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(!success, "CoWaitForMultipleHandles didn't pump any messages\n"); index = WaitForSingleObject(thread, 200); ok(index == WAIT_OBJECT_0, "WaitForSingleObject failed\n"); CloseHandle(thread);
index = 0xdeadbeef; thread = CreateThread(NULL, 0, send_message_thread, hWnd, 0, &tid); ok(thread != NULL, "CreateThread failed, error %u\n", GetLastError()); hr = CoWaitForMultipleHandles(0, 100, 2, handles, &index); ok(hr == RPC_S_CALLPENDING, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr); ok(index == 0 || broken(index == 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(!success, "CoWaitForMultipleHandles didn't pump any messages\n"); index = WaitForSingleObject(thread, 200); ok(index == WAIT_OBJECT_0, "WaitForSingleObject failed\n"); CloseHandle(thread);
ReleaseSemaphore(handles[0], 1, NULL); ReleaseSemaphore(handles[1], 1, NULL);
/* test with COWAIT_WAITALL */
index = 0xdeadbeef; PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); hr = CoWaitForMultipleHandles(COWAIT_WAITALL, 50, 2, handles, &index); ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr); ok(index == 0, "expected index 0, got %u\n", index); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(success, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
index = 0xdeadbeef; PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); hr = CoWaitForMultipleHandles(0, 50, 2, handles, &index); ok(hr == RPC_S_CALLPENDING, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr); ok(index == 0 || broken(index == 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(!success, "CoWaitForMultipleHandles didn't pump any messages\n");
ReleaseSemaphore(handles[0], 1, NULL); ReleaseSemaphore(handles[1], 1, NULL);
/* test with COWAIT_ALERTABLE */
index = 0xdeadbeef; PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); hr = CoWaitForMultipleHandles(COWAIT_ALERTABLE, 50, 1, handles, &index); ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr); ok(index == 0, "expected index 0, got %u\n", index); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(success, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
index = 0xdeadbeef; PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); hr = CoWaitForMultipleHandles(COWAIT_ALERTABLE, 50, 2, handles, &index); ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr); ok(index == 1, "expected index 1, got %u\n", index); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(success, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
index = 0xdeadbeef; PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); hr = CoWaitForMultipleHandles(COWAIT_ALERTABLE, 50, 2, handles, &index); ok(hr == RPC_S_CALLPENDING, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr); ok(index == 0 || broken(index == 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(!success, "CoWaitForMultipleHandles didn't pump any messages\n");
index = 0xdeadbeef; PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); success = QueueUserAPC(apc_test_proc, GetCurrentThread(), 0); ok(success, "QueueUserAPC failed %u\n", GetLastError()); hr = CoWaitForMultipleHandles(COWAIT_ALERTABLE, 50, 2, handles, &index); ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr); ok(index == WAIT_IO_COMPLETION, "expected index WAIT_IO_COMPLETION, got %u\n", index); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(success, "CoWaitForMultipleHandles unexpectedly pumped messages\n");
/* test with COWAIT_INPUTAVAILABLE (semaphores are still locked) */
index = 0xdeadbeef; PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_NOREMOVE); ok(success, "PeekMessageA returned FALSE\n"); hr = CoWaitForMultipleHandles(0, 50, 2, handles, &index); ok(hr == RPC_S_CALLPENDING, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr); ok(index == 0 || broken(index == 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(!success, "CoWaitForMultipleHandles didn't pump any messages\n");
index = 0xdeadbeef; PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_NOREMOVE); ok(success, "PeekMessageA returned FALSE\n"); thread = CreateThread(NULL, 0, release_semaphore_thread, handles[1], 0, &tid); ok(thread != NULL, "CreateThread failed, error %u\n", GetLastError()); hr = CoWaitForMultipleHandles(COWAIT_INPUTAVAILABLE, 50, 2, handles, &index); ok(hr == RPC_S_CALLPENDING || broken(hr == E_INVALIDARG) || broken(hr == S_OK) /* Win 8 */, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr); if (hr != S_OK) ReleaseSemaphore(handles[1], 1, NULL); ok(index == 0 || broken(index == 1) /* Win 8 */, "expected index 0, got %u\n", index); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(!success || broken(success && hr == E_INVALIDARG), "CoWaitForMultipleHandles didn't pump any messages\n"); index = WaitForSingleObject(thread, 200); ok(index == WAIT_OBJECT_0, "WaitForSingleObject failed\n"); CloseHandle(thread);
cowait_msgs_reset(); PostMessageA(hWnd, 0, 0, 0); PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); PostMessageA(hWnd, WM_USER+1, 0, 0); PostMessageA(hWnd, WM_DDE_FIRST+1, 0, 0); thread = CreateThread(NULL, 0, send_and_post_user_message_thread, hWnd, 0, &tid); ok(thread != NULL, "CreateThread failed, error %u\n", GetLastError());
hr = CoWaitForMultipleHandles(0, 100, 2, handles, &index); ok(hr == RPC_S_CALLPENDING, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr);
cowait_msgs_expect_notified(WM_DDE_FIRST); cowait_msgs_expect_notified(WM_DDE_FIRST+1); cowait_msgs_expect_notified(WM_USER); cowait_msgs_expect_empty(); cowait_msgs_expect_queued(hWnd, WM_USER); cowait_msgs_expect_queued(hWnd, WM_USER+1); flush_messages();
index = WaitForSingleObject(thread, 200); ok(index == WAIT_OBJECT_0, "WaitForSingleObject failed\n"); CloseHandle(thread);
/* test behaviour of WM_QUIT (semaphores are still locked) */
PostMessageA(hWnd, WM_QUIT, 40, 0); memset(&msg, 0, sizeof(msg)); success = PeekMessageA(&msg, hWnd, WM_QUIT, WM_QUIT, PM_REMOVE); ok(success, "PeekMessageA failed, error %u\n", GetLastError()); ok(msg.message == WM_QUIT, "expected msg.message = WM_QUIT, got %u\n", msg.message); ok(msg.wParam == 40, "expected msg.wParam = 40, got %lu\n", msg.wParam); success = PeekMessageA(&msg, hWnd, WM_QUIT, WM_QUIT, PM_REMOVE); ok(!success, "PeekMessageA succeeded\n");
cowait_msgs_reset(); PostMessageA(hWnd, WM_QUIT, 40, 0); PostMessageA(hWnd, 0, 0, 0); PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); PostMessageA(hWnd, WM_USER+1, 0, 0); PostMessageA(hWnd, WM_DDE_FIRST+1, 0, 0); thread = CreateThread(NULL, 0, send_and_post_user_message_thread, hWnd, 0, &tid); ok(thread != NULL, "CreateThread failed, error %u\n", GetLastError());
hr = CoWaitForMultipleHandles(0, 100, 2, handles, &index); ok(hr == RPC_S_CALLPENDING, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr);
cowait_msgs_expect_notified(WM_DDE_FIRST); cowait_msgs_expect_notified(WM_DDE_FIRST+1); cowait_msgs_expect_notified(WM_USER); cowait_msgs_expect_empty(); cowait_msgs_expect_queued(hWnd, WM_USER); flush_messages();
index = WaitForSingleObject(thread, 200); ok(index == WAIT_OBJECT_0, "WaitForSingleObject failed\n"); CloseHandle(thread);
index = 0xdeadbeef; PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); PostMessageA(hWnd, WM_QUIT, 41, 0); thread = CreateThread(NULL, 0, post_message_thread, hWnd, 0, &tid); ok(thread != NULL, "CreateThread failed, error %u\n", GetLastError()); hr = CoWaitForMultipleHandles(0, 100, 2, handles, &index); ok(hr == RPC_S_CALLPENDING, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr); ok(index == 0 || broken(index == 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); todo_wine ok(success || broken(!success) /* Win 2000/XP/8 */, "PeekMessageA failed, error %u\n", GetLastError()); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(!success, "PeekMessageA succeeded\n"); memset(&msg, 0, sizeof(msg)); success = PeekMessageA(&msg, hWnd, WM_QUIT, WM_QUIT, PM_REMOVE); todo_wine ok(!success || broken(success) /* Win 2000/XP/8 */, "PeekMessageA succeeded\n"); if (success) { ok(msg.message == WM_QUIT, "expected msg.message = WM_QUIT, got %u\n", msg.message); ok(msg.wParam == 41, "expected msg.wParam = 41, got %lu\n", msg.wParam); } index = WaitForSingleObject(thread, 200); ok(index == WAIT_OBJECT_0, "WaitForSingleObject failed\n"); CloseHandle(thread);
index = 0xdeadbeef; PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); PostMessageA(hWnd, WM_QUIT, 42, 0); thread = CreateThread(NULL, 0, send_message_thread, hWnd, 0, &tid); ok(thread != NULL, "CreateThread failed, error %u\n", GetLastError()); hr = CoWaitForMultipleHandles(0, 100, 2, handles, &index); ok(hr == RPC_S_CALLPENDING, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr); ok(index == 0 || broken(index == 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(!success, "CoWaitForMultipleHandles didn't pump all WM_DDE_FIRST messages\n"); memset(&msg, 0, sizeof(msg)); success = PeekMessageA(&msg, hWnd, WM_QUIT, WM_QUIT, PM_REMOVE); ok(success, "PeekMessageA failed, error %u\n", GetLastError()); ok(msg.message == WM_QUIT, "expected msg.message = WM_QUIT, got %u\n", msg.message); ok(msg.wParam == 42, "expected msg.wParam = 42, got %lu\n", msg.wParam); index = WaitForSingleObject(thread, 200); ok(index == WAIT_OBJECT_0, "WaitForSingleObject failed\n"); CloseHandle(thread);
PostQuitMessage(43); memset(&msg, 0, sizeof(msg)); success = PeekMessageA(&msg, hWnd, WM_QUIT, WM_QUIT, PM_REMOVE); ok(success || broken(!success) /* Win 8 */, "PeekMessageA failed, error %u\n", GetLastError()); if (!success) win_skip("PostQuitMessage didn't queue a WM_QUIT message, skipping tests\n"); else { ok(msg.message == WM_QUIT, "expected msg.message = WM_QUIT, got %u\n", msg.message); ok(msg.wParam == 43, "expected msg.wParam = 43, got %lu\n", msg.wParam); success = PeekMessageA(&msg, hWnd, WM_QUIT, WM_QUIT, PM_REMOVE); ok(!success, "PeekMessageA succeeded\n");
index = 0xdeadbeef; PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); PostQuitMessage(44); thread = CreateThread(NULL, 0, post_message_thread, hWnd, 0, &tid); ok(thread != NULL, "CreateThread failed, error %u\n", GetLastError()); hr = CoWaitForMultipleHandles(0, 100, 2, handles, &index); ok(hr == RPC_S_CALLPENDING, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr); ok(index == 0 || broken(index == 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(success, "PeekMessageA failed, error %u\n", GetLastError()); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(!success, "PeekMessageA succeeded\n"); success = PeekMessageA(&msg, hWnd, WM_QUIT, WM_QUIT, PM_REMOVE); ok(!success, "CoWaitForMultipleHandles didn't remove WM_QUIT messages\n"); index = WaitForSingleObject(thread, 200); ok(index == WAIT_OBJECT_0, "WaitForSingleObject failed\n"); CloseHandle(thread);
index = 0xdeadbeef; PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); PostQuitMessage(45); thread = CreateThread(NULL, 0, send_message_thread, hWnd, 0, &tid); ok(thread != NULL, "CreateThread failed, error %u\n", GetLastError()); hr = CoWaitForMultipleHandles(0, 100, 2, handles, &index); ok(hr == RPC_S_CALLPENDING, "expected RPC_S_CALLPENDING, got 0x%08x\n", hr); ok(index == 0 || broken(index == 0xdeadbeef) /* Win 8 */, "expected index 0, got %u\n", index); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(success, "PeekMessageA failed, error %u\n", GetLastError()); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(!success, "PeekMessageA succeeded\n"); success = PeekMessageA(&msg, hWnd, WM_QUIT, WM_QUIT, PM_REMOVE); ok(!success, "CoWaitForMultipleHandles didn't remove WM_QUIT messages\n"); index = WaitForSingleObject(thread, 200); ok(index == WAIT_OBJECT_0, "WaitForSingleObject failed\n"); CloseHandle(thread); }
/* test message pumping when CoWaitForMultipleHandles is called from non main apartment thread */ thread = CreateThread(NULL, 0, test_CoWaitForMultipleHandles_thread, handles, 0, &tid); index = WaitForSingleObject(thread, 500); ok(index == WAIT_OBJECT_0, "WaitForSingleObject failed\n"); CloseHandle(thread);
CoUninitialize();
/* If COM was not initialized, messages are neither pumped nor peeked at */ PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); hr = CoWaitForMultipleHandles(0, 100, 2, handles, &index); ok(hr == RPC_S_CALLPENDING, "got %#x\n", hr); success = MsgWaitForMultipleObjectsEx(0, NULL, 2, QS_ALLPOSTMESSAGE, MWMO_ALERTABLE); ok(success == 0, "MsgWaitForMultipleObjects returned %x\n", success); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(success, "PeekMessage failed: %u\n", GetLastError());
/* same in an MTA */ CoInitializeEx(NULL, COINIT_MULTITHREADED);
PostMessageA(hWnd, WM_DDE_FIRST, 0, 0); hr = CoWaitForMultipleHandles(0, 100, 2, handles, &index); ok(hr == RPC_S_CALLPENDING, "got %#x\n", hr); success = MsgWaitForMultipleObjectsEx(0, NULL, 2, QS_ALLPOSTMESSAGE, MWMO_ALERTABLE); ok(success == 0, "MsgWaitForMultipleObjects returned %x\n", success); success = PeekMessageA(&msg, hWnd, WM_DDE_FIRST, WM_DDE_FIRST, PM_REMOVE); ok(success, "PeekMessage failed: %u\n", GetLastError());
CoUninitialize();
CloseHandle(handles[0]); CloseHandle(handles[1]); DestroyWindow(hWnd);
success = UnregisterClassA(cls_name, GetModuleHandleA(0)); ok(success, "UnregisterClass failed %u\n", GetLastError());}
static void test_CoGetMalloc(void){ IMalloc *imalloc; HRESULT hr;
if (0) /* crashes on native */ hr = CoGetMalloc(0, NULL);
imalloc = (void*)0xdeadbeef; hr = CoGetMalloc(0, &imalloc); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); ok(imalloc == NULL, "got %p\n", imalloc);
imalloc = (void*)0xdeadbeef; hr = CoGetMalloc(MEMCTX_SHARED, &imalloc); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); ok(imalloc == NULL, "got %p\n", imalloc);
imalloc = (void*)0xdeadbeef; hr = CoGetMalloc(MEMCTX_MACSYSTEM, &imalloc); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); ok(imalloc == NULL, "got %p\n", imalloc);
imalloc = (void*)0xdeadbeef; hr = CoGetMalloc(MEMCTX_UNKNOWN, &imalloc); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); ok(imalloc == NULL, "got %p\n", imalloc);
imalloc = (void*)0xdeadbeef; hr = CoGetMalloc(MEMCTX_SAME, &imalloc); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); ok(imalloc == NULL, "got %p\n", imalloc);
imalloc = NULL; hr = CoGetMalloc(MEMCTX_TASK, &imalloc); ok(hr == S_OK, "got 0x%08x\n", hr); ok(imalloc != NULL, "got %p\n", imalloc); IMalloc_Release(imalloc);}
static void test_CoGetApartmentType(void){ APTTYPEQUALIFIER qualifier; APTTYPE type; HRESULT hr;
if (!pCoGetApartmentType) { win_skip("CoGetApartmentType not present\n"); return; }
hr = pCoGetApartmentType(NULL, NULL); ok(hr == E_INVALIDARG, "CoGetApartmentType succeeded, error: 0x%08x\n", hr);
type = 0xdeadbeef; hr = pCoGetApartmentType(&type, NULL); ok(hr == E_INVALIDARG, "CoGetApartmentType succeeded, error: 0x%08x\n", hr); ok(type == 0xdeadbeef, "Expected 0xdeadbeef, got %u\n", type);
qualifier = 0xdeadbeef; hr = pCoGetApartmentType(NULL, &qualifier); ok(hr == E_INVALIDARG, "CoGetApartmentType succeeded, error: 0x%08x\n", hr); ok(qualifier == 0xdeadbeef, "Expected 0xdeadbeef, got %u\n", qualifier);
type = 0xdeadbeef; qualifier = 0xdeadbeef; hr = pCoGetApartmentType(&type, &qualifier); ok(hr == CO_E_NOTINITIALIZED, "CoGetApartmentType succeeded, error: 0x%08x\n", hr); ok(type == APTTYPE_CURRENT, "Expected APTTYPE_CURRENT, got %u\n", type); ok(qualifier == APTTYPEQUALIFIER_NONE, "Expected APTTYPEQUALIFIER_NONE, got %u\n", qualifier);
type = 0xdeadbeef; qualifier = 0xdeadbeef; hr = pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED); ok(hr == S_OK, "CoInitializeEx failed, error: 0x%08x\n", hr); hr = pCoGetApartmentType(&type, &qualifier); ok(hr == S_OK, "CoGetApartmentType failed, error: 0x%08x\n", hr); ok(type == APTTYPE_MAINSTA, "Expected APTTYPE_MAINSTA, got %u\n", type); ok(qualifier == APTTYPEQUALIFIER_NONE, "Expected APTTYPEQUALIFIER_NONE, got %u\n", qualifier); CoUninitialize();
type = 0xdeadbeef; qualifier = 0xdeadbeef; hr = pCoInitializeEx(NULL, COINIT_MULTITHREADED); ok(hr == S_OK, "CoInitializeEx failed, error: 0x%08x\n", hr); hr = pCoGetApartmentType(&type, &qualifier); ok(hr == S_OK, "CoGetApartmentType failed, error: 0x%08x\n", hr); ok(type == APTTYPE_MTA, "Expected APTTYPE_MTA, got %u\n", type); ok(qualifier == APTTYPEQUALIFIER_NONE, "Expected APTTYPEQUALIFIER_NONE, got %u\n", qualifier); CoUninitialize();}
static HRESULT WINAPI testspy_QI(IMallocSpy *iface, REFIID riid, void **obj){ if (IsEqualIID(riid, &IID_IMallocSpy) || IsEqualIID(riid, &IID_IUnknown)) { *obj = iface; IMallocSpy_AddRef(iface); return S_OK; }
return E_NOINTERFACE;}
static ULONG WINAPI testspy_AddRef(IMallocSpy *iface){ return 2;}
static ULONG WINAPI testspy_Release(IMallocSpy *iface){ return 1;}
static SIZE_T WINAPI testspy_PreAlloc(IMallocSpy *iface, SIZE_T cb){ ok(0, "unexpected call\n"); return 0;}
static void* WINAPI testspy_PostAlloc(IMallocSpy *iface, void *ptr){ ok(0, "unexpected call\n"); return NULL;}
static void* WINAPI testspy_PreFree(IMallocSpy *iface, void *ptr, BOOL spyed){ ok(0, "unexpected call\n"); return NULL;}
static void WINAPI testspy_PostFree(IMallocSpy *iface, BOOL spyed){ ok(0, "unexpected call\n");}
static SIZE_T WINAPI testspy_PreRealloc(IMallocSpy *iface, void *ptr, SIZE_T cb, void **newptr, BOOL spyed){ ok(0, "unexpected call\n"); return 0;}
static void* WINAPI testspy_PostRealloc(IMallocSpy *iface, void *ptr, BOOL spyed){ ok(0, "unexpected call\n"); return NULL;}
static void* WINAPI testspy_PreGetSize(IMallocSpy *iface, void *ptr, BOOL spyed){ ok(0, "unexpected call\n"); return NULL;}
static SIZE_T WINAPI testspy_PostGetSize(IMallocSpy *iface, SIZE_T actual, BOOL spyed){ ok(0, "unexpected call\n"); return 0;}
static void* WINAPI testspy_PreDidAlloc(IMallocSpy *iface, void *ptr, BOOL spyed){ ok(0, "unexpected call\n"); return NULL;}
static int WINAPI testspy_PostDidAlloc(IMallocSpy *iface, void *ptr, BOOL spyed, int actual){ ok(0, "unexpected call\n"); return 0;}
static void WINAPI testspy_PreHeapMinimize(IMallocSpy *iface){ ok(0, "unexpected call\n");}
static void WINAPI testspy_PostHeapMinimize(IMallocSpy *iface){ ok(0, "unexpected call\n");}
static const IMallocSpyVtbl testspyvtbl ={ testspy_QI, testspy_AddRef, testspy_Release, testspy_PreAlloc, testspy_PostAlloc, testspy_PreFree, testspy_PostFree, testspy_PreRealloc, testspy_PostRealloc, testspy_PreGetSize, testspy_PostGetSize, testspy_PreDidAlloc, testspy_PostDidAlloc, testspy_PreHeapMinimize, testspy_PostHeapMinimize};
static IMallocSpy testspy = { &testspyvtbl };
static void test_IMallocSpy(void){ IMalloc *imalloc; HRESULT hr;
hr = CoRegisterMallocSpy(NULL); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
hr = CoRevokeMallocSpy(); ok(hr == CO_E_OBJNOTREG, "got 0x%08x\n", hr);
hr = CoRegisterMallocSpy(&testspy); ok(hr == S_OK, "got 0x%08x\n", hr);
hr = CoRegisterMallocSpy(NULL); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
hr = CoRegisterMallocSpy(&testspy); ok(hr == CO_E_OBJISREG, "got 0x%08x\n", hr);
imalloc = NULL; hr = CoGetMalloc(MEMCTX_TASK, &imalloc); ok(hr == S_OK, "got 0x%08x\n", hr); ok(imalloc != NULL, "got %p\n", imalloc);
IMalloc_Free(imalloc, NULL);
IMalloc_Release(imalloc);
hr = CoRevokeMallocSpy(); ok(hr == S_OK, "got 0x%08x\n", hr);
hr = CoRevokeMallocSpy(); ok(hr == CO_E_OBJNOTREG, "got 0x%08x\n", hr);}
static void test_CoGetCurrentLogicalThreadId(void){ HRESULT hr; GUID id;
hr = CoGetCurrentLogicalThreadId(NULL); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
id = GUID_NULL; hr = CoGetCurrentLogicalThreadId(&id); ok(hr == S_OK, "got 0x%08x\n", hr); ok(!IsEqualGUID(&id, &GUID_NULL), "got null id\n");}
static HRESULT WINAPI testinitialize_QI(IInitializeSpy *iface, REFIID riid, void **obj){ if (IsEqualIID(riid, &IID_IInitializeSpy) || IsEqualIID(riid, &IID_IUnknown)) { *obj = iface; IInitializeSpy_AddRef(iface); return S_OK; }
*obj = NULL; return E_NOINTERFACE;}
static ULONG WINAPI testinitialize_AddRef(IInitializeSpy *iface){ return 2;}
static ULONG WINAPI testinitialize_Release(IInitializeSpy *iface){ return 1;}
static DWORD expected_coinit_flags;static ULARGE_INTEGER init_cookies[3];static BOOL revoke_spies_on_uninit;
static HRESULT WINAPI testinitialize_PreInitialize(IInitializeSpy *iface, DWORD coinit, DWORD aptrefs){ CHECK_EXPECT2(PreInitialize); ok(coinit == expected_coinit_flags, "Unexpected init flags %#x, expected %#x.\n", coinit, expected_coinit_flags); return S_OK;}
static HRESULT WINAPI testinitialize_PostInitialize(IInitializeSpy *iface, HRESULT hr, DWORD coinit, DWORD aptrefs){ CHECK_EXPECT2(PostInitialize); ok(coinit == expected_coinit_flags, "Unexpected init flags %#x, expected %#x.\n", coinit, expected_coinit_flags); return hr;}
static HRESULT WINAPI testinitialize_PreUninitialize(IInitializeSpy *iface, DWORD aptrefs){ HRESULT hr; CHECK_EXPECT2(PreUninitialize); if (revoke_spies_on_uninit) { hr = CoRevokeInitializeSpy(init_cookies[0]); ok(hr == S_OK, "got 0x%08x\n", hr);
hr = CoRevokeInitializeSpy(init_cookies[1]); ok(hr == S_OK, "got 0x%08x\n", hr);
hr = CoRevokeInitializeSpy(init_cookies[2]); ok(hr == S_OK, "got 0x%08x\n", hr);
revoke_spies_on_uninit = FALSE; } return S_OK;}
static HRESULT WINAPI testinitialize_PostUninitialize(IInitializeSpy *iface, DWORD aptrefs){ CHECK_EXPECT2(PostUninitialize); return E_NOTIMPL;}
static const IInitializeSpyVtbl testinitializevtbl ={ testinitialize_QI, testinitialize_AddRef, testinitialize_Release, testinitialize_PreInitialize, testinitialize_PostInitialize, testinitialize_PreUninitialize, testinitialize_PostUninitialize};
static IInitializeSpy testinitialize = { &testinitializevtbl };
static DWORD WINAPI test_init_spies_proc(void *arg){ HRESULT hr;
hr = CoInitializeEx(NULL, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE); ok(hr == S_OK, "Failed to initialize COM, hr %#x.\n", hr);
hr = CoRevokeInitializeSpy(init_cookies[2]); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
CoUninitialize(); return 0;}
static void test_IInitializeSpy(BOOL mt){ HRESULT hr;
if (mt) { hr = pCoInitializeEx(NULL, COINIT_MULTITHREADED); ok(hr == S_OK, "CoInitializeEx failed: %#x\n", hr); }
hr = CoRegisterInitializeSpy(NULL, NULL); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
init_cookies[0].QuadPart = 1; hr = CoRegisterInitializeSpy(NULL, &init_cookies[0]); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); ok(init_cookies[0].QuadPart == 1, "got wrong cookie\n");
hr = CoRegisterInitializeSpy(&testinitialize, NULL); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
init_cookies[0].HighPart = 0; init_cookies[0].LowPart = 1; hr = CoRegisterInitializeSpy(&testinitialize, &init_cookies[0]); ok(hr == S_OK, "got 0x%08x\n", hr); ok(init_cookies[0].HighPart == GetCurrentThreadId(), "got high part 0x%08x, expected 0x%08x\n", init_cookies[0].HighPart, GetCurrentThreadId()); if (!mt) ok(init_cookies[0].LowPart == 0, "got wrong low part 0x%x\n", init_cookies[0].LowPart);
/* register same instance one more time */ init_cookies[1].HighPart = 0; init_cookies[1].LowPart = 0; hr = CoRegisterInitializeSpy(&testinitialize, &init_cookies[1]); ok(hr == S_OK, "got 0x%08x\n", hr); ok(init_cookies[1].HighPart == GetCurrentThreadId(), "got high part 0x%08x, expected 0x%08x\n", init_cookies[1].HighPart, GetCurrentThreadId()); if (!mt) ok(init_cookies[1].LowPart == 1, "got wrong low part 0x%x\n", init_cookies[1].LowPart);
init_cookies[2].HighPart = 0; init_cookies[2].LowPart = 0; hr = CoRegisterInitializeSpy(&testinitialize, &init_cookies[2]); ok(hr == S_OK, "got 0x%08x\n", hr); ok(init_cookies[2].HighPart == GetCurrentThreadId(), "got high part 0x%08x, expected 0x%08x\n", init_cookies[2].HighPart, GetCurrentThreadId()); if (!mt) ok(init_cookies[2].LowPart == 2, "got wrong low part 0x%x\n", init_cookies[2].LowPart);
hr = CoRevokeInitializeSpy(init_cookies[1]); ok(hr == S_OK, "got 0x%08x\n", hr);
hr = CoRevokeInitializeSpy(init_cookies[1]); ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
init_cookies[1].HighPart = 0; init_cookies[1].LowPart = 0; hr = CoRegisterInitializeSpy(&testinitialize, &init_cookies[1]); ok(hr == S_OK, "got 0x%08x\n", hr); ok(init_cookies[1].HighPart == GetCurrentThreadId(), "got high part 0x%08x, expected 0x%08x\n", init_cookies[1].HighPart, GetCurrentThreadId()); if (!mt) ok(init_cookies[1].LowPart == 1, "got wrong low part 0x%x\n", init_cookies[1].LowPart);
SET_EXPECT(PreInitialize); SET_EXPECT(PostInitialize); hr = CoInitializeEx(NULL, expected_coinit_flags = ((mt ? COINIT_MULTITHREADED : COINIT_APARTMENTTHREADED) | COINIT_DISABLE_OLE1DDE)); ok(hr == (mt ? S_FALSE : S_OK), "Failed to initialize COM, hr %#x.\n", hr); CHECK_CALLED(PreInitialize, 3); CHECK_CALLED(PostInitialize, 3);
if (mt) { HANDLE thread; thread = CreateThread(NULL, 0, test_init_spies_proc, NULL, 0, NULL); ok(thread != NULL, "CreateThread failed: %u\n", GetLastError()); ok(!WaitForSingleObject(thread, 1000), "wait failed\n"); }
SET_EXPECT(PreInitialize); SET_EXPECT(PostInitialize); hr = CoInitializeEx(NULL, expected_coinit_flags = ((mt ? COINIT_MULTITHREADED : COINIT_APARTMENTTHREADED) | COINIT_DISABLE_OLE1DDE)); ok(hr == S_FALSE, "Failed to initialize COM, hr %#x.\n", hr); CHECK_CALLED(PreInitialize, 3); CHECK_CALLED(PostInitialize, 3);
SET_EXPECT(PreUninitialize); SET_EXPECT(PostUninitialize); CoUninitialize(); CHECK_CALLED(PreUninitialize, 3); CHECK_CALLED(PostUninitialize, 3);
SET_EXPECT(PreUninitialize); SET_EXPECT(PostUninitialize); CoUninitialize(); CHECK_CALLED(PreUninitialize, 3); CHECK_CALLED(PostUninitialize, 3);
if (mt) { SET_EXPECT(PreUninitialize); SET_EXPECT(PostUninitialize); CoUninitialize(); CHECK_CALLED(PreUninitialize, 3); CHECK_CALLED(PostUninitialize, 3); }
SET_EXPECT(PreInitialize); SET_EXPECT(PostInitialize); hr = CoInitializeEx(NULL, expected_coinit_flags = ((mt ? COINIT_MULTITHREADED : COINIT_APARTMENTTHREADED) | COINIT_DISABLE_OLE1DDE)); ok(hr == S_OK, "Failed to initialize COM, hr %#x.\n", hr); CHECK_CALLED(PreInitialize, 3); CHECK_CALLED(PostInitialize, 3);
SET_EXPECT(PreUninitialize); revoke_spies_on_uninit = TRUE; CoUninitialize(); CHECK_CALLED(PreUninitialize, 1);}
static HRESULT g_persistfile_qi_ret;static HRESULT g_persistfile_load_ret;static HRESULT WINAPI testinstance_QI(IPersistFile *iface, REFIID riid, void **obj){ if (IsEqualIID(riid, &IID_IUnknown)) { *obj = iface; IUnknown_AddRef(iface); return S_OK; }
if (IsEqualIID(riid, &IID_IPersistFile)) { if (SUCCEEDED(g_persistfile_qi_ret)) { *obj = iface; IUnknown_AddRef(iface); } else *obj = NULL; return g_persistfile_qi_ret; }
ok(0, "unexpected riid %s\n", wine_dbgstr_guid(riid)); *obj = NULL; return E_NOINTERFACE;}
static ULONG WINAPI testinstance_AddRef(IPersistFile *iface){ return 2;}
static ULONG WINAPI testinstance_Release(IPersistFile *iface){ return 1;}
static HRESULT WINAPI testinstance_GetClassID(IPersistFile *iface, CLSID *clsid){ ok(0, "unexpected call\n"); return E_NOTIMPL;}
static HRESULT WINAPI testinstance_IsDirty(IPersistFile *iface){ ok(0, "unexpected call\n"); return E_NOTIMPL;}
static HRESULT WINAPI testinstance_Load(IPersistFile *iface, LPCOLESTR filename, DWORD mode){ return g_persistfile_load_ret;}
static HRESULT WINAPI testinstance_Save(IPersistFile *iface, LPCOLESTR filename, BOOL remember){ return E_NOTIMPL;}
static HRESULT WINAPI testinstance_SaveCompleted(IPersistFile *iface, LPCOLESTR filename){ ok(0, "unexpected call\n"); return E_NOTIMPL;}
static HRESULT WINAPI testinstance_GetCurFile(IPersistFile *iface, LPOLESTR *filename){ ok(0, "unexpected call\n"); return E_NOTIMPL;}
static const IPersistFileVtbl testpersistfilevtbl = { testinstance_QI, testinstance_AddRef, testinstance_Release, testinstance_GetClassID, testinstance_IsDirty, testinstance_Load, testinstance_Save, testinstance_SaveCompleted, testinstance_GetCurFile};
static IPersistFile testpersistfile = { &testpersistfilevtbl };
static HRESULT WINAPI getinstance_cf_QI(IClassFactory *iface, REFIID riid, void **obj){ if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) { *obj = iface; IClassFactory_AddRef(iface); return S_OK; }
*obj = NULL; return E_NOINTERFACE;}
static ULONG WINAPI getinstance_cf_AddRef(IClassFactory *iface){ return 2;}
static ULONG WINAPI getinstance_cf_Release(IClassFactory *iface){ return 1;}
static HRESULT WINAPI getinstance_cf_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID riid, void **obj){ if (IsEqualIID(riid, &IID_IUnknown)) { *obj = &testpersistfile; return S_OK; }
ok(0, "unexpected call, riid %s\n", wine_dbgstr_guid(riid)); *obj = NULL; return E_NOTIMPL;}
static HRESULT WINAPI getinstance_cf_LockServer(IClassFactory *iface, BOOL lock){ ok(0, "unexpected call\n"); return E_NOTIMPL;}
static const IClassFactoryVtbl getinstance_cf_vtbl = { getinstance_cf_QI, getinstance_cf_AddRef, getinstance_cf_Release, getinstance_cf_CreateInstance, getinstance_cf_LockServer};
static IClassFactory getinstance_cf = { &getinstance_cf_vtbl };
static void test_CoGetInstanceFromFile(void){ static const WCHAR filenameW[] = {'d','u','m','m','y','p','a','t','h',0}; CLSID *clsid = (CLSID*)&CLSID_testclsid; MULTI_QI mqi[2]; DWORD cookie; HRESULT hr;
hr = pCoInitializeEx(NULL, COINIT_APARTMENTTHREADED); ok(hr == S_OK, "got 0x%08x\n", hr);
/* CLSID is not specified, file does not exist */ mqi[0].pIID = &IID_IUnknown; mqi[0].pItf = NULL; mqi[0].hr = E_NOTIMPL; hr = CoGetInstanceFromFile(NULL, NULL, NULL, CLSCTX_INPROC_SERVER, STGM_READ, (OLECHAR*)filenameW, 1, mqi);todo_wine ok(hr == MK_E_CANTOPENFILE, "got 0x%08x\n", hr); ok(mqi[0].pItf == NULL, "got %p\n", mqi[0].pItf); ok(mqi[0].hr == E_NOINTERFACE, "got 0x%08x\n", mqi[0].hr);
/* class is not available */ mqi[0].pIID = &IID_IUnknown; mqi[0].pItf = NULL; mqi[0].hr = E_NOTIMPL; hr = CoGetInstanceFromFile(NULL, clsid, NULL, CLSCTX_INPROC_SERVER, STGM_READ, (OLECHAR*)filenameW, 1, mqi); ok(hr == REGDB_E_CLASSNOTREG, "got 0x%08x\n", hr); ok(mqi[0].pItf == NULL, "got %p\n", mqi[0].pItf); ok(mqi[0].hr == REGDB_E_CLASSNOTREG, "got 0x%08x\n", mqi[0].hr);
hr = CoRegisterClassObject(clsid, (IUnknown*)&getinstance_cf, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &cookie); ok(hr == S_OK, "got 0x%08x\n", hr);
mqi[0].pIID = &IID_IUnknown; mqi[0].pItf = (void*)0xdeadbeef; mqi[0].hr = S_OK; hr = CoGetInstanceFromFile(NULL, clsid, NULL, CLSCTX_INPROC_SERVER, STGM_READ, (OLECHAR*)filenameW, 1, mqi);todo_wine { ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); ok(mqi[0].pItf == (void*)0xdeadbeef, "got %p\n", mqi[0].pItf);} ok(mqi[0].hr == S_OK, "got 0x%08x\n", mqi[0].hr);
mqi[0].pIID = &IID_IUnknown; mqi[0].pItf = (void*)0xdeadbeef; mqi[0].hr = E_NOTIMPL; hr = CoGetInstanceFromFile(NULL, clsid, NULL, CLSCTX_INPROC_SERVER, STGM_READ, (OLECHAR*)filenameW, 1, mqi);todo_wine { ok(hr == E_INVALIDARG, "got 0x%08x\n", hr); ok(mqi[0].pItf == (void*)0xdeadbeef, "got %p\n", mqi[0].pItf); ok(mqi[0].hr == E_NOTIMPL, "got 0x%08x\n", mqi[0].hr);} mqi[0].pIID = &IID_IUnknown; mqi[0].pItf = NULL; mqi[0].hr = E_NOTIMPL; hr = CoGetInstanceFromFile(NULL, clsid, NULL, CLSCTX_INPROC_SERVER, STGM_READ, (OLECHAR*)filenameW, 1, mqi); ok(hr == S_OK, "got 0x%08x\n", hr); ok(mqi[0].pItf != NULL, "got %p\n", mqi[0].pItf); ok(mqi[0].hr == S_OK, "got 0x%08x\n", mqi[0].hr);
mqi[0].pIID = &IID_IUnknown; mqi[0].pItf = NULL; mqi[0].hr = S_OK; hr = CoGetInstanceFromFile(NULL, clsid, NULL, CLSCTX_INPROC_SERVER, STGM_READ, (OLECHAR*)filenameW, 1, mqi); ok(hr == S_OK, "got 0x%08x\n", hr); ok(mqi[0].pItf != NULL, "got %p\n", mqi[0].pItf); ok(mqi[0].hr == S_OK, "got 0x%08x\n", mqi[0].hr);
mqi[0].pIID = &IID_IUnknown; mqi[0].pItf = NULL; mqi[0].hr = S_OK; g_persistfile_qi_ret = S_FALSE; hr = CoGetInstanceFromFile(NULL, clsid, NULL, CLSCTX_INPROC_SERVER, STGM_READ, (OLECHAR*)filenameW, 1, mqi); ok(hr == S_OK, "got 0x%08x\n", hr); ok(mqi[0].pItf != NULL, "got %p\n", mqi[0].pItf); ok(mqi[0].hr == S_OK, "got 0x%08x\n", mqi[0].hr); g_persistfile_qi_ret = S_OK;
mqi[0].pIID = &IID_IUnknown; mqi[0].pItf = NULL; mqi[0].hr = S_OK; mqi[1].pIID = &IID_IUnknown; mqi[1].pItf = NULL; mqi[1].hr = S_OK; g_persistfile_qi_ret = 0x8000efef; hr = CoGetInstanceFromFile(NULL, clsid, NULL, CLSCTX_INPROC_SERVER, STGM_READ, (OLECHAR*)filenameW, 2, mqi); ok(hr == 0x8000efef, "got 0x%08x\n", hr); ok(mqi[0].pItf == NULL, "got %p\n", mqi[0].pItf); ok(mqi[0].hr == 0x8000efef, "got 0x%08x\n", mqi[0].hr); ok(mqi[1].pItf == NULL, "got %p\n", mqi[1].pItf); ok(mqi[1].hr == 0x8000efef, "got 0x%08x\n", mqi[1].hr); g_persistfile_qi_ret = S_OK;
mqi[0].pIID = &IID_IUnknown; mqi[0].pItf = NULL; mqi[0].hr = S_OK; mqi[1].pIID = &IID_IUnknown; mqi[1].pItf = NULL; mqi[1].hr = S_OK; g_persistfile_load_ret = 0x8000fefe; hr = CoGetInstanceFromFile(NULL, clsid, NULL, CLSCTX_INPROC_SERVER, STGM_READ, (OLECHAR*)filenameW, 2, mqi); ok(hr == 0x8000fefe, "got 0x%08x\n", hr); ok(mqi[0].pItf == NULL, "got %p\n", mqi[0].pItf); ok(mqi[0].hr == 0x8000fefe, "got 0x%08x\n", mqi[0].hr); ok(mqi[1].pItf == NULL, "got %p\n", mqi[1].pItf); ok(mqi[1].hr == 0x8000fefe, "got 0x%08x\n", mqi[1].hr); g_persistfile_load_ret = S_OK;
hr = CoRevokeClassObject(cookie); ok(hr == S_OK, "got 0x%08x\n", hr);
CoUninitialize();}
static void test_GlobalOptions(void){ IGlobalOptions *global_options; HRESULT hres;
CoInitialize(NULL);
hres = CoCreateInstance(&CLSID_GlobalOptions, NULL, CLSCTX_INPROC_SERVER, &IID_IGlobalOptions, (void**)&global_options); ok(hres == S_OK || broken(hres == E_NOINTERFACE), "CoCreateInstance(CLSID_GlobalOptions) failed: %08x\n", hres); if(FAILED(hres)) { win_skip("CLSID_GlobalOptions not available\n"); CoUninitialize(); return; }
IGlobalOptions_Release(global_options);
hres = CoCreateInstance(&CLSID_GlobalOptions, (IUnknown*)0xdeadbeef, CLSCTX_INPROC_SERVER, &IID_IGlobalOptions, (void**)&global_options); ok(hres == E_INVALIDARG, "CoCreateInstance(CLSID_GlobalOptions) failed: %08x\n", hres);
CoUninitialize();}
static void init_funcs(void){ HMODULE hOle32 = GetModuleHandleA("ole32"); HMODULE hAdvapi32 = GetModuleHandleA("advapi32"); HMODULE hkernel32 = GetModuleHandleA("kernel32");
pCoGetObjectContext = (void*)GetProcAddress(hOle32, "CoGetObjectContext"); pCoSwitchCallContext = (void*)GetProcAddress(hOle32, "CoSwitchCallContext"); pCoGetTreatAsClass = (void*)GetProcAddress(hOle32,"CoGetTreatAsClass"); pCoTreatAsClass = (void*)GetProcAddress(hOle32,"CoTreatAsClass"); pCoGetContextToken = (void*)GetProcAddress(hOle32, "CoGetContextToken"); pCoGetApartmentType = (void*)GetProcAddress(hOle32, "CoGetApartmentType"); pRegDeleteKeyExA = (void*)GetProcAddress(hAdvapi32, "RegDeleteKeyExA"); pRegOverridePredefKey = (void*)GetProcAddress(hAdvapi32, "RegOverridePredefKey"); pCoInitializeEx = (void*)GetProcAddress(hOle32, "CoInitializeEx");
pActivateActCtx = (void*)GetProcAddress(hkernel32, "ActivateActCtx"); pCreateActCtxW = (void*)GetProcAddress(hkernel32, "CreateActCtxW"); pDeactivateActCtx = (void*)GetProcAddress(hkernel32, "DeactivateActCtx"); pIsWow64Process = (void*)GetProcAddress(hkernel32, "IsWow64Process"); pReleaseActCtx = (void*)GetProcAddress(hkernel32, "ReleaseActCtx");}
static DWORD CALLBACK implicit_mta_proc(void *param){ IComThreadingInfo *threading_info; ULONG_PTR token; IUnknown *unk; DWORD cookie; CLSID clsid; HRESULT hr;
test_apt_type(APTTYPE_MTA, APTTYPEQUALIFIER_IMPLICIT_MTA);
hr = CoCreateInstance(&CLSID_InternetZoneManager, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&unk); ok_ole_success(hr, "CoCreateInstance"); IUnknown_Release(unk);
hr = CoGetClassObject(&CLSID_InternetZoneManager, CLSCTX_INPROC_SERVER, NULL, &IID_IUnknown, (void **)&unk); ok_ole_success(hr, "CoGetClassObject"); IUnknown_Release(unk);
hr = CoGetObjectContext(&IID_IComThreadingInfo, (void **)&threading_info); ok_ole_success(hr, "CoGetObjectContext"); IComThreadingInfo_Release(threading_info);
hr = CoGetContextToken(&token); ok_ole_success(hr, "CoGetContextToken");
hr = CoRegisterPSClsid(&IID_IWineTest, &CLSID_WineTestPSFactoryBuffer); ok_ole_success(hr, "CoRegisterPSClsid");
hr = CoGetPSClsid(&IID_IClassFactory, &clsid); ok_ole_success(hr, "CoGetPSClsid");
hr = CoRegisterClassObject(&CLSID_WineOOPTest, (IUnknown *)&Test_ClassFactory, CLSCTX_INPROC_SERVER, REGCLS_SINGLEUSE, &cookie); ok_ole_success(hr, "CoRegisterClassObject");
hr = CoRevokeClassObject(cookie); ok_ole_success(hr, "CoRevokeClassObject");
hr = CoRegisterMessageFilter(NULL, NULL); ok(hr == CO_E_NOT_SUPPORTED, "got %#x\n", hr);
hr = CoLockObjectExternal(&Test_Unknown, TRUE, TRUE); ok_ole_success(hr, "CoLockObjectExternal");
hr = CoDisconnectObject(&Test_Unknown, 0); ok_ole_success(hr, "CoDisconnectObject");
return 0;}
/* Some COM functions (perhaps even all of them?) can make use of an "implicit" * multi-threaded apartment created by another thread in the same process. */static void test_implicit_mta(void){ HANDLE thread;
CoInitializeEx(NULL, COINIT_MULTITHREADED);
thread = CreateThread(NULL, 0, implicit_mta_proc, NULL, 0, NULL); ok(!WaitForSingleObject(thread, 1000), "wait failed\n");
CoUninitialize();}
START_TEST(compobj){ init_funcs();
if (!pCoInitializeEx) { trace("You need DCOM95 installed to run this test\n"); return; }
if (!pCreateActCtxW) win_skip("Activation contexts are not supported, some tests will be skipped.\n");
test_ProgIDFromCLSID(); test_CLSIDFromProgID(); test_CLSIDFromString(); test_IIDFromString(); test_StringFromGUID2(); test_CoCreateInstance(); test_ole_menu(); test_CoGetClassObject(); test_CoCreateInstanceEx(); test_CoRegisterMessageFilter(); test_CoRegisterPSClsid(); test_CoGetPSClsid(); test_CoUnmarshalInterface(); test_CoGetInterfaceAndReleaseStream(); test_CoMarshalInterface(); test_CoMarshalInterThreadInterfaceInStream(); test_CoRegisterClassObject(); test_registered_object_thread_affinity(); test_CoFreeUnusedLibraries(); test_CoGetObjectContext(); test_CoGetCallContext(); test_CoGetContextToken(); test_TreatAsClass(); test_CoInitializeEx(); test_OleInitialize_InitCounting(); test_OleRegGetMiscStatus(); test_CoCreateGuid(); test_CoWaitForMultipleHandles(); test_CoGetMalloc(); test_OleRegGetUserType(); test_CoGetApartmentType(); test_IMallocSpy(); test_CoGetCurrentLogicalThreadId(); test_IInitializeSpy(FALSE); test_IInitializeSpy(TRUE); test_CoGetInstanceFromFile(); test_GlobalOptions(); test_implicit_mta();}