From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- test/source/sheet/xnamedrange.cxx | 112 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 test/source/sheet/xnamedrange.cxx (limited to 'test/source/sheet/xnamedrange.cxx') 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 + +#include +#include +#include + +#include +#include + +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: */ -- cgit v1.2.3