PageRenderTime 80ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/manual/qdesktopservices/tst_qdesktopservices.cpp

https://gitlab.com/f3822/qtbase
C++ | 118 lines | 68 code | 21 blank | 29 comment | 0 complexity | c4a36021ec78fbcf2be1152f0f6579c8 MD5 | raw file
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 Intel Corporation.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the test suite of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
  21. ** included in the packaging of this file. Please review the following
  22. ** information to ensure the GNU General Public License requirements will
  23. ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
  24. **
  25. ** $QT_END_LICENSE$
  26. **
  27. ****************************************************************************/
  28. #include <QString>
  29. #include <QTest>
  30. #include <QCoreApplication>
  31. #include <QDesktopServices>
  32. class tst_QDesktopServices : public QObject
  33. {
  34. Q_OBJECT
  35. private Q_SLOTS:
  36. void openUrl();
  37. void openUrl_data();
  38. };
  39. void tst_QDesktopServices::openUrl_data()
  40. {
  41. QTest::addColumn<QUrl>("data");
  42. QTest::addColumn<QString>("message");
  43. QUrl localFile = QUrl::fromLocalFile(QFINDTESTDATA("test.txt"));
  44. QTest::newRow("text-file")
  45. << localFile
  46. << "This should open test.txt in a text editor";
  47. localFile.setQuery("x=y");
  48. QTest::newRow("text-file-with-query")
  49. << localFile
  50. << "This should open test.txt in a text editor. Queries do not usually show up.";
  51. localFile.setQuery(QString());
  52. localFile.setFragment("top");
  53. QTest::newRow("text-file-with-fragment")
  54. << localFile
  55. << "This should open test.txt in a text editor. Fragments do not usually show up.";
  56. QTest::newRow("browser-plain")
  57. << QUrl("http://qt-project.org")
  58. << "This should open http://qt-project.org in the default web browser";
  59. QTest::newRow("search-url")
  60. << QUrl("http://google.com/search?q=Qt+Project")
  61. << "This should search \"Qt Project\" on Google";
  62. QTest::newRow("search-url-with-space")
  63. << QUrl("http://google.com/search?q=Qt Project")
  64. << "This should search \"Qt Project\" on Google";
  65. QTest::newRow("search-url-with-quotes")
  66. << QUrl("http://google.com/search?q=\"Qt+Project\"")
  67. << "This should search '\"Qt Project\"' on Google (including the quotes)";
  68. QTest::newRow("search-url-with-hashtag")
  69. << QUrl("http://google.com/search?q=%23qtproject")
  70. << "This should search \"#qtproject\" on Google. The # should appear in the Google search field";
  71. QTest::newRow("search-url-with-fragment")
  72. << QUrl("http://google.com/search?q=Qt+Project#top")
  73. << "This should search \"Qt Project\" on Google. There should be no # in the Google search field";
  74. // see QTBUG-32311
  75. QTest::newRow("search-url-with-slashes")
  76. << QUrl("http://google.com/search?q=/profile/5")
  77. << "This should search \"/profile/5\" on Google.";
  78. // see QTBUG-31945
  79. QTest::newRow("two-fragments")
  80. << QUrl("http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926-CH3-SW81")
  81. << "This should open \"Implementing a Container View Controller\" in the UIViewController docs";
  82. QTest::newRow("mail")
  83. << QUrl("mailto:development@qt-project.org")
  84. << "This should open an email composer with the destination set to development@qt-project.org";
  85. QTest::newRow("mail-subject")
  86. << QUrl("mailto:development@qt-project.org?subject=[Development]%20Test%20Mail")
  87. << "This should open an email composer and tries to set the subject";
  88. }
  89. void tst_QDesktopServices::openUrl()
  90. {
  91. QFETCH(QUrl, data);
  92. QFETCH(QString, message);
  93. qWarning("\n\nOpening \"%s\": %s", qPrintable(data.toString()), qPrintable(message));
  94. QVERIFY(QDesktopServices::openUrl(data));
  95. }
  96. QTEST_MAIN(tst_QDesktopServices)
  97. #include "tst_qdesktopservices.moc"