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.

139 lines
6.6 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c)2000 Microsoft Corporation, All Rights Reserved
  4. //
  5. /////////////////////////////////////////////////////////////////////////////////////////////
  6. #ifndef _BVT_UTIL_HEADER
  7. #define _BVT_UTIL_HEADER
  8. /////////////////////////////////////////////////////////////////////////////////////////////
  9. //*******************************************************************************************
  10. //
  11. // Class definitions & prototypes
  12. //
  13. //*******************************************************************************************
  14. /////////////////////////////////////////////////////////////////////////////////////////////
  15. HRESULT AllocateAndConvertAnsiToUnicode( char * pstr, WCHAR *& pszW);
  16. int ExecuteScript ( int nTest);
  17. void LogCLSID ( const char * csFile, const ULONG Line, WCHAR * wcsID, CLSID clsid);
  18. BOOL InitMasterList ( const WCHAR * wcsClassesAfterDelete,ItemList & MasterList);
  19. BOOL InitAndExpandMasterList ( const WCHAR * wcsClassesString, int nWhichTest, ItemList & MasterList);
  20. BOOL InitMasterListOfAddDeleteClasses ( const WCHAR * wcsClassesAddDelete,int nWhichTest,ItemList & MasterList);
  21. int CrackClassName ( const WCHAR * wcsString, CHString & sClass, BOOL fExpectedFailure, const char * csFile, const ULONG Line );
  22. int CrackAssociation ( const WCHAR * wcsString, CHString & sClass, CPropertyList & Properties, int & n, BOOL fExpectedFailure, const char * csFile, const ULONG Line );
  23. int CrackClass ( WCHAR * wcsInClassString, CHString & sClass, CHString & sParentClass, CHString & sInstance,
  24. CPropertyList & Properties, int & nResults, BOOL fExpectedFailure,const char * csFile, const ULONG Line );
  25. int CrackEvent ( WCHAR * wcsInEventString, EventInfo & Event, BOOL fExpectedFailure, const char * csFile, const ULONG Line );
  26. int CrackNamespace ( WCHAR * wcsInString, CHString & sNamespace, BOOL fExpectedFailure,const char * csFile, const ULONG Line );
  27. int CrackClassNameAndResults ( WCHAR * wcsInString, CHString & sClass, ItemList & nResults, BOOL fExpectedFailure, const char * csFile, const ULONG Line );
  28. int CrackMethod ( WCHAR * wcsInString, CHString & sClass, CHString & sInst, CHString & sMethod,CPropertyList & InProp, CPropertyList & OutProps,
  29. int & nResults, BOOL fExpectedFailure, const char * csFile, const ULONG Line );
  30. BOOL CompareType ( CVARIANT & Var1, CVARIANT & Var2, long lType );
  31. /////////////////////////////////////////////////////////////////////////////////////////////
  32. class CLogAndDisplayOnScreen
  33. {
  34. protected:
  35. WCHAR m_wcsFileName[MAX_PATH+2];
  36. BOOL m_fDisplay;
  37. CCriticalSection m_CritSec;
  38. BOOL WriteToFile(WCHAR * pwcsError, WCHAR * pwcsFileAndLine, const WCHAR *wcsString);
  39. public:
  40. CLogAndDisplayOnScreen();
  41. ~CLogAndDisplayOnScreen();
  42. BOOL LogError(const char * csFile , const ULONG Line , int nErrorType, const WCHAR *fmt, ...);
  43. virtual BOOL Log(WCHAR * pwcsError, WCHAR * pwcsFileAndLine, const WCHAR *wcsString) { return FALSE;}
  44. inline void SetDisplay(BOOL fDisplay) { CAutoBlock Block(&m_CritSec); m_fDisplay = fDisplay;}
  45. inline void SetFileName(WCHAR * wcsFile ) { CAutoBlock Block(&m_CritSec); wcsncpy( m_wcsFileName, wcsFile, MAX_PATH); }
  46. };
  47. /////////////////////////////////////////////////////////////////////////////////////////////
  48. class CIniFileAndGlobalOptions
  49. {
  50. private:
  51. WCHAR m_wcsFileName[MAX_PATH+2];
  52. CCriticalSection m_CritSec;
  53. CFlexArray m_SpecificTests;
  54. BOOL m_fSpecificTests;
  55. int m_nThreads;
  56. int m_nConnections;
  57. BOOL ReadIniFile( WCHAR * wcsSection, const WCHAR * wcsKey, WCHAR * wcsDefault, CHString & sBuffer);
  58. void DeleteList();
  59. public:
  60. CIniFileAndGlobalOptions();
  61. ~CIniFileAndGlobalOptions();
  62. BOOL GetSpecificOptionForAPITest(const WCHAR * wcsClass, CHString & sClass, int nTest);
  63. void WriteDefaultIniFile();
  64. inline void AddToSpecificTestList(int nTest) { int * p = new int; *p = nTest; m_SpecificTests.Add(p); }
  65. inline int SpecificTestSize() { return m_SpecificTests.Size(); }
  66. inline int GetSpecificTest(int n) { int * p = (int*) m_SpecificTests.GetAt(n); return *p;}
  67. inline void SpecificTests(BOOL f) { m_fSpecificTests = f;}
  68. inline BOOL RunSpecificTests() { return m_fSpecificTests;}
  69. inline void SetFileName(WCHAR * wcsFile ) { CAutoBlock Block(&m_CritSec); wcsncpy( m_wcsFileName, wcsFile, MAX_PATH); }
  70. inline void SetThreads(int nThreads) { m_nThreads = nThreads;}
  71. inline void SetConnections(int nConn) { m_nConnections = nConn;}
  72. inline int GetThreads() { return m_nThreads;}
  73. inline int GetConnections() { return m_nConnections;}
  74. };
  75. class CSinkEx : public IWbemObjectSinkEx
  76. {
  77. CFlexArray m_aObjects;
  78. LONG m_lRefCount;
  79. CRITICAL_SECTION m_cs;
  80. HANDLE m_hEvent;
  81. HRESULT m_hres;
  82. IWbemClassObject* m_pErrorObj;
  83. IID m_pInterfaceID;
  84. IUnknown *m_pInterface;
  85. public:
  86. STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID FAR* ppvObj);
  87. STDMETHOD_(ULONG, AddRef)(THIS);
  88. STDMETHOD_(ULONG, Release)(THIS);
  89. STDMETHOD(Indicate)(long lObjectCount, IWbemClassObject** pObjArray);
  90. STDMETHOD(SetStatus)(long lFlags, HRESULT hResult, BSTR strParam, IWbemClassObject* pObjPAram);
  91. STDMETHOD(Set)(long lFlags, REFIID riid, void *pComObject);
  92. // Private to implementation.
  93. // ==========================
  94. CSinkEx(LONG lStartingRefCount = 1);
  95. ~CSinkEx();
  96. UINT WaitForSignal(DWORD dwMSec) { return ::WbemWaitForSingleObject(m_hEvent, dwMSec); }
  97. CFlexArray* GetObjectArray() { return &m_aObjects; }
  98. int GetNumberOfObjectsReceived() { return m_aObjects.Size();}
  99. IUnknown *GetInterface() { return m_pInterface; }
  100. HRESULT GetStatusCode(IWbemClassObject** ppErrorObj = NULL)
  101. {
  102. if(ppErrorObj)
  103. {
  104. *ppErrorObj = m_pErrorObj;
  105. if(m_pErrorObj) m_pErrorObj->AddRef();
  106. }
  107. return m_hres;
  108. }
  109. void Lock() { EnterCriticalSection(&m_cs); }
  110. void Unlock() { LeaveCriticalSection(&m_cs); }
  111. };
  112. #endif