Skip to content

Commit 87dce61

Browse files
author
Xisco Fauli
committed
UnoApiTest: factor out common code
Change-Id: I1d84d8c1e371016a4f4f068af1e9c76635f28cf4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142490 Tested-by: Jenkins Reviewed-by: Xisco Fauli <[email protected]>
1 parent 7f8b79c commit 87dce61

30 files changed

+106
-184
lines changed

dbaccess/CppunitTest_dbaccess_firebird_test.mk

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ $(eval $(call gb_CppunitTest_use_libraries,dbaccess_firebird_test, \
2424
subsequenttest \
2525
svt \
2626
test \
27+
tl \
2728
unotest \
2829
utl \
2930
xo \

dbaccess/CppunitTest_dbaccess_hsqldb_test.mk

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ $(eval $(call gb_CppunitTest_use_libraries,dbaccess_hsqldb_test, \
2828
utl \
2929
test \
3030
tk \
31+
tl \
3132
unotest \
3233
xo \
3334
))

desktop/qa/desktop_lib/test_desktop_lib.cxx

+14-37
Original file line numberDiff line numberDiff line change
@@ -675,9 +675,7 @@ void DesktopLOKTest::testPaintTile()
675675
void DesktopLOKTest::testSaveAs()
676676
{
677677
LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
678-
utl::TempFileNamed aTempFile;
679-
aTempFile.EnableKillingFile();
680-
CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "png", nullptr));
678+
CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, maTempFile.GetURL().toUtf8().getStr(), "png", nullptr));
681679
}
682680

683681
void DesktopLOKTest::testSaveAsJsonOptions()
@@ -686,21 +684,12 @@ void DesktopLOKTest::testSaveAsJsonOptions()
686684
LibLODocument_Impl* pDocument = loadDoc("3page.odg");
687685

688686
// When exporting that document to PDF, skipping the first page:
689-
utl::TempFileNamed aTempFile;
690-
aTempFile.EnableKillingFile();
691687
OString aOptions("{\"PageRange\":{\"type\":\"string\",\"value\":\"2-\"}}");
692-
CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "pdf", aOptions.getStr()));
688+
CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, maTempFile.GetURL().toUtf8().getStr(), "pdf", aOptions.getStr()));
693689

694690
// Then make sure the resulting PDF has 2 pages:
695-
SvFileStream aFile(aTempFile.GetURL(), StreamMode::READ);
696-
SvMemoryStream aMemory;
697-
aMemory.WriteStream(aFile);
698-
std::shared_ptr<vcl::pdf::PDFium> pPDFium = vcl::pdf::PDFiumLibrary::get();
699-
if (!pPDFium)
700-
return;
701691
std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument
702-
= pPDFium->openDocument(aMemory.GetData(), aMemory.GetSize(), OString());
703-
CPPUNIT_ASSERT(pPdfDocument);
692+
= parsePDFExport();
704693
// Without the accompanying fix in place, this test would have failed with:
705694
// - Expected: 2
706695
// - Actual : 3
@@ -711,9 +700,7 @@ void DesktopLOKTest::testSaveAsJsonOptions()
711700
void DesktopLOKTest::testSaveAsCalc()
712701
{
713702
LibLODocument_Impl* pDocument = loadDoc("search.ods");
714-
utl::TempFileNamed aTempFile;
715-
aTempFile.EnableKillingFile();
716-
CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "png", nullptr));
703+
CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, maTempFile.GetURL().toUtf8().getStr(), "png", nullptr));
717704
}
718705

719706
void DesktopLOKTest::testPasteWriter()
@@ -2725,12 +2712,10 @@ void DesktopLOKTest::testInsertCertificate_DER_ODT()
27252712
{
27262713
// Load the document, save it into a temp file and load that file again
27272714
LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
2728-
utl::TempFileNamed aTempFile;
2729-
aTempFile.EnableKillingFile();
2730-
CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "odt", nullptr));
2715+
CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, maTempFile.GetURL().toUtf8().getStr(), "odt", nullptr));
27312716
closeDoc();
27322717

2733-
pDocument = loadDocUrl(aTempFile.GetURL(), LOK_DOCTYPE_TEXT);
2718+
pDocument = loadDocUrl(maTempFile.GetURL(), LOK_DOCTYPE_TEXT);
27342719

27352720
Scheduler::ProcessEventsToIdle();
27362721
CPPUNIT_ASSERT(mxComponent.is());
@@ -2775,12 +2760,10 @@ void DesktopLOKTest::testInsertCertificate_PEM_ODT()
27752760
{
27762761
// Load the document, save it into a temp file and load that file again
27772762
LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
2778-
utl::TempFileNamed aTempFile;
2779-
aTempFile.EnableKillingFile();
2780-
CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "odt", nullptr));
2763+
CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, maTempFile.GetURL().toUtf8().getStr(), "odt", nullptr));
27812764
closeDoc();
27822765

2783-
pDocument = loadDocUrl(aTempFile.GetURL(), LOK_DOCTYPE_TEXT);
2766+
pDocument = loadDocUrl(maTempFile.GetURL(), LOK_DOCTYPE_TEXT);
27842767

27852768
Scheduler::ProcessEventsToIdle();
27862769
CPPUNIT_ASSERT(mxComponent.is());
@@ -2832,12 +2815,10 @@ void DesktopLOKTest::testInsertCertificate_PEM_DOCX()
28322815
{
28332816
// Load the document, save it into a temp file and load that file again
28342817
LibLODocument_Impl* pDocument = loadDoc("blank_text.docx");
2835-
utl::TempFileNamed aTempFile;
2836-
aTempFile.EnableKillingFile();
2837-
CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "docx", nullptr));
2818+
CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, maTempFile.GetURL().toUtf8().getStr(), "docx", nullptr));
28382819
closeDoc();
28392820

2840-
pDocument = loadDocUrl(aTempFile.GetURL(), LOK_DOCTYPE_TEXT);
2821+
pDocument = loadDocUrl(maTempFile.GetURL(), LOK_DOCTYPE_TEXT);
28412822

28422823
Scheduler::ProcessEventsToIdle();
28432824
CPPUNIT_ASSERT(mxComponent.is());
@@ -2889,8 +2870,6 @@ void DesktopLOKTest::testSignDocument_PEM_PDF()
28892870
{
28902871
// Load the document, save it into a temp file and load that file again
28912872
LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
2892-
utl::TempFileNamed aTempFile;
2893-
aTempFile.EnableKillingFile();
28942873

28952874
Scheduler::ProcessEventsToIdle();
28962875
CPPUNIT_ASSERT(mxComponent.is());
@@ -2924,7 +2903,7 @@ void DesktopLOKTest::testSignDocument_PEM_PDF()
29242903
CPPUNIT_ASSERT(bResult);
29252904
}
29262905

2927-
CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "pdf", nullptr));
2906+
CPPUNIT_ASSERT(pDocument->pClass->saveAs(pDocument, maTempFile.GetURL().toUtf8().getStr(), "pdf", nullptr));
29282907

29292908
closeDoc();
29302909

@@ -2934,7 +2913,7 @@ void DesktopLOKTest::testSignDocument_PEM_PDF()
29342913
readFileIntoByteVector(u"test-PK-signing.pem", aPrivateKey);
29352914

29362915
LibLibreOffice_Impl aOffice;
2937-
bool bResult = aOffice.m_pOfficeClass->signDocument(&aOffice, aTempFile.GetURL().toUtf8().getStr(),
2916+
bool bResult = aOffice.m_pOfficeClass->signDocument(&aOffice, maTempFile.GetURL().toUtf8().getStr(),
29382917
aCertificate.data(), int(aCertificate.size()),
29392918
aPrivateKey.data(), int(aPrivateKey.size()));
29402919

@@ -3096,13 +3075,11 @@ void DesktopLOKTest::testCalcSaveAs()
30963075
Scheduler::ProcessEventsToIdle();
30973076

30983077
// Save as a new file.
3099-
utl::TempFileNamed aTempFile;
3100-
aTempFile.EnableKillingFile();
3101-
pDocument->pClass->saveAs(pDocument, aTempFile.GetURL().toUtf8().getStr(), "ods", nullptr);
3078+
pDocument->pClass->saveAs(pDocument, maTempFile.GetURL().toUtf8().getStr(), "ods", nullptr);
31023079
closeDoc();
31033080

31043081
// Load the new document and verify that the in-flight changes are saved.
3105-
pDocument = loadDocUrl(aTempFile.GetURL(), LOK_DOCTYPE_SPREADSHEET);
3082+
pDocument = loadDocUrl(maTempFile.GetURL(), LOK_DOCTYPE_SPREADSHEET);
31063083
CPPUNIT_ASSERT(pDocument);
31073084

31083085
ViewCallback aView(pDocument);

include/test/unoapi_test.hxx

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <com/sun/star/lang/XComponent.hpp>
2020
#include <osl/file.hxx>
2121
#include <unotools/tempfile.hxx>
22+
#include <vcl/filter/PDFiumLibrary.hxx>
2223

2324
// basic uno api test class
2425

@@ -40,6 +41,8 @@ public:
4041
void saveAndClose(const OUString& rFilter);
4142
void saveAndReload(const OUString& rFilter);
4243

44+
std::unique_ptr<vcl::pdf::PDFiumDocument> parsePDFExport(const OString& rPassword = OString());
45+
4346
void skipValidation() { mbSkipValidation = true; }
4447
void setFilterOptions(const OUString& rFilterOptions) { maFilterOptions = rFilterOptions; }
4548

@@ -53,6 +56,7 @@ private:
5356
bool mbSkipValidation;
5457
OUString m_aBaseString;
5558
OUString maFilterOptions;
59+
SvMemoryStream maMemory; // Underlying memory for parsed PDF files.
5660
};
5761

5862
#endif // INCLUDED_TEST_UNOAPI_TEST_HXX

oox/CppunitTest_oox_export.mk

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ $(eval $(call gb_CppunitTest_use_libraries,oox_export, \
2929
test \
3030
unotest \
3131
utl \
32+
tl \
3233
))
3334

3435
$(eval $(call gb_CppunitTest_use_sdk_api,oox_export))

oox/CppunitTest_oox_mathml.mk

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ $(eval $(call gb_CppunitTest_use_libraries,oox_mathml, \
2828
test \
2929
unotest \
3030
utl \
31+
tl \
3132
))
3233

3334
$(eval $(call gb_CppunitTest_use_sdk_api,oox_mathml))

oox/CppunitTest_oox_vml.mk

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ $(eval $(call gb_CppunitTest_use_libraries,oox_vml, \
2828
test \
2929
unotest \
3030
utl \
31+
tl \
3132
))
3233

3334
$(eval $(call gb_CppunitTest_use_sdk_api,oox_vml))

sc/CppunitTest_sc_functionlistobj.mk

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_functionlistobj, \
2626
test \
2727
unotest \
2828
utl \
29+
tl \
2930
))
3031

3132
$(eval $(call gb_CppunitTest_set_include,sc_functionlistobj,\

sc/common_unoapi_tests.mk

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_$(1), \
3232
test \
3333
unotest \
3434
utl \
35+
tl \
3536
vcl \
3637
))
3738

0 commit comments

Comments
 (0)