diff options
author | August Sodora <augsod@gmail.com> | 2011-11-26 13:55:52 -0500 |
---|---|---|
committer | August Sodora <augsod@gmail.com> | 2011-11-26 13:55:52 -0500 |
commit | 091ba739bad456938d462d808f5a76927d884ed9 (patch) | |
tree | 20ae59b7a508685c76e62d5768474f78c9fce50a | |
parent | e81f36f6b62c6686f0156aef151ad8bf6d1b7917 (diff) |
Added test for linguistic::RemoveHyphen and some simplification
-rw-r--r-- | svl/CppunitTest_svl_lngmisc.mk | 36 | ||||
-rw-r--r-- | svl/Module_svl.mk | 4 | ||||
-rw-r--r-- | svl/inc/svl/lngmisc.hxx | 2 | ||||
-rw-r--r-- | svl/qa/unit/test_lngmisc.cxx | 83 | ||||
-rw-r--r-- | svl/source/misc/lngmisc.cxx | 12 |
5 files changed, 129 insertions, 8 deletions
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 <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 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 <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 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 ) |