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/.
11 #include "functions_test.hxx"
12 #include <document.hxx>
14 #include <rtl/math.hxx>
16 FunctionsTest::FunctionsTest():
21 bool FunctionsTest::load(const OUString
& rFilter
, const OUString
& rURL
,
22 const OUString
& rUserData
, SfxFilterFlags nFilterFlags
,
23 SotClipboardFormatId nClipboardID
,
24 unsigned int nFilterVersion
)
26 ScDocShellRef xDocShRef
= loadDoc(rURL
, rFilter
, rUserData
,
27 OUString(), nFilterFlags
, nClipboardID
, nFilterVersion
);
28 CPPUNIT_ASSERT(xDocShRef
.is());
30 xDocShRef
->DoHardRecalc();
32 ScDocument
& rDoc
= xDocShRef
->GetDocument();
34 if(!rtl::math::approxEqual(1.0, rDoc
.GetValue(1, 2, 0)))
36 // Cell B3 in Sheet1 has the cumulative success/failure result.
37 // Try to find the actual failure.
38 for(SCTAB tab
= 1; tab
<= rDoc
.GetMaxTableNumber(); ++tab
)
40 SCROW maxRow
= rDoc
.GetLastDataRow(tab
, 2, 2, rDoc
.MaxRow());
41 for(SCROW row
= 0; row
<= maxRow
; ++row
)
43 // Column A has the result value, column B has the expected
44 // value, Column C has the check result (1 or 0), column D has
46 if(rDoc
.HasStringData(2, row
, tab
) || !rDoc
.HasData(2, row
, tab
))
48 if (!rtl::math::approxEqual(1.0, rDoc
.GetValue(2, row
, tab
)))
50 if (rDoc
.HasValueData(1, row
, tab
))
52 // snprintf provides requested precision, unlike OUString::number, which
53 // rounds to 15 decimals
55 int len
= snprintf(buf
, 25, "%.17G", rDoc
.GetValue(0, row
, tab
));
56 OUString
result(OUString::createFromAscii(std::string_view(buf
, len
)));
57 len
= snprintf(buf
, 25, "%.17G", rDoc
.GetValue(1, row
, tab
));
58 OUString
expected(OUString::createFromAscii(std::string_view(buf
, len
)));
59 CPPUNIT_FAIL( OUString( "Testing " + rURL
+ " failed, "
60 + rDoc
.GetAllTableNames()[tab
] + ".A" + OUString::number(row
+1)
61 + " \'" + rDoc
.GetString(3, row
, tab
) + "\'"
63 + ", expected: " + expected
)
68 CPPUNIT_FAIL( OUString( "Testing " + rURL
+ " failed, "
69 + rDoc
.GetAllTableNames()[tab
] + ".A" + OUString::number(row
+1)
70 + " \'" + rDoc
.GetString(3, row
, tab
) + "\'"
71 " result: " + rDoc
.GetString(0, row
, tab
)
72 + ", expected: " + rDoc
.GetString(1, row
, tab
))
79 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, rDoc
.GetValue(1, 2, 0), 1e-14);
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */