imported boolean values can be "true/false" or "0/1" exception otherwise

This commit is contained in:
fps 2013-09-06 11:53:48 +00:00
parent 1a0e41bedd
commit 53f4fa8d2f
3 changed files with 20 additions and 1 deletions

View File

@ -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)

View File

@ -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));

View File

@ -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();