Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / qa / unit / functions_test.cxx
blob40504480d04d54ad146f2f768e0b314f9475b74b
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 */
11 #include "functions_test.hxx"
12 #include <document.hxx>
14 #include <rtl/math.hxx>
16 FunctionsTest::FunctionsTest():
17 ScFilterTestBase()
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
45 // the formula text.
46 if(rDoc.HasStringData(2, row, tab) || !rDoc.HasData(2, row, tab))
47 continue;
48 if(!rtl::math::approxEqual(1.0, rDoc.GetValue(2, row, 1)))
49 CPPUNIT_FAIL( OUString( "Testing " + rURL + " failed, "
50 + rDoc.GetAllTableNames()[tab] + ".A" + OUString::number(row+1)
51 + " \'" + rDoc.GetString(3, row, 1) + "\'"
52 " result: " + OUString::number(rDoc.GetValue(0, row, 1))
53 + ", expected: " + OUString::number(rDoc.GetValue(1, row, 1)))
54 .toUtf8().getStr());
58 CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, rDoc.GetValue(1, 2, 0), 1e-14);
60 xDocShRef->DoClose();
62 return true;
65 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */