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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
/* -*- 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 <test/bootstrapfixture.hxx>
#include <EditLineList.hxx>
namespace
{
class EditLineListTest : public test::BootstrapFixture
{
};
CPPUNIT_TEST_FIXTURE(EditLineListTest, testConstruction)
{
EditLineList aNewList;
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewList.Count());
}
CPPUNIT_TEST_FIXTURE(EditLineListTest, testAppendAndInsert)
{
// Test case:
// Append EditLine1
// Append EditLine3
// Insert EditLine2 in-between EditLine1 and pEditLine3
EditLineList aNewList;
EditLine* pEditLine1 = new EditLine;
EditLine* pEditLine2 = new EditLine;
EditLine* pEditLine3 = new EditLine;
aNewList.Append(std::unique_ptr<EditLine>(pEditLine1));
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewList.Count());
aNewList.Append(std::unique_ptr<EditLine>(pEditLine3));
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewList.Count());
CPPUNIT_ASSERT_EQUAL(pEditLine1, &aNewList[0]);
CPPUNIT_ASSERT_EQUAL(pEditLine3, &aNewList[1]);
aNewList.Insert(1, std::unique_ptr<EditLine>(pEditLine2));
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aNewList.Count());
CPPUNIT_ASSERT_EQUAL(pEditLine1, &aNewList[0]);
CPPUNIT_ASSERT_EQUAL(pEditLine2, &aNewList[1]);
CPPUNIT_ASSERT_EQUAL(pEditLine3, &aNewList[2]);
}
CPPUNIT_TEST_FIXTURE(EditLineListTest, testReset)
{
EditLineList aNewList;
aNewList.Append(std::make_unique<EditLine>());
aNewList.Append(std::make_unique<EditLine>());
aNewList.Append(std::make_unique<EditLine>());
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aNewList.Count());
aNewList.Reset();
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewList.Count());
}
CPPUNIT_TEST_FIXTURE(EditLineListTest, testDeleteFrom)
{
EditLineList aNewList;
aNewList.Append(std::make_unique<EditLine>());
aNewList.Append(std::make_unique<EditLine>());
aNewList.Append(std::make_unique<EditLine>());
aNewList.Append(std::make_unique<EditLine>());
aNewList.Append(std::make_unique<EditLine>());
aNewList[0].SetStart(10);
aNewList[1].SetStart(11);
aNewList[2].SetStart(12);
aNewList[3].SetStart(13);
aNewList[4].SetStart(14);
CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aNewList.Count());
aNewList.DeleteFromLine(2);
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewList.Count());
CPPUNIT_ASSERT_EQUAL(sal_Int32(10), aNewList[0].GetStart());
CPPUNIT_ASSERT_EQUAL(sal_Int32(11), aNewList[1].GetStart());
aNewList.Append(std::make_unique<EditLine>());
aNewList.Append(std::make_unique<EditLine>());
aNewList.Append(std::make_unique<EditLine>());
aNewList.Append(std::make_unique<EditLine>());
aNewList[2].SetStart(15);
aNewList[3].SetStart(16);
aNewList[4].SetStart(17);
aNewList[5].SetStart(18);
CPPUNIT_ASSERT_EQUAL(sal_Int32(6), aNewList.Count());
CPPUNIT_ASSERT_EQUAL(sal_Int32(10), aNewList[0].GetStart());
CPPUNIT_ASSERT_EQUAL(sal_Int32(11), aNewList[1].GetStart());
CPPUNIT_ASSERT_EQUAL(sal_Int32(15), aNewList[2].GetStart());
CPPUNIT_ASSERT_EQUAL(sal_Int32(16), aNewList[3].GetStart());
CPPUNIT_ASSERT_EQUAL(sal_Int32(17), aNewList[4].GetStart());
CPPUNIT_ASSERT_EQUAL(sal_Int32(18), aNewList[5].GetStart());
aNewList.DeleteFromLine(4);
CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aNewList.Count());
CPPUNIT_ASSERT_EQUAL(sal_Int32(10), aNewList[0].GetStart());
CPPUNIT_ASSERT_EQUAL(sal_Int32(11), aNewList[1].GetStart());
CPPUNIT_ASSERT_EQUAL(sal_Int32(15), aNewList[2].GetStart());
CPPUNIT_ASSERT_EQUAL(sal_Int32(16), aNewList[3].GetStart());
}
CPPUNIT_TEST_FIXTURE(EditLineListTest, testFindLine)
{
EditLineList aNewList;
EditLine* pEditLine1 = new EditLine;
pEditLine1->SetStart(0);
pEditLine1->SetEnd(10);
aNewList.Append(std::unique_ptr<EditLine>(pEditLine1));
EditLine* pEditLine2 = new EditLine;
pEditLine2->SetStart(10);
pEditLine2->SetEnd(20);
aNewList.Append(std::unique_ptr<EditLine>(pEditLine2));
EditLine* pEditLine3 = new EditLine;
pEditLine3->SetStart(20);
pEditLine3->SetEnd(30);
aNewList.Append(std::unique_ptr<EditLine>(pEditLine3));
// Exclude end
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewList.FindLine(-1, false));
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewList.FindLine(0, false));
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewList.FindLine(5, false));
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewList.FindLine(9, false));
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewList.FindLine(10, false));
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewList.FindLine(15, false));
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewList.FindLine(19, false));
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewList.FindLine(20, false));
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewList.FindLine(25, false));
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewList.FindLine(30, false));
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewList.FindLine(31, false));
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewList.FindLine(10000, false));
// Include end
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewList.FindLine(-1, true));
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewList.FindLine(0, true));
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewList.FindLine(5, true));
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewList.FindLine(9, true));
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aNewList.FindLine(10, true));
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewList.FindLine(15, true));
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewList.FindLine(19, true));
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aNewList.FindLine(20, true));
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewList.FindLine(25, true));
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewList.FindLine(30, true));
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewList.FindLine(31, true));
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aNewList.FindLine(10000, true));
}
} // end anonymous namespace
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|