mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2025-02-05 16:54:17 +05:00
imported boolean values can be "true/false" or "0/1" exception otherwise
This commit is contained in:
parent
1a0e41bedd
commit
53f4fa8d2f
@ -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)
|
||||
|
@ -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));
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user