1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <sal/config.h>
#include <test/bootstrapfixture.hxx>
#include "document.hxx"
#include "docsh.hxx"
#include "rangelst.hxx"
class Test : public test::BootstrapFixture {
public:
virtual void setUp();
virtual void tearDown();
void testDeleteArea_4Ranges();
void testDeleteArea_2Ranges();
void testDeleteArea_0Ranges();
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(testDeleteArea_4Ranges);
CPPUNIT_TEST(testDeleteArea_2Ranges);
CPPUNIT_TEST(testDeleteArea_0Ranges);
CPPUNIT_TEST_SUITE_END();
private:
ScDocument *m_pDoc;
ScDocShellRef m_xDocShRef;
};
void Test::setUp()
{
BootstrapFixture::setUp();
ScDLL::Init();
m_xDocShRef = new ScDocShell(
SFXMODEL_STANDARD |
SFXMODEL_DISABLE_EMBEDDED_SCRIPTS |
SFXMODEL_DISABLE_DOCUMENT_RECOVERY);
m_pDoc = m_xDocShRef->GetDocument();
}
void Test::tearDown()
{
m_xDocShRef.Clear();
BootstrapFixture::tearDown();
}
void Test::testDeleteArea_4Ranges()
{
ScRangeList aList(ScRange(0,0,0,5,5,0));
aList.DeleteArea(2,2,0,3,3,0);
CPPUNIT_ASSERT_EQUAL(aList.size(), static_cast<size_t>(4));
for(SCCOL nCol = 0; nCol <= 5; ++nCol)
{
for(SCROW nRow = 0; nRow <= 5; ++nRow)
{
if((nCol == 2 || nCol == 3) && ( nRow == 2 || nRow == 3))
CPPUNIT_ASSERT(!aList.Intersects(ScRange(nCol, nRow, 0)));
else
CPPUNIT_ASSERT(aList.Intersects(ScRange(nCol, nRow, 0)));
}
}
}
void Test::testDeleteArea_2Ranges()
{
ScRangeList aList(ScRange(0,0,0,5,5,5));
ScRangeList aList2(aList);
aList.DeleteArea(4,4,0,6,7,0);
aList2.DeleteArea(4,4,0,6,7,0);
CPPUNIT_ASSERT_EQUAL(aList.size(), static_cast<size_t>(2));
CPPUNIT_ASSERT_EQUAL(aList2.size(), static_cast<size_t>(2));
for(SCCOL nCol = 0; nCol <= 5; ++nCol)
{
for(SCROW nRow = 0; nRow <= 5; ++nRow)
{
if(nCol>=4 && nRow >= 4)
CPPUNIT_ASSERT(!aList.Intersects(ScRange(nCol, nRow, 0)));
else
CPPUNIT_ASSERT(aList.Intersects(ScRange(nCol, nRow, 0)));
}
}
}
void Test::testDeleteArea_0Ranges()
{
ScRangeList aList(ScRange(1,1,0,3,3,0));
aList.DeleteArea(1,1,0,3,3,0);
CPPUNIT_ASSERT(aList.empty());
ScRangeList aList2(ScRange(1,1,0,3,3,0));
aList2.DeleteArea(0,0,0,4,4,0);
CPPUNIT_ASSERT(aList.empty());
}
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|