]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDRO_tests/test_HYDROGUI_ProfilesDlg.cxx
Salome HOME
refs #1331: automatic test for profiles points in GUI
[modules/hydro.git] / src / HYDRO_tests / test_HYDROGUI_ProfilesDlg.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #undef HYDROGUI_EXPORTS
20
21 #include <test_HYDROGUI_ProfilesDlg.h>
22
23 #define private public
24 #include <HYDROGUI_ProfileDlg.h>
25 #undef private 
26
27 #include <HYDROGUI_CurveCreatorProfile.h>
28 #include <CurveCreator_Widget.h>
29 #include <CurveCreator_TableView.h>
30 #include <CurveCreator_Displayer.hxx>
31 #include <CurveCreator_Utils.hxx>
32
33 #include <HYDROData_Document.h>
34 #include <HYDROData_Profile.h>
35
36
37 #include <TestViewer.h>
38 #include <QApplication>
39 #include <QAction>
40 #include <QSplitter>
41 #include <QTest>
42
43 #define CPPUNIT_ASSERT_WIDGET( theWidget, theCase )                           \
44   {                                                                           \
45     QPixmap aPixmap = QPixmap::grabWindow( theWidget->winId() );              \
46     QImage anImage = aPixmap.toImage();                                       \
47     QString aMessage;                                                         \
48     if( !TestViewer::AssertImages( aMessage, &anImage, theCase, false ) )     \
49     {                                                                         \
50       TestViewer::showColorScale( false );                                    \
51       std::string aMessageStl = aMessage.toStdString();                       \
52       CPPUNIT_FAIL( aMessageStl.c_str() );                                    \
53     }                                                                         \
54   }                                                                           \
55
56
57 void test_HYDROGUI_ProfilesDlg::test_default_size()
58 {
59   HYDROGUI_ProfileDlg* dlg = new HYDROGUI_ProfileDlg( 0, "test" );
60   dlg->resize( 320, 640 );
61   dlg->show();
62   QTest::qWaitForWindowExposed( dlg );
63
64   CPPUNIT_ASSERT_WIDGET( dlg, "profiles_dlg_presentation" );
65
66   dlg->deleteLater();
67   qApp->processEvents();
68 }
69
70 void test_HYDROGUI_ProfilesDlg::test_points_table()
71 {
72   HYDROGUI_ProfileDlg* dlg = new HYDROGUI_ProfileDlg( 0, "test" );
73   dlg->resize( 320, 800 );
74  
75   HYDROGUI_CurveCreatorProfile* aProfile = new HYDROGUI_CurveCreatorProfile();
76   CurveCreator::Coordinates coords;
77   coords.push_back( 0 );
78   coords.push_back( 20 );
79   coords.push_back( 30 );
80   coords.push_back( 0 );
81   coords.push_back( 60 );
82   coords.push_back( 0 );
83   coords.push_back( 90 );
84   coords.push_back( 20 );
85   aProfile->addPoints( coords, 0 );
86
87   dlg->setProfile( aProfile );
88   dlg->show();
89   QTest::qWaitForWindowExposed( dlg );
90
91   Handle(AIS_InteractiveContext) aCtx = dlg->getAISContext();
92   CurveCreator_Displayer* aDisplayer = new CurveCreator_Displayer( aCtx );
93   aProfile->setDisplayer( aDisplayer );
94   aDisplayer->display( aProfile->getAISObject( true ), true );
95   
96   CurveCreator_ICurve::SectionToPointList sel;
97   sel.push_back( CurveCreator_ICurve::SectionToPoint( 0, 0 ) );
98   sel.push_back( CurveCreator_ICurve::SectionToPoint( 0, 1 ) );
99   sel.push_back( CurveCreator_ICurve::SectionToPoint( 0, 2 ) );
100   sel.push_back( CurveCreator_ICurve::SectionToPoint( 0, 3 ) );
101   dlg->myEditorWidget->getAction( CurveCreator_Widget::ModificationMode )->toggle();
102   dlg->myEditorWidget->onModificationMode( true );
103   dlg->myEditorWidget->setSelectedPoints( sel );
104   dlg->myEditorWidget->updateLocalPointView();
105
106   QList<int> sizes;
107   sizes.append( 25 );
108   sizes.append( 100 );
109   sizes.append( 200 );
110   sizes.append( 25 );
111   sizes.append( 25 );
112   dlg->splitter()->setSizes( sizes );
113
114   qApp->processEvents();
115
116   QTest::qWait( 50000 );
117
118   dlg->deleteLater();
119   delete aProfile;
120   delete aDisplayer;
121   qApp->processEvents();
122 }