From ecc855aa1c86d88a99c3be06c70ed382180be688 Mon Sep 17 00:00:00 2001 From: Ajay Mahato Date: Mon, 21 Jan 2019 23:14:15 +0530 Subject: tdf#45904 Move XSimpleText Java tests to C++ Change-Id: I6232615f15b52a1f004a13ed97fc0b8002a22269 Reviewed-on: https://gerrit.libreoffice.org/66694 Tested-by: Jenkins Reviewed-by: Jens Carl --- include/test/text/xsimpletext.hxx | 36 ++++++++++ .../sc/com.sun.star.comp.office.ScCellObj.csv | 4 -- sc/qa/extras/sccellobj.cxx | 54 ++++++++------- test/Library_subsequenttest.mk | 1 + test/source/text/xsimpletext.cxx | 76 ++++++++++++++++++++++ 5 files changed, 145 insertions(+), 26 deletions(-) create mode 100644 include/test/text/xsimpletext.hxx create mode 100644 test/source/text/xsimpletext.cxx diff --git a/include/test/text/xsimpletext.hxx b/include/test/text/xsimpletext.hxx new file mode 100644 index 000000000000..fca6d24a0d6a --- /dev/null +++ b/include/test/text/xsimpletext.hxx @@ -0,0 +1,36 @@ +/* -*- 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/. + */ + +#ifndef INCLUDED_TEST_TEXT_XSIMPLETEXT_HXX +#define INCLUDED_TEST_TEXT_XSIMPLETEXT_HXX + +#include + +#include + +namespace apitest +{ +class OOO_DLLPUBLIC_TEST XSimpleText +{ +public: + virtual css::uno::Reference init() = 0; + + void testCreateTextCursor(); + void testCreateTextCursorByRange(); + void testInsertString(); + void testInsertControlCharacter(); + +protected: + ~XSimpleText() {} +}; +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/qadevOOo/objdsc/sc/com.sun.star.comp.office.ScCellObj.csv b/qadevOOo/objdsc/sc/com.sun.star.comp.office.ScCellObj.csv index 3be24423a38d..e31e938fe88b 100644 --- a/qadevOOo/objdsc/sc/com.sun.star.comp.office.ScCellObj.csv +++ b/qadevOOo/objdsc/sc/com.sun.star.comp.office.ScCellObj.csv @@ -109,10 +109,6 @@ "ScCellObj";"com::sun::star::text::XTextRangeMover#optional";"moveTextRange()" "ScCellObj";"com::sun::star::text::XTextRangeCompare#optional";"compareRegionStarts()" "ScCellObj";"com::sun::star::text::XTextRangeCompare#optional";"compareRegionEnds()" -"ScCellObj";"com::sun::star::text::XSimpleText";"createTextCursor()" -"ScCellObj";"com::sun::star::text::XSimpleText";"createTextCursorByRange()" -"ScCellObj";"com::sun::star::text::XSimpleText";"insertString()" -"ScCellObj";"com::sun::star::text::XSimpleText";"insertControlCharacter()" "ScCellObj";"com::sun::star::sheet::XCellRangesQuery";"queryVisibleCells()" "ScCellObj";"com::sun::star::sheet::XCellRangesQuery";"queryEmptyCells()" "ScCellObj";"com::sun::star::sheet::XCellRangesQuery";"queryContentCells()" diff --git a/sc/qa/extras/sccellobj.cxx b/sc/qa/extras/sccellobj.cxx index cb1c5a1421fd..51d7b0ce22b1 100644 --- a/sc/qa/extras/sccellobj.cxx +++ b/sc/qa/extras/sccellobj.cxx @@ -10,11 +10,12 @@ #include #include #include -#include #include #include #include +#include #include +#include #include #include @@ -25,27 +26,30 @@ #include #include #include +#include #include using namespace css; using namespace css::uno; -namespace sc_apitest { - -class ScCellObj : public CalcUnoApiTest, public apitest::SheetCell, - public apitest::XCell, - public apitest::XCellAddressable, - public apitest::XColumnRowRange, - public apitest::XEnumerationAccess, - public apitest::XFormulaQuery, - public apitest::XIndent, - public apitest::XSheetAnnotationAnchor +namespace sc_apitest +{ +class ScCellObj : public CalcUnoApiTest, + public apitest::SheetCell, + public apitest::XCell, + public apitest::XCellAddressable, + public apitest::XColumnRowRange, + public apitest::XEnumerationAccess, + public apitest::XFormulaQuery, + public apitest::XIndent, + public apitest::XSheetAnnotationAnchor, + public apitest::XSimpleText { public: ScCellObj(); - virtual uno::Reference< uno::XInterface > init() override; - virtual uno::Reference< uno::XInterface > getXSpreadsheet() override; + virtual uno::Reference init() override; + virtual uno::Reference getXSpreadsheet() override; virtual void setUp() override; virtual void tearDown() override; @@ -81,23 +85,30 @@ public: // XSheetAnnotationAnchor CPPUNIT_TEST(testGetAnnotation); + // XSimpleText + CPPUNIT_TEST(testCreateTextCursor); + CPPUNIT_TEST(testCreateTextCursorByRange); + CPPUNIT_TEST(testInsertString); + CPPUNIT_TEST(testInsertControlCharacter); + CPPUNIT_TEST_SUITE_END(); private: - uno::Reference< lang::XComponent > mxComponent; + uno::Reference mxComponent; }; ScCellObj::ScCellObj() - : CalcUnoApiTest("/sc/qa/extras/testdocuments"), - apitest::XFormulaQuery(table::CellRangeAddress(0, 2, 3, 2, 3), table::CellRangeAddress(0, 0, 0, 3, 0), 0, 0) + : CalcUnoApiTest("/sc/qa/extras/testdocuments") + , apitest::XFormulaQuery(table::CellRangeAddress(0, 2, 3, 2, 3), + table::CellRangeAddress(0, 0, 0, 3, 0), 0, 0) { } -uno::Reference< uno::XInterface > ScCellObj::init() +uno::Reference ScCellObj::init() { - uno::Reference< sheet::XSpreadsheetDocument > xSheetDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference xSheetDoc(mxComponent, uno::UNO_QUERY_THROW); - uno::Reference xSheets (xSheetDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference xSheets(xSheetDoc->getSheets(), UNO_QUERY_THROW); uno::Reference xIndex(xSheets, UNO_QUERY_THROW); uno::Reference xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); @@ -111,9 +122,9 @@ uno::Reference< uno::XInterface > ScCellObj::init() uno::Reference ScCellObj::getXSpreadsheet() { - uno::Reference< sheet::XSpreadsheetDocument > xSheetDoc(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference xSheetDoc(mxComponent, uno::UNO_QUERY_THROW); - uno::Reference xSheets (xSheetDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference xSheets(xSheetDoc->getSheets(), UNO_QUERY_THROW); uno::Reference xIndex(xSheets, UNO_QUERY_THROW); uno::Reference xSheet(xIndex->getByIndex(0), UNO_QUERY_THROW); @@ -134,7 +145,6 @@ void ScCellObj::tearDown() CalcUnoApiTest::tearDown(); } - CPPUNIT_TEST_SUITE_REGISTRATION(ScCellObj); } // end namespace diff --git a/test/Library_subsequenttest.mk b/test/Library_subsequenttest.mk index 1269f3771f81..d0ce3ad4dac0 100644 --- a/test/Library_subsequenttest.mk +++ b/test/Library_subsequenttest.mk @@ -164,6 +164,7 @@ $(eval $(call gb_Library_add_exception_objects,subsequenttest,\ test/source/table/xtablechart \ test/source/table/xtablechartssupplier \ test/source/table/xtablerows \ + test/source/text/xsimpletext \ test/source/text/xtext \ test/source/text/xtextcontent \ test/source/text/xtextfield \ diff --git a/test/source/text/xsimpletext.cxx b/test/source/text/xsimpletext.cxx new file mode 100644 index 000000000000..edb61faa80ee --- /dev/null +++ b/test/source/text/xsimpletext.cxx @@ -0,0 +1,76 @@ +/* -*- 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 +#include +#include +#include +#include + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XSimpleText::testCreateTextCursor() +{ + uno::Reference xSimpleText(init(), UNO_QUERY_THROW); + + CPPUNIT_ASSERT(xSimpleText->createTextCursor()); +} + +void XSimpleText::testCreateTextCursorByRange() +{ + uno::Reference xSimpleText(init(), UNO_QUERY_THROW); + uno::Reference xCursor(xSimpleText->createTextCursor(), UNO_QUERY_THROW); + + xCursor->gotoStart(false); + + CPPUNIT_ASSERT(xSimpleText->createTextCursorByRange(xCursor)); +} + +void XSimpleText::testInsertString() +{ + uno::Reference xSimpleText(init(), UNO_QUERY_THROW); + uno::Reference xCursor(xSimpleText->createTextCursor(), UNO_QUERY_THROW); + ::rtl::OUString sString = "TestString"; + + xSimpleText->insertString(xCursor, sString, false); + ::rtl::OUString gString = xSimpleText->getText()->getString(); + + CPPUNIT_ASSERT(!gString.isEmpty()); + CPPUNIT_ASSERT(gString.indexOf(sString) >= 0); +} + +void XSimpleText::testInsertControlCharacter() +{ + bool bOK = true; + + uno::Reference xSimpleText(init(), UNO_QUERY_THROW); + uno::Reference xCursor(xSimpleText->createTextCursor(), UNO_QUERY_THROW); + + try + { + xSimpleText->insertControlCharacter(xCursor, text::ControlCharacter::PARAGRAPH_BREAK, + false); + xSimpleText->insertControlCharacter(xCursor, text::ControlCharacter::LINE_BREAK, false); + xSimpleText->insertString(xSimpleText->createTextCursor(), "newLine", false); + } + catch (const lang::IllegalArgumentException&) + { + bOK = false; + } + + OUString gString = xSimpleText->getString(); + CPPUNIT_ASSERT(bOK); + CPPUNIT_ASSERT(gString.indexOf("\n") > -1); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit