Salome HOME
519a2ed94fe45ddba499546c26795352c4703fdb
[modules/geom.git] / src / XAO / tests / XaoUtilsTest.cxx
1 // Copyright (C) 2013-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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, or (at your option) any later version.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "XaoUtilsTest.hxx"
21 #include "../XAO_Xao.hxx"
22 #include "../XAO_XaoUtils.hxx"
23
24 using namespace XAO;
25
26
27 void XaoUtilsTest::setUp()
28 {
29 }
30
31 void XaoUtilsTest::tearDown()
32 {
33 }
34
35 void XaoUtilsTest::cleanUp()
36 {
37 }
38
39 void XaoUtilsTest::testBoolean()
40 {
41     CPPUNIT_ASSERT_EQUAL(std::string("true"), XaoUtils::booleanToString(true));
42     CPPUNIT_ASSERT_EQUAL(std::string("false"), XaoUtils::booleanToString(false));
43
44     CPPUNIT_ASSERT_EQUAL(true, XaoUtils::stringToBoolean("true"));
45     CPPUNIT_ASSERT_EQUAL(true, XaoUtils::stringToBoolean("1"));
46     CPPUNIT_ASSERT_EQUAL(false, XaoUtils::stringToBoolean("false"));
47     CPPUNIT_ASSERT_EQUAL(false, XaoUtils::stringToBoolean("0"));
48     CPPUNIT_ASSERT_THROW(XaoUtils::stringToBoolean("abc"), XAO_Exception);
49 }
50
51 void XaoUtilsTest::testInteger()
52 {
53     CPPUNIT_ASSERT_EQUAL(std::string("0"), XaoUtils::intToString(0));
54     CPPUNIT_ASSERT_EQUAL(std::string("123"), XaoUtils::intToString(123));
55
56     CPPUNIT_ASSERT_EQUAL(123, XaoUtils::stringToInt("123"));
57     CPPUNIT_ASSERT_THROW(XaoUtils::stringToInt("abc"), XAO_Exception);
58 }
59
60 void XaoUtilsTest::testDouble()
61 {
62     CPPUNIT_ASSERT_EQUAL(std::string("0"), XaoUtils::doubleToString(0));
63     CPPUNIT_ASSERT_EQUAL(std::string("12.3"), XaoUtils::doubleToString(12.3));
64
65     CPPUNIT_ASSERT_DOUBLES_EQUAL(0.123, XaoUtils::stringToDouble("0.123"), 1e-3);
66     CPPUNIT_ASSERT_THROW(XaoUtils::stringToDouble("abc"), XAO_Exception);
67 }
68
69 void XaoUtilsTest::testDimension()
70 {
71     CPPUNIT_ASSERT_EQUAL(std::string("vertex"), XaoUtils::dimensionToString(XAO::VERTEX));
72     CPPUNIT_ASSERT_EQUAL(std::string("edge"), XaoUtils::dimensionToString(XAO::EDGE));
73     CPPUNIT_ASSERT_EQUAL(std::string("face"), XaoUtils::dimensionToString(XAO::FACE));
74     CPPUNIT_ASSERT_EQUAL(std::string("solid"), XaoUtils::dimensionToString(XAO::SOLID));
75     CPPUNIT_ASSERT_EQUAL(std::string("whole"), XaoUtils::dimensionToString(XAO::WHOLE));
76
77     CPPUNIT_ASSERT_EQUAL(XAO::VERTEX, XaoUtils::stringToDimension("vertex"));
78     CPPUNIT_ASSERT_EQUAL(XAO::EDGE, XaoUtils::stringToDimension("edge"));
79     CPPUNIT_ASSERT_EQUAL(XAO::FACE, XaoUtils::stringToDimension("face"));
80     CPPUNIT_ASSERT_EQUAL(XAO::SOLID, XaoUtils::stringToDimension("solid"));
81     CPPUNIT_ASSERT_EQUAL(XAO::WHOLE, XaoUtils::stringToDimension("whole"));
82     CPPUNIT_ASSERT_THROW(XaoUtils::stringToDimension("zz"), XAO_Exception);
83 }
84
85 void XaoUtilsTest::testType()
86 {
87     CPPUNIT_ASSERT_EQUAL(std::string("boolean"), XaoUtils::fieldTypeToString(XAO::BOOLEAN));
88     CPPUNIT_ASSERT_EQUAL(std::string("integer"), XaoUtils::fieldTypeToString(XAO::INTEGER));
89     CPPUNIT_ASSERT_EQUAL(std::string("double"), XaoUtils::fieldTypeToString(XAO::DOUBLE));
90     CPPUNIT_ASSERT_EQUAL(std::string("string"), XaoUtils::fieldTypeToString(XAO::STRING));
91
92     CPPUNIT_ASSERT_EQUAL(XAO::BOOLEAN, XaoUtils::stringToFieldType("boolean"));
93     CPPUNIT_ASSERT_EQUAL(XAO::INTEGER, XaoUtils::stringToFieldType("integer"));
94     CPPUNIT_ASSERT_EQUAL(XAO::DOUBLE, XaoUtils::stringToFieldType("double"));
95     CPPUNIT_ASSERT_EQUAL(XAO::STRING, XaoUtils::stringToFieldType("string"));
96     CPPUNIT_ASSERT_THROW(XaoUtils::stringToFieldType("zz"), XAO_Exception);
97 }
98
99 void XaoUtilsTest::testFormat()
100 {
101     CPPUNIT_ASSERT_EQUAL(std::string("BREP"), XaoUtils::shapeFormatToString(XAO::BREP));
102     CPPUNIT_ASSERT_EQUAL(std::string("STEP"), XaoUtils::shapeFormatToString(XAO::STEP));
103
104     CPPUNIT_ASSERT_EQUAL(XAO::BREP, XaoUtils::stringToShapeFormat("BREP"));
105     CPPUNIT_ASSERT_EQUAL(XAO::STEP, XaoUtils::stringToShapeFormat("STEP"));
106     CPPUNIT_ASSERT_THROW(XaoUtils::stringToShapeFormat("zz"), XAO_Exception);
107 }