1 // Copyright (C) 2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Frederic Pons (OpenCascade)
21 #include "TestUtils.hxx"
22 #include "ImportExportTest.hxx"
23 #include "../XAO_XaoUtils.hxx"
24 #include "../XAO_Geometry.hxx"
25 #include "../XAO_Group.hxx"
26 #include "../XAO_Field.hxx"
27 #include "../XAO_IntegerField.hxx"
28 #include "../XAO_IntegerStep.hxx"
33 void ImportExportTest::setUp()
37 void ImportExportTest::tearDown()
41 void ImportExportTest::cleanUp()
45 void ImportExportTest::testExportNoGeometry()
49 bool res = xao.exportXAO("empty.xao");
53 void ImportExportTest::testExportGeometry()
56 Geometry* geom = Geometry::createGeometry(XAO::BREP);
57 geom->setName("mygeom");
58 CPPUNIT_ASSERT_EQUAL(false, geom->isReadOnly());
61 geom->setCountVertices(4);
62 geom->setVertex(0, "v1", "1");
63 geom->setVertex(1, "", "2");
64 geom->setVertex(2, "v3", "3");
65 geom->setVertex(3, "", "4");
67 geom->setCountEdges(3);
68 geom->setEdge(0, "e1", "5");
69 geom->setEdge(1, "", "6");
70 geom->setEdge(2, "e3", "7");
72 geom->setCountFaces(2);
73 geom->setFace(0, "f1", "8");
74 geom->setFace(1, "", "9");
76 geom->setCountSolids(1);
77 geom->setSolid(0, "s1", "10");
79 xao.setGeometry(geom);
80 CPPUNIT_ASSERT_EQUAL(true, geom->isReadOnly());
83 Group* group = xao.addGroup(XAO::SOLID);
84 group->setName("boite1");
87 group = xao.addGroup(XAO::FACE);
88 group->setName("faces");
93 IntegerField* field = (IntegerField*)xao.addField(XAO::INTEGER, XAO::FACE, 2, "color");
94 for (int stepIndex = 0; stepIndex < 10; ++stepIndex)
96 IntegerStep* istep = field->addStep(stepIndex, 100*stepIndex);
97 for (int eltIndex = 0; eltIndex < istep->countElements(); ++eltIndex)
99 for (int compIndex = 0; compIndex < istep->countComponents(); ++compIndex)
101 istep->setValue(eltIndex, compIndex, istep->getStamp() + eltIndex*10 + compIndex);
106 bool res = xao.exportXAO("mygeom.xao");
109 std::string xml = xao.getXML();
110 //CPPUNIT_ASSERT_EQUAL(strlen(xml) == 1007);
113 void ImportExportTest::testGeometryError()
115 Geometry* geom = Geometry::createGeometry(XAO::BREP);
116 geom->setName("mygeom");
117 geom->setCountVertices(2);
118 CPPUNIT_ASSERT_THROW(geom->setVertex(3, "v4", "4"), XAO_Exception);
122 void ImportExportTest::testImportXao()
125 xao.importXAO(TestUtils::getTestFilePath("test.xao"));
129 void ImportExportTest::testImportXaoFromText()
131 char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath("test.xao"));
138 void ImportExportTest::checkImport(Xao& xao)
140 CPPUNIT_ASSERT_EQUAL(std::string("me"), xao.getAuthor());
141 CPPUNIT_ASSERT_EQUAL(std::string("1.0"), xao.getVersion());
143 Geometry* geom = xao.getGeometry();
144 CPPUNIT_ASSERT(geom != NULL);
145 CPPUNIT_ASSERT_EQUAL(std::string("mygeom"), geom->getName());
147 CPPUNIT_ASSERT_EQUAL(4, geom->countVertices());
148 CPPUNIT_ASSERT_EQUAL(std::string("v1"), geom->getVertexName(0));
149 CPPUNIT_ASSERT_EQUAL(std::string("1"), geom->getVertexReference(0));
150 CPPUNIT_ASSERT_EQUAL(std::string(""), geom->getVertexName(1));
151 CPPUNIT_ASSERT_EQUAL(std::string("2"), geom->getVertexReference(1));
152 CPPUNIT_ASSERT_EQUAL(std::string("v3"), geom->getVertexName(2));
153 CPPUNIT_ASSERT_EQUAL(std::string("3"), geom->getVertexReference(2));
154 CPPUNIT_ASSERT_EQUAL(std::string(""), geom->getVertexName(3));
155 CPPUNIT_ASSERT_EQUAL(std::string("4"), geom->getVertexReference(3));
157 CPPUNIT_ASSERT_EQUAL(3, geom->countEdges());
158 CPPUNIT_ASSERT_EQUAL(std::string("e1"), geom->getEdgeName(0));
159 CPPUNIT_ASSERT_EQUAL(std::string("5"), geom->getEdgeReference(0));
160 CPPUNIT_ASSERT_EQUAL(std::string(""), geom->getEdgeName(1));
161 CPPUNIT_ASSERT_EQUAL(std::string("6"), geom->getEdgeReference(1));
162 CPPUNIT_ASSERT_EQUAL(std::string("e3"), geom->getEdgeName(2));
163 CPPUNIT_ASSERT_EQUAL(std::string("7"), geom->getEdgeReference(2));
165 CPPUNIT_ASSERT_EQUAL(2, geom->countFaces());
166 CPPUNIT_ASSERT_EQUAL(std::string("f1"), geom->getFaceName(0));
167 CPPUNIT_ASSERT_EQUAL(std::string("8"), geom->getFaceReference(0));
168 CPPUNIT_ASSERT_EQUAL(std::string(""), geom->getFaceName(1));
169 CPPUNIT_ASSERT_EQUAL(std::string("9"), geom->getFaceReference(1));
171 CPPUNIT_ASSERT_EQUAL(1, geom->countSolids());
172 CPPUNIT_ASSERT_EQUAL(std::string("s1"), geom->getSolidName(0));
173 CPPUNIT_ASSERT_EQUAL(std::string("10"), geom->getSolidReference(0));
175 CPPUNIT_ASSERT_EQUAL(2, xao.countGroups());
176 Group* group = xao.getGroup(0);
177 CPPUNIT_ASSERT_EQUAL(1, group->count());
178 CPPUNIT_ASSERT_EQUAL(std::string("boite_1"), group->getName());
179 CPPUNIT_ASSERT_EQUAL(XAO::SOLID, group->getDimension());
180 CPPUNIT_ASSERT_EQUAL(0, group->get(0));
181 group = xao.getGroup(1);
182 CPPUNIT_ASSERT_EQUAL(2, group->count());
183 CPPUNIT_ASSERT_EQUAL(std::string(""), group->getName());
184 CPPUNIT_ASSERT_EQUAL(XAO::FACE, group->getDimension());
185 CPPUNIT_ASSERT_EQUAL(0, group->get(0));
186 CPPUNIT_ASSERT_EQUAL(1, group->get(1));