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
|
/* -*- 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 <rtl/ustring.hxx>
#include "helper/qahelper.hxx"
#include "document.hxx"
#include <stringutil.hxx>
#include "address.hxx"
#include "dataprovider.hxx"
#include "datatransformation.hxx"
#include <vcl/scheduler.hxx>
#include <memory>
class ScDataTransformationTest : public ScBootstrapFixture
{
public:
ScDataTransformationTest();
virtual void setUp() override;
virtual void tearDown() override;
void testColumnRemove();
void testColumnSplit();
void testColumnMerge();
CPPUNIT_TEST_SUITE(ScDataTransformationTest);
CPPUNIT_TEST(testColumnRemove);
CPPUNIT_TEST(testColumnSplit);
CPPUNIT_TEST(testColumnMerge);
CPPUNIT_TEST_SUITE_END();
private:
ScDocShellRef m_xDocShell;
ScDocument *m_pDoc;
};
void ScDataTransformationTest::testColumnRemove()
{
for (SCROW nRow = 0; nRow < 10; ++nRow)
{
for (SCCOL nCol = 0; nCol < 10; ++nCol)
{
m_pDoc->SetValue(nCol, nRow, 0, nRow*nCol);
}
}
sc::ColumnRemoveTransformation aTransformation(5);
aTransformation.Transform(*m_pDoc);
for (SCROW nRow = 0; nRow < 10; ++nRow)
{
for (SCCOL nCol = 0; nCol < 9; ++nCol)
{
double nVal = m_pDoc->GetValue(nCol, nRow, 0);
if (nCol < 5)
{
ASSERT_DOUBLES_EQUAL((double)(nCol)*nRow, nVal);
}
else
{
ASSERT_DOUBLES_EQUAL((double)(nCol+1)*nRow, nVal);
}
}
}
}
void ScDataTransformationTest::testColumnSplit()
{
m_pDoc->SetString(2, 0, 0, "Test1,Test2");
m_pDoc->SetString(2, 1, 0, "Test1,");
m_pDoc->SetString(2, 2, 0, ",Test1");
m_pDoc->SetString(2, 3, 0, "Test1,Test2,Test3");
m_pDoc->SetString(3, 0, 0, "AnotherString");
sc::SplitColumnTransformation aTransform(2, ',');
aTransform.Transform(*m_pDoc);
CPPUNIT_ASSERT_EQUAL(OUString("AnotherString"), m_pDoc->GetString(4, 0, 0));
CPPUNIT_ASSERT_EQUAL(OUString("Test1"), m_pDoc->GetString(2, 0, 0));
CPPUNIT_ASSERT_EQUAL(OUString("Test1"), m_pDoc->GetString(2, 1, 0));
CPPUNIT_ASSERT_EQUAL(OUString(""), m_pDoc->GetString(2, 2, 0));
CPPUNIT_ASSERT_EQUAL(OUString("Test1"), m_pDoc->GetString(2, 3, 0));
CPPUNIT_ASSERT_EQUAL(OUString("Test2"), m_pDoc->GetString(3, 0, 0));
CPPUNIT_ASSERT_EQUAL(OUString(""), m_pDoc->GetString(3, 1, 0));
CPPUNIT_ASSERT_EQUAL(OUString("Test1"), m_pDoc->GetString(3, 2, 0));
CPPUNIT_ASSERT_EQUAL(OUString("Test2,Test3"), m_pDoc->GetString(3, 3, 0));
}
void ScDataTransformationTest::testColumnMerge()
{
m_pDoc->SetString(2, 0, 0, "Berlin");
m_pDoc->SetString(2, 1, 0, "Brussels");
m_pDoc->SetString(2, 2, 0, "Paris");
m_pDoc->SetString(2, 3, 0, "Peking");
m_pDoc->SetString(4, 0, 0, "Germany");
m_pDoc->SetString(4, 1, 0, "Belgium");
m_pDoc->SetString(4, 2, 0, "France");
m_pDoc->SetString(4, 3, 0, "China");
sc::MergeColumnTransformation aTransform(2, 4, ", ");
aTransform.Transform(*m_pDoc);
CPPUNIT_ASSERT_EQUAL(OUString("Berlin, Germany"), m_pDoc->GetString(2, 0, 0));
CPPUNIT_ASSERT_EQUAL(OUString("Brussels, Belgium"), m_pDoc->GetString(2, 1, 0));
CPPUNIT_ASSERT_EQUAL(OUString("Paris, France"), m_pDoc->GetString(2, 2, 0));
CPPUNIT_ASSERT_EQUAL(OUString("Peking, China"), m_pDoc->GetString(2, 3, 0));
for (SCROW nRow = 0; nRow <= 3; ++nRow)
{
CPPUNIT_ASSERT(m_pDoc->GetString(4, nRow, 0).isEmpty());
}
}
ScDataTransformationTest::ScDataTransformationTest() :
ScBootstrapFixture( "sc/qa/unit/data/dataprovider" ),
m_pDoc(nullptr)
{
}
void ScDataTransformationTest::setUp()
{
ScBootstrapFixture::setUp();
ScDLL::Init();
m_xDocShell = new ScDocShell(
SfxModelFlags::EMBEDDED_OBJECT |
SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS |
SfxModelFlags::DISABLE_DOCUMENT_RECOVERY);
m_xDocShell->SetIsInUcalc();
m_xDocShell->DoInitUnitTest();
m_pDoc = &m_xDocShell->GetDocument();
m_pDoc->InsertTab(0, "Tab");
}
void ScDataTransformationTest::tearDown()
{
m_xDocShell->DoClose();
m_xDocShell.clear();
ScBootstrapFixture::tearDown();
}
CPPUNIT_TEST_SUITE_REGISTRATION(ScDataTransformationTest);
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|