const bool XaoUtils::stringToBoolean(const std::string& value)
{
- return (value == std::string("true"));
+ if (value == "true" || value == "1")
+ return true;
+ if (value == "false" || value == "0")
+ return false;
+
+ throw SALOME_Exception(MsgBuilder() << "Invalid boolean value: " << value);
}
const std::string XaoUtils::dimensionToString(const XAO::Dimension& dimension)
{
}
+void XaoUtilsTest::testBoolean()
+{
+ CPPUNIT_ASSERT_EQUAL(std::string("true"), XaoUtils::booleanToString(true));
+ CPPUNIT_ASSERT_EQUAL(std::string("false"), XaoUtils::booleanToString(false));
+
+ CPPUNIT_ASSERT_EQUAL(true, XaoUtils::stringToBoolean("true"));
+ CPPUNIT_ASSERT_EQUAL(true, XaoUtils::stringToBoolean("1"));
+ CPPUNIT_ASSERT_EQUAL(false, XaoUtils::stringToBoolean("false"));
+ CPPUNIT_ASSERT_EQUAL(false, XaoUtils::stringToBoolean("0"));
+ CPPUNIT_ASSERT_THROW(XaoUtils::stringToBoolean("abc"), SALOME_Exception);
+}
+
void XaoUtilsTest::testInteger()
{
CPPUNIT_ASSERT_EQUAL(std::string("0"), XaoUtils::intToString(0));
class XaoUtilsTest: public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(XaoUtilsTest);
+ CPPUNIT_TEST(testBoolean);
CPPUNIT_TEST(testInteger);
CPPUNIT_TEST(testDouble);
CPPUNIT_TEST(testDimension);
void tearDown();
void cleanUp();
+ void testBoolean();
void testInteger();
void testDouble();
void testDimension();