From: fps Date: Mon, 9 Sep 2013 15:07:57 +0000 (+0000) Subject: improve code X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a24956bf0aa4a7dd3c997e4fa479ac0de4f4c980;p=modules%2Fgeom.git improve code add more tests --- diff --git a/src/XAO/XAO_BrepGeometry.cxx b/src/XAO/XAO_BrepGeometry.cxx index 29cbd514b..a95c84ed0 100644 --- a/src/XAO/XAO_BrepGeometry.cxx +++ b/src/XAO/XAO_BrepGeometry.cxx @@ -95,11 +95,15 @@ void BrepGeometry::initListIds(const TopAbs_ShapeEnum& shapeType, GeometricEleme TopTools_MapOfShape mapShape; TopTools_ListOfShape listShape; + int nbElt = 0; TopExp_Explorer exp(m_shape, shapeType); for (; exp.More(); exp.Next()) { if (mapShape.Add(exp.Current())) + { listShape.Append(exp.Current()); + nbElt++; + } } if (listShape.IsEmpty()) @@ -108,19 +112,14 @@ void BrepGeometry::initListIds(const TopAbs_ShapeEnum& shapeType, GeometricEleme TopTools_IndexedMapOfShape indices; TopExp::MapShapes(m_shape, indices); - std::list indexList; + eltList.setSize(nbElt); TopTools_ListIteratorOfListOfShape itSub(listShape); - for (int index = 1; itSub.More(); itSub.Next(), ++index) + for (int index = 0; itSub.More(); itSub.Next(), ++index) { TopoDS_Shape value = itSub.Value(); - indexList.push_back(indices.FindIndex(value)); + int ref = indices.FindIndex(value); + eltList.setReference(index, XaoUtils::intToString(ref)); } - - std::list::iterator it = indexList.begin(); - - eltList.setSize(indexList.size()); - for (int i = 0; it != indexList.end(); it++, i++) - eltList.setReference(i, XaoUtils::intToString((*it))); } TopoDS_Shape BrepGeometry::getSubShape(const TopoDS_Shape& mainShape, const TopAbs_ShapeEnum& shapeType, const int& shapeIndex) @@ -137,14 +136,10 @@ TopoDS_Shape BrepGeometry::getSubShape(const TopoDS_Shape& mainShape, const TopA if (!listShape.IsEmpty()) { - // use main shape indices - TopTools_IndexedMapOfShape indices; - TopExp::MapShapes(mainShape, indices); - TopTools_ListIteratorOfListOfShape itSub(listShape); - for (int index = 1; itSub.More(); itSub.Next(), ++index) + for (int index = 0; itSub.More(); itSub.Next(), ++index) { - if (shapeIndex + 1 == index) + if (shapeIndex == index) { TopoDS_Shape value = itSub.Value(); return value; @@ -159,13 +154,9 @@ TopoDS_Shape BrepGeometry::getSubShape(const TopoDS_Shape& mainShape, const TopA const int BrepGeometry::countGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType) { int res = 0; - TopTools_MapOfShape mapShape; TopExp_Explorer exp(shape, shapeType); for (; exp.More(); exp.Next()) - { -// if (mapShape.Add(exp.Current())) - res++; - } + res++; return res; } @@ -191,7 +182,7 @@ std::vector BrepGeometry::getGeometricalElements(const TopoDS_Shape& shape, TopExp::MapShapes(m_shape, indices); TopTools_ListIteratorOfListOfShape itSub(listShape); - for (int index = 1; itSub.More(); itSub.Next(), ++index) + for (int index = 0; itSub.More(); itSub.Next(), ++index) { TopoDS_Shape value = itSub.Value(); int id = indices.FindIndex(value); @@ -338,6 +329,7 @@ const int BrepGeometry::findElement(const XAO::Dimension& dim, const int& id) return findFace(id); if (dim == XAO::SOLID) return findSolid(id); + throw SALOME_Exception(MsgBuilder() << "Unknown Dimension: " << dim); } diff --git a/src/XAO/XAO_BrepGeometry.hxx b/src/XAO/XAO_BrepGeometry.hxx index 923520cf3..16561b8a3 100644 --- a/src/XAO/XAO_BrepGeometry.hxx +++ b/src/XAO/XAO_BrepGeometry.hxx @@ -146,8 +146,6 @@ namespace XAO void setFaceID(const int& index, const int& id); void setSolidID(const int& index, const int& id); - const int findElement(const XAO::Dimension& dim, const int& id); - /** * Finds a vertex with its ID. * @param id the ID of the vertex. @@ -238,6 +236,7 @@ namespace XAO TopoDS_Shape getSubShape(const TopoDS_Shape& mainShape, const TopAbs_ShapeEnum& shapeType, const int& shapeIndex); const int countGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType); std::vector getGeometricalElements(const TopoDS_Shape& shape, const TopAbs_ShapeEnum& shapeType, const XAO::Dimension& dim); + const int findElement(const XAO::Dimension& dim, const int& id); private: TopoDS_Shape m_shape; diff --git a/src/XAO/XAO_GeometricElement.cxx b/src/XAO/XAO_GeometricElement.cxx index a0f39600b..3d5c6233a 100644 --- a/src/XAO/XAO_GeometricElement.cxx +++ b/src/XAO/XAO_GeometricElement.cxx @@ -54,7 +54,7 @@ GeometricElementList::GeometricElementList() GeometricElementList::GeometricElementList(const int& count) { - setSize(m_count); + setSize(count); } void GeometricElementList::setSize(const int& nb) @@ -67,52 +67,48 @@ void GeometricElementList::setSize(const int& nb) } } -void GeometricElementList::setElement(const int& index, const std::string& name, const std::string& reference) +void GeometricElementList::checkElementIndex(const int& index) const { - if (m_count == 0 || index > m_count) - throw SALOME_Exception("Problem with number of elements"); + if (m_count >= 0 && index < m_count) + return; + + throw SALOME_Exception(MsgBuilder() << "Index of element is out of range [0, " << m_count<< "]: " << index); +} +void GeometricElementList::setElement(const int& index, const std::string& name, const std::string& reference) +{ + checkElementIndex(index); m_elements[index].setName(name); m_elements[index].setReference(reference); } const std::string GeometricElementList::getName(const int& index) { - if (m_count == 0 || index > m_count) - throw SALOME_Exception("Problem with number of elements"); - + checkElementIndex(index); return m_elements[index].getName(); } void GeometricElementList::setName(const int& index, const std::string& name) { - if (m_count == 0 || index > m_count) - throw SALOME_Exception("Problem with number of elements"); - + checkElementIndex(index); m_elements[index].setName(name); } const bool GeometricElementList::hasName(const int& index) { - if (m_count == 0 || index > m_count) - throw SALOME_Exception("Problem with number of elements"); - + checkElementIndex(index); return m_elements[index].hasName(); } const std::string GeometricElementList::getReference(const int& index) { - if (m_count == 0 || index > m_count) - throw SALOME_Exception("Problem with number of elements"); - + checkElementIndex(index); return m_elements[index].getReference(); } void GeometricElementList::setReference(const int& index, const std::string& name) { - if (m_count == 0 || index > m_count) - throw SALOME_Exception("Problem with number of elements"); - + checkElementIndex(index); m_elements[index].setReference(name); } diff --git a/src/XAO/XAO_GeometricElement.hxx b/src/XAO/XAO_GeometricElement.hxx index a2be162db..cb374acc0 100644 --- a/src/XAO/XAO_GeometricElement.hxx +++ b/src/XAO/XAO_GeometricElement.hxx @@ -200,6 +200,9 @@ namespace XAO */ iterator end() { return m_elements.end(); } + private: + void checkElementIndex(const int& index) const; + private: int m_count; std::map m_elements; diff --git a/src/XAO/XAO_Step.cxx b/src/XAO/XAO_Step.cxx index e14eb7004..a337f57ac 100644 --- a/src/XAO/XAO_Step.cxx +++ b/src/XAO/XAO_Step.cxx @@ -30,20 +30,6 @@ using namespace XAO; -Step* Step::createStep(const XAO::Type& type, const int& step, const int& stamp, const int& nbElements, const int& nbComponents) -{ - if (type == XAO::BOOLEAN) - return new BooleanStep(step, stamp, nbElements, nbComponents); - if (type == XAO::INTEGER) - return new IntegerStep(step, stamp, nbElements, nbComponents); - if (type == XAO::DOUBLE) - return new DoubleStep(step, stamp, nbElements, nbComponents); - if (type == XAO::STRING) - return new StringStep(step, stamp, nbElements, nbComponents); - - throw SALOME_Exception("Unknown Type"); -} - void Step::checkElementIndex(const int& element) { if (element < m_nbElements && element >= 0) diff --git a/src/XAO/XAO_Step.hxx b/src/XAO/XAO_Step.hxx index c588d164a..4ebf27a55 100644 --- a/src/XAO/XAO_Step.hxx +++ b/src/XAO/XAO_Step.hxx @@ -33,17 +33,6 @@ namespace XAO Step() {} public: - /** - * Creates a step. - * @param type the type of the values for the step. - * @param step the index of the step. - * @param stamp the stamp of the step. - * @param nbElements the number of elements in the step. - * @param nbComponents the number of components in the step. - * @return - */ - static Step* createStep(const XAO::Type& type, const int& step, const int& stamp, const int& nbElements, const int& nbComponents); - /** * Destructor. */ diff --git a/src/XAO/XAO_Xao.cxx b/src/XAO/XAO_Xao.cxx index 95923aa67..b1d469844 100644 --- a/src/XAO/XAO_Xao.cxx +++ b/src/XAO/XAO_Xao.cxx @@ -71,6 +71,8 @@ const int Xao::countGroups() const Group* Xao::getGroup(const int& index) { + checkGroupIndex(index); + int i = 0; for (std::list::iterator it = m_groups.begin(); it != m_groups.end(); ++it, ++i) { @@ -94,9 +96,11 @@ Group* Xao::addGroup(const std::string& name, const XAO::Dimension& dim) return group; } -void Xao::removeGroup(Group* group) +bool Xao::removeGroup(Group* group) { + int nb = countGroups(); m_groups.remove(group); + return (nb-1 == countGroups()); } const int Xao::countFields() const @@ -106,6 +110,8 @@ const int Xao::countFields() const Field* Xao::getField(const int& index) { + checkFieldIndex(index); + int i = 0; for (std::list::iterator it = m_fields.begin(); it != m_fields.end(); ++it, ++i) { @@ -130,9 +136,11 @@ Field* Xao::addField(const XAO::Type& type, const std::string& name, const XAO:: return field; } -void Xao::removeField(Field* field) +bool Xao::removeField(Field* field) { + int nb = countFields(); m_fields.remove(field); + return (nb-1 == countFields()); } const bool Xao::exportXAO(const std::string& fileName) @@ -160,3 +168,21 @@ void Xao::checkGeometry() const if (m_geometry == NULL) throw SALOME_Exception("Geometry is null"); } + +void Xao::checkGroupIndex(const int& index) const +{ + if (index >= 0 && index < countGroups()) + return; + + throw SALOME_Exception(MsgBuilder() << "Group index is out of range [0, " + << countGroups()-1 << "]: " << index); +} + +void Xao::checkFieldIndex(const int& index) const +{ + if (index >= 0 && index < countFields()) + return; + + throw SALOME_Exception(MsgBuilder() << "Field index is out of range [0, " + << countFields()-1 << "]: " << index); +} diff --git a/src/XAO/XAO_Xao.hxx b/src/XAO/XAO_Xao.hxx index 7c092be2a..b96d2774a 100644 --- a/src/XAO/XAO_Xao.hxx +++ b/src/XAO/XAO_Xao.hxx @@ -170,8 +170,9 @@ namespace XAO /** * Removes a group. * \param group the group to remove. + * \return true if the group has been removed, false otherwise. */ - void removeGroup(Group* group); + bool removeGroup(Group* group); // // Fields @@ -208,8 +209,9 @@ namespace XAO /** * Removes a field. * \param field the field to remove. + * \return true if the field has been removed, false otherwise. */ - void removeField(Field* field); + bool removeField(Field* field); // // Import / Export @@ -241,6 +243,8 @@ namespace XAO private: void checkGeometry() const; + void checkGroupIndex(const int& index) const; + void checkFieldIndex(const int& index) const; private: /** The author of the file. */ diff --git a/src/XAO/XAO_XaoExporter.cxx b/src/XAO/XAO_XaoExporter.cxx index 65e84247b..1a909d107 100644 --- a/src/XAO/XAO_XaoExporter.cxx +++ b/src/XAO/XAO_XaoExporter.cxx @@ -115,7 +115,7 @@ int XaoExporter::readIntegerProp(xmlNodePtr node, const xmlChar* attribute, const bool XaoExporter::saveToFile(Xao* xaoObject, const std::string& fileName) { xmlDocPtr doc = exportXMLDoc(xaoObject); - xmlSaveFormatFileEnc(fileName.c_str(), doc, "UTF-8", 2); + xmlSaveFormatFileEnc(fileName.c_str(), doc, "UTF-8", 1); // format = 1 for node indentation xmlFreeDoc(doc); return true; @@ -127,7 +127,7 @@ const std::string XaoExporter::saveToXml(Xao* xaoObject) xmlChar *xmlbuff; int buffersize; - xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1); + xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1); // format = 1 for node indentation xmlFreeDoc(doc); xmlCleanupGlobals(); @@ -267,7 +267,7 @@ void XaoExporter::exportStep(Step* step, Field* field, xmlNodePtr nodeSteps) for (int j = 0; j < step->countComponents(); ++j) { std::string content = step->getStringValue(i, j); - xmlNodePtr nodeValue= xmlNewTextChild(nodeElt, 0, C_TAG_VALUE, BAD_CAST content.c_str()); + xmlNodePtr nodeValue = xmlNewChild(nodeElt, NULL, C_TAG_VALUE, BAD_CAST content.c_str()); xmlNewProp(nodeValue, C_ATTR_VALUE_COMPONENT, BAD_CAST XaoUtils::intToString(j).c_str()); } } diff --git a/src/XAO/XAO_XaoUtils.hxx b/src/XAO/XAO_XaoUtils.hxx index 06e43f629..c9088a636 100644 --- a/src/XAO/XAO_XaoUtils.hxx +++ b/src/XAO/XAO_XaoUtils.hxx @@ -129,6 +129,7 @@ namespace XAO { public: MsgBuilder() {}; + ~MsgBuilder() {}; template MsgBuilder& operator <<(const T& t) diff --git a/src/XAO/tests/BrepGeometryTest.cxx b/src/XAO/tests/BrepGeometryTest.cxx index ef8a524aa..3dd1c2b07 100644 --- a/src/XAO/tests/BrepGeometryTest.cxx +++ b/src/XAO/tests/BrepGeometryTest.cxx @@ -92,6 +92,48 @@ void BrepGeometryTest::testGetReferences() delete geom; } +void BrepGeometryTest::testGetNames() +{ + BrepGeometry* geom = new BrepGeometry("box"); + readBrep(geom, "Box_1.brep"); + + int id; + + // vertex of index 1 has id = 7 + id = 7; + CPPUNIT_ASSERT_EQUAL(std::string(""), geom->findVertexName(id)); + geom->changeVertexName(id, std::string("va")); + CPPUNIT_ASSERT_EQUAL(std::string("va"), geom->findVertexName(id)); + CPPUNIT_ASSERT_THROW(geom->changeVertexName(100, "a"), SALOME_Exception); + CPPUNIT_ASSERT_THROW(geom->findVertexName(100), SALOME_Exception); + + // edge of index 1 has id = 8 + id = 8; + CPPUNIT_ASSERT_EQUAL(std::string(""), geom->findEdgeName(id)); + geom->changeEdgeName(id, std::string("ea")); + CPPUNIT_ASSERT_EQUAL(std::string("ea"), geom->findEdgeName(id)); + CPPUNIT_ASSERT_THROW(geom->changeEdgeName(100, "a"), SALOME_Exception); + CPPUNIT_ASSERT_THROW(geom->findEdgeName(100), SALOME_Exception); + + // face of index 1 has id = 13 + id = 13; + CPPUNIT_ASSERT_EQUAL(std::string(""), geom->findFaceName(id)); + geom->changeFaceName(id, std::string("fa")); + CPPUNIT_ASSERT_EQUAL(std::string("fa"), geom->findFaceName(id)); + CPPUNIT_ASSERT_THROW(geom->changeFaceName(100, "a"), SALOME_Exception); + CPPUNIT_ASSERT_THROW(geom->findFaceName(100), SALOME_Exception); + + // solid of index 0 has id = 1 + id = 1; + CPPUNIT_ASSERT_EQUAL(std::string(""), geom->findSolidName(id)); + geom->changeSolidName(id, std::string("sa")); + CPPUNIT_ASSERT_EQUAL(std::string("sa"), geom->findSolidName(id)); + CPPUNIT_ASSERT_THROW(geom->changeSolidName(100, "a"), SALOME_Exception); + CPPUNIT_ASSERT_THROW(geom->findSolidName(100), SALOME_Exception); + + delete geom; +} + void BrepGeometryTest::testGetEdgeVertices() { BrepGeometry* geom = new BrepGeometry("box"); diff --git a/src/XAO/tests/BrepGeometryTest.hxx b/src/XAO/tests/BrepGeometryTest.hxx index bb4b057a3..d74b63ce0 100644 --- a/src/XAO/tests/BrepGeometryTest.hxx +++ b/src/XAO/tests/BrepGeometryTest.hxx @@ -10,6 +10,7 @@ namespace XAO CPPUNIT_TEST_SUITE(BrepGeometryTest); CPPUNIT_TEST(testGetIDs); CPPUNIT_TEST(testGetReferences); + CPPUNIT_TEST(testGetNames); CPPUNIT_TEST(testGetEdgeVertices); CPPUNIT_TEST(testGetFaceEdges); CPPUNIT_TEST(testSolidFaces); @@ -26,6 +27,7 @@ namespace XAO void testGetIDs(); void testGetReferences(); + void testGetNames(); void testGetEdgeVertices(); void testGetFaceEdges(); void testSolidFaces(); diff --git a/src/XAO/tests/FieldTest.cxx b/src/XAO/tests/FieldTest.cxx index caf2b38ee..bed396ede 100644 --- a/src/XAO/tests/FieldTest.cxx +++ b/src/XAO/tests/FieldTest.cxx @@ -53,6 +53,7 @@ Field* FieldTest::testField(XAO::Type type) CPPUNIT_ASSERT_EQUAL(0, f->countSteps()); Step* step = f->addNewStep(0); + CPPUNIT_ASSERT_EQUAL(type, step->getType()); CPPUNIT_ASSERT_EQUAL(1, f->countSteps()); step = f->addNewStep(1); step = f->addNewStep(2); @@ -125,9 +126,8 @@ void FieldTest::testStringField() CPPUNIT_ASSERT_THROW(f->addStep(10), SALOME_Exception); // step already exists } -void FieldTest::testStep(XAO::Type type) +void FieldTest::testStep(XAO::Type type, Step* step) { - Step* step = Step::createStep(type, 0, 0, 5, 3); CPPUNIT_ASSERT_EQUAL(type, step->getType()); CPPUNIT_ASSERT_EQUAL(0, step->getStep()); @@ -145,19 +145,23 @@ void FieldTest::testStep(XAO::Type type) void FieldTest::testBooleanStep() { - testStep(XAO::BOOLEAN); + Step* step = new BooleanStep(0, 0, 5, 3); + testStep(XAO::BOOLEAN, step); } void FieldTest::testIntegerStep() { - testStep(XAO::INTEGER); + Step* step = new IntegerStep(0, 0, 5, 3); + testStep(XAO::INTEGER, step); } void FieldTest::testDoubleStep() { - testStep(XAO::DOUBLE); + Step* step = new DoubleStep(0, 0, 5, 3); + testStep(XAO::DOUBLE, step); } void FieldTest::testStringStep() { - testStep(XAO::STRING); + Step* step = new StringStep(0, 0, 5, 3); + testStep(XAO::STRING, step); } void FieldTest::testBooleanStepValues() @@ -165,7 +169,7 @@ void FieldTest::testBooleanStepValues() int nbComponents = 3; // > 1 int nbElements = 5; // > 1 - BooleanStep* step = (BooleanStep*)Step::createStep(XAO::BOOLEAN, 0, 0, nbElements, nbComponents); + BooleanStep* step = new BooleanStep(0, 0, nbElements, nbComponents); for (int i = 0; i < step->countElements(); ++i) { for (int j = 0; j < step->countComponents(); ++j) @@ -225,7 +229,7 @@ void FieldTest::testBooleanStepValues() // set string value step->setStringValue(0, 0, "true"); - CPPUNIT_ASSERT_NO_THROW(step->setStringValue(0, 0, "aa")); // set false + CPPUNIT_ASSERT_THROW(step->setStringValue(0, 0, "aa"), SALOME_Exception); // set all values std::vector allValues; @@ -243,7 +247,7 @@ void FieldTest::testIntegerStepValues() int nbComponents = 3; int nbElements = 5; - IntegerStep* step = (IntegerStep*)Step::createStep(XAO::INTEGER, 0, 0, nbElements, nbComponents); + IntegerStep* step = new IntegerStep(0, 0, nbElements, nbComponents); for (int i = 0; i < step->countElements(); ++i) { for (int j = 0; j < step->countComponents(); ++j) @@ -314,7 +318,7 @@ void FieldTest::testDoubleStepValues() int nbComponents = 3; int nbElements = 5; - DoubleStep* step = (DoubleStep*)Step::createStep(XAO::DOUBLE, 0, 0, nbElements, nbComponents); + DoubleStep* step = new DoubleStep(0, 0, nbElements, nbComponents); for (int i = 0; i < step->countElements(); ++i) { for (int j = 0; j < step->countComponents(); ++j) @@ -383,7 +387,7 @@ void FieldTest::testStringStepValues() int nbComponents = 3; int nbElements = 5; - StringStep* step = (StringStep*)Step::createStep(XAO::STRING, 0, 0, nbElements, nbComponents); + StringStep* step = new StringStep(0, 0, nbElements, nbComponents); for (int i = 0; i < step->countElements(); ++i) { for (int j = 0; j < step->countComponents(); ++j) diff --git a/src/XAO/tests/FieldTest.hxx b/src/XAO/tests/FieldTest.hxx index babf12df1..9a4a8d82d 100644 --- a/src/XAO/tests/FieldTest.hxx +++ b/src/XAO/tests/FieldTest.hxx @@ -5,6 +5,7 @@ #include "../XAO_Xao.hxx" #include "../XAO_Field.hxx" +#include "../XAO_Step.hxx" namespace XAO { @@ -36,7 +37,7 @@ namespace XAO void testDoubleField(); void testStringField(); - void testStep(XAO::Type type); + void testStep(XAO::Type type, Step* step); void testBooleanStep(); void testIntegerStep(); void testDoubleStep(); diff --git a/src/XAO/tests/GeometryTest.cxx b/src/XAO/tests/GeometryTest.cxx index cae08b67c..797b68217 100644 --- a/src/XAO/tests/GeometryTest.cxx +++ b/src/XAO/tests/GeometryTest.cxx @@ -4,6 +4,7 @@ #include "TestUtils.hxx" #include "GeometryTest.hxx" #include "../XAO_Geometry.hxx" +#include "../XAO_GeometricElement.hxx" using namespace XAO; @@ -19,6 +20,78 @@ void GeometryTest::cleanUp() { } +void GeometryTest::testGeometryElement() +{ + GeometricElement elt; + CPPUNIT_ASSERT_EQUAL(false, elt.hasName()); + CPPUNIT_ASSERT_EQUAL(std::string(""), elt.getName()); + CPPUNIT_ASSERT_EQUAL(std::string(""), elt.getReference()); + + elt.setName("test"); + CPPUNIT_ASSERT_EQUAL(true, elt.hasName()); + CPPUNIT_ASSERT_EQUAL(std::string("test"), elt.getName()); + + elt.setReference("abc"); + CPPUNIT_ASSERT_EQUAL(std::string("abc"), elt.getReference()); + + GeometricElement elt2("aa", "bb"); + CPPUNIT_ASSERT_EQUAL(std::string("aa"), elt2.getName()); + CPPUNIT_ASSERT_EQUAL(std::string("bb"), elt2.getReference()); +} + +void GeometryTest::testGeometryElementList() +{ + GeometricElementList lst; + CPPUNIT_ASSERT_EQUAL(0, lst.getSize()); + lst.setSize(10); + CPPUNIT_ASSERT_EQUAL(10, lst.getSize()); + + GeometricElementList otherLst(15); + CPPUNIT_ASSERT_EQUAL(15, otherLst.getSize()); + CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getName(0)); + CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getReference(0)); + + CPPUNIT_ASSERT_THROW(otherLst.getName(20), SALOME_Exception); + CPPUNIT_ASSERT_THROW(otherLst.getReference(20), SALOME_Exception); + CPPUNIT_ASSERT_THROW(otherLst.hasName(20), SALOME_Exception); + + otherLst.setName(0, "aa"); + CPPUNIT_ASSERT_EQUAL(std::string("aa"), otherLst.getName(0)); + CPPUNIT_ASSERT_THROW(otherLst.setName(20, "aa"), SALOME_Exception); + otherLst.setReference(0, "bb"); + CPPUNIT_ASSERT_EQUAL(std::string("bb"), otherLst.getReference(0)); + CPPUNIT_ASSERT_THROW(otherLst.setReference(20, "aa"), SALOME_Exception); + + otherLst.setSize(10); + CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getName(0)); + CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getReference(0)); + CPPUNIT_ASSERT_EQUAL(false, otherLst.hasName(0)); + + otherLst.setElement(3, "name", "ref"); + CPPUNIT_ASSERT_EQUAL(std::string("name"), otherLst.getName(3)); + CPPUNIT_ASSERT_EQUAL(std::string("ref"), otherLst.getReference(3)); + CPPUNIT_ASSERT_EQUAL(true, otherLst.hasName(3)); + CPPUNIT_ASSERT_THROW(otherLst.setElement(30, "name", "ref"), SALOME_Exception); + + // ---- create elements "name i", "Ri" + for (int i = 0; i < otherLst.getSize(); ++i) + { + std::ostringstream name; + name << "name " << i; + std::ostringstream ref; + ref << "R" << i; + + otherLst.setElement(i, name.str(), ref.str()); + } + + CPPUNIT_ASSERT_EQUAL(8, otherLst.getIndexByReference("R8")); + CPPUNIT_ASSERT_THROW(otherLst.getIndexByReference("ZZ"), SALOME_Exception); + + GeometricElementList::iterator first = otherLst.begin(); + GeometricElement firstElt = first->second; + CPPUNIT_ASSERT_EQUAL(std::string("R0"), firstElt.getReference()); +} + void GeometryTest::testGeometry() { Geometry* geom = Geometry::createGeometry(XAO::BREP, "cube"); @@ -28,9 +101,42 @@ void GeometryTest::testGeometry() geom->setName("sphere"); CPPUNIT_ASSERT_EQUAL(std::string("sphere"), geom->getName()); + + delete geom; } void GeometryTest::testGeometryErrors() { CPPUNIT_ASSERT_THROW(Geometry::createGeometry(XAO::STEP), SALOME_Exception); } + +void GeometryTest::testSetElement() +{ + Geometry* geom = Geometry::createGeometry(XAO::BREP, "cube"); + + CPPUNIT_ASSERT_THROW(geom->setVertexName(0, "aa"), SALOME_Exception); + + char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath("Box_1.brep")); + geom->setShape(txt); + + CPPUNIT_ASSERT_EQUAL(false, geom->hasVertexName(0)); + geom->setVertexName(0, "va"); + CPPUNIT_ASSERT_EQUAL(true, geom->hasVertexName(0)); + CPPUNIT_ASSERT_EQUAL(std::string("va"), geom->getVertexName(0)); + CPPUNIT_ASSERT_THROW(geom->getVertexName(100), SALOME_Exception); + CPPUNIT_ASSERT_THROW(geom->hasVertexName(100), SALOME_Exception); + + geom->setEdgeName(0, "ea"); + CPPUNIT_ASSERT_EQUAL(std::string("ea"), geom->getEdgeName(0)); + CPPUNIT_ASSERT_THROW(geom->getEdgeName(100), SALOME_Exception); + + geom->setFaceName(0, "fa"); + CPPUNIT_ASSERT_EQUAL(std::string("fa"), geom->getFaceName(0)); + CPPUNIT_ASSERT_THROW(geom->getFaceName(100), SALOME_Exception); + + geom->setSolidName(0, "sa"); + CPPUNIT_ASSERT_EQUAL(std::string("sa"), geom->getSolidName(0)); + CPPUNIT_ASSERT_THROW(geom->getSolidName(100), SALOME_Exception); + + delete geom; +} diff --git a/src/XAO/tests/GeometryTest.hxx b/src/XAO/tests/GeometryTest.hxx index 4cac2c91c..63ad244ff 100644 --- a/src/XAO/tests/GeometryTest.hxx +++ b/src/XAO/tests/GeometryTest.hxx @@ -8,6 +8,8 @@ namespace XAO class GeometryTest: public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(GeometryTest); + CPPUNIT_TEST(testGeometryElement); + CPPUNIT_TEST(testGeometryElementList); CPPUNIT_TEST(testGeometry); CPPUNIT_TEST(testGeometryErrors); CPPUNIT_TEST_SUITE_END(); @@ -17,8 +19,11 @@ namespace XAO void tearDown(); void cleanUp(); + void testGeometryElement(); + void testGeometryElementList(); void testGeometry(); void testGeometryErrors(); + void testSetElement(); }; } diff --git a/src/XAO/tests/Makefile.am b/src/XAO/tests/Makefile.am index 1c406443c..d2d7de205 100755 --- a/src/XAO/tests/Makefile.am +++ b/src/XAO/tests/Makefile.am @@ -43,6 +43,7 @@ dist_TestXAO_SOURCES = \ GeometryTest.cxx \ ImportExportTest.cxx \ BrepGeometryTest.cxx \ + XaoTest.cxx \ XAOTests.cxx UNIT_TEST_PROG = TestXAO diff --git a/src/XAO/tests/XAOTests.cxx b/src/XAO/tests/XAOTests.cxx index 0238e7f9b..baef3d19d 100644 --- a/src/XAO/tests/XAOTests.cxx +++ b/src/XAO/tests/XAOTests.cxx @@ -4,6 +4,7 @@ #include "GeometryTest.hxx" #include "ImportExportTest.hxx" #include "BrepGeometryTest.hxx" +#include "XaoTest.hxx" CPPUNIT_TEST_SUITE_REGISTRATION(XAO::XaoUtilsTest); CPPUNIT_TEST_SUITE_REGISTRATION(XAO::GroupTest); @@ -11,5 +12,6 @@ CPPUNIT_TEST_SUITE_REGISTRATION(XAO::FieldTest); CPPUNIT_TEST_SUITE_REGISTRATION(XAO::GeometryTest); CPPUNIT_TEST_SUITE_REGISTRATION(XAO::ImportExportTest); CPPUNIT_TEST_SUITE_REGISTRATION(XAO::BrepGeometryTest); +CPPUNIT_TEST_SUITE_REGISTRATION(XAO::XaoTest); #include "MainTest.hxx"