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 "helper/qahelper.hxx"
13 #include "document.hxx"
16 #include "rangelst.hxx"
18 class Test
: public test::BootstrapFixture
26 virtual void setUp() SAL_OVERRIDE
;
27 virtual void tearDown() SAL_OVERRIDE
;
29 void testDeleteArea_4Ranges();
30 void testDeleteArea_3Ranges();
31 void testDeleteArea_3Ranges_Case2();
32 void testDeleteArea_3Ranges_Case3();
33 void testDeleteArea_3Ranges_Case4();
34 void testDeleteArea_3Ranges_Case5();
35 void testDeleteArea_2Ranges();
36 void testDeleteArea_2Ranges_Case2();
37 void testDeleteArea_2Ranges_Case3();
38 void testDeleteArea_2Ranges_Case4();
39 void testDeleteArea_2Ranges_Case5();
40 void testDeleteArea_2Ranges_Case6();
41 void testDeleteArea_2Ranges_Case7();
42 void testDeleteArea_2Ranges_Case8();
43 void testDeleteArea_1Range();
44 void testDeleteArea_0Ranges();
45 void testJoin_Case1();
46 void testJoin_Case2();
47 void testGetIntersectedRange();
49 void testUpdateReference_DeleteRow();
50 void testUpdateReference_DeleteCol();
55 CPPUNIT_TEST_SUITE(Test
);
56 CPPUNIT_TEST(testDeleteArea_4Ranges
);
57 CPPUNIT_TEST(testDeleteArea_3Ranges
);
58 CPPUNIT_TEST(testDeleteArea_3Ranges_Case2
);
59 CPPUNIT_TEST(testDeleteArea_3Ranges_Case3
);
60 CPPUNIT_TEST(testDeleteArea_3Ranges_Case4
);
61 CPPUNIT_TEST(testDeleteArea_3Ranges_Case5
);
62 CPPUNIT_TEST(testDeleteArea_2Ranges
);
63 CPPUNIT_TEST(testDeleteArea_2Ranges_Case2
);
64 CPPUNIT_TEST(testDeleteArea_2Ranges_Case3
);
65 CPPUNIT_TEST(testDeleteArea_2Ranges_Case4
);
66 CPPUNIT_TEST(testDeleteArea_2Ranges_Case5
);
67 CPPUNIT_TEST(testDeleteArea_2Ranges_Case6
);
68 CPPUNIT_TEST(testDeleteArea_2Ranges_Case7
);
69 CPPUNIT_TEST(testDeleteArea_2Ranges_Case8
);
70 CPPUNIT_TEST(testDeleteArea_1Range
);
71 CPPUNIT_TEST(testDeleteArea_0Ranges
);
72 CPPUNIT_TEST(testJoin_Case1
);
73 CPPUNIT_TEST(testJoin_Case2
);
74 CPPUNIT_TEST(testUpdateReference_DeleteRow
);
75 CPPUNIT_TEST(testUpdateReference_DeleteCol
);
76 CPPUNIT_TEST(testGetIntersectedRange
);
77 CPPUNIT_TEST(testInsertRow
);
78 CPPUNIT_TEST(testInsertCol
);
79 CPPUNIT_TEST_SUITE_END();
83 ScDocShellRef m_xDocShRef
;
88 BootstrapFixture::setUp();
91 m_xDocShRef
= new ScDocShell(
92 SfxModelFlags::EMBEDDED_OBJECT
|
93 SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS
|
94 SfxModelFlags::DISABLE_DOCUMENT_RECOVERY
);
96 m_pDoc
= &m_xDocShRef
->GetDocument();
102 BootstrapFixture::tearDown();
105 void Test::testDeleteArea_4Ranges()
107 ScRangeList
aList(ScRange(0,0,0,5,5,0));
108 aList
.DeleteArea(2,2,0,3,3,0);
110 CPPUNIT_ASSERT_EQUAL(aList
.size(), static_cast<size_t>(4));
111 for(SCCOL nCol
= 0; nCol
<= 5; ++nCol
)
113 for(SCROW nRow
= 0; nRow
<= 5; ++nRow
)
115 if((nCol
== 2 || nCol
== 3) && ( nRow
== 2 || nRow
== 3))
116 CPPUNIT_ASSERT(!aList
.In(ScRange(nCol
, nRow
, 0)));
118 CPPUNIT_ASSERT(aList
.In(ScRange(nCol
, nRow
, 0)));
123 void Test::testDeleteArea_3Ranges()
125 ScRangeList
aList(ScRange(1,1,0,6,6,0));
126 aList
.DeleteArea(3,3,0,8,4,0);
128 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aList
.size());
129 for(SCCOL nCol
= 1; nCol
<= 6; ++nCol
)
131 for(SCROW nRow
= 1; nRow
<= 6; ++nRow
)
133 if((nRow
== 3 || nRow
== 4) && (nCol
>= 3))
134 CPPUNIT_ASSERT(!aList
.In(ScRange(nCol
, nRow
, 0)));
136 CPPUNIT_ASSERT(aList
.In(ScRange(nCol
, nRow
, 0)));
140 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(28), aList
.GetCellCount());
143 void Test::testDeleteArea_3Ranges_Case2()
145 ScRangeList
aList(ScRange(1,1,0,6,6,0));
146 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aList
.size());
147 aList
.DeleteArea(0,2,0,2,4,0);
148 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aList
.size());
150 // Column 1-2 && Row 2-4 should not be in the range list. The rest should
152 for (SCCOL nCol
= 1; nCol
<= 6; ++nCol
)
154 for (SCROW nRow
= 1; nRow
<= 6; ++nRow
)
156 if ((1 <= nCol
&& nCol
<= 2) && (2 <= nRow
&& nRow
<= 4))
157 CPPUNIT_ASSERT(!aList
.In(ScRange(nCol
, nRow
, 0)));
159 CPPUNIT_ASSERT(aList
.In(ScRange(nCol
, nRow
, 0)));
164 void Test::testDeleteArea_3Ranges_Case3()
166 ScRangeList
aList(ScRange(1,5,0,6,11,0));
167 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aList
.size());
168 aList
.DeleteArea(3,2,0,4,8,0);
169 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aList
.size());
171 // Column 3-4 && Row 5-8 should not be in the range list.
172 for (SCCOL nCol
= 1; nCol
<= 6; ++nCol
)
174 for (SCROW nRow
= 5; nRow
<= 11; ++nRow
)
176 if ((3 <= nCol
&& nCol
<= 4) && (5 <= nRow
&& nRow
<= 8))
177 CPPUNIT_ASSERT(!aList
.In(ScRange(nCol
, nRow
, 0)));
179 CPPUNIT_ASSERT(aList
.In(ScRange(nCol
, nRow
, 0)));
184 void Test::testDeleteArea_3Ranges_Case4()
186 ScRangeList
aList(ScRange(1,5,0,6,11,0));
187 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aList
.size());
188 aList
.DeleteArea(3,5,0,4,5,0);
189 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aList
.size());
191 // Column 3-4 && Row 5 should not be in the range list.
192 for (SCCOL nCol
= 1; nCol
<= 6; ++nCol
)
194 for (SCROW nRow
= 5; nRow
<= 11; ++nRow
)
196 if ((3 <= nCol
&& nCol
<= 4) && 5 == nRow
)
197 CPPUNIT_ASSERT(!aList
.In(ScRange(nCol
, nRow
, 0)));
199 CPPUNIT_ASSERT(aList
.In(ScRange(nCol
, nRow
, 0)));
204 void Test::testDeleteArea_3Ranges_Case5()
206 ScRangeList
aList(ScRange(1,5,0,6,11,0));
207 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aList
.size());
208 aList
.DeleteArea(6,7,0,6,9,0);
209 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aList
.size());
211 // Column 6 && Row 7-9 should not be in the range list.
212 for (SCCOL nCol
= 1; nCol
<= 6; ++nCol
)
214 for (SCROW nRow
= 5; nRow
<= 11; ++nRow
)
216 if ( nCol
== 6 && (7 <= nRow
&& nRow
<= 9))
217 CPPUNIT_ASSERT(!aList
.In(ScRange(nCol
, nRow
, 0)));
219 CPPUNIT_ASSERT(aList
.In(ScRange(nCol
, nRow
, 0)));
224 void Test::testDeleteArea_2Ranges()
226 ScRangeList
aList(ScRange(0,0,0,5,5,5));
227 ScRangeList
aList2(aList
);
229 aList
.DeleteArea(4,4,0,6,7,0);
230 aList2
.DeleteArea(4,4,0,6,7,0);
231 CPPUNIT_ASSERT_EQUAL(aList
.size(), static_cast<size_t>(2));
232 CPPUNIT_ASSERT_EQUAL(aList2
.size(), static_cast<size_t>(2));
234 for(SCCOL nCol
= 0; nCol
<= 5; ++nCol
)
236 for(SCROW nRow
= 0; nRow
<= 5; ++nRow
)
238 if(nCol
>=4 && nRow
>= 4)
239 CPPUNIT_ASSERT(!aList
.In(ScRange(nCol
, nRow
, 0)));
241 CPPUNIT_ASSERT(aList
.In(ScRange(nCol
, nRow
, 0)));
246 void Test::testDeleteArea_2Ranges_Case2()
248 ScRangeList
aList(ScRange(1,1,0,1,5,0));
249 aList
.DeleteArea(0,3,0,MAXCOL
,3,0);
251 for(SCROW nRow
= 1; nRow
<= 5; ++nRow
)
254 CPPUNIT_ASSERT(!aList
.In(ScRange(1,3,0)));
256 CPPUNIT_ASSERT(aList
.In(ScRange(1,nRow
,0)));
258 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), aList
.GetCellCount());
261 void Test::testDeleteArea_2Ranges_Case3()
263 ScRangeList
aList(ScRange(0,5,0,2,10,0));
264 aList
.DeleteArea(2,3,0,3,7,0);
265 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aList
.size());
267 // Column 2 Row 5-7 shouldn't be in the list.
268 for (SCCOL nCol
= 0; nCol
<= 2; ++nCol
)
270 for (SCROW nRow
= 5; nRow
<= 10; ++nRow
)
272 if (nCol
== 2 && (5 <= nRow
&& nRow
<= 7))
273 CPPUNIT_ASSERT(!aList
.In(ScRange(nCol
,nRow
,0)));
275 CPPUNIT_ASSERT(aList
.In(ScRange(nCol
,nRow
,0)));
280 void Test::testDeleteArea_2Ranges_Case4()
282 ScRangeList
aList(ScRange(2,3,0,4,7,0));
283 aList
.DeleteArea(0,1,0,2,5,0);
284 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aList
.size());
286 // Column 2 Row 3-5 shouldn't be in the list.
287 for (SCCOL nCol
= 2; nCol
<= 4; ++nCol
)
289 for (SCROW nRow
= 3; nRow
<= 7; ++nRow
)
291 if (nCol
== 2 && (3 <= nRow
&& nRow
<= 5))
292 CPPUNIT_ASSERT(!aList
.In(ScRange(nCol
,nRow
,0)));
294 CPPUNIT_ASSERT(aList
.In(ScRange(nCol
,nRow
,0)));
299 void Test::testDeleteArea_2Ranges_Case5()
301 ScRangeList
aList(ScRange(2,2,0,5,5,0));
302 aList
.DeleteArea(4,5,0,5,5,0);
303 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aList
.size());
305 // Column 4 and 5 Row 5 shouldn't be in the list.
306 for(SCCOL nCol
= 2; nCol
<= 5; ++nCol
)
308 for(SCROW nRow
= 2; nRow
<= 5; ++nRow
)
310 if(nRow
== 5 && 4 <= nCol
)
311 CPPUNIT_ASSERT(!aList
.In(ScRange(nCol
, nRow
, 0)));
313 CPPUNIT_ASSERT(aList
.In(ScRange(nCol
, nRow
, 0)));
318 void Test::testDeleteArea_2Ranges_Case6()
320 ScRangeList
aList(ScRange(2,2,0,5,5,0));
321 aList
.DeleteArea(4,2,0,5,2,0);
322 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aList
.size());
324 // Column 4 and 5 Row 2 shouldn't be in the list.
325 for(SCCOL nCol
= 2; nCol
<= 5; ++nCol
)
327 for(SCROW nRow
= 2; nRow
<= 5; ++nRow
)
329 if(nRow
== 2 && 4 <= nCol
)
330 CPPUNIT_ASSERT(!aList
.In(ScRange(nCol
, nRow
, 0)));
332 CPPUNIT_ASSERT(aList
.In(ScRange(nCol
, nRow
, 0)));
337 void Test::testDeleteArea_2Ranges_Case7()
339 ScRangeList
aList(ScRange(2,2,0,5,5,0));
340 aList
.DeleteArea(2,5,0,2,5,0);
341 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aList
.size());
343 // Column 2 Row 5 shouldn't be in the list.
344 for(SCCOL nCol
= 2; nCol
<= 5; ++nCol
)
346 for(SCROW nRow
= 2; nRow
<= 5; ++nRow
)
348 if(nRow
== 5 && nCol
== 2)
349 CPPUNIT_ASSERT(!aList
.In(ScRange(nCol
, nRow
, 0)));
351 CPPUNIT_ASSERT(aList
.In(ScRange(nCol
, nRow
, 0)));
356 void Test::testDeleteArea_2Ranges_Case8()
358 ScRangeList
aList(ScRange(2,2,0,5,5,0));
359 aList
.DeleteArea(2,2,0,3,2,0);
360 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), aList
.size());
362 // Column 2 & 3 Row 2 shouldn't be in the list.
363 for(SCCOL nCol
= 2; nCol
<= 5; ++nCol
)
365 for(SCROW nRow
= 2; nRow
<= 5; ++nRow
)
367 if(nRow
== 2 && nCol
<= 3)
368 CPPUNIT_ASSERT(!aList
.In(ScRange(nCol
, nRow
, 0)));
370 CPPUNIT_ASSERT(aList
.In(ScRange(nCol
, nRow
, 0)));
375 void Test::testDeleteArea_1Range()
377 ScRangeList
aList(ScRange(1,1,0,3,3,0));
378 aList
.DeleteArea(1,1,0,2,3,0);
380 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aList
.size());
382 for(SCROW nRow
= 1; nRow
<= 3; ++nRow
)
384 CPPUNIT_ASSERT(aList
.In(ScRange(3,nRow
,0)));
386 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aList
.GetCellCount());
389 void Test::testDeleteArea_0Ranges()
391 ScRangeList
aList(ScRange(1,1,0,3,3,0));
392 aList
.DeleteArea(1,1,0,3,3,0);
394 CPPUNIT_ASSERT(aList
.empty());
396 ScRangeList
aList2(ScRange(1,1,0,3,3,0));
397 aList2
.DeleteArea(0,0,0,4,4,0);
399 CPPUNIT_ASSERT(aList
.empty());
402 void Test::testJoin_Case1()
405 aList
.push_back(new ScRange(1,1,0,3,3,0));
406 aList
.Join(ScRange(4,1,0,6,3,0));
408 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aList
.size());
409 CPPUNIT_ASSERT( ScRange(1,1,0,6,3,0) == *aList
[0]);
412 void Test::testJoin_Case2()
415 aList
.push_back(new ScRange(1,1,0,3,3,0));
416 aList
.push_back(new ScRange(4,1,0,6,3,0));
417 aList
.push_back(new ScRange(7,1,0,9,3,0));
419 aList
.Join(*aList
[2], true);
421 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aList
.size());
422 CPPUNIT_ASSERT(ScRange(1,1,0,9,3,0) == *aList
[0]);
425 void Test::testUpdateReference_DeleteRow()
427 ScRangeList
aList(ScRange(1,1,0,4,4,0));
428 bool bUpdated
= aList
.UpdateReference(URM_INSDEL
, m_pDoc
, ScRange(0,3,0,MAXCOL
,MAXROW
,0), 0, -1, 0);
429 CPPUNIT_ASSERT(bUpdated
);
431 for(SCCOL nCol
= 1; nCol
<= 4; ++nCol
)
433 for(SCROW nRow
= 1; nRow
<= 3; ++nRow
)
435 CPPUNIT_ASSERT(aList
.In(ScRange(nCol
, nRow
, 0)));
437 CPPUNIT_ASSERT(!aList
.In(ScRange(nCol
, 4, 0)));
439 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(12), aList
.GetCellCount());
441 ScRangeList
aList2(ScRange(2,2,0,2,2,0));
442 aList2
.UpdateReference(URM_INSDEL
, m_pDoc
, ScRange(0,3,0,MAXCOL
,MAXROW
,0), 0, -1, 0);
443 CPPUNIT_ASSERT(aList2
.empty());
446 void Test::testUpdateReference_DeleteCol()
448 ScRangeList
aList(ScRange(1,1,0,4,4,0));
449 bool bUpdated
= aList
.UpdateReference(URM_INSDEL
, m_pDoc
, ScRange(3,0,0,MAXCOL
,MAXROW
,0), -1, 0, 0);
450 CPPUNIT_ASSERT(bUpdated
);
452 for(SCROW nRow
= 1; nRow
<= 4; ++nRow
)
454 for(SCCOL nCol
= 1; nCol
<= 3; ++nCol
)
456 CPPUNIT_ASSERT(aList
.In(ScRange(nCol
, nRow
, 0)));
458 CPPUNIT_ASSERT(!aList
.In(ScRange(4, nRow
, 0)));
460 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(12), aList
.GetCellCount());
463 void Test::testGetIntersectedRange()
465 ScRangeList
aList(ScRange(2, 2, 0, 5, 5, 0));
466 ScRangeList aIntersecting
= aList
.GetIntersectedRange(ScRange(0, 0, 0, 3, 3, 0));
467 CPPUNIT_ASSERT_EQUAL(ScRangeList(ScRange(2,2,0,3,3,0)), aIntersecting
);
470 void Test::testInsertRow()
472 ScRangeList
aList(ScRange(1,1,0,4,4,0));
473 aList
.InsertRow(0, 0, MAXCOL
, 5, 2);
474 CPPUNIT_ASSERT_EQUAL(ScRangeList(ScRange(1,1,0,4,6,0)), aList
);
477 void Test::testInsertCol()
479 ScRangeList
aList(ScRange(1,1,0,4,4,0));
480 aList
.InsertCol(0, 0, MAXROW
, 5, 2);
481 CPPUNIT_ASSERT_EQUAL(ScRangeList(ScRange(1,1,0,6,4,0)), aList
);
484 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
486 CPPUNIT_PLUGIN_IMPLEMENT();
487 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */