LibreOffice Module test (master) 1
xspreadsheets.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
11
12#include <com/sun/star/container/XIndexAccess.hpp>
13#include <com/sun/star/container/XNamed.hpp>
14#include <com/sun/star/sheet/XSpreadsheets.hpp>
15
16#include <cppunit/TestAssert.h>
17
18using namespace com::sun::star;
19using namespace com::sun::star::uno;
20
21
22namespace apitest {
23
25{
26 uno::Reference< sheet::XSpreadsheets > xSpreadsheets(init(), UNO_QUERY_THROW);
27
28 OUString newSheetName( "SheetToInsert" );
29 xSpreadsheets->insertNewByName(newSheetName, 0);
30
31 uno::Reference< container::XNameAccess > xNameAccess(xSpreadsheets, UNO_QUERY_THROW);
32 CPPUNIT_ASSERT_MESSAGE("Sheet was not insert",
33 xNameAccess->hasByName(newSheetName));
34}
35
37{
38 uno::Reference< sheet::XSpreadsheets > xSpreadsheets(init(), UNO_QUERY_THROW);
39
40 CPPUNIT_ASSERT_THROW_MESSAGE("No exception thrown",
41 xSpreadsheets->insertNewByName("$%#/?\\", 0),
42 uno::RuntimeException);
43}
44
46{
47 uno::Reference< sheet::XSpreadsheets > xSpreadsheets(init(), UNO_QUERY_THROW);
48
49 // first insert one that should be moved
50 xSpreadsheets->insertNewByName("SheetToMove", 0);
51 uno::Reference< container::XNameAccess > xNameAccess(xSpreadsheets, UNO_QUERY_THROW);
52 CPPUNIT_ASSERT_MESSAGE("Sheet to move was not insert",
53 xNameAccess->hasByName("SheetToMove"));
54
55 xSpreadsheets->moveByName("SheetToMove", 2);
56
57 // get sheet from the new position
58 uno::Reference< container::XIndexAccess > oIndexAccess(xSpreadsheets, UNO_QUERY_THROW);
59 uno::Any aAny = oIndexAccess->getByIndex(1);
60 uno::Reference< container::XNamed > xNamed;
61 CPPUNIT_ASSERT(aAny >>= xNamed);
62
63 CPPUNIT_ASSERT_EQUAL_MESSAGE("Sheet was not moved",
64 OUString("SheetToMove"),
65 xNamed->getName());
66}
67
69{
70 uno::Reference< sheet::XSpreadsheets > xSpreadsheets(init(), UNO_QUERY_THROW);
71
72 // insert new sheet to copy
73 xSpreadsheets->insertNewByName("SheetToCopySrc", 0);
74 uno::Reference< container::XNameAccess > xNameAccess(xSpreadsheets, UNO_QUERY_THROW);
75 CPPUNIT_ASSERT_MESSAGE("Sheet to copy was not insert",
76 xNameAccess->hasByName("SheetToCopySrc"));
77
78 xSpreadsheets->copyByName("SheetToCopySrc", "SheetToCopyDst", 0);
79 CPPUNIT_ASSERT_MESSAGE("Sheet was not copied",
80 xNameAccess->hasByName("SheetToCopyDst"));
81}
82
83}
84
85/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Reference< css::uno::XInterface > init()=0