]> SALOME platform Git repositories - modules/geom.git/blob - src/XAO/tests/GeometryTest.cxx
Salome HOME
fix test data
[modules/geom.git] / src / XAO / tests / GeometryTest.cxx
1 #include <vector>
2
3 #include "TestUtils.hxx"
4 #include "GeometryTest.hxx"
5 #include "../XAO_XaoUtils.hxx"
6 #include "../XAO_Geometry.hxx"
7 #include "../XAO_GeometricElement.hxx"
8
9 using namespace XAO;
10
11 void GeometryTest::setUp()
12 {
13 }
14
15 void GeometryTest::tearDown()
16 {
17 }
18
19 void GeometryTest::cleanUp()
20 {
21 }
22
23 void GeometryTest::testGeometryElement()
24 {
25     GeometricElement elt;
26     CPPUNIT_ASSERT_EQUAL(false, elt.hasName());
27     CPPUNIT_ASSERT_EQUAL(std::string(""), elt.getName());
28     CPPUNIT_ASSERT_EQUAL(std::string(""), elt.getReference());
29
30     elt.setName("test");
31     CPPUNIT_ASSERT_EQUAL(true, elt.hasName());
32     CPPUNIT_ASSERT_EQUAL(std::string("test"), elt.getName());
33
34     elt.setReference("abc");
35     CPPUNIT_ASSERT_EQUAL(std::string("abc"), elt.getReference());
36
37     GeometricElement elt2("aa", "bb");
38     CPPUNIT_ASSERT_EQUAL(std::string("aa"), elt2.getName());
39     CPPUNIT_ASSERT_EQUAL(std::string("bb"), elt2.getReference());
40 }
41
42 void GeometryTest::testGeometryElementList()
43 {
44     GeometricElementList lst;
45     CPPUNIT_ASSERT_EQUAL(0, lst.getSize());
46     lst.setSize(10);
47     CPPUNIT_ASSERT_EQUAL(10, lst.getSize());
48
49     GeometricElementList otherLst(15);
50     CPPUNIT_ASSERT_EQUAL(15, otherLst.getSize());
51     CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getName(0));
52     CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getReference(0));
53
54     CPPUNIT_ASSERT_THROW(otherLst.getName(20), XAO_Exception);
55     CPPUNIT_ASSERT_THROW(otherLst.getReference(20), XAO_Exception);
56     CPPUNIT_ASSERT_THROW(otherLst.hasName(20), XAO_Exception);
57
58     otherLst.setName(0, "aa");
59     CPPUNIT_ASSERT_EQUAL(std::string("aa"), otherLst.getName(0));
60     CPPUNIT_ASSERT_THROW(otherLst.setName(20, "aa"), XAO_Exception);
61     otherLst.setReference(0, "bb");
62     CPPUNIT_ASSERT_EQUAL(std::string("bb"), otherLst.getReference(0));
63     CPPUNIT_ASSERT_THROW(otherLst.setReference(20, "aa"), XAO_Exception);
64
65     otherLst.setSize(10);
66     CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getName(0));
67     CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getReference(0));
68     CPPUNIT_ASSERT_EQUAL(false, otherLst.hasName(0));
69
70     otherLst.setElement(3, "name", "ref");
71     CPPUNIT_ASSERT_EQUAL(std::string("name"), otherLst.getName(3));
72     CPPUNIT_ASSERT_EQUAL(std::string("ref"), otherLst.getReference(3));
73     CPPUNIT_ASSERT_EQUAL(true, otherLst.hasName(3));
74     CPPUNIT_ASSERT_THROW(otherLst.setElement(30, "name", "ref"), XAO_Exception);
75
76     // ---- create elements "name i", "Ri"
77     for (int i = 0; i < otherLst.getSize(); ++i)
78     {
79         std::ostringstream name;
80         name << "name " << i;
81         std::ostringstream ref;
82         ref << "R" << i;
83
84         otherLst.setElement(i, name.str(), ref.str());
85     }
86
87     CPPUNIT_ASSERT_EQUAL(8, otherLst.getIndexByReference("R8"));
88     CPPUNIT_ASSERT_THROW(otherLst.getIndexByReference("ZZ"), XAO_Exception);
89
90     GeometricElementList::iterator first = otherLst.begin();
91     GeometricElement firstElt = first->second;
92     CPPUNIT_ASSERT_EQUAL(std::string("R0"),  firstElt.getReference());
93 }
94
95 void GeometryTest::testGeometry()
96 {
97     Geometry* geom = Geometry::createGeometry(XAO::BREP, "cube");
98
99     CPPUNIT_ASSERT_EQUAL(std::string("cube"), geom->getName());
100     CPPUNIT_ASSERT_EQUAL(XAO::BREP, geom->getFormat());
101
102     geom->setName("sphere");
103     CPPUNIT_ASSERT_EQUAL(std::string("sphere"), geom->getName());
104
105     delete geom;
106 }
107
108 void GeometryTest::testGeometryErrors()
109 {
110     CPPUNIT_ASSERT_THROW(Geometry::createGeometry(XAO::STEP), XAO_Exception);
111 }
112
113 void GeometryTest::testSetElement()
114 {
115     Geometry* geom = Geometry::createGeometry(XAO::BREP, "cube");
116
117     CPPUNIT_ASSERT_THROW(geom->setVertexName(0, "aa"), XAO_Exception);
118
119     char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath("Box_1.brep"));
120     geom->setShapeString(txt);
121
122     CPPUNIT_ASSERT_EQUAL(false, geom->hasVertexName(0));
123     geom->setVertexName(0, "va");
124     CPPUNIT_ASSERT_EQUAL(true, geom->hasVertexName(0));
125     CPPUNIT_ASSERT_EQUAL(std::string("va"), geom->getVertexName(0));
126     CPPUNIT_ASSERT_THROW(geom->getVertexName(100), XAO_Exception);
127     CPPUNIT_ASSERT_THROW(geom->hasVertexName(100), XAO_Exception);
128
129     geom->setEdgeName(0, "ea");
130     CPPUNIT_ASSERT_EQUAL(std::string("ea"), geom->getEdgeName(0));
131     CPPUNIT_ASSERT_THROW(geom->getEdgeName(100), XAO_Exception);
132
133     geom->setFaceName(0, "fa");
134     CPPUNIT_ASSERT_EQUAL(std::string("fa"), geom->getFaceName(0));
135     CPPUNIT_ASSERT_THROW(geom->getFaceName(100), XAO_Exception);
136
137     geom->setSolidName(0, "sa");
138     CPPUNIT_ASSERT_EQUAL(std::string("sa"), geom->getSolidName(0));
139     CPPUNIT_ASSERT_THROW(geom->getSolidName(100), XAO_Exception);
140
141     delete geom;
142 }