sc/qa/unit/tiledrendering/tiledrendering.cxx |   30 +++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

New commits:
commit 92caeb1a365d10d9cafaca0aed1368db92bc90f0
Author:     Dennis Francis <dennis.fran...@collabora.com>
AuthorDate: Tue Apr 12 10:43:00 2022 +0530
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Apr 12 08:17:17 2022 +0200

    unit test: use temp copy in testInvalidEntrySave()
    
    Use a temporary copy of the source file to run this test otherwise it
    will execute a .uno:Save on the original document in the git tree!
    
    Change-Id: I673aad64453e72a9140efcad2b0ff9c0ceabc038
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132854
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx 
b/sc/qa/unit/tiledrendering/tiledrendering.cxx
index 7ce8ad47105b..935c04d14d46 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx
@@ -38,6 +38,8 @@
 #include <docoptio.hxx>
 #include <postit.hxx>
 #include <test/lokcallback.hxx>
+#include <osl/file.hxx>
+#include <unotools/tempfile.hxx>
 
 #include <chrono>
 #include <cstddef>
@@ -185,10 +187,11 @@ public:
     CPPUNIT_TEST_SUITE_END();
 
 private:
-    ScModelObj* createDoc(const char* pName);
+    ScModelObj* createDoc(const char* pName, bool bMakeTempCopy = false);
     void setupLibreOfficeKitViewCallback(SfxViewShell* pViewShell);
     static void callback(int nType, const char* pPayload, void* pData);
     void callbackImpl(int nType, const char* pPayload);
+    void makeTempCopy(const OUString& rOrigURL);
 
     /// document size changed callback.
     osl::Condition m_aDocSizeCondition;
@@ -196,6 +199,7 @@ private:
 
     uno::Reference<lang::XComponent> mxComponent;
     TestLokCallbackWrapper m_callbackWrapper;
+    std::unique_ptr<utl::TempFile> mpTempFile;
 };
 
 ScTiledRenderingTest::ScTiledRenderingTest()
@@ -236,11 +240,29 @@ void ScTiledRenderingTest::tearDown()
     test::BootstrapFixture::tearDown();
 }
 
-ScModelObj* ScTiledRenderingTest::createDoc(const char* pName)
+void ScTiledRenderingTest::makeTempCopy(const OUString& rOrigURL)
+{
+    mpTempFile.reset(new utl::TempFile());
+    mpTempFile->EnableKillingFile();
+    auto const aError = osl::File::copy(rOrigURL, mpTempFile->GetURL());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE(
+        OUString("<" + rOrigURL + "> -> <" + mpTempFile->GetURL() + 
">").toUtf8().getStr(),
+        osl::FileBase::E_None, aError);
+}
+
+ScModelObj* ScTiledRenderingTest::createDoc(const char* pName, bool 
bMakeTempCopy)
 {
     if (mxComponent.is())
         mxComponent->dispose();
-    mxComponent = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) 
+ OUString::createFromAscii(pName), "com.sun.star.sheet.SpreadsheetDocument");
+
+    OUString aOriginalSrc = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
OUString::createFromAscii(pName);
+    if (bMakeTempCopy)
+        makeTempCopy(aOriginalSrc);
+
+    mxComponent = loadFromDesktop(
+        bMakeTempCopy ? mpTempFile->GetURL() : aOriginalSrc,
+        "com.sun.star.sheet.SpreadsheetDocument");
+
     ScModelObj* pModelObj = dynamic_cast<ScModelObj*>(mxComponent.get());
     CPPUNIT_ASSERT(pModelObj);
     
pModelObj->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
@@ -2928,7 +2950,7 @@ void ScTiledRenderingTest::testInvalidEntrySave()
     // Load a document
     comphelper::LibreOfficeKit::setActive();
 
-    ScModelObj* pModelObj = createDoc("validity.xlsx");
+    ScModelObj* pModelObj = createDoc("validity.xlsx", true /* bMakeTempCopy 
*/);
     const ScDocument* pDoc = pModelObj->GetDocument();
     ViewCallback aView;
     int nView = SfxLokHelper::getView();

Reply via email to