main.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright (C) 2010 Apple Inc. All rights reserved.
  3. * Copyright (C) 2010 University of Szeged.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  15. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  16. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  18. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  19. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  20. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  21. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  22. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  23. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  24. * THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include "config.h"
  27. #include "QtTestSupport.h"
  28. #include "TestController.h"
  29. #include "qquickwebview_p.h"
  30. #include <stdio.h>
  31. #if !defined(NDEBUG) && defined(Q_OS_UNIX)
  32. #include <signal.h>
  33. #include <unistd.h>
  34. #endif
  35. #include <QApplication>
  36. #include <QObject>
  37. #include <QTimer>
  38. class Launcher : public QObject {
  39. Q_OBJECT
  40. public:
  41. Launcher(int argc, char** argv)
  42. : m_argc(argc)
  43. , m_argv(argv)
  44. {
  45. }
  46. ~Launcher()
  47. {
  48. delete m_controller;
  49. }
  50. public Q_SLOTS:
  51. void launch()
  52. {
  53. m_controller = new WTR::TestController(m_argc, const_cast<const char**>(m_argv));
  54. QApplication::exit();
  55. }
  56. private:
  57. WTR::TestController* m_controller;
  58. int m_argc;
  59. char** m_argv;
  60. };
  61. #if !defined(NDEBUG) && defined(Q_OS_UNIX)
  62. static void sigcontHandler(int)
  63. {
  64. }
  65. #endif
  66. void messageHandler(QtMsgType type, const QMessageLogContext&, const QString& message)
  67. {
  68. if (type == QtCriticalMsg) {
  69. fprintf(stderr, "%s\n", qPrintable(message));
  70. return;
  71. }
  72. // Do nothing
  73. }
  74. int main(int argc, char** argv)
  75. {
  76. #if !defined(NDEBUG) && defined(Q_OS_UNIX)
  77. if (qgetenv("QT_WEBKIT_PAUSE_UI_PROCESS") == "1") {
  78. struct sigaction newAction, oldAction;
  79. newAction.sa_handler = sigcontHandler;
  80. sigemptyset(&newAction.sa_mask);
  81. newAction.sa_flags = 0;
  82. sigaction(SIGCONT, &newAction, &oldAction);
  83. fprintf(stderr, "Pausing UI process, please attach to PID %d and send signal SIGCONT... ", getpid());
  84. pause();
  85. sigaction(SIGCONT, &oldAction, 0);
  86. fprintf(stderr, " OK\n");
  87. }
  88. #endif
  89. // Suppress debug output from Qt if not started with --verbose
  90. bool suppressQtDebugOutput = true;
  91. for (int i = 1; i < argc; ++i) {
  92. if (!qstrcmp(argv[i], "--verbose")) {
  93. suppressQtDebugOutput = false;
  94. break;
  95. }
  96. }
  97. // Has to be done before QApplication is constructed in case
  98. // QApplication itself produces debug output.
  99. if (suppressQtDebugOutput) {
  100. qInstallMessageHandler(messageHandler);
  101. if (qgetenv("QT_WEBKIT_SUPPRESS_WEB_PROCESS_OUTPUT").isEmpty())
  102. qputenv("QT_WEBKIT_SUPPRESS_WEB_PROCESS_OUTPUT", "1");
  103. }
  104. qputenv("QT_WEBKIT_THEME_NAME", "qstyle");
  105. WebKit::QtTestSupport::initializeTestFonts();
  106. QCoreApplication::setAttribute(Qt::AA_Use96Dpi, true);
  107. QApplication app(argc, argv);
  108. Launcher launcher(argc, argv);
  109. QTimer::singleShot(0, &launcher, SLOT(launch()));
  110. return app.exec();;
  111. }
  112. #include "main.moc"