Salome HOME
0e7b47071c8ac2dce6d7f68b50e5b3207e7b6b02
[modules/geom.git] / src / XAO / tests / XaoTest.cxx
1 // Copyright (C) 2013-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include <vector>
21
22 #include "TestUtils.hxx"
23 #include "XaoTest.hxx"
24 #include "../XAO_XaoUtils.hxx"
25 #include "../XAO_Xao.hxx"
26 #include "../XAO_BrepGeometry.hxx"
27 #include "../XAO_Group.hxx"
28 #include "../XAO_Field.hxx"
29
30 using namespace XAO;
31
32 void XaoTest::setUp()
33 {
34 }
35
36 void XaoTest::tearDown()
37 {
38 }
39
40 void XaoTest::cleanUp()
41 {
42 }
43
44 void XaoTest::testGroups()
45 {
46     Xao obj;
47     CPPUNIT_ASSERT_THROW(obj.addGroup(XAO::FACE), XAO_Exception);
48
49     BrepGeometry* geom = new BrepGeometry("test");
50     obj.setGeometry(geom);
51     Group* gr = obj.addGroup(XAO::FACE);
52     CPPUNIT_ASSERT_EQUAL(XAO::FACE, gr->getDimension());
53     CPPUNIT_ASSERT_EQUAL(1, obj.countGroups());
54     Group* gr2 = obj.addGroup(XAO::FACE);
55     gr2->setName("AA");
56
57     Group* agr = obj.getGroup(0);
58     CPPUNIT_ASSERT(gr == agr);
59     CPPUNIT_ASSERT_THROW(obj.getGroup(10), XAO_Exception);
60
61     CPPUNIT_ASSERT_EQUAL(true, obj.removeGroup(gr2));
62     CPPUNIT_ASSERT_EQUAL(1, obj.countGroups());
63
64     // remove other group
65     Group* gr3 = new Group(XAO::FACE, 3);
66     CPPUNIT_ASSERT_EQUAL(false, obj.removeGroup(gr3));
67     delete gr3;
68 }
69
70 void XaoTest::testFields()
71 {
72     Xao obj;
73     CPPUNIT_ASSERT_THROW(obj.addField(XAO::INTEGER, XAO::FACE, 3), XAO_Exception);
74
75     BrepGeometry* geom = new BrepGeometry("test");
76     obj.setGeometry(geom);
77     Field* fi = obj.addField(XAO::INTEGER, XAO::FACE, 3);
78     CPPUNIT_ASSERT_EQUAL(1, obj.countFields());
79     CPPUNIT_ASSERT_EQUAL(XAO::INTEGER, fi->getType());
80     CPPUNIT_ASSERT_EQUAL(XAO::FACE, fi->getDimension());
81     CPPUNIT_ASSERT_EQUAL(3, fi->countComponents());
82
83     Field* fb = obj.addField(XAO::BOOLEAN, XAO::FACE, 3);
84     /*Field* fd = */obj.addField(XAO::DOUBLE, XAO::FACE, 3);
85     /*Field* fs = */obj.addField(XAO::STRING, XAO::FACE, 3);
86     CPPUNIT_ASSERT_EQUAL(4, obj.countFields());
87     CPPUNIT_ASSERT_THROW(obj.getField(10), XAO_Exception);
88
89     CPPUNIT_ASSERT_EQUAL(true, obj.removeField(fb));
90     CPPUNIT_ASSERT_EQUAL(3, obj.countFields());
91
92
93     Field* ff = Field::createField(XAO::INTEGER, XAO::FACE, 3, 3);
94     CPPUNIT_ASSERT_EQUAL(false, obj.removeField(ff));
95     delete ff;
96 }
97
98 void XaoTest::testFieldsTypes()
99 {
100     Xao obj;
101     BrepGeometry* geom = new BrepGeometry("test");
102     obj.setGeometry(geom);
103
104     IntegerField* fi = obj.addIntegerField(XAO::FACE, 3);
105     BooleanField* fb = obj.addBooleanField(XAO::FACE, 3);
106     DoubleField* fd = obj.addDoubleField(XAO::FACE, 3);
107     StringField* fs = obj.addStringField(XAO::FACE, 3);
108
109     IntegerField* gfi = obj.getIntegerField(0);
110     CPPUNIT_ASSERT(gfi == fi);
111     BooleanField* gfb = obj.getBooleanField(1);
112     CPPUNIT_ASSERT(gfb == fb);
113     DoubleField* gfd = obj.getDoubleField(2);
114     CPPUNIT_ASSERT(gfd == fd);
115     StringField* gfs = obj.getStringField(3);
116     CPPUNIT_ASSERT(gfs == fs);
117
118     CPPUNIT_ASSERT_THROW(obj.getIntegerField(1), XAO_Exception);
119     CPPUNIT_ASSERT_THROW(obj.getBooleanField(0), XAO_Exception);
120     CPPUNIT_ASSERT_THROW(obj.getDoubleField(0), XAO_Exception);
121     CPPUNIT_ASSERT_THROW(obj.getStringField(0), XAO_Exception);
122 }