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.

103 lines
5.6 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Useful classes, macros
  3. #define VSS_EVAL(X) X
  4. #define VSS_STRINGIZE_ARG(X) #X
  5. #define VSS_STRINGIZE(X) VSS_EVAL(VSS_STRINGIZE_ARG(X))
  6. #define VSS_MERGE(A, B) A##B
  7. #define VSS_MAKE_W(A) VSS_MERGE(L, A)
  8. #define VSS_WSTRINGIZE(X) VSS_MAKE_W(VSS_STRINGIZE(X))
  9. #define __WFILE__ VSS_MAKE_W(VSS_EVAL(__FILE__))
  10. #define VSS_ERROR_CASE(wszBuffer, dwBufferLen, X) \
  11. case X: ::StringCchCopyW(wszBuffer, dwBufferLen, VSS_MAKE_W(VSS_EVAL(#X)) ); break;
  12. #define WSTR_GUID_FMT L"{%.8x-%.4x-%.4x-%.2x%.2x-%.2x%.2x%.2x%.2x%.2x%.2x}"
  13. #define WSTR_DWORD_FMT L"%c%c%c%c%c%c%c%c.%c%c%c%c%c%c%c%c.%c%c%c%c%c%c%c%c.%c%c%c%c%c%c%c%c"
  14. #define GUID_PRINTF_ARG( X ) \
  15. (X).Data1, \
  16. (X).Data2, \
  17. (X).Data3, \
  18. (X).Data4[0], (X).Data4[1], (X).Data4[2], (X).Data4[3], \
  19. (X).Data4[4], (X).Data4[5], (X).Data4[6], (X).Data4[7]
  20. #define BIT_PRINTF_ARG( X, val ) (((X) & (1 << (val-1)))? L'1': L'0')
  21. #define DWORD_PRINTF_ARG( X ) \
  22. BIT_PRINTF_ARG(X,0x20), BIT_PRINTF_ARG(X,0x1f), BIT_PRINTF_ARG(X,0x1e), BIT_PRINTF_ARG(X,0x1d), \
  23. BIT_PRINTF_ARG(X,0x1c), BIT_PRINTF_ARG(X,0x1b), BIT_PRINTF_ARG(X,0x1A), BIT_PRINTF_ARG(X,0x19), \
  24. BIT_PRINTF_ARG(X,0x18), BIT_PRINTF_ARG(X,0x17), BIT_PRINTF_ARG(X,0x16), BIT_PRINTF_ARG(X,0x15), \
  25. BIT_PRINTF_ARG(X,0x14), BIT_PRINTF_ARG(X,0x13), BIT_PRINTF_ARG(X,0x12), BIT_PRINTF_ARG(X,0x11), \
  26. BIT_PRINTF_ARG(X,0x10), BIT_PRINTF_ARG(X,0x0f), BIT_PRINTF_ARG(X,0x0e), BIT_PRINTF_ARG(X,0x0d), \
  27. BIT_PRINTF_ARG(X,0x0c), BIT_PRINTF_ARG(X,0x0b), BIT_PRINTF_ARG(X,0x0A), BIT_PRINTF_ARG(X,0x09), \
  28. BIT_PRINTF_ARG(X,0x08), BIT_PRINTF_ARG(X,0x07), BIT_PRINTF_ARG(X,0x06), BIT_PRINTF_ARG(X,0x05), \
  29. BIT_PRINTF_ARG(X,0x04), BIT_PRINTF_ARG(X,0x03), BIT_PRINTF_ARG(X,0x02), BIT_PRINTF_ARG(X,0x01)
  30. #define CHECK_CONDITION( Cond, FinalCode ) \
  31. { \
  32. if (!(Cond)) { \
  33. ft.Msg(L"- ERROR: Condition %S not succeeded. \n", #Cond ); \
  34. do { FinalCode } while(0); \
  35. throw(E_UNEXPECTED); \
  36. } else \
  37. ft.Msg(L"- Condition %S succeeded\n", #Cond); \
  38. }
  39. #define CHECK_COM( Call, FinalCode ) \
  40. { \
  41. HRESULT hr = Call; \
  42. if (FAILED(hr)) { \
  43. ft.Msg(L"- ERROR: Call %S not succeeded. \n" \
  44. L"\t Error Code = 0x%08lx. Error description = %s\n", \
  45. #Call, hr, \
  46. CVssSecurityTest::GetStringFromFailureType(hr)); \
  47. do { FinalCode } while(0); \
  48. throw(hr); \
  49. } else \
  50. ft.Msg(L"- (OK) %S\n", #Call); \
  51. }
  52. #define CHECK_WIN32( Cond, FinalCode ) \
  53. { \
  54. if (!(Cond)) { \
  55. ft.Msg(L"- ERROR: Condition %S not succeeded. \n" \
  56. L"\t Error Code = 0x%08lx. Error description = %s\n", \
  57. #Cond, HRESULT_FROM_WIN32(GetLastError()), \
  58. CVssSecurityTest::GetStringFromFailureType(HRESULT_FROM_WIN32(GetLastError()))); \
  59. do { FinalCode } while(0); \
  60. throw(HRESULT_FROM_WIN32(GetLastError())); \
  61. } else \
  62. ft.Msg(L"- (OK) %S\n", #Cond); \
  63. }
  64. #define CHECK_WIN32_FUNC( LValue, Condition, Call, FinalCode ) \
  65. { \
  66. LValue = Call; \
  67. if (!(Condition)) { \
  68. ft.Msg(L"- ERROR: (%S) when %S \n" \
  69. L"\t Error Code = 0x%08lx. Error description = %s\n", \
  70. #Call, #Condition, HRESULT_FROM_WIN32(GetLastError()), \
  71. CVssSecurityTest::GetStringFromFailureType(HRESULT_FROM_WIN32(GetLastError()))); \
  72. do { FinalCode } while(0); \
  73. throw(HRESULT_FROM_WIN32(GetLastError())); \
  74. } else \
  75. ft.Msg(L"- (OK) %S\n", #Call); \
  76. }
  77. #define PRINT_ERROR_DELTA( dwError, dwLastError ) \
  78. if ( dwError == dwLastError ) {} else { \
  79. ft.Msg(L"- ERROR: %s = 0x%08lx [%s]. (Previous value 0x%08lx)\n", \
  80. #dwLastError, dwError, \
  81. CVssSecurityTest::GetStringFromFailureType(HRESULT_FROM_WIN32(GetLastError())), \
  82. dwLastError ); \
  83. dwLastError = dwError; \
  84. }