Salome HOME
22358fa9217c74adc0313a5be1b04021d852d672
[modules/geom.git] / src / XAO / tests / XaoUtilsTest.cxx
1 #include "XaoUtilsTest.hxx"
2 #include "../XAO_Xao.hxx"
3 #include "../XAO_XaoUtils.hxx"
4
5 using namespace XAO;
6
7
8 void XaoUtilsTest::setUp()
9 {
10 }
11
12 void XaoUtilsTest::tearDown()
13 {
14 }
15
16 void XaoUtilsTest::cleanUp()
17 {
18 }
19
20 void XaoUtilsTest::testBoolean()
21 {
22     CPPUNIT_ASSERT_EQUAL(std::string("true"), XaoUtils::booleanToString(true));
23     CPPUNIT_ASSERT_EQUAL(std::string("false"), XaoUtils::booleanToString(false));
24
25     CPPUNIT_ASSERT_EQUAL(true, XaoUtils::stringToBoolean("true"));
26     CPPUNIT_ASSERT_EQUAL(true, XaoUtils::stringToBoolean("1"));
27     CPPUNIT_ASSERT_EQUAL(false, XaoUtils::stringToBoolean("false"));
28     CPPUNIT_ASSERT_EQUAL(false, XaoUtils::stringToBoolean("0"));
29     CPPUNIT_ASSERT_THROW(XaoUtils::stringToBoolean("abc"), XAO_Exception);
30 }
31
32 void XaoUtilsTest::testInteger()
33 {
34     CPPUNIT_ASSERT_EQUAL(std::string("0"), XaoUtils::intToString(0));
35     CPPUNIT_ASSERT_EQUAL(std::string("123"), XaoUtils::intToString(123));
36
37     CPPUNIT_ASSERT_EQUAL(123, XaoUtils::stringToInt("123"));
38     CPPUNIT_ASSERT_THROW(XaoUtils::stringToInt("abc"), XAO_Exception);
39 }
40
41 void XaoUtilsTest::testDouble()
42 {
43     CPPUNIT_ASSERT_EQUAL(std::string("0"), XaoUtils::doubleToString(0));
44     CPPUNIT_ASSERT_EQUAL(std::string("12.3"), XaoUtils::doubleToString(12.3));
45
46     CPPUNIT_ASSERT_DOUBLES_EQUAL(0.123, XaoUtils::stringToDouble("0.123"), 1e-3);
47     CPPUNIT_ASSERT_THROW(XaoUtils::stringToDouble("abc"), XAO_Exception);
48 }
49
50 void XaoUtilsTest::testDimension()
51 {
52     CPPUNIT_ASSERT_EQUAL(std::string("vertex"), XaoUtils::dimensionToString(XAO::VERTEX));
53     CPPUNIT_ASSERT_EQUAL(std::string("edge"), XaoUtils::dimensionToString(XAO::EDGE));
54     CPPUNIT_ASSERT_EQUAL(std::string("face"), XaoUtils::dimensionToString(XAO::FACE));
55     CPPUNIT_ASSERT_EQUAL(std::string("solid"), XaoUtils::dimensionToString(XAO::SOLID));
56     CPPUNIT_ASSERT_EQUAL(std::string("whole"), XaoUtils::dimensionToString(XAO::WHOLE));
57
58     CPPUNIT_ASSERT_EQUAL(XAO::VERTEX, XaoUtils::stringToDimension("vertex"));
59     CPPUNIT_ASSERT_EQUAL(XAO::EDGE, XaoUtils::stringToDimension("edge"));
60     CPPUNIT_ASSERT_EQUAL(XAO::FACE, XaoUtils::stringToDimension("face"));
61     CPPUNIT_ASSERT_EQUAL(XAO::SOLID, XaoUtils::stringToDimension("solid"));
62     CPPUNIT_ASSERT_EQUAL(XAO::WHOLE, XaoUtils::stringToDimension("whole"));
63     CPPUNIT_ASSERT_THROW(XaoUtils::stringToDimension("zz"), XAO_Exception);
64 }
65
66 void XaoUtilsTest::testType()
67 {
68     CPPUNIT_ASSERT_EQUAL(std::string("boolean"), XaoUtils::fieldTypeToString(XAO::BOOLEAN));
69     CPPUNIT_ASSERT_EQUAL(std::string("integer"), XaoUtils::fieldTypeToString(XAO::INTEGER));
70     CPPUNIT_ASSERT_EQUAL(std::string("double"), XaoUtils::fieldTypeToString(XAO::DOUBLE));
71     CPPUNIT_ASSERT_EQUAL(std::string("string"), XaoUtils::fieldTypeToString(XAO::STRING));
72
73     CPPUNIT_ASSERT_EQUAL(XAO::BOOLEAN, XaoUtils::stringToFieldType("boolean"));
74     CPPUNIT_ASSERT_EQUAL(XAO::INTEGER, XaoUtils::stringToFieldType("integer"));
75     CPPUNIT_ASSERT_EQUAL(XAO::DOUBLE, XaoUtils::stringToFieldType("double"));
76     CPPUNIT_ASSERT_EQUAL(XAO::STRING, XaoUtils::stringToFieldType("string"));
77     CPPUNIT_ASSERT_THROW(XaoUtils::stringToFieldType("zz"), XAO_Exception);
78 }
79
80 void XaoUtilsTest::testFormat()
81 {
82     CPPUNIT_ASSERT_EQUAL(std::string("BREP"), XaoUtils::shapeFormatToString(XAO::BREP));
83     CPPUNIT_ASSERT_EQUAL(std::string("STEP"), XaoUtils::shapeFormatToString(XAO::STEP));
84
85     CPPUNIT_ASSERT_EQUAL(XAO::BREP, XaoUtils::stringToShapeFormat("BREP"));
86     CPPUNIT_ASSERT_EQUAL(XAO::STEP, XaoUtils::stringToShapeFormat("STEP"));
87     CPPUNIT_ASSERT_THROW(XaoUtils::stringToShapeFormat("zz"), XAO_Exception);
88 }