12 #include <com/sun/star/beans/XPropertySet.hpp>
13 #include <com/sun/star/sheet/XSpreadsheet.hpp>
14 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
15 #include <com/sun/star/sheet/XSpreadsheets.hpp>
16 #include <com/sun/star/table/XCell.hpp>
17 #include <com/sun/star/uno/Any.hxx>
18 #include <com/sun/star/uno/Reference.hxx>
19 #include <com/sun/star/uno/Sequence.hxx>
21 #include <cppunit/TestAssert.h>
28 void Shape::testShapePropertiesAnchor()
30 uno::Reference<beans::XPropertySet> xShape(
init(), UNO_QUERY_THROW);
33 uno::Reference<sheet::XSpreadsheetDocument> xDoc(getXSheetDocument(), UNO_QUERY_THROW);
34 uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW);
35 uno::Sequence<OUString> sheetNames = xSheets->getElementNames();
36 uno::Reference<sheet::XSpreadsheet> xSheet(xSheets->getByName(sheetNames[0]), UNO_QUERY_THROW);
37 uno::Reference<table::XCell> xCell(xSheet->getCellByPosition(0, 0), UNO_SET_THROW);
40 uno::Reference<sheet::XSpreadsheet> xSheetGet;
41 CPPUNIT_ASSERT_MESSAGE(
"Unable to get PropertyValue Anchor (XSpreadsheet)",
42 xShape->getPropertyValue(
"Anchor") >>= xSheetGet);
46 xShape->setPropertyValue(
"Anchor", aNewValue);
47 uno::Reference<table::XCell> xCellGet;
48 CPPUNIT_ASSERT_MESSAGE(
"Unable to get PropertyValue Anchor (XCell)",
49 xShape->getPropertyValue(
"Anchor") >>= xCellGet);
52 bool bIsResizeWithCell = {};
53 CPPUNIT_ASSERT(xShape->getPropertyValue(
"ResizeWithCell") >>= bIsResizeWithCell);
54 CPPUNIT_ASSERT_MESSAGE(
"Shape should not resize with the cell", !bIsResizeWithCell);
56 xShape->setPropertyValue(
"ResizeWithCell",
uno::Any(
true));
57 CPPUNIT_ASSERT(xShape->getPropertyValue(
"ResizeWithCell") >>= bIsResizeWithCell);
58 CPPUNIT_ASSERT_MESSAGE(
"Shape should resize with the cell", bIsResizeWithCell);
61 uno::Reference<table::XCell> xCell2(xSheet->getCellByPosition(1, 2), UNO_SET_THROW);
63 xShape->setPropertyValue(
"Anchor", aNewValue);
64 CPPUNIT_ASSERT(xShape->getPropertyValue(
"ResizeWithCell") >>= bIsResizeWithCell);
65 CPPUNIT_ASSERT_MESSAGE(
"ResizeWithCell should still be set", bIsResizeWithCell);
69 xShape->setPropertyValue(
"Anchor", aNewValue);
70 CPPUNIT_ASSERT(xShape->getPropertyValue(
"Anchor") >>= xSheetGet);
71 CPPUNIT_ASSERT_MESSAGE(
"Unable to get PropertyValue Anchor (XSpreadsheet)",
72 xShape->getPropertyValue(
"Anchor") >>= xSheetGet);
75 CPPUNIT_ASSERT(xShape->getPropertyValue(
"ResizeWithCell") >>= bIsResizeWithCell);
76 CPPUNIT_ASSERT_MESSAGE(
"ResizeWithCell should be false for sheet anchored shapes",
78 xShape->setPropertyValue(
"ResizeWithCell",
uno::Any(
true));
79 CPPUNIT_ASSERT(xShape->getPropertyValue(
"ResizeWithCell") >>= bIsResizeWithCell);
80 CPPUNIT_ASSERT_MESSAGE(
"ResizeWithCell should be unchangeable for sheet anchored shapes",
84 void Shape::testShapePropertiesPosition()
86 uno::Reference<beans::XPropertySet> xShape(
init(), UNO_QUERY_THROW);
89 sal_Int32 nHoriOrientPositionGet = 0;
90 sal_Int32 nHoriOrientPositionSet = 0;
91 CPPUNIT_ASSERT_MESSAGE(
"Unable to get PropertyValue HoriOrientPosition",
92 xShape->getPropertyValue(
"HoriOrientPosition")
93 >>= nHoriOrientPositionGet);
95 aNewValue <<= nHoriOrientPositionGet + 42;
96 xShape->setPropertyValue(
"HoriOrientPosition", aNewValue);
97 CPPUNIT_ASSERT(xShape->getPropertyValue(
"HoriOrientPosition") >>= nHoriOrientPositionSet);
98 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Unable to set PropertyValue HoriOrientPosition",
99 nHoriOrientPositionGet + 42, nHoriOrientPositionSet);
101 sal_Int32 nVertOrientPositionGet = 0;
102 sal_Int32 nVertOrientPositionSet = 0;
103 CPPUNIT_ASSERT_MESSAGE(
"Unable to get PropertyValue VertOrientPosition",
104 xShape->getPropertyValue(
"VertOrientPosition")
105 >>= nVertOrientPositionGet);
107 aNewValue <<= nVertOrientPositionGet + 42;
108 xShape->setPropertyValue(
"VertOrientPosition", aNewValue);
109 CPPUNIT_ASSERT(xShape->getPropertyValue(
"VertOrientPosition") >>= nVertOrientPositionSet);
110 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Unable to set PropertyValue VertOrientPosition",
111 nVertOrientPositionGet + 42, nVertOrientPositionSet);
FILE * init(int, char **)