xmloff/qa/unit/uxmloff.cxx      |  136 ++++++++++++++++++++++++++++++++++++++++
 xmloff/source/core/xmlimp.cxx   |    2 
 xmloff/source/meta/xmlmetai.cxx |   19 +++--
 3 files changed, 148 insertions(+), 9 deletions(-)

New commits:
commit 90ea159df9b326c0d00b736abaf769062122a32b
Author: Michael Stahl <[email protected]>
Date:   Mon Mar 12 20:03:34 2018 +0100

    xmloff: ODF import: improve meta:generator checks
    
    Instead of a hard-coded check for (effectively) one project name
    "LibreOffice" (which is build-time configurable), check for the string
    "LibreOffice_project", which has been produced hard-coded ever since
    LO 3.3.0.
    
    This now recognises additional downstreams "LibreOffice_Vanilla"
    and "Collabora_Office", and also historic "BrOffice".
    
    An important point here is that the build-time configurable version
    numbers of any downstream that retains the hard-coded
    "LibreOffice_project" *MUST* be the same as the upstream's at least
    in their major and minor versions (micro and further digits are
    currently not used), and that such downstreams don't backport
    changes with ODF export compatibility impact further than upstream.
    
    Add a unit test too, with a representative sample of 4372 distinct
    generators in bugzilla attachments.
    
    This revealed that StarOffice 6 and AOO 4.0.1 were falling through
    the cracks and not recognised, so fix that too.
    
    Change-Id: I8105222d3428e7b20cc4a6b8e76732c697812594
    Reviewed-on: https://gerrit.libreoffice.org/51171
    Tested-by: Jenkins <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>
    (cherry picked from commit 0d6ffe118fd1d03e22fcda2f06d49b4c932d2018)
    Reviewed-on: https://gerrit.libreoffice.org/51261
    Reviewed-by: Michael Meeks <[email protected]>

diff --git a/xmloff/qa/unit/uxmloff.cxx b/xmloff/qa/unit/uxmloff.cxx
index bb4a15cc8852..71a1b371f006 100644
--- a/xmloff/qa/unit/uxmloff.cxx
+++ b/xmloff/qa/unit/uxmloff.cxx
@@ -10,6 +10,12 @@
 #include <sal/config.h>
 #include <test/bootstrapfixture.hxx>
 
+#include <com/sun/star/beans/PropertyAttribute.hpp>
+
+#include <comphelper/genericpropertyset.hxx>
+
+#include <xmloff/xmlimp.hxx>
+#include <xmloff/xmlmetai.hxx>
 #include <xmloff/xmlexp.hxx>
 #include <xmloff/xmltoken.hxx>
 #include <xmloff/xmlaustp.hxx>
@@ -30,9 +36,11 @@ public:
     virtual void tearDown() override;
 
     void testAutoStylePool();
+    void testMetaGenerator();
 
     CPPUNIT_TEST_SUITE(Test);
     CPPUNIT_TEST(testAutoStylePool);
+    CPPUNIT_TEST(testMetaGenerator);
     CPPUNIT_TEST_SUITE_END();
 private:
     SvXMLExport *pExport;
@@ -87,6 +95,134 @@ void Test::testAutoStylePool()
     CPPUNIT_ASSERT_EQUAL_MESSAGE( "same style not found", aName, aSameName );
 }
 
+void Test::testMetaGenerator()
+{
+    comphelper::PropertyMapEntry const aInfoMap[] = {
+        { OUString("BuildId"), 0, ::cppu::UnoType<OUString>::get(), 
beans::PropertyAttribute::MAYBEVOID, 0 },
+        { OUString(), 0, css::uno::Type(), 0, 0 }
+    };
+    uno::Reference<beans::XPropertySet> const xInfoSet(
+        comphelper::GenericPropertySet_CreateInstance(
+            new comphelper::PropertySetInfo(aInfoMap)));
+
+    struct {
+        char const*const generator;
+        char const*const buildId;
+        sal_uInt16 const result;
+    } const tests [] = {
+        // foreign
+        { "AbiWord/2.8.6 (unix, gtk)", "", SvXMLImport::ProductVersionUnknown 
},
+        { "Aspose.Words for Java 13.10.0.0", "", 
SvXMLImport::ProductVersionUnknown },
+        { "CIB jsmerge 1.0.0", "", SvXMLImport::ProductVersionUnknown },
+        { "Calligra/2.4.3", "", SvXMLImport::ProductVersionUnknown },
+        { "CocoaODFWriter/1339", "", SvXMLImport::ProductVersionUnknown },
+        { "KOffice/1.4.1", "", SvXMLImport::ProductVersionUnknown },
+        { "KPresenter 1.3", "", SvXMLImport::ProductVersionUnknown },
+        { "KSpread 1.3.2", "", SvXMLImport::ProductVersionUnknown },
+        { "Lotus Symphony/1.2.0_20081023.1730/Win32", "", 
SvXMLImport::ProductVersionUnknown },
+        { "Microsoft Excel Online", "", SvXMLImport::ProductVersionUnknown },
+        { "MicrosoftOffice/12.0 MicrosoftExcel/CalculationVersion-4518", "", 
SvXMLImport::ProductVersionUnknown },
+        { "MicrosoftOffice/15.0 MicrosoftWord", "", 
SvXMLImport::ProductVersionUnknown },
+        { "ODF Converter v1.0.0", "", SvXMLImport::ProductVersionUnknown },
+        { "ODF::lpOD 1.121", "", SvXMLImport::ProductVersionUnknown },
+        { "ODFDOM/0.6.1$Build-1", "", SvXMLImport::ProductVersionUnknown },
+        { "ODFPY/0.9.6", "", SvXMLImport::ProductVersionUnknown },
+        { "OpenXML/ODF Translator Command Line Tool 3.0 2.0.0", "", 
SvXMLImport::ProductVersionUnknown },
+        { "Org-7.8.03/Emacs-24.0.93.1", "", SvXMLImport::ProductVersionUnknown 
},
+        { "TeX4ht from eqns_long.tex, options: xhtml,ooffice,refcaption", "", 
SvXMLImport::ProductVersionUnknown },
+        { "TextMaker", "", SvXMLImport::ProductVersionUnknown },
+        { "docbook2odf generator (http://open.comsultia.com/docbook2odf/)", 
"", SvXMLImport::ProductVersionUnknown },
+        { "fig2sxd", "", SvXMLImport::ProductVersionUnknown },
+        { "gnumeric/1.10.9", "", SvXMLImport::ProductVersionUnknown },
+        { "libodfgen/0.1.6", "", SvXMLImport::ProductVersionUnknown },
+
+        // OOo 1.x
+        { "StarSuite 6.0 (Linux)", "645$8687", SvXMLImport::OOo_1x },
+        { "StarOffice 6.1 (Win32)", "645$8687", SvXMLImport::OOo_1x },
+        { "OpenOffice.org 1.1.2RC3.DE (Win32)", "645$8687", 
SvXMLImport::OOo_1x },
+        { "OpenOffice.org 1.1.5 (Win32)", "645$8687", SvXMLImport::OOo_1x },
+        { "StarOffice 7 (Win32)", "645$8687", SvXMLImport::OOo_1x },
+
+        // OOo 2.x
+        { "Sun_ODF_Plugin_for_Microsoft_Office/1.1$Win32 
OpenOffice.org_project/680m5$Build-9221", "680$9221", SvXMLImport::OOo_2x },
+        { "StarSuite/8$Win32 OpenOffice.org_project/680m6$Build-9095", 
"680$9095", SvXMLImport::OOo_2x },
+        { "StarOffice/8$Win32 OpenOffice.org_project/680m93$Build-8897", 
"680$8897", SvXMLImport::OOo_2x },
+        { "OpenOffice.org/2.0$Linux OpenOffice.org_project/680m3$Build-8968", 
"680$8968", SvXMLImport::OOo_2x },
+        { "OpenOffice.org/2.1$Win32 OpenOffice.org_project/680m6$Build-9095", 
"680$9095", SvXMLImport::OOo_2x },
+        { "OpenOffice.org/2.4$Win32 
OpenOffice.org_project/680m248$Build-9274", "680$9274", SvXMLImport::OOo_2x },
+
+        // OOo 3.x
+        { "OpenOffice.org/3.0$Solaris_Sparc 
OpenOffice.org_project/300m9$Build-9358", "300$9358", SvXMLImport::OOo_30x },
+        { "StarSuite/9$Unix OpenOffice.org_project/300m9$Build-9358", 
"300$9358", SvXMLImport::OOo_30x },
+        { "StarOffice/9$Win32 OpenOffice.org_project/300m14$Build-9376", 
"300$9376", SvXMLImport::OOo_30x },
+        { "OpenOffice.org/3.1$Solaris_x86 
OpenOffice.org_project/310m11$Build-9399", "310$9399", SvXMLImport::OOo_31x },
+        { "IBM_Lotus_Symphony/2.0$Win32 
OpenOffice.org_project/310m11$Build-9399", "310$9399", SvXMLImport::OOo_31x },
+        { "BrOffice.org/3.1$Linux OpenOffice.org_project/310m11$Build-9399", 
"310$9399", SvXMLImport::OOo_31x },
+        { "StarOffice/9$Solaris_Sparc 
OpenOffice.org_project/310m19$Build-9420", "310$9420", SvXMLImport::OOo_31x },
+        { "OpenOffice.org/3.2$Linux OpenOffice.org_project/320m12$Build-9483", 
"320$9483", SvXMLImport::OOo_32x },
+        { "StarOffice/9$Win32 OpenOffice.org_project/320m12$Build-9483", 
"320$9483", SvXMLImport::OOo_32x },
+        { "OpenOffice.org/3.3$Linux OpenOffice.org_project/330m20$Build-9567", 
"330$9567", SvXMLImport::OOo_33x },
+        { "Oracle_Open_Office/3.3$Win32 
OpenOffice.org_project/330m7$Build-9552", "330$9552", SvXMLImport::OOo_33x },
+        { "OpenOffice.org/3.4$Unix OpenOffice.org_project/340m1$Build-9590", 
"340$9590", SvXMLImport::OOo_34x },
+
+        // AOO versions
+        { "OpenOffice/4.0.0$Win32 OpenOffice.org_project/400m3$Build-9702", 
"400$9702", SvXMLImport::AOO_40x },
+        { "OpenOffice/4.0.1$Linux OpenOffice.org_project/401m4$Build-9713", 
"401$9713", SvXMLImport::AOO_40x },
+        { "OpenOffice/4.1.1$FreeBSD/amd64 
OpenOffice.org_project/411m6$Build-9775", "411$9775", SvXMLImport::AOO_4x },
+        { "OpenOffice/4.1.2$OS/2 OpenOffice.org_project/412m3$Build-9782-bww", 
"412$9782-bww", SvXMLImport::AOO_4x },
+        { "OpenOffice/4.1.4$Unix OpenOffice.org_project/414m2$Build-9785", 
"414$9785", SvXMLImport::AOO_4x },
+
+        // LO versions
+        { "LibreOffice/3.3$Linux LibreOffice_project/330m17$Build-3", 
"330$3;33", SvXMLImport::LO_3x },
+        { "BrOffice/3.3$Win32 LibreOffice_project/330m19$Build-8", "330$8;33", 
SvXMLImport::LO_3x },
+        { "LibreOffice/3.4$Linux LibreOffice_project/340m1$Build-1206", 
"340$1206;34", SvXMLImport::LO_3x },
+        { "LibreOffice/3.5$Linux_X86_64 
LibreOffice_project/3fa2330-e49ffd2-90d118b-705e248-051e21c", ";35", 
SvXMLImport::LO_3x },
+        { "LibreOffice/3.6$Windows_x86 
LibreOffice_project/a9a0717-273e462-768e6e3-978247f-65e65f", ";36", 
SvXMLImport::LO_3x },
+        { "LibreOffice/4.0.2.2$Windows_x86 
LibreOffice_project/4c82dcdd6efcd48b1d8bba66bfe1989deee49c3", ";4022", 
SvXMLImport::LO_41x },
+        { "LibreOffice/4.1.2.3$MacOSX_x86 
LibreOffice_project/40b2d7fde7e8d2d7bc5a449dc65df4d08a7dd38", ";4123", 
SvXMLImport::LO_41x },
+        { "LibreOffice/4.2.8.2$Windows_x86 
LibreOffice_project/48d50dbfc06349262c9d50868e5c1f630a573ebd", ";4282", 
SvXMLImport::LO_42x },
+        { "LibreOffice_from_Collabora_4.2-8/4.2.10.8$Linux_x86 
LibreOffice_project/84584cc237b2eb93f7684d8fcd063bb37e87b5fb", ";42108", 
SvXMLImport::LO_42x },
+        { "LibreOffice/4.3.3.2$Linux_x86 
LibreOffice_project/9bb7eadab57b6755b1265afa86e04bf45fbfc644", ";4332", 
SvXMLImport::LO_43x },
+        { "LibreOffice_from_Collabora_4.4-10/4.4.10.9$Linux_x86 
LibreOffice_project/5600b19b88a01bbb669b0900100760758dff8c26", ";44109", 
SvXMLImport::LO_44x },
+        { "LibreOffice/4.3.3.2$Linux_X86_64 
LibreOffice_project/430m0$Build-2", "430$2;4332", SvXMLImport::LO_43x },
+        { "LibreOffice/4.4.3.2$Linux_x86 
LibreOffice_project/88805f81e9fe61362df02b9941de8e38a9b5fd16", ";4432", 
SvXMLImport::LO_44x },
+        { "LibreOffice/5.0.1.1$Linux_x86 LibreOffice_project/00m0$Build-1", 
"00$1;5011", SvXMLImport::LO_5x },
+        { "LibreOffice/5.0.3.2$Windows_X86_64 
LibreOffice_project/e5f16313668ac592c1bfb310f4390624e3dbfb75", ";5032", 
SvXMLImport::LO_5x },
+        { "Collabora_Office/5.0.10.19$Linux_X86_64 
LibreOffice_project/95060d44300d8866fa81c16fc8fe2afe22d63777", ";501019", 
SvXMLImport::LO_5x },
+        { "LibreOffice/5.1.6.2.0$Linux_X86_64 LibreOffice_project/10$Build-2", 
";51620", SvXMLImport::LO_5x },
+        { "Collabora_Office/5.1.10.17$Linux_X86_64 
LibreOffice_project/a104cbe76eefca3cf23973da68893d2225fd718b", ";511017", 
SvXMLImport::LO_5x },
+        { "LibreOffice/5.2.1.2$Windows_X86_64 
LibreOffice_project/31dd62db80d4e60af04904455ec9c9219178d620", ";5212", 
SvXMLImport::LO_5x },
+        { "LibreOffice_Vanilla/5.2.3.5$MacOSX_X86_64 
LibreOffice_project/83adc9c35c74e0badc710d981405858b1179a327", ";5235", 
SvXMLImport::LO_5x },
+        { "LibreOffice/5.3.4.2$Windows_X86_64 
LibreOffice_project/f82d347ccc0be322489bf7da61d7e4ad13fe2ff3", ";5342", 
SvXMLImport::LO_5x },
+        { "Collabora_Office/5.3.10.27$Linux_X86_64 
LibreOffice_project/7a5a5378661e338a44666c08773cc796b8d1c84a", ";531027", 
SvXMLImport::LO_5x },
+        { "LibreOfficeDev/5.4.7.0.0$Linux_X86_64 
LibreOffice_project/ba7461fc88c08e75e315f786020a2946e56166c9", ";54700", 
SvXMLImport::LO_5x },
+        { "LibreOfficeDev/6.0.3.0.0$Linux_X86_64 
LibreOffice_project/34442b85bfb0c451738b4db023345a7484463321", ";60300", 
SvXMLImport::LO_6x },
+    };
+
+    for (size_t i = 0; i < SAL_N_ELEMENTS(tests); ++i)
+    {
+        // the DocumentInfo instance is cached so need fresh SvXMLImport
+        rtl::Reference<SvXMLImport> const pImport(new SvXMLImport(
+            comphelper::getProcessComponentContext(), "testdummy",
+            SvXMLImportFlags::ALL));
+
+        pImport->initialize(uno::Sequence<uno::Any>{ uno::Any(xInfoSet) });
+
+        SvXMLMetaDocumentContext::setBuildId(
+                OUString::createFromAscii(tests[i].generator), xInfoSet);
+        if (std::strlen(tests[i].buildId) != 0)
+        {
+            CPPUNIT_ASSERT_EQUAL(OUString::createFromAscii(tests[i].buildId),
+                    xInfoSet->getPropertyValue("BuildId").get<OUString>());
+        }
+        else
+        {
+            CPPUNIT_ASSERT(!xInfoSet->getPropertyValue("BuildId").hasValue());
+        }
+        CPPUNIT_ASSERT_EQUAL(tests[i].result, pImport->getGeneratorVersion());
+    }
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx
index 324fbc0dd4e9..af7a0788bf02 100644
--- a/xmloff/source/core/xmlimp.cxx
+++ b/xmloff/source/core/xmlimp.cxx
@@ -222,7 +222,7 @@ public:
             {
                 mnGeneratorVersion = SvXMLImport::OOo_34x;
             }
-            else if (nUPD == 400)
+            else if (nUPD == 400 || nUPD == 401)
             {
                 mnGeneratorVersion = SvXMLImport::AOO_40x;
             }
diff --git a/xmloff/source/meta/xmlmetai.cxx b/xmloff/source/meta/xmlmetai.cxx
index ba733bd73a20..1f9a1b9604e2 100644
--- a/xmloff/source/meta/xmlmetai.cxx
+++ b/xmloff/source/meta/xmlmetai.cxx
@@ -256,6 +256,8 @@ void SvXMLMetaDocumentContext::setBuildId(OUString const& 
i_rBuildId, const uno:
     {
         if (    i_rBuildId.startsWith("StarOffice 7")
             ||  i_rBuildId.startsWith("StarSuite 7")
+            ||  i_rBuildId.startsWith("StarOffice 6")
+            ||  i_rBuildId.startsWith("StarSuite 6")
             ||  i_rBuildId.startsWith("OpenOffice.org 1"))
         {
             sBuildId = "645$8687";
@@ -266,19 +268,20 @@ void SvXMLMetaDocumentContext::setBuildId(OUString const& 
i_rBuildId, const uno:
         }
     }
 
-    OUString rest;
-    if (i_rBuildId.startsWith("LibreOffice/", &rest) ||
-        i_rBuildId.startsWith("LibreOfficeDev/", &rest) ||
-        i_rBuildId.startsWith("LOdev/", &rest))
+    // "LibreOffice_project" was hard-coded since LO 3.3.0
+    // see utl::DocInfoHelper::GetGeneratorString()
+    if (i_rBuildId.indexOf("LibreOffice_project/") != -1)
     {
         OUStringBuffer sNumber;
-        for (sal_Int32 i = 0; i < rest.getLength(); ++i)
+        auto const firstSlash = i_rBuildId.indexOf("/");
+        assert(firstSlash != -1);
+        for (sal_Int32 i = firstSlash + 1; i < i_rBuildId.getLength(); ++i)
         {
-            if (rtl::isAsciiDigit(rest[i]))
+            if (rtl::isAsciiDigit(i_rBuildId[i]))
             {
-                sNumber.append(rest[i]);
+                sNumber.append(i_rBuildId[i]);
             }
-            else if ('.' != rest[i])
+            else if ('.' != i_rBuildId[i])
             {
                 break;
             }
_______________________________________________
Libreoffice-commits mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to