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.

250 lines
3.7 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. return E_INVALIDARG;
  128. }
  129. // initialize test object;
  130. pTest->SetTest(ptheTest);
  131. IDispatch* pDisp = NULL;
  132. hr = pTest->QueryInterface(&pDisp);
  133. if (SUCCEEDED(hr))
  134. {
  135. pVal->vt = VT_DISPATCH;
  136. pVal->pdispVal = pDisp;
  137. // if we need to initialize our Suites object, it should be done here.
  138. }
  139. else
  140. {
  141. delete pTest;
  142. }
  143. return hr;
  144. }
  145. bool CSuite::GetTest(const VARIANT &Index, DWORD dwSuiteIndex, PTVerificationTest *ppTest)
  146. {
  147. ASSERT( IsValid() );
  148. ASSERT(ppTest);
  149. ASSERT(dwSuiteIndex < GlobalTestData.GetSuiteCount());
  150. *ppTest = NULL;
  151. switch(Index.vt)
  152. {
  153. case VT_I4 :
  154. case VT_UI2:
  155. case VT_UINT:
  156. case VT_INT:
  157. case VT_I2:
  158. {
  159. if ((Index.iVal >= 0) && (DWORD(Index.iVal) < GlobalTestData.GetTestCount(dwSuiteIndex)))
  160. {
  161. *ppTest = GlobalTestData.GetTest(dwSuiteIndex, Index.iVal);
  162. return true;
  163. }
  164. else
  165. {
  166. return false;
  167. }
  168. }
  169. break;
  170. case VT_BSTR :
  171. {
  172. if (!Index.bstrVal)
  173. {
  174. return false;
  175. }
  176. else
  177. {
  178. for (DWORD dw = 0; dw < GlobalTestData.GetTestCount(dwSuiteIndex); dw++)
  179. {
  180. USES_CONVERSION;
  181. CComBSTR bstr;
  182. VERIFY(bstr.LoadString(GlobalTestData.GetTest(dwSuiteIndex, dw)->uiName));
  183. if (_tcscmp(bstr, Index.bstrVal) == 0)
  184. {
  185. // ok we got the index
  186. *ppTest = GlobalTestData.GetTest(dwSuiteIndex, dw);
  187. return true;
  188. }
  189. }
  190. return false;
  191. }
  192. }
  193. break;
  194. default:
  195. return false;
  196. break;
  197. }
  198. }