/* -*- 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/.
*/
void ScModelTestBase::testFormats(ScDocument* pDoc,std::u16string_view sFormat)
{ //test Sheet1 with csv file
OUString aCSVFileName = createFilePath(u"contentCSV/numberFormat.csv");
testFile(aCSVFileName, *pDoc, 0, StringType::PureString); //need to test the color of B3 //it's not a font color! //formatting for B5: # ??/100 gets lost during import
pPattern->fillFontOnly(aFont);
pPattern->fillColor(aComplexColor, ScAutoFontColorMode::Raw);
CPPUNIT_ASSERT_EQUAL_MESSAGE("font size should be 10", tools::Long(200), aFont.GetFontSize().getHeight());
CPPUNIT_ASSERT_EQUAL_MESSAGE("font color should be black", COL_AUTO, aComplexColor.getFinalColor());
pPattern = pDoc->GetPattern(0,1,1);
pPattern->fillFontOnly(aFont);
CPPUNIT_ASSERT_EQUAL_MESSAGE("font size should be 12", tools::Long(240), aFont.GetFontSize().getHeight());
pPattern = pDoc->GetPattern(0,2,1);
pPattern->fillFontOnly(aFont);
CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be italic", ITALIC_NORMAL, aFont.GetItalicMaybeAskConfig());
pPattern = pDoc->GetPattern(0,4,1);
pPattern->fillFontOnly(aFont);
CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be bold", WEIGHT_BOLD, aFont.GetWeightMaybeAskConfig());
pPattern = pDoc->GetPattern(1,0,1);
pPattern->fillFontOnly(aFont);
pPattern->fillColor(aComplexColor, ScAutoFontColorMode::Raw);
CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be blue", COL_BLUE, aComplexColor.getFinalColor());
pPattern = pDoc->GetPattern(1,1,1);
pPattern->fillFontOnly(aFont);
CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be striked out with a single line", STRIKEOUT_SINGLE, aFont.GetStrikeout()); //some tests on sheet2 only for ods if (sFormat == u"calc8")
{
pPattern = pDoc->GetPattern(1,2,1);
pPattern->fillFontOnly(aFont);
CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be striked out with a double line", STRIKEOUT_DOUBLE, aFont.GetStrikeout());
pPattern = pDoc->GetPattern(1,3,1);
pPattern->fillFontOnly(aFont);
CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be underlined with a dotted line", LINESTYLE_DOTTED, aFont.GetUnderline()); //check row height import //disable for now until we figure out cause of win tinderboxes test failures //CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(256), pDoc->GetRowHeight(0,1) ); //0.178in //CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(304), pDoc->GetRowHeight(1,1) ); //0.211in //CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(477), pDoc->GetRowHeight(5,1) ); //0.3311in //check column width import
CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(555), pDoc->GetColWidth(4,1) ); //0.3854in
CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(1280), pDoc->GetColWidth(5,1) ); //0.889in
CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(4153), pDoc->GetColWidth(6,1) ); //2.8839in //test case for i53253 where a cell has text with different styles and space between the text.
OUString aTestStr = pDoc->GetString(3,0,1);
OUString aKnownGoodStr(u"text14 space"_ustr);
CPPUNIT_ASSERT_EQUAL( aKnownGoodStr, aTestStr ); //test case for cell text with line breaks.
aTestStr = pDoc->GetString(3,5,1);
aKnownGoodStr = "Hello,\nCalc!";
CPPUNIT_ASSERT_EQUAL( aKnownGoodStr, aTestStr );
}
pPattern = pDoc->GetPattern(1,4,1);
Color aColor = pPattern->GetItem(ATTR_BACKGROUND).GetColor();
CPPUNIT_ASSERT_EQUAL_MESSAGE("background color should be green", COL_LIGHTGREEN, aColor);
pPattern = pDoc->GetPattern(2,0,1);
SvxCellHorJustify eHorJustify = pPattern->GetItem(ATTR_HOR_JUSTIFY).GetValue();
CPPUNIT_ASSERT_EQUAL_MESSAGE("cell content should be aligned centre horizontally", SvxCellHorJustify::Center, eHorJustify); //test alignment
pPattern = pDoc->GetPattern(2,1,1);
eHorJustify = pPattern->GetItem(ATTR_HOR_JUSTIFY).GetValue();
CPPUNIT_ASSERT_EQUAL_MESSAGE("cell content should be aligned right horizontally", SvxCellHorJustify::Right, eHorJustify);
pPattern = pDoc->GetPattern(2,2,1);
eHorJustify = pPattern->GetItem(ATTR_HOR_JUSTIFY).GetValue();
CPPUNIT_ASSERT_EQUAL_MESSAGE("cell content should be aligned block horizontally", SvxCellHorJustify::Block, eHorJustify);
//test Sheet3 only for ods and xlsx if ( sFormat == u"calc8" || sFormat == u"Calc Office Open XML" )
{
aCSVFileName = createFilePath(u"contentCSV/conditionalFormatting.csv");
testCondFile(aCSVFileName, pDoc, 2); // test parent cell style import ( fdo#55198 ) if ( sFormat == u"Calc Office Open XML" )
{
pPattern = pDoc->GetPattern(1,1,3);
ScStyleSheet* pStyleSheet = const_cast<ScStyleSheet*>(pPattern->GetStyleSheet()); // check parent style name
OUString sExpected(u"Excel Built-in Date"_ustr);
OUString sResult = pStyleSheet->GetName();
CPPUNIT_ASSERT_EQUAL_MESSAGE("parent style for Sheet4.B2 is 'Excel Built-in Date'", sExpected, sResult); // check align of style
SfxItemSet& rItemSet = pStyleSheet->GetItemSet();
eHorJustify = rItemSet.Get( ATTR_HOR_JUSTIFY ).GetValue();
CPPUNIT_ASSERT_EQUAL_MESSAGE("'Excel Built-in Date' style should be aligned centre horizontally", SvxCellHorJustify::Center, eHorJustify); // check date format ( should be just month e.g. 29 )
sResult =pDoc->GetString( 1,1,3 );
sExpected = "29";
CPPUNIT_ASSERT_EQUAL_MESSAGE("'Excel Built-in Date' style should just display month", sExpected, sResult );
// check actual align applied to cell, should be the same as // the style
eHorJustify = pPattern->GetItem( ATTR_HOR_JUSTIFY ).GetValue();
CPPUNIT_ASSERT_EQUAL_MESSAGE("cell with 'Excel Built-in Date' style should be aligned centre horizontally", SvxCellHorJustify::Center, eHorJustify);
}
}
// Make sure the chart object has correct range references.
Reference<frame::XModel> xModel = rChartObj.getXModel(); if (!xModel.is())
{
cout << "Failed to get the embedded object interface." << endl; return aRangeReps;
}
Reference<chart2::XChartDocument> xChartDoc(xModel, UNO_QUERY); if (!xChartDoc.is())
{
cout << "Failed to get the chart document interface." << endl; return aRangeReps;
}
Reference<chart2::data::XDataSource> xDataSource(xChartDoc, UNO_QUERY); if (!xDataSource.is())
{
cout << "Failed to get the data source interface." << endl; return aRangeReps;
}
Sequence<Reference<chart2::data::XLabeledDataSequence> > xDataSeqs = xDataSource->getDataSequences(); if (!xDataSeqs.hasElements())
{
cout << "There should be at least one data sequences." << endl; return aRangeReps;
}
Reference<chart2::data::XDataReceiver> xDataRec(xChartDoc, UNO_QUERY); if (!xDataRec.is())
{
cout << "Failed to get the data receiver interface." << endl; return aRangeReps;
}
ScRangeList ScModelTestBase::getChartRanges(ScDocument& rDoc, const SdrOle2Obj& rChartObj)
{
std::vector<OUString> aRangeReps = getChartRangeRepresentations(rChartObj);
ScRangeList aRanges; for (size_t i = 0, n = aRangeReps.size(); i < n; ++i)
{
ScRange aRange;
ScRefFlags nRes = aRange.Parse(aRangeReps[i], rDoc, rDoc.GetAddressConvention()); if (nRes & ScRefFlags::VALID) // This is a range address.
aRanges.push_back(aRange); else
{ // Parse it as a single cell address.
ScAddress aAddr;
nRes = aAddr.Parse(aRangeReps[i], rDoc, rDoc.GetAddressConvention());
CPPUNIT_ASSERT_MESSAGE("Failed to parse a range representation.", (nRes & ScRefFlags::VALID));
aRanges.push_back(ScRange(aAddr));
}
}
if ( !sExportType.isEmpty() )
saveAndReload(sExportType);
ScDocument* pDoc = getScDoc();
for (int i=0; i<aTestValues[ index ].nRowData; ++i)
{
SCROW nRow = aTestValues[ index ].pData[ i].nStartRow;
SCROW nEndRow = aTestValues[ index ].pData[ i ].nEndRow;
SCTAB nTab = aTestValues[ index ].pData[ i ].nTab; int nExpectedHeight = aTestValues[ index ].pData[ i ].nExpectedHeight; if ( nExpectedHeight == -1 )
nExpectedHeight = convertTwipToMm100(ScGlobal::GetStandardRowHeight()); bool bCheckOpt = ( ( aTestValues[ index ].pData[ i ].nCheck & CHECK_OPTIMAL ) == CHECK_OPTIMAL ); for ( ; nRow <= nEndRow; ++nRow )
{
SAL_INFO( "sc.qa", " checking row " << nRow << " for height " << nExpectedHeight ); int nHeight = convertTwipToMm100(pDoc->GetRowHeight(nRow, nTab, false)); if ( bCheckOpt )
{ bool bOpt = !(pDoc->GetRowFlags( nRow, nTab ) & CRFlags::ManualSize);
CPPUNIT_ASSERT_EQUAL(aTestValues[ index ].pData[ i ].bOptimal, bOpt);
}
CPPUNIT_ASSERT_EQUAL(nExpectedHeight, nHeight);
}
}
}
}
void ScModelTestBase::enableOpenCL()
{ /** * Turn on OpenCL group interpreter. Call this after the document is * loaded and before performing formula calculation.
*/
sc::FormulaGroupInterpreter::enableOpenCL_UnitTestsOnly();
}
// Open the document with OpenCL disabled
mxComponent = mxDesktop->loadComponentFromURL(
createFileURL(fileName), u"_default"_ustr, 0, comphelper::containerToSequence(args));
// it's not possible to open the same document twice, thus, create a temp file
createTempCopy(fileName);
// Open the document with OpenCL enabled
mxComponent2 = mxDesktop->loadComponentFromURL(
maTempFile.GetURL(), u"_default"_ustr, 0, comphelper::containerToSequence(args));
// Check there are 2 documents
uno::Reference<frame::XFrames> xFrames = mxDesktop->getFrames();
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xFrames->getCount());
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.