/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include #include #include #include #include #include #include #include #include #include using namespace com::sun::star; using namespace com::sun::star::uno; namespace apitest { void SheetCellRanges::testSheetCellRangesProperties() { uno::Reference xSheetCellRanges(init(), UNO_QUERY_THROW); OUString propName; uno::Any aNewValue; uno::Sequence aPropValue{ comphelper::makePropertyValue( u"StyleName"_ustr, u"Result2"_ustr) }; propName = "ConditionalFormat"; uno::Reference aConditionalFormatGet; uno::Reference aConditionalFormatSet; CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ConditionalFormat", xSheetCellRanges->getPropertyValue(propName) >>= aConditionalFormatGet); uno::Reference aConditionalFormatNew(aConditionalFormatGet, UNO_SET_THROW); aConditionalFormatNew->addNew(aPropValue); aNewValue <<= aConditionalFormatNew; xSheetCellRanges->setPropertyValue(propName, aNewValue); CPPUNIT_ASSERT(xSheetCellRanges->getPropertyValue(propName) >>= aConditionalFormatSet); for (auto i = 0; i < aConditionalFormatSet->getCount(); i++) { uno::Reference xSCENew(aConditionalFormatNew->getByIndex(i), UNO_QUERY_THROW); uno::Reference xSCESet(aConditionalFormatSet->getByIndex(i), UNO_QUERY_THROW); CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ConditionalFormat[" + std::to_string(i) + "]", xSCENew->getStyleName(), xSCESet->getStyleName()); } propName = "ConditionalFormatLocal"; uno::Reference aConditionalFormatLocalGet; uno::Reference aConditionalFormatLocalSet; CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ConditionalFormatLocal", xSheetCellRanges->getPropertyValue(propName) >>= aConditionalFormatLocalGet); uno::Reference aConditionalFormatLocalNew( aConditionalFormatLocalGet, UNO_SET_THROW); aConditionalFormatLocalNew->addNew(aPropValue); aNewValue <<= aConditionalFormatLocalNew; xSheetCellRanges->setPropertyValue(propName, aNewValue); CPPUNIT_ASSERT(xSheetCellRanges->getPropertyValue(propName) >>= aConditionalFormatLocalSet); for (auto i = 0; i < aConditionalFormatLocalSet->getCount(); i++) { uno::Reference xSCENew( aConditionalFormatLocalNew->getByIndex(i), UNO_QUERY_THROW); uno::Reference xSCESet( aConditionalFormatLocalSet->getByIndex(i), UNO_QUERY_THROW); CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ConditionalFormatLocal[" + std::to_string(i) + "]", xSCENew->getStyleName(), xSCESet->getStyleName()); } propName = "Validation"; uno::Reference aValidationGet; uno::Reference aValidationSet; CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Validation", xSheetCellRanges->getPropertyValue(propName) >>= aValidationGet); uno::Reference aValidationNew(aValidationGet, UNO_SET_THROW); uno::Any aValidationType; aValidationType <<= sheet::ValidationType_WHOLE; aValidationNew->setPropertyValue(u"Type"_ustr, aValidationType); aNewValue <<= aValidationNew; xSheetCellRanges->setPropertyValue(propName, aNewValue); CPPUNIT_ASSERT(xSheetCellRanges->getPropertyValue(propName) >>= aValidationSet); sheet::ValidationType aType; aValidationSet->getPropertyValue(u"Type"_ustr) >>= aType; CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue Validation", sheet::ValidationType_WHOLE, aType); propName = "ValidationLocal"; uno::Reference aValidationLocalGet; uno::Reference aValidationLocalSet; CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ValidationLocal", xSheetCellRanges->getPropertyValue(propName) >>= aValidationLocalGet); uno::Reference aValidationLocalNew(aValidationLocalGet, UNO_SET_THROW); aValidationType <<= sheet::ValidationType_WHOLE; aValidationLocalNew->setPropertyValue(u"Type"_ustr, aValidationType); aNewValue <<= aValidationLocalNew; xSheetCellRanges->setPropertyValue(propName, aNewValue); CPPUNIT_ASSERT(xSheetCellRanges->getPropertyValue(propName) >>= aValidationLocalSet); aValidationLocalSet->getPropertyValue(u"Type"_ustr) >>= aType; CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ValidationLocal", sheet::ValidationType_WHOLE, aType); propName = "AbsoluteName"; OUString aAbsoluteNameGet = u""_ustr; CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue AbsoluteName", xSheetCellRanges->getPropertyValue(propName) >>= aAbsoluteNameGet); OUString aAbsoluteNameSet = u"$Sheet1.$C$3"_ustr; aNewValue <<= aAbsoluteNameSet; xSheetCellRanges->setPropertyValue(propName, aNewValue); CPPUNIT_ASSERT(xSheetCellRanges->getPropertyValue(propName) >>= aAbsoluteNameSet); CPPUNIT_ASSERT_EQUAL_MESSAGE("Able to set PropertyValue AbsoluteName", aAbsoluteNameGet, aAbsoluteNameSet); } } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */