[Libreoffice-commits] .: 2 commits - sw/qa sw/source

Caolán McNamara caolan at kemper.freedesktop.org
Tue Jan 4 12:29:54 PST 2011


 sw/qa/core/makefile.mk            |    6 ++-
 sw/qa/core/swdoc-test.cxx         |   67 +++++++++++++++++++++++++++++++++++++-
 sw/source/core/fields/docufld.cxx |    2 -
 3 files changed, 72 insertions(+), 3 deletions(-)

New commits:
commit a28ee58ddcdfb2155813c2e4386d609a2be47a6f
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Jan 4 19:48:56 2011 +0000

    Related: fdo#32463 add cppunit test for SwFileNameFieldType

diff --git a/sw/qa/core/makefile.mk b/sw/qa/core/makefile.mk
index f19f5bc..0d180a5 100644
--- a/sw/qa/core/makefile.mk
+++ b/sw/qa/core/makefile.mk
@@ -135,7 +135,11 @@ $(MISC)/$(TARGET)/udkapi.rdb .ERRREMOVE : $(SOLARBINDIR)$/udkapi.rdb
 $(MISC)/$(TARGET)/services.rdb .ERRREMOVE : $(MISC)/$(TARGET)/udkapi.rdb makefile.mk
     $(MKDIRHIER) $(@:d)
     $(REGCOMP) -register -br $(MISC)/$(TARGET)/udkapi.rdb -r $@ -wop \
-        -c $(DLLPRE)fwk$(DLLPOSTFIX)$(DLLPOST)
+        -c $(DLLPRE)fwk$(DLLPOSTFIX)$(DLLPOST) \
+        -c $(DLLPRE)sfx$(DLLPOSTFIX)$(DLLPOST) \
+        -c $(DLLPRE)unoxml$(DLLPOSTFIX)$(DLLPOST) \
+        -c i18npool.uno$(DLLPOST)
+
 
 #Tweak things so that we use the .res files in the solver
 STAR_RESOURCEPATH:=$(PWD)/$(BIN)$(PATH_SEPERATOR)$(SOLARBINDIR)
diff --git a/sw/qa/core/swdoc-test.cxx b/sw/qa/core/swdoc-test.cxx
index b3f89c6..170856f 100644
--- a/sw/qa/core/swdoc-test.cxx
+++ b/sw/qa/core/swdoc-test.cxx
@@ -43,11 +43,20 @@
 #include <comphelper/processfactory.hxx>
 #include <vcl/svapp.hxx>
 #include <sfx2/app.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/sfxmodelfactory.hxx>
+#include <tools/urlobj.hxx>
+#include <unotools/tempfile.hxx>
 
 #include "init.hxx"
 #include "swtypes.hxx"
 #include "doc.hxx"
+#include "docsh.hxx"
 #include "shellres.hxx"
+#include "docufld.hxx"
+
+SO2_DECL_REF(SwDocShell)
+SO2_IMPL_REF(SwDocShell)
 
 using namespace ::com::sun::star;
 
@@ -62,18 +71,21 @@ public:
     virtual void setUp();
     virtual void tearDown();
 
-    void testPageDescName();
     void randomTest();
+    void testPageDescName();
+    void testFileNameFields();
 
     CPPUNIT_TEST_SUITE(SwDocTest);
     CPPUNIT_TEST(randomTest);
     CPPUNIT_TEST(testPageDescName);
+    CPPUNIT_TEST(testFileNameFields);
     CPPUNIT_TEST_SUITE_END();
 
 private:
     uno::Reference<uno::XComponentContext> m_xContext;
     uno::Reference<lang::XMultiComponentFactory> m_xFactory;
     SwDoc *m_pDoc;
+    SwDocShellRef m_xDocShRef;
 };
 
 void SwDocTest::testPageDescName()
@@ -95,6 +107,56 @@ void SwDocTest::testPageDescName()
     CPPUNIT_ASSERT_MESSAGE("GetPageDescName results must be unique", aResults.size() == 3);
 }
 
+//See https://bugs.freedesktop.org/show_bug.cgi?id=32463 for motivation
+void SwDocTest::testFileNameFields()
+{
+    //Here's a file name with some chars in it that will be %% encoded, when expanding
+    //SwFileNameFields we want to restore the original readable filename
+    utl::TempFile aTempFile(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("demo [name]")));
+    aTempFile.EnableKillingFile();
+
+    INetURLObject aTempFileURL(aTempFile.GetURL());
+    String sFileURL = aTempFileURL.GetMainURL(INetURLObject::NO_DECODE);
+    SfxMedium* pDstMed = new SfxMedium(sFileURL, STREAM_STD_READWRITE, true);
+
+    m_xDocShRef->DoSaveAs(*pDstMed);
+    m_xDocShRef->DoSaveCompleted(pDstMed);
+
+    const INetURLObject &rUrlObj = m_xDocShRef->GetMedium()->GetURLObject();
+
+    SwFileNameFieldType aNameField(m_pDoc);
+
+    {
+        rtl::OUString sResult(aNameField.Expand(FF_NAME));
+        rtl::OUString sExpected(rUrlObj.getName(INetURLObject::LAST_SEGMENT,
+            true,INetURLObject::DECODE_WITH_CHARSET));
+        CPPUNIT_ASSERT_MESSAGE("Expected Readable FileName", sResult == sExpected);
+    }
+
+    {
+        rtl::OUString sResult(aNameField.Expand(FF_PATHNAME));
+        rtl::OUString sExpected(rUrlObj.GetFull());
+        CPPUNIT_ASSERT_MESSAGE("Expected Readable FileName", sResult == sExpected);
+    }
+
+    {
+        rtl::OUString sResult(aNameField.Expand(FF_PATH));
+        INetURLObject aTemp(rUrlObj);
+        aTemp.removeSegment();
+        rtl::OUString sExpected(aTemp.PathToFileName());
+        CPPUNIT_ASSERT_MESSAGE("Expected Readable FileName", sResult == sExpected);
+    }
+
+    {
+        rtl::OUString sResult(aNameField.Expand(FF_NAME_NOEXT));
+        rtl::OUString sExpected(rUrlObj.getName(INetURLObject::LAST_SEGMENT,
+            true,INetURLObject::DECODE_WITH_CHARSET));
+        //Chop off .tmp
+        sExpected = sExpected.copy(0, sExpected.getLength() - 4);
+        CPPUNIT_ASSERT_MESSAGE("Expected Readable FileName", sResult == sExpected);
+    }
+}
+
 void SwDocTest::randomTest()
 {
     CPPUNIT_ASSERT_MESSAGE("SwDoc::IsRedlineOn()", !m_pDoc->IsRedlineOn());
@@ -120,6 +182,8 @@ SwDocTest::SwDocTest()
 void SwDocTest::setUp()
 {
     m_pDoc = new SwDoc;
+    m_xDocShRef = new SwDocShell(m_pDoc, SFX_CREATE_MODE_EMBEDDED);
+    m_xDocShRef->DoInitNew(0);
 }
 
 SwDocTest::~SwDocTest()
@@ -128,6 +192,7 @@ SwDocTest::~SwDocTest()
 
 void SwDocTest::tearDown()
 {
+    m_xDocShRef.Clear();
     delete m_pDoc;
 }
 
commit 17143361d48c62cb5ca152e9ed2834b849f4888d
Author: Dan Corneanu <cdan at savatech.ro>
Date:   Thu Dec 30 00:56:21 2010 +0200

    See Bug Id 32463

diff --git a/sw/source/core/fields/docufld.cxx b/sw/source/core/fields/docufld.cxx
index 2a4d6da..492bf91 100644
--- a/sw/source/core/fields/docufld.cxx
+++ b/sw/source/core/fields/docufld.cxx
@@ -467,7 +467,7 @@ String SwFileNameFieldType::Expand(ULONG nFmt) const
                 break;
 
             case FF_NAME:
-                aRet = rURLObj.GetLastName( URL_DECODE );
+                aRet = rURLObj.GetLastName( INetURLObject::DECODE_WITH_CHARSET );
                 break;
 
             case FF_NAME_NOEXT:


More information about the Libreoffice-commits mailing list