ctkFileDialogEventTranslatorPlayerTest1.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QAction>
  16. #include <QApplication>
  17. #include <QCheckBox>
  18. #include <QDebug>
  19. #include <QStandardItemModel>
  20. #include <QTimer>
  21. #include <QTreeView>
  22. // CTK includes
  23. #include "ctkCallback.h"
  24. #include "ctkConfig.h"
  25. #include "ctkEventTranslatorPlayerWidget.h"
  26. #include "ctkFileDialog.h"
  27. #include "ctkFileDialogEventPlayer.h"
  28. #include "ctkFileDialogEventTranslator.h"
  29. #include "ctkSetName.h"
  30. // QtTesting includes
  31. #include "pqTestUtility.h"
  32. // STD includes
  33. #include <cstdlib>
  34. #include <iostream>
  35. namespace
  36. {
  37. //-----------------------------------------------------------------------------
  38. void checkFinalWidgetState(void* data)
  39. {
  40. ctkFileDialog* widget = reinterpret_cast<ctkFileDialog*>(data);
  41. QStringList listActual = widget->selectedFiles();
  42. QStringList listExpected;
  43. listExpected << "/home/benjaminlong/Documents/ctk-QtTesting-renderView/ctkVTKRenderViewEventTranslatorPlayerTest1Screenshot.png";
  44. listExpected << "/home/benjaminlong/Documents/ctk-QtTesting-renderView/ctkVTKRenderViewEventTranslatorPlayerTest1ScreenshotTest.png";
  45. if( listActual.count() == listExpected.count())
  46. {
  47. for(int i = 0 ; i < listActual.count() ; i++)
  48. {
  49. CTKCOMPARE(listExpected[i], listActual[i]);
  50. }
  51. }
  52. else
  53. {
  54. QApplication::exit(EXIT_FAILURE);
  55. }
  56. }
  57. //-----------------------------------------------------------------------------
  58. void checkFinalWidgetState2(void* data)
  59. {
  60. ctkFileDialog* widget = reinterpret_cast<ctkFileDialog*>(data);
  61. QStringList actual = widget->selectedFiles();
  62. QString expected = "/home/benjaminlong/GroupBox.png";
  63. if( actual.count() == 1)
  64. {
  65. CTKCOMPARE(actual[0], expected);
  66. }
  67. else
  68. {
  69. QApplication::exit(EXIT_FAILURE);
  70. }
  71. }
  72. //-----------------------------------------------------------------------------
  73. void checkFinalWidgetState3(void* data)
  74. {
  75. ctkFileDialog* widget = reinterpret_cast<ctkFileDialog*>(data);
  76. CTKCOMPARE(widget->isHidden(), true);
  77. }
  78. }
  79. //-----------------------------------------------------------------------------
  80. int ctkFileDialogEventTranslatorPlayerTest1(int argc, char * argv [] )
  81. {
  82. QApplication app(argc, argv);
  83. QString xmlDirectory = CTK_SOURCE_DIR "/Libs/Widgets/Testing/Cpp/";
  84. // ------------------------
  85. ctkEventTranslatorPlayerWidget etpWidget;
  86. pqTestUtility* testUtility = new pqTestUtility(&etpWidget);
  87. etpWidget.setTestUtility(testUtility);
  88. etpWidget.addWidgetEventPlayer(new ctkFileDialogEventPlayer(etpWidget.testUtility()));
  89. etpWidget.addWidgetEventTranslator(new ctkFileDialogEventTranslator(etpWidget.testUtility()));
  90. // Test case 1
  91. ctkFileDialog* fileDialog = new ctkFileDialog() << ctkSetName("fileDialog1");
  92. fileDialog->setFileMode(QFileDialog::ExistingFiles);
  93. fileDialog->setNameFilter("Images (*.png *.xpm *.jpg)");
  94. fileDialog->setViewMode(QFileDialog::Detail);
  95. QCheckBox* checkBox = new QCheckBox << ctkSetName("checkBox1");
  96. fileDialog->setBottomWidget(checkBox, "Foo Bar:");
  97. QObject::connect(checkBox, SIGNAL(toggled(bool)),
  98. fileDialog, SLOT(setAcceptButtonEnable(bool)));
  99. fileDialog->setAcceptButtonEnable(false);
  100. etpWidget.addTestCase(fileDialog,
  101. xmlDirectory + "ctkFileDialogEventTranslatorPlayerTest1.xml",
  102. &checkFinalWidgetState);
  103. // Test case 2
  104. ctkFileDialog* fileDialog2 = new ctkFileDialog() << ctkSetName("fileDialog2");
  105. fileDialog2->setFileMode(QFileDialog::AnyFile);
  106. fileDialog2->setViewMode(QFileDialog::Detail);
  107. QCheckBox* checkBox2 = new QCheckBox << ctkSetName("checkBox2");
  108. fileDialog2->setBottomWidget(checkBox2, "Foo Bar:");
  109. QObject::connect(checkBox2, SIGNAL(toggled(bool)),
  110. fileDialog2, SLOT(setAcceptButtonEnable(bool)));
  111. fileDialog2->setAcceptButtonEnable(false);
  112. etpWidget.addTestCase(fileDialog2,
  113. xmlDirectory + "ctkFileDialogEventTranslatorPlayerTest2.xml",
  114. &checkFinalWidgetState2);
  115. // Test case 2
  116. ctkFileDialog* fileDialog3 = new ctkFileDialog() << ctkSetName("fileDialog3");
  117. fileDialog3->setFileMode(QFileDialog::AnyFile);
  118. fileDialog3->setViewMode(QFileDialog::Detail);
  119. QCheckBox* checkBox3 = new QCheckBox << ctkSetName("checkBox3");
  120. fileDialog3->setBottomWidget(checkBox3, "Foo Bar:");
  121. QObject::connect(checkBox3, SIGNAL(toggled(bool)),
  122. fileDialog3, SLOT(setAcceptButtonEnable(bool)));
  123. fileDialog3->setAcceptButtonEnable(false);
  124. etpWidget.addTestCase(fileDialog3,
  125. xmlDirectory + "ctkFileDialogEventTranslatorPlayerTest3.xml",
  126. &checkFinalWidgetState3);
  127. // ------------------------
  128. if (!app.arguments().contains("-I"))
  129. {
  130. QTimer::singleShot(0, &etpWidget, SLOT(play()));
  131. }
  132. etpWidget.show();
  133. return app.exec();
  134. }