nss: upgrade to release 3.73
[LibreOffice.git] / sc / qa / unit / range.cxx
blob21add9ee37fedd128f39712d309cc556131faf0e
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->DoClose();
61 m_xDocShRef.clear();
62 BootstrapFixture::tearDown();
65 class ScRangeTest : public test::BootstrapFixture
67 public:
68 virtual void setUp() override;
69 virtual void tearDown() override;
71 CPPUNIT_TEST_SUITE(ScRangeTest);
72 CPPUNIT_TEST(testRangeParsing);
73 CPPUNIT_TEST_SUITE_END();
75 void testRangeParsing();
77 private:
78 ScDocShellRef m_xDocShRef;
81 void ScRangeTest::testRangeParsing()
83 ScRange aRange;
84 ScDocument& rDoc = m_xDocShRef->GetDocument();
85 ScRefFlags nRes = aRange.Parse(":1", rDoc, formula::FormulaGrammar::CONV_OOO);
86 CPPUNIT_ASSERT_MESSAGE("Should fail to parse.", !(nRes & ScRefFlags::VALID));
89 void ScRangeTest::setUp()
91 BootstrapFixture::setUp();
93 ScDLL::Init();
94 m_xDocShRef = new ScDocShell(
95 SfxModelFlags::EMBEDDED_OBJECT |
96 SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS |
97 SfxModelFlags::DISABLE_DOCUMENT_RECOVERY);
100 void ScRangeTest::tearDown()
102 m_xDocShRef.clear();
103 BootstrapFixture::tearDown();
106 class ScRangeUpdaterTest : public CppUnit::TestFixture
108 public:
110 virtual void setUp() override
112 utl::ConfigManager::EnableFuzzing();
113 ScDLL::Init();
114 ScGlobal::Init();
116 void testUpdateInsertTabBeforePos();
117 void testUpdateInsertTabAtPos();
118 void testUpdateInsertTabAfterPos();
119 void testUpdateDeleteTabBeforePos();
120 void testUpdateDeleteTabAtPos();
121 void testUpdateDeleteTabAfterPos();
123 CPPUNIT_TEST_SUITE(ScRangeUpdaterTest);
124 CPPUNIT_TEST(testUpdateInsertTabBeforePos);
125 CPPUNIT_TEST(testUpdateInsertTabAtPos);
126 CPPUNIT_TEST(testUpdateInsertTabAfterPos);
127 CPPUNIT_TEST(testUpdateDeleteTabBeforePos);
128 CPPUNIT_TEST(testUpdateDeleteTabAtPos);
129 CPPUNIT_TEST(testUpdateDeleteTabAfterPos);
130 CPPUNIT_TEST_SUITE_END();
133 void ScRangeUpdaterTest::testUpdateInsertTabBeforePos()
135 ScDocument aDoc;
136 ScAddress aAddr(1, 1, 1);
137 sc::RefUpdateInsertTabContext aContext(aDoc, 0, 1);
138 ScRangeUpdater::UpdateInsertTab(aAddr, aContext);
139 CPPUNIT_ASSERT_EQUAL(ScAddress(1, 1, 2), aAddr);
142 void ScRangeUpdaterTest::testUpdateInsertTabAtPos()
144 ScDocument aDoc;
145 ScAddress aAddr(1, 1, 1);
146 sc::RefUpdateInsertTabContext aContext(aDoc, 1, 1);
147 ScRangeUpdater::UpdateInsertTab(aAddr, aContext);
148 CPPUNIT_ASSERT_EQUAL(ScAddress(1, 1, 2), aAddr);
151 void ScRangeUpdaterTest::testUpdateInsertTabAfterPos()
153 ScDocument aDoc;
154 ScAddress aAddr(1, 1, 1);
155 sc::RefUpdateInsertTabContext aContext(aDoc, 2, 1);
156 ScRangeUpdater::UpdateInsertTab(aAddr, aContext);
157 CPPUNIT_ASSERT_EQUAL(ScAddress(1, 1, 1), aAddr);
160 void ScRangeUpdaterTest::testUpdateDeleteTabBeforePos()
162 ScDocument aDoc;
163 ScAddress aAddr(1, 1, 1);
164 sc::RefUpdateDeleteTabContext aContext(aDoc, 0, 1);
165 ScRangeUpdater::UpdateDeleteTab(aAddr, aContext);
166 CPPUNIT_ASSERT_EQUAL(ScAddress(1, 1, 0), aAddr);
169 void ScRangeUpdaterTest::testUpdateDeleteTabAtPos()
171 ScDocument aDoc;
172 ScAddress aAddr(1, 1, 1);
173 sc::RefUpdateDeleteTabContext aContext(aDoc, 1, 1);
174 ScRangeUpdater::UpdateDeleteTab(aAddr, aContext);
175 CPPUNIT_ASSERT_EQUAL(ScAddress(1, 1, 0), aAddr);
178 void ScRangeUpdaterTest::testUpdateDeleteTabAfterPos()
180 ScDocument aDoc;
181 ScAddress aAddr(1, 1, 1);
182 sc::RefUpdateDeleteTabContext aContext(aDoc, 2, 1);
183 ScRangeUpdater::UpdateDeleteTab(aAddr, aContext);
184 CPPUNIT_ASSERT_EQUAL(ScAddress(1, 1, 1), aAddr);
187 CPPUNIT_TEST_SUITE_REGISTRATION(ScAddressTest);
188 CPPUNIT_TEST_SUITE_REGISTRATION(ScRangeTest);
189 CPPUNIT_TEST_SUITE_REGISTRATION(ScRangeUpdaterTest);
191 CPPUNIT_PLUGIN_IMPLEMENT();
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */