LibreOffice Module test (master) 1
xrecentfunctions.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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
10#include <random>
11
13
14#include <com/sun/star/sheet/XRecentFunctions.hpp>
15#include <com/sun/star/uno/Reference.hxx>
16#include <com/sun/star/uno/Sequence.hxx>
17
18#include <cppunit/TestAssert.h>
19
20using namespace css;
21using namespace css::uno;
22
23namespace apitest
24{
26{
27 uno::Reference<sheet::XRecentFunctions> xRecentFunctions(init(), UNO_QUERY_THROW);
28
29 uno::Sequence<sal_Int32> aIds = xRecentFunctions->getRecentFunctionIds();
30 const sal_Int32 nNumber = aIds.getLength();
31 CPPUNIT_ASSERT_MESSAGE("Recent IDs greater the max number",
32 nNumber <= xRecentFunctions->getMaxRecentFunctions());
33 for (int i = 0; i < nNumber - 1; i++)
34 for (int j = i + 1; j < nNumber; j++)
35 CPPUNIT_ASSERT_MESSAGE("Same IDs found", aIds[i] != aIds[j]);
36}
37
39{
40 uno::Reference<sheet::XRecentFunctions> xRecentFunctions(init(), UNO_QUERY_THROW);
41
42 const sal_Int32 nMaxNumber = xRecentFunctions->getMaxRecentFunctions();
43
44 // empty list
45 uno::Sequence<sal_Int32> aIds;
46 xRecentFunctions->setRecentFunctionIds(aIds);
47
48 aIds = xRecentFunctions->getRecentFunctionIds();
49 CPPUNIT_ASSERT_MESSAGE("Unable to set Ids (empty list)", !aIds.hasElements());
50
51 // max. size list
52 aIds.realloc(nMaxNumber);
53 auto pIds = aIds.getArray();
54 std::random_device rd;
55 std::mt19937 gen(rd());
56 std::uniform_int_distribution<> distr(1, nMaxNumber + 1);
57
58 int nStartIdx = distr(gen);
59 for (int i = nStartIdx; i < nStartIdx + nMaxNumber; i++)
60 pIds[i - nStartIdx] = 1;
61
62 xRecentFunctions->setRecentFunctionIds(aIds);
63
64 aIds = xRecentFunctions->getRecentFunctionIds();
65 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set Ids (max. size list)", nMaxNumber,
66 aIds.getLength());
67}
68
70{
71 uno::Reference<sheet::XRecentFunctions> xRecentFunctions(init(), UNO_QUERY_THROW);
72 CPPUNIT_ASSERT_MESSAGE("Unable to execute getMaxRecentFunctions()",
73 sal_Int32(0) != xRecentFunctions->getMaxRecentFunctions());
74}
75}
76
77/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
virtual css::uno::Reference< css::uno::XInterface > init()=0
int i