From: fps Date: Wed, 4 Sep 2013 16:08:50 +0000 (+0000) Subject: more tests X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=42a005d08680f8cd96e5a2757c746abd3599c2ff;p=modules%2Fgeom.git more tests --- diff --git a/src/XAO/BooleanStep.cxx b/src/XAO/BooleanStep.cxx index 915824995..02c2f2960 100644 --- a/src/XAO/BooleanStep.cxx +++ b/src/XAO/BooleanStep.cxx @@ -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& values) @@ -126,7 +126,7 @@ void BooleanStep::setValues(const std::vector& values) void BooleanStep::setElements(const int& element, const std::vector& 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& eleme void BooleanStep::setComponents(const int& component, const std::vector& 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)); } diff --git a/src/XAO/Field.cxx b/src/XAO/Field.cxx index 010f97421..6368c4ef4 100644 --- a/src/XAO/Field.cxx +++ b/src/XAO/Field.cxx @@ -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); } diff --git a/src/XAO/Step.cxx b/src/XAO/Step.cxx index f7ab052a7..bbc2decd9 100644 --- a/src/XAO/Step.cxx +++ b/src/XAO/Step.cxx @@ -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); } diff --git a/src/XAO/XaoUtils.cxx b/src/XAO/XaoUtils.cxx index 31d6f71c8..f0952140b 100644 --- a/src/XAO/XaoUtils.cxx +++ b/src/XAO/XaoUtils.cxx @@ -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) diff --git a/src/XAO/XaoUtils.hxx b/src/XAO/XaoUtils.hxx index 4b5f5b11f..a626c5a1b 100644 --- a/src/XAO/XaoUtils.hxx +++ b/src/XAO/XaoUtils.hxx @@ -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. diff --git a/src/XAO/tests/BrepGeometryTest.cxx b/src/XAO/tests/BrepGeometryTest.cxx index ae60a3de1..883454a4c 100644 --- a/src/XAO/tests/BrepGeometryTest.cxx +++ b/src/XAO/tests/BrepGeometryTest.cxx @@ -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"); diff --git a/src/XAO/tests/BrepGeometryTest.hxx b/src/XAO/tests/BrepGeometryTest.hxx index 1f1c37122..a3810268d 100644 --- a/src/XAO/tests/BrepGeometryTest.hxx +++ b/src/XAO/tests/BrepGeometryTest.hxx @@ -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(); diff --git a/src/XAO/tests/FieldTest.cxx b/src/XAO/tests/FieldTest.cxx index 2f9d82b48..3e0e3cc96 100644 --- a/src/XAO/tests/FieldTest.cxx +++ b/src/XAO/tests/FieldTest.cxx @@ -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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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);} diff --git a/src/XAO/tests/FieldTest.hxx b/src/XAO/tests/FieldTest.hxx index 5a5d13bc5..e7b19bcc9 100644 --- a/src/XAO/tests/FieldTest.hxx +++ b/src/XAO/tests/FieldTest.hxx @@ -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(); }; } diff --git a/src/XAO/tests/Makefile.am b/src/XAO/tests/Makefile.am index dbdec080a..6fe1b3274 100755 --- a/src/XAO/tests/Makefile.am +++ b/src/XAO/tests/Makefile.am @@ -39,6 +39,7 @@ TestXAO_LDFLAGS = \ ../libXAO.la dist_TestXAO_SOURCES = \ + XaoUtilsTest.cxx \ GroupTest.cxx \ FieldTest.cxx \ GeometryTest.cxx \ diff --git a/src/XAO/tests/XAOTests.cxx b/src/XAO/tests/XAOTests.cxx index 832e4cd60..0238e7f9b 100644 --- a/src/XAO/tests/XAOTests.cxx +++ b/src/XAO/tests/XAOTests.cxx @@ -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 index 000000000..92e8f2f6d --- /dev/null +++ b/src/XAO/tests/XaoUtilsTest.cxx @@ -0,0 +1,78 @@ +#include + +#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 index 000000000..d9926145e --- /dev/null +++ b/src/XAO/tests/XaoUtilsTest.hxx @@ -0,0 +1,33 @@ +#ifndef __XAO_UTILS_TEST_HXX__ +#define __XAO_UTILS_TEST_HXX__ + +#include + +#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__