Salome HOME
Merge branch 'BR_2018_V8_5' into BR_PY3
[modules/hydro.git] / src / HYDRO_tests / test_HYDROData_Iterator.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 #include<test_HYDROData_Iterator.h>
20
21 #include <HYDROData_Document.h>
22 #include <HYDROData_Iterator.h>
23
24 #include <QString>
25
26 void test_HYDROData_Iterator::testOneKind()
27 {
28   static const QString aName1("test_name1");
29   static const QString aName2("test_name2");
30   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
31
32   Handle(HYDROData_Entity) anObj = aDoc->CreateObject(KIND_IMAGE); // image object
33   anObj->SetName(aName1);
34   // first HYDROData_Entity must be destroyed because there is no hander pointer naymore
35   anObj = aDoc->CreateObject(KIND_IMAGE); // second image object
36   anObj->SetName(aName2);
37
38   HYDROData_Iterator anIter(aDoc, KIND_IMAGE);
39   CPPUNIT_ASSERT(anIter.More());
40   CPPUNIT_ASSERT(!anIter.Current().IsNull());
41   CPPUNIT_ASSERT_EQUAL(aName1.toStdString(), anIter.Current()->GetName().toStdString());
42
43   anIter.Next();
44   CPPUNIT_ASSERT(anIter.More());
45   CPPUNIT_ASSERT(!anIter.Current().IsNull());
46   CPPUNIT_ASSERT_EQUAL(aName2.toStdString(), anIter.Current()->GetName().toStdString());
47
48   anIter.Next();
49   CPPUNIT_ASSERT(!anIter.More());
50
51   aDoc->Close();
52 }
53
54 void test_HYDROData_Iterator::testAllKinds()
55 {
56   static const QString aName1("test_name1");
57   static const QString aName2("test_name2");
58   Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
59
60   Handle(HYDROData_Entity) anObj = aDoc->CreateObject(KIND_IMAGE); // image object
61   anObj->SetName(aName1);
62   // first HYDROData_Entity must be destroyed because there is no hander pointer naymore
63   anObj = aDoc->CreateObject(KIND_IMAGE); // second image object
64   anObj->SetName(aName2);
65
66   HYDROData_Iterator anIter(aDoc, KIND_UNKNOWN);
67   CPPUNIT_ASSERT(anIter.More());
68   CPPUNIT_ASSERT(!anIter.Current().IsNull());
69   CPPUNIT_ASSERT_EQUAL(aName1.toStdString(), anIter.Current()->GetName().toStdString());
70
71   anIter.Next();
72   CPPUNIT_ASSERT(anIter.More());
73   CPPUNIT_ASSERT(!anIter.Current().IsNull());
74   CPPUNIT_ASSERT_EQUAL(aName2.toStdString(), anIter.Current()->GetName().toStdString());
75
76   anIter.Next();
77   CPPUNIT_ASSERT(!anIter.More());
78
79   aDoc->Close();
80 }