LibreOffice Module test (master)  1
xnamed.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 #include <rtl/ustring.hxx>
12 
13 #include <com/sun/star/container/XNamed.hpp>
14 #include <com/sun/star/uno/RuntimeException.hpp>
15 
16 #include <com/sun/star/uno/Reference.hxx>
17 
18 #include <cppunit/TestAssert.h>
19 
20 using namespace css;
21 using namespace css::uno;
22 
23 namespace apitest
24 {
25 void XNamed::testGetName()
26 {
27  uno::Reference<container::XNamed> xNamed(init(), UNO_QUERY_THROW);
28  CPPUNIT_ASSERT_EQUAL(m_aTestName, xNamed->getName());
29 }
30 
31 void XNamed::testSetName()
32 {
33  uno::Reference<container::XNamed> xNamed(init(), UNO_QUERY_THROW);
34  OUString aTestName("NewName");
35 
36  xNamed->setName(aTestName);
37  CPPUNIT_ASSERT_EQUAL(aTestName, xNamed->getName());
38 
39  // restore old name
40  xNamed->setName(m_aTestName);
41  CPPUNIT_ASSERT_EQUAL(m_aTestName, xNamed->getName());
42 }
43 
44 void XNamed::testSetNameByScSheetLinkObj()
45 {
46  uno::Reference<container::XNamed> xNamed(init(), uno::UNO_QUERY_THROW);
47  OUString aTestName(m_aTestName.replaceAll("ScSheetLinkObj", "NewScSheetLinkObj"));
48 
49  xNamed->setName(aTestName);
50  CPPUNIT_ASSERT_EQUAL(aTestName, xNamed->getName());
51 
52  // restore old name
53  xNamed->setName(m_aTestName);
54  CPPUNIT_ASSERT_EQUAL(m_aTestName, xNamed->getName());
55 }
56 
57 void XNamed::testSetNameThrowsException()
58 {
59  uno::Reference<container::XNamed> xNamed(init(), uno::UNO_QUERY_THROW);
60 
61  CPPUNIT_ASSERT_THROW(xNamed->setName("NewName"), uno::RuntimeException);
62 }
63 }
64 
65 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FILE * init(int, char **)