diff --git a/src/XAO/XaoUtils.cxx b/src/XAO/XaoUtils.cxx index f0952140b..c61d6980c 100644 --- a/src/XAO/XaoUtils.cxx +++ b/src/XAO/XaoUtils.cxx @@ -70,7 +70,12 @@ const std::string XaoUtils::booleanToString(const bool& value) 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) diff --git a/src/XAO/tests/XaoUtilsTest.cxx b/src/XAO/tests/XaoUtilsTest.cxx index 92e8f2f6d..37d12ce2a 100644 --- a/src/XAO/tests/XaoUtilsTest.cxx +++ b/src/XAO/tests/XaoUtilsTest.cxx @@ -19,6 +19,18 @@ void XaoUtilsTest::cleanUp() { } +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)); diff --git a/src/XAO/tests/XaoUtilsTest.hxx b/src/XAO/tests/XaoUtilsTest.hxx index d9926145e..b69c66cc0 100644 --- a/src/XAO/tests/XaoUtilsTest.hxx +++ b/src/XAO/tests/XaoUtilsTest.hxx @@ -10,6 +10,7 @@ namespace XAO class XaoUtilsTest: public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(XaoUtilsTest); + CPPUNIT_TEST(testBoolean); CPPUNIT_TEST(testInteger); CPPUNIT_TEST(testDouble); CPPUNIT_TEST(testDimension); @@ -22,6 +23,7 @@ namespace XAO void tearDown(); void cleanUp(); + void testBoolean(); void testInteger(); void testDouble(); void testDimension();