sw/source/ui/app/appopt.cxx | 1 writerperfect/CppunitTest_writerperfect_stream.mk | 53 ++++ writerperfect/Module_writerperfect.mk | 6 writerperfect/qa/unit/WPXSvStreamTest.cxx | 252 ++++++++++++++++++++++ writerperfect/source/common/WPXSvStream.cxx | 2 5 files changed, 313 insertions(+), 1 deletion(-)
New commits: commit bb3a290e3b602169d3bee98108a8380dce51b608 Author: David Tardon <dtar...@redhat.com> Date: Thu Aug 8 16:37:58 2013 +0200 rhbz#994886 update unit in draw. obj. props toolbar I am not sure this is the only/correct way to do it (maybe it should be already handled by some broadcast from SFX_APP()->SetOptions()), but it is what Draw and Calc do (cf. handling of SID_ATTR_METRIC in SdModule::ApplyItemSet() and ScModule::ModifyOptions()). Change-Id: I25bada60188a96c6c82db5029c7475b45b595176 diff --git a/sw/source/ui/app/appopt.cxx b/sw/source/ui/app/appopt.cxx index b3fb4af..4998dd9 100644 --- a/sw/source/ui/app/appopt.cxx +++ b/sw/source/ui/app/appopt.cxx @@ -296,6 +296,7 @@ void SwModule::ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet ) if( SFX_ITEM_SET == rSet.GetItemState(SID_ATTR_METRIC, sal_False, &pItem ) ) { SFX_APP()->SetOptions(rSet); + PutItem(*pItem); const SfxUInt16Item* pMetricItem = (const SfxUInt16Item*)pItem; ::SetDfltMetric((FieldUnit)pMetricItem->GetValue(), !bTextDialog); } commit 988036c3c4fc7515aaaad7ff80664fc4c5fd8236 Author: David Tardon <dtar...@redhat.com> Date: Thu Aug 8 13:43:42 2013 +0200 add unit test for WPXSvInputStream Change-Id: Ia799cf54e8c90f68a8e74df72b0c8b6a33c41e7e diff --git a/writerperfect/CppunitTest_writerperfect_stream.mk b/writerperfect/CppunitTest_writerperfect_stream.mk new file mode 100644 index 0000000..f5b79c9 --- /dev/null +++ b/writerperfect/CppunitTest_writerperfect_stream.mk @@ -0,0 +1,53 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_CppunitTest_CppunitTest,writerperfect_stream)) + +$(eval $(call gb_CppunitTest_set_include,writerperfect_stream,\ + -I$(SRCDIR)/writerperfect/source/common \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_CppunitTest_use_api,writerperfect_stream,\ + offapi \ + udkapi \ +)) + +$(eval $(call gb_CppunitTest_use_ure,writerperfect_stream)) + +$(eval $(call gb_CppunitTest_use_externals,writerperfect_stream,\ + wpd \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,writerperfect_stream,\ + comphelper \ + cppu \ + sal \ + sot \ + test \ + utl \ +)) + +$(eval $(call gb_CppunitTest_use_static_libraries,writerperfect_stream,\ + writerperfect \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,writerperfect_stream)) + +$(eval $(call gb_CppunitTest_use_components,writerperfect_stream,\ + configmgr/source/configmgr \ + ucb/source/core/ucb1 \ + ucb/source/ucp/file/ucpfile1 \ +)) + +$(eval $(call gb_CppunitTest_add_exception_objects,writerperfect_stream,\ + writerperfect/qa/unit/WPXSvStreamTest \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/writerperfect/Module_writerperfect.mk b/writerperfect/Module_writerperfect.mk index b6a3990..fee590d 100644 --- a/writerperfect/Module_writerperfect.mk +++ b/writerperfect/Module_writerperfect.mk @@ -55,4 +55,10 @@ endif endif endif +ifneq (,$(SYSTEM_WPD)) +$(eval $(call gb_Module_add_check_targets,writerperfect,\ + CppunitTest_writerperfect_stream \ +)) +endif + # vim: set noet sw=4 ts=4: diff --git a/writerperfect/qa/unit/WPXSvStreamTest.cxx b/writerperfect/qa/unit/WPXSvStreamTest.cxx new file mode 100644 index 0000000..287d3fd --- /dev/null +++ b/writerperfect/qa/unit/WPXSvStreamTest.cxx @@ -0,0 +1,252 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <algorithm> +#include <cassert> + +#include <boost/shared_ptr.hpp> + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> + +#include "com/sun/star/io/XInputStream.hpp" +#include "com/sun/star/uno/Reference.hxx" + +#include "comphelper/seqstream.hxx" + +#include "rtl/ref.hxx" + +#include "test/bootstrapfixture.hxx" + +#include "WPXSvStream.hxx" + +namespace io = com::sun::star::io; +namespace uno = com::sun::star::uno; + +using boost::shared_ptr; + +using std::equal; + +namespace +{ + +class WPXSvStreamTest : public test::BootstrapFixture +{ +public: + CPPUNIT_TEST_SUITE(WPXSvStreamTest); + CPPUNIT_TEST(testRead); + CPPUNIT_TEST(testSeekSet); + CPPUNIT_TEST(testSeekCur); + CPPUNIT_TEST(testSeekEnd); + CPPUNIT_TEST_SUITE_END(); + +private: + void testRead(); + void testSeekSet(); + void testSeekCur(); + void testSeekEnd(); +}; + +static const char aText[] = "hello world"; + +shared_ptr<WPXInputStream> lcl_createStream() +{ + using comphelper::SequenceInputStream; + + const comphelper::ByteSequence aData(reinterpret_cast<const sal_Int8*>(aText), sizeof aText); + const uno::Reference<io::XInputStream> xInputStream(new SequenceInputStream(aData)); + + shared_ptr<WPXInputStream> pInputStream; + if (xInputStream.is()) + pInputStream.reset(new WPXSvInputStream(xInputStream)); + + return pInputStream; +} + +void WPXSvStreamTest::testRead() +{ + const shared_ptr<WPXInputStream> pInput(lcl_createStream()); + const unsigned long nLen = sizeof aText; + + unsigned long nReadBytes = 0; + const unsigned char* pData = 0; + const unsigned char* const pTextOrig = reinterpret_cast<const unsigned char*>(aText); + const unsigned char* pText = pTextOrig; + + // reading by small pieces + pData = pInput->read(1UL, nReadBytes); + CPPUNIT_ASSERT_EQUAL(1UL, nReadBytes); + CPPUNIT_ASSERT(equal(pText, pText + nReadBytes, pData)); + CPPUNIT_ASSERT(!pInput->atEOS()); + pText += nReadBytes; + + pData = pInput->read(2UL, nReadBytes); + CPPUNIT_ASSERT_EQUAL(2UL, nReadBytes); + CPPUNIT_ASSERT(equal(pText, pText + nReadBytes, pData)); + CPPUNIT_ASSERT(!pInput->atEOS()); + pText += nReadBytes; + + pData = pInput->read(3UL, nReadBytes); + CPPUNIT_ASSERT_EQUAL(3UL, nReadBytes); + CPPUNIT_ASSERT(equal(pText, pText + nReadBytes, pData)); + CPPUNIT_ASSERT(!pInput->atEOS()); + pText += nReadBytes; + + assert(nLen > 6); + pData = pInput->read(nLen - 6, nReadBytes); + CPPUNIT_ASSERT_EQUAL(nLen - 6, nReadBytes); + CPPUNIT_ASSERT(equal(pText, pText + nReadBytes, pData)); + CPPUNIT_ASSERT(pInput->atEOS()); + + // reading everything at once + pInput->seek(0, WPX_SEEK_SET); + pText = pTextOrig; + + pData = pInput->read(nLen, nReadBytes); + CPPUNIT_ASSERT_EQUAL(nLen, nReadBytes); + CPPUNIT_ASSERT(equal(pText, pText + nReadBytes, pData)); + CPPUNIT_ASSERT(pInput->atEOS()); + + // trying to read too much + pInput->seek(0, WPX_SEEK_SET); + pText = pTextOrig; + + pData = pInput->read(nLen + 1, nReadBytes); + CPPUNIT_ASSERT_EQUAL(nLen, nReadBytes); + CPPUNIT_ASSERT(equal(pText, pText + nReadBytes, pData)); + CPPUNIT_ASSERT(pInput->atEOS()); + + // trying to read nothing + pInput->seek(0, WPX_SEEK_SET); + pText = pTextOrig; + + pData = pInput->read(0UL, nReadBytes); + CPPUNIT_ASSERT_EQUAL(0UL, nReadBytes); + CPPUNIT_ASSERT_EQUAL(0L, pInput->tell()); + CPPUNIT_ASSERT(!pInput->atEOS()); +} + +void WPXSvStreamTest::testSeekSet() +{ + const shared_ptr<WPXInputStream> pInput(lcl_createStream()); + const size_t nLen = sizeof aText; + + // check initial state + CPPUNIT_ASSERT_EQUAL(0L, pInput->tell()); + CPPUNIT_ASSERT(!pInput->atEOS()); + + // valid seeks + CPPUNIT_ASSERT_EQUAL(0, pInput->seek(0, WPX_SEEK_SET)); + CPPUNIT_ASSERT_EQUAL(0L, pInput->tell()); + CPPUNIT_ASSERT(!pInput->atEOS()); + + CPPUNIT_ASSERT_EQUAL(0, pInput->seek(1, WPX_SEEK_SET)); + CPPUNIT_ASSERT_EQUAL(1L, pInput->tell()); + CPPUNIT_ASSERT(!pInput->atEOS()); + + CPPUNIT_ASSERT_EQUAL(0, pInput->seek(nLen, WPX_SEEK_SET)); + CPPUNIT_ASSERT(nLen == pInput->tell()); + CPPUNIT_ASSERT(pInput->atEOS()); + + // go back to the beginning + CPPUNIT_ASSERT_EQUAL(0, pInput->seek(0, WPX_SEEK_SET)); + CPPUNIT_ASSERT_EQUAL(0L, pInput->tell()); + + // invalid seeks + CPPUNIT_ASSERT(0 != pInput->seek(-1, WPX_SEEK_SET)); + // Okay, this is not defined. But it is what the WPXSvInputStream + // does ATM and it is reasonable. + CPPUNIT_ASSERT_EQUAL(0L, pInput->tell()); + CPPUNIT_ASSERT(!pInput->atEOS()); + + CPPUNIT_ASSERT(0 != pInput->seek(nLen + 1, WPX_SEEK_SET)); + CPPUNIT_ASSERT(nLen == pInput->tell()); + CPPUNIT_ASSERT(pInput->atEOS()); +} + +void WPXSvStreamTest::testSeekCur() +{ + const shared_ptr<WPXInputStream> pInput(lcl_createStream()); + const size_t nLen = sizeof aText; + + // check initial state + CPPUNIT_ASSERT(!pInput->atEOS()); + CPPUNIT_ASSERT_EQUAL(0L, pInput->tell()); + + // valid seeks + + CPPUNIT_ASSERT_EQUAL(0, pInput->seek(0, WPX_SEEK_CUR)); + CPPUNIT_ASSERT_EQUAL(0L, pInput->tell()); + CPPUNIT_ASSERT(!pInput->atEOS()); + + CPPUNIT_ASSERT_EQUAL(0, pInput->seek(1, WPX_SEEK_CUR)); + CPPUNIT_ASSERT_EQUAL(1L, pInput->tell()); + CPPUNIT_ASSERT(!pInput->atEOS()); + + CPPUNIT_ASSERT_EQUAL(0, pInput->seek(-1, WPX_SEEK_CUR)); + CPPUNIT_ASSERT_EQUAL(0L, pInput->tell()); + CPPUNIT_ASSERT(!pInput->atEOS()); + + // go back to the beginning + CPPUNIT_ASSERT_EQUAL(0, pInput->seek(0, WPX_SEEK_SET)); + CPPUNIT_ASSERT_EQUAL(0L, pInput->tell()); + + // invalid seeks + CPPUNIT_ASSERT(0 != pInput->seek(-1, WPX_SEEK_CUR)); + CPPUNIT_ASSERT_EQUAL(0L, pInput->tell()); + CPPUNIT_ASSERT(!pInput->atEOS()); + + CPPUNIT_ASSERT(0 != pInput->seek(nLen + 1, WPX_SEEK_CUR)); + CPPUNIT_ASSERT(nLen == pInput->tell()); + CPPUNIT_ASSERT(pInput->atEOS()); +} + +void WPXSvStreamTest::testSeekEnd() +{ + const shared_ptr<WPXInputStream> pInput(lcl_createStream()); + const size_t nLen = sizeof aText; + + // check initial state + CPPUNIT_ASSERT(!pInput->atEOS()); + CPPUNIT_ASSERT_EQUAL(0L, pInput->tell()); + + // valid seeks + CPPUNIT_ASSERT_EQUAL(0, pInput->seek(0, WPX_SEEK_END)); + CPPUNIT_ASSERT(nLen == pInput->tell()); + CPPUNIT_ASSERT(pInput->atEOS()); + + CPPUNIT_ASSERT_EQUAL(0, pInput->seek(-1, WPX_SEEK_END)); + CPPUNIT_ASSERT((nLen - 1) == pInput->tell()); + CPPUNIT_ASSERT(!pInput->atEOS()); + + CPPUNIT_ASSERT_EQUAL(0, pInput->seek(-nLen, WPX_SEEK_END)); + CPPUNIT_ASSERT_EQUAL(0L, pInput->tell()); + CPPUNIT_ASSERT(!pInput->atEOS()); + + // go back to the beginning + CPPUNIT_ASSERT_EQUAL(0, pInput->seek(0, WPX_SEEK_SET)); + CPPUNIT_ASSERT_EQUAL(0L, pInput->tell()); + + // invalid seeks + CPPUNIT_ASSERT(0 != pInput->seek(1, WPX_SEEK_END)); + CPPUNIT_ASSERT(nLen == pInput->tell()); + CPPUNIT_ASSERT(pInput->atEOS()); + + CPPUNIT_ASSERT(0 != pInput->seek(-nLen - 1, WPX_SEEK_END)); + CPPUNIT_ASSERT_EQUAL(0L, pInput->tell()); + CPPUNIT_ASSERT(!pInput->atEOS()); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(WPXSvStreamTest); + +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 3ce9508e31226f2b453877e34946dc5916519d86 Author: David Tardon <dtar...@redhat.com> Date: Thu Aug 8 13:43:11 2013 +0200 fix seek behind end of stream Change-Id: I38db7759df87edee8a14b311005c6e31ff8ae856 diff --git a/writerperfect/source/common/WPXSvStream.cxx b/writerperfect/source/common/WPXSvStream.cxx index e0c8d8c..dd35311 100644 --- a/writerperfect/source/common/WPXSvStream.cxx +++ b/writerperfect/source/common/WPXSvStream.cxx @@ -143,7 +143,7 @@ int WPXSvInputStreamImpl::seek(long offset, WPX_SEEK_TYPE seekType) tmpOffset = 0; retVal = -1; } - if (offset > mnLength) + if (tmpOffset > mnLength) { tmpOffset = mnLength; retVal = -1; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits