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>
21using namespace css::uno;
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]);
40 uno::Reference<sheet::XRecentFunctions> xRecentFunctions(
init(), UNO_QUERY_THROW);
42 const sal_Int32 nMaxNumber = xRecentFunctions->getMaxRecentFunctions();
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());
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);
58 int nStartIdx = distr(gen);
59 for (
int i = nStartIdx;
i < nStartIdx + nMaxNumber;
i++)
60 pIds[
i - nStartIdx] = 1;
62 xRecentFunctions->setRecentFunctionIds(aIds);
64 aIds = xRecentFunctions->getRecentFunctionIds();
65 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Unable to set Ids (max. size list)", nMaxNumber,
71 uno::Reference<sheet::XRecentFunctions> xRecentFunctions(
init(), UNO_QUERY_THROW);
72 CPPUNIT_ASSERT_MESSAGE(
"Unable to execute getMaxRecentFunctions()",
73 sal_Int32(0) != xRecentFunctions->getMaxRecentFunctions());
virtual css::uno::Reference< css::uno::XInterface > init()=0
void testGetRecentFunctionIds()
void testGetMaxRecentFunctions()
void testSetRecentFunctionIds()