sc/CppunitTest_sc_editfieldobj_cell.mk | 134 +++++++++++++++++++++++++ sc/CppunitTest_sc_editfieldobj_header.mk | 134 +++++++++++++++++++++++++ sc/Module_sc.mk | 2 sc/qa/extras/sceditfieldobj-cell.cxx | 165 +++++++++++++++++++++++++++++++ sc/qa/extras/sceditfieldobj-header.cxx | 158 +++++++++++++++++++++++++++++ sc/source/ui/unoobj/fielduno.cxx | 9 - test/inc/test/text/xtextcontent.hxx | 4 test/inc/test/text/xtextfield.hxx | 4 test/source/text/xtextcontent.cxx | 1 9 files changed, 604 insertions(+), 7 deletions(-)
New commits: commit df92f499f963a5a4d8cb7100ea1f846bb0f91014 Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Sat Apr 28 00:23:51 2012 -0400 Fixed crash on tear down during cppunit test. Change-Id: I5573e554420967d8942295cabe788a9e56835ba0 diff --git a/sc/qa/extras/sceditfieldobj-cell.cxx b/sc/qa/extras/sceditfieldobj-cell.cxx index 962834a..e7ad2ed 100644 --- a/sc/qa/extras/sceditfieldobj-cell.cxx +++ b/sc/qa/extras/sceditfieldobj-cell.cxx @@ -83,7 +83,10 @@ void ScEditFieldObj_Cell::setUp() void ScEditFieldObj_Cell::tearDown() { if (nTest == NUMBER_OF_TESTS) + { + mxField.clear(); closeDocument(mxComponent); + } UnoApiTest::tearDown(); } diff --git a/sc/qa/extras/sceditfieldobj-header.cxx b/sc/qa/extras/sceditfieldobj-header.cxx index 85d9817..44bdeb5 100644 --- a/sc/qa/extras/sceditfieldobj-header.cxx +++ b/sc/qa/extras/sceditfieldobj-header.cxx @@ -86,7 +86,12 @@ void ScEditFieldObj_Header::setUp() void ScEditFieldObj_Header::tearDown() { if (nTest == NUMBER_OF_TESTS) + { + // Clear these before the component is destroyed. This is important! + mxField.clear(); + mxRightText.clear(); closeDocument(mxComponent); + } UnoApiTest::tearDown(); } commit 852f502efd7eff39db8168abdb4ae41eb5933123 Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Fri Apr 27 22:47:14 2012 -0400 Test the header field API for real. But it crashes on exit, due to some sort of order of deletion... Change-Id: Ife9da1c0a647038cbdc68410db5b211bcce5dfa4 diff --git a/sc/qa/extras/sceditfieldobj-header.cxx b/sc/qa/extras/sceditfieldobj-header.cxx index ab84b70..85d9817 100644 --- a/sc/qa/extras/sceditfieldobj-header.cxx +++ b/sc/qa/extras/sceditfieldobj-header.cxx @@ -32,17 +32,20 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> #include <com/sun/star/text/XText.hpp> #include <com/sun/star/text/XTextField.hpp> #include <com/sun/star/text/XTextFieldsSupplier.hpp> #include <com/sun/star/sheet/XSpreadsheetDocument.hpp> #include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XHeaderFooterContent.hpp> -#define NUMBER_OF_TESTS 3 +#define NUMBER_OF_TESTS 2 namespace sc_apitest { -class ScEditFieldObj_Header : public UnoApiTest, apitest::XTextField, apitest::XTextContent +class ScEditFieldObj_Header : public UnoApiTest, apitest::XTextContent { public: ScEditFieldObj_Header(); @@ -52,11 +55,9 @@ public: virtual uno::Reference<uno::XInterface> init(); virtual uno::Reference<text::XTextContent> getTextContent(); virtual uno::Reference<text::XTextRange> getTextRange(); - virtual bool isAttachSupported() { return true; } + virtual bool isAttachSupported() { return false; } CPPUNIT_TEST_SUITE(ScEditFieldObj_Header); - // XTextField - CPPUNIT_TEST(testGetPresentation); // XTextContent CPPUNIT_TEST(testGetAnchor); CPPUNIT_TEST(testAttach); @@ -66,11 +67,13 @@ private: static sal_Int32 nTest; static uno::Reference<lang::XComponent> mxComponent; static uno::Reference<text::XTextField> mxField; + static uno::Reference<text::XText> mxRightText; }; sal_Int32 ScEditFieldObj_Header::nTest = 0; uno::Reference<lang::XComponent> ScEditFieldObj_Header::mxComponent; uno::Reference<text::XTextField> ScEditFieldObj_Header::mxField; +uno::Reference<text::XText> ScEditFieldObj_Header::mxRightText; ScEditFieldObj_Header::ScEditFieldObj_Header() {} @@ -88,23 +91,9 @@ void ScEditFieldObj_Header::tearDown() UnoApiTest::tearDown(); } -namespace { - -uno::Reference<text::XTextField> getNewField(const uno::Reference<lang::XMultiServiceFactory>& xSM) -{ - uno::Reference<text::XTextField> xField( - xSM->createInstance("com.sun.star.text.TextField.URL"), UNO_QUERY_THROW); - uno::Reference<beans::XPropertySet> xPropSet(xField, UNO_QUERY_THROW); - xPropSet->setPropertyValue("Representation", uno::makeAny(rtl::OUString("LibreOffice"))); - xPropSet->setPropertyValue("URL", uno::makeAny(rtl::OUString("http://www.libreoffice.org/"))); - return xField; -} - -} - uno::Reference<uno::XInterface> ScEditFieldObj_Header::init() { - // Return a field that's already in the cell. + // Return a field that's already in the header. if (!mxField.is()) { if (!mxComponent.is()) @@ -114,21 +103,28 @@ uno::Reference<uno::XInterface> ScEditFieldObj_Header::init() uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, UNO_QUERY_THROW); // Create a new URL field object, and populate it with name and URL. - mxField = getNewField(xSM); + mxField.set(xSM->createInstance("com.sun.star.text.TextField.Time"), UNO_QUERY_THROW); + + uno::Reference<style::XStyleFamiliesSupplier> xSFS(mxComponent, UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xStyleFamilies(xSFS->getStyleFamilies(), UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xPageStyles(xStyleFamilies->getByName("PageStyles"), UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPropSet(xPageStyles->getByName("Default"), UNO_QUERY_THROW); - // Insert this field into a cell. - uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); - uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), UNO_QUERY_THROW); - uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); - // Use cell A1 for this. - uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 0); - uno::Reference<text::XText> xText(xCell, UNO_QUERY_THROW); + uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( + xPropSet->getPropertyValue("RightPageHeaderContent"), UNO_QUERY_THROW); + // Use the left header text. + uno::Reference<text::XText> xText = xHeaderContent->getLeftText(); uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); uno::Reference<text::XTextRange> xRange(xCursor, UNO_QUERY_THROW); uno::Reference<text::XTextContent> xContent(mxField, UNO_QUERY_THROW); xText->insertTextContent(xRange, xContent, sal_False); + + xPropSet->setPropertyValue("RightPageHeaderContent", uno::makeAny(xHeaderContent)); + + mxRightText = xHeaderContent->getRightText(); } + return mxField; } @@ -136,20 +132,15 @@ uno::Reference<text::XTextContent> ScEditFieldObj_Header::getTextContent() { // Return a field object that's not yet inserted. uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, UNO_QUERY_THROW); - return uno::Reference<text::XTextContent>(getNewField(xSM), UNO_QUERY_THROW); + uno::Reference<text::XTextContent> xField( + xSM->createInstance("com.sun.star.text.TextField.Date"), UNO_QUERY_THROW); + return xField; } uno::Reference<text::XTextRange> ScEditFieldObj_Header::getTextRange() { - // Use cell A2 for this. - uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); - uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), UNO_QUERY_THROW); - uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); - uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 1); - uno::Reference<text::XText> xText(xCell, UNO_QUERY_THROW); - - uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); - uno::Reference<text::XTextRange> xRange(xCursor, UNO_QUERY_THROW); + // Use the right header text for this. + uno::Reference<text::XTextRange> xRange(mxRightText, UNO_QUERY_THROW); return xRange; } commit 9c9e0db4f0dd17843eae06c30730358a60b5ea8e Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Fri Apr 27 21:03:46 2012 -0400 Copy & paste the *_Cell test code into *_Header test code. I still need to rewrite it to make it the header test. Change-Id: I0f8c469d51340ae72cb61696a22ebcbdcf84ffa6 diff --git a/sc/CppunitTest_sc_editfieldobj.mk b/sc/CppunitTest_sc_editfieldobj.mk deleted file mode 100644 index c14dc4d..0000000 --- a/sc/CppunitTest_sc_editfieldobj.mk +++ /dev/null @@ -1,134 +0,0 @@ -# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- -#************************************************************************* -# Version: MPL 1.1 / GPLv3+ / LGPLv3+ -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License or as specified alternatively below. You may obtain a copy of -# the License at http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Initial Developer of the Original Code is -# Kohei Yoshida <kohei.yosh...@suse.com> -# Portions created by the Initial Developer are Copyright (C) 2011 the -# Initial Developer. All Rights Reserved. -# -# Major Contributor(s): -# -# For minor contributions see the git repository. -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 3 or later (the "GPLv3+"), or -# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), -# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable -# instead of those above. -#************************************************************************* - -$(eval $(call gb_CppunitTest_CppunitTest,sc_editfieldobj)) - -$(eval $(call gb_CppunitTest_add_exception_objects,sc_editfieldobj, \ - sc/qa/extras/sceditfieldobj-cell \ -)) - -$(eval $(call gb_CppunitTest_use_libraries,sc_editfieldobj, \ - avmedia \ - basegfx \ - comphelper \ - cppu \ - cppuhelper \ - drawinglayer \ - editeng \ - fileacc \ - for \ - forui \ - i18nisolang1 \ - msfilter \ - oox \ - sal \ - salhelper \ - sax \ - sb \ - sc \ - sfx \ - sot \ - svl \ - svt \ - svx \ - svxcore \ - test \ - tl \ - tk \ - subsequenttest \ - ucbhelper \ - unotest \ - utl \ - vbahelper \ - vcl \ - xo \ - $(gb_STDLIBS) \ -)) - -$(eval $(call gb_CppunitTest_set_include,sc_editfieldobj,\ - -I$(SRCDIR)/sc/source/ui/inc \ - -I$(SRCDIR)/sc/inc \ - $$(INCLUDE) \ -)) - -$(eval $(call gb_CppunitTest_use_api,sc_editfieldobj,\ - offapi \ - udkapi \ -)) - -$(eval $(call gb_CppunitTest_use_ure,sc_editfieldobj)) - -$(eval $(call gb_CppunitTest_use_components,sc_editfieldobj,\ - basic/util/sb \ - comphelper/util/comphelp \ - configmgr/source/configmgr \ - dbaccess/util/dba \ - fileaccess/source/fileacc \ - filter/source/config/cache/filterconfig1 \ - forms/util/frm \ - framework/util/fwk \ - i18npool/util/i18npool \ - oox/util/oox \ - package/source/xstor/xstor \ - package/util/package2 \ - sax/source/expatwrap/expwrap \ - sax/source/fastparser/fastsax \ - sc/util/sc \ - sc/util/scd \ - sc/util/scfilt \ - sc/util/vbaobj \ - scripting/source/basprov/basprov \ - scripting/util/scriptframe \ - sfx2/util/sfx \ - sot/util/sot \ - svl/source/fsstor/fsstorage \ - toolkit/util/tk \ - ucb/source/core/ucb1 \ - ucb/source/ucp/file/ucpfile1 \ - ucb/source/ucp/tdoc/ucptdoc1 \ - unotools/util/utl \ - unoxml/source/rdf/unordf \ - unoxml/source/service/unoxml \ -)) - -$(eval $(call gb_CppunitTest_use_configuration,sc_editfieldobj)) - -$(eval $(call gb_CppunitTest_use_filter_configuration,sc_editfieldobj)) - -$(eval $(call gb_CppunitTest_use_extra_configuration,sc_editfieldobj,\ - $(OUTDIR)/unittest/registry \ -)) - -# we need to -# - explicitly depend on the sc resource files needed at unit-test runtime -$(call gb_CppunitTest_get_target,sc_editfieldobj) : \ - $(WORKDIR)/AllLangRes/sc \ - -# vim: set noet sw=4 ts=4: diff --git a/sc/CppunitTest_sc_editfieldobj_cell.mk b/sc/CppunitTest_sc_editfieldobj_cell.mk new file mode 100644 index 0000000..70ca94c --- /dev/null +++ b/sc/CppunitTest_sc_editfieldobj_cell.mk @@ -0,0 +1,134 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# Version: MPL 1.1 / GPLv3+ / LGPLv3+ +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License or as specified alternatively below. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Initial Developer of the Original Code is +# Kohei Yoshida <kohei.yosh...@suse.com> +# Portions created by the Initial Developer are Copyright (C) 2011 the +# Initial Developer. All Rights Reserved. +# +# Major Contributor(s): +# +# For minor contributions see the git repository. +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 3 or later (the "GPLv3+"), or +# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), +# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable +# instead of those above. +#************************************************************************* + +$(eval $(call gb_CppunitTest_CppunitTest,sc_editfieldobj_cell)) + +$(eval $(call gb_CppunitTest_add_exception_objects,sc_editfieldobj_cell, \ + sc/qa/extras/sceditfieldobj-cell \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,sc_editfieldobj_cell, \ + avmedia \ + basegfx \ + comphelper \ + cppu \ + cppuhelper \ + drawinglayer \ + editeng \ + fileacc \ + for \ + forui \ + i18nisolang1 \ + msfilter \ + oox \ + sal \ + salhelper \ + sax \ + sb \ + sc \ + sfx \ + sot \ + svl \ + svt \ + svx \ + svxcore \ + test \ + tl \ + tk \ + subsequenttest \ + ucbhelper \ + unotest \ + utl \ + vbahelper \ + vcl \ + xo \ + $(gb_STDLIBS) \ +)) + +$(eval $(call gb_CppunitTest_set_include,sc_editfieldobj_cell,\ + -I$(SRCDIR)/sc/source/ui/inc \ + -I$(SRCDIR)/sc/inc \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_CppunitTest_use_api,sc_editfieldobj_cell,\ + offapi \ + udkapi \ +)) + +$(eval $(call gb_CppunitTest_use_ure,sc_editfieldobj_cell)) + +$(eval $(call gb_CppunitTest_use_components,sc_editfieldobj_cell,\ + basic/util/sb \ + comphelper/util/comphelp \ + configmgr/source/configmgr \ + dbaccess/util/dba \ + fileaccess/source/fileacc \ + filter/source/config/cache/filterconfig1 \ + forms/util/frm \ + framework/util/fwk \ + i18npool/util/i18npool \ + oox/util/oox \ + package/source/xstor/xstor \ + package/util/package2 \ + sax/source/expatwrap/expwrap \ + sax/source/fastparser/fastsax \ + sc/util/sc \ + sc/util/scd \ + sc/util/scfilt \ + sc/util/vbaobj \ + scripting/source/basprov/basprov \ + scripting/util/scriptframe \ + sfx2/util/sfx \ + sot/util/sot \ + svl/source/fsstor/fsstorage \ + toolkit/util/tk \ + ucb/source/core/ucb1 \ + ucb/source/ucp/file/ucpfile1 \ + ucb/source/ucp/tdoc/ucptdoc1 \ + unotools/util/utl \ + unoxml/source/rdf/unordf \ + unoxml/source/service/unoxml \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,sc_editfieldobj_cell)) + +$(eval $(call gb_CppunitTest_use_filter_configuration,sc_editfieldobj_cell)) + +$(eval $(call gb_CppunitTest_use_extra_configuration,sc_editfieldobj_cell,\ + $(OUTDIR)/unittest/registry \ +)) + +# we need to +# - explicitly depend on the sc resource files needed at unit-test runtime +$(call gb_CppunitTest_get_target,sc_editfieldobj_cell) : \ + $(WORKDIR)/AllLangRes/sc \ + +# vim: set noet sw=4 ts=4: diff --git a/sc/CppunitTest_sc_editfieldobj_header.mk b/sc/CppunitTest_sc_editfieldobj_header.mk new file mode 100644 index 0000000..301c8f0 --- /dev/null +++ b/sc/CppunitTest_sc_editfieldobj_header.mk @@ -0,0 +1,134 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# Version: MPL 1.1 / GPLv3+ / LGPLv3+ +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License or as specified alternatively below. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Initial Developer of the Original Code is +# Kohei Yoshida <kohei.yosh...@suse.com> +# Portions created by the Initial Developer are Copyright (C) 2011 the +# Initial Developer. All Rights Reserved. +# +# Major Contributor(s): +# +# For minor contributions see the git repository. +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 3 or later (the "GPLv3+"), or +# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), +# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable +# instead of those above. +#************************************************************************* + +$(eval $(call gb_CppunitTest_CppunitTest,sc_editfieldobj_header)) + +$(eval $(call gb_CppunitTest_add_exception_objects,sc_editfieldobj_header, \ + sc/qa/extras/sceditfieldobj-header \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,sc_editfieldobj_header, \ + avmedia \ + basegfx \ + comphelper \ + cppu \ + cppuhelper \ + drawinglayer \ + editeng \ + fileacc \ + for \ + forui \ + i18nisolang1 \ + msfilter \ + oox \ + sal \ + salhelper \ + sax \ + sb \ + sc \ + sfx \ + sot \ + svl \ + svt \ + svx \ + svxcore \ + test \ + tl \ + tk \ + subsequenttest \ + ucbhelper \ + unotest \ + utl \ + vbahelper \ + vcl \ + xo \ + $(gb_STDLIBS) \ +)) + +$(eval $(call gb_CppunitTest_set_include,sc_editfieldobj_header,\ + -I$(SRCDIR)/sc/source/ui/inc \ + -I$(SRCDIR)/sc/inc \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_CppunitTest_use_api,sc_editfieldobj_header,\ + offapi \ + udkapi \ +)) + +$(eval $(call gb_CppunitTest_use_ure,sc_editfieldobj_header)) + +$(eval $(call gb_CppunitTest_use_components,sc_editfieldobj_header,\ + basic/util/sb \ + comphelper/util/comphelp \ + configmgr/source/configmgr \ + dbaccess/util/dba \ + fileaccess/source/fileacc \ + filter/source/config/cache/filterconfig1 \ + forms/util/frm \ + framework/util/fwk \ + i18npool/util/i18npool \ + oox/util/oox \ + package/source/xstor/xstor \ + package/util/package2 \ + sax/source/expatwrap/expwrap \ + sax/source/fastparser/fastsax \ + sc/util/sc \ + sc/util/scd \ + sc/util/scfilt \ + sc/util/vbaobj \ + scripting/source/basprov/basprov \ + scripting/util/scriptframe \ + sfx2/util/sfx \ + sot/util/sot \ + svl/source/fsstor/fsstorage \ + toolkit/util/tk \ + ucb/source/core/ucb1 \ + ucb/source/ucp/file/ucpfile1 \ + ucb/source/ucp/tdoc/ucptdoc1 \ + unotools/util/utl \ + unoxml/source/rdf/unordf \ + unoxml/source/service/unoxml \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,sc_editfieldobj_header)) + +$(eval $(call gb_CppunitTest_use_filter_configuration,sc_editfieldobj_header)) + +$(eval $(call gb_CppunitTest_use_extra_configuration,sc_editfieldobj_header,\ + $(OUTDIR)/unittest/registry \ +)) + +# we need to +# - explicitly depend on the sc resource files needed at unit-test runtime +$(call gb_CppunitTest_get_target,sc_editfieldobj_header) : \ + $(WORKDIR)/AllLangRes/sc \ + +# vim: set noet sw=4 ts=4: diff --git a/sc/Module_sc.mk b/sc/Module_sc.mk index 926ac33..4727d74 100644 --- a/sc/Module_sc.mk +++ b/sc/Module_sc.mk @@ -64,7 +64,8 @@ $(eval $(call gb_Module_add_subsequentcheck_targets,sc,\ CppunitTest_sc_namedrangesobj \ CppunitTest_sc_tablesheetobj \ CppunitTest_sc_tablesheetsobj \ - CppunitTest_sc_editfieldobj \ + CppunitTest_sc_editfieldobj_cell \ + CppunitTest_sc_editfieldobj_header \ )) # vim: set noet sw=4 ts=4: diff --git a/sc/qa/extras/sceditfieldobj-header.cxx b/sc/qa/extras/sceditfieldobj-header.cxx new file mode 100644 index 0000000..ab84b70 --- /dev/null +++ b/sc/qa/extras/sceditfieldobj-header.cxx @@ -0,0 +1,162 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Major Contributor(s): + * Copyright (C) 2012 Kohei Yoshida <kohei.yosh...@suse.com> + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ + +#include <test/unoapi_test.hxx> +#include <test/text/xtextfield.hxx> +#include <test/text/xtextcontent.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextField.hpp> +#include <com/sun/star/text/XTextFieldsSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> + +#define NUMBER_OF_TESTS 3 + +namespace sc_apitest { + +class ScEditFieldObj_Header : public UnoApiTest, apitest::XTextField, apitest::XTextContent +{ +public: + ScEditFieldObj_Header(); + + virtual void setUp(); + virtual void tearDown(); + virtual uno::Reference<uno::XInterface> init(); + virtual uno::Reference<text::XTextContent> getTextContent(); + virtual uno::Reference<text::XTextRange> getTextRange(); + virtual bool isAttachSupported() { return true; } + + CPPUNIT_TEST_SUITE(ScEditFieldObj_Header); + // XTextField + CPPUNIT_TEST(testGetPresentation); + // XTextContent + CPPUNIT_TEST(testGetAnchor); + CPPUNIT_TEST(testAttach); + CPPUNIT_TEST_SUITE_END(); + +private: + static sal_Int32 nTest; + static uno::Reference<lang::XComponent> mxComponent; + static uno::Reference<text::XTextField> mxField; +}; + +sal_Int32 ScEditFieldObj_Header::nTest = 0; +uno::Reference<lang::XComponent> ScEditFieldObj_Header::mxComponent; +uno::Reference<text::XTextField> ScEditFieldObj_Header::mxField; + +ScEditFieldObj_Header::ScEditFieldObj_Header() {} + +void ScEditFieldObj_Header::setUp() +{ + ++nTest; + UnoApiTest::setUp(); +} + +void ScEditFieldObj_Header::tearDown() +{ + if (nTest == NUMBER_OF_TESTS) + closeDocument(mxComponent); + + UnoApiTest::tearDown(); +} + +namespace { + +uno::Reference<text::XTextField> getNewField(const uno::Reference<lang::XMultiServiceFactory>& xSM) +{ + uno::Reference<text::XTextField> xField( + xSM->createInstance("com.sun.star.text.TextField.URL"), UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPropSet(xField, UNO_QUERY_THROW); + xPropSet->setPropertyValue("Representation", uno::makeAny(rtl::OUString("LibreOffice"))); + xPropSet->setPropertyValue("URL", uno::makeAny(rtl::OUString("http://www.libreoffice.org/"))); + return xField; +} + +} + +uno::Reference<uno::XInterface> ScEditFieldObj_Header::init() +{ + // Return a field that's already in the cell. + if (!mxField.is()) + { + if (!mxComponent.is()) + // Load an empty document. + mxComponent = loadFromDesktop("private:factory/scalc"); + + uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, UNO_QUERY_THROW); + + // Create a new URL field object, and populate it with name and URL. + mxField = getNewField(xSM); + + // Insert this field into a cell. + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); + // Use cell A1 for this. + uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 0); + uno::Reference<text::XText> xText(xCell, UNO_QUERY_THROW); + + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<text::XTextRange> xRange(xCursor, UNO_QUERY_THROW); + uno::Reference<text::XTextContent> xContent(mxField, UNO_QUERY_THROW); + xText->insertTextContent(xRange, xContent, sal_False); + } + return mxField; +} + +uno::Reference<text::XTextContent> ScEditFieldObj_Header::getTextContent() +{ + // Return a field object that's not yet inserted. + uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, UNO_QUERY_THROW); + return uno::Reference<text::XTextContent>(getNewField(xSM), UNO_QUERY_THROW); +} + +uno::Reference<text::XTextRange> ScEditFieldObj_Header::getTextRange() +{ + // Use cell A2 for this. + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); + uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 1); + uno::Reference<text::XText> xText(xCell, UNO_QUERY_THROW); + + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<text::XTextRange> xRange(xCursor, UNO_QUERY_THROW); + return xRange; +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScEditFieldObj_Header); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 8600f21b7d3c3656c1458aa440dbb330c08a7c7c Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Fri Apr 27 20:48:08 2012 -0400 Renamed the file to make room for the header version of the same test. This ScEditFieldObj is used for both cell fields and header/footer fields. Change-Id: I8c51de5d173ae934ea604c68030cd84b13f90ef3 diff --git a/sc/CppunitTest_sc_editfieldobj.mk b/sc/CppunitTest_sc_editfieldobj.mk index 2e68c1e..c14dc4d 100644 --- a/sc/CppunitTest_sc_editfieldobj.mk +++ b/sc/CppunitTest_sc_editfieldobj.mk @@ -31,7 +31,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,sc_editfieldobj)) $(eval $(call gb_CppunitTest_add_exception_objects,sc_editfieldobj, \ - sc/qa/extras/sceditfieldobj \ + sc/qa/extras/sceditfieldobj-cell \ )) $(eval $(call gb_CppunitTest_use_libraries,sc_editfieldobj, \ diff --git a/sc/Module_sc.mk b/sc/Module_sc.mk index 18ab358..926ac33 100644 --- a/sc/Module_sc.mk +++ b/sc/Module_sc.mk @@ -64,6 +64,7 @@ $(eval $(call gb_Module_add_subsequentcheck_targets,sc,\ CppunitTest_sc_namedrangesobj \ CppunitTest_sc_tablesheetobj \ CppunitTest_sc_tablesheetsobj \ + CppunitTest_sc_editfieldobj \ )) # vim: set noet sw=4 ts=4: diff --git a/sc/qa/extras/sceditfieldobj-cell.cxx b/sc/qa/extras/sceditfieldobj-cell.cxx new file mode 100644 index 0000000..962834a --- /dev/null +++ b/sc/qa/extras/sceditfieldobj-cell.cxx @@ -0,0 +1,162 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Major Contributor(s): + * Copyright (C) 2012 Kohei Yoshida <kohei.yosh...@suse.com> + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ + +#include <test/unoapi_test.hxx> +#include <test/text/xtextfield.hxx> +#include <test/text/xtextcontent.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextField.hpp> +#include <com/sun/star/text/XTextFieldsSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> + +#define NUMBER_OF_TESTS 3 + +namespace sc_apitest { + +class ScEditFieldObj_Cell : public UnoApiTest, apitest::XTextField, apitest::XTextContent +{ +public: + ScEditFieldObj_Cell(); + + virtual void setUp(); + virtual void tearDown(); + virtual uno::Reference<uno::XInterface> init(); + virtual uno::Reference<text::XTextContent> getTextContent(); + virtual uno::Reference<text::XTextRange> getTextRange(); + virtual bool isAttachSupported() { return true; } + + CPPUNIT_TEST_SUITE(ScEditFieldObj_Cell); + // XTextField + CPPUNIT_TEST(testGetPresentation); + // XTextContent + CPPUNIT_TEST(testGetAnchor); + CPPUNIT_TEST(testAttach); + CPPUNIT_TEST_SUITE_END(); + +private: + static sal_Int32 nTest; + static uno::Reference<lang::XComponent> mxComponent; + static uno::Reference<text::XTextField> mxField; +}; + +sal_Int32 ScEditFieldObj_Cell::nTest = 0; +uno::Reference<lang::XComponent> ScEditFieldObj_Cell::mxComponent; +uno::Reference<text::XTextField> ScEditFieldObj_Cell::mxField; + +ScEditFieldObj_Cell::ScEditFieldObj_Cell() {} + +void ScEditFieldObj_Cell::setUp() +{ + ++nTest; + UnoApiTest::setUp(); +} + +void ScEditFieldObj_Cell::tearDown() +{ + if (nTest == NUMBER_OF_TESTS) + closeDocument(mxComponent); + + UnoApiTest::tearDown(); +} + +namespace { + +uno::Reference<text::XTextField> getNewField(const uno::Reference<lang::XMultiServiceFactory>& xSM) +{ + uno::Reference<text::XTextField> xField( + xSM->createInstance("com.sun.star.text.TextField.URL"), UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPropSet(xField, UNO_QUERY_THROW); + xPropSet->setPropertyValue("Representation", uno::makeAny(rtl::OUString("LibreOffice"))); + xPropSet->setPropertyValue("URL", uno::makeAny(rtl::OUString("http://www.libreoffice.org/"))); + return xField; +} + +} + +uno::Reference<uno::XInterface> ScEditFieldObj_Cell::init() +{ + // Return a field that's already in the cell. + if (!mxField.is()) + { + if (!mxComponent.is()) + // Load an empty document. + mxComponent = loadFromDesktop("private:factory/scalc"); + + uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, UNO_QUERY_THROW); + + // Create a new URL field object, and populate it with name and URL. + mxField = getNewField(xSM); + + // Insert this field into a cell. + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); + // Use cell A1 for this. + uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 0); + uno::Reference<text::XText> xText(xCell, UNO_QUERY_THROW); + + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<text::XTextRange> xRange(xCursor, UNO_QUERY_THROW); + uno::Reference<text::XTextContent> xContent(mxField, UNO_QUERY_THROW); + xText->insertTextContent(xRange, xContent, sal_False); + } + return mxField; +} + +uno::Reference<text::XTextContent> ScEditFieldObj_Cell::getTextContent() +{ + // Return a field object that's not yet inserted. + uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, UNO_QUERY_THROW); + return uno::Reference<text::XTextContent>(getNewField(xSM), UNO_QUERY_THROW); +} + +uno::Reference<text::XTextRange> ScEditFieldObj_Cell::getTextRange() +{ + // Use cell A2 for this. + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); + uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 1); + uno::Reference<text::XText> xText(xCell, UNO_QUERY_THROW); + + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<text::XTextRange> xRange(xCursor, UNO_QUERY_THROW); + return xRange; +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScEditFieldObj_Cell); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/extras/sceditfieldobj.cxx b/sc/qa/extras/sceditfieldobj.cxx deleted file mode 100644 index d5a22ad..0000000 --- a/sc/qa/extras/sceditfieldobj.cxx +++ /dev/null @@ -1,162 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * Version: MPL 1.1 / GPLv3+ / LGPLv3+ - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License or as specified alternatively below. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * Major Contributor(s): - * Copyright (C) 2012 Kohei Yoshida <kohei.yosh...@suse.com> - * - * All Rights Reserved. - * - * For minor contributions see the git repository. - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 3 or later (the "GPLv3+"), or - * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), - * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable - * instead of those above. - */ - -#include <test/unoapi_test.hxx> -#include <test/text/xtextfield.hxx> -#include <test/text/xtextcontent.hxx> - -#include <com/sun/star/beans/XPropertySet.hpp> -#include <com/sun/star/container/XEnumerationAccess.hpp> -#include <com/sun/star/text/XText.hpp> -#include <com/sun/star/text/XTextField.hpp> -#include <com/sun/star/text/XTextFieldsSupplier.hpp> -#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> -#include <com/sun/star/sheet/XSpreadsheet.hpp> - -#define NUMBER_OF_TESTS 3 - -namespace sc_apitest { - -class ScEditFieldObj : public UnoApiTest, apitest::XTextField, apitest::XTextContent -{ -public: - ScEditFieldObj(); - - virtual void setUp(); - virtual void tearDown(); - virtual uno::Reference<uno::XInterface> init(); - virtual uno::Reference<text::XTextContent> getTextContent(); - virtual uno::Reference<text::XTextRange> getTextRange(); - virtual bool isAttachSupported() { return true; } - - CPPUNIT_TEST_SUITE(ScEditFieldObj); - // XTextField - CPPUNIT_TEST(testGetPresentation); - // XTextContent - CPPUNIT_TEST(testGetAnchor); - CPPUNIT_TEST(testAttach); - CPPUNIT_TEST_SUITE_END(); - -private: - static sal_Int32 nTest; - static uno::Reference<lang::XComponent> mxComponent; - static uno::Reference<text::XTextField> mxField; -}; - -sal_Int32 ScEditFieldObj::nTest = 0; -uno::Reference<lang::XComponent> ScEditFieldObj::mxComponent; -uno::Reference<text::XTextField> ScEditFieldObj::mxField; - -ScEditFieldObj::ScEditFieldObj() {} - -void ScEditFieldObj::setUp() -{ - ++nTest; - UnoApiTest::setUp(); -} - -void ScEditFieldObj::tearDown() -{ - if (nTest == NUMBER_OF_TESTS) - closeDocument(mxComponent); - - UnoApiTest::tearDown(); -} - -namespace { - -uno::Reference<text::XTextField> getNewField(const uno::Reference<lang::XMultiServiceFactory>& xSM) -{ - uno::Reference<text::XTextField> xField( - xSM->createInstance("com.sun.star.text.TextField.URL"), UNO_QUERY_THROW); - uno::Reference<beans::XPropertySet> xPropSet(xField, UNO_QUERY_THROW); - xPropSet->setPropertyValue("Representation", uno::makeAny(rtl::OUString("LibreOffice"))); - xPropSet->setPropertyValue("URL", uno::makeAny(rtl::OUString("http://www.libreoffice.org/"))); - return xField; -} - -} - -uno::Reference<uno::XInterface> ScEditFieldObj::init() -{ - // Return a field that's already in the cell. - if (!mxField.is()) - { - if (!mxComponent.is()) - // Load an empty document. - mxComponent = loadFromDesktop("private:factory/scalc"); - - uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, UNO_QUERY_THROW); - - // Create a new URL field object, and populate it with name and URL. - mxField = getNewField(xSM); - - // Insert this field into a cell. - uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); - uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), UNO_QUERY_THROW); - uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); - // Use cell A1 for this. - uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 0); - uno::Reference<text::XText> xText(xCell, UNO_QUERY_THROW); - - uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); - uno::Reference<text::XTextRange> xRange(xCursor, UNO_QUERY_THROW); - uno::Reference<text::XTextContent> xContent(mxField, UNO_QUERY_THROW); - xText->insertTextContent(xRange, xContent, sal_False); - } - return mxField; -} - -uno::Reference<text::XTextContent> ScEditFieldObj::getTextContent() -{ - // Return a field object that's not yet inserted. - uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, UNO_QUERY_THROW); - return uno::Reference<text::XTextContent>(getNewField(xSM), UNO_QUERY_THROW); -} - -uno::Reference<text::XTextRange> ScEditFieldObj::getTextRange() -{ - // Use cell A2 for this. - uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); - uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), UNO_QUERY_THROW); - uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); - uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 1); - uno::Reference<text::XText> xText(xCell, UNO_QUERY_THROW); - - uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); - uno::Reference<text::XTextRange> xRange(xCursor, UNO_QUERY_THROW); - return xRange; -} - -CPPUNIT_TEST_SUITE_REGISTRATION(ScEditFieldObj); - -CPPUNIT_PLUGIN_IMPLEMENT(); - -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 219cef62f8bbb5a057eaa830e6a4b2964c242c44 Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Fri Apr 27 20:41:52 2012 -0400 Do the test for real. XTextField and XTextContent. Change-Id: I303562873fab5d41614f092966e47ff296c12610 diff --git a/sc/qa/extras/sceditfieldobj.cxx b/sc/qa/extras/sceditfieldobj.cxx index a065a3f..d5a22ad 100644 --- a/sc/qa/extras/sceditfieldobj.cxx +++ b/sc/qa/extras/sceditfieldobj.cxx @@ -28,14 +28,21 @@ #include <test/unoapi_test.hxx> #include <test/text/xtextfield.hxx> +#include <test/text/xtextcontent.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/text/XText.hpp> #include <com/sun/star/text/XTextField.hpp> +#include <com/sun/star/text/XTextFieldsSupplier.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> -#define NUMBER_OF_TESTS 1 +#define NUMBER_OF_TESTS 3 namespace sc_apitest { -class ScEditFieldObj : public UnoApiTest, apitest::XTextField +class ScEditFieldObj : public UnoApiTest, apitest::XTextField, apitest::XTextContent { public: ScEditFieldObj(); @@ -43,18 +50,27 @@ public: virtual void setUp(); virtual void tearDown(); virtual uno::Reference<uno::XInterface> init(); + virtual uno::Reference<text::XTextContent> getTextContent(); + virtual uno::Reference<text::XTextRange> getTextRange(); + virtual bool isAttachSupported() { return true; } CPPUNIT_TEST_SUITE(ScEditFieldObj); + // XTextField CPPUNIT_TEST(testGetPresentation); + // XTextContent + CPPUNIT_TEST(testGetAnchor); + CPPUNIT_TEST(testAttach); CPPUNIT_TEST_SUITE_END(); private: static sal_Int32 nTest; static uno::Reference<lang::XComponent> mxComponent; + static uno::Reference<text::XTextField> mxField; }; sal_Int32 ScEditFieldObj::nTest = 0; uno::Reference<lang::XComponent> ScEditFieldObj::mxComponent; +uno::Reference<text::XTextField> ScEditFieldObj::mxField; ScEditFieldObj::ScEditFieldObj() {} @@ -72,12 +88,69 @@ void ScEditFieldObj::tearDown() UnoApiTest::tearDown(); } +namespace { + +uno::Reference<text::XTextField> getNewField(const uno::Reference<lang::XMultiServiceFactory>& xSM) +{ + uno::Reference<text::XTextField> xField( + xSM->createInstance("com.sun.star.text.TextField.URL"), UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPropSet(xField, UNO_QUERY_THROW); + xPropSet->setPropertyValue("Representation", uno::makeAny(rtl::OUString("LibreOffice"))); + xPropSet->setPropertyValue("URL", uno::makeAny(rtl::OUString("http://www.libreoffice.org/"))); + return xField; +} + +} + uno::Reference<uno::XInterface> ScEditFieldObj::init() { - if (!mxComponent.is()) - mxComponent = loadFromDesktop("private:factory/scalc"); + // Return a field that's already in the cell. + if (!mxField.is()) + { + if (!mxComponent.is()) + // Load an empty document. + mxComponent = loadFromDesktop("private:factory/scalc"); + + uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, UNO_QUERY_THROW); + + // Create a new URL field object, and populate it with name and URL. + mxField = getNewField(xSM); + + // Insert this field into a cell. + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); + // Use cell A1 for this. + uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 0); + uno::Reference<text::XText> xText(xCell, UNO_QUERY_THROW); + + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<text::XTextRange> xRange(xCursor, UNO_QUERY_THROW); + uno::Reference<text::XTextContent> xContent(mxField, UNO_QUERY_THROW); + xText->insertTextContent(xRange, xContent, sal_False); + } + return mxField; +} - return mxComponent; +uno::Reference<text::XTextContent> ScEditFieldObj::getTextContent() +{ + // Return a field object that's not yet inserted. + uno::Reference<lang::XMultiServiceFactory> xSM(mxComponent, UNO_QUERY_THROW); + return uno::Reference<text::XTextContent>(getNewField(xSM), UNO_QUERY_THROW); +} + +uno::Reference<text::XTextRange> ScEditFieldObj::getTextRange() +{ + // Use cell A2 for this. + uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); + uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 1); + uno::Reference<text::XText> xText(xCell, UNO_QUERY_THROW); + + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<text::XTextRange> xRange(xCursor, UNO_QUERY_THROW); + return xRange; } CPPUNIT_TEST_SUITE_REGISTRATION(ScEditFieldObj); diff --git a/test/source/text/xtextcontent.cxx b/test/source/text/xtextcontent.cxx index c6662e7..8e84dc2 100644 --- a/test/source/text/xtextcontent.cxx +++ b/test/source/text/xtextcontent.cxx @@ -63,7 +63,6 @@ void XTextContent::testAttach() bool bAttachSupported = isAttachSupported(); if (bAttachSupported) CPPUNIT_ASSERT(false); - } catch (const RuntimeException& e) { commit e3c7b1a0bebb96e51b7c7927367a243c0a2f8402 Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Fri Apr 27 17:06:46 2012 -0400 Oops I should return empty strings on fail. Change-Id: I9f04ef448055e14c3d003c977a3c83421838a88b diff --git a/sc/source/ui/unoobj/fielduno.cxx b/sc/source/ui/unoobj/fielduno.cxx index 2753fa6..6bef71a 100644 --- a/sc/source/ui/unoobj/fielduno.cxx +++ b/sc/source/ui/unoobj/fielduno.cxx @@ -965,7 +965,7 @@ rtl::OUString SAL_CALL ScEditFieldObj::getPresentation( sal_Bool bShowCommand ) SolarMutexGuard aGuard; if (!mpEditSource) - return rtl::OUString("no edit source!!!"); + return rtl::OUString(); //! Feld-Funktionen muessen an den Forwarder !!! ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); @@ -975,14 +975,15 @@ rtl::OUString SAL_CALL ScEditFieldObj::getPresentation( sal_Bool bShowCommand ) const SvxFieldData* pField = aTempEngine.FindByPos( aSelection.nStartPara, aSelection.nStartPos, 0 ); OSL_ENSURE(pField,"getPresentation: Feld nicht gefunden"); if (!pField) - return rtl::OUString("not inserted yet"); + return rtl::OUString(); switch (meType) { case URL: { if (pField->GetClassId() != SVX_URLFIELD) - return rtl::OUString("not url field but url expected"); + // Not an URL field, but URL is expected. + throw uno::RuntimeException(); const SvxURLField* pURL = static_cast<const SvxURLField*>(pField); return bShowCommand ? pURL->GetURL() : pURL->GetRepresentation(); @@ -991,7 +992,7 @@ rtl::OUString SAL_CALL ScEditFieldObj::getPresentation( sal_Bool bShowCommand ) default: ; } - return rtl::OUString("total fail"); + return rtl::OUString(); } // XTextContent commit d0af33e87db753d6d171548f75c2e242cde00497 Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Fri Apr 27 15:32:19 2012 -0400 Initial skeleton for API test on ScEditFieldObj. ScEditFieldObj was formerly ScCellFieldObj and ScHeaderFieldObj merged into one. Change-Id: I600188d7ee22bb7c7c18735f570460ce50083c6a diff --git a/sc/CppunitTest_sc_editfieldobj.mk b/sc/CppunitTest_sc_editfieldobj.mk new file mode 100644 index 0000000..2e68c1e --- /dev/null +++ b/sc/CppunitTest_sc_editfieldobj.mk @@ -0,0 +1,134 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# Version: MPL 1.1 / GPLv3+ / LGPLv3+ +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License or as specified alternatively below. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Initial Developer of the Original Code is +# Kohei Yoshida <kohei.yosh...@suse.com> +# Portions created by the Initial Developer are Copyright (C) 2011 the +# Initial Developer. All Rights Reserved. +# +# Major Contributor(s): +# +# For minor contributions see the git repository. +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 3 or later (the "GPLv3+"), or +# the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), +# in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable +# instead of those above. +#************************************************************************* + +$(eval $(call gb_CppunitTest_CppunitTest,sc_editfieldobj)) + +$(eval $(call gb_CppunitTest_add_exception_objects,sc_editfieldobj, \ + sc/qa/extras/sceditfieldobj \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,sc_editfieldobj, \ + avmedia \ + basegfx \ + comphelper \ + cppu \ + cppuhelper \ + drawinglayer \ + editeng \ + fileacc \ + for \ + forui \ + i18nisolang1 \ + msfilter \ + oox \ + sal \ + salhelper \ + sax \ + sb \ + sc \ + sfx \ + sot \ + svl \ + svt \ + svx \ + svxcore \ + test \ + tl \ + tk \ + subsequenttest \ + ucbhelper \ + unotest \ + utl \ + vbahelper \ + vcl \ + xo \ + $(gb_STDLIBS) \ +)) + +$(eval $(call gb_CppunitTest_set_include,sc_editfieldobj,\ + -I$(SRCDIR)/sc/source/ui/inc \ + -I$(SRCDIR)/sc/inc \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_CppunitTest_use_api,sc_editfieldobj,\ + offapi \ + udkapi \ +)) + +$(eval $(call gb_CppunitTest_use_ure,sc_editfieldobj)) + +$(eval $(call gb_CppunitTest_use_components,sc_editfieldobj,\ + basic/util/sb \ + comphelper/util/comphelp \ + configmgr/source/configmgr \ + dbaccess/util/dba \ + fileaccess/source/fileacc \ + filter/source/config/cache/filterconfig1 \ + forms/util/frm \ + framework/util/fwk \ + i18npool/util/i18npool \ + oox/util/oox \ + package/source/xstor/xstor \ + package/util/package2 \ + sax/source/expatwrap/expwrap \ + sax/source/fastparser/fastsax \ + sc/util/sc \ + sc/util/scd \ + sc/util/scfilt \ + sc/util/vbaobj \ + scripting/source/basprov/basprov \ + scripting/util/scriptframe \ + sfx2/util/sfx \ + sot/util/sot \ + svl/source/fsstor/fsstorage \ + toolkit/util/tk \ + ucb/source/core/ucb1 \ + ucb/source/ucp/file/ucpfile1 \ + ucb/source/ucp/tdoc/ucptdoc1 \ + unotools/util/utl \ + unoxml/source/rdf/unordf \ + unoxml/source/service/unoxml \ +)) + +$(eval $(call gb_CppunitTest_use_configuration,sc_editfieldobj)) + +$(eval $(call gb_CppunitTest_use_filter_configuration,sc_editfieldobj)) + +$(eval $(call gb_CppunitTest_use_extra_configuration,sc_editfieldobj,\ + $(OUTDIR)/unittest/registry \ +)) + +# we need to +# - explicitly depend on the sc resource files needed at unit-test runtime +$(call gb_CppunitTest_get_target,sc_editfieldobj) : \ + $(WORKDIR)/AllLangRes/sc \ + +# vim: set noet sw=4 ts=4: diff --git a/sc/qa/extras/sceditfieldobj.cxx b/sc/qa/extras/sceditfieldobj.cxx new file mode 100644 index 0000000..a065a3f --- /dev/null +++ b/sc/qa/extras/sceditfieldobj.cxx @@ -0,0 +1,89 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Major Contributor(s): + * Copyright (C) 2012 Kohei Yoshida <kohei.yosh...@suse.com> + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ + +#include <test/unoapi_test.hxx> +#include <test/text/xtextfield.hxx> + +#include <com/sun/star/text/XTextField.hpp> + +#define NUMBER_OF_TESTS 1 + +namespace sc_apitest { + +class ScEditFieldObj : public UnoApiTest, apitest::XTextField +{ +public: + ScEditFieldObj(); + + virtual void setUp(); + virtual void tearDown(); + virtual uno::Reference<uno::XInterface> init(); + + CPPUNIT_TEST_SUITE(ScEditFieldObj); + CPPUNIT_TEST(testGetPresentation); + CPPUNIT_TEST_SUITE_END(); + +private: + static sal_Int32 nTest; + static uno::Reference<lang::XComponent> mxComponent; +}; + +sal_Int32 ScEditFieldObj::nTest = 0; +uno::Reference<lang::XComponent> ScEditFieldObj::mxComponent; + +ScEditFieldObj::ScEditFieldObj() {} + +void ScEditFieldObj::setUp() +{ + ++nTest; + UnoApiTest::setUp(); +} + +void ScEditFieldObj::tearDown() +{ + if (nTest == NUMBER_OF_TESTS) + closeDocument(mxComponent); + + UnoApiTest::tearDown(); +} + +uno::Reference<uno::XInterface> ScEditFieldObj::init() +{ + if (!mxComponent.is()) + mxComponent = loadFromDesktop("private:factory/scalc"); + + return mxComponent; +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScEditFieldObj); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/inc/test/text/xtextcontent.hxx b/test/inc/test/text/xtextcontent.hxx index 6009849..4f13d0b 100644 --- a/test/inc/test/text/xtextcontent.hxx +++ b/test/inc/test/text/xtextcontent.hxx @@ -30,11 +30,13 @@ #include <com/sun/star/text/XTextRange.hpp> #include <com/sun/star/text/XTextContent.hpp> +#include "test/testdllapi.hxx" + using namespace com::sun::star; namespace apitest { -class XTextContent +class OOO_DLLPUBLIC_TEST XTextContent { public: virtual ~XTextContent() {} diff --git a/test/inc/test/text/xtextfield.hxx b/test/inc/test/text/xtextfield.hxx index 9798ecc..dc95779 100644 --- a/test/inc/test/text/xtextfield.hxx +++ b/test/inc/test/text/xtextfield.hxx @@ -28,12 +28,14 @@ #include <com/sun/star/uno/Reference.hxx> +#include "test/testdllapi.hxx" + using namespace com::sun::star; namespace apitest { -class XTextField +class OOO_DLLPUBLIC_TEST XTextField { public: virtual ~XTextField() {} _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits