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>
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();
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 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,
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());
FILE * init(int, char **)