]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
improve code
authorfps <fps@opencascade.com>
Mon, 9 Sep 2013 15:07:57 +0000 (15:07 +0000)
committerfps <fps@opencascade.com>
Mon, 9 Sep 2013 15:07:57 +0000 (15:07 +0000)
add more tests

18 files changed:
src/XAO/XAO_BrepGeometry.cxx
src/XAO/XAO_BrepGeometry.hxx
src/XAO/XAO_GeometricElement.cxx
src/XAO/XAO_GeometricElement.hxx
src/XAO/XAO_Step.cxx
src/XAO/XAO_Step.hxx
src/XAO/XAO_Xao.cxx
src/XAO/XAO_Xao.hxx
src/XAO/XAO_XaoExporter.cxx
src/XAO/XAO_XaoUtils.hxx
src/XAO/tests/BrepGeometryTest.cxx
src/XAO/tests/BrepGeometryTest.hxx
src/XAO/tests/FieldTest.cxx
src/XAO/tests/FieldTest.hxx
src/XAO/tests/GeometryTest.cxx
src/XAO/tests/GeometryTest.hxx
src/XAO/tests/Makefile.am
src/XAO/tests/XAOTests.cxx

index 29cbd514b741765026a6ba2ea18969ed2c8aea29..a95c84ed0f8854f98d58a1741b561e2586f10259 100644 (file)
@@ -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<int> 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<int>::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<int> 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);
 }
 
index 923520cf3be0c3d853b2e9067d20357aad4acda0..16561b8a35569bfe48af2a5ae921286807f220ac 100644 (file)
@@ -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<int> 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;
index a0f39600bbdfa7909e6556e135a25f1b98685e86..3d5c6233ab83937c4803f4ad53f2dc8ace30e365 100644 (file)
@@ -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);
 }
 
index a2be162dbb0c4531256f0f4ca7605eafd84217ae..cb374acc0efcbad415d508f93de0f330eecf4e56 100644 (file)
@@ -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<int, GeometricElement> m_elements;
index e14eb7004b8a8287933a3d0d228da2d59675e5d7..a337f57ac9867e5e65b2ef843e80373c5681c107 100644 (file)
 
 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)
index c588d164aa01d955764b45137b0c78d8c3ba1f81..4ebf27a55b205085947754ab963700a08ac6a7c1 100644 (file)
@@ -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.
          */
index 95923aa6742a34a77a812ed69b074d1e9826e070..b1d469844d7cb6b633333f64dd64059458b88603 100644 (file)
@@ -71,6 +71,8 @@ const int Xao::countGroups() const
 
 Group* Xao::getGroup(const int& index)
 {
+    checkGroupIndex(index);
+
     int i = 0;
     for (std::list<Group*>::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<Field*>::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);
+}
index 7c092be2a4596d21b4d87d0c3a79d12d8bab8e65..b96d2774ac5de5435e4ef402ef25c1368fed8b80 100644 (file)
@@ -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. */
index 65e84247bcb67963ed156bcb2610a27b93888cbb..1a909d107fe5f74ee46191834c961704bee7f1f8 100644 (file)
@@ -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());
         }
     }
index 06e43f629fe9db3e797fa586c7b0fb0d273c13e0..c9088a636aec060f2bde3effc2067b2d175d524e 100644 (file)
@@ -129,6 +129,7 @@ namespace XAO
     {
     public:
         MsgBuilder() {};
+        ~MsgBuilder() {};
 
         template <typename T>
         MsgBuilder& operator <<(const T& t)
index ef8a524aaf1c85007db0ccc93aa2ac69d5a695af..3dd1c2b0772de7cb619115b02e885ab62475a04d 100644 (file)
@@ -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");
index bb4b057a33e312cdecbde43aca21336a5a9baa3d..d74b63ce0ba9be5288211f001c841cf0a4c65590 100644 (file)
@@ -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();
index caf2b38eedcd3d275135fab0fe303d93393c59c3..bed396ede170700141b40826ecab7e75cd7c19e6 100644 (file)
@@ -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<bool> 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)
index babf12df122ae4824c7835c471ac9fbc45ae834c..9a4a8d82da34158c12ba26ce7c78783118b7e266 100644 (file)
@@ -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();
index cae08b67cc7d54f71c459f2a51a3cfe75fdbf8a3..797b68217a14d1436ed5f4fe470091b70164957c 100644 (file)
@@ -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;
+}
index 4cac2c91c2ba4b58e91b685538c018cbb88826e1..63ad244fff35d8a18c9eb6dc5cfc9ffeed7b4019 100644 (file)
@@ -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();
     };
 }
 
index 1c406443cd130a66974b4492a349eefc1683c015..d2d7de20584ef72a8e15dadfedc1515c9c242e28 100755 (executable)
@@ -43,6 +43,7 @@ dist_TestXAO_SOURCES = \
     GeometryTest.cxx \
     ImportExportTest.cxx \
     BrepGeometryTest.cxx \
+    XaoTest.cxx \
     XAOTests.cxx
 
 UNIT_TEST_PROG = TestXAO
index 0238e7f9b4d5f9cefcf2e3f72259089b968d8ef8..baef3d19d27857113a0ef299a2f09ad0fc71b1de 100644 (file)
@@ -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"