Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / qa / unit / ucalc_datatransformation.cxx
blob64fa91c399a59979c39bdaf144338ad9a4a13879
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
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
20 public:
21 virtual void setUp() override;
24 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testColumnRemove)
26 for (SCROW nRow = 0; nRow < 10; ++nRow)
28 for (SCCOL nCol = 0; nCol < 10; ++nCol)
30 m_pDoc->SetValue(nCol, nRow, 0, nRow*nCol);
34 sc::ColumnRemoveTransformation aTransformation({5});
35 aTransformation.Transform(*m_pDoc);
37 for (SCROW nRow = 0; nRow < 10; ++nRow)
39 for (SCCOL nCol = 0; nCol < 9; ++nCol)
41 double nVal = m_pDoc->GetValue(nCol, nRow, 0);
42 if (nCol < 5)
44 ASSERT_DOUBLES_EQUAL(static_cast<double>(nCol)*nRow, nVal);
46 else
48 ASSERT_DOUBLES_EQUAL(static_cast<double>(nCol+1)*nRow, nVal);
54 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testColumnSplit)
56 m_pDoc->SetString(2, 0, 0, "Test1,Test2");
57 m_pDoc->SetString(2, 1, 0, "Test1,");
58 m_pDoc->SetString(2, 2, 0, ",Test1");
59 m_pDoc->SetString(2, 3, 0, "Test1,Test2,Test3");
60 m_pDoc->SetString(3, 0, 0, "AnotherString");
62 sc::SplitColumnTransformation aTransform(2, ',');
63 aTransform.Transform(*m_pDoc);
65 CPPUNIT_ASSERT_EQUAL(OUString("AnotherString"), m_pDoc->GetString(4, 0, 0));
67 CPPUNIT_ASSERT_EQUAL(OUString("Test1"), m_pDoc->GetString(2, 0, 0));
68 CPPUNIT_ASSERT_EQUAL(OUString("Test1"), m_pDoc->GetString(2, 1, 0));
69 CPPUNIT_ASSERT_EQUAL(OUString(""), m_pDoc->GetString(2, 2, 0));
70 CPPUNIT_ASSERT_EQUAL(OUString("Test1"), m_pDoc->GetString(2, 3, 0));
72 CPPUNIT_ASSERT_EQUAL(OUString("Test2"), m_pDoc->GetString(3, 0, 0));
73 CPPUNIT_ASSERT_EQUAL(OUString(""), m_pDoc->GetString(3, 1, 0));
74 CPPUNIT_ASSERT_EQUAL(OUString("Test1"), m_pDoc->GetString(3, 2, 0));
75 CPPUNIT_ASSERT_EQUAL(OUString("Test2,Test3"), m_pDoc->GetString(3, 3, 0));
78 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testColumnMerge)
80 m_pDoc->SetString(2, 0, 0, "Berlin");
81 m_pDoc->SetString(2, 1, 0, "Brussels");
82 m_pDoc->SetString(2, 2, 0, "Paris");
83 m_pDoc->SetString(2, 3, 0, "Peking");
85 m_pDoc->SetString(4, 0, 0, "Germany");
86 m_pDoc->SetString(4, 1, 0, "Belgium");
87 m_pDoc->SetString(4, 2, 0, "France");
88 m_pDoc->SetString(4, 3, 0, "China");
90 sc::MergeColumnTransformation aTransform({2, 4}, ", ");
91 aTransform.Transform(*m_pDoc);
93 CPPUNIT_ASSERT_EQUAL(OUString("Berlin, Germany"), m_pDoc->GetString(2, 0, 0));
94 CPPUNIT_ASSERT_EQUAL(OUString("Brussels, Belgium"), m_pDoc->GetString(2, 1, 0));
95 CPPUNIT_ASSERT_EQUAL(OUString("Paris, France"), m_pDoc->GetString(2, 2, 0));
96 CPPUNIT_ASSERT_EQUAL(OUString("Peking, China"), m_pDoc->GetString(2, 3, 0));
98 for (SCROW nRow = 0; nRow <= 3; ++nRow)
100 CPPUNIT_ASSERT(m_pDoc->GetString(4, nRow, 0).isEmpty());
104 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testTextToLower)
106 m_pDoc->SetString(2, 0, 0, "Berlin");
107 m_pDoc->SetString(2, 1, 0, "Brussels");
108 m_pDoc->SetString(2, 2, 0, "Paris");
109 m_pDoc->SetString(2, 3, 0, "Peking");
111 sc::TextTransformation aTransform({2}, sc::TEXT_TRANSFORM_TYPE::TO_LOWER);
112 aTransform.Transform(*m_pDoc);
114 CPPUNIT_ASSERT_EQUAL(OUString("berlin"), m_pDoc->GetString(2, 0, 0));
115 CPPUNIT_ASSERT_EQUAL(OUString("brussels"), m_pDoc->GetString(2, 1, 0));
116 CPPUNIT_ASSERT_EQUAL(OUString("paris"), m_pDoc->GetString(2, 2, 0));
117 CPPUNIT_ASSERT_EQUAL(OUString("peking"), m_pDoc->GetString(2, 3, 0));
120 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testTextToUpper)
122 m_pDoc->SetString(2, 0, 0, "Berlin");
123 m_pDoc->SetString(2, 1, 0, "Brussels");
124 m_pDoc->SetString(2, 2, 0, "Paris");
125 m_pDoc->SetString(2, 3, 0, "Peking");
127 sc::TextTransformation aTransform({2}, sc::TEXT_TRANSFORM_TYPE::TO_UPPER);
128 aTransform.Transform(*m_pDoc);
130 CPPUNIT_ASSERT_EQUAL(OUString("BERLIN"), m_pDoc->GetString(2, 0, 0));
131 CPPUNIT_ASSERT_EQUAL(OUString("BRUSSELS"), m_pDoc->GetString(2, 1, 0));
132 CPPUNIT_ASSERT_EQUAL(OUString("PARIS"), m_pDoc->GetString(2, 2, 0));
133 CPPUNIT_ASSERT_EQUAL(OUString("PEKING"), m_pDoc->GetString(2, 3, 0));
136 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testTextCapitalize)
138 m_pDoc->SetString(2, 0, 0, "hello woRlD");
139 m_pDoc->SetString(2, 1, 0, "qUe vA");
140 m_pDoc->SetString(2, 2, 0, "si tu la ves");
141 m_pDoc->SetString(2, 3, 0, "cUaNdO mE EnAmOro");
143 sc::TextTransformation aTransform({2}, sc::TEXT_TRANSFORM_TYPE::CAPITALIZE);
144 aTransform.Transform(*m_pDoc);
146 CPPUNIT_ASSERT_EQUAL(OUString("Hello World"), m_pDoc->GetString(2, 0, 0));
147 CPPUNIT_ASSERT_EQUAL(OUString("Que Va"), m_pDoc->GetString(2, 1, 0));
148 CPPUNIT_ASSERT_EQUAL(OUString("Si Tu La Ves"), m_pDoc->GetString(2, 2, 0));
149 CPPUNIT_ASSERT_EQUAL(OUString("Cuando Me Enamoro"), m_pDoc->GetString(2, 3, 0));
152 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testTextTrim)
154 m_pDoc->SetString(2, 0, 0, " Berlin");
155 m_pDoc->SetString(2, 1, 0, "Brussels ");
156 m_pDoc->SetString(2, 2, 0, " Paris ");
158 sc::TextTransformation aTransform({2}, sc::TEXT_TRANSFORM_TYPE::TRIM);
159 aTransform.Transform(*m_pDoc);
161 CPPUNIT_ASSERT_EQUAL(OUString("Berlin"), m_pDoc->GetString(2, 0, 0));
162 CPPUNIT_ASSERT_EQUAL(OUString("Brussels"), m_pDoc->GetString(2, 1, 0));
163 CPPUNIT_ASSERT_EQUAL(OUString("Paris"), m_pDoc->GetString(2, 2, 0));
166 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testAggregateSum)
168 m_pDoc->SetValue(2, 0, 0, 2034);
169 m_pDoc->SetValue(2, 1, 0, 2342);
170 m_pDoc->SetValue(2, 2, 0, 57452);
172 m_pDoc->SetValue(4, 0, 0, 4829.98);
173 m_pDoc->SetValue(4, 1, 0, 53781.3);
174 m_pDoc->SetValue(4, 2, 0, 9876.4);
175 m_pDoc->SetValue(4, 3, 0, 0);
177 sc::AggregateFunction aTransform({2, 4}, sc::AGGREGATE_FUNCTION::SUM);
178 aTransform.Transform(*m_pDoc);
180 CPPUNIT_ASSERT_DOUBLES_EQUAL(61828, m_pDoc->GetValue(2, 4, 0), 1e-10);
181 CPPUNIT_ASSERT_DOUBLES_EQUAL(68487.68, m_pDoc->GetValue(4, 4, 0), 1e-10);
184 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testAggregateAverage)
186 m_pDoc->SetValue(2, 0, 0, 2034);
187 m_pDoc->SetValue(2, 1, 0, 2342);
188 m_pDoc->SetValue(2, 2, 0, 57453);
190 m_pDoc->SetValue(3, 0, 0, 4);
191 m_pDoc->SetValue(3, 1, 0, 4);
192 m_pDoc->SetValue(3, 2, 0, 4);
194 sc::AggregateFunction aTransform({2, 3}, sc::AGGREGATE_FUNCTION::AVERAGE);
195 aTransform.Transform(*m_pDoc);
197 CPPUNIT_ASSERT_DOUBLES_EQUAL(20609.6666666667, m_pDoc->GetValue(2, 3, 0), 1e-10);
198 CPPUNIT_ASSERT_DOUBLES_EQUAL(4, m_pDoc->GetValue(3, 3, 0), 1e-10);
201 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testAggregateMin)
203 m_pDoc->SetValue(2, 0, 0, 2034);
204 m_pDoc->SetValue(2, 1, 0, 2342);
205 m_pDoc->SetValue(2, 2, 0, 57453);
207 m_pDoc->SetValue(3, 0, 0, 2034);
208 m_pDoc->SetValue(3, 1, 0, -2342);
209 m_pDoc->SetValue(3, 2, 0, 57453);
211 sc::AggregateFunction aTransform({2, 3}, sc::AGGREGATE_FUNCTION::MIN);
212 aTransform.Transform(*m_pDoc);
214 CPPUNIT_ASSERT_DOUBLES_EQUAL(2034, m_pDoc->GetValue(2, 3, 0), 1e-10);
215 CPPUNIT_ASSERT_DOUBLES_EQUAL(-2342, m_pDoc->GetValue(3, 3, 0), 1e-10);
218 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testAggregateMax)
220 m_pDoc->SetValue(2, 0, 0, 2034);
221 m_pDoc->SetValue(2, 1, 0, 2342);
222 m_pDoc->SetValue(2, 2, 0, 57453);
223 m_pDoc->SetValue(2, 3, 0, -453);
225 m_pDoc->SetValue(3, 0, 0, 2034);
226 m_pDoc->SetValue(3, 1, 0, -2342);
227 m_pDoc->SetValue(3, 2, 0, -57453);
228 m_pDoc->SetValue(3, 3, 0, -453);
230 sc::AggregateFunction aTransform({2, 3}, sc::AGGREGATE_FUNCTION::MAX);
231 aTransform.Transform(*m_pDoc);
233 CPPUNIT_ASSERT_DOUBLES_EQUAL(57453, m_pDoc->GetValue(2, 4, 0), 1e-10);
234 CPPUNIT_ASSERT_DOUBLES_EQUAL(2034, m_pDoc->GetValue(3, 4, 0), 1e-10);
237 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testNumberRound)
239 m_pDoc->SetValue(2, 0, 0, 2034.342453456);
240 m_pDoc->SetValue(2, 1, 0, 2342.252678567542);
241 m_pDoc->SetValue(2, 2, 0, 57453.651345687654345676);
242 m_pDoc->SetValue(2, 3, 0, -453.22234567543);
244 sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::ROUND, 4);
245 aTransform.Transform(*m_pDoc);
247 CPPUNIT_ASSERT_EQUAL(2034.3425, m_pDoc->GetValue(2, 0, 0));
248 CPPUNIT_ASSERT_EQUAL(2342.2527, m_pDoc->GetValue(2, 1, 0));
249 CPPUNIT_ASSERT_EQUAL(57453.6513, m_pDoc->GetValue(2, 2, 0));
250 CPPUNIT_ASSERT_EQUAL(-453.2223, m_pDoc->GetValue(2, 3, 0));
253 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testNumberRoundUp)
255 m_pDoc->SetValue(2, 0, 0, 2034.34);
256 m_pDoc->SetValue(2, 1, 0, 2342.22);
257 m_pDoc->SetValue(2, 2, 0, 57453.65);
258 m_pDoc->SetValue(2, 3, 0, -453.22);
260 sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::ROUND_UP);
261 aTransform.Transform(*m_pDoc);
263 CPPUNIT_ASSERT_EQUAL(2035.0, m_pDoc->GetValue(2, 0, 0));
264 CPPUNIT_ASSERT_EQUAL(2343.0, m_pDoc->GetValue(2, 1, 0));
265 CPPUNIT_ASSERT_EQUAL(57454.0, m_pDoc->GetValue(2, 2, 0));
266 CPPUNIT_ASSERT_EQUAL(-453.0, m_pDoc->GetValue(2, 3, 0));
269 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testNumberRoundDown)
271 m_pDoc->SetValue(2, 0, 0, 2034.34);
272 m_pDoc->SetValue(2, 1, 0, 2342.22);
273 m_pDoc->SetValue(2, 2, 0, 57453.65);
274 m_pDoc->SetValue(2, 3, 0, -453.22);
276 sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::ROUND_DOWN);
277 aTransform.Transform(*m_pDoc);
279 CPPUNIT_ASSERT_EQUAL(2034.0, m_pDoc->GetValue(2, 0, 0));
280 CPPUNIT_ASSERT_EQUAL(2342.0, m_pDoc->GetValue(2, 1, 0));
281 CPPUNIT_ASSERT_EQUAL(57453.0, m_pDoc->GetValue(2, 2, 0));
282 CPPUNIT_ASSERT_EQUAL(-454.0, m_pDoc->GetValue(2, 3, 0));
285 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testNumberAbsolute)
287 m_pDoc->SetValue(2, 0, 0, 2034.34);
288 m_pDoc->SetValue(2, 1, 0, -2342.22);
289 m_pDoc->SetValue(2, 2, 0, 57453.65);
290 m_pDoc->SetValue(2, 3, 0, -453.22);
292 sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::ABSOLUTE);
293 aTransform.Transform(*m_pDoc);
295 CPPUNIT_ASSERT_EQUAL(2034.34, m_pDoc->GetValue(2, 0, 0));
296 CPPUNIT_ASSERT_EQUAL(2342.22, m_pDoc->GetValue(2, 1, 0));
297 CPPUNIT_ASSERT_EQUAL(57453.65, m_pDoc->GetValue(2, 2, 0));
298 CPPUNIT_ASSERT_EQUAL(453.22, m_pDoc->GetValue(2, 3, 0));
301 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testNumberLogE)
303 m_pDoc->SetValue(2, 0, 0, 1);
304 m_pDoc->SetValue(2, 1, 0, 5);
305 m_pDoc->SetValue(2, 2, 0, -9);
306 m_pDoc->SetValue(2, 3, 0, 500);
308 sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::LOG_E);
309 aTransform.Transform(*m_pDoc);
311 CPPUNIT_ASSERT_DOUBLES_EQUAL(0, m_pDoc->GetValue(2, 0, 0), 1e-10);
312 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.60943791243, m_pDoc->GetValue(2, 1, 0), 1e-10);
313 CPPUNIT_ASSERT_EQUAL(OUString(""), m_pDoc->GetString(2, 2, 0));
314 CPPUNIT_ASSERT_DOUBLES_EQUAL(6.21460809842, m_pDoc->GetValue(2, 3, 0), 1e-10);
317 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testNumberLog10)
319 m_pDoc->SetValue(2, 0, 0, 1);
320 m_pDoc->SetValue(2, 1, 0, 10);
321 m_pDoc->SetValue(2, 2, 0, -9);
322 m_pDoc->SetValue(2, 3, 0, 500);
324 sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::LOG_10);
325 aTransform.Transform(*m_pDoc);
327 CPPUNIT_ASSERT_DOUBLES_EQUAL(0, m_pDoc->GetValue(2, 0, 0), 1e-10);
328 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, m_pDoc->GetValue(2, 1, 0), 1e-10);
329 CPPUNIT_ASSERT_EQUAL(OUString(), m_pDoc->GetString(2, 2, 0));
330 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.69897000434, m_pDoc->GetValue(2, 3, 0), 1e-10);
333 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testNumberCube)
335 m_pDoc->SetValue(2, 0, 0, 2);
336 m_pDoc->SetValue(2, 1, 0, -2);
337 m_pDoc->SetValue(2, 2, 0, 8);
338 m_pDoc->SetValue(2, 3, 0, -8);
340 sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::CUBE);
341 aTransform.Transform(*m_pDoc);
343 CPPUNIT_ASSERT_EQUAL(8.0, m_pDoc->GetValue(2, 0, 0));
344 CPPUNIT_ASSERT_EQUAL(-8.0, m_pDoc->GetValue(2, 1, 0));
345 CPPUNIT_ASSERT_EQUAL(512.0, m_pDoc->GetValue(2, 2, 0));
346 CPPUNIT_ASSERT_EQUAL(-512.0, m_pDoc->GetValue(2, 3, 0));
349 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testNumberSquare)
351 m_pDoc->SetValue(2, 0, 0, 2);
352 m_pDoc->SetValue(2, 1, 0, -2);
353 m_pDoc->SetValue(2, 2, 0, 8);
354 m_pDoc->SetValue(2, 3, 0, -8);
356 sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::SQUARE);
357 aTransform.Transform(*m_pDoc);
359 CPPUNIT_ASSERT_EQUAL(4.0, m_pDoc->GetValue(2, 0, 0));
360 CPPUNIT_ASSERT_EQUAL(4.0, m_pDoc->GetValue(2, 1, 0));
361 CPPUNIT_ASSERT_EQUAL(64.0, m_pDoc->GetValue(2, 2, 0));
362 CPPUNIT_ASSERT_EQUAL(64.0, m_pDoc->GetValue(2, 3, 0));
365 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testNumberSquareRoot)
367 m_pDoc->SetValue(2, 0, 0, 8);
368 m_pDoc->SetValue(2, 1, 0, 4);
369 m_pDoc->SetValue(2, 2, 0, 9);
371 sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::SQUARE_ROOT);
372 aTransform.Transform(*m_pDoc);
374 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.82842712475, m_pDoc->GetValue(2, 0, 0), 1e-10);
375 CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, m_pDoc->GetValue(2, 1, 0), 1e-10);
376 CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0, m_pDoc->GetValue(2, 2, 0), 1e-10);
379 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testNumberEven)
381 m_pDoc->SetValue(2, 0, 0, 2034);
382 m_pDoc->SetValue(2, 1, 0, 2343);
383 m_pDoc->SetValue(2, 2, 0, 57453.65);
384 m_pDoc->SetValue(2, 3, 0, -453);
386 sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::IS_EVEN);
387 aTransform.Transform(*m_pDoc);
389 CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(2, 0, 0));
390 CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(2, 1, 0));
391 CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(2, 2, 0));
392 CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(2, 3, 0));
395 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testNumberOdd)
397 m_pDoc->SetValue(2, 0, 0, 2034);
398 m_pDoc->SetValue(2, 1, 0, 2343);
399 m_pDoc->SetValue(2, 2, 0, 57453.65);
400 m_pDoc->SetValue(2, 3, 0, -453);
402 sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::IS_ODD);
403 aTransform.Transform(*m_pDoc);
405 CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(2, 0, 0));
406 CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(2, 1, 0));
407 CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(2, 2, 0));
408 CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(2, 3, 0));
411 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testNumberSign)
413 m_pDoc->SetValue(2, 0, 0, 2034.34);
414 m_pDoc->SetValue(2, 1, 0, -2342.22);
415 m_pDoc->SetValue(2, 2, 0, 0);
416 m_pDoc->SetValue(2, 3, 0, -453.22);
418 sc::NumberTransformation aTransform({2}, sc::NUMBER_TRANSFORM_TYPE::SIGN);
419 aTransform.Transform(*m_pDoc);
421 CPPUNIT_ASSERT_EQUAL(1.0, m_pDoc->GetValue(2, 0, 0));
422 CPPUNIT_ASSERT_EQUAL(-1.0, m_pDoc->GetValue(2, 1, 0));
423 CPPUNIT_ASSERT_EQUAL(0.0, m_pDoc->GetValue(2, 2, 0));
424 CPPUNIT_ASSERT_EQUAL(-1.0, m_pDoc->GetValue(2, 3, 0));
427 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testReplaceNull)
429 m_pDoc->SetString(2, 0, 0, "Berlin");
430 m_pDoc->SetString(2, 1, 0, "");
431 m_pDoc->SetString(2, 2, 0, "");
432 m_pDoc->SetString(2, 3, 0, "Peking");
434 sc::ReplaceNullTransformation aTransform({2}, "Empty");
435 aTransform.Transform(*m_pDoc);
437 CPPUNIT_ASSERT_EQUAL(OUString("Berlin"), m_pDoc->GetString(2, 0, 0));
438 CPPUNIT_ASSERT_EQUAL(OUString("Empty"), m_pDoc->GetString(2, 1, 0));
439 CPPUNIT_ASSERT_EQUAL(OUString("Empty"), m_pDoc->GetString(2, 2, 0));
440 CPPUNIT_ASSERT_EQUAL(OUString("Peking"), m_pDoc->GetString(2, 3, 0));
444 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testGetDateString)
446 SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
447 css::util::Date aDate1(25,1,2011);
448 css::util::Date aDate2(12,10,1994);
449 css::util::Date aDate3(23,9,1996);
450 css::util::Date aDate4(15,8,1947);
452 double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
453 double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
454 double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
455 double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
457 m_pDoc->SetValue(2, 0, 0, nDate1);
458 m_pDoc->SetValue(2, 1, 0, nDate2);
459 m_pDoc->SetValue(2, 2, 0, nDate3);
460 m_pDoc->SetValue(2, 3, 0, nDate4);
462 sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::DATE_STRING );
463 aTransform.Transform(*m_pDoc);
465 CPPUNIT_ASSERT_EQUAL(OUString("01/25/11"), m_pDoc->GetString(2, 0, 0));
466 CPPUNIT_ASSERT_EQUAL(OUString("10/12/94"), m_pDoc->GetString(2, 1, 0));
467 CPPUNIT_ASSERT_EQUAL(OUString("09/23/96"), m_pDoc->GetString(2, 2, 0));
468 CPPUNIT_ASSERT_EQUAL(OUString("08/15/47"), m_pDoc->GetString(2, 3, 0));
471 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testGetYear)
473 SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
474 css::util::Date aDate1(25,1,2011);
475 css::util::Date aDate2(12,10,1994);
476 css::util::Date aDate3(23,9,1996);
477 css::util::Date aDate4(15,8,1947);
479 double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
480 double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
481 double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
482 double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
484 m_pDoc->SetValue(2, 0, 0, nDate1);
485 m_pDoc->SetValue(2, 1, 0, nDate2);
486 m_pDoc->SetValue(2, 2, 0, nDate3);
487 m_pDoc->SetValue(2, 3, 0, nDate4);
489 sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::YEAR );
490 aTransform.Transform(*m_pDoc);
492 CPPUNIT_ASSERT_DOUBLES_EQUAL(2011, m_pDoc->GetValue(2, 0, 0), 0);
493 CPPUNIT_ASSERT_DOUBLES_EQUAL(1994, m_pDoc->GetValue(2, 1, 0), 0);
494 CPPUNIT_ASSERT_DOUBLES_EQUAL(1996, m_pDoc->GetValue(2, 2, 0), 0);
495 CPPUNIT_ASSERT_DOUBLES_EQUAL(1947, m_pDoc->GetValue(2, 3, 0), 0);
498 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testGetStartOfYear)
500 SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
501 css::util::Date aDate1(25,1,2011);
502 css::util::Date aDate2(12,10,1994);
503 css::util::Date aDate3(23,9,1996);
504 css::util::Date aDate4(15,8,1947);
506 double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
507 double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
508 double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
509 double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
511 m_pDoc->SetValue(2, 0, 0, nDate1);
512 m_pDoc->SetValue(2, 1, 0, nDate2);
513 m_pDoc->SetValue(2, 2, 0, nDate3);
514 m_pDoc->SetValue(2, 3, 0, nDate4);
516 sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::START_OF_YEAR );
517 aTransform.Transform(*m_pDoc);
519 CPPUNIT_ASSERT_EQUAL(OUString("01/01/11"), m_pDoc->GetString(2, 0, 0));
520 CPPUNIT_ASSERT_EQUAL(OUString("01/01/94"), m_pDoc->GetString(2, 1, 0));
521 CPPUNIT_ASSERT_EQUAL(OUString("01/01/96"), m_pDoc->GetString(2, 2, 0));
522 CPPUNIT_ASSERT_EQUAL(OUString("01/01/47"), m_pDoc->GetString(2, 3, 0));
525 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testGetEndOfYear)
527 SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
528 css::util::Date aDate1(25,1,2011);
529 css::util::Date aDate2(12,10,1994);
530 css::util::Date aDate3(23,9,1996);
531 css::util::Date aDate4(15,8,1947);
533 double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
534 double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
535 double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
536 double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
538 m_pDoc->SetValue(2, 0, 0, nDate1);
539 m_pDoc->SetValue(2, 1, 0, nDate2);
540 m_pDoc->SetValue(2, 2, 0, nDate3);
541 m_pDoc->SetValue(2, 3, 0, nDate4);
543 sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::END_OF_YEAR );
544 aTransform.Transform(*m_pDoc);
546 CPPUNIT_ASSERT_EQUAL(OUString("12/31/11"), m_pDoc->GetString(2, 0, 0));
547 CPPUNIT_ASSERT_EQUAL(OUString("12/31/94"), m_pDoc->GetString(2, 1, 0));
548 CPPUNIT_ASSERT_EQUAL(OUString("12/31/96"), m_pDoc->GetString(2, 2, 0));
549 CPPUNIT_ASSERT_EQUAL(OUString("12/31/47"), m_pDoc->GetString(2, 3, 0));
552 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testGetMonth)
554 SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
555 css::util::Date aDate1(25,1,2011);
556 css::util::Date aDate2(12,10,1994);
557 css::util::Date aDate3(23,9,1996);
558 css::util::Date aDate4(15,8,1947);
560 double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
561 double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
562 double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
563 double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
565 m_pDoc->SetValue(2, 0, 0, nDate1);
566 m_pDoc->SetValue(2, 1, 0, nDate2);
567 m_pDoc->SetValue(2, 2, 0, nDate3);
568 m_pDoc->SetValue(2, 3, 0, nDate4);
570 sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::MONTH );
571 aTransform.Transform(*m_pDoc);
573 CPPUNIT_ASSERT_DOUBLES_EQUAL(1, m_pDoc->GetValue(2, 0, 0), 0);
574 CPPUNIT_ASSERT_DOUBLES_EQUAL(10, m_pDoc->GetValue(2, 1, 0), 0);
575 CPPUNIT_ASSERT_DOUBLES_EQUAL(9, m_pDoc->GetValue(2, 2, 0), 0);
576 CPPUNIT_ASSERT_DOUBLES_EQUAL(8, m_pDoc->GetValue(2, 3, 0), 0);
579 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testGetMonthName)
581 SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
582 css::util::Date aDate1(25,1,2011);
583 css::util::Date aDate2(12,10,1994);
584 css::util::Date aDate3(23,9,1996);
585 css::util::Date aDate4(15,8,1947);
587 double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
588 double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
589 double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
590 double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
592 m_pDoc->SetValue(2, 0, 0, nDate1);
593 m_pDoc->SetValue(2, 1, 0, nDate2);
594 m_pDoc->SetValue(2, 2, 0, nDate3);
595 m_pDoc->SetValue(2, 3, 0, nDate4);
597 sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::MONTH_NAME);
598 aTransform.Transform(*m_pDoc);
600 CPPUNIT_ASSERT_EQUAL(OUString("January"), m_pDoc->GetString(2, 0, 0));
601 CPPUNIT_ASSERT_EQUAL(OUString("October"), m_pDoc->GetString(2, 1, 0));
602 CPPUNIT_ASSERT_EQUAL(OUString("September"), m_pDoc->GetString(2, 2, 0));
603 CPPUNIT_ASSERT_EQUAL(OUString("August"), m_pDoc->GetString(2, 3, 0));
606 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testGetStartOfMonth)
608 SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
609 css::util::Date aDate1(25,1,2011);
610 css::util::Date aDate2(12,10,1994);
611 css::util::Date aDate3(23,9,1996);
612 css::util::Date aDate4(15,8,1947);
614 double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
615 double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
616 double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
617 double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
619 m_pDoc->SetValue(2, 0, 0, nDate1);
620 m_pDoc->SetValue(2, 1, 0, nDate2);
621 m_pDoc->SetValue(2, 2, 0, nDate3);
622 m_pDoc->SetValue(2, 3, 0, nDate4);
624 sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::START_OF_MONTH );
625 aTransform.Transform(*m_pDoc);
627 CPPUNIT_ASSERT_EQUAL(OUString("01/01/11"), m_pDoc->GetString(2, 0, 0));
628 CPPUNIT_ASSERT_EQUAL(OUString("10/01/94"), m_pDoc->GetString(2, 1, 0));
629 CPPUNIT_ASSERT_EQUAL(OUString("09/01/96"), m_pDoc->GetString(2, 2, 0));
630 CPPUNIT_ASSERT_EQUAL(OUString("08/01/47"), m_pDoc->GetString(2, 3, 0));
633 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testGetEndOfMonth)
635 SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
636 css::util::Date aDate1(25,1,2011);
637 css::util::Date aDate2(12,10,1994);
638 css::util::Date aDate3(23,9,1996);
639 css::util::Date aDate4(15,8,1947);
641 double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
642 double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
643 double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
644 double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
646 m_pDoc->SetValue(2, 0, 0, nDate1);
647 m_pDoc->SetValue(2, 1, 0, nDate2);
648 m_pDoc->SetValue(2, 2, 0, nDate3);
649 m_pDoc->SetValue(2, 3, 0, nDate4);
651 sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::END_OF_MONTH );
652 aTransform.Transform(*m_pDoc);
654 CPPUNIT_ASSERT_EQUAL(OUString("01/31/11"), m_pDoc->GetString(2, 0, 0));
655 CPPUNIT_ASSERT_EQUAL(OUString("10/31/94"), m_pDoc->GetString(2, 1, 0));
656 CPPUNIT_ASSERT_EQUAL(OUString("09/30/96"), m_pDoc->GetString(2, 2, 0));
657 CPPUNIT_ASSERT_EQUAL(OUString("08/31/47"), m_pDoc->GetString(2, 3, 0));
660 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testGetDay)
662 SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
663 css::util::Date aDate1(25,1,2011);
664 css::util::Date aDate2(12,10,1994);
665 css::util::Date aDate3(23,9,1996);
666 css::util::Date aDate4(15,8,1947);
668 double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
669 double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
670 double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
671 double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
673 m_pDoc->SetValue(2, 0, 0, nDate1);
674 m_pDoc->SetValue(2, 1, 0, nDate2);
675 m_pDoc->SetValue(2, 2, 0, nDate3);
676 m_pDoc->SetValue(2, 3, 0, nDate4);
678 sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::DAY );
679 aTransform.Transform(*m_pDoc);
681 CPPUNIT_ASSERT_DOUBLES_EQUAL(25, m_pDoc->GetValue(2, 0, 0), 0);
682 CPPUNIT_ASSERT_DOUBLES_EQUAL(12, m_pDoc->GetValue(2, 1, 0), 0);
683 CPPUNIT_ASSERT_DOUBLES_EQUAL(23, m_pDoc->GetValue(2, 2, 0), 0);
684 CPPUNIT_ASSERT_DOUBLES_EQUAL(15, m_pDoc->GetValue(2, 3, 0), 0);
687 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testGetDayOfWeek)
689 SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
690 css::util::Date aDate1(25,1,2011);
691 css::util::Date aDate2(12,10,1994);
692 css::util::Date aDate3(23,9,1996);
693 css::util::Date aDate4(15,8,1947);
695 double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
696 double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
697 double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
698 double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
700 m_pDoc->SetValue(2, 0, 0, nDate1);
701 m_pDoc->SetValue(2, 1, 0, nDate2);
702 m_pDoc->SetValue(2, 2, 0, nDate3);
703 m_pDoc->SetValue(2, 3, 0, nDate4);
705 sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::DAY_OF_WEEK );
706 aTransform.Transform(*m_pDoc);
708 CPPUNIT_ASSERT_DOUBLES_EQUAL(1, m_pDoc->GetValue(2, 0, 0), 0);
709 CPPUNIT_ASSERT_DOUBLES_EQUAL(2, m_pDoc->GetValue(2, 1, 0), 0);
710 CPPUNIT_ASSERT_DOUBLES_EQUAL(0, m_pDoc->GetValue(2, 2, 0), 0);
711 CPPUNIT_ASSERT_DOUBLES_EQUAL(4, m_pDoc->GetValue(2, 3, 0), 0);
714 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testGetDayOfYear)
716 SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
717 css::util::Date aDate1(25,1,2011);
718 css::util::Date aDate2(12,10,1994);
719 css::util::Date aDate3(23,9,1996);
720 css::util::Date aDate4(15,8,1947);
722 double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
723 double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
724 double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
725 double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
727 m_pDoc->SetValue(2, 0, 0, nDate1);
728 m_pDoc->SetValue(2, 1, 0, nDate2);
729 m_pDoc->SetValue(2, 2, 0, nDate3);
730 m_pDoc->SetValue(2, 3, 0, nDate4);
732 sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::DAY_OF_YEAR );
733 aTransform.Transform(*m_pDoc);
735 CPPUNIT_ASSERT_DOUBLES_EQUAL(25, m_pDoc->GetValue(2, 0, 0), 0);
736 CPPUNIT_ASSERT_DOUBLES_EQUAL(285, m_pDoc->GetValue(2, 1, 0), 0);
737 CPPUNIT_ASSERT_DOUBLES_EQUAL(267, m_pDoc->GetValue(2, 2, 0), 0);
738 CPPUNIT_ASSERT_DOUBLES_EQUAL(227, m_pDoc->GetValue(2, 3, 0), 0);
741 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testGetQuarter)
743 SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
744 css::util::Date aDate1(25,1,2011);
745 css::util::Date aDate2(12,10,1994);
746 css::util::Date aDate3(23,9,1996);
747 css::util::Date aDate4(15,8,1947);
749 double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
750 double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
751 double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
752 double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
754 m_pDoc->SetValue(2, 0, 0, nDate1);
755 m_pDoc->SetValue(2, 1, 0, nDate2);
756 m_pDoc->SetValue(2, 2, 0, nDate3);
757 m_pDoc->SetValue(2, 3, 0, nDate4);
759 sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::QUARTER );
760 aTransform.Transform(*m_pDoc);
762 CPPUNIT_ASSERT_DOUBLES_EQUAL(1, m_pDoc->GetValue(2, 0, 0), 0);
763 CPPUNIT_ASSERT_DOUBLES_EQUAL(4, m_pDoc->GetValue(2, 1, 0), 0);
764 CPPUNIT_ASSERT_DOUBLES_EQUAL(3, m_pDoc->GetValue(2, 2, 0), 0);
765 CPPUNIT_ASSERT_DOUBLES_EQUAL(3, m_pDoc->GetValue(2, 3, 0), 0);
768 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testGetStartOfQuarter)
770 SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
771 css::util::Date aDate1(25,1,2011);
772 css::util::Date aDate2(12,10,1994);
773 css::util::Date aDate3(23,9,1996);
774 css::util::Date aDate4(15,8,1947);
776 double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
777 double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
778 double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
779 double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
781 m_pDoc->SetValue(2, 0, 0, nDate1);
782 m_pDoc->SetValue(2, 1, 0, nDate2);
783 m_pDoc->SetValue(2, 2, 0, nDate3);
784 m_pDoc->SetValue(2, 3, 0, nDate4);
786 sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::START_OF_QUARTER );
787 aTransform.Transform(*m_pDoc);
789 CPPUNIT_ASSERT_EQUAL(OUString("01/01/11"), m_pDoc->GetString(2, 0, 0));
790 CPPUNIT_ASSERT_EQUAL(OUString("10/01/94"), m_pDoc->GetString(2, 1, 0));
791 CPPUNIT_ASSERT_EQUAL(OUString("07/01/96"), m_pDoc->GetString(2, 2, 0));
792 CPPUNIT_ASSERT_EQUAL(OUString("07/01/47"), m_pDoc->GetString(2, 3, 0));
795 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testGetEndOfQuarter)
797 SvNumberFormatter* pFormatter = m_pDoc->GetFormatTable();
798 css::util::Date aDate1(25,1,2011);
799 css::util::Date aDate2(12,10,1994);
800 css::util::Date aDate3(23,9,1996);
801 css::util::Date aDate4(15,8,1947);
803 double nDate1 = static_cast<double>(aDate1 - pFormatter->GetNullDate());
804 double nDate2 = static_cast<double>(aDate2 - pFormatter->GetNullDate());
805 double nDate3 = static_cast<double>(aDate3 - pFormatter->GetNullDate());
806 double nDate4 = static_cast<double>(aDate4 - pFormatter->GetNullDate());
808 m_pDoc->SetValue(2, 0, 0, nDate1);
809 m_pDoc->SetValue(2, 1, 0, nDate2);
810 m_pDoc->SetValue(2, 2, 0, nDate3);
811 m_pDoc->SetValue(2, 3, 0, nDate4);
813 sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::END_OF_QUARTER );
814 aTransform.Transform(*m_pDoc);
816 CPPUNIT_ASSERT_EQUAL(OUString("03/31/11"), m_pDoc->GetString(2, 0, 0));
817 CPPUNIT_ASSERT_EQUAL(OUString("12/31/94"), m_pDoc->GetString(2, 1, 0));
818 CPPUNIT_ASSERT_EQUAL(OUString("09/30/96"), m_pDoc->GetString(2, 2, 0));
819 CPPUNIT_ASSERT_EQUAL(OUString("09/30/47"), m_pDoc->GetString(2, 3, 0));
822 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testGetTime)
824 tools::Time aTime1(5,30,12);
825 tools::Time aTime2(7,23,9);
826 tools::Time aTime3(9,34,40);
827 tools::Time aTime4(22,9,49);
829 m_pDoc->SetValue(2, 0, 0, aTime1.GetTimeInDays());
830 m_pDoc->SetValue(2, 1, 0, aTime2.GetTimeInDays());
831 m_pDoc->SetValue(2, 2, 0, aTime3.GetTimeInDays());
832 m_pDoc->SetValue(2, 3, 0, aTime4.GetTimeInDays());
834 sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::TIME );
835 aTransform.Transform(*m_pDoc);
837 CPPUNIT_ASSERT_EQUAL(OUString("05:30:12 AM"), m_pDoc->GetString(2, 0, 0));
838 CPPUNIT_ASSERT_EQUAL(OUString("07:23:09 AM"), m_pDoc->GetString(2, 1, 0));
839 CPPUNIT_ASSERT_EQUAL(OUString("09:34:40 AM"), m_pDoc->GetString(2, 2, 0));
840 CPPUNIT_ASSERT_EQUAL(OUString("10:09:49 PM"), m_pDoc->GetString(2, 3, 0));
843 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testGetHour)
845 tools::Time aTime1(5,30,12);
846 tools::Time aTime2(7,23,9);
847 tools::Time aTime3(9,34,40);
848 tools::Time aTime4(22,9,49);
850 m_pDoc->SetValue(2, 0, 0, aTime1.GetTimeInDays());
851 m_pDoc->SetValue(2, 1, 0, aTime2.GetTimeInDays());
852 m_pDoc->SetValue(2, 2, 0, aTime3.GetTimeInDays());
853 m_pDoc->SetValue(2, 3, 0, aTime4.GetTimeInDays());
855 sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::HOUR );
856 aTransform.Transform(*m_pDoc);
858 CPPUNIT_ASSERT_DOUBLES_EQUAL(5, m_pDoc->GetValue(2, 0, 0), 0);
859 CPPUNIT_ASSERT_DOUBLES_EQUAL(7, m_pDoc->GetValue(2, 1, 0), 0);
860 CPPUNIT_ASSERT_DOUBLES_EQUAL(9, m_pDoc->GetValue(2, 2, 0), 0);
861 CPPUNIT_ASSERT_DOUBLES_EQUAL(22, m_pDoc->GetValue(2, 3, 0), 0);
864 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testGetMinute)
866 tools::Time aTime1(5,30,12);
867 tools::Time aTime2(7,23,9);
868 tools::Time aTime3(9,34,40);
869 tools::Time aTime4(22,9,49);
871 m_pDoc->SetValue(2, 0, 0, aTime1.GetTimeInDays());
872 m_pDoc->SetValue(2, 1, 0, aTime2.GetTimeInDays());
873 m_pDoc->SetValue(2, 2, 0, aTime3.GetTimeInDays());
874 m_pDoc->SetValue(2, 3, 0, aTime4.GetTimeInDays());
876 sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::MINUTE );
877 aTransform.Transform(*m_pDoc);
879 CPPUNIT_ASSERT_DOUBLES_EQUAL(30, m_pDoc->GetValue(2, 0, 0), 0);
880 CPPUNIT_ASSERT_DOUBLES_EQUAL(23, m_pDoc->GetValue(2, 1, 0), 0);
881 CPPUNIT_ASSERT_DOUBLES_EQUAL(34, m_pDoc->GetValue(2, 2, 0), 0);
882 CPPUNIT_ASSERT_DOUBLES_EQUAL(9, m_pDoc->GetValue(2, 3, 0), 0);
885 CPPUNIT_TEST_FIXTURE(ScDataTransformationTest, testGetSecond)
887 tools::Time aTime1(5,30,53);
888 tools::Time aTime2(7,23,10);
889 tools::Time aTime3(9,34,40);
890 tools::Time aTime4(22,9,49);
892 m_pDoc->SetValue(2, 0, 0, aTime1.GetTimeInDays());
893 m_pDoc->SetValue(2, 1, 0, aTime2.GetTimeInDays());
894 m_pDoc->SetValue(2, 2, 0, aTime3.GetTimeInDays());
895 m_pDoc->SetValue(2, 3, 0, aTime4.GetTimeInDays());
897 sc:: DateTimeTransformation aTransform({2}, sc::DATETIME_TRANSFORMATION_TYPE::SECOND );
898 aTransform.Transform(*m_pDoc);
900 CPPUNIT_ASSERT_DOUBLES_EQUAL(53, m_pDoc->GetValue(2, 0, 0), 0);
901 CPPUNIT_ASSERT_DOUBLES_EQUAL(10, m_pDoc->GetValue(2, 1, 0), 0);
902 CPPUNIT_ASSERT_DOUBLES_EQUAL(40, m_pDoc->GetValue(2, 2, 0), 0);
903 CPPUNIT_ASSERT_DOUBLES_EQUAL(49, m_pDoc->GetValue(2, 3, 0), 0);
906 void ScDataTransformationTest::setUp()
908 ScUcalcTestBase::setUp();
909 m_pDoc->InsertTab(0, "Tab");
912 CPPUNIT_PLUGIN_IMPLEMENT();
914 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */