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.

142 lines
2.3 KiB

  1. // Suites.cpp: implementation of the CSuites class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "TSDiag.h"
  6. #include "Suites.h"
  7. #include "suite.h"
  8. #include "testdata.h"
  9. //////////////////////////////////////////////////////////////////////
  10. // Construction/Destruction
  11. //////////////////////////////////////////////////////////////////////
  12. CSuites::CSuites()
  13. {
  14. }
  15. CSuites::~CSuites()
  16. {
  17. }
  18. STDMETHODIMP CSuites::get_Count(long *pVal)
  19. {
  20. if (!pVal)
  21. return E_POINTER;
  22. *pVal = GlobalTestData.GetSuiteCount();
  23. return S_OK;
  24. }
  25. STDMETHODIMP CSuites::get__NewEnum(LPUNKNOWN *pVal)
  26. {
  27. if (!pVal)
  28. return E_POINTER;
  29. return E_NOTIMPL;
  30. }
  31. STDMETHODIMP CSuites::get_Item(VARIANT Index, VARIANT *pVal)
  32. {
  33. if (!pVal)
  34. {
  35. return E_POINTER;
  36. }
  37. // BUGBUG find right index value.
  38. DWORD dwIndex;
  39. if (!SuiteIndexFromVarient(Index, &dwIndex ))
  40. {
  41. return E_INVALIDARG;
  42. }
  43. ASSERT(dwIndex < GlobalTestData.GetSuiteCount());
  44. CComObject<CSuite> *pSuite;
  45. HRESULT hr = CComObject<CSuite>::CreateInstance(&pSuite);
  46. if (FAILED(hr))
  47. return hr;
  48. // if we need to initialize our Suite object, it should be done here.
  49. pSuite->SetSuiteIndex(dwIndex);
  50. IDispatch* pDisp = NULL;
  51. hr = pSuite->QueryInterface(&pDisp);
  52. if (SUCCEEDED(hr))
  53. {
  54. VariantInit(pVal);
  55. pVal->vt = VT_DISPATCH;
  56. pVal->pdispVal = pDisp;
  57. }
  58. else
  59. {
  60. delete pSuite;
  61. }
  62. return hr;
  63. }
  64. bool CSuites::SuiteIndexFromVarient(const VARIANT &Index, DWORD *pdwIndex)
  65. {
  66. ASSERT(pdwIndex);
  67. *pdwIndex = 0xffffffff;
  68. switch(Index.vt)
  69. {
  70. case VT_I4:
  71. case VT_UI2:
  72. case VT_UINT:
  73. case VT_INT:
  74. case VT_I2:
  75. {
  76. if ((Index.iVal >= 0) && (DWORD(Index.iVal) < GlobalTestData.GetSuiteCount()))
  77. {
  78. *pdwIndex = Index.iVal;
  79. return true;
  80. }
  81. else
  82. {
  83. return false;
  84. }
  85. }
  86. break;
  87. case VT_BSTR :
  88. {
  89. if (!Index.bstrVal)
  90. {
  91. return false;
  92. }
  93. else
  94. {
  95. for (DWORD dw = 0; dw < GlobalTestData.GetSuiteCount(); dw++)
  96. {
  97. if (_tcscmp(GlobalTestData.GetSuiteName(dw), Index.bstrVal) == 0)
  98. {
  99. // ok we got the index
  100. *pdwIndex = dw;
  101. return true;
  102. }
  103. }
  104. return false;
  105. }
  106. }
  107. break;
  108. default:
  109. return false;
  110. break;
  111. }
  112. }