Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / qa / unit / range.cxx
blob4eb490d81b56943657d2e4a35bc757aef28e310f
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 <test/bootstrapfixture.hxx>
12 #include <unotools/configmgr.hxx>
13 #include <document.hxx>
14 #include <docsh.hxx>
15 #include <global.hxx>
16 #include <scdll.hxx>
18 #include <address.hxx>
19 #include <rangeutl.hxx>
20 #include <refupdatecontext.hxx>
22 class ScAddressTest : public test::BootstrapFixture
24 public:
26 virtual void setUp() override;
27 virtual void tearDown() override;
29 CPPUNIT_TEST_SUITE(ScAddressTest);
30 CPPUNIT_TEST(testAddressParsing);
31 CPPUNIT_TEST_SUITE_END();
33 void testAddressParsing();
35 private:
36 ScDocShellRef m_xDocShRef;
39 void ScAddressTest::testAddressParsing()
41 ScAddress aAddr;
42 ScDocument& rDoc = m_xDocShRef->GetDocument();
43 ScRefFlags nRes = aAddr.Parse("1", &rDoc, formula::FormulaGrammar::CONV_OOO);
44 CPPUNIT_ASSERT_MESSAGE("Should fail to parse.", !(nRes & ScRefFlags::VALID));
47 void ScAddressTest::setUp()
49 BootstrapFixture::setUp();
51 ScDLL::Init();
52 m_xDocShRef = new ScDocShell(
53 SfxModelFlags::EMBEDDED_OBJECT |
54 SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS |
55 SfxModelFlags::DISABLE_DOCUMENT_RECOVERY);
58 void ScAddressTest::tearDown()
60 m_xDocShRef.clear();
61 BootstrapFixture::tearDown();
64 class ScRangeTest : public test::BootstrapFixture
66 public:
67 virtual void setUp() override;
68 virtual void tearDown() override;
70 CPPUNIT_TEST_SUITE(ScRangeTest);
71 CPPUNIT_TEST(testRangeParsing);
72 CPPUNIT_TEST_SUITE_END();
74 void testRangeParsing();
76 private:
77 ScDocShellRef m_xDocShRef;
80 void ScRangeTest::testRangeParsing()
82 ScRange aRange;
83 ScDocument& rDoc = m_xDocShRef->GetDocument();
84 ScRefFlags nRes = aRange.Parse(":1", &rDoc, formula::FormulaGrammar::CONV_OOO);
85 CPPUNIT_ASSERT_MESSAGE("Should fail to parse.", !(nRes & ScRefFlags::VALID));
88 void ScRangeTest::setUp()
90 BootstrapFixture::setUp();
92 ScDLL::Init();
93 m_xDocShRef = new ScDocShell(
94 SfxModelFlags::EMBEDDED_OBJECT |
95 SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS |
96 SfxModelFlags::DISABLE_DOCUMENT_RECOVERY);
99 void ScRangeTest::tearDown()
101 m_xDocShRef.clear();
102 BootstrapFixture::tearDown();
105 class ScRangeUpdaterTest : public CppUnit::TestFixture
107 public:
109 virtual void setUp() override
111 utl::ConfigManager::EnableFuzzing();
112 ScDLL::Init();
113 ScGlobal::Init();
115 void testUpdateInsertTabBeforePos();
116 void testUpdateInsertTabAtPos();
117 void testUpdateInsertTabAfterPos();
118 void testUpdateDeleteTabBeforePos();
119 void testUpdateDeleteTabAtPos();
120 void testUpdateDeleteTabAfterPos();
122 CPPUNIT_TEST_SUITE(ScRangeUpdaterTest);
123 CPPUNIT_TEST(testUpdateInsertTabBeforePos);
124 CPPUNIT_TEST(testUpdateInsertTabAtPos);
125 CPPUNIT_TEST(testUpdateInsertTabAfterPos);
126 CPPUNIT_TEST(testUpdateDeleteTabBeforePos);
127 CPPUNIT_TEST(testUpdateDeleteTabAtPos);
128 CPPUNIT_TEST(testUpdateDeleteTabAfterPos);
129 CPPUNIT_TEST_SUITE_END();
132 void ScRangeUpdaterTest::testUpdateInsertTabBeforePos()
134 ScDocument aDoc;
135 ScAddress aAddr(1, 1, 1);
136 sc::RefUpdateInsertTabContext aContext(aDoc, 0, 1);
137 ScRangeUpdater::UpdateInsertTab(aAddr, aContext);
138 CPPUNIT_ASSERT_EQUAL(ScAddress(1, 1, 2), aAddr);
141 void ScRangeUpdaterTest::testUpdateInsertTabAtPos()
143 ScDocument aDoc;
144 ScAddress aAddr(1, 1, 1);
145 sc::RefUpdateInsertTabContext aContext(aDoc, 1, 1);
146 ScRangeUpdater::UpdateInsertTab(aAddr, aContext);
147 CPPUNIT_ASSERT_EQUAL(ScAddress(1, 1, 2), aAddr);
150 void ScRangeUpdaterTest::testUpdateInsertTabAfterPos()
152 ScDocument aDoc;
153 ScAddress aAddr(1, 1, 1);
154 sc::RefUpdateInsertTabContext aContext(aDoc, 2, 1);
155 ScRangeUpdater::UpdateInsertTab(aAddr, aContext);
156 CPPUNIT_ASSERT_EQUAL(ScAddress(1, 1, 1), aAddr);
159 void ScRangeUpdaterTest::testUpdateDeleteTabBeforePos()
161 ScDocument aDoc;
162 ScAddress aAddr(1, 1, 1);
163 sc::RefUpdateDeleteTabContext aContext(aDoc, 0, 1);
164 ScRangeUpdater::UpdateDeleteTab(aAddr, aContext);
165 CPPUNIT_ASSERT_EQUAL(ScAddress(1, 1, 0), aAddr);
168 void ScRangeUpdaterTest::testUpdateDeleteTabAtPos()
170 ScDocument aDoc;
171 ScAddress aAddr(1, 1, 1);
172 sc::RefUpdateDeleteTabContext aContext(aDoc, 1, 1);
173 ScRangeUpdater::UpdateDeleteTab(aAddr, aContext);
174 CPPUNIT_ASSERT_EQUAL(ScAddress(1, 1, 0), aAddr);
177 void ScRangeUpdaterTest::testUpdateDeleteTabAfterPos()
179 ScDocument aDoc;
180 ScAddress aAddr(1, 1, 1);
181 sc::RefUpdateDeleteTabContext aContext(aDoc, 2, 1);
182 ScRangeUpdater::UpdateDeleteTab(aAddr, aContext);
183 CPPUNIT_ASSERT_EQUAL(ScAddress(1, 1, 1), aAddr);
186 CPPUNIT_TEST_SUITE_REGISTRATION(ScAddressTest);
187 CPPUNIT_TEST_SUITE_REGISTRATION(ScRangeTest);
188 CPPUNIT_TEST_SUITE_REGISTRATION(ScRangeUpdaterTest);
190 CPPUNIT_PLUGIN_IMPLEMENT();
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */