[Libreoffice-commits] core.git: sd/qa
Mike Kaganski (via logerrit)
logerrit at kemper.freedesktop.org
Tue Aug 17 12:55:27 UTC 2021
sd/qa/unit/SdrPdfImportTest.cxx | 76 +++++++++++++++++++++-------------------
1 file changed, 41 insertions(+), 35 deletions(-)
New commits:
commit c3d71e0ab926bf5240994179f405be101cd3148b
Author: Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Tue Aug 17 11:58:09 2021 +0200
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Tue Aug 17 14:54:53 2021 +0200
Enable sd pdf import tests on Windows
Change-Id: I101e59a6ce1a3467a1f743bdcc288b16307eb5a1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120579
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
diff --git a/sd/qa/unit/SdrPdfImportTest.cxx b/sd/qa/unit/SdrPdfImportTest.cxx
index e88316c35945..e35b83b82373 100644
--- a/sd/qa/unit/SdrPdfImportTest.cxx
+++ b/sd/qa/unit/SdrPdfImportTest.cxx
@@ -31,6 +31,44 @@
using namespace css;
+namespace
+{
+class EnvVarGuard
+{
+public:
+ EnvVarGuard(const char* var, const char* val)
+ {
+ if (getenv(var) == nullptr)
+ {
+ sVar = var;
+ SetEnv(sVar, val);
+ }
+ }
+ ~EnvVarGuard()
+ {
+ if (sVar)
+ SetEnv(sVar, nullptr);
+ }
+
+private:
+ static void SetEnv(const char* var, const char* val)
+ {
+#ifdef _WIN32
+ if (!val)
+ val = ""; // remove
+ _putenv_s(var, val);
+#else
+ if (val)
+ setenv(var, val, false);
+ else
+ unsetenv(var);
+#endif
+ }
+
+ const char* sVar = nullptr;
+};
+}
+
class SdrPdfImportTest : public test::BootstrapFixture, public unotest::MacrosTest
{
protected:
@@ -61,7 +99,6 @@ void SdrPdfImportTest::tearDown()
// convert the PDF content into objects/shapes.
CPPUNIT_TEST_FIXTURE(SdrPdfImportTest, testImportSimpleText)
{
-#if !defined(_WIN32)
auto pPdfium = vcl::pdf::PDFiumLibrary::get();
if (!pPdfium)
{
@@ -69,16 +106,7 @@ CPPUNIT_TEST_FIXTURE(SdrPdfImportTest, testImportSimpleText)
}
// We need to enable PDFium import (and make sure to disable after the test)
- bool bResetEnvVar = false;
- if (getenv("LO_IMPORT_USE_PDFIUM") == nullptr)
- {
- bResetEnvVar = true;
- setenv("LO_IMPORT_USE_PDFIUM", "1", false);
- }
- comphelper::ScopeGuard aPDFiumEnvVarGuard([&]() {
- if (bResetEnvVar)
- unsetenv("LO_IMPORT_USE_PDFIUM");
- });
+ EnvVarGuard UsePDFiumGuard("LO_IMPORT_USE_PDFIUM", "1");
mxComponent = loadFromDesktop(m_directories.getURLFromSrc(u"sd/qa/unit/data/SimplePDF.pdf"));
auto pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
@@ -132,12 +160,10 @@ CPPUNIT_TEST_FIXTURE(SdrPdfImportTest, testImportSimpleText)
const EditTextObject& aEdit = pOutlinerParagraphObject->GetTextObject();
OUString sText = aEdit.GetText(0);
CPPUNIT_ASSERT_EQUAL(OUString("This is PDF!"), sText);
-#endif
}
CPPUNIT_TEST_FIXTURE(SdrPdfImportTest, testAnnotationsImportExport)
{
-#if !defined(_WIN32)
auto pPdfium = vcl::pdf::PDFiumLibrary::get();
if (!pPdfium)
{
@@ -145,27 +171,9 @@ CPPUNIT_TEST_FIXTURE(SdrPdfImportTest, testAnnotationsImportExport)
}
// We need to enable PDFium import (and make sure to disable after the test)
- bool bResetEnvVar = false;
- if (getenv("LO_IMPORT_USE_PDFIUM") == nullptr)
- {
- bResetEnvVar = true;
- setenv("LO_IMPORT_USE_PDFIUM", "1", false);
- }
- comphelper::ScopeGuard aPDFiumEnvVarGuard([&]() {
- if (bResetEnvVar)
- unsetenv("LO_IMPORT_USE_PDFIUM");
- });
+ EnvVarGuard UsePDFiumGuard("LO_IMPORT_USE_PDFIUM", "1");
- bool bPDFCompressorResetEnvVar = false;
- if (getenv("VCL_DEBUG_DISABLE_PDFCOMPRESSION") == nullptr)
- {
- bPDFCompressorResetEnvVar = true;
- setenv("VCL_DEBUG_DISABLE_PDFCOMPRESSION", "1", false);
- }
- comphelper::ScopeGuard aPDFCompressorEnvVarGuard([&]() {
- if (bPDFCompressorResetEnvVar)
- unsetenv("VCL_DEBUG_DISABLE_PDFCOMPRESSION");
- });
+ EnvVarGuard DisablePDFCompressionGuard("VCL_DEBUG_DISABLE_PDFCOMPRESSION", "1");
auto pPdfiumLibrary = vcl::pdf::PDFiumLibrary::get();
@@ -295,8 +303,6 @@ CPPUNIT_TEST_FIXTURE(SdrPdfImportTest, testAnnotationsImportExport)
CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), aDateTime.NanoSeconds);
CPPUNIT_ASSERT_EQUAL(false, bool(aDateTime.IsUTC));
}
-
-#endif
}
CPPUNIT_PLUGIN_IMPLEMENT();
More information about the Libreoffice-commits
mailing list