diff options
author | Jens Carl <j.carl43@gmx.de> | 2017-08-05 04:31:57 +0000 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2017-08-07 00:46:24 +0200 |
commit | 44077dc6104e5eab40414889e7be776767709984 (patch) | |
tree | d91df4e9e9c55b740f4572cad377110741423a61 | |
parent | f79258444185f3d6939facb3cab071ad92d873e4 (diff) |
tdf#45904 Move Java _XSpreadsheets tests to C++
Change-Id: If311e2c8ca89528760b14d977bca76e14164e6e3
Reviewed-on: https://gerrit.libreoffice.org/40783
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
-rw-r--r-- | include/test/sheet/xspreadsheets.hxx | 38 | ||||
-rw-r--r-- | qadevOOo/Jar_OOoRunner.mk | 1 | ||||
-rw-r--r-- | qadevOOo/objdsc/sc/com.sun.star.comp.office.ScTableSheetsObj.csv | 3 | ||||
-rw-r--r-- | qadevOOo/tests/java/ifc/sheet/_XSpreadsheets.java | 178 | ||||
-rw-r--r-- | sc/qa/extras/sctablesheetsobj.cxx | 11 | ||||
-rw-r--r-- | test/Library_subsequenttest.mk | 1 | ||||
-rw-r--r-- | test/source/sheet/xspreadsheets.cxx | 85 |
7 files changed, 133 insertions, 184 deletions
diff --git a/include/test/sheet/xspreadsheets.hxx b/include/test/sheet/xspreadsheets.hxx new file mode 100644 index 000000000000..3c8ecb4f37e5 --- /dev/null +++ b/include/test/sheet/xspreadsheets.hxx @@ -0,0 +1,38 @@ +/* -*- 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_SHEET_XSPREADSHEETS_HXX +#define INCLUDED_TEST_SHEET_XSPREADSHEETS_HXX + +#include <test/testdllapi.hxx> +#include <com/sun/star/uno/XInterface.hpp> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace apitest { + +class OOO_DLLPUBLIC_TEST XSpreadsheets +{ +public: + virtual uno::Reference< uno::XInterface > init() = 0; + virtual ~XSpreadsheets(){} + + void testInsertNewByName(); + void testInsertNewByNameBadName(); + void testMoveByName(); + void testCopyByName(); +}; + +} + +#endif // INCLUDED_TEST_SHEET_XSPREADSHEETS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/qadevOOo/Jar_OOoRunner.mk b/qadevOOo/Jar_OOoRunner.mk index 191fb20ac158..f68fca900db2 100644 --- a/qadevOOo/Jar_OOoRunner.mk +++ b/qadevOOo/Jar_OOoRunner.mk @@ -648,7 +648,6 @@ $(eval $(call gb_Jar_add_sourcefiles,OOoRunner,\ qadevOOo/tests/java/ifc/sheet/_XSheetPageBreak \ qadevOOo/tests/java/ifc/sheet/_XSpreadsheet \ qadevOOo/tests/java/ifc/sheet/_XSpreadsheetDocument \ - qadevOOo/tests/java/ifc/sheet/_XSpreadsheets \ qadevOOo/tests/java/ifc/sheet/_XSpreadsheetView \ qadevOOo/tests/java/ifc/sheet/_XSubTotalCalculatable \ qadevOOo/tests/java/ifc/sheet/_XSubTotalDescriptor \ diff --git a/qadevOOo/objdsc/sc/com.sun.star.comp.office.ScTableSheetsObj.csv b/qadevOOo/objdsc/sc/com.sun.star.comp.office.ScTableSheetsObj.csv index ff6726f4270a..514566881a29 100644 --- a/qadevOOo/objdsc/sc/com.sun.star.comp.office.ScTableSheetsObj.csv +++ b/qadevOOo/objdsc/sc/com.sun.star.comp.office.ScTableSheetsObj.csv @@ -6,9 +6,6 @@ "ScTableSheetsObj";"com::sun::star::container::XNameContainer";"removeByName()" "ScTableSheetsObj";"com::sun::star::container::XIndexAccess";"getCount()" "ScTableSheetsObj";"com::sun::star::container::XIndexAccess";"getByIndex()" -"ScTableSheetsObj";"com::sun::star::sheet::XSpreadsheets";"insertNewByName()" -"ScTableSheetsObj";"com::sun::star::sheet::XSpreadsheets";"moveByName()" -"ScTableSheetsObj";"com::sun::star::sheet::XSpreadsheets";"copyByName()" "ScTableSheetsObj";"com::sun::star::container::XElementAccess";"getElementType()" "ScTableSheetsObj";"com::sun::star::container::XElementAccess";"hasElements()" "ScTableSheetsObj";"com::sun::star::container::XEnumerationAccess";"createEnumeration()" diff --git a/qadevOOo/tests/java/ifc/sheet/_XSpreadsheets.java b/qadevOOo/tests/java/ifc/sheet/_XSpreadsheets.java deleted file mode 100644 index 2944e9c53cec..000000000000 --- a/qadevOOo/tests/java/ifc/sheet/_XSpreadsheets.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * 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/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -package ifc.sheet; - -import java.util.concurrent.atomic.AtomicInteger; - -import com.sun.star.sheet.XSpreadsheets; - -import lib.MultiMethodTest; - - -/** -* Testing <code>com.sun.star.sheet.XSpreadsheets</code> -* interface methods : -* <ul> -* <li><code> insertNewByName()</code></li> -* <li><code> moveByName()</code></li> -* <li><code> copyByName()</code></li> -* </ul> <p> -* Test is multithread compliant. <p> -* @see com.sun.star.sheet.XSpreadsheets -*/ -public class _XSpreadsheets extends MultiMethodTest { - private static final AtomicInteger uniqCount = new AtomicInteger(0); - public XSpreadsheets oObj = null; - protected int uniqNumber = 0; - - /** - * Sets the unique number for the current test. - */ - @Override - protected synchronized void before() { - uniqNumber = uniqCount.getAndIncrement(); - } - - /** - * Test inserts new sheet using the name returned by the method - * <code>newName</code>, copies inserted sheet with the new name, - * checks existence of the sheet with this name in collection and removes - * the both sheets from the collection. <p> - * Has <b> OK </b> status if the sheet with the name of the copy exists - * in the collection and no exceptions were thrown. <p> - */ - public void _copyByName() { - boolean result = true; - - //first insert one that should be copied - String iS = newName("copyFrom"); - log.println("Inserting sheet '" + iS + "'"); - oObj.insertNewByName(iS, (short) 0); - - String[] eNames = oObj.getElementNames(); - String NewSheet = newName("copyTo"); - log.println("Try to copy " + eNames[0] + " to " + NewSheet); - oObj.copyByName(eNames[0], NewSheet, (short) 0); - result = oObj.hasByName(NewSheet); - - //remove all inserted sheets - try { - oObj.removeByName(NewSheet); - oObj.removeByName(iS); - } catch (com.sun.star.lang.WrappedTargetException e) { - log.print("Can't remove sheet by name"); - e.printStackTrace(log); - result = false; - } catch (com.sun.star.container.NoSuchElementException e) { - log.print("Can't remove sheet by name"); - e.printStackTrace(log); - result = false; - } - - tRes.tested("copyByName()", result); - } // finished _copyByName - - /** - * Test inserts new sheet using the name returned by the method - * <code>newName</code>, moves the inserted sheet to the new position - * in collection, gets all element names in collection and checks the name - * of the sheet in the new position. <p> - * Has <b> OK </b> status if the sheet name in the new position is equal to - * the name of the sheet that was moved. <p> - */ - public void _moveByName() { - //first insert one that should be moved - String iS = newName("move"); - oObj.insertNewByName(iS, (short) 0); - - String[] eNames = oObj.getElementNames(); - String sheetToMove = eNames[0]; - log.println("Try to move " + sheetToMove); - oObj.moveByName(sheetToMove, (short) 2); - eNames = oObj.getElementNames(); - tRes.tested("moveByName()", sheetToMove.equals(eNames[1])); - } // finished _moveByName - - /** - * Test inserts new sheet using the name returned by the method - * <code>newName</code>, checks the existence of the inserted sheet in - * the collection, removes the sheet, tries to insert the sheet with the - * bad name returned by method <code>badName()</code>. <p> - * Has <b> OK </b> status if the inserted sheet exists in the collection - * after first method call and if exception occurred during the second call. <p> - */ - public void _insertNewByName() { - boolean result = false; - - String NewSheet = newName("insert"); - log.println("Try to insert " + NewSheet); - oObj.insertNewByName(NewSheet, (short) 0); - result = oObj.hasByName(NewSheet); - - try { - oObj.removeByName(NewSheet); - } catch (com.sun.star.lang.WrappedTargetException e) { - log.print("Can't remove sheet '" + NewSheet + "':"); - e.printStackTrace(log); - result = false; - } catch (com.sun.star.container.NoSuchElementException e) { - log.print("Can't remove sheet '" + NewSheet + "':"); - e.printStackTrace(log); - result = false; - } - - try { - NewSheet = badName(); - log.println("Try to insert " + NewSheet); - oObj.insertNewByName(NewSheet, (short) 0); - log.println( - "No Exception thrown while inserting sheet with invalid name"); - result &= false; - oObj.removeByName(NewSheet); - } catch (com.sun.star.uno.RuntimeException e) { - log.println( - "Expected exception occurred during testing 'insertNewByName'"); - result &= true; - } catch (com.sun.star.lang.WrappedTargetException e) { - log.print("Can't remove sheet '" + NewSheet + "':"); - e.printStackTrace(log); - result = false; - } catch (com.sun.star.container.NoSuchElementException e) { - log.print("Can't remove sheet '" + NewSheet + "':"); - e.printStackTrace(log); - result = false; - } - - tRes.tested("insertNewByName()", result); - } // finished _insertByName - - /** - * Method returns unique new name using passed prefix and unique number - * of the current test. - */ - public String newName(String prefix) { - return prefix + uniqNumber; - } // finished newName - - /** - * Method return bad name for a sheet using the name of the current thread. - */ - public String badName() { - return "$%#/?\\"; - } // finished badName -} //finish class _XSpreadsheets diff --git a/sc/qa/extras/sctablesheetsobj.cxx b/sc/qa/extras/sctablesheetsobj.cxx index a67bf2dda1ba..8bc3010c06af 100644 --- a/sc/qa/extras/sctablesheetsobj.cxx +++ b/sc/qa/extras/sctablesheetsobj.cxx @@ -8,6 +8,7 @@ */ #include <test/calc_unoapi_test.hxx> +#include <test/sheet/xspreadsheets.hxx> #include <test/sheet/xspreadsheets2.hxx> #include <test/container/xnamecontainer.hxx> @@ -19,9 +20,9 @@ using namespace css::uno; namespace sc_apitest { -#define NUMBER_OF_TESTS 11 +#define NUMBER_OF_TESTS 15 -class ScTableSheetsObj : public CalcUnoApiTest, public ::apitest::XSpreadsheets2, public apitest::XNameContainer +class ScTableSheetsObj : public CalcUnoApiTest, public ::apitest::XSpreadsheets, public ::apitest::XSpreadsheets2, public apitest::XNameContainer { public: ScTableSheetsObj(); @@ -30,6 +31,12 @@ public: virtual void tearDown() override; CPPUNIT_TEST_SUITE(ScTableSheetsObj); + // XSpreadsheets + CPPUNIT_TEST(testInsertNewByName); + CPPUNIT_TEST(testInsertNewByNameBadName); + CPPUNIT_TEST(testCopyByName); + CPPUNIT_TEST(testMoveByName); + // XSpreadsheets2 CPPUNIT_TEST(testImportedSheetNameAndIndex); CPPUNIT_TEST(testImportString); CPPUNIT_TEST(testImportValue); diff --git a/test/Library_subsequenttest.mk b/test/Library_subsequenttest.mk index fb0e3f42000d..d996d7ddf524 100644 --- a/test/Library_subsequenttest.mk +++ b/test/Library_subsequenttest.mk @@ -59,6 +59,7 @@ $(eval $(call gb_Library_add_exception_objects,subsequenttest,\ test/source/sheet/xnamedranges \ test/source/sheet/xprintareas \ test/source/sheet/xspreadsheetdocument \ + test/source/sheet/xspreadsheets \ test/source/sheet/xspreadsheets2 \ test/source/sheet/xsheetannotation \ test/source/sheet/xsheetannotations \ diff --git a/test/source/sheet/xspreadsheets.cxx b/test/source/sheet/xspreadsheets.cxx new file mode 100644 index 000000000000..8c59258c1711 --- /dev/null +++ b/test/source/sheet/xspreadsheets.cxx @@ -0,0 +1,85 @@ +/* -*- 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 <test/sheet/xspreadsheets.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> + +#include "cppunit/extensions/HelperMacros.h" + +using namespace com::sun::star; +using namespace com::sun::star::uno; + + +namespace apitest { + +void XSpreadsheets::testInsertNewByName() +{ + uno::Reference< sheet::XSpreadsheets > xSpreadsheets(init(), UNO_QUERY_THROW); + + OUString newSheetName( "SheetToInsert" ); + xSpreadsheets->insertNewByName(newSheetName, 0); + + uno::Reference< container::XNameAccess > xNameAccess(xSpreadsheets, UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("Sheet was not insert", + xNameAccess->hasByName(newSheetName)); +} + +void XSpreadsheets::testInsertNewByNameBadName() +{ + uno::Reference< sheet::XSpreadsheets > xSpreadsheets(init(), UNO_QUERY_THROW); + + CPPUNIT_ASSERT_THROW_MESSAGE("No excpetion thrown", + xSpreadsheets->insertNewByName("$%#/?\\", 0), + uno::RuntimeException); +} + +void XSpreadsheets::testMoveByName() +{ + uno::Reference< sheet::XSpreadsheets > xSpreadsheets(init(), UNO_QUERY_THROW); + + // first insert one that should be moved + xSpreadsheets->insertNewByName("SheetToMove", 0); + uno::Reference< container::XNameAccess > xNameAccess(xSpreadsheets, UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("Sheet to move was not insert", + xNameAccess->hasByName("SheetToCopySrc")); + + xSpreadsheets->moveByName("SheetToMove", 2); + + // get sheet from the new position + uno::Reference< container::XIndexAccess > oIndexAccess(xSpreadsheets, UNO_QUERY_THROW); + uno::Any aAny = oIndexAccess->getByIndex(1); + uno::Reference< container::XNamed > xNamed; + CPPUNIT_ASSERT(aAny >>= xNamed); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Sheet was not moved", + OUString("SheetToMove"), + xNamed->getName()); +} + +void XSpreadsheets::testCopyByName() +{ + uno::Reference< sheet::XSpreadsheets > xSpreadsheets(init(), UNO_QUERY_THROW); + + // insert new sheet to copy + xSpreadsheets->insertNewByName("SheetToCopySrc", 0); + uno::Reference< container::XNameAccess > xNameAccess(xSpreadsheets, UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("Sheet to copy was not insert", + xNameAccess->hasByName("SheetToCopySrc")); + + xSpreadsheets->copyByName("SheetToCopySrc", "SheetToCopyDst", 0); + CPPUNIT_ASSERT_MESSAGE("Sheet was not copied", + xNameAccess->hasByName("SheetToCopyDst")); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |