cool#10630 doc sign: fix Impress sign line, to be able to finish signing again
[LibreOffice.git] / sc / qa / unit / ucalc_range.cxx
blob4c515e4026982d596a8df8745d326ec9eece8766
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <sal/config.h>
11 #include "helper/qahelper.hxx"
12 #include <comphelper/configuration.hxx>
13 #include <document.hxx>
14 #include <global.hxx>
15 #include <scdll.hxx>
17 #include <address.hxx>
18 #include <rangeutl.hxx>
19 #include <refupdatecontext.hxx>
21 class ScRangeTest : public ScUcalcTestBase
25 CPPUNIT_TEST_FIXTURE(ScRangeTest, testOverlap)
27 ScRange aRange1( ScAddress( 0, 0, 0 ), ScAddress( 1, 1, 1 ));
28 CPPUNIT_ASSERT(aRange1.Contains( ScAddress( 0, 0, 0 )));
29 CPPUNIT_ASSERT(aRange1.Contains( ScAddress( 1, 1, 1 )));
30 CPPUNIT_ASSERT(!aRange1.Contains( ScAddress( 2, 1, 1 )));
31 CPPUNIT_ASSERT(!aRange1.Contains( ScAddress( 1, 2, 1 )));
32 CPPUNIT_ASSERT(!aRange1.Contains( ScAddress( 1, 1, 2 )));
34 ScRange aRange2( ScAddress( 0, 0, 0 ), ScAddress( 10, 10, 10 ));
35 ScRange aRange3( ScAddress( 5, 5, 5 ), ScAddress( 15, 15, 15 ));
36 CPPUNIT_ASSERT(!aRange2.Contains( aRange3 ));
37 CPPUNIT_ASSERT(!aRange3.Contains( aRange2 ));
38 CPPUNIT_ASSERT(aRange2.Intersects( aRange3 ));
39 CPPUNIT_ASSERT(aRange3.Intersects( aRange2 ));
40 CPPUNIT_ASSERT(!aRange3.Intersects( aRange1 ));
41 CPPUNIT_ASSERT(!aRange1.Intersects( aRange3 ));
44 CPPUNIT_TEST_FIXTURE(ScRangeTest, testRangeParsing)
46 ScRange aRange;
47 ScRefFlags nRes = aRange.Parse(u":1"_ustr, *m_pDoc, formula::FormulaGrammar::CONV_OOO);
48 CPPUNIT_ASSERT_MESSAGE("Should fail to parse.", !(nRes & ScRefFlags::VALID));
51 CPPUNIT_TEST_FIXTURE(ScRangeTest, testAddressParsing)
53 ScAddress aAddr;
54 ScRefFlags nRes = aAddr.Parse(u"1"_ustr, *m_pDoc, formula::FormulaGrammar::CONV_OOO);
55 CPPUNIT_ASSERT_MESSAGE("Should fail to parse.", !(nRes & ScRefFlags::VALID));
58 CPPUNIT_TEST_FIXTURE(ScRangeTest, testTdf147451)
60 ScAddress aAddr;
61 // "Sheet1" is technically a valid address like "XF1", but it should overflow.
62 ScRefFlags nRes = aAddr.Parse(u"Sheet1"_ustr, *m_pDoc, formula::FormulaGrammar::CONV_OOO);
63 CPPUNIT_ASSERT_MESSAGE("Should fail to parse.", !(nRes & ScRefFlags::VALID));
66 class ScRangeUpdaterTest : public CppUnit::TestFixture
68 public:
70 virtual void setUp() override
72 comphelper::EnableFuzzing();
73 ScDLL::Init();
74 ScGlobal::Init();
78 CPPUNIT_TEST_FIXTURE(ScRangeUpdaterTest, testUpdateInsertTabBeforePos)
80 ScDocument aDoc;
81 ScAddress aAddr(1, 1, 1);
82 sc::RefUpdateInsertTabContext aContext(aDoc, 0, 1);
83 ScRangeUpdater::UpdateInsertTab(aAddr, aContext);
84 CPPUNIT_ASSERT_EQUAL(ScAddress(1, 1, 2), aAddr);
87 CPPUNIT_TEST_FIXTURE(ScRangeUpdaterTest, testUpdateInsertTabAtPos)
89 ScDocument aDoc;
90 ScAddress aAddr(1, 1, 1);
91 sc::RefUpdateInsertTabContext aContext(aDoc, 1, 1);
92 ScRangeUpdater::UpdateInsertTab(aAddr, aContext);
93 CPPUNIT_ASSERT_EQUAL(ScAddress(1, 1, 2), aAddr);
96 CPPUNIT_TEST_FIXTURE(ScRangeUpdaterTest, testUpdateInsertTabAfterPos)
98 ScDocument aDoc;
99 ScAddress aAddr(1, 1, 1);
100 sc::RefUpdateInsertTabContext aContext(aDoc, 2, 1);
101 ScRangeUpdater::UpdateInsertTab(aAddr, aContext);
102 CPPUNIT_ASSERT_EQUAL(ScAddress(1, 1, 1), aAddr);
105 CPPUNIT_TEST_FIXTURE(ScRangeUpdaterTest, testUpdateDeleteTabBeforePos)
107 ScDocument aDoc;
108 ScAddress aAddr(1, 1, 1);
109 sc::RefUpdateDeleteTabContext aContext(aDoc, 0, 1);
110 ScRangeUpdater::UpdateDeleteTab(aAddr, aContext);
111 CPPUNIT_ASSERT_EQUAL(ScAddress(1, 1, 0), aAddr);
114 CPPUNIT_TEST_FIXTURE(ScRangeUpdaterTest, testUpdateDeleteTabAtPos)
116 ScDocument aDoc;
118 // Position within deleted range is moved to the front.
120 ScAddress aAddr(1, 1, 1);
121 sc::RefUpdateDeleteTabContext aContext(aDoc, 1, 1);
122 ScRangeUpdater::UpdateDeleteTab(aAddr, aContext);
123 CPPUNIT_ASSERT_EQUAL(ScAddress(1, 1, 0), aAddr);
126 ScAddress aAddr(1, 1, 2);
127 sc::RefUpdateDeleteTabContext aContext(aDoc, 1, 2);
128 ScRangeUpdater::UpdateDeleteTab(aAddr, aContext);
129 CPPUNIT_ASSERT_EQUAL(ScAddress(1, 1, 0), aAddr);
132 // Would-be negative results are clamped to 0.
134 ScAddress aAddr(1, 1, 0);
135 sc::RefUpdateDeleteTabContext aContext(aDoc, 0, 1);
136 ScRangeUpdater::UpdateDeleteTab(aAddr, aContext);
137 CPPUNIT_ASSERT_EQUAL(ScAddress(1, 1, 0), aAddr);
140 ScAddress aAddr(1, 1, 1);
141 sc::RefUpdateDeleteTabContext aContext(aDoc, 0, 2);
142 ScRangeUpdater::UpdateDeleteTab(aAddr, aContext);
143 CPPUNIT_ASSERT_EQUAL(ScAddress(1, 1, 0), aAddr);
147 CPPUNIT_TEST_FIXTURE(ScRangeUpdaterTest, testUpdateDeleteTabAfterPos)
149 ScDocument aDoc;
150 ScAddress aAddr(1, 1, 1);
151 sc::RefUpdateDeleteTabContext aContext(aDoc, 2, 1);
152 ScRangeUpdater::UpdateDeleteTab(aAddr, aContext);
153 CPPUNIT_ASSERT_EQUAL(ScAddress(1, 1, 1), aAddr);
156 CPPUNIT_PLUGIN_IMPLEMENT();
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */