testConsoleBufChild.cxx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*============================================================================
  2. KWSys - Kitware System Library
  3. Copyright 2000-2016 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "kwsysPrivate.h"
  11. #include KWSYS_HEADER(ConsoleBuf.hxx)
  12. #include KWSYS_HEADER(Encoding.hxx)
  13. // Work-around CMake dependency scanning limitation. This must
  14. // duplicate the above list of headers.
  15. #if 0
  16. # include "ConsoleBuf.hxx.in"
  17. # include "Encoding.hxx.in"
  18. #endif
  19. #include <iostream>
  20. #include "testConsoleBuf.hxx"
  21. //----------------------------------------------------------------------------
  22. int main(int argc, const char* argv[])
  23. {
  24. #if defined(_WIN32)
  25. kwsys::ConsoleBuf::Manager out(std::cout);
  26. kwsys::ConsoleBuf::Manager err(std::cerr, true);
  27. kwsys::ConsoleBuf::Manager in(std::cin);
  28. if (argc > 1) {
  29. std::cout << argv[1] << std::endl;
  30. std::cerr << argv[1] << std::endl;
  31. } else {
  32. std::string str = kwsys::Encoding::ToNarrow(UnicodeTestString);
  33. std::cout << str << std::endl;
  34. std::cerr << str << std::endl;
  35. }
  36. std::string input;
  37. HANDLE syncEvent = OpenEventW(EVENT_MODIFY_STATE, FALSE, SyncEventName);
  38. if (syncEvent) {
  39. SetEvent(syncEvent);
  40. }
  41. std::cin >> input;
  42. std::cout << input << std::endl;
  43. if (syncEvent) {
  44. SetEvent(syncEvent);
  45. CloseHandle(syncEvent);
  46. }
  47. #else
  48. static_cast<void>(argc);
  49. static_cast<void>(argv);
  50. #endif
  51. return 0;
  52. }