Leaked source code of windows server 2003
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.

351 lines
9.2 KiB

  1. //+------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1993.
  5. //
  6. // File: bm_api.cxx
  7. //
  8. // Contents: Miscellaneous OLE API tests
  9. //
  10. // Classes: CApiTest
  11. //
  12. // History: 1-July-93 t-martig Created
  13. //
  14. //--------------------------------------------------------------------------
  15. #include <headers.cxx>
  16. #pragma hdrstop
  17. #include <bm_api.hxx>
  18. const GUID CLSID_Balls =
  19. {0x0000013a,0x0001,0x0008,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};
  20. const GUID CLSID_Dummy =
  21. {0x00000142,0x0000,0x0008,{0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46}};
  22. TCHAR *CApiTest::Name ()
  23. {
  24. return TEXT("ApiTest");
  25. }
  26. SCODE CApiTest::Setup (CTestInput *pInput)
  27. {
  28. CTestBase::Setup(pInput);
  29. // get iteration count
  30. m_ulIterations = pInput->GetIterations(Name());
  31. // initialize timing arrays
  32. INIT_RESULTS(m_ulCoBuildVersion);
  33. INIT_RESULTS(m_ulOleBuildVersion);
  34. INIT_RESULTS(m_ulCoGetCurrentProcess);
  35. INIT_RESULTS(m_ulCoGetMalloc);
  36. // time APIs
  37. INIT_RESULTS(m_ulCoFileTimeNow);
  38. INIT_RESULTS(m_ulCoFileTimeToDosDateTime);
  39. INIT_RESULTS(m_ulCoDosDateTimeToFileTime);
  40. // registry & class APIs
  41. INIT_RESULTS(m_ulCoCreateGuid);
  42. INIT_RESULTS(m_ulCoTreatAsClass);
  43. INIT_RESULTS(m_ulCoGetTreatAsClass);
  44. INIT_RESULTS(m_ulCoIsOle1Class);
  45. INIT_RESULTS(m_ulGetClassFile);
  46. INIT_RESULTS(m_ulStringFromCLSID);
  47. INIT_RESULTS(m_ulCLSIDFromString);
  48. INIT_RESULTS(m_ulProgIDFromCLSID);
  49. INIT_RESULTS(m_ulStringFromIID);
  50. INIT_RESULTS(m_ulIIDFromString);
  51. INIT_RESULTS(m_ulCLSIDFromProgID);
  52. INIT_RESULTS(m_ulStringFromGUID2);
  53. // Get ClsID for this Ctx from the .ini file
  54. CLSID ClsID;
  55. HRESULT sc = pInput->GetGUID(&ClsID, Name(), apszClsIDName[1]);
  56. if (FAILED(sc))
  57. {
  58. Log (TEXT("Setup - GetClassID failed."), sc);
  59. return sc;
  60. }
  61. sc = InitCOM();
  62. if (FAILED(sc))
  63. {
  64. Log (TEXT("Setup - CoInitialize failed."), sc);
  65. return sc;
  66. }
  67. // Create an instance
  68. IClassFactory *pICF = NULL;
  69. sc = CoGetClassObject(ClsID, dwaClsCtx[1], NULL,
  70. IID_IClassFactory, (void **)&pICF);
  71. if (SUCCEEDED(sc))
  72. {
  73. IPersistFile *pIPF = NULL;
  74. sc = pICF->CreateInstance(NULL, IID_IPersistFile,
  75. (void **)&pIPF);
  76. pICF->Release();
  77. if (SUCCEEDED(sc))
  78. {
  79. // save the class instance in the storage
  80. sc = pIPF->Save(apszPerstName[1], FALSE);
  81. pIPF->Release();
  82. if (FAILED(sc))
  83. {
  84. Log (TEXT("Setup - pIPF->Save failed."), sc);
  85. }
  86. }
  87. else
  88. {
  89. Log (TEXT("Setup - CreateInstance failed"), sc);
  90. }
  91. }
  92. else
  93. {
  94. Log (TEXT("Setup - CoGetClassObject failed"), sc);
  95. }
  96. return sc;
  97. }
  98. SCODE CApiTest::Cleanup ()
  99. {
  100. UninitCOM();
  101. // delete the file
  102. CHAR szPerstName[MAX_PATH];
  103. wcstombs(szPerstName, apszPerstName[1], wcslen(apszPerstName[1])+1);
  104. _unlink (szPerstName);
  105. return S_OK;
  106. }
  107. SCODE CApiTest::Run ()
  108. {
  109. CStopWatch sw;
  110. SCODE sc;
  111. for (ULONG iIter=0; iIter<m_ulIterations; iIter++)
  112. {
  113. sw.Reset();
  114. DWORD bldver = CoBuildVersion();
  115. m_ulCoBuildVersion[iIter] = sw.Read();
  116. }
  117. for (iIter=0; iIter<m_ulIterations; iIter++)
  118. {
  119. sw.Reset();
  120. DWORD bldver = OleBuildVersion();
  121. m_ulOleBuildVersion[iIter] = sw.Read();
  122. }
  123. for (iIter=0; iIter<m_ulIterations; iIter++)
  124. {
  125. sw.Reset();
  126. DWORD pid = CoGetCurrentProcess();
  127. m_ulCoGetCurrentProcess[iIter] = sw.Read();
  128. }
  129. for (iIter=0; iIter<m_ulIterations; iIter++)
  130. {
  131. IMalloc *pMalloc = NULL;
  132. sw.Reset();
  133. sc = CoGetMalloc(MEMCTX_TASK, &pMalloc);
  134. if (SUCCEEDED(sc))
  135. {
  136. pMalloc->Release();
  137. }
  138. m_ulCoGetMalloc[iIter] = sw.Read();
  139. Log (TEXT("CoGetMalloc"), sc);
  140. }
  141. for (iIter=0; iIter<m_ulIterations; iIter++)
  142. {
  143. FILETIME ft;
  144. WORD wDosDate, wDosTime;
  145. sw.Reset();
  146. sc = CoFileTimeNow(&ft);
  147. m_ulCoFileTimeNow[iIter] = sw.Read();
  148. Log (TEXT("CoFileTimeNow"), sc);
  149. sw.Reset();
  150. sc = CoFileTimeToDosDateTime(&ft, &wDosDate, &wDosTime);
  151. m_ulCoFileTimeToDosDateTime[iIter] = sw.Read();
  152. Log (TEXT("CoFileTimeToDosDateTime"), sc);
  153. sw.Reset();
  154. sc = CoDosDateTimeToFileTime(wDosDate, wDosTime, &ft);
  155. m_ulCoDosDateTimeToFileTime[iIter] = sw.Read();
  156. Log (TEXT("CoDosDateTimeToFileTime"), sc);
  157. }
  158. IMalloc *pMalloc = NULL;
  159. sc = CoGetMalloc(MEMCTX_TASK, &pMalloc);
  160. if (FAILED(sc))
  161. {
  162. return sc;
  163. }
  164. for (iIter=0; iIter<m_ulIterations; iIter++)
  165. {
  166. GUID Guid, GuidNew;
  167. LPOLESTR pwsz = NULL;
  168. OLECHAR awsz[50];
  169. sw.Reset();
  170. sc = CoCreateGuid(&Guid);
  171. m_ulCoCreateGuid[iIter] = sw.Read();
  172. if (FAILED(sc))
  173. m_ulCoCreateGuid[iIter] = NOTAVAIL;
  174. sw.Reset();
  175. sc = CoTreatAsClass(CLSID_Dummy, Guid);
  176. m_ulCoTreatAsClass[iIter] = sw.Read();
  177. Log (TEXT("CoTreatAsClass"), sc);
  178. if (FAILED(sc))
  179. m_ulCoTreatAsClass[iIter] = NOTAVAIL;
  180. sw.Reset();
  181. sc = CoGetTreatAsClass(CLSID_Dummy, &GuidNew);
  182. m_ulCoGetTreatAsClass[iIter] = sw.Read();
  183. Log (TEXT("CoGetTreatAsClass"), sc);
  184. if (FAILED(sc))
  185. m_ulCoGetTreatAsClass[iIter] = NOTAVAIL;
  186. sw.Reset();
  187. sc = GetClassFile(apszPerstName[1], &Guid);
  188. m_ulGetClassFile[iIter] = sw.Read();
  189. Log (TEXT("GetClassFile"), sc);
  190. if (FAILED(sc))
  191. m_ulGetClassFile[iIter] = NOTAVAIL;
  192. sw.Reset();
  193. sc = StringFromCLSID(Guid, &pwsz);
  194. m_ulStringFromCLSID[iIter] = sw.Read();
  195. Log (TEXT("StringFromCLSID"), sc);
  196. if (FAILED(sc))
  197. m_ulStringFromCLSID[iIter] = NOTAVAIL;
  198. sw.Reset();
  199. sc = CLSIDFromString(pwsz, &GuidNew);
  200. m_ulCLSIDFromString[iIter] = sw.Read();
  201. Log (TEXT("CLSIDFromString"), sc);
  202. if (FAILED(sc))
  203. m_ulCLSIDFromString[iIter] = NOTAVAIL;
  204. pMalloc->Free((void *)pwsz);
  205. sw.Reset();
  206. sc = StringFromIID(Guid, &pwsz);
  207. m_ulStringFromIID[iIter] = sw.Read();
  208. Log (TEXT("StringFromIID"), sc);
  209. if (FAILED(sc))
  210. m_ulStringFromIID[iIter] = NOTAVAIL;
  211. sw.Reset();
  212. sc = IIDFromString(pwsz, &GuidNew);
  213. m_ulIIDFromString[iIter] = sw.Read();
  214. Log (TEXT("IIDFromString"), sc);
  215. if (FAILED(sc))
  216. m_ulIIDFromString[iIter] = NOTAVAIL;
  217. pMalloc->Free((void *)pwsz);
  218. sw.Reset();
  219. sc = StringFromGUID2(Guid, awsz, 50);
  220. m_ulStringFromGUID2[iIter] = sw.Read();
  221. Log (TEXT("StringFromGUID2"), sc);
  222. if (FAILED(sc))
  223. m_ulStringFromGUID2[iIter] = NOTAVAIL;
  224. }
  225. for (iIter=0; iIter<m_ulIterations; iIter++)
  226. {
  227. GUID Guid;
  228. LPOLESTR pwsz = NULL;
  229. sw.Reset();
  230. sc = ProgIDFromCLSID(CLSID_Balls, &pwsz);
  231. m_ulProgIDFromCLSID[iIter] = sw.Read();
  232. Log (TEXT("ProgIDFromCLSID"), sc);
  233. if (FAILED(sc))
  234. m_ulProgIDFromCLSID[iIter] = NOTAVAIL;
  235. sw.Reset();
  236. sc = CLSIDFromProgID(pwsz, &Guid);
  237. m_ulCLSIDFromProgID[iIter] = sw.Read();
  238. Log (TEXT("CLSIDFromProgID"), sc);
  239. if (FAILED(sc))
  240. m_ulCLSIDFromProgID[iIter] = NOTAVAIL;
  241. pMalloc->Free((void *)pwsz);
  242. }
  243. if (pMalloc)
  244. pMalloc->Release();
  245. // INIT_RESULTS(m_ulCoIsOle1Class);
  246. return S_OK;
  247. }
  248. SCODE CApiTest::Report (CTestOutput &output)
  249. {
  250. output.WriteSectionHeader (Name(), TEXT("Misc COM Apis"), *m_pInput);
  251. output.WriteString (TEXT("\n"));
  252. output.WriteResults (TEXT("CoBuildVersion "), m_ulIterations, m_ulCoBuildVersion);
  253. output.WriteResults (TEXT("OleBuildVersion "), m_ulIterations, m_ulOleBuildVersion);
  254. output.WriteResults (TEXT("CoGetCurrentProcess"), m_ulIterations, m_ulCoGetCurrentProcess);
  255. output.WriteResults (TEXT("CoGetMalloc "), m_ulIterations, m_ulCoGetMalloc);
  256. output.WriteString (TEXT("\n"));
  257. output.WriteResults (TEXT("CoFileTimeNow "), m_ulIterations, m_ulCoFileTimeNow);
  258. output.WriteResults (TEXT("CoFileTimeToDosDateTime"), m_ulIterations, m_ulCoFileTimeToDosDateTime);
  259. output.WriteResults (TEXT("CoDosDateTimeToFileTime"), m_ulIterations, m_ulCoDosDateTimeToFileTime);
  260. output.WriteString (TEXT("\n"));
  261. output.WriteResults (TEXT("CoCreateGuid "), m_ulIterations, m_ulCoCreateGuid);
  262. output.WriteResults (TEXT("CoTreatAsClass "), m_ulIterations, m_ulCoTreatAsClass);
  263. output.WriteResults (TEXT("CoGetTreatAsClass "), m_ulIterations, m_ulCoGetTreatAsClass);
  264. output.WriteResults (TEXT("CoIsOle1Class "), m_ulIterations, m_ulCoIsOle1Class);
  265. output.WriteResults (TEXT("GetClassFile "), m_ulIterations, m_ulGetClassFile);
  266. output.WriteString (TEXT("\n"));
  267. output.WriteResults (TEXT("StringFromCLSID "), m_ulIterations, m_ulStringFromCLSID);
  268. output.WriteResults (TEXT("CLSIDFromString "), m_ulIterations, m_ulCLSIDFromString);
  269. output.WriteResults (TEXT("ProgIDFromCLSID "), m_ulIterations, m_ulProgIDFromCLSID);
  270. output.WriteResults (TEXT("StringFromIID "), m_ulIterations, m_ulStringFromIID);
  271. output.WriteResults (TEXT("IIDFromString "), m_ulIterations, m_ulIIDFromString);
  272. output.WriteResults (TEXT("StringFromGUID2 "), m_ulIterations, m_ulStringFromGUID2);
  273. return S_OK;
  274. }
  275.