bump product version to 7.2.5.1
[LibreOffice.git] / test / source / sheet / xrecentfunctions.cxx
blob7dded7f3516c2a5f793be600b9f1459070a1ac52
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.
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 */
10 #include <random>
12 #include <test/sheet/xrecentfunctions.hxx>
14 #include <com/sun/star/sheet/XRecentFunctions.hpp>
15 #include <com/sun/star/uno/Reference.hxx>
16 #include <com/sun/star/uno/Sequence.hxx>
18 #include <cppunit/TestAssert.h>
20 using namespace css;
21 using namespace css::uno;
23 namespace apitest
25 void XRecentFunctions::testGetRecentFunctionIds()
27 uno::Reference<sheet::XRecentFunctions> xRecentFunctions(init(), UNO_QUERY_THROW);
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]);
38 void XRecentFunctions::testSetRecentFunctionIds()
40 uno::Reference<sheet::XRecentFunctions> xRecentFunctions(init(), UNO_QUERY_THROW);
42 const sal_Int32 nMaxNumber = xRecentFunctions->getMaxRecentFunctions();
44 // empty list
45 uno::Sequence<sal_Int32> aIds;
46 xRecentFunctions->setRecentFunctionIds(aIds);
48 aIds = xRecentFunctions->getRecentFunctionIds();
49 CPPUNIT_ASSERT_MESSAGE("Unable to set Ids (empty list)", !aIds.hasElements());
51 // max. size list
52 aIds.realloc(nMaxNumber);
53 std::random_device rd;
54 std::mt19937 gen(rd());
55 std::uniform_int_distribution<> distr(1, nMaxNumber + 1);
57 int nStartIdx = distr(gen);
58 for (int i = nStartIdx; i < nStartIdx + nMaxNumber; i++)
59 aIds[i - nStartIdx] = 1;
61 xRecentFunctions->setRecentFunctionIds(aIds);
63 aIds = xRecentFunctions->getRecentFunctionIds();
64 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set Ids (max. size list)", nMaxNumber,
65 aIds.getLength());
68 void XRecentFunctions::testGetMaxRecentFunctions()
70 uno::Reference<sheet::XRecentFunctions> xRecentFunctions(init(), UNO_QUERY_THROW);
71 CPPUNIT_ASSERT_MESSAGE("Unable to execute getMaxRecentFunctions()",
72 sal_Int32(0) != xRecentFunctions->getMaxRecentFunctions());
76 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */