Просмотр исходного кода

ENH: Make ctkSettingsTest1 more robust

ctkSettingsTest1 tests setting and restoring the main window position. If the
system running the tests had a decoration--such as dock/menu bar/task bar--in
the hard-coded position of the window, then the test would fail. This happened
because the logic that restores the window position ensures that the window
position avoids those decorations.

Update ctkSettingsTest1 to account for the available desktop geometry when
positioning the test window.
Max Smolens лет назад: 7
Родитель
Сommit
a6382042a6
1 измененных файлов с 9 добавлено и 4 удалено
  1. 9 4
      Libs/Widgets/Testing/Cpp/ctkSettingsTest1.cpp

+ 9 - 4
Libs/Widgets/Testing/Cpp/ctkSettingsTest1.cpp

@@ -20,6 +20,7 @@
 
 // Qt includes
 #include <QApplication>
+#include <QDesktopWidget>
 #include <QDialog>
 #include <QMainWindow>
 #include <QTimer>
@@ -49,23 +50,27 @@ int ctkSettingsTest1(int argc, char * argv [] )
   QMainWindow mainWindow(0);
   mainWindow.show();
   
-  mainWindow.move(123, 123);
+  QDesktopWidget desktop;
+  QRect desktopRect = desktop.availableGeometry(&mainWindow);
+  const QPoint origin = desktopRect.topLeft();
+
+  mainWindow.move(origin);
   mainWindow.resize(640, 470);
   
   settings.saveState(mainWindow,"");
-  mainWindow.move(100, 100);
+  mainWindow.move(origin + QPoint(30, 20));
   mainWindow.resize(300, 200);
   settings.saveState(mainWindow, "key");
   
   settings.restoreState("", mainWindow);
-  if (mainWindow.pos() != QPoint(123,123) ||
+  if (mainWindow.pos() != origin ||
       mainWindow.size() != QSize(640, 470))
     {
     std::cerr << "ctkSettings::restoreState failed" << std::endl;
     return EXIT_FAILURE;
     }
   settings.restoreState("key", mainWindow);
-  if (mainWindow.pos() != QPoint(100,100) ||
+  if (mainWindow.pos() != (origin + QPoint(30, 20)) ||
       mainWindow.size() != QSize(300, 200))
     {
     std::cerr << "ctkSettings::restoreState failed" << std::endl;