printing_test.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef PRINTING_PRINTING_TEST_H_
  5. #define PRINTING_PRINTING_TEST_H_
  6. #include <windows.h>
  7. #include <winspool.h>
  8. #include <string>
  9. // Disable the whole test case when executing on a computer that has no printer
  10. // installed.
  11. // Note: Parent should be testing::Test or InProcessBrowserTest.
  12. template <typename Parent>
  13. class PrintingTest : public Parent {
  14. public:
  15. static bool IsTestCaseDisabled() { return GetDefaultPrinter().empty(); }
  16. static std::wstring GetDefaultPrinter() {
  17. wchar_t printer_name[MAX_PATH];
  18. DWORD size = std::size(printer_name);
  19. BOOL result = ::GetDefaultPrinter(printer_name, &size);
  20. if (result == 0) {
  21. if (GetLastError() == ERROR_FILE_NOT_FOUND) {
  22. printf("There is no printer installed, printing can't be tested!\n");
  23. return std::wstring();
  24. }
  25. printf("INTERNAL PRINTER ERROR!\n");
  26. return std::wstring();
  27. }
  28. return printer_name;
  29. }
  30. };
  31. #endif // PRINTING_PRINTING_TEST_H_