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.

512 lines
15 KiB

  1. // csdrtcat.cxx
  2. // This runs the following tests.
  3. // Adds two classes catclsid1, catclsid2
  4. // adds 3 categories
  5. // 1 with 1 desc and locale id.
  6. // 2 with 2 desc and locale id.
  7. // 3 without 1 desc and locale id 2.
  8. //
  9. // register 2 categories in the req. list for catclsid1. (cat1, cat2)
  10. // register 1 impl category in the impl list for catclsid1 (cat3)
  11. //
  12. // register 2 in the the impl for the catclsid2.(cat2, cat3)
  13. //
  14. // unregister 1 cat frm the req list for catclsid1 (cat2)
  15. // register that one for impl list of catclsid1 (cat2)
  16. //
  17. //
  18. // Info tests confirmations as well as tests.
  19. //
  20. // Enumcat result should be two. Match descriptions.
  21. // EnumImplCategories of clsid1 should be 2. (cat2, cat3)
  22. // EnumReqCategories of clsid2 should be zero.
  23. //
  24. // Enumclasses of categories with (req: cat1, cat3) (impl: cat2) should be two.
  25. //
  26. // GetCategoryDesc with the other locale id than the one used in EnumCat. cat2
  27. // with any locale id cat3.
  28. //
  29. // IsClassOfCategories clsid1 impl cat2, req: cat1 answer should be S_OK
  30. //
  31. //
  32. #include "csdrt.hxx"
  33. extern BOOL fVerbose;
  34. GUID catClsid1;
  35. GUID catClsid2;
  36. GUID testCatid1;
  37. GUID testCatid2;
  38. GUID testCatid3;
  39. Sname testCatDesc1, testCatDesc2, testCatDesc21, testCatDesc3, TestCatClassDesc1, TestCatClassDesc2;
  40. Sname testCatPackName1, testCatPackName2;
  41. LCID TestCatLocale1, TestCatLocale2;
  42. LPOLESTR testConstCatDesc1 = L"CS DRT Test Category Desc, 1 (Locale same as Thread)";
  43. LPOLESTR testConstCatDesc2 = L"CS DRT Test Category Desc, 2 (Locale same as Thread)";
  44. LPOLESTR testConstCatDesc21 = L"CS DRT Test Category Desc, 2 (Locale = Thread Locale + 1)";
  45. LPOLESTR testConstCatDesc3 = L"CS DRT Test Category Desc, 3 (Locale = Thread Locale + 1)";
  46. LPOLESTR testConstCatClassDesc1 = L"CS DRT Class id 1 for comcat test";
  47. LPOLESTR testConstCatClassDesc2 = L"CS DRT Class id 2 for comcat test";
  48. LPOLESTR testConstCatPackName1 = L"CS DRT Test Comcat Pack 1";
  49. LPOLESTR testConstCatPackName2 = L"CS DRT Test Comcat Pack 2";
  50. void InitCatTempNames()
  51. {
  52. CreateGuid(&catClsid1);
  53. CreateGuid(&catClsid2);
  54. CreateGuid(&testCatid1);
  55. CreateGuid(&testCatid2);
  56. CreateGuid(&testCatid3);
  57. CreateUnique(testCatDesc1, testConstCatDesc1);
  58. CreateUnique(testCatDesc2, testConstCatDesc2);
  59. CreateUnique(testCatDesc21, testConstCatDesc21);
  60. CreateUnique(testCatDesc3, testConstCatDesc3);
  61. CreateUnique(TestCatClassDesc1, testConstCatClassDesc1);
  62. CreateUnique(TestCatClassDesc2, testConstCatClassDesc2);
  63. TestCatLocale1 = GetThreadLocale();
  64. TestCatLocale2 = 2*TestCatLocale1 + 1;
  65. CreateUnique(testCatPackName1, testConstCatPackName1);
  66. CreateUnique(testCatPackName2, testConstCatPackName2);
  67. }
  68. void ReleaseObj(GUID obj)
  69. {
  70. }
  71. void ReleaseObj(CATEGORYINFO obj)
  72. {
  73. }
  74. HRESULT CreateCatClasses(IClassAdmin *pIClassAdmin1, IClassAdmin *pIClassAdmin2)
  75. {
  76. // CLASSDETAIL ClassDetail;
  77. // PACKAGEDETAIL PackageDetail;
  78. HRESULT hr = S_OK;
  79. // adding classes--------------------------------
  80. InitCatTempNames();
  81. // memset (&ClassDetail, NULL, sizeof (CLASSDETAIL));
  82. // memcpy (&ClassDetail.Clsid, &catClsid1, sizeof (GUID));
  83. //
  84. // memset(&PackageDetail, 0, sizeof(PACKAGEDETAIL));
  85. // PackageDetail.pActInfo->cClasses = 1;
  86. // PackageDetail.pActInfo->pClasses = (CLASSDETAIL *)CoTaskMemAlloc(sizeof(CLASSDETAIL));
  87. // PackageDetail.pActInfo->pClasses[0] = ClassDetail;
  88. //
  89. // hr = pIClassAdmin1->AddPackage(testCatPackName1, &PackageDetail);
  90. // if (!SUCCEEDED(hr))
  91. // {
  92. // printf ("ERROR! 1. NewPackage() in CatTest returned 0x%x.\n", hr);
  93. // return hr;
  94. // }
  95. //
  96. // PackageDetail.pActInfo->pClasses[0].Clsid = catClsid2;
  97. //
  98. // if (pIClassAdmin2)
  99. // hr = pIClassAdmin2->AddPackage(testCatPackName2, &PackageDetail);
  100. // else
  101. // hr = pIClassAdmin1->AddPackage(testCatPackName2, &PackageDetail);
  102. //
  103. // if (!SUCCEEDED(hr))
  104. // {
  105. // printf ("ERROR! 2. NewPackage() in CatTest returned 0x%x.\n", hr);
  106. // return hr;
  107. // }
  108. return hr;
  109. }
  110. HRESULT RegCategories(ICatRegister *pICatRegister1, ICatRegister *pICatRegister2)
  111. {
  112. HRESULT hr;
  113. CATEGORYINFO CategoryInfo;
  114. // adding categories---------------------------
  115. memset (&CategoryInfo, NULL, sizeof (CATEGORYINFO));
  116. memcpy(&CategoryInfo.catid, &testCatid1, sizeof(GUID));
  117. CategoryInfo.lcid = TestCatLocale1;
  118. wcscpy(CategoryInfo.szDescription, testCatDesc1);
  119. hr = pICatRegister1->RegisterCategories(1, &CategoryInfo);
  120. if (FAILED(hr))
  121. {
  122. printf("Error! 1. RegisterCategories in CatTest returned 0x%x.\n", hr);
  123. return hr;
  124. }
  125. memset (&CategoryInfo, NULL, sizeof (CATEGORYINFO));
  126. memcpy(&CategoryInfo.catid, &testCatid2, sizeof(GUID));
  127. CategoryInfo.lcid = TestCatLocale1;
  128. wcscpy(CategoryInfo.szDescription, testCatDesc2);
  129. hr = pICatRegister1->RegisterCategories(1, &CategoryInfo);
  130. if (FAILED(hr))
  131. {
  132. printf("Error! 2. RegisterCategories in CatTest returned 0x%x.\n", hr);
  133. return hr;
  134. }
  135. memset (&CategoryInfo, NULL, sizeof (CATEGORYINFO));
  136. memcpy(&CategoryInfo.catid, &testCatid2, sizeof(GUID));
  137. CategoryInfo.lcid = TestCatLocale2;
  138. wcscpy(CategoryInfo.szDescription, testCatDesc21);
  139. hr = pICatRegister1->RegisterCategories(1, &CategoryInfo);
  140. if (FAILED(hr))
  141. {
  142. printf("Error! 3. RegisterCategories in CatTest returned 0x%x.\n", hr);
  143. return hr;
  144. }
  145. memset (&CategoryInfo, NULL, sizeof (CATEGORYINFO));
  146. memcpy(&CategoryInfo.catid, &testCatid3, sizeof(GUID));
  147. CategoryInfo.lcid = TestCatLocale2;
  148. wcscpy(CategoryInfo.szDescription, testCatDesc3);
  149. if (pICatRegister2)
  150. hr = pICatRegister2->RegisterCategories(1, &CategoryInfo);
  151. else
  152. hr = pICatRegister1->RegisterCategories(1, &CategoryInfo);
  153. if (FAILED(hr))
  154. {
  155. printf("Error! 4. RegisterCategories in CatTest returned 0x%x.\n", hr);
  156. return hr;
  157. }
  158. return hr;
  159. }
  160. HRESULT RegCategoriesWithClasses(ICatRegister *pICatRegister1,
  161. ICatRegister *pICatRegister2)
  162. {
  163. GUID guids[4];
  164. HRESULT hr=S_OK;
  165. // registering implemented and required categories.--------------
  166. guids[0] = testCatid1;
  167. guids[1] = testCatid2;
  168. hr = pICatRegister1->RegisterClassReqCategories(catClsid1, 2, guids);
  169. if (FAILED(hr))
  170. {
  171. printf("Error! 1. RegisterClassReqCategories in CatTest returned 0x%x.\n", hr);
  172. return hr;
  173. }
  174. hr = pICatRegister1->RegisterClassImplCategories(catClsid1, 1, &testCatid3);
  175. if (FAILED(hr))
  176. {
  177. printf("Error! 1. RegisterClassImplCategories in CatTest returned 0x%x.\n", hr);
  178. return hr;
  179. }
  180. guids[0] = testCatid2;
  181. guids[1] = testCatid3;
  182. if (pICatRegister2)
  183. hr = pICatRegister2->RegisterClassImplCategories(catClsid2, 2, guids);
  184. else
  185. hr = pICatRegister1->RegisterClassImplCategories(catClsid2, 2, guids);
  186. if (FAILED(hr))
  187. {
  188. printf("Error! 2. RegisterClassImplCategories in CatTest returned 0x%x.\n", hr);
  189. return hr;
  190. }
  191. hr = pICatRegister1->UnRegisterClassReqCategories(catClsid1, 1, &testCatid2);
  192. if (FAILED(hr))
  193. {
  194. printf("Error! 1. UnRegisterClassReqCategories in CatTest returned 0x%x.\n", hr);
  195. return hr;
  196. }
  197. hr = pICatRegister1->RegisterClassImplCategories(catClsid1, 1, &testCatid2);
  198. if (FAILED(hr))
  199. {
  200. printf("Error! 1. RegisterClassImplCategories in CatTest returned 0x%x.\n", hr);
  201. return hr;
  202. }
  203. return hr;
  204. }
  205. void VerbosePrintObj(CATEGORYINFO catinfo)
  206. {
  207. VerbosePrint("Description %S\n", catinfo.szDescription);
  208. }
  209. void VerbosePrintObj(GUID guid)
  210. {
  211. }
  212. HRESULT DoEnumCatsOfClassesTest(ICatInformation *pICatInformation)
  213. {
  214. HRESULT hr=S_OK;
  215. IEnumGUID *pIEnumGUID = NULL;
  216. GUID guids[4];
  217. LPOLESTR szDesc;
  218. ULONG got;
  219. // Enumerating Implemented Categories-------------------------
  220. hr = pICatInformation->EnumImplCategoriesOfClass(catClsid1, &pIEnumGUID);
  221. if (FAILED(hr))
  222. {
  223. printf("Error! EnumImplCategoriesOfClass in CatTest returned 0x%x\n", hr);
  224. return hr;
  225. }
  226. hr = EnumTests<IEnumGUID, GUID>(pIEnumGUID, 2, NULL, 0, 0, FALSE);
  227. // Enumerating Required Categories-------------------------
  228. hr = pICatInformation->EnumReqCategoriesOfClass(catClsid1, &pIEnumGUID);
  229. if (FAILED(hr))
  230. {
  231. printf("Error! EnumImplCategoriesOfClass in CatTest returned 0x%x\n", hr);
  232. return hr;
  233. }
  234. if (FAILED(hr))
  235. {
  236. printf("Error! EnumReqCategoriesOfClass in CatTest returned 0x%x\n", hr);
  237. return hr;
  238. }
  239. hr = EnumTests<IEnumGUID, GUID>(pIEnumGUID, 1, NULL, 0, 0, FALSE);
  240. return hr;
  241. }
  242. HRESULT DoEnumClassesOfCats(ICatInformation *pICatInformation)
  243. {
  244. HRESULT hr=S_OK;
  245. IEnumGUID *pIEnumGUID = NULL;
  246. GUID guids[4];
  247. ULONG got;
  248. // Enumerating classes of categories--------------------------------
  249. guids[0] = testCatid1;
  250. guids[1] = testCatid3;
  251. hr = pICatInformation->EnumClassesOfCategories(1, &testCatid2, 2, guids, &pIEnumGUID);
  252. if (FAILED(hr))
  253. {
  254. printf("Error! EnumClassesOfCategories in CatTest returned 0x%x\n", hr);
  255. return hr;
  256. }
  257. EnumTests<IEnumGUID, GUID>(pIEnumGUID, 2, NULL, 0, 0, FALSE);
  258. return hr;
  259. }
  260. HRESULT CatCleanup(ICatRegister *pICatRegister1, ICatRegister *pICatRegister2)
  261. {
  262. HRESULT hr;
  263. // Removing the categories at the end of the test.-----------------
  264. hr = pICatRegister1->UnRegisterCategories(1, &testCatid1);
  265. if (FAILED(hr))
  266. printf ("ERROR! 1. UnRegisterCategories() in CatTest returned 0x%x.\n", hr);
  267. hr = pICatRegister1->UnRegisterCategories(1, &testCatid2);
  268. if (FAILED(hr))
  269. printf ("ERROR! 2. UnRegisterCategories() in CatTest returned 0x%x.\n", hr);
  270. if (pICatRegister2)
  271. hr = pICatRegister2->UnRegisterCategories(1, &testCatid3);
  272. else
  273. hr = pICatRegister1->UnRegisterCategories(1, &testCatid3);
  274. if (FAILED(hr))
  275. printf ("ERROR! 3. UnRegisterCategories() in CatTest returned 0x%x.\n", hr);
  276. return hr;
  277. }
  278. HRESULT CatClassCleanup(IClassAdmin *pIClassAdmin1, IClassAdmin *pIClassAdmin2)
  279. {
  280. HRESULT hr;
  281. // Removing the classes and at the end of the test.--------------
  282. // hr = pIClassAdmin1->RemovePackage(testCatPackName1, 0);
  283. // if (FAILED(hr))
  284. // printf ("ERROR! 1. RemovePackage() in CatTest returned 0x%x.\n", hr);
  285. if (pIClassAdmin2)
  286. hr = pIClassAdmin2->RemovePackage(testCatPackName2, 0);
  287. else
  288. hr = pIClassAdmin1->RemovePackage(testCatPackName2, 0);
  289. if (FAILED(hr))
  290. printf ("ERROR! 2. RemovePackage() in CatTest returned 0x%x.\n", hr);
  291. return hr;
  292. }
  293. HRESULT DoCatTests(IClassAdmin *pIClassAdmin1, IClassAdmin *pIClassAdmin2)
  294. {
  295. HRESULT hr=S_OK, hr1=S_OK;
  296. CATEGORYINFO CategoryInfo;
  297. ICatRegister *pICatRegister1=NULL, *pICatRegister2=NULL;
  298. ICatInformation *pICatInformation = NULL;
  299. IEnumGUID *pIEnumGUID = NULL;
  300. GUID guids[4];
  301. LPOLESTR szDesc;
  302. ULONG expected, got=0;
  303. IEnumCATEGORYINFO *pIEnumCATEGORYINFO = NULL;
  304. VerbosePrint("Creating classes for category test\n\n");
  305. hr = CreateCatClasses(pIClassAdmin1, pIClassAdmin2);
  306. if (FAILED(hr))
  307. goto ReleaseAll;
  308. //getting Icatregister interface--------------
  309. hr = pIClassAdmin1->QueryInterface(IID_ICatRegister, (void **)&pICatRegister1);
  310. if (FAILED(hr))
  311. {
  312. printf("Error! QueryInterface failed for ICatRegister in CatTest returned 0x%x.\n", hr);
  313. goto ReleaseAll;
  314. }
  315. if (pIClassAdmin2)
  316. hr = pIClassAdmin2->QueryInterface(IID_ICatRegister, (void **)&pICatRegister2);
  317. if (FAILED(hr))
  318. {
  319. printf("Error! QueryInterface failed for ICatRegister in CatTest returned 0x%x.\n", hr);
  320. goto ReleaseAll;
  321. }
  322. // getting the ICatInformation pointer
  323. hr = CoCreateInstance(CLSID_GblComponentCategoriesMgr, NULL, CLSCTX_INPROC,
  324. IID_ICatInformation, (void **)&pICatInformation);
  325. if (FAILED(hr))
  326. {
  327. printf("**Error! QueryInterface failed for ICatInformation in comcat returned 0x%x.\n", hr);
  328. goto ReleaseAll;
  329. }
  330. VerbosePrint("\nEnumerating Categories for category test before registering\n\n");
  331. hr = pICatInformation->EnumCategories(TestCatLocale1, &pIEnumCATEGORYINFO);
  332. if (FAILED(hr)) {
  333. printf("**Error! EnumCategories failed for ICatInformation in comcat returned 0x%x.\n", hr);
  334. goto ReleaseAll;
  335. }
  336. hr = EnumTests<IEnumCATEGORYINFO, CATEGORYINFO>(pIEnumCATEGORYINFO, 0, &got, 0, 0, FALSE);
  337. if (FAILED(hr))
  338. goto ReleaseAll;
  339. VerbosePrint("\nRegistering Categories for category test\n\n");
  340. hr = RegCategories(pICatRegister1, pICatRegister2);
  341. if (FAILED(hr))
  342. goto ReleaseAll;
  343. VerbosePrint("\nRegistering Categories with classes for category test\n\n");
  344. hr = RegCategoriesWithClasses(pICatRegister1, pICatRegister2);
  345. if (FAILED(hr))
  346. goto ReleaseAll;
  347. VerbosePrint("\nEnumerating Categories for category test after registering\n\n");
  348. hr = pICatInformation->EnumCategories(TestCatLocale1, &pIEnumCATEGORYINFO);
  349. if (FAILED(hr)) {
  350. printf("**Error! EnumCategories failed for ICatInformation in comcat returned 0x%x.\n", hr);
  351. goto ReleaseAll;
  352. }
  353. hr = EnumTests<IEnumCATEGORYINFO, CATEGORYINFO>(pIEnumCATEGORYINFO, got+3, NULL, 0, 0, FALSE);
  354. if (FAILED(hr))
  355. goto ReleaseAll;
  356. VerbosePrint("\nEnumerating Categories of the classes for category test\n\n");
  357. hr = DoEnumCatsOfClassesTest(pICatInformation);
  358. if (FAILED(hr))
  359. goto ReleaseAll;
  360. VerbosePrint("\nEnumerating Classes of the categories for category test\n\n");
  361. hr = DoEnumClassesOfCats(pICatInformation);
  362. if (FAILED(hr))
  363. goto ReleaseAll;
  364. VerbosePrint("\nTesting IsClassOfCategories for category test\n\n");
  365. hr = pICatInformation->IsClassOfCategories(catClsid1, 1, &testCatid2, -1, NULL); // 1, &testCatid1);
  366. if (hr != S_OK)
  367. {
  368. printf("Error! IsClassOfCategories in CatTest returned 0x%x\n", hr);
  369. goto ReleaseAll;
  370. }
  371. // GetCategoryDesc------------------
  372. VerbosePrint("\nCalling GetCategoryDesc for category test\n\n");
  373. hr = pICatInformation->GetCategoryDesc(testCatid2, TestCatLocale2, &szDesc);
  374. if (FAILED(hr))
  375. {
  376. printf("Error!1. GetCategoryDesc in CatTest returned 0x%x\n", hr);
  377. goto ReleaseAll;
  378. }
  379. if (wcscmp(szDesc, testCatDesc21) != 0)
  380. {
  381. printf("Description not matching, Expected: \"%s\", got \"%s\"\n");
  382. goto ReleaseAll;
  383. }
  384. CoTaskMemFree(szDesc);
  385. hr = pICatInformation->GetCategoryDesc(testCatid3, TestCatLocale2, &szDesc);
  386. if (FAILED(hr))
  387. {
  388. printf("Error!2. GetCategoryDesc in CatTest returned 0x%x\n", hr);
  389. goto ReleaseAll;
  390. }
  391. if (wcscmp(szDesc, testCatDesc3) != 0)
  392. {
  393. printf("Error!3. Description not matching, Expected: \"%s\", got \"%s\"\n");
  394. goto ReleaseAll;
  395. }
  396. CoTaskMemFree(szDesc);
  397. VerbosePrint("\nCleaning up the classes and the categories for category test\n\n");
  398. ReleaseAll:
  399. CatCleanup(pICatRegister1, pICatRegister2);
  400. CatClassCleanup(pIClassAdmin1, pIClassAdmin2);
  401. if (pICatRegister1)
  402. pICatRegister1->Release();
  403. if (pICatRegister2)
  404. pICatRegister2->Release();
  405. if (pICatInformation)
  406. pICatInformation->Release();
  407. return hr;
  408. }
  409.