[diffoscope] 02/02: Add support for comparing XMLBeans binary schemas.

Chris Lamb chris at chris-lamb.co.uk
Sat Feb 10 17:03:46 CET 2018


This is an automated email from the git hooks/post-receive script.

lamby pushed a commit to branch master
in repository diffoscope.

commit c1e29ac2d1ea0562b951f32689436b5e5e987ad4
Author: Chris Lamb <lamby at debian.org>
Date:   Sat Feb 10 16:02:53 2018 +0000

    Add support for comparing XMLBeans binary schemas.
---
 debian/control                     |   1 +
 diffoscope/comparators/__init__.py |   1 +
 diffoscope/comparators/xsb.py      |  47 ++++++++++++
 diffoscope/external_tools.py       |   3 +
 tests/comparators/test_xsb.py      |  54 +++++++++++++
 tests/data/test1.xsb               | Bin 0 -> 1546 bytes
 tests/data/test2.xsb               | Bin 0 -> 1546 bytes
 tests/data/xsb_expected_diff       | 153 +++++++++++++++++++++++++++++++++++++
 8 files changed, 259 insertions(+)

diff --git a/debian/control b/debian/control
index 7091feb..4e001eb 100644
--- a/debian/control
+++ b/debian/control
@@ -70,6 +70,7 @@ Build-Depends:
  squashfs-tools <!nocheck>,
  tcpdump <!nocheck>,
  unzip <!nocheck>,
+ xmlbeans <!nocheck>,
  xxd <!nocheck> | vim-common <!nocheck>,
 Standards-Version: 4.1.2
 Rules-Requires-Root: no
diff --git a/diffoscope/comparators/__init__.py b/diffoscope/comparators/__init__.py
index 311f43c..10165f9 100644
--- a/diffoscope/comparators/__init__.py
+++ b/diffoscope/comparators/__init__.py
@@ -90,6 +90,7 @@ class ComparatorManager(object):
         ('pgp.PgpFile',),
         ('dtb.DeviceTreeFile',),
         ('ogg.OggFile',),
+        ('xsb.XsbFile',),
     )
 
     _singleton = {}
diff --git a/diffoscope/comparators/xsb.py b/diffoscope/comparators/xsb.py
new file mode 100644
index 0000000..713ad45
--- /dev/null
+++ b/diffoscope/comparators/xsb.py
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2018 Chris Lamb <lamby at debian.org>
+#
+# diffoscope is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# diffoscope is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
+
+from diffoscope.tools import tool_required
+from diffoscope.difference import Difference
+
+from .utils.file import File
+from .utils.command import Command
+
+
+class Dumpxsb(Command):
+    @tool_required('dumpxsb')
+    def cmdline(self):
+        return ('dumpxsb', self.path)
+
+    def filter(self, line):
+        if line.decode('utf-8').strip() == self.path:
+            return b''
+        return line
+
+
+class XsbFile(File):
+    FILE_EXTENSION_SUFFIX = '.xsb'
+
+    def compare_details(self, other, source=None):
+        return [Difference.from_command(
+            Dumpxsb,
+            self.path,
+            other.path,
+            source='dumpxsb',
+        )]
diff --git a/diffoscope/external_tools.py b/diffoscope/external_tools.py
index 1e2f052..e58a1de 100644
--- a/diffoscope/external_tools.py
+++ b/diffoscope/external_tools.py
@@ -260,6 +260,9 @@ EXTERNAL_TOOLS = {
     'procyon-decompiler': {
         'debian': 'procyon-decompiler',
     },
+    'dumpxsb': {
+        'debian': 'xmlutils',
+    }
 }
 
 # May be populated at runtime by remapped names like
diff --git a/tests/comparators/test_xsb.py b/tests/comparators/test_xsb.py
new file mode 100644
index 0000000..59edd5b
--- /dev/null
+++ b/tests/comparators/test_xsb.py
@@ -0,0 +1,54 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2018 Chris Lamb <lamby at debian.org>
+#
+# diffoscope is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# diffoscope is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
+
+import pytest
+
+from diffoscope.comparators.xsb import XsbFile
+
+from ..utils.data import load_fixture, get_data
+from ..utils.tools import skip_unless_tools_exist
+from ..utils.nonexisting import assert_non_existing
+
+xsb1 = load_fixture('test1.xsb')
+xsb2 = load_fixture('test2.xsb')
+
+
+def test_identification(xsb1):
+    assert isinstance(xsb1, XsbFile)
+
+
+def test_no_differences(xsb1):
+    difference = xsb1.compare(xsb1)
+    assert difference is None
+
+
+ at pytest.fixture
+def differences(xsb1, xsb2):
+    return xsb1.compare(xsb2).details
+
+
+ at skip_unless_tools_exist('dumpxsb')
+def test_diff(differences):
+    expected_diff = get_data('xsb_expected_diff')
+    assert differences[0].unified_diff == expected_diff
+
+
+ at skip_unless_tools_exist('dumpxsb')
+def test_compare_non_existing(monkeypatch, xsb1):
+    assert_non_existing(monkeypatch, xsb1, has_null_source=False)
diff --git a/tests/data/test1.xsb b/tests/data/test1.xsb
new file mode 100644
index 0000000..349094c
Binary files /dev/null and b/tests/data/test1.xsb differ
diff --git a/tests/data/test2.xsb b/tests/data/test2.xsb
new file mode 100644
index 0000000..3e0f884
Binary files /dev/null and b/tests/data/test2.xsb differ
diff --git a/tests/data/xsb_expected_diff b/tests/data/xsb_expected_diff
new file mode 100644
index 0000000..4a1b880
--- /dev/null
+++ b/tests/data/xsb_expected_diff
@@ -0,0 +1,153 @@
+@@ -1,101 +1,101 @@
+   Magic cookie: da7ababe
+   Major version: 2
+   Minor version: 24
+   Release number: 0
+   Filetype: FILETYPE_SCHEMAINDEX
+   String pool (41):
+-    1 = "testcase939btype"
+-    2 = "files7c3eelemtype"
+-    3 = "filedesc9392type"
+-    4 = "role21a8attrtype"
+-    5 = "codef72ftype"
+-    6 = "timport22datype"
+-    7 = "downloadedschemaentry1c75type"
+-    8 = "tests5621doctype"
+-    9 = "tests9d6eelemtype"
+-    10 = "testselement"
++    1 = "downloadedschemaentry1c75type"
++    2 = "timport22datype"
++    3 = "testcase939btype"
++    4 = "files7c3eelemtype"
++    5 = "filedesc9392type"
++    6 = "role21a8attrtype"
++    7 = "codef72ftype"
++    8 = "downloadedschemas2dd7doctype"
++    9 = "downloadedschemasb3efelemtype"
++    10 = "downloadedschemaselement"
+     11 = "definitionsc7f1doctype"
+     12 = "definitions05ddelemtype"
+     13 = "definitionselement"
+-    14 = "downloadedschemas2dd7doctype"
+-    15 = "downloadedschemasb3efelemtype"
+-    16 = "downloadedschemaselement"
+-    17 = "http://www.bea.com/2003/05/xmlbean/ltgfmt"
+-    18 = "tests"
++    14 = "tests5621doctype"
++    15 = "tests9d6eelemtype"
++    16 = "testselement"
++    17 = "http://www.bea.com/2003/01/xmlbean/xsdownload"
++    18 = "downloaded-schemas"
+     19 = "http://www.apache.org/internal/xmlbeans/wsdlsubst"
+     20 = "definitions"
+-    21 = "http://www.bea.com/2003/01/xmlbean/xsdownload"
+-    22 = "downloaded-schemas"
+-    23 = "test-case"
+-    24 = "file-desc"
+-    25 = "code"
+-    26 = "TImport"
+-    27 = "downloaded-schema-entry"
+-    28 = "org.apache.xmlbeans.impl.xb.ltgfmt.TestsDocument"
++    21 = "http://www.bea.com/2003/05/xmlbean/ltgfmt"
++    22 = "tests"
++    23 = "downloaded-schema-entry"
++    24 = "TImport"
++    25 = "test-case"
++    26 = "file-desc"
++    27 = "code"
++    28 = "org.apache.xmlbeans.impl.xb.xsdownload.DownloadedSchemasDocument"
+     29 = "org.apache.xmlbeans.impl.xb.substwsdl.DefinitionsDocument"
+-    30 = "org.apache.xmlbeans.impl.xb.xsdownload.DownloadedSchemasDocument"
+-    31 = "org.apache.xmlbeans.impl.xb.ltgfmt.TestCase"
+-    32 = "org.apache.xmlbeans.impl.xb.ltgfmt.FileDesc"
+-    33 = "org.apache.xmlbeans.impl.xb.ltgfmt.Code"
+-    34 = "org.apache.xmlbeans.impl.xb.substwsdl.TImport"
+-    35 = "org.apache.xmlbeans.impl.xb.xsdownload.DownloadedSchemaEntry"
+-    36 = "org.apache.xmlbeans.impl.xb.ltgfmt.TestsDocument.Tests"
++    30 = "org.apache.xmlbeans.impl.xb.ltgfmt.TestsDocument"
++    31 = "org.apache.xmlbeans.impl.xb.xsdownload.DownloadedSchemaEntry"
++    32 = "org.apache.xmlbeans.impl.xb.substwsdl.TImport"
++    33 = "org.apache.xmlbeans.impl.xb.ltgfmt.TestCase"
++    34 = "org.apache.xmlbeans.impl.xb.ltgfmt.FileDesc"
++    35 = "org.apache.xmlbeans.impl.xb.ltgfmt.Code"
++    36 = "org.apache.xmlbeans.impl.xb.xsdownload.DownloadedSchemasDocument.DownloadedSchemas"
+     37 = "org.apache.xmlbeans.impl.xb.substwsdl.DefinitionsDocument.Definitions"
+-    38 = "org.apache.xmlbeans.impl.xb.xsdownload.DownloadedSchemasDocument.DownloadedSchemas"
++    38 = "org.apache.xmlbeans.impl.xb.ltgfmt.TestsDocument.Tests"
+     39 = "org.apache.xmlbeans.impl.xb.ltgfmt.TestCase.Files"
+     40 = "org.apache.xmlbeans.impl.xb.ltgfmt.FileDesc.Role"
+   Handle pool (16):
++    downloadedschemaentry1c75type (FILETYPE_SCHEMATYPE)
++    timport22datype (FILETYPE_SCHEMATYPE)
+     testcase939btype (FILETYPE_SCHEMATYPE)
+     files7c3eelemtype (FILETYPE_SCHEMATYPE)
+     filedesc9392type (FILETYPE_SCHEMATYPE)
+     role21a8attrtype (FILETYPE_SCHEMATYPE)
+     codef72ftype (FILETYPE_SCHEMATYPE)
+-    timport22datype (FILETYPE_SCHEMATYPE)
+-    downloadedschemaentry1c75type (FILETYPE_SCHEMATYPE)
+-    tests5621doctype (FILETYPE_SCHEMATYPE)
+-    tests9d6eelemtype (FILETYPE_SCHEMATYPE)
+-    testselement (FILETYPE_SCHEMAELEMENT)
+-    definitionsc7f1doctype (FILETYPE_SCHEMATYPE)
+-    definitions05ddelemtype (FILETYPE_SCHEMATYPE)
+-    definitionselement (FILETYPE_SCHEMAELEMENT)
+     downloadedschemas2dd7doctype (FILETYPE_SCHEMATYPE)
+     downloadedschemasb3efelemtype (FILETYPE_SCHEMATYPE)
+     downloadedschemaselement (FILETYPE_SCHEMAELEMENT)
++    definitionsc7f1doctype (FILETYPE_SCHEMATYPE)
++    definitions05ddelemtype (FILETYPE_SCHEMATYPE)
++    definitionselement (FILETYPE_SCHEMAELEMENT)
++    tests5621doctype (FILETYPE_SCHEMATYPE)
++    tests9d6eelemtype (FILETYPE_SCHEMATYPE)
++    testselement (FILETYPE_SCHEMAELEMENT)
+   Global elements (3):
+-    tests at http://www.bea.com/2003/05/xmlbean/ltgfmt = testselement
+-    definitions at http://www.apache.org/internal/xmlbeans/wsdlsubst = definitionselement
+     downloaded-schemas at http://www.bea.com/2003/01/xmlbean/xsdownload = downloadedschemaselement
++    definitions at http://www.apache.org/internal/xmlbeans/wsdlsubst = definitionselement
++    tests at http://www.bea.com/2003/05/xmlbean/ltgfmt = testselement
+   Global attributes (0):
+   Model groups (0):
+   Attribute groups (0):
+   Identity constraints (0):
+   Global types (5):
++    downloaded-schema-entry at http://www.bea.com/2003/01/xmlbean/xsdownload = downloadedschemaentry1c75type
++    TImport at http://www.apache.org/internal/xmlbeans/wsdlsubst = timport22datype
+     test-case at http://www.bea.com/2003/05/xmlbean/ltgfmt = testcase939btype
+     file-desc at http://www.bea.com/2003/05/xmlbean/ltgfmt = filedesc9392type
+     code at http://www.bea.com/2003/05/xmlbean/ltgfmt = codef72ftype
+-    TImport at http://www.apache.org/internal/xmlbeans/wsdlsubst = timport22datype
+-    downloaded-schema-entry at http://www.bea.com/2003/01/xmlbean/xsdownload = downloadedschemaentry1c75type
+   Document types (3):
+-    tests at http://www.bea.com/2003/05/xmlbean/ltgfmt = tests5621doctype
+-    definitions at http://www.apache.org/internal/xmlbeans/wsdlsubst = definitionsc7f1doctype
+     downloaded-schemas at http://www.bea.com/2003/01/xmlbean/xsdownload = downloadedschemas2dd7doctype
++    definitions at http://www.apache.org/internal/xmlbeans/wsdlsubst = definitionsc7f1doctype
++    tests at http://www.bea.com/2003/05/xmlbean/ltgfmt = tests5621doctype
+   Attribute types (0):
+   All types by classname (13):
+-    org.apache.xmlbeans.impl.xb.ltgfmt.TestsDocument = tests5621doctype
+-    org.apache.xmlbeans.impl.xb.substwsdl.DefinitionsDocument = definitionsc7f1doctype
+     org.apache.xmlbeans.impl.xb.xsdownload.DownloadedSchemasDocument = downloadedschemas2dd7doctype
++    org.apache.xmlbeans.impl.xb.substwsdl.DefinitionsDocument = definitionsc7f1doctype
++    org.apache.xmlbeans.impl.xb.ltgfmt.TestsDocument = tests5621doctype
++    org.apache.xmlbeans.impl.xb.xsdownload.DownloadedSchemaEntry = downloadedschemaentry1c75type
++    org.apache.xmlbeans.impl.xb.substwsdl.TImport = timport22datype
+     org.apache.xmlbeans.impl.xb.ltgfmt.TestCase = testcase939btype
+     org.apache.xmlbeans.impl.xb.ltgfmt.FileDesc = filedesc9392type
+     org.apache.xmlbeans.impl.xb.ltgfmt.Code = codef72ftype
+-    org.apache.xmlbeans.impl.xb.substwsdl.TImport = timport22datype
+-    org.apache.xmlbeans.impl.xb.xsdownload.DownloadedSchemaEntry = downloadedschemaentry1c75type
+-    org.apache.xmlbeans.impl.xb.ltgfmt.TestsDocument.Tests = tests9d6eelemtype
+-    org.apache.xmlbeans.impl.xb.substwsdl.DefinitionsDocument.Definitions = definitions05ddelemtype
+     org.apache.xmlbeans.impl.xb.xsdownload.DownloadedSchemasDocument.DownloadedSchemas = downloadedschemasb3efelemtype
++    org.apache.xmlbeans.impl.xb.substwsdl.DefinitionsDocument.Definitions = definitions05ddelemtype
++    org.apache.xmlbeans.impl.xb.ltgfmt.TestsDocument.Tests = tests9d6eelemtype
+     org.apache.xmlbeans.impl.xb.ltgfmt.TestCase.Files = files7c3eelemtype
+     org.apache.xmlbeans.impl.xb.ltgfmt.FileDesc.Role = role21a8attrtype
+   Defined namespaces (3):
+     http://www.bea.com/2003/01/xmlbean/xsdownload
+     http://www.bea.com/2003/05/xmlbean/ltgfmt
+     http://www.apache.org/internal/xmlbeans/wsdlsubst
+   Redefined global types (0):

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list