summaryrefslogtreecommitdiff
path: root/sfx2/qa
diff options
context:
space:
mode:
authorAndreas Heinisch <andreas.heinisch@yahoo.de>2021-01-28 18:34:18 +0100
committerMiklos Vajna <vmiklos@collabora.com>2021-02-01 09:37:20 +0100
commita62878ff86ecb38f9ea9fbe99f06518ed6016566 (patch)
tree89a2b2b46d7741223f107d12555b61379f3a260c /sfx2/qa
parent21312572497e43317faa2f115a2a5449a97f1b44 (diff)
tdf#60237 - correct the behaviour of the Overwrite property
If the Overwrite property of the MediaDescriptor is set to false, try to write the file before trying to rename or copy it. If the file already exists, raise an error (ERRCODE_IO_ALREADYEXISTS). In addition, the documentation about the default option was corrected. Change-Id: I1031dca3a039343fc599d194fcaa99a20dd13e2a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110089 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sfx2/qa')
-rw-r--r--sfx2/qa/cppunit/test_misc.cxx33
1 files changed, 33 insertions, 0 deletions
diff --git a/sfx2/qa/cppunit/test_misc.cxx b/sfx2/qa/cppunit/test_misc.cxx
index f6039b0e68d8..02c2ed356f88 100644
--- a/sfx2/qa/cppunit/test_misc.cxx
+++ b/sfx2/qa/cppunit/test_misc.cxx
@@ -25,11 +25,13 @@
#include <com/sun/star/packages/zip/ZipFileAccess.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/XStorable.hpp>
+#include <com/sun/star/ucb/NameClashException.hpp>
#include <test/bootstrapfixture.hxx>
#include <test/xmltesttools.hxx>
#include <unotest/macros_test.hxx>
+#include <unotools/mediadescriptor.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <comphelper/propertysequence.hxx>
#include <comphelper/processfactory.hxx>
@@ -192,6 +194,37 @@ CPPUNIT_TEST_FIXTURE(MiscTest, testHardLinks)
#endif
}
+CPPUNIT_TEST_FIXTURE(MiscTest, testOverwrite)
+{
+ // tdf#60237 - try to overwrite an existing file using the different settings of the Overwrite option
+ utl::TempFile aTempFile;
+ aTempFile.EnableKillingFile();
+ uno::Reference<lang::XComponent> xComponent
+ = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.text.TextDocument");
+ CPPUNIT_ASSERT(xComponent.is());
+ uno::Reference<frame::XStorable> xStorable(xComponent, uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xStorable.is());
+
+ // overwrite the file using the default case of the Overwrite option (true)
+ CPPUNIT_ASSERT_NO_THROW(xStorable->storeToURL(aTempFile.GetURL(), {}));
+
+ // explicitly overwrite the file using the Overwrite option
+ CPPUNIT_ASSERT_NO_THROW(xStorable->storeToURL(
+ aTempFile.GetURL(),
+ comphelper::InitPropertySequence({ { "Overwrite", uno::makeAny(true) } })));
+
+ try
+ {
+ // overwrite an existing file with the Overwrite flag set to false
+ xStorable->storeToURL(aTempFile.GetURL(), comphelper::InitPropertySequence(
+ { { "Overwrite", uno::makeAny(false) } }));
+ CPPUNIT_ASSERT_MESSAGE("We expect an exception on overwriting an existing file", false);
+ }
+ catch (const css::uno::Exception&)
+ {
+ }
+}
+
}
CPPUNIT_PLUGIN_IMPLEMENT();