From 7faecc70c286c0e1a3068b77ccde771640928b37 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Tue, 8 Mar 2016 23:03:48 +0100 Subject: tdf#87530 finish the regression test Need to store the document twice to actually reproduce the bug. Change-Id: I2332bce1e30546b3a9fe2ec020f2eea8e8d0da58 --- sw/qa/core/macros-test.cxx | 71 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 16 deletions(-) diff --git a/sw/qa/core/macros-test.cxx b/sw/qa/core/macros-test.cxx index 44ac68f0a9fd..3a5453aa6e06 100644 --- a/sw/qa/core/macros-test.cxx +++ b/sw/qa/core/macros-test.cxx @@ -439,24 +439,61 @@ void SwMacrosTest::testFdo87530() Reference xComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + + Sequence desc(1); + desc[0].Name = "FilterName"; + desc[0].Value <<= OUString("writer8"); + { + // insert initial password protected library Reference xDocScr(xComponent, UNO_QUERY_THROW); Reference xStorBasLib(xDocScr->getBasicLibraries()); Reference xBasLib(xStorBasLib, UNO_QUERY_THROW); Reference xBasLibPwd(xStorBasLib, UNO_QUERY_THROW); - xBasLib->createLibrary("Library1"); - xBasLibPwd->changeLibraryPassword("Library1", "", "foo"); + Reference xLibrary(xBasLib->createLibrary("BarLibrary")); + xLibrary->insertByName("BarModule", + uno::makeAny(OUString("Sub Main\nEnd Sub\n"))); + xBasLibPwd->changeLibraryPassword("BarLibrary", "", "foo"); + + Reference xDocStorable(xComponent, UNO_QUERY_THROW); + CPPUNIT_ASSERT(xDocStorable.is()); + + xDocStorable->storeAsURL(aTempFile.GetURL(), desc); } - Reference xDocStorable(xComponent, UNO_QUERY_THROW); - CPPUNIT_ASSERT(xDocStorable.is()); + Reference(xComponent, UNO_QUERY_THROW)->close(false); - utl::TempFile aTempFile; - aTempFile.EnableKillingFile(); - Sequence desc(1); - desc[0].Name = "FilterName"; - desc[0].Value <<= OUString("writer8"); - xDocStorable->storeAsURL(aTempFile.GetURL(), desc); + // re-load + xComponent = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.text.TextDocument"); + + { + // check that password-protected library survived store and re-load + Reference xDocScr(xComponent, UNO_QUERY_THROW); + Reference xStorBasLib(xDocScr->getBasicLibraries()); + Reference xBasLib(xStorBasLib, UNO_QUERY_THROW); + Reference xBasLibPwd(xStorBasLib, UNO_QUERY_THROW); + CPPUNIT_ASSERT(xBasLibPwd->isLibraryPasswordProtected("BarLibrary")); + CPPUNIT_ASSERT(xBasLibPwd->verifyLibraryPassword("BarLibrary", "foo")); + xBasLib->loadLibrary("BarLibrary"); + CPPUNIT_ASSERT(xBasLib->isLibraryLoaded("BarLibrary")); + Reference xLibrary(xBasLib->getByName("BarLibrary"), UNO_QUERY); + Any module(xLibrary->getByName("BarModule")); + CPPUNIT_ASSERT_EQUAL(module.get(), OUString("Sub Main\nEnd Sub\n")); + + // add a second module now - tdf#87530 happened here + Reference xFooLib(xBasLib->createLibrary("FooLibrary")); + xFooLib->insertByName("FooModule", + uno::makeAny(OUString("Sub Main\nEnd Sub\n"))); + xBasLibPwd->changeLibraryPassword("FooLibrary", "", "foo"); + + // store again + Reference xDocStorable(xComponent, UNO_QUERY_THROW); + CPPUNIT_ASSERT(xDocStorable.is()); + + xDocStorable->store(); + } Reference(xComponent, UNO_QUERY_THROW)->close(false); @@ -468,14 +505,16 @@ void SwMacrosTest::testFdo87530() Reference xStorBasLib(xDocScr->getBasicLibraries()); Reference xBasLib(xStorBasLib, UNO_QUERY_THROW); Reference xBasLibPwd(xStorBasLib, UNO_QUERY_THROW); - CPPUNIT_ASSERT(xBasLibPwd->isLibraryPasswordProtected("Library1")); - CPPUNIT_ASSERT(xBasLibPwd->verifyLibraryPassword("Library1", "foo")); - xBasLib->loadLibrary("Library1"); - CPPUNIT_ASSERT(xBasLib->isLibraryLoaded("Library1")); + CPPUNIT_ASSERT(xBasLibPwd->isLibraryPasswordProtected("FooLibrary")); + CPPUNIT_ASSERT(xBasLibPwd->verifyLibraryPassword("FooLibrary", "foo")); + xBasLib->loadLibrary("FooLibrary"); + CPPUNIT_ASSERT(xBasLib->isLibraryLoaded("FooLibrary")); + Reference xLibrary(xBasLib->getByName("FooLibrary"), UNO_QUERY); + Any module(xLibrary->getByName("FooModule")); + CPPUNIT_ASSERT_EQUAL(module.get(), OUString("Sub Main\nEnd Sub\n")); // close - Reference xDocCloseable(xComponent, UNO_QUERY_THROW); - xDocCloseable->close(false); + Reference(xComponent, UNO_QUERY_THROW)->close(false); } -- cgit v1.2.3