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.

376 lines
7.5 KiB

  1. // tsdgns.cpp : Implementation of CTSDiagnosis
  2. #include "stdafx.h"
  3. #include "TSDiag.h"
  4. #include "tsdgns.h"
  5. #include "testdata.h"
  6. #include "suites.h"
  7. static int iTSDiag = 0;
  8. CTSDiagnosis::CTSDiagnosis()
  9. {
  10. m_dwSuite = 0;
  11. iTSDiag++;
  12. TCHAR szString[256];
  13. _stprintf(szString, _T("iTSDiag = %d\n"), iTSDiag);
  14. OutputDebugString(szString);
  15. }
  16. CTSDiagnosis::~CTSDiagnosis()
  17. {
  18. iTSDiag--;
  19. TCHAR szString[256];
  20. _stprintf(szString, _T("iTSDiag = %d\n"), iTSDiag);
  21. OutputDebugString(szString);
  22. }
  23. DWORD CTSDiagnosis::GetTotalTestCount ()
  24. {
  25. return GlobalTestData.GetTestCount(m_dwSuite);
  26. }
  27. STDMETHODIMP CTSDiagnosis::get_TestCount(long *pVal)
  28. {
  29. // TODO: Add your implementation code here
  30. *pVal = GetTotalTestCount ();
  31. return ERROR_SUCCESS;
  32. }
  33. STDMETHODIMP CTSDiagnosis::get_TestDescription(int i, BSTR * pVal)
  34. {
  35. // TODO: Add your implementation code here
  36. if (i >= (int)GetTotalTestCount ())
  37. {
  38. return ERROR_INVALID_PARAMETER;
  39. }
  40. if (!pVal)
  41. {
  42. return ERROR_INVALID_PARAMETER;
  43. }
  44. return E_NOTIMPL;
  45. return ERROR_SUCCESS;
  46. }
  47. STDMETHODIMP CTSDiagnosis::get_TestApplicable(int i, BOOL *pbApplicable)
  48. {
  49. if (i >= (int)GetTotalTestCount ())
  50. {
  51. return ERROR_INVALID_PARAMETER;
  52. }
  53. if (!pbApplicable)
  54. {
  55. return ERROR_INVALID_PARAMETER;
  56. }
  57. PTVerificationTest pTest = GlobalTestData.GetTest(m_dwSuite, i);
  58. if (pTest->pfnNeedRunTest && !(*(pTest->pfnNeedRunTest))())
  59. {
  60. *pbApplicable = FALSE;
  61. }
  62. else
  63. {
  64. *pbApplicable = TRUE;
  65. }
  66. return ERROR_SUCCESS;
  67. }
  68. STDMETHODIMP CTSDiagnosis::RunTest(int i)
  69. {
  70. USES_CONVERSION;
  71. if (i >= (int)GetTotalTestCount ())
  72. {
  73. return ERROR_INVALID_PARAMETER;
  74. }
  75. PTVerificationTest pTest = GlobalTestData.GetTest(m_dwSuite, i);
  76. if (pTest->pfnNeedRunTest && !(*(pTest->pfnNeedRunTest))())
  77. {
  78. return ERROR_INVALID_PARAMETER;
  79. }
  80. ASSERT (pTest->pfnTestFunc);
  81. char szOutput[512];
  82. ostrstream oTestResult(szOutput, 512);
  83. ZeroMemory(oTestResult.str(), 512);
  84. m_lTestResult = (*(pTest->pfnTestFunc))(oTestResult);
  85. //oTestResult << "\0";
  86. m_bstrTestResultString = oTestResult.str();
  87. return S_OK;
  88. }
  89. STDMETHODIMP CTSDiagnosis::get_TestResultString(BSTR *pVal)
  90. {
  91. if (!pVal)
  92. {
  93. return ERROR_INVALID_PARAMETER;
  94. }
  95. *pVal = m_bstrTestResultString.copy();
  96. return S_OK;
  97. }
  98. STDMETHODIMP CTSDiagnosis::get_TestResult(long *pVal)
  99. {
  100. if (!pVal)
  101. {
  102. return ERROR_INVALID_PARAMETER;
  103. }
  104. *pVal = m_lTestResult;
  105. return S_OK;
  106. }
  107. STDMETHODIMP CTSDiagnosis::put_TestType(VARIANT newVal)
  108. {
  109. switch(newVal.vt)
  110. {
  111. case VT_I4 :
  112. case VT_UI2:
  113. case VT_UINT:
  114. case VT_INT:
  115. {
  116. if (DWORD(newVal.iVal) >= GlobalTestData.GetSuiteCount())
  117. {
  118. return E_INVALIDARG;
  119. }
  120. else
  121. {
  122. m_dwSuite = newVal.iVal;
  123. }
  124. }
  125. break;
  126. case VT_BSTR :
  127. {
  128. if (!newVal.bstrVal)
  129. {
  130. return E_INVALIDARG;
  131. }
  132. else
  133. {
  134. _bstr_t bstrGroupName = newVal.bstrVal;
  135. for (DWORD i = 0; i < GlobalTestData.GetSuiteCount(); i++)
  136. {
  137. if (0 == _tcscmp(bstrGroupName, GlobalTestData.GetSuiteName(i)) )
  138. {
  139. m_dwSuite = i;
  140. }
  141. }
  142. if (i == GlobalTestData.GetSuiteCount())
  143. {
  144. return E_INVALIDARG;
  145. }
  146. }
  147. }
  148. break;
  149. default:
  150. return E_INVALIDARG;
  151. break;
  152. }
  153. return S_OK;
  154. }
  155. STDMETHODIMP CTSDiagnosis::get_TestDetails(int i, BSTR *pVal)
  156. {
  157. // TODO: Add your implementation code here
  158. if (i >= (int)GetTotalTestCount ())
  159. {
  160. return ERROR_INVALID_PARAMETER;
  161. }
  162. if (!pVal)
  163. {
  164. return ERROR_INVALID_PARAMETER;
  165. }
  166. bstr_t bstrTestDetails;
  167. PTVerificationTest pTest = GlobalTestData.GetTest(m_dwSuite, i);
  168. bstrTestDetails = pTest->TestDetails;
  169. *pVal = bstrTestDetails.copy();
  170. return ERROR_SUCCESS;
  171. }
  172. STDMETHODIMP CTSDiagnosis::ExecuteIt(BSTR strCommand)
  173. {
  174. ASSERT(strCommand);
  175. HINSTANCE hInst = ShellExecute(NULL, _T("open"), strCommand, NULL, NULL, SW_SHOW );
  176. if (32 > PtrToLong(hInst))
  177. {
  178. PROCESS_INFORMATION pinfo;
  179. STARTUPINFO sinfo;
  180. ZeroMemory(&sinfo, sizeof(sinfo));
  181. sinfo.cb = sizeof(sinfo);
  182. if (CreateProcess(
  183. NULL, // name of executable module
  184. strCommand, // command line string
  185. NULL, // SD
  186. NULL, // SD
  187. FALSE, // handle inheritance option
  188. CREATE_NEW_PROCESS_GROUP, // creation flags
  189. NULL, // new environment block
  190. NULL, // current directory name
  191. &sinfo, // startup information
  192. &pinfo // process information
  193. ))
  194. {
  195. // MessageBox(NULL, _T("Executed fine"), _T("TSDIAG"), MB_OK);
  196. }
  197. else
  198. {
  199. MessageBox(NULL, _T("Failed to Execute"), _T("TSDIAG"), MB_OK);
  200. }
  201. }
  202. return S_OK;
  203. }
  204. STDMETHODIMP CTSDiagnosis::put_RemoteMachineName(BSTR newVal)
  205. {
  206. if (!GlobalTestData.SetMachineName(newVal))
  207. return E_OUTOFMEMORY;
  208. return S_OK;
  209. }
  210. STDMETHODIMP CTSDiagnosis::get_SuiteApplicable (DWORD dwSuite, BOOL * pVal)
  211. {
  212. if (!pVal)
  213. {
  214. return ERROR_INVALID_PARAMETER;
  215. }
  216. if (dwSuite >= GlobalTestData.GetSuiteCount())
  217. {
  218. return ERROR_INVALID_PARAMETER;
  219. }
  220. *pVal = GlobalTestData.CanExecuteSuite(dwSuite);
  221. return S_OK;
  222. }
  223. STDMETHODIMP CTSDiagnosis::get_SuiteErrorText (DWORD dwSuite, BSTR * pVal)
  224. {
  225. if (!pVal)
  226. {
  227. return ERROR_INVALID_PARAMETER;
  228. }
  229. if (dwSuite >= GlobalTestData.GetSuiteCount())
  230. {
  231. return ERROR_INVALID_PARAMETER;
  232. }
  233. bstr_t bstrSuiteError;
  234. bstrSuiteError = GlobalTestData.GetSuiteErrorText(dwSuite);
  235. *pVal = bstrSuiteError.copy();
  236. return S_OK;
  237. }
  238. STDMETHODIMP CTSDiagnosis::ExecuteCommand (BSTR strCommand)
  239. {
  240. ASSERT(strCommand);
  241. HINSTANCE hInst = ShellExecute(NULL, _T("open"), strCommand, NULL, NULL, SW_SHOW );
  242. if (32 > PtrToLong(hInst))
  243. {
  244. PROCESS_INFORMATION pinfo;
  245. STARTUPINFO sinfo;
  246. ZeroMemory(&sinfo, sizeof(sinfo));
  247. sinfo.cb = sizeof(sinfo);
  248. if (CreateProcess(
  249. NULL, // name of executable module
  250. strCommand, // command line string
  251. NULL, // SD
  252. NULL, // SD
  253. FALSE, // handle inheritance option
  254. CREATE_NEW_PROCESS_GROUP, // creation flags
  255. NULL, // new environment block
  256. NULL, // current directory name
  257. &sinfo, // startup information
  258. &pinfo // process information
  259. ))
  260. {
  261. // MessageBox(NULL, _T("Executed fine"), _T("TSDIAG"), MB_OK);
  262. }
  263. else
  264. {
  265. MessageBox(NULL, _T("Failed to Execute"), _T("TSDIAG"), MB_OK);
  266. }
  267. }
  268. return S_OK;
  269. }
  270. STDMETHODIMP CTSDiagnosis::put_MachineName (BSTR newVal)
  271. {
  272. if (!GlobalTestData.SetMachineName(newVal))
  273. {
  274. return E_OUTOFMEMORY;
  275. }
  276. return S_OK;
  277. }
  278. STDMETHODIMP CTSDiagnosis::get_Suites (VARIANT * pVal)
  279. {
  280. if (!pVal)
  281. {
  282. return E_POINTER;
  283. }
  284. CComObject<CSuites> *pSuites;
  285. HRESULT hr = CComObject<CSuites>::CreateInstance(&pSuites);
  286. if (FAILED(hr))
  287. return hr;
  288. // if we need to initialize our Suites object, it should be done here.
  289. IDispatch* pDisp = NULL;
  290. hr = pSuites->QueryInterface(&pDisp);
  291. if (SUCCEEDED(hr))
  292. {
  293. pVal->vt = VT_DISPATCH;
  294. pVal->pdispVal = pDisp;
  295. // if we need to initialize our Suites object, it should be done here.
  296. }
  297. else
  298. {
  299. delete pSuites;
  300. }
  301. return hr;
  302. }