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.

346 lines
8.3 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. ioutest.cpp
  5. Abstract:
  6. incident object unit test
  7. Revision History:
  8. DerekM created 07/14/99
  9. ********************************************************************/
  10. #include <module.h>
  11. #include <MPC_utils.h>
  12. #include <MPC_com.h>
  13. #include <MPC_streams.h>
  14. #include <stdio.h>
  15. #include "HelpServiceTypeLib.h"
  16. #include "HelpServiceTypeLib_i.c"
  17. #include "HelpCenterTypeLib.h"
  18. #include "HelpCenterTypeLib_i.c"
  19. #include "hsi.h"
  20. #include <initguid.h>
  21. #include <msscript.h>
  22. #include <incident.h>
  23. // **************************************************************************
  24. int __cdecl wmain(int argc, WCHAR **argv, WCHAR **envp)
  25. {
  26. CComObject<MPC::FileStream> *pfsHist = NULL;
  27. CComObject<MPC::FileStream> *pfsSnap = NULL;
  28. CComObject<CHSC> *phsc = NULL;
  29. IDictionary *pDict = NULL;
  30. CComObject<CSAFIncident> *pIO = NULL;
  31. IDispatch *pdisp = NULL;
  32. CComBSTR bstrFile;
  33. CComBSTR bstr;
  34. CComBSTR bstrVal, bstrKey;
  35. VARIANT varVal, varKey;
  36. VARIANT_BOOL fRCReq = VARIANT_TRUE;
  37. VARIANT_BOOL fRCReqRet;
  38. CComBSTR bstrRCTicket, bstrRCTicket1;
  39. CComBSTR bstrStartPage, bstrStartPage1;
  40. CComBSTR bstrXMLBlob;
  41. HRESULT hr = NOERROR;
  42. if (argc < 2)
  43. {
  44. printf("Usage: ioutest <save | load | getxml>\n\n");
  45. return E_FAIL;
  46. }
  47. hr = CoInitialize(NULL);
  48. if (FAILED(hr))
  49. return hr;
  50. hr = CComObject<CSAFIncident>::CreateInstance(&pIO);
  51. if (FAILED(hr))
  52. goto done;
  53. hr = CComObject<MPC::FileStream>::CreateInstance(&pfsHist);
  54. if (FAILED(hr))
  55. goto done;
  56. hr = CComObject<MPC::FileStream>::CreateInstance(&pfsSnap);
  57. if (FAILED(hr))
  58. goto done;
  59. pfsHist->AddRef();
  60. pfsSnap->AddRef();
  61. bstrFile = L"d:\\incident.xml";
  62. hr = pIO->LoadFromXMLFile(bstrFile);
  63. bstrXMLBlob = L"<?xml version=\"1.0\" encoding=\"Unicode\"?><UPLOADINFO TYPE=\"Bug\"><UPLOADDATA USERNAME=\"Rajesh\" PROBLEMDESCRIPTION=\"Test Description\" RCTICKET=\"1,nsoytest1,HelpAssistant,90!4SbO7NTfN4v,1,TSRDP0,ht^5GmLrR2SKwI,0\" RCREQUESTED=\"1\" RCENCRYPTED=\"1\" SALEMID=\"1,nsoytest1,HelpAssistant,90!4SbO7NTfN4v,1,TSRDP0,ht^5GmLrR2SKwI,0\"/></UPLOADINFO>";
  64. hr = pIO->LoadFromXMLString(bstrXMLBlob);
  65. /*
  66. // Get the dictionary stuff
  67. hr = pIO->get_Misc(&pdisp);
  68. if (FAILED(hr))
  69. goto done;
  70. hr = pdisp->QueryInterface(IID_IDictionary, (LPVOID *)&pDict);
  71. if (FAILED(hr))
  72. goto done;
  73. // Read the contents of the dictionary object here...
  74. if(pDict)
  75. {
  76. VARIANT varKey;
  77. VARIANT varValue;
  78. VariantInit(&varKey);
  79. VariantInit(&varValue);
  80. V_VT(&varKey) = VT_BSTR;
  81. V_BSTR(&varKey) = L"USERNAME";
  82. hr = pDict->get_Item( &varKey, &varValue );
  83. V_VT(&varKey) = VT_BSTR;
  84. V_BSTR(&varKey) = L"PROBLEMDESCRIPTION";
  85. hr = pDict->get_Item( &varKey, &varValue );
  86. V_VT(&varKey) = VT_BSTR;
  87. V_BSTR(&varKey) = L"SALEMID";
  88. hr = pDict->get_Item( &varKey, &varValue );
  89. }
  90. */
  91. // add machine history stream
  92. bstrFile = L"d:\\hist.xml";
  93. hr = pfsHist->InitForRead( bstrFile );
  94. if (FAILED(hr))
  95. goto done;
  96. hr = pIO->put_MachineHistory(pfsHist);
  97. if (FAILED(hr))
  98. goto done;
  99. // add machine snapshot stream
  100. bstrFile = L"d:\\snap.xml";
  101. hr = pfsSnap->InitForRead( bstrFile );
  102. if (FAILED(hr))
  103. goto done;
  104. hr = pIO->put_MachineSnapshot(pfsSnap);
  105. if (FAILED(hr))
  106. goto done;
  107. // add problem description
  108. bstr = L"It doesn't work at all";
  109. hr = pIO->put_ProblemDescription(bstr);
  110. if (FAILED(hr))
  111. goto done;
  112. // add product name
  113. bstr = L"NonFunctionality 1.0";
  114. hr = pIO->put_ProductName(bstr);
  115. if (FAILED(hr))
  116. goto done;
  117. // add product id
  118. bstr = L"NF10";
  119. hr = pIO->put_ProductID(bstr);
  120. if (FAILED(hr))
  121. goto done;
  122. // add username
  123. bstr = L"Jim Bob Robberts";
  124. hr = pIO->put_UserName(bstr);
  125. if (FAILED(hr))
  126. goto done;
  127. // add upload type
  128. hr = pIO->put_UploadType(eutBug);
  129. if (FAILED(hr))
  130. goto done;
  131. // add the dictionary stuff
  132. hr = pIO->get_Misc(&pdisp);
  133. if (FAILED(hr))
  134. goto done;
  135. hr = pdisp->QueryInterface(IID_IDictionary, (LPVOID *)&pDict);
  136. if (FAILED(hr))
  137. goto done;
  138. VariantInit(&varKey);
  139. VariantInit(&varVal);
  140. V_VT(&varKey) = VT_BSTR;
  141. V_VT(&varVal) = VT_BSTR;
  142. bstrKey = L"Title";
  143. bstrVal = L"Exploding windows";
  144. V_BSTR(&varKey) = bstrKey.m_str;
  145. V_BSTR(&varVal) = bstrVal.m_str;
  146. hr = pDict->put_Item(&varKey, &varVal);
  147. if (FAILED(hr))
  148. goto done;
  149. bstrKey = L"Severity";
  150. bstrVal = L"Really Bad";
  151. V_BSTR(&varKey) = bstrKey.m_str;
  152. V_BSTR(&varVal) = bstrVal.m_str;
  153. hr = pDict->put_Item(&varKey, &varVal);
  154. if (FAILED(hr))
  155. goto done;
  156. bstrKey = L"Area";
  157. bstrVal = L"Windows";
  158. V_BSTR(&varKey) = bstrKey.m_str;
  159. V_BSTR(&varVal) = bstrVal.m_str;
  160. hr = pDict->put_Item(&varKey, &varVal);
  161. if (FAILED(hr))
  162. goto done;
  163. bstrKey = L"ExpectedResults";
  164. bstrVal = L"It just works!";
  165. V_BSTR(&varKey) = bstrKey.m_str;
  166. V_BSTR(&varVal) = bstrVal.m_str;
  167. hr = pDict->put_Item(&varKey, &varVal);
  168. if (FAILED(hr))
  169. goto done;
  170. bstrKey = L"ReproSteps";
  171. bstrVal = L"Turn on computer. Watch it explode.";
  172. V_BSTR(&varKey) = bstrKey.m_str;
  173. V_BSTR(&varVal) = bstrVal.m_str;
  174. hr = pDict->put_Item(&varKey, &varVal);
  175. if (FAILED(hr))
  176. goto done;
  177. // add the trace stuff
  178. hr = CComObject<CHSC>::CreateInstance(&phsc);
  179. if (FAILED(hr))
  180. goto done;
  181. //hr = pIO->put_SelfHelpTrace(phsc);
  182. //if (FAILED(hr))
  183. //goto done;
  184. // Add the new RC properties.
  185. // add RCRequested
  186. hr = pIO->put_RCRequested(fRCReq);
  187. if (FAILED(hr))
  188. goto done;
  189. hr = pIO->get_RCRequested(&fRCReqRet);
  190. if (FAILED(hr))
  191. goto done;
  192. // add RCTicketEncrypted
  193. hr = pIO->put_RCTicketEncrypted(fRCReq);
  194. if (FAILED(hr))
  195. goto done;
  196. hr = pIO->get_RCTicketEncrypted(&fRCReqRet);
  197. if (FAILED(hr))
  198. goto done;
  199. bstrRCTicket = L"This is the RCTicket";
  200. // Add RCTicket
  201. hr = pIO->put_RCTicket(bstrRCTicket);
  202. if (FAILED(hr))
  203. goto done;
  204. hr = pIO->get_RCTicket(&bstrRCTicket1);
  205. if (FAILED(hr))
  206. goto done;
  207. // add startpage
  208. bstrStartPage = L"http://startpage.htm";
  209. hr = pIO->put_StartPage(bstrStartPage);
  210. if (FAILED(hr))
  211. goto done;
  212. hr = pIO->get_StartPage(&bstrStartPage1);
  213. if (FAILED(hr))
  214. goto done;
  215. // dump the output
  216. switch(argv[1][0])
  217. {
  218. case 'L':
  219. case 'l':
  220. bstrFile = "d:\\out.sav";
  221. hr = pIO->Load(bstrFile);
  222. if (FAILED(hr))
  223. goto done;
  224. bstrFile = "d:\\out.xml";
  225. hr = pIO->GetXML(bstrFile);
  226. if (FAILED(hr))
  227. goto done;
  228. break;
  229. case 'S':
  230. case 's':
  231. bstrFile = "d:\\out.sav";
  232. hr = pIO->Save(bstrFile);
  233. if (FAILED(hr))
  234. goto done;
  235. break;
  236. case 'G':
  237. case 'g':
  238. bstrFile = "d:\\out.xml";
  239. hr = pIO->GetXML(bstrFile);
  240. if (FAILED(hr))
  241. goto done;
  242. break;
  243. default:
  244. printf("Usage: ioutest <save | load | getxml>\n\n");
  245. hr = E_INVALIDARG;
  246. break;
  247. }
  248. done:
  249. if (pfsHist != NULL)
  250. pfsHist->Release();
  251. if (pfsSnap != NULL)
  252. pfsSnap->Release();
  253. if (pDict != NULL)
  254. pDict->Release();
  255. if (pdisp != NULL)
  256. pdisp->Release();
  257. if (pIO != NULL)
  258. pIO->Release();
  259. CoUninitialize();
  260. return hr;
  261. }