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 <rtl/ustring.hxx>
12 #include "helper/qahelper.hxx"
13 #include <document.hxx>
14 #include <datatransformation.hxx>
15 #include <svl/numformat.hxx>
16 #include <tools/time.hxx>
18 class ScDataTransformationTest
: public ScUcalcTestBase
22 virtual void setUp() override
;
24 void testColumnRemove();
25 void testColumnSplit();
26 void testColumnMerge();
27 void testTextToLower();
28 void testTextToUpper();
29 void testTextCapitalize();
31 void testAggregateSum();
32 void testAggregateAverage();
33 void testAggregateMin();
34 void testAggregateMax();
35 void testNumberRound();
36 void testNumberRoundUp();
37 void testNumberRoundDown();
38 void testNumberAbsolute();
39 void testNumberLogE();
40 void testNumberLog10();
41 void testNumberCube();
42 void testNumberSquare();
43 void testNumberSquareRoot();
44 void testNumberEven();
46 void testNumberSign();
47 void testReplaceNull();
48 void testGetDateString();
50 void testGetStartOfYear();
51 void testGetEndOfYear();
53 void testGetMonthName();
54 void testGetStartOfMonth();
55 void testGetEndOfMonth();
57 void testGetDayOfWeek();
58 void testGetDayOfYear();
59 void testGetQuarter();
60 void testGetStartOfQuarter();
61 void testGetEndOfQuarter();
67 CPPUNIT_TEST_SUITE(ScDataTransformationTest
);
68 CPPUNIT_TEST(testColumnRemove
);
69 CPPUNIT_TEST(testColumnSplit
);
70 CPPUNIT_TEST(testColumnMerge
);
71 CPPUNIT_TEST(testTextToLower
);
72 CPPUNIT_TEST(testTextToUpper
);
73 CPPUNIT_TEST(testTextCapitalize
);
74 CPPUNIT_TEST(testTextTrim
);
75 CPPUNIT_TEST(testAggregateSum
);
76 CPPUNIT_TEST(testAggregateAverage
);
77 CPPUNIT_TEST(testAggregateMin
);
78 CPPUNIT_TEST(testAggregateMax
);
79 CPPUNIT_TEST(testNumberRound
);
80 CPPUNIT_TEST(testNumberRoundUp
);
81 CPPUNIT_TEST(testNumberRoundDown
);
82 CPPUNIT_TEST(testNumberAbsolute
);
83 CPPUNIT_TEST(testNumberLogE
);
84 CPPUNIT_TEST(testNumberLog10
);
85 CPPUNIT_TEST(testNumberCube
);
86 CPPUNIT_TEST(testNumberSquare
);
87 CPPUNIT_TEST(testNumberSquareRoot
);
88 CPPUNIT_TEST(testNumberEven
);
89 CPPUNIT_TEST(testNumberOdd
);
90 CPPUNIT_TEST(testNumberSign
);
91 CPPUNIT_TEST(testReplaceNull
);
92 CPPUNIT_TEST(testGetDateString
);
93 CPPUNIT_TEST(testGetYear
);
94 CPPUNIT_TEST(testGetStartOfYear
);
95 CPPUNIT_TEST(testGetEndOfYear
);
96 CPPUNIT_TEST(testGetMonth
);
97 CPPUNIT_TEST(testGetMonthName
);
98 CPPUNIT_TEST(testGetStartOfMonth
);
99 CPPUNIT_TEST(testGetEndOfMonth
);
100 CPPUNIT_TEST(testGetDay
);
101 CPPUNIT_TEST(testGetDayOfWeek
);
102 CPPUNIT_TEST(testGetDayOfYear
);
103 CPPUNIT_TEST(testGetQuarter
);
104 CPPUNIT_TEST(testGetStartOfQuarter
);
105 CPPUNIT_TEST(testGetEndOfQuarter
);
106 CPPUNIT_TEST(testGetTime
);
107 CPPUNIT_TEST(testGetHour
);
108 CPPUNIT_TEST(testGetMinute
);
109 CPPUNIT_TEST(testGetSecond
);
110 CPPUNIT_TEST_SUITE_END();
113 void ScDataTransformationTest::testColumnRemove()
115 for (SCROW nRow
= 0; nRow
< 10; ++nRow
)
117 for (SCCOL nCol
= 0; nCol
< 10; ++nCol
)
119 m_pDoc
->SetValue(nCol
, nRow
, 0, nRow
*nCol
);
123 sc::ColumnRemoveTransformation
aTransformation({5});
124 aTransformation
.Transform(*m_pDoc
);
126 for (SCROW nRow
= 0; nRow
< 10; ++nRow
)
128 for (SCCOL nCol
= 0; nCol
< 9; ++nCol
)
130 double nVal
= m_pDoc
->GetValue(nCol
, nRow
, 0);
133 ASSERT_DOUBLES_EQUAL(static_cast<double>(nCol
)*nRow
, nVal
);
137 ASSERT_DOUBLES_EQUAL(static_cast<double>(nCol
+1)*nRow
, nVal
);
143 void ScDataTransformationTest::testColumnSplit()
145 m_pDoc
->SetString(2, 0, 0, "Test1,Test2");
146 m_pDoc
->SetString(2, 1, 0, "Test1,");
147 m_pDoc
->SetString(2, 2, 0, ",Test1");
148 m_pDoc
->SetString(2, 3, 0, "Test1,Test2,Test3");
149 m_pDoc
->SetString(3, 0, 0, "AnotherString");
151 sc::SplitColumnTransformation
aTransform(2, ',');
152 aTransform
.Transform(*m_pDoc
);
154 CPPUNIT_ASSERT_EQUAL(OUString("AnotherString"), m_pDoc
->GetString(4, 0, 0));
156 CPPUNIT_ASSERT_EQUAL(OUString("Test1"), m_pDoc
->GetString(2, 0, 0));
157 CPPUNIT_ASSERT_EQUAL(OUString("Test1"), m_pDoc
->GetString(2, 1, 0));
158 CPPUNIT_ASSERT_EQUAL(OUString(""), m_pDoc
->GetString(2, 2, 0));
159 CPPUNIT_ASSERT_EQUAL(OUString("Test1"), m_pDoc
->GetString(2, 3, 0));
161 CPPUNIT_ASSERT_EQUAL(OUString("Test2"), m_pDoc
->GetString(3, 0, 0));
162 CPPUNIT_ASSERT_EQUAL(OUString(""), m_pDoc
->GetString(3, 1, 0));
163 CPPUNIT_ASSERT_EQUAL(OUString("Test1"), m_pDoc
->GetString(3, 2, 0));
164 CPPUNIT_ASSERT_EQUAL(OUString("Test2,Test3"), m_pDoc
->GetString(3, 3, 0));
167 void ScDataTransformationTest::testColumnMerge()
169 m_pDoc
->SetString(2, 0, 0, "Berlin");
170 m_pDoc
->SetString(2, 1, 0, "Brussels");
171 m_pDoc
->SetString(2, 2, 0, "Paris");
172 m_pDoc
->SetString(2, 3, 0, "Peking");
174 m_pDoc
->SetString(4, 0, 0, "Germany");
175 m_pDoc
->SetString(4, 1, 0, "Belgium");
176 m_pDoc
->SetString(4, 2, 0, "France");
177 m_pDoc
->SetString(4, 3, 0, "China");
179 sc::MergeColumnTransformation
aTransform({2, 4}, ", ");
180 aTransform
.Transform(*m_pDoc
);
182 CPPUNIT_ASSERT_EQUAL(OUString("Berlin, Germany"), m_pDoc
->GetString(2, 0, 0));
183 CPPUNIT_ASSERT_EQUAL(OUString("Brussels, Belgium"), m_pDoc
->GetString(2, 1, 0));
184 CPPUNIT_ASSERT_EQUAL(OUString("Paris, France"), m_pDoc
->GetString(2, 2, 0));
185 CPPUNIT_ASSERT_EQUAL(OUString("Peking, China"), m_pDoc
->GetString(2, 3, 0));
187 for (SCROW nRow
= 0; nRow
<= 3; ++nRow
)
189 CPPUNIT_ASSERT(m_pDoc
->GetString(4, nRow
, 0).isEmpty());
193 void ScDataTransformationTest::testTextToLower()
195 m_pDoc
->SetString(2, 0, 0, "Berlin");
196 m_pDoc
->SetString(2, 1, 0, "Brussels");
197 m_pDoc
->SetString(2, 2, 0, "Paris");
198 m_pDoc
->SetString(2, 3, 0, "Peking");
200 sc::TextTransformation
aTransform({2}, sc::TEXT_TRANSFORM_TYPE::TO_LOWER
);
201 aTransform
.Transform(*m_pDoc
);
203 CPPUNIT_ASSERT_EQUAL(OUString("berlin"), m_pDoc
->GetString(2, 0, 0));
204 CPPUNIT_ASSERT_EQUAL(OUString("brussels"), m_pDoc
->GetString(2, 1, 0));
205 CPPUNIT_ASSERT_EQUAL(OUString("paris"), m_pDoc
->GetString(2, 2, 0));
206 CPPUNIT_ASSERT_EQUAL(OUString("peking"), m_pDoc
->GetString(2, 3, 0));
209 void ScDataTransformationTest::testTextToUpper()
211 m_pDoc
->SetString(2, 0, 0, "Berlin");
212 m_pDoc
->SetString(2, 1, 0, "Brussels");
213 m_pDoc
->SetString(2, 2, 0, "Paris");
214 m_pDoc
->SetString(2, 3, 0, "Peking");
216 sc::TextTransformation
aTransform({2}, sc::TEXT_TRANSFORM_TYPE::TO_UPPER
);
217 aTransform
.Transform(*m_pDoc
);
219 CPPUNIT_ASSERT_EQUAL(OUString("BERLIN"), m_pDoc
->GetString(2, 0, 0));
220 CPPUNIT_ASSERT_EQUAL(OUString("BRUSSELS"), m_pDoc
->GetString(2, 1, 0));
221 CPPUNIT_ASSERT_EQUAL(OUString("PARIS"), m_pDoc
->GetString(2, 2, 0));
222 CPPUNIT_ASSERT_EQUAL(OUString("PEKING"), m_pDoc
->GetString(2, 3, 0));
225 void ScDataTransformationTest::testTextCapitalize()
227 m_pDoc
->SetString(2, 0, 0, "hello woRlD");
228 m_pDoc
->SetString(2, 1, 0, "qUe vA");
229 m_pDoc
->SetString(2, 2, 0, "si tu la ves");
230 m_pDoc
->SetString(2, 3, 0, "cUaNdO mE EnAmOro");
232 sc::TextTransformation
aTransform({2}, sc::TEXT_TRANSFORM_TYPE::CAPITALIZE
);
233 aTransform
.Transform(*m_pDoc
);
235 CPPUNIT_ASSERT_EQUAL(OUString("Hello World"), m_pDoc
->GetString(2, 0, 0));
236 CPPUNIT_ASSERT_EQUAL(OUString("Que Va"), m_pDoc
->GetString(2, 1, 0));
237 CPPUNIT_ASSERT_EQUAL(OUString("Si Tu La Ves"), m_pDoc
->GetString(2, 2, 0));
238 CPPUNIT_ASSERT_EQUAL(OUString("Cuando Me Enamoro"), m_pDoc
->GetString(2, 3, 0));
241 void ScDataTransformationTest::testTextTrim()
243 m_pDoc
->SetString(2, 0, 0, " Berlin");
244 m_pDoc
->SetString(2, 1, 0, "Brussels ");
245 m_pDoc
->SetString(2, 2, 0, " Paris ");
247 sc::TextTransformation
aTransform({2}, sc::TEXT_TRANSFORM_TYPE::TRIM
);
248 aTransform
.Transform(*m_pDoc
);
250 CPPUNIT_ASSERT_EQUAL(OUString("Berlin"), m_pDoc
->GetString(2, 0, 0));
251 CPPUNIT_ASSERT_EQUAL(OUString("Brussels"), m_pDoc
->GetString(2, 1, 0));
252 CPPUNIT_ASSERT_EQUAL(OUString("Paris"), m_pDoc
->GetString(2, 2, 0));
255 void ScDataTransformationTest::testAggregateSum()
257 m_pDoc
->SetValue(2, 0, 0, 2034);
258 m_pDoc
->SetValue(2, 1, 0, 2342);
259 m_pDoc
->SetValue(2, 2, 0, 57452);
261 m_pDoc
->SetValue(4, 0, 0, 4829.98);
262 m_pDoc
->SetValue(4, 1, 0, 53781.3);
263 m_pDoc
->SetValue(4, 2, 0, 9876.4);
264 m_pDoc
->SetValue(4, 3, 0, 0);
266 sc::AggregateFunction
aTransform({2, 4}, sc::AGGREGATE_FUNCTION::SUM
);
267 aTransform
.Transform(*m_pDoc
);
269 CPPUNIT_ASSERT_DOUBLES_EQUAL(61828, m_pDoc
->GetValue(2, 4, 0), 1e-10);
270 CPPUNIT_ASSERT_DOUBLES_EQUAL(68487.68, m_pDoc
->GetValue(4, 4, 0), 1e-10);
273 void ScDataTransformationTest::testAggregateAverage()
275 m_pDoc
->SetValue(2, 0, 0, 2034);
276 m_pDoc
->SetValue(2, 1, 0, 2342);
277 m_pDoc
->SetValue(2, 2, 0, 57453);
279 m_pDoc
->SetValue(3, 0, 0, 4);
280 m_pDoc
->SetValue(3, 1, 0, 4);
281 m_pDoc
->SetValue(3, 2, 0, 4);
283 sc::AggregateFunction
aTransform({2, 3}, sc::AGGREGATE_FUNCTION::AVERAGE
);
284 aTransform
.Transform(*m_pDoc
);
286 CPPUNIT_ASSERT_DOUBLES_EQUAL(20609.6666666667, m_pDoc
->GetValue(2, 3, 0), 1e-10);
287 CPPUNIT_ASSERT_DOUBLES_EQUAL(4, m_pDoc
->GetValue(3, 3, 0), 1e-10);
290 void ScDataTransformationTest::testAggregateMin()
292 m_pDoc
->SetValue(2, 0, 0, 2034);
293 m_pDoc
->SetValue(2, 1, 0, 2342);
294 m_pDoc
->SetValue(2, 2, 0, 57453);
296 m_pDoc
->SetValue(3, 0, 0, 2034);
297 m_pDoc
->SetValue(3, 1, 0, -2342);
298 m_pDoc
->SetValue(3, 2, 0, 57453);
300 sc::AggregateFunction
aTransform({2, 3}, sc::AGGREGATE_FUNCTION::MIN
);
301 aTransform
.Transform(*m_pDoc
);
303 CPPUNIT_ASSERT_DOUBLES_EQUAL(2034, m_pDoc
->GetValue(2, 3, 0), 1e-10);
304 CPPUNIT_ASSERT_DOUBLES_EQUAL(-2342, m_pDoc
->GetValue(3, 3, 0), 1e-10);
307 void ScDataTransformationTest::testAggregateMax()
309 m_pDoc
->SetValue(2, 0, 0, 2034);
310 m_pDoc
->SetValue(2, 1, 0, 2342);
311 m_pDoc
->SetValue(2, 2, 0, 57453);
312 m_pDoc
->SetValue(2, 3, 0, -453);
314 m_pDoc
->SetValue(3, 0, 0, 2034);
315 m_pDoc
->SetValue(3, 1, 0, -2342);
316 m_pDoc
->SetValue(3, 2, 0, -57453);
317 m_pDoc
->SetValue(3, 3, 0, -453);
319 sc::AggregateFunction
aTransform({2, 3}, sc::AGGREGATE_FUNCTION::MAX
);
320 aTransform
.Transform(*m_pDoc
);
322 CPPUNIT_ASSERT_DOUBLES_EQUAL(57453, m_pDoc
->GetValue(2, 4, 0), 1e-10);
323 CPPUNIT_ASSERT_DOUBLES_EQUAL(2034, m_pDoc
->GetValue(3, 4, 0), 1e-10);
326 void ScDataTransformationTest::testNumberRound()
328 m_pDoc
->SetValue(2, 0, 0, 2034.342453456);
329 m_pDoc
->SetValue(2, 1, 0, 2342.252678567542);
330 m_pDoc
->SetValue(2, 2, 0, 57453.651345687654345676);
331 m_pDoc
->SetValue(2, 3, 0, -453.22234567543);
333 sc::NumberTransformation
aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::ROUND
, 4);
334 aTransform
.Transform(*m_pDoc
);
336 CPPUNIT_ASSERT_EQUAL(2034.3425, m_pDoc
->GetValue(2, 0, 0));
337 CPPUNIT_ASSERT_EQUAL(2342.2527, m_pDoc
->GetValue(2, 1, 0));
338 CPPUNIT_ASSERT_EQUAL(57453.6513, m_pDoc
->GetValue(2, 2, 0));
339 CPPUNIT_ASSERT_EQUAL(-453.2223, m_pDoc
->GetValue(2, 3, 0));
342 void ScDataTransformationTest::testNumberRoundUp()
344 m_pDoc
->SetValue(2, 0, 0, 2034.34);
345 m_pDoc
->SetValue(2, 1, 0, 2342.22);
346 m_pDoc
->SetValue(2, 2, 0, 57453.65);
347 m_pDoc
->SetValue(2, 3, 0, -453.22);
349 sc::NumberTransformation
aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::ROUND_UP
);
350 aTransform
.Transform(*m_pDoc
);
352 CPPUNIT_ASSERT_EQUAL(2035.0, m_pDoc
->GetValue(2, 0, 0));
353 CPPUNIT_ASSERT_EQUAL(2343.0, m_pDoc
->GetValue(2, 1, 0));
354 CPPUNIT_ASSERT_EQUAL(57454.0, m_pDoc
->GetValue(2, 2, 0));
355 CPPUNIT_ASSERT_EQUAL(-453.0, m_pDoc
->GetValue(2, 3, 0));
358 void ScDataTransformationTest::testNumberRoundDown()
360 m_pDoc
->SetValue(2, 0, 0, 2034.34);
361 m_pDoc
->SetValue(2, 1, 0, 2342.22);
362 m_pDoc
->SetValue(2, 2, 0, 57453.65);
363 m_pDoc
->SetValue(2, 3, 0, -453.22);
365 sc::NumberTransformation
aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::ROUND_DOWN
);
366 aTransform
.Transform(*m_pDoc
);
368 CPPUNIT_ASSERT_EQUAL(2034.0, m_pDoc
->GetValue(2, 0, 0));
369 CPPUNIT_ASSERT_EQUAL(2342.0, m_pDoc
->GetValue(2, 1, 0));
370 CPPUNIT_ASSERT_EQUAL(57453.0, m_pDoc
->GetValue(2, 2, 0));
371 CPPUNIT_ASSERT_EQUAL(-454.0, m_pDoc
->GetValue(2, 3, 0));
374 void ScDataTransformationTest::testNumberAbsolute()
376 m_pDoc
->SetValue(2, 0, 0, 2034.34);
377 m_pDoc
->SetValue(2, 1, 0, -2342.22);
378 m_pDoc
->SetValue(2, 2, 0, 57453.65);
379 m_pDoc
->SetValue(2, 3, 0, -453.22);
381 sc::NumberTransformation
aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::ABSOLUTE
);
382 aTransform
.Transform(*m_pDoc
);
384 CPPUNIT_ASSERT_EQUAL(2034.34, m_pDoc
->GetValue(2, 0, 0));
385 CPPUNIT_ASSERT_EQUAL(2342.22, m_pDoc
->GetValue(2, 1, 0));
386 CPPUNIT_ASSERT_EQUAL(57453.65, m_pDoc
->GetValue(2, 2, 0));
387 CPPUNIT_ASSERT_EQUAL(453.22, m_pDoc
->GetValue(2, 3, 0));
390 void ScDataTransformationTest::testNumberLogE()
392 m_pDoc
->SetValue(2, 0, 0, 1);
393 m_pDoc
->SetValue(2, 1, 0, 5);
394 m_pDoc
->SetValue(2, 2, 0, -9);
395 m_pDoc
->SetValue(2, 3, 0, 500);
397 sc::NumberTransformation
aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::LOG_E
);
398 aTransform
.Transform(*m_pDoc
);
400 CPPUNIT_ASSERT_DOUBLES_EQUAL(0, m_pDoc
->GetValue(2, 0, 0), 1e-10);
401 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.60943791243, m_pDoc
->GetValue(2, 1, 0), 1e-10);
402 CPPUNIT_ASSERT_EQUAL(OUString(""), m_pDoc
->GetString(2, 2, 0));
403 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.21460809842, m_pDoc
->GetValue(2, 3, 0), 1e-10);
406 void ScDataTransformationTest::testNumberLog10()
408 m_pDoc
->SetValue(2, 0, 0, 1);
409 m_pDoc
->SetValue(2, 1, 0, 10);
410 m_pDoc
->SetValue(2, 2, 0, -9);
411 m_pDoc
->SetValue(2, 3, 0, 500);
413 sc::NumberTransformation
aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::LOG_10
);
414 aTransform
.Transform(*m_pDoc
);
416 CPPUNIT_ASSERT_DOUBLES_EQUAL(0, m_pDoc
->GetValue(2, 0, 0), 1e-10);
417 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, m_pDoc
->GetValue(2, 1, 0), 1e-10);
418 CPPUNIT_ASSERT_EQUAL(OUString(), m_pDoc
->GetString(2, 2, 0));
419 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.69897000434, m_pDoc
->GetValue(2, 3, 0), 1e-10);
422 void ScDataTransformationTest::testNumberCube()
424 m_pDoc
->SetValue(2, 0, 0, 2);
425 m_pDoc
->SetValue(2, 1, 0, -2);
426 m_pDoc
->SetValue(2, 2, 0, 8);
427 m_pDoc
->SetValue(2, 3, 0, -8);
429 sc::NumberTransformation
aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::CUBE
);
430 aTransform
.Transform(*m_pDoc
);
432 CPPUNIT_ASSERT_EQUAL(8.0, m_pDoc
->GetValue(2, 0, 0));
433 CPPUNIT_ASSERT_EQUAL(-8.0, m_pDoc
->GetValue(2, 1, 0));
434 CPPUNIT_ASSERT_EQUAL(512.0, m_pDoc
->GetValue(2, 2, 0));
435 CPPUNIT_ASSERT_EQUAL(-512.0, m_pDoc
->GetValue(2, 3, 0));
438 void ScDataTransformationTest::testNumberSquare()
440 m_pDoc
->SetValue(2, 0, 0, 2);
441 m_pDoc
->SetValue(2, 1, 0, -2);
442 m_pDoc
->SetValue(2, 2, 0, 8);
443 m_pDoc
->SetValue(2, 3, 0, -8);
445 sc::NumberTransformation
aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::SQUARE
);
446 aTransform
.Transform(*m_pDoc
);
448 CPPUNIT_ASSERT_EQUAL(4.0, m_pDoc
->GetValue(2, 0, 0));
449 CPPUNIT_ASSERT_EQUAL(4.0, m_pDoc
->GetValue(2, 1, 0));
450 CPPUNIT_ASSERT_EQUAL(64.0, m_pDoc
->GetValue(2, 2, 0));
451 CPPUNIT_ASSERT_EQUAL(64.0, m_pDoc
->GetValue(2, 3, 0));
454 void ScDataTransformationTest::testNumberSquareRoot()
456 m_pDoc
->SetValue(2, 0, 0, 8);
457 m_pDoc
->SetValue(2, 1, 0, 4);
458 m_pDoc
->SetValue(2, 2, 0, 9);
460 sc::NumberTransformation
aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::SQUARE_ROOT
);
461 aTransform
.Transform(*m_pDoc
);
463 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.82842712475, m_pDoc
->GetValue(2, 0, 0), 1e-10);
464 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, m_pDoc
->GetValue(2, 1, 0), 1e-10);
465 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0, m_pDoc
->GetValue(2, 2, 0), 1e-10);
468 void ScDataTransformationTest::testNumberEven()
470 m_pDoc
->SetValue(2, 0, 0, 2034);
471 m_pDoc
->SetValue(2, 1, 0, 2343);
472 m_pDoc
->SetValue(2, 2, 0, 57453.65);
473 m_pDoc
->SetValue(2, 3, 0, -453);
475 sc::NumberTransformation
aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::IS_EVEN
);
476 aTransform
.Transform(*m_pDoc
);
478 CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc
->GetValue(2, 0, 0));
479 CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc
->GetValue(2, 1, 0));
480 CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc
->GetValue(2, 2, 0));
481 CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc
->GetValue(2, 3, 0));
484 void ScDataTransformationTest::testNumberOdd()
486 m_pDoc
->SetValue(2, 0, 0, 2034);
487 m_pDoc
->SetValue(2, 1, 0, 2343);
488 m_pDoc
->SetValue(2, 2, 0, 57453.65);
489 m_pDoc
->SetValue(2, 3, 0, -453);
491 sc::NumberTransformation
aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::IS_ODD
);
492 aTransform
.Transform(*m_pDoc
);
494 CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc
->GetValue(2, 0, 0));
495 CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc
->GetValue(2, 1, 0));
496 CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc
->GetValue(2, 2, 0));
497 CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc
->GetValue(2, 3, 0));
500 void ScDataTransformationTest::testNumberSign()
502 m_pDoc
->SetValue(2, 0, 0, 2034.34);
503 m_pDoc
->SetValue(2, 1, 0, -2342.22);
504 m_pDoc
->SetValue(2, 2, 0, 0);
505 m_pDoc
->SetValue(2, 3, 0, -453.22);
507 sc::NumberTransformation
aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::SIGN
);
508 aTransform
.Transform(*m_pDoc
);
510 CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc
->GetValue(2, 0, 0));
511 CPPUNIT_ASSERT_EQUAL(-1.0, m_pDoc
->GetValue(2, 1, 0));
512 CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc
->GetValue(2, 2, 0));
513 CPPUNIT_ASSERT_EQUAL(-1.0, m_pDoc
->GetValue(2, 3, 0));
516 void ScDataTransformationTest::testReplaceNull()
518 m_pDoc
->SetString(2, 0, 0, "Berlin");
519 m_pDoc
->SetString(2, 1, 0, "");
520 m_pDoc
->SetString(2, 2, 0, "");
521 m_pDoc
->SetString(2, 3, 0, "Peking");
523 sc::ReplaceNullTransformation
aTransform({2}, "Empty");
524 aTransform
.Transform(*m_pDoc
);
526 CPPUNIT_ASSERT_EQUAL(OUString("Berlin"), m_pDoc
->GetString(2, 0, 0));
527 CPPUNIT_ASSERT_EQUAL(OUString("Empty"), m_pDoc
->GetString(2, 1, 0));
528 CPPUNIT_ASSERT_EQUAL(OUString("Empty"), m_pDoc
->GetString(2, 2, 0));
529 CPPUNIT_ASSERT_EQUAL(OUString("Peking"), m_pDoc
->GetString(2, 3, 0));
533 void ScDataTransformationTest::testGetDateString()
535 SvNumberFormatter
* pFormatter
= m_pDoc
->GetFormatTable();
536 css::util::Date
aDate1(25,1,2011);
537 css::util::Date
aDate2(12,10,1994);
538 css::util::Date
aDate3(23,9,1996);
539 css::util::Date
aDate4(15,8,1947);
541 double nDate1
= static_cast<double>(aDate1
- pFormatter
->GetNullDate());
542 double nDate2
= static_cast<double>(aDate2
- pFormatter
->GetNullDate());
543 double nDate3
= static_cast<double>(aDate3
- pFormatter
->GetNullDate());
544 double nDate4
= static_cast<double>(aDate4
- pFormatter
->GetNullDate());
546 m_pDoc
->SetValue(2, 0, 0, nDate1
);
547 m_pDoc
->SetValue(2, 1, 0, nDate2
);
548 m_pDoc
->SetValue(2, 2, 0, nDate3
);
549 m_pDoc
->SetValue(2, 3, 0, nDate4
);
551 sc:: DateTimeTransformation
aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::DATE_STRING
);
552 aTransform
.Transform(*m_pDoc
);
554 CPPUNIT_ASSERT_EQUAL(OUString("01/25/11"), m_pDoc
->GetString(2, 0, 0));
555 CPPUNIT_ASSERT_EQUAL(OUString("10/12/94"), m_pDoc
->GetString(2, 1, 0));
556 CPPUNIT_ASSERT_EQUAL(OUString("09/23/96"), m_pDoc
->GetString(2, 2, 0));
557 CPPUNIT_ASSERT_EQUAL(OUString("08/15/47"), m_pDoc
->GetString(2, 3, 0));
560 void ScDataTransformationTest::testGetYear()
562 SvNumberFormatter
* pFormatter
= m_pDoc
->GetFormatTable();
563 css::util::Date
aDate1(25,1,2011);
564 css::util::Date
aDate2(12,10,1994);
565 css::util::Date
aDate3(23,9,1996);
566 css::util::Date
aDate4(15,8,1947);
568 double nDate1
= static_cast<double>(aDate1
- pFormatter
->GetNullDate());
569 double nDate2
= static_cast<double>(aDate2
- pFormatter
->GetNullDate());
570 double nDate3
= static_cast<double>(aDate3
- pFormatter
->GetNullDate());
571 double nDate4
= static_cast<double>(aDate4
- pFormatter
->GetNullDate());
573 m_pDoc
->SetValue(2, 0, 0, nDate1
);
574 m_pDoc
->SetValue(2, 1, 0, nDate2
);
575 m_pDoc
->SetValue(2, 2, 0, nDate3
);
576 m_pDoc
->SetValue(2, 3, 0, nDate4
);
578 sc:: DateTimeTransformation
aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::YEAR
);
579 aTransform
.Transform(*m_pDoc
);
581 CPPUNIT_ASSERT_DOUBLES_EQUAL(2011, m_pDoc
->GetValue(2, 0, 0), 0);
582 CPPUNIT_ASSERT_DOUBLES_EQUAL(1994, m_pDoc
->GetValue(2, 1, 0), 0);
583 CPPUNIT_ASSERT_DOUBLES_EQUAL(1996, m_pDoc
->GetValue(2, 2, 0), 0);
584 CPPUNIT_ASSERT_DOUBLES_EQUAL(1947, m_pDoc
->GetValue(2, 3, 0), 0);
587 void ScDataTransformationTest::testGetStartOfYear()
589 SvNumberFormatter
* pFormatter
= m_pDoc
->GetFormatTable();
590 css::util::Date
aDate1(25,1,2011);
591 css::util::Date
aDate2(12,10,1994);
592 css::util::Date
aDate3(23,9,1996);
593 css::util::Date
aDate4(15,8,1947);
595 double nDate1
= static_cast<double>(aDate1
- pFormatter
->GetNullDate());
596 double nDate2
= static_cast<double>(aDate2
- pFormatter
->GetNullDate());
597 double nDate3
= static_cast<double>(aDate3
- pFormatter
->GetNullDate());
598 double nDate4
= static_cast<double>(aDate4
- pFormatter
->GetNullDate());
600 m_pDoc
->SetValue(2, 0, 0, nDate1
);
601 m_pDoc
->SetValue(2, 1, 0, nDate2
);
602 m_pDoc
->SetValue(2, 2, 0, nDate3
);
603 m_pDoc
->SetValue(2, 3, 0, nDate4
);
605 sc:: DateTimeTransformation
aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::START_OF_YEAR
);
606 aTransform
.Transform(*m_pDoc
);
608 CPPUNIT_ASSERT_EQUAL(OUString("01/01/11"), m_pDoc
->GetString(2, 0, 0));
609 CPPUNIT_ASSERT_EQUAL(OUString("01/01/94"), m_pDoc
->GetString(2, 1, 0));
610 CPPUNIT_ASSERT_EQUAL(OUString("01/01/96"), m_pDoc
->GetString(2, 2, 0));
611 CPPUNIT_ASSERT_EQUAL(OUString("01/01/47"), m_pDoc
->GetString(2, 3, 0));
614 void ScDataTransformationTest::testGetEndOfYear()
616 SvNumberFormatter
* pFormatter
= m_pDoc
->GetFormatTable();
617 css::util::Date
aDate1(25,1,2011);
618 css::util::Date
aDate2(12,10,1994);
619 css::util::Date
aDate3(23,9,1996);
620 css::util::Date
aDate4(15,8,1947);
622 double nDate1
= static_cast<double>(aDate1
- pFormatter
->GetNullDate());
623 double nDate2
= static_cast<double>(aDate2
- pFormatter
->GetNullDate());
624 double nDate3
= static_cast<double>(aDate3
- pFormatter
->GetNullDate());
625 double nDate4
= static_cast<double>(aDate4
- pFormatter
->GetNullDate());
627 m_pDoc
->SetValue(2, 0, 0, nDate1
);
628 m_pDoc
->SetValue(2, 1, 0, nDate2
);
629 m_pDoc
->SetValue(2, 2, 0, nDate3
);
630 m_pDoc
->SetValue(2, 3, 0, nDate4
);
632 sc:: DateTimeTransformation
aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::END_OF_YEAR
);
633 aTransform
.Transform(*m_pDoc
);
635 CPPUNIT_ASSERT_EQUAL(OUString("12/31/11"), m_pDoc
->GetString(2, 0, 0));
636 CPPUNIT_ASSERT_EQUAL(OUString("12/31/94"), m_pDoc
->GetString(2, 1, 0));
637 CPPUNIT_ASSERT_EQUAL(OUString("12/31/96"), m_pDoc
->GetString(2, 2, 0));
638 CPPUNIT_ASSERT_EQUAL(OUString("12/31/47"), m_pDoc
->GetString(2, 3, 0));
641 void ScDataTransformationTest::testGetMonth()
643 SvNumberFormatter
* pFormatter
= m_pDoc
->GetFormatTable();
644 css::util::Date
aDate1(25,1,2011);
645 css::util::Date
aDate2(12,10,1994);
646 css::util::Date
aDate3(23,9,1996);
647 css::util::Date
aDate4(15,8,1947);
649 double nDate1
= static_cast<double>(aDate1
- pFormatter
->GetNullDate());
650 double nDate2
= static_cast<double>(aDate2
- pFormatter
->GetNullDate());
651 double nDate3
= static_cast<double>(aDate3
- pFormatter
->GetNullDate());
652 double nDate4
= static_cast<double>(aDate4
- pFormatter
->GetNullDate());
654 m_pDoc
->SetValue(2, 0, 0, nDate1
);
655 m_pDoc
->SetValue(2, 1, 0, nDate2
);
656 m_pDoc
->SetValue(2, 2, 0, nDate3
);
657 m_pDoc
->SetValue(2, 3, 0, nDate4
);
659 sc:: DateTimeTransformation
aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::MONTH
);
660 aTransform
.Transform(*m_pDoc
);
662 CPPUNIT_ASSERT_DOUBLES_EQUAL(1, m_pDoc
->GetValue(2, 0, 0), 0);
663 CPPUNIT_ASSERT_DOUBLES_EQUAL(10, m_pDoc
->GetValue(2, 1, 0), 0);
664 CPPUNIT_ASSERT_DOUBLES_EQUAL(9, m_pDoc
->GetValue(2, 2, 0), 0);
665 CPPUNIT_ASSERT_DOUBLES_EQUAL(8, m_pDoc
->GetValue(2, 3, 0), 0);
668 void ScDataTransformationTest::testGetMonthName()
670 SvNumberFormatter
* pFormatter
= m_pDoc
->GetFormatTable();
671 css::util::Date
aDate1(25,1,2011);
672 css::util::Date
aDate2(12,10,1994);
673 css::util::Date
aDate3(23,9,1996);
674 css::util::Date
aDate4(15,8,1947);
676 double nDate1
= static_cast<double>(aDate1
- pFormatter
->GetNullDate());
677 double nDate2
= static_cast<double>(aDate2
- pFormatter
->GetNullDate());
678 double nDate3
= static_cast<double>(aDate3
- pFormatter
->GetNullDate());
679 double nDate4
= static_cast<double>(aDate4
- pFormatter
->GetNullDate());
681 m_pDoc
->SetValue(2, 0, 0, nDate1
);
682 m_pDoc
->SetValue(2, 1, 0, nDate2
);
683 m_pDoc
->SetValue(2, 2, 0, nDate3
);
684 m_pDoc
->SetValue(2, 3, 0, nDate4
);
686 sc:: DateTimeTransformation
aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::MONTH_NAME
);
687 aTransform
.Transform(*m_pDoc
);
689 CPPUNIT_ASSERT_EQUAL(OUString("January"), m_pDoc
->GetString(2, 0, 0));
690 CPPUNIT_ASSERT_EQUAL(OUString("October"), m_pDoc
->GetString(2, 1, 0));
691 CPPUNIT_ASSERT_EQUAL(OUString("September"), m_pDoc
->GetString(2, 2, 0));
692 CPPUNIT_ASSERT_EQUAL(OUString("August"), m_pDoc
->GetString(2, 3, 0));
695 void ScDataTransformationTest::testGetStartOfMonth()
697 SvNumberFormatter
* pFormatter
= m_pDoc
->GetFormatTable();
698 css::util::Date
aDate1(25,1,2011);
699 css::util::Date
aDate2(12,10,1994);
700 css::util::Date
aDate3(23,9,1996);
701 css::util::Date
aDate4(15,8,1947);
703 double nDate1
= static_cast<double>(aDate1
- pFormatter
->GetNullDate());
704 double nDate2
= static_cast<double>(aDate2
- pFormatter
->GetNullDate());
705 double nDate3
= static_cast<double>(aDate3
- pFormatter
->GetNullDate());
706 double nDate4
= static_cast<double>(aDate4
- pFormatter
->GetNullDate());
708 m_pDoc
->SetValue(2, 0, 0, nDate1
);
709 m_pDoc
->SetValue(2, 1, 0, nDate2
);
710 m_pDoc
->SetValue(2, 2, 0, nDate3
);
711 m_pDoc
->SetValue(2, 3, 0, nDate4
);
713 sc:: DateTimeTransformation
aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::START_OF_MONTH
);
714 aTransform
.Transform(*m_pDoc
);
716 CPPUNIT_ASSERT_EQUAL(OUString("01/01/11"), m_pDoc
->GetString(2, 0, 0));
717 CPPUNIT_ASSERT_EQUAL(OUString("10/01/94"), m_pDoc
->GetString(2, 1, 0));
718 CPPUNIT_ASSERT_EQUAL(OUString("09/01/96"), m_pDoc
->GetString(2, 2, 0));
719 CPPUNIT_ASSERT_EQUAL(OUString("08/01/47"), m_pDoc
->GetString(2, 3, 0));
722 void ScDataTransformationTest::testGetEndOfMonth()
724 SvNumberFormatter
* pFormatter
= m_pDoc
->GetFormatTable();
725 css::util::Date
aDate1(25,1,2011);
726 css::util::Date
aDate2(12,10,1994);
727 css::util::Date
aDate3(23,9,1996);
728 css::util::Date
aDate4(15,8,1947);
730 double nDate1
= static_cast<double>(aDate1
- pFormatter
->GetNullDate());
731 double nDate2
= static_cast<double>(aDate2
- pFormatter
->GetNullDate());
732 double nDate3
= static_cast<double>(aDate3
- pFormatter
->GetNullDate());
733 double nDate4
= static_cast<double>(aDate4
- pFormatter
->GetNullDate());
735 m_pDoc
->SetValue(2, 0, 0, nDate1
);
736 m_pDoc
->SetValue(2, 1, 0, nDate2
);
737 m_pDoc
->SetValue(2, 2, 0, nDate3
);
738 m_pDoc
->SetValue(2, 3, 0, nDate4
);
740 sc:: DateTimeTransformation
aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::END_OF_MONTH
);
741 aTransform
.Transform(*m_pDoc
);
743 CPPUNIT_ASSERT_EQUAL(OUString("01/31/11"), m_pDoc
->GetString(2, 0, 0));
744 CPPUNIT_ASSERT_EQUAL(OUString("10/31/94"), m_pDoc
->GetString(2, 1, 0));
745 CPPUNIT_ASSERT_EQUAL(OUString("09/30/96"), m_pDoc
->GetString(2, 2, 0));
746 CPPUNIT_ASSERT_EQUAL(OUString("08/31/47"), m_pDoc
->GetString(2, 3, 0));
749 void ScDataTransformationTest::testGetDay()
751 SvNumberFormatter
* pFormatter
= m_pDoc
->GetFormatTable();
752 css::util::Date
aDate1(25,1,2011);
753 css::util::Date
aDate2(12,10,1994);
754 css::util::Date
aDate3(23,9,1996);
755 css::util::Date
aDate4(15,8,1947);
757 double nDate1
= static_cast<double>(aDate1
- pFormatter
->GetNullDate());
758 double nDate2
= static_cast<double>(aDate2
- pFormatter
->GetNullDate());
759 double nDate3
= static_cast<double>(aDate3
- pFormatter
->GetNullDate());
760 double nDate4
= static_cast<double>(aDate4
- pFormatter
->GetNullDate());
762 m_pDoc
->SetValue(2, 0, 0, nDate1
);
763 m_pDoc
->SetValue(2, 1, 0, nDate2
);
764 m_pDoc
->SetValue(2, 2, 0, nDate3
);
765 m_pDoc
->SetValue(2, 3, 0, nDate4
);
767 sc:: DateTimeTransformation
aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::DAY
);
768 aTransform
.Transform(*m_pDoc
);
770 CPPUNIT_ASSERT_DOUBLES_EQUAL(25, m_pDoc
->GetValue(2, 0, 0), 0);
771 CPPUNIT_ASSERT_DOUBLES_EQUAL(12, m_pDoc
->GetValue(2, 1, 0), 0);
772 CPPUNIT_ASSERT_DOUBLES_EQUAL(23, m_pDoc
->GetValue(2, 2, 0), 0);
773 CPPUNIT_ASSERT_DOUBLES_EQUAL(15, m_pDoc
->GetValue(2, 3, 0), 0);
776 void ScDataTransformationTest::testGetDayOfWeek()
778 SvNumberFormatter
* pFormatter
= m_pDoc
->GetFormatTable();
779 css::util::Date
aDate1(25,1,2011);
780 css::util::Date
aDate2(12,10,1994);
781 css::util::Date
aDate3(23,9,1996);
782 css::util::Date
aDate4(15,8,1947);
784 double nDate1
= static_cast<double>(aDate1
- pFormatter
->GetNullDate());
785 double nDate2
= static_cast<double>(aDate2
- pFormatter
->GetNullDate());
786 double nDate3
= static_cast<double>(aDate3
- pFormatter
->GetNullDate());
787 double nDate4
= static_cast<double>(aDate4
- pFormatter
->GetNullDate());
789 m_pDoc
->SetValue(2, 0, 0, nDate1
);
790 m_pDoc
->SetValue(2, 1, 0, nDate2
);
791 m_pDoc
->SetValue(2, 2, 0, nDate3
);
792 m_pDoc
->SetValue(2, 3, 0, nDate4
);
794 sc:: DateTimeTransformation
aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::DAY_OF_WEEK
);
795 aTransform
.Transform(*m_pDoc
);
797 CPPUNIT_ASSERT_DOUBLES_EQUAL(1, m_pDoc
->GetValue(2, 0, 0), 0);
798 CPPUNIT_ASSERT_DOUBLES_EQUAL(2, m_pDoc
->GetValue(2, 1, 0), 0);
799 CPPUNIT_ASSERT_DOUBLES_EQUAL(0, m_pDoc
->GetValue(2, 2, 0), 0);
800 CPPUNIT_ASSERT_DOUBLES_EQUAL(4, m_pDoc
->GetValue(2, 3, 0), 0);
803 void ScDataTransformationTest::testGetDayOfYear()
805 SvNumberFormatter
* pFormatter
= m_pDoc
->GetFormatTable();
806 css::util::Date
aDate1(25,1,2011);
807 css::util::Date
aDate2(12,10,1994);
808 css::util::Date
aDate3(23,9,1996);
809 css::util::Date
aDate4(15,8,1947);
811 double nDate1
= static_cast<double>(aDate1
- pFormatter
->GetNullDate());
812 double nDate2
= static_cast<double>(aDate2
- pFormatter
->GetNullDate());
813 double nDate3
= static_cast<double>(aDate3
- pFormatter
->GetNullDate());
814 double nDate4
= static_cast<double>(aDate4
- pFormatter
->GetNullDate());
816 m_pDoc
->SetValue(2, 0, 0, nDate1
);
817 m_pDoc
->SetValue(2, 1, 0, nDate2
);
818 m_pDoc
->SetValue(2, 2, 0, nDate3
);
819 m_pDoc
->SetValue(2, 3, 0, nDate4
);
821 sc:: DateTimeTransformation
aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::DAY_OF_YEAR
);
822 aTransform
.Transform(*m_pDoc
);
824 CPPUNIT_ASSERT_DOUBLES_EQUAL(25, m_pDoc
->GetValue(2, 0, 0), 0);
825 CPPUNIT_ASSERT_DOUBLES_EQUAL(285, m_pDoc
->GetValue(2, 1, 0), 0);
826 CPPUNIT_ASSERT_DOUBLES_EQUAL(267, m_pDoc
->GetValue(2, 2, 0), 0);
827 CPPUNIT_ASSERT_DOUBLES_EQUAL(227, m_pDoc
->GetValue(2, 3, 0), 0);
830 void ScDataTransformationTest::testGetQuarter()
832 SvNumberFormatter
* pFormatter
= m_pDoc
->GetFormatTable();
833 css::util::Date
aDate1(25,1,2011);
834 css::util::Date
aDate2(12,10,1994);
835 css::util::Date
aDate3(23,9,1996);
836 css::util::Date
aDate4(15,8,1947);
838 double nDate1
= static_cast<double>(aDate1
- pFormatter
->GetNullDate());
839 double nDate2
= static_cast<double>(aDate2
- pFormatter
->GetNullDate());
840 double nDate3
= static_cast<double>(aDate3
- pFormatter
->GetNullDate());
841 double nDate4
= static_cast<double>(aDate4
- pFormatter
->GetNullDate());
843 m_pDoc
->SetValue(2, 0, 0, nDate1
);
844 m_pDoc
->SetValue(2, 1, 0, nDate2
);
845 m_pDoc
->SetValue(2, 2, 0, nDate3
);
846 m_pDoc
->SetValue(2, 3, 0, nDate4
);
848 sc:: DateTimeTransformation
aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::QUARTER
);
849 aTransform
.Transform(*m_pDoc
);
851 CPPUNIT_ASSERT_DOUBLES_EQUAL(1, m_pDoc
->GetValue(2, 0, 0), 0);
852 CPPUNIT_ASSERT_DOUBLES_EQUAL(4, m_pDoc
->GetValue(2, 1, 0), 0);
853 CPPUNIT_ASSERT_DOUBLES_EQUAL(3, m_pDoc
->GetValue(2, 2, 0), 0);
854 CPPUNIT_ASSERT_DOUBLES_EQUAL(3, m_pDoc
->GetValue(2, 3, 0), 0);
857 void ScDataTransformationTest::testGetStartOfQuarter()
859 SvNumberFormatter
* pFormatter
= m_pDoc
->GetFormatTable();
860 css::util::Date
aDate1(25,1,2011);
861 css::util::Date
aDate2(12,10,1994);
862 css::util::Date
aDate3(23,9,1996);
863 css::util::Date
aDate4(15,8,1947);
865 double nDate1
= static_cast<double>(aDate1
- pFormatter
->GetNullDate());
866 double nDate2
= static_cast<double>(aDate2
- pFormatter
->GetNullDate());
867 double nDate3
= static_cast<double>(aDate3
- pFormatter
->GetNullDate());
868 double nDate4
= static_cast<double>(aDate4
- pFormatter
->GetNullDate());
870 m_pDoc
->SetValue(2, 0, 0, nDate1
);
871 m_pDoc
->SetValue(2, 1, 0, nDate2
);
872 m_pDoc
->SetValue(2, 2, 0, nDate3
);
873 m_pDoc
->SetValue(2, 3, 0, nDate4
);
875 sc:: DateTimeTransformation
aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::START_OF_QUARTER
);
876 aTransform
.Transform(*m_pDoc
);
878 CPPUNIT_ASSERT_EQUAL(OUString("01/01/11"), m_pDoc
->GetString(2, 0, 0));
879 CPPUNIT_ASSERT_EQUAL(OUString("10/01/94"), m_pDoc
->GetString(2, 1, 0));
880 CPPUNIT_ASSERT_EQUAL(OUString("07/01/96"), m_pDoc
->GetString(2, 2, 0));
881 CPPUNIT_ASSERT_EQUAL(OUString("07/01/47"), m_pDoc
->GetString(2, 3, 0));
884 void ScDataTransformationTest::testGetEndOfQuarter()
886 SvNumberFormatter
* pFormatter
= m_pDoc
->GetFormatTable();
887 css::util::Date
aDate1(25,1,2011);
888 css::util::Date
aDate2(12,10,1994);
889 css::util::Date
aDate3(23,9,1996);
890 css::util::Date
aDate4(15,8,1947);
892 double nDate1
= static_cast<double>(aDate1
- pFormatter
->GetNullDate());
893 double nDate2
= static_cast<double>(aDate2
- pFormatter
->GetNullDate());
894 double nDate3
= static_cast<double>(aDate3
- pFormatter
->GetNullDate());
895 double nDate4
= static_cast<double>(aDate4
- pFormatter
->GetNullDate());
897 m_pDoc
->SetValue(2, 0, 0, nDate1
);
898 m_pDoc
->SetValue(2, 1, 0, nDate2
);
899 m_pDoc
->SetValue(2, 2, 0, nDate3
);
900 m_pDoc
->SetValue(2, 3, 0, nDate4
);
902 sc:: DateTimeTransformation
aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::END_OF_QUARTER
);
903 aTransform
.Transform(*m_pDoc
);
905 CPPUNIT_ASSERT_EQUAL(OUString("03/31/11"), m_pDoc
->GetString(2, 0, 0));
906 CPPUNIT_ASSERT_EQUAL(OUString("12/31/94"), m_pDoc
->GetString(2, 1, 0));
907 CPPUNIT_ASSERT_EQUAL(OUString("09/30/96"), m_pDoc
->GetString(2, 2, 0));
908 CPPUNIT_ASSERT_EQUAL(OUString("09/30/47"), m_pDoc
->GetString(2, 3, 0));
911 void ScDataTransformationTest::testGetTime()
913 tools::Time
aTime1(5,30,12);
914 tools::Time
aTime2(7,23,9);
915 tools::Time
aTime3(9,34,40);
916 tools::Time
aTime4(22,9,49);
918 m_pDoc
->SetValue(2, 0, 0, aTime1
.GetTimeInDays());
919 m_pDoc
->SetValue(2, 1, 0, aTime2
.GetTimeInDays());
920 m_pDoc
->SetValue(2, 2, 0, aTime3
.GetTimeInDays());
921 m_pDoc
->SetValue(2, 3, 0, aTime4
.GetTimeInDays());
923 sc:: DateTimeTransformation
aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::TIME
);
924 aTransform
.Transform(*m_pDoc
);
926 CPPUNIT_ASSERT_EQUAL(OUString("05:30:12 AM"), m_pDoc
->GetString(2, 0, 0));
927 CPPUNIT_ASSERT_EQUAL(OUString("07:23:09 AM"), m_pDoc
->GetString(2, 1, 0));
928 CPPUNIT_ASSERT_EQUAL(OUString("09:34:40 AM"), m_pDoc
->GetString(2, 2, 0));
929 CPPUNIT_ASSERT_EQUAL(OUString("10:09:49 PM"), m_pDoc
->GetString(2, 3, 0));
932 void ScDataTransformationTest::testGetHour()
934 tools::Time
aTime1(5,30,12);
935 tools::Time
aTime2(7,23,9);
936 tools::Time
aTime3(9,34,40);
937 tools::Time
aTime4(22,9,49);
939 m_pDoc
->SetValue(2, 0, 0, aTime1
.GetTimeInDays());
940 m_pDoc
->SetValue(2, 1, 0, aTime2
.GetTimeInDays());
941 m_pDoc
->SetValue(2, 2, 0, aTime3
.GetTimeInDays());
942 m_pDoc
->SetValue(2, 3, 0, aTime4
.GetTimeInDays());
944 sc:: DateTimeTransformation
aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::HOUR
);
945 aTransform
.Transform(*m_pDoc
);
947 CPPUNIT_ASSERT_DOUBLES_EQUAL(5, m_pDoc
->GetValue(2, 0, 0), 0);
948 CPPUNIT_ASSERT_DOUBLES_EQUAL(7, m_pDoc
->GetValue(2, 1, 0), 0);
949 CPPUNIT_ASSERT_DOUBLES_EQUAL(9, m_pDoc
->GetValue(2, 2, 0), 0);
950 CPPUNIT_ASSERT_DOUBLES_EQUAL(22, m_pDoc
->GetValue(2, 3, 0), 0);
953 void ScDataTransformationTest::testGetMinute()
955 tools::Time
aTime1(5,30,12);
956 tools::Time
aTime2(7,23,9);
957 tools::Time
aTime3(9,34,40);
958 tools::Time
aTime4(22,9,49);
960 m_pDoc
->SetValue(2, 0, 0, aTime1
.GetTimeInDays());
961 m_pDoc
->SetValue(2, 1, 0, aTime2
.GetTimeInDays());
962 m_pDoc
->SetValue(2, 2, 0, aTime3
.GetTimeInDays());
963 m_pDoc
->SetValue(2, 3, 0, aTime4
.GetTimeInDays());
965 sc:: DateTimeTransformation
aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::MINUTE
);
966 aTransform
.Transform(*m_pDoc
);
968 CPPUNIT_ASSERT_DOUBLES_EQUAL(30, m_pDoc
->GetValue(2, 0, 0), 0);
969 CPPUNIT_ASSERT_DOUBLES_EQUAL(23, m_pDoc
->GetValue(2, 1, 0), 0);
970 CPPUNIT_ASSERT_DOUBLES_EQUAL(34, m_pDoc
->GetValue(2, 2, 0), 0);
971 CPPUNIT_ASSERT_DOUBLES_EQUAL(9, m_pDoc
->GetValue(2, 3, 0), 0);
974 void ScDataTransformationTest::testGetSecond()
976 tools::Time
aTime1(5,30,53);
977 tools::Time
aTime2(7,23,10);
978 tools::Time
aTime3(9,34,40);
979 tools::Time
aTime4(22,9,49);
981 m_pDoc
->SetValue(2, 0, 0, aTime1
.GetTimeInDays());
982 m_pDoc
->SetValue(2, 1, 0, aTime2
.GetTimeInDays());
983 m_pDoc
->SetValue(2, 2, 0, aTime3
.GetTimeInDays());
984 m_pDoc
->SetValue(2, 3, 0, aTime4
.GetTimeInDays());
986 sc:: DateTimeTransformation
aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::SECOND
);
987 aTransform
.Transform(*m_pDoc
);
989 CPPUNIT_ASSERT_DOUBLES_EQUAL(53, m_pDoc
->GetValue(2, 0, 0), 0);
990 CPPUNIT_ASSERT_DOUBLES_EQUAL(10, m_pDoc
->GetValue(2, 1, 0), 0);
991 CPPUNIT_ASSERT_DOUBLES_EQUAL(40, m_pDoc
->GetValue(2, 2, 0), 0);
992 CPPUNIT_ASSERT_DOUBLES_EQUAL(49, m_pDoc
->GetValue(2, 3, 0), 0);
995 void ScDataTransformationTest::setUp()
997 ScUcalcTestBase::setUp();
998 m_pDoc
->InsertTab(0, "Tab");
1001 CPPUNIT_TEST_SUITE_REGISTRATION(ScDataTransformationTest
);
1003 CPPUNIT_PLUGIN_IMPLEMENT();
1005 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */