1 // Copyright (C) 2013-2016 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "TestUtils.hxx"
23 #include "GeometryTest.hxx"
24 #include "../XAO_XaoUtils.hxx"
25 #include "../XAO_Geometry.hxx"
26 #include "../XAO_GeometricElement.hxx"
30 void GeometryTest::setUp()
34 void GeometryTest::tearDown()
38 void GeometryTest::cleanUp()
42 void GeometryTest::testGeometryElement()
45 CPPUNIT_ASSERT_EQUAL(false, elt.hasName());
46 CPPUNIT_ASSERT_EQUAL(std::string(""), elt.getName());
47 CPPUNIT_ASSERT_EQUAL(std::string(""), elt.getReference());
50 CPPUNIT_ASSERT_EQUAL(true, elt.hasName());
51 CPPUNIT_ASSERT_EQUAL(std::string("test"), elt.getName());
53 elt.setReference("abc");
54 CPPUNIT_ASSERT_EQUAL(std::string("abc"), elt.getReference());
56 GeometricElement elt2("aa", "bb");
57 CPPUNIT_ASSERT_EQUAL(std::string("aa"), elt2.getName());
58 CPPUNIT_ASSERT_EQUAL(std::string("bb"), elt2.getReference());
61 void GeometryTest::testGeometryElementList()
63 GeometricElementList lst;
64 CPPUNIT_ASSERT_EQUAL(0, lst.getSize());
66 CPPUNIT_ASSERT_EQUAL(10, lst.getSize());
68 GeometricElementList otherLst(15);
69 CPPUNIT_ASSERT_EQUAL(15, otherLst.getSize());
70 CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getName(0));
71 CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getReference(0));
73 CPPUNIT_ASSERT_THROW(otherLst.getName(20), XAO_Exception);
74 CPPUNIT_ASSERT_THROW(otherLst.getReference(20), XAO_Exception);
75 CPPUNIT_ASSERT_THROW(otherLst.hasName(20), XAO_Exception);
77 otherLst.setName(0, "aa");
78 CPPUNIT_ASSERT_EQUAL(std::string("aa"), otherLst.getName(0));
79 CPPUNIT_ASSERT_THROW(otherLst.setName(20, "aa"), XAO_Exception);
80 otherLst.setReference(0, "bb");
81 CPPUNIT_ASSERT_EQUAL(std::string("bb"), otherLst.getReference(0));
82 CPPUNIT_ASSERT_THROW(otherLst.setReference(20, "aa"), XAO_Exception);
85 CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getName(0));
86 CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getReference(0));
87 CPPUNIT_ASSERT_EQUAL(false, otherLst.hasName(0));
89 otherLst.setElement(3, "name", "ref");
90 CPPUNIT_ASSERT_EQUAL(std::string("name"), otherLst.getName(3));
91 CPPUNIT_ASSERT_EQUAL(std::string("ref"), otherLst.getReference(3));
92 CPPUNIT_ASSERT_EQUAL(true, otherLst.hasName(3));
93 CPPUNIT_ASSERT_THROW(otherLst.setElement(30, "name", "ref"), XAO_Exception);
95 // ---- create elements "name i", "Ri"
96 for (int i = 0; i < otherLst.getSize(); ++i)
98 std::ostringstream name;
100 std::ostringstream ref;
103 otherLst.setElement(i, name.str(), ref.str());
106 CPPUNIT_ASSERT_EQUAL(8, otherLst.getIndexByReference("R8"));
107 CPPUNIT_ASSERT_THROW(otherLst.getIndexByReference("ZZ"), XAO_Exception);
109 GeometricElementList::iterator first = otherLst.begin();
110 GeometricElement firstElt = first->second;
111 CPPUNIT_ASSERT_EQUAL(std::string("R0"), firstElt.getReference());
114 void GeometryTest::testGeometry()
116 Geometry* geom = Geometry::createGeometry(XAO::BREP, "cube");
118 CPPUNIT_ASSERT_EQUAL(std::string("cube"), geom->getName());
119 CPPUNIT_ASSERT_EQUAL(XAO::BREP, geom->getFormat());
121 geom->setName("sphere");
122 CPPUNIT_ASSERT_EQUAL(std::string("sphere"), geom->getName());
127 void GeometryTest::testGeometryErrors()
129 CPPUNIT_ASSERT_THROW(Geometry::createGeometry(XAO::STEP), XAO_Exception);
132 void GeometryTest::testSetElement()
134 Geometry* geom = Geometry::createGeometry(XAO::BREP, "cube");
136 CPPUNIT_ASSERT_THROW(geom->setVertexName(0, "aa"), XAO_Exception);
138 char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath("Box_1.brep"));
139 geom->setShapeString(txt);
141 CPPUNIT_ASSERT_EQUAL(false, geom->hasVertexName(0));
142 geom->setVertexName(0, "va");
143 CPPUNIT_ASSERT_EQUAL(true, geom->hasVertexName(0));
144 CPPUNIT_ASSERT_EQUAL(std::string("va"), geom->getVertexName(0));
145 CPPUNIT_ASSERT_THROW(geom->getVertexName(100), XAO_Exception);
146 CPPUNIT_ASSERT_THROW(geom->hasVertexName(100), XAO_Exception);
148 geom->setEdgeName(0, "ea");
149 CPPUNIT_ASSERT_EQUAL(std::string("ea"), geom->getEdgeName(0));
150 CPPUNIT_ASSERT_THROW(geom->getEdgeName(100), XAO_Exception);
152 geom->setFaceName(0, "fa");
153 CPPUNIT_ASSERT_EQUAL(std::string("fa"), geom->getFaceName(0));
154 CPPUNIT_ASSERT_THROW(geom->getFaceName(100), XAO_Exception);
156 geom->setSolidName(0, "sa");
157 CPPUNIT_ASSERT_EQUAL(std::string("sa"), geom->getSolidName(0));
158 CPPUNIT_ASSERT_THROW(geom->getSolidName(100), XAO_Exception);