From 091ba739bad456938d462d808f5a76927d884ed9 Mon Sep 17 00:00:00 2001 From: August Sodora Date: Sat, 26 Nov 2011 13:55:52 -0500 Subject: Added test for linguistic::RemoveHyphen and some simplification --- svl/CppunitTest_svl_lngmisc.mk | 36 ++++++++++++++++++ svl/Module_svl.mk | 4 ++ svl/inc/svl/lngmisc.hxx | 2 + svl/qa/unit/test_lngmisc.cxx | 83 ++++++++++++++++++++++++++++++++++++++++++ svl/source/misc/lngmisc.cxx | 12 ++---- 5 files changed, 129 insertions(+), 8 deletions(-) create mode 100644 svl/CppunitTest_svl_lngmisc.mk create mode 100644 svl/qa/unit/test_lngmisc.cxx (limited to 'svl') diff --git a/svl/CppunitTest_svl_lngmisc.mk b/svl/CppunitTest_svl_lngmisc.mk new file mode 100644 index 000000000000..89c211bc9df3 --- /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 880db26e3c98..6367ee73956d 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 176022f98b3f..5278aed16577 100644 --- a/svl/inc/svl/lngmisc.hxx +++ b/svl/inc/svl/lngmisc.hxx @@ -31,6 +31,8 @@ #include "svl/svldllapi.h" +#include + class String; /////////////////////////////////////////////////////////////////////////// diff --git a/svl/qa/unit/test_lngmisc.cxx b/svl/qa/unit/test_lngmisc.cxx new file mode 100644 index 000000000000..47f671a9dfe6 --- /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 + +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 ca1b68a6c0e5..f204f4bf8924 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 ) -- cgit