ctkSettingsDialogEventTranslatorPlayerTest1.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 <QSettings>
  20. #include <QStandardItemModel>
  21. #include <QTimer>
  22. #include <QTreeView>
  23. // CTK includes
  24. #include "ctkCallback.h"
  25. #include "ctkConfig.h"
  26. #include "ctkSettingsDialog.h"
  27. #include "ctkSettingsPanel.h"
  28. #include "ctkEventTranslatorPlayerWidget.h"
  29. // QtTesting includes
  30. #include "pqTestUtility.h"
  31. // STD includes
  32. #include <cstdlib>
  33. #include <iostream>
  34. namespace
  35. {
  36. //-----------------------------------------------------------------------------
  37. void checkFinalWidgetState(void* data)
  38. {
  39. ctkSettingsDialog* widget = reinterpret_cast<ctkSettingsDialog*>(data);
  40. CTKCOMPARE(widget->currentPanel()->windowTitle(), "Panel 4");
  41. }
  42. }
  43. //-----------------------------------------------------------------------------
  44. int ctkSettingsDialogEventTranslatorPlayerTest1(int argc, char * argv [] )
  45. {
  46. QApplication app(argc, argv);
  47. QString xmlDirectory = CTK_SOURCE_DIR "/Libs/Widgets/Testing/Cpp/";
  48. // ------------------------
  49. ctkEventTranslatorPlayerWidget etpWidget;
  50. pqTestUtility* testUtility = new pqTestUtility(&etpWidget);
  51. etpWidget.setTestUtility(testUtility);
  52. // Test case 1
  53. QSettings settings(QSettings::IniFormat, QSettings::UserScope, "Common ToolKit", "CTK");
  54. settings.remove("key 1");
  55. ctkSettingsDialog* widget = new ctkSettingsDialog();
  56. ctkSettingsPanel* panel1 = new ctkSettingsPanel;
  57. widget->addPanel("Panel 1", panel1);
  58. widget->addPanel("Panel 2", new ctkSettingsPanel);
  59. widget->addPanel("Panel 3", new ctkSettingsPanel);
  60. ctkSettingsPanel* panel4 = new ctkSettingsPanel;
  61. widget->addPanel("Panel 4", panel4, panel1);
  62. widget->setCurrentPanel("Panel 4");
  63. QCheckBox* box = new QCheckBox(panel4);
  64. box->setChecked(true);
  65. QVariant boxVal = settings.value("key 1");
  66. boxVal = settings.value("key 1");
  67. panel4->registerProperty("key 1", box, "checked",
  68. SIGNAL(toggled(bool)));
  69. etpWidget.addTestCase(widget,
  70. xmlDirectory + "ctkSettingsDialogEventTranslatorPlayerTest1.xml",
  71. &checkFinalWidgetState);
  72. // ------------------------
  73. if (argc < 2 || QString(argv[1]) != "-I")
  74. {
  75. QTimer::singleShot(0, &etpWidget, SLOT(play()));
  76. }
  77. etpWidget.show();
  78. return app.exec();
  79. }