svl/CppunitTest_svl_lngmisc.mk |   36 +++++++++++++++++
 svl/Module_svl.mk              |    4 +
 svl/inc/svl/lngmisc.hxx        |   15 +++----
 svl/qa/unit/test_lngmisc.cxx   |   83 +++++++++++++++++++++++++++++++++++++++++
 svl/source/misc/lngmisc.cxx    |   12 +----
 5 files changed, 134 insertions(+), 16 deletions(-)

New commits:
commit 091ba739bad456938d462d808f5a76927d884ed9
Author: August Sodora <aug...@gmail.com>
Date:   Sat Nov 26 13:55:52 2011 -0500

    Added test for linguistic::RemoveHyphen and some simplification

diff --git a/svl/CppunitTest_svl_lngmisc.mk b/svl/CppunitTest_svl_lngmisc.mk
new file mode 100644
index 0000000..89c211b
--- /dev/null
+++ b/svl/CppunitTest_svl_lngmisc.mk
@@ -0,0 +1,36 @@
+$(eval $(call gb_CppunitTest_CppunitTest,svl_lngmisc))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,svl_lngmisc, \
+svl/qa/unit/test_lngmisc \
+))
+
+# add a list of all needed libraries here
+$(eval $(call gb_CppunitTest_add_linked_libs,svl_lngmisc, \
+    comphelper \
+    cppu \
+    cppuhelper \
+    sal \
+    salhelper \
+    sb \
+    sot \
+    svl \
+    svt \
+    tl \
+    utl \
+    vcl \
+    xcr \
+    $(gb_STDLIBS) \
+))
+
+ifeq ($(GUI),WNT)
+$(eval $(call gb_CppunitTest_add_linked_libs,svl_lngmisc, \
+       oleaut32 \
+))
+endif
+
+$(eval $(call gb_CppunitTest_set_include,svl_lngmisc,\
+-I$(realpath $(SRCDIR)/svl/source/inc) \
+-I$(realpath $(SRCDIR)/svl/inc) \
+$$(INCLUDE) \
+-I$(OUTDIR)/inc \
+))
\ No newline at end of file
diff --git a/svl/Module_svl.mk b/svl/Module_svl.mk
index 880db26..6367ee7 100644
--- a/svl/Module_svl.mk
+++ b/svl/Module_svl.mk
@@ -36,6 +36,10 @@ $(eval $(call gb_Module_add_targets,svl,\
     Package_inc \
 ))
 
+$(eval $(call gb_Module_add_check_targets,svl,\
+       CppunitTest_svl_lngmisc \
+))
+
 $(eval $(call gb_Module_add_subsequentcheck_targets,svl,\
     JunitTest_svl_complex \
 ))
diff --git a/svl/inc/svl/lngmisc.hxx b/svl/inc/svl/lngmisc.hxx
index 176022f..5278aed 100644
--- a/svl/inc/svl/lngmisc.hxx
+++ b/svl/inc/svl/lngmisc.hxx
@@ -31,6 +31,8 @@
 
 #include "svl/svldllapi.h"
 
+#include <rtl/ustring.hxx>
+
 class String;
 
 ///////////////////////////////////////////////////////////////////////////
diff --git a/svl/qa/unit/test_lngmisc.cxx b/svl/qa/unit/test_lngmisc.cxx
new file mode 100644
index 0000000..47f671a
--- /dev/null
+++ b/svl/qa/unit/test_lngmisc.cxx
@@ -0,0 +1,83 @@
+#include "sal/config.h"
+#include "sal/precppunit.hxx"
+
+#include "cppunit/TestAssert.h"
+#include "cppunit/TestFixture.h"
+#include "cppunit/extensions/HelperMacros.h"
+#include "cppunit/plugin/TestPlugIn.h"
+
+#include "svl/lngmisc.hxx"
+
+#include <rtl/ustrbuf.hxx>
+
+namespace
+{
+  class LngMiscTest : public CppUnit::TestFixture
+  {
+  private:
+    void testRemoveHyphens();
+    //    void testRemoveControlChars();
+    //    void testReplaceControlChars();
+    //    void testGetThesaurusReplaceText();
+
+    CPPUNIT_TEST_SUITE(LngMiscTest);
+
+    CPPUNIT_TEST(testRemoveHyphens);
+    //    CPPUNIT_TEST(testRemoveControlChars);
+    //    CPPUNIT_TEST(testReplaceControlChars);
+    //    CPPUNIT_TEST(testGetThesaurusReplaceText);
+
+    CPPUNIT_TEST_SUITE_END();
+  };
+
+  void LngMiscTest::testRemoveHyphens()
+  {
+    ::rtl::OUString str1(RTL_CONSTASCII_USTRINGPARAM(""));
+    ::rtl::OUString str2(RTL_CONSTASCII_USTRINGPARAM("a-b--c---"));
+
+    ::rtl::OUStringBuffer str3Buf;
+    str3Buf.append(SVT_SOFT_HYPHEN);
+    str3Buf.append(SVT_HARD_HYPHEN);
+    str3Buf.append(SVT_HARD_HYPHEN);
+    ::rtl::OUString str3(str3Buf.makeStringAndClear());
+
+    ::rtl::OUString str4(RTL_CONSTASCII_USTRINGPARAM("asdf"));
+
+    bool bModified = linguistic::RemoveHyphens(str1);
+    CPPUNIT_ASSERT(!bModified);
+    CPPUNIT_ASSERT(str1.isEmpty());
+
+    // Note that '-' isn't a hyphen to RemoveHyphens.
+    bModified = linguistic::RemoveHyphens(str2);
+    CPPUNIT_ASSERT(!bModified);
+    CPPUNIT_ASSERT(str2.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("a-b--c---")));
+
+    bModified = linguistic::RemoveHyphens(str3);
+    CPPUNIT_ASSERT(bModified);
+    CPPUNIT_ASSERT(str3.isEmpty());
+
+    bModified = linguistic::RemoveHyphens(str4);
+    CPPUNIT_ASSERT(!bModified);
+    CPPUNIT_ASSERT(str4.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("asdf")));
+  }
+
+  /*
+  void LngMiscTest::testRemoveControlChars()
+  {
+    CPPUNIT_ASSERT(true);
+  }
+
+  void LngMiscTest::testReplaceControlChars()
+  {
+    CPPUNIT_ASSERT(true);
+  }
+
+  void LngMiscTest::testGetThesaurusReplaceText()
+  {
+    CPPUNIT_ASSERT(true);
+  }
+  */
+
+  CPPUNIT_TEST_SUITE_REGISTRATION(LngMiscTest);
+}
+CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/svl/source/misc/lngmisc.cxx b/svl/source/misc/lngmisc.cxx
index ca1b68a..f204f4b 100644
--- a/svl/source/misc/lngmisc.cxx
+++ b/svl/source/misc/lngmisc.cxx
@@ -58,14 +58,10 @@ sal_Int32 GetNumControlChars( const OUString &rTxt )
 
 sal_Bool RemoveHyphens( OUString &rTxt )
 {
-    sal_Bool bModified = sal_False;
-    if (HasHyphens(rTxt))
-    {
-        rTxt = comphelper::string::remove(rTxt, SVT_SOFT_HYPHEN);
-        rTxt = comphelper::string::remove(rTxt, SVT_HARD_HYPHEN);
-        bModified = sal_True;
-    }
-    return bModified;
+    sal_Int32 n = rTxt.getLength();
+    rTxt = comphelper::string::remove(rTxt, SVT_SOFT_HYPHEN);
+    rTxt = comphelper::string::remove(rTxt, SVT_HARD_HYPHEN);
+    return n != rTxt.getLength();
 }
 
 sal_Bool RemoveControlChars( OUString &rTxt )
commit e81f36f6b62c6686f0156aef151ad8bf6d1b7917
Author: August Sodora <aug...@gmail.com>
Date:   Sat Nov 26 13:19:58 2011 -0500

    C-style cast -> C++-style cast

diff --git a/svl/inc/svl/lngmisc.hxx b/svl/inc/svl/lngmisc.hxx
index 8976a65..176022f 100644
--- a/svl/inc/svl/lngmisc.hxx
+++ b/svl/inc/svl/lngmisc.hxx
@@ -35,11 +35,11 @@ class String;
 
 ///////////////////////////////////////////////////////////////////////////
 
-#define SVT_SOFT_HYPHEN ((sal_Unicode) 0x00AD)
-#define SVT_HARD_HYPHEN ((sal_Unicode) 0x2011)
+#define SVT_SOFT_HYPHEN (static_cast<sal_Unicode>(0x00AD))
+#define SVT_HARD_HYPHEN (static_cast<sal_Unicode>(0x2011))
 
 // the non-breaking space
-#define SVT_HARD_SPACE  ((sal_Unicode) 0x00A0)
+#define SVT_HARD_SPACE  (static_cast<sal_Unicode>(0x00A0))
 
 namespace linguistic
 {
@@ -52,10 +52,9 @@ inline sal_Bool IsHyphen( sal_Unicode cChar )
 
 inline sal_Bool IsControlChar( sal_Unicode cChar )
 {
-    return cChar < (sal_Unicode) ' ';
+    return cChar < static_cast<sal_Unicode>(' ');
 }
 
-
 inline sal_Bool HasHyphens( const rtl::OUString &rTxt )
 {
     return  rTxt.indexOf( SVT_SOFT_HYPHEN ) != -1  ||
commit a97dc8f45d3d8c5b17acb5b694df1db5ae74e2ca
Author: August Sodora <aug...@gmail.com>
Date:   Sat Nov 26 13:18:03 2011 -0500

    Remove unnecessary includes

diff --git a/svl/inc/svl/lngmisc.hxx b/svl/inc/svl/lngmisc.hxx
index 9e6c5c2..8976a65 100644
--- a/svl/inc/svl/lngmisc.hxx
+++ b/svl/inc/svl/lngmisc.hxx
@@ -30,10 +30,8 @@
 #define _SVTOOLS_LNGMISC_HXX_
 
 #include "svl/svldllapi.h"
-#include <tools/solar.h>
-#include <sal/types.h>
-#include <rtl/ustring.hxx>
-#include <tools/string.hxx>
+
+class String;
 
 ///////////////////////////////////////////////////////////////////////////
 
_______________________________________________
Libreoffice-commits mailing list
Libreoffice-commits@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to