1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #include <test/sheet/xspreadsheets.hxx>
12 #include <com/sun/star/container/XIndexAccess.hpp>
13 #include <com/sun/star/container/XNamed.hpp>
14 #include <com/sun/star/sheet/XSpreadsheets.hpp>
16 #include <cppunit/TestAssert.h>
18 using namespace com::sun::star
;
19 using namespace com::sun::star::uno
;
24 void XSpreadsheets::testInsertNewByName()
26 uno::Reference
< sheet::XSpreadsheets
> xSpreadsheets(init(), UNO_QUERY_THROW
);
28 OUString
newSheetName( "SheetToInsert" );
29 xSpreadsheets
->insertNewByName(newSheetName
, 0);
31 uno::Reference
< container::XNameAccess
> xNameAccess(xSpreadsheets
, UNO_QUERY_THROW
);
32 CPPUNIT_ASSERT_MESSAGE("Sheet was not insert",
33 xNameAccess
->hasByName(newSheetName
));
36 void XSpreadsheets::testInsertNewByNameBadName()
38 uno::Reference
< sheet::XSpreadsheets
> xSpreadsheets(init(), UNO_QUERY_THROW
);
40 CPPUNIT_ASSERT_THROW_MESSAGE("No exception thrown",
41 xSpreadsheets
->insertNewByName("$%#/?\\", 0),
42 uno::RuntimeException
);
45 void XSpreadsheets::testMoveByName()
47 uno::Reference
< sheet::XSpreadsheets
> xSpreadsheets(init(), UNO_QUERY_THROW
);
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"));
55 xSpreadsheets
->moveByName("SheetToMove", 2);
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
);
63 CPPUNIT_ASSERT_EQUAL_MESSAGE("Sheet was not moved",
64 OUString("SheetToMove"),
68 void XSpreadsheets::testCopyByName()
70 uno::Reference
< sheet::XSpreadsheets
> xSpreadsheets(init(), UNO_QUERY_THROW
);
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"));
78 xSpreadsheets
->copyByName("SheetToCopySrc", "SheetToCopyDst", 0);
79 CPPUNIT_ASSERT_MESSAGE("Sheet was not copied",
80 xNameAccess
->hasByName("SheetToCopyDst"));
85 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */