3 #include "TestUtils.hxx"
4 #include "GeometryTest.hxx"
5 #include "../XAO_XaoUtils.hxx"
6 #include "../XAO_Geometry.hxx"
7 #include "../XAO_GeometricElement.hxx"
11 void GeometryTest::setUp()
15 void GeometryTest::tearDown()
19 void GeometryTest::cleanUp()
23 void GeometryTest::testGeometryElement()
26 CPPUNIT_ASSERT_EQUAL(false, elt.hasName());
27 CPPUNIT_ASSERT_EQUAL(std::string(""), elt.getName());
28 CPPUNIT_ASSERT_EQUAL(std::string(""), elt.getReference());
31 CPPUNIT_ASSERT_EQUAL(true, elt.hasName());
32 CPPUNIT_ASSERT_EQUAL(std::string("test"), elt.getName());
34 elt.setReference("abc");
35 CPPUNIT_ASSERT_EQUAL(std::string("abc"), elt.getReference());
37 GeometricElement elt2("aa", "bb");
38 CPPUNIT_ASSERT_EQUAL(std::string("aa"), elt2.getName());
39 CPPUNIT_ASSERT_EQUAL(std::string("bb"), elt2.getReference());
42 void GeometryTest::testGeometryElementList()
44 GeometricElementList lst;
45 CPPUNIT_ASSERT_EQUAL(0, lst.getSize());
47 CPPUNIT_ASSERT_EQUAL(10, lst.getSize());
49 GeometricElementList otherLst(15);
50 CPPUNIT_ASSERT_EQUAL(15, otherLst.getSize());
51 CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getName(0));
52 CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getReference(0));
54 CPPUNIT_ASSERT_THROW(otherLst.getName(20), XAO_Exception);
55 CPPUNIT_ASSERT_THROW(otherLst.getReference(20), XAO_Exception);
56 CPPUNIT_ASSERT_THROW(otherLst.hasName(20), XAO_Exception);
58 otherLst.setName(0, "aa");
59 CPPUNIT_ASSERT_EQUAL(std::string("aa"), otherLst.getName(0));
60 CPPUNIT_ASSERT_THROW(otherLst.setName(20, "aa"), XAO_Exception);
61 otherLst.setReference(0, "bb");
62 CPPUNIT_ASSERT_EQUAL(std::string("bb"), otherLst.getReference(0));
63 CPPUNIT_ASSERT_THROW(otherLst.setReference(20, "aa"), XAO_Exception);
66 CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getName(0));
67 CPPUNIT_ASSERT_EQUAL(std::string(""), otherLst.getReference(0));
68 CPPUNIT_ASSERT_EQUAL(false, otherLst.hasName(0));
70 otherLst.setElement(3, "name", "ref");
71 CPPUNIT_ASSERT_EQUAL(std::string("name"), otherLst.getName(3));
72 CPPUNIT_ASSERT_EQUAL(std::string("ref"), otherLst.getReference(3));
73 CPPUNIT_ASSERT_EQUAL(true, otherLst.hasName(3));
74 CPPUNIT_ASSERT_THROW(otherLst.setElement(30, "name", "ref"), XAO_Exception);
76 // ---- create elements "name i", "Ri"
77 for (int i = 0; i < otherLst.getSize(); ++i)
79 std::ostringstream name;
81 std::ostringstream ref;
84 otherLst.setElement(i, name.str(), ref.str());
87 CPPUNIT_ASSERT_EQUAL(8, otherLst.getIndexByReference("R8"));
88 CPPUNIT_ASSERT_THROW(otherLst.getIndexByReference("ZZ"), XAO_Exception);
90 GeometricElementList::iterator first = otherLst.begin();
91 GeometricElement firstElt = first->second;
92 CPPUNIT_ASSERT_EQUAL(std::string("R0"), firstElt.getReference());
95 void GeometryTest::testGeometry()
97 Geometry* geom = Geometry::createGeometry(XAO::BREP, "cube");
99 CPPUNIT_ASSERT_EQUAL(std::string("cube"), geom->getName());
100 CPPUNIT_ASSERT_EQUAL(XAO::BREP, geom->getFormat());
102 geom->setName("sphere");
103 CPPUNIT_ASSERT_EQUAL(std::string("sphere"), geom->getName());
108 void GeometryTest::testGeometryErrors()
110 CPPUNIT_ASSERT_THROW(Geometry::createGeometry(XAO::STEP), XAO_Exception);
113 void GeometryTest::testSetElement()
115 Geometry* geom = Geometry::createGeometry(XAO::BREP, "cube");
117 CPPUNIT_ASSERT_THROW(geom->setVertexName(0, "aa"), XAO_Exception);
119 char* txt = TestUtils::readTextFile(TestUtils::getTestFilePath("Box_1.brep"));
120 geom->setShapeString(txt);
122 CPPUNIT_ASSERT_EQUAL(false, geom->hasVertexName(0));
123 geom->setVertexName(0, "va");
124 CPPUNIT_ASSERT_EQUAL(true, geom->hasVertexName(0));
125 CPPUNIT_ASSERT_EQUAL(std::string("va"), geom->getVertexName(0));
126 CPPUNIT_ASSERT_THROW(geom->getVertexName(100), XAO_Exception);
127 CPPUNIT_ASSERT_THROW(geom->hasVertexName(100), XAO_Exception);
129 geom->setEdgeName(0, "ea");
130 CPPUNIT_ASSERT_EQUAL(std::string("ea"), geom->getEdgeName(0));
131 CPPUNIT_ASSERT_THROW(geom->getEdgeName(100), XAO_Exception);
133 geom->setFaceName(0, "fa");
134 CPPUNIT_ASSERT_EQUAL(std::string("fa"), geom->getFaceName(0));
135 CPPUNIT_ASSERT_THROW(geom->getFaceName(100), XAO_Exception);
137 geom->setSolidName(0, "sa");
138 CPPUNIT_ASSERT_EQUAL(std::string("sa"), geom->getSolidName(0));
139 CPPUNIT_ASSERT_THROW(geom->getSolidName(100), XAO_Exception);