]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
more tests
authorfps <fps@opencascade.com>
Wed, 4 Sep 2013 16:08:50 +0000 (16:08 +0000)
committerfps <fps@opencascade.com>
Wed, 4 Sep 2013 16:08:50 +0000 (16:08 +0000)
13 files changed:
src/XAO/BooleanStep.cxx
src/XAO/Field.cxx
src/XAO/Step.cxx
src/XAO/XaoUtils.cxx
src/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/Makefile.am
src/XAO/tests/XAOTests.cxx
src/XAO/tests/XaoUtilsTest.cxx [new file with mode: 0644]
src/XAO/tests/XaoUtilsTest.hxx [new file with mode: 0644]

index 91582499569bc402e80a13345818cc596b51c1d1..02c2f2960ba8b6146caef45a380b087201320590 100644 (file)
@@ -107,7 +107,7 @@ const bool BooleanStep::getValue(const int& element, const int& component)
 
 const std::string BooleanStep::getStringValue(const int& element, const int& component)
 {
-    return (getValue(element, component) ? "true" : "false");
+    return XaoUtils::booleanToString(getValue(element, component));
 }
 
 void BooleanStep::setValues(const std::vector<bool>& values)
@@ -126,7 +126,7 @@ void BooleanStep::setValues(const std::vector<bool>& values)
 void BooleanStep::setElements(const int& element, const std::vector<bool>& elements)
 {
     checkElementIndex(element);
-    checkNbElements((int)elements.size());
+    checkNbComponents(elements.size());
 
     for (int i = 0; i < m_nbComponents; ++i)
         m_values[element][i] = elements[i];
@@ -135,7 +135,7 @@ void BooleanStep::setElements(const int& element, const std::vector<bool>& eleme
 void BooleanStep::setComponents(const int& component, const std::vector<bool>& components)
 {
     checkComponentIndex(component);
-    checkNbElements((int)components.size());
+    checkNbElements(components.size());
 
     for (int i = 0; i < m_nbElements; ++i)
         m_values[i][component] = components[i];
@@ -151,8 +151,5 @@ void BooleanStep::setValue(const int& element, const int& component, const bool&
 
 void BooleanStep::setStringValue(const int& element, const int& component, const std::string& value)
 {
-    if (value != "true" && value != "false")
-        throw SALOME_Exception(MsgBuilder() << "Bad boolean value: " << value);
-
-    setValue(element, component, value == "true");
+    setValue(element, component, XaoUtils::stringToBoolean(value));
 }
index 010f974214fbe10e0fa50cf6feffb6f60143a1e0..6368c4ef415d0db09d3360ff785f973136764a58 100644 (file)
@@ -67,7 +67,7 @@ Field* Field::createField(const XAO::Type& type, const std::string& name, const
     if (type == XAO::STRING)
         return new StringField(name, dimension, nbElements, nbComponents);
 
-    throw SALOME_Exception(MsgBuilder() << "Bad Type:" << type);
+    throw SALOME_Exception(MsgBuilder() << "Bad Type: " << type);
 }
 
 const std::string Field::getComponentName(const int& index)
@@ -104,7 +104,7 @@ void Field::checkComponent(const int& component)
         return;
 
     throw SALOME_Exception(MsgBuilder() << "Step index is out of range [0, "
-                                        << m_nbComponents << "] : " << component);
+                                        << m_nbComponents << "]: " << component);
 }
 
 void Field::checkStepIndex(const int& step)
@@ -113,5 +113,5 @@ void Field::checkStepIndex(const int& step)
         return;
 
     throw SALOME_Exception(MsgBuilder() << "Step index is out of range [0, "
-                                        << m_steps.size() << "] : " << step);
+                                        << m_steps.size() << "]: " << step);
 }
index f7ab052a7be72a0e29ef93e5447d210b7fdc2900..bbc2decd952858d15110c5d99a33a1ce084726b1 100644 (file)
@@ -50,7 +50,7 @@ void Step::checkElementIndex(const int& element)
         return;
 
     throw SALOME_Exception(MsgBuilder() << "Element index is out of range [0, "
-                                        << m_nbElements-1 << "] : " << element);
+                                        << m_nbElements-1 << "]: " << element);
 }
 
 void Step::checkComponentIndex(const int& component)
@@ -59,7 +59,7 @@ void Step::checkComponentIndex(const int& component)
         return;
 
     throw SALOME_Exception(MsgBuilder() << "Component index is out of range [0, "
-                                        << m_nbComponents-1 << "] : " << component);
+                                        << m_nbComponents-1 << "]: " << component);
 }
 
 void Step::checkNbElements(const int& nbElements)
@@ -67,7 +67,7 @@ void Step::checkNbElements(const int& nbElements)
     if (nbElements == m_nbElements)
         return;
 
-    throw SALOME_Exception(MsgBuilder() << "Invalid number of elements:" << nbElements
+    throw SALOME_Exception(MsgBuilder() << "Invalid number of elements: " << nbElements
                                         << ", expected " << m_nbElements);
 }
 
@@ -76,7 +76,7 @@ void Step::checkNbComponents(const int& nbComponents)
     if (nbComponents == m_nbComponents)
         return;
 
-    throw SALOME_Exception(MsgBuilder() << "Invalid number of components:" << nbComponents
+    throw SALOME_Exception(MsgBuilder() << "Invalid number of components: " << nbComponents
                                         << ", expected " << m_nbComponents);
 }
 
index 31d6f71c859d08773bd83dc7b199c540481a359b..f0952140bcf87a20d39ffbbdff2f3123dbc20f9a 100644 (file)
@@ -41,7 +41,7 @@ const int XaoUtils::stringToInt(const std::string& value)
     int res;
     std::istringstream convert(value);
     if ( !(convert >> res) )
-        res = 0;
+        throw SALOME_Exception(MsgBuilder() << "Cannot convert '" << value << "' to integer.");
     return res;
 }
 
@@ -57,10 +57,22 @@ const double XaoUtils::stringToDouble(const std::string& value)
     double res;
     std::istringstream convert(value);
     if ( !(convert >> res) )
-        res = 0;
+        throw SALOME_Exception(MsgBuilder() << "Cannot convert '" << value << "' to double.");
     return res;
 }
 
+const std::string XaoUtils::booleanToString(const bool& value)
+{
+    if (value)
+        return "true";
+    return "false";
+}
+
+const bool XaoUtils::stringToBoolean(const std::string& value)
+{
+    return (value == std::string("true"));
+}
+
 const std::string XaoUtils::dimensionToString(const XAO::Dimension& dimension)
 {
     if (dimension == XAO::VERTEX)
index 4b5f5b11f11f78720bcf32b49f147599378e45f4..a626c5a1b50157791db3d021b7f9537380bf7769 100644 (file)
@@ -42,11 +42,40 @@ namespace XAO
          * \return the string.
          */
         static const std::string intToString(const int& value);
+
+        /**
+         * Converts a string into an integer.
+         * \param value the string to convert.
+         * \return the integer value.
+         */
         static const int stringToInt(const std::string& value);
 
+        /**
+         * Converts a double into a string.
+         * @param value the double to convert.
+         * @return the string.
+         */
         static const std::string doubleToString(const double& value);
+        /**
+         * Converts a string into a double.
+         * @param value the string to convert.
+         * @return the double value.
+         */
         static const double stringToDouble(const std::string& value);
 
+        /**
+         * Converts a boolean into a string.
+         * @param value the boolean to convert.
+         * @return the string.
+         */
+        static const std::string booleanToString(const bool& value);
+        /**
+         * Converts a string into a boolean.
+         * @param value the string to convert.
+         * @return the boolean value.
+         */
+        static const bool stringToBoolean(const std::string& value);
+
         /**
          * Converts a Dimension to string.
          * \param dimension the Dimension to convert.
index ae60a3de1599a9dcfced385d300ce33b6f26309b..883454a4c155fa9f9c16b591fedf703038b3ad7b 100644 (file)
@@ -31,23 +31,67 @@ void BrepGeometryTest::testGetIDs()
     BrepGeometry* geom = new BrepGeometry("box");
     readBrep(geom, "Box_1.brep");
 
+    CPPUNIT_ASSERT_EQUAL(8, geom->countElements(XAO::VERTEX));
+    CPPUNIT_ASSERT_EQUAL(8, geom->countVertices());
     int vertices[8] = { 6,7,9,11,16,17,19,21 };
     for (int i = 0; i < 8; ++i)
         CPPUNIT_ASSERT_EQUAL(vertices[i], geom->getVertexID(i));
 
+    CPPUNIT_ASSERT_EQUAL(12, geom->countElements(XAO::EDGE));
+    CPPUNIT_ASSERT_EQUAL(12, geom->countEdges());
     int edges[12] = { 5,8,10,12,15,18,20,22,25,26,29,30 };
     for (int i = 0; i < 12; ++i)
         CPPUNIT_ASSERT_EQUAL(edges[i], geom->getEdgeID(i));
 
+    CPPUNIT_ASSERT_EQUAL(6, geom->countElements(XAO::FACE));
+    CPPUNIT_ASSERT_EQUAL(6, geom->countFaces());
     int faces[6] = { 3,13,23,27,31,33 };
     for (int i = 0; i < 6; ++i)
         CPPUNIT_ASSERT_EQUAL(faces[i], geom->getFaceID(i));
 
+    CPPUNIT_ASSERT_EQUAL(1, geom->countElements(XAO::SOLID));
+    CPPUNIT_ASSERT_EQUAL(1, geom->countSolids());
     CPPUNIT_ASSERT_EQUAL(1, geom->getSolidID(0));
 
     delete geom;
 }
 
+void BrepGeometryTest::testGetReferences()
+{
+    BrepGeometry* geom = new BrepGeometry("box");
+    readBrep(geom, "Box_1.brep");
+
+    // vertex of index 1 has id = 7
+    CPPUNIT_ASSERT_EQUAL(std::string("7"), geom->getElementReference(XAO::VERTEX, 1));
+    CPPUNIT_ASSERT_EQUAL(std::string("7"), geom->getVertexReference(1));
+    CPPUNIT_ASSERT_EQUAL(7, geom->getVertexID(1));
+    CPPUNIT_ASSERT_EQUAL(1, geom->getElementIndexByReference(XAO::VERTEX, "7"));
+    CPPUNIT_ASSERT_EQUAL(1, geom->findVertex(7));
+
+    // edge of index 1 has id = 8
+    CPPUNIT_ASSERT_EQUAL(std::string("8"), geom->getElementReference(XAO::EDGE, 1));
+    CPPUNIT_ASSERT_EQUAL(std::string("8"), geom->getEdgeReference(1));
+    CPPUNIT_ASSERT_EQUAL(8, geom->getEdgeID(1));
+    CPPUNIT_ASSERT_EQUAL(1, geom->getElementIndexByReference(XAO::EDGE, "8"));
+    CPPUNIT_ASSERT_EQUAL(1, geom->findEdge(8));
+
+    // face of index 1 has id = 13
+    CPPUNIT_ASSERT_EQUAL(std::string("13"), geom->getElementReference(XAO::FACE, 1));
+    CPPUNIT_ASSERT_EQUAL(std::string("13"), geom->getFaceReference(1));
+    CPPUNIT_ASSERT_EQUAL(13, geom->getFaceID(1));
+    CPPUNIT_ASSERT_EQUAL(1, geom->getElementIndexByReference(XAO::FACE, "13"));
+    CPPUNIT_ASSERT_EQUAL(1, geom->findFace(13));
+
+    // solid of index 0 has id = 1
+    CPPUNIT_ASSERT_EQUAL(std::string("1"), geom->getElementReference(XAO::SOLID, 0));
+    CPPUNIT_ASSERT_EQUAL(std::string("1"), geom->getSolidReference(0));
+    CPPUNIT_ASSERT_EQUAL(1, geom->getSolidID(0));
+    CPPUNIT_ASSERT_EQUAL(0, geom->getElementIndexByReference(XAO::SOLID, "1"));
+    CPPUNIT_ASSERT_EQUAL(0, geom->findSolid(1));
+
+    delete geom;
+}
+
 void BrepGeometryTest::testGetEdgeVertices()
 {
     BrepGeometry* geom = new BrepGeometry("box");
index 1f1c37122313a19782111ccd677b94241e6e7336..a3810268dbc0c6d96d4e6e38f175104ddab612b9 100644 (file)
@@ -11,6 +11,7 @@ namespace XAO
     {
         CPPUNIT_TEST_SUITE(BrepGeometryTest);
         CPPUNIT_TEST(testGetIDs);
+        CPPUNIT_TEST(testGetReferences);
         CPPUNIT_TEST(testGetEdgeVertices);
         CPPUNIT_TEST(testGetFaceWires);
         CPPUNIT_TEST(testSolidShells);
@@ -26,6 +27,7 @@ namespace XAO
         void cleanUp();
 
         void testGetIDs();
+        void testGetReferences();
         void testGetEdgeVertices();
         void testGetFaceWires();
         void testSolidShells();
index 2f9d82b4824d5dce0325ca5cfbfbfdac1d048b6e..3e0e3cc969dda2f6a528c7b04fd2dc33af074f58 100644 (file)
@@ -3,9 +3,13 @@
 
 #include "FieldTest.hxx"
 #include "../Xao.hxx"
+#include "../XaoUtils.hxx"
 #include "../Field.hxx"
 #include "../Step.hxx"
-#include "../IntegerStep.hxx"
+#include "../BooleanField.hxx"
+#include "../IntegerField.hxx"
+#include "../DoubleField.hxx"
+#include "../StringField.hxx"
 
 using namespace XAO;
 
@@ -22,7 +26,7 @@ void FieldTest::cleanUp()
 {
 }
 
-void FieldTest::testField(XAO::Type type)
+Field* FieldTest::testField(XAO::Type type)
 {
     Field* f = Field::createField(type, XAO::FACE, 10, 3);
 
@@ -46,23 +50,73 @@ void FieldTest::testField(XAO::Type type)
     CPPUNIT_ASSERT_EQUAL(std::string("z"), f->getComponentName(2));
     CPPUNIT_ASSERT_THROW(f->setComponentName(3, "a"), SALOME_Exception);
     CPPUNIT_ASSERT_THROW(f->getComponentName(3), SALOME_Exception);
+
+    CPPUNIT_ASSERT_EQUAL(0, f->countSteps());
+    Step* step = f->addNewStep(0);
+    CPPUNIT_ASSERT_EQUAL(1, f->countSteps());
+    step = f->addNewStep(1);
+    step = f->addNewStep(2);
+    CPPUNIT_ASSERT_EQUAL(3, f->countSteps());
+
+    CPPUNIT_ASSERT_EQUAL(true, f->removeStep(step));
+    CPPUNIT_ASSERT_EQUAL(2, f->countSteps());
+    CPPUNIT_ASSERT_EQUAL(false, f->removeStep(step)); // remove same
+    CPPUNIT_ASSERT_EQUAL(2, f->countSteps());
+
+    return f;
 }
 
 void FieldTest::testBooleanField()
 {
-    testField(XAO::BOOLEAN);
+    BooleanField* f = (BooleanField*)testField(XAO::BOOLEAN);
+
+    BooleanStep* step = f->getStep(0);
+    CPPUNIT_ASSERT_EQUAL(XAO::BOOLEAN, step->getType());
+    CPPUNIT_ASSERT_MESSAGE("step is NULL", step != NULL);
+    CPPUNIT_ASSERT_THROW(f->getStep(2), SALOME_Exception);
+
+    step = f->addStep(10);
+    CPPUNIT_ASSERT_EQUAL(XAO::BOOLEAN, step->getType());
+    CPPUNIT_ASSERT_EQUAL(3, f->countSteps());
 }
 void FieldTest::testIntegerField()
 {
-    testField(XAO::INTEGER);
+    IntegerField* f = (IntegerField*)testField(XAO::INTEGER);
+
+    IntegerStep* step = f->getStep(0);
+    CPPUNIT_ASSERT_EQUAL(XAO::INTEGER, step->getType());
+    CPPUNIT_ASSERT_MESSAGE("step is NULL", step != NULL);
+    CPPUNIT_ASSERT_THROW(f->getStep(2), SALOME_Exception);
+
+    step = f->addStep(10);
+    CPPUNIT_ASSERT_EQUAL(XAO::INTEGER, step->getType());
+    CPPUNIT_ASSERT_EQUAL(3, f->countSteps());
 }
 void FieldTest::testDoubleField()
 {
-    testField(XAO::DOUBLE);
+    DoubleField* f = (DoubleField*)testField(XAO::DOUBLE);
+
+    DoubleStep* step = f->getStep(0);
+    CPPUNIT_ASSERT_EQUAL(XAO::DOUBLE, step->getType());
+    CPPUNIT_ASSERT_MESSAGE("step is NULL", step != NULL);
+    CPPUNIT_ASSERT_THROW(f->getStep(2), SALOME_Exception);
+
+    step = f->addStep(10);
+    CPPUNIT_ASSERT_EQUAL(XAO::DOUBLE, step->getType());
+    CPPUNIT_ASSERT_EQUAL(3, f->countSteps());
 }
 void FieldTest::testStringField()
 {
-    testField(XAO::STRING);
+    StringField* f = (StringField*)testField(XAO::STRING);
+
+    StringStep* step = f->getStep(0);
+    CPPUNIT_ASSERT_EQUAL(XAO::STRING, step->getType());
+    CPPUNIT_ASSERT_MESSAGE("step is NULL", step != NULL);
+    CPPUNIT_ASSERT_THROW(f->getStep(2), SALOME_Exception);
+
+    step = f->addStep(10);
+    CPPUNIT_ASSERT_EQUAL(XAO::STRING, step->getType());
+    CPPUNIT_ASSERT_EQUAL(3, f->countSteps());
 }
 
 void FieldTest::testStep(XAO::Type type)
@@ -100,25 +154,103 @@ void FieldTest::testStringStep()
     testStep(XAO::STRING);
 }
 
+void FieldTest::testBooleanStepValues()
+{
+    int nbComponents = 3; // > 1
+    int nbElements = 5;   // > 1
+
+    BooleanStep* step = (BooleanStep*)Step::createStep(XAO::BOOLEAN, 0, 0, nbElements, nbComponents);
+    for (int i = 0; i < step->countElements(); ++i)
+    {
+        for (int j = 0; j < step->countComponents(); ++j)
+        {
+            step->setValue(i, j, j % 2 == 0);
+        }
+    }
+
+    CPPUNIT_ASSERT_EQUAL(true, step->getValue(1, 2));
+    CPPUNIT_ASSERT_EQUAL(std::string("true"), step->getStringValue(1, 2));
+    CPPUNIT_ASSERT_THROW(step->getValue(nbElements, 2), SALOME_Exception);
+    CPPUNIT_ASSERT_THROW(step->getValue(1, nbComponents), SALOME_Exception);
+
+    // get all values
+    std::vector<bool> values;
+    values = step->getValues();
+    CPPUNIT_ASSERT_EQUAL(nbElements*nbComponents, (int)values.size());
+    for (int i = 0; i < nbElements; ++i)
+    {
+        for (int j = 0; j < nbComponents; ++j)
+            CPPUNIT_ASSERT((j % 2 == 0) == values[i*nbComponents+j]);
+    }
+
+    // get one element
+    values = step->getElement(2);
+    CPPUNIT_ASSERT_THROW(step->getElement(nbElements), SALOME_Exception);
+    CPPUNIT_ASSERT_EQUAL(nbComponents, (int)values.size());
+    for (int i = 0; i < nbComponents; ++i)
+        CPPUNIT_ASSERT((i % 2 == 0) == values[i]);
+
+    // get one component
+    values = step->getComponent(1);
+    CPPUNIT_ASSERT_THROW(step->getComponent(nbComponents), SALOME_Exception);
+    CPPUNIT_ASSERT_EQUAL(nbElements, (int)values.size());
+    for (int i = 0; i < nbElements; ++i)
+        CPPUNIT_ASSERT(false == values[i]);
+
+    // set one element
+    std::vector<bool> newEltValues;
+    // only one value
+    newEltValues.push_back(true);
+    CPPUNIT_ASSERT_THROW(step->setElements(2, newEltValues), SALOME_Exception);
+    // all values
+    for (int i = 1; i < nbComponents; ++i)
+        newEltValues.push_back(true);
+    step->setElements(2, newEltValues);
+
+    // set one component
+    std::vector<bool> newCompValues;
+    // only one value
+    newCompValues.push_back(true);
+    CPPUNIT_ASSERT_THROW(step->setComponents(1, newCompValues), SALOME_Exception);
+    // all values
+    for (int i = 1; i < nbElements; ++i)
+        newCompValues.push_back(true);
+    step->setComponents(1, newCompValues);
+
+    // set string value
+    step->setStringValue(0, 0, "true");
+    CPPUNIT_ASSERT_NO_THROW(step->setStringValue(0, 0, "aa")); // set false
+
+    // set all values
+    std::vector<bool> allValues;
+    // only one value
+    allValues.push_back(true);
+    CPPUNIT_ASSERT_THROW(step->setValues(allValues), SALOME_Exception);
+    // all values
+    for (int i = 1; i < nbElements*nbComponents; ++i)
+        allValues.push_back(true);
+    step->setValues(allValues);
+}
+
 void FieldTest::testIntegerStepValues()
 {
     int nbComponents = 3;
     int nbElements = 5;
 
-    IntegerStep* istep = (IntegerStep*)Step::createStep(XAO::INTEGER, 0, 0, nbElements, nbComponents);
-    for (int i = 0; i < istep->countElements(); ++i)
+    IntegerStep* step = (IntegerStep*)Step::createStep(XAO::INTEGER, 0, 0, nbElements, nbComponents);
+    for (int i = 0; i < step->countElements(); ++i)
     {
-        for (int j = 0; j < istep->countComponents(); ++j)
-            istep->setValue(i, j, i*10 + j);
+        for (int j = 0; j < step->countComponents(); ++j)
+            step->setValue(i, j, i*10 + j);
     }
 
-    CPPUNIT_ASSERT_EQUAL(12, istep->getValue(1, 2));
-    CPPUNIT_ASSERT_THROW(istep->getValue(nbElements, 2), SALOME_Exception);
-    CPPUNIT_ASSERT_THROW(istep->getValue(1, nbComponents), SALOME_Exception);
+    CPPUNIT_ASSERT_EQUAL(12, step->getValue(1, 2));
+    CPPUNIT_ASSERT_THROW(step->getValue(nbElements, 2), SALOME_Exception);
+    CPPUNIT_ASSERT_THROW(step->getValue(1, nbComponents), SALOME_Exception);
 
     // get all values
     std::vector<int> values;
-    values = istep->getValues();
+    values = step->getValues();
     CPPUNIT_ASSERT_EQUAL(nbElements*nbComponents, (int)values.size());
     for (int i = 0; i < nbElements; ++i)
     {
@@ -127,15 +259,15 @@ void FieldTest::testIntegerStepValues()
     }
 
     // get one element
-    values = istep->getElement(2);
-    CPPUNIT_ASSERT_THROW(istep->getElement(nbElements), SALOME_Exception);
+    values = step->getElement(2);
+    CPPUNIT_ASSERT_THROW(step->getElement(nbElements), SALOME_Exception);
     CPPUNIT_ASSERT_EQUAL(nbComponents, (int)values.size());
     for (int i = 0; i < nbComponents; ++i)
         CPPUNIT_ASSERT_EQUAL(20+i, values[i]);
 
     // get one component
-    values = istep->getComponent(1);
-    CPPUNIT_ASSERT_THROW(istep->getComponent(nbComponents), SALOME_Exception);
+    values = step->getComponent(1);
+    CPPUNIT_ASSERT_THROW(step->getComponent(nbComponents), SALOME_Exception);
     CPPUNIT_ASSERT_EQUAL(nbElements, (int)values.size());
     for (int i = 0; i < nbElements; ++i)
         CPPUNIT_ASSERT_EQUAL(10*i+1, values[i]);
@@ -143,18 +275,168 @@ void FieldTest::testIntegerStepValues()
     // set one element
     std::vector<int> newEltValues;
     newEltValues.push_back(1);
-    CPPUNIT_ASSERT_THROW(istep->setElements(2, newEltValues), SALOME_Exception);
+    CPPUNIT_ASSERT_THROW(step->setElements(2, newEltValues), SALOME_Exception);
     for (int i = 1; i < nbComponents; ++i)
         newEltValues.push_back(1);
-    istep->setElements(2, newEltValues);
+    step->setElements(2, newEltValues);
 
     // set one component
     std::vector<int> newCompValues;
     newCompValues.push_back(100);
-    CPPUNIT_ASSERT_THROW(istep->setComponents(1, newCompValues), SALOME_Exception);
+    CPPUNIT_ASSERT_THROW(step->setComponents(1, newCompValues), SALOME_Exception);
     for (int i = 1; i < nbElements; ++i)
         newCompValues.push_back(100);
-    istep->setComponents(1, newCompValues);
+    step->setComponents(1, newCompValues);
+
+    // set string value
+    step->setStringValue(0, 0, "0");
+    CPPUNIT_ASSERT_THROW(step->setStringValue(0, 0, "aa"), SALOME_Exception);
+
+    // set all values
+    std::vector<int> allValues;
+    // only one value
+    allValues.push_back(11);
+    CPPUNIT_ASSERT_THROW(step->setValues(allValues), SALOME_Exception);
+    // all values
+    for (int i = 1; i < nbElements*nbComponents; ++i)
+        allValues.push_back(11);
+    step->setValues(allValues);
 }
 
+void FieldTest::testDoubleStepValues()
+{
+    int nbComponents = 3;
+    int nbElements = 5;
+
+    DoubleStep* step = (DoubleStep*)Step::createStep(XAO::DOUBLE, 0, 0, nbElements, nbComponents);
+    for (int i = 0; i < step->countElements(); ++i)
+    {
+        for (int j = 0; j < step->countComponents(); ++j)
+            step->setValue(i, j, i*10 + j*0.1);
+    }
+
+    CPPUNIT_ASSERT_EQUAL(10.2, step->getValue(1, 2));
+    CPPUNIT_ASSERT_THROW(step->getValue(nbElements, 2), SALOME_Exception);
+    CPPUNIT_ASSERT_THROW(step->getValue(1, nbComponents), SALOME_Exception);
+
+    // get all values
+    std::vector<double> values;
+    values = step->getValues();
+    CPPUNIT_ASSERT_EQUAL(nbElements*nbComponents, (int)values.size());
+    for (int i = 0; i < nbElements; ++i)
+    {
+        for (int j = 0; j < nbComponents; ++j)
+            CPPUNIT_ASSERT_EQUAL(10*i+j*0.1, values[i*nbComponents+j]);
+    }
+
+    // get one element
+    values = step->getElement(2);
+    CPPUNIT_ASSERT_THROW(step->getElement(nbElements), SALOME_Exception);
+    CPPUNIT_ASSERT_EQUAL(nbComponents, (int)values.size());
+    for (int i = 0; i < nbComponents; ++i)
+        CPPUNIT_ASSERT_EQUAL(20+i*0.1, values[i]);
+
+    // get one component
+    values = step->getComponent(1);
+    CPPUNIT_ASSERT_THROW(step->getComponent(nbComponents), SALOME_Exception);
+    CPPUNIT_ASSERT_EQUAL(nbElements, (int)values.size());
+    for (int i = 0; i < nbElements; ++i)
+        CPPUNIT_ASSERT_EQUAL(10*i+0.1, values[i]);
+
+    // set one element
+    std::vector<double> newEltValues;
+    newEltValues.push_back(1.);
+    CPPUNIT_ASSERT_THROW(step->setElements(2, newEltValues), SALOME_Exception);
+    for (int i = 1; i < nbComponents; ++i)
+        newEltValues.push_back(1.);
+    step->setElements(2, newEltValues);
+
+    // set one component
+    std::vector<double> newCompValues;
+    newCompValues.push_back(100.0);
+    CPPUNIT_ASSERT_THROW(step->setComponents(1, newCompValues), SALOME_Exception);
+    for (int i = 1; i < nbElements; ++i)
+        newCompValues.push_back(100.0);
+    step->setComponents(1, newCompValues);
+
+    // set string value
+    step->setStringValue(0, 0, "0.2");
+    CPPUNIT_ASSERT_THROW(step->setStringValue(0, 0, "aa"), SALOME_Exception);
+
+    std::vector<double> allValues;
+    // only one value
+    allValues.push_back(1.1);
+    CPPUNIT_ASSERT_THROW(step->setValues(allValues), SALOME_Exception);
+    // all values
+    for (int i = 1; i < nbElements*nbComponents; ++i)
+        allValues.push_back(1.1);
+    step->setValues(allValues);}
+
+void FieldTest::testStringStepValues()
+{
+    int nbComponents = 3;
+    int nbElements = 5;
+
+    StringStep* step = (StringStep*)Step::createStep(XAO::STRING, 0, 0, nbElements, nbComponents);
+    for (int i = 0; i < step->countElements(); ++i)
+    {
+        for (int j = 0; j < step->countComponents(); ++j)
+            step->setValue(i, j, XaoUtils::intToString(i*10 + j));
+    }
+
+    CPPUNIT_ASSERT_EQUAL(std::string("12"), step->getValue(1, 2));
+    CPPUNIT_ASSERT_THROW(step->getValue(nbElements, 2), SALOME_Exception);
+    CPPUNIT_ASSERT_THROW(step->getValue(1, nbComponents), SALOME_Exception);
+
+    // get all values
+    std::vector<std::string> values;
+    values = step->getValues();
+    CPPUNIT_ASSERT_EQUAL(nbElements*nbComponents, (int)values.size());
+    for (int i = 0; i < nbElements; ++i)
+    {
+        for (int j = 0; j < nbComponents; ++j)
+            CPPUNIT_ASSERT_EQUAL(XaoUtils::intToString(10*i+j), values[i*nbComponents+j]);
+    }
+
+    // get one element
+    values = step->getElement(2);
+    CPPUNIT_ASSERT_THROW(step->getElement(nbElements), SALOME_Exception);
+    CPPUNIT_ASSERT_EQUAL(nbComponents, (int)values.size());
+    for (int i = 0; i < nbComponents; ++i)
+        CPPUNIT_ASSERT_EQUAL(XaoUtils::intToString(20+i), values[i]);
+
+    // get one component
+    values = step->getComponent(1);
+    CPPUNIT_ASSERT_THROW(step->getComponent(nbComponents), SALOME_Exception);
+    CPPUNIT_ASSERT_EQUAL(nbElements, (int)values.size());
+    for (int i = 0; i < nbElements; ++i)
+        CPPUNIT_ASSERT_EQUAL(XaoUtils::intToString(10*i+1), values[i]);
+
+    // set one element
+    std::vector<std::string> newEltValues;
+    newEltValues.push_back("1");
+    CPPUNIT_ASSERT_THROW(step->setElements(2, newEltValues), SALOME_Exception);
+    for (int i = 1; i < nbComponents; ++i)
+        newEltValues.push_back("1");
+    step->setElements(2, newEltValues);
+
+    // set one component
+    std::vector<std::string> newCompValues;
+    newCompValues.push_back("100");
+    CPPUNIT_ASSERT_THROW(step->setComponents(1, newCompValues), SALOME_Exception);
+    for (int i = 1; i < nbElements; ++i)
+        newCompValues.push_back("100");
+    step->setComponents(1, newCompValues);
+
+    // set string value
+    std::cout << "set string value" << std::endl;
+    step->setStringValue(0, 0, "0");
 
+    std::vector<std::string> allValues;
+    // only one value
+    allValues.push_back("abc");
+    CPPUNIT_ASSERT_THROW(step->setValues(allValues), SALOME_Exception);
+    // all values
+    for (int i = 1; i < nbElements*nbComponents; ++i)
+        allValues.push_back("abc");
+    step->setValues(allValues);}
index 5a5d13bc561271fe947ca9b4ff4ee6a66d7343ce..e7b19bcc91d478e5c34b7ea42f7ce0059bfe9ed1 100644 (file)
@@ -18,7 +18,10 @@ namespace XAO
         CPPUNIT_TEST(testIntegerStep);
         CPPUNIT_TEST(testDoubleStep);
         CPPUNIT_TEST(testStringStep);
+        CPPUNIT_TEST(testBooleanStepValues);
         CPPUNIT_TEST(testIntegerStepValues);
+        CPPUNIT_TEST(testDoubleStepValues);
+        CPPUNIT_TEST(testStringStepValues);
         CPPUNIT_TEST_SUITE_END();
 
     public:
@@ -26,7 +29,7 @@ namespace XAO
         void tearDown();
         void cleanUp();
 
-        void testField(XAO::Type type);
+        Field* testField(XAO::Type type);
         void testBooleanField();
         void testIntegerField();
         void testDoubleField();
@@ -38,7 +41,10 @@ namespace XAO
         void testDoubleStep();
         void testStringStep();
 
+        void testBooleanStepValues();
         void testIntegerStepValues();
+        void testDoubleStepValues();
+        void testStringStepValues();
     };
 }
 
index dbdec080ab62ce7941b36f6848d524c9364f52cf..6fe1b32740ba14fc5d4183a7510b632f7ba35005 100755 (executable)
@@ -39,6 +39,7 @@ TestXAO_LDFLAGS = \
     ../libXAO.la
 
 dist_TestXAO_SOURCES = \
+    XaoUtilsTest.cxx \
     GroupTest.cxx \
     FieldTest.cxx \
     GeometryTest.cxx \
index 832e4cd602e1e5f6d941cade0337d30693ed2861..0238e7f9b4d5f9cefcf2e3f72259089b968d8ef8 100644 (file)
@@ -1,9 +1,11 @@
+#include "XaoUtilsTest.hxx"
 #include "GroupTest.hxx"
 #include "FieldTest.hxx"
 #include "GeometryTest.hxx"
 #include "ImportExportTest.hxx"
 #include "BrepGeometryTest.hxx"
 
+CPPUNIT_TEST_SUITE_REGISTRATION(XAO::XaoUtilsTest);
 CPPUNIT_TEST_SUITE_REGISTRATION(XAO::GroupTest);
 CPPUNIT_TEST_SUITE_REGISTRATION(XAO::FieldTest);
 CPPUNIT_TEST_SUITE_REGISTRATION(XAO::GeometryTest);
diff --git a/src/XAO/tests/XaoUtilsTest.cxx b/src/XAO/tests/XaoUtilsTest.cxx
new file mode 100644 (file)
index 0000000..92e8f2f
--- /dev/null
@@ -0,0 +1,78 @@
+#include <Utils_SALOME_Exception.hxx>
+
+#include "XaoUtilsTest.hxx"
+#include "../Xao.hxx"
+#include "../XaoUtils.hxx"
+
+using namespace XAO;
+
+
+void XaoUtilsTest::setUp()
+{
+}
+
+void XaoUtilsTest::tearDown()
+{
+}
+
+void XaoUtilsTest::cleanUp()
+{
+}
+
+void XaoUtilsTest::testInteger()
+{
+    CPPUNIT_ASSERT_EQUAL(std::string("0"), XaoUtils::intToString(0));
+    CPPUNIT_ASSERT_EQUAL(std::string("123"), XaoUtils::intToString(123));
+
+    CPPUNIT_ASSERT_EQUAL(123, XaoUtils::stringToInt("123"));
+    CPPUNIT_ASSERT_THROW(XaoUtils::stringToInt("abc"), SALOME_Exception);
+}
+
+void XaoUtilsTest::testDouble()
+{
+    CPPUNIT_ASSERT_EQUAL(std::string("0"), XaoUtils::doubleToString(0));
+    CPPUNIT_ASSERT_EQUAL(std::string("12.3"), XaoUtils::doubleToString(12.3));
+
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(0.123, XaoUtils::stringToDouble("0.123"), 1e-3);
+    CPPUNIT_ASSERT_THROW(XaoUtils::stringToDouble("abc"), SALOME_Exception);
+}
+
+void XaoUtilsTest::testDimension()
+{
+    CPPUNIT_ASSERT_EQUAL(std::string("vertex"), XaoUtils::dimensionToString(XAO::VERTEX));
+    CPPUNIT_ASSERT_EQUAL(std::string("edge"), XaoUtils::dimensionToString(XAO::EDGE));
+    CPPUNIT_ASSERT_EQUAL(std::string("face"), XaoUtils::dimensionToString(XAO::FACE));
+    CPPUNIT_ASSERT_EQUAL(std::string("solid"), XaoUtils::dimensionToString(XAO::SOLID));
+    CPPUNIT_ASSERT_EQUAL(std::string("whole"), XaoUtils::dimensionToString(XAO::WHOLE));
+
+    CPPUNIT_ASSERT_EQUAL(XAO::VERTEX, XaoUtils::stringToDimension("vertex"));
+    CPPUNIT_ASSERT_EQUAL(XAO::EDGE, XaoUtils::stringToDimension("edge"));
+    CPPUNIT_ASSERT_EQUAL(XAO::FACE, XaoUtils::stringToDimension("face"));
+    CPPUNIT_ASSERT_EQUAL(XAO::SOLID, XaoUtils::stringToDimension("solid"));
+    CPPUNIT_ASSERT_EQUAL(XAO::WHOLE, XaoUtils::stringToDimension("whole"));
+    CPPUNIT_ASSERT_THROW(XaoUtils::stringToDimension("zz"), SALOME_Exception);
+}
+
+void XaoUtilsTest::testType()
+{
+    CPPUNIT_ASSERT_EQUAL(std::string("boolean"), XaoUtils::fieldTypeToString(XAO::BOOLEAN));
+    CPPUNIT_ASSERT_EQUAL(std::string("integer"), XaoUtils::fieldTypeToString(XAO::INTEGER));
+    CPPUNIT_ASSERT_EQUAL(std::string("double"), XaoUtils::fieldTypeToString(XAO::DOUBLE));
+    CPPUNIT_ASSERT_EQUAL(std::string("string"), XaoUtils::fieldTypeToString(XAO::STRING));
+
+    CPPUNIT_ASSERT_EQUAL(XAO::BOOLEAN, XaoUtils::stringToFieldType("boolean"));
+    CPPUNIT_ASSERT_EQUAL(XAO::INTEGER, XaoUtils::stringToFieldType("integer"));
+    CPPUNIT_ASSERT_EQUAL(XAO::DOUBLE, XaoUtils::stringToFieldType("double"));
+    CPPUNIT_ASSERT_EQUAL(XAO::STRING, XaoUtils::stringToFieldType("string"));
+    CPPUNIT_ASSERT_THROW(XaoUtils::stringToFieldType("zz"), SALOME_Exception);
+}
+
+void XaoUtilsTest::testFormat()
+{
+    CPPUNIT_ASSERT_EQUAL(std::string("BREP"), XaoUtils::shapeFormatToString(XAO::BREP));
+    CPPUNIT_ASSERT_EQUAL(std::string("STEP"), XaoUtils::shapeFormatToString(XAO::STEP));
+
+    CPPUNIT_ASSERT_EQUAL(XAO::BREP, XaoUtils::stringToShapeFormat("BREP"));
+    CPPUNIT_ASSERT_EQUAL(XAO::STEP, XaoUtils::stringToShapeFormat("STEP"));
+    CPPUNIT_ASSERT_THROW(XaoUtils::stringToShapeFormat("zz"), SALOME_Exception);
+}
diff --git a/src/XAO/tests/XaoUtilsTest.hxx b/src/XAO/tests/XaoUtilsTest.hxx
new file mode 100644 (file)
index 0000000..d992614
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef __XAO_UTILS_TEST_HXX__
+#define __XAO_UTILS_TEST_HXX__
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "../Xao.hxx"
+
+namespace XAO
+{
+    class XaoUtilsTest: public CppUnit::TestFixture
+    {
+        CPPUNIT_TEST_SUITE(XaoUtilsTest);
+        CPPUNIT_TEST(testInteger);
+        CPPUNIT_TEST(testDouble);
+        CPPUNIT_TEST(testDimension);
+        CPPUNIT_TEST(testType);
+        CPPUNIT_TEST(testFormat);
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+        void setUp();
+        void tearDown();
+        void cleanUp();
+
+        void testInteger();
+        void testDouble();
+        void testDimension();
+        void testType();
+        void testFormat();
+    };
+}
+
+#endif // __XAO_FIELD_TEST_HXX__