Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

594 lines
14 KiB

  1. //
  2. // Author: DebiM
  3. // Date: March 97. Revised for Beta2 in Nov 97.
  4. // File: csdrtgc.cxx
  5. //
  6. // Class Store DRTs
  7. //
  8. // This source file contains DRTs for Class Store App Access
  9. // CClassAccess::IClassAccess
  10. //
  11. //
  12. // It tests the following Class Store functionality
  13. //
  14. // GetAppInfo()
  15. // CsEnumApps()
  16. //
  17. //
  18. //
  19. //---------------------------------------------------------------------
  20. #include "csdrt.hxx"
  21. extern BOOL fVerbose;
  22. extern BOOL fMultiStore;
  23. extern IClassAccess *pIClassAccess;
  24. extern GUID TestClsid1, TestClsid2, TestClsid3, TestClsid4, TestClsid5;
  25. extern Sname TestPackName4, TestFileExt1, TestFileExt4, TestMimeType2;
  26. extern Sname TestOtherProgID2, TestProgId1, TestProgId3;
  27. extern WCHAR szLookupPackageName [];
  28. extern BOOL fClassInfoVerify;
  29. //
  30. // Routines to verify that the App Package returned is as expected.
  31. //
  32. HRESULT AssertPackage(INSTALLINFO *pInstallInfo)
  33. {
  34. // Code Path should be present
  35. VerifyPackage (pInstallInfo->pszScriptPath != NULL, L"Script Path Missing");
  36. // Script should be present
  37. #if 0
  38. VerifyPackage (pInstallInfo->cScriptLen != 0, L"Script Missing");
  39. for (UINT i=0; i < pInstallInfo->cScriptLen; i++)
  40. {
  41. VerifyPackage (pInstallInfo->pScript[i] == i%128, L"Script Content Wrong");
  42. }
  43. #endif
  44. // ReleaseInstallInfo(pInstallInfo);
  45. return S_OK;
  46. }
  47. void ReleaseObj(PACKAGEDISPINFO obj)
  48. {
  49. ReleasePackageInfo(&obj);
  50. }
  51. void VerbosePrintObj(PACKAGEDISPINFO obj)
  52. {
  53. }
  54. //
  55. // Routine to call GetAppInfo() with different class spec.
  56. //
  57. HRESULT CallClassSpecInfo (uCLSSPEC *pclsspec,
  58. INSTALLINFO *pInstallInfo)
  59. {
  60. QUERYCONTEXT QryContext;
  61. HRESULT hr;
  62. QryContext.dwContext = CLSCTX_INPROC_SERVER + CLSCTX_LOCAL_SERVER;
  63. QryContext.Locale = GetThreadLocale();
  64. GetDefaultPlatform(&QryContext.Platform);
  65. QryContext.dwVersionHi = 0;
  66. QryContext.dwVersionLo = 0;
  67. hr = pIClassAccess->GetAppInfo(
  68. pclsspec,
  69. &QryContext,
  70. pInstallInfo);
  71. if (!SUCCEEDED(hr))
  72. return hr;
  73. PrintInstallInfo(pInstallInfo);
  74. return hr;
  75. }
  76. //
  77. // This routine calls GetAppInfo() for a FileExtension
  78. //
  79. HRESULT LookupByFileext (LPOLESTR pExt,
  80. INSTALLINFO *pInstallInfo)
  81. {
  82. HRESULT hr;
  83. uCLSSPEC clsspec;
  84. clsspec.tyspec = TYSPEC_FILEEXT;
  85. clsspec.tagged_union.pFileExt = pExt;
  86. hr = CallClassSpecInfo(&clsspec, pInstallInfo);
  87. if (!SUCCEEDED(hr))
  88. {
  89. VerbosePrint("....... GetClassSpecInfo (EXT=%S) returned 0x%x\n", pExt, hr);
  90. return hr;
  91. }
  92. return S_OK;
  93. }
  94. //
  95. // This routine calls GetAppInfo() for a Clsid
  96. //
  97. HRESULT LookupByClsid (GUID Clsid,
  98. INSTALLINFO *pInstallInfo)
  99. {
  100. HRESULT hr;
  101. uCLSSPEC clsspec;
  102. clsspec.tyspec = TYSPEC_CLSID;
  103. memcpy(&clsspec.tagged_union.clsid, &Clsid, sizeof(GUID));
  104. hr = CallClassSpecInfo(&clsspec, pInstallInfo);
  105. if (!SUCCEEDED(hr))
  106. {
  107. VerbosePrint("....... GetClassSpecInfo (CLSID=) returned 0x%x\n", hr);
  108. return hr;
  109. }
  110. return S_OK;
  111. }
  112. //
  113. // This routine calls GetAppInfo() for a MimeType
  114. //
  115. HRESULT LookupByMimeType (LPOLESTR pMimeType,
  116. INSTALLINFO *pInstallInfo)
  117. {
  118. HRESULT hr;
  119. uCLSSPEC clsspec;
  120. clsspec.tyspec = TYSPEC_MIMETYPE;
  121. clsspec.tagged_union.pMimeType = pMimeType;
  122. hr = CallClassSpecInfo(&clsspec, pInstallInfo);
  123. if (!SUCCEEDED(hr))
  124. {
  125. VerbosePrint("....... GetClassSpecInfo (MimeType=%S) returned 0x%x\n", pMimeType, hr);
  126. return hr;
  127. }
  128. return S_OK;
  129. }
  130. //
  131. // This routine calls GetAppInfo() for a Progid
  132. //
  133. HRESULT LookupByProgid (LPOLESTR pProgId,
  134. INSTALLINFO *pInstallInfo)
  135. {
  136. HRESULT hr;
  137. uCLSSPEC clsspec;
  138. clsspec.tyspec = TYSPEC_PROGID;
  139. clsspec.tagged_union.pProgId = pProgId;
  140. hr = CallClassSpecInfo (&clsspec, pInstallInfo);
  141. if (!SUCCEEDED(hr))
  142. {
  143. VerbosePrint("....... GetClassSpecInfo (ProgId=%S) returned 0x%x\n", pProgId, hr);
  144. return hr;
  145. }
  146. return S_OK;
  147. }
  148. //
  149. // This routine calls GetAppInfo() by Name of Package
  150. //
  151. HRESULT LookupByName (LPOLESTR pName,
  152. INSTALLINFO *pInstallInfo)
  153. {
  154. HRESULT hr;
  155. uCLSSPEC clsspec;
  156. clsspec.tyspec = TYSPEC_PACKAGENAME;
  157. clsspec.tagged_union.pPackageName = pName;
  158. hr = CallClassSpecInfo (&clsspec, pInstallInfo);
  159. if (!SUCCEEDED(hr))
  160. {
  161. VerbosePrint("....... GetClassSpecInfo (PackageName=%S) returned 0x%x\n", pName, hr);
  162. return hr;
  163. }
  164. return S_OK;
  165. }
  166. //
  167. // This routine calls GetClassInfo() for a TypeLib
  168. //
  169. HRESULT LookupByTlbid (GUID TlbId,
  170. INSTALLINFO *pInstallInfo)
  171. {
  172. HRESULT hr;
  173. uCLSSPEC clsspec;
  174. clsspec.tyspec = TYSPEC_TYPELIB;
  175. memcpy(&clsspec.tagged_union.typelibID, &TlbId, sizeof(GUID));
  176. hr = CallClassSpecInfo (&clsspec, pInstallInfo);
  177. if (!SUCCEEDED(hr))
  178. {
  179. VerbosePrint("....... GetClassSpecInfo (Tlb) returned 0x%x\n", hr);
  180. return hr;
  181. }
  182. return S_OK;
  183. }
  184. void HandleEnumResult(UINT cElt, UINT cFound, HRESULT hr, PACKAGEDISPINFO PackageInfo[])
  185. {
  186. if (fVerbose)
  187. {
  188. if ((hr != S_OK) && (hr != S_FALSE))
  189. {
  190. printf ("..........Next(%d) returned error = 0x%x.\n", cElt, hr);
  191. }
  192. else
  193. {
  194. printf ("..........Next(%d) returned %d packages. hr = 0x%x.\n", cElt, cFound, hr);
  195. for (UINT i = 0; i < cFound; i++)
  196. {
  197. printf ("..........PackageInfo[%d].pszPackageName = %S, Flags=%d\n",
  198. i,
  199. PackageInfo[i].pszPackageName,
  200. PackageInfo[i].dwActFlags);
  201. ReleasePackageInfo(&PackageInfo[i]);
  202. }
  203. }
  204. }
  205. }
  206. PACKAGEDISPINFO PackageDisp[3];
  207. // DoCoEnumApps Test
  208. HRESULT DoCoEnumAppsTest()
  209. {
  210. PACKAGEDISPINFO PackageInfo[30];
  211. ULONG cFound;
  212. HRESULT hr;
  213. IEnumPackage *pIEnumPackage = NULL;
  214. VerbosePrint("...... CsEnumApps(All Platform & Locale).\n");
  215. hr = CsEnumApps(
  216. NULL,
  217. NULL,
  218. NULL,
  219. APPINFO_ALLLOCALE | APPINFO_ALLPLATFORM,
  220. &pIEnumPackage
  221. );
  222. if (hr != S_OK)
  223. {
  224. printf ("CsEnumApps returned error = 0x%x.\n", hr);
  225. return hr;
  226. }
  227. memset (&PackageInfo[0], 0, sizeof(PACKAGEDISPINFO) * 30);
  228. VerbosePrint("......... Next(6)\n");
  229. hr = pIEnumPackage->Next(6, &PackageInfo[0], &cFound );
  230. HandleEnumResult(6, cFound, hr, &PackageInfo[0]);
  231. VerbosePrint("......... Next(4)\n");
  232. hr = pIEnumPackage->Next(4, &PackageInfo[0], &cFound );
  233. HandleEnumResult(4, cFound, hr, &PackageInfo[0]);
  234. pIEnumPackage->Release();
  235. pIEnumPackage = NULL;
  236. VerbosePrint("...... CsEnumApps(All Platform & Locale, Wildcard=*2*2*)\n");
  237. hr = CsEnumApps(
  238. L"*2*2*",
  239. NULL,
  240. NULL,
  241. APPINFO_ALLLOCALE | APPINFO_ALLPLATFORM,
  242. &pIEnumPackage
  243. );
  244. if (hr != S_OK)
  245. {
  246. printf ("CsEnumApps returned error = 0x%x.\n", hr);
  247. return hr;
  248. }
  249. if (fClassInfoVerify) {
  250. DWORD cgot;
  251. EnumTests(pIEnumPackage, 3, &cgot, PackageDisp, 3, TRUE);
  252. }
  253. else {
  254. memset (&PackageInfo[0], 0, sizeof(PACKAGEDISPINFO) * 30);
  255. VerbosePrint("......... Next(6)\n");
  256. hr = pIEnumPackage->Next(6, &PackageInfo[0], &cFound );
  257. HandleEnumResult(6, cFound, hr, &PackageInfo[0]);
  258. }
  259. pIEnumPackage->Release();
  260. pIEnumPackage = NULL;
  261. VerbosePrint("...... CsEnumApps(ASSIGNED & MSI ONLY)\n");
  262. hr = CsEnumApps(
  263. NULL,
  264. NULL,
  265. NULL,
  266. APPINFO_ASSIGNED | APPINFO_MSI,
  267. &pIEnumPackage
  268. );
  269. if (hr != S_OK)
  270. {
  271. printf ("CsEnumApps returned error = 0x%x.\n", hr);
  272. return hr;
  273. }
  274. if (fClassInfoVerify) {
  275. DWORD cgot;
  276. EnumTests(pIEnumPackage, 3, &cgot, PackageDisp, 3, TRUE);
  277. }
  278. else {
  279. memset (&PackageInfo[0], 0, sizeof(PACKAGEDISPINFO) * 30);
  280. VerbosePrint("......... Next(6)\n");
  281. hr = pIEnumPackage->Next(6, &PackageInfo[0], &cFound );
  282. HandleEnumResult(6, cFound, hr, &PackageInfo[0]);
  283. }
  284. pIEnumPackage->Release();
  285. pIEnumPackage = NULL;
  286. VerbosePrint("...... CsEnumApps(PUBLISHED & VISIBLE ONLY)\n");
  287. hr = CsEnumApps(
  288. NULL,
  289. NULL,
  290. NULL,
  291. APPINFO_PUBLISHED | APPINFO_VISIBLE,
  292. &pIEnumPackage
  293. );
  294. if (hr != S_OK)
  295. {
  296. printf ("CsEnumApps returned error = 0x%x.\n", hr);
  297. return hr;
  298. }
  299. if (fClassInfoVerify) {
  300. DWORD cgot;
  301. EnumTests(pIEnumPackage, 3, &cgot, PackageDisp, 3, TRUE);
  302. }
  303. else {
  304. memset (&PackageInfo[0], 0, sizeof(PACKAGEDISPINFO) * 30);
  305. VerbosePrint("......... Next(6)\n");
  306. hr = pIEnumPackage->Next(6, &PackageInfo[0], &cFound );
  307. HandleEnumResult(6, cFound, hr, &PackageInfo[0]);
  308. }
  309. pIEnumPackage->Release();
  310. return hr;
  311. }
  312. extern PACKAGEDETAIL PackageDetail1, PackageDetail2,
  313. PackageDetail3, PackageDetail4;
  314. HRESULT DoClassInfoTest()
  315. {
  316. INSTALLINFO InstallInfo;
  317. HRESULT hr = S_OK, hr2;
  318. //By Package Name
  319. VerbosePrint("...... Lookup by Package Name.\n");
  320. hr = LookupByName (TestPackName4,
  321. &InstallInfo);
  322. if (fClassInfoVerify)
  323. if (!Compare(InstallInfo, *(PackageDetail3.pInstallInfo)))
  324. printf("!!!Members of InstallInfo not matching\n\n");
  325. ReleaseInstallInfo(&InstallInfo);
  326. //FileExt1
  327. VerbosePrint("...... Lookup by FileExt1.\n");
  328. hr2 = LookupByFileext (TestFileExt1, &InstallInfo);
  329. if (SUCCEEDED(hr2))
  330. {
  331. // Check expected values
  332. //
  333. hr2 = AssertPackage(&InstallInfo);
  334. if (fClassInfoVerify)
  335. if (!Compare(InstallInfo, *(PackageDetail1.pInstallInfo)))
  336. printf("!!!Members of InstallInfo not matching\n\n");
  337. }
  338. if (!SUCCEEDED(hr2))
  339. hr = hr2;
  340. ReleaseInstallInfo(&InstallInfo);
  341. //Clsid1
  342. VerbosePrint("...... Lookup by Clsid1.\n");
  343. hr2 = LookupByClsid (TestClsid1, &InstallInfo);
  344. if (SUCCEEDED(hr2))
  345. {
  346. // Check expected values
  347. //
  348. hr2 = AssertPackage(&InstallInfo);
  349. if (fClassInfoVerify)
  350. if ((!Compare(InstallInfo, *(PackageDetail1.pInstallInfo))) &&
  351. (!Compare(InstallInfo, *(PackageDetail2.pInstallInfo))))
  352. printf("!!!Members of InstallInfo not matching\n\n");
  353. }
  354. if (!SUCCEEDED(hr2))
  355. hr = hr2;
  356. ReleaseInstallInfo(&InstallInfo);
  357. //ProgId1
  358. VerbosePrint("...... Lookup by ProgId1.\n");
  359. hr2 = LookupByProgid (TestProgId1, &InstallInfo);
  360. if (SUCCEEDED(hr2))
  361. {
  362. //
  363. // Check expected values
  364. //
  365. hr2 = AssertPackage(&InstallInfo);
  366. if (fClassInfoVerify)
  367. if ((!Compare(InstallInfo, *(PackageDetail1.pInstallInfo))) &&
  368. (!Compare(InstallInfo, *(PackageDetail2.pInstallInfo))))
  369. printf("!!!Members of InstallInfo not matching\n\n");
  370. }
  371. if (!SUCCEEDED(hr2))
  372. hr = hr2;
  373. ReleaseInstallInfo(&InstallInfo);
  374. //Clsid2
  375. VerbosePrint("...... Lookup by Clsid2.\n");
  376. hr2 = LookupByClsid (TestClsid2, &InstallInfo);
  377. if (SUCCEEDED(hr2))
  378. {
  379. //
  380. // Check expected values
  381. //
  382. hr2 = AssertPackage(&InstallInfo);
  383. if (fClassInfoVerify)
  384. if (!Compare(InstallInfo, *(PackageDetail1.pInstallInfo)))
  385. printf("!!!Members of InstallInfo not matching\n\n");
  386. }
  387. if (!SUCCEEDED(hr2))
  388. hr = hr2;
  389. ReleaseInstallInfo(&InstallInfo);
  390. //ProgId3
  391. VerbosePrint("...... Lookup by ProgId3.\n");
  392. hr2 = LookupByProgid (TestProgId3, &InstallInfo);
  393. if (SUCCEEDED(hr2))
  394. {
  395. //
  396. // Check expected values
  397. //
  398. hr2 = AssertPackage(&InstallInfo);
  399. if (fClassInfoVerify)
  400. if (!Compare(InstallInfo, *(PackageDetail2.pInstallInfo)))
  401. printf("!!!Members of InstallInfo not matching\n\n");
  402. }
  403. if (!SUCCEEDED(hr2))
  404. hr = hr2;
  405. ReleaseInstallInfo(&InstallInfo);
  406. //TestOtherProgID2
  407. VerbosePrint("...... Lookup by OtherProgId2.\n");
  408. hr2 = LookupByProgid (TestOtherProgID2, &InstallInfo);
  409. if (SUCCEEDED(hr2))
  410. {
  411. //
  412. // Check expected values
  413. //
  414. hr2 = AssertPackage(&InstallInfo);
  415. if (fClassInfoVerify)
  416. if ((!Compare(InstallInfo, *(PackageDetail1.pInstallInfo))) &&
  417. (!Compare(InstallInfo, *(PackageDetail2.pInstallInfo))))
  418. printf("!!!Members of InstallInfo not matching\n\n");
  419. }
  420. if (!SUCCEEDED(hr2))
  421. hr = hr2;
  422. ReleaseInstallInfo(&InstallInfo);
  423. if (!fMultiStore)
  424. return hr;
  425. VerbosePrint(".... Looking in Second Store.\n");
  426. //FileExt4
  427. VerbosePrint("...... Lookup by FileExt4.\n");
  428. hr = LookupByFileext (TestFileExt4, &InstallInfo);
  429. if (SUCCEEDED(hr))
  430. {
  431. // Check expected values
  432. //
  433. hr2 = AssertPackage(&InstallInfo);
  434. if (fClassInfoVerify)
  435. if ((!Compare(InstallInfo, *(PackageDetail1.pInstallInfo))) &&
  436. (!Compare(InstallInfo, *(PackageDetail3.pInstallInfo))))
  437. printf("!!!Members of InstallInfo not matching\n\n");
  438. }
  439. ReleaseInstallInfo(&InstallInfo);
  440. // Clsid4
  441. // Should get two packages now !!
  442. VerbosePrint("...... Lookup by Clsid4.\n");
  443. hr2 = LookupByClsid (TestClsid4, &InstallInfo);
  444. if (SUCCEEDED(hr2))
  445. {
  446. //
  447. // Check expected values
  448. //
  449. hr2 = AssertPackage(&InstallInfo);
  450. }
  451. if (!SUCCEEDED(hr2))
  452. hr = hr2;
  453. ReleaseInstallInfo(&InstallInfo);
  454. // Tlbid1
  455. VerbosePrint("...... Lookup by Tlbid1.\n");
  456. hr2 = LookupByTlbid (TestClsid1, &InstallInfo);
  457. if (SUCCEEDED(hr2))
  458. {
  459. //
  460. // Check expected values
  461. //
  462. hr2 = AssertPackage(&InstallInfo);
  463. }
  464. if (!SUCCEEDED(hr2))
  465. hr = hr2;
  466. ReleaseInstallInfo(&InstallInfo);
  467. // Tlbid2
  468. VerbosePrint("...... Lookup by Tlbid2.\n");
  469. hr2 = LookupByTlbid (TestClsid2, &InstallInfo);
  470. if (SUCCEEDED(hr2))
  471. {
  472. //
  473. // Check expected values
  474. //
  475. //AssertPackage(&InstallInfo);
  476. }
  477. if (!SUCCEEDED(hr2))
  478. hr = hr2;
  479. ReleaseInstallInfo(&InstallInfo);
  480. // Clsid5
  481. VerbosePrint("...... Lookup by Clsid5.\n");
  482. hr2 = LookupByClsid (TestClsid5, &InstallInfo);
  483. if (SUCCEEDED(hr2))
  484. {
  485. //
  486. // Check expected values
  487. //
  488. hr2 = AssertPackage(&InstallInfo);
  489. }
  490. if (!SUCCEEDED(hr2))
  491. hr = hr2;
  492. ReleaseInstallInfo(&InstallInfo);
  493. return hr;
  494. }