ctkFontButtonEventTranslatorPlayerTest1.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 <QDebug>
  18. #include <QStandardItemModel>
  19. #include <QTimer>
  20. #include <QTreeView>
  21. // CTK includes
  22. #include "ctkCallback.h"
  23. #include "ctkConfig.h"
  24. #include "ctkFontButton.h"
  25. #include "ctkFontButtonEventPlayer.h"
  26. #include "ctkFontButtonEventTranslator.h"
  27. #include "ctkEventTranslatorPlayerWidget.h"
  28. // QtTesting includes
  29. #include "pqTestUtility.h"
  30. // STD includes
  31. #include <cstdlib>
  32. #include <iostream>
  33. namespace
  34. {
  35. //-----------------------------------------------------------------------------
  36. void checkFinalWidgetState(void* data)
  37. {
  38. ctkFontButton* widget = reinterpret_cast<ctkFontButton*>(data);
  39. CTKCOMPARE(widget->font().style(), QFont::StyleOblique);
  40. CTKCOMPARE(widget->font().pointSize(), 9);
  41. CTKCOMPARE(widget->font().underline(), true);
  42. CTKCOMPARE(widget->font().strikeOut(), false);
  43. CTKCOMPARE(widget->font().family(), QString("Lohit Bengali"));
  44. }
  45. //-----------------------------------------------------------------------------
  46. void checkFinalWidgetState2(void* data)
  47. {
  48. ctkFontButton* widget = reinterpret_cast<ctkFontButton*>(data);
  49. CTKCOMPARE(widget->font().style(), QFont::StyleItalic);
  50. CTKCOMPARE(widget->font().pointSize(), 36);
  51. CTKCOMPARE(widget->font().underline(), true);
  52. CTKCOMPARE(widget->font().strikeOut(), true);
  53. CTKCOMPARE(widget->font().family(), QString("Ubuntu"));
  54. }
  55. }
  56. //-----------------------------------------------------------------------------
  57. int ctkFontButtonEventTranslatorPlayerTest1(int argc, char * argv [] )
  58. {
  59. QApplication app(argc, argv);
  60. QString xmlDirectory = CTK_SOURCE_DIR "/Libs/Widgets/Testing/Cpp/";
  61. // ------------------------
  62. ctkEventTranslatorPlayerWidget etpWidget;
  63. pqTestUtility* testUtility = new pqTestUtility(&etpWidget);
  64. etpWidget.setTestUtility(testUtility);
  65. etpWidget.addWidgetEventPlayer(new ctkFontButtonEventPlayer);
  66. etpWidget.addWidgetEventTranslator(new ctkFontButtonEventTranslator);
  67. // Test case 1
  68. ctkFontButton* widget = new ctkFontButton();
  69. etpWidget.addTestCase(widget,
  70. xmlDirectory + "ctkFontButtonEventTranslatorPlayerTest1.xml",
  71. &checkFinalWidgetState);
  72. // Test case 2
  73. ctkFontButton* widget2 = new ctkFontButton();
  74. etpWidget.addTestCase(widget2,
  75. xmlDirectory + "ctkFontButtonEventTranslatorPlayerTest2.xml",
  76. &checkFinalWidgetState2);
  77. // ------------------------
  78. if (!app.arguments().contains("-I"))
  79. {
  80. QTimer::singleShot(0, &etpWidget, SLOT(play()));
  81. }
  82. etpWidget.show();
  83. return app.exec();
  84. }