ctkVTKMatrixWidgetEventTranslatorPlayerTest1.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. // VTK includes
  22. #include <vtkMatrix4x4.h>
  23. // CTK includes
  24. #include "ctkCallback.h"
  25. #include "ctkConfig.h"
  26. #include "ctkEventTranslatorPlayerWidget.h"
  27. // QtTesting includes
  28. #include "pqTestUtility.h"
  29. #include "ctkMatrixWidgetEventPlayer.h"
  30. #include "ctkMatrixWidgetEventTranslator.h"
  31. #include "ctkVTKMatrixWidget.h"
  32. // STD includes
  33. #include <cstdlib>
  34. #include <iostream>
  35. namespace
  36. {
  37. //-----------------------------------------------------------------------------
  38. void checkFinalWidgetState(void* data)
  39. {
  40. ctkVTKMatrixWidget* widget = reinterpret_cast<ctkVTKMatrixWidget*>(data);
  41. CTKCOMPARE(widget->value(1,0),2.00);
  42. CTKCOMPARE(widget->value(2,0),-0.14);
  43. CTKCOMPARE(widget->value(0,3),5.00);
  44. }
  45. }
  46. //-----------------------------------------------------------------------------
  47. int ctkVTKMatrixWidgetEventTranslatorPlayerTest1(int argc, char * argv [] )
  48. {
  49. QApplication app(argc, argv);
  50. QString xmlDirectory = CTK_SOURCE_DIR "/Libs/Visualization/VTK/Widgets/Testing/Cpp/";
  51. // ------------------------
  52. ctkEventTranslatorPlayerWidget etpWidget;
  53. pqTestUtility* testUtility = new pqTestUtility(&etpWidget);
  54. etpWidget.setTestUtility(testUtility);
  55. etpWidget.addWidgetEventTranslator(new ctkMatrixWidgetEventTranslator);
  56. etpWidget.addWidgetEventPlayer(new ctkMatrixWidgetEventPlayer);
  57. // Test case 1
  58. ctkVTKMatrixWidget* widget = new ctkVTKMatrixWidget(0);
  59. widget->setEditable(true);
  60. vtkMatrix4x4* matrix = vtkMatrix4x4::New();
  61. widget->setMatrix(matrix);
  62. matrix->Delete();
  63. etpWidget.addTestCase(widget,
  64. xmlDirectory + "ctkVTKMatrixWidgetEventTranslatorPlayerTest1.xml",
  65. &checkFinalWidgetState);
  66. // ------------------------
  67. if (!app.arguments().contains("-I"))
  68. {
  69. QTimer::singleShot(0, &etpWidget, SLOT(play()));
  70. }
  71. etpWidget.show();
  72. return app.exec();
  73. }