1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
12 #include <test/sheet/xfunctiondescriptions.hxx>
14 #include <com/sun/star/beans/PropertyValue.hpp>
15 #include <com/sun/star/sheet/XFunctionDescriptions.hpp>
16 #include <com/sun/star/lang/IllegalArgumentException.hpp>
17 #include <com/sun/star/uno/Reference.hxx>
19 #include <cppunit/TestAssert.h>
22 using namespace com::sun::star
;
23 using namespace com::sun::star::uno
;
27 void XFunctionDescriptions::testGetById()
29 uno::Reference
<sheet::XFunctionDescriptions
> xFD(init(), UNO_QUERY_THROW
);
31 const sal_Int32 nCount
= xFD
->getCount();
32 CPPUNIT_ASSERT_MESSAGE("No FunctionDescriptions available", 0 < nCount
);
34 // first grab a random function descriptions
35 std::random_device rd
;
36 std::mt19937
gen(rd());
37 std::uniform_int_distribution
<> distr(0, nCount
- 1);
38 int nNumber
= distr(gen
);
42 uno::Sequence
<beans::PropertyValue
> aProps1
;
43 CPPUNIT_ASSERT(xFD
->getByIndex(nNumber
) >>= aProps1
);
44 for (const auto& aProp
: std::as_const(aProps1
))
46 if (aProp
.Name
== "Id")
47 aId1
= aProp
.Value
.get
<sal_Int32
>();
48 if (aProp
.Name
== "Name")
49 aName1
= aProp
.Value
.get
<OUString
>();
52 // fetch the same descriptions by its id
55 const uno::Sequence
<beans::PropertyValue
> aProps2
= xFD
->getById(aId1
);
56 CPPUNIT_ASSERT_MESSAGE("Received empty FunctionDescriptions from getById()",
57 aProps2
.hasElements());
58 for (const auto& aProp
: aProps2
)
60 if (aProp
.Name
== "Id")
61 aId2
= aProp
.Value
.get
<sal_Int32
>();
62 if (aProp
.Name
== "Name")
63 aName2
= aProp
.Value
.get
<OUString
>();
65 CPPUNIT_ASSERT_EQUAL_MESSAGE("Received wrong FunctionDescriptions (Id)", aId1
, aId2
);
66 CPPUNIT_ASSERT_EQUAL_MESSAGE("Received wrong FunctionDescriptions (Name)", aName1
, aName2
);
68 CPPUNIT_ASSERT_THROW_MESSAGE("No IllegalArgumentException thrown", xFD
->getById(-1),
69 css::lang::IllegalArgumentException
);
73 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */