ctkFileDialogEventTranslatorPlayerTest1.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. // STD includes
  31. #include <cstdlib>
  32. #include <iostream>
  33. namespace
  34. {
  35. //-----------------------------------------------------------------------------
  36. void checkFinalWidgetState(void* data)
  37. {
  38. ctkFileDialog* widget = reinterpret_cast<ctkFileDialog*>(data);
  39. QStringList listActual = widget->selectedFiles();
  40. QStringList listExpected;
  41. listExpected << "/home/benjaminlong/Documents/ctk-QtTesting-renderView/ctkVTKRenderViewEventTranslatorPlayerTest1Screenshot.png";
  42. listExpected << "/home/benjaminlong/Documents/ctk-QtTesting-renderView/ctkVTKRenderViewEventTranslatorPlayerTest1ScreenshotTest.png";
  43. if( listActual.count() == listExpected.count())
  44. {
  45. for(int i = 0 ; i < listActual.count() ; i++)
  46. {
  47. CTKCOMPARE(listExpected[i], listActual[i]);
  48. }
  49. }
  50. else
  51. {
  52. QApplication::exit(EXIT_FAILURE);
  53. }
  54. }
  55. //-----------------------------------------------------------------------------
  56. void checkFinalWidgetState2(void* data)
  57. {
  58. ctkFileDialog* widget = reinterpret_cast<ctkFileDialog*>(data);
  59. QStringList actual = widget->selectedFiles();
  60. QString expected = "/home/benjaminlong/GroupBox.png";
  61. if( actual.count() == 1)
  62. {
  63. CTKCOMPARE(actual[0], expected);
  64. }
  65. else
  66. {
  67. QApplication::exit(EXIT_FAILURE);
  68. }
  69. }
  70. //-----------------------------------------------------------------------------
  71. void checkFinalWidgetState3(void* data)
  72. {
  73. ctkFileDialog* widget = reinterpret_cast<ctkFileDialog*>(data);
  74. CTKCOMPARE(widget->isHidden(), true);
  75. }
  76. }
  77. //-----------------------------------------------------------------------------
  78. int ctkFileDialogEventTranslatorPlayerTest1(int argc, char * argv [] )
  79. {
  80. QApplication app(argc, argv);
  81. QString xmlDirectory = CTK_SOURCE_DIR "/Libs/Widgets/Testing/Cpp/";
  82. // ------------------------
  83. ctkEventTranslatorPlayerWidget etpWidget;
  84. etpWidget.addWidgetEventPlayer(new ctkFileDialogEventPlayer(etpWidget.testUtility()));
  85. etpWidget.addWidgetEventTranslator(new ctkFileDialogEventTranslator(etpWidget.testUtility()));
  86. // Test case 1
  87. ctkFileDialog* fileDialog = new ctkFileDialog() << ctkSetName("fileDialog1");
  88. fileDialog->setFileMode(QFileDialog::ExistingFiles);
  89. fileDialog->setNameFilter("Images (*.png *.xpm *.jpg)");
  90. fileDialog->setViewMode(QFileDialog::Detail);
  91. QCheckBox* checkBox = new QCheckBox << ctkSetName("checkBox1");
  92. fileDialog->setBottomWidget(checkBox, "Foo Bar:");
  93. QObject::connect(checkBox, SIGNAL(toggled(bool)),
  94. fileDialog, SLOT(setAcceptButtonEnable(bool)));
  95. fileDialog->setAcceptButtonEnable(false);
  96. etpWidget.addTestCase(fileDialog,
  97. xmlDirectory + "ctkFileDialogEventTranslatorPlayerTest1.xml",
  98. &checkFinalWidgetState);
  99. // Test case 2
  100. ctkFileDialog* fileDialog2 = new ctkFileDialog() << ctkSetName("fileDialog2");
  101. fileDialog2->setFileMode(QFileDialog::AnyFile);
  102. fileDialog2->setViewMode(QFileDialog::Detail);
  103. QCheckBox* checkBox2 = new QCheckBox << ctkSetName("checkBox2");
  104. fileDialog2->setBottomWidget(checkBox2, "Foo Bar:");
  105. QObject::connect(checkBox2, SIGNAL(toggled(bool)),
  106. fileDialog2, SLOT(setAcceptButtonEnable(bool)));
  107. fileDialog2->setAcceptButtonEnable(false);
  108. etpWidget.addTestCase(fileDialog2,
  109. xmlDirectory + "ctkFileDialogEventTranslatorPlayerTest2.xml",
  110. &checkFinalWidgetState2);
  111. // Test case 2
  112. ctkFileDialog* fileDialog3 = new ctkFileDialog() << ctkSetName("fileDialog3");
  113. fileDialog3->setFileMode(QFileDialog::AnyFile);
  114. fileDialog3->setViewMode(QFileDialog::Detail);
  115. QCheckBox* checkBox3 = new QCheckBox << ctkSetName("checkBox3");
  116. fileDialog3->setBottomWidget(checkBox3, "Foo Bar:");
  117. QObject::connect(checkBox3, SIGNAL(toggled(bool)),
  118. fileDialog3, SLOT(setAcceptButtonEnable(bool)));
  119. fileDialog3->setAcceptButtonEnable(false);
  120. etpWidget.addTestCase(fileDialog3,
  121. xmlDirectory + "ctkFileDialogEventTranslatorPlayerTest3.xml",
  122. &checkFinalWidgetState3);
  123. // ------------------------
  124. if (!app.arguments().contains("-I"))
  125. {
  126. QTimer::singleShot(0, &etpWidget, SLOT(play()));
  127. }
  128. etpWidget.show();
  129. return app.exec();
  130. }