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.

128 lines
3.6 KiB

  1. /*
  2. **++
  3. **
  4. ** Copyright (c) 2002 Microsoft Corporation
  5. **
  6. **
  7. ** Module Name:
  8. **
  9. ** main.cpp
  10. **
  11. **
  12. ** Abstract:
  13. **
  14. ** Test program to to register a Writer with various properties
  15. **
  16. ** Author:
  17. **
  18. ** Reuven Lax [reuvenl] 04-June-2002
  19. **
  20. **
  21. ** Revision History:
  22. **
  23. **--
  24. */
  25. ///////////////////////////////////////////////////////////////////////////////
  26. // Includes
  27. #include "stdafx.h"
  28. #include "main.h"
  29. #include "swriter.h"
  30. #include "writerconfig.h"
  31. #include <string>
  32. #include <sstream>
  33. #include <utility>
  34. #include <memory>
  35. ///////////////////////////////////////////////////////////////////////////////
  36. // Declarations
  37. HANDLE g_quitEvent = NULL;
  38. using Utility::checkReturn;
  39. ///////////////////////////////////////////////////////////////////////////////
  40. extern "C" __cdecl wmain(int argc, wchar_t ** argv)
  41. try
  42. {
  43. if (argc != 2)
  44. throw Utility::TestWriterException(L"Invalid number of arguments\n Format: vswriter.exe <config-file>");
  45. HRESULT hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED );
  46. checkReturn(hr, L"CoInitializeEx");
  47. loadFile(argv[1]);
  48. hr = ::CoInitializeSecurity(
  49. NULL, // IN PSECURITY_DESCRIPTOR pSecDesc,
  50. -1, // IN LONG cAuthSvc,
  51. NULL, // IN SOLE_AUTHENTICATION_SERVICE *asAuthSvc,
  52. NULL, // IN void *pReserved1,
  53. RPC_C_AUTHN_LEVEL_PKT_PRIVACY, // IN DWORD dwAuthnLevel,
  54. RPC_C_IMP_LEVEL_IDENTIFY, // IN DWORD dwImpLevel,
  55. NULL, // IN void *pAuthList,
  56. EOAC_NONE,
  57. // IN DWORD dwCapabilities,
  58. NULL // IN void *pReserved3
  59. );
  60. checkReturn(hr, L"CoInitializeSecurity");
  61. g_quitEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
  62. if (g_quitEvent == NULL)
  63. throw Utility::TestWriterException(L"Internal Error: could not create event\n");
  64. // set a control handler that allows the writer to be shut down
  65. if (!::SetConsoleCtrlHandler(handler, TRUE))
  66. checkReturn(HRESULT_FROM_WIN32(::GetLastError()), L"SetConsoleCtrlHandler");
  67. // We want the writer to go out of scope before the return statement
  68. {
  69. TestWriter writer;
  70. hr = writer.Initialize();
  71. checkReturn(hr, L"TestWriter::Initialize");
  72. if(::WaitForSingleObject(g_quitEvent, INFINITE) != WAIT_OBJECT_0)
  73. throw Utility::TestWriterException(L"internal Error: did not successfully wait on event\n");
  74. }
  75. return 0;
  76. }
  77. catch(const std::exception& error)
  78. {
  79. Utility::printStatus(error.what(), Utility::low);
  80. exit(1);
  81. }
  82. catch(HRESULT error)
  83. {
  84. Utility::TestWriterException e(error);
  85. Utility::printStatus(e.what(), Utility::low);
  86. exit(1);
  87. }
  88. void loadFile(wchar_t* fileName)
  89. {
  90. CXMLDocument document;
  91. if (!document.LoadFromFile(fileName))
  92. Utility::parseError(document);
  93. CComBSTR xmlString = document.SaveAsXML();
  94. WriterConfiguration::instance()->loadFromXML((BSTR)xmlString);
  95. return;
  96. }
  97. BOOL WINAPI handler(DWORD dwCtrlType)
  98. {
  99. // only print to console if it's safe
  100. if ((dwCtrlType == CTRL_C_EVENT) ||
  101. (dwCtrlType == CTRL_BREAK_EVENT))
  102. Utility::printStatus(L"Terminating writer", Utility::low);
  103. // we want to quit independent of what the control event was
  104. ::SetEvent(g_quitEvent);
  105. return TRUE;
  106. }