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 
20 using namespace css;
21 using namespace css::uno;
22 
23 namespace apitest
24 {
25 void XRecentFunctions::testGetRecentFunctionIds()
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 
38 void XRecentFunctions::testSetRecentFunctionIds()
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  std::random_device rd;
54  std::mt19937 gen(rd());
55  std::uniform_int_distribution<> distr(1, nMaxNumber + 1);
56 
57  int nStartIdx = distr(gen);
58  for (int i = nStartIdx; i < nStartIdx + nMaxNumber; i++)
59  aIds[i - nStartIdx] = 1;
60 
61  xRecentFunctions->setRecentFunctionIds(aIds);
62 
63  aIds = xRecentFunctions->getRecentFunctionIds();
64  CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set Ids (max. size list)", nMaxNumber,
65  aIds.getLength());
66 }
67 
68 void XRecentFunctions::testGetMaxRecentFunctions()
69 {
70  uno::Reference<sheet::XRecentFunctions> xRecentFunctions(init(), UNO_QUERY_THROW);
71  CPPUNIT_ASSERT_MESSAGE("Unable to execute getMaxRecentFunctions()",
72  sal_Int32(0) != xRecentFunctions->getMaxRecentFunctions());
73 }
74 }
75 
76 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
int i
FILE * init(int, char **)