1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <sal/config.h>
11 #include <test/bootstrapfixture.hxx>
12 #include <unotools/configmgr.hxx>
13 #include <document.hxx>
18 #include <address.hxx>
19 #include <rangeutl.hxx>
20 #include <refupdatecontext.hxx>
22 class ScAddressTest
: public test::BootstrapFixture
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();
36 ScDocShellRef m_xDocShRef
;
39 void ScAddressTest::testAddressParsing()
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();
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();
62 BootstrapFixture::tearDown();
65 class ScRangeTest
: public test::BootstrapFixture
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();
78 ScDocShellRef m_xDocShRef
;
81 void ScRangeTest::testRangeParsing()
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();
94 m_xDocShRef
= new ScDocShell(
95 SfxModelFlags::EMBEDDED_OBJECT
|
96 SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS
|
97 SfxModelFlags::DISABLE_DOCUMENT_RECOVERY
);
100 void ScRangeTest::tearDown()
103 BootstrapFixture::tearDown();
106 class ScRangeUpdaterTest
: public CppUnit::TestFixture
110 virtual void setUp() override
112 utl::ConfigManager::EnableFuzzing();
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()
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()
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()
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()
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()
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()
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: */