Salome HOME
fix test data
[modules/geom.git] / src / XAO / tests / XaoTest.cxx
1 #include <vector>
2
3 #include "TestUtils.hxx"
4 #include "XaoTest.hxx"
5 #include "../XAO_XaoUtils.hxx"
6 #include "../XAO_Xao.hxx"
7 #include "../XAO_BrepGeometry.hxx"
8 #include "../XAO_Group.hxx"
9 #include "../XAO_Field.hxx"
10
11 using namespace XAO;
12
13 void XaoTest::setUp()
14 {
15 }
16
17 void XaoTest::tearDown()
18 {
19 }
20
21 void XaoTest::cleanUp()
22 {
23 }
24
25 void XaoTest::testGroups()
26 {
27     Xao obj;
28     CPPUNIT_ASSERT_THROW(obj.addGroup(XAO::FACE), XAO_Exception);
29
30     BrepGeometry* geom = new BrepGeometry("test");
31     obj.setGeometry(geom);
32     Group* gr = obj.addGroup(XAO::FACE);
33     CPPUNIT_ASSERT_EQUAL(XAO::FACE, gr->getDimension());
34     CPPUNIT_ASSERT_EQUAL(1, obj.countGroups());
35     Group* gr2 = obj.addGroup(XAO::FACE);
36     gr2->setName("AA");
37
38     Group* agr = obj.getGroup(0);
39     CPPUNIT_ASSERT(gr == agr);
40     CPPUNIT_ASSERT_THROW(obj.getGroup(10), XAO_Exception);
41
42     CPPUNIT_ASSERT_EQUAL(true, obj.removeGroup(gr2));
43     CPPUNIT_ASSERT_EQUAL(1, obj.countGroups());
44
45     // remove other group
46     Group* gr3 = new Group(XAO::FACE, 3);
47     CPPUNIT_ASSERT_EQUAL(false, obj.removeGroup(gr3));
48     delete gr3;
49 }
50
51 void XaoTest::testFields()
52 {
53     Xao obj;
54     CPPUNIT_ASSERT_THROW(obj.addField(XAO::INTEGER, XAO::FACE, 3), XAO_Exception);
55
56     BrepGeometry* geom = new BrepGeometry("test");
57     obj.setGeometry(geom);
58     Field* fi = obj.addField(XAO::INTEGER, XAO::FACE, 3);
59     CPPUNIT_ASSERT_EQUAL(1, obj.countFields());
60     CPPUNIT_ASSERT_EQUAL(XAO::INTEGER, fi->getType());
61     CPPUNIT_ASSERT_EQUAL(XAO::FACE, fi->getDimension());
62     CPPUNIT_ASSERT_EQUAL(3, fi->countComponents());
63
64     Field* fb = obj.addField(XAO::BOOLEAN, XAO::FACE, 3);
65     Field* fd = obj.addField(XAO::DOUBLE, XAO::FACE, 3);
66     Field* fs = obj.addField(XAO::STRING, XAO::FACE, 3);
67     CPPUNIT_ASSERT_EQUAL(4, obj.countFields());
68     CPPUNIT_ASSERT_THROW(obj.getField(10), XAO_Exception);
69
70     CPPUNIT_ASSERT_EQUAL(true, obj.removeField(fb));
71     CPPUNIT_ASSERT_EQUAL(3, obj.countFields());
72
73
74     Field* ff = Field::createField(XAO::INTEGER, XAO::FACE, 3, 3);
75     CPPUNIT_ASSERT_EQUAL(false, obj.removeField(ff));
76     delete ff;
77 }
78
79 void XaoTest::testFieldsTypes()
80 {
81     Xao obj;
82     BrepGeometry* geom = new BrepGeometry("test");
83     obj.setGeometry(geom);
84
85     IntegerField* fi = obj.addIntegerField(XAO::FACE, 3);
86     BooleanField* fb = obj.addBooleanField(XAO::FACE, 3);
87     DoubleField* fd = obj.addDoubleField(XAO::FACE, 3);
88     StringField* fs = obj.addStringField(XAO::FACE, 3);
89
90     IntegerField* gfi = obj.getIntegerField(0);
91     CPPUNIT_ASSERT(gfi == fi);
92     BooleanField* gfb = obj.getBooleanField(1);
93     CPPUNIT_ASSERT(gfb == fb);
94     DoubleField* gfd = obj.getDoubleField(2);
95     CPPUNIT_ASSERT(gfd == fd);
96     StringField* gfs = obj.getStringField(3);
97     CPPUNIT_ASSERT(gfs == fs);
98
99     CPPUNIT_ASSERT_THROW(obj.getIntegerField(1), XAO_Exception);
100     CPPUNIT_ASSERT_THROW(obj.getBooleanField(0), XAO_Exception);
101     CPPUNIT_ASSERT_THROW(obj.getDoubleField(0), XAO_Exception);
102     CPPUNIT_ASSERT_THROW(obj.getStringField(0), XAO_Exception);
103 }