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.

251 lines
4.0 KiB

  1. // Suite.cpp: implementation of the CSuite class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "TSDiag.h"
  6. #include "Suite.h"
  7. #include "testdata.h"
  8. #include "test.h"
  9. //////////////////////////////////////////////////////////////////////
  10. // Construction/Destruction
  11. //////////////////////////////////////////////////////////////////////
  12. CSuite::CSuite()
  13. {
  14. SetInvalidSuiteIndex();
  15. }
  16. CSuite::~CSuite()
  17. {
  18. }
  19. void CSuite::SetSuiteIndex (DWORD dwSuite)
  20. {
  21. ASSERT(GlobalTestData.GetSuiteCount() > dwSuite);
  22. m_dwSuiteIndex = dwSuite;
  23. }
  24. STDMETHODIMP CSuite::get_Name(BSTR *pVal)
  25. {
  26. if (!pVal)
  27. {
  28. return E_POINTER;
  29. }
  30. if (!IsValid())
  31. {
  32. return CO_E_NOTCONSTRUCTED;
  33. }
  34. bstr_t bstr = GlobalTestData.GetSuiteName(m_dwSuiteIndex);
  35. *pVal = bstr.copy();
  36. return S_OK;
  37. }
  38. STDMETHODIMP CSuite::get_Description(BSTR *pVal)
  39. {
  40. if (!pVal)
  41. {
  42. return E_POINTER;
  43. }
  44. if (!IsValid())
  45. {
  46. return CO_E_NOTCONSTRUCTED;
  47. }
  48. bstr_t bstr = GlobalTestData.GetSuiteName(m_dwSuiteIndex);
  49. *pVal = bstr.copy();
  50. return E_NOTIMPL;
  51. }
  52. STDMETHODIMP CSuite::get_IsApplicable(BOOL *pVal)
  53. {
  54. if (!pVal)
  55. {
  56. return E_POINTER;
  57. }
  58. if (!IsValid())
  59. {
  60. return CO_E_NOTCONSTRUCTED;
  61. }
  62. *pVal = GlobalTestData.CanExecuteSuite(m_dwSuiteIndex);
  63. return S_OK;
  64. }
  65. STDMETHODIMP CSuite::get_WhyNotApplicable(BSTR *pVal)
  66. {
  67. if (!pVal)
  68. {
  69. return E_POINTER;
  70. }
  71. if (!IsValid())
  72. {
  73. return CO_E_NOTCONSTRUCTED;
  74. }
  75. if (GlobalTestData.CanExecuteSuite(m_dwSuiteIndex))
  76. {
  77. return CO_E_NOTCONSTRUCTED;
  78. }
  79. bstr_t bstr = GlobalTestData.GetSuiteErrorText(m_dwSuiteIndex);
  80. *pVal = bstr.copy();
  81. return S_OK;
  82. }
  83. STDMETHODIMP CSuite::get_Count(long *pVal)
  84. {
  85. if (!pVal)
  86. {
  87. return E_POINTER;
  88. }
  89. if (!IsValid())
  90. {
  91. return CO_E_NOTCONSTRUCTED;
  92. }
  93. *pVal = GlobalTestData.GetTestCount(m_dwSuiteIndex);
  94. return S_OK;
  95. }
  96. STDMETHODIMP CSuite::get__NewEnum(LPUNKNOWN *pVal)
  97. {
  98. if (!pVal)
  99. {
  100. return E_POINTER;
  101. }
  102. if (!IsValid())
  103. {
  104. return CO_E_NOTCONSTRUCTED;
  105. }
  106. return E_NOTIMPL;
  107. }
  108. STDMETHODIMP CSuite::get_Item(VARIANT Index, VARIANT *pVal)
  109. {
  110. if (!pVal)
  111. {
  112. return E_POINTER;
  113. }
  114. if (!IsValid())
  115. {
  116. return CO_E_NOTCONSTRUCTED;
  117. }
  118. CComObject<CTest> *pTest;
  119. HRESULT hr = CComObject<CTest>::CreateInstance(&pTest);
  120. if (FAILED(hr))
  121. {
  122. return hr;
  123. }
  124. PTVerificationTest ptheTest;
  125. if (!GetTest(Index, m_dwSuiteIndex, &ptheTest))
  126. {
  127. delete pTest;
  128. return E_INVALIDARG;
  129. }
  130. // initialize test object;
  131. pTest->SetTest(ptheTest);
  132. IDispatch* pDisp = NULL;
  133. hr = pTest->QueryInterface(&pDisp);
  134. if (SUCCEEDED(hr))
  135. {
  136. pVal->vt = VT_DISPATCH;
  137. pVal->pdispVal = pDisp;
  138. // if we need to initialize our Suites object, it should be done here.
  139. }
  140. else
  141. {
  142. delete pTest;
  143. }
  144. return hr;
  145. }
  146. bool CSuite::GetTest(const VARIANT &Index, DWORD dwSuiteIndex, PTVerificationTest *ppTest)
  147. {
  148. ASSERT( IsValid() );
  149. ASSERT(ppTest);
  150. ASSERT(dwSuiteIndex < GlobalTestData.GetSuiteCount());
  151. *ppTest = NULL;
  152. switch(Index.vt)
  153. {
  154. case VT_I4 :
  155. case VT_UI2:
  156. case VT_UINT:
  157. case VT_INT:
  158. case VT_I2:
  159. {
  160. if ((Index.iVal >= 0) && (DWORD(Index.iVal) < GlobalTestData.GetTestCount(dwSuiteIndex)))
  161. {
  162. *ppTest = GlobalTestData.GetTest(dwSuiteIndex, Index.iVal);
  163. return true;
  164. }
  165. else
  166. {
  167. return false;
  168. }
  169. }
  170. break;
  171. case VT_BSTR :
  172. {
  173. if (!Index.bstrVal)
  174. {
  175. return false;
  176. }
  177. else
  178. {
  179. for (DWORD dw = 0; dw < GlobalTestData.GetTestCount(dwSuiteIndex); dw++)
  180. {
  181. USES_CONVERSION;
  182. CComBSTR bstr;
  183. VERIFY(bstr.LoadString(GlobalTestData.GetTest(dwSuiteIndex, dw)->uiName));
  184. if (_tcscmp(bstr, Index.bstrVal) == 0)
  185. {
  186. // ok we got the index
  187. *ppTest = GlobalTestData.GetTest(dwSuiteIndex, dw);
  188. return true;
  189. }
  190. }
  191. return false;
  192. }
  193. }
  194. break;
  195. default:
  196. return false;
  197. break;
  198. }
  199. }