Salome HOME
Merge branch 'master' of ssh://git.salome-platform.org/modules/hydro
[modules/hydro.git] / src / HYDROData / test_HYDROData_Iterator.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include<test_HYDROData_Iterator.h>
24
25 #include <HYDROData_Document.h>
26 #include <HYDROData_Iterator.h>
27
28 #include <QString>
29
30 void test_HYDROData_Iterator::testOneKind()
31 {
32   static const QString aName1("test_name1");
33   static const QString aName2("test_name2");
34   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
35
36   Handle(HYDROData_Entity) anObj = aDoc->CreateObject(KIND_IMAGE); // image object
37   anObj->SetName(aName1);
38   // first HYDROData_Entity must be destroyed because there is no hander pointer naymore
39   anObj = aDoc->CreateObject(KIND_IMAGE); // second image object
40   anObj->SetName(aName2);
41
42   HYDROData_Iterator anIter(aDoc, KIND_IMAGE);
43   CPPUNIT_ASSERT(anIter.More());
44   CPPUNIT_ASSERT(!anIter.Current().IsNull());
45   CPPUNIT_ASSERT_EQUAL(aName1.toStdString(), anIter.Current()->GetName().toStdString());
46
47   anIter.Next();
48   CPPUNIT_ASSERT(anIter.More());
49   CPPUNIT_ASSERT(!anIter.Current().IsNull());
50   CPPUNIT_ASSERT_EQUAL(aName2.toStdString(), anIter.Current()->GetName().toStdString());
51
52   anIter.Next();
53   CPPUNIT_ASSERT(!anIter.More());
54
55   aDoc->Close();
56 }
57
58 void test_HYDROData_Iterator::testAllKinds()
59 {
60   static const QString aName1("test_name1");
61   static const QString aName2("test_name2");
62   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
63
64   Handle(HYDROData_Entity) anObj = aDoc->CreateObject(KIND_IMAGE); // image object
65   anObj->SetName(aName1);
66   // first HYDROData_Entity must be destroyed because there is no hander pointer naymore
67   anObj = aDoc->CreateObject(KIND_IMAGE); // second image object
68   anObj->SetName(aName2);
69
70   HYDROData_Iterator anIter(aDoc, KIND_UNKNOWN);
71   CPPUNIT_ASSERT(anIter.More());
72   CPPUNIT_ASSERT(!anIter.Current().IsNull());
73   CPPUNIT_ASSERT_EQUAL(aName1.toStdString(), anIter.Current()->GetName().toStdString());
74
75   anIter.Next();
76   CPPUNIT_ASSERT(anIter.More());
77   CPPUNIT_ASSERT(!anIter.Current().IsNull());
78   CPPUNIT_ASSERT_EQUAL(aName2.toStdString(), anIter.Current()->GetName().toStdString());
79
80   anIter.Next();
81   CPPUNIT_ASSERT(!anIter.More());
82
83   aDoc->Close();
84 }