]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
imported boolean values can be "true/false" or "0/1" exception otherwise
authorfps <fps@opencascade.com>
Fri, 6 Sep 2013 11:53:48 +0000 (11:53 +0000)
committerfps <fps@opencascade.com>
Fri, 6 Sep 2013 11:53:48 +0000 (11:53 +0000)
src/XAO/XaoUtils.cxx
src/XAO/tests/XaoUtilsTest.cxx
src/XAO/tests/XaoUtilsTest.hxx

index f0952140bcf87a20d39ffbbdff2f3123dbc20f9a..c61d6980c78137f1d6e36d97eef46611d1f0e839 100644 (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)
index 92e8f2f6dea1a14d7fae3f207ff6e19fe995989f..37d12ce2ad9af1671173a7f911be3d1061521315 100644 (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));
index d9926145e7941188723c9fcb95bc521ef8af2d82..b69c66cc02a9611fb0aaee3dadf3afcf92b13fb8 100644 (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();