ctkPathListWidgetWithButtonsTest.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0.txt
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =========================================================================*/
  15. // Qt includes
  16. #include <QApplication>
  17. #include <QWidget>
  18. #include <QHBoxLayout>
  19. #include <QTimer>
  20. #include <QToolButton>
  21. // CTK includes
  22. #include "ctkPathListWidget.h"
  23. #include "ctkPathListButtonsWidget.h"
  24. #include "ctkUtils.h"
  25. #include "ctkTest.h"
  26. // STD includes
  27. #include <cstdlib>
  28. #include <iostream>
  29. //-----------------------------------------------------------------------------
  30. class ctkPathListWidgetWithButtonsTester : public QObject
  31. {
  32. Q_OBJECT
  33. private slots:
  34. void testButtons();
  35. };
  36. // ----------------------------------------------------------------------------
  37. void ctkPathListWidgetWithButtonsTester::testButtons()
  38. {
  39. QWidget topLevel;
  40. topLevel.setLayout(new QHBoxLayout());
  41. ctkPathListWidget pathList(&topLevel);
  42. QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  43. sizePolicy.setHorizontalStretch(1);
  44. pathList.setSizePolicy(sizePolicy);
  45. ctkPathListButtonsWidget pathListButtons(&topLevel);
  46. pathListButtons.init(&pathList);
  47. pathListButtons.setOrientation(Qt::Vertical);
  48. topLevel.layout()->addWidget(&pathList);
  49. topLevel.layout()->addWidget(&pathListButtons);
  50. topLevel.show();
  51. #if (QT_VERSION >= 0x50000)
  52. QTest::qWaitForWindowActive(&topLevel);
  53. #else
  54. QTest::qWaitForWindowShown(&topLevel);
  55. #endif
  56. struct CloseModalDialog : public QRunnable
  57. {
  58. void run()
  59. {
  60. QTest::qWait(1000);
  61. QTimer::singleShot(0, QApplication::activeModalWidget(), SLOT(accept()));
  62. QTest::qWait(1000);
  63. }
  64. };
  65. QThreadPool::globalInstance()->start(new CloseModalDialog);
  66. QTest::mouseClick(pathListButtons.buttonAddDirectory(), Qt::LeftButton);
  67. QCOMPARE(pathList.count(), 1);
  68. QVERIFY(!pathListButtons.buttonRemove()->isEnabled());
  69. QVERIFY(!pathListButtons.buttonEdit()->isEnabled());
  70. pathList.selectAll();
  71. QVERIFY(pathListButtons.buttonRemove()->isEnabled());
  72. QVERIFY(pathListButtons.buttonEdit()->isEnabled());
  73. QTest::mouseClick(pathListButtons.buttonRemove(), Qt::LeftButton);
  74. QCOMPARE(pathList.count(), 0);
  75. }
  76. // ----------------------------------------------------------------------------
  77. CTK_TEST_MAIN(ctkPathListWidgetWithButtonsTest)
  78. #include "moc_ctkPathListWidgetWithButtonsTest.cpp"