1 #include "XaoUtilsTest.hxx"
2 #include "../XAO_Xao.hxx"
3 #include "../XAO_XaoUtils.hxx"
8 void XaoUtilsTest::setUp()
12 void XaoUtilsTest::tearDown()
16 void XaoUtilsTest::cleanUp()
20 void XaoUtilsTest::testBoolean()
22 CPPUNIT_ASSERT_EQUAL(std::string("true"), XaoUtils::booleanToString(true));
23 CPPUNIT_ASSERT_EQUAL(std::string("false"), XaoUtils::booleanToString(false));
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);
32 void XaoUtilsTest::testInteger()
34 CPPUNIT_ASSERT_EQUAL(std::string("0"), XaoUtils::intToString(0));
35 CPPUNIT_ASSERT_EQUAL(std::string("123"), XaoUtils::intToString(123));
37 CPPUNIT_ASSERT_EQUAL(123, XaoUtils::stringToInt("123"));
38 CPPUNIT_ASSERT_THROW(XaoUtils::stringToInt("abc"), XAO_Exception);
41 void XaoUtilsTest::testDouble()
43 CPPUNIT_ASSERT_EQUAL(std::string("0"), XaoUtils::doubleToString(0));
44 CPPUNIT_ASSERT_EQUAL(std::string("12.3"), XaoUtils::doubleToString(12.3));
46 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.123, XaoUtils::stringToDouble("0.123"), 1e-3);
47 CPPUNIT_ASSERT_THROW(XaoUtils::stringToDouble("abc"), XAO_Exception);
50 void XaoUtilsTest::testDimension()
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));
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);
66 void XaoUtilsTest::testType()
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));
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);
80 void XaoUtilsTest::testFormat()
82 CPPUNIT_ASSERT_EQUAL(std::string("BREP"), XaoUtils::shapeFormatToString(XAO::BREP));
83 CPPUNIT_ASSERT_EQUAL(std::string("STEP"), XaoUtils::shapeFormatToString(XAO::STEP));
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);