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

Caolán McNamara caolan at kemper.freedesktop.org
Mon Feb 14 13:18:27 PST 2011


 sal/inc/rtl/strbuf.hxx                                         |    5 
 sal/inc/rtl/ustrbuf.hxx                                        |    6 
 sal/prj/build.lst                                              |    1 
 sal/qa/rtl/oustringbuffer/makefile.mk                          |   49 +--
 sal/qa/rtl/oustringbuffer/rtl_OUStringBuffer2.cxx              |  103 -------
 sal/qa/rtl/oustringbuffer/test_oustringbuffer_noadditional.cxx |   36 ++
 sal/qa/rtl/oustringbuffer/test_oustringbuffer_tostring.cxx     |   64 ++++
 sal/qa/rtl/oustringbuffer/test_oustringbuffer_utf32.cxx        |  136 ++++++++++
 sal/qa/rtl/strings/makefile.mk                                 |    1 
 sal/qa/rtl/strings/test_oustringbuffer_utf32.cxx               |  136 ----------
 10 files changed, 265 insertions(+), 272 deletions(-)

New commits:
commit d52a7e72ce312570207d4ac7cf3ce5d9c13f1072
Author: Sébastien Le Ray <sebastien-libreoffice at orniz.org>
Date:   Sat Feb 12 14:48:56 2011 +0100

    Unit test cleanup for OUStringBuffer.
    
    Moved OUStringBuffer related tests from qa/srt/strings to
    qa/rt/oustringbuffer and reactivated it in project build.
    It seems that rtl_OUStringBuffer2.cxx was replaced by
    test_oustringbuffer_utf32.cxx so the later has been removed.
    
    Added unit tests for toString.

diff --git a/sal/prj/build.lst b/sal/prj/build.lst
index 0d53b82..1b38581 100644
--- a/sal/prj/build.lst
+++ b/sal/prj/build.lst
@@ -22,3 +22,4 @@ sa sal\qa\osl\file nmake - u sa_qa_osl_file sa_cppunittester sa_util NULL
 sa sal\qa\osl\module nmake - u sa_qa_osl_module sa_cppunittester sa_util NULL
 sa sal\qa\osl\condition nmake - all sa_qa_osl_condition sa_cppunittester sa_util NULL
 sa sal\qa\rtl\strings nmake - all sa_qa_rt_strings sa_cppunittester sa_util NULL
+sa sal\qa\rtl\oustringbuffer nmake - all sa_qa_rt_oustringbuffer sa_cppunittester sa_util NULL
diff --git a/sal/qa/rtl/oustringbuffer/makefile.mk b/sal/qa/rtl/oustringbuffer/makefile.mk
index 544f7b7..9165daa 100644
--- a/sal/qa/rtl/oustringbuffer/makefile.mk
+++ b/sal/qa/rtl/oustringbuffer/makefile.mk
@@ -25,46 +25,31 @@
 #
 #*************************************************************************
 
-PRJ=..$/..$/..
-INCPRE+= $(PRJ)$/qa$/inc
+PRJ := ..$/..$/..
+PRJNAME := sal
 
-PRJNAME=sal
-TARGET=rtl_oustringbuffer2
+TARGET := qa_rtl_oustringbuffer
 
-ENABLE_EXCEPTIONS=TRUE
+ENABLE_EXCEPTIONS := TRUE
 
-# --- Settings -----------------------------------------------------
+.INCLUDE: settings.mk
 
-.INCLUDE :  settings.mk
 
 CFLAGS+= $(LFS_CFLAGS)
 CXXFLAGS+= $(LFS_CFLAGS)
 
 CFLAGSCXX += $(CPPUNIT_CFLAGS)
 
-# BEGIN ----------------------------------------------------------------
-# auto generated Target:joblist by codegen.pl
-SHL1OBJS=  \
-    $(SLO)$/rtl_OUStringBuffer2.obj
-
-SHL1TARGET= rtl_OUStringBuffer2
-SHL1STDLIBS= $(SALLIB) $(CPPUNITLIB) $(TESTSHL2LIB)
-
-SHL1IMPLIB= i$(SHL1TARGET)
-# SHL1DEF=    $(MISC)$/$(SHL1TARGET).def
-
-DEF1NAME    =$(SHL1TARGET)
-# DEF1EXPORTFILE= export.exp
-SHL1VERSIONMAP= $(PRJ)$/qa$/export.map
-# auto generated Target:joblist
-# END ------------------------------------------------------------------
-
-#------------------------------- All object files -------------------------------
-# do this here, so we get right dependencies
-# SLOFILES=$(SHL1OBJS)
-
-# --- Targets ------------------------------------------------------
-
-.INCLUDE :  target.mk
-.INCLUDE : _cppunit.mk
+SHL1TARGET := $(TARGET)
+SHL1OBJS := \
+    $(SLO)$/test_oustringbuffer_utf32.obj \
+    $(SLO)$/test_oustringbuffer_tostring.obj \
+    $(SLO)$/test_oustringbuffer_noadditional.obj
+SHL1IMPLIB := i$(SHL1TARGET)
+SHL1STDLIBS := $(SALLIB) $(CPPUNITLIB)
+SHL1VERSIONMAP := $(PRJ)$/qa$/export.map
+DEF1NAME := $(SHL1TARGET)
+
+.INCLUDE: target.mk
+.INCLUDE: $(PRJ)$/qa$/cppunit_local.mk
 
diff --git a/sal/qa/rtl/oustringbuffer/rtl_OUStringBuffer2.cxx b/sal/qa/rtl/oustringbuffer/rtl_OUStringBuffer2.cxx
deleted file mode 100644
index 119985a..0000000
--- a/sal/qa/rtl/oustringbuffer/rtl_OUStringBuffer2.cxx
+++ /dev/null
@@ -1,103 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org.  If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_sal.hxx"
-#include <testshl/simpleheader.hxx>
-#include "stringhelper.hxx"
-#include <rtl/ustrbuf.hxx>
-#include <rtl/uri.hxx>
-
-namespace rtl_OUStringBuffer
-{
-
-
-class insertUtf32 : public CppUnit::TestFixture
-{
-public:
-    // initialise your test code values here.
-    void setUp()
-    {
-    }
-
-    void tearDown()
-    {
-    }
-
-    void insertUtf32_001()
-        {
-            ::rtl::OUStringBuffer aUStrBuf(4);
-            aUStrBuf.insertUtf32(0,0x10ffff);
-
-            rtl::OUString suStr = aUStrBuf.makeStringAndClear();
-            rtl::OUString suStr2 = rtl::Uri::encode(suStr, rtl_UriCharClassUnoParamValue, rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8);
-
-            rtl::OString sStr;
-            sStr <<= suStr2;
-            t_print("%s\n", sStr.getStr());
-
-            CPPUNIT_ASSERT_MESSAGE("Strings must be '%F4%8F%BF%BF'", sStr.equals(rtl::OString("%F4%8F%BF%BF")) == sal_True);
-        }
-
-    void insertUtf32_002()
-        {
-            ::rtl::OUStringBuffer aUStrBuf(4);
-            aUStrBuf.insertUtf32(0,0x41);
-            aUStrBuf.insertUtf32(1,0x42);
-            aUStrBuf.insertUtf32(2,0x43);
-
-            rtl::OUString suStr = aUStrBuf.makeStringAndClear();
-            rtl::OUString suStr2 = rtl::Uri::encode(suStr, rtl_UriCharClassUnoParamValue, rtl_UriEncodeKeepEscapes, RTL_TEXTENCODING_UTF8);
-
-            rtl::OString sStr;
-            sStr <<= suStr2;
-            t_print("%s\n", sStr.getStr());
-
-            CPPUNIT_ASSERT_MESSAGE("Strings must be 'ABC'", sStr.equals(rtl::OString("ABC")) == sal_True);
-        }
-
-    CPPUNIT_TEST_SUITE(insertUtf32);
-    CPPUNIT_TEST(insertUtf32_001);
-    CPPUNIT_TEST(insertUtf32_002);
-    CPPUNIT_TEST_SUITE_END();
-}; // class getToken
-
-// -----------------------------------------------------------------------------
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_OUStringBuffer::insertUtf32, "rtl_OUStringBuffer");
-
-} // namespace rtl_OUStringBuffer
-
-
-// -----------------------------------------------------------------------------
-
-// this macro creates an empty function, which will called by the RegisterAllFunctions()
-// to let the user the possibility to also register some functions by hand.
-NOADDITIONAL;
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/qa/rtl/oustringbuffer/test_oustringbuffer_noadditional.cxx b/sal/qa/rtl/oustringbuffer/test_oustringbuffer_noadditional.cxx
new file mode 100644
index 0000000..18e8a63
--- /dev/null
+++ b/sal/qa/rtl/oustringbuffer/test_oustringbuffer_noadditional.cxx
@@ -0,0 +1,36 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sal.hxx"
+
+#include <cppunit/plugin/TestPlugIn.h>
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/qa/rtl/oustringbuffer/test_oustringbuffer_tostring.cxx b/sal/qa/rtl/oustringbuffer/test_oustringbuffer_tostring.cxx
new file mode 100644
index 0000000..31aecac
--- /dev/null
+++ b/sal/qa/rtl/oustringbuffer/test_oustringbuffer_tostring.cxx
@@ -0,0 +1,64 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sal.hxx"
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/TestAssert.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include "rtl/ustrbuf.hxx"
+#include "rtl/ustring.hxx"
+
+namespace test { namespace oustringbuffer {
+
+class ToString: public CppUnit::TestFixture {
+private:
+    void testToString();
+
+    CPPUNIT_TEST_SUITE(ToString);
+    CPPUNIT_TEST(testToString);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+} }
+
+CPPUNIT_TEST_SUITE_REGISTRATION(test::oustringbuffer::ToString);
+
+void test::oustringbuffer::ToString::testToString() {
+    rtl::OUStringBuffer sb(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("test string")));
+    rtl::OUString str = sb.toString();
+    CPPUNIT_ASSERT(str.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("test string")));
+    // returned OUString must be independent from sb
+    sb.append('a');
+    CPPUNIT_ASSERT(str.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("test string")));
+    sb.setLength(0);
+    CPPUNIT_ASSERT(str.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("test string")));
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/qa/rtl/oustringbuffer/test_oustringbuffer_utf32.cxx b/sal/qa/rtl/oustringbuffer/test_oustringbuffer_utf32.cxx
new file mode 100644
index 0000000..a7609c5
--- /dev/null
+++ b/sal/qa/rtl/oustringbuffer/test_oustringbuffer_utf32.cxx
@@ -0,0 +1,136 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sal.hxx"
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/TestAssert.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include "rtl/strbuf.hxx"
+#include "rtl/ustrbuf.hxx"
+#include "rtl/ustring.h"
+#include "rtl/ustring.hxx"
+
+namespace test { namespace oustringbuffer {
+
+class Utf32: public CppUnit::TestFixture {
+private:
+    void appendUtf32();
+
+    void insertUtf32();
+
+    CPPUNIT_TEST_SUITE(Utf32);
+    CPPUNIT_TEST(appendUtf32);
+    CPPUNIT_TEST(insertUtf32);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+} }
+
+CPPUNIT_TEST_SUITE_REGISTRATION(test::oustringbuffer::Utf32);
+
+namespace {
+
+void appendString(rtl::OStringBuffer & buffer, rtl::OUString const & string) {
+    buffer.append('"');
+    for (int i = 0; i < string.getLength(); ++i) {
+        buffer.append(RTL_CONSTASCII_STRINGPARAM("\\u"));
+        sal_Unicode c = string[i];
+        if (c < 0x1000) {
+            buffer.append('0');
+            if (c < 0x100) {
+                buffer.append('0');
+                if (c < 0x10) {
+                    buffer.append('0');
+                }
+            }
+        }
+        buffer.append(
+            static_cast< sal_Int32 >(c), static_cast< sal_Int16 >(16));
+    }
+    buffer.append('"');
+}
+
+void createMessage(
+    rtl::OStringBuffer & message, rtl::OUString const & string1,
+    rtl::OUString const & string2)
+{
+    message.setLength(0);
+    appendString(message, string1);
+    message.append(RTL_CONSTASCII_STRINGPARAM(" vs. "));
+    appendString(message, string2);
+}
+
+}
+
+void test::oustringbuffer::Utf32::appendUtf32() {
+    int const str1Len = 3;
+    sal_Unicode const str1[str1Len] = { 'a', 'b', 'c' };
+    int const str2Len = 4;
+    sal_Unicode const str2[str2Len] = { 'a', 'b', 'c', 'd' };
+    int const str3Len = 6;
+    sal_Unicode const str3[str3Len] = { 'a', 'b', 'c', 'd', 0xD800, 0xDC00 };
+    rtl::OStringBuffer message;
+    rtl::OUStringBuffer buf1(rtl::OUString(str1, str1Len));
+    buf1.appendUtf32('d');
+    rtl::OUString res1(buf1.makeStringAndClear());
+    createMessage(message, res1, rtl::OUString(str2, str2Len));
+    CPPUNIT_ASSERT_MESSAGE(
+        (const char *) message.getStr(), res1 == rtl::OUString(str2, str2Len));
+    rtl::OUStringBuffer buf2(rtl::OUString(str2, str2Len));
+    buf2.appendUtf32(0x10000);
+    rtl::OUString res2(buf2.makeStringAndClear());
+    createMessage(message, res2, rtl::OUString(str3, str3Len));
+    CPPUNIT_ASSERT_MESSAGE(
+        (const char *)message.getStr(), res2 == rtl::OUString(str3, str3Len));
+}
+
+void test::oustringbuffer::Utf32::insertUtf32() {
+    int const str1Len = 3;
+    sal_Unicode const str1[str1Len] = { 'a', 'b', 'c' };
+    int const str2Len = 4;
+    sal_Unicode const str2[str2Len] = { 'a', 'b', 'd', 'c' };
+    int const str3Len = 6;
+    sal_Unicode const str3[str3Len] = { 'a', 'b', 0xDBFF, 0xDFFF, 'd', 'c' };
+    rtl::OStringBuffer message;
+    rtl::OUStringBuffer buf1(rtl::OUString(str1, str1Len));
+    buf1.insertUtf32(2, 'd');
+    rtl::OUString res1(buf1.makeStringAndClear());
+    createMessage(message, res1, rtl::OUString(str2, str2Len));
+    CPPUNIT_ASSERT_MESSAGE(
+        (const char *) message.getStr(), res1 == rtl::OUString(str2, str2Len));
+    rtl::OUStringBuffer buf2(rtl::OUString(str2, str2Len));
+    buf2.insertUtf32(2, 0x10FFFF);
+    rtl::OUString res2(buf2.makeStringAndClear());
+    createMessage(message, res2, rtl::OUString(str3, str3Len));
+    CPPUNIT_ASSERT_MESSAGE(
+        (const char *) message.getStr(), res2 == rtl::OUString(str3, str3Len));
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/qa/rtl/strings/makefile.mk b/sal/qa/rtl/strings/makefile.mk
index d167c47..2b07539 100644
--- a/sal/qa/rtl/strings/makefile.mk
+++ b/sal/qa/rtl/strings/makefile.mk
@@ -42,7 +42,6 @@ CFLAGSCXX += $(CPPUNIT_CFLAGS)
 
 SHL1TARGET := $(TARGET)
 SHL1OBJS := \
-    $(SLO)$/test_oustringbuffer_utf32.obj \
     $(SLO)$/test_oustring_compare.obj \
     $(SLO)$/test_oustring_convert.obj \
     $(SLO)$/test_oustring_endswith.obj \
diff --git a/sal/qa/rtl/strings/test_oustringbuffer_utf32.cxx b/sal/qa/rtl/strings/test_oustringbuffer_utf32.cxx
deleted file mode 100644
index a7609c5..0000000
--- a/sal/qa/rtl/strings/test_oustringbuffer_utf32.cxx
+++ /dev/null
@@ -1,136 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
- * Copyright 2000, 2010 Oracle and/or its affiliates.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org.  If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_sal.hxx"
-
-#include <cppunit/TestFixture.h>
-#include <cppunit/TestAssert.h>
-#include <cppunit/extensions/HelperMacros.h>
-#include "rtl/strbuf.hxx"
-#include "rtl/ustrbuf.hxx"
-#include "rtl/ustring.h"
-#include "rtl/ustring.hxx"
-
-namespace test { namespace oustringbuffer {
-
-class Utf32: public CppUnit::TestFixture {
-private:
-    void appendUtf32();
-
-    void insertUtf32();
-
-    CPPUNIT_TEST_SUITE(Utf32);
-    CPPUNIT_TEST(appendUtf32);
-    CPPUNIT_TEST(insertUtf32);
-    CPPUNIT_TEST_SUITE_END();
-};
-
-} }
-
-CPPUNIT_TEST_SUITE_REGISTRATION(test::oustringbuffer::Utf32);
-
-namespace {
-
-void appendString(rtl::OStringBuffer & buffer, rtl::OUString const & string) {
-    buffer.append('"');
-    for (int i = 0; i < string.getLength(); ++i) {
-        buffer.append(RTL_CONSTASCII_STRINGPARAM("\\u"));
-        sal_Unicode c = string[i];
-        if (c < 0x1000) {
-            buffer.append('0');
-            if (c < 0x100) {
-                buffer.append('0');
-                if (c < 0x10) {
-                    buffer.append('0');
-                }
-            }
-        }
-        buffer.append(
-            static_cast< sal_Int32 >(c), static_cast< sal_Int16 >(16));
-    }
-    buffer.append('"');
-}
-
-void createMessage(
-    rtl::OStringBuffer & message, rtl::OUString const & string1,
-    rtl::OUString const & string2)
-{
-    message.setLength(0);
-    appendString(message, string1);
-    message.append(RTL_CONSTASCII_STRINGPARAM(" vs. "));
-    appendString(message, string2);
-}
-
-}
-
-void test::oustringbuffer::Utf32::appendUtf32() {
-    int const str1Len = 3;
-    sal_Unicode const str1[str1Len] = { 'a', 'b', 'c' };
-    int const str2Len = 4;
-    sal_Unicode const str2[str2Len] = { 'a', 'b', 'c', 'd' };
-    int const str3Len = 6;
-    sal_Unicode const str3[str3Len] = { 'a', 'b', 'c', 'd', 0xD800, 0xDC00 };
-    rtl::OStringBuffer message;
-    rtl::OUStringBuffer buf1(rtl::OUString(str1, str1Len));
-    buf1.appendUtf32('d');
-    rtl::OUString res1(buf1.makeStringAndClear());
-    createMessage(message, res1, rtl::OUString(str2, str2Len));
-    CPPUNIT_ASSERT_MESSAGE(
-        (const char *) message.getStr(), res1 == rtl::OUString(str2, str2Len));
-    rtl::OUStringBuffer buf2(rtl::OUString(str2, str2Len));
-    buf2.appendUtf32(0x10000);
-    rtl::OUString res2(buf2.makeStringAndClear());
-    createMessage(message, res2, rtl::OUString(str3, str3Len));
-    CPPUNIT_ASSERT_MESSAGE(
-        (const char *)message.getStr(), res2 == rtl::OUString(str3, str3Len));
-}
-
-void test::oustringbuffer::Utf32::insertUtf32() {
-    int const str1Len = 3;
-    sal_Unicode const str1[str1Len] = { 'a', 'b', 'c' };
-    int const str2Len = 4;
-    sal_Unicode const str2[str2Len] = { 'a', 'b', 'd', 'c' };
-    int const str3Len = 6;
-    sal_Unicode const str3[str3Len] = { 'a', 'b', 0xDBFF, 0xDFFF, 'd', 'c' };
-    rtl::OStringBuffer message;
-    rtl::OUStringBuffer buf1(rtl::OUString(str1, str1Len));
-    buf1.insertUtf32(2, 'd');
-    rtl::OUString res1(buf1.makeStringAndClear());
-    createMessage(message, res1, rtl::OUString(str2, str2Len));
-    CPPUNIT_ASSERT_MESSAGE(
-        (const char *) message.getStr(), res1 == rtl::OUString(str2, str2Len));
-    rtl::OUStringBuffer buf2(rtl::OUString(str2, str2Len));
-    buf2.insertUtf32(2, 0x10FFFF);
-    rtl::OUString res2(buf2.makeStringAndClear());
-    createMessage(message, res2, rtl::OUString(str3, str3Len));
-    CPPUNIT_ASSERT_MESSAGE(
-        (const char *) message.getStr(), res2 == rtl::OUString(str3, str3Len));
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 5e8daecbf11733890a0996fc39fc32c2c8577609
Author: Sébastien Le Ray <sebastien-libreoffice at orniz.org>
Date:   Sat Feb 12 14:48:08 2011 +0100

    Added toString() method to O(U)StringBuffer.

diff --git a/sal/inc/rtl/strbuf.hxx b/sal/inc/rtl/strbuf.hxx
index 9a78044..21ff603 100644
--- a/sal/inc/rtl/strbuf.hxx
+++ b/sal/inc/rtl/strbuf.hxx
@@ -275,6 +275,11 @@ public:
      */
     const sal_Char* getStr() const { return pData->buffer; }
 
+    /**
+        Return a OString instance reflecting the current content
+        of this OStringBuffer.
+     */
+    const OString toString() const { return OString(pData->buffer); }
 
     /**
         The character at the specified index of this string buffer is set
diff --git a/sal/inc/rtl/ustrbuf.hxx b/sal/inc/rtl/ustrbuf.hxx
index 4977aac..b6160cc 100644
--- a/sal/inc/rtl/ustrbuf.hxx
+++ b/sal/inc/rtl/ustrbuf.hxx
@@ -274,6 +274,12 @@ public:
      */
     const sal_Unicode*  getStr() const { return pData->buffer; }
 
+    /**
+        Return a OUString instance reflecting the current content
+        of this OUStringBuffer.
+     */
+    const OUString toString() const { return OUString(pData->buffer); }
+
 
     /**
         The character at the specified index of this string buffer is set


More information about the Libreoffice-commits mailing list