]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #1331: final automatic test for sorting points
authorasl <asl@opencascade.com>
Thu, 28 Sep 2017 08:49:12 +0000 (11:49 +0300)
committerasl <asl@opencascade.com>
Thu, 28 Sep 2017 08:49:12 +0000 (11:49 +0300)
src/HYDRO_tests/reference_data/CMakeLists.txt
src/HYDRO_tests/reference_data/profiles_selected_points.png [new file with mode: 0644]
src/HYDRO_tests/test_HYDROGUI_ProfilesDlg.cxx

index 41dd3c0e6ef2fdbc24632d96991385d2b47ee2be..17ac2ca8a94a0870c165c941c732419b40b1cf8c 100644 (file)
@@ -125,6 +125,7 @@ SET(REFERENCE_DATA
     gv_zoomed_1.png
     gv_zoomed_2.png
     profiles_dlg_presentation.png
+    profiles_selected_points.png
 )
 
 # Application tests
diff --git a/src/HYDRO_tests/reference_data/profiles_selected_points.png b/src/HYDRO_tests/reference_data/profiles_selected_points.png
new file mode 100644 (file)
index 0000000..f941721
Binary files /dev/null and b/src/HYDRO_tests/reference_data/profiles_selected_points.png differ
index 6a24a09c242cb7e8808a08ec9b3e463ab73ae6e9..65902854a25f2a7851dd4fc06a0e3a9931f8f6b2 100644 (file)
 
 #define private public
 #include <HYDROGUI_ProfileDlg.h>
+#include <CurveCreator_Widget.h>
 #undef private 
 
 #include <HYDROGUI_CurveCreatorProfile.h>
-#include <CurveCreator_Widget.h>
 #include <CurveCreator_TableView.h>
 #include <CurveCreator_Displayer.hxx>
 #include <CurveCreator_Utils.hxx>
@@ -67,12 +67,13 @@ void test_HYDROGUI_ProfilesDlg::test_default_size()
   qApp->processEvents();
 }
 
-void test_HYDROGUI_ProfilesDlg::test_points_table()
+HYDROGUI_CurveCreatorProfile* profile()
 {
-  HYDROGUI_ProfileDlg* dlg = new HYDROGUI_ProfileDlg( 0, "test" );
-  dlg->resize( 320, 800 );
-  HYDROGUI_CurveCreatorProfile* aProfile = new HYDROGUI_CurveCreatorProfile();
+  static HYDROGUI_CurveCreatorProfile* aProfile = 0;
+  if( aProfile )
+    return aProfile;
+
+  aProfile = new HYDROGUI_CurveCreatorProfile();
   CurveCreator::Coordinates coords;
   coords.push_back( 0 );
   coords.push_back( 20 );
@@ -83,16 +84,19 @@ void test_HYDROGUI_ProfilesDlg::test_points_table()
   coords.push_back( 90 );
   coords.push_back( 20 );
   aProfile->addPoints( coords, 0 );
+  return aProfile;
+}
 
-  dlg->setProfile( aProfile );
-  dlg->show();
-  QTest::qWaitForWindowExposed( dlg );
-
+void show_profile( HYDROGUI_ProfileDlg* dlg )
+{
   Handle(AIS_InteractiveContext) aCtx = dlg->getAISContext();
   CurveCreator_Displayer* aDisplayer = new CurveCreator_Displayer( aCtx );
-  aProfile->setDisplayer( aDisplayer );
-  aDisplayer->display( aProfile->getAISObject( true ), true );
-  
+  profile()->setDisplayer( aDisplayer );
+  aDisplayer->display( profile()->getAISObject( true ), true );
+}
+
+void select_points( HYDROGUI_ProfileDlg* dlg )
+{
   CurveCreator_ICurve::SectionToPointList sel;
   sel.push_back( CurveCreator_ICurve::SectionToPoint( 0, 0 ) );
   sel.push_back( CurveCreator_ICurve::SectionToPoint( 0, 1 ) );
@@ -102,6 +106,39 @@ void test_HYDROGUI_ProfilesDlg::test_points_table()
   dlg->myEditorWidget->onModificationMode( true );
   dlg->myEditorWidget->setSelectedPoints( sel );
   dlg->myEditorWidget->updateLocalPointView();
+}
+
+std::string coords( HYDROGUI_ProfileDlg* dlg, int col=2 )
+{
+  int n = dlg->myEditorWidget->myLocalPointView->rowCount();
+  QStringList datas;
+  for( int r=0; r<n; r++ )
+  {
+    QString data = dlg->myEditorWidget->myLocalPointView->item(r, col)->data( Qt::DisplayRole ).toString();
+    datas.append( data );
+  }
+  return datas.join( ", " ).toStdString();
+}
+
+void setCoords( HYDROGUI_ProfileDlg* dlg, int theIndex, double theValue )
+{
+  QAbstractItemModel* m = dlg->myEditorWidget->myLocalPointView->model();
+  QModelIndex index = m->index( theIndex, 2 );
+
+  m->setData( index, theValue, Qt::UserRole );
+  dlg->myEditorWidget->updateLocalPointView();
+}
+
+void test_HYDROGUI_ProfilesDlg::test_points_table()
+{
+  HYDROGUI_ProfileDlg* dlg = new HYDROGUI_ProfileDlg( 0, "test" );
+  dlg->resize( 320, 800 );
+  dlg->setProfile( profile() );
+  dlg->show();
+  QTest::qWaitForWindowExposed( dlg );
+
+  show_profile( dlg );  
+  select_points( dlg );
 
   QList<int> sizes;
   sizes.append( 25 );
@@ -110,13 +147,32 @@ void test_HYDROGUI_ProfilesDlg::test_points_table()
   sizes.append( 25 );
   sizes.append( 25 );
   dlg->splitter()->setSizes( sizes );
-
   qApp->processEvents();
 
-  QTest::qWait( 50000 );
+  CPPUNIT_ASSERT_WIDGET( dlg, "profiles_selected_points" );
+  CPPUNIT_ASSERT_EQUAL( std::string( "0, 30, 60, 90" ), coords( dlg ) );
+  CPPUNIT_ASSERT_EQUAL( std::string( "20, 0, 0, 20" ), coords( dlg, 3 ) );
+  
+  setCoords( dlg, 0, 130 );
+  CPPUNIT_ASSERT_EQUAL( std::string( "130, 30, 60, 90" ), coords( dlg ) );
+  CPPUNIT_ASSERT_EQUAL( std::string( "20, 0, 0, 20" ), coords( dlg, 3 ) );
+
+  setCoords( dlg, 0, 0 );
+  CPPUNIT_ASSERT_EQUAL( std::string( "0, 30, 60, 90" ), coords( dlg ) );
+  CPPUNIT_ASSERT_EQUAL( std::string( "20, 0, 0, 20" ), coords( dlg, 3 ) );
+
+  setCoords( dlg, 0, 80 );
+  dlg->myEditorWidget->myLocalPointView->sortByColumn( 2 );
+  CPPUNIT_ASSERT_EQUAL( std::string( "90, 80, 60, 30" ), coords( dlg ) );
+  CPPUNIT_ASSERT_EQUAL( std::string( "20, 20, 0, 0" ), coords( dlg, 3 ) );
+
+  setCoords( dlg, 1, 0 );
+  CPPUNIT_ASSERT_EQUAL( std::string( "90, 0, 60, 30" ), coords( dlg ) );
+  CPPUNIT_ASSERT_EQUAL( std::string( "20, 20, 0, 0" ), coords( dlg, 3 ) );
+
+  //qApp->processEvents();
+  //QTest::qWait( 50000 );
 
   dlg->deleteLater();
-  delete aProfile;
-  delete aDisplayer;
   qApp->processEvents();
 }