[Libreoffice-commits] core.git: 2 commits - sal/inc sal/qa

Stephan Bergmann sbergman at redhat.com
Mon Feb 4 05:47:05 PST 2013


 sal/inc/rtl/string.hxx                     |   20 ++++++++++++++++++--
 sal/inc/rtl/ustring.hxx                    |   20 ++++++++++++++++++--
 sal/qa/rtl/strings/test_strings_valuex.cxx |   24 ++++++++++++++++++++++++
 sal/qa/rtl_strings/rtl_OString.cxx         |    8 ++++----
 sal/qa/rtl_strings/rtl_OUString.cxx        |    8 ++++----
 5 files changed, 68 insertions(+), 12 deletions(-)

New commits:
commit 6ba8a2eab28cbe0967b360a09e1e9d7a7bb7bd26
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Mon Feb 4 14:44:24 2013 +0100

    OK for boolean() to take true bool argument
    
    ...instead of sal_Bool; this would cause C4800 performance warnings with MSVC,
    but we disable them anyway.
    
    Also, added unit tests that are actually executed.
    
    Change-Id: Ib405132565918be72d93b3fc24180edcb6e565c7

diff --git a/sal/inc/rtl/string.hxx b/sal/inc/rtl/string.hxx
index 9ed01e5..a239768 100644
--- a/sal/inc/rtl/string.hxx
+++ b/sal/inc/rtl/string.hxx
@@ -1504,11 +1504,11 @@ public:
       If the sal_Bool is false, the string "false" is returned.
       This function can't be used for language specific conversion.
 
-      @param    b   a sal_Bool.
+      @param    b   a bool.
       @return   a string with the string representation of the argument.
       @since LibreOffice 4.1
     */
-    static OString boolean( sal_Bool b ) SAL_THROW(())
+    static OString boolean( bool b ) SAL_THROW(())
     {
         sal_Char aBuf[RTL_STR_MAX_VALUEOFBOOLEAN];
         rtl_String* pNewData = 0;
diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx
index 7cdbb4e..25ed82b 100644
--- a/sal/inc/rtl/ustring.hxx
+++ b/sal/inc/rtl/ustring.hxx
@@ -2155,11 +2155,11 @@ public:
       If the sal_Bool is false, the string "false" is returned.
       This function can't be used for language specific conversion.
 
-      @param    b   a sal_Bool.
+      @param    b   a bool.
       @return   a string with the string representation of the argument.
       @since LibreOffice 4.1
     */
-    static OUString boolean( sal_Bool b ) SAL_THROW(())
+    static OUString boolean( bool b ) SAL_THROW(())
     {
         sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFBOOLEAN];
         rtl_uString* pNewData = 0;
diff --git a/sal/qa/rtl/strings/test_strings_valuex.cxx b/sal/qa/rtl/strings/test_strings_valuex.cxx
index cbd12c5..3ad4cd7 100644
--- a/sal/qa/rtl/strings/test_strings_valuex.cxx
+++ b/sal/qa/rtl/strings/test_strings_valuex.cxx
@@ -17,12 +17,16 @@ namespace test { namespace strings {
 
 class valueX : public CppUnit::TestFixture {
 public:
+    void testOBoolean();
+    void testOUBoolean();
     void testOUInt();
     void testOInt();
     void testOUFloat();
     void testOFloat();
 
     CPPUNIT_TEST_SUITE(valueX);
+    CPPUNIT_TEST(testOBoolean);
+    CPPUNIT_TEST(testOUBoolean);
     CPPUNIT_TEST(testOUInt);
     CPPUNIT_TEST(testOInt);
     CPPUNIT_TEST(testOUFloat);
@@ -34,6 +38,26 @@ public:
 
 CPPUNIT_TEST_SUITE_REGISTRATION(test::strings::valueX);
 
+namespace {
+
+template< typename T >
+void testBoolean() {
+    CPPUNIT_ASSERT_EQUAL( T( "false" ), T::boolean( false ) );
+    CPPUNIT_ASSERT_EQUAL( T( "false" ), T::boolean( sal_False ) );
+    CPPUNIT_ASSERT_EQUAL( T( "true" ), T::boolean( true ) );
+    CPPUNIT_ASSERT_EQUAL( T( "true" ), T::boolean( sal_True ) );
+}
+
+}
+
+void test::strings::valueX::testOBoolean() {
+    testBoolean<rtl::OString>();
+}
+
+void test::strings::valueX::testOUBoolean() {
+    testBoolean<rtl::OString>();
+}
+
 template< typename T >
 void testInt() {
     CPPUNIT_ASSERT_EQUAL( T( "30039062" ), T::number( 30039062 ));
commit 751950edc84e0069e5bce1083160d46d9ba1bf33
Author: David Ostrovsky <david at ostrovsky.org>
Date:   Mon Feb 4 11:40:14 2013 +0100

    Strings: boolean() as a replacement for valueOf(sal_Bool)
    
    valueOf(?) has been superseded by number(?).
    O(U)String::valueOf(sal_Bool) has been deprecated without providing an
    alternative method. Use boolean() method as a replacement for it.
    
    Change-Id: I7eb74574fa8f1a3cf007cb0cbc32e681007ffb92
    Signed-off-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/sal/inc/rtl/string.hxx b/sal/inc/rtl/string.hxx
index 69592f9..9ed01e5 100644
--- a/sal/inc/rtl/string.hxx
+++ b/sal/inc/rtl/string.hxx
@@ -1490,9 +1490,25 @@ public:
 
       @param    b   a sal_Bool.
       @return   a string with the string representation of the argument.
-      @deprecated there is no replacement, use 'condition ? OString( "true" ) : OString( "false" )'
+      @deprecated use boolean()
     */
-    SAL_DEPRECATED_INTERNAL("write explicit code") static OString valueOf( sal_Bool b ) SAL_THROW(())
+    SAL_DEPRECATED_INTERNAL("use boolean()") static OString valueOf( sal_Bool b ) SAL_THROW(())
+    {
+        return boolean(b);
+    }
+
+    /**
+      Returns the string representation of the boolean argument.
+
+      If the sal_Bool is true, the string "true" is returned.
+      If the sal_Bool is false, the string "false" is returned.
+      This function can't be used for language specific conversion.
+
+      @param    b   a sal_Bool.
+      @return   a string with the string representation of the argument.
+      @since LibreOffice 4.1
+    */
+    static OString boolean( sal_Bool b ) SAL_THROW(())
     {
         sal_Char aBuf[RTL_STR_MAX_VALUEOFBOOLEAN];
         rtl_String* pNewData = 0;
diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx
index 8190d20..7cdbb4e 100644
--- a/sal/inc/rtl/ustring.hxx
+++ b/sal/inc/rtl/ustring.hxx
@@ -2141,9 +2141,25 @@ public:
 
       @param    b   a sal_Bool.
       @return   a string with the string representation of the argument.
-      @deprecated there is no replacement, use 'condition ? OString( "true" ) : OString( "false" )'
+      @deprecated use boolean()
     */
-    SAL_DEPRECATED_INTERNAL("write explicit condition") static OUString valueOf( sal_Bool b ) SAL_THROW(())
+    SAL_DEPRECATED_INTERNAL("use boolean()") static OUString valueOf( sal_Bool b ) SAL_THROW(())
+    {
+        return boolean(b);
+    }
+
+    /**
+      Returns the string representation of the boolean argument.
+
+      If the sal_Bool is true, the string "true" is returned.
+      If the sal_Bool is false, the string "false" is returned.
+      This function can't be used for language specific conversion.
+
+      @param    b   a sal_Bool.
+      @return   a string with the string representation of the argument.
+      @since LibreOffice 4.1
+    */
+    static OUString boolean( sal_Bool b ) SAL_THROW(())
     {
         sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFBOOLEAN];
         rtl_uString* pNewData = 0;
diff --git a/sal/qa/rtl_strings/rtl_OString.cxx b/sal/qa/rtl_strings/rtl_OString.cxx
index cea3cb1..1934f06 100644
--- a/sal/qa/rtl_strings/rtl_OString.cxx
+++ b/sal/qa/rtl_strings/rtl_OString.cxx
@@ -1785,9 +1785,9 @@ extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_trim(
 
 
 //------------------------------------------------------------------------
-// testing the method valueOf( sal_Bool b )
+// testing the method boolean( sal_Bool b )
 //------------------------------------------------------------------------
-sal_Bool SAL_CALL test_rtl_OString_valueOf_sal_Bool(
+sal_Bool SAL_CALL test_rtl_OString_boolean(
                                                 hTestResult hRtlTestResult )
 {
     sal_Char methName[MAXBUFLENGTH];
@@ -1813,7 +1813,7 @@ sal_Bool SAL_CALL test_rtl_OString_valueOf_sal_Bool(
     for(i = 0; i < (sizeof (arrTestCase))/(sizeof (TestCase)); i++)
     {
         ::rtl::OString aStr1;
-        aStr1 = aStr1.valueOf( arrTestCase[i].input1 );
+        aStr1 = aStr1.boolean( arrTestCase[i].input1 );
         sal_Bool lastRes = (arrTestCase[i].expVal->compareTo(aStr1) == 0);
 
         c_rtl_tres_state
@@ -2446,7 +2446,7 @@ extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OString_valueOf(
                                                 hTestResult hRtlTestResult )
 {
     c_rtl_tres_state_start(hRtlTestResult, "valueOf");
-    sal_Bool bTState = test_rtl_OString_valueOf_sal_Bool( hRtlTestResult );
+    sal_Bool bTState = test_rtl_OString_boolean( hRtlTestResult );
 
     bTState &= test_rtl_OString_valueOf_sal_Char( hRtlTestResult );
 
diff --git a/sal/qa/rtl_strings/rtl_OUString.cxx b/sal/qa/rtl_strings/rtl_OUString.cxx
index 4982f29..3ba20e7 100644
--- a/sal/qa/rtl_strings/rtl_OUString.cxx
+++ b/sal/qa/rtl_strings/rtl_OUString.cxx
@@ -1262,9 +1262,9 @@ extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_compareToAscii(
 
 
 //------------------------------------------------------------------------
-//       testing the method valueOf( sal_Bool b )
+//       testing the method boolean( sal_Bool b )
 //------------------------------------------------------------------------
-extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_valueOf_sal_Bool(
+extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_boolean(
     hTestResult hRtlTestResult )
 {
     c_rtl_tres_state_start( hRtlTestResult, "Bool");
@@ -1300,7 +1300,7 @@ extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString_valueOf_sal_Bool(
     for(i=0;i<(sizeof(arrTestCase))/(sizeof(TestCase));i++)
     {
         sal_Bool lastRes=(*arrTestCase[i].expVal==
-                          OUString::valueOf(arrTestCase[i].input1)
+                          OUString::boolean(arrTestCase[i].input1)
 
                           );
 
@@ -3347,7 +3347,7 @@ extern "C" void /* sal_Bool */ SAL_CALL test_rtl_OUString( hTestResult hRtlTestR
     test_rtl_OUString_equalsAscii( hRtlTestResult );
     test_rtl_OUString_equalsAsciiL( hRtlTestResult );
     test_rtl_OUString_compareToAscii( hRtlTestResult );
-    test_rtl_OUString_valueOf_sal_Bool( hRtlTestResult );
+    test_rtl_OUString_boolean( hRtlTestResult );
     test_rtl_OUString_valueOf_sal_Unicode( hRtlTestResult );
     test_rtl_OUString_valueOf( hRtlTestResult );
     test_rtl_OUString_createFromAscii( hRtlTestResult );


More information about the Libreoffice-commits mailing list