diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /test/source | |
parent | Initial commit. (diff) | |
download | libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/source')
177 files changed, 15440 insertions, 0 deletions
diff --git a/test/source/beans/xpropertyset.cxx b/test/source/beans/xpropertyset.cxx new file mode 100644 index 000000000..00c337810 --- /dev/null +++ b/test/source/beans/xpropertyset.cxx @@ -0,0 +1,338 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/beans/xpropertyset.hxx> + +#include <com/sun/star/beans/Property.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/beans/PropertyChangeEvent.hpp> +#include <com/sun/star/beans/XPropertyChangeListener.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XVetoableChangeListener.hpp> +#include <com/sun/star/lang/EventObject.hpp> +#include <com/sun/star/util/DateTime.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Type.h> + +#include <cppuhelper/implbase.hxx> +#include <rtl/ref.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +XPropertySet::PropsToTest::PropsToTest() + : initialized(false) +{ +} + +namespace +{ +class MockedPropertyChangeListener : public ::cppu::WeakImplHelper<beans::XPropertyChangeListener> +{ +public: + MockedPropertyChangeListener() + : m_bListenerCalled(false) + { + } + + bool m_bListenerCalled; + + virtual void SAL_CALL propertyChange(const beans::PropertyChangeEvent& /* xEvent */) override + { + m_bListenerCalled = true; + } + + virtual void SAL_CALL disposing(const lang::EventObject& /* xEventObj */) override {} +}; + +class MockedVetoableChangeListener : public ::cppu::WeakImplHelper<beans::XVetoableChangeListener> +{ +public: + MockedVetoableChangeListener() + : m_bListenerCalled(false) + { + } + + bool m_bListenerCalled; + + virtual void SAL_CALL vetoableChange(const beans::PropertyChangeEvent& /* xEvent */) override + { + m_bListenerCalled = true; + } + + virtual void SAL_CALL disposing(const lang::EventObject& /* xEventObj */) override {} +}; +} + +void XPropertySet::testPropertyChangeListener() +{ + uno::Reference<beans::XPropertySet> xPropSet(init(), uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySetInfo> xPropInfo = xPropSet->getPropertySetInfo(); + fillPropsToTest(xPropInfo); + + for (const auto& aName : maPropsToTest.bound) + { + rtl::Reference<MockedPropertyChangeListener> xListener = new MockedPropertyChangeListener(); + xPropSet->addPropertyChangeListener( + aName, uno::Reference<beans::XPropertyChangeListener>(xListener)); + if (!isPropertyValueChangeable(aName)) + continue; + + CPPUNIT_ASSERT(xListener->m_bListenerCalled); + + xListener->m_bListenerCalled = false; + xPropSet->removePropertyChangeListener( + aName, uno::Reference<beans::XPropertyChangeListener>(xListener)); + isPropertyValueChangeable(aName); + CPPUNIT_ASSERT(!xListener->m_bListenerCalled); + } +} + +void XPropertySet::testVetoableChangeListener() +{ + uno::Reference<beans::XPropertySet> xPropSet(init(), uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySetInfo> xPropInfo = xPropSet->getPropertySetInfo(); + fillPropsToTest(xPropInfo); + + for (const auto& aName : maPropsToTest.bound) + { + rtl::Reference<MockedVetoableChangeListener> xListener = new MockedVetoableChangeListener(); + xPropSet->addVetoableChangeListener( + aName, uno::Reference<beans::XVetoableChangeListener>(xListener)); + if (!isPropertyValueChangeable(aName)) + continue; + + CPPUNIT_ASSERT(xListener->m_bListenerCalled); + + xListener->m_bListenerCalled = false; + xPropSet->removeVetoableChangeListener( + aName, uno::Reference<beans::XVetoableChangeListener>(xListener)); + isPropertyValueChangeable(aName); + CPPUNIT_ASSERT(!xListener->m_bListenerCalled); + } +} + +void XPropertySet::testGetPropertySetInfo() +{ + uno::Reference<beans::XPropertySet> xPropSet(init(), UNO_QUERY_THROW); + uno::Reference<beans::XPropertySetInfo> xPropInfo = xPropSet->getPropertySetInfo(); + if (xPropInfo.is()) + { + fillPropsToTest(xPropInfo); + } + else + { + // TODO: Add a means for the client code to populate the PropsToTest. + } +} + +void XPropertySet::testSetPropertyValue() +{ + testGetPropertySetInfo(); + + for (size_t i = 0, n = maPropsToTest.normal.size(); i < n; ++i) + { + bool bSuccess = isPropertyValueChangeable(maPropsToTest.normal[i]); + CPPUNIT_ASSERT(bSuccess); + } +} + +void XPropertySet::testGetPropertyValue() +{ + testGetPropertySetInfo(); + uno::Reference<beans::XPropertySet> xPropSet(init(), UNO_QUERY_THROW); + + // Check read-only properties. + for (size_t i = 0, n = maPropsToTest.readonly.size(); i < n; ++i) + { + bool bSuccess = getSinglePropertyValue(xPropSet, maPropsToTest.readonly[i]); + CPPUNIT_ASSERT(bSuccess); + } + + // Check writable properties. + for (size_t i = 0, n = maPropsToTest.normal.size(); i < n; ++i) + { + bool bSuccess = getSinglePropertyValue(xPropSet, maPropsToTest.normal[i]); + CPPUNIT_ASSERT(bSuccess); + } +} + +bool XPropertySet::isPropertyValueChangeable(const OUString& rName) +{ + bool bIgnore = isPropertyIgnored(rName); + if (bIgnore) + return false; + + uno::Reference<beans::XPropertySet> xPropSet(init(), UNO_QUERY_THROW); + try + { + uno::Any any = xPropSet->getPropertyValue(rName); + const uno::Type& type = any.getValueType(); + if (type == cppu::UnoType<bool>::get()) + { + // boolean type + bool bOld = any.get<bool>(); + xPropSet->setPropertyValue(rName, Any(!bOld)); + } + else if (type == cppu::UnoType<sal_Int8>::get()) + { + // 8-bit integer + sal_Int8 nOld = any.get<sal_Int8>(); + sal_Int8 nNew = nOld + 1; + xPropSet->setPropertyValue(rName, Any(nNew)); + } + else if (type == cppu::UnoType<sal_Int16>::get()) + { + // 16-bit integer + sal_Int16 nOld = any.get<sal_Int16>(); + sal_Int16 nNew = nOld + 1; + xPropSet->setPropertyValue(rName, Any(nNew)); + } + else if (type == cppu::UnoType<sal_Int32>::get()) + { + // 32-bit integer + sal_Int32 nOld = any.get<sal_Int32>(); + sal_Int32 nNew = nOld + 3; + xPropSet->setPropertyValue(rName, Any(nNew)); + } + else if (type == cppu::UnoType<sal_Int64>::get()) + { + // 64-bit integer + sal_Int64 nOld = any.get<sal_Int64>(); + sal_Int64 nNew = nOld + 4; + xPropSet->setPropertyValue(rName, Any(nNew)); + } + else if (type == cppu::UnoType<float>::get()) + { + // single precision + float fOld = any.get<float>(); + float fNew = fOld + 1.2; + xPropSet->setPropertyValue(rName, Any(fNew)); + } + else if (type == cppu::UnoType<double>::get()) + { + // double precision + double fOld = any.get<double>(); + double fNew = fOld + 1.3; + xPropSet->setPropertyValue(rName, Any(fNew)); + } + else if (type == cppu::UnoType<OUString>::get()) + { + // string type + OUString aOld = any.get<OUString>(); + OUString aNew = aOld + "foo"; + xPropSet->setPropertyValue(rName, Any(aNew)); + } + else if (type == cppu::UnoType<util::DateTime>::get()) + { + // date time type + util::DateTime aDT = any.get<util::DateTime>(); + aDT.Year += 1; + xPropSet->setPropertyValue(rName, Any(aDT)); + } + else + { + std::cout << "Unknown type:\n" + "Type: " + << type.getTypeName() + << "\n" + "Name: " + << rName << "\n"; + CPPUNIT_ASSERT_MESSAGE( + "XPropertySet::isPropertyValueChangeable: unknown type in Any tested.", false); + } + + uno::Any anyTest = xPropSet->getPropertyValue(rName); + return any != anyTest; + } + catch (const uno::Exception&) + { + std::cout << "Exception thrown while retrieving with property: " << rName << "\n"; + CPPUNIT_ASSERT_MESSAGE("XPropertySet::isPropertyValueChangeable: exception thrown while " + "retrieving the property value.", + false); + } + + return false; +} + +void XPropertySet::fillPropsToTest(const uno::Reference<beans::XPropertySetInfo>& xPropInfo) +{ + if (maPropsToTest.initialized) + return; + + const uno::Sequence<beans::Property> aProps = xPropInfo->getProperties(); + + // some properties should not be changed in a unspecific way. + // TODO: Maybe we should mark these properties read-only, instead of + // giving them a special treatment here? + std::set<OUString> aSkip; + aSkip.insert("PrinterName"); + aSkip.insert("CharRelief"); + aSkip.insert("IsLayerMode"); + + for (const beans::Property& aProp : aProps) + { + if (aSkip.count(aProp.Name) > 0) + continue; + + if ((aProp.Attributes & beans::PropertyAttribute::READONLY) != 0) + { + maPropsToTest.readonly.push_back(aProp.Name); + continue; + } + + if ((aProp.Attributes & beans::PropertyAttribute::MAYBEVOID) != 0) + continue; + + bool bBound = (aProp.Attributes & beans::PropertyAttribute::BOUND) != 0; + bool bConstrained = (aProp.Attributes & beans::PropertyAttribute::CONSTRAINED) != 0; + bool bCanChange = isPropertyValueChangeable(aProp.Name); + + if (bBound && bCanChange) + maPropsToTest.bound.push_back(aProp.Name); + + if (bConstrained && bCanChange) + maPropsToTest.constrained.push_back(aProp.Name); + + if (bCanChange) + maPropsToTest.normal.push_back(aProp.Name); + } + + maPropsToTest.initialized = true; +} + +bool XPropertySet::getSinglePropertyValue(const uno::Reference<beans::XPropertySet>& xPropSet, + const OUString& rName) +{ + try + { + xPropSet->getPropertyValue(rName); + return true; + } + catch (const uno::Exception&) + { + } + return false; +} + +bool XPropertySet::isPropertyIgnored(const OUString& rName) +{ + return m_IgnoreValue.count(rName) > 0; +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/bootstrapfixture.cxx b/test/source/bootstrapfixture.cxx new file mode 100644 index 000000000..d9048b394 --- /dev/null +++ b/test/source/bootstrapfixture.cxx @@ -0,0 +1,281 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <config_validation.h> + +#include <test/bootstrapfixture.hxx> +#include <vcl/errinf.hxx> +#include <sal/log.hxx> +#include <comphelper/processfactory.hxx> + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/ucb/XContentProvider.hpp> +#include <com/sun/star/ucb/XUniversalContentBroker.hpp> + +#include <vcl/outdev.hxx> +#include <vcl/svapp.hxx> +#include <tools/link.hxx> +#include <vcl/graphicfilter.hxx> +#include <osl/file.hxx> +#include <osl/process.h> +#include <unotest/getargument.hxx> +#include <unotools/tempfile.hxx> +#include <vcl/salgtype.hxx> +#include <vcl/scheduler.hxx> +#include <vcl/virdev.hxx> +#include <o3tl/string_view.hxx> + +#include <memory> +#include <cstring> + +#include "setupvcl.hxx" + +using namespace ::com::sun::star; + +static void aBasicErrorFunc( const OUString &rErr, const OUString &rAction ) +{ + OString aErr = "Unexpected dialog: " + + OUStringToOString( rAction, RTL_TEXTENCODING_ASCII_US ) + + " Error: " + + OUStringToOString( rErr, RTL_TEXTENCODING_ASCII_US ); + CPPUNIT_ASSERT_MESSAGE( aErr.getStr(), false); +} + +// NB. this constructor is called before any tests are run, once for each +// test function in a rather non-intuitive way. This is why all the 'real' +// heavy lifting is deferred until setUp. setUp and tearDown are interleaved +// between the tests as you might expect. +test::BootstrapFixture::BootstrapFixture( bool bAssertOnDialog, bool bNeedUCB ) + : m_bNeedUCB( bNeedUCB ) + , m_bAssertOnDialog( bAssertOnDialog ) +{ +} + +extern "C" +{ + +static void test_init_impl(bool bAssertOnDialog, bool bNeedUCB, + lang::XMultiServiceFactory * pSFactory) +{ + if (bAssertOnDialog) + ErrorRegistry::RegisterDisplay( aBasicErrorFunc ); + + // Make GraphicConverter work, normally done in desktop::Desktop::Main() + Application::SetFilterHdl( + LINK(nullptr, test::BootstrapFixture, ImplInitFilterHdl)); + + if (bNeedUCB) + { + // initialise unconfigured UCB: + uno::Reference<ucb::XUniversalContentBroker> xUcb(pSFactory->createInstance("com.sun.star.ucb.UniversalContentBroker"), uno::UNO_QUERY_THROW); + uno::Reference<ucb::XContentProvider> xFileProvider(pSFactory->createInstance("com.sun.star.ucb.FileContentProvider"), uno::UNO_QUERY_THROW); + xUcb->registerContentProvider(xFileProvider, "file", true); + uno::Reference<ucb::XContentProvider> xTdocProvider(pSFactory->createInstance("com.sun.star.ucb.TransientDocumentsContentProvider"), uno::UNO_QUERY); + if (xTdocProvider.is()) + { + xUcb->registerContentProvider(xTdocProvider, "vnd.sun.star.tdoc", true); + } + } +} + +// this is called from pyuno +SAL_DLLPUBLIC_EXPORT void test_init(lang::XMultiServiceFactory *pFactory) +{ + try + { + ::comphelper::setProcessServiceFactory(pFactory); + test::setUpVcl(true); // hard-code python tests to headless + test_init_impl(false, true, pFactory); + } + catch (...) { abort(); } +} + +// this is called from pyuno +SAL_DLLPUBLIC_EXPORT void test_deinit() +{ + DeInitVCL(); +} + +} // extern "C" + +void test::BootstrapFixture::setUp() +{ + test::BootstrapFixtureBase::setUp(); + + test_init_impl(m_bAssertOnDialog, m_bNeedUCB, m_xSFactory.get()); + +#if OSL_DEBUG_LEVEL > 0 + Scheduler::ProcessEventsToIdle(); +#endif + + mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory())); +} + +test::BootstrapFixture::~BootstrapFixture() +{ +} + +#if HAVE_EXPORT_VALIDATION +namespace { + +OString loadFile(const OUString& rURL) +{ + osl::File aFile(rURL); + osl::FileBase::RC eStatus = aFile.open(osl_File_OpenFlag_Read); + CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, eStatus); + sal_uInt64 nSize; + aFile.getSize(nSize); + std::unique_ptr<char[]> aBytes(new char[nSize]); + sal_uInt64 nBytesRead; + aFile.read(aBytes.get(), nSize, nBytesRead); + CPPUNIT_ASSERT_EQUAL(nSize, nBytesRead); + OString aContent(aBytes.get(), nBytesRead); + + return aContent; +} + +} +#endif + +void test::BootstrapFixture::validate(const OUString& rPath, test::ValidationFormat eFormat) const +{ +#if HAVE_EXPORT_VALIDATION + OUString var; + if( eFormat == test::OOXML ) + { + var = "OFFICEOTRON"; + } + else if ( eFormat == test::ODF ) + { + var = "ODFVALIDATOR"; + } + else if ( eFormat == test::MSBINARY ) + { +#if HAVE_BFFVALIDATOR + var = "BFFVALIDATOR"; +#else + // Binary Format Validator is disabled + return; +#endif + } + OUString aValidator; + oslProcessError e = osl_getEnvironment(var.pData, &aValidator.pData); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + OUString("cannot get env var " + var).toUtf8().getStr(), + osl_Process_E_None, e); + CPPUNIT_ASSERT_MESSAGE( + OUString("empty get env var " + var).toUtf8().getStr(), + !aValidator.isEmpty()); + + if (eFormat == test::ODF) + { + // invoke without -e so that we know when something new is written + // in loext namespace that isn't yet in the custom schema + aValidator += " -M " + + m_directories.getPathFromSrc(u"/schema/libreoffice/OpenDocument-v1.3+libreoffice-manifest-schema.rng") + + " -D " + + m_directories.getPathFromSrc(u"/schema/libreoffice/OpenDocument-v1.3+libreoffice-dsig-schema.rng") + + " -O " + + m_directories.getPathFromSrc(u"/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng") + + " -m " + + m_directories.getPathFromSrc(u"/schema/mathml2/mathml2.xsd"); + } + + utl::TempFile aOutput; + aOutput.EnableKillingFile(); + OUString aOutputFile = aOutput.GetFileName(); + OUString aCommand = aValidator + " " + rPath + " > " + aOutputFile + " 2>&1"; + +#if !defined _WIN32 + // For now, this is only needed by some Linux ASan builds, so keep it simply and disable it on + // Windows (which doesn't support the relevant shell syntax for (un-)setting environment + // variables). + OUString env; + if (test::getArgument(u"env", &env)) { + auto const n = env.indexOf('='); + if (n == -1) { + aCommand = "unset -v " + env + " && " + aCommand; + } else { + aCommand = env + " " + aCommand; + } + } +#endif + + SAL_INFO("test", "BootstrapFixture::validate: executing '" << aCommand << "'"); + int returnValue = system(OUStringToOString(aCommand, RTL_TEXTENCODING_UTF8).getStr()); + + OString aContentString = loadFile(aOutput.GetURL()); + OUString aContentOUString = OStringToOUString(aContentString, RTL_TEXTENCODING_UTF8); + + if( eFormat == test::OOXML && !aContentOUString.isEmpty() ) + { + // check for validation errors here + sal_Int32 nIndex = aContentOUString.lastIndexOf("Grand total of errors in submitted package: "); + if(nIndex == -1) + { + SAL_WARN("test", "no summary line"); + } + else + { + sal_Int32 nStartOfNumber = nIndex + std::strlen("Grand total of errors in submitted package: "); + std::u16string_view aNumber = aContentOUString.subView(nStartOfNumber); + sal_Int32 nErrors = o3tl::toInt32(aNumber); + OString aMsg = "validation error in OOXML export: Errors: " + OString::number(nErrors); + if(nErrors) + { + SAL_WARN("test", aContentOUString); + } + CPPUNIT_ASSERT_EQUAL_MESSAGE(aMsg.getStr(), sal_Int32(0), nErrors); + } + } + else if( eFormat == test::ODF && !aContentOUString.isEmpty() ) + { + if( aContentOUString.indexOf("Error") != -1 ) + { + SAL_WARN("test", aContentOUString); + CPPUNIT_FAIL(aContentString.getStr()); + } + } + CPPUNIT_ASSERT_EQUAL_MESSAGE( + OString( + "failed to execute: " + OUStringToOString(aCommand, RTL_TEXTENCODING_UTF8) + "\n" + + OUStringToOString(aContentOUString, RTL_TEXTENCODING_UTF8)).getStr(), + 0, returnValue); +#else + (void)rPath; + (void)eFormat; +#endif +} + +IMPL_STATIC_LINK( + test::BootstrapFixture, ImplInitFilterHdl, ConvertData&, rData, bool) +{ + return GraphicFilter::GetGraphicFilter().GetFilterCallback().Call( rData ); +} + +bool test::BootstrapFixture::IsDefaultDPI() +{ + return (Application::GetDefaultDevice()->GetDPIX() == 96 + && Application::GetDefaultDevice()->GetDPIY() == 96); +} + +std::pair<double, double> test::BootstrapFixture::getDPIScaling() +{ + return { Application::GetDefaultDevice()->GetDPIX() / 96.0, + Application::GetDefaultDevice()->GetDPIY() / 96.0 }; +} + +sal_uInt16 test::BootstrapFixture::getDefaultDeviceBitCount() +{ + ScopedVclPtr<VirtualDevice> device + = VclPtr<VirtualDevice>::Create(DeviceFormat::DEFAULT); + return device->GetBitCount(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/calc_unoapi_test.cxx b/test/source/calc_unoapi_test.cxx new file mode 100644 index 000000000..8d7e218d9 --- /dev/null +++ b/test/source/calc_unoapi_test.cxx @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/calc_unoapi_test.hxx> + +using namespace css; +using namespace css::uno; + +CalcUnoApiTest::CalcUnoApiTest(const OUString& path) + : UnoApiTest(path) +{ +} + +void CalcUnoApiTest::setUp() +{ + UnoApiTest::setUp(); + + // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure, + // which is a private symbol to us, gets called + m_xCalcComponent = + getMultiServiceFactory()->createInstance("com.sun.star.comp.Calc.SpreadsheetDocument"); + CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xCalcComponent.is()); +} + +void CalcUnoApiTest::tearDown() +{ + uno::Reference< lang::XComponent >( m_xCalcComponent, UNO_QUERY_THROW )->dispose(); + UnoApiTest::tearDown(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/callgrind.cxx b/test/source/callgrind.cxx new file mode 100644 index 000000000..d5e864aa8 --- /dev/null +++ b/test/source/callgrind.cxx @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/callgrind.hxx> + +#ifdef HAVE_VALGRIND_HEADERS +#include <valgrind/callgrind.h> +#else +#define CALLGRIND_START_INSTRUMENTATION +#define CALLGRIND_ZERO_STATS +#define CALLGRIND_STOP_INSTRUMENTATION +#define CALLGRIND_DUMP_STATS_AT(name) (void)name; +#endif + +void callgrindStart() +{ + CALLGRIND_ZERO_STATS; + CALLGRIND_START_INSTRUMENTATION; +}; + +void callgrindDump(const char* name) +{ + CALLGRIND_STOP_INSTRUMENTATION; + CALLGRIND_DUMP_STATS_AT(name); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/chart/xchartdata.cxx b/test/source/chart/xchartdata.cxx new file mode 100644 index 000000000..5d0dcb48f --- /dev/null +++ b/test/source/chart/xchartdata.cxx @@ -0,0 +1,97 @@ +/* -*- 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 <test/chart/xchartdata.hxx> +#include <cppuhelper/implbase.hxx> +#include <rtl/ref.hxx> + +#include <com/sun/star/chart/ChartDataChangeEvent.hpp> +#include <com/sun/star/chart/XChartData.hpp> +#include <com/sun/star/chart/XChartDataArray.hpp> +#include <com/sun/star/chart/XChartDataChangeEventListener.hpp> +#include <com/sun/star/lang/EventObject.hpp> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +namespace +{ +class MockedChartDataChangeEventListener + : public ::cppu::WeakImplHelper<chart::XChartDataChangeEventListener> +{ +public: + MockedChartDataChangeEventListener() + : m_bListenerCalled(false) + { + } + + bool m_bListenerCalled; + virtual void SAL_CALL chartDataChanged(const chart::ChartDataChangeEvent& /* rEvent */) override + { + m_bListenerCalled = true; + } + + virtual void SAL_CALL disposing(const lang::EventObject& /* xEvent */) override {} +}; +} + +void XChartData::testGetNotANumber() +{ + uno::Reference<chart::XChartData> xCD(init(), uno::UNO_QUERY_THROW); + const double fNaN = xCD->getNotANumber(); + + CPPUNIT_ASSERT(fNaN != 1.0); +} + +void XChartData::testIsNotANumber() +{ + uno::Reference<chart::XChartData> xCD(init(), uno::UNO_QUERY_THROW); + const double fNaN = xCD->getNotANumber(); + CPPUNIT_ASSERT(xCD->isNotANumber(fNaN)); + CPPUNIT_ASSERT(!xCD->isNotANumber(fNaN + 1.0)); +} + +void XChartData::testChartDataChangeEventListener() +{ + uno::Reference<chart::XChartData> xCD(init(), uno::UNO_QUERY_THROW); + + rtl::Reference<MockedChartDataChangeEventListener> pListener0 + = new MockedChartDataChangeEventListener(); + xCD->addChartDataChangeEventListener( + uno::Reference<chart::XChartDataChangeEventListener>(pListener0)); + rtl::Reference<MockedChartDataChangeEventListener> pListener1 + = new MockedChartDataChangeEventListener(); + xCD->addChartDataChangeEventListener( + uno::Reference<chart::XChartDataChangeEventListener>(pListener1)); + + uno::Reference<chart::XChartDataArray> xCDD(xCD, uno::UNO_QUERY_THROW); + uno::Sequence<uno::Sequence<double>> aData = xCDD->getData(); + auto& rFirstCell = aData.getArray()[0].getArray()[0]; + rFirstCell += 1.0; + xCDD->setData(aData); + CPPUNIT_ASSERT(pListener0->m_bListenerCalled); + CPPUNIT_ASSERT(pListener1->m_bListenerCalled); + + pListener0->m_bListenerCalled = false; + pListener1->m_bListenerCalled = false; + + xCD->removeChartDataChangeEventListener( + uno::Reference<chart::XChartDataChangeEventListener>(pListener1)); + rFirstCell += 1.0; + xCDD->setData(aData); + CPPUNIT_ASSERT(pListener0->m_bListenerCalled); + CPPUNIT_ASSERT(!pListener1->m_bListenerCalled); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/container/xchild.cxx b/test/source/container/xchild.cxx new file mode 100644 index 000000000..eac97b0eb --- /dev/null +++ b/test/source/container/xchild.cxx @@ -0,0 +1,38 @@ +/* -*- 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 <test/container/xchild.hxx> + +#include <com/sun/star/container/XChild.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XChild::testGetSetParent() +{ + uno::Reference<container::XChild> xChild(init(), UNO_QUERY_THROW); + uno::Reference<uno::XInterface> xInterface(xChild, UNO_QUERY_THROW); + xInterface = xChild->getParent(); + + CPPUNIT_ASSERT_MESSAGE("Successfully able to Get Parent", xInterface); + + xChild->setParent(xInterface); + + CPPUNIT_ASSERT_MESSAGE("Successfully able to Set Parent", xChild); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/container/xelementaccess.cxx b/test/source/container/xelementaccess.cxx new file mode 100644 index 000000000..4ec751520 --- /dev/null +++ b/test/source/container/xelementaccess.cxx @@ -0,0 +1,36 @@ +/* -*- 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 <test/container/xelementaccess.hxx> + +#include <com/sun/star/container/XElementAccess.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XElementAccess::testGetElementType() +{ + uno::Reference<container::XElementAccess> xElementAccess(init(), UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL(m_aType, xElementAccess->getElementType()); +} + +void XElementAccess::testHasElements() +{ + uno::Reference<container::XElementAccess> xElementAccess(init(), UNO_QUERY_THROW); + CPPUNIT_ASSERT(xElementAccess->hasElements()); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/container/xenumeration.cxx b/test/source/container/xenumeration.cxx new file mode 100644 index 000000000..190ef27fe --- /dev/null +++ b/test/source/container/xenumeration.cxx @@ -0,0 +1,43 @@ +/* -*- 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 <test/container/xenumeration.hxx> + +#include <com/sun/star/container/NoSuchElementException.hpp> +#include <com/sun/star/container/XEnumeration.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XEnumeration::testHasMoreElements() +{ + uno::Reference<container::XEnumeration> xEnumeration(init(), uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xEnumeration->hasMoreElements()); +} + +void XEnumeration::testNextElement() +{ + uno::Reference<container::XEnumeration> xEnumeration(init(), uno::UNO_QUERY_THROW); + + // unwind all elements from the enumeration + while (xEnumeration->hasMoreElements()) + CPPUNIT_ASSERT_NO_THROW(xEnumeration->nextElement()); + + CPPUNIT_ASSERT_THROW_MESSAGE("Incorrect exception", xEnumeration->nextElement(), + container::NoSuchElementException); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/container/xenumerationaccess.cxx b/test/source/container/xenumerationaccess.cxx new file mode 100644 index 000000000..e3c53064e --- /dev/null +++ b/test/source/container/xenumerationaccess.cxx @@ -0,0 +1,31 @@ +/* -*- 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 <test/container/xenumerationaccess.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XEnumerationAccess::testCreateEnumeration() +{ + uno::Reference<container::XEnumerationAccess> xEnumerationAccess(init(), UNO_QUERY_THROW); + + CPPUNIT_ASSERT_MESSAGE("Unable to create enumeration", xEnumerationAccess->createEnumeration()); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/container/xindexaccess.cxx b/test/source/container/xindexaccess.cxx new file mode 100644 index 000000000..7fc08027c --- /dev/null +++ b/test/source/container/xindexaccess.cxx @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/container/xindexaccess.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XIndexAccess::testGetCount() +{ + uno::Reference<container::XIndexAccess> xIndexAccess(init(), UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL(m_nItems, xIndexAccess->getCount()); +} + +void XIndexAccess::testGetByIndex() +{ + uno::Reference<container::XIndexAccess> xIndexAccess(init(), UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL(m_nItems, xIndexAccess->getCount()); + + if (m_nItems > 0) + { + Any aAny = xIndexAccess->getByIndex(0); + CPPUNIT_ASSERT(aAny.hasValue()); + + aAny = xIndexAccess->getByIndex(m_nItems / 2); + CPPUNIT_ASSERT(aAny.hasValue()); + + aAny = xIndexAccess->getByIndex(m_nItems - 1); + CPPUNIT_ASSERT(aAny.hasValue()); + } +} + +void XIndexAccess::testGetByIndexException() +{ + uno::Reference<container::XIndexAccess> xIndexAccess(init(), UNO_QUERY_THROW); + xIndexAccess->getByIndex(m_nItems); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/container/xnameaccess.cxx b/test/source/container/xnameaccess.cxx new file mode 100644 index 000000000..3616c4cda --- /dev/null +++ b/test/source/container/xnameaccess.cxx @@ -0,0 +1,55 @@ +/* -*- 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 <test/container/xnameaccess.hxx> + +#include <com/sun/star/container/NoSuchElementException.hpp> +#include <com/sun/star/container/XNameAccess.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XNameAccess::testGetByName() +{ + uno::Reference<container::XNameAccess> xNA(init(), uno::UNO_QUERY_THROW); + + // test with existing name + CPPUNIT_ASSERT_NO_THROW(xNA->getByName(m_aName)); + // test with non-existing name + CPPUNIT_ASSERT_THROW(xNA->getByName(m_aName + "UnitTest"), container::NoSuchElementException); +} + +void XNameAccess::testGetElementNames() +{ + uno::Reference<container::XNameAccess> xNA(init(), uno::UNO_QUERY_THROW); + uno::Sequence<OUString> aNames = xNA->getElementNames(); + + CPPUNIT_ASSERT(aNames.hasElements()); +} + +void XNameAccess::testHasByName() +{ + uno::Reference<container::XNameAccess> xNA(init(), uno::UNO_QUERY_THROW); + + // test with existing name + CPPUNIT_ASSERT(xNA->hasByName(m_aName)); + // test with non-existing name + CPPUNIT_ASSERT(!xNA->hasByName(m_aName + "UnitTest")); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/container/xnamecontainer.cxx b/test/source/container/xnamecontainer.cxx new file mode 100644 index 000000000..5df1e76b3 --- /dev/null +++ b/test/source/container/xnamecontainer.cxx @@ -0,0 +1,101 @@ +/* -*- 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 <test/container/xnamecontainer.hxx> + +#include <com/sun/star/container/ElementExistException.hpp> +#include <com/sun/star/container/NoSuchElementException.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/lang/IllegalArgumentException.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void XNameContainer::testInsertByName() +{ + uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW); + + CPPUNIT_ASSERT(!xNameContainer->hasByName(m_aName + "Insert")); + xNameContainer->insertByName(m_aName + "Insert", m_aElement); + CPPUNIT_ASSERT(xNameContainer->hasByName(m_aName + "Insert")); +} + +void XNameContainer::testInsertByNameEmptyName() +{ + uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW); + + uno::Any aAny; + CPPUNIT_ASSERT_THROW(xNameContainer->insertByName("", aAny), lang::IllegalArgumentException); +} + +void XNameContainer::testInsertByNameInvalidElement() +{ + uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW); + + // TODO: Find a way to create an invalid element. + // CPPUNIT_ASSERT_THROW(xNameContainer->insertByName("Dummy", nullptr), + // lang::IllegalArgumentException); +} + +void XNameContainer::testInsertByNameDuplicate() +{ + uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW); + + CPPUNIT_ASSERT(!xNameContainer->hasByName(m_aName + "Duplicate")); + xNameContainer->insertByName(m_aName + "Duplicate", m_aElement); + CPPUNIT_ASSERT(xNameContainer->hasByName(m_aName + "Duplicate")); + + bool bExceptionThrown = false; + try + { + xNameContainer->insertByName(m_aName + "Duplicate", m_aElement); + } + catch (const container::ElementExistException&) + { + bExceptionThrown = true; + } + catch (const lang::IllegalArgumentException&) + { + bExceptionThrown = true; + } + CPPUNIT_ASSERT(bExceptionThrown); +} + +void XNameContainer::testRemoveByName() +{ + uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xNameContainer->hasByName(m_aName)); + xNameContainer->removeByName(m_aName); + CPPUNIT_ASSERT(!xNameContainer->hasByName(m_aName)); +} + +void XNameContainer::testRemoveByNameEmptyName() +{ + uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW); + + CPPUNIT_ASSERT_THROW(xNameContainer->removeByName(""), lang::IllegalArgumentException); +} + +void XNameContainer::testRemoveByNameNoneExistingElement() +{ + uno::Reference<container::XNameContainer> xNameContainer(init(), uno::UNO_QUERY_THROW); + + CPPUNIT_ASSERT_THROW(xNameContainer->removeByName("UnitTest"), + container::NoSuchElementException); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/container/xnamed.cxx b/test/source/container/xnamed.cxx new file mode 100644 index 000000000..000a9f62e --- /dev/null +++ b/test/source/container/xnamed.cxx @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/container/xnamed.hxx> +#include <rtl/ustring.hxx> + +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/uno/RuntimeException.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XNamed::testGetName() +{ + uno::Reference<container::XNamed> xNamed(init(), UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL(m_aTestName, xNamed->getName()); +} + +void XNamed::testSetName() +{ + uno::Reference<container::XNamed> xNamed(init(), UNO_QUERY_THROW); + OUString aTestName("NewName"); + + xNamed->setName(aTestName); + CPPUNIT_ASSERT_EQUAL(aTestName, xNamed->getName()); + + // restore old name + xNamed->setName(m_aTestName); + CPPUNIT_ASSERT_EQUAL(m_aTestName, xNamed->getName()); +} + +void XNamed::testSetNameByScSheetLinkObj() +{ + uno::Reference<container::XNamed> xNamed(init(), uno::UNO_QUERY_THROW); + OUString aTestName(m_aTestName.replaceAll("ScSheetLinkObj", "NewScSheetLinkObj")); + + xNamed->setName(aTestName); + CPPUNIT_ASSERT_EQUAL(aTestName, xNamed->getName()); + + // restore old name + xNamed->setName(m_aTestName); + CPPUNIT_ASSERT_EQUAL(m_aTestName, xNamed->getName()); +} + +void XNamed::testSetNameThrowsException() +{ + uno::Reference<container::XNamed> xNamed(init(), uno::UNO_QUERY_THROW); + + CPPUNIT_ASSERT_THROW(xNamed->setName("NewName"), uno::RuntimeException); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/container/xnamereplace.cxx b/test/source/container/xnamereplace.cxx new file mode 100644 index 000000000..2475cb5a0 --- /dev/null +++ b/test/source/container/xnamereplace.cxx @@ -0,0 +1,37 @@ +/* -*- 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 <test/container/xnamereplace.hxx> + +#include <com/sun/star/container/XNameReplace.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void XNameReplace::testReplaceByName() +{ + uno::Reference<container::XNameReplace> xNameReplace(init(), uno::UNO_QUERY_THROW); + + CPPUNIT_ASSERT_NO_THROW(xNameReplace->replaceByName(m_aReplacementName, m_aReplacementElement)); + uno::Any aAny = xNameReplace->getByName(m_aReplacementName); + + // we deliberately avoid uno::UNO_QUERY_THROW, so a test on .is() can be made + uno::Reference<uno::XInterface> xElement(aAny, uno::UNO_QUERY); + CPPUNIT_ASSERT(xElement.is()); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/diff/README b/test/source/diff/README new file mode 100644 index 000000000..2ed65928d --- /dev/null +++ b/test/source/diff/README @@ -0,0 +1,5 @@ +This xml diff is an adapted version of the version at git://people.freedesktop.org/~mmohrhard/xmldiff. +Please write a mail to <markus.mohrhard@googlemail.com> after modifying this version with a patch otherwise it +might get overridden when updating the version in the source tree. + +!This xml diff is still experimental! diff --git a/test/source/diff/diff.cxx b/test/source/diff/diff.cxx new file mode 100644 index 000000000..097452665 --- /dev/null +++ b/test/source/diff/diff.cxx @@ -0,0 +1,416 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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/. + */ + +#define USE_CPPUNIT 1 + +#include <test/xmldiff.hxx> + +#include <libxml/xpath.h> +#include <libxml/parser.h> + +#include <set> +#include <sstream> +#include <cassert> +#include <cmath> +#include <vector> + +#if USE_CPPUNIT +#include <cppunit/TestAssert.h> +#endif + +namespace { + +struct tolerance +{ + ~tolerance() + { + xmlFree(elementName); + xmlFree(attribName); + } + + tolerance() + : elementName(nullptr) + , attribName(nullptr) + , relative(false) + , value(0.0) + { + } + + tolerance(const tolerance& tol) + { + elementName = xmlStrdup(tol.elementName); + attribName = xmlStrdup(tol.attribName); + relative = tol.relative; + value = tol.value; + } + + xmlChar* elementName; + xmlChar* attribName; + bool relative; + double value; + bool operator<(const tolerance& rTol) const + { + int cmp = xmlStrcmp(elementName, rTol.elementName); + if(cmp == 0) + { + cmp = xmlStrcmp(attribName, rTol.attribName); + } + + return cmp < 0; + } +}; + +class XMLDiff +{ +public: + XMLDiff(const char* pFileName, const char* pContent, int size, const char* pToleranceFileName); + ~XMLDiff(); + + bool compare(); +private: + typedef std::set<tolerance> ToleranceContainer; + + void loadToleranceFile(xmlDocPtr xmlTolerance); + bool compareAttributes(xmlNodePtr node1, xmlNodePtr node2); + bool compareElements(xmlNode* node1, xmlNode* node2); + + /// Error message for cppunit that prints out when expected and found are not equal. + void cppunitAssertEqual(const xmlChar *expected, const xmlChar *found); + + /// Error message for cppunit that prints out when expected and found are not equal - for doubles. + void cppunitAssertEqualDouble(const xmlNodePtr node, const xmlAttrPtr attr, double expected, double found, double delta); + + ToleranceContainer toleranceContainer; + xmlDocPtr xmlFile1; + xmlDocPtr xmlFile2; + std::string fileName; +}; + +} + +XMLDiff::XMLDiff( const char* pFileName, const char* pContent, int size, const char* pToleranceFile) + : xmlFile1(xmlParseFile(pFileName)) + , xmlFile2(xmlParseMemory(pContent, size)) + , fileName(pFileName) +{ + if(pToleranceFile) + { + xmlDocPtr xmlToleranceFile = xmlParseFile(pToleranceFile); + loadToleranceFile(xmlToleranceFile); + xmlFreeDoc(xmlToleranceFile); + } +} + +XMLDiff::~XMLDiff() +{ + xmlFreeDoc(xmlFile1); + xmlFreeDoc(xmlFile2); +} + +namespace { + +void readAttributesForTolerance(xmlNodePtr node, tolerance& tol) +{ + xmlChar* elementName = xmlGetProp(node, BAD_CAST("elementName")); + tol.elementName = elementName; + + xmlChar* attribName = xmlGetProp(node, BAD_CAST("attribName")); + tol.attribName = attribName; + + xmlChar* value = xmlGetProp(node, BAD_CAST("value")); + double val = xmlXPathCastStringToNumber(value); + xmlFree(value); + tol.value = val; + + xmlChar* relative = xmlGetProp(node, BAD_CAST("relative")); + bool rel = false; + if(xmlStrEqual(relative, BAD_CAST("true"))) + rel = true; + xmlFree(relative); + tol.relative = rel; +} + +} + +void XMLDiff::loadToleranceFile(xmlDocPtr xmlToleranceFile) +{ + xmlNodePtr root = xmlDocGetRootElement(xmlToleranceFile); +#if USE_CPPUNIT + CPPUNIT_ASSERT_MESSAGE("did not find correct tolerance file", xmlStrEqual( root->name, BAD_CAST("tolerances") )); +#else + if(!xmlStrEqual( root->name, BAD_CAST("tolerances") )) + { + assert(false); + return; + } +#endif + xmlNodePtr child = nullptr; + for (child = root->children; child != nullptr; child = child->next) + { + // assume a valid xml file + if(child->type != XML_ELEMENT_NODE) + continue; + + assert(xmlStrEqual(child->name, BAD_CAST("tolerance"))); + + tolerance tol; + readAttributesForTolerance(child, tol); + toleranceContainer.insert(tol); + } +} + +bool XMLDiff::compare() +{ + xmlNode* root1 = xmlDocGetRootElement(xmlFile1); + xmlNode* root2 = xmlDocGetRootElement(xmlFile2); + +#if USE_CPPUNIT + CPPUNIT_ASSERT(root1); + CPPUNIT_ASSERT(root2); + cppunitAssertEqual(root1->name, root2->name); +#else + if (!root1 || !root2) + return false; + if(!xmlStrEqual(root1->name, root2->name)) + return false; +#endif + return compareElements(root1, root2); +} + +namespace { + +bool checkForEmptyChildren(xmlNodePtr node) +{ + if(!node) + return true; + + for(; node != nullptr; node = node->next) + { + if (node->type == XML_ELEMENT_NODE) + return false; + } + return true; +} + +} + +bool XMLDiff::compareElements(xmlNode* node1, xmlNode* node2) +{ +#if USE_CPPUNIT + cppunitAssertEqual(node1->name, node2->name); +#else + if (!xmlStrEqual( node1->name, node2->name )) + return false; +#endif + + //compare attributes + bool sameAttribs = compareAttributes(node1, node2); +#if USE_CPPUNIT + CPPUNIT_ASSERT(sameAttribs); +#else + if (!sameAttribs) + return false; +#endif + + // compare children + xmlNode* child2 = nullptr; + xmlNode* child1 = nullptr; + for(child1 = node1->children, child2 = node2->children; child1 != nullptr && child2 != nullptr; child1 = child1->next, child2 = child2->next) + { + if (child1->type == XML_ELEMENT_NODE) + { + bool bCompare = compareElements(child1, child2); + if(!bCompare) + { + return false; + } + } + } + +#if USE_CPPUNIT + CPPUNIT_ASSERT(checkForEmptyChildren(child1)); + CPPUNIT_ASSERT(checkForEmptyChildren(child2)); +#else + if(!checkForEmptyChildren(child1) || !checkForEmptyChildren(child2)) + return false; +#endif + + return true; +} + +void XMLDiff::cppunitAssertEqual(const xmlChar *expected, const xmlChar *found) +{ +#if USE_CPPUNIT + std::stringstream stringStream; + stringStream << "Reference: " << fileName << "\n- Expected: " << reinterpret_cast<const char*>(expected) << "\n- Found: " << reinterpret_cast<const char*>(found); + + CPPUNIT_ASSERT_MESSAGE(stringStream.str(), xmlStrEqual(expected, found)); +#endif +} + +void XMLDiff::cppunitAssertEqualDouble(const xmlNodePtr node, const xmlAttrPtr attr, double expected, double found, double delta) +{ +#if USE_CPPUNIT + xmlChar * path = xmlGetNodePath(node); + std::stringstream stringStream; + stringStream << "Reference: " << fileName << "\n- Node: " << reinterpret_cast<const char*>(path) << "\n- Attr: " << reinterpret_cast<const char*>(attr->name); + xmlFree(path); + + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(stringStream.str(), expected, found, delta); +#endif +} + +namespace { + +bool compareValuesWithTolerance(double val1, double val2, double tolerance, bool relative) +{ + if(relative) + { + return (val1/tolerance) <= val2 && val2 <= (val1*tolerance); + } + else + { + return (val1 - tolerance) <= val2 && val2 <= (val1 + tolerance); + } +} + +} + +bool XMLDiff::compareAttributes(xmlNodePtr node1, xmlNodePtr node2) +{ + xmlAttrPtr attr1 = nullptr; + xmlAttrPtr attr2 = nullptr; + for(attr1 = node1->properties, attr2 = node2->properties; attr1 != nullptr && attr2 != nullptr; attr1 = attr1->next, attr2 = attr2->next) + { +#if USE_CPPUNIT + cppunitAssertEqual(attr1->name, attr2->name); +#else + if (!xmlStrEqual( attr1->name, attr2->name )) + return false; +#endif + + xmlChar* val1 = xmlGetProp(node1, attr1->name); + xmlChar* val2 = xmlGetProp(node2, attr2->name); + + double dVal1 = xmlXPathCastStringToNumber(val1); + double dVal2 = xmlXPathCastStringToNumber(val2); + + if(!std::isnan(dVal1) || !std::isnan(dVal2)) + { + //compare by value and respect tolerance + tolerance tol; + tol.elementName = xmlStrdup(node1->name); + tol.attribName = xmlStrdup(attr1->name); + ToleranceContainer::iterator itr = toleranceContainer.find( tol ); + bool useTolerance = false; + if (itr != toleranceContainer.end()) + { + useTolerance = true; + } + + if (useTolerance) + { + bool valInTolerance = compareValuesWithTolerance(dVal1, dVal2, itr->value, itr->relative); +#if USE_CPPUNIT + std::stringstream stringStream("Expected Value: "); + stringStream << dVal1 << "; Found Value: " << dVal2 << "; Tolerance: " << itr->value; + stringStream << "; Relative: " << itr->relative; + CPPUNIT_ASSERT_MESSAGE(stringStream.str(), valInTolerance); +#else + if (!valInTolerance) + return false; +#endif + } + else + { +#if USE_CPPUNIT + cppunitAssertEqualDouble(node1, attr1, dVal1, dVal2, 1e-08); +#else + if (dVal1 != dVal2) + return false; +#endif + } + } + else + { + +#if USE_CPPUNIT + cppunitAssertEqual(val1, val2); +#else + if(!xmlStrEqual( val1, val2 )) + return false; +#endif + } + + xmlFree(val1); + xmlFree(val2); + } + + // unequal number of attributes +#ifdef CPPUNIT_ASSERT + if (attr1 || attr2) + { + std::stringstream failStream; + failStream << "Unequal number of attributes in "; + // print chain from document root + std::vector<std::string> parents; + auto n = node1; + while (n) + { + if (n->name) + parents.push_back(std::string(reinterpret_cast<const char *>(n->name))); + n = n->parent; + } + bool first = true; + for (auto it = parents.rbegin(); it != parents.rend(); ++it) + { + if (!first) + failStream << "->"; + first = false; + failStream << *it; + } + failStream << " Attr1: "; + attr1 = node1->properties; + while (attr1 != nullptr) + { + xmlChar* val1 = xmlGetProp(node1, attr1->name); + failStream << BAD_CAST(attr1->name) << "=" << BAD_CAST(val1) << ", "; + xmlFree(val1); + attr1 = attr1->next; + } + + failStream << " Attr2: "; + attr2 = node2->properties; + while (attr2 != nullptr) + { + xmlChar* val2 = xmlGetProp(node2, attr2->name); + failStream << BAD_CAST(attr2->name) << "=" << BAD_CAST(val2) << ", "; + xmlFree(val2); + attr2 = attr2->next; + } + CPPUNIT_ASSERT_MESSAGE(failStream.str(), false); + } +#else + if (attr1 || attr2) + return false; +#endif + + return true; +} + + +bool +doXMLDiff(char const*const pFileName, char const*const pContent, int const size, + char const*const pToleranceFileName) +{ + XMLDiff aDiff(pFileName, pContent, size, pToleranceFileName); + return aDiff.compare(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/document/xactionlockable.cxx b/test/source/document/xactionlockable.cxx new file mode 100644 index 000000000..47d2774ae --- /dev/null +++ b/test/source/document/xactionlockable.cxx @@ -0,0 +1,46 @@ +/* -*- 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 <test/document/xactionlockable.hxx> +#include <sal/types.h> + +#include <com/sun/star/document/XActionLockable.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void XActionLockable::testAddRemoveActionLock() +{ + uno::Reference<document::XActionLockable> xAL(init(), uno::UNO_QUERY_THROW); + + xAL->addActionLock(); + CPPUNIT_ASSERT(xAL->isActionLocked()); + + xAL->removeActionLock(); + CPPUNIT_ASSERT(!xAL->isActionLocked()); +} + +void XActionLockable::testSetResetActionLock() +{ + uno::Reference<document::XActionLockable> xAL(init(), uno::UNO_QUERY_THROW); + + CPPUNIT_ASSERT_NO_THROW(xAL->setActionLocks(0)); + + const sal_Int16 nLocks = xAL->resetActionLocks(); + CPPUNIT_ASSERT_EQUAL(sal_Int16(0), nLocks); + CPPUNIT_ASSERT(!xAL->isActionLocked()); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/document/xembeddedobjectsupplier.cxx b/test/source/document/xembeddedobjectsupplier.cxx new file mode 100644 index 000000000..baa2ecbfb --- /dev/null +++ b/test/source/document/xembeddedobjectsupplier.cxx @@ -0,0 +1,30 @@ +/* -*- 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 <test/document/xembeddedobjectsupplier.hxx> + +#include <com/sun/star/document/XEmbeddedObjectSupplier.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void XEmbeddedObjectSupplier::testGetEmbeddedObject() +{ + uno::Reference<document::XEmbeddedObjectSupplier> xEOS(init(), uno::UNO_QUERY_THROW); + + CPPUNIT_ASSERT(xEOS->getEmbeddedObject()); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/document/xlinktargetsupplier.cxx b/test/source/document/xlinktargetsupplier.cxx new file mode 100644 index 000000000..eec08a900 --- /dev/null +++ b/test/source/document/xlinktargetsupplier.cxx @@ -0,0 +1,30 @@ +/* -*- 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 <test/document/xlinktargetsupplier.hxx> + +#include <com/sun/star/document/XLinkTargetSupplier.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XLinkTargetSupplier::testGetLinks() +{ + uno::Reference<document::XLinkTargetSupplier> xLinkTargetSupplier(init(), UNO_QUERY_THROW); + CPPUNIT_ASSERT(xLinkTargetSupplier->getLinks()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/drawing/captionshape.cxx b/test/source/drawing/captionshape.cxx new file mode 100644 index 000000000..66093e70d --- /dev/null +++ b/test/source/drawing/captionshape.cxx @@ -0,0 +1,178 @@ +/* -*- 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 <test/cppunitasserthelper.hxx> +#include <test/drawing/captionshape.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/awt/Point.hpp> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void CaptionShape::testCaptionShapeProperties() +{ + uno::Reference<beans::XPropertySet> xCaptionShape(init(), UNO_QUERY_THROW); + OUString propName; + uno::Any aNewValue; + + propName = "CornerRadius"; + sal_Int32 nCornerRadiusGet = 5; + sal_Int32 nCornerRadiusSet = 0; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue CornerRadius", + xCaptionShape->getPropertyValue(propName) >>= nCornerRadiusGet); + + aNewValue <<= nCornerRadiusGet + 5; + xCaptionShape->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xCaptionShape->getPropertyValue(propName) >>= nCornerRadiusSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue CornerRadius", nCornerRadiusGet + 5, + nCornerRadiusSet); + + propName = "CaptionPoint"; + awt::Point aCaptionPointGet; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue of CaptionPoint", + xCaptionShape->getPropertyValue(propName) >>= aCaptionPointGet); + + awt::Point aCaptionPointSet; + aNewValue <<= awt::Point(5, 5); + xCaptionShape->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xCaptionShape->getPropertyValue(propName) >>= aCaptionPointSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Able to set PropertyValue of CaptionPoint", aCaptionPointSet, + awt::Point(5, 5)); + + propName = "CaptionType"; + sal_Int16 captionTypeGet = 0; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue of CaptionType", + xCaptionShape->getPropertyValue(propName) >>= captionTypeGet); + + sal_Int16 captionTypeSet = 0; + const sal_Int16 FIVE = 5; + aNewValue <<= FIVE; + xCaptionShape->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xCaptionShape->getPropertyValue(propName) >>= captionTypeSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set the PropertyValue of CaptionType", FIVE, + captionTypeSet); + + propName = "CaptionIsFixedAngle"; + bool captionIsFixedAngleGet = false; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue of CaptionPointIsFixedAngle", + xCaptionShape->getPropertyValue(propName) >>= captionIsFixedAngleGet); + + bool captionIsFixedAngleSet = false; + aNewValue <<= !captionIsFixedAngleGet; + xCaptionShape->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xCaptionShape->getPropertyValue(propName) >>= captionIsFixedAngleSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set the PropertyValue of CaptionPointisFixedAngle", + captionIsFixedAngleSet, !captionIsFixedAngleGet); + + propName = "CaptionAngle"; + sal_Int32 captionAngleGet = {}; + CPPUNIT_ASSERT_MESSAGE("Unable to get the PropertyValue of CaptionAngle", + xCaptionShape->getPropertyValue(propName) >>= captionAngleGet); + + sal_Int32 captionAngleSet = 0; + aNewValue <<= captionAngleGet + 5; + xCaptionShape->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xCaptionShape->getPropertyValue(propName) >>= captionAngleSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set the PropertyValue of CaptionAngle", captionAngleSet, + captionAngleGet + 5); + + propName = "CaptionGap"; + sal_Int32 captionGapGet = {}; + CPPUNIT_ASSERT_MESSAGE("Unable to get the PropertyValue of CaptionGap", + xCaptionShape->getPropertyValue(propName) >>= captionGapGet); + + sal_Int32 captionGapSet = 0; + aNewValue <<= captionGapGet + 5; + xCaptionShape->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xCaptionShape->getPropertyValue(propName) >>= captionGapSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set the PropertyValue of CaptionGap", captionGapSet, + captionGapGet + 5); + + propName = "CaptionEscapeDirection"; + sal_Int32 captionEscapeDirectionGet = {}; + CPPUNIT_ASSERT_MESSAGE("Unable to get the PropertyValue of CaptionEscapeDirection", + xCaptionShape->getPropertyValue(propName) >>= captionEscapeDirectionGet); + + sal_Int32 captionEscapeDirectionSet = 0; + aNewValue <<= captionEscapeDirectionGet + 5; + xCaptionShape->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xCaptionShape->getPropertyValue(propName) >>= captionEscapeDirectionSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set the PropertyValue of CaptionEscapeDirection", + captionEscapeDirectionSet, captionEscapeDirectionGet + 5); + + propName = "CaptionIsEscapeRelative"; + bool captionIsEscapeRelativeGet = false; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue of CaptionIsEscapeRelative", + xCaptionShape->getPropertyValue(propName) + >>= captionIsEscapeRelativeGet); + + bool captionIsEscapeRelativeSet = false; + aNewValue <<= !captionIsEscapeRelativeGet; + xCaptionShape->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xCaptionShape->getPropertyValue(propName) >>= captionIsEscapeRelativeSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set the PropertyValue of CaptionIsEscapeRelative", + captionIsEscapeRelativeSet, !captionIsEscapeRelativeGet); + + propName = "CaptionEscapeRelative"; + sal_Int32 captionEscapeRelativeGet = {}; + CPPUNIT_ASSERT_MESSAGE("Unable to get the PropertyValue of CaptionEscapeRelative", + xCaptionShape->getPropertyValue(propName) >>= captionEscapeRelativeGet); + + sal_Int32 captionEscapeRelativeSet = 0; + aNewValue <<= captionEscapeRelativeGet + 5; + xCaptionShape->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xCaptionShape->getPropertyValue(propName) >>= captionEscapeRelativeSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set the PropertyValue of CaptionEscapeRelative", + captionEscapeRelativeSet, captionEscapeRelativeGet + 5); + + propName = "CaptionEscapeAbsolute"; + sal_Int32 captionEscapeAbsoluteGet = {}; + CPPUNIT_ASSERT_MESSAGE("Unable to get the PropertyValue of CaptionEscapeAbsolute", + xCaptionShape->getPropertyValue(propName) >>= captionEscapeAbsoluteGet); + + sal_Int32 captionEscapeAbsoluteSet = 0; + aNewValue <<= captionEscapeAbsoluteGet + 5; + xCaptionShape->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xCaptionShape->getPropertyValue(propName) >>= captionEscapeAbsoluteSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set the PropertyValue of CaptionEscapeAbsolute", + captionEscapeAbsoluteSet, captionEscapeAbsoluteGet + 5); + + propName = "CaptionLineLength"; + sal_Int32 captionLineLengthGet = {}; + CPPUNIT_ASSERT_MESSAGE("Unable to get the PropertyValue of CaptionLineLength", + xCaptionShape->getPropertyValue(propName) >>= captionLineLengthGet); + + sal_Int32 captionLineLengthSet = 0; + aNewValue <<= captionLineLengthGet + 5; + xCaptionShape->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xCaptionShape->getPropertyValue(propName) >>= captionLineLengthSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set the PropertyValue of CaptionEscapeAbsolute", + captionLineLengthSet, captionLineLengthGet + 5); + + propName = "CaptionIsFitLineLength"; + bool captionIsFitLineLengthGet = false; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue of CaptionIsFitLineLength", + xCaptionShape->getPropertyValue(propName) >>= captionIsFitLineLengthGet); + + bool captionIsFitLineLengthSet = false; + aNewValue <<= !captionIsFitLineLengthGet; + xCaptionShape->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xCaptionShape->getPropertyValue(propName) >>= captionIsFitLineLengthSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set the PropertyValue of CaptionIsFitLineLength", + captionIsFitLineLengthSet, !captionIsFitLineLengthGet); +} +} +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/drawing/xdrawpages.cxx b/test/source/drawing/xdrawpages.cxx new file mode 100644 index 000000000..be57c4852 --- /dev/null +++ b/test/source/drawing/xdrawpages.cxx @@ -0,0 +1,50 @@ +/* -*- 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 <test/drawing/xdrawpages.hxx> + +#include <com/sun/star/drawing/XDrawPage.hpp> +#include <com/sun/star/drawing/XDrawPages.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <sal/types.h> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XDrawPages::testInsertNewByIndex() +{ + uno::Reference<drawing::XDrawPages> xDrawPages(init(), uno::UNO_QUERY_THROW); + const sal_Int32 nCount = xDrawPages->getCount(); + + uno::Reference<drawing::XDrawPage> xDP(xDrawPages->insertNewByIndex(0), uno::UNO_SET_THROW); + CPPUNIT_ASSERT(xDP.is()); + CPPUNIT_ASSERT_EQUAL(nCount + 1, xDrawPages->getCount()); +} + +void XDrawPages::testRemove() +{ + uno::Reference<drawing::XDrawPages> xDrawPages(init(), uno::UNO_QUERY_THROW); + const sal_Int32 nCount = xDrawPages->getCount(); + + uno::Reference<drawing::XDrawPage> xDP(xDrawPages->insertNewByIndex(0), uno::UNO_SET_THROW); + CPPUNIT_ASSERT(xDP.is()); + + xDrawPages->remove(xDP); + CPPUNIT_ASSERT_EQUAL(nCount, xDrawPages->getCount()); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/drawing/xgluepointssupplier.cxx b/test/source/drawing/xgluepointssupplier.cxx new file mode 100644 index 000000000..186c18d71 --- /dev/null +++ b/test/source/drawing/xgluepointssupplier.cxx @@ -0,0 +1,32 @@ +/* -*- 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 <test/drawing/xgluepointssupplier.hxx> + +#include <com/sun/star/container/XIndexContainer.hpp> +#include <com/sun/star/drawing/XGluePointsSupplier.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void XGluePointsSupplier::testGetGluePoints() +{ + uno::Reference<drawing::XGluePointsSupplier> xGPS(init(), uno::UNO_QUERY_THROW); + + uno::Reference<container::XIndexContainer> xIC = xGPS->getGluePoints(); + CPPUNIT_ASSERT(xIC->getCount()); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/drawing/xshape.cxx b/test/source/drawing/xshape.cxx new file mode 100644 index 000000000..a63b89265 --- /dev/null +++ b/test/source/drawing/xshape.cxx @@ -0,0 +1,56 @@ +/* -*- 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 <test/drawing/xshape.hxx> +#include <test/cppunitasserthelper.hxx> + +#include <com/sun/star/awt/Point.hpp> +#include <com/sun/star/awt/Size.hpp> +#include <com/sun/star/drawing/XShape.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void XShape::testGetSetPosition() +{ + uno::Reference<drawing::XShape> xShape(init(), uno::UNO_QUERY_THROW); + if (m_bObjSupportsPosition) + { + awt::Point aOldPoint = xShape->getPosition(); + CPPUNIT_ASSERT_NO_THROW( + xShape->setPosition(awt::Point(aOldPoint.X + 100, aOldPoint.Y + 100))); + + awt::Point aNewPoint = xShape->getPosition(); + CPPUNIT_ASSERT_EQUAL(awt::Point(aOldPoint.X + 100, aOldPoint.Y + 100), aNewPoint); + } + CPPUNIT_ASSERT(true); +} + +void XShape::testGetSetSize() +{ + uno::Reference<drawing::XShape> xShape(init(), uno::UNO_QUERY_THROW); + + awt::Size aOldSize = xShape->getSize(); + + CPPUNIT_ASSERT_NO_THROW(xShape->setSize(awt::Size(aOldSize.Width + 10, aOldSize.Height + 10))); + + awt::Size aNewSize = xShape->getSize(); + const sal_Int16 aAcceptableLimit = 2; + CPPUNIT_ASSERT(aOldSize.Height - aNewSize.Height <= aAcceptableLimit); + CPPUNIT_ASSERT(aOldSize.Height - aNewSize.Height <= aAcceptableLimit); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/drawing/xshapedescriptor.cxx b/test/source/drawing/xshapedescriptor.cxx new file mode 100644 index 000000000..ff14513ef --- /dev/null +++ b/test/source/drawing/xshapedescriptor.cxx @@ -0,0 +1,30 @@ +/* -*- 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 <test/drawing/xshapedescriptor.hxx> + +#include <com/sun/star/drawing/XShapeDescriptor.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void XShapeDescriptor::testGetShapeType() +{ + uno::Reference<drawing::XShapeDescriptor> xSD(init(), uno::UNO_QUERY_THROW); + + CPPUNIT_ASSERT_EQUAL(m_aShapeType, xSD->getShapeType()); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/drawing/xshapegrouper.cxx b/test/source/drawing/xshapegrouper.cxx new file mode 100644 index 000000000..353faa1e7 --- /dev/null +++ b/test/source/drawing/xshapegrouper.cxx @@ -0,0 +1,57 @@ +/* -*- 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 <test/drawing/xshapegrouper.hxx> +#include <sal/types.h> + +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/drawing/XShapeGroup.hpp> +#include <com/sun/star/drawing/XShapeGrouper.hpp> +#include <com/sun/star/drawing/XShapes.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void XShapeGrouper::testGroup() +{ + uno::Reference<drawing::XShapeGrouper> xSG(init(), uno::UNO_QUERY_THROW); + + uno::Reference<drawing::XShapes> xShapes(m_xDrawPage, uno::UNO_QUERY_THROW); + const sal_Int32 nCountBeforeGroup = xShapes->getCount(); + + uno::Reference<drawing::XShape> xShape(xSG->group(xShapes), uno::UNO_QUERY_THROW); + const sal_Int32 nCountAfterGroup = xShapes->getCount(); + + CPPUNIT_ASSERT(xShape.is()); + CPPUNIT_ASSERT(nCountAfterGroup < nCountBeforeGroup); +} + +void XShapeGrouper::testUngroup() +{ + uno::Reference<drawing::XShapeGrouper> xSG(init(), uno::UNO_QUERY_THROW); + + uno::Reference<drawing::XShapes> xShapes(m_xDrawPage, uno::UNO_QUERY_THROW); + uno::Reference<drawing::XShape> xShape(xSG->group(xShapes), uno::UNO_QUERY_THROW); + uno::Reference<drawing::XShapeGroup> xShapeGroup(xShape, uno::UNO_QUERY_THROW); + + const sal_Int32 nCountAfterGroup = xShapes->getCount(); + + xSG->ungroup(xShapeGroup); + const sal_Int32 nCountAfterUngroup = xShapes->getCount(); + + CPPUNIT_ASSERT(nCountAfterUngroup != nCountAfterGroup); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/drawing/xshapes.cxx b/test/source/drawing/xshapes.cxx new file mode 100644 index 000000000..d836daf2b --- /dev/null +++ b/test/source/drawing/xshapes.cxx @@ -0,0 +1,38 @@ +/* -*- 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 <test/drawing/xshapes.hxx> +#include <sal/types.h> + +#include <com/sun/star/drawing/XShapes.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void XShapes::testAddRemove() +{ + uno::Reference<drawing::XShapes> xShapes(init(), uno::UNO_QUERY_THROW); + + const sal_Int32 nCountBeforeAdd = xShapes->getCount(); + xShapes->add(m_xShape); + const sal_Int32 nCountAfterAdd = xShapes->getCount(); + CPPUNIT_ASSERT_EQUAL(nCountBeforeAdd + 1, nCountAfterAdd); + + xShapes->remove(m_xShape); + const sal_Int32 nCountAfterRemove = xShapes->getCount(); + CPPUNIT_ASSERT_EQUAL(nCountBeforeAdd, nCountAfterRemove); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/helper/form.cxx b/test/source/helper/form.cxx new file mode 100644 index 000000000..5727909a6 --- /dev/null +++ b/test/source/helper/form.cxx @@ -0,0 +1,62 @@ +/* -*- 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 <test/helper/form.hxx> +#include <sal/types.h> + +#include <com/sun/star/awt/Point.hpp> +#include <com/sun/star/awt/Size.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/drawing/XControlShape.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace apitest::helper::form +{ +uno::Reference<drawing::XControlShape> + OOO_DLLPUBLIC_TEST createCommandButton(const uno::Reference<lang::XComponent>& r_xComponent, + const sal_Int32 nX, const sal_Int32 nY, + const sal_Int32 nHeight, const sal_Int32 nWidth) +{ + return createControlShape(r_xComponent, u"CommandButton", nX, nY, nHeight, nWidth); +} + +uno::Reference<drawing::XControlShape> OOO_DLLPUBLIC_TEST createControlShape( + const uno::Reference<lang::XComponent>& r_xComponent, std::u16string_view r_aKind, + const sal_Int32 nX, const sal_Int32 nY, const sal_Int32 nHeight, const sal_Int32 nWidth) +{ + uno::Reference<lang::XMultiServiceFactory> xMSF(r_xComponent, uno::UNO_QUERY_THROW); + + uno::Reference<drawing::XControlShape> xControlShape( + xMSF->createInstance("com.sun.star.drawing.ControlShape"), uno::UNO_QUERY_THROW); + + uno::Reference<uno::XInterface> aComponent( + xMSF->createInstance(OUString::Concat("com.sun.star.form.component.") + r_aKind), + uno::UNO_SET_THROW); + uno::Reference<beans::XPropertySet> xPropertySet(aComponent, uno::UNO_QUERY_THROW); + xPropertySet->setPropertyValue( + "DefaultControl", uno::Any(OUString::Concat("com.sun.star.form.control.") + r_aKind)); + uno::Reference<awt::XControlModel> xControlModel(aComponent, uno::UNO_QUERY_THROW); + + xControlShape->setSize(awt::Size(nHeight, nWidth)); + xControlShape->setPosition(awt::Point(nX, nY)); + + xControlShape->setControl(xControlModel); + + return xControlShape; +} + +} // namespace apitest::helper::form + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/helper/shape.cxx b/test/source/helper/shape.cxx new file mode 100644 index 000000000..0fbc3bc6d --- /dev/null +++ b/test/source/helper/shape.cxx @@ -0,0 +1,71 @@ +/* -*- 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 <test/helper/shape.hxx> +#include <sal/types.h> + +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/beans/PropertyVetoException.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace apitest::helper::shape +{ +uno::Reference<drawing::XShape> + OOO_DLLPUBLIC_TEST createEllipse(const uno::Reference<lang::XComponent>& r_xComponent, + const sal_Int32 nX, const sal_Int32 nY, const sal_Int32 nWidth, + const sal_Int32 nHeight) +{ + return createShape(r_xComponent, u"Ellipse", nX, nY, nWidth, nHeight); +} + +uno::Reference<drawing::XShape> + OOO_DLLPUBLIC_TEST createLine(const uno::Reference<lang::XComponent>& r_xComponent, + const sal_Int32 nX, const sal_Int32 nY, const sal_Int32 nWidth, + const sal_Int32 nHeight) +{ + return createShape(r_xComponent, u"Line", nX, nY, nWidth, nHeight); +} + +uno::Reference<drawing::XShape> + OOO_DLLPUBLIC_TEST createRectangle(const uno::Reference<lang::XComponent>& r_xComponent, + const sal_Int32 nX, const sal_Int32 nY, + const sal_Int32 nWidth, const sal_Int32 nHeight) +{ + return createShape(r_xComponent, u"Rectangle", nX, nY, nWidth, nHeight); +} + +uno::Reference<drawing::XShape> OOO_DLLPUBLIC_TEST +createShape(const uno::Reference<lang::XComponent>& r_xComponent, std::u16string_view r_aKind, + const sal_Int32 nX, const sal_Int32 nY, const sal_Int32 nWidth, const sal_Int32 nHeight) +{ + uno::Reference<lang::XMultiServiceFactory> xMSF(r_xComponent, uno::UNO_QUERY_THROW); + uno::Reference<drawing::XShape> xShape( + xMSF->createInstance(OUString::Concat("com.sun.star.drawing.") + r_aKind + "Shape"), + uno::UNO_QUERY_THROW); + + try + { + xShape->setPosition(awt::Point(nX, nY)); + xShape->setSize(awt::Size(nWidth, nHeight)); + } + catch (const beans::PropertyVetoException&) + { + } + + return xShape; +} + +} // namespace apitest::helper::shape + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/helper/transferable.cxx b/test/source/helper/transferable.cxx new file mode 100644 index 000000000..201b3c50e --- /dev/null +++ b/test/source/helper/transferable.cxx @@ -0,0 +1,82 @@ +/* -*- 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 <test/helper/transferable.hxx> +#include <com/sun/star/datatransfer/UnsupportedFlavorException.hpp> +#include <o3tl/string_view.hxx> + +using namespace css; + +namespace apitest::helper::transferable +{ +OString OOO_DLLPUBLIC_TEST getTextSelection( + const css::uno::Reference<css::datatransfer::XTransferable>& xTransferable, OString mimeType) +{ + if (!xTransferable.is()) + return OString(); + + // Take care of UTF-8 text here. + bool bConvert = false; + sal_Int32 nIndex = 0; + if (o3tl::getToken(mimeType, 0, ';', nIndex) == "text/plain") + { + if (o3tl::getToken(mimeType, 0, ';', nIndex) == "charset=utf-8") + { + mimeType = "text/plain;charset=utf-16"; + bConvert = true; + } + } + + datatransfer::DataFlavor aFlavor; + aFlavor.MimeType = OUString::fromUtf8(mimeType.getStr()); + if (mimeType == "text/plain;charset=utf-16") + aFlavor.DataType = cppu::UnoType<OUString>::get(); + else + aFlavor.DataType = cppu::UnoType<uno::Sequence<sal_Int8>>::get(); + + if (!xTransferable.is() || !xTransferable->isDataFlavorSupported(aFlavor)) + return OString(); + + uno::Any aAny; + try + { + aAny = xTransferable->getTransferData(aFlavor); + } + catch (const css::datatransfer::UnsupportedFlavorException&) + { + return OString(); + } + catch (const css::uno::Exception&) + { + return OString(); + } + + OString aRet; + if (aFlavor.DataType == cppu::UnoType<OUString>::get()) + { + OUString aString; + aAny >>= aString; + if (bConvert) + aRet = OUStringToOString(aString, RTL_TEXTENCODING_UTF8); + else + aRet = OString(reinterpret_cast<const char*>(aString.getStr()), + aString.getLength() * sizeof(sal_Unicode)); + } + else + { + uno::Sequence<sal_Int8> aSequence; + aAny >>= aSequence; + aRet = OString(reinterpret_cast<char*>(aSequence.getArray()), aSequence.getLength()); + } + return aRet; +} + +} // namespace apitest::helper::transferable + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/htmltesttools.cxx b/test/source/htmltesttools.cxx new file mode 100644 index 000000000..d61f07bd3 --- /dev/null +++ b/test/source/htmltesttools.cxx @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/htmltesttools.hxx> +#include <sal/log.hxx> + +#include <memory> + +htmlDocUniquePtr HtmlTestTools::parseHtml(utl::TempFile const & aTempFile) +{ + SvFileStream aFileStream(aTempFile.GetURL(), StreamMode::READ); + htmlDocUniquePtr doc = parseHtmlStream(&aFileStream); + xmlFree(doc->name); + doc->name = reinterpret_cast<char *>( + xmlStrdup( + reinterpret_cast<xmlChar const *>( + OUStringToOString( + aTempFile.GetURL(), RTL_TEXTENCODING_UTF8).getStr()))); + return doc; +} + +htmlDocUniquePtr HtmlTestTools::parseHtmlStream(SvStream* pStream) +{ + std::size_t nSize = pStream->remainingSize(); + std::unique_ptr<sal_uInt8[]> pBuffer(new sal_uInt8[nSize + 1]); + pStream->ReadBytes(pBuffer.get(), nSize); + pBuffer[nSize] = 0; + auto pCharBuffer = reinterpret_cast<xmlChar*>(pBuffer.get()); + SAL_INFO("test", "HtmlTestTools::parseXmlStream: pBuffer is '" << pCharBuffer << "'"); + return htmlDocUniquePtr(htmlParseDoc(pCharBuffer, nullptr)); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/isheadless.hxx b/test/source/isheadless.hxx new file mode 100644 index 000000000..c9f22232b --- /dev/null +++ b/test/source/isheadless.hxx @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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/. + */ + +#pragma once + +#include <sal/config.h> + +#include <rtl/process.h> +#include <rtl/ustring.hxx> +#include <sal/types.h> + +namespace test { + +inline bool isHeadless() { + sal_uInt32 n = rtl_getAppCommandArgCount(); + for (sal_uInt32 i = 0; i != n; ++i) { + OUString arg; + rtl_getAppCommandArg(i, &arg.pData); + if (arg == "--headless") { + return true; + } + } + return false; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/lang/xcomponent.cxx b/test/source/lang/xcomponent.cxx new file mode 100644 index 000000000..286f66c5c --- /dev/null +++ b/test/source/lang/xcomponent.cxx @@ -0,0 +1,77 @@ +/* -*- 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 <cppuhelper/implbase.hxx> +#include <test/lang/xcomponent.hxx> +#include <rtl/ref.hxx> + +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XEventListener.hpp> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; +namespace +{ +struct TestEventListener final : ::cppu::WeakImplHelper<lang::XEventListener> +{ + bool m_hasDisposingCalled; + TestEventListener() + : m_hasDisposingCalled(false) + { + } + virtual void SAL_CALL disposing(const lang::EventObject&) override + { + m_hasDisposingCalled = true; + } +}; +} + +namespace apitest +{ +void XComponent::testAddEventListener() +{ + Reference<lang::XComponent> xComponent(init(), uno::UNO_QUERY_THROW); + rtl::Reference<TestEventListener> pListenerAdded(new TestEventListener()); + xComponent->addEventListener(pListenerAdded); + xComponent->dispose(); + CPPUNIT_ASSERT_EQUAL(true, pListenerAdded->m_hasDisposingCalled); +} + +void XComponent::testRemoveEventListener() +{ + Reference<lang::XComponent> xComponent(init(), uno::UNO_QUERY_THROW); + rtl::Reference<TestEventListener> pListenerAddedAndRemoved(new TestEventListener()); + xComponent->addEventListener(pListenerAddedAndRemoved); + xComponent->removeEventListener(pListenerAddedAndRemoved); + xComponent->dispose(); + CPPUNIT_ASSERT_EQUAL(false, pListenerAddedAndRemoved->m_hasDisposingCalled); +} + +void XComponent::testDispose() +{ + Reference<lang::XComponent> xComponent(init(), uno::UNO_QUERY_THROW); + rtl::Reference<TestEventListener> pListenerAdded(new TestEventListener()); + xComponent->addEventListener(pListenerAdded); + xComponent->dispose(); + CPPUNIT_ASSERT_EQUAL(true, pListenerAdded->m_hasDisposingCalled); +} + +void XComponent::testDisposedByDesktopTerminate() +{ + Reference<lang::XComponent> xComponent(init(), uno::UNO_QUERY_THROW); + rtl::Reference<TestEventListener> pListenerAdded(new TestEventListener()); + xComponent->addEventListener(pListenerAdded); + triggerDesktopTerminate(); + CPPUNIT_ASSERT_EQUAL(true, pListenerAdded->m_hasDisposingCalled); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/lang/xserviceinfo.cxx b/test/source/lang/xserviceinfo.cxx new file mode 100644 index 000000000..54a19cf2a --- /dev/null +++ b/test/source/lang/xserviceinfo.cxx @@ -0,0 +1,48 @@ +/* -*- 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 <test/lang/xserviceinfo.hxx> + +#include <com/sun/star/lang/XServiceInfo.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void XServiceInfo::testGetImplementationName() +{ + uno::Reference<lang::XServiceInfo> xSI(init(), uno::UNO_QUERY_THROW); + + CPPUNIT_ASSERT_EQUAL(m_aImplName, xSI->getImplementationName()); +} + +void XServiceInfo::testGetSupportedServiceNames() +{ + uno::Reference<lang::XServiceInfo> xSI(init(), uno::UNO_QUERY_THROW); + + uno::Sequence<OUString> aServiceNames = xSI->getSupportedServiceNames(); + CPPUNIT_ASSERT(aServiceNames.hasElements()); +} + +void XServiceInfo::testSupportsService() +{ + uno::Reference<lang::XServiceInfo> xSI(init(), uno::UNO_QUERY_THROW); + + for (const auto& aServiceName : m_aServiceNames) + CPPUNIT_ASSERT(xSI->supportsService(aServiceName)); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/lokcallback.cxx b/test/source/lokcallback.cxx new file mode 100644 index 000000000..323ba4af1 --- /dev/null +++ b/test/source/lokcallback.cxx @@ -0,0 +1,183 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/lokcallback.hxx> + +#include <LibreOfficeKit/LibreOfficeKitEnums.h> +#include <rtl/strbuf.hxx> +#include <tools/gen.hxx> +#include <comphelper/lok.hxx> +#include <sfx2/viewsh.hxx> + +TestLokCallbackWrapper::TestLokCallbackWrapper(LibreOfficeKitCallback callback, void* data) + : Idle("TestLokCallbackWrapper flush timer") + , m_callback(callback) + , m_data(data) +{ + // Flushing timer needs to run with the lowest priority, so that all pending tasks + // such as invalidations are processed before it. + SetPriority(TaskPriority::LOWEST); +} + +void TestLokCallbackWrapper::clear() +{ + m_viewId = -1; + m_updatedTypes.clear(); + m_updatedTypesPerViewId.clear(); +} + +inline void TestLokCallbackWrapper::startTimer() +{ + if (!IsActive()) + Start(); +} + +constexpr int NO_VIEWID = -1; + +inline void TestLokCallbackWrapper::callCallback(int nType, const char* pPayload, int nViewId) +{ + discardUpdatedTypes(nType, nViewId); + m_callback(nType, pPayload, m_data); + startTimer(); +} + +void TestLokCallbackWrapper::libreOfficeKitViewCallback(int nType, const char* pPayload) +{ + callCallback(nType, pPayload, NO_VIEWID); +} + +void TestLokCallbackWrapper::libreOfficeKitViewCallbackWithViewId(int nType, const char* pPayload, + int nViewId) +{ + callCallback(nType, pPayload, nViewId); +} + +void TestLokCallbackWrapper::libreOfficeKitViewInvalidateTilesCallback( + const tools::Rectangle* pRect, int nPart) +{ + OStringBuffer buf(64); + if (pRect) + buf.append(pRect->toString()); + else + buf.append("EMPTY"); + if (comphelper::LibreOfficeKit::isPartInInvalidation()) + { + buf.append(", "); + buf.append(static_cast<sal_Int32>(nPart)); + } + callCallback(LOK_CALLBACK_INVALIDATE_TILES, buf.makeStringAndClear().getStr(), NO_VIEWID); +} + +// TODO This is probably a pointless code duplication with CallbackFlushHandler, +// and using this in unittests also means that CallbackFlushHandler does not get +// tested as thoroughly as it could. On the other hand, this class is simpler, +// so debugging those unittests should also be simpler. The proper solution +// is presumably this class using CallbackFlushHandler internally by default, +// but having an option to use this simpler code when needed. + +void TestLokCallbackWrapper::libreOfficeKitViewUpdatedCallback(int nType) +{ + if (std::find(m_updatedTypes.begin(), m_updatedTypes.end(), nType) == m_updatedTypes.end()) + { + m_updatedTypes.push_back(nType); + startTimer(); + } +} + +void TestLokCallbackWrapper::libreOfficeKitViewUpdatedCallbackPerViewId(int nType, int nViewId, + int nSourceViewId) +{ + const PerViewIdData data{ nType, nViewId, nSourceViewId }; + auto& l = m_updatedTypesPerViewId; + // The source view doesn't matter for uniqueness, just keep the latest one. + auto it = std::find_if(l.begin(), l.end(), [data](const PerViewIdData& other) { + return data.type == other.type && data.viewId == other.viewId; + }); + if (it != l.end()) + *it = data; + else + l.push_back(data); + startTimer(); +} + +void TestLokCallbackWrapper::discardUpdatedTypes(int nType, int nViewId) +{ + // If a callback is called directly with an event, drop the updated flag for it, since + // the direct event replaces it. + for (auto it = m_updatedTypes.begin(); it != m_updatedTypes.end();) + { + if (*it == nType) + it = m_updatedTypes.erase(it); + else + ++it; + } + // If we do not have a specific view id, drop flag for all views. + bool allViewIds = false; + if (nViewId < 0) + allViewIds = true; + if (nType == LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR + && !comphelper::LibreOfficeKit::isViewIdForVisCursorInvalidation()) + allViewIds = true; + for (auto it = m_updatedTypesPerViewId.begin(); it != m_updatedTypesPerViewId.end();) + { + if (it->type == nType && (allViewIds || it->viewId == nViewId)) + it = m_updatedTypesPerViewId.erase(it); + else + ++it; + } +} + +void TestLokCallbackWrapper::flushLOKData() +{ + if (m_updatedTypes.empty() && m_updatedTypesPerViewId.empty()) + return; + // Ask for payloads of all the pending types that need updating, and call the generic callback with that data. + assert(m_viewId >= 0); + SfxViewShell* viewShell = SfxViewShell::GetFirst(false, [this](const SfxViewShell* shell) { + return shell->GetViewShellId().get() == m_viewId; + }); + assert(viewShell != nullptr); + // First move data to local structures, so that callbacks don't possibly modify it. + std::vector<int> updatedTypes; + std::swap(updatedTypes, m_updatedTypes); + std::vector<PerViewIdData> updatedTypesPerViewId; + std::swap(updatedTypesPerViewId, m_updatedTypesPerViewId); + + for (int type : updatedTypes) + { + bool ignore = false; + OString payload = viewShell->getLOKPayload(type, m_viewId, &ignore); + if (!ignore) + libreOfficeKitViewCallback(type, payload.getStr()); + } + for (const PerViewIdData& data : updatedTypesPerViewId) + { + viewShell = SfxViewShell::GetFirst(false, [data](const SfxViewShell* shell) { + return shell->GetViewShellId().get() == data.sourceViewId; + }); + assert(viewShell != nullptr); + bool ignore = false; + OString payload = viewShell->getLOKPayload(data.type, data.viewId, &ignore); + if (!ignore) + libreOfficeKitViewCallbackWithViewId(data.type, payload.getStr(), data.viewId); + } +} + +void TestLokCallbackWrapper::Invoke() +{ + // Timer timeout, flush any possibly pending data. + for (SfxViewShell* viewShell = SfxViewShell::GetFirst(false); viewShell != nullptr; + viewShell = SfxViewShell::GetNext(*viewShell, false)) + { + viewShell->flushPendingLOKInvalidateTiles(); + } + flushLOKData(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/screenshot_test.cxx b/test/source/screenshot_test.cxx new file mode 100644 index 000000000..f8bd3c6d4 --- /dev/null +++ b/test/source/screenshot_test.cxx @@ -0,0 +1,279 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <sal/config.h> + +#include <iostream> + +#include <test/screenshot_test.hxx> + +#include <com/sun/star/frame/Desktop.hpp> +#include <comphelper/processfactory.hxx> +#include <vcl/abstdlg.hxx> +#include <vcl/pngwrite.hxx> +#include <vcl/svapp.hxx> +#include <vcl/virdev.hxx> +#include <vcl/weld.hxx> +#include <tools/stream.hxx> + + +namespace { + void splitHelpId( const OString& rHelpId, OUString& rDirname, OUString &rBasename ) + { + sal_Int32 nIndex = rHelpId.lastIndexOf( '/' ); + + if( nIndex > 0 ) + rDirname = OStringToOUString( rHelpId.subView( 0, nIndex ), RTL_TEXTENCODING_UTF8 ); + + if( rHelpId.getLength() > nIndex+1 ) + rBasename= OStringToOUString( rHelpId.subView( nIndex+1 ), RTL_TEXTENCODING_UTF8 ); + } +} + +using namespace css; +using namespace css::uno; + + /// the target directory for screenshots +constexpr OUStringLiteral g_aScreenshotDirectory(u"screenshots"); + +ScreenshotTest::ScreenshotTest() + : maParent(nullptr, "vcl/ui/screenshotparent.ui", "ScreenShot") + , mxParentWidget(maParent.getDialog()->weld_content_area()) +{ + if (auto const env = getenv("LO_TEST_LOCALE")) { + maCurrentLanguage = OUString::fromUtf8(env); + } +} + +ScreenshotTest::~ScreenshotTest() +{ +} + +void ScreenshotTest::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop = css::frame::Desktop::create( comphelper::getComponentContext(getMultiServiceFactory()) ); + CPPUNIT_ASSERT_MESSAGE("no desktop!", mxDesktop.is()); + + osl::Directory::create( m_directories.getURLFromWorkdir( g_aScreenshotDirectory)) ; + + // initialize maKnownDialogs + if (maKnownDialogs.empty()) + { + registerKnownDialogsByID(maKnownDialogs); + } +} + +void ScreenshotTest::implSaveScreenshot(const BitmapEx& rScreenshot, const OString& rScreenshotId) +{ + OUString aDirname, aBasename; + splitHelpId(rScreenshotId, aDirname, aBasename); + aDirname = g_aScreenshotDirectory + "/" + aDirname + + ( (maCurrentLanguage == "en-US") ? OUString() : "/" + maCurrentLanguage ); + + auto const dirUrl = m_directories.getURLFromWorkdir(aDirname); + auto const e = osl::Directory::createPath(dirUrl); + if (e != osl::FileBase::E_EXIST) { + CPPUNIT_ASSERT_EQUAL_MESSAGE( + OString("Failed to create " + OUStringToOString(dirUrl, RTL_TEXTENCODING_UTF8)) + .getStr(), + osl::FileBase::E_None, e); + } + + auto const pngUrl = OUString(dirUrl + "/" + aBasename + ".png"); + SvFileStream aNew(pngUrl, StreamMode::WRITE | StreamMode::TRUNC); + CPPUNIT_ASSERT_MESSAGE(OString("Failed to open <" + OUStringToOString(pngUrl, RTL_TEXTENCODING_UTF8) + ">: " + OString::number(sal_uInt32(aNew.GetErrorCode()))).getStr(), aNew.IsOpen()); + + std::cout << "saving " << pngUrl << ":\n"; + vcl::PNGWriter aPNGWriter(rScreenshot); + aPNGWriter.Write(aNew); +} + +void ScreenshotTest::saveScreenshot(VclAbstractDialog const & rDialog) +{ + const BitmapEx aScreenshot(rDialog.createScreenshot()); + + if (!aScreenshot.IsEmpty()) + { + const OString aScreenshotId = rDialog.GetScreenshotId(); + + if (!aScreenshotId.isEmpty()) + { + implSaveScreenshot(aScreenshot, aScreenshotId); + } + } +} + +void ScreenshotTest::saveScreenshot(weld::Window& rDialog) +{ + VclPtr<VirtualDevice> xDialogSurface(rDialog.screenshot()); + const BitmapEx aScreenshot(xDialogSurface->GetBitmapEx(Point(), xDialogSurface->GetOutputSizePixel())); + + if (!aScreenshot.IsEmpty()) + { + const OString aScreenshotId = rDialog.get_help_id(); + assert(!aScreenshotId.isEmpty()); + implSaveScreenshot(aScreenshot, aScreenshotId); + } +} + +VclPtr<VclAbstractDialog> ScreenshotTest::createDialogByName(const OString& rName) +{ + const mapType::const_iterator aHit = maKnownDialogs.find(rName); + + if (aHit != maKnownDialogs.end()) + { + return createDialogByID((*aHit).second); + } + + return VclPtr<VclAbstractDialog>(); +} + +void ScreenshotTest::dumpDialogToPath(VclAbstractDialog& rDialog) +{ + const std::vector<OString> aPageDescriptions(rDialog.getAllPageUIXMLDescriptions()); + + if (!aPageDescriptions.empty()) + { + for (size_t a(0); a < aPageDescriptions.size(); a++) + { + if (rDialog.selectPageByUIXMLDescription(aPageDescriptions[a])) + { + saveScreenshot(rDialog); + } + else + { + CPPUNIT_ASSERT(false); + } + } + } + else + { + saveScreenshot(rDialog); + } +} + +void ScreenshotTest::dumpDialogToPath(weld::Builder& rBuilder) +{ + std::unique_ptr<weld::Window> xDialog(rBuilder.create_screenshot_window()); + + auto xTabCtrl = rBuilder.weld_notebook("tabcontrol"); + + int nPages = xTabCtrl ? xTabCtrl->get_n_pages() : 0; + if (nPages) + { + for (int i = 0; i < nPages; ++i) + { + OString sIdent(xTabCtrl->get_page_ident(i)); + xTabCtrl->set_current_page(sIdent); + if (xTabCtrl->get_current_page_ident() == sIdent) + { + OString sOrigHelpId(xDialog->get_help_id()); + // skip empty pages + weld::Container* pPage = xTabCtrl->get_page(sIdent); + OString sBuildableName(pPage->get_buildable_name()); + if (!sBuildableName.isEmpty() && !sBuildableName.startsWith("__")) + xDialog->set_help_id(pPage->get_help_id()); + saveScreenshot(*xDialog); + xDialog->set_help_id(sOrigHelpId); + } + else + { + CPPUNIT_ASSERT(false); + } + } + } + else + { + saveScreenshot(*xDialog); + } +} + +void ScreenshotTest::dumpDialogToPath(std::string_view rUIXMLDescription) +{ + if (rUIXMLDescription.empty()) + return; + + bool bNonConforming = rUIXMLDescription == "modules/swriter/ui/sidebarstylepresets.ui" || + rUIXMLDescription == "modules/swriter/ui/sidebartheme.ui" || + rUIXMLDescription == "modules/swriter/ui/notebookbar.ui" || + rUIXMLDescription == "modules/scalc/ui/sidebaralignment.ui" || + rUIXMLDescription == "modules/scalc/ui/sidebarcellappearance.ui" || + rUIXMLDescription == "modules/scalc/ui/sidebarnumberformat.ui" || + rUIXMLDescription == "sfx/ui/helpbookmarkpage.ui" || + rUIXMLDescription == "sfx/ui/helpcontentpage.ui" || + rUIXMLDescription == "sfx/ui/helpindexpage.ui" || + rUIXMLDescription == "sfx/ui/helpsearchpage.ui" || + rUIXMLDescription == "sfx/ui/startcenter.ui" || + rUIXMLDescription == "svx/ui/datanavigator.ui" || + rUIXMLDescription == "svx/ui/xformspage.ui" || + rUIXMLDescription == "modules/dbreport/ui/conditionwin.ui"; + if (bNonConforming) // skip these broken ones + return; + std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(mxParentWidget.get(), OStringToOUString(rUIXMLDescription, RTL_TEXTENCODING_UTF8))); + dumpDialogToPath(*xBuilder); +} + +void ScreenshotTest::processAllKnownDialogs() +{ + for (const auto& rDialog : getKnownDialogs()) + { + ScopedVclPtr<VclAbstractDialog> pDlg(createDialogByID(rDialog.second)); + + if (pDlg) + { + // known dialog, dump screenshot to path + dumpDialogToPath(*pDlg); + } + else + { + // unknown dialog, should not happen in this basic loop. + // You have probably forgotten to add a case and + // implementation to createDialogByID, please do this + } + } +} + +void ScreenshotTest::processDialogBatchFile(std::u16string_view rFile) +{ + test::Directories aDirectories; + const OUString aURL(aDirectories.getURLFromSrc(rFile)); + SvFileStream aStream(aURL, StreamMode::READ); + OString aNextUIFile; + const OString aComment("#"); + + while (aStream.ReadLine(aNextUIFile)) + { + if (!aNextUIFile.isEmpty() && !aNextUIFile.startsWith(aComment)) + { + std::cout << "processing " << aNextUIFile << ":\n"; + + // first check if it's a known dialog + ScopedVclPtr<VclAbstractDialog> pDlg(createDialogByName(aNextUIFile)); + + if (pDlg) + { + // known dialog, dump screenshot to path + dumpDialogToPath(*pDlg); + } + else + { + // unknown dialog, try fallback to generic created + // Builder-generated instance. Keep in mind that Dialogs + // using this mechanism will probably not be layouted well + // since the setup/initialization part is missing. Thus, + // only use for fallback when only the UI file is available. + dumpDialogToPath(aNextUIFile); + } + } + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/setupvcl.cxx b/test/source/setupvcl.cxx new file mode 100644 index 000000000..7e489effb --- /dev/null +++ b/test/source/setupvcl.cxx @@ -0,0 +1,94 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <sal/config.h> + +#include <com/sun/star/configuration/theDefaultProvider.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/util/XFlushable.hpp> +#include <com/sun/star/frame/Desktop.hpp> +#include <comphelper/processfactory.hxx> +#include <i18nlangtag/languagetag.hxx> +#include <i18nlangtag/mslangid.hxx> +#include <unotools/configmgr.hxx> +#include <unotools/syslocaleoptions.hxx> +#include <vcl/svapp.hxx> + +#include "isheadless.hxx" +#include "setupvcl.hxx" + +namespace { + +struct Hook { // LINK only works as a member of a class... + DECL_STATIC_LINK(Hook, deinitHook, LinkParamNone *, void); +}; + +// HACK so that defaultBootstrap_InitialComponentContext (in +// unobootstrapprotector) is called before InitVCL (below), but component +// context is disposed (redundantly again in unobootstrapprotector) from within +// DeInitVCL (cf. Desktop::DeInit, desktop/source/app/app.cxx): +IMPL_STATIC_LINK_NOARG(Hook, deinitHook, LinkParamNone *, void) { + css::uno::Reference<css::uno::XComponentContext> context; + try { + context = comphelper::getProcessComponentContext(); + } catch (css::uno::RuntimeException &) {} + + if (!context) + return; + + css::uno::Reference<css::lang::XMultiServiceFactory> config; + try { + config = css::configuration::theDefaultProvider::get(context); + } catch (css::uno::DeploymentException &) {} + if (config) { + utl::ConfigManager::storeConfigItems(); + css::uno::Reference<css::util::XFlushable>( + config, css::uno::UNO_QUERY_THROW)->flush(); + } + + // the desktop has to be terminate() before it can be dispose() + css::uno::Reference<css::frame::XDesktop> xDesktop; + try { + xDesktop = css::frame::Desktop::create(comphelper::getProcessComponentContext()); + } catch (css::uno::DeploymentException &) {} + if (xDesktop) + try { + xDesktop->terminate(); + } catch (css::uno::DeploymentException &) {} + + css::uno::Reference<css::lang::XComponent>( + context, css::uno::UNO_QUERY_THROW)->dispose(); + + comphelper::setProcessServiceFactory(nullptr); +} + +} + +void test::setUpVcl(bool const forceHeadless) { + // Force locale (and resource files loaded): + OUString locale; + if (getenv("LO_TEST_LOCALE") != nullptr) + locale = OUString::fromUtf8(getenv("LO_TEST_LOCALE")); + else + locale = "en-US"; + + SvtSysLocaleOptions localOptions; + localOptions.SetLocaleConfigString(locale); + localOptions.SetUILocaleConfigString(locale); + LanguageTag tag(locale); + MsLangId::setConfiguredSystemUILanguage(tag.getLanguageType(false)); + LanguageTag::setConfiguredSystemLanguage(tag.getLanguageType(false)); + InitVCL(); + if (forceHeadless || isHeadless()) { + Application::EnableHeadlessMode(false); + } + Application::setDeInitHook(LINK(nullptr, Hook, deinitHook)); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/setupvcl.hxx b/test/source/setupvcl.hxx new file mode 100644 index 000000000..5da3b19e0 --- /dev/null +++ b/test/source/setupvcl.hxx @@ -0,0 +1,25 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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/. + */ + +#ifndef INCLUDED_TEST_SETUPVCL_HXX +#define INCLUDED_TEST_SETUPVCL_HXX + +#include <sal/config.h> + +#include <test/testdllapi.hxx> + +namespace test +{ +// Calls InitVCL etc.; needed from multiple places in the test infrastructure: +OOO_DLLPUBLIC_TEST_SETUPVCL void setUpVcl(bool forceHeadless = false); +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/cellarealink.cxx b/test/source/sheet/cellarealink.cxx new file mode 100644 index 000000000..bfaf4c3fe --- /dev/null +++ b/test/source/sheet/cellarealink.cxx @@ -0,0 +1,114 @@ +/* -*- 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 <test/sheet/cellarealink.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void CellAreaLink::testUrl() +{ + uno::Reference<beans::XPropertySet> xCellAreaLink(init(), uno::UNO_QUERY_THROW); + + static const OUStringLiteral propName(u"Url"); + + OUString aUrl; + CPPUNIT_ASSERT(xCellAreaLink->getPropertyValue(propName) >>= aUrl); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Default Url already changed", m_aFileURL, aUrl); + + uno::Any aNewUrl; + aNewUrl <<= OUString("file:///tmp"); + xCellAreaLink->setPropertyValue(propName, aNewUrl); + CPPUNIT_ASSERT(xCellAreaLink->getPropertyValue(propName) >>= aUrl); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Value of Url wasn't changed", OUString("file:///tmp"), aUrl); +} + +void CellAreaLink::testFilter() +{ + uno::Reference<beans::XPropertySet> xCellAreaLink(init(), uno::UNO_QUERY_THROW); + + static const OUStringLiteral propName(u"Filter"); + + OUString aFilter; + CPPUNIT_ASSERT(xCellAreaLink->getPropertyValue(propName) >>= aFilter); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Default Filter already changed", OUString("calc8"), aFilter); + + uno::Any aNewFilter; + aNewFilter <<= OUString("UnitTest"); + xCellAreaLink->setPropertyValue(propName, aNewFilter); + CPPUNIT_ASSERT(xCellAreaLink->getPropertyValue(propName) >>= aFilter); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Value of Filter wasn't changed", OUString("UnitTest"), aFilter); +} + +void CellAreaLink::testFilterOptions() +{ + uno::Reference<beans::XPropertySet> xCellAreaLink(init(), uno::UNO_QUERY_THROW); + + static const OUStringLiteral propName(u"FilterOptions"); + + OUString aFilterOptions; + CPPUNIT_ASSERT(xCellAreaLink->getPropertyValue(propName) >>= aFilterOptions); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Default FilterOptions already changed", OUString(""), + aFilterOptions); + + uno::Any aNewFilterOptions; + aNewFilterOptions <<= OUString("UnitTest"); + xCellAreaLink->setPropertyValue(propName, aNewFilterOptions); + CPPUNIT_ASSERT(xCellAreaLink->getPropertyValue(propName) >>= aFilterOptions); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Value of FilterOptions wasn't changed", OUString("UnitTest"), + aFilterOptions); +} + +void CellAreaLink::testRefreshDelay() +{ + uno::Reference<beans::XPropertySet> xCellAreaLink(init(), uno::UNO_QUERY_THROW); + + static const OUStringLiteral propName(u"RefreshDelay"); + + sal_Int32 aRefreshDelay = 0; + CPPUNIT_ASSERT(xCellAreaLink->getPropertyValue(propName) >>= aRefreshDelay); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Default RefreshDelay already changed", sal_Int32(0), + aRefreshDelay); + + uno::Any aNewRefreshDelay; + aNewRefreshDelay <<= static_cast<sal_Int32>(42); + xCellAreaLink->setPropertyValue(propName, aNewRefreshDelay); + CPPUNIT_ASSERT(xCellAreaLink->getPropertyValue(propName) >>= aRefreshDelay); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Value of RefreshDelay wasn't changed", sal_Int32(42), + aRefreshDelay); +} + +void CellAreaLink::testRefreshPeriod() +{ + uno::Reference<beans::XPropertySet> xCellAreaLink(init(), uno::UNO_QUERY_THROW); + + static const OUStringLiteral propName(u"RefreshPeriod"); + + sal_Int32 aRefreshPeriod = 0; + CPPUNIT_ASSERT(xCellAreaLink->getPropertyValue(propName) >>= aRefreshPeriod); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Default RefreshPeriod already changed", sal_Int32(0), + aRefreshPeriod); + + uno::Any aNewRefreshPeriod; + aNewRefreshPeriod <<= static_cast<sal_Int32>(42); + xCellAreaLink->setPropertyValue(propName, aNewRefreshPeriod); + CPPUNIT_ASSERT(xCellAreaLink->getPropertyValue(propName) >>= aRefreshPeriod); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Value of RefreshPeriod wasn't changed", sal_Int32(42), + aRefreshPeriod); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/cellproperties.cxx b/test/source/sheet/cellproperties.cxx new file mode 100644 index 000000000..3d7908be7 --- /dev/null +++ b/test/source/sheet/cellproperties.cxx @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/cellproperties.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> + +#include <cppunit/TestAssert.h> +#include <iostream> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void CellProperties::testVertJustify() +{ + uno::Reference<beans::XPropertySet> xCellRangeBase(init(), UNO_QUERY_THROW); + OUString aVertJustify("VertJustify"); + uno::Any aOldVertJustify = xCellRangeBase->getPropertyValue(aVertJustify); + sal_Int32 aValue = 0; + CPPUNIT_ASSERT(aOldVertJustify >>= aValue); + std::cout << "Old VertJustify value: " << aValue << std::endl; + + uno::Any aNewVertJustify; + aNewVertJustify <<= static_cast<sal_Int32>(3); + xCellRangeBase->setPropertyValue(aVertJustify, aNewVertJustify); + uno::Any aVertJustifyControllValue = xCellRangeBase->getPropertyValue(aVertJustify); + CPPUNIT_ASSERT(aVertJustifyControllValue >>= aValue); + std::cout << "New VertJustify value: " << aValue << std::endl; + CPPUNIT_ASSERT_EQUAL_MESSAGE("value has not been changed", sal_Int32(3), aValue); +} + +void CellProperties::testRotateReference() +{ + uno::Reference<beans::XPropertySet> xCellRangeBase(init(), UNO_QUERY_THROW); + OUString aRotateReference("RotateReference"); + uno::Any aOldRotateReference = xCellRangeBase->getPropertyValue(aRotateReference); + sal_Int32 aValue = 0; + CPPUNIT_ASSERT(aOldRotateReference >>= aValue); + std::cout << "Old RotateReference Value: " << aValue << std::endl; + + uno::Any aNewRotateReference; + aNewRotateReference <<= static_cast<sal_Int32>(3); + xCellRangeBase->setPropertyValue(aRotateReference, aNewRotateReference); + uno::Any aRotateReferenceControllValue = xCellRangeBase->getPropertyValue(aRotateReference); + CPPUNIT_ASSERT(aRotateReferenceControllValue >>= aValue); + std::cout << "New RotateReference value: " << aValue << std::endl; + CPPUNIT_ASSERT_EQUAL_MESSAGE("value has not been changed", sal_Int32(3), aValue); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/databaseimportdescriptor.cxx b/test/source/sheet/databaseimportdescriptor.cxx new file mode 100644 index 000000000..132f88817 --- /dev/null +++ b/test/source/sheet/databaseimportdescriptor.cxx @@ -0,0 +1,102 @@ +/* -*- 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 <test/sheet/databaseimportdescriptor.hxx> + +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sheet/DataImportMode.hpp> +#include <com/sun/star/util/XImportable.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void DatabaseImportDescriptor::testDatabaseImportDescriptorProperties() +{ + uno::Reference<beans::XPropertySet> xDatabaseImportDescriptor(init(), UNO_QUERY_THROW); + uno::Reference<util::XImportable> xImportable(getXImportable(), UNO_QUERY_THROW); + uno::Sequence<beans::PropertyValue> aPropValues = xImportable->createImportDescriptor(true); + + for (auto& rPropValue : asNonConstRange(aPropValues)) + { + uno::Any aOldValue; + uno::Any aNewValue; + if (rPropValue.Name == "DatabaseName" || rPropValue.Name == "SourceObject" + || rPropValue.Name == "ConnectionResource") + { + OUString aValue; + aOldValue = rPropValue.Value; + aOldValue >>= aValue; + OString aMsgGet = "Unable to get PropertyValue " + + OUStringToOString(rPropValue.Name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_EQUAL_MESSAGE(aMsgGet.getStr(), OUString(""), aValue); + + aNewValue <<= OUString("New"); + rPropValue.Value = aNewValue; + + aOldValue = rPropValue.Value; + aOldValue >>= aValue; + OString aMsgSet = "Unable to set PropertyValue " + + OUStringToOString(rPropValue.Name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_EQUAL_MESSAGE(aMsgSet.getStr(), OUString("New"), aValue); + } + else if (rPropValue.Name == "IsNative") + { + bool aValue = true; + aOldValue = rPropValue.Value; + aOldValue >>= aValue; + OString aMsgGet = "Unable to get PropertyValue " + + OUStringToOString(rPropValue.Name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_MESSAGE(aMsgGet.getStr(), !aValue); + + aNewValue <<= true; + rPropValue.Value = aNewValue; + + aOldValue = rPropValue.Value; + aOldValue >>= aValue; + OString aMsgSet = "Unable to set PropertyValue " + + OUStringToOString(rPropValue.Name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_MESSAGE(aMsgSet.getStr(), aValue); + } + else if (rPropValue.Name == "SourceType") + { + sheet::DataImportMode aValue; + aOldValue = rPropValue.Value; + aOldValue >>= aValue; + OString aMsgGet = "Unable to get PropertyValue " + + OUStringToOString(rPropValue.Name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_EQUAL_MESSAGE(aMsgGet.getStr(), sheet::DataImportMode_NONE, aValue); + + aNewValue <<= sheet::DataImportMode_SQL; + rPropValue.Value = aNewValue; + + aOldValue = rPropValue.Value; + aOldValue >>= aValue; + OString aMsgSet = "Unable to set PropertyValue " + + OUStringToOString(rPropValue.Name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_EQUAL_MESSAGE(aMsgSet.getStr(), sheet::DataImportMode_SQL, aValue); + } + else + { + OString aMsg = "Unsupported PropertyValue " + + OUStringToOString(rPropValue.Name, RTL_TEXTENCODING_UTF8); + CPPUNIT_FAIL(aMsg.getStr()); + } + } +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/databaserange.cxx b/test/source/sheet/databaserange.cxx new file mode 100644 index 000000000..d87e3723c --- /dev/null +++ b/test/source/sheet/databaserange.cxx @@ -0,0 +1,219 @@ +/* -*- 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 <test/sheet/databaserange.hxx> +#include <test/cppunitasserthelper.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sheet/XDatabaseRange.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void DatabaseRange::testMoveCells() +{ + uno::Reference<beans::XPropertySet> xDatabaseRange(init("DataArea"), UNO_QUERY_THROW); + + static const OUStringLiteral propName(u"MoveCells"); + + bool bMoveCells = true; + CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bMoveCells); + CPPUNIT_ASSERT_MESSAGE("Default MoveCells already changed", !bMoveCells); + + uno::Any aNewMoveCells; + aNewMoveCells <<= true; + xDatabaseRange->setPropertyValue(propName, aNewMoveCells); + CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bMoveCells); + CPPUNIT_ASSERT_MESSAGE("Value of MoveCells wasn't changed", bMoveCells); +} + +void DatabaseRange::testKeepFormats() +{ + uno::Reference<beans::XPropertySet> xDatabaseRange(init("DataArea"), UNO_QUERY_THROW); + + static const OUStringLiteral propName(u"KeepFormats"); + + bool bKeepFormats = true; + CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bKeepFormats); + CPPUNIT_ASSERT_MESSAGE("Default KeepFormats already changed", !bKeepFormats); + + uno::Any aNewKeepFormats; + aNewKeepFormats <<= true; + xDatabaseRange->setPropertyValue(propName, aNewKeepFormats); + CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bKeepFormats); + CPPUNIT_ASSERT_MESSAGE("Value of KeepFormats wasn't changed", bKeepFormats); +} + +void DatabaseRange::testStripData() +{ + uno::Reference<beans::XPropertySet> xDatabaseRange(init("DataArea"), UNO_QUERY_THROW); + + static const OUStringLiteral propName(u"StripData"); + + bool bStripData = true; + CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bStripData); + CPPUNIT_ASSERT_MESSAGE("Default StripData already changed", !bStripData); + + uno::Any aNewStripData; + aNewStripData <<= true; + xDatabaseRange->setPropertyValue(propName, aNewStripData); + CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bStripData); + CPPUNIT_ASSERT_MESSAGE("Value of StripData wasn't changed", bStripData); +} + +void DatabaseRange::testAutoFilter() +{ + uno::Reference<beans::XPropertySet> xDatabaseRange(init("DataArea"), UNO_QUERY_THROW); + + static const OUStringLiteral propName(u"AutoFilter"); + + bool bAutoFilter = true; + CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bAutoFilter); + CPPUNIT_ASSERT_MESSAGE("Default AutoFilter already changed", !bAutoFilter); + + uno::Any aNewAutoFilter; + aNewAutoFilter <<= true; + xDatabaseRange->setPropertyValue(propName, aNewAutoFilter); + CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bAutoFilter); + CPPUNIT_ASSERT_MESSAGE("Value of AutoFilter wasn't changed", bAutoFilter); +} + +void DatabaseRange::testUseFilterCriteriaSource() +{ + uno::Reference<beans::XPropertySet> xDatabaseRange(init("DataArea"), UNO_QUERY_THROW); + + static const OUStringLiteral propName(u"UseFilterCriteriaSource"); + + bool bUseFilterCriteriaSource = true; + CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bUseFilterCriteriaSource); + CPPUNIT_ASSERT_MESSAGE("Default UseFilterCriteriaSource already changed", + !bUseFilterCriteriaSource); + + uno::Any aNewUseFilterCriteriaSource; + aNewUseFilterCriteriaSource <<= true; + xDatabaseRange->setPropertyValue(propName, aNewUseFilterCriteriaSource); + CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bUseFilterCriteriaSource); + CPPUNIT_ASSERT_MESSAGE("Value of UseFilterCriteriaSource wasn't changed", + bUseFilterCriteriaSource); +} + +void DatabaseRange::testFilterCriteriaSource() +{ + uno::Reference<beans::XPropertySet> xDatabaseRange(init("DataArea"), UNO_QUERY_THROW); + + static const OUStringLiteral propName(u"FilterCriteriaSource"); + + table::CellRangeAddress cellRangeAddress; + CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= cellRangeAddress); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Default RefreshPeriod already changed", + table::CellRangeAddress(0, 0, 0, 0, 0), cellRangeAddress); + + uno::Any aFilterCriteriaSource; + aFilterCriteriaSource <<= table::CellRangeAddress(1, 1, 1, 1, 1); + xDatabaseRange->setPropertyValue(propName, aFilterCriteriaSource); + CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= cellRangeAddress); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Value of FilterCriteriaSource wasn't changed", + table::CellRangeAddress(1, 1, 1, 1, 1), cellRangeAddress); +} + +void DatabaseRange::testRefreshPeriod() +{ + uno::Reference<beans::XPropertySet> xDatabaseRange(init("DataArea"), UNO_QUERY_THROW); + + static const OUStringLiteral propName(u"RefreshPeriod"); + + sal_Int32 aRefreshPeriod = 1; + CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= aRefreshPeriod); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Default RefreshPeriod already changed", sal_Int32(0), + aRefreshPeriod); + + uno::Any aNewRefreshPeriod; + aNewRefreshPeriod <<= static_cast<sal_Int32>(42); + xDatabaseRange->setPropertyValue(propName, aNewRefreshPeriod); + CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= aRefreshPeriod); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Value of RefreshPeriod wasn't changed", sal_Int32(42), + aRefreshPeriod); +} + +void DatabaseRange::testFromSelection() +{ + uno::Reference<beans::XPropertySet> xDatabaseRange(init("DataArea"), UNO_QUERY_THROW); + + static const OUStringLiteral propName(u"FromSelection"); + + bool bFromSelection = true; + CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bFromSelection); + CPPUNIT_ASSERT_MESSAGE("Default FromSelection already changed", !bFromSelection); + + uno::Any aNewFromSelection; + aNewFromSelection <<= true; + xDatabaseRange->setPropertyValue(propName, aNewFromSelection); + CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bFromSelection); + CPPUNIT_ASSERT_MESSAGE("Value of FromSelection wasn't changed", bFromSelection); +} + +void DatabaseRange::testTokenIndex() +{ + uno::Reference<beans::XPropertySet> xDatabaseRange(init("DataArea"), UNO_QUERY_THROW); + + static const OUStringLiteral propName(u"TokenIndex"); + + sal_Int32 aTokenIndex = 0; + CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= aTokenIndex); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Default TotalIndex already changed", sal_Int32(1), aTokenIndex); + + uno::Any aNewTokenIndex; + aNewTokenIndex <<= static_cast<sal_Int32>(42); + xDatabaseRange->setPropertyValue(propName, aNewTokenIndex); + CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= aTokenIndex); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Value of TotalIndex was changed", sal_Int32(1), aTokenIndex); +} + +void DatabaseRange::testTotalsRow() +{ + uno::Reference<beans::XPropertySet> xDatabaseRange(init("DataArea"), UNO_QUERY_THROW); + + static const OUStringLiteral propName(u"TotalsRow"); + + bool bTotalsRow = true; + CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bTotalsRow); + CPPUNIT_ASSERT_MESSAGE("Default TotalsRow already changed", !bTotalsRow); + + uno::Any aNewTotalsRow; + aNewTotalsRow <<= true; + xDatabaseRange->setPropertyValue(propName, aNewTotalsRow); + CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bTotalsRow); + CPPUNIT_ASSERT_MESSAGE("Value of TotalsRow wasn't changed", bTotalsRow); +} + +void DatabaseRange::testContainsHeader() +{ + uno::Reference<beans::XPropertySet> xDatabaseRange(init("DataArea"), UNO_QUERY_THROW); + + static const OUStringLiteral propName(u"ContainsHeader"); + + bool bContainsHeader = false; + CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bContainsHeader); + CPPUNIT_ASSERT_MESSAGE("Default ContainsHeader already changed", bContainsHeader); + + uno::Any aNewContainsHeader; + aNewContainsHeader <<= false; + xDatabaseRange->setPropertyValue(propName, aNewContainsHeader); + CPPUNIT_ASSERT(xDatabaseRange->getPropertyValue(propName) >>= bContainsHeader); + CPPUNIT_ASSERT_MESSAGE("Value of ContainsHeader wasn't changed", !bContainsHeader); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/datapilotfield.cxx b/test/source/sheet/datapilotfield.cxx new file mode 100644 index 000000000..020f33680 --- /dev/null +++ b/test/source/sheet/datapilotfield.cxx @@ -0,0 +1,189 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/datapilotfield.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sheet/DataPilotFieldSortInfo.hpp> +#include <com/sun/star/sheet/DataPilotFieldSortMode.hpp> +#include <com/sun/star/sheet/DataPilotFieldReferenceItemType.hpp> +#include <com/sun/star/sheet/DataPilotFieldLayoutMode.hpp> +#include <com/sun/star/sheet/DataPilotFieldLayoutInfo.hpp> +#include <com/sun/star/sheet/DataPilotFieldReference.hpp> +#include <com/sun/star/sheet/DataPilotFieldAutoShowInfo.hpp> + +#include <rtl/ustring.hxx> +#include <cppunit/TestAssert.h> +#include <iostream> + +using namespace css; +using namespace css::uno; + +namespace apitest { + +void DataPilotField::testSortInfo() +{ + uno::Reference< beans::XPropertySet> xPropSet(init(),UNO_QUERY_THROW); + sheet::DataPilotFieldSortInfo aSortInfoValue; + OUString aSortInfo("SortInfo"); + aSortInfoValue.Field = "Col1"; + aSortInfoValue.IsAscending = false; + aSortInfoValue.Mode = sheet::DataPilotFieldSortMode::MANUAL; + uno::Any aValue; + aValue <<= aSortInfoValue; + xPropSet->setPropertyValue(aSortInfo, aValue); + + sheet::DataPilotFieldSortInfo aNewSortInfoValue; + aValue = xPropSet->getPropertyValue(aSortInfo); + CPPUNIT_ASSERT( aValue >>= aNewSortInfoValue ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("set value should be the same as got value", aSortInfoValue.Field, aNewSortInfoValue.Field); + CPPUNIT_ASSERT_EQUAL_MESSAGE("set value should be the same as got value", aSortInfoValue.Mode, aNewSortInfoValue.Mode); + CPPUNIT_ASSERT_EQUAL_MESSAGE("set value should be the same as got value", aSortInfoValue.IsAscending, aNewSortInfoValue.IsAscending); + + //setting HasSortInfo only makes sense for false, for true the uno implementation does nothing + bool bHasSortInfo(false); + OUString aHasSortInfo("HasSortInfo"); + aValue = xPropSet->getPropertyValue(aHasSortInfo); + CPPUNIT_ASSERT( aValue >>= bHasSortInfo ); + CPPUNIT_ASSERT_MESSAGE("should have sort info", bHasSortInfo); + + bHasSortInfo = false; + aValue <<= bHasSortInfo; + xPropSet->setPropertyValue(aHasSortInfo, aValue); + + aValue = xPropSet->getPropertyValue(aHasSortInfo); + CPPUNIT_ASSERT( aValue >>= bHasSortInfo ); + CPPUNIT_ASSERT_MESSAGE("should have no sort info", !bHasSortInfo); +} + +void DataPilotField::testLayoutInfo() +{ + uno::Reference< beans::XPropertySet > xPropSet(init(),UNO_QUERY_THROW); + sheet::DataPilotFieldLayoutInfo aLayoutInfoValue; + OUString aLayoutInfo("LayoutInfo"); + aLayoutInfoValue.AddEmptyLines = false; + aLayoutInfoValue.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM; + uno::Any aValue; + aValue <<= aLayoutInfoValue; + xPropSet->setPropertyValue(aLayoutInfo, aValue); + + sheet::DataPilotFieldLayoutInfo aNewLayoutInfoValue; + aValue = xPropSet->getPropertyValue(aLayoutInfo); + CPPUNIT_ASSERT( aValue >>= aNewLayoutInfoValue ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("set value should be the same as the got value", aLayoutInfoValue.LayoutMode, aNewLayoutInfoValue.LayoutMode); + CPPUNIT_ASSERT_EQUAL_MESSAGE("set value should be the same as the got value", aLayoutInfoValue.AddEmptyLines, aNewLayoutInfoValue.AddEmptyLines); + + //setting HasLayoutInfo only makes sense for false, tor true the uno implementation does nothing + bool bHasLayoutInfo(false); + OUString aHasLayoutInfo("HasLayoutInfo"); + aValue = xPropSet->getPropertyValue(aHasLayoutInfo); + CPPUNIT_ASSERT( aValue >>= bHasLayoutInfo ); + CPPUNIT_ASSERT_MESSAGE("should have layout information", bHasLayoutInfo); + + bHasLayoutInfo = false; + aValue <<= bHasLayoutInfo; + xPropSet->setPropertyValue(aHasLayoutInfo, aValue); + + aValue = xPropSet->getPropertyValue(aHasLayoutInfo); + CPPUNIT_ASSERT( aValue >>= bHasLayoutInfo ); + CPPUNIT_ASSERT_MESSAGE("should have no longer sort information", !bHasLayoutInfo); +} + +void DataPilotField::testAutoShowInfo() +{ + uno::Reference< beans::XPropertySet > xPropSet(init(),UNO_QUERY_THROW); + sheet::DataPilotFieldAutoShowInfo aAutoShowInfoValue; + aAutoShowInfoValue.DataField = "Col1"; + aAutoShowInfoValue.IsEnabled = true; + OUString aAutoShowInfo("AutoShowInfo"); + uno::Any aValue; + aValue <<= aAutoShowInfoValue; + xPropSet->setPropertyValue(aAutoShowInfo, aValue); + + sheet::DataPilotFieldAutoShowInfo aNewAutoShowInfoValue; + aValue = xPropSet->getPropertyValue(aAutoShowInfo); + CPPUNIT_ASSERT( aValue >>= aNewAutoShowInfoValue ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("set value should be the same as the got value", aAutoShowInfoValue.DataField, aNewAutoShowInfoValue.DataField); + CPPUNIT_ASSERT_EQUAL_MESSAGE("set value should be the same as the got value", aAutoShowInfoValue.IsEnabled, aNewAutoShowInfoValue.IsEnabled); + + //setting HasLayoutInfo only makes sense for false, tor true the uno implementation does nothing + bool bHasAutoShowInfo(false); + OUString aHasAutoShowInfo("HasAutoShowInfo"); + aValue = xPropSet->getPropertyValue(aHasAutoShowInfo); + CPPUNIT_ASSERT( aValue >>= bHasAutoShowInfo ); + CPPUNIT_ASSERT_MESSAGE("should have AutoShow information", bHasAutoShowInfo); + + bHasAutoShowInfo = false; + aValue <<= bHasAutoShowInfo; + xPropSet->setPropertyValue(aHasAutoShowInfo, aValue); + + aValue = xPropSet->getPropertyValue(aHasAutoShowInfo); + CPPUNIT_ASSERT( aValue >>= bHasAutoShowInfo ); + CPPUNIT_ASSERT_MESSAGE("should have no longer AutoShow information", !bHasAutoShowInfo); +} + +void DataPilotField::testReference() +{ + uno::Reference< beans::XPropertySet > xPropSet(init(),UNO_QUERY_THROW); + sheet::DataPilotFieldReference aReferenceValue; + aReferenceValue.ReferenceField = "Col1"; + aReferenceValue.ReferenceItemType = sheet::DataPilotFieldReferenceItemType::NAMED; + OUString aReference("Reference"); + uno::Any aValue; + aValue <<= aReferenceValue; + xPropSet->setPropertyValue(aReference, aValue); + + sheet::DataPilotFieldReference aNewReferenceValue; + aValue = xPropSet->getPropertyValue(aReference); + CPPUNIT_ASSERT( aValue >>= aNewReferenceValue ); + CPPUNIT_ASSERT_EQUAL_MESSAGE("set value should be the same as the got value", aReferenceValue.ReferenceField, aNewReferenceValue.ReferenceField); + CPPUNIT_ASSERT_EQUAL_MESSAGE("set value should be the same as the got value", aReferenceValue.ReferenceItemType, aNewReferenceValue.ReferenceItemType); + + //setting HasReference only makes sense for false, tor true the uno implementation does nothing + bool bHasReference(false); + OUString aHasReference("HasReference"); + aValue = xPropSet->getPropertyValue(aHasReference); + CPPUNIT_ASSERT( aValue >>= bHasReference ); + CPPUNIT_ASSERT_MESSAGE("should have Reference information", bHasReference); + + bHasReference = false; + aValue <<= bHasReference; + xPropSet->setPropertyValue(aHasReference, aValue); + + aValue = xPropSet->getPropertyValue(aHasReference); + CPPUNIT_ASSERT( aValue >>= bHasReference ); + CPPUNIT_ASSERT_MESSAGE("should have no longer reference information", !bHasReference); +} + +void DataPilotField::testIsGroupField() +{ + uno::Reference< beans::XPropertySet > xPropSet(init(),UNO_QUERY_THROW); + uno::Any aValue; + OUString aIsGroupField("IsGroupField"); + bool bIsGroupField(false); + + aValue = xPropSet->getPropertyValue(aIsGroupField); + CPPUNIT_ASSERT( aValue >>= bIsGroupField); + //only setting to false is supported + if (bIsGroupField) + { + bIsGroupField = false; + aValue <<= bIsGroupField; + + xPropSet->setPropertyValue(aIsGroupField, aValue); + aValue = xPropSet->getPropertyValue(aIsGroupField); + CPPUNIT_ASSERT(aValue >>= bIsGroupField); + CPPUNIT_ASSERT_MESSAGE("setting IsGroupField is supported and should have happened", !bIsGroupField); + } + else + std::cout << "Could not test IsGroupField" << std::endl; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/datapilotitem.cxx b/test/source/sheet/datapilotitem.cxx new file mode 100644 index 000000000..bfbe2110a --- /dev/null +++ b/test/source/sheet/datapilotitem.cxx @@ -0,0 +1,64 @@ +/* -*- 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 <test/sheet/datapilotitem.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void DataPilotItem::testProperties() +{ + uno::Reference<beans::XPropertySet> xItem(init(), UNO_QUERY_THROW); + + static const OUStringLiteral propNameIS(u"IsHidden"); + + bool bIsHidden = true; + CPPUNIT_ASSERT(xItem->getPropertyValue(propNameIS) >>= bIsHidden); + CPPUNIT_ASSERT_MESSAGE("Default IsHidden already changed", !bIsHidden); + + uno::Any aNewIsHidden; + aNewIsHidden <<= false; + xItem->setPropertyValue(propNameIS, aNewIsHidden); + CPPUNIT_ASSERT(xItem->getPropertyValue(propNameIS) >>= bIsHidden); + CPPUNIT_ASSERT_MESSAGE("Value of IsHidden wasn't changed", !bIsHidden); + + static const OUStringLiteral propNameSD(u"ShowDetail"); + + bool bShowDetail = false; + CPPUNIT_ASSERT(xItem->getPropertyValue(propNameSD) >>= bShowDetail); + CPPUNIT_ASSERT_MESSAGE("Default ShowDetail already changed", bShowDetail); + + uno::Any aNewShowDetail; + aNewShowDetail <<= true; + xItem->setPropertyValue(propNameSD, aNewShowDetail); + CPPUNIT_ASSERT(xItem->getPropertyValue(propNameSD) >>= bShowDetail); + CPPUNIT_ASSERT_MESSAGE("Value of ShowDetail wasn't changed", bShowDetail); + + sal_Int32 nPosition = 42; + CPPUNIT_ASSERT(xItem->getPropertyValue("Position") >>= nPosition); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Default Position already changed", sal_Int32(0), nPosition); + + // FIXME: This throws somehow a com.sun.star.lang.IllegalArgumentException + //uno::Any aNewPosition; + //aNewPosition <<= static_cast<sal_Int32>(42); + //xItem->setPropertyValue(propNameP, aNewPosition); + //CPPUNIT_ASSERT(xItem->getPropertyValue(propNameP) >>= nPosition); + //CPPUNIT_ASSERT_EQUAL_MESSAGE("Value of Position wasn't changed", sal_Int32(42), nPosition); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/documentsettings.cxx b/test/source/sheet/documentsettings.cxx new file mode 100644 index 000000000..644b7273c --- /dev/null +++ b/test/source/sheet/documentsettings.cxx @@ -0,0 +1,183 @@ +/* -*- 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 <test/sheet/documentsettings.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void DocumentSettings::testDocumentSettingsProperties() +{ + uno::Reference<beans::XPropertySet> xDocumentSettings(init(), UNO_QUERY_THROW); + OUString propName; + uno::Any aNewValue; + + propName = "ShowZeroValues"; + bool aShowZeroValues = false; + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aShowZeroValues); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ShowZeroValues", aShowZeroValues); + + aNewValue <<= false; + xDocumentSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aShowZeroValues); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue ShowZeroValues", !aShowZeroValues); + + propName = "ShowNotes"; + bool aShowNotes = false; + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aShowNotes); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ShowNotes", aShowNotes); + + aNewValue <<= false; + xDocumentSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aShowNotes); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue ShowNotes", !aShowNotes); + + propName = "ShowGrid"; + bool aShowGrid = false; + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aShowGrid); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ShowGrid", aShowGrid); + + aNewValue <<= false; + xDocumentSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aShowGrid); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue ShowGrid", !aShowGrid); + + propName = "ShowPageBreaks"; + bool aShowPageBreaks = false; + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aShowPageBreaks); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ShowPageBreaks", aShowPageBreaks); + + aNewValue <<= false; + xDocumentSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aShowPageBreaks); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue ShowPageBreaks", !aShowPageBreaks); + + propName = "HasColumnRowHeaders"; + bool aHasColumnRowHeaders = false; + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aHasColumnRowHeaders); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue HasColumnRowHeaders", aHasColumnRowHeaders); + + aNewValue <<= false; + xDocumentSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aHasColumnRowHeaders); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue HasColumnRowHeaders", + !aHasColumnRowHeaders); + + propName = "HasSheetTabs"; + bool aHasSheetTabs = false; + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aHasSheetTabs); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue HasSheetTabs", aHasSheetTabs); + + aNewValue <<= false; + xDocumentSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aHasSheetTabs); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue HasSheetTabs", !aHasSheetTabs); + + propName = "IsOutlineSymbolsSet"; + bool aIsOutlineSymbolsSet = false; + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aIsOutlineSymbolsSet); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue IsOutlineSymbolsSet", aIsOutlineSymbolsSet); + + aNewValue <<= false; + xDocumentSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aIsOutlineSymbolsSet); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue IsOutlineSymbolsSet", + !aIsOutlineSymbolsSet); + + propName = "IsSnapToRaster"; + bool aIsSnapToRaster = true; + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aIsSnapToRaster); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue IsSnapToRaster", !aIsSnapToRaster); + + aNewValue <<= true; + xDocumentSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aIsSnapToRaster); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue IsSnapToRaster", aIsSnapToRaster); + + propName = "RasterIsVisible"; + bool aRasterIsVisible = true; + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aRasterIsVisible); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue RasterIsVisible", !aRasterIsVisible); + + aNewValue <<= true; + xDocumentSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aRasterIsVisible); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue RasterIsVisible", aRasterIsVisible); + + propName = "RasterResolutionX"; + sal_Int32 aRasterResolutionX = 0; + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aRasterResolutionX); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue RasterResolutionX", sal_Int32(1270), + aRasterResolutionX); + + aNewValue <<= sal_Int32(42); + xDocumentSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aRasterResolutionX); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue RasterResolutionX", sal_Int32(42), + aRasterResolutionX); + + propName = "RasterResolutionY"; + sal_Int32 aRasterResolutionY = 0; + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aRasterResolutionY); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue RasterResolutionY", sal_Int32(1270), + aRasterResolutionY); + + aNewValue <<= sal_Int32(42); + xDocumentSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aRasterResolutionY); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue RasterResolutionY", sal_Int32(42), + aRasterResolutionY); + + propName = "RasterSubdivisionX"; + sal_Int32 aRasterSubdivisionX = 0; + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aRasterSubdivisionX); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue RasterSubdivisionX", sal_Int32(1), + aRasterSubdivisionX); + + aNewValue <<= sal_Int32(42); + xDocumentSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aRasterSubdivisionX); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue RasterSubdivisionX", sal_Int32(42), + aRasterSubdivisionX); + + propName = "RasterSubdivisionY"; + sal_Int32 aRasterSubdivisionY = 0; + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aRasterSubdivisionY); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue RasterSubdivisionY", sal_Int32(1), + aRasterSubdivisionY); + + aNewValue <<= sal_Int32(42); + xDocumentSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aRasterSubdivisionY); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue RasterSubdivisionY", sal_Int32(42), + aRasterSubdivisionY); + + propName = "IsRasterAxisSynchronized"; + bool aIsRasterAxisSynchronized = false; + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aIsRasterAxisSynchronized); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue IsRasterAxisSynchronized", + aIsRasterAxisSynchronized); + + aNewValue <<= false; + xDocumentSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xDocumentSettings->getPropertyValue(propName) >>= aIsRasterAxisSynchronized); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue IsRasterAxisSynchronized", + !aIsRasterAxisSynchronized); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/functiondescription.cxx b/test/source/sheet/functiondescription.cxx new file mode 100644 index 000000000..e90a138e8 --- /dev/null +++ b/test/source/sheet/functiondescription.cxx @@ -0,0 +1,85 @@ +/* -*- 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 <vector> + +#include <test/sheet/functiondescription.hxx> + +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/sheet/FunctionArgument.hpp> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void FunctionDescription::testFunctionDescriptionProperties() +{ + const uno::Sequence<beans::PropertyValue> aFunctionDescription(init()); + + std::vector<OUString> names; + // Only test the get/read operation of the values, because set/write operation doesn't + // make any sense. It doesn't trigger any changes. + // See discussion: nabble.documentfoundation.org/Testing-UNO-API-service-properties-td4236286.html. + for (const auto& value : aFunctionDescription) + { + if (value.Name == "Id") + { + names.push_back(value.Name); + sal_Int32 nValue = 0; + CPPUNIT_ASSERT(value.Value >>= nValue); + } + else if (value.Name == "Category") + { + names.push_back(value.Name); + sal_Int32 nValue = 0; + CPPUNIT_ASSERT(value.Value >>= nValue); + } + else if (value.Name == "Name") + { + names.push_back(value.Name); + OUString sValue; + CPPUNIT_ASSERT(value.Value >>= sValue); + } + else if (value.Name == "Description") + { + names.push_back(value.Name); + OUString sValue; + CPPUNIT_ASSERT(value.Value >>= sValue); + } + else if (value.Name == "Arguments") + { + names.push_back(value.Name); + uno::Sequence<sheet::FunctionArgument> sArguments; + CPPUNIT_ASSERT(value.Value >>= sArguments); + } + else + { + OString aMsg = "Unsupported PropertyValue: " + + OUStringToOString(value.Name, RTL_TEXTENCODING_UTF8); + CPPUNIT_FAIL(aMsg.getStr()); + } + } + + CPPUNIT_ASSERT_MESSAGE("Property Id not found", + std::count(std::begin(names), std::end(names), "Id")); + CPPUNIT_ASSERT_MESSAGE("Property Category not found", + std::count(std::begin(names), std::end(names), "Category")); + CPPUNIT_ASSERT_MESSAGE("Property Name not found", + std::count(std::begin(names), std::end(names), "Name")); + CPPUNIT_ASSERT_MESSAGE("Property Description not found", + std::count(std::begin(names), std::end(names), "Description")); + CPPUNIT_ASSERT_MESSAGE("Property Arguments not found", + std::count(std::begin(names), std::end(names), "Arguments")); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/globalsheetsettings.cxx b/test/source/sheet/globalsheetsettings.cxx new file mode 100644 index 000000000..3e796fc58 --- /dev/null +++ b/test/source/sheet/globalsheetsettings.cxx @@ -0,0 +1,150 @@ +/* -*- 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 <test/sheet/globalsheetsettings.hxx> + +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/configuration/theDefaultProvider.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/util/XChangesBatch.hpp> + +#include <comphelper/processfactory.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void GlobalSheetSettings::testGlobalSheetSettingsProperties() +{ + uno::Reference<beans::XPropertySet> xGlobalSheetSettings(init(), UNO_QUERY_THROW); + auto configProvider + = css::configuration::theDefaultProvider::get(comphelper::getProcessComponentContext()); + + auto DoCheck = [&xGlobalSheetSettings, &configProvider]( + const OUString& propName, const auto& origValue, const auto& newValue, + const OUString& regNodeName, const OUString& regValueName) { + OString sMessage = "PropertyValue " + propName.toUtf8(); + css::uno::Any aOrigValue(origValue), aNewValue(newValue); + + css::uno::Sequence<css::uno::Any> args{ css::uno::Any( + css::beans::NamedValue("nodepath", css::uno::Any(regNodeName))) }; + css::uno::Reference<beans::XPropertySet> xRegNodeRO( + configProvider->createInstanceWithArguments( + "com.sun.star.configuration.ConfigurationAccess", args), + css::uno::UNO_QUERY_THROW); + css::uno::Reference<beans::XPropertySet> xRegNodeRW( + configProvider->createInstanceWithArguments( + "com.sun.star.configuration.ConfigurationUpdateAccess", args), + css::uno::UNO_QUERY_THROW); + css::uno::Reference<css::util::XChangesBatch> xBatch(xRegNodeRW, css::uno::UNO_QUERY_THROW); + + // 1. Check initial value + CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aOrigValue, + xGlobalSheetSettings->getPropertyValue(propName)); + CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aOrigValue, + xRegNodeRO->getPropertyValue(regValueName)); + + // 2. Check setting the value through GlobalSheetSettings + xGlobalSheetSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aNewValue, + xGlobalSheetSettings->getPropertyValue(propName)); + CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aNewValue, + xRegNodeRO->getPropertyValue(regValueName)); + + // 3. Check setting the value through ConfigurationUpdateAccess + xRegNodeRW->setPropertyValue(regValueName, aOrigValue); + xBatch->commitChanges(); + CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aOrigValue, + xRegNodeRO->getPropertyValue(regValueName)); + CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aOrigValue, + xGlobalSheetSettings->getPropertyValue(propName)); + }; + + OUString node = "/org.openoffice.Office.Calc/Input"; + DoCheck("MoveSelection", true, false, node, "MoveSelection"); + DoCheck("MoveDirection", sal_Int16(0), sal_Int16(1), node, "MoveSelectionDirection"); + DoCheck("EnterEdit", false, true, node, "SwitchToEditMode"); + DoCheck("ExtendFormat", false, true, node, "ExpandFormatting"); + DoCheck("RangeFinder", true, false, node, "ShowReference"); + DoCheck("ExpandReferences", false, true, node, "ExpandReference"); + DoCheck("MarkHeader", true, false, node, "HighlightSelection"); + DoCheck("UseTabCol", false, true, node, "UseTabCol"); + DoCheck("UsePrinterMetrics", false, true, node, "UsePrinterMetrics"); + DoCheck("ReplaceCellsWarning", true, false, node, "ReplaceCellsWarning"); + + node = "/org.openoffice.Office.Calc/Layout/Other/MeasureUnit"; + DoCheck("Metric", sal_Int16(8), sal_Int16(1), node, "NonMetric"); // Test uses en-US locale + + node = "/org.openoffice.Office.Calc/Input"; + DoCheck("DoAutoComplete", true, false, node, "AutoInput"); + + node = "/org.openoffice.Office.Calc/Content/Update"; + DoCheck("LinkUpdateMode", sal_Int16(2), sal_Int16(1), node, "Link"); + + node = "/org.openoffice.Office.Calc/Print/"; + DoCheck("PrintAllSheets", false, true, node + "Other", "AllSheets"); + DoCheck("PrintEmptyPages", false, true, node + "Page", "EmptyPages"); + + OUString propName; + uno::Any aNewValue; + + propName = "Scale"; + sal_Int16 aScale = 42; + CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aScale); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue Scale", sal_Int16(100), aScale); + + aNewValue <<= sal_Int16(-1); + xGlobalSheetSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aScale); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue Scale", sal_Int16(-1), aScale); + + propName = "StatusBarFunction"; + sal_Int16 aStatusBarFunction = 42; + CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aStatusBarFunction); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue StatusBarFunction", sal_Int16(514), + aStatusBarFunction); + + aNewValue <<= sal_Int16(1); + xGlobalSheetSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aStatusBarFunction); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue StatusBarFunction", sal_Int16(1), + aStatusBarFunction); + + propName = "UserLists"; + uno::Sequence<OUString> aSeq{ + "Sun,Mon,Tue,Wed,Thu,Fri,Sat", + "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday", + "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", + "January,February,March,April,May,June,July,August,September,October,November,December", + "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Shabbat", + "Nissan,Iyar,Sivan,Tammuz,Av,Elul,Tishri,Heshvan,Kislev,Tevet,Shevat,Adar,Adar B" + }; + + uno::Sequence<OUString> aUserLists; + CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aUserLists); + for (auto i = 0; i < aUserLists.getLength(); i++) + { + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue UserLists[" + std::to_string(i) + + "]", + aSeq[i], aUserLists[i]); + } + + aNewValue <<= uno::Sequence<OUString>(); + xGlobalSheetSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xGlobalSheetSettings->getPropertyValue(propName) >>= aUserLists); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue UserLists", !aUserLists.hasElements()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/scenario.cxx b/test/source/sheet/scenario.cxx new file mode 100644 index 000000000..dc96e3cc3 --- /dev/null +++ b/test/source/sheet/scenario.cxx @@ -0,0 +1,113 @@ +/* -*- 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 <test/sheet/scenario.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void Scenario::testScenarioProperties() +{ + uno::Reference<beans::XPropertySet> xScenario(getScenarioSpreadsheet(), UNO_QUERY_THROW); + OUString propName; + uno::Any aNewValue; + + propName = "IsActive"; + bool aIsActive = false; + CPPUNIT_ASSERT(xScenario->getPropertyValue(propName) >>= aIsActive); + CPPUNIT_ASSERT_MESSAGE("Unable to get property value IsActive", aIsActive); + + aNewValue <<= false; + xScenario->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xScenario->getPropertyValue(propName) >>= aIsActive); + CPPUNIT_ASSERT_MESSAGE("Unable to set property value IsActive", !aIsActive); + + propName = "BorderColor"; + sal_Int32 aBorderColor = 0; + CPPUNIT_ASSERT(xScenario->getPropertyValue(propName) >>= aBorderColor); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value BorderColor", sal_Int32(12632256), + aBorderColor); + + aNewValue <<= sal_Int32(42); + xScenario->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xScenario->getPropertyValue(propName) >>= aBorderColor); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set property value BorderColor", sal_Int32(42), + aBorderColor); + + propName = "Protected"; + bool aProtected = false; + CPPUNIT_ASSERT(xScenario->getPropertyValue(propName) >>= aProtected); + CPPUNIT_ASSERT_MESSAGE("Unable to get property value Protected", aProtected); + + aNewValue <<= false; + xScenario->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xScenario->getPropertyValue(propName) >>= aProtected); + CPPUNIT_ASSERT_MESSAGE("Unable to set property value Protected", !aProtected); + + propName = "ShowBorder"; + bool aShowBorder = false; + CPPUNIT_ASSERT(xScenario->getPropertyValue(propName) >>= aShowBorder); + CPPUNIT_ASSERT_MESSAGE("Unable to get property value ShowBorder", aShowBorder); + + aNewValue <<= false; + xScenario->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xScenario->getPropertyValue(propName) >>= aShowBorder); + CPPUNIT_ASSERT_MESSAGE("Unable to set property value ShowBorder", !aShowBorder); + + propName = "PrintBorder"; + bool aPrintBorder = false; + CPPUNIT_ASSERT(xScenario->getPropertyValue(propName) >>= aPrintBorder); + CPPUNIT_ASSERT_MESSAGE("Unable to get property value PrintBorder", aPrintBorder); + + aNewValue <<= false; + xScenario->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xScenario->getPropertyValue(propName) >>= aPrintBorder); + CPPUNIT_ASSERT_MESSAGE("Unable to set property value PrintBorder", !aPrintBorder); + + propName = "CopyBack"; + bool aCopyBack = false; + CPPUNIT_ASSERT(xScenario->getPropertyValue(propName) >>= aCopyBack); + CPPUNIT_ASSERT_MESSAGE("Unable to get property value CopyBack", aCopyBack); + + aNewValue <<= false; + xScenario->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xScenario->getPropertyValue(propName) >>= aCopyBack); + CPPUNIT_ASSERT_MESSAGE("Unable to set property value CopyBack", !aCopyBack); + + propName = "CopyStyles"; + bool aCopyStyles = true; + CPPUNIT_ASSERT(xScenario->getPropertyValue(propName) >>= aCopyStyles); + CPPUNIT_ASSERT_MESSAGE("Unable to get property value CopyStyles", !aCopyStyles); + + aNewValue <<= true; + xScenario->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xScenario->getPropertyValue(propName) >>= aCopyStyles); + CPPUNIT_ASSERT_MESSAGE("Unable to set property value CopyStyles", aCopyStyles); + + propName = "CopyFormulas"; + bool aCopyFormulas = false; + CPPUNIT_ASSERT(xScenario->getPropertyValue(propName) >>= aCopyFormulas); + CPPUNIT_ASSERT_MESSAGE("Unable to get property value CopyFormulas", aCopyFormulas); + + aNewValue <<= false; + xScenario->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xScenario->getPropertyValue(propName) >>= aCopyFormulas); + CPPUNIT_ASSERT_MESSAGE("Unable to set property value CopyFormulas", !aCopyFormulas); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/shape.cxx b/test/source/sheet/shape.cxx new file mode 100644 index 000000000..ab2abec6e --- /dev/null +++ b/test/source/sheet/shape.cxx @@ -0,0 +1,115 @@ +/* -*- 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 <test/sheet/shape.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void Shape::testShapePropertiesAnchor() +{ + uno::Reference<beans::XPropertySet> xShape(init(), UNO_QUERY_THROW); + uno::Any aNewValue; + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(getXSheetDocument(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Sequence<OUString> sheetNames = xSheets->getElementNames(); + uno::Reference<sheet::XSpreadsheet> xSheet(xSheets->getByName(sheetNames[0]), UNO_QUERY_THROW); + uno::Reference<table::XCell> xCell(xSheet->getCellByPosition(0, 0), UNO_SET_THROW); + + // Shape should be anchored to sheet by default + uno::Reference<sheet::XSpreadsheet> xSheetGet; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Anchor (XSpreadsheet)", + xShape->getPropertyValue("Anchor") >>= xSheetGet); + + // Anchor the shape to a cell + aNewValue <<= xCell; + xShape->setPropertyValue("Anchor", aNewValue); + uno::Reference<table::XCell> xCellGet; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Anchor (XCell)", + xShape->getPropertyValue("Anchor") >>= xCellGet); + + // Shape should not resize with cell by default + bool bIsResizeWithCell = {}; + CPPUNIT_ASSERT(xShape->getPropertyValue("ResizeWithCell") >>= bIsResizeWithCell); + CPPUNIT_ASSERT_MESSAGE("Shape should not resize with the cell", !bIsResizeWithCell); + + xShape->setPropertyValue("ResizeWithCell", uno::Any(true)); + CPPUNIT_ASSERT(xShape->getPropertyValue("ResizeWithCell") >>= bIsResizeWithCell); + CPPUNIT_ASSERT_MESSAGE("Shape should resize with the cell", bIsResizeWithCell); + + // Anchoring to a different cell should keep the "ResizeWithCell" attribute + uno::Reference<table::XCell> xCell2(xSheet->getCellByPosition(1, 2), UNO_SET_THROW); + aNewValue <<= xCell2; + xShape->setPropertyValue("Anchor", aNewValue); + CPPUNIT_ASSERT(xShape->getPropertyValue("ResizeWithCell") >>= bIsResizeWithCell); + CPPUNIT_ASSERT_MESSAGE("ResizeWithCell should still be set", bIsResizeWithCell); + + // Now anchor to sheet again + aNewValue <<= xSheet; + xShape->setPropertyValue("Anchor", aNewValue); + CPPUNIT_ASSERT(xShape->getPropertyValue("Anchor") >>= xSheetGet); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Anchor (XSpreadsheet)", + xShape->getPropertyValue("Anchor") >>= xSheetGet); + + // Setting ResizeWithCell while anchored to page should not have any effect + CPPUNIT_ASSERT(xShape->getPropertyValue("ResizeWithCell") >>= bIsResizeWithCell); + CPPUNIT_ASSERT_MESSAGE("ResizeWithCell should be false for sheet anchored shapes", + !bIsResizeWithCell); + xShape->setPropertyValue("ResizeWithCell", uno::Any(true)); + CPPUNIT_ASSERT(xShape->getPropertyValue("ResizeWithCell") >>= bIsResizeWithCell); + CPPUNIT_ASSERT_MESSAGE("ResizeWithCell should be unchangeable for sheet anchored shapes", + !bIsResizeWithCell); +} + +void Shape::testShapePropertiesPosition() +{ + uno::Reference<beans::XPropertySet> xShape(init(), UNO_QUERY_THROW); + uno::Any aNewValue; + + sal_Int32 nHoriOrientPositionGet = 0; + sal_Int32 nHoriOrientPositionSet = 0; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue HoriOrientPosition", + xShape->getPropertyValue("HoriOrientPosition") + >>= nHoriOrientPositionGet); + + aNewValue <<= nHoriOrientPositionGet + 42; + xShape->setPropertyValue("HoriOrientPosition", aNewValue); + CPPUNIT_ASSERT(xShape->getPropertyValue("HoriOrientPosition") >>= nHoriOrientPositionSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue HoriOrientPosition", + nHoriOrientPositionGet + 42, nHoriOrientPositionSet); + + sal_Int32 nVertOrientPositionGet = 0; + sal_Int32 nVertOrientPositionSet = 0; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue VertOrientPosition", + xShape->getPropertyValue("VertOrientPosition") + >>= nVertOrientPositionGet); + + aNewValue <<= nVertOrientPositionGet + 42; + xShape->setPropertyValue("VertOrientPosition", aNewValue); + CPPUNIT_ASSERT(xShape->getPropertyValue("VertOrientPosition") >>= nVertOrientPositionSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue VertOrientPosition", + nVertOrientPositionGet + 42, nVertOrientPositionSet); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/sheetcell.cxx b/test/source/sheet/sheetcell.cxx new file mode 100644 index 000000000..d0a2c6c03 --- /dev/null +++ b/test/source/sheet/sheetcell.cxx @@ -0,0 +1,215 @@ +/* -*- 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 <test/cppunitasserthelper.hxx> +#include <test/sheet/sheetcell.hxx> + +#include <com/sun/star/awt/Point.hpp> +#include <com/sun/star/awt/Size.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sheet/ValidationType.hpp> +#include <com/sun/star/sheet/XSheetConditionalEntry.hpp> +#include <com/sun/star/sheet/XSheetConditionalEntries.hpp> +#include <com/sun/star/table/CellContentType.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <comphelper/propertyvalue.hxx> +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void SheetCell::testSheetCellProperties() +{ + uno::Reference<beans::XPropertySet> xSheetCell(init(), UNO_QUERY_THROW); + OUString propName; + uno::Any aNewValue; + + propName = "Position"; + awt::Point aPositionGet; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Position", + xSheetCell->getPropertyValue(propName) >>= aPositionGet); + + awt::Point aPositionSet(42, 42); + aNewValue <<= aPositionSet; + xSheetCell->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aPositionSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Able to set PropertyValue Position", aPositionGet, aPositionGet); + + propName = "Size"; + awt::Size aSizeGet; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Size", + xSheetCell->getPropertyValue(propName) >>= aSizeGet); + + awt::Size aSizeSet(42, 42); + aNewValue <<= aSizeGet; + xSheetCell->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aSizeSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Able to set PropertyValue Size", aSizeGet, aSizeSet); + + propName = "FormulaLocal"; + OUString aFormulaLocal = ""; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue FormulaLocal", + xSheetCell->getPropertyValue(propName) >>= aFormulaLocal); + + aNewValue <<= OUString("FormulaLocal"); + xSheetCell->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aFormulaLocal); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue FormulaLocal", + OUString("FormulaLocal"), aFormulaLocal); + + propName = "CellContentType"; + table::CellContentType aCellContentTypeGet; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue CellContentType", + xSheetCell->getPropertyValue(propName) >>= aCellContentTypeGet); + + table::CellContentType aCellContentTypeSet = table::CellContentType_TEXT; + aNewValue <<= aCellContentTypeSet; + xSheetCell->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aCellContentTypeSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Able to set PropertyValue CellContentType", aCellContentTypeGet, + aCellContentTypeSet); + + // Special case, because the API returns the wrong type. + propName = "FormulaResultType"; + table::CellContentType aFormulaResultTypeGet; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue FormulaResultType", + xSheetCell->getPropertyValue(propName) >>= aFormulaResultTypeGet); + + table::CellContentType aFormulaResultTypeSet = table::CellContentType_TEXT; + aNewValue <<= aFormulaResultTypeSet; + xSheetCell->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aFormulaResultTypeSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Able to set PropertyValue FormulaResultType", + aFormulaResultTypeGet, aFormulaResultTypeSet); + + propName = "FormulaResultType2"; + sal_Int32 aFormulaResultType2Get = 42; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue FormulaResultType2", + xSheetCell->getPropertyValue(propName) >>= aFormulaResultType2Get); + + sal_Int32 aFormulaResultType2Set = 42; + aNewValue <<= aFormulaResultType2Set; + xSheetCell->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aFormulaResultType2Set); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Able to set PropertyValue FormulaResultType2", + aFormulaResultType2Get, aFormulaResultType2Set); + + uno::Sequence<beans::PropertyValue> aPropValue{ comphelper::makePropertyValue( + "StyleName", OUString("Result2")) }; + + propName = "ConditionalFormat"; + uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatGet; + uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatSet; + + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ConditionalFormat", + xSheetCell->getPropertyValue(propName) >>= aConditionalFormatGet); + + uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatNew(aConditionalFormatGet, + UNO_SET_THROW); + aConditionalFormatNew->addNew(aPropValue); + + aNewValue <<= aConditionalFormatNew; + xSheetCell->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aConditionalFormatSet); + for (auto i = 0; i < aConditionalFormatSet->getCount(); i++) + { + uno::Reference<sheet::XSheetConditionalEntry> xSCENew(aConditionalFormatNew->getByIndex(i), + UNO_QUERY_THROW); + uno::Reference<sheet::XSheetConditionalEntry> 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<sheet::XSheetConditionalEntries> aConditionalFormatLocalGet; + uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatLocalSet; + + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ConditionalFormatLocal", + xSheetCell->getPropertyValue(propName) >>= aConditionalFormatLocalGet); + + uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatLocalNew( + aConditionalFormatLocalGet, UNO_SET_THROW); + aConditionalFormatLocalNew->addNew(aPropValue); + + aNewValue <<= aConditionalFormatLocalNew; + xSheetCell->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aConditionalFormatLocalSet); + for (auto i = 0; i < aConditionalFormatLocalSet->getCount(); i++) + { + uno::Reference<sheet::XSheetConditionalEntry> xSCENew( + aConditionalFormatLocalNew->getByIndex(i), UNO_QUERY_THROW); + uno::Reference<sheet::XSheetConditionalEntry> 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<beans::XPropertySet> aValidationGet; + uno::Reference<beans::XPropertySet> aValidationSet; + + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Validation", + xSheetCell->getPropertyValue(propName) >>= aValidationGet); + + uno::Reference<beans::XPropertySet> aValidationNew(aValidationGet, UNO_SET_THROW); + uno::Any aValidationType; + aValidationType <<= sheet::ValidationType_WHOLE; + aValidationNew->setPropertyValue("Type", aValidationType); + + aNewValue <<= aValidationNew; + xSheetCell->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aValidationSet); + sheet::ValidationType aType; + aValidationSet->getPropertyValue("Type") >>= aType; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue Validation", + sheet::ValidationType_WHOLE, aType); + + propName = "ValidationLocal"; + uno::Reference<beans::XPropertySet> aValidationLocalGet; + uno::Reference<beans::XPropertySet> aValidationLocalSet; + + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ValidationLocal", + xSheetCell->getPropertyValue(propName) >>= aValidationLocalGet); + + uno::Reference<beans::XPropertySet> aValidationLocalNew(aValidationLocalGet, UNO_SET_THROW); + aValidationType <<= sheet::ValidationType_WHOLE; + aValidationLocalNew->setPropertyValue("Type", aValidationType); + + aNewValue <<= aValidationLocalNew; + xSheetCell->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetCell->getPropertyValue(propName) >>= aValidationLocalSet); + aValidationLocalSet->getPropertyValue("Type") >>= aType; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ValidationLocal", + sheet::ValidationType_WHOLE, aType); + + propName = "AbsoluteName"; + OUString aAbsoluteNameGet = ""; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue AbsoluteName", + xSheetCell->getPropertyValue(propName) >>= aAbsoluteNameGet); + + OUString aAbsoluteNameSet = "$Sheet1.$C$3"; + aNewValue <<= aAbsoluteNameSet; + xSheetCell->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetCell->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: */ diff --git a/test/source/sheet/sheetcellrange.cxx b/test/source/sheet/sheetcellrange.cxx new file mode 100644 index 000000000..bf5684936 --- /dev/null +++ b/test/source/sheet/sheetcellrange.cxx @@ -0,0 +1,167 @@ +/* -*- 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 <test/cppunitasserthelper.hxx> +#include <test/sheet/sheetcellrange.hxx> + +#include <com/sun/star/awt/Point.hpp> +#include <com/sun/star/awt/Size.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sheet/ValidationType.hpp> +#include <com/sun/star/sheet/XSheetConditionalEntry.hpp> +#include <com/sun/star/sheet/XSheetConditionalEntries.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <comphelper/propertyvalue.hxx> +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void SheetCellRange::testSheetCellRangeProperties() +{ + uno::Reference<beans::XPropertySet> xSheetCellRange(init(), UNO_QUERY_THROW); + OUString propName; + uno::Any aNewValue; + + propName = "Position"; + awt::Point aPositionGet; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Position", + xSheetCellRange->getPropertyValue(propName) >>= aPositionGet); + + awt::Point aPositionSet(42, 42); + aNewValue <<= aPositionSet; + xSheetCellRange->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetCellRange->getPropertyValue(propName) >>= aPositionSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Able to set PropertyValue Position", aPositionGet, aPositionGet); + + propName = "Size"; + awt::Size aSizeGet; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Size", + xSheetCellRange->getPropertyValue(propName) >>= aSizeGet); + + awt::Size aSizeSet(42, 42); + aNewValue <<= aSizeGet; + xSheetCellRange->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetCellRange->getPropertyValue(propName) >>= aSizeSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Able to set PropertyValue Size", aSizeGet, aSizeSet); + + uno::Sequence<beans::PropertyValue> aPropValue{ comphelper::makePropertyValue( + "StyleName", OUString("Result2")) }; + + propName = "ConditionalFormat"; + uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatGet; + uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatSet; + + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ConditionalFormat", + xSheetCellRange->getPropertyValue(propName) >>= aConditionalFormatGet); + + uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatNew(aConditionalFormatGet, + UNO_SET_THROW); + aConditionalFormatNew->addNew(aPropValue); + + aNewValue <<= aConditionalFormatNew; + xSheetCellRange->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetCellRange->getPropertyValue(propName) >>= aConditionalFormatSet); + for (auto i = 0; i < aConditionalFormatSet->getCount(); i++) + { + uno::Reference<sheet::XSheetConditionalEntry> xSCENew(aConditionalFormatNew->getByIndex(i), + UNO_QUERY_THROW); + uno::Reference<sheet::XSheetConditionalEntry> 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<sheet::XSheetConditionalEntries> aConditionalFormatLocalGet; + uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatLocalSet; + + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ConditionalFormatLocal", + xSheetCellRange->getPropertyValue(propName) + >>= aConditionalFormatLocalGet); + + uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatLocalNew( + aConditionalFormatLocalGet, UNO_SET_THROW); + aConditionalFormatLocalNew->addNew(aPropValue); + + aNewValue <<= aConditionalFormatLocalNew; + xSheetCellRange->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetCellRange->getPropertyValue(propName) >>= aConditionalFormatLocalSet); + for (auto i = 0; i < aConditionalFormatLocalSet->getCount(); i++) + { + uno::Reference<sheet::XSheetConditionalEntry> xSCENew( + aConditionalFormatLocalNew->getByIndex(i), UNO_QUERY_THROW); + uno::Reference<sheet::XSheetConditionalEntry> 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<beans::XPropertySet> aValidationGet; + uno::Reference<beans::XPropertySet> aValidationSet; + + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Validation", + xSheetCellRange->getPropertyValue(propName) >>= aValidationGet); + + uno::Reference<beans::XPropertySet> aValidationNew(aValidationGet, UNO_SET_THROW); + uno::Any aValidationType; + aValidationType <<= sheet::ValidationType_WHOLE; + aValidationNew->setPropertyValue("Type", aValidationType); + + aNewValue <<= aValidationNew; + xSheetCellRange->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetCellRange->getPropertyValue(propName) >>= aValidationSet); + sheet::ValidationType aType; + aValidationSet->getPropertyValue("Type") >>= aType; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue Validation", + sheet::ValidationType_WHOLE, aType); + + propName = "ValidationLocal"; + uno::Reference<beans::XPropertySet> aValidationLocalGet; + uno::Reference<beans::XPropertySet> aValidationLocalSet; + + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ValidationLocal", + xSheetCellRange->getPropertyValue(propName) >>= aValidationLocalGet); + + uno::Reference<beans::XPropertySet> aValidationLocalNew(aValidationLocalGet, UNO_SET_THROW); + aValidationType <<= sheet::ValidationType_WHOLE; + aValidationLocalNew->setPropertyValue("Type", aValidationType); + + aNewValue <<= aValidationLocalNew; + xSheetCellRange->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetCellRange->getPropertyValue(propName) >>= aValidationLocalSet); + aValidationLocalSet->getPropertyValue("Type") >>= aType; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ValidationLocal", + sheet::ValidationType_WHOLE, aType); + + propName = "AbsoluteName"; + OUString aAbsoluteNameGet = ""; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue AbsoluteName", + xSheetCellRange->getPropertyValue(propName) >>= aAbsoluteNameGet); + + OUString aAbsoluteNameSet = "$Sheet1.$C$3"; + aNewValue <<= aAbsoluteNameSet; + xSheetCellRange->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetCellRange->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: */ diff --git a/test/source/sheet/sheetcellranges.cxx b/test/source/sheet/sheetcellranges.cxx new file mode 100644 index 000000000..9611a33bd --- /dev/null +++ b/test/source/sheet/sheetcellranges.cxx @@ -0,0 +1,142 @@ +/* -*- 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 <test/sheet/sheetcellranges.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sheet/ValidationType.hpp> +#include <com/sun/star/sheet/XSheetConditionalEntry.hpp> +#include <com/sun/star/sheet/XSheetConditionalEntries.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <comphelper/propertyvalue.hxx> +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void SheetCellRanges::testSheetCellRangesProperties() +{ + uno::Reference<beans::XPropertySet> xSheetCellRanges(init(), UNO_QUERY_THROW); + OUString propName; + uno::Any aNewValue; + + uno::Sequence<beans::PropertyValue> aPropValue{ comphelper::makePropertyValue( + "StyleName", OUString("Result2")) }; + + propName = "ConditionalFormat"; + uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatGet; + uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatSet; + + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ConditionalFormat", + xSheetCellRanges->getPropertyValue(propName) >>= aConditionalFormatGet); + + uno::Reference<sheet::XSheetConditionalEntries> 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<sheet::XSheetConditionalEntry> xSCENew(aConditionalFormatNew->getByIndex(i), + UNO_QUERY_THROW); + uno::Reference<sheet::XSheetConditionalEntry> 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<sheet::XSheetConditionalEntries> aConditionalFormatLocalGet; + uno::Reference<sheet::XSheetConditionalEntries> aConditionalFormatLocalSet; + + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ConditionalFormatLocal", + xSheetCellRanges->getPropertyValue(propName) + >>= aConditionalFormatLocalGet); + + uno::Reference<sheet::XSheetConditionalEntries> 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<sheet::XSheetConditionalEntry> xSCENew( + aConditionalFormatLocalNew->getByIndex(i), UNO_QUERY_THROW); + uno::Reference<sheet::XSheetConditionalEntry> 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<beans::XPropertySet> aValidationGet; + uno::Reference<beans::XPropertySet> aValidationSet; + + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Validation", + xSheetCellRanges->getPropertyValue(propName) >>= aValidationGet); + + uno::Reference<beans::XPropertySet> aValidationNew(aValidationGet, UNO_SET_THROW); + uno::Any aValidationType; + aValidationType <<= sheet::ValidationType_WHOLE; + aValidationNew->setPropertyValue("Type", aValidationType); + + aNewValue <<= aValidationNew; + xSheetCellRanges->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetCellRanges->getPropertyValue(propName) >>= aValidationSet); + sheet::ValidationType aType; + aValidationSet->getPropertyValue("Type") >>= aType; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue Validation", + sheet::ValidationType_WHOLE, aType); + + propName = "ValidationLocal"; + uno::Reference<beans::XPropertySet> aValidationLocalGet; + uno::Reference<beans::XPropertySet> aValidationLocalSet; + + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ValidationLocal", + xSheetCellRanges->getPropertyValue(propName) >>= aValidationLocalGet); + + uno::Reference<beans::XPropertySet> aValidationLocalNew(aValidationLocalGet, UNO_SET_THROW); + aValidationType <<= sheet::ValidationType_WHOLE; + aValidationLocalNew->setPropertyValue("Type", aValidationType); + + aNewValue <<= aValidationLocalNew; + xSheetCellRanges->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetCellRanges->getPropertyValue(propName) >>= aValidationLocalSet); + aValidationLocalSet->getPropertyValue("Type") >>= aType; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ValidationLocal", + sheet::ValidationType_WHOLE, aType); + + propName = "AbsoluteName"; + OUString aAbsoluteNameGet = ""; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue AbsoluteName", + xSheetCellRanges->getPropertyValue(propName) >>= aAbsoluteNameGet); + + OUString aAbsoluteNameSet = "$Sheet1.$C$3"; + 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: */ diff --git a/test/source/sheet/sheetfilterdescriptor.cxx b/test/source/sheet/sheetfilterdescriptor.cxx new file mode 100644 index 000000000..3a0b1364d --- /dev/null +++ b/test/source/sheet/sheetfilterdescriptor.cxx @@ -0,0 +1,151 @@ +/* -*- 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 <test/cppunitasserthelper.hxx> +#include <test/sheet/sheetfilterdescriptor.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/TableOrientation.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void SheetFilterDescriptor::testSheetFilterDescriptorProperties() +{ + uno::Reference<beans::XPropertySet> xSheetFilterDescriptor(init(), UNO_QUERY_THROW); + OUString propName; + uno::Any aNewValue; + + propName = "IsCaseSensitive"; + bool bIsCaseSensitiveGet = false; + bool bIsCaseSensitiveSet = false; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue IsCaseSensitive", + xSheetFilterDescriptor->getPropertyValue(propName) + >>= bIsCaseSensitiveGet); + + aNewValue <<= !bIsCaseSensitiveGet; + xSheetFilterDescriptor->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetFilterDescriptor->getPropertyValue(propName) >>= bIsCaseSensitiveSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue IsCaseSensitive", + !bIsCaseSensitiveGet, bIsCaseSensitiveSet); + + propName = "SkipDuplicates"; + bool bSkipDuplicatesGet = false; + bool bSkipDuplicatesSet = false; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue SkipDuplicates", + xSheetFilterDescriptor->getPropertyValue(propName) + >>= bSkipDuplicatesGet); + + aNewValue <<= !bSkipDuplicatesGet; + xSheetFilterDescriptor->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetFilterDescriptor->getPropertyValue(propName) >>= bSkipDuplicatesSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue SkipDuplicates", !bSkipDuplicatesGet, + bSkipDuplicatesSet); + + propName = "UseRegularExpressions"; + bool bUseRegularExpressionsGet = false; + bool bUseRegularExpressionsSet = false; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue UseRegularExpressions", + xSheetFilterDescriptor->getPropertyValue(propName) + >>= bUseRegularExpressionsGet); + + aNewValue <<= !bUseRegularExpressionsGet; + xSheetFilterDescriptor->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetFilterDescriptor->getPropertyValue(propName) + >>= bUseRegularExpressionsSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue UseRegularExpressions", + !bUseRegularExpressionsGet, bUseRegularExpressionsSet); + + propName = "SaveOutputPosition"; + bool bSaveOutputPositionGet = false; + bool bSaveOutputPositionSet = false; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue SaveOutputPosition", + xSheetFilterDescriptor->getPropertyValue(propName) + >>= bSaveOutputPositionGet); + + aNewValue <<= !bSaveOutputPositionGet; + xSheetFilterDescriptor->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetFilterDescriptor->getPropertyValue(propName) >>= bSaveOutputPositionSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue SaveOutputPosition", + !bSaveOutputPositionGet, bSaveOutputPositionSet); + + propName = "Orientation"; + table::TableOrientation aOrientationGet; + table::TableOrientation aOrientationSet; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Orientation", + xSheetFilterDescriptor->getPropertyValue(propName) >>= aOrientationGet); + + aNewValue <<= table::TableOrientation_COLUMNS; + xSheetFilterDescriptor->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetFilterDescriptor->getPropertyValue(propName) >>= aOrientationSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue Orientation", + table::TableOrientation_COLUMNS, aOrientationSet); + + propName = "ContainsHeader"; + bool bContainsHeaderGet = false; + bool bContainsHeaderSet = false; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ContainsHeader", + xSheetFilterDescriptor->getPropertyValue(propName) + >>= bContainsHeaderGet); + + aNewValue <<= !bContainsHeaderGet; + xSheetFilterDescriptor->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetFilterDescriptor->getPropertyValue(propName) >>= bContainsHeaderSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ContainsHeader", !bContainsHeaderGet, + bContainsHeaderSet); + + propName = "CopyOutputData"; + bool bCopyOutputDataGet = false; + bool bCopyOutputDataSet = false; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue CopyOutputData", + xSheetFilterDescriptor->getPropertyValue(propName) + >>= bCopyOutputDataGet); + + aNewValue <<= !bCopyOutputDataGet; + xSheetFilterDescriptor->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetFilterDescriptor->getPropertyValue(propName) >>= bCopyOutputDataSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue CopyOutputData", !bCopyOutputDataGet, + bCopyOutputDataSet); + + propName = "OutputPosition"; + table::CellAddress aCellAddressGet; + table::CellAddress aCellAddressSet; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue OutputPosition", + xSheetFilterDescriptor->getPropertyValue(propName) >>= aCellAddressGet); + + aCellAddressGet = table::CellAddress(0, 42, 42); + aNewValue <<= aCellAddressGet; + xSheetFilterDescriptor->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetFilterDescriptor->getPropertyValue(propName) >>= aCellAddressSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue OutputPosition", aCellAddressGet, + aCellAddressSet); + + propName = "MaxFieldCount"; + sal_Int32 nMaxFieldCountGet = 0; + sal_Int32 nMaxFieldCountSet = 0; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue MaxFieldCount", + xSheetFilterDescriptor->getPropertyValue(propName) + >>= nMaxFieldCountGet); + + aNewValue <<= nMaxFieldCountGet + 42; + xSheetFilterDescriptor->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetFilterDescriptor->getPropertyValue(propName) >>= nMaxFieldCountSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Able to set PropertyValue MaxFieldCount", nMaxFieldCountGet, + nMaxFieldCountSet); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/sheetlink.cxx b/test/source/sheet/sheetlink.cxx new file mode 100644 index 000000000..de6a2148e --- /dev/null +++ b/test/source/sheet/sheetlink.cxx @@ -0,0 +1,67 @@ +/* -*- 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 <test/sheet/sheetlink.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void SheetLink::testSheetLinkProperties() +{ + uno::Reference<beans::XPropertySet> xSheetLink(init(), UNO_QUERY_THROW); + OUString propName; + uno::Any aNewValue; + + propName = "Url"; + OUString aUrlGet; + OUString aUrlSet; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Url", + xSheetLink->getPropertyValue(propName) >>= aUrlGet); + + aNewValue <<= OUString("file:///tmp/ScSheetLinkObj.ods"); + xSheetLink->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetLink->getPropertyValue(propName) >>= aUrlSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue Url", + OUString("file:///tmp/ScSheetLinkObj.ods"), aUrlSet); + + propName = "Filter"; + OUString aFilterGet; + OUString aFilterSet; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue Filter", + xSheetLink->getPropertyValue(propName) >>= aFilterGet); + + aNewValue <<= OUString("Text - txt - csv (StarCalc)"); + xSheetLink->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetLink->getPropertyValue(propName) >>= aFilterSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue Filter", + OUString("Text - txt - csv (StarCalc)"), aFilterSet); + + propName = "FilterOptions"; + OUString aFilterOptionsGet; + OUString aFilterOptionsSet; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue FilterOptions", + xSheetLink->getPropertyValue(propName) >>= aFilterOptionsGet); + + aNewValue <<= OUString("NewValue"); + xSheetLink->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSheetLink->getPropertyValue(propName) >>= aFilterOptionsSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue FilterOptions", OUString("NewValue"), + aFilterOptionsSet); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/sheetsortdescriptor2.cxx b/test/source/sheet/sheetsortdescriptor2.cxx new file mode 100644 index 000000000..3f84d9577 --- /dev/null +++ b/test/source/sheet/sheetsortdescriptor2.cxx @@ -0,0 +1,123 @@ +/* -*- 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 <test/cppunitasserthelper.hxx> +#include <test/sheet/sheetsortdescriptor2.hxx> + +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/util/XSortable.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/TableSortField.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +#include <vector> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void SheetSortDescriptor2::testSheetSortDescriptor2Properties() +{ + uno::Reference<util::XSortable> xSortable(init(), UNO_QUERY_THROW); + const uno::Sequence<beans::PropertyValue> values = xSortable->createSortDescriptor(); + + std::vector<OUString> names; + // Only test the get/read operation of the values, because set/write operation doesn't + // make any sense. It doesn't trigger any changes. + // See discussion: nabble.documentfoundation.org/Testing-UNO-API-service-properties-td4236286.html. + for (const auto& value : values) + { + if (value.Name == "BindFormatsToContent") + { + names.push_back(value.Name); + bool bValue = false; + CPPUNIT_ASSERT(value.Value >>= bValue); + } + else if (value.Name == "IsUserListEnabled") + { + names.push_back(value.Name); + bool bValue = false; + CPPUNIT_ASSERT(value.Value >>= bValue); + } + else if (value.Name == "UserListIndex") + { + names.push_back(value.Name); + sal_Int32 nValue = 0; + CPPUNIT_ASSERT(value.Value >>= nValue); + } + else if (value.Name == "CopyOutputData") + { + names.push_back(value.Name); + bool bValue = false; + CPPUNIT_ASSERT(value.Value >>= bValue); + } + else if (value.Name == "OutputPosition") + { + names.push_back(value.Name); + table::CellAddress cellAddr; + CPPUNIT_ASSERT(value.Value >>= cellAddr); + } + else if (value.Name == "SortFields") + { + names.push_back(value.Name); + uno::Sequence<table::TableSortField> sSortFields; + CPPUNIT_ASSERT(value.Value >>= sSortFields); + } + else if (value.Name == "MaxFieldCount") + { + names.push_back(value.Name); + sal_Int32 nValue = 0; + CPPUNIT_ASSERT(value.Value >>= nValue); + } + else if (value.Name == "IsSortColumns") + { + names.push_back(value.Name); + bool bValue = false; + CPPUNIT_ASSERT(value.Value >>= bValue); + } + else if (value.Name == "ContainsHeader") + { + names.push_back(value.Name); + bool bValue = false; + CPPUNIT_ASSERT(value.Value >>= bValue); + } + else + { + OString sMsg = "Unsupported PropertyValue: " + + OUStringToOString(value.Name, RTL_TEXTENCODING_UTF8); + CPPUNIT_FAIL(sMsg.getStr()); + } + } + + CPPUNIT_ASSERT_MESSAGE("Property BindFormatsToContent not found", + std::count(std::begin(names), std::end(names), "BindFormatsToContent")); + CPPUNIT_ASSERT_MESSAGE("Property IsUserListEnabled not found", + std::count(std::begin(names), std::end(names), "IsUserListEnabled")); + CPPUNIT_ASSERT_MESSAGE("Property UserListIndex not found", + std::count(std::begin(names), std::end(names), "UserListIndex")); + CPPUNIT_ASSERT_MESSAGE("Property CopyOutputData not found", + std::count(std::begin(names), std::end(names), "CopyOutputData")); + CPPUNIT_ASSERT_MESSAGE("Property OutputPosition not found", + std::count(std::begin(names), std::end(names), "OutputPosition")); + CPPUNIT_ASSERT_MESSAGE("Property SortFields not found", + std::count(std::begin(names), std::end(names), "SortFields")); + CPPUNIT_ASSERT_MESSAGE("Property MaxFieldCount not found", + std::count(std::begin(names), std::end(names), "MaxFieldCount")); + CPPUNIT_ASSERT_MESSAGE("Property IsSortColumns not found", + std::count(std::begin(names), std::end(names), "IsSortColumns")); + CPPUNIT_ASSERT_MESSAGE("Property ContainsHeader not found", + std::count(std::begin(names), std::end(names), "ContainsHeader")); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/spreadsheet.cxx b/test/source/sheet/spreadsheet.cxx new file mode 100644 index 000000000..8e2ca12cf --- /dev/null +++ b/test/source/sheet/spreadsheet.cxx @@ -0,0 +1,90 @@ +/* -*- 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 <test/sheet/spreadsheet.hxx> +#include <test/unoapi_property_testers.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/sheet/XConditionalFormats.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/text/WritingMode2.hpp> +#include <com/sun/star/util/Color.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void Spreadsheet::testSpreadsheetProperties() +{ + uno::Reference<beans::XPropertySet> xSpreadsheet(init(), UNO_QUERY_THROW); + OUString propName; + uno::Any aNewValue; + + propName = "IsVisible"; + testBooleanProperty(xSpreadsheet, propName); + + propName = "PageStyle"; + testStringProperty(xSpreadsheet, propName, "Report"); + + propName = "TableLayout"; + testShortProperty(xSpreadsheet, propName, text::WritingMode2::RL_TB); + + propName = "AutomaticPrintArea"; + testBooleanProperty(xSpreadsheet, propName); + + propName = "TabColor"; + util::Color aColorGet; + util::Color aColorSet; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue: TabColor", + xSpreadsheet->getPropertyValue(propName) >>= aColorGet); + + aNewValue <<= util::Color(42); + xSpreadsheet->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheet->getPropertyValue(propName) >>= aColorSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue: TabColor", util::Color(42), + aColorSet); + + propName = "ConditionalFormats"; + uno::Reference<sheet::XConditionalFormats> xConditionalFormatsGet; + uno::Reference<sheet::XConditionalFormats> xConditionalFormatsSet; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue: ConditionalFormats", + xSpreadsheet->getPropertyValue(propName) >>= xConditionalFormatsGet); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(getXSpreadsheetDocument(), UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), UNO_QUERY_THROW); + + uno::Reference<lang::XMultiServiceFactory> xMSF(xDoc, UNO_QUERY_THROW); + uno::Reference<container::XNameContainer> xRanges( + xMSF->createInstance("com.sun.star.sheet.SheetCellRanges"), UNO_QUERY_THROW); + uno::Reference<sheet::XSheetCellRanges> xSheetCellRanges(xRanges, UNO_QUERY_THROW); + + uno::Any xCellRange; + xCellRange <<= xSheet->getCellRangeByName("C1:D4"); + xRanges->insertByName("Range1", xCellRange); + xConditionalFormatsGet->createByRange(xSheetCellRanges); + + aNewValue <<= xConditionalFormatsGet; + xSpreadsheet->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheet->getPropertyValue(propName) >>= xConditionalFormatsSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue: ConditionalFormats", sal_Int32(1), + xConditionalFormatsSet->getLength()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/spreadsheetdocumentsettings.cxx b/test/source/sheet/spreadsheetdocumentsettings.cxx new file mode 100644 index 000000000..a1eec4d0d --- /dev/null +++ b/test/source/sheet/spreadsheetdocumentsettings.cxx @@ -0,0 +1,190 @@ +/* -*- 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 <test/unoapi_property_testers.hxx> +#include <test/sheet/spreadsheetdocumentsettings.hxx> + +#include <com/sun/star/awt/XDevice.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/lang/Locale.hpp> +#include <com/sun/star/i18n/XForbiddenCharacters.hpp> +#include <com/sun/star/util/Date.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void SpreadsheetDocumentSettings::testSpreadsheetDocumentSettingsProperties() +{ + uno::Reference<beans::XPropertySet> xSpreadsheetDocumentSettings(init(), UNO_QUERY_THROW); + OUString propName; + uno::Any aNewValue; + + propName = "IsIterationEnabled"; + testBooleanProperty(xSpreadsheetDocumentSettings, propName); + + propName = "IterationCount"; + testLongProperty(xSpreadsheetDocumentSettings, propName); + + propName = "IterationEpsilon"; + testDoubleProperty(xSpreadsheetDocumentSettings, propName); + + propName = "StandardDecimals"; + testShortProperty(xSpreadsheetDocumentSettings, propName); + + propName = "NullDate"; + util::Date aNullDateGet; + util::Date aNullDateSet; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue: NullDate", + xSpreadsheetDocumentSettings->getPropertyValue(propName) + >>= aNullDateGet); + + aNewValue <<= util::Date(1, 1, 2000); + xSpreadsheetDocumentSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetDocumentSettings->getPropertyValue(propName) >>= aNullDateSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue: NullDate", sal_Int16(2000), + aNullDateSet.Year); + + propName = "DefaultTabStop"; + testShortProperty(xSpreadsheetDocumentSettings, propName); + + propName = "IgnoreCase"; + testBooleanProperty(xSpreadsheetDocumentSettings, propName); + + propName = "CalcAsShown"; + testBooleanProperty(xSpreadsheetDocumentSettings, propName); + + propName = "MatchWholeCell"; + testBooleanProperty(xSpreadsheetDocumentSettings, propName); + + propName = "SpellOnline"; + testBooleanProperty(xSpreadsheetDocumentSettings, propName); + + propName = "LookUpLabels"; + testBooleanProperty(xSpreadsheetDocumentSettings, propName); + + propName = "RegularExpressions"; + testBooleanProperty(xSpreadsheetDocumentSettings, propName); + + propName = "ForbiddenCharacters"; + uno::Reference<i18n::XForbiddenCharacters> xForbiddenCharactersGet; + uno::Reference<i18n::XForbiddenCharacters> xForbiddenCharactersSet; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue: ForbiddenCharacters", + xSpreadsheetDocumentSettings->getPropertyValue(propName) + >>= xForbiddenCharactersGet); + + lang::Locale aForbiddenCharactersLocale; + aForbiddenCharactersLocale.Language = "ru"; + aForbiddenCharactersLocale.Country = "RU"; + + uno::Reference<i18n::XForbiddenCharacters> xForbiddenCharactersNew; + aNewValue <<= xForbiddenCharactersNew; + xSpreadsheetDocumentSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetDocumentSettings->getPropertyValue(propName) + >>= xForbiddenCharactersSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Able to set PropertyValue: ForbiddenCharacters", + xForbiddenCharactersGet->hasForbiddenCharacters(aForbiddenCharactersLocale), + xForbiddenCharactersSet->hasForbiddenCharacters(aForbiddenCharactersLocale)); + + propName = "HasDrawPages"; + testBooleanReadonlyProperty(xSpreadsheetDocumentSettings, propName); + + propName = "CharLocale"; + lang::Locale aCharLocaleGet; + lang::Locale aCharLocaleSet; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue: CharLocale", + xSpreadsheetDocumentSettings->getPropertyValue(propName) + >>= aCharLocaleGet); + + lang::Locale aCharLocaleNew; + aCharLocaleNew.Language = "en"; + aCharLocaleNew.Country = "CA"; + aNewValue <<= aCharLocaleNew; + xSpreadsheetDocumentSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetDocumentSettings->getPropertyValue(propName) >>= aCharLocaleSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue: CharLocale", aCharLocaleNew.Country, + aCharLocaleSet.Country); + + propName = "CharLocaleAsian"; + lang::Locale aCharLocaleAsianGet; + lang::Locale aCharLocaleAsianSet; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue: CharLocaleAsian", + xSpreadsheetDocumentSettings->getPropertyValue(propName) + >>= aCharLocaleAsianGet); + + lang::Locale aCharLocaleAsianNew; + aCharLocaleAsianNew.Language = "en"; + aCharLocaleAsianNew.Country = "CA"; + aNewValue <<= aCharLocaleAsianNew; + xSpreadsheetDocumentSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetDocumentSettings->getPropertyValue(propName) + >>= aCharLocaleAsianSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue: CharLocaleAsian", + aCharLocaleAsianNew.Country, aCharLocaleAsianSet.Country); + + propName = "CharLocaleComplex"; + lang::Locale aCharLocaleComplexGet; + lang::Locale aCharLocaleComplexSet; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue: CharLocaleComplex", + xSpreadsheetDocumentSettings->getPropertyValue(propName) + >>= aCharLocaleComplexGet); + + lang::Locale aCharLocaleComplexNew; + aCharLocaleComplexNew.Language = "en"; + aCharLocaleComplexNew.Country = "CA"; + aNewValue <<= aCharLocaleComplexNew; + xSpreadsheetDocumentSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetDocumentSettings->getPropertyValue(propName) + >>= aCharLocaleComplexSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue: CharLocaleComplex", + aCharLocaleComplexNew.Country, aCharLocaleComplexSet.Country); + + propName = "IsLoaded"; + testBooleanProperty(xSpreadsheetDocumentSettings, propName); + + propName = "IsUndoEnabled"; + testBooleanProperty(xSpreadsheetDocumentSettings, propName); + + propName = "IsAdjustHeightEnabled"; + testBooleanProperty(xSpreadsheetDocumentSettings, propName); + + propName = "IsExecuteLinkEnabled"; + testBooleanProperty(xSpreadsheetDocumentSettings, propName); + + propName = "ReferenceDevice"; + uno::Reference<awt::XDevice> xDeviceGet; + uno::Reference<awt::XDevice> xDeviceSet; + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue: ReferenceDevice", + xSpreadsheetDocumentSettings->getPropertyValue(propName) >>= xDeviceGet); + + uno::Reference<awt::XDevice> xDeviceNew; + aNewValue <<= xDeviceNew; + xSpreadsheetDocumentSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetDocumentSettings->getPropertyValue(propName) >>= xDeviceSet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Able to set PropertyValue: ReferenceDevice", + xDeviceSet->getInfo().Width, xDeviceGet->getInfo().Width); + + propName = "RecordChanges"; + testBooleanProperty(xSpreadsheetDocumentSettings, propName); + + propName = "IsRecordChangesProtected"; + testBooleanReadonlyProperty(xSpreadsheetDocumentSettings, propName); + + propName = "Wildcards"; + testBooleanProperty(xSpreadsheetDocumentSettings, propName); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/spreadsheetviewsettings.cxx b/test/source/sheet/spreadsheetviewsettings.cxx new file mode 100644 index 000000000..1a5916dcf --- /dev/null +++ b/test/source/sheet/spreadsheetviewsettings.cxx @@ -0,0 +1,251 @@ +/* -*- 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 <test/sheet/spreadsheetviewsettings.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/util/Color.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void SpreadsheetViewSettings::testSpreadsheetViewSettingsProperties() +{ + uno::Reference<beans::XPropertySet> xSpreadsheetViewSettings(init(), UNO_QUERY_THROW); + OUString propName; + uno::Any aNewValue; + + propName = "ShowFormulas"; + bool aShowFormulas = true; + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aShowFormulas); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ShowFormulas", !aShowFormulas); + + aNewValue <<= true; + xSpreadsheetViewSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aShowFormulas); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue ShowFormulas", aShowFormulas); + + propName = "ShowZeroValues"; + bool aShowZeroValues = false; + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aShowZeroValues); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ShowZeroValues", aShowZeroValues); + + aNewValue <<= false; + xSpreadsheetViewSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aShowZeroValues); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue ShowZeroValues", !aShowZeroValues); + + propName = "IsValueHighlightingEnabled"; + bool aIsValueHighlightingEnabled = true; + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) + >>= aIsValueHighlightingEnabled); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue IsValueHighlightingEnabled", + !aIsValueHighlightingEnabled); + + aNewValue <<= true; + xSpreadsheetViewSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) + >>= aIsValueHighlightingEnabled); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue IsValueHighlightingEnabled", + aIsValueHighlightingEnabled); + + propName = "ShowNotes"; + bool aShowNotes = false; + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aShowNotes); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ShowNotes", aShowNotes); + + aNewValue <<= false; + xSpreadsheetViewSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aShowNotes); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue ShowNotes", !aShowNotes); + + propName = "HasVerticalScrollBar"; + bool aHasVerticalScrollBar = false; + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aHasVerticalScrollBar); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue HasVerticalScrollBar", + aHasVerticalScrollBar); + + aNewValue <<= false; + xSpreadsheetViewSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aHasVerticalScrollBar); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue HasVerticalScrollBar", + !aHasVerticalScrollBar); + + propName = "HasHorizontalScrollBar"; + bool aHasHorizontalScrollBar = false; + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) + >>= aHasHorizontalScrollBar); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue HasHorizontalScrollBar", + aHasHorizontalScrollBar); + + aNewValue <<= false; + xSpreadsheetViewSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) + >>= aHasHorizontalScrollBar); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue HasHorizontalScrollBar", + !aHasHorizontalScrollBar); + + propName = "HasSheetTabs"; + bool aHasSheetTabs = false; + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aHasSheetTabs); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue HasSheetTabs", aHasSheetTabs); + + aNewValue <<= false; + xSpreadsheetViewSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aHasSheetTabs); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue HasSheetTabs", !aHasSheetTabs); + + propName = "IsOutlineSymbolsSet"; + bool aIsOutlineSymbolsSet = false; + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aIsOutlineSymbolsSet); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue IsOutlineSymbolsSet", aIsOutlineSymbolsSet); + + aNewValue <<= false; + xSpreadsheetViewSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aIsOutlineSymbolsSet); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue IsOutlineSymbolsSet", + !aIsOutlineSymbolsSet); + + propName = "HasColumnRowHeaders"; + bool aHasColumnRowHeaders = false; + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aHasColumnRowHeaders); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue HasColumnRowHeaders", aHasColumnRowHeaders); + + aNewValue <<= false; + xSpreadsheetViewSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aHasColumnRowHeaders); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue HasColumnRowHeaders", + !aHasColumnRowHeaders); + + propName = "ShowGrid"; + bool aShowGrid = false; + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aShowGrid); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ShowGrid", aShowGrid); + + aNewValue <<= false; + xSpreadsheetViewSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aShowGrid); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue ShowGrid", !aShowGrid); + + propName = "GridColor"; + util::Color aGridColor; + xSpreadsheetViewSettings->getPropertyValue(propName) >>= aGridColor; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue GridColor", sal_Int32(12632256), + aGridColor); + + aNewValue <<= sal_Int32(42); + xSpreadsheetViewSettings->setPropertyValue(propName, aNewValue); + xSpreadsheetViewSettings->getPropertyValue(propName) >>= aGridColor; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue GridColor", sal_Int32(42), + aGridColor); + + propName = "ShowHelpLines"; + bool aShowHelpLines = true; + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aShowHelpLines); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ShowHelpLines", !aShowHelpLines); + + aNewValue <<= true; + xSpreadsheetViewSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aShowHelpLines); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue ShowHelpLines", aShowHelpLines); + + propName = "ShowAnchor"; + bool aShowAnchor = false; + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aShowAnchor); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ShowAnchor", aShowAnchor); + + aNewValue <<= false; + xSpreadsheetViewSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aShowAnchor); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue ShowAnchor", !aShowAnchor); + + propName = "ShowPageBreaks"; + bool aShowPageBreaks = false; + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aShowPageBreaks); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue ShowPageBreaks", aShowPageBreaks); + + aNewValue <<= false; + xSpreadsheetViewSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aShowPageBreaks); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue ShowPageBreaks", !aShowPageBreaks); + + propName = "ShowObjects"; + sal_Int16 aShowObjects = 42; + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aShowObjects); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue ShowObjects", sal_Int16(0), + aShowObjects); + + aNewValue <<= sal_Int16(1); + xSpreadsheetViewSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aShowObjects); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ShowObjects", sal_Int16(1), + aShowObjects); + + propName = "ShowCharts"; + sal_Int16 aShowCharts = 42; + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aShowCharts); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue ShowCharts", sal_Int16(0), + aShowCharts); + + aNewValue <<= sal_Int16(1); + xSpreadsheetViewSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aShowCharts); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ShowCharts", sal_Int16(1), + aShowCharts); + + propName = "ShowDrawing"; + sal_Int16 aShowDrawing = 42; + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aShowDrawing); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue ShowDrawing", sal_Int16(0), + aShowDrawing); + + aNewValue <<= sal_Int16(1); + xSpreadsheetViewSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aShowDrawing); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ShowDrawing", sal_Int16(1), + aShowDrawing); + + propName = "ZoomType"; + sal_Int16 aZoomType = 42; + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aZoomType); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue ZoomType", sal_Int16(3), aZoomType); + + aNewValue <<= sal_Int16(1); + xSpreadsheetViewSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aZoomType); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ZoomType", sal_Int16(1), aZoomType); + + propName = "ZoomValue"; + sal_Int16 aZoomValue = 42; + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aZoomValue); + + aNewValue <<= sal_Int16(1); + xSpreadsheetViewSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aZoomValue); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue ZoomValue", sal_Int16(1), aZoomValue); + + propName = "FormulaBarHeight"; + sal_Int16 aFormulaBarHeight; + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aFormulaBarHeight); + + aNewValue <<= sal_Int16(15); + xSpreadsheetViewSettings->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSpreadsheetViewSettings->getPropertyValue(propName) >>= aFormulaBarHeight); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue FormulaBarHeight", sal_Int16(15), + aFormulaBarHeight); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/subtotaldescriptor.cxx b/test/source/sheet/subtotaldescriptor.cxx new file mode 100644 index 000000000..e9dffdb75 --- /dev/null +++ b/test/source/sheet/subtotaldescriptor.cxx @@ -0,0 +1,116 @@ +/* -*- 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 <test/sheet/subtotaldescriptor.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void SubTotalDescriptor::testSubTotalDescriptorProperties() +{ + uno::Reference<beans::XPropertySet> xSubTotalDescriptor(init(), UNO_QUERY_THROW); + OUString propName; + uno::Any aNewValue; + + propName = "InsertPageBreaks"; + bool aInsertPageBreaks = true; + CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aInsertPageBreaks); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue InsertPageBreaks", !aInsertPageBreaks); + + aNewValue <<= true; + xSubTotalDescriptor->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aInsertPageBreaks); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue InsertPageBreaks", aInsertPageBreaks); + + propName = "IsCaseSensitive"; + bool aIsCaseSensitive = true; + CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aIsCaseSensitive); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue IsCaseSensitive", !aIsCaseSensitive); + + aNewValue <<= true; + xSubTotalDescriptor->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aIsCaseSensitive); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue IsCaseSensitive", aIsCaseSensitive); + + propName = "EnableUserSortList"; + bool aEnableUserSortList = true; + CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aEnableUserSortList); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue EnableUserSortList", !aEnableUserSortList); + + aNewValue <<= true; + xSubTotalDescriptor->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aEnableUserSortList); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue EnableUserSortList", aEnableUserSortList); + + propName = "UserSortListIndex"; + sal_Int32 aUserSortListIndex = 42; + CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aUserSortListIndex); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue UserSortListIndex", sal_Int32(0), + aUserSortListIndex); + + aNewValue <<= sal_Int32(42); + xSubTotalDescriptor->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aUserSortListIndex); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue UserSortListIndex", sal_Int32(42), + aUserSortListIndex); + + propName = "BindFormatsToContent"; + bool aBindFormatsToContent = true; + CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aBindFormatsToContent); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue BindFormatsToContent", + !aBindFormatsToContent); + + aNewValue <<= true; + xSubTotalDescriptor->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aBindFormatsToContent); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue BindFormatsToContent", + aBindFormatsToContent); + + propName = "EnableSort"; + bool aEnableSort = false; + CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aEnableSort); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue EnableSort", aEnableSort); + + aNewValue <<= false; + xSubTotalDescriptor->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aEnableSort); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue EnableSort", !aEnableSort); + + propName = "SortAscending"; + bool aSortAscending = false; + CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aSortAscending); + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue SortAscending", aSortAscending); + + aNewValue <<= false; + xSubTotalDescriptor->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aSortAscending); + CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue SortAscending", !aSortAscending); + + propName = "MaxFieldCount"; + sal_Int32 aMaxFieldCount = 42; + CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aMaxFieldCount); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue MaxFieldCount", sal_Int32(3), + aMaxFieldCount); + + aNewValue <<= sal_Int32(42); + CPPUNIT_ASSERT_THROW_MESSAGE("Able to change PropertyValue MaxFieldCount", + xSubTotalDescriptor->setPropertyValue(propName, aNewValue), + lang::IllegalArgumentException); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/tableautoformat.cxx b/test/source/sheet/tableautoformat.cxx new file mode 100644 index 000000000..2d5595f0a --- /dev/null +++ b/test/source/sheet/tableautoformat.cxx @@ -0,0 +1,94 @@ +/* -*- 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 <test/sheet/tableautoformat.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void TableAutoFormat::testTableAutoFormatProperties() +{ + uno::Reference<beans::XPropertySet> xTableAutoFormat(init(), UNO_QUERY_THROW); + OUString propName; + uno::Any aNewValue; + + propName = "IncludeFont"; + bool aIncludeFont = false; + CPPUNIT_ASSERT_MESSAGE("Unable to get property value IncludeFont", + xTableAutoFormat->getPropertyValue(propName) >>= aIncludeFont); + + aNewValue <<= false; + xTableAutoFormat->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xTableAutoFormat->getPropertyValue(propName) >>= aIncludeFont); + CPPUNIT_ASSERT_MESSAGE("Unable to set property value IncludeFont", !aIncludeFont); + + propName = "IncludeJustify"; + bool aIncludeJustify = false; + CPPUNIT_ASSERT_MESSAGE("Unable to get property value IncludeJustify", + xTableAutoFormat->getPropertyValue(propName) >>= aIncludeJustify); + + aNewValue <<= false; + xTableAutoFormat->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xTableAutoFormat->getPropertyValue(propName) >>= aIncludeJustify); + CPPUNIT_ASSERT_MESSAGE("Unable to set property value IncludeJustify", !aIncludeJustify); + + propName = "IncludeBorder"; + bool aIncludeBorder = false; + CPPUNIT_ASSERT_MESSAGE("Unable to get property value IncludeBorder", + xTableAutoFormat->getPropertyValue(propName) >>= aIncludeBorder); + + aNewValue <<= false; + xTableAutoFormat->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xTableAutoFormat->getPropertyValue(propName) >>= aIncludeBorder); + CPPUNIT_ASSERT_MESSAGE("Unable to set property value IncludeBorder", !aIncludeBorder); + + propName = "IncludeBackground"; + bool aIncludeBackground = false; + CPPUNIT_ASSERT_MESSAGE("Unable to get property value IncludeBackground", + xTableAutoFormat->getPropertyValue(propName) >>= aIncludeBackground); + + aNewValue <<= false; + xTableAutoFormat->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xTableAutoFormat->getPropertyValue(propName) >>= aIncludeBackground); + CPPUNIT_ASSERT_MESSAGE("Unable to set property value IncludeBackground", !aIncludeBackground); + + propName = "IncludeNumberFormat"; + bool aIncludeNumberFormat = false; + CPPUNIT_ASSERT_MESSAGE("Unable to get property value IncludeNumberFormat", + xTableAutoFormat->getPropertyValue(propName) >>= aIncludeNumberFormat); + + aNewValue <<= false; + xTableAutoFormat->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xTableAutoFormat->getPropertyValue(propName) >>= aIncludeNumberFormat); + CPPUNIT_ASSERT_MESSAGE("Unable to set property value IncludeNumberFormat", + !aIncludeNumberFormat); + + propName = "IncludeWidthAndHeight"; + bool aIncludeWidthAndHeight = false; + CPPUNIT_ASSERT(xTableAutoFormat->getPropertyValue(propName) >>= aIncludeWidthAndHeight); + CPPUNIT_ASSERT_MESSAGE("Unable to get property value IncludeWidthAndHeight", + aIncludeWidthAndHeight); + + aNewValue <<= false; + xTableAutoFormat->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xTableAutoFormat->getPropertyValue(propName) >>= aIncludeWidthAndHeight); + CPPUNIT_ASSERT_MESSAGE("Unable to set property value IncludeWidthAndHeight", + !aIncludeWidthAndHeight); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/tablevalidation.cxx b/test/source/sheet/tablevalidation.cxx new file mode 100644 index 000000000..438301960 --- /dev/null +++ b/test/source/sheet/tablevalidation.cxx @@ -0,0 +1,153 @@ +/* -*- 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 <test/sheet/tablevalidation.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sheet/ValidationAlertStyle.hpp> +#include <com/sun/star/sheet/ValidationType.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void TableValidation::testTableValidationProperties() +{ + uno::Reference<beans::XPropertySet> xTableValidation(init(), UNO_QUERY_THROW); + OUString propName; + uno::Any aNewValue; + + propName = "Type"; + uno::Any aValue = xTableValidation->getPropertyValue(propName); + sheet::ValidationType aValidationType; + aValue >>= aValidationType; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value Type", sheet::ValidationType_ANY, + aValidationType); + + aNewValue <<= sheet::ValidationType_WHOLE; + xTableValidation->setPropertyValue(propName, aNewValue); + aValue = xTableValidation->getPropertyValue(propName); + aValue >>= aValidationType; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set property value Type", sheet::ValidationType_WHOLE, + aValidationType); + + propName = "ShowInputMessage"; + bool aShowInputMessage = true; + CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aShowInputMessage); + CPPUNIT_ASSERT_MESSAGE("Unable to get property value ShowInputMessage", !aShowInputMessage); + + aNewValue <<= true; + xTableValidation->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aShowInputMessage); + CPPUNIT_ASSERT_MESSAGE("Unable to set property value ShowInputMessage", aShowInputMessage); + + // only possible if ShowInputMessage is true + propName = "InputMessage"; + OUString aInputMessage; + CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aInputMessage); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value InputMessage", OUString(""), + aInputMessage); + + aNewValue <<= OUString("UnitTest InputMessage"); + xTableValidation->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aInputMessage); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value InputMessage", + OUString("UnitTest InputMessage"), aInputMessage); + + // only possible if ShowInputMessage is true + propName = "InputTitle"; + OUString aInputTitle; + CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aInputTitle); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value InputTitle", OUString(""), + aInputTitle); + + aNewValue <<= OUString("UnitTest InputTitle"); + xTableValidation->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aInputTitle); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value InputTitle", + OUString("UnitTest InputTitle"), aInputTitle); + + propName = "ShowErrorMessage"; + bool aShowErrorMessage = true; + CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aShowErrorMessage); + CPPUNIT_ASSERT_MESSAGE("Unable to get property value ShowErrorMessage", !aShowErrorMessage); + + aNewValue <<= true; + xTableValidation->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aShowErrorMessage); + CPPUNIT_ASSERT_MESSAGE("Unable to set property value ShowErrorMessage", aShowErrorMessage); + + // only possible if ShowErrorMessage is true + propName = "ErrorMessage"; + OUString aErrorMessage; + CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aErrorMessage); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value ErrorMessage", OUString(""), + aErrorMessage); + + aNewValue <<= OUString("UnitTest ErrorMessage"); + xTableValidation->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aErrorMessage); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value ErrorMessage", + OUString("UnitTest ErrorMessage"), aErrorMessage); + + // only possible if ShowErrorMessage is true + propName = "ErrorTitle"; + OUString aErrorTitle; + CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aErrorTitle); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value ErrorTitle", OUString(""), + aErrorTitle); + + aNewValue <<= OUString("UnitTest ErrorTitle"); + xTableValidation->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aErrorTitle); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value ErrorTitle", + OUString("UnitTest ErrorTitle"), aErrorTitle); + + propName = "IgnoreBlankCells"; + bool aIgnoreBlankCells = false; + CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aIgnoreBlankCells); + CPPUNIT_ASSERT_MESSAGE("Unable to get property value IgnoreBlankCells", aIgnoreBlankCells); + + aNewValue <<= false; + xTableValidation->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aIgnoreBlankCells); + CPPUNIT_ASSERT_MESSAGE("Unable to set property value IgnoreBlankCells", !aIgnoreBlankCells); + + propName = "ErrorAlertStyle"; + aValue = xTableValidation->getPropertyValue(propName); + sheet::ValidationAlertStyle aValidationAlertStyle; + aValue >>= aValidationAlertStyle; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value ValidationAlertStyle", + sheet::ValidationAlertStyle_STOP, aValidationAlertStyle); + + aNewValue <<= sheet::ValidationAlertStyle_WARNING; + xTableValidation->setPropertyValue(propName, aNewValue); + aValue = xTableValidation->getPropertyValue(propName); + aValue >>= aValidationAlertStyle; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set property value ValidationAlertStyle", + sheet::ValidationAlertStyle_WARNING, aValidationAlertStyle); + + propName = "ShowList"; + sal_Int16 aShowList = 0; + CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aShowList); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value ShowList", sal_Int16(1), aShowList); + + aNewValue <<= sal_Int16(42); + xTableValidation->setPropertyValue(propName, aNewValue); + CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aShowList); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set property value ShowList", sal_Int16(42), aShowList); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xactivationbroadcaster.cxx b/test/source/sheet/xactivationbroadcaster.cxx new file mode 100644 index 000000000..6c7769db5 --- /dev/null +++ b/test/source/sheet/xactivationbroadcaster.cxx @@ -0,0 +1,70 @@ +/* -*- 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 <test/sheet/xactivationbroadcaster.hxx> + +#include <com/sun/star/lang/EventObject.hpp> +#include <com/sun/star/sheet/ActivationEvent.hpp> +#include <com/sun/star/sheet/XActivationBroadcaster.hpp> +#include <com/sun/star/sheet/XActivationEventListener.hpp> +#include <com/sun/star/sheet/XSpreadsheetView.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppuhelper/implbase.hxx> +#include <rtl/ref.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +namespace +{ +class MockedActivationEventListener : public ::cppu::WeakImplHelper<sheet::XActivationEventListener> +{ +public: + MockedActivationEventListener() + : mbListenerCalled(false) + { + } + bool mbListenerCalled; + virtual void SAL_CALL + activeSpreadsheetChanged(const sheet::ActivationEvent& /* xEvent */) override + { + mbListenerCalled = true; + } + virtual void SAL_CALL disposing(const lang::EventObject& /* xEventObj */) override {} +}; +} + +void XActivationBroadcaster::testAddRemoveActivationEventListener() +{ + uno::Reference<sheet::XActivationBroadcaster> xAB(init(), UNO_QUERY_THROW); + xAB->addActivationEventListener(nullptr); + + rtl::Reference<MockedActivationEventListener> xListener = new MockedActivationEventListener(); + xAB->addActivationEventListener(uno::Reference<sheet::XActivationEventListener>(xListener)); + + uno::Reference<sheet::XSpreadsheetView> xView(xAB, UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet1(xView->getActiveSheet(), UNO_SET_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet2(getXSpreadsheet(1), UNO_QUERY_THROW); + + xView->setActiveSheet(xSheet2); + + CPPUNIT_ASSERT_MESSAGE("Listener wasn't called", xListener->mbListenerCalled); + + xAB->removeActivationEventListener(uno::Reference<sheet::XActivationEventListener>(xListener)); + xView->setActiveSheet(xSheet1); + CPPUNIT_ASSERT_MESSAGE("Listener still called after removal", xListener->mbListenerCalled); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xarealink.cxx b/test/source/sheet/xarealink.cxx new file mode 100644 index 000000000..77e9cb98b --- /dev/null +++ b/test/source/sheet/xarealink.cxx @@ -0,0 +1,65 @@ +/* -*- 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 <test/sheet/xarealink.hxx> +#include <test/cppunitasserthelper.hxx> + +#include <com/sun/star/sheet/XAreaLink.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest { + +void XAreaLink::testSetDestArea() +{ + uno::Reference< sheet::XAreaLink > xAreaLink(init(), UNO_QUERY_THROW); + + xAreaLink->setDestArea(table::CellRangeAddress(1,3,4,5,8)); + // After setting the destination area, the link is refreshed and the area + // is adjusted to the size of the source data. + // Only test the 'Sheet', 'StartCol', and 'StartRow' + table::CellRangeAddress aDestArea = xAreaLink->getDestArea(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Couldn't set new DestArea (Sheet)", sal_Int16(1), aDestArea.Sheet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Couldn't set new DestArea (StartCol)", sal_Int32(3), aDestArea.StartColumn); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Couldn't set new DestArea (StartRow)", sal_Int32(4), aDestArea.StartRow); +} + +void XAreaLink::testSetSourceArea() +{ + uno::Reference< sheet::XAreaLink > xAreaLink(init(), UNO_QUERY_THROW); + + xAreaLink->setSourceArea("Sheet1.A1:B1"); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Couldn't set new source area", + OUString("Sheet1.A1:B1"), xAreaLink->getSourceArea()); +} + +void XAreaLink::testGetDestArea() +{ + uno::Reference< sheet::XAreaLink > xAreaLink(init(), UNO_QUERY_THROW); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Couldn't get dest area", + table::CellRangeAddress(1,2,3,3,6), xAreaLink->getDestArea()); +} + +void XAreaLink::testGetSourceArea() +{ + uno::Reference< sheet::XAreaLink > xAreaLink(init(), UNO_QUERY_THROW); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Couldn't get source area", + OUString("a2:b5"), xAreaLink->getSourceArea()); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xarealinks.cxx b/test/source/sheet/xarealinks.cxx new file mode 100644 index 000000000..f52dcc35b --- /dev/null +++ b/test/source/sheet/xarealinks.cxx @@ -0,0 +1,50 @@ +/* -*- 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 <test/sheet/xarealinks.hxx> + +#include <com/sun/star/sheet/XAreaLinks.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest { + +void XAreaLinks::testInsertAtPosition() +{ + uno::Reference< sheet::XAreaLinks > xAreaLinks(init(), UNO_QUERY_THROW); + + table::CellAddress aCellAddress(1, 2, 3); + xAreaLinks->insertAtPosition(aCellAddress, "", "a2:b5", "", ""); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to insert new CellAddress", + sal_Int32(1), xAreaLinks->getCount()); +} + +void XAreaLinks::testRemoveByIndex() +{ + uno::Reference< sheet::XAreaLinks > xAreaLinks(init(), UNO_QUERY_THROW); + + table::CellAddress aCellAddress(1, 2, 3); + xAreaLinks->insertAtPosition(aCellAddress, "", "a2:b5", "", ""); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to insert CellAddress for removal", + sal_Int32(1), xAreaLinks->getCount()); + + xAreaLinks->removeByIndex(0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to remove CellAddress", + sal_Int32(0), xAreaLinks->getCount()); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xarrayformularange.cxx b/test/source/sheet/xarrayformularange.cxx new file mode 100644 index 000000000..f7f30a1af --- /dev/null +++ b/test/source/sheet/xarrayformularange.cxx @@ -0,0 +1,54 @@ +/* -*- 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 <test/sheet/xarrayformularange.hxx> + +#include <com/sun/star/sheet/XArrayFormulaRange.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XArrayFormulaRange::testGetSetArrayFormula() +{ + uno::Reference<sheet::XArrayFormulaRange> xAFR(init(), UNO_QUERY_THROW); + + static const OUStringLiteral sFormula(u"=1 + 2 * 5"); + + xAFR->setArrayFormula(sFormula); + uno::Reference<sheet::XCellRangeAddressable> xCRA(xAFR, UNO_QUERY_THROW); + table::CellRangeAddress cellRangeAddress = xCRA->getRangeAddress(); + + uno::Reference<sheet::XSpreadsheet> xSheet(getXSpreadsheet(), UNO_QUERY_THROW); + + for (auto i = cellRangeAddress.StartColumn; i <= cellRangeAddress.EndColumn; i++) + { + for (auto j = cellRangeAddress.StartRow; j <= cellRangeAddress.EndRow; j++) + { + uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(i, j); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Value of Cell " + std::to_string(i) + "," + + std::to_string(j), + 11.0, xCell->getValue(), 0.5); + } + } + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to test getArrayFormula()", OUString("{" + sFormula + "}"), + xAFR->getArrayFormula()); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xcalculatable.cxx b/test/source/sheet/xcalculatable.cxx new file mode 100644 index 000000000..44c201534 --- /dev/null +++ b/test/source/sheet/xcalculatable.cxx @@ -0,0 +1,74 @@ +/* -*- 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 <test/sheet/xcalculatable.hxx> + +#include <com/sun/star/sheet/XCalculatable.hpp> +#include <com/sun/star/table/XCell.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XCalculatable::testEnableAutomaticCalculation() +{ + uno::Reference<sheet::XCalculatable> xCalculatable(init(), UNO_QUERY_THROW); + + bool bIsAutomaticCalculationEnabled = xCalculatable->isAutomaticCalculationEnabled(); + xCalculatable->enableAutomaticCalculation(!bIsAutomaticCalculationEnabled); + bool bIsAutomaticCalculationEnabledNew = xCalculatable->isAutomaticCalculationEnabled(); + CPPUNIT_ASSERT_MESSAGE("Unable to set enableAutomaticCalculation()", + bIsAutomaticCalculationEnabled != bIsAutomaticCalculationEnabledNew); +} + +void XCalculatable::testCalculate() +{ + uno::Reference<sheet::XCalculatable> xCalculatable(init(), UNO_QUERY_THROW); + xCalculatable->enableAutomaticCalculation(false); + + uno::Sequence<uno::Reference<table::XCell>> xCells = getXCells(); + + double dProduct = xCells[2]->getValue(); + double dFactor1 = xCells[0]->getValue(); + xCells[0]->setValue(dFactor1 + 1.0); + double dProduct2 = xCells[2]->getValue(); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculated products are equal", dProduct, dProduct2, 0.5); + + xCalculatable->calculate(); + dProduct2 = xCells[2]->getValue(); + CPPUNIT_ASSERT_MESSAGE("Calculated products are not equal", dProduct != dProduct2); +} + +void XCalculatable::testCalculateAll() +{ + uno::Reference<sheet::XCalculatable> xCalculatable(init(), UNO_QUERY_THROW); + xCalculatable->enableAutomaticCalculation(false); + + uno::Sequence<uno::Reference<table::XCell>> xCells = getXCells(); + + double dProduct = xCells[2]->getValue(); + double dFactor1 = xCells[0]->getValue(); + xCells[0]->setValue(dFactor1 + 1.0); + double dProduct2 = xCells[2]->getValue(); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculated products are equal", dProduct, dProduct2, 0.5); + + xCalculatable->calculateAll(); + dProduct2 = xCells[2]->getValue(); + CPPUNIT_ASSERT_MESSAGE("Calculated products are not equal", dProduct != dProduct2); + xCalculatable->calculateAll(); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xcelladdressable.cxx b/test/source/sheet/xcelladdressable.cxx new file mode 100644 index 000000000..e42809170 --- /dev/null +++ b/test/source/sheet/xcelladdressable.cxx @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xcelladdressable.hxx> +#include <test/cppunitasserthelper.hxx> + +#include <com/sun/star/sheet/XCellAddressable.hpp> +#include <com/sun/star/table/CellAddress.hpp> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XCellAddressable::testGetCellAddress() +{ + uno::Reference<sheet::XCellAddressable> xCellAddressable(init(), UNO_QUERY_THROW); + table::CellAddress xCellAddress = xCellAddressable->getCellAddress(); + table::CellAddress defaultCellAddress(0, 2, 3); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("getCellAddress() didn't returned default cell address", + defaultCellAddress, xCellAddress); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xcellformatrangessupplier.cxx b/test/source/sheet/xcellformatrangessupplier.cxx new file mode 100644 index 000000000..d4390b538 --- /dev/null +++ b/test/source/sheet/xcellformatrangessupplier.cxx @@ -0,0 +1,39 @@ +/* -*- 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 <test/sheet/xcellformatrangessupplier.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/sheet/XCellFormatRangesSupplier.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XCellFormatRangesSupplier::testGetCellFormatRanges() +{ + uno::Reference<sheet::XCellFormatRangesSupplier> xCFRS(init(), UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIA(xCFRS->getCellFormatRanges(), UNO_SET_THROW); + + const sal_Int32 nCount = xIA->getCount(); + CPPUNIT_ASSERT_MESSAGE("No items found", sal_Int32(0) != nCount); + for (auto i = 0; i < nCount; i++) + { + CPPUNIT_ASSERT_NO_THROW_MESSAGE("Unable to access element at position " + std::to_string(i), + xIA->getByIndex(i)); + } +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xcellrangeaddressable.cxx b/test/source/sheet/xcellrangeaddressable.cxx new file mode 100644 index 000000000..179a56fa1 --- /dev/null +++ b/test/source/sheet/xcellrangeaddressable.cxx @@ -0,0 +1,33 @@ +/* -*- 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 <test/sheet/xcellrangeaddressable.hxx> + +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XCellRangeAddressable::testGetRangeAddress() +{ + uno::Reference<sheet::XCellRangeAddressable> xCRA(init(), UNO_QUERY_THROW); + + table::CellRangeAddress aCellRangeAddr = xCRA->getRangeAddress(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get CellRangeAddress", sal_Int16(0), + aCellRangeAddr.Sheet); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xcellrangedata.cxx b/test/source/sheet/xcellrangedata.cxx new file mode 100644 index 000000000..eff104147 --- /dev/null +++ b/test/source/sheet/xcellrangedata.cxx @@ -0,0 +1,95 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xcellrangedata.hxx> + +#include <com/sun/star/sheet/XCellRangeData.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest { + +namespace { + +void setValues(uno::Sequence< uno::Sequence < Any > >& rColRow, double nOffset) +{ + auto pColRow = rColRow.getArray(); + for (sal_Int32 i = 0; i < 4; ++i) + { + pColRow[i].realloc(4); + auto pCol = pColRow[i].getArray(); + for (sal_Int32 j = 0; j < 4; ++j) + { + Any& aAny = pCol[j]; + double nValue = i + j + nOffset; + aAny <<= nValue; + } + } +} + +} + +void XCellRangeData::testSetDataArray() +{ + uno::Reference< sheet::XCellRangeData > xCellRangeData( getXCellRangeData(), UNO_QUERY_THROW); + + uno::Sequence< uno::Sequence < Any > > aColRow(4); + setValues(aColRow, 1); + xCellRangeData->setDataArray(aColRow); + + for ( sal_Int32 i = 0; i < aColRow.getLength(); ++i) + { + for ( sal_Int32 j = 0; j < aColRow[i].getLength(); ++j) + { + const Any& aAny = aColRow[i][j]; + double nValue = 0.0; + CPPUNIT_ASSERT( aAny >>= nValue); + CPPUNIT_ASSERT_DOUBLES_EQUAL(static_cast<double>(i+j+1), nValue, 0.000001); + } + } + + // set old values + setValues(aColRow, 0); + xCellRangeData->setDataArray(aColRow); +} + +void XCellRangeData::testGetDataArray() +{ + uno::Reference< sheet::XCellRangeData > xCellRangeData( getXCellRangeData(), UNO_QUERY_THROW); + uno::Sequence< uno::Sequence < Any > > aColRow = xCellRangeData->getDataArray(); + CPPUNIT_ASSERT(aColRow.hasElements()); +} + +void XCellRangeData::testGetDataArrayOnTableSheet() +{ + uno::Reference< sheet::XCellRangeData > xCellRangeData( getXCellRangeData(), UNO_QUERY_THROW); + CPPUNIT_ASSERT_THROW_MESSAGE("No RuntimeException thrown", xCellRangeData->getDataArray(), + css::uno::RuntimeException); +} + +void XCellRangeData::testSetDataArrayOnTableSheet() +{ + uno::Reference< sheet::XCellRangeData > xCellRangeData( getXCellRangeData(), UNO_QUERY_THROW); + + uno::Sequence< uno::Sequence < Any > > aColRow; + aColRow.realloc(4); + setValues(aColRow, 1); + CPPUNIT_ASSERT_THROW_MESSAGE("No RuntimeException thrown", xCellRangeData->setDataArray(aColRow), + css::uno::RuntimeException); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xcellrangeformula.cxx b/test/source/sheet/xcellrangeformula.cxx new file mode 100644 index 000000000..ce7fc54eb --- /dev/null +++ b/test/source/sheet/xcellrangeformula.cxx @@ -0,0 +1,41 @@ +/* -*- 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 <test/sheet/xcellrangeformula.hxx> + +#include <com/sun/star/sheet/XCellRangeFormula.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XCellRangeFormula::testGetSetFormulaArray() +{ + uno::Reference<sheet::XCellRangeFormula> xCRF(init(), UNO_QUERY_THROW); + + uno::Sequence<uno::Sequence<OUString>> aFormulaArrayOriginal = xCRF->getFormulaArray(); + uno::Sequence<uno::Sequence<OUString>> aFormulaArrayNew = xCRF->getFormulaArray(); + aFormulaArrayNew.getArray()[0].getArray()[0] = "NewValue"; + + xCRF->setFormulaArray(aFormulaArrayNew); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get new FormulaArray", OUString("NewValue"), + xCRF->getFormulaArray()[0][0]); + + xCRF->setFormulaArray(aFormulaArrayOriginal); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set new FormulaArray", aFormulaArrayOriginal[0][0], + xCRF->getFormulaArray()[0][0]); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xcellrangemovement.cxx b/test/source/sheet/xcellrangemovement.cxx new file mode 100644 index 000000000..ac25a4603 --- /dev/null +++ b/test/source/sheet/xcellrangemovement.cxx @@ -0,0 +1,120 @@ +/* -*- 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 <test/sheet/xcellrangemovement.hxx> + +#include <com/sun/star/sheet/CellDeleteMode.hpp> +#include <com/sun/star/sheet/CellInsertMode.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XCellRangeMovement.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XCellRangeMovement::testInsertCells() +{ + uno::Reference<sheet::XCellRangeMovement> xCRM(init(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xCRM, UNO_QUERY_THROW); + + uno::Reference<sheet::XCellRangeAddressable> xCRA(xCRM, UNO_QUERY_THROW); + const sal_Int16 nSheet = xCRA->getRangeAddress().Sheet; + + xSheet->getCellByPosition(0, 20)->setValue(100); + xSheet->getCellByPosition(1, 20)->setValue(100); + xSheet->getCellByPosition(2, 20)->setValue(100); + xSheet->getCellByPosition(3, 20)->setValue(100); + xSheet->getCellByPosition(0, 21)->setValue(200); + xSheet->getCellByPosition(1, 21)->setValue(200); + xSheet->getCellByPosition(2, 21)->setValue(200); + xSheet->getCellByPosition(3, 21)->setValue(200); + + table::CellRangeAddress aSrcCellRangeAddr(nSheet, 0, 21, 5, 21); + xCRM->insertCells(aSrcCellRangeAddr, sheet::CellInsertMode_DOWN); + + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Unable to insert cells", 0.0, + xSheet->getCellByPosition(1, 21)->getValue(), 0.0); +} + +void XCellRangeMovement::testCopyRange() +{ + uno::Reference<sheet::XCellRangeMovement> xCRM(init(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xCRM, UNO_QUERY_THROW); + + xSheet->getCellByPosition(1, 1)->setValue(100); + xSheet->getCellByPosition(1, 2)->setValue(200); + xSheet->getCellByPosition(2, 1)->setValue(300); + xSheet->getCellByPosition(2, 2)->setValue(400); + + uno::Reference<sheet::XCellRangeAddressable> xCRA(xCRM, UNO_QUERY_THROW); + const sal_Int16 nSheet = xCRA->getRangeAddress().Sheet; + + table::CellRangeAddress aSrcCellRangeAddr(nSheet, 1, 1, 2, 2); + table::CellAddress aDstCellAddr(nSheet, 1, 10); + + xCRM->copyRange(aDstCellAddr, aSrcCellRangeAddr); + + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Value was not copied from position 1,1 to 1,10", 100.0, + xSheet->getCellByPosition(1, 10)->getValue(), 0.1); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Value was not copied from position 1,2 to 1,11", 200.0, + xSheet->getCellByPosition(1, 11)->getValue(), 0.1); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Value was not copied from position 2,1 to 2,10", 300.0, + xSheet->getCellByPosition(2, 10)->getValue(), 0.1); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Value was not copied from position 2,2 to 2,11", 400.0, + xSheet->getCellByPosition(2, 11)->getValue(), 0.1); +} +void XCellRangeMovement::testMoveRange() +{ + uno::Reference<sheet::XCellRangeMovement> xCRM(init(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xCRM, UNO_QUERY_THROW); + + xSheet->getCellByPosition(4, 0)->setValue(111); + xSheet->getCellByPosition(4, 1)->setValue(222); + + uno::Reference<sheet::XCellRangeAddressable> xCRA(xCRM, UNO_QUERY_THROW); + const sal_Int16 nSheet = xCRA->getRangeAddress().Sheet; + + table::CellRangeAddress aSrcCellRangeAddr(nSheet, 4, 0, 4, 1); + table::CellAddress aDstCellAddr(nSheet, 4, 4); + + xCRM->moveRange(aDstCellAddr, aSrcCellRangeAddr); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Unable to move range", 333.0, + xSheet->getCellByPosition(4, 4)->getValue() + + xSheet->getCellByPosition(4, 5)->getValue(), + 0.0); +} +void XCellRangeMovement::testRemoveRange() +{ + uno::Reference<sheet::XCellRangeMovement> xCRM(init(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xCRM, UNO_QUERY_THROW); + + xSheet->getCellByPosition(5, 0)->setValue(333); + xSheet->getCellByPosition(5, 1)->setValue(444); + + uno::Reference<sheet::XCellRangeAddressable> xCRA(xCRM, UNO_QUERY_THROW); + const sal_Int16 nSheet = xCRA->getRangeAddress().Sheet; + + table::CellRangeAddress aSrcCellRangeAddr(nSheet, 5, 0, 5, 1); + + xCRM->removeRange(aSrcCellRangeAddr, sheet::CellDeleteMode_UP); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Unable to remove range", 0.0, + xSheet->getCellByPosition(5, 0)->getValue() + + xSheet->getCellByPosition(5, 1)->getValue(), + 0.0); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xcellrangereferrer.cxx b/test/source/sheet/xcellrangereferrer.cxx new file mode 100644 index 000000000..575bee05e --- /dev/null +++ b/test/source/sheet/xcellrangereferrer.cxx @@ -0,0 +1,36 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/cppunitasserthelper.hxx> +#include <test/sheet/xcellrangereferrer.hxx> + +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XCellRangeReferrer.hpp> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XCellRangeReferrer::testGetReferredCells() +{ + uno::Reference<sheet::XCellRangeReferrer> xReferrer(init(), UNO_QUERY_THROW); + uno::Reference<table::XCellRange> xReferredRange = xReferrer->getReferredCells(); + + uno::Reference<sheet::XCellRangeAddressable> xAddressable(xReferredRange, UNO_QUERY_THROW); + table::CellRangeAddress aCellRange = xAddressable->getRangeAddress(); + + CPPUNIT_ASSERT_EQUAL(aCellRange, getCellRange()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xcellrangesquery.cxx b/test/source/sheet/xcellrangesquery.cxx new file mode 100644 index 000000000..55d24224a --- /dev/null +++ b/test/source/sheet/xcellrangesquery.cxx @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xcellrangesquery.hxx> + +#include <com/sun/star/sheet/XCellRangesQuery.hpp> +#include <com/sun/star/sheet/XSheetCellRanges.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/sheet/CellFlags.hpp> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + + +namespace apitest { + +void XCellRangesQuery::testQueryColumnDifference() +{ + uno::Reference<sheet::XCellRangesQuery> xCellRangesQuery(init(),UNO_QUERY_THROW); + uno::Reference<sheet::XSheetCellRanges> xRanges = xCellRangesQuery->queryColumnDifferences(table::CellAddress(0, 1, 1)); + OUString aResult = xRanges->getRangeAddressesAsString(); + std::cout << "testQueryColumnDifference: Result: " << aResult << std::endl; + CPPUNIT_ASSERT_EQUAL_MESSAGE("testQueryColumnDifference", OUString( "Sheet1.B1:C1,Sheet1.B3:C5" ), aResult); +} + +void XCellRangesQuery::testQueryContentDifference() +{ + uno::Reference<sheet::XCellRangesQuery> xCellRangesQuery(init(),UNO_QUERY_THROW); + uno::Reference<sheet::XSheetCellRanges> xRanges = xCellRangesQuery->queryContentCells(sheet::CellFlags::VALUE); + OUString aResult = xRanges->getRangeAddressesAsString(); + std::cout << "testQueryContentDifference: Result: " << aResult << std::endl; + CPPUNIT_ASSERT_EQUAL_MESSAGE("testQueryContentDifference", OUString( "Sheet1.B3,Sheet1.C2" ), aResult); +} + +void XCellRangesQuery::testQueryEmptyCells() +{ + uno::Reference<sheet::XCellRangesQuery> xCellRangesQuery(init(),UNO_QUERY_THROW); + uno::Reference<sheet::XSheetCellRanges> xRanges = xCellRangesQuery->queryEmptyCells(); + OUString aResult = xRanges->getRangeAddressesAsString(); + std::cout << "testQueryEmptyCells: Result: " << aResult << std::endl; + CPPUNIT_ASSERT_EQUAL_MESSAGE("testQueryEmptyCells", OUString( "Sheet1.A1:A5,Sheet1.B1:C1,Sheet1.B5,Sheet1.C3:C5,Sheet1.D1:E5" ), aResult); +} + +void XCellRangesQuery::testQueryFormulaCells() +{ + uno::Reference<sheet::XCellRangesQuery> xCellRangesQuery(init(),UNO_QUERY_THROW); + uno::Reference<sheet::XSheetCellRanges> xRanges = xCellRangesQuery->queryFormulaCells(sheet::CellFlags::FORMULA); + OUString aResult = xRanges->getRangeAddressesAsString(); + std::cout << "testQueryFormulaCells: Result: " << aResult << std::endl; + CPPUNIT_ASSERT_EQUAL_MESSAGE("testQueryFormulaCells", OUString( "Sheet1.B2" ), aResult); +} + +void XCellRangesQuery::testQueryIntersection() +{ + uno::Reference<sheet::XCellRangesQuery> xCellRangesQuery(init(),UNO_QUERY_THROW); + uno::Reference<sheet::XSheetCellRanges> xRanges = xCellRangesQuery->queryIntersection(table::CellRangeAddress(0,3,3,7,7)); + OUString aResult = xRanges->getRangeAddressesAsString(); + std::cout << "testQueryIntersection: Result: " << aResult << std::endl; + CPPUNIT_ASSERT_EQUAL_MESSAGE("testQueryIntersection", OUString( "Sheet1.D4:E5" ), aResult); +} + +void XCellRangesQuery::testQueryRowDifference() +{ + uno::Reference<sheet::XCellRangesQuery> xCellRangesQuery(init(),UNO_QUERY_THROW); + uno::Reference<sheet::XSheetCellRanges> xRanges = xCellRangesQuery->queryRowDifferences(table::CellAddress(0,1,1)); + OUString aResult = xRanges->getRangeAddressesAsString(); + std::cout << "testQueryRowDifference: Result: " << aResult << std::endl; + CPPUNIT_ASSERT_EQUAL_MESSAGE("testQueryRowDifference", OUString( "Sheet1.A2:A4,Sheet1.C2:E4" ), aResult); +} + +void XCellRangesQuery::testQueryVisibleCells() +{ + uno::Reference<sheet::XCellRangesQuery> xCellRangesQuery(init(),UNO_QUERY_THROW); + uno::Reference<sheet::XSheetCellRanges> xRanges = xCellRangesQuery->queryVisibleCells(); + OUString aResult = xRanges->getRangeAddressesAsString(); + std::cout << "testQueryVisibleCells: Result: " << aResult << std::endl; + CPPUNIT_ASSERT_EQUAL_MESSAGE("testQueryVisibleCells", OUString( "Sheet1.A1:E5" ), aResult); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xcellseries.cxx b/test/source/sheet/xcellseries.cxx new file mode 100644 index 000000000..3aff084f8 --- /dev/null +++ b/test/source/sheet/xcellseries.cxx @@ -0,0 +1,114 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xcellseries.hxx> + +#include <com/sun/star/sheet/XCellSeries.hpp> +#include <com/sun/star/table/XCellRange.hpp> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest { + +void XCellSeries::testFillAuto() +{ + uno::Reference<table::XCellRange> xCellRange(init(), UNO_QUERY_THROW); + sal_Int32 maValue = xCellRange->getCellByPosition(maStartX, maStartY)->getValue(); + + uno::Reference<table::XCellRange> xCellRangeH(xCellRange->getCellRangeByPosition(maStartX, maStartY, maStartX + 2, maStartY), UNO_SET_THROW); + uno::Reference<sheet::XCellSeries> xCellSeriesH(xCellRangeH, UNO_QUERY_THROW); + xCellSeriesH->fillAuto(sheet::FillDirection_TO_RIGHT, 1); + sal_Int32 sumH = 0; + for(sal_Int32 i = 0; i < 3; i++) { + uno::Reference<table::XCell> xCellResultH(xCellRange->getCellByPosition(maStartX + i, maStartY), UNO_SET_THROW); + sumH += xCellResultH->getValue(); + } + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong result for fillAuto with TO_RIGHT", maValue * 3 + 3, sumH); + + uno::Reference<table::XCellRange> xCellRangeV(xCellRange->getCellRangeByPosition(maStartX, maStartY, maStartX, maStartY + 2), UNO_SET_THROW); + uno::Reference<sheet::XCellSeries> xCellSeriesV(xCellRangeV, UNO_QUERY_THROW); + xCellSeriesV->fillAuto(sheet::FillDirection_TO_BOTTOM, 1); + sal_Int32 sumV = 0; + for(sal_Int32 i = 0; i < 3; i++) { + uno::Reference<table::XCell> xCellResultV(xCellRange->getCellByPosition(maStartX, maStartY + i), UNO_SET_THROW); + sumV += xCellResultV->getValue(); + } + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong result for fillAuto with TO_BOTTOM", maValue * 3 + 3, sumV); + + for(sal_Int32 i = 1; i < 3; i++) { + uno::Reference<table::XCell> xCellResultH(xCellRange->getCellByPosition(maStartX + i, maStartY), UNO_SET_THROW); + xCellResultH->setFormula(""); + uno::Reference<table::XCell> xCellResultV(xCellRange->getCellByPosition(maStartX, maStartY + i), UNO_SET_THROW); + xCellResultV->setFormula(""); + } +} + +void XCellSeries::testFillSeries() +{ + uno::Reference<table::XCellRange> xCellRange(init(), UNO_QUERY_THROW); + sal_Int32 maValue = xCellRange->getCellByPosition(maStartX, maStartY)->getValue(); + + uno::Reference<table::XCellRange> xCellRangeH(xCellRange->getCellRangeByPosition(maStartX, maStartY, maStartX + 2, maStartY), UNO_SET_THROW); + uno::Reference<sheet::XCellSeries> xCellSeriesH(xCellRangeH, UNO_QUERY_THROW); + xCellSeriesH->fillSeries(sheet::FillDirection_TO_RIGHT, + sheet::FillMode_LINEAR, + sheet::FillDateMode_FILL_DATE_DAY, 2, 1000); + sal_Int32 sumH = 0; + for(sal_Int32 i = 0; i < 3; i++) { + uno::Reference<table::XCell> xCellResultH(xCellRange->getCellByPosition(maStartX + i, maStartY), UNO_SET_THROW); + sumH += xCellResultH->getValue(); + } + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong result for fillSeries with TO_RIGHT and LINEAR", maValue * 3 + 6, sumH); + + xCellSeriesH->fillSeries(sheet::FillDirection_TO_RIGHT, + sheet::FillMode_GROWTH, + sheet::FillDateMode_FILL_DATE_DAY, 2, 1000); + sumH = 0; + for(sal_Int32 i = 0; i < 3; i++) { + uno::Reference<table::XCell> xCellResultH(xCellRange->getCellByPosition(maStartX + i, maStartY), UNO_SET_THROW); + sumH += xCellResultH->getValue(); + } + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong result for fillSeries with TO_RIGHT and GROWTH", maValue + maValue * 2 + maValue * 4, sumH); + + uno::Reference<table::XCellRange> xCellRangeV(xCellRange->getCellRangeByPosition(maStartX, maStartY, maStartX, maStartY + 2), UNO_SET_THROW); + uno::Reference<sheet::XCellSeries> xCellSeriesV(xCellRangeV, UNO_QUERY_THROW); + xCellSeriesV->fillSeries(sheet::FillDirection_TO_BOTTOM, + sheet::FillMode_LINEAR, + sheet::FillDateMode_FILL_DATE_DAY, 2, 1000); + sal_Int32 sumV = 0; + for(sal_Int32 i = 0; i < 3; i++) { + uno::Reference<table::XCell> xCellResultV(xCellRange->getCellByPosition(maStartX, maStartY + i), UNO_SET_THROW); + sumV += xCellResultV->getValue(); + } + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong result for fillSeries with TO_BOTTOM and LINEAR", maValue * 3 + 6, sumV); + + xCellSeriesV->fillSeries(sheet::FillDirection_TO_BOTTOM, + sheet::FillMode_GROWTH, + sheet::FillDateMode_FILL_DATE_DAY, 2, 1000); + sumV = 0; + for(sal_Int32 i = 0; i < 3; i++) { + uno::Reference<table::XCell> xCellResultV(xCellRange->getCellByPosition(maStartX, maStartY + i), UNO_SET_THROW); + sumV += xCellResultV->getValue(); + } + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong result for fillSeries with TO_BOTTOM and GROWTH", maValue + maValue * 2 + maValue * 4, sumV); + + for(sal_Int32 i = 1; i < 3; i++) { + uno::Reference<table::XCell> xCellResultH(xCellRange->getCellByPosition(maStartX + i, maStartY), UNO_SET_THROW); + xCellResultH->setFormula(""); + uno::Reference<table::XCell> xCellResultV(xCellRange->getCellByPosition(maStartX, maStartY + i), UNO_SET_THROW); + xCellResultV->setFormula(""); + } +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xconsolidatable.cxx b/test/source/sheet/xconsolidatable.cxx new file mode 100644 index 000000000..0efa16b69 --- /dev/null +++ b/test/source/sheet/xconsolidatable.cxx @@ -0,0 +1,43 @@ +/* -*- 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 <test/sheet/xconsolidatable.hxx> + +#include <com/sun/star/sheet/XConsolidatable.hpp> +#include <com/sun/star/sheet/XConsolidationDescriptor.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XConsolidatable::testCreateConsolidationDescriptor() +{ + uno::Reference<sheet::XConsolidatable> xConsolidatable(init(), UNO_QUERY_THROW); + + uno::Reference<sheet::XConsolidationDescriptor> xConsolidationDescriptor( + xConsolidatable->createConsolidationDescriptor(true), UNO_SET_THROW); +} + +void XConsolidatable::testConsolidate() +{ + uno::Reference<sheet::XConsolidatable> xConsolidatable(init(), UNO_QUERY_THROW); + + uno::Reference<sheet::XConsolidationDescriptor> xConsolidationDescriptor( + xConsolidatable->createConsolidationDescriptor(true), UNO_SET_THROW); + + xConsolidatable->consolidate(xConsolidationDescriptor); + CPPUNIT_ASSERT_MESSAGE("consolidate()", true); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xconsolidationdescriptor.cxx b/test/source/sheet/xconsolidationdescriptor.cxx new file mode 100644 index 000000000..45ba69877 --- /dev/null +++ b/test/source/sheet/xconsolidationdescriptor.cxx @@ -0,0 +1,143 @@ +/* -*- 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 <test/sheet/xconsolidationdescriptor.hxx> +#include <test/cppunitasserthelper.hxx> + +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/XConsolidationDescriptor.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XConsolidationDescriptor::testGetFunction() +{ + uno::Reference<sheet::XConsolidationDescriptor> xConsolidationDescriptor(init(), + UNO_QUERY_THROW); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get function", sheet::GeneralFunction_SUM, + xConsolidationDescriptor->getFunction()); +} + +void XConsolidationDescriptor::testSetFunction() +{ + uno::Reference<sheet::XConsolidationDescriptor> xConsolidationDescriptor(init(), + UNO_QUERY_THROW); + + xConsolidationDescriptor->setFunction(sheet::GeneralFunction_COUNT); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set function", sheet::GeneralFunction_COUNT, + xConsolidationDescriptor->getFunction()); +} + +void XConsolidationDescriptor::testGetSources() +{ + uno::Reference<sheet::XConsolidationDescriptor> xConsolidationDescriptor(init(), + UNO_QUERY_THROW); + + uno::Sequence<table::CellRangeAddress> aSources = xConsolidationDescriptor->getSources(); + CPPUNIT_ASSERT_MESSAGE("Unable to get sources", !aSources.hasElements()); +} + +void XConsolidationDescriptor::testSetSources() +{ + uno::Reference<sheet::XConsolidationDescriptor> xConsolidationDescriptor(init(), + UNO_QUERY_THROW); + + uno::Sequence<table::CellRangeAddress> aSources{ table::CellRangeAddress(0, 1, 1, 5, 5) }; + xConsolidationDescriptor->setSources(aSources); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set sources", table::CellRangeAddress(0, 1, 1, 5, 5), + xConsolidationDescriptor->getSources()[0]); +} + +void XConsolidationDescriptor::testGetStartOutputPosition() +{ + uno::Reference<sheet::XConsolidationDescriptor> xConsolidationDescriptor(init(), + UNO_QUERY_THROW); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get start output position", table::CellAddress(0, 0, 0), + xConsolidationDescriptor->getStartOutputPosition()); +} + +void XConsolidationDescriptor::testSetStartOutputPosition() +{ + uno::Reference<sheet::XConsolidationDescriptor> xConsolidationDescriptor(init(), + UNO_QUERY_THROW); + + xConsolidationDescriptor->setStartOutputPosition(table::CellAddress(0, 1, 2)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set start output position", table::CellAddress(0, 1, 2), + xConsolidationDescriptor->getStartOutputPosition()); +} + +void XConsolidationDescriptor::testGetUseColumnHeaders() +{ + uno::Reference<sheet::XConsolidationDescriptor> xConsolidationDescriptor(init(), + UNO_QUERY_THROW); + + CPPUNIT_ASSERT_MESSAGE("Unable to get use column headers", + !xConsolidationDescriptor->getUseColumnHeaders()); +} + +void XConsolidationDescriptor::testSetUseColumnHeaders() +{ + uno::Reference<sheet::XConsolidationDescriptor> xConsolidationDescriptor(init(), + UNO_QUERY_THROW); + + xConsolidationDescriptor->setUseColumnHeaders(true); + CPPUNIT_ASSERT_MESSAGE("Unable to set use column headers", + xConsolidationDescriptor->getUseColumnHeaders()); +} + +void XConsolidationDescriptor::testGetUseRowHeaders() +{ + uno::Reference<sheet::XConsolidationDescriptor> xConsolidationDescriptor(init(), + UNO_QUERY_THROW); + + CPPUNIT_ASSERT_MESSAGE("Unable to get use row headers", + !xConsolidationDescriptor->getUseRowHeaders()); +} + +void XConsolidationDescriptor::testSetUseRowHeaders() +{ + uno::Reference<sheet::XConsolidationDescriptor> xConsolidationDescriptor(init(), + UNO_QUERY_THROW); + + xConsolidationDescriptor->setUseRowHeaders(true); + CPPUNIT_ASSERT_MESSAGE("Unable to set use row headers", + xConsolidationDescriptor->getUseRowHeaders()); +} + +void XConsolidationDescriptor::testGetInsertLinks() +{ + uno::Reference<sheet::XConsolidationDescriptor> xConsolidationDescriptor(init(), + UNO_QUERY_THROW); + + CPPUNIT_ASSERT_MESSAGE("Unable to get use insert links", + !xConsolidationDescriptor->getInsertLinks()); +} + +void XConsolidationDescriptor::testSetInsertLinks() +{ + uno::Reference<sheet::XConsolidationDescriptor> xConsolidationDescriptor(init(), + UNO_QUERY_THROW); + + xConsolidationDescriptor->setInsertLinks(true); + CPPUNIT_ASSERT_MESSAGE("Unable to set use insert links", + xConsolidationDescriptor->getInsertLinks()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xdatabaserange.cxx b/test/source/sheet/xdatabaserange.cxx new file mode 100644 index 000000000..f1133ac00 --- /dev/null +++ b/test/source/sheet/xdatabaserange.cxx @@ -0,0 +1,174 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xdatabaserange.hxx> + +#include <com/sun/star/sheet/XSubTotalDescriptor.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/sheet/XDatabaseRange.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sheet/XCellRangeReferrer.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/table/XTableRows.hpp> +#include <com/sun/star/table/XColumnRowRange.hpp> + +#include <rtl/ustring.hxx> +#include <cppunit/TestAssert.h> +#include <iostream> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +/** + * tests setDataArea and getDataArea + */ +void XDatabaseRange::testDataArea() +{ + uno::Reference<sheet::XDatabaseRange> xDBRange(init("DataArea"), UNO_QUERY_THROW); + + table::CellRangeAddress aCellAddress; + aCellAddress.Sheet = 0; + aCellAddress.StartColumn = 1; + aCellAddress.EndColumn = 4; + aCellAddress.StartRow = 2; + aCellAddress.EndRow = 5; + xDBRange->setDataArea(aCellAddress); + table::CellRangeAddress aValue = xDBRange->getDataArea(); + CPPUNIT_ASSERT_EQUAL(aCellAddress.Sheet, aValue.Sheet); + CPPUNIT_ASSERT_EQUAL(aCellAddress.StartRow, aValue.StartRow); + CPPUNIT_ASSERT_EQUAL(aCellAddress.EndRow, aValue.EndRow); + CPPUNIT_ASSERT_EQUAL(aCellAddress.StartColumn, aValue.StartColumn); + CPPUNIT_ASSERT_EQUAL(aCellAddress.EndColumn, aValue.EndColumn); +} + +void XDatabaseRange::testGetSubtotalDescriptor() +{ + uno::Reference<sheet::XDatabaseRange> xDBRange(init("SubtotalDescriptor"), UNO_QUERY_THROW); + uno::Reference<sheet::XSubTotalDescriptor> xSubtotalDescr = xDBRange->getSubTotalDescriptor(); + CPPUNIT_ASSERT(xSubtotalDescr.is()); +} + +void XDatabaseRange::testGetSortDescriptor() +{ + uno::Reference<sheet::XDatabaseRange> xDBRange(init("SortDescriptor"), UNO_QUERY_THROW); + const uno::Sequence<beans::PropertyValue> xSortDescr = xDBRange->getSortDescriptor(); + for (const beans::PropertyValue& aProp : xSortDescr) + { + //std::cout << "Prop " << i << " Name: " << OUString(aProp.Name) << std::endl; + + if (aProp.Name == "IsSortColumns") + { + bool bIsSortColumns = true; + aProp.Value >>= bIsSortColumns; + CPPUNIT_ASSERT(!bIsSortColumns); + } + else if (aProp.Name == "ContainsHeader") + { + bool bContainsHeader = true; + aProp.Value >>= bContainsHeader; + CPPUNIT_ASSERT(bContainsHeader); + } + else if (aProp.Name == "MaxFieldCount") + { + sal_Int32 nMaxFieldCount = 0; + aProp.Value >>= nMaxFieldCount; + std::cout << "Value: " << nMaxFieldCount << std::endl; + } + else if (aProp.Name == "SortFields") + { + } + else if (aProp.Name == "BindFormatsToContent") + { + bool bBindFormatsToContent = false; + aProp.Value >>= bBindFormatsToContent; + CPPUNIT_ASSERT(bBindFormatsToContent); + } + else if (aProp.Name == "CopyOutputData") + { + bool bCopyOutputData = true; + aProp.Value >>= bCopyOutputData; + CPPUNIT_ASSERT(!bCopyOutputData); + } + else if (aProp.Name == "OutputPosition") + { + } + else if (aProp.Name == "IsUserListEnabled") + { + bool bIsUserListEnabled = true; + aProp.Value >>= bIsUserListEnabled; + CPPUNIT_ASSERT(!bIsUserListEnabled); + } + else if (aProp.Name == "UserListIndex") + { + sal_Int32 nUserListIndex = 1; + aProp.Value >>= nUserListIndex; + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nUserListIndex); + } + } +} + +void XDatabaseRange::testGetFilterDescriptor() +{ + uno::Reference<sheet::XDatabaseRange> xDBRange(init("FilterDescriptor"), UNO_QUERY_THROW); + uno::Reference<uno::XInterface> xFilterDescr(xDBRange->getFilterDescriptor(), UNO_QUERY_THROW); +} + +void XDatabaseRange::testGetImportDescriptor() +{ + uno::Reference<sheet::XDatabaseRange> xDBRange(init("ImportDescriptor"), UNO_QUERY_THROW); + uno::Sequence<beans::PropertyValue> xImportDescr = xDBRange->getImportDescriptor(); + (void)xImportDescr; +} + +void XDatabaseRange::testRefresh() +{ + uno::Reference<sheet::XDatabaseRange> xDBRange(init("Refresh"), UNO_QUERY_THROW); + + const sal_Int32 nCol = 0; + OUString aHidden("IsVisible"); + uno::Reference<sheet::XCellRangeReferrer> xCellRangeReferrer(xDBRange, UNO_QUERY_THROW); + uno::Reference<table::XCellRange> xCellRange = xCellRangeReferrer->getReferredCells(); + + for (sal_Int32 i = 1; i < 5; ++i) + { + uno::Reference<table::XCell> xCell = xCellRange->getCellByPosition(nCol, i); + xCell->setValue(0); + } + + for (sal_Int32 i = 2; i < 5; ++i) + { + uno::Reference<table::XColumnRowRange> xColRowRange(xCellRange, UNO_QUERY_THROW); + uno::Reference<table::XTableRows> xRows = xColRowRange->getRows(); + uno::Reference<table::XCellRange> xRow(xRows->getByIndex(i), UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPropRow(xRow, UNO_QUERY_THROW); + Any aAny = xPropRow->getPropertyValue(aHidden); + + CPPUNIT_ASSERT(aAny.get<bool>()); + } + + xDBRange->refresh(); + std::cout << "after refresh" << std::endl; + + for (sal_Int32 i = 1; i < 5; ++i) + { + uno::Reference<table::XColumnRowRange> xColRowRange(xCellRange, UNO_QUERY_THROW); + uno::Reference<table::XTableRows> xRows = xColRowRange->getRows(); + uno::Reference<table::XCellRange> xRow(xRows->getByIndex(i), UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPropRow(xRow, UNO_QUERY_THROW); + Any aAny = xPropRow->getPropertyValue(aHidden); + + CPPUNIT_ASSERT(!aAny.get<bool>()); + } +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xdatabaseranges.cxx b/test/source/sheet/xdatabaseranges.cxx new file mode 100644 index 000000000..650a0faa3 --- /dev/null +++ b/test/source/sheet/xdatabaseranges.cxx @@ -0,0 +1,45 @@ +/* -*- 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 <test/sheet/xdatabaseranges.hxx> + +#include <com/sun/star/sheet/XDatabaseRanges.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XDatabaseRanges::testAddRemoveDbRanges() +{ + uno::Reference<sheet::XDatabaseRanges> xDbRanges(init(), UNO_QUERY_THROW); + + xDbRanges->addNewByName("addNewRange", table::CellRangeAddress(0, 1, 2, 3, 4)); + CPPUNIT_ASSERT_MESSAGE("Unable to add new db range", xDbRanges->hasByName("addNewRange")); + + CPPUNIT_ASSERT_THROW_MESSAGE( + "No exception thrown, when adding range with existing name", + xDbRanges->addNewByName("addNewRange", table::CellRangeAddress(0, 1, 2, 3, 4)), + css::uno::RuntimeException); + + xDbRanges->removeByName("addNewRange"); + CPPUNIT_ASSERT_MESSAGE("Unable to remove db range", !xDbRanges->hasByName("addNewRange")); + + CPPUNIT_ASSERT_THROW_MESSAGE("No exception, when removing none-existing range", + xDbRanges->removeByName("addNewRange"), + css::uno::RuntimeException); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xdatapilotdescriptor.cxx b/test/source/sheet/xdatapilotdescriptor.cxx new file mode 100644 index 000000000..a9cbcf5b1 --- /dev/null +++ b/test/source/sheet/xdatapilotdescriptor.cxx @@ -0,0 +1,192 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xdatapilotdescriptor.hxx> + +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> + +#include <cppunit/TestAssert.h> + +#include <o3tl/safeint.hxx> +#include <rtl/ustring.hxx> + +using namespace css; +using namespace css::uno; + +namespace apitest { + +std::vector< OUString > XDataPilotDescriptor::maFieldNames; + +void XDataPilotDescriptor::testTag() +{ + OUString aTag("DataPilotDescriptor_Tag"); + uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW); + xDescr->setTag(aTag); + OUString aNewTag = xDescr->getTag(); + CPPUNIT_ASSERT_EQUAL( aTag, aNewTag ); +} + +void XDataPilotDescriptor::testSourceRange() +{ + uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW); + table::CellRangeAddress aOldAddress = xDescr->getSourceRange(); + + table::CellRangeAddress aAddress; + aAddress.Sheet = 1; + aAddress.StartColumn = 1; + aAddress.StartRow = 1; + aAddress.EndColumn = 5; + aAddress.EndRow = 5; + xDescr->setSourceRange(aAddress); + + table::CellRangeAddress aReturn = xDescr->getSourceRange(); + + CPPUNIT_ASSERT_EQUAL(aAddress.Sheet, aReturn.Sheet); + CPPUNIT_ASSERT_EQUAL(aAddress.StartColumn, aReturn.StartColumn); + CPPUNIT_ASSERT_EQUAL(aAddress.StartRow, aReturn.StartRow); + CPPUNIT_ASSERT_EQUAL(aAddress.EndColumn, aReturn.EndColumn); + CPPUNIT_ASSERT_EQUAL(aAddress.EndRow, aReturn.EndRow); + + //restore old settings + xDescr->setSourceRange(aOldAddress); +} + +void XDataPilotDescriptor::testGetFilterDescriptor() +{ + uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW); + uno::Reference< sheet::XSheetFilterDescriptor > xSheetFilterDescr = xDescr->getFilterDescriptor(); + CPPUNIT_ASSERT(xSheetFilterDescr.is()); +} + +void XDataPilotDescriptor::testGetDataPilotFields_Impl( uno::Reference< sheet::XDataPilotDescriptor > const & xDescr) +{ + uno::Reference< container::XIndexAccess > xIndex(xDescr->getDataPilotFields(), UNO_SET_THROW); + + sal_Int32 nCount = xIndex->getCount(); + + OUString aOrientation("Orientation"); + for (sal_Int32 i = 0; i < nCount && i < 5; ++i) + { + uno::Reference< container::XNamed > xNamed( xIndex->getByIndex( i ), UNO_QUERY_THROW); + OUString aName = xNamed->getName(); + maFieldNames.push_back(aName); + CPPUNIT_ASSERT( aName != "Data" ); + + uno::Reference< beans::XPropertySet > xPropSet( xNamed, UNO_QUERY_THROW); + + switch ( i % 5 ) + { + case 0: + { + uno::Any aAny; + aAny<<= sheet::DataPilotFieldOrientation_COLUMN; + xPropSet->setPropertyValue(aOrientation, aAny); + } + break; + case 1: + { + uno::Any aAny; + aAny<<= sheet::DataPilotFieldOrientation_ROW; + xPropSet->setPropertyValue(aOrientation, aAny); + } + break; + case 2: + { + uno::Any aAny; + aAny<<= sheet::DataPilotFieldOrientation_DATA; + xPropSet->setPropertyValue(aOrientation, aAny); + } + break; + case 3: + { + uno::Any aAny; + aAny<<= sheet::DataPilotFieldOrientation_HIDDEN; + xPropSet->setPropertyValue(aOrientation, aAny); + } + break; + case 4: + { + uno::Any aAny; + aAny<<= sheet::DataPilotFieldOrientation_PAGE; + xPropSet->setPropertyValue(aOrientation, aAny); + } + break; + } + } +} + +void XDataPilotDescriptor::testGetDataPilotFields() +{ + uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW); + testGetDataPilotFields_Impl( xDescr ); +} + +void XDataPilotDescriptor::testGetColumnFields() +{ + uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW); + testGetDataPilotFields_Impl( xDescr ); + uno::Reference< container::XIndexAccess > xIndex(xDescr->getColumnFields(), UNO_SET_THROW); + + checkName( xIndex, 0 ); +} + +void XDataPilotDescriptor::testGetRowFields() +{ + uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW); + testGetDataPilotFields_Impl( xDescr ); + uno::Reference< container::XIndexAccess > xIndex(xDescr->getRowFields(), UNO_SET_THROW); + + //checkName( xIndex, 1 ); +} + +void XDataPilotDescriptor::testGetPageFields() +{ + uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(), UNO_QUERY_THROW); + testGetDataPilotFields_Impl( xDescr ); + uno::Reference< container::XIndexAccess > xIndex(xDescr->getPageFields(), UNO_SET_THROW); + + checkName( xIndex, 4 ); +} + +void XDataPilotDescriptor::testGetDataFields() +{ + uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW); + testGetDataPilotFields_Impl( xDescr ); + uno::Reference< container::XIndexAccess > xIndex(xDescr->getDataFields(), UNO_SET_THROW); + + checkName( xIndex, 2 ); +} + +void XDataPilotDescriptor::testGetHiddenFields() +{ + uno::Reference< sheet::XDataPilotDescriptor > xDescr(init(),UNO_QUERY_THROW); + testGetDataPilotFields_Impl( xDescr ); + uno::Reference< container::XIndexAccess > xIndex(xDescr->getHiddenFields(), UNO_SET_THROW); + + checkName( xIndex, 3 ); +} + +void XDataPilotDescriptor::checkName( uno::Reference< container::XIndexAccess > const & xIndex, sal_Int32 nIndex ) +{ + CPPUNIT_ASSERT(xIndex.is()); + CPPUNIT_ASSERT(maFieldNames.size() >= o3tl::make_unsigned(nIndex)); + + for (sal_Int32 i = 0; i < xIndex->getCount(); ++i) + { + uno::Reference< container::XNamed > xNamed( xIndex->getByIndex(i), UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL(maFieldNames[nIndex], xNamed->getName()); + } +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xdatapilotfield.cxx b/test/source/sheet/xdatapilotfield.cxx new file mode 100644 index 000000000..9f14709e6 --- /dev/null +++ b/test/source/sheet/xdatapilotfield.cxx @@ -0,0 +1,40 @@ +/* -*- 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 <test/sheet/xdatapilotfield.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/sheet/XDataPilotField.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XDataPilotField::testGetItems() +{ + uno::Reference<sheet::XDataPilotField> xDPF(init(), UNO_QUERY_THROW); + + uno::Reference<container::XIndexAccess> xIA(xDPF->getItems(), UNO_SET_THROW); + + const sal_Int32 nCount = xIA->getCount(); + CPPUNIT_ASSERT_MESSAGE("No items found", sal_Int32(0) != nCount); + + for (auto i = 0; i < nCount; i++) + { + CPPUNIT_ASSERT_NO_THROW_MESSAGE("Unable to access element at position " + std::to_string(i), + xIA->getByIndex(i)); + } +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xdatapilotfieldgrouping.cxx b/test/source/sheet/xdatapilotfieldgrouping.cxx new file mode 100644 index 000000000..d3ca40d13 --- /dev/null +++ b/test/source/sheet/xdatapilotfieldgrouping.cxx @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xdatapilotfieldgrouping.hxx> + +#include <com/sun/star/sheet/XDataPilotFieldGrouping.hpp> +#include <com/sun/star/sheet/DataPilotFieldGroupBy.hpp> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest { + +void XDataPilotFieldGrouping::testCreateNameGroup() +{ + uno::Reference< sheet::XDataPilotFieldGrouping > xDataPilotFieldGrouping(init(),UNO_QUERY_THROW); + uno::Reference< sheet::XDataPilotField > xDataPilotField( xDataPilotFieldGrouping, UNO_QUERY_THROW ); + uno::Reference< container::XNameAccess > xNameAccess( xDataPilotField->getItems(), UNO_QUERY_THROW ); + CPPUNIT_ASSERT(xNameAccess->hasElements()); + + uno::Sequence< OUString > aElements = xNameAccess->getElementNames(); + xDataPilotFieldGrouping->createNameGroup( aElements ); +} + +void XDataPilotFieldGrouping::testCreateDateGroup() +{ + uno::Reference< sheet::XDataPilotFieldGrouping > xDataPilotFieldGrouping(init(),UNO_QUERY_THROW); + sheet::DataPilotFieldGroupInfo aGroupInfo; + aGroupInfo.GroupBy = sheet::DataPilotFieldGroupBy::MONTHS; + aGroupInfo.HasDateValues = true; + xDataPilotFieldGrouping->createDateGroup(aGroupInfo); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xdatapilottable.cxx b/test/source/sheet/xdatapilottable.cxx new file mode 100644 index 000000000..4cfff74ed --- /dev/null +++ b/test/source/sheet/xdatapilottable.cxx @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xdatapilottable.hxx> +#include <com/sun/star/sheet/XDataPilotTable.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XDataPilotTable::testGetOutputRange() +{ + uno::Reference<sheet::XDataPilotTable> xDPTable(init(), UNO_QUERY_THROW); + + table::CellRangeAddress aRange = xDPTable->getOutputRange(); + CPPUNIT_ASSERT_EQUAL(sal_Int16(0), aRange.Sheet); + CPPUNIT_ASSERT_EQUAL(sal_Int32(7), aRange.StartColumn); + CPPUNIT_ASSERT_EQUAL(sal_Int32(8), aRange.StartRow); +} + +void XDataPilotTable::testRefresh() +{ + uno::Reference<sheet::XDataPilotTable> xDPTable(init(), UNO_QUERY_THROW); + std::cout << "xCellForChange: Old Value: " << xCellForChange->getValue() << std::endl; + std::cout << "xCellForCheck: Old Value: " << xCellForCheck->getValue() << std::endl; + double aOldData = xCellForCheck->getValue(); + xCellForChange->setValue(5); + + xDPTable->refresh(); + xDPTable->refresh(); + std::cout << "xCellForChange: Old Value: " << xCellForChange->getValue() << std::endl; + std::cout << "xCellForCheck: Old Value: " << xCellForCheck->getValue() << std::endl; + double aNewData = xCellForCheck->getValue(); + CPPUNIT_ASSERT_MESSAGE("value needs to change", aOldData != aNewData); +} + +XDataPilotTable::~XDataPilotTable() {} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xdatapilottable2.cxx b/test/source/sheet/xdatapilottable2.cxx new file mode 100644 index 000000000..2e802eead --- /dev/null +++ b/test/source/sheet/xdatapilottable2.cxx @@ -0,0 +1,276 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xdatapilottable2.hxx> +#include <com/sun/star/sheet/XDataPilotTable2.hpp> +#include <com/sun/star/sheet/DataPilotTableResultData.hpp> +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> +#include <com/sun/star/sheet/DataPilotTablePositionType.hpp> +#include <com/sun/star/sheet/DataPilotOutputRangeType.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/sheet/XCellAddressable.hpp> +#include <com/sun/star/table/XCellCursor.hpp> +#include <com/sun/star/sheet/XCellRangeData.hpp> +#include <com/sun/star/sheet/DataResult.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <cppunit/TestAssert.h> +#include <numeric> + +using namespace css; +using namespace css::uno; + +namespace apitest { + +XDataPilotTable2::~XDataPilotTable2() +{ +} + +void XDataPilotTable2::testGetPositionData() +{ + uno::Reference< sheet::XDataPilotTable2 > xDPTable(initDP2(), UNO_QUERY_THROW); + getOutputRanges(xDPTable); + table::CellAddress aAddr; + + aAddr.Sheet = maRangeTable.Sheet; + for (sal_Int32 x = maRangeTable.StartColumn; x <= maRangeTable.EndColumn; ++x) + { + for (sal_Int32 y = maRangeTable.StartRow; y <= maRangeTable.EndRow; ++y) + { + aAddr.Column = x; + aAddr.Row = y; + + sheet::DataPilotTablePositionData aPosData = xDPTable->getPositionData(aAddr); + if (aPosData.PositionType == sheet::DataPilotTablePositionType::NOT_IN_TABLE) + { + CPPUNIT_ASSERT(false); + } + } + } +} + +void XDataPilotTable2::testGetDrillDownData() +{ + uno::Reference< sheet::XDataPilotTable2 > xDPTable(initDP2(), UNO_QUERY_THROW); + + getOutputRanges(xDPTable); + buildDataFields(xDPTable); + buildResultCells(xDPTable); + + for (const auto& rResultCell : maResultCells) + { + sheet::DataPilotTablePositionData aPosData = xDPTable->getPositionData(rResultCell); + Any aTempAny = aPosData.PositionData; + sheet::DataPilotTableResultData aResData; + CPPUNIT_ASSERT(aTempAny >>= aResData); + sal_Int32 nDim = maDataFieldDims[aResData.DataFieldIndex]; + sheet::DataResult aRes = aResData.Result; + double nVal = aRes.Value; + + const Sequence< Sequence<Any> > aData = xDPTable->getDrillDownData(rResultCell); + double sum = 0; + + if( aData.getLength() > 1 ) + { + sum = std::accumulate(std::next(aData.begin()), aData.end(), double(0), + [nDim](double res, const Sequence<Any>& rSeq) { + double nValue = 0; + if (rSeq[nDim] >>= nValue) + return res + nValue; + return res; + }); + } + + CPPUNIT_ASSERT_DOUBLES_EQUAL(nVal, sum, 1E-12); + } + + +} + +void XDataPilotTable2::testGetOutputRangeByType() +{ + uno::Reference< sheet::XDataPilotTable2 > xDPTable(initDP2(), UNO_QUERY_THROW); + getOutputRanges(xDPTable); + + // check for wrong arguments + bool bCaught = false; + try + { + xDPTable->getOutputRangeByType(-1); + } + catch ( const lang::IllegalArgumentException& ) + { + bCaught = true; + } + CPPUNIT_ASSERT(bCaught); + + bCaught = false; + try + { + xDPTable->getOutputRangeByType(100); + } + catch ( const lang::IllegalArgumentException& ) + { + bCaught = true; + } + CPPUNIT_ASSERT(bCaught); + + // make sure the whole range is not empty + CPPUNIT_ASSERT( maRangeWhole.EndColumn - maRangeWhole.StartColumn > 0); + CPPUNIT_ASSERT( maRangeWhole.EndRow - maRangeWhole.StartRow > 0); + + //table range must be of equal width with the whole range, and the same bottom + CPPUNIT_ASSERT_EQUAL( maRangeWhole.Sheet, maRangeTable.Sheet ); + CPPUNIT_ASSERT_EQUAL( maRangeWhole.EndRow, maRangeTable.EndRow ); + CPPUNIT_ASSERT_EQUAL( maRangeWhole.StartColumn, maRangeTable.StartColumn ); + CPPUNIT_ASSERT_EQUAL( maRangeWhole.EndColumn, maRangeTable.EndColumn ); + + //result range must be smaller than the table range, and must share the same lower-right corner + CPPUNIT_ASSERT_EQUAL( maRangeTable.Sheet, maRangeResult.Sheet ); + CPPUNIT_ASSERT( maRangeResult.StartColumn >= maRangeTable.StartColumn ); + CPPUNIT_ASSERT( maRangeResult.StartRow >= maRangeTable.StartRow ); + CPPUNIT_ASSERT_EQUAL( maRangeTable.EndRow, maRangeResult.EndRow ); + CPPUNIT_ASSERT_EQUAL( maRangeTable.EndColumn, maRangeResult.EndColumn ); + +} + +void XDataPilotTable2::testInsertDrillDownSheet() +{ + uno::Reference< sheet::XDataPilotTable2 > xDPTable(initDP2(), UNO_QUERY_THROW); + sal_Int32 nCellCount = maResultCells.size(); + + uno::Reference< sheet::XSpreadsheets > xSheets(getSheets(), UNO_QUERY_THROW); + uno::Reference< container::XIndexAccess > xIA(xSheets, UNO_QUERY_THROW); + sal_Int32 nSheetCount = xIA->getCount(); + + for (sal_Int32 i = 0; i < nCellCount; ++i) + { + table::CellAddress aAddr = maResultCells[i]; + uno::Sequence< uno::Sequence< Any > > aData = xDPTable->getDrillDownData(aAddr); + xDPTable->insertDrillDownSheet(aAddr); + + sal_Int32 nNewSheetCount= xIA->getCount(); + if (nNewSheetCount == nSheetCount + 1) + { + CPPUNIT_ASSERT(aData.getLength() >= 2); + uno::Reference< sheet::XSpreadsheet > xSheet(xIA->getByIndex(aAddr.Sheet),UNO_QUERY_THROW); + + checkDrillDownSheetContent(xSheet, aData); + + uno::Reference< container::XNamed > xNamed(xSheet, UNO_QUERY_THROW); + OUString aName = xNamed->getName(); + xSheets->removeByName(aName); + } + else if (nNewSheetCount == nSheetCount) + { + if (aData.getLength() > 1) + { + CPPUNIT_ASSERT(false); + } + } + else + { + CPPUNIT_ASSERT(false); + } + + } +} + +void XDataPilotTable2::buildResultCells( uno::Reference< sheet::XDataPilotTable2 > const & xDPTable) +{ + getOutputRanges(xDPTable); + maResultCells.clear(); + + for ( sal_Int32 x = maRangeResult.StartColumn; x < maRangeResult.EndColumn; ++x) + { + for( sal_Int32 y = maRangeResult.StartRow; y < maRangeResult.EndRow; ++y) + { + table::CellAddress aAddr; + aAddr.Sheet = maRangeResult.Sheet; + aAddr.Column = x; + aAddr.Row = y; + sheet::DataPilotTablePositionData aPosData = xDPTable->getPositionData(aAddr); + if (aPosData.PositionType != sheet::DataPilotTablePositionType::RESULT) + { + CPPUNIT_ASSERT(false); + } + maResultCells.push_back(aAddr); + } + } +} + +void XDataPilotTable2::getOutputRanges( uno::Reference< sheet::XDataPilotTable2 > const & xDPTable) +{ + maRangeWhole = xDPTable->getOutputRangeByType(sheet::DataPilotOutputRangeType::WHOLE); + maRangeTable = xDPTable->getOutputRangeByType(sheet::DataPilotOutputRangeType::TABLE); + maRangeResult = xDPTable->getOutputRangeByType(sheet::DataPilotOutputRangeType::RESULT); +} + +void XDataPilotTable2::buildDataFields( uno::Reference< sheet::XDataPilotTable2 > const & xDPTable ) +{ + uno::Reference< sheet::XDataPilotDescriptor > xDesc(xDPTable, UNO_QUERY_THROW); + uno::Reference< container::XIndexAccess > xIndex(xDesc->getDataPilotFields(), UNO_SET_THROW); + + sal_Int32 nFieldCount = xIndex->getCount(); + for( sal_Int32 i = 0; i < nFieldCount; ++i) + { + uno::Reference< beans::XPropertySet > xPropSet(xIndex->getByIndex(i), UNO_QUERY_THROW); + Any aAny = xPropSet->getPropertyValue("Orientation"); + sheet::DataPilotFieldOrientation aOrientation; + CPPUNIT_ASSERT( aAny >>= aOrientation ); + + if ( aOrientation == sheet::DataPilotFieldOrientation_DATA ) + { + maDataFieldDims.push_back( i ); + } + } +} + +namespace { + +table::CellAddress getLastUsedCellAddress( uno::Reference< sheet::XSpreadsheet > const & xSheet, sal_Int32 nCol, sal_Int32 nRow ) +{ + uno::Reference< sheet::XSheetCellRange > xSheetRange( xSheet->getCellRangeByPosition(nCol, nRow, nCol, nRow), UNO_QUERY_THROW); + uno::Reference< sheet::XSheetCellCursor > xCursor = xSheet->createCursorByRange(xSheetRange); + uno::Reference< table::XCellCursor > xCellCursor(xCursor, UNO_QUERY_THROW); + xCellCursor->gotoEnd(); + + uno::Reference< sheet::XCellAddressable > xCellAddr(xCursor->getCellByPosition(0, 0), UNO_QUERY_THROW); + return xCellAddr->getCellAddress(); +} + +} + +void XDataPilotTable2::checkDrillDownSheetContent(uno::Reference< sheet::XSpreadsheet > const & xSheet, const uno::Sequence< uno::Sequence< Any > >& aData) +{ + table::CellAddress aLastCell = getLastUsedCellAddress(xSheet, 0, 0); + CPPUNIT_ASSERT(aData.hasElements()); + CPPUNIT_ASSERT(aLastCell.Row); + CPPUNIT_ASSERT(aLastCell.Column); + + CPPUNIT_ASSERT_EQUAL(aData.getLength(), aLastCell.Row + 1); + CPPUNIT_ASSERT_EQUAL(aData[0].getLength(), aLastCell.Column + 1); + + uno::Reference< table::XCellRange > xCellRange = xSheet->getCellRangeByPosition(0, 0, aLastCell.Column, aLastCell.Row); + uno::Reference< sheet::XCellRangeData > xCellRangeData(xCellRange, UNO_QUERY_THROW); + + uno::Sequence< uno::Sequence< Any > > aSheetData = xCellRangeData->getDataArray(); + for (sal_Int32 x = 0; x < aSheetData.getLength(); ++x) + { + for(sal_Int32 y = 0; y < aSheetData[x].getLength(); ++y) + { + const Any& aCell1 = aSheetData[x][y]; + const Any& aCell2 = aData[x][y]; + CPPUNIT_ASSERT_EQUAL(aCell2, aCell1); + } + } +} + +} +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xdatapilottables.cxx b/test/source/sheet/xdatapilottables.cxx new file mode 100644 index 000000000..b666650ea --- /dev/null +++ b/test/source/sheet/xdatapilottables.cxx @@ -0,0 +1,53 @@ +/* -*- 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 <test/sheet/xdatapilottables.hxx> + +#include <com/sun/star/sheet/XDataPilotDescriptor.hpp> +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XDataPilotTables::testXDataPilotTables() +{ + uno::Reference<sheet::XDataPilotTables> xDPT(init(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(getXSpreadsheet(), UNO_QUERY_THROW); + + uno::Reference<sheet::XDataPilotDescriptor> xDPD(xDPT->createDataPilotDescriptor(), + UNO_SET_THROW); + + xDPT->insertNewByName("XDataPilotTables", table::CellAddress(0, 9, 8), xDPD); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to insert new DataPilotTable", OUString("Filter"), + xSheet->getCellByPosition(9, 8)->getFormula()); + + CPPUNIT_ASSERT_THROW_MESSAGE( + "No exception thrown, when inserting element with existing name", + xDPT->insertNewByName("XDataPilotTables", table::CellAddress(0, 7, 7), xDPD), + css::uno::RuntimeException); + + xDPT->removeByName("XDataPilotTables"); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to remove DataPilotTable", OUString(""), + xSheet->getCellByPosition(9, 8)->getFormula()); + + CPPUNIT_ASSERT_THROW_MESSAGE("No exception, when removing no existing element", + xDPT->removeByName("XDataPilotTables"), + css::uno::RuntimeException); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xdatapilottablessupplier.cxx b/test/source/sheet/xdatapilottablessupplier.cxx new file mode 100644 index 000000000..66b8d44ca --- /dev/null +++ b/test/source/sheet/xdatapilottablessupplier.cxx @@ -0,0 +1,29 @@ +/* -*- 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 <test/sheet/xdatapilottablessupplier.hxx> + +#include <com/sun/star/sheet/XDataPilotTables.hpp> +#include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XDataPilotTablesSupplier::testGetDataPilotTables() +{ + uno::Reference<sheet::XDataPilotTablesSupplier> xDPTS(init(), UNO_QUERY_THROW); + + uno::Reference<sheet::XDataPilotTables> xDPT(xDPTS->getDataPilotTables(), UNO_SET_THROW); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xddelink.cxx b/test/source/sheet/xddelink.cxx new file mode 100644 index 000000000..cf56fe9cd --- /dev/null +++ b/test/source/sheet/xddelink.cxx @@ -0,0 +1,44 @@ +/* -*- 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 <test/sheet/xddelink.hxx> + +#include <com/sun/star/sheet/XDDELink.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XDDELink::testGetApplication() +{ + uno::Reference<sheet::XDDELink> xLink(init(), UNO_QUERY_THROW); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to execute getApplication()", OUString("soffice"), + xLink->getApplication()); +} +void XDDELink::testGetItem() +{ + uno::Reference<sheet::XDDELink> xLink(init(), UNO_QUERY_THROW); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to execute getItem()", OUString("Sheet1.A1"), + xLink->getItem()); +} +void XDDELink::testGetTopic() +{ + uno::Reference<sheet::XDDELink> xLink(init(), UNO_QUERY_THROW); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to execute getTopic()", m_URL, xLink->getTopic()); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xddelinks.cxx b/test/source/sheet/xddelinks.cxx new file mode 100644 index 000000000..fc18a16a1 --- /dev/null +++ b/test/source/sheet/xddelinks.cxx @@ -0,0 +1,41 @@ +/* -*- 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 <test/sheet/xddelinks.hxx> + +#include <com/sun/star/sheet/DDELinkMode.hpp> +#include <com/sun/star/sheet/XDDELink.hpp> +#include <com/sun/star/sheet/XDDELinks.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XDDELinks::testAddDDELink() +{ + uno::Reference<sheet::XDDELinks> xLinks(init(), UNO_QUERY_THROW); + + uno::Reference<sheet::XDDELink> xLink + = xLinks->addDDELink("soffice", m_aTopic, "Sheet1.A1", sheet::DDELinkMode_DEFAULT); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to execute getApplication()", OUString("soffice"), + xLink->getApplication()); + CPPUNIT_ASSERT_MESSAGE("Unable to execute getTopic()", + xLink->getTopic().endsWith("ScDDELinksObj.ods")); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to execute getItem()", OUString("Sheet1.A1"), + xLink->getItem()); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xdocumentauditing.cxx b/test/source/sheet/xdocumentauditing.cxx new file mode 100644 index 000000000..8728f02bf --- /dev/null +++ b/test/source/sheet/xdocumentauditing.cxx @@ -0,0 +1,137 @@ +/* -*- 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 <test/sheet/xdocumentauditing.hxx> + +#include <com/sun/star/awt/Point.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/drawing/XDrawPage.hpp> +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/frame/DispatchHelper.hpp> +#include <com/sun/star/frame/XDispatchHelper.hpp> +#include <com/sun/star/frame/XDispatchProvider.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/sheet/XDocumentAuditing.hpp> +#include <com/sun/star/sheet/XSheetAuditing.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/XComponentContext.hpp> + +#include <comphelper/processfactory.hxx> +#include <comphelper/propertyvalue.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XDocumentAuditing::dispatch(const uno::Reference<frame::XFrame>& xFrame, + const uno::Sequence<beans::PropertyValue>& rArguments) +{ + uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext(); + uno::Reference<frame::XDispatchHelper> xDispatchHelper(frame::DispatchHelper::create(xContext), + UNO_SET_THROW); + CPPUNIT_ASSERT(xDispatchHelper.is()); + + uno::Reference<frame::XDispatchProvider> xDispatchProvider(xFrame, UNO_QUERY_THROW); + CPPUNIT_ASSERT(xDispatchProvider.is()); + + xDispatchHelper->executeDispatch(xDispatchProvider, ".uno:AutoRefreshArrows", "", 0, + rArguments); +} + +bool XDocumentAuditing::hasRightAmountOfShapes(const uno::Reference<drawing::XDrawPage>& xDrawPage, + sal_Int32 nElementCount, sal_Int32 nShapes) +{ + const sal_Int32 nCount = xDrawPage->getCount(); + if (nCount != nElementCount + nShapes) + return false; + else + { + if (nShapes >= 0) + { + for (sal_Int32 i = nElementCount; i < nCount; i++) + { + uno::Reference<drawing::XShape> xShape(xDrawPage->getByIndex(i), UNO_QUERY_THROW); + m_Position = xShape->getPosition(); + } + } + } + return true; +} + +void XDocumentAuditing::testRefreshArrows() +{ + uno::Reference<sheet::XDocumentAuditing> xDocumentAuditing(init(), UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(xDocumentAuditing, UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), UNO_SET_THROW); + uno::Reference<container::XIndexAccess> xIA(xSheets, UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet1(xIA->getByIndex(0), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet2(xIA->getByIndex(1), UNO_QUERY_THROW); + + uno::Reference<drawing::XDrawPagesSupplier> xDPS(xDocumentAuditing, UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPage> xDrawPage(xDPS->getDrawPages()->getByIndex(1), + UNO_QUERY_THROW); + + sal_Int32 nDrawPageElementCount = 0; + if (xDrawPage->hasElements()) + nDrawPageElementCount = xDrawPage->getCount(); + + uno::Sequence<beans::PropertyValue> aPropertyValue{ comphelper::makePropertyValue( + "AutoRefreshArrows", false) }; + uno::Reference<frame::XModel> xModel(xDocumentAuditing, UNO_QUERY_THROW); + dispatch(xModel->getCurrentController()->getFrame(), aPropertyValue); + + xSheet1->getCellByPosition(6, 6)->setValue(9); + uno::Reference<container::XNamed> xNA1(xSheet1, UNO_QUERY_THROW); + OUString sSheet1Name = xNA1->getName(); + + xSheet2->getCellByPosition(6, 6)->setValue(16); + xSheet2->getCellByPosition(6, 7)->setFormula("= SQRT(G7)"); + + uno::Reference<sheet::XSheetAuditing> xSheetAuditing(xSheet2, UNO_QUERY_THROW); + xSheetAuditing->showPrecedents(table::CellAddress(1, 6, 7)); + bool bResult = hasRightAmountOfShapes(xDrawPage, nDrawPageElementCount, 1); + CPPUNIT_ASSERT_MESSAGE("Wrong amount of shapes on page", bResult); + awt::Point Position0 = m_Position; + + CPPUNIT_ASSERT_DOUBLES_EQUAL(4, xSheet2->getCellByPosition(6, 7)->getValue(), 0.1); + xSheet2->getCellByPosition(6, 7)->setFormula("= SQRT(" + sSheet1Name + ".G7)"); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3, xSheet2->getCellByPosition(6, 7)->getValue(), 0.1); + + bResult = hasRightAmountOfShapes(xDrawPage, nDrawPageElementCount, 1); + CPPUNIT_ASSERT_MESSAGE("Wrong amount of shapes on page", bResult); + awt::Point Position1 = m_Position; + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Arrow has been refreshed", Position0.X, Position1.X); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Arrow has been refreshed", Position0.Y, Position1.Y); + + xDocumentAuditing->refreshArrows(); + + bResult = hasRightAmountOfShapes(xDrawPage, nDrawPageElementCount, 1); + CPPUNIT_ASSERT_MESSAGE("Wrong amount of shapes on page", bResult); + awt::Point Position2 = m_Position; + + CPPUNIT_ASSERT_MESSAGE("Arrow has not been refreshed", + Position1.X != Position2.X || Position1.Y != Position2.Y); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xformulaquery.cxx b/test/source/sheet/xformulaquery.cxx new file mode 100644 index 000000000..32540847e --- /dev/null +++ b/test/source/sheet/xformulaquery.cxx @@ -0,0 +1,66 @@ +/* -*- 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 <test/cppunitasserthelper.hxx> +#include <test/sheet/xformulaquery.hxx> + +#include <com/sun/star/sheet/XFormulaQuery.hpp> +#include <com/sun/star/sheet/XSheetCellRanges.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XFormulaQuery::testQueryDependents() +{ + uno::Reference<sheet::XSpreadsheet> xSheet(getXSpreadsheet(), UNO_QUERY_THROW); + xSheet->getCellByPosition(0, 0)->setValue(1); + xSheet->getCellByPosition(1, 0)->setValue(1); + xSheet->getCellByPosition(2, 0)->setValue(1); + xSheet->getCellByPosition(3, 0)->setValue(1); + + uno::Reference<table::XCell> xCell = getXCell(); + xCell->setFormula("=SUM(A1:D1)"); + + uno::Reference<sheet::XFormulaQuery> xFormulaQuery(init(), UNO_QUERY_THROW); + uno::Reference<sheet::XSheetCellRanges> xSCR = xFormulaQuery->queryDependents(false); + uno::Sequence<table::CellRangeAddress> aCellRangeAddress = xSCR->getRangeAddresses(); + + CPPUNIT_ASSERT_EQUAL(aCellRangeAddress[m_nIdxDependents], m_aCellRangeAddressDependents); +} + +void XFormulaQuery::testQueryPrecedents() +{ + uno::Reference<sheet::XSpreadsheet> xSheet(getXSpreadsheet(), UNO_QUERY_THROW); + xSheet->getCellByPosition(0, 0)->setValue(1); + xSheet->getCellByPosition(1, 0)->setValue(1); + xSheet->getCellByPosition(2, 0)->setValue(1); + xSheet->getCellByPosition(3, 0)->setValue(1); + xSheet->getCellByPosition(1, 2)->setFormula("=A16 * 2"); + + uno::Reference<table::XCell> xCell = getXCell(); + xCell->setFormula("=SUM(A1:D1)"); + + uno::Reference<sheet::XFormulaQuery> xFormulaQuery(init(), UNO_QUERY_THROW); + uno::Reference<sheet::XSheetCellRanges> xSCR = xFormulaQuery->queryPrecedents(false); + uno::Sequence<table::CellRangeAddress> aCellRangeAddress = xSCR->getRangeAddresses(); + + CPPUNIT_ASSERT_EQUAL(aCellRangeAddress[m_nIdxPrecedents], m_aCellRangeAddressPrecedents); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xfunctiondescriptions.cxx b/test/source/sheet/xfunctiondescriptions.cxx new file mode 100644 index 000000000..1b4ef645e --- /dev/null +++ b/test/source/sheet/xfunctiondescriptions.cxx @@ -0,0 +1,73 @@ +/* -*- 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 <random> + +#include <test/sheet/xfunctiondescriptions.hxx> + +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/sheet/XFunctionDescriptions.hpp> +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XFunctionDescriptions::testGetById() +{ + uno::Reference<sheet::XFunctionDescriptions> xFD(init(), UNO_QUERY_THROW); + + const sal_Int32 nCount = xFD->getCount(); + CPPUNIT_ASSERT_MESSAGE("No FunctionDescriptions available", 0 < nCount); + + // first grab a random function descriptions + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> distr(0, nCount - 1); + int nNumber = distr(gen); + + sal_Int32 aId1 = 0; + OUString aName1; + uno::Sequence<beans::PropertyValue> aProps1; + CPPUNIT_ASSERT(xFD->getByIndex(nNumber) >>= aProps1); + for (const auto& aProp : std::as_const(aProps1)) + { + if (aProp.Name == "Id") + aId1 = aProp.Value.get<sal_Int32>(); + if (aProp.Name == "Name") + aName1 = aProp.Value.get<OUString>(); + } + + // fetch the same descriptions by its id + sal_Int32 aId2 = 0; + OUString aName2; + const uno::Sequence<beans::PropertyValue> aProps2 = xFD->getById(aId1); + CPPUNIT_ASSERT_MESSAGE("Received empty FunctionDescriptions from getById()", + aProps2.hasElements()); + for (const auto& aProp : aProps2) + { + if (aProp.Name == "Id") + aId2 = aProp.Value.get<sal_Int32>(); + if (aProp.Name == "Name") + aName2 = aProp.Value.get<OUString>(); + } + CPPUNIT_ASSERT_EQUAL_MESSAGE("Received wrong FunctionDescriptions (Id)", aId1, aId2); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Received wrong FunctionDescriptions (Name)", aName1, aName2); + + CPPUNIT_ASSERT_THROW_MESSAGE("No IllegalArgumentException thrown", xFD->getById(-1), + css::lang::IllegalArgumentException); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xgoalseek.cxx b/test/source/sheet/xgoalseek.cxx new file mode 100644 index 000000000..b1de09d2e --- /dev/null +++ b/test/source/sheet/xgoalseek.cxx @@ -0,0 +1,36 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xgoalseek.hxx> +#include <com/sun/star/sheet/XGoalSeek.hpp> +#include <com/sun/star/sheet/GoalResult.hpp> +#include <com/sun/star/table/CellAddress.hpp> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XGoalSeek::testSeekGoal() +{ + uno::Reference<sheet::XGoalSeek> xGoalSeek(init(), UNO_QUERY_THROW); + + table::CellAddress aFormulaAddr(0, 3, 5); + table::CellAddress aVariableAddr(0, 3, 4); + sheet::GoalResult aResult = xGoalSeek->seekGoal(aFormulaAddr, aVariableAddr, "4"); + + double nDivergence = 0.01; + CPPUNIT_ASSERT(aResult.Divergence < nDivergence); + CPPUNIT_ASSERT_DOUBLES_EQUAL(16, aResult.Result, nDivergence); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xheaderfootercontent.cxx b/test/source/sheet/xheaderfootercontent.cxx new file mode 100644 index 000000000..1683cc7e7 --- /dev/null +++ b/test/source/sheet/xheaderfootercontent.cxx @@ -0,0 +1,48 @@ +/* -*- 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 <test/sheet/xheaderfootercontent.hxx> + +#include <com/sun/star/sheet/XHeaderFooterContent.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XHeaderFooterContent::testGetCenterText() +{ + uno::Reference<sheet::XHeaderFooterContent> xHFC(init(), UNO_QUERY_THROW); + + uno::Reference<text::XText> xText(xHFC->getCenterText(), UNO_SET_THROW); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get center text", OUString("CENTER"), + xText->getString()); +} + +void XHeaderFooterContent::testGetLeftText() +{ + uno::Reference<sheet::XHeaderFooterContent> xHFC(init(), UNO_QUERY_THROW); + + uno::Reference<text::XText> xText(xHFC->getLeftText(), UNO_SET_THROW); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get left text", OUString("LEFT"), xText->getString()); +} +void XHeaderFooterContent::testGetRightText() +{ + uno::Reference<sheet::XHeaderFooterContent> xHFC(init(), UNO_QUERY_THROW); + + uno::Reference<text::XText> xText(xHFC->getRightText(), UNO_SET_THROW); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get right text", OUString("RIGHT"), xText->getString()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xlabelrange.cxx b/test/source/sheet/xlabelrange.cxx new file mode 100644 index 000000000..ed7195123 --- /dev/null +++ b/test/source/sheet/xlabelrange.cxx @@ -0,0 +1,50 @@ +/* -*- 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 <test/sheet/xlabelrange.hxx> +#include <test/cppunitasserthelper.hxx> + +#include <com/sun/star/sheet/XLabelRange.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XLabelRange::testGetSetDataArea() +{ + uno::Reference<sheet::XLabelRange> xLabelRange(init(), UNO_QUERY_THROW); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get DataArea", table::CellRangeAddress(0, 0, 0, 0, 1), + xLabelRange->getDataArea()); + + table::CellRangeAddress aDataAddr(1, 0, 1, 0, 8); + xLabelRange->setDataArea(aDataAddr); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set DataArea", aDataAddr, xLabelRange->getDataArea()); +} + +void XLabelRange::testGetSetLabelArea() +{ + uno::Reference<sheet::XLabelRange> xLabelRange(init(), UNO_QUERY_THROW); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get DataArea", table::CellRangeAddress(0, 0, 1, 0, 6), + xLabelRange->getLabelArea()); + + table::CellRangeAddress aLabelAddr(1, 0, 1, 0, 8); + xLabelRange->setLabelArea(aLabelAddr); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set LabelArea", aLabelAddr, + xLabelRange->getLabelArea()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xlabelranges.cxx b/test/source/sheet/xlabelranges.cxx new file mode 100644 index 000000000..36e2edb45 --- /dev/null +++ b/test/source/sheet/xlabelranges.cxx @@ -0,0 +1,44 @@ +/* -*- 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 <test/sheet/xlabelranges.hxx> + +#include <com/sun/star/sheet/XLabelRanges.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XLabelRanges::testAddNew() +{ + uno::Reference<sheet::XLabelRanges> xLabelRanges(init(), UNO_QUERY_THROW); + + const sal_Int32 nCount = xLabelRanges->getCount(); + xLabelRanges->addNew(table::CellRangeAddress(0, 1, 0, 1, 0), + table::CellRangeAddress(0, 1, 1, 1, 6)); + + CPPUNIT_ASSERT_MESSAGE("Unable to add new range", nCount < xLabelRanges->getCount()); +} + +void XLabelRanges::testRemoveByIndex() +{ + uno::Reference<sheet::XLabelRanges> xLabelRanges(init(), UNO_QUERY_THROW); + + const sal_Int32 nCount = xLabelRanges->getCount(); + xLabelRanges->removeByIndex(nCount - 1); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to remove range", (nCount - 1), xLabelRanges->getCount()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xmultiformulatokens.cxx b/test/source/sheet/xmultiformulatokens.cxx new file mode 100644 index 000000000..ac2b76382 --- /dev/null +++ b/test/source/sheet/xmultiformulatokens.cxx @@ -0,0 +1,43 @@ +/* -*- 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 <test/sheet/xmultiformulatokens.hxx> + +#include <com/sun/star/sheet/FormulaToken.hpp> +#include <com/sun/star/sheet/XMultiFormulaTokens.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void XMultiFormulaTokens::testGetCount() +{ + uno::Reference<sheet::XMultiFormulaTokens> xMFT(init(), uno::UNO_QUERY_THROW); + + CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xMFT->getCount()); +} + +void XMultiFormulaTokens::testGetSetTokens() +{ + uno::Reference<sheet::XMultiFormulaTokens> xMFT(init(), uno::UNO_QUERY_THROW); + + uno::Sequence<sheet::FormulaToken> aTokens{ { /* OpCode */ 2, /* Data */ {} } }; + xMFT->setTokens(0, aTokens); + + CPPUNIT_ASSERT_EQUAL(aTokens[0].OpCode, xMFT->getTokens(0)[0].OpCode); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xmultipleoperation.cxx b/test/source/sheet/xmultipleoperation.cxx new file mode 100644 index 000000000..d97f26934 --- /dev/null +++ b/test/source/sheet/xmultipleoperation.cxx @@ -0,0 +1,95 @@ +/* -*- 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 <test/sheet/xmultipleoperation.hxx> + +#include <com/sun/star/sheet/TableOperationMode.hpp> +#include <com/sun/star/sheet/XCellAddressable.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XMultipleOperation.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XMultipleOperation::testSetTableOperation() +{ + uno::Reference<sheet::XMultipleOperation> xMultipleOperation(init(), UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheet> xSheet(getXSpreadsheet(), UNO_QUERY_THROW); + uno::Reference<table::XCellRange> xCellRange(xSheet->getCellRangeByName("$A$20:$A$20"), + UNO_SET_THROW); + uno::Reference<sheet::XCellRangeAddressable> xCellRangeAddr(xCellRange, UNO_QUERY_THROW); + + uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(0, 19); + xCell->setFormula("=a18+a19"); + + uno::Reference<table::XCell> xCell1 = xSheet->getCellByPosition(0, 17); + uno::Reference<sheet::XCellAddressable> xCellAddr1(xCell1, UNO_QUERY_THROW); + + uno::Reference<table::XCell> xCell2 = xSheet->getCellByPosition(0, 18); + uno::Reference<sheet::XCellAddressable> xCellAddr2(xCell2, UNO_QUERY_THROW); + + fillCells(xSheet); + xMultipleOperation->setTableOperation( + xCellRangeAddr->getRangeAddress(), sheet::TableOperationMode_ROW, + xCellAddr1->getCellAddress(), xCellAddr2->getCellAddress()); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Check cell at position 1,1 (OpMode: ROW)", 5.0, + xSheet->getCellByPosition(1, 1)->getValue()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Check cell at position 2,1 (OpMode: ROW)", 10.0, + xSheet->getCellByPosition(2, 1)->getValue()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Check cell at position 3,1 (OpMode: ROW)", 15.0, + xSheet->getCellByPosition(3, 1)->getValue()); + + fillCells(xSheet); + xMultipleOperation->setTableOperation( + xCellRangeAddr->getRangeAddress(), sheet::TableOperationMode_COLUMN, + xCellAddr1->getCellAddress(), xCellAddr2->getCellAddress()); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Check cell at position 1,1 (OpMode: COLUMN)", 12.0, + xSheet->getCellByPosition(1, 1)->getValue()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Check cell at position 1,2 (OpMode: COLUMN)", 24.0, + xSheet->getCellByPosition(1, 2)->getValue()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Check cell at position 1,3 (OpMode: COLUMN)", 36.0, + xSheet->getCellByPosition(1, 3)->getValue()); + + fillCells(xSheet); + xMultipleOperation->setTableOperation( + xCellRangeAddr->getRangeAddress(), sheet::TableOperationMode_BOTH, + xCellAddr1->getCellAddress(), xCellAddr2->getCellAddress()); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Check cell at position 1,1 (OpMode: BOTH)", 17.0, + xSheet->getCellByPosition(1, 1)->getValue()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Check cell at position 2,2 (OpMode: BOTH)", 34.0, + xSheet->getCellByPosition(2, 2)->getValue()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Check cell at position 3,3 (OpMode: BOTH)", 51.0, + xSheet->getCellByPosition(3, 3)->getValue()); +} + +void XMultipleOperation::fillCells(uno::Reference<sheet::XSpreadsheet> const& xSheet) +{ + for (unsigned int i = 1; i < 5; i++) + { + uno::Reference<table::XCell> xCellFill = xSheet->getCellByPosition(0, i); + xCellFill->setValue(i * 12); + xCellFill = xSheet->getCellByPosition(i, 0); + xCellFill->setValue(i * 5); + } +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xnamedrange.cxx b/test/source/sheet/xnamedrange.cxx new file mode 100644 index 000000000..ea9fb7781 --- /dev/null +++ b/test/source/sheet/xnamedrange.cxx @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xnamedrange.hxx> + +#include <com/sun/star/sheet/XNamedRange.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/sheet/NamedRangeFlag.hpp> + +#include <cppunit/TestAssert.h> +#include <rtl/ustring.hxx> + +using namespace css; +using namespace css::uno; + +namespace apitest { + +void XNamedRange::testGetContent() +{ + uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange("initial1"); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected content for initial1 on GetContent", OUString("$Sheet1.$B$1"), xNamedRange->getContent()); +} + +void XNamedRange::testSetContent() +{ + uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange("initial1"); + + OUString aExpectedContent; + + // test a cell + aExpectedContent = "D1"; + xNamedRange->setContent(aExpectedContent); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected content for initial1 after SetContent a cell", aExpectedContent, xNamedRange->getContent()); + + // test a cellrange + aExpectedContent = "D1:D10"; + xNamedRange->setContent(aExpectedContent); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected content for initial1 after SetContent a cellrange", aExpectedContent, xNamedRange->getContent()); + + // test a formula + aExpectedContent = "=D10"; + xNamedRange->setContent(aExpectedContent); + aExpectedContent = "D10"; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected content for initial1 after SetContent a formula", aExpectedContent, xNamedRange->getContent()); +} + +void XNamedRange::testGetType() +{ + uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange("initial1"); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected Type", sal_Int32(0), xNamedRange->getType()); +} + +void XNamedRange::testSetType() +{ + uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange("initial1"); + + sal_Int32 nType = ::sheet::NamedRangeFlag::ROW_HEADER; + xNamedRange->setType(nType); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected Type ROW_HEADER after setting it", nType, xNamedRange->getType()); + + nType = ::sheet::NamedRangeFlag::COLUMN_HEADER; + xNamedRange->setType(nType); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected Type COLUMN_HEADER after setting it", nType, xNamedRange->getType()); + + nType = ::sheet::NamedRangeFlag::FILTER_CRITERIA; + xNamedRange->setType(nType); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected Type FILTER_CRITERIA after setting it", nType, xNamedRange->getType()); + + nType = ::sheet::NamedRangeFlag::PRINT_AREA; + xNamedRange->setType(nType); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected Type PRINT_AREA after setting it", nType, xNamedRange->getType()); + + nType = 0; + xNamedRange->setType(nType); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected Type 0 after setting it", nType, xNamedRange->getType()); +} + +void XNamedRange::testGetReferencePosition() +{ + uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange("initial2"); + + table::CellAddress aCellAddress = xNamedRange->getReferencePosition(); + // the expected address is on B1, as it was the active cell when initial2 was created + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong SHEET reference position", sal_Int16(0), aCellAddress.Sheet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong COLUMN reference position", sal_Int32(1), aCellAddress.Column); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong ROW reference position", sal_Int32(0), aCellAddress.Row); +} + +void XNamedRange::testSetReferencePosition() +{ + uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange("initial1"); + + table::CellAddress aBaseAddress(1,2,3); + + xNamedRange->setReferencePosition(aBaseAddress); + + table::CellAddress aCellAddress = xNamedRange->getReferencePosition(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong SHEET reference position after setting it", sal_Int16(1), aCellAddress.Sheet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong COLUMN reference position after setting it", sal_Int32(2), aCellAddress.Column); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong ROW reference position after setting it", sal_Int32(3), aCellAddress.Row); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xnamedranges.cxx b/test/source/sheet/xnamedranges.cxx new file mode 100644 index 000000000..e07911f42 --- /dev/null +++ b/test/source/sheet/xnamedranges.cxx @@ -0,0 +1,194 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xnamedranges.hxx> +#include <rtl/ustring.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/sheet/Border.hpp> +#include <com/sun/star/sheet/NamedRangeFlag.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XCellRangeReferrer.hpp> +#include <com/sun/star/sheet/XNamedRange.hpp> +#include <com/sun/star/sheet/XNamedRanges.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/text/XTextRange.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +#include <iostream> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XNamedRanges::testAddNewByName() +{ + uno::Reference<sheet::XNamedRanges> xNamedRanges(init(), UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xNamedRangesNameAccess(getXNamedRanges(1), + UNO_QUERY_THROW); + + table::CellAddress aBaseAddress(0, 0, 0); + + sal_Int32 nType = 0; + OUString aName1("type_0"); + xNamedRanges->addNewByName(aName1, "D1", aBaseAddress, nType); + CPPUNIT_ASSERT_MESSAGE("Failed to create Namedrange Type 0 - Normal case", + xNamedRanges->hasByName(aName1)); + + nType = ::sheet::NamedRangeFlag::COLUMN_HEADER; + OUString aName2("type_COLUMN_HEADER"); + xNamedRanges->addNewByName(aName2, "D2", aBaseAddress, nType); + CPPUNIT_ASSERT_MESSAGE("Failed to create Namedrange Type COLUMN_HEADER", + xNamedRanges->hasByName(aName2)); + + nType = ::sheet::NamedRangeFlag::FILTER_CRITERIA; + OUString aName3("type_FILTER_CRITERIA"); + xNamedRanges->addNewByName(aName3, "D3", aBaseAddress, nType); + CPPUNIT_ASSERT_MESSAGE("Failed to create Namedrange Type FILTER_CRITERIA", + xNamedRanges->hasByName(aName3)); + + nType = ::sheet::NamedRangeFlag::PRINT_AREA; + OUString aName4("type_PRINT_AREA"); + xNamedRanges->addNewByName(aName4, "D4", aBaseAddress, nType); + CPPUNIT_ASSERT_MESSAGE("Failed to create Namedrange Type PRINT_AREA", + xNamedRanges->hasByName(aName4)); + + nType = ::sheet::NamedRangeFlag::ROW_HEADER; + OUString aName5("type_ROW_HEADER"); + xNamedRanges->addNewByName(aName5, "D5", aBaseAddress, nType); + CPPUNIT_ASSERT_MESSAGE("Failed to create Namedrange Type ROW_HEADER", + xNamedRanges->hasByName(aName5)); + + // tdf#119457 - check for a valid range name + OUString aName6("type_INVALID_BAD_STRING.+:"); + CPPUNIT_ASSERT_THROW(xNamedRanges->addNewByName(aName6, "D6", aBaseAddress, 0), + uno::RuntimeException); + CPPUNIT_ASSERT_MESSAGE("Created Namedrange with invalid name", + !xNamedRanges->hasByName(aName6)); +} + +void XNamedRanges::testAddNewFromTitles() +{ + uno::Reference<sheet::XNamedRanges> xNamedRanges(getXNamedRanges(1), UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xNamedRangesIndex(xNamedRanges, UNO_QUERY_THROW); + uno::Reference<container::XNameAccess> xNamedRangesNameAccess(xNamedRanges, UNO_QUERY_THROW); + + table::CellRangeAddress aCellRangeAddress(1, 0, 0, 3, 3); + + OUString aString; + uno::Reference<table::XCell> xCell; + + xNamedRanges->addNewFromTitles(aCellRangeAddress, sheet::Border_TOP); + + for (sal_Int32 i = 1; i < 4; i++) + { + // verify namedrange exists + xCell = xSheet->getCellByPosition(i, 0); + uno::Reference<text::XTextRange> xTextRange(xCell, UNO_QUERY_THROW); + aString = xTextRange->getString(); + std::cout << "addNewFromTitles: verify " << aString << std::endl; + CPPUNIT_ASSERT_MESSAGE("Non existing NamedRange", xNamedRanges->hasByName(aString)); + + // verify it points on the right cell + uno::Any aNr = xNamedRangesNameAccess->getByName(aString); + uno::Reference<sheet::XNamedRange> xNamedRange(aNr, UNO_QUERY_THROW); + + uno::Reference<sheet::XCellRangeReferrer> xCellRangeRef(xNamedRange, UNO_QUERY_THROW); + uno::Reference<sheet::XCellRangeAddressable> xCellRangeAdr( + xCellRangeRef->getReferredCells(), UNO_QUERY_THROW); + table::CellRangeAddress cellRangeAddress = xCellRangeAdr->getRangeAddress(); + + CPPUNIT_ASSERT_EQUAL(i, cellRangeAddress.EndColumn); + CPPUNIT_ASSERT_EQUAL(i, cellRangeAddress.StartColumn); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), cellRangeAddress.StartRow); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), cellRangeAddress.EndRow); + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), cellRangeAddress.Sheet); + } + + xNamedRanges->addNewFromTitles(aCellRangeAddress, sheet::Border_LEFT); + + for (sal_Int32 i = 1; i < 4; i++) + { + // verify namedrange exists + xCell = xSheet->getCellByPosition(0, i); + uno::Reference<text::XTextRange> xTextRange(xCell, UNO_QUERY_THROW); + aString = xTextRange->getString(); + std::cout << "verify " << aString << std::endl; + CPPUNIT_ASSERT_MESSAGE("Non existing NamedRange", xNamedRanges->hasByName(aString)); + + // verify it points on the right cell + uno::Any aNr = xNamedRangesNameAccess->getByName(aString); + uno::Reference<sheet::XNamedRange> xNamedRange(aNr, UNO_QUERY_THROW); + + uno::Reference<sheet::XCellRangeReferrer> xCellRangeRef(xNamedRange, UNO_QUERY_THROW); + uno::Reference<sheet::XCellRangeAddressable> xCellRangeAdr( + xCellRangeRef->getReferredCells(), UNO_QUERY_THROW); + table::CellRangeAddress cellRangeAddress = xCellRangeAdr->getRangeAddress(); + + CPPUNIT_ASSERT_EQUAL(i, cellRangeAddress.EndRow); + CPPUNIT_ASSERT_EQUAL(i, cellRangeAddress.StartRow); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), cellRangeAddress.StartColumn); + CPPUNIT_ASSERT_EQUAL(sal_Int32(3), cellRangeAddress.EndColumn); + CPPUNIT_ASSERT_EQUAL(sal_Int16(1), cellRangeAddress.Sheet); + } +} + +void XNamedRanges::testRemoveByName() +{ + uno::Reference<sheet::XNamedRanges> xNamedRanges(init(), UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIndex(xNamedRanges, UNO_QUERY_THROW); + + bool bHasIt = xNamedRanges->hasByName(maNameToRemove); + CPPUNIT_ASSERT_MESSAGE("NamedRange initial1 does not exist, can't remove it", bHasIt); + + if (!bHasIt) + return; + + // remove existing + sal_Int32 nInitialCount = xIndex->getCount(); + xNamedRanges->removeByName(maNameToRemove); + sal_Int32 nNewCount = xIndex->getCount(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("NamedRange initial1 not removed", nNewCount, nInitialCount - 1); + CPPUNIT_ASSERT_MESSAGE("Wrong NamedRange removed, initial1 still present", + !xNamedRanges->hasByName(maNameToRemove)); + // try to remove non existing + xNamedRanges->removeByName("dummyNonExistingNamedRange"); // an exception should be raised here +} + +void XNamedRanges::testOutputList() +{ + table::CellAddress aCellAddress(0, 2, 0); + uno::Reference<sheet::XNamedRanges> xNamedRanges(init(), UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xNamedRangesIndex(init(), UNO_QUERY_THROW); + sal_Int32 nElementsCount = xNamedRangesIndex->getCount(); + + xNamedRanges->outputList(aCellAddress); + + OUString aString; + uno::Reference<table::XCell> xCell; + + for (sal_Int32 i = 0; i < nElementsCount; i++) + { + xCell = xSheet->getCellByPosition(2, i); + uno::Reference<text::XTextRange> xTextRange(xCell, UNO_QUERY_THROW); + aString = xTextRange->getString(); + std::cout << "verify " << aString << std::endl; + CPPUNIT_ASSERT_MESSAGE("Non existing NamedRange", xNamedRanges->hasByName(aString)); + } +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xprintareas.cxx b/test/source/sheet/xprintareas.cxx new file mode 100644 index 000000000..8c5ffe3d0 --- /dev/null +++ b/test/source/sheet/xprintareas.cxx @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xprintareas.hxx> +#include <com/sun/star/sheet/XPrintAreas.hpp> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest { + + void XPrintAreas::testSetAndGetPrintTitleColumns() + { + uno::Reference< sheet::XPrintAreas > xPrintAreas(init(), UNO_QUERY_THROW); + xPrintAreas->setPrintTitleColumns(true); + + CPPUNIT_ASSERT_MESSAGE("Wrong attribution at PrintTitleColumns", xPrintAreas->getPrintTitleColumns()); + + } + + void XPrintAreas::testSetAndGetPrintTitleRows() + { + uno::Reference< sheet::XPrintAreas > xPrintAreas(init(), UNO_QUERY_THROW); + xPrintAreas->setPrintTitleRows(true); + + CPPUNIT_ASSERT_MESSAGE("Wrong attribution at PrintTitleRows", xPrintAreas->getPrintTitleRows()); + } + + // the rest is right now in progress... + + +} diff --git a/test/source/sheet/xrecentfunctions.cxx b/test/source/sheet/xrecentfunctions.cxx new file mode 100644 index 000000000..5680b666a --- /dev/null +++ b/test/source/sheet/xrecentfunctions.cxx @@ -0,0 +1,77 @@ +/* -*- 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 <random> + +#include <test/sheet/xrecentfunctions.hxx> + +#include <com/sun/star/sheet/XRecentFunctions.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XRecentFunctions::testGetRecentFunctionIds() +{ + uno::Reference<sheet::XRecentFunctions> xRecentFunctions(init(), UNO_QUERY_THROW); + + uno::Sequence<sal_Int32> aIds = xRecentFunctions->getRecentFunctionIds(); + const sal_Int32 nNumber = aIds.getLength(); + CPPUNIT_ASSERT_MESSAGE("Recent IDs greater the max number", + nNumber <= xRecentFunctions->getMaxRecentFunctions()); + for (int i = 0; i < nNumber - 1; i++) + for (int j = i + 1; j < nNumber; j++) + CPPUNIT_ASSERT_MESSAGE("Same IDs found", aIds[i] != aIds[j]); +} + +void XRecentFunctions::testSetRecentFunctionIds() +{ + uno::Reference<sheet::XRecentFunctions> xRecentFunctions(init(), UNO_QUERY_THROW); + + const sal_Int32 nMaxNumber = xRecentFunctions->getMaxRecentFunctions(); + + // empty list + uno::Sequence<sal_Int32> aIds; + xRecentFunctions->setRecentFunctionIds(aIds); + + aIds = xRecentFunctions->getRecentFunctionIds(); + CPPUNIT_ASSERT_MESSAGE("Unable to set Ids (empty list)", !aIds.hasElements()); + + // max. size list + aIds.realloc(nMaxNumber); + auto pIds = aIds.getArray(); + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> distr(1, nMaxNumber + 1); + + int nStartIdx = distr(gen); + for (int i = nStartIdx; i < nStartIdx + nMaxNumber; i++) + pIds[i - nStartIdx] = 1; + + xRecentFunctions->setRecentFunctionIds(aIds); + + aIds = xRecentFunctions->getRecentFunctionIds(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set Ids (max. size list)", nMaxNumber, + aIds.getLength()); +} + +void XRecentFunctions::testGetMaxRecentFunctions() +{ + uno::Reference<sheet::XRecentFunctions> xRecentFunctions(init(), UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("Unable to execute getMaxRecentFunctions()", + sal_Int32(0) != xRecentFunctions->getMaxRecentFunctions()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xscenario.cxx b/test/source/sheet/xscenario.cxx new file mode 100644 index 000000000..9d874d951 --- /dev/null +++ b/test/source/sheet/xscenario.cxx @@ -0,0 +1,43 @@ +/* -*- 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 <test/sheet/xscenario.hxx> + +#include <com/sun/star/sheet/XScenario.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XScenario::testScenario() +{ + uno::Reference<sheet::XScenario> xScenario(getScenarioSpreadsheet(), UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("Sheet is not a Scenario sheet", xScenario->getIsScenario()); + + uno::Sequence<table::CellRangeAddress> aCellRangeAddr(1); + xScenario->addRanges(aCellRangeAddr); + xScenario->apply(); + + CPPUNIT_ASSERT_MESSAGE("Unable add and apply ranges", xScenario->getIsScenario()); + CPPUNIT_ASSERT_MESSAGE("Unable execute getScenarioComment()", + !xScenario->getScenarioComment().isEmpty()); + + xScenario->setScenarioComment("Test"); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable execute setScenarioComment()", OUString("Test"), + xScenario->getScenarioComment()); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xscenarioenhanced.cxx b/test/source/sheet/xscenarioenhanced.cxx new file mode 100644 index 000000000..ed4d934b6 --- /dev/null +++ b/test/source/sheet/xscenarioenhanced.cxx @@ -0,0 +1,38 @@ +/* -*- 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 <test/sheet/xscenarioenhanced.hxx> +#include <test/cppunitasserthelper.hxx> + +#include <com/sun/star/sheet/XScenarioEnhanced.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XScenarioEnhanced::testGetRanges() +{ + uno::Reference<sheet::XScenarioEnhanced> xSE(getScenarioSpreadsheet(), UNO_QUERY_THROW); + + uno::Sequence<table::CellRangeAddress> aCellRangeAddr = xSE->getRanges(); + CPPUNIT_ASSERT_MESSAGE("No ranges found", aCellRangeAddr.hasElements()); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong CellRangeAddres", table::CellRangeAddress(1, 0, 0, 10, 10), + aCellRangeAddr[0]); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xscenarios.cxx b/test/source/sheet/xscenarios.cxx new file mode 100644 index 000000000..77781361e --- /dev/null +++ b/test/source/sheet/xscenarios.cxx @@ -0,0 +1,43 @@ +/* -*- 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 <test/sheet/xscenarios.hxx> + +#include <com/sun/star/sheet/XScenarios.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XScenarios::testAddNewByName() +{ + uno::Reference<sheet::XScenarios> xScenarios(init(), UNO_QUERY_THROW); + + uno::Sequence<table::CellRangeAddress> aCellRangeAddresses{ table::CellRangeAddress(0, 0, 0, 0, + 0) }; + xScenarios->addNewByName("XScenarios2", aCellRangeAddresses, "new"); + CPPUNIT_ASSERT_MESSAGE("Unable to add new XScenario", xScenarios->hasByName("XScenarios2")); +} + +void XScenarios::testRemoveByName() +{ + uno::Reference<sheet::XScenarios> xScenarios(init(), UNO_QUERY_THROW); + + xScenarios->removeByName("XScenarios"); + CPPUNIT_ASSERT_MESSAGE("Unable to remove XScenario", !xScenarios->hasByName("XScenario")); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xscenariossupplier.cxx b/test/source/sheet/xscenariossupplier.cxx new file mode 100644 index 000000000..3b9ff68d4 --- /dev/null +++ b/test/source/sheet/xscenariossupplier.cxx @@ -0,0 +1,28 @@ +/* -*- 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 <test/sheet/xscenariossupplier.hxx> + +#include <com/sun/star/sheet/XScenarios.hpp> +#include <com/sun/star/sheet/XScenariosSupplier.hpp> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XScenariosSupplier::testGetScenarios() +{ + uno::Reference<sheet::XScenariosSupplier> xSupplier(init(), UNO_QUERY_THROW); + uno::Reference<sheet::XScenarios> xScenarios(xSupplier->getScenarios(), UNO_SET_THROW); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xsheetannotation.cxx b/test/source/sheet/xsheetannotation.cxx new file mode 100644 index 000000000..1ce4e1a79 --- /dev/null +++ b/test/source/sheet/xsheetannotation.cxx @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xsheetannotation.hxx> + +#include <com/sun/star/table/CellAddress.hpp> + +#include <cppunit/TestAssert.h> +#include <rtl/ustring.hxx> + +using namespace css; +using namespace css::uno; + +namespace apitest { + +void XSheetAnnotation::testGetPosition() +{ + uno::Reference< sheet::XSheetAnnotation > aSheetAnnotation (init(), UNO_QUERY_THROW); + table::CellAddress aResultCellAddress = aSheetAnnotation->getPosition(); + + //expected result + table::CellAddress aExpectedCellAddress; + aExpectedCellAddress.Sheet = 0; + aExpectedCellAddress.Row = 1; + aExpectedCellAddress.Column = 2; + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong SHEET reference position", aExpectedCellAddress.Sheet, aResultCellAddress.Sheet); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong COLUMN reference position", aExpectedCellAddress.Column, aResultCellAddress.Column); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong ROW reference position", aExpectedCellAddress.Row, aResultCellAddress.Row); +} + +void XSheetAnnotation::testGetAuthor() +{ + uno::Reference< sheet::XSheetAnnotation > aSheetAnnotation (init(), UNO_QUERY_THROW); + OUString aAuthor = aSheetAnnotation->getAuthor(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong author", OUString("LG"), aAuthor); +} +void XSheetAnnotation::testGetDate() +{ + uno::Reference< sheet::XSheetAnnotation > aSheetAnnotation (init(), UNO_QUERY_THROW); + OUString aDate = aSheetAnnotation->getDate(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong date", OUString("01/17/2013"), aDate); +} +void XSheetAnnotation::testGetIsVisible() +{ + uno::Reference< sheet::XSheetAnnotation > aSheetAnnotation (init(), UNO_QUERY_THROW); + bool isVisible = aSheetAnnotation->getIsVisible(); + + CPPUNIT_ASSERT_MESSAGE("Wrong visible state", isVisible); +} +void XSheetAnnotation::testSetIsVisible() +{ + uno::Reference< sheet::XSheetAnnotation > aSheetAnnotation (init(), UNO_QUERY_THROW); + aSheetAnnotation->setIsVisible(false); + bool isVisible = aSheetAnnotation->getIsVisible(); + + CPPUNIT_ASSERT_MESSAGE("Visible state not changed", !isVisible); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xsheetannotationanchor.cxx b/test/source/sheet/xsheetannotationanchor.cxx new file mode 100644 index 000000000..9fbf4b00d --- /dev/null +++ b/test/source/sheet/xsheetannotationanchor.cxx @@ -0,0 +1,44 @@ +/* -*- 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 <test/sheet/xsheetannotationanchor.hxx> +#include <test/cppunitasserthelper.hxx> + +#include <com/sun/star/sheet/XSheetAnnotation.hpp> +#include <com/sun/star/sheet/XSheetAnnotationAnchor.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XSheetAnnotationAnchor::testGetAnnotation() +{ + uno::Reference<sheet::XSheetAnnotationAnchor> xAnchor(init(), UNO_QUERY_THROW); + uno::Reference<sheet::XSheetAnnotation> xAnnotation(xAnchor->getAnnotation(), UNO_SET_THROW); + CPPUNIT_ASSERT_MESSAGE("Unable to get XSheetAnnotation", xAnnotation.is()); + + CPPUNIT_ASSERT_MESSAGE("Unable to check: getAuthor()", xAnnotation->getAuthor().isEmpty()); + CPPUNIT_ASSERT_MESSAGE("Unable to check: getDate()", !xAnnotation->getDate().isEmpty()); + CPPUNIT_ASSERT_MESSAGE("Unable to check: getIsVisible()", !xAnnotation->getIsVisible()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to check: getPosition()", table::CellAddress(0, 2, 3), + xAnnotation->getPosition()); + + xAnnotation->setIsVisible(false); + CPPUNIT_ASSERT_MESSAGE("Unable to setIsVisible() to false", !xAnnotation->getIsVisible()); + xAnnotation->setIsVisible(true); + CPPUNIT_ASSERT_MESSAGE("Unable to setIsVisible() to true", xAnnotation->getIsVisible()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xsheetannotations.cxx b/test/source/sheet/xsheetannotations.cxx new file mode 100644 index 000000000..9f082eeb9 --- /dev/null +++ b/test/source/sheet/xsheetannotations.cxx @@ -0,0 +1,212 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xsheetannotations.hxx> + +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/sheet/XSheetAnnotation.hpp> +#include <com/sun/star/text/XTextRange.hpp> + +#include <cppunit/TestAssert.h> +#include <rtl/ustring.hxx> + +using namespace css; +using namespace css::uno; + +namespace apitest { + +void XSheetAnnotations::testCount() +{ + uno::Reference< sheet::XSheetAnnotations > aSheetAnnotations (init(), UNO_QUERY_THROW); + + // count on sheet 1 before inserting + uno::Reference< container::XIndexAccess > xAnnotationsIndex (aSheetAnnotations, UNO_QUERY_THROW); + sal_Int32 nBefore = xAnnotationsIndex->getCount(); + + // get Sheet 2 annotations + uno::Reference< sheet::XSheetAnnotations > xSheet2Annotations( getAnnotations(1), UNO_SET_THROW); + + // insert a note on sheet 2 + table::CellAddress aTargetCellAddress (1,0,0); + xSheet2Annotations->insertNew(aTargetCellAddress, "an inserted annotation on sheet 2"); + + // count again on sheet 1 + sal_Int32 nAfter = xAnnotationsIndex->getCount(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( "Annotations count should not change on sheet 1", nBefore, nAfter); +} + +void XSheetAnnotations::testInsertNew() +{ + uno::Reference< sheet::XSheetAnnotations > aSheetAnnotations (init(), UNO_QUERY_THROW); + + // count before inserting + uno::Reference< container::XIndexAccess > xAnnotationsIndex (aSheetAnnotations, UNO_QUERY_THROW); + sal_Int32 nBefore = xAnnotationsIndex->getCount(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "There should already be one note", sal_Int32(1), nBefore ); + + // insert the annotation + table::CellAddress aTargetCellAddress (0,3,4); + aSheetAnnotations->insertNew(aTargetCellAddress, "an inserted annotation"); + + // count after inserting + //uno::Reference< container::XIndexAccess > xAnnotationsIndexAfter (aSheetAnnotations, UNO_QUERY_THROW); + sal_Int32 nAfter = xAnnotationsIndex->getCount(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Annotations index not updated", nBefore + 1, nAfter); + + // is the position ok ? + uno::Reference< sheet::XSheetAnnotation > aLastSheetAnnotation (xAnnotationsIndex->getByIndex(nAfter-1), UNO_QUERY_THROW); + table::CellAddress aResultCellAddress = aLastSheetAnnotation->getPosition(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Insert Annotation - Wrong SHEET reference position", + aTargetCellAddress.Sheet, aResultCellAddress.Sheet); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Insert Annotation - Wrong COLUMN reference position", + aTargetCellAddress.Column, aResultCellAddress.Column); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Insert Annotation - Wrong ROW reference position", + aTargetCellAddress.Row, aResultCellAddress.Row); + + // is the string ok ? + uno::Reference< text::XTextRange > aTextSheetAnnotation(aLastSheetAnnotation, UNO_QUERY_THROW); + OUString aString = aTextSheetAnnotation->getString(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Insert Annotation - Wrong string", OUString("an inserted annotation"), + aString); + +} + +void XSheetAnnotations::testRemoveByIndex() +{ + uno::Reference< sheet::XSheetAnnotations > aSheetAnnotations (init(), UNO_QUERY_THROW); + + // insert some annotations + table::CellAddress aTargetCellAddress (0,4,5); + aSheetAnnotations->insertNew(aTargetCellAddress, "an inserted annotation 1"); + table::CellAddress aToBeRemovedCellAddress (0,5,6); + aSheetAnnotations->insertNew(aToBeRemovedCellAddress, "an inserted annotation 2"); + table::CellAddress aOtherCellAddress (0,7,8); + aSheetAnnotations->insertNew(aOtherCellAddress, "an inserted annotation 3"); + + // count before removing + uno::Reference< container::XIndexAccess > xAnnotationsIndex (aSheetAnnotations, UNO_QUERY_THROW); + sal_Int32 nBefore = xAnnotationsIndex->getCount(); + + // remove the xToBeRemovedCellAddress + aSheetAnnotations->removeByIndex(nBefore-2); + + // count after removing + //uno::Reference< container::XIndexAccess > xAnnotationsIndex (aSheetAnnotations, UNO_QUERY_THROW); + sal_Int32 nAfter = xAnnotationsIndex->getCount(); + + // the last position should be xOtherCellAddress + uno::Reference< sheet::XSheetAnnotation > aLastSheetAnnotation (xAnnotationsIndex->getByIndex(nAfter-1), UNO_QUERY_THROW); + table::CellAddress aResultCellAddress = aLastSheetAnnotation->getPosition(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Remove Annotation - Wrong SHEET reference position", + aOtherCellAddress.Sheet, aResultCellAddress.Sheet); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Remove Annotation - Wrong COLUMN reference position", + aOtherCellAddress.Column, aResultCellAddress.Column); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Remove Annotation - Wrong ROW reference position", + aOtherCellAddress.Row, aResultCellAddress.Row); + + // is the string ok ? + uno::Reference< text::XTextRange > aLastTextSheetAnnotation(aLastSheetAnnotation, UNO_QUERY_THROW); + OUString aLastString = aLastTextSheetAnnotation->getString(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Remove Annotation - Wrong string", + OUString("an inserted annotation 3"), aLastString); + + // the previous should be xTargetCellAddress + uno::Reference< sheet::XSheetAnnotation > aPreviousSheetAnnotation (xAnnotationsIndex->getByIndex(nAfter-2), UNO_QUERY_THROW); + table::CellAddress aPreviousCellAddress = aPreviousSheetAnnotation->getPosition(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Remove Annotation - Wrong SHEET reference position", + aTargetCellAddress.Sheet, aPreviousCellAddress.Sheet); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Remove Annotation - Wrong COLUMN reference position", + aTargetCellAddress.Column, aPreviousCellAddress.Column); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Remove Annotation - Wrong ROW reference position", + aTargetCellAddress.Row, aPreviousCellAddress.Row); + + // is the string ok ? + uno::Reference< text::XTextRange > aPreviousTextSheetAnnotation(aPreviousSheetAnnotation, UNO_QUERY_THROW); + OUString aPreviousString = aPreviousTextSheetAnnotation->getString(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Remove Annotation - Wrong string", + OUString("an inserted annotation 1"), aPreviousString); +} + +void XSheetAnnotations::testIndex() +{ + + // testing #fdo80551 - getByIndex not on the first sheet + + // insert annotations in first sheet + uno::Reference< sheet::XSheetAnnotations > aSheet0Annotations (init(), UNO_QUERY_THROW); + table::CellAddress aTargetCellAddress0 (0,0,1); + aSheet0Annotations->insertNew(aTargetCellAddress0, "an inserted annotation 1 on sheet 1"); + table::CellAddress aSecondTargetCellAddress0 (0,0,2); + aSheet0Annotations->insertNew(aSecondTargetCellAddress0, "an inserted annotation 2 on sheet 1"); + table::CellAddress aThirdCellAddress0 (0,0,3); + aSheet0Annotations->insertNew(aThirdCellAddress0, "an inserted annotation 3 on sheet 1"); + + // insert annotations in third sheet + uno::Reference< sheet::XSheetAnnotations > aSheet2Annotations (getAnnotations(2), UNO_SET_THROW); + table::CellAddress aTargetCellAddress2 (2,4,5); + aSheet2Annotations->insertNew(aTargetCellAddress2, "an inserted annotation 1 on sheet 3"); + table::CellAddress aSecondTargetCellAddress2 (2,5,6); + aSheet2Annotations->insertNew(aSecondTargetCellAddress2, "an inserted annotation 2 on sheet 3"); + table::CellAddress aThirdCellAddress2 (2,7,8); + aSheet2Annotations->insertNew(aThirdCellAddress2, "an inserted annotation 3 on sheet 3"); + + // get second annotation for second sheet + uno::Reference< sheet::XSheetAnnotations > aSheetAnnotations (getAnnotations(2), UNO_SET_THROW); + uno::Reference< container::XIndexAccess > xAnnotationsIndex (aSheetAnnotations, UNO_QUERY_THROW); + uno::Reference< sheet::XSheetAnnotation > aAnnotation (xAnnotationsIndex->getByIndex(1), UNO_QUERY_THROW); + + table::CellAddress aToBeAnalyzedCellAddress = aAnnotation->getPosition(); + + // is the CellAddress ok ? + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "GetByIndex Annotation - Wrong SHEET reference position", + aSecondTargetCellAddress2.Sheet, aToBeAnalyzedCellAddress.Sheet); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "GetByIndex Annotation - Wrong COLUMN reference position", + aSecondTargetCellAddress2.Column, aToBeAnalyzedCellAddress.Column); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "GetByIndex Annotation - Wrong ROW reference position", + aSecondTargetCellAddress2.Row, aToBeAnalyzedCellAddress.Row); + + // is the string ok ? + uno::Reference< text::XTextRange > aTextSheetAnnotation(aAnnotation, UNO_QUERY_THROW); + OUString aString = aTextSheetAnnotation->getString(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "GetByIndex Annotation - Wrong string", + OUString("an inserted annotation 2 on sheet 3"), aString); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xsheetannotationshapesupplier.cxx b/test/source/sheet/xsheetannotationshapesupplier.cxx new file mode 100644 index 000000000..dac446b72 --- /dev/null +++ b/test/source/sheet/xsheetannotationshapesupplier.cxx @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xsheetannotationshapesupplier.hxx> + +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/sheet/XSheetAnnotationShapeSupplier.hpp> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + + +namespace apitest { + +void XSheetAnnotationShapeSupplier::testGetAnnotationShape() +{ + uno::Reference< sheet::XSheetAnnotationShapeSupplier > xSheetAnnotationShapeSupplier(init(), UNO_QUERY_THROW); + uno::Reference< drawing::XShape > xShape = xSheetAnnotationShapeSupplier->getAnnotationShape(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("getAnnotationShape() wrong X position", + sal_Int32(7373), xShape->getPosition().X); + CPPUNIT_ASSERT_EQUAL_MESSAGE("getAnnotationShape() wrong Y position", + sal_Int32(451), xShape->getPosition().Y); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("getAnnotationShape() wrong width", + sal_Int32(11275), xShape->getSize().Width); + CPPUNIT_ASSERT_EQUAL_MESSAGE("getAnnotationShape() wrong height", + sal_Int32(1386), xShape->getSize().Height); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xsheetannotationssupplier.cxx b/test/source/sheet/xsheetannotationssupplier.cxx new file mode 100644 index 000000000..aa6f7fd1c --- /dev/null +++ b/test/source/sheet/xsheetannotationssupplier.cxx @@ -0,0 +1,30 @@ +/* -*- 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 <test/sheet/xsheetannotationssupplier.hxx> + +#include <com/sun/star/sheet/XSheetAnnotations.hpp> +#include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XSheetAnnotationsSupplier::testGetAnnotations() +{ + uno::Reference<sheet::XSheetAnnotationsSupplier> xSupplier(init(), UNO_QUERY_THROW); + + uno::Reference<sheet::XSheetAnnotations> xAnnotations(xSupplier->getAnnotations(), + UNO_SET_THROW); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xsheetauditing.cxx b/test/source/sheet/xsheetauditing.cxx new file mode 100644 index 000000000..992a7441c --- /dev/null +++ b/test/source/sheet/xsheetauditing.cxx @@ -0,0 +1,137 @@ +/* -*- 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 <test/sheet/xsheetauditing.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/drawing/XDrawPage.hpp> +#include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <com/sun/star/sheet/XSheetAuditing.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/ValidationType.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XSheetAuditing::testShowHideDependents() +{ + uno::Reference<sheet::XSheetAuditing> xAuditing(init(), UNO_QUERY_THROW); + + uno::Reference<drawing::XDrawPageSupplier> xDPS(xAuditing, UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPage> xDrawPage = xDPS->getDrawPage(); + const sal_Int32 nElements = xDrawPage->getCount(); + + xAuditing->showDependents(table::CellAddress(0, 8, 6)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to showDependents()", nElements + 1, + xDrawPage->getCount()); + + xAuditing->hideDependents(table::CellAddress(0, 8, 6)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to hideDependents()", nElements, xDrawPage->getCount()); +} + +void XSheetAuditing::testShowHidePrecedents() +{ + uno::Reference<sheet::XSheetAuditing> xAuditing(init(), UNO_QUERY_THROW); + + uno::Reference<drawing::XDrawPageSupplier> xDPS(xAuditing, UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPage> xDrawPage = xDPS->getDrawPage(); + const sal_Int32 nElements = xDrawPage->getCount(); + + xAuditing->showPrecedents(table::CellAddress(0, 8, 6)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to showPrecedents()", nElements + 2, + xDrawPage->getCount()); + + xAuditing->hidePrecedents(table::CellAddress(0, 8, 6)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to showPrecedents()", nElements, xDrawPage->getCount()); +} + +void XSheetAuditing::testClearArrows() +{ + uno::Reference<sheet::XSheetAuditing> xAuditing(init(), UNO_QUERY_THROW); + + uno::Reference<drawing::XDrawPageSupplier> xDPS(xAuditing, UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPage> xDrawPage = xDPS->getDrawPage(); + const sal_Int32 nElements = xDrawPage->getCount(); + + xAuditing->showPrecedents(table::CellAddress(0, 8, 6)); + xAuditing->showDependents(table::CellAddress(0, 8, 6)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set arrows", nElements + 3, xDrawPage->getCount()); + + xAuditing->clearArrows(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to clear arrows", nElements, xDrawPage->getCount()); +} + +void XSheetAuditing::testShowErrors() +{ + uno::Reference<sheet::XSheetAuditing> xAuditing(init(), UNO_QUERY_THROW); + + uno::Reference<drawing::XDrawPageSupplier> xDPS(xAuditing, UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPage> xDrawPage = xDPS->getDrawPage(); + const sal_Int32 nElements = xDrawPage->getCount(); + + uno::Reference<sheet::XSpreadsheet> xSheet(xAuditing, UNO_QUERY_THROW); + uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(7, 6); + xCell->setValue(-9); + xCell->setFormula("=SQRT(" + OUStringChar(static_cast<char>('A' + 7)) + OUString::number(7) + + ")"); + + uno::Reference<text::XText> xText(xCell, UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL_MESSAGE("No error code", OUString("Err:522"), xText->getString()); + + xAuditing->showErrors(table::CellAddress(0, 7, 6)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to show errors", nElements + 1, xDrawPage->getCount()); +} + +void XSheetAuditing::testShowInvalid() +{ + uno::Reference<sheet::XSheetAuditing> xAuditing(init(), UNO_QUERY_THROW); + + uno::Reference<drawing::XDrawPageSupplier> xDPS(xAuditing, UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPage> xDrawPage = xDPS->getDrawPage(); + const sal_Int32 nElements = xDrawPage->getCount(); + + uno::Reference<sheet::XSpreadsheet> xSheet(xAuditing, UNO_QUERY_THROW); + uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(7, 6); + xCell->setValue(2.5); + + uno::Reference<beans::XPropertySet> xPropSet(xCell, UNO_QUERY_THROW); + uno::Any aValidation = xPropSet->getPropertyValue("Validation"); + uno::Reference<beans::XPropertySet> xValidation(aValidation, UNO_QUERY_THROW); + uno::Any aAny; + + aAny <<= sheet::ValidationType_WHOLE; + xValidation->setPropertyValue("Type", aAny); + aAny <<= xValidation; + xPropSet->setPropertyValue("Validation", aAny); + xAuditing->showInvalid(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to show invalid (WHOLE)", nElements + 1, + xDrawPage->getCount()); + + xAuditing->clearArrows(); + + aAny <<= sheet::ValidationType_ANY; + xValidation->setPropertyValue("Type", aAny); + aAny <<= xValidation; + xPropSet->setPropertyValue("Validation", aAny); + + xAuditing->showInvalid(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to show invalid (ANY)", nElements, xDrawPage->getCount()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xsheetcellcursor.cxx b/test/source/sheet/xsheetcellcursor.cxx new file mode 100644 index 000000000..fcaeb7fe7 --- /dev/null +++ b/test/source/sheet/xsheetcellcursor.cxx @@ -0,0 +1,138 @@ +/* -*- 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 <test/sheet/xsheetcellcursor.hxx> + +#include <com/sun/star/sheet/XArrayFormulaRange.hpp> +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XSheetCellCursor.hpp> +#include <com/sun/star/sheet/XSheetOperation.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/table/XColumnRowRange.hpp> +#include <com/sun/star/util/XMergeable.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XSheetCellCursor::testCollapseToCurrentArray() +{ + uno::Reference<sheet::XSheetCellCursor> xSheetCellCursor(init(), UNO_QUERY_THROW); + + uno::Reference<sheet::XCellRangeAddressable> xCellRangeAddressable(xSheetCellCursor, + UNO_QUERY_THROW); + table::CellRangeAddress aCellRangeAddr = xCellRangeAddressable->getRangeAddress(); + const sal_Int32 nHeight = aCellRangeAddr.EndRow - aCellRangeAddr.StartRow + 1; + + uno::Reference<table::XCellRange> xCellRange + = xSheetCellCursor->getCellRangeByPosition(0, 0, 0, nHeight - 1); + uno::Reference<sheet::XArrayFormulaRange> xArrayFormulaRange(xCellRange, UNO_QUERY_THROW); + xArrayFormulaRange->setArrayFormula("A1:A" + OUString::number(nHeight)); + + xSheetCellCursor->collapseToSize(1, 1); + xSheetCellCursor->collapseToCurrentArray(); + + uno::Reference<table::XColumnRowRange> xColRowRange(xSheetCellCursor, UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to collapseToCurrentArray (cols)", sal_Int32(1), + xColRowRange->getColumns()->getCount()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to collapseToCurrentArray (rows)", nHeight, + xColRowRange->getRows()->getCount()); + xArrayFormulaRange->setArrayFormula(""); +} + +void XSheetCellCursor::testCollapseToCurrentRegion() +{ + uno::Reference<sheet::XSheetCellCursor> xSheetCellCursor(init(), UNO_QUERY_THROW); + + const sal_Int32 nWidth = 4, nHeight = 4; + uno::Reference<sheet::XSpreadsheet> xSheet = xSheetCellCursor->getSpreadsheet(); + uno::Reference<sheet::XSheetOperation> xSheetOp(xSheet, UNO_QUERY_THROW); + xSheetOp->clearContents(65535); + + xSheetCellCursor->collapseToCurrentRegion(); + uno::Reference<table::XColumnRowRange> xColRowRange(xSheetCellCursor, UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to collapseToCurrentRegion (cols)", nWidth, + xColRowRange->getColumns()->getCount()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to collapseToCurrentRegion (rows)", nHeight, + xColRowRange->getRows()->getCount()); +} + +void XSheetCellCursor::testCollapseToMergedArea() +{ + uno::Reference<sheet::XSheetCellCursor> xSheetCellCursor(init(), UNO_QUERY_THROW); + xSheetCellCursor->collapseToSize(1, 1); + + const sal_Int32 nLeftCol = 0, nTopRow = 0, nWidth = 8, nHeight = 8; + uno::Reference<sheet::XSpreadsheet> xSheet = xSheetCellCursor->getSpreadsheet(); + + uno::Reference<table::XCellRange> xCellRange = xSheet->getCellRangeByPosition( + nLeftCol + nWidth - 8, nTopRow + nHeight - 8, nLeftCol + nWidth, nTopRow + nHeight); + + uno::Reference<util::XMergeable> xMergeable(xCellRange, UNO_QUERY_THROW); + xMergeable->merge(true); + CPPUNIT_ASSERT_MESSAGE("Unable to merge area", xMergeable->getIsMerged()); + xSheetCellCursor->collapseToMergedArea(); + xMergeable->merge(false); + + uno::Reference<table::XColumnRowRange> xColRowRange(xSheetCellCursor, UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to collapseToMergedArea (cols)", nWidth + 1, + xColRowRange->getColumns()->getCount()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to collapseToMergedArea (rows)", nHeight + 1, + xColRowRange->getRows()->getCount()); +} + +void XSheetCellCursor::testCollapseToSize() +{ + uno::Reference<sheet::XSheetCellCursor> xSheetCellCursor(init(), UNO_QUERY_THROW); + + const sal_Int32 nWidth = 1, nHeight = 1; + xSheetCellCursor->collapseToSize(nWidth + 3, nHeight + 3); + + uno::Reference<table::XColumnRowRange> xColRowRange(xSheetCellCursor, UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to collapseToSize (cols)", nWidth + 3, + xColRowRange->getColumns()->getCount()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to collapseToSize (rows)", nHeight + 3, + xColRowRange->getRows()->getCount()); +} + +void XSheetCellCursor::testExpandToEntireColumns() +{ + uno::Reference<sheet::XSheetCellCursor> xSheetCellCursor(init(), UNO_QUERY_THROW); + + xSheetCellCursor->expandToEntireColumns(); + + uno::Reference<table::XColumnRowRange> xColRowRange(xSheetCellCursor, UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to expandToEntireColumns (cols)", sal_Int32(4), + xColRowRange->getColumns()->getCount()); + CPPUNIT_ASSERT_MESSAGE("Unable to expandToEntireColumns (rows)", + xColRowRange->getRows()->getCount() >= sal_Int32(32000)); +} + +void XSheetCellCursor::testExpandToEntireRows() +{ + uno::Reference<sheet::XSheetCellCursor> xSheetCellCursor(init(), UNO_QUERY_THROW); + + xSheetCellCursor->expandToEntireRows(); + + uno::Reference<table::XColumnRowRange> xColRowRange(xSheetCellCursor, UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("Unable to expandToEntireRows (cols)", + xColRowRange->getColumns()->getCount() >= sal_Int32(256)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to expandToEntireRows (rows)", sal_Int32(4), + xColRowRange->getRows()->getCount()); +} +} + +/* vim:set shiftnWidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xsheetcellrange.cxx b/test/source/sheet/xsheetcellrange.cxx new file mode 100644 index 000000000..a5714e324 --- /dev/null +++ b/test/source/sheet/xsheetcellrange.cxx @@ -0,0 +1,33 @@ +/* -*- 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 <test/sheet/xsheetcellrange.hxx> + +#include <com/sun/star/sheet/XSheetCellRange.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XSheetCellRange::testGetSpreadsheet() +{ + uno::Reference<sheet::XSheetCellRange> xSheetCellRange(init(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet = xSheetCellRange->getSpreadsheet(); + + CPPUNIT_ASSERT_MESSAGE("Unable to get spreadsheet", xSheet.is()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xsheetcellrangecontainer.cxx b/test/source/sheet/xsheetcellrangecontainer.cxx new file mode 100644 index 000000000..af5d02d70 --- /dev/null +++ b/test/source/sheet/xsheetcellrangecontainer.cxx @@ -0,0 +1,101 @@ +/* -*- 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 <test/sheet/xsheetcellrangecontainer.hxx> +#include <test/cppunitasserthelper.hxx> + +#include <com/sun/star/sheet/XSheetCellRangeContainer.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XSheetCellRangeContainer::testAddRemoveRangeAddress() +{ + uno::Reference<sheet::XSheetCellRangeContainer> xSCRC(init(), UNO_QUERY_THROW); + xSCRC->removeRangeAddresses(xSCRC->getRangeAddresses()); // prepare a clean slate + uno::Sequence<table::CellRangeAddress> aAddr = createCellRangeAddresses(); + + sal_Int32 cnt = xSCRC->getCount(); + xSCRC->addRangeAddress(aAddr[0], false); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to add CellRangeAddress (count)", cnt + 1, + xSCRC->getCount()); + + uno::Sequence<table::CellRangeAddress> aAfterAddAddr = xSCRC->getRangeAddresses(); + cnt = xSCRC->getCount(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to add CellRangeAddress (entry)", aAddr[0], + aAfterAddAddr[cnt - 1]); + + xSCRC->removeRangeAddress(aAddr[0]); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to remove CellRangeAddress (count)", cnt - 1, + xSCRC->getCount()); + + const uno::Sequence<table::CellRangeAddress> aAfterRemoveAddr = xSCRC->getRangeAddresses(); + for (auto const& addr : aAfterRemoveAddr) + { + CPPUNIT_ASSERT_MESSAGE("Unable to remove CellRangeAddress (entry)", aAddr[0] != addr); + } +} + +void XSheetCellRangeContainer::testAddRemoveRangeAddresses() +{ + uno::Reference<sheet::XSheetCellRangeContainer> xSCRC(init(), UNO_QUERY_THROW); + xSCRC->removeRangeAddresses(xSCRC->getRangeAddresses()); // prepare a clean slate + uno::Sequence<table::CellRangeAddress> aAddr = createCellRangeAddresses(); + + sal_Int32 cnt = xSCRC->getCount(); + xSCRC->addRangeAddresses(aAddr, false); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to add CellRangeAddress (count)", cnt + 2, + xSCRC->getCount()); + + uno::Sequence<table::CellRangeAddress> aAfterAddAddr = xSCRC->getRangeAddresses(); + cnt = xSCRC->getCount(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to add CellRangeAddresses (entry: first)", aAddr[0], + aAfterAddAddr[cnt - 2]); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to add CellRangeAddresses (entry: second)", aAddr[1], + aAfterAddAddr[cnt - 1]); + + xSCRC->removeRangeAddresses(aAddr); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to remove CellRangeAddresses (count)", cnt - 2, + xSCRC->getCount()); + + const uno::Sequence<table::CellRangeAddress> aAfterRemoveAddr = xSCRC->getRangeAddresses(); + for (auto const& addr : aAfterRemoveAddr) + { + CPPUNIT_ASSERT_MESSAGE("Unable to remove CellRangeAddresses (entry: first)", + aAddr[0] != addr); + CPPUNIT_ASSERT_MESSAGE("Unable to remove CellRangeAddresses (entry: second)", + aAddr[1] != addr); + } +} + +uno::Sequence<table::CellRangeAddress> XSheetCellRangeContainer::createCellRangeAddresses() +{ + uno::Sequence<table::CellRangeAddress> aAddr(2); + auto pAddr = aAddr.getArray(); + for (unsigned int i = 0; i < 2; i++) + { + pAddr[i].Sheet = i; + pAddr[i].StartColumn = i; + pAddr[i].StartRow = i; + pAddr[i].EndColumn = i + 3; + pAddr[i].EndRow = i + 3; + } + + return aAddr; +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xsheetcellranges.cxx b/test/source/sheet/xsheetcellranges.cxx new file mode 100644 index 000000000..d40a47e03 --- /dev/null +++ b/test/source/sheet/xsheetcellranges.cxx @@ -0,0 +1,50 @@ +/* -*- 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 <test/sheet/xsheetcellranges.hxx> + +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/sheet/XSheetCellRanges.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XSheetCellRanges::testGetCells() +{ + uno::Reference<sheet::XSheetCellRanges> xSheetCellRanges(init(), UNO_QUERY_THROW); + uno::Reference<container::XEnumerationAccess> xEA = xSheetCellRanges->getCells(); + + CPPUNIT_ASSERT_MESSAGE("Unable to get cells", xEA->hasElements()); +} + +void XSheetCellRanges::testGetRangeAddresses() +{ + uno::Reference<sheet::XSheetCellRanges> xSheetCellRanges(init(), UNO_QUERY_THROW); + uno::Sequence<table::CellRangeAddress> aCellRangeAddress + = xSheetCellRanges->getRangeAddresses(); + CPPUNIT_ASSERT_MESSAGE("Unable to get RangeAddresses", aCellRangeAddress.getLength() > 2); +} + +void XSheetCellRanges::testGetRangeAddressesAsString() +{ + uno::Reference<sheet::XSheetCellRanges> xSheetCellRanges(init(), UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("Unable to get RangeAddresses (string)", + xSheetCellRanges->getRangeAddressesAsString().indexOf("C1:D4") > 0); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xsheetcondition.cxx b/test/source/sheet/xsheetcondition.cxx new file mode 100644 index 000000000..27068fec6 --- /dev/null +++ b/test/source/sheet/xsheetcondition.cxx @@ -0,0 +1,72 @@ +/* -*- 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 <test/sheet/xsheetcondition.hxx> + +#include <com/sun/star/sheet/ConditionOperator.hpp> +#include <com/sun/star/sheet/XSheetCondition.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XSheetCondition::testGetSetFormula1() +{ + uno::Reference<sheet::XSheetCondition> xSheetCondition(init(), UNO_QUERY_THROW); + OUString aFormula1; + CPPUNIT_ASSERT_NO_THROW_MESSAGE("Unable to get Formula1", + aFormula1 = xSheetCondition->getFormula1()); + + xSheetCondition->setFormula1("$Sheet1.$C$"); + CPPUNIT_ASSERT_MESSAGE("Unable to set Formula1", aFormula1 != xSheetCondition->getFormula1()); +} + +void XSheetCondition::testGetSetFormula2() +{ + uno::Reference<sheet::XSheetCondition> xSheetCondition(init(), UNO_QUERY_THROW); + OUString aFormula2; + CPPUNIT_ASSERT_NO_THROW_MESSAGE("Unable to get Formula2", + aFormula2 = xSheetCondition->getFormula2()); + + xSheetCondition->setFormula2("$Sheet1.$A$"); + CPPUNIT_ASSERT_MESSAGE("Unable to set Formula2", aFormula2 != xSheetCondition->getFormula2()); +} + +void XSheetCondition::testGetSetOperator() +{ + uno::Reference<sheet::XSheetCondition> xSheetCondition(init(), UNO_QUERY_THROW); + sheet::ConditionOperator aOperator; + CPPUNIT_ASSERT_NO_THROW_MESSAGE("Unable to get Operator", + aOperator = xSheetCondition->getOperator()); + + xSheetCondition->setOperator(sheet::ConditionOperator_BETWEEN); + sheet::ConditionOperator aOperatorNew = xSheetCondition->getOperator(); + CPPUNIT_ASSERT_MESSAGE("Unable to set Operator", aOperator != aOperatorNew); +} + +void XSheetCondition::testGetSetSourcePosition() +{ + uno::Reference<sheet::XSheetCondition> xSheetCondition(init(), UNO_QUERY_THROW); + table::CellAddress aSourcePosition(0, 0, 0); + CPPUNIT_ASSERT_NO_THROW_MESSAGE("Unable to get SourcePosition", + aSourcePosition = xSheetCondition->getSourcePosition()); + + xSheetCondition->setSourcePosition(table::CellAddress(0, 1, 1)); + table::CellAddress aSourcePositionNew = xSheetCondition->getSourcePosition(); + CPPUNIT_ASSERT_MESSAGE("Unable to set SourcePosition", + aSourcePosition.Row != aSourcePositionNew.Row); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xsheetconditionalentries.cxx b/test/source/sheet/xsheetconditionalentries.cxx new file mode 100644 index 000000000..8062d42f5 --- /dev/null +++ b/test/source/sheet/xsheetconditionalentries.cxx @@ -0,0 +1,57 @@ +/* -*- 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 <test/sheet/xsheetconditionalentries.hxx> + +#include <com/sun/star/sheet/XSheetConditionalEntries.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XSheetConditionalEntries::testAddNew() +{ + uno::Reference<sheet::XSheetConditionalEntries> xSheetConditionalEntries(init(), + UNO_QUERY_THROW); + const sal_Int32 aCount = xSheetConditionalEntries->getCount(); + + xSheetConditionalEntries->addNew(createCondition(4)); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to add new condition", aCount + 1, + xSheetConditionalEntries->getCount()); +} + +void XSheetConditionalEntries::testClear() +{ + uno::Reference<sheet::XSheetConditionalEntries> xSheetConditionalEntries(init(), + UNO_QUERY_THROW); + xSheetConditionalEntries->clear(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to clear conditions", sal_Int32(0), + xSheetConditionalEntries->getCount()); +} + +void XSheetConditionalEntries::testRemoveByIndex() +{ + uno::Reference<sheet::XSheetConditionalEntries> xSheetConditionalEntries(init(), + UNO_QUERY_THROW); + const sal_Int32 aCount = xSheetConditionalEntries->getCount(); + + xSheetConditionalEntries->removeByIndex(0); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to remove condition", aCount - 1, + xSheetConditionalEntries->getCount()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xsheetconditionalentry.cxx b/test/source/sheet/xsheetconditionalentry.cxx new file mode 100644 index 000000000..0523d9be6 --- /dev/null +++ b/test/source/sheet/xsheetconditionalentry.cxx @@ -0,0 +1,35 @@ +/* -*- 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 <test/sheet/xsheetconditionalentry.hxx> + +#include <com/sun/star/sheet/XSheetConditionalEntry.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XSheetConditionalEntry::testGetSetStyleName() +{ + uno::Reference<sheet::XSheetConditionalEntry> xSheetConditionalEntry(init(), UNO_QUERY_THROW); + OUString aStyleName = xSheetConditionalEntry->getStyleName(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get StyleName", OUString("Result2"), aStyleName); + + xSheetConditionalEntry->setStyleName("Heading"); + CPPUNIT_ASSERT_MESSAGE("Unable to set StyleName", + aStyleName != xSheetConditionalEntry->getStyleName()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xsheetfilterable.cxx b/test/source/sheet/xsheetfilterable.cxx new file mode 100644 index 000000000..2f5509e95 --- /dev/null +++ b/test/source/sheet/xsheetfilterable.cxx @@ -0,0 +1,95 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xsheetfilterable.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sheet/FilterOperator.hpp> +#include <com/sun/star/sheet/TableFilterField.hpp> +#include <com/sun/star/sheet/XSheetFilterable.hpp> +#include <com/sun/star/sheet/XSheetFilterDescriptor.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/XColumnRowRange.hpp> +#include <com/sun/star/table/XTableRows.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest { + +void XSheetFilterable::testCreateFilterDescriptor() +{ + uno::Reference< sheet::XSheetFilterable > xFA(init(), UNO_QUERY_THROW); + uno::Reference< sheet::XSheetFilterDescriptor > xSFD = xFA->createFilterDescriptor(true); + + uno::Sequence< sheet::TableFilterField > xTFF{ + { /* Connection */ {}, + /* Field */ 0, + /* Operator */ sheet::FilterOperator_GREATER_EQUAL, + /* IsNumeric */ true, + /* NumericValue */ 2, + /* StringValue */ {}}, + { /* Connection */ {}, + /* Field */ 1, + /* Operator */ sheet::FilterOperator_LESS, + /* IsNumeric */ false, + /* NumericValue */ {}, + /* StringValue */ "C" } + }; + + CPPUNIT_ASSERT_NO_THROW_MESSAGE("Unable to create XSheetFilterDescriptor", xSFD->setFilterFields(xTFF)); +} + +void XSheetFilterable::testFilter() +{ + uno::Reference< sheet::XSpreadsheet > xSheet(getXSpreadsheet(), UNO_QUERY_THROW); + + uno::Reference< sheet::XSheetFilterable > xFA(xSheet, UNO_QUERY_THROW); + uno::Reference< sheet::XSheetFilterDescriptor > xSFD = xFA->createFilterDescriptor(true); + + uno::Sequence< sheet::TableFilterField > xTFF{ + { /* Connection */ {}, + /* Field */ 0, + /* Operator */ sheet::FilterOperator_GREATER_EQUAL, + /* IsNumeric */ true, + /* NumericValue */ 2, + /* StringValue */ {}}, + { /* Connection */ {}, + /* Field */ 1, + /* Operator */ sheet::FilterOperator_LESS, + /* IsNumeric */ false, + /* NumericValue */ {}, + /* StringValue */ "C" } + }; + xSFD->setFilterFields(xTFF); + + xSheet->getCellByPosition(0, 0)->setValue(1); + xSheet->getCellByPosition(0, 1)->setValue(2); + xSheet->getCellByPosition(0, 2)->setValue(3); + xSheet->getCellByPosition(1, 0)->setFormula("A"); + xSheet->getCellByPosition(1, 1)->setFormula("B"); + xSheet->getCellByPosition(1, 2)->setFormula("C"); + xFA->filter(xSFD); + + uno::Reference< table::XColumnRowRange > xColRowRange(xSheet, UNO_QUERY_THROW); + uno::Reference< table::XTableRows > xTableRows = xColRowRange->getRows(); + uno::Reference< beans::XPropertySet > xRowProps(xTableRows->getByIndex(0), UNO_QUERY_THROW); + bool bIsVisible = true; + CPPUNIT_ASSERT(xRowProps->getPropertyValue("IsVisible") >>= bIsVisible); + + CPPUNIT_ASSERT_MESSAGE("Row 1 should be invisible", !bIsVisible); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xsheetfilterableex.cxx b/test/source/sheet/xsheetfilterableex.cxx new file mode 100644 index 000000000..eeecf737d --- /dev/null +++ b/test/source/sheet/xsheetfilterableex.cxx @@ -0,0 +1,59 @@ +/* -*- 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 <test/sheet/xsheetfilterableex.hxx> + +#include <com/sun/star/sheet/FilterConnection.hpp> +#include <com/sun/star/sheet/FilterOperator.hpp> +#include <com/sun/star/sheet/TableFilterField.hpp> +#include <com/sun/star/sheet/XSheetFilterDescriptor.hpp> +#include <com/sun/star/sheet/XSheetFilterable.hpp> +#include <com/sun/star/sheet/XSheetFilterableEx.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XSheetFilterableEx::testCreateFilterDescriptorByObject() +{ + uno::Reference<sheet::XSheetFilterableEx> xSFEx(init(), UNO_QUERY_THROW); + uno::Reference<sheet::XSheetFilterable> xSF(getXSpreadsheet(), UNO_QUERY_THROW); + + uno::Reference<sheet::XSheetFilterDescriptor> xSFD = xSFEx->createFilterDescriptorByObject(xSF); + CPPUNIT_ASSERT_MESSAGE("no XSheetFilterDescriptor", xSFD.is()); + + const uno::Sequence<sheet::TableFilterField> xTFF = xSFD->getFilterFields(); + CPPUNIT_ASSERT_MESSAGE("The gained XSheetFilterDescriptor is empty", xTFF.hasElements()); + + for (const auto& field : xTFF) + { + // we don't care about the actual value, just that we can access the fields + CPPUNIT_ASSERT_MESSAGE("Unable to retrieve field: StringValue", + !field.StringValue.isEmpty() || field.StringValue.isEmpty()); + CPPUNIT_ASSERT_MESSAGE("Unable to retrieve field: IsNumeric", + !field.IsNumeric || field.IsNumeric); + CPPUNIT_ASSERT_MESSAGE("Unable to retrieve field: NumericValue", + field.NumericValue != 0.0 || field.NumericValue == 0.0); + CPPUNIT_ASSERT_MESSAGE("Unable to retrieve field: Field", + field.Field != 0 || field.Field == 0); + CPPUNIT_ASSERT_MESSAGE("Unable to retrieve field: Connection", + field.Connection == sheet::FilterConnection_AND + || field.Connection == sheet::FilterConnection_OR); + CPPUNIT_ASSERT_MESSAGE("Unable to retrieve field: Operator", + field.Operator != sheet::FilterOperator_EMPTY); + } +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xsheetfilterdescriptor.cxx b/test/source/sheet/xsheetfilterdescriptor.cxx new file mode 100644 index 000000000..503cc84f8 --- /dev/null +++ b/test/source/sheet/xsheetfilterdescriptor.cxx @@ -0,0 +1,42 @@ +/* -*- 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 <test/sheet/xsheetfilterdescriptor.hxx> + +#include <com/sun/star/sheet/TableFilterField.hpp> +#include <com/sun/star/sheet/XSheetFilterDescriptor.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XSheetFilterDescriptor::testGetSetFilterFields() +{ + uno::Reference<sheet::XSheetFilterDescriptor> xSFD(init(), uno::UNO_QUERY_THROW); + uno::Sequence<sheet::TableFilterField> aDefaultTFF = xSFD->getFilterFields(); + + CPPUNIT_ASSERT_MESSAGE("Unable to get TableFilterField", !aDefaultTFF.hasElements()); + + uno::Sequence<sheet::TableFilterField> aTFF; + aTFF.realloc(1); + + xSFD->setFilterFields(aTFF); + uno::Sequence<sheet::TableFilterField> aNewTFF = xSFD->getFilterFields(); + CPPUNIT_ASSERT_MESSAGE("Unable to set TableFilterField", aNewTFF != aDefaultTFF); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xsheetfilterdescriptor2.cxx b/test/source/sheet/xsheetfilterdescriptor2.cxx new file mode 100644 index 000000000..fc060f73c --- /dev/null +++ b/test/source/sheet/xsheetfilterdescriptor2.cxx @@ -0,0 +1,42 @@ +/* -*- 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 <test/sheet/xsheetfilterdescriptor2.hxx> + +#include <com/sun/star/sheet/TableFilterField2.hpp> +#include <com/sun/star/sheet/XSheetFilterDescriptor2.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XSheetFilterDescriptor2::testGetSetFilterFields2() +{ + uno::Reference<sheet::XSheetFilterDescriptor2> xSFD(init(), uno::UNO_QUERY_THROW); + uno::Sequence<sheet::TableFilterField2> aDefaultTFF = xSFD->getFilterFields2(); + + CPPUNIT_ASSERT_MESSAGE("Unable to get TableFilterField", !aDefaultTFF.hasElements()); + + uno::Sequence<sheet::TableFilterField2> aTFF; + aTFF.realloc(1); + + xSFD->setFilterFields2(aTFF); + uno::Sequence<sheet::TableFilterField2> aNewTFF = xSFD->getFilterFields2(); + CPPUNIT_ASSERT_MESSAGE("Unable to set TableFilterField", aNewTFF != aDefaultTFF); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xsheetfilterdescriptor3.cxx b/test/source/sheet/xsheetfilterdescriptor3.cxx new file mode 100644 index 000000000..e46a34552 --- /dev/null +++ b/test/source/sheet/xsheetfilterdescriptor3.cxx @@ -0,0 +1,42 @@ +/* -*- 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 <test/sheet/xsheetfilterdescriptor3.hxx> + +#include <com/sun/star/sheet/TableFilterField3.hpp> +#include <com/sun/star/sheet/XSheetFilterDescriptor3.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XSheetFilterDescriptor3::testGetSetFilterFields3() +{ + uno::Reference<sheet::XSheetFilterDescriptor3> xSFD(init(), uno::UNO_QUERY_THROW); + uno::Sequence<sheet::TableFilterField3> aDefaultTFF = xSFD->getFilterFields3(); + + CPPUNIT_ASSERT_MESSAGE("Unable to get TableFilterField", !aDefaultTFF.hasElements()); + + uno::Sequence<sheet::TableFilterField3> aTFF; + aTFF.realloc(1); + + xSFD->setFilterFields3(aTFF); + uno::Sequence<sheet::TableFilterField3> aNewTFF = xSFD->getFilterFields3(); + CPPUNIT_ASSERT_MESSAGE("Unable to set TableFilterField", aNewTFF != aDefaultTFF); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xsheetlinkable.cxx b/test/source/sheet/xsheetlinkable.cxx new file mode 100644 index 000000000..aa394a006 --- /dev/null +++ b/test/source/sheet/xsheetlinkable.cxx @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xsheetlinkable.hxx> + +#include <com/sun/star/sheet/SheetLinkMode.hpp> +#include <com/sun/star/sheet/XSheetLinkable.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest { + +void XSheetLinkable::testSheetLinkable() +{ + uno::Reference< sheet::XSheetLinkable > xSheetLinkable(init(), UNO_QUERY_THROW); + + xSheetLinkable->link(getFileURL(), "Sheet1", "", "", sheet::SheetLinkMode_VALUE); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get link mode", + sheet::SheetLinkMode_VALUE, xSheetLinkable->getLinkMode()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get link URL", + getFileURL(), xSheetLinkable->getLinkUrl()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get sheet name", + OUString("Sheet1"), xSheetLinkable->getLinkSheetName()); + + xSheetLinkable->setLinkMode(sheet::SheetLinkMode_NONE); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set link mode", + sheet::SheetLinkMode_NONE, xSheetLinkable->getLinkMode()); + + xSheetLinkable->setLinkSheetName("Sheet2"); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set sheet name", + OUString("Sheet2"), xSheetLinkable->getLinkSheetName()); + + xSheetLinkable->setLinkUrl(getFileURL()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set link URL", + getFileURL(), xSheetLinkable->getLinkUrl()); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xsheetoperation.cxx b/test/source/sheet/xsheetoperation.cxx new file mode 100644 index 000000000..6f8496482 --- /dev/null +++ b/test/source/sheet/xsheetoperation.cxx @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xsheetoperation.hxx> + +#include <com/sun/star/sheet/CellFlags.hpp> +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/XSheetOperation.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XSheetOperation::testClearContents() +{ + uno::Reference<sheet::XSheetOperation> xSheetOperation(init(), UNO_QUERY_THROW); + + xSheetOperation->clearContents(sheet::CellFlags::VALUE | sheet::CellFlags::FORMULA); + + double sum = xSheetOperation->computeFunction(sheet::GeneralFunction_SUM); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to clean contents", 0.0, sum); +} + +void XSheetOperation::testComputeFunction() +{ + uno::Reference<sheet::XSheetOperation> xSheetOperation(init(), UNO_QUERY_THROW); + + double count = xSheetOperation->computeFunction(sheet::GeneralFunction_COUNT); + CPPUNIT_ASSERT_MESSAGE("Unable to compute function", count >= 0.0); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xsheetoutline.cxx b/test/source/sheet/xsheetoutline.cxx new file mode 100644 index 000000000..d60820021 --- /dev/null +++ b/test/source/sheet/xsheetoutline.cxx @@ -0,0 +1,264 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xsheetoutline.hxx> + +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/table/XCellRange.hpp> + +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/table/TableOrientation.hpp> + +#include <com/sun/star/sheet/XSheetCellRanges.hpp> +#include <com/sun/star/sheet/XSheetOutline.hpp> +#include <com/sun/star/sheet/XCellRangesQuery.hpp> + +#include <cppunit/TestAssert.h> +#include <rtl/ustring.hxx> + +using namespace css; +using namespace css::uno; + +namespace apitest { + +constexpr OUStringLiteral colLevel1 = u"OutlineSheet.A1:Z1"; +constexpr OUStringLiteral colLevel2 = u"OutlineSheet.C1:W1"; +constexpr OUStringLiteral colLevel3 = u"OutlineSheet.E1:U1"; +constexpr OUStringLiteral colLevel4 = u"OutlineSheet.G1:S1"; + +constexpr OUStringLiteral rowLevel1 = u"OutlineSheet.A1:A30"; +constexpr OUStringLiteral rowLevel2 = u"OutlineSheet.A3:A27"; + +static OUString getVisibleAddress( + uno::Reference<sheet::XSpreadsheet> const& xSheet, + const OUString& aLevelRangeString) +{ + + uno::Reference<table::XCellRange> aSheetRangeAccess(xSheet, UNO_QUERY_THROW); + uno::Reference<table::XCellRange> aLevelRange = aSheetRangeAccess->getCellRangeByName(aLevelRangeString); + + uno::Reference<sheet::XCellRangesQuery> xCellRangesQuery(aLevelRange,UNO_QUERY_THROW); + uno::Reference<sheet::XSheetCellRanges> xRanges = xCellRangesQuery->queryVisibleCells(); + OUString aResult = xRanges->getRangeAddressesAsString(); + + return aResult; + +} + +static table::CellRangeAddress getAddressFromRangeString( + uno::Reference<sheet::XSpreadsheet> const& xSheet, + const OUString& aStringAddress) +{ + + uno::Reference< table::XCellRange > aSheetRangeAccess(xSheet, UNO_QUERY_THROW); + uno::Reference<table::XCellRange> aRange = aSheetRangeAccess->getCellRangeByName(aStringAddress); + + uno::Reference<sheet::XCellRangeAddressable> xCellRangeAddressable(aRange, UNO_QUERY_THROW); + table::CellRangeAddress aLevelRangeAddress = xCellRangeAddressable->getRangeAddress(); + + return aLevelRangeAddress; + +} + +void XSheetOutline::testHideDetail() +{ + + uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW); + uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW); + + // Column level 2 + table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aSheet, colLevel2); + aSheetOutline->hideDetail(aLevelRangeAddress); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Column level 2 not hidden", + getVisibleAddress(aSheet, colLevel2), OUString()); + + // Row Level 2 + aLevelRangeAddress = getAddressFromRangeString(aSheet, rowLevel2); + aSheetOutline->hideDetail(aLevelRangeAddress); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Row level 2 not hidden", + getVisibleAddress(aSheet, rowLevel2), OUString()); + +} + +void XSheetOutline::testShowDetail() +{ + uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW); + uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW); + + aSheetOutline->showDetail(getAddressFromRangeString(aSheet, colLevel1)); + aSheetOutline->showDetail(getAddressFromRangeString(aSheet, rowLevel1)); + + // Row Level 2 + table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aSheet, rowLevel2); + aSheetOutline->showDetail(aLevelRangeAddress); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Row level 2 still hidden", + getVisibleAddress(aSheet, rowLevel2), OUString(rowLevel2)); + + // Column Level 2 + aLevelRangeAddress = getAddressFromRangeString(aSheet, colLevel2); + aSheetOutline->showDetail(aLevelRangeAddress); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Column level 2 still hidden", + getVisibleAddress(aSheet, colLevel2), OUString(colLevel2)); + +} + +void XSheetOutline::testShowLevel() +{ + + uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW); + uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW); + + // test columns + + table::CellRangeAddress aLevel1 = getAddressFromRangeString(aSheet, colLevel1); + table::CellRangeAddress aLevel2 = getAddressFromRangeString(aSheet, colLevel2); + table::CellRangeAddress aLevel3 = getAddressFromRangeString(aSheet, colLevel3); + table::CellRangeAddress aLevel4 = getAddressFromRangeString(aSheet, colLevel4); + + aSheetOutline->showDetail(getAddressFromRangeString(aSheet, colLevel1)); + aSheetOutline->showDetail(getAddressFromRangeString(aSheet, colLevel2)); + aSheetOutline->showDetail(getAddressFromRangeString(aSheet, rowLevel1)); + + aSheetOutline->hideDetail(aLevel1); + aSheetOutline->hideDetail(aLevel2); + aSheetOutline->hideDetail(aLevel3); + aSheetOutline->hideDetail(aLevel4); + + aSheetOutline->showLevel(2, table::TableOrientation_COLUMNS); + + std::cout << " verify showLevel col apres" << getVisibleAddress(aSheet, "OutlineSheet.A1:Z30") << std::endl; + + // verify that level 2 and level 1 are shown --> column 0..3 & column 22..26 + // level 3 & 4 are hidden --> column 4..19 + + CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString("OutlineSheet.A1:D1"), getVisibleAddress(aSheet, "OutlineSheet.A1:D1")); + CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString("OutlineSheet.V1:Z1"), getVisibleAddress(aSheet, "OutlineSheet.V1:Z1")); + CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Column", OUString(), getVisibleAddress(aSheet, colLevel3)); + +/* FIXME !! + + // test Rows + + aLevel1 = getAddressFromRangeString(rowLevel1); + aLevel2 = getAddressFromRangeString(rowLevel2); + aLevel3 = getAddressFromRangeString(rowLevel3); + aLevel4 = getAddressFromRangeString(rowLevel4); + + aSheetOutline->showDetail(getAddressFromRangeString(colLevel1)); + aSheetOutline->showDetail(getAddressFromRangeString(rowLevel1)); + aSheetOutline->showDetail(getAddressFromRangeString(rowLevel2)); + + std::cout << " verify showLevel row before" << OUStringToOString(getVisibleAddress("OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl; + + aSheetOutline->hideDetail(aLevel1); + aSheetOutline->hideDetail(aLevel2); + aSheetOutline->hideDetail(aLevel3); + aSheetOutline->hideDetail(aLevel4); + + std::cout << " verify showLevel row just before" << OUStringToOString(getVisibleAddress("OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl; + + aSheetOutline->showLevel(2, table::TableOrientation_ROWS); + + std::cout << " verify showLevel row after" << OUStringToOString(getVisibleAddress("OutlineSheet.A1:Z30"), RTL_TEXTENCODING_UTF8).getStr() << std::endl; + + // verify rows visible 0..3 & 24..29 + // verify rows hidden 4..23 + + CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Row", OUString("OutlineSheet.A1:A4"), getVisibleAddress("OutlineSheet.A1:A4")); + CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Row", OUString("OutlineSheet.A25:A30"), getVisibleAddress("OutlineSheet.A25:A30")); + CPPUNIT_ASSERT_EQUAL_MESSAGE("testShowLevel Row", OUString(), getVisibleAddress(rowLevel3)); + +*/ + +} + +void XSheetOutline::testGroup() +{ + + uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW); + uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW); + + // Column level 2 + OUString aNewString = "OutlineSheet.AB1:AG1"; + table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aSheet, aNewString); + aSheetOutline->group(aLevelRangeAddress, table::TableOrientation_COLUMNS); + + aSheetOutline->hideDetail(aLevelRangeAddress); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("testGroup Column still visible", getVisibleAddress(aSheet, aNewString), OUString()); + + // Row Level 2 + aNewString = "OutlineSheet.A50:A60"; + aLevelRangeAddress = getAddressFromRangeString(aSheet, aNewString); + aSheetOutline->group(aLevelRangeAddress, table::TableOrientation_ROWS); + + aSheetOutline->hideDetail(aLevelRangeAddress); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("testGroup Row still visible", getVisibleAddress(aSheet, aNewString), OUString()); + +} + +void XSheetOutline::testUngroup() +{ + uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW); + uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW); + + // New Column level + OUString aNewString = "OutlineSheet.BB1:BG1"; + table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aSheet, aNewString); + aSheetOutline->group(aLevelRangeAddress, table::TableOrientation_COLUMNS); + aSheetOutline->hideDetail(aLevelRangeAddress); + + aSheetOutline->ungroup(aLevelRangeAddress, table::TableOrientation_COLUMNS); + + aSheetOutline->showDetail(aLevelRangeAddress); + // should remain hidden ? + + CPPUNIT_ASSERT_EQUAL_MESSAGE("testUnGroup Column becomes visible after ungroup", getVisibleAddress(aSheet, aNewString), OUString()); + + // New Row level + aNewString = "OutlineSheet.A70:A80"; + aLevelRangeAddress = getAddressFromRangeString(aSheet, aNewString); + aSheetOutline->group(aLevelRangeAddress, table::TableOrientation_ROWS); + aSheetOutline->hideDetail(aLevelRangeAddress); + + aSheetOutline->ungroup(aLevelRangeAddress, table::TableOrientation_ROWS); + + aSheetOutline->showDetail(aLevelRangeAddress); + // should remain hidden ? + + CPPUNIT_ASSERT_EQUAL_MESSAGE("testUnGroup Row becomes visible after ungroup", getVisibleAddress(aSheet, aNewString), OUString()); + +} + +void XSheetOutline::testClearOutline() +{ + uno::Reference< sheet::XSpreadsheet > aSheet(init(), UNO_QUERY_THROW); + uno::Reference< sheet::XSheetOutline > aSheetOutline(aSheet, UNO_QUERY_THROW); + + aSheetOutline->clearOutline(); + + table::CellRangeAddress aLevelRangeAddress = getAddressFromRangeString(aSheet, colLevel1); + aSheetOutline->hideDetail(aLevelRangeAddress); + aLevelRangeAddress = getAddressFromRangeString(aSheet, rowLevel1); + aSheetOutline->hideDetail(aLevelRangeAddress); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("testClearOutline Columns are hidden after clear", getVisibleAddress(aSheet, colLevel1), OUString(colLevel1)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("testClearOutline Rows are hidden after clear", getVisibleAddress(aSheet, rowLevel1), OUString(rowLevel1)); + +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xsheetpagebreak.cxx b/test/source/sheet/xsheetpagebreak.cxx new file mode 100644 index 000000000..a1fde311c --- /dev/null +++ b/test/source/sheet/xsheetpagebreak.cxx @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xsheetpagebreak.hxx> + +#include <com/sun/star/sheet/TablePageBreakData.hpp> +#include <com/sun/star/sheet/XSheetPageBreak.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest { + +void XSheetPageBreak::testGetColumnPageBreaks() +{ + uno::Reference< sheet::XSheetPageBreak > xSheetPageBreak(init(), UNO_QUERY_THROW); + + uno::Sequence< sheet::TablePageBreakData > xColPageBreak = xSheetPageBreak->getColumnPageBreaks(); + CPPUNIT_ASSERT_MESSAGE("Unable to get column page breaks", xColPageBreak.hasElements()); +} + +void XSheetPageBreak::testGetRowPageBreaks() +{ + uno::Reference< sheet::XSheetPageBreak > xSheetPageBreak(init(), UNO_QUERY_THROW); + + uno::Sequence< sheet::TablePageBreakData > xRowPageBreak = xSheetPageBreak->getRowPageBreaks(); + CPPUNIT_ASSERT_MESSAGE("Unable to get row page breaks", xRowPageBreak.hasElements()); +} + +void XSheetPageBreak::testRemoveAllManualPageBreaks() +{ + uno::Reference< sheet::XSheetPageBreak > xSheetPageBreak(init(), UNO_QUERY_THROW); + + xSheetPageBreak->removeAllManualPageBreaks(); + + const uno::Sequence< sheet::TablePageBreakData > xColPageBreak = xSheetPageBreak->getColumnPageBreaks(); + sal_Int32 manualColPageBreaks = 0; + for ( const auto & data : xColPageBreak ) + { + if (data.ManualBreak) + manualColPageBreaks++; + } + CPPUNIT_ASSERT_EQUAL_MESSAGE("Found manual column page break", + sal_Int32(0), manualColPageBreaks); + + const uno::Sequence< sheet::TablePageBreakData > xRowPageBreak = xSheetPageBreak->getRowPageBreaks(); + sal_Int32 manualRowPageBreaks = 0; + for ( const auto & data : xRowPageBreak ) + { + if (data.ManualBreak) + manualRowPageBreaks++; + } + CPPUNIT_ASSERT_EQUAL_MESSAGE("Found manual row page break", + sal_Int32(0), manualRowPageBreaks); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xspreadsheet.cxx b/test/source/sheet/xspreadsheet.cxx new file mode 100644 index 000000000..466f995fe --- /dev/null +++ b/test/source/sheet/xspreadsheet.cxx @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xspreadsheet.hxx> + +#include <com/sun/star/sheet/XSheetCellCursor.hpp> +#include <com/sun/star/sheet/XSheetCellRange.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/uno/Reference.hxx> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + + +namespace apitest { + +void XSpreadsheet::testCreateCursor() +{ + uno::Reference< sheet::XSpreadsheet > xSheet(init(), UNO_QUERY_THROW); + + uno::Reference< sheet::XSheetCellCursor > xCursor(xSheet->createCursor(), UNO_SET_THROW); +} + +void XSpreadsheet::testCreateCursorByRange() +{ + uno::Reference< sheet::XSpreadsheet > xSheet(init(), UNO_QUERY_THROW); + + uno::Reference< sheet::XSheetCellRange > xCellRange(xSheet->getCellRangeByPosition(1, 1, 2, 3), UNO_QUERY_THROW); + uno::Reference< sheet::XSheetCellCursor > xCursor(xSheet->createCursorByRange(xCellRange), UNO_SET_THROW); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xspreadsheetdocument.cxx b/test/source/sheet/xspreadsheetdocument.cxx new file mode 100644 index 000000000..d808d8b31 --- /dev/null +++ b/test/source/sheet/xspreadsheetdocument.cxx @@ -0,0 +1,32 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xspreadsheetdocument.hxx> +#include <com/sun/star/sheet/XSpreadsheets.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XSpreadsheetDocument::testGetSheets() +{ + uno::Reference<sheet::XSpreadsheetDocument> xSpreadsheetDoc(init(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadsheetDoc->getSheets(); + CPPUNIT_ASSERT(xSheets.is()); + + uno::Reference<container::XIndexAccess> xIA(xSheets, UNO_QUERY_THROW); + CPPUNIT_ASSERT_EQUAL(mnSheets, xIA->getCount()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xspreadsheets.cxx b/test/source/sheet/xspreadsheets.cxx new file mode 100644 index 000000000..14e2bf996 --- /dev/null +++ b/test/source/sheet/xspreadsheets.cxx @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xspreadsheets.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/sheet/XSpreadsheets.hpp> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + + +namespace apitest { + +void XSpreadsheets::testInsertNewByName() +{ + uno::Reference< sheet::XSpreadsheets > xSpreadsheets(init(), UNO_QUERY_THROW); + + OUString newSheetName( "SheetToInsert" ); + xSpreadsheets->insertNewByName(newSheetName, 0); + + uno::Reference< container::XNameAccess > xNameAccess(xSpreadsheets, UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("Sheet was not insert", + xNameAccess->hasByName(newSheetName)); +} + +void XSpreadsheets::testInsertNewByNameBadName() +{ + uno::Reference< sheet::XSpreadsheets > xSpreadsheets(init(), UNO_QUERY_THROW); + + CPPUNIT_ASSERT_THROW_MESSAGE("No exception thrown", + xSpreadsheets->insertNewByName("$%#/?\\", 0), + uno::RuntimeException); +} + +void XSpreadsheets::testMoveByName() +{ + uno::Reference< sheet::XSpreadsheets > xSpreadsheets(init(), UNO_QUERY_THROW); + + // first insert one that should be moved + xSpreadsheets->insertNewByName("SheetToMove", 0); + uno::Reference< container::XNameAccess > xNameAccess(xSpreadsheets, UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("Sheet to move was not insert", + xNameAccess->hasByName("SheetToMove")); + + xSpreadsheets->moveByName("SheetToMove", 2); + + // get sheet from the new position + uno::Reference< container::XIndexAccess > oIndexAccess(xSpreadsheets, UNO_QUERY_THROW); + uno::Any aAny = oIndexAccess->getByIndex(1); + uno::Reference< container::XNamed > xNamed; + CPPUNIT_ASSERT(aAny >>= xNamed); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Sheet was not moved", + OUString("SheetToMove"), + xNamed->getName()); +} + +void XSpreadsheets::testCopyByName() +{ + uno::Reference< sheet::XSpreadsheets > xSpreadsheets(init(), UNO_QUERY_THROW); + + // insert new sheet to copy + xSpreadsheets->insertNewByName("SheetToCopySrc", 0); + uno::Reference< container::XNameAccess > xNameAccess(xSpreadsheets, UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("Sheet to copy was not insert", + xNameAccess->hasByName("SheetToCopySrc")); + + xSpreadsheets->copyByName("SheetToCopySrc", "SheetToCopyDst", 0); + CPPUNIT_ASSERT_MESSAGE("Sheet was not copied", + xNameAccess->hasByName("SheetToCopyDst")); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xspreadsheets2.cxx b/test/source/sheet/xspreadsheets2.cxx new file mode 100644 index 000000000..f88de2a43 --- /dev/null +++ b/test/source/sheet/xspreadsheets2.cxx @@ -0,0 +1,366 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xspreadsheets2.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheets2.hpp> +#include <com/sun/star/sheet/XNamedRanges.hpp> +#include <com/sun/star/sheet/XNamedRange.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> + +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/table/CellVertJustify.hpp> +#include <com/sun/star/util/XCloseable.hpp> + +#include <rtl/ustring.hxx> +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest { + +constexpr OUStringLiteral gaSrcSheetName(u"SheetToCopy"); +constexpr OUStringLiteral gaSrcFileName(u"rangenamessrc.ods"); +constexpr OUStringLiteral gaDestFileBase(u"ScNamedRangeObj.ods"); + +static sal_Int32 nInsertedSheets(0); + + +XSpreadsheets2::XSpreadsheets2() +{ +} + +XSpreadsheets2::~XSpreadsheets2() +{ + if (xDestDoc.is()) + { + uno::Reference<util::XCloseable> xCloseable(xDestDoc, UNO_QUERY_THROW); + xCloseable->close(true); + } +} + +void XSpreadsheets2::testImportedSheetNameAndIndex() +{ +/** + Verify that the imported sheet has the correct name and is placed at the right requested index +*/ + + importSheetToCopy(); + + uno::Reference< container::XNameAccess > xDestSheetNameAccess(xDestDoc->getSheets(), UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("Wrong sheet name", xDestSheetNameAccess->hasByName(gaSrcSheetName)); + +} + +void XSpreadsheets2::testImportString() +{ +/** + tests the cell A1 containing a string correctly imported +*/ + importSheetToCopy(); + + uno::Reference< table::XCell > xSrcCell = xSrcSheet->getCellByPosition(0,0); + uno::Reference< text::XTextRange > xSrcTextRange(xSrcCell, UNO_QUERY_THROW); + OUString aSrcString = xSrcTextRange->getString(); + + uno::Reference< table::XCell > xDestCell = xDestSheet->getCellByPosition(0,0); + uno::Reference< text::XTextRange > xDestTextRange(xDestCell, UNO_QUERY_THROW); + OUString aDestString = xDestTextRange->getString(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong string imported", aSrcString, aDestString); +} + +void XSpreadsheets2::testImportValue() +{ +/** + tests the cell B1 containing a value correctly imported +*/ + importSheetToCopy(); + + uno::Reference< table::XCell > xSrcCell = xSrcSheet->getCellByPosition(1,0); + sal_Int32 aSrcValue = xSrcCell->getValue(); + + uno::Reference< table::XCell > xDestCell = xDestSheet->getCellByPosition(1,0); + sal_Int32 aDestValue = xDestCell->getValue(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong value imported", aSrcValue, aDestValue); +} + +void XSpreadsheets2::testImportFormulaBasicMath() +{ +/** + tests the cell C1 containing an arithmetic formula correctly imported +*/ + importSheetToCopy(); + + uno::Reference< table::XCell > xSrcCell = xSrcSheet->getCellByPosition(2,0); + OUString aSrcFormula = xSrcCell->getFormula(); + + uno::Reference< table::XCell > xDestCell = xDestSheet->getCellByPosition(2,0); + OUString aDestFormula = xDestCell->getFormula(); + + // potential problem later: formulas might be adjusted + // add some tests that the formulas are correctly adjusted + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong formula imported", aSrcFormula, aDestFormula); +} + +void XSpreadsheets2::testImportFormulaWithNamedRange() +{ +/** + tests the cell D1 containing a formula that uses a NamedRange expression +*/ + importSheetToCopy(); + + uno::Reference< table::XCell > xSrcCell = xSrcSheet->getCellByPosition(3,0); + OUString aSrcFormula = xSrcCell->getFormula(); + + uno::Reference< table::XCell > xDestCell = xDestSheet->getCellByPosition(3,0); + OUString aDestFormula = xDestCell->getFormula(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong Namedrange formula imported", aSrcFormula, aDestFormula); +} + +void XSpreadsheets2::testImportOverExistingNamedRange() +{ +/** + Both Source and Target file define the named range initial1 + in Source, initial1 is defined outside the copied sheet + In Target, after import sheet, initial1 should point on its initial definition $Sheet1.$B$1 + + NEED MORE WORK +*/ + importSheetToCopy(); + + uno::Reference< container::XNameAccess > xDestNamedRangesNameAccess(getNamedRanges(xDestDoc), UNO_QUERY_THROW); + uno::Any aNr = xDestNamedRangesNameAccess->getByName("initial1"); + uno::Reference< sheet::XNamedRange > xDestNamedRange(aNr, UNO_QUERY_THROW); + OUString aNrDestContent = xDestNamedRange->getContent(); + + std::cout << "testImportSheet : initial1 aNrDestContent " << aNrDestContent << std::endl; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong address for initial1", OUString("$Sheet1.$B$1"), aNrDestContent); + +} + +void XSpreadsheets2::testImportNamedRangeDefinedInSource() +{ +/** + in Source file, InSheetRangeName named range is defined in the copied sheet + it does not exists in target file + test that the range named is created in target and that it points in the target copied sheet +*/ + importSheetToCopy(); + + // New range name defined in imported sheet $SheetToCopy.$A$7 + OUString aNewInSheetNamedRangeString("InSheetRangeName"); + uno::Reference< container::XNameAccess > xDestNamedRangesNameAccess(getNamedRanges(xDestDoc), UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("InSheetRangeName", xDestNamedRangesNameAccess->hasByName(aNewInSheetNamedRangeString)); + + uno::Any aNewInSheetNr = xDestNamedRangesNameAccess->getByName(aNewInSheetNamedRangeString); + uno::Reference< sheet::XNamedRange > xDestNewInSheetNamedRange(aNewInSheetNr, UNO_QUERY_THROW); + OUString aNewInSheetNrDestContent = xDestNewInSheetNamedRange->getContent(); + OUString aNewInSheetExpectedContent("$SheetToCopy.$A$7"); + + std::cout << "testImportSheet : InSheetRangeName content " << aNewInSheetNrDestContent << std::endl; + std::cout << "testImportSheet : InSheetRangeName expected " << aNewInSheetExpectedContent << std::endl; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong address for InSheetRangeName", aNewInSheetExpectedContent, aNewInSheetNrDestContent); +} + +void XSpreadsheets2::testImportNamedRangeRedefinedInSource() +{ +/** + in Source file, initial2 named range is defined in the copied sheet + it is defined in another sheet of target file + test that the range named points in the target copied sheet +*/ + importSheetToCopy(); + + // the source file redefines an existing named range in the imported sheet --> the target should not be changed + OUString aRedefinedInSheetNamedRangeString("initial2"); + uno::Reference< container::XNameAccess > xDestNamedRangesNameAccess(getNamedRanges(xDestDoc), UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("aRedefinedInSheetNamedRangeString", xDestNamedRangesNameAccess->hasByName(aRedefinedInSheetNamedRangeString)); + + uno::Any aRedefinedInSheetNr = xDestNamedRangesNameAccess->getByName(aRedefinedInSheetNamedRangeString); + uno::Reference< sheet::XNamedRange > xDestRedefinedInSheetNamedRange(aRedefinedInSheetNr, UNO_QUERY_THROW); + OUString aRedefinedInSheetNrDestContent = xDestRedefinedInSheetNamedRange->getContent(); + std::cout << "testImportSheet : initial2 content " << aRedefinedInSheetNrDestContent << std::endl; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong address for Redefined InSheet named range", OUString("$Sheet1.$B$2"), aRedefinedInSheetNrDestContent); +} + +void XSpreadsheets2::testImportNewNamedRange() +{ +/** + in Source file, new_rangename range named is defined outside the copied sheet + it does not exists in target file test that new_rangename is created and its + content points to source file as an external reference +*/ + importSheetToCopy(); + + //formula with a non-existent named range in dest - new_rangename + OUString aNewNamedRangeString("new_rangename"); + uno::Reference< container::XNameAccess > xDestNamedRangesNameAccess(getNamedRanges(xDestDoc), UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("New NamedRange not created", xDestNamedRangesNameAccess->hasByName(aNewNamedRangeString)); + + // verify the content of this new namedrange, pointing on $Sheet1.$B$1 in source. This address is already defined in target as NR content + + uno::Any aNewNr = xDestNamedRangesNameAccess->getByName(aNewNamedRangeString); + uno::Reference< sheet::XNamedRange > xDestNewNamedRange(aNewNr, UNO_QUERY_THROW); + OUString aNewNrDestContent = xDestNewNamedRange->getContent(); + + OUString aNewExpectedContent("$Sheet1.$B$1"); + + std::cout << "testImportSheet : new_rangename aNewExpectedContent " << aNewExpectedContent << std::endl; + std::cout << "testImportSheet : new_rangename aNewNrDestContent " << aNewNrDestContent << std::endl; + CPPUNIT_ASSERT_MESSAGE("Wrong New NamedRange formula string value", isExternalReference(aNewNrDestContent, aNewExpectedContent)); +} + +void XSpreadsheets2::testImportCellStyle() +{ +/** + in source file, imported sheet uses a cellstyle that does not exists in target + test that + - an imported cell D1 uses the right cellStyle + - the cellStyle is created in CellStyles family + - a property of the cellStyle (VertJustify) is correctly set +*/ + importSheetToCopy(); + + uno::Reference< table::XCell > xSrcCell = xSrcSheet->getCellByPosition(3,0); + xDestSheet->getCellByPosition(3,0); + + //new style created in dest + uno::Reference< beans::XPropertySet > xSrcCellPropSet (xSrcCell, UNO_QUERY_THROW); + static const OUStringLiteral aCellProperty(u"CellStyle"); + OUString aSrcStyleName; + CPPUNIT_ASSERT(xSrcCellPropSet->getPropertyValue(aCellProperty) >>= aSrcStyleName); + + uno::Reference< beans::XPropertySet > xDestCellPropSet (xSrcCell, UNO_QUERY_THROW); + OUString aDestStyleName; + CPPUNIT_ASSERT(xDestCellPropSet->getPropertyValue(aCellProperty) >>= aDestStyleName); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong imported Cell Style", aSrcStyleName, aDestStyleName); + + uno::Reference< style::XStyleFamiliesSupplier > xFamiliesSupplier (xDestDoc, UNO_QUERY_THROW); + uno::Reference< container::XNameAccess > xFamiliesNameAccess (xFamiliesSupplier->getStyleFamilies(), UNO_SET_THROW); + uno::Any aCellStylesFamily = xFamiliesNameAccess->getByName("CellStyles"); + uno::Reference< container::XNameContainer > xCellStylesFamilyNameAccess (aCellStylesFamily, UNO_QUERY_THROW); + + CPPUNIT_ASSERT_MESSAGE("New cell style not present", xCellStylesFamilyNameAccess->hasByName(aDestStyleName)); + + uno::Any aCellStyle = xCellStylesFamilyNameAccess->getByName(aDestStyleName); + uno::Reference< beans::XPropertySet > xCellStyleProp (aCellStyle, UNO_QUERY_THROW); + sal_Int32 aVertJustify = 0; + CPPUNIT_ASSERT(xCellStyleProp->getPropertyValue("VertJustify") >>= aVertJustify); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("New style: VertJustify not set", table::CellVertJustify_CENTER, static_cast<table::CellVertJustify>(aVertJustify)); +} + +void XSpreadsheets2::testLastAfterInsertCopy() +{ + /** Test that results in row 1 of all inserted sheets are equal to the + source sheet. The loaded destination document is kept open so several + sheets are imported. + */ + + CPPUNIT_ASSERT(nInsertedSheets > 0); + constexpr sal_Int32 nCols = 7; + + uno::Reference< container::XNameAccess> xSrcNameAccess(init(),UNO_QUERY_THROW); + xSrcSheet.set( xSrcNameAccess->getByName(gaSrcSheetName), UNO_QUERY_THROW); + + OUString aSrcString[nCols]; + for (sal_Int32 nCol=0; nCol < nCols; ++nCol) + { + uno::Reference< table::XCell > xSrcCell = xSrcSheet->getCellByPosition(nCol, 0); + uno::Reference< text::XTextRange > xSrcTextRange(xSrcCell, UNO_QUERY_THROW); + aSrcString[nCol] = xSrcTextRange->getString(); + } + // The named range 'initial2' is already present in the destination + // document defined to $Sheet1.$B$2 and thus is not copied, pointing to + // "content2" instead. + aSrcString[6] = "content2"; + + xDestDoc = getDoc(gaDestFileBase); + CPPUNIT_ASSERT(xDestDoc.is()); + uno::Reference< container::XIndexAccess > xDestSheetIndexAccess (xDestDoc->getSheets(), UNO_QUERY_THROW); + CPPUNIT_ASSERT( nInsertedSheets < xDestSheetIndexAccess->getCount()); + for (sal_Int32 nSheet=0; nSheet < nInsertedSheets; ++nSheet) + { + xDestSheet.set( xDestSheetIndexAccess->getByIndex(nSheet), UNO_QUERY_THROW); + for (sal_Int32 nCol=0; nCol < nCols; ++nCol) + { + uno::Reference< table::XCell > xDestCell = xDestSheet->getCellByPosition(nCol, 0); + uno::Reference< text::XTextRange > xDestTextRange(xDestCell, UNO_QUERY_THROW); + OUString aDestString = xDestTextRange->getString(); + + if (nCol == 4 && aDestString == "Err:540") + // The created external reference to the source document not + // allowed may result in Err:540 + continue; + + OString aMessage("Imported result does not match, sheet " + OString::number(nSheet) + + " column " + OString::number(nCol)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( aMessage.getStr(), aSrcString[nCol], aDestString); + } + } +} + +uno::Reference< sheet::XSpreadsheetDocument> XSpreadsheets2::getDoc(const OUString& aFileBase) +{ + OUString aFileURL; + createFileURL(aFileBase, aFileURL); + + uno::Reference< lang::XComponent > xComp = loadFromDesktop(aFileURL); + uno::Reference< sheet::XSpreadsheetDocument > xDoc(xComp, UNO_QUERY_THROW); + return xDoc; +} + +uno::Reference< sheet::XNamedRanges> XSpreadsheets2::getNamedRanges(uno::Reference< sheet::XSpreadsheetDocument> const & xDoc) +{ + uno::Reference< beans::XPropertySet > xPropSet (xDoc, UNO_QUERY_THROW); + uno::Reference< sheet::XNamedRanges > xNamedRanges(xPropSet->getPropertyValue("NamedRanges"), UNO_QUERY_THROW); + return xNamedRanges; +} + +void XSpreadsheets2::importSheetToCopy() +{ + uno::Reference< container::XNameAccess> xSrcNameAccess(init(),UNO_QUERY_THROW); + xSrcSheet.set( xSrcNameAccess->getByName(gaSrcSheetName), UNO_QUERY_THROW); + + xDestDoc = getDoc(gaDestFileBase); + CPPUNIT_ASSERT(xDestDoc.is()); + + // import sheet + uno::Reference< sheet::XSpreadsheets2 > xDestSheets (xDestDoc->getSheets(), UNO_QUERY_THROW); + sal_Int32 nDestPos = 0; + sal_Int32 nDestPosEffective = xDestSheets->importSheet(xDocument, gaSrcSheetName, nDestPos); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong sheet index", nDestPos, nDestPosEffective); + ++nInsertedSheets; + + uno::Reference< container::XIndexAccess > xDestSheetIndexAccess (xDestDoc->getSheets(), UNO_QUERY_THROW); + xDestSheet.set( xDestSheetIndexAccess->getByIndex(nDestPosEffective), UNO_QUERY_THROW); +} + +bool XSpreadsheets2::isExternalReference(const OUString& aDestContent, std::u16string_view aSrcContent ) +{ + CPPUNIT_ASSERT(aDestContent.startsWith("'file://")); + + return (aDestContent.endsWithIgnoreAsciiCase(aSrcContent) // same cell address + && aDestContent.indexOf(gaSrcFileName)>0); // contains source file name +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xspreadsheetview.cxx b/test/source/sheet/xspreadsheetview.cxx new file mode 100644 index 000000000..d8804cf5d --- /dev/null +++ b/test/source/sheet/xspreadsheetview.cxx @@ -0,0 +1,41 @@ +/* -*- 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 <test/sheet/xspreadsheetview.hxx> + +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSpreadsheetView.hpp> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XSpreadsheetView::testGetSetActiveSheet() +{ + uno::Reference<sheet::XSpreadsheetView> xView(init(), UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheet> xActiveSheet = xView->getActiveSheet(); + CPPUNIT_ASSERT_MESSAGE("Unable to get default active sheet", xActiveSheet.is()); + + uno::Reference<sheet::XSpreadsheet> xNewSheet = xActiveSheet; + CPPUNIT_ASSERT_MESSAGE("no sheet", xNewSheet.is()); + xView->setActiveSheet(xNewSheet); + + uno::Reference<sheet::XSpreadsheet> xNewActiveSheet = xView->getActiveSheet(); + CPPUNIT_ASSERT_MESSAGE("Unable to get new active sheet", xNewActiveSheet.is()); + CPPUNIT_ASSERT_MESSAGE("Default and new active sheet are not different", + xActiveSheet.get() != xNewActiveSheet.get()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xsubtotalcalculatable.cxx b/test/source/sheet/xsubtotalcalculatable.cxx new file mode 100644 index 000000000..ad29154d6 --- /dev/null +++ b/test/source/sheet/xsubtotalcalculatable.cxx @@ -0,0 +1,70 @@ +/* -*- 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 <test/sheet/xsubtotalcalculatable.hxx> + +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/SubTotalColumn.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XSubTotalCalculatable.hpp> +#include <com/sun/star/sheet/XSubTotalDescriptor.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest { + +void XSubTotalCalculatable::testCreateSubTotalDescriptor() +{ + uno::Reference< sheet::XSubTotalCalculatable > xSTC(init(), uno::UNO_QUERY_THROW); + uno::Reference< sheet::XSubTotalDescriptor > xSTD = xSTC->createSubTotalDescriptor(true); + + uno::Sequence< sheet::SubTotalColumn > xCols{ { /* Column */ 5, + /* Function */ sheet::GeneralFunction_SUM } }; + + CPPUNIT_ASSERT_NO_THROW_MESSAGE("Unable to create XSubTotalDescriptor", xSTD->addNew(xCols, 1)); +} + +void XSubTotalCalculatable::testApplyRemoveSubTotals() +{ + uno::Reference< sheet::XSpreadsheet > xSheet(getXSpreadsheet(), UNO_QUERY_THROW); + uno::Reference< sheet::XSubTotalCalculatable > xSTC(xSheet, UNO_QUERY_THROW); + + uno::Reference< sheet::XSubTotalDescriptor > xSTD = xSTC->createSubTotalDescriptor(true); + uno::Sequence< sheet::SubTotalColumn > xCols{ { /* Column */ 0, + /* Function */ sheet::GeneralFunction_SUM } }; + xSTD->addNew(xCols, 1); + + xSheet->getCellByPosition(0, 0)->setFormula("first"); + xSheet->getCellByPosition(1, 0)->setFormula("second"); + xSheet->getCellByPosition(0, 3)->setFormula(""); + xSheet->getCellByPosition(0, 1)->setValue(5); + xSheet->getCellByPosition(0, 2)->setValue(5); + xSheet->getCellByPosition(1, 1)->setValue(17); + xSheet->getCellByPosition(1, 2)->setValue(17); + + xSTC->applySubTotals(xSTD, true); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to apply SubTotals", + OUString("=SUBTOTAL(9;$A$2:$A$3)"), + xSheet->getCellByPosition(0, 3)->getFormula()); + + xSTC->removeSubTotals(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to remove SubTotals", + OUString(""), + xSheet->getCellByPosition(0, 3)->getFormula()); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xsubtotaldescriptor.cxx b/test/source/sheet/xsubtotaldescriptor.cxx new file mode 100644 index 000000000..037963a28 --- /dev/null +++ b/test/source/sheet/xsubtotaldescriptor.cxx @@ -0,0 +1,44 @@ +/* -*- 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 <test/sheet/xsubtotaldescriptor.hxx> + +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/SubTotalColumn.hpp> +#include <com/sun/star/sheet/XSubTotalDescriptor.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XSubTotalDescriptor::testAddNew() +{ + uno::Reference<sheet::XSubTotalDescriptor> xSTD(init(), uno::UNO_QUERY_THROW); + + uno::Sequence<sheet::SubTotalColumn> xCols{ { /* Column */ 5, + /* Function */ sheet::GeneralFunction_SUM } }; + + CPPUNIT_ASSERT_NO_THROW_MESSAGE("Unable to add column", xSTD->addNew(xCols, 1)); +} + +void XSubTotalDescriptor::testClear() +{ + uno::Reference<sheet::XSubTotalDescriptor> xSTD(init(), UNO_QUERY_THROW); + + CPPUNIT_ASSERT_NO_THROW_MESSAGE("Unable to clear XSubTotalDescriptor", xSTD->clear()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xsubtotalfield.cxx b/test/source/sheet/xsubtotalfield.cxx new file mode 100644 index 000000000..dd022af10 --- /dev/null +++ b/test/source/sheet/xsubtotalfield.cxx @@ -0,0 +1,77 @@ +/* -*- 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 <test/sheet/xsubtotalfield.hxx> + +#include <com/sun/star/sheet/GeneralFunction.hpp> +#include <com/sun/star/sheet/SubTotalColumn.hpp> +#include <com/sun/star/sheet/XSubTotalField.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +CPPUNIT_NS_BEGIN + +template<> struct assertion_traits<uno::Sequence< sheet::SubTotalColumn > > +{ + static bool equal(const uno::Sequence< sheet::SubTotalColumn >& x, + const uno::Sequence< sheet::SubTotalColumn >& y) + { + return x == y; + } + + static std::string toString(const uno::Sequence< sheet::SubTotalColumn >& x) + { + OStringStream ost; + ost << "Sequence: Length: " << x.getLength() << "\n"; + for (const auto& rElement : x) + ost << "Column: " << rElement.Column << " Function:\n"; + // FIXME: Find a way to print Function + //ost << "Column: " << element->Column << " Function: " << element->Function << "\n"; + return ost.str(); + } +}; + +CPPUNIT_NS_END + +namespace apitest { + +void XSubTotalField::testGetSetGroupColumn() +{ + uno::Reference< sheet::XSubTotalField > xSTF(init(), uno::UNO_QUERY_THROW); + + CPPUNIT_ASSERT_MESSAGE("Unable to get GroupColumn", xSTF->getGroupColumn() != 0); + + xSTF->setGroupColumn(2); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set GroupColumn to new value", + sal_Int32(2), xSTF->getGroupColumn()); +} + +void XSubTotalField::testGetSetTotalColumns() +{ + uno::Reference< sheet::XSubTotalField > xSTF(init(), UNO_QUERY_THROW); + + uno::Sequence< sheet::SubTotalColumn > sDefaultCols = xSTF->getSubTotalColumns(); + CPPUNIT_ASSERT_MESSAGE("Unable to get SubTotalColumns", sDefaultCols.hasElements()); + + uno::Sequence< sheet::SubTotalColumn > sNewCols{ { /* Column */ 5, + /* Function */ sheet::GeneralFunction_AVERAGE } }; + xSTF->setSubTotalColumns(sNewCols); + + CPPUNIT_ASSERT_MESSAGE("Unable to set SubTotalColumns", sDefaultCols != xSTF->getSubTotalColumns()); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xuniquecellformatrangessupplier.cxx b/test/source/sheet/xuniquecellformatrangessupplier.cxx new file mode 100644 index 000000000..14f4a29b8 --- /dev/null +++ b/test/source/sheet/xuniquecellformatrangessupplier.cxx @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xuniquecellformatrangessupplier.hxx> + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/sheet/XUniqueCellFormatRangesSupplier.hpp> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest { + +void XUniqueCellFormatRangesSupplier::testGetUniqueCellFormatRanges() +{ + uno::Reference< sheet::XUniqueCellFormatRangesSupplier > xSupplier(init(), UNO_QUERY_THROW); + uno::Reference< container::XIndexAccess > xIndexAccess = xSupplier->getUniqueCellFormatRanges(); + + auto count = xIndexAccess->getCount(); + CPPUNIT_ASSERT_MESSAGE("No elements found", count); + for (auto i = 0; i<count; i++) { + CPPUNIT_ASSERT_NO_THROW_MESSAGE(OString("Unable to access element " + OString::number(i)).getStr(), + xIndexAccess->getByIndex(i)); + } +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xusedareacursor.cxx b/test/source/sheet/xusedareacursor.cxx new file mode 100644 index 000000000..dcee0cf57 --- /dev/null +++ b/test/source/sheet/xusedareacursor.cxx @@ -0,0 +1,97 @@ +/* -*- 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 <test/sheet/xusedareacursor.hxx> + +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XSheetCellCursor.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/sheet/XUsedAreaCursor.hpp> + +#include <com/sun/star/table/CellRangeAddress.hpp> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + + +namespace apitest { + +void XUsedAreaCursor::testGotoStartOfUsedArea() +{ + uno::Reference< sheet::XSpreadsheet > xSheet(getXSpreadsheet(), UNO_QUERY_THROW); + uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor(xSheet->createCursor(), UNO_SET_THROW); + uno::Reference< sheet::XCellRangeAddressable> xCellRangeAddressable(xSheetCellCursor, UNO_QUERY_THROW); + + uno::Reference< sheet::XUsedAreaCursor > xUsedAreaCursor(xSheetCellCursor, UNO_QUERY_THROW); + + xUsedAreaCursor->gotoStartOfUsedArea(false); + xUsedAreaCursor->gotoEndOfUsedArea(true); + table::CellRangeAddress cellRangeAddress = xCellRangeAddressable->getRangeAddress(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong start column", + sal_Int32(0), cellRangeAddress.StartColumn); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong end column", + sal_Int32(2), cellRangeAddress.EndColumn); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong start row", + sal_Int32(0), cellRangeAddress.StartRow); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong end column", + sal_Int32(0), cellRangeAddress.EndRow); + + xUsedAreaCursor->gotoEndOfUsedArea(false); + cellRangeAddress = xCellRangeAddressable->getRangeAddress(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong start column", + sal_Int32(2), cellRangeAddress.StartColumn); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong end column", + sal_Int32(2), cellRangeAddress.EndColumn); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong start row", + sal_Int32(0), cellRangeAddress.StartRow); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong end column", + sal_Int32(0), cellRangeAddress.EndRow); +} + +void XUsedAreaCursor::testGotoEndOfUsedArea() +{ + uno::Reference< sheet::XSpreadsheet > xSheet(getXSpreadsheet(), UNO_QUERY_THROW); + uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor(xSheet->createCursor(), UNO_SET_THROW); + uno::Reference< sheet::XCellRangeAddressable> xCellRangeAddressable(xSheetCellCursor, UNO_QUERY_THROW); + + uno::Reference< sheet::XUsedAreaCursor > xUsedAreaCursor(xSheetCellCursor, UNO_QUERY_THROW); + + xUsedAreaCursor->gotoEndOfUsedArea(false); + xUsedAreaCursor->gotoStartOfUsedArea(true); + table::CellRangeAddress cellRangeAddress = xCellRangeAddressable->getRangeAddress(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong start column", + sal_Int32(0), cellRangeAddress.StartColumn); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong end column", + sal_Int32(2), cellRangeAddress.EndColumn); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong start row", + sal_Int32(0), cellRangeAddress.StartRow); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong end column", + sal_Int32(0), cellRangeAddress.EndRow); + + xUsedAreaCursor->gotoStartOfUsedArea(false); + cellRangeAddress = xCellRangeAddressable->getRangeAddress(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong start column", + sal_Int32(0), cellRangeAddress.StartColumn); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong end column", + sal_Int32(0), cellRangeAddress.EndColumn); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong start row", + sal_Int32(0), cellRangeAddress.StartRow); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong end column", + sal_Int32(0), cellRangeAddress.EndRow); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xviewfreezable.cxx b/test/source/sheet/xviewfreezable.cxx new file mode 100644 index 000000000..2e13ffd29 --- /dev/null +++ b/test/source/sheet/xviewfreezable.cxx @@ -0,0 +1,32 @@ +/* -*- 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 <test/sheet/xviewfreezable.hxx> + +#include <com/sun/star/sheet/XViewFreezable.hpp> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XViewFreezable::testFreeze() +{ + uno::Reference<sheet::XViewFreezable> xViewFreezable(init(), UNO_QUERY_THROW); + + CPPUNIT_ASSERT_MESSAGE("View has already frozen panes", !xViewFreezable->hasFrozenPanes()); + + xViewFreezable->freezeAtPosition(1, 1); + CPPUNIT_ASSERT_MESSAGE("Unable to freeze pane", xViewFreezable->hasFrozenPanes()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/sheet/xviewpane.cxx b/test/source/sheet/xviewpane.cxx new file mode 100644 index 000000000..a10c59d9c --- /dev/null +++ b/test/source/sheet/xviewpane.cxx @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/sheet/xviewpane.hxx> +#include <com/sun/star/sheet/XViewPane.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XViewPane::testFirstVisibleColumn() +{ + sal_Int32 nCol = 5; + uno::Reference<sheet::XViewPane> xViewPane(init(), UNO_QUERY_THROW); + xViewPane->setFirstVisibleColumn(nCol); + CPPUNIT_ASSERT_EQUAL(xViewPane->getFirstVisibleColumn(), nCol); +} + +void XViewPane::testFirstVisibleRow() +{ + sal_Int32 nRow = 3; + uno::Reference<sheet::XViewPane> xViewPane(init(), UNO_QUERY_THROW); + xViewPane->setFirstVisibleRow(nRow); + CPPUNIT_ASSERT_EQUAL(xViewPane->getFirstVisibleRow(), nRow); +} + +void XViewPane::testVisibleRange() +{ + constexpr sal_Int32 nCol = 5; + constexpr sal_Int32 nRow = 3; + uno::Reference<sheet::XViewPane> xViewPane(init(), UNO_QUERY_THROW); + xViewPane->setFirstVisibleColumn(nCol); + xViewPane->setFirstVisibleRow(nRow); + + table::CellRangeAddress aCellRangeAddress = xViewPane->getVisibleRange(); + CPPUNIT_ASSERT_EQUAL(short(0), aCellRangeAddress.Sheet); + CPPUNIT_ASSERT_EQUAL(nRow, aCellRangeAddress.StartRow); + CPPUNIT_ASSERT_EQUAL(nCol, aCellRangeAddress.StartColumn); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/sheet/xviewsplitable.cxx b/test/source/sheet/xviewsplitable.cxx new file mode 100644 index 000000000..e9f8d62b8 --- /dev/null +++ b/test/source/sheet/xviewsplitable.cxx @@ -0,0 +1,42 @@ +/* -*- 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 <test/sheet/xviewsplitable.hxx> + +#include <com/sun/star/sheet/XViewSplitable.hpp> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest { + +void XViewSplitable::testSplit() +{ + uno::Reference< sheet::XViewSplitable > xViewSplitable(init(), UNO_QUERY_THROW); + CPPUNIT_ASSERT_MESSAGE("View is already split", !xViewSplitable->getIsWindowSplit()); + + xViewSplitable->splitAtPosition(90, 51); + + CPPUNIT_ASSERT_MESSAGE("View wasn't split", xViewSplitable->getIsWindowSplit()); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong horizontal pixel position", + sal_Int32(90), xViewSplitable->getSplitHorizontal()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong vertical pixel position", + sal_Int32(51), xViewSplitable->getSplitVertical()); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong column", + sal_Int32(1), xViewSplitable->getSplitColumn()); + CPPUNIT_ASSERT_MESSAGE("Wrong row", xViewSplitable->getSplitRow() != 0); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/style/xstyleloader.cxx b/test/source/style/xstyleloader.cxx new file mode 100644 index 000000000..4b58758d9 --- /dev/null +++ b/test/source/style/xstyleloader.cxx @@ -0,0 +1,123 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/style/xstyleloader.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/style/XStyleLoader2.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <rtl/ustring.hxx> +#include <cppunit/TestAssert.h> +#include <comphelper/processfactory.hxx> +#include <comphelper/storagehelper.hxx> + +using namespace comphelper; +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XStyleLoader::testLoadStylesFromURL() +{ + uno::Reference<style::XStyleLoader2> xStyleLoader(init(), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(getTargetDoc(), uno::UNO_SET_THROW); + const OUString aFileURL = getTestURL(); + + uno::Sequence<beans::PropertyValue> aOptions = xStyleLoader->getStyleLoaderOptions(); + xStyleLoader->loadStylesFromURL(aFileURL, aOptions); + + uno::Reference<style::XStyleFamiliesSupplier> xFamilySupplier(xDoc, UNO_QUERY_THROW); + checkStyleProperties(xFamilySupplier); +} + +void XStyleLoader::testLoadStylesFromDocument() +{ + uno::Reference<style::XStyleLoader2> xStyleLoader(init(), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(getTargetDoc(), uno::UNO_SET_THROW); + uno::Reference<lang::XComponent> xSrcComponent(getSourceComponent(), UNO_SET_THROW); + + uno::Sequence<beans::PropertyValue> aOptions = xStyleLoader->getStyleLoaderOptions(); + xStyleLoader->loadStylesFromDocument(xSrcComponent, aOptions); + + uno::Reference<style::XStyleFamiliesSupplier> xFamilySupplier(xDoc, UNO_QUERY_THROW); + checkStyleProperties(xFamilySupplier); +} + +void XStyleLoader::testLoadStylesFromStream() +{ + uno::Reference<style::XStyleLoader2> xStyleLoader(init(), uno::UNO_QUERY_THROW); + + uno::Reference<sheet::XSpreadsheetDocument> xDoc(getTargetDoc(), uno::UNO_SET_THROW); + const OUString aFileURL = getTestURL(); + const uno::Reference<io::XInputStream> xInputStream + = OStorageHelper::GetInputStreamFromURL(aFileURL, getProcessComponentContext()); + + uno::Sequence<beans::PropertyValue> aOptions = xStyleLoader->getStyleLoaderOptions(); + auto nLength = aOptions.getLength(); + aOptions.realloc(nLength + 1); + beans::PropertyValue aInputStream; + aInputStream.Name = "InputStream"; + uno::Any aTmp; + aTmp <<= xInputStream; + aInputStream.Value = aTmp; + aOptions.getArray()[nLength] = aInputStream; + + xStyleLoader->loadStylesFromURL("private:stream", aOptions); + + uno::Reference<style::XStyleFamiliesSupplier> xFamilySupplier(xDoc, UNO_QUERY_THROW); + checkStyleProperties(xFamilySupplier); +} + +void XStyleLoader::checkStyleProperties( + uno::Reference<style::XStyleFamiliesSupplier> const& xFamilySupplier) +{ + // check if targetDocument has myStyle + uno::Reference<container::XNameAccess> xFamilies(xFamilySupplier->getStyleFamilies(), + UNO_SET_THROW); + uno::Reference<container::XNameContainer> xCellStyles(xFamilies->getByName("CellStyles"), + UNO_QUERY_THROW); + + CPPUNIT_ASSERT_MESSAGE("Style not imported", xCellStyles->hasByName("myStyle")); + + // test the backgroundcolor is correctly imported + uno::Reference<style::XStyle> xMyStyle(xCellStyles->getByName("myStyle"), UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPropSet(xMyStyle, UNO_QUERY_THROW); + + uno::Any aBackColor = xPropSet->getPropertyValue("CellBackColor"); + uno::Any expectedBackColor(sal_Int32(16724787)); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong CellBackColor", expectedBackColor, aBackColor); + + // test default pageStyle + + uno::Reference<container::XNameContainer> xPageStyles(xFamilies->getByName("PageStyles"), + UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPagePropSet(xPageStyles->getByName("Default"), + UNO_QUERY_THROW); + + uno::Any aPageBackColor = xPagePropSet->getPropertyValue("BackColor"); + uno::Any expectedPageBackColor(sal_Int32(13434879)); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong page style BackColor", expectedPageBackColor, + aPageBackColor); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/table/tablecolumn.cxx b/test/source/table/tablecolumn.cxx new file mode 100644 index 000000000..08a008ce8 --- /dev/null +++ b/test/source/table/tablecolumn.cxx @@ -0,0 +1,53 @@ +/* -*- 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 <test/table/tablecolumn.hxx> +#include <test/unoapi_property_testers.hxx> +#include <comphelper/types.hxx> +#include <rtl/ustring.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/table/XCellRange.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void TableColumn::testTableColumnProperties() +{ + uno::Reference<beans::XPropertySet> xPS(init(), uno::UNO_QUERY_THROW); + + OUString aPropName = "Width"; + testLongProperty(xPS, aPropName); + + // currently changing the value to false has no effect + aPropName = "OptimalWidth"; + uno::Reference<table::XCellRange> xCR(m_xSheet, uno::UNO_QUERY_THROW); + xCR->getCellByPosition(0, 0)->setFormula("That's a pretty long text."); + const sal_Int64 nWidthBefore = ::comphelper::getINT64(xPS->getPropertyValue("Width")); + xPS->setPropertyValue(aPropName, uno::Any(true)); + CPPUNIT_ASSERT(::comphelper::getBOOL(xPS->getPropertyValue(aPropName))); + const sal_Int64 nWidthAfter = ::comphelper::getINT64(xPS->getPropertyValue("Width")); + CPPUNIT_ASSERT(nWidthBefore != nWidthAfter); + + aPropName = "IsVisible"; + testBooleanProperty(xPS, aPropName); + + aPropName = "IsStartOfNewPage"; + testBooleanProperty(xPS, aPropName); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/table/tablerow.cxx b/test/source/table/tablerow.cxx new file mode 100644 index 000000000..2d14c1625 --- /dev/null +++ b/test/source/table/tablerow.cxx @@ -0,0 +1,40 @@ +/* -*- 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 <test/table/tablerow.hxx> +#include <test/unoapi_property_testers.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> + +using namespace css; + +namespace apitest +{ +void TableRow::testTableRowProperties() +{ + uno::Reference<beans::XPropertySet> xPS(init(), uno::UNO_QUERY_THROW); + + OUString aPropName; + + aPropName = "Height"; + testLongProperty(xPS, aPropName); + + aPropName = "OptimalHeight"; + testBooleanProperty(xPS, aPropName); + + aPropName = "IsVisible"; + testBooleanProperty(xPS, aPropName); + + aPropName = "IsStartOfNewPage"; + testBooleanProperty(xPS, aPropName); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/table/xcell.cxx b/test/source/table/xcell.cxx new file mode 100644 index 000000000..8540117a5 --- /dev/null +++ b/test/source/table/xcell.cxx @@ -0,0 +1,79 @@ +/* -*- 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 <test/table/xcell.hxx> + +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/table/CellContentType.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XCell::testGetError() +{ + uno::Reference<table::XCell> xCell(init(), UNO_QUERY_THROW); + const sal_Int32 nCorrectFormula = xCell->getError(); + xCell->setFormula("=sqrt(-2)"); + const sal_Int32 nIncorrectFormula = xCell->getError(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Successfully able to get Error", sal_Int32(0), nCorrectFormula); + CPPUNIT_ASSERT_MESSAGE("Successfully able to get Error", (nIncorrectFormula != 0)); +} + +void XCell::testGetType() +{ + uno::Reference<table::XCell> xCell(init(), UNO_QUERY_THROW); + bool aResult = true; + + if (xCell->getType() == table::CellContentType_EMPTY) + aResult &= true; + else if (xCell->getType() == table::CellContentType_VALUE) + aResult &= true; + else if (xCell->getType() == table::CellContentType_TEXT) + aResult &= true; + else if (xCell->getType() == table::CellContentType_FORMULA) + aResult &= true; + else + aResult = false; + + CPPUNIT_ASSERT_MESSAGE("Successfully able to get Type", aResult); +} + +void XCell::testSetGetFormula() +{ + uno::Reference<table::XCell> xCell(init(), UNO_QUERY_THROW); + OUString aFormula = "=2+2"; + + xCell->setFormula(aFormula); + + OUString aFormula2 = xCell->getFormula(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Successfully able to set and get Formula", aFormula, aFormula2); +} + +void XCell::testSetGetValue() +{ + uno::Reference<table::XCell> xCell(init(), UNO_QUERY_THROW); + double nInValue = 222.555; + + xCell->setValue(nInValue); + + double nCellValue = xCell->getValue(); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Successfully able to set and get Value", nInValue, nCellValue); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/table/xcellcursor.cxx b/test/source/table/xcellcursor.cxx new file mode 100644 index 000000000..6f6cc33e0 --- /dev/null +++ b/test/source/table/xcellcursor.cxx @@ -0,0 +1,126 @@ +/* -*- 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 <test/table/xcellcursor.hxx> + +#include <com/sun/star/sheet/XCellRangeAddressable.hpp> +#include <com/sun/star/sheet/XSheetCellCursor.hpp> +#include <com/sun/star/sheet/XSheetCellRange.hpp> +#include <com/sun/star/sheet/XSpreadsheet.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/table/XCellCursor.hpp> +#include <com/sun/star/table/XCellRange.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XCellCursor::testGoToNext() +{ + uno::Reference<table::XCellCursor> xCellCursor(init(), UNO_QUERY_THROW); + + uno::Reference<sheet::XCellRangeAddressable> xCellRangeAddressable(xCellCursor, + UNO_QUERY_THROW); + table::CellRangeAddress aCellRangeAddr = xCellRangeAddressable->getRangeAddress(); + const sal_Int32 startCol = aCellRangeAddr.StartColumn; + + xCellCursor->gotoNext(); + + aCellRangeAddr = xCellRangeAddressable->getRangeAddress(); + const sal_Int32 startCol2 = aCellRangeAddr.StartColumn; + + CPPUNIT_ASSERT_MESSAGE("Successfully able to go to Next", startCol != startCol2); +} + +void XCellCursor::testGoToOffset() +{ + uno::Reference<table::XCellCursor> xCellCursor(init(), UNO_QUERY_THROW); + + uno::Reference<sheet::XCellRangeAddressable> xCellRangeAddressable(xCellCursor, + UNO_QUERY_THROW); + table::CellRangeAddress aCellRangeAddr = xCellRangeAddressable->getRangeAddress(); + const sal_Int32 startRow = aCellRangeAddr.StartRow; + const sal_Int32 startCol = aCellRangeAddr.StartColumn; + + xCellCursor->gotoOffset(4, 4); + + aCellRangeAddr = xCellRangeAddressable->getRangeAddress(); + const sal_Int32 startRow2 = aCellRangeAddr.StartRow; + const sal_Int32 startCol2 = aCellRangeAddr.StartColumn; + + CPPUNIT_ASSERT_MESSAGE("Successfully able to go to Offset", + (startCol != startCol2) || (startRow == startRow2)); +} + +void XCellCursor::testGoToPrevious() +{ + uno::Reference<table::XCellCursor> xCellCursor(init(), UNO_QUERY_THROW); + + uno::Reference<sheet::XCellRangeAddressable> xCellRangeAddressable(xCellCursor, + UNO_QUERY_THROW); + xCellCursor->gotoOffset(4, 4); + + table::CellRangeAddress aCellRangeAddr = xCellRangeAddressable->getRangeAddress(); + const sal_Int32 startCol = aCellRangeAddr.StartColumn; + + xCellCursor->gotoPrevious(); + + aCellRangeAddr = xCellRangeAddressable->getRangeAddress(); + const sal_Int32 startCol2 = aCellRangeAddr.StartColumn; + CPPUNIT_ASSERT_MESSAGE("Successfully able to go to Previous", startCol != startCol2); +} + +void XCellCursor::testGoToStart() +{ + uno::Reference<table::XCellCursor> xCellCursor(init(), UNO_QUERY_THROW); + + uno::Reference<sheet::XCellRangeAddressable> xCellRangeAddressable(xCellCursor, + UNO_QUERY_THROW); + xCellCursor->gotoStart(); + + table::CellRangeAddress aCellRangeAddr = xCellRangeAddressable->getRangeAddress(); + + const sal_Int32 startRow = aCellRangeAddr.StartRow; + const sal_Int32 startCol = aCellRangeAddr.StartColumn; + const sal_Int32 endRow = aCellRangeAddr.EndRow; + const sal_Int32 endCol = aCellRangeAddr.EndColumn; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Successfully able to go to Start", startCol, endCol); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Successfully able to go to Start", endRow, startRow); +} + +void XCellCursor::testGoToEnd() +{ + uno::Reference<table::XCellCursor> xCellCursor(init(), UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSpreadsheet(getXSpreadsheet(), UNO_QUERY_THROW); + uno::Reference<table::XCellRange> xCellRange(xCellCursor, UNO_QUERY_THROW); + xCellRange = xSpreadsheet->getCellRangeByName("$A$1:$g$7"); + uno::Reference<sheet::XSheetCellRange> xSheetCellRange(xCellCursor, UNO_QUERY_THROW); + uno::Reference<sheet::XSheetCellCursor> xSheetCellCursor(xCellCursor, UNO_QUERY_THROW); + xSheetCellCursor = xSpreadsheet->createCursorByRange(xSheetCellRange); + uno::Reference<sheet::XCellRangeAddressable> xCellRangeAddressable(xCellCursor, + UNO_QUERY_THROW); + + xCellCursor->gotoEnd(); + + table::CellRangeAddress aCellRangeAddr = xCellRangeAddressable->getRangeAddress(); + const sal_Int32 startRow = aCellRangeAddr.StartRow; + const sal_Int32 startCol = aCellRangeAddr.StartColumn; + const sal_Int32 endRow = aCellRangeAddr.EndRow; + const sal_Int32 endCol = aCellRangeAddr.EndColumn; + CPPUNIT_ASSERT_EQUAL_MESSAGE("Successfully able to go to End", startCol, endCol); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Successfully able to go to End", endRow, startRow); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/table/xcellrange.cxx b/test/source/table/xcellrange.cxx new file mode 100644 index 000000000..392904078 --- /dev/null +++ b/test/source/table/xcellrange.cxx @@ -0,0 +1,56 @@ +/* -*- 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 <test/table/xcellrange.hxx> + +#include <com/sun/star/lang/IndexOutOfBoundsException.hpp> +#include <com/sun/star/table/XCell.hpp> +#include <com/sun/star/table/XCellRange.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void XCellRange::testGetCellByPosition() +{ + uno::Reference<table::XCellRange> xCR(init(), uno::UNO_QUERY_THROW); + + uno::Reference<table::XCell> xCell(xCR->getCellByPosition(0, 0), uno::UNO_SET_THROW); + CPPUNIT_ASSERT(xCell.is()); + + CPPUNIT_ASSERT_THROW(xCR->getCellByPosition(-1, 1), lang::IndexOutOfBoundsException); +} + +void XCellRange::testGetCellRangeByName() +{ + uno::Reference<table::XCellRange> xCR(init(), uno::UNO_QUERY_THROW); + + uno::Reference<table::XCellRange> xCellRange(xCR->getCellRangeByName(m_aRangeName), + uno::UNO_SET_THROW); + CPPUNIT_ASSERT(xCellRange.is()); +} + +void XCellRange::testGetCellRangeByPosition() +{ + uno::Reference<table::XCellRange> xCR(init(), uno::UNO_QUERY_THROW); + + uno::Reference<table::XCellRange> xCellRange(xCR->getCellRangeByPosition(0, 0, 0, 0), + uno::UNO_SET_THROW); + CPPUNIT_ASSERT(xCellRange.is()); + + CPPUNIT_ASSERT_THROW(xCR->getCellRangeByPosition(-1, 0, -1, 1), + lang::IndexOutOfBoundsException); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/table/xcolumnrowrange.cxx b/test/source/table/xcolumnrowrange.cxx new file mode 100644 index 000000000..748a4825d --- /dev/null +++ b/test/source/table/xcolumnrowrange.cxx @@ -0,0 +1,36 @@ +/* -*- 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 <test/table/xcolumnrowrange.hxx> + +#include <com/sun/star/table/XColumnRowRange.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XColumnRowRange::testGetColumns() +{ + uno::Reference<table::XColumnRowRange> xColumnRowRange(init(), UNO_QUERY_THROW); + CPPUNIT_ASSERT(xColumnRowRange->getColumns()); +} + +void XColumnRowRange::testGetRows() +{ + uno::Reference<table::XColumnRowRange> xColumnRowRange(init(), UNO_QUERY_THROW); + CPPUNIT_ASSERT(xColumnRowRange->getRows()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/table/xtablechart.cxx b/test/source/table/xtablechart.cxx new file mode 100644 index 000000000..38a43eee6 --- /dev/null +++ b/test/source/table/xtablechart.cxx @@ -0,0 +1,60 @@ +/* -*- 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 <test/table/xtablechart.hxx> +#include <test/cppunitasserthelper.hxx> + +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/table/XTableChart.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void XTableChart::testGetSetHasColumnHeaders() +{ + uno::Reference<table::XTableChart> xTC(init(), uno::UNO_QUERY_THROW); + + xTC->setHasColumnHeaders(false); + CPPUNIT_ASSERT(!xTC->getHasColumnHeaders()); + + xTC->setHasColumnHeaders(true); + CPPUNIT_ASSERT(xTC->getHasColumnHeaders()); +} + +void XTableChart::testGetSetHasRowHeaders() +{ + uno::Reference<table::XTableChart> xTC(init(), uno::UNO_QUERY_THROW); + + xTC->setHasRowHeaders(false); + CPPUNIT_ASSERT(!xTC->getHasRowHeaders()); + + xTC->setHasRowHeaders(true); + CPPUNIT_ASSERT(xTC->getHasRowHeaders()); +} + +void XTableChart::testGetSetRanges() +{ + uno::Reference<table::XTableChart> xTC(init(), uno::UNO_QUERY_THROW); + + uno::Sequence<table::CellRangeAddress> aCRA = xTC->getRanges(); + aCRA.getArray()[0].EndRow = 1; + + xTC->setRanges(aCRA); + + CPPUNIT_ASSERT_EQUAL(aCRA[0], xTC->getRanges()[0]); +} + +} // namespace apitest +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/table/xtablecharts.cxx b/test/source/table/xtablecharts.cxx new file mode 100644 index 000000000..15aa710ff --- /dev/null +++ b/test/source/table/xtablecharts.cxx @@ -0,0 +1,39 @@ +/* -*- 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 <test/table/xtablecharts.hxx> + +#include <com/sun/star/awt/Rectangle.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <com/sun/star/table/XTableCharts.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void XTableCharts::testAddNewRemoveByName() +{ + uno::Reference<table::XTableCharts> xTC(init(), uno::UNO_QUERY_THROW); + + uno::Sequence<table::CellRangeAddress> aRanges{ table::CellRangeAddress(0, 1, 1, 14, 4) }; + xTC->addNewByName("XTableCharts", awt::Rectangle(500, 3000, 25000, 11000), aRanges, true, true); + CPPUNIT_ASSERT(xTC->hasByName("XTableCharts")); + + xTC->removeByName("XTableCharts"); + CPPUNIT_ASSERT(!xTC->hasByName("XTableCharts")); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/table/xtablechartssupplier.cxx b/test/source/table/xtablechartssupplier.cxx new file mode 100644 index 000000000..047695dfc --- /dev/null +++ b/test/source/table/xtablechartssupplier.cxx @@ -0,0 +1,31 @@ +/* -*- 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 <test/table/xtablechartssupplier.hxx> + +#include <com/sun/star/table/XTableChartsSupplier.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XTableChartsSupplier::testGetCharts() +{ + uno::Reference<table::XTableChartsSupplier> xTableChartsSupplier(init(), UNO_QUERY_THROW); + + CPPUNIT_ASSERT_MESSAGE("Successfully able to Get Charts", xTableChartsSupplier->getCharts()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/table/xtablecolumns.cxx b/test/source/table/xtablecolumns.cxx new file mode 100644 index 000000000..0d72a8dd1 --- /dev/null +++ b/test/source/table/xtablecolumns.cxx @@ -0,0 +1,173 @@ +/* -*- 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 <test/table/xtablecolumns.hxx> + +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/table/XTableColumns.hpp> +#include <com/sun/star/text/XSimpleText.hpp> +#include <com/sun/star/uno/RuntimeException.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void XTableColumns::testInsertByIndex() +{ + uno::Reference<table::XTableColumns> xTC(init(), uno::UNO_QUERY_THROW); + uno::Reference<table::XCellRange> xCR(m_xSheet, uno::UNO_QUERY_THROW); + + // insert one column at position one + xTC->insertByIndex(1, 1); + CPPUNIT_ASSERT_EQUAL(OUString("0a"), getCellText(xCR->getCellByPosition(0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0b"), getCellText(xCR->getCellByPosition(0, 1))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(1, 1))); + CPPUNIT_ASSERT_EQUAL(OUString("1a"), getCellText(xCR->getCellByPosition(2, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("1b"), getCellText(xCR->getCellByPosition(2, 1))); + CPPUNIT_ASSERT_EQUAL(OUString("2a"), getCellText(xCR->getCellByPosition(3, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("2b"), getCellText(xCR->getCellByPosition(3, 1))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(4, 0))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(4, 1))); + + // insert one column at position zero + xTC->insertByIndex(0, 1); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(0, 1))); + CPPUNIT_ASSERT_EQUAL(OUString("0a"), getCellText(xCR->getCellByPosition(1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0b"), getCellText(xCR->getCellByPosition(1, 1))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(2, 0))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(2, 1))); + CPPUNIT_ASSERT_EQUAL(OUString("1a"), getCellText(xCR->getCellByPosition(3, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("1b"), getCellText(xCR->getCellByPosition(3, 1))); + CPPUNIT_ASSERT_EQUAL(OUString("2a"), getCellText(xCR->getCellByPosition(4, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("2b"), getCellText(xCR->getCellByPosition(4, 1))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(5, 0))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(5, 1))); + + // insert two columns at position zero + xTC->insertByIndex(0, 2); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(0, 1))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(1, 1))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(2, 0))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(2, 1))); + CPPUNIT_ASSERT_EQUAL(OUString("0a"), getCellText(xCR->getCellByPosition(3, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0b"), getCellText(xCR->getCellByPosition(3, 1))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(4, 0))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(4, 1))); + CPPUNIT_ASSERT_EQUAL(OUString("1a"), getCellText(xCR->getCellByPosition(5, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("1b"), getCellText(xCR->getCellByPosition(5, 1))); + CPPUNIT_ASSERT_EQUAL(OUString("2a"), getCellText(xCR->getCellByPosition(6, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("2b"), getCellText(xCR->getCellByPosition(6, 1))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(7, 0))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(7, 1))); +} + +void XTableColumns::testInsertByIndexWithNegativeIndex() +{ + uno::Reference<table::XTableColumns> xTC(init(), uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_THROW(xTC->insertByIndex(-1, 1), uno::RuntimeException); +} + +void XTableColumns::testInsertByIndexWithNoColumn() +{ + uno::Reference<table::XTableColumns> xTC(init(), uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_THROW(xTC->insertByIndex(0, 0), uno::RuntimeException); +} + +void XTableColumns::testInsertByIndexWithOutOfBoundIndex() +{ + uno::Reference<table::XTableColumns> xTC(init(), uno::UNO_QUERY_THROW); + + CPPUNIT_ASSERT_THROW(xTC->insertByIndex(xTC->getCount(), 1), uno::RuntimeException); +} + +void XTableColumns::testRemoveByIndex() +{ + uno::Reference<table::XTableColumns> xTC(init(), uno::UNO_QUERY_THROW); + uno::Reference<table::XCellRange> xCR(m_xSheet, uno::UNO_QUERY_THROW); + + xTC->insertByIndex(1, 1); // insert one column at position one + xTC->insertByIndex(0, 1); // insert one column at position zero + xTC->insertByIndex(0, 2); // insert two columns at position zero + + // remove two columns at position zero + xTC->removeByIndex(0, 2); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(0, 1))); + CPPUNIT_ASSERT_EQUAL(OUString("0a"), getCellText(xCR->getCellByPosition(1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0b"), getCellText(xCR->getCellByPosition(1, 1))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(2, 0))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(2, 1))); + CPPUNIT_ASSERT_EQUAL(OUString("1a"), getCellText(xCR->getCellByPosition(3, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("1b"), getCellText(xCR->getCellByPosition(3, 1))); + CPPUNIT_ASSERT_EQUAL(OUString("2a"), getCellText(xCR->getCellByPosition(4, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("2b"), getCellText(xCR->getCellByPosition(4, 1))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(5, 0))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(5, 1))); + + // remove one column at position zero + xTC->removeByIndex(0, 1); + CPPUNIT_ASSERT_EQUAL(OUString("0a"), getCellText(xCR->getCellByPosition(0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0b"), getCellText(xCR->getCellByPosition(0, 1))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(1, 1))); + CPPUNIT_ASSERT_EQUAL(OUString("1a"), getCellText(xCR->getCellByPosition(2, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("1b"), getCellText(xCR->getCellByPosition(2, 1))); + CPPUNIT_ASSERT_EQUAL(OUString("2a"), getCellText(xCR->getCellByPosition(3, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("2b"), getCellText(xCR->getCellByPosition(3, 1))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(4, 0))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(4, 1))); + + // remove one column at position one + xTC->removeByIndex(1, 1); + CPPUNIT_ASSERT_EQUAL(OUString("0a"), getCellText(xCR->getCellByPosition(0, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("0b"), getCellText(xCR->getCellByPosition(0, 1))); + CPPUNIT_ASSERT_EQUAL(OUString("1a"), getCellText(xCR->getCellByPosition(1, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("1b"), getCellText(xCR->getCellByPosition(1, 1))); + CPPUNIT_ASSERT_EQUAL(OUString("2a"), getCellText(xCR->getCellByPosition(2, 0))); + CPPUNIT_ASSERT_EQUAL(OUString("2b"), getCellText(xCR->getCellByPosition(2, 1))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(3, 0))); + CPPUNIT_ASSERT_EQUAL(OUString(""), getCellText(xCR->getCellByPosition(3, 1))); +} + +void XTableColumns::testRemoveByIndexWithNegativeIndex() +{ + uno::Reference<table::XTableColumns> xTC(init(), uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_THROW(xTC->removeByIndex(-1, 1), uno::RuntimeException); +} + +void XTableColumns::testRemoveByIndexWithNoColumn() +{ + uno::Reference<table::XTableColumns> xTC(init(), uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT_THROW(xTC->removeByIndex(0, 0), uno::RuntimeException); +} + +void XTableColumns::testRemoveByIndexWithOutOfBoundIndex() +{ + uno::Reference<table::XTableColumns> xTC(init(), uno::UNO_QUERY_THROW); + + CPPUNIT_ASSERT_THROW(xTC->removeByIndex(xTC->getCount(), 1), uno::RuntimeException); +} + +OUString XTableColumns::getCellText(const uno::Reference<table::XCell>& r_xCell) +{ + uno::Reference<text::XSimpleText> xST(r_xCell, uno::UNO_QUERY_THROW); + return xST->getString(); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/table/xtablerows.cxx b/test/source/table/xtablerows.cxx new file mode 100644 index 000000000..c241b2bb8 --- /dev/null +++ b/test/source/table/xtablerows.cxx @@ -0,0 +1,55 @@ +/* -*- 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 <test/table/xtablerows.hxx> + +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/table/XTableRows.hpp> +#include <com/sun/star/uno/RuntimeException.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XTableRows::testInsertByIndex() +{ + uno::Reference<table::XCellRange> xCellRange(getXCellRange(), uno::UNO_QUERY_THROW); + xCellRange->getCellByPosition(0, 0)->setValue(17); + xCellRange->getCellByPosition(0, 1)->setValue(15); + + uno::Reference<table::XTableRows> xTableRows(init(), uno::UNO_QUERY_THROW); + xTableRows->removeByIndex(0, 1); + + xTableRows->insertByIndex(0, 1); + CPPUNIT_ASSERT_DOUBLES_EQUAL(xCellRange->getCellByPosition(0, 1)->getValue(), 15.0, 0.1); + + CPPUNIT_ASSERT_THROW(xTableRows->insertByIndex(-1, 1), uno::RuntimeException); +} + +void XTableRows::testRemoveByIndex() +{ + uno::Reference<table::XCellRange> xCellRange(getXCellRange(), uno::UNO_QUERY_THROW); + xCellRange->getCellByPosition(0, 0)->setValue(17); + xCellRange->getCellByPosition(0, 1)->setValue(15); + + uno::Reference<table::XTableRows> xTableRows(init(), uno::UNO_QUERY_THROW); + xTableRows->removeByIndex(0, 1); + CPPUNIT_ASSERT_DOUBLES_EQUAL(xCellRange->getCellByPosition(0, 0)->getValue(), 15.0, 0.1); + + CPPUNIT_ASSERT_THROW(xTableRows->removeByIndex(-1, 1), uno::RuntimeException); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/text/baseindex.cxx b/test/source/text/baseindex.cxx new file mode 100644 index 000000000..683a24221 --- /dev/null +++ b/test/source/text/baseindex.cxx @@ -0,0 +1,151 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <cppunit/TestAssert.h> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/graphic/XGraphic.hpp> +#include <com/sun/star/text/XTextColumns.hpp> +#include <com/sun/star/text/XTextSection.hpp> + +#include <vcl/BitmapTools.hxx> +#include <vcl/pngwrite.hxx> +#include <unotools/tempfile.hxx> +#include <tools/stream.hxx> + +#include <test/unoapi_property_testers.hxx> +#include <test/text/baseindex.hxx> + +namespace +{ +BitmapEx createExampleBitmap() +{ + vcl::bitmap::RawBitmap aRawBitmap(Size(4, 4), 24); + aRawBitmap.SetPixel(0, 0, COL_LIGHTBLUE); + aRawBitmap.SetPixel(0, 1, COL_LIGHTGREEN); + aRawBitmap.SetPixel(1, 0, COL_LIGHTRED); + aRawBitmap.SetPixel(1, 1, COL_LIGHTMAGENTA); + return vcl::bitmap::CreateFromData(std::move(aRawBitmap)); +} + +void writerFileWithBitmap(OUString const& rURL) +{ + BitmapEx aBitmapEx = createExampleBitmap(); + SvFileStream aFileStream(rURL, StreamMode::READ | StreamMode::WRITE); + vcl::PNGWriter aWriter(aBitmapEx); + aWriter.Write(aFileStream); + aFileStream.Seek(STREAM_SEEK_TO_BEGIN); + aFileStream.Close(); +} +} + +namespace apitest +{ +BaseIndex::~BaseIndex() {} + +void BaseIndex::testBaseIndexProperties() +{ + css::uno::Reference<css::beans::XPropertySet> xBaseIndex(init(), css::uno::UNO_QUERY_THROW); + testStringProperty(xBaseIndex, "Title", "Value"); + testBooleanProperty(xBaseIndex, "IsProtected"); + + testStringProperty(xBaseIndex, "ParaStyleHeading", "Value"); + testStringProperty(xBaseIndex, "ParaStyleLevel1", "Value"); + testStringOptionalProperty(xBaseIndex, "ParaStyleLevel2"); + testStringOptionalProperty(xBaseIndex, "ParaStyleLevel3"); + testStringOptionalProperty(xBaseIndex, "ParaStyleLevel4"); + testStringOptionalProperty(xBaseIndex, "ParaStyleLevel5"); + testStringOptionalProperty(xBaseIndex, "ParaStyleLevel6"); + testStringOptionalProperty(xBaseIndex, "ParaStyleLevel7"); + testStringOptionalProperty(xBaseIndex, "ParaStyleLevel8"); + testStringOptionalProperty(xBaseIndex, "ParaStyleLevel9"); + testStringOptionalProperty(xBaseIndex, "ParaStyleLevel10"); + testStringOptionalProperty(xBaseIndex, "ParaStyleSeparator"); + + // [property] XTextColumns TextColumns; + { + OUString name = "TextColumns"; + + css::uno::Reference<css::text::XTextColumns> xGetTextColumns; + CPPUNIT_ASSERT(xBaseIndex->getPropertyValue(name) >>= xGetTextColumns); + + xGetTextColumns->setColumnCount(xGetTextColumns->getColumnCount() + 1); + xBaseIndex->setPropertyValue(name, css::uno::Any(xGetTextColumns)); + + css::uno::Reference<css::text::XTextColumns> xSetTextColumns; + CPPUNIT_ASSERT(xBaseIndex->getPropertyValue(name) >>= xSetTextColumns); + + //CPPUNIT_ASSERT_EQUAL(xGetTextColumns->getColumnCount(), xSetTextColumns->getColumnCount()); + } + + // [property] com::sun::star::graphic::XGraphic BackGraphic; + // [property] string BackGraphicURL; + { + OUString name = "BackGraphicURL"; + bool bOK = false; + try + { + xBaseIndex->getPropertyValue(name); + } + catch (css::uno::RuntimeException const& /*ex*/) + { + bOK = true; + } + // BackGraphicURL is "set-only" attribute + CPPUNIT_ASSERT_MESSAGE("Expected RuntimeException wasn't thrown", bOK); + + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + writerFileWithBitmap(aTempFile.GetURL()); + + css::uno::Reference<css::graphic::XGraphic> xGraphic; + CPPUNIT_ASSERT(xBaseIndex->getPropertyValue("BackGraphic") >>= xGraphic); + CPPUNIT_ASSERT(!xGraphic.is()); + + xBaseIndex->setPropertyValue(name, css::uno::Any(aTempFile.GetURL())); + + CPPUNIT_ASSERT(xBaseIndex->getPropertyValue("BackGraphic") >>= xGraphic); + CPPUNIT_ASSERT(xGraphic.is()); + } + + testStringProperty(xBaseIndex, "BackGraphicFilter", "Value"); + + // [property] com::sun::star::style::GraphicLocation BackGraphicLocation; + + testColorProperty(xBaseIndex, "BackColor"); + testBooleanProperty(xBaseIndex, "BackTransparent"); + + // [optional, property] com::sun::star::container::XIndexReplace LevelFormat; + + testBooleanOptionalProperty(xBaseIndex, "CreateFromChapter"); + + // [property] com::sun::star::text::XTextSection ContentSection; + { + OUString name = "ContentSection"; + + css::uno::Reference<css::text::XTextSection> xGetTextSection; + CPPUNIT_ASSERT_MESSAGE(name.toUtf8().getStr(), + xBaseIndex->getPropertyValue(name) >>= xGetTextSection); + CPPUNIT_ASSERT_EQUAL_MESSAGE(name.toUtf8().getStr(), OUString(""), + xGetTextSection->getAnchor()->getString()); + } + + // [property] com::sun::star::text::XTextSection HeaderSection; + { + OUString name = "HeaderSection"; + + css::uno::Reference<css::text::XTextSection> xGetTextSection; + if (xBaseIndex->getPropertyValue(name).hasValue()) + CPPUNIT_ASSERT_MESSAGE(name.toUtf8().getStr(), + xBaseIndex->getPropertyValue(name) >>= xGetTextSection); + } +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/text/textcontent.cxx b/test/source/text/textcontent.cxx new file mode 100644 index 000000000..61990d869 --- /dev/null +++ b/test/source/text/textcontent.cxx @@ -0,0 +1,68 @@ +/* -*- 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 <test/text/textcontent.hxx> + +#include <com/sun/star/text/TextContentAnchorType.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void TextContent::testTextContentProperties() +{ + uno::Reference<beans::XPropertySet> xPS(init(), uno::UNO_QUERY_THROW); + + text::TextContentAnchorType aExpectedTCAT; + CPPUNIT_ASSERT(xPS->getPropertyValue("AnchorType") >>= aExpectedTCAT); + CPPUNIT_ASSERT_EQUAL(m_aExpectedTCAT, aExpectedTCAT); + + try + { + xPS->setPropertyValue("AnchorType", uno::Any(m_aNewTCAT)); + text::TextContentAnchorType aNewTCAT; + CPPUNIT_ASSERT(xPS->getPropertyValue("AnchorType") >>= aNewTCAT); + CPPUNIT_ASSERT_EQUAL(m_aNewTCAT, aNewTCAT); + } + catch (const beans::UnknownPropertyException& /* ex */) + { + // ignore if property is optional + } + + uno::Sequence<text::TextContentAnchorType> aAnchorTypes; + CPPUNIT_ASSERT(xPS->getPropertyValue("AnchorTypes") >>= aAnchorTypes); + CPPUNIT_ASSERT(aAnchorTypes.hasElements()); + + text::WrapTextMode aExpectedWTM; + CPPUNIT_ASSERT(xPS->getPropertyValue("TextWrap") >>= aExpectedWTM); + CPPUNIT_ASSERT_EQUAL(m_aExpectedWTM, aExpectedWTM); + + try + { + xPS->setPropertyValue("TextWrap", uno::Any(m_aNewWTM)); + text::WrapTextMode aNewWTM; + CPPUNIT_ASSERT(xPS->getPropertyValue("TextWrap") >>= aNewWTM); + CPPUNIT_ASSERT_EQUAL(m_aNewWTM, aNewWTM); + } + catch (const beans::UnknownPropertyException& /* ex */) + { + // ignore if property is optional + } +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/text/textdocumentindex.cxx b/test/source/text/textdocumentindex.cxx new file mode 100644 index 000000000..67f161cf3 --- /dev/null +++ b/test/source/text/textdocumentindex.cxx @@ -0,0 +1,36 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <com/sun/star/beans/XPropertySet.hpp> + +#include <test/unoapi_property_testers.hxx> +#include <test/text/textdocumentindex.hxx> + +namespace apitest +{ +TextDocumentIndex::~TextDocumentIndex() {} + +void TextDocumentIndex::testDocumentIndexProperties() +{ + css::uno::Reference<css::beans::XPropertySet> xDocumentIndex(init(), css::uno::UNO_QUERY_THROW); + + testBooleanProperty(xDocumentIndex, "UseAlphabeticalSeparators"); + testBooleanProperty(xDocumentIndex, "UseKeyAsEntry"); + testBooleanProperty(xDocumentIndex, "UseCombinedEntries"); + testBooleanProperty(xDocumentIndex, "IsCaseSensitive"); + testBooleanProperty(xDocumentIndex, "UsePP"); + testBooleanProperty(xDocumentIndex, "UseDash"); + testBooleanProperty(xDocumentIndex, "UseUpperCase"); + testStringOptionalProperty(xDocumentIndex, "MainEntryCharacterStyleName"); + // [readonly, property] sequence <com::sun::star::text::XDocumentIndexMark> DocumentIndexMarks; + // [property] com::sun::star::lang::Locale Locale; + testStringProperty(xDocumentIndex, "SortAlgorithm", "Value"); +} +} +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/text/textdocumentsettings.cxx b/test/source/text/textdocumentsettings.cxx new file mode 100644 index 000000000..9ef0518b0 --- /dev/null +++ b/test/source/text/textdocumentsettings.cxx @@ -0,0 +1,42 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/text/textdocumentsettings.hxx> +#include <test/unoapi_property_testers.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/uno/Reference.hxx> + +using namespace css::uno; + +namespace apitest +{ +TextDocumentSettings::~TextDocumentSettings() {} + +void TextDocumentSettings::testDocumentSettingsProperties() +{ + css::uno::Reference<css::beans::XPropertySet> xDocumentSettings(init(), + css::uno::UNO_QUERY_THROW); + + testBooleanOptionalProperty(xDocumentSettings, "ChartAutoUpdate"); + testBooleanOptionalProperty(xDocumentSettings, "AddParaTableSpacing"); + testBooleanOptionalProperty(xDocumentSettings, "AddParaTableSpacingAtStart"); + testBooleanOptionalProperty(xDocumentSettings, "AlignTabStopPosition"); + testBooleanOptionalProperty(xDocumentSettings, "SaveGlobalDocumentLinks"); + testBooleanOptionalProperty(xDocumentSettings, "IsLabelDocument"); + testBooleanOptionalProperty(xDocumentSettings, "UseFormerLineSpacing"); + testBooleanOptionalProperty(xDocumentSettings, "AddParaSpacingToTableCells"); + testBooleanOptionalProperty(xDocumentSettings, "UseFormerObjectPositioning"); + testBooleanOptionalProperty(xDocumentSettings, "ConsiderTextWrapOnObjPos"); + testBooleanOptionalProperty(xDocumentSettings, "MathBaselineAlignment"); +} + +} // end namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/text/textprintersettings.cxx b/test/source/text/textprintersettings.cxx new file mode 100644 index 000000000..b28c65241 --- /dev/null +++ b/test/source/text/textprintersettings.cxx @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <com/sun/star/beans/XPropertySet.hpp> + +#include <test/unoapi_property_testers.hxx> +#include <test/text/textprintersettings.hxx> + +namespace apitest +{ +TextPrinterSettings::~TextPrinterSettings() {} +void TextPrinterSettings::testPrinterSettingsProperties() +{ + css::uno::Reference<css::beans::XPropertySet> xPrinterSettings(init(), + css::uno::UNO_QUERY_THROW); + + testBooleanProperty(xPrinterSettings, "PrintGraphics"); + testBooleanProperty(xPrinterSettings, "PrintTables"); + testBooleanProperty(xPrinterSettings, "PrintDrawings"); + testBooleanProperty(xPrinterSettings, "PrintLeftPages"); + testBooleanProperty(xPrinterSettings, "PrintRightPages"); + testBooleanProperty(xPrinterSettings, "PrintControls"); + testBooleanProperty(xPrinterSettings, "PrintReversed"); + testBooleanProperty(xPrinterSettings, "PrintControls"); + testStringProperty(xPrinterSettings, "PrintFaxName", "FaxName"); + testBooleanProperty(xPrinterSettings, "PrintProspect"); + testBooleanProperty(xPrinterSettings, "PrintPageBackground"); + testBooleanProperty(xPrinterSettings, "PrintBlackFonts"); + testBooleanOptionalProperty(xPrinterSettings, "PrintEmptyPages"); +} +} // end namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/text/textsettings.cxx b/test/source/text/textsettings.cxx new file mode 100644 index 000000000..112fc939d --- /dev/null +++ b/test/source/text/textsettings.cxx @@ -0,0 +1,153 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <cppunit/TestAssert.h> + +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/i18n/XForbiddenCharacters.hpp> + +#include <test/unoapi_property_testers.hxx> +#include <test/text/textsettings.hxx> + +namespace +{ +bool extstsProperty(css::uno::Reference<css::beans::XPropertySet> const& rxPropertySet, + OUString const& rPropertyName) +{ + css::uno::Reference<css::beans::XPropertySetInfo> xPropertySetInfo( + rxPropertySet->getPropertySetInfo()); + return xPropertySetInfo->hasPropertyByName(rPropertyName); +} + +bool isPropertyReadOnly(css::uno::Reference<css::beans::XPropertySet> const& rxPropertySet, + std::u16string_view rPropertyName) +{ + css::uno::Reference<css::beans::XPropertySetInfo> xPropertySetInfo( + rxPropertySet->getPropertySetInfo()); + const css::uno::Sequence<css::beans::Property> xProperties = xPropertySetInfo->getProperties(); + + for (auto const& rProperty : xProperties) + { + if (rProperty.Name == rPropertyName) + return (rProperty.Attributes & com::sun::star::beans::PropertyAttribute::READONLY) != 0; + } + + return false; +} +// [property] string PrinterName; +void testPrinterName(css::uno::Reference<css::beans::XPropertySet> const& rxSettings) +{ + static const OUStringLiteral rPropertyName(u"PrinterName"); + + if (!extstsProperty(rxSettings, rPropertyName)) + return; // Property is sometimes not set - bug? it is not defined as optional + + OUString aPrinterName_Get; + + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue", + rxSettings->getPropertyValue(rPropertyName) >>= aPrinterName_Get); + + OUString aPrinterName_Set; + css::uno::Any aNewValue; + aNewValue <<= aPrinterName_Get; + rxSettings->setPropertyValue(rPropertyName, aNewValue); + + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue", + rxSettings->getPropertyValue(rPropertyName) >>= aPrinterName_Set); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue", aPrinterName_Get, aPrinterName_Set); +} + +// [optional, property] short PrinterIndependentLayout; +void testPrinterIndependentLayout(css::uno::Reference<css::beans::XPropertySet> const& rxSettings) +{ + static const OUStringLiteral rPropertyName(u"PrinterIndependentLayout"); + + if (!extstsProperty(rxSettings, rPropertyName)) + return; // Property is optional + + sal_Int16 aValue_Get = {}; + + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue", + rxSettings->getPropertyValue(rPropertyName) >>= aValue_Get); + + sal_Int16 aValue_New; + aValue_New = (aValue_Get == 1 ? 3 : 1); + rxSettings->setPropertyValue(rPropertyName, css::uno::Any(aValue_New)); + + sal_Int16 aValue_Set; + + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue", + rxSettings->getPropertyValue(rPropertyName) >>= aValue_Set); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue", aValue_New, aValue_Set); +} + +// [optional, property] com::sun::star::i18n::XForbiddenCharacters ForbiddenCharacters; +void testForbiddenCharacters(css::uno::Reference<css::beans::XPropertySet> const& rxSettings) +{ + static const OUStringLiteral rPropertyName(u"ForbiddenCharacters"); + + if (!extstsProperty(rxSettings, rPropertyName)) + return; // Property is optional + + CPPUNIT_ASSERT_MESSAGE("Property is read-only but shouldn't be", + !isPropertyReadOnly(rxSettings, rPropertyName)); + + css::uno::Reference<css::i18n::XForbiddenCharacters> aValue_Get; + + CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue", + rxSettings->getPropertyValue(rPropertyName) >>= aValue_Get); + CPPUNIT_ASSERT_MESSAGE("Empty reference to XForbiddenCharacters", aValue_Get.is()); +} +} + +namespace apitest +{ +TextSettings::~TextSettings() {} +void TextSettings::testSettingsProperties() +{ + css::uno::Reference<css::beans::XPropertySet> xSettings(init(), css::uno::UNO_QUERY_THROW); + + testForbiddenCharacters(xSettings); + //testShortOptionalProperty(xSettings, "LinkUpdateMode"); + testPrinterName(xSettings); + // [property] sequence< byte > PrinterSetup; + testBooleanOptionalProperty(xSettings, "IsKernAsianPunctuation"); + //testShortOptionalProperty(xSettings, "CharacterCompressionType"); + testBooleanOptionalProperty(xSettings, "ApplyUserData"); + testBooleanOptionalProperty(xSettings, "SaveVersionOnClose"); + testBooleanOptionalProperty(xSettings, "UpdateFromTemplate"); + testBooleanOptionalProperty(xSettings, "FieldAutoUpdate"); + testStringOptionalProperty(xSettings, "CurrentDatabaseDataSource"); + testStringOptionalProperty(xSettings, "CurrentDatabaseCommand"); + testLongOptionalProperty(xSettings, "CurrentDatabaseCommandType"); + testLongOptionalProperty(xSettings, "DefaultTabStop"); + testBooleanOptionalProperty(xSettings, "IsPrintBooklet"); + testBooleanOptionalProperty(xSettings, "IsPrintBookletFront"); + testBooleanOptionalProperty(xSettings, "IsPrintBookletBack"); + testLongOptionalProperty(xSettings, "PrintQuality"); + testStringOptionalProperty(xSettings, "ColorTableURL"); + testStringOptionalProperty(xSettings, "DashTableURL"); + testStringOptionalProperty(xSettings, "LineEndTableURL"); + testStringOptionalProperty(xSettings, "HatchTableURL"); + testStringOptionalProperty(xSettings, "GradientTableURL"); + testStringOptionalProperty(xSettings, "BitmapTableURL"); + testBooleanOptionalProperty(xSettings, "AutoCalculate"); + testPrinterIndependentLayout(xSettings); + testBooleanOptionalProperty(xSettings, "AddExternalLeading"); + testBooleanOptionalProperty(xSettings, "EmbedFonts"); + testBooleanOptionalProperty(xSettings, "EmbedSystemFonts"); + testBooleanOptionalProperty(xSettings, "EmbedOnlyUsedFonts"); + testBooleanOptionalProperty(xSettings, "EmbedLatinScriptFonts"); + testBooleanOptionalProperty(xSettings, "EmbedAsianScriptFonts"); + testBooleanOptionalProperty(xSettings, "EmbedComplexScriptFonts"); +} +} // end namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/text/xdocumentindex.cxx b/test/source/text/xdocumentindex.cxx new file mode 100644 index 000000000..9f9ad73c8 --- /dev/null +++ b/test/source/text/xdocumentindex.cxx @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <cppunit/TestAssert.h> + +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XDocumentIndex.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +#include <test/text/xdocumentindex.hxx> + +namespace apitest +{ +XDocumentIndex::~XDocumentIndex() {} +/** + * Gets the document from relation and insert a new index mark. + * Then it stores the text content of document index before + * update and after.<p> + * + * Has <b> OK </b> status if index content is changed and + * new index contains index mark inserted. <p> + */ +void XDocumentIndex::testUpdate() +{ + css::uno::Reference<css::text::XDocumentIndex> xDocumentIndex(init(), + css::uno::UNO_QUERY_THROW); + + bool bOK = true; + try + { + auto xText = getTextDocument()->getText(); + auto xTextRange = xText->getEnd(); + xTextRange->setString("IndexMark"); + css::uno::Reference<css::lang::XMultiServiceFactory> xFactory(getTextDocument(), + css::uno::UNO_QUERY_THROW); + css::uno::Reference<css::text::XTextContent> xTextContentMark( + xFactory->createInstance("com.sun.star.text.DocumentIndexMark"), + css::uno::UNO_QUERY_THROW); + xText->insertTextContent(xTextRange, xTextContentMark, true); + } + catch (css::uno::Exception /*exception*/) + { + bOK = false; + } + + CPPUNIT_ASSERT_MESSAGE("Couldn't create the document index mark", bOK); + + OUString sContentBefore = xDocumentIndex->getAnchor()->getString(); + xDocumentIndex->update(); + OUString sContentAfter = xDocumentIndex->getAnchor()->getString(); + + CPPUNIT_ASSERT_MESSAGE("Before and after shouldn't be equal", sContentBefore != sContentAfter); + CPPUNIT_ASSERT_MESSAGE("Content after should contain string 'IndexMark'", + sContentAfter.indexOf("IndexMark") >= 0); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/text/xsimpletext.cxx b/test/source/text/xsimpletext.cxx new file mode 100644 index 000000000..23ea6c785 --- /dev/null +++ b/test/source/text/xsimpletext.cxx @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/text/xsimpletext.hxx> +#include <com/sun/star/text/XTextCursor.hpp> +#include <com/sun/star/text/ControlCharacter.hpp> +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XSimpleText::testCreateTextCursor() +{ + uno::Reference<text::XSimpleText> xSimpleText(init(), UNO_QUERY_THROW); + + CPPUNIT_ASSERT(xSimpleText->createTextCursor()); +} + +void XSimpleText::testCreateTextCursorByRange() +{ + uno::Reference<text::XSimpleText> xSimpleText(init(), UNO_QUERY_THROW); + uno::Reference<text::XTextCursor> xCursor(xSimpleText->createTextCursor(), UNO_SET_THROW); + + xCursor->gotoStart(false); + + CPPUNIT_ASSERT(xSimpleText->createTextCursorByRange(xCursor)); +} + +void XSimpleText::testInsertString() +{ + uno::Reference<text::XSimpleText> xSimpleText(init(), UNO_QUERY_THROW); + uno::Reference<text::XTextRange> xCursor(xSimpleText->createTextCursor(), UNO_QUERY_THROW); + ::rtl::OUString sString = "TestString"; + + xSimpleText->insertString(xCursor, sString, false); + ::rtl::OUString gString = xSimpleText->getText()->getString(); + + CPPUNIT_ASSERT(!gString.isEmpty()); + CPPUNIT_ASSERT(gString.indexOf(sString) >= 0); +} + +void XSimpleText::testInsertControlCharacter() +{ + bool bOK = true; + + uno::Reference<text::XSimpleText> xSimpleText(init(), UNO_QUERY_THROW); + uno::Reference<text::XTextRange> xCursor(xSimpleText->createTextCursor(), UNO_QUERY_THROW); + + try + { + xSimpleText->insertControlCharacter(xCursor, text::ControlCharacter::PARAGRAPH_BREAK, + false); + xSimpleText->insertControlCharacter(xCursor, text::ControlCharacter::LINE_BREAK, false); + xSimpleText->insertString(xSimpleText->createTextCursor(), "newLine", false); + } + catch (const lang::IllegalArgumentException&) + { + bOK = false; + } + + OUString gString = xSimpleText->getString(); + CPPUNIT_ASSERT(bOK); + CPPUNIT_ASSERT(gString.indexOf("\n") > -1); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/text/xtext.cxx b/test/source/text/xtext.cxx new file mode 100644 index 000000000..6f6274156 --- /dev/null +++ b/test/source/text/xtext.cxx @@ -0,0 +1,29 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/text/xtext.hxx> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +XText::~XText() {} + +void XText::testInsertRemoveTextContent() +{ + uno::Reference<text::XText> xText(init(), UNO_QUERY_THROW); + uno::Reference<text::XTextRange> xCursor(xText->createTextCursor(), UNO_QUERY_THROW); + + xText->insertTextContent(xCursor, getTextContent(), false); + xText->removeTextContent(getTextContent()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/text/xtextcontent.cxx b/test/source/text/xtextcontent.cxx new file mode 100644 index 000000000..762584e88 --- /dev/null +++ b/test/source/text/xtextcontent.cxx @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/text/xtextcontent.hxx> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/XTextRange.hpp> +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <cppunit/TestAssert.h> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XTextContent::testGetAnchor() +{ + uno::Reference<text::XTextContent> xTextContent(init(), UNO_QUERY_THROW); + uno::Reference<uno::XInterface> xAnchor(xTextContent->getAnchor()); + CPPUNIT_ASSERT(xAnchor.is()); +} + +void XTextContent::testAttach() +{ + uno::Reference<text::XTextContent> xTextContent(init(), UNO_QUERY_THROW); + + uno::Reference<text::XTextContent> xContent(getTextContent(), UNO_SET_THROW); + uno::Reference<text::XTextRange> xRange(getTextRange(), UNO_SET_THROW); + + try + { + if (xContent.is()) + xContent->attach(xRange); + else + xTextContent->attach(xRange); + } + catch (const lang::IllegalArgumentException&) + { + bool bAttachSupported = isAttachSupported(); + if (bAttachSupported) + CPPUNIT_ASSERT(false); + } + catch (const RuntimeException&) + { + bool bAttachSupported = isAttachSupported(); + if (bAttachSupported) + CPPUNIT_ASSERT(false); + } +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/text/xtextfield.cxx b/test/source/text/xtextfield.cxx new file mode 100644 index 000000000..ceefcceed --- /dev/null +++ b/test/source/text/xtextfield.cxx @@ -0,0 +1,43 @@ +/* -*- 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 <test/text/xtextfield.hxx> + +#include <com/sun/star/text/XTextField.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void XTextField::testGetPresentation() +{ + uno::Reference<text::XTextField> xTextField(init(), uno::UNO_QUERY_THROW); + + OUString aString = xTextField->getPresentation(true); + CPPUNIT_ASSERT(!aString.isEmpty()); + aString = xTextField->getPresentation(false); + CPPUNIT_ASSERT(!aString.isEmpty()); +} + +void XTextField::testGetPresentationEmptyString() +{ + uno::Reference<text::XTextField> xTextField(init(), uno::UNO_QUERY_THROW); + + OUString aString = xTextField->getPresentation(true); + CPPUNIT_ASSERT(aString.isEmpty()); + aString = xTextField->getPresentation(false); + CPPUNIT_ASSERT(aString.isEmpty()); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/text/xtextrange.cxx b/test/source/text/xtextrange.cxx new file mode 100644 index 000000000..64428b476 --- /dev/null +++ b/test/source/text/xtextrange.cxx @@ -0,0 +1,61 @@ +/* -*- 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 <test/text/xtextrange.hxx> + +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextRange.hpp> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void XTextRange::testGetEnd() +{ + uno::Reference<text::XTextRange> xTextRange(init(), uno::UNO_QUERY_THROW); + + xTextRange->setString("UnitTest"); + uno::Reference<text::XTextRange> xTR_end(xTextRange->getEnd(), uno::UNO_SET_THROW); + xTR_end->setString("End"); + + CPPUNIT_ASSERT(xTextRange->getText()->getString().endsWith("End")); +} + +void XTextRange::testGetSetString() +{ + uno::Reference<text::XTextRange> xTextRange(init(), uno::UNO_QUERY_THROW); + + xTextRange->setString("UnitTest"); + CPPUNIT_ASSERT_EQUAL(OUString("UnitTest"), xTextRange->getString()); +} + +void XTextRange::testGetStart() +{ + uno::Reference<text::XTextRange> xTextRange(init(), uno::UNO_QUERY_THROW); + + xTextRange->setString("UnitTest"); + uno::Reference<text::XTextRange> xTR_start(xTextRange->getStart(), uno::UNO_SET_THROW); + xTR_start->setString("Start"); + + CPPUNIT_ASSERT(xTextRange->getText()->getString().startsWith("Start")); +} + +void XTextRange::testGetText() +{ + uno::Reference<text::XTextRange> xTextRange(init(), uno::UNO_QUERY_THROW); + + xTextRange->setString("UnitTest"); + uno::Reference<text::XText> xText(xTextRange->getText(), uno::UNO_SET_THROW); + CPPUNIT_ASSERT_EQUAL(OUString("UnitTest"), xTextRange->getString()); +} +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/unoapi_property_testers.cxx b/test/source/unoapi_property_testers.cxx new file mode 100644 index 000000000..f261c4ce3 --- /dev/null +++ b/test/source/unoapi_property_testers.cxx @@ -0,0 +1,288 @@ +/* -*- 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 <test/unoapi_property_testers.hxx> + +#include <com/sun/star/uno/Any.hxx> +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void testBooleanProperty(uno::Reference<beans::XPropertySet> const& xPropertySet, + const OUString& name) +{ + uno::Any aNewValue; + + bool bPropertyGet = false; + bool bPropertySet = false; + + OString msgGet + = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= bPropertyGet); + + aNewValue <<= !bPropertyGet; + xPropertySet->setPropertyValue(name, aNewValue); + CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= bPropertySet); + OString msgSet + = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), !bPropertyGet, bPropertySet); +} + +void testBooleanOptionalProperty(uno::Reference<beans::XPropertySet> const& xPropertySet, + const OUString& rName) +{ + try + { + testBooleanProperty(xPropertySet, rName); + } + catch (const css::beans::UnknownPropertyException& /*ex*/) + { + // ignore if the property is unknown as it is optional + } +} + +void testBooleanReadonlyProperty(uno::Reference<beans::XPropertySet> const& xPropertySet, + const OUString& name) +{ + uno::Any aNewValue; + + bool bPropertyGet = false; + bool bPropertySet = false; + + OString msgGet + = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= bPropertyGet); + + aNewValue <<= !bPropertyGet; + xPropertySet->setPropertyValue(name, aNewValue); + CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= bPropertySet); + OString msgSet = "Able to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), bPropertyGet, bPropertySet); +} + +void testDoubleProperty(uno::Reference<beans::XPropertySet> const& xPropertySet, + const OUString& name, const double& dValue) +{ + uno::Any aNewValue; + + double dPropertyGet; + double dPropertySet; + + OString msgGet + = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= dPropertyGet); + + aNewValue <<= dValue; + xPropertySet->setPropertyValue(name, aNewValue); + CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= dPropertySet); + OString msgSet + = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(msgSet.getStr(), dValue, dPropertySet, 0.5); +} + +void testDoubleReadonlyProperty(uno::Reference<beans::XPropertySet> const& xPropertySet, + const OUString& name, const double& dValue) +{ + uno::Any aNewValue; + + double dPropertyGet; + double dPropertySet; + + OString msgGet + = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= dPropertyGet); + + aNewValue <<= dValue; + xPropertySet->setPropertyValue(name, aNewValue); + CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= dPropertySet); + OString msgSet = "Able to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(msgSet.getStr(), dPropertyGet, dPropertySet, 0.5); +} + +void testLongProperty(uno::Reference<beans::XPropertySet> const& xPropertySet, const OUString& name, + const sal_Int32& nValue) +{ + uno::Any aNewValue; + + sal_Int32 nPropertyGet; + sal_Int32 nPropertySet; + + OString msgGet + = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= nPropertyGet); + + aNewValue <<= nValue; + xPropertySet->setPropertyValue(name, aNewValue); + CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= nPropertySet); + OString msgSet + = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), nValue, nPropertySet); +} + +void testLongOptionalProperty(uno::Reference<beans::XPropertySet> const& xPropertySet, + const OUString& rName, const sal_Int32& rValue) +{ + try + { + testLongProperty(xPropertySet, rName, rValue); + } + catch (const css::beans::UnknownPropertyException& /*ex*/) + { + // ignore if the property is unknown as it is optional + } +} + +void testLongReadonlyProperty(uno::Reference<beans::XPropertySet> const& xPropertySet, + const OUString& name, const sal_Int32& nValue) +{ + uno::Any aNewValue; + + sal_Int32 nPropertyGet; + sal_Int32 nPropertySet; + + OString msgGet + = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= nPropertyGet); + + aNewValue <<= nValue; + xPropertySet->setPropertyValue(name, aNewValue); + CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= nPropertySet); + OString msgSet = "Able to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), nPropertyGet, nPropertySet); +} + +void testShortProperty(uno::Reference<beans::XPropertySet> const& xPropertySet, + const OUString& name, const sal_Int16& nValue) +{ + uno::Any aNewValue; + + sal_Int16 nPropertyGet; + sal_Int16 nPropertySet; + + OString msgGet + = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= nPropertyGet); + + aNewValue <<= nValue; + xPropertySet->setPropertyValue(name, aNewValue); + CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= nPropertySet); + OString msgSet + = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), nValue, nPropertySet); +} + +void testShortOptionalProperty(uno::Reference<beans::XPropertySet> const& xPropertySet, + const OUString& rName, const sal_Int16& rValue) +{ + try + { + testShortProperty(xPropertySet, rName, rValue); + } + catch (const css::beans::UnknownPropertyException& /*ex*/) + { + // ignore if the property is unknown as it is optional + } +} + +void testShortReadonlyProperty(uno::Reference<beans::XPropertySet> const& xPropertySet, + const OUString& name, const sal_Int16& nValue) +{ + uno::Any aNewValue; + + sal_Int16 nPropertyGet; + sal_Int16 nPropertySet; + + OString msgGet + = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= nPropertyGet); + + aNewValue <<= nValue; + xPropertySet->setPropertyValue(name, aNewValue); + CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= nPropertySet); + OString msgSet = "Able to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), nPropertyGet, nPropertySet); +} + +void testStringOptionalProperty(uno::Reference<beans::XPropertySet> const& xPropertySet, + const OUString& rName, const OUString& rValue) +{ + try + { + testStringProperty(xPropertySet, rName, rValue); + } + catch (const css::beans::UnknownPropertyException& /*ex*/) + { + // ignore if the property is unknown as it is optional + } +} + +void testStringProperty(uno::Reference<beans::XPropertySet> const& xPropertySet, + const OUString& name, const OUString& rValue) +{ + uno::Any aNewValue; + + OUString sPropertyGet; + OUString sPropertySet; + + OString msgGet + = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= sPropertyGet); + + aNewValue <<= rValue; + xPropertySet->setPropertyValue(name, aNewValue); + CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= sPropertySet); + OString msgSet + = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), rValue, sPropertySet); +} + +void testStringReadonlyProperty(uno::Reference<beans::XPropertySet> const& xPropertySet, + const OUString& name, const OUString& rValue) +{ + uno::Any aNewValue; + + OUString sPropertyGet; + OUString sPropertySet; + + OString msgGet + = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= sPropertyGet); + + aNewValue <<= rValue; + xPropertySet->setPropertyValue(name, aNewValue); + CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= sPropertySet); + OString msgSet = "Able to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), sPropertyGet, sPropertySet); +} + +void testColorProperty(uno::Reference<beans::XPropertySet> const& xPropertySet, + const OUString& name, const util::Color& rValue) +{ + uno::Any aNewValue; + + util::Color sPropertyGet; + util::Color sPropertySet; + + OString msgGet + = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= sPropertyGet); + + aNewValue <<= rValue; + xPropertySet->setPropertyValue(name, aNewValue); + CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= sPropertySet); + OString msgSet + = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), rValue, sPropertySet); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/unoapi_test.cxx b/test/source/unoapi_test.cxx new file mode 100644 index 000000000..50d0ff562 --- /dev/null +++ b/test/source/unoapi_test.cxx @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/unoapi_test.hxx> + +#include <com/sun/star/util/XCloseable.hpp> +#include <com/sun/star/frame/Desktop.hpp> +#include <comphelper/processfactory.hxx> + +using namespace css; +using namespace css::uno; + +UnoApiTest::UnoApiTest(const OUString& path) + : m_aBaseString(path) +{ +} + +void UnoApiTest::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop + = css::frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory())); + CPPUNIT_ASSERT_MESSAGE("no desktop!", mxDesktop.is()); +} + +void UnoApiTest::createFileURL(std::u16string_view aFileBase, OUString& rFilePath) +{ + rFilePath = m_directories.getSrcRootURL() + m_aBaseString + "/" + aFileBase; +} + +void UnoApiTest::closeDocument(uno::Reference<lang::XComponent> const& xDocument) +{ + uno::Reference<util::XCloseable> xCloseable(xDocument, UNO_QUERY_THROW); + xCloseable->close(false); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/util/searchdescriptor.cxx b/test/source/util/searchdescriptor.cxx new file mode 100644 index 000000000..d82994558 --- /dev/null +++ b/test/source/util/searchdescriptor.cxx @@ -0,0 +1,63 @@ +/* -*- 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 <test/util/searchdescriptor.hxx> +#include <test/unoapi_property_testers.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +using namespace css; + +namespace apitest +{ +void SearchDescriptor::testSearchDescriptorProperties() +{ + uno::Reference<beans::XPropertySet> xPS(init(), uno::UNO_QUERY_THROW); + + OUString aPropName; + + aPropName = "SearchBackwards"; + testBooleanProperty(xPS, aPropName); + + aPropName = "SearchCaseSensitive"; + testBooleanProperty(xPS, aPropName); + + aPropName = "SearchWords"; + testBooleanProperty(xPS, aPropName); + + aPropName = "SearchRegularExpression"; + testBooleanProperty(xPS, aPropName); + + aPropName = "SearchStyles"; + testBooleanProperty(xPS, aPropName); + + aPropName = "SearchSimilarity"; + testBooleanProperty(xPS, aPropName); + + aPropName = "SearchSimilarityRelax"; + testBooleanProperty(xPS, aPropName); + + aPropName = "SearchSimilarityRemove"; + testShortProperty(xPS, aPropName); + + aPropName = "SearchSimilarityAdd"; + testShortProperty(xPS, aPropName); + + aPropName = "SearchSimilarityExchange"; + testShortProperty(xPS, aPropName); + + aPropName = "SearchWildcard"; + testBooleanOptionalProperty(xPS, aPropName); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/util/xindent.cxx b/test/source/util/xindent.cxx new file mode 100644 index 000000000..6b15407f9 --- /dev/null +++ b/test/source/util/xindent.cxx @@ -0,0 +1,54 @@ +/* -*- 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 <test/util/xindent.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/util/XIndent.hpp> + +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XIndent::testIncrementIndent() +{ + uno::Reference<util::XIndent> xIndent(init(), UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPropertySet(xIndent, UNO_QUERY_THROW); + uno::Any aAny = xPropertySet->getPropertyValue("ParaIndent"); + sal_Int32 nOldValue = aAny.get<sal_Int32>(); + + xIndent->incrementIndent(); + + uno::Any aAny2 = xPropertySet->getPropertyValue("ParaIndent"); + sal_Int32 nNewValue = aAny2.get<sal_Int32>(); + CPPUNIT_ASSERT_MESSAGE("Successfully able to Increment Indent", nOldValue < nNewValue); +} +void XIndent::testDecrementIndent() +{ + uno::Reference<util::XIndent> xIndent(init(), UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPropertySet(xIndent, UNO_QUERY_THROW); + xIndent->incrementIndent(); + uno::Any aAny = xPropertySet->getPropertyValue("ParaIndent"); + sal_Int32 nOldValue = aAny.get<sal_Int32>(); + + xIndent->decrementIndent(); + + uno::Any aAny2 = xPropertySet->getPropertyValue("ParaIndent"); + sal_Int32 nNewValue = aAny2.get<sal_Int32>(); + CPPUNIT_ASSERT_MESSAGE("Successfully able to Decrement Indent", nOldValue > nNewValue); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/util/xmergeable.cxx b/test/source/util/xmergeable.cxx new file mode 100644 index 000000000..211b2b67f --- /dev/null +++ b/test/source/util/xmergeable.cxx @@ -0,0 +1,33 @@ +/* -*- 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 <test/util/xmergeable.hxx> + +#include <com/sun/star/util/XMergeable.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +void XMergeable::testGetIsMergedMerge() +{ + uno::Reference<util::XMergeable> xMergeable(init(), UNO_QUERY_THROW); + bool aIsMerged = xMergeable->getIsMerged(); + xMergeable->merge(!aIsMerged); + bool aIsMerged2 = xMergeable->getIsMerged(); + CPPUNIT_ASSERT_MESSAGE("Successfully able to Get is Merged and Merge", aIsMerged != aIsMerged2); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/util/xrefreshable.cxx b/test/source/util/xrefreshable.cxx new file mode 100644 index 000000000..5d145e5b2 --- /dev/null +++ b/test/source/util/xrefreshable.cxx @@ -0,0 +1,64 @@ +/* -*- 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 <test/util/xrefreshable.hxx> + +#include <com/sun/star/lang/EventObject.hpp> +#include <com/sun/star/util/XRefreshListener.hpp> +#include <com/sun/star/util/XRefreshable.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppuhelper/implbase.hxx> +#include <rtl/ref.hxx> + +#include <cppunit/TestAssert.h> + +using namespace com::sun::star; +using namespace com::sun::star::uno; + +namespace apitest +{ +namespace +{ +class MockedRefreshListener : public ::cppu::WeakImplHelper<util::XRefreshListener> +{ +public: + MockedRefreshListener() + : m_bListenerCalled(false) + { + } + + bool m_bListenerCalled; + virtual void SAL_CALL refreshed(const lang::EventObject& /* xEvent */) override + { + m_bListenerCalled = true; + } + virtual void SAL_CALL disposing(const lang::EventObject& /* xEventObj */) override {} +}; +} + +void XRefreshable::testRefreshListener() +{ + uno::Reference<util::XRefreshable> xRefreshable(init(), uno::UNO_QUERY_THROW); + + rtl::Reference<MockedRefreshListener> xListener = new MockedRefreshListener(); + xRefreshable->addRefreshListener(uno::Reference<util::XRefreshListener>(xListener)); + + xRefreshable->refresh(); + CPPUNIT_ASSERT(xListener->m_bListenerCalled); + + xListener->m_bListenerCalled = false; + xRefreshable->removeRefreshListener(uno::Reference<util::XRefreshListener>(xListener)); + xRefreshable->refresh(); + CPPUNIT_ASSERT(!xListener->m_bListenerCalled); +} + +} // namespace apitest +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/util/xreplaceable.cxx b/test/source/util/xreplaceable.cxx new file mode 100644 index 000000000..4e315c665 --- /dev/null +++ b/test/source/util/xreplaceable.cxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/util/xreplaceable.hxx> + +#include <com/sun/star/util/XReplaceable.hpp> +#include <com/sun/star/util/XReplaceDescriptor.hpp> +#include <com/sun/star/util/XSearchDescriptor.hpp> +#include <cppunit/TestAssert.h> + +#include <iostream> + +#include <test/callgrind.hxx> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XReplaceable::testCreateReplaceDescriptor() +{ + uno::Reference<util::XReplaceable> xReplaceable(init(), UNO_QUERY_THROW); + uno::Reference<util::XReplaceDescriptor> xReplaceDescr + = xReplaceable->createReplaceDescriptor(); + CPPUNIT_ASSERT(xReplaceDescr.is()); +} + +void XReplaceable::testReplaceAll() +{ + std::cout << "testReplaceAll" << std::endl; + uno::Reference<util::XReplaceable> xReplaceable(init(), UNO_QUERY_THROW); + uno::Reference<util::XReplaceDescriptor> xReplaceDescr + = xReplaceable->createReplaceDescriptor(); + CPPUNIT_ASSERT(xReplaceDescr.is()); + + uno::Reference<util::XSearchDescriptor> xSearchDescr = xReplaceable->createSearchDescriptor(); + xSearchDescr->setSearchString(maSearchString); + + //check that at least one object is there that will be replaced + uno::Reference<uno::XInterface> xElement = xReplaceable->findFirst(xSearchDescr); + CPPUNIT_ASSERT(xElement.is()); + + //check that there is none object with the replace string + xSearchDescr->setSearchString(maReplaceString); + xElement = xReplaceable->findFirst(xSearchDescr); + CPPUNIT_ASSERT(!xElement.is()); + + xReplaceDescr->setSearchString(maSearchString); + xReplaceDescr->setReplaceString(maReplaceString); + + callgrindStart(); + xReplaceable->replaceAll( + uno::Reference<util::XSearchDescriptor>(xReplaceDescr, UNO_QUERY_THROW)); + callgrindDump("test:replace_all"); + + //check that now at least one element is found + xElement = xReplaceable->findFirst(xSearchDescr); + CPPUNIT_ASSERT(xElement.is()); + + xSearchDescr->setSearchString(maSearchString); + xElement = xReplaceable->findFirst(xSearchDescr); + CPPUNIT_ASSERT(!xElement.is()); + + //redo the whole thing + xReplaceDescr->setSearchString(maReplaceString); + xReplaceDescr->setReplaceString(maSearchString); + + xReplaceable->replaceAll( + uno::Reference<util::XSearchDescriptor>(xReplaceDescr, UNO_QUERY_THROW)); + + //check that it works + xElement = xReplaceable->findFirst(xSearchDescr); + CPPUNIT_ASSERT(xElement.is()); + + //check that there is none object with the replace string + xSearchDescr->setSearchString(maReplaceString); + xElement = xReplaceable->findFirst(xSearchDescr); + CPPUNIT_ASSERT(!xElement.is()); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/util/xreplacedescriptor.cxx b/test/source/util/xreplacedescriptor.cxx new file mode 100644 index 000000000..b3b042a2d --- /dev/null +++ b/test/source/util/xreplacedescriptor.cxx @@ -0,0 +1,37 @@ +/* -*- 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 <test/util/xreplacedescriptor.hxx> +#include <rtl/ustring.hxx> + +#include <com/sun/star/util/XReplaceDescriptor.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void XReplaceDescriptor::testGetSetReplaceString() +{ + uno::Reference<util::XReplaceDescriptor> xRD(init(), uno::UNO_QUERY_THROW); + const OUString aReplaceStringOld = xRD->getReplaceString(); + CPPUNIT_ASSERT(aReplaceStringOld.isEmpty()); + + xRD->setReplaceString("_XReplaceDescriptor"); + const OUString aReplaceStringNew = xRD->getReplaceString(); + CPPUNIT_ASSERT_EQUAL(OUString("_XReplaceDescriptor"), aReplaceStringNew); + CPPUNIT_ASSERT(aReplaceStringOld != aReplaceStringNew); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/util/xsearchable.cxx b/test/source/util/xsearchable.cxx new file mode 100644 index 000000000..15b0cecde --- /dev/null +++ b/test/source/util/xsearchable.cxx @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <com/sun/star/util/XSearchable.hpp> +#include <com/sun/star/util/XSearchDescriptor.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <cppunit/TestAssert.h> + +#include <test/util/xsearchable.hxx> + +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XSearchable::testFindAll() +{ + uno::Reference<util::XSearchable> xSearchable(init(), UNO_QUERY_THROW); + uno::Reference<util::XSearchDescriptor> xSearchDescr = xSearchable->createSearchDescriptor(); + xSearchDescr->setSearchString(maSearchString); + + uno::Reference<container::XIndexAccess> xIndex = xSearchable->findAll(xSearchDescr); + CPPUNIT_ASSERT(xIndex.is()); + CPPUNIT_ASSERT_EQUAL(mnCount, xIndex->getCount()); +} + +void XSearchable::testFindFirst() +{ + uno::Reference<util::XSearchable> xSearchable(init(), UNO_QUERY_THROW); + uno::Reference<util::XSearchDescriptor> xSearchDescr = xSearchable->createSearchDescriptor(); + xSearchDescr->setSearchString(maSearchString); + + uno::Reference<uno::XInterface> xElement = xSearchable->findFirst(xSearchDescr); + CPPUNIT_ASSERT(xElement.is()); +} + +void XSearchable::testFindNext() +{ + uno::Reference<util::XSearchable> xSearchable(init(), UNO_QUERY_THROW); + uno::Reference<util::XSearchDescriptor> xSearchDescr = xSearchable->createSearchDescriptor(); + xSearchDescr->setSearchString(maSearchString); + + uno::Reference<uno::XInterface> xElement = xSearchable->findFirst(xSearchDescr); + CPPUNIT_ASSERT(xElement.is()); + + if (mnCount > 1) + { + uno::Reference<uno::XInterface> xElement2 = xSearchable->findNext(xElement, xSearchDescr); + CPPUNIT_ASSERT(xElement2.is()); + } +} + +XSearchable::~XSearchable() {} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/util/xsearchdescriptor.cxx b/test/source/util/xsearchdescriptor.cxx new file mode 100644 index 000000000..2740b2e26 --- /dev/null +++ b/test/source/util/xsearchdescriptor.cxx @@ -0,0 +1,36 @@ +/* -*- 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 <test/util/xsearchdescriptor.hxx> + +#include <com/sun/star/util/XSearchDescriptor.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void XSearchDescriptor::testGetSetSearchString() +{ + uno::Reference<util::XSearchDescriptor> xDS(init(), uno::UNO_QUERY_THROW); + const OUString aSearchStringOld = xDS->getSearchString(); + CPPUNIT_ASSERT(aSearchStringOld.isEmpty()); + + xDS->setSearchString("_XSearchDescriptor"); + const OUString aSearchStringNew = xDS->getSearchString(); + CPPUNIT_ASSERT_EQUAL(OUString("_XSearchDescriptor"), aSearchStringNew); + CPPUNIT_ASSERT(aSearchStringOld != aSearchStringNew); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/vclbootstrapprotector.cxx b/test/source/vclbootstrapprotector.cxx new file mode 100644 index 000000000..f6d1b9762 --- /dev/null +++ b/test/source/vclbootstrapprotector.cxx @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <sal/config.h> + +#include <cppunit/Protector.h> +#include <sal/types.h> +#include <sal/log.hxx> +#include <vcl/svapp.hxx> +#include <comphelper/threadpool.hxx> +#include "setupvcl.hxx" + +namespace { + +class Protector: public CppUnit::Protector { +public: + Protector() { test::setUpVcl(); } + Protector(const Protector&) = delete; + Protector& operator=(const Protector&) = delete; + +private: + virtual ~Protector() override { +#if defined(__COVERITY__) + try { +#endif + DeInitVCL(); + // for the 6 tests that use it + comphelper::ThreadPool::getSharedOptimalPool().shutdown(); +#if defined(__COVERITY__) + } catch (const std::exception& e) { + SAL_WARN("vcl.app", "Fatal exception: " << e.what()); + std::terminate(); + } +#endif + } + + virtual bool protect( + CppUnit::Functor const & functor, CppUnit::ProtectorContext const &) + override + { return functor(); } +}; + +} + +extern "C" SAL_DLLPUBLIC_EXPORT CppUnit::Protector * +vclbootstrapprotector() { + return new Protector; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/source/view/xcontrolaccess.cxx b/test/source/view/xcontrolaccess.cxx new file mode 100644 index 000000000..43a98c9c8 --- /dev/null +++ b/test/source/view/xcontrolaccess.cxx @@ -0,0 +1,56 @@ +/* -*- 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 <test/view/xcontrolaccess.hxx> +#include <test/helper/form.hxx> + +#include <com/sun/star/awt/XControl.hpp> +#include <com/sun/star/awt/XControlModel.hpp> +#include <com/sun/star/drawing/XControlShape.hpp> +#include <com/sun/star/drawing/XDrawPage.hpp> +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/drawing/XShapes.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/view/XControlAccess.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void XControlAccess::testGetControl() +{ + uno::Reference<view::XControlAccess> xCA(init(), uno::UNO_QUERY_THROW); + + uno::Reference<lang::XComponent> xComponent(getXComponent(), uno::UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPagesSupplier> xDPS(xComponent, uno::UNO_QUERY_THROW); + uno::Reference<drawing::XDrawPage> xDP(xDPS->getDrawPages()->getByIndex(0), + uno::UNO_QUERY_THROW); + + uno::Reference<drawing::XShapes> xShapes(xDP, uno::UNO_QUERY_THROW); + uno::Reference<drawing::XShape> xShape( + helper::form::createControlShape(xComponent, u"CommandButton", 10000, 50000, 100, 100), + uno::UNO_QUERY_THROW); + + xShapes->add(xShape); + + uno::Reference<drawing::XControlShape> xCS(xShape, uno::UNO_QUERY_THROW); + uno::Reference<awt::XControlModel> xCM(xCS->getControl(), uno::UNO_SET_THROW); + uno::Reference<awt::XControl> xControl(xCA->getControl(xCM), uno::UNO_SET_THROW); + + CPPUNIT_ASSERT(xControl.is()); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/view/xformlayeraccess.cxx b/test/source/view/xformlayeraccess.cxx new file mode 100644 index 000000000..68903fcc0 --- /dev/null +++ b/test/source/view/xformlayeraccess.cxx @@ -0,0 +1,56 @@ +/* -*- 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 <test/view/xformlayeraccess.hxx> + +#include <com/sun/star/form/runtime/XFormController.hpp> +#include <com/sun/star/view/XFormLayerAccess.hpp> + +#include <com/sun/star/uno/Reference.hxx> + +#include <cppunit/TestAssert.h> + +using namespace css; + +namespace apitest +{ +void XFormLayerAccess::testGetFormController() +{ + uno::Reference<view::XFormLayerAccess> xFLA(init(), uno::UNO_QUERY_THROW); + + const bool bCurrentMode = xFLA->isFormDesignMode(); + + // deliberately don't use UNO_QUERY_THROW, so we can use + // uno::XInterface::is() in CPPUNIT_ASSERT() + xFLA->setFormDesignMode(false); + uno::Reference<form::runtime::XFormController> xFC = xFLA->getFormController(m_xForm); + CPPUNIT_ASSERT(xFC.is()); + + xFLA->setFormDesignMode(bCurrentMode); +} + +void XFormLayerAccess::testIsFormDesignMode() { testSetFormDesignMode(); } + +void XFormLayerAccess::testSetFormDesignMode() +{ + uno::Reference<view::XFormLayerAccess> xFLA(init(), uno::UNO_QUERY_THROW); + + const bool bCurrentMode = xFLA->isFormDesignMode(); + xFLA->setFormDesignMode(!bCurrentMode); + + const bool bNewMode = xFLA->isFormDesignMode(); + CPPUNIT_ASSERT_EQUAL(!bCurrentMode, bNewMode); + + xFLA->setFormDesignMode(bCurrentMode); + CPPUNIT_ASSERT_EQUAL(bCurrentMode, static_cast<bool>(xFLA->isFormDesignMode())); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/test/source/xmltesttools.cxx b/test/source/xmltesttools.cxx new file mode 100644 index 000000000..63580366e --- /dev/null +++ b/test/source/xmltesttools.cxx @@ -0,0 +1,455 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <test/xmltesttools.hxx> + +#include <memory> + +#include <vcl/mtfxmldump.hxx> +#include <sal/log.hxx> + +namespace { + +OUString convert(xmlChar const * string) { + OUString s; + CPPUNIT_ASSERT_MESSAGE( + "xmlChar string is not UTF-8", + rtl_convertStringToUString( + &s.pData, reinterpret_cast<char const *>(string), xmlStrlen(string), + RTL_TEXTENCODING_UTF8, + (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR + | RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR))); + return s; +} + +OString oconvert(xmlChar const * string) +{ + return reinterpret_cast<char const *>(string); +} + +} + +XmlTestTools::XmlTestTools() +{} + +XmlTestTools::~XmlTestTools() +{} + +xmlDocUniquePtr XmlTestTools::parseXml(utl::TempFile const & aTempFile) +{ + SvFileStream aFileStream(aTempFile.GetURL(), StreamMode::READ); + return parseXmlStream(&aFileStream); +} + +xmlDocUniquePtr XmlTestTools::parseXmlStream(SvStream* pStream) +{ + std::size_t nSize = pStream->remainingSize(); + std::unique_ptr<sal_uInt8[]> pBuffer(new sal_uInt8[nSize + 1]); + pStream->ReadBytes(pBuffer.get(), nSize); + pBuffer[nSize] = 0; + auto pCharBuffer = reinterpret_cast<xmlChar*>(pBuffer.get()); + SAL_INFO("test", "XmlTestTools::parseXmlStream: pBuffer is '" << pCharBuffer << "'"); + return xmlDocUniquePtr(xmlParseDoc(pCharBuffer)); +} + +xmlDocUniquePtr XmlTestTools::dumpAndParse(MetafileXmlDump& rDumper, const GDIMetaFile& rGDIMetaFile) +{ + SvMemoryStream aStream; + rDumper.dump(rGDIMetaFile, aStream); + aStream.Seek(STREAM_SEEK_TO_BEGIN); + return XmlTestTools::parseXmlStream(&aStream); +} + +xmlXPathObjectPtr XmlTestTools::getXPathNode(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath) +{ + xmlXPathContextPtr pXmlXpathCtx = xmlXPathNewContext(pXmlDoc.get()); + registerNamespaces(pXmlXpathCtx); + xmlXPathObjectPtr pXmlXpathObj = xmlXPathEvalExpression(BAD_CAST(rXPath.getStr()), pXmlXpathCtx); + xmlXPathFreeContext(pXmlXpathCtx); + return pXmlXpathObj; +} + +void XmlTestTools::registerNamespaces(xmlXPathContextPtr& /*pXmlXpathCtx*/) +{ +} + +OUString XmlTestTools::getXPath(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OString& rAttribute) +{ + CPPUNIT_ASSERT(pXmlDoc); + xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath); + CPPUNIT_ASSERT(pXmlObj); + xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval; + CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + "' number of nodes is incorrect").getStr(), + 1, xmlXPathNodeSetGetLength(pXmlNodes)); + if (rAttribute.isEmpty()) + { + xmlXPathFreeObject(pXmlObj); + return OUString(); + } + xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0]; + xmlChar * prop = xmlGetProp(pXmlNode, BAD_CAST(rAttribute.getStr())); + OString sAttAbsent = OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + + "' no attribute '" + rAttribute + "' exist"; + CPPUNIT_ASSERT_MESSAGE(sAttAbsent.getStr(), prop); + OUString s(convert(prop)); + xmlFree(prop); + xmlXPathFreeObject(pXmlObj); + return s; +} + +OUString XmlTestTools::getXPathContent(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath) +{ + xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath); + switch (pXmlObj->type) + { + case XPATH_UNDEFINED: + CPPUNIT_FAIL("Undefined XPath type"); + case XPATH_NODESET: + { + xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval; + + CPPUNIT_ASSERT_MESSAGE( + OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + "' not found") + .getStr(), + xmlXPathNodeSetGetLength(pXmlNodes) > 0); + + xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0]; + xmlNodePtr pXmlChild = pXmlNode->children; + OUString s; + while (pXmlChild && pXmlChild->type != XML_TEXT_NODE) + pXmlChild = pXmlChild->next; + if (pXmlChild && pXmlChild->type == XML_TEXT_NODE) + s = convert(pXmlChild->content); + xmlXPathFreeObject(pXmlObj); + return s; + } + case XPATH_BOOLEAN: + { + auto boolVal = pXmlObj->boolval; + xmlXPathFreeObject(pXmlObj); + return boolVal ? OUString("true") : OUString("false"); + } + case XPATH_NUMBER: + { + auto floatVal = pXmlObj->floatval; + xmlXPathFreeObject(pXmlObj); + return OUString::number(floatVal); + } + case XPATH_STRING: + { + auto convertedVal = convert(pXmlObj->stringval); + xmlXPathFreeObject(pXmlObj); + return convertedVal; + } +#if LIBXML_VERSION < 21000 || defined(LIBXML_XPTR_LOCS_ENABLED) + case XPATH_POINT: + case XPATH_RANGE: + case XPATH_LOCATIONSET: +#endif + case XPATH_USERS: + case XPATH_XSLT_TREE: + xmlXPathFreeObject(pXmlObj); + CPPUNIT_FAIL("Unsupported XPath type"); + } + + CPPUNIT_FAIL("Invalid XPath type"); +} + +void XmlTestTools::assertXPath(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath) +{ + getXPath(pXmlDoc, rXPath, ""); // it asserts that rXPath exists, and returns exactly one node +} + +void XmlTestTools::assertXPath(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OString& rAttribute, const OUString& rExpectedValue) +{ + OUString aValue = getXPath(pXmlDoc, rXPath, rAttribute); + CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, attribute '" + rAttribute + "' of '" + rXPath + "' incorrect value.").getStr(), + rExpectedValue, aValue); +} + +void XmlTestTools::assertXPathAttrs(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, + const std::vector<std::pair<OString, OUString>>& aPairVector) +{ + for (auto& rPair : aPairVector) + { + assertXPath(pXmlDoc, rXPath, rPair.first, rPair.second); + } +} + +int XmlTestTools::countXPathNodes(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath) +{ + xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath); + xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval; + const int n = xmlXPathNodeSetGetLength(pXmlNodes); + xmlXPathFreeObject(pXmlObj); + return n; +} + +void XmlTestTools::assertXPath(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, int nNumberOfNodes) +{ + CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + "' number of nodes is incorrect").getStr(), + nNumberOfNodes, countXPathNodes(pXmlDoc, rXPath)); +} + +void XmlTestTools::assertXPathContent(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OUString& rContent) +{ + CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath contents of child does not match").getStr(), rContent, getXPathContent(pXmlDoc, rXPath)); +} + +void XmlTestTools::assertXPathNSDef(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, + std::u16string_view rNSPrefix, std::u16string_view rNSHref) +{ + xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath); + xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval; + CPPUNIT_ASSERT_MESSAGE( + OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + "' not found").getStr(), + xmlXPathNodeSetGetLength(pXmlNodes) > 0); + + xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0]; + bool bFound = false; + for (xmlNsPtr pNamespace = pXmlNode->nsDef; pNamespace; pNamespace = pNamespace->next) + { + if (!pNamespace->prefix) + continue; + + CPPUNIT_ASSERT(pNamespace->href); + if (rNSPrefix == convert(pNamespace->prefix) && rNSHref == convert(pNamespace->href)) + { + bFound = true; + break; + } + } + xmlXPathFreeObject(pXmlObj); + CPPUNIT_ASSERT(bFound); +} + +void XmlTestTools::assertXPathChildren(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, int nNumberOfChildNodes) +{ +#if LIBXML_VERSION >= 20703 /* xmlChildElementCount is only available in libxml2 >= 2.7.3 */ + xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath); + xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval; + CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + "' number of nodes is incorrect").getStr(), + 1, xmlXPathNodeSetGetLength(pXmlNodes)); + xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0]; + CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + "' number of child-nodes is incorrect").getStr(), + nNumberOfChildNodes, static_cast<int>(xmlChildElementCount(pXmlNode))); + xmlXPathFreeObject(pXmlObj); +#else + (void)pXmlDoc; + (void)rXPath; + (void)nNumberOfChildNodes; +#endif +} + +void XmlTestTools::assertXPathNoAttribute(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, const OString& rAttribute) +{ + xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath); + xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval; + CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + "' number of nodes is incorrect").getStr(), + 1, xmlXPathNodeSetGetLength(pXmlNodes)); + xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0]; + CPPUNIT_ASSERT_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + "' unexpected '" + rAttribute + "' attribute").getStr(), + !xmlGetProp(pXmlNode, BAD_CAST(rAttribute.getStr()))); + xmlXPathFreeObject(pXmlObj); +} + +int XmlTestTools::getXPathPosition(const xmlDocUniquePtr& pXmlDoc, const OString& rXPath, std::string_view rChildName) +{ + xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath); + xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval; + CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + "' number of nodes is incorrect").getStr(), + 1, + xmlXPathNodeSetGetLength(pXmlNodes)); + xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0]; + int nRet = 0; + bool bFound = false; + for (xmlNodePtr pChild = pXmlNode->children; pChild; pChild = pChild->next) + { + if (oconvert(pChild->name) == rChildName) + { + bFound = true; + break; + } + ++nRet; + } + xmlXPathFreeObject(pXmlObj); + CPPUNIT_ASSERT_MESSAGE(OString(OString::Concat("In <") + pXmlDoc->name + ">, XPath '" + rXPath + + "' child '" + rChildName + "' not found") + .getStr(), + bFound); + return nRet; +} + +void XmlTestTools::registerODFNamespaces(xmlXPathContextPtr& pXmlXpathCtx) +{ + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("office"), + BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:office:1.0")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("style"), + BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:style:1.0")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("text"), + BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:text:1.0")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("table"), + BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:table:1.0")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("draw"), + BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:drawing:1.0")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("fo"), + BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("config"), + BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:config:1.0")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("xlink"), BAD_CAST("http://www.w3.org/1999/xlink")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("dc"), BAD_CAST("http://purl.org/dc/elements/1.1/")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("meta"), + BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:meta:1.0")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("number"), + BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("svg"), + BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("chart"), + BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:chart:1.0")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("dr3d"), + BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("math"), + BAD_CAST("http://www.w3.org/1998/Math/MathML")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("form"), + BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:form:1.0")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("script"), + BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:script:1.0")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("ooo"), + BAD_CAST("http://openoffice.org/2004/office")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("ooow"), + BAD_CAST("http://openoffice.org/2004/writer")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("oooc"), BAD_CAST("http://openoffice.org/2004/calc")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("dom"), + BAD_CAST("http://www.w3.org/2001/xml-events")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("xforms"), BAD_CAST("http://www.w3.org/2002/xforms")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("xsd"), BAD_CAST("http://www.w3.org/2001/XMLSchema")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("xsi"), + BAD_CAST("http://www.w3.org/2001/XMLSchema-instance")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("rpt"), + BAD_CAST("http://openoffice.org/2005/report")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("of"), + BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:of:1.2")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("xhtml"), BAD_CAST("http://www.w3.org/1999/xhtml")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("grddl"), + BAD_CAST("http://www.w3.org/2003/g/data-view#")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("officeooo"), + BAD_CAST("http://openoffice.org/2009/office")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("tableooo"), + BAD_CAST("http://openoffice.org/2009/table")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("drawooo"), + BAD_CAST("http://openoffice.org/2010/draw")); + xmlXPathRegisterNs( + pXmlXpathCtx, BAD_CAST("calcext"), + BAD_CAST("urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0")); + xmlXPathRegisterNs( + pXmlXpathCtx, BAD_CAST("loext"), + BAD_CAST("urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0")); + xmlXPathRegisterNs( + pXmlXpathCtx, BAD_CAST("field"), + BAD_CAST("urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0")); + xmlXPathRegisterNs( + pXmlXpathCtx, BAD_CAST("formx"), + BAD_CAST("urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("css3t"), + BAD_CAST("http://www.w3.org/TR/css3-text/")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("anim"), + BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:animation:1.0")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("smil"), + BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("presentation"), + BAD_CAST("urn:oasis:names:tc:opendocument:xmlns:presentation:1.0")); + // user-defined + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("foo"), + BAD_CAST("http://example.com/")); +} + +void XmlTestTools::registerOOXMLNamespaces(xmlXPathContextPtr& pXmlXpathCtx) +{ + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("w"), + BAD_CAST("http://schemas.openxmlformats.org/wordprocessingml/2006/main")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("v"), BAD_CAST("urn:schemas-microsoft-com:vml")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("mc"), + BAD_CAST("http://schemas.openxmlformats.org/markup-compatibility/2006")); + xmlXPathRegisterNs( + pXmlXpathCtx, BAD_CAST("wps"), + BAD_CAST("http://schemas.microsoft.com/office/word/2010/wordprocessingShape")); + xmlXPathRegisterNs( + pXmlXpathCtx, BAD_CAST("wpg"), + BAD_CAST("http://schemas.microsoft.com/office/word/2010/wordprocessingGroup")); + xmlXPathRegisterNs( + pXmlXpathCtx, BAD_CAST("wp"), + BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing")); + xmlXPathRegisterNs( + pXmlXpathCtx, BAD_CAST("wp14"), + BAD_CAST("http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("a"), + BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/main")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("pic"), + BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/picture")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("rels"), + BAD_CAST("http://schemas.openxmlformats.org/package/2006/relationships")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("w14"), + BAD_CAST("http://schemas.microsoft.com/office/word/2010/wordml")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("w15"), + BAD_CAST("http://schemas.microsoft.com/office/word/2012/wordml")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("m"), + BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/math")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("ContentType"), + BAD_CAST("http://schemas.openxmlformats.org/package/2006/content-types")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("lc"), + BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas")); + xmlXPathRegisterNs( + pXmlXpathCtx, BAD_CAST("cp"), + BAD_CAST("http://schemas.openxmlformats.org/package/2006/metadata/core-properties")); + xmlXPathRegisterNs( + pXmlXpathCtx, BAD_CAST("extended-properties"), + BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/extended-properties")); + xmlXPathRegisterNs( + pXmlXpathCtx, BAD_CAST("custom-properties"), + BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/custom-properties")); + xmlXPathRegisterNs( + pXmlXpathCtx, BAD_CAST("vt"), + BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("dcterms"), BAD_CAST("http://purl.org/dc/terms/")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("a14"), + BAD_CAST("http://schemas.microsoft.com/office/drawing/2010/main")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("c"), + BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/chart")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("x"), + BAD_CAST("http://schemas.openxmlformats.org/spreadsheetml/2006/main")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("r"), + BAD_CAST("http://schemas.openxmlformats.org/officeDocument/2006/relationships")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("xx"), + BAD_CAST("urn:schemas-microsoft-com:office:excel")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("xdr"), + BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("x14"), + BAD_CAST("http://schemas.microsoft.com/office/spreadsheetml/2009/9/main")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("xm"), + BAD_CAST("http://schemas.microsoft.com/office/excel/2006/main")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("x12ac"), + BAD_CAST("http://schemas.microsoft.com/office/spreadsheetml/2011/1/ac")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("o"), + BAD_CAST("urn:schemas-microsoft-com:office:office")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("w10"), + BAD_CAST("urn:schemas-microsoft-com:office:word")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("p"), + BAD_CAST("http://schemas.openxmlformats.org/presentationml/2006/main")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("p14"), + BAD_CAST("http://schemas.microsoft.com/office/powerpoint/2010/main")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("dgm"), + BAD_CAST("http://schemas.openxmlformats.org/drawingml/2006/diagram")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("c15"), + BAD_CAST("http://schemas.microsoft.com/office/drawing/2012/chart")); + xmlXPathRegisterNs(pXmlXpathCtx, BAD_CAST("xr2"), + BAD_CAST("http://schemas.microsoft.com/office/spreadsheetml/2015/revision2")); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |