From 2d2975bd9fb32bb6dc50c7f513cbe00337fc16b0 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 8 Jul 2024 13:48:08 +0200 Subject: [PATCH] Change the mimetype database embedded into QtCore Instead of freedesktop.org.xml (which is GPL), use the tika mimetypes definition (Apache licensed), as fallback on platforms where shared-mime-info isn't installed. [ChangeLog][QtCore][QMimeDatabase] For licensing reasons, QtCore no longer ships a copy of the MIME database from freedesktop.org's shared-mime-info project, but the one from the Apache Tika project. The tika definitions don't have icons or translated descriptions, but are sufficient for matching file types. [ChangeLog][Third-Party Code] Added TIKA mimetypes and the corresponding attribution file. Change-Id: I360ed973f6d89a470dc2f17a21abdf5630c6d15d Reviewed-by: Volker Hilsheimer (cherry picked from commit 74ad4cbeef40b1f51a59b3168f8c0b62eb0b29c8) Reviewed-by: Qt Cherry-pick Bot --- .../3rdparty/process_tika_mimetypes.py | 173 + .../mimetypes/3rdparty/qt_attribution.json | 26 + .../mimetypes/3rdparty/tika-mimetypes.xml | 8304 +++++++++++++++++ .../mimetypes/mimetypes_resources.cmake | 6 +- src/corelib/mimetypes/qmimetypeparser.cpp | 1 + .../3rdparty}/freedesktop.org.xml | 0 .../mimetypes/qmimedatabase/CMakeLists.txt | 6 +- .../CMakeLists.txt | 24 +- .../tst_qmimedatabase-cache-builtin.cpp | 25 + .../qmimedatabase-cache-fdoxml/CMakeLists.txt | 95 + .../tst_qmimedatabase-cache-fdoxml.cpp} | 10 + .../CMakeLists.txt | 24 +- .../tst_qmimedatabase-xml-builtin.cpp | 19 + .../qmimedatabase-xml-fdoxml/CMakeLists.txt | 95 + .../tst_qmimedatabase-xml-fdoxml.cpp} | 9 + .../qmimedatabase/tst_qmimedatabase.cpp | 253 +- .../qmimedatabase/tst_qmimedatabase.h | 3 + 17 files changed, 8962 insertions(+), 111 deletions(-) create mode 100755 src/corelib/mimetypes/3rdparty/process_tika_mimetypes.py create mode 100644 src/corelib/mimetypes/3rdparty/qt_attribution.json create mode 100644 src/corelib/mimetypes/3rdparty/tika-mimetypes.xml rename {src/corelib/mimetypes/mime/packages => tests/auto/corelib/mimetypes/qmimedatabase/3rdparty}/freedesktop.org.xml (100%) rename tests/auto/corelib/mimetypes/qmimedatabase/{qmimedatabase-cache => qmimedatabase-cache-builtin}/CMakeLists.txt (71%) create mode 100644 tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache-builtin/tst_qmimedatabase-cache-builtin.cpp create mode 100644 tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache-fdoxml/CMakeLists.txt rename tests/auto/corelib/mimetypes/qmimedatabase/{qmimedatabase-cache/tst_qmimedatabase-cache.cpp => qmimedatabase-cache-fdoxml/tst_qmimedatabase-cache-fdoxml.cpp} (76%) rename tests/auto/corelib/mimetypes/qmimedatabase/{qmimedatabase-xml => qmimedatabase-xml-builtin}/CMakeLists.txt (72%) create mode 100644 tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml-builtin/tst_qmimedatabase-xml-builtin.cpp create mode 100644 tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml-fdoxml/CMakeLists.txt rename tests/auto/corelib/mimetypes/qmimedatabase/{qmimedatabase-xml/tst_qmimedatabase-xml.cpp => qmimedatabase-xml-fdoxml/tst_qmimedatabase-xml-fdoxml.cpp} (62%) diff --git a/src/corelib/mimetypes/3rdparty/process_tika_mimetypes.py b/src/corelib/mimetypes/3rdparty/process_tika_mimetypes.py new file mode 100755 index 00000000000..85652e26635 --- /dev/null +++ b/src/corelib/mimetypes/3rdparty/process_tika_mimetypes.py @@ -0,0 +1,173 @@ +#!/usr/bin/env python3 +# Copyright (C) 2024 Klaralvdalens Datakonsult AB (KDAB) +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +# The tika database at https://raw.githubusercontent.com/apache/tika/main/tika-core/src/main/resources/org/apache/tika/mime/tika-mimetypes.xml +# uses a format that is *close* to the freedesktop.org shared-mime-info format, but not quite. They extended it with +# - match types such as stringignorecase, regex, unicodeLE +# - 0x syntax for strings +# - making the type and offset attributes optional +# - to specify that at least two of the submatches should match +# It's also missing some crucial mimetypes that we need. +# This script fixes all that. + +# Usage: download tika-mimetypes.xml as tika-mimetypes.xml.orig and run this script to produce Qt's version of tika-mimetypes.xml + +import sys, re + +inputfile = "tika-mimetypes.xml.orig" +file = "tika-mimetypes.xml" + +def wrap_with_comment(line): + if not '\n" + return line + +def transform_hex_value(line): + match = re.search(r'value="0x([0-9a-fA-F]+)"', line) + if match: + hex_value = match.group(1) + # Insert \\x before every pair of hex characters + transformed_value = ''.join(f'\\x{hex_value[i:i+2]}' for i in range(0, len(hex_value), 2)) + line = re.sub(r'value="0x[0-9a-fA-F]+"', lambda m: f'value="{transformed_value}"', line) + return line + +def open_input_file(inputfile): + try: + return open(inputfile, "r") + except FileNotFoundError: + sys.exit(f"{inputfile} not found") + except OSError as e: + sys.exit(f"OS error when opening {inputfile}: {e}") + +with open_input_file(inputfile) as f: + with open(file, "w") as out: + + current_mime_type = '' + skip_until = '' + for line in f: + + line = line.replace('\t', ' ') # Untabify + line = re.sub(r' +\n$', '\n', line) # Remove trailing whitespace + + match = re.search(r'', line) + if match: + current_mime_type = match.group(1) + + # remove mimetypes with regex matches having submatches, just commenting out the line would break the xml structure + if current_mime_type == "application/marc" or current_mime_type == "application/x-touhou" or ';format' in current_mime_type: + # line = wrap_with_comment(line) # leads to issues with -- inside comments + continue + + if 'be a bit more flexible, but require one from each of these' in line: + skip_until = '' + if skip_until == "" and 'minShouldMatch="' in line: + skip_until = '' + if 'value="OggS\\000' in line: # off by one in mask length, it seems (audio/x-oggflac and following) + skip_until = '' + + if skip_until != "": + if skip_until in line: + skip_until = "" + else: + line = wrap_with_comment(line) + + # uncomment "conflicting" globs + pattern = re.compile(r'( *)') + match = pattern.search(line) + if match: + line = match.group(1) + match.group(2) + ' \n' + + if not '') + + # No offset specified, spell out 0 + if '' in line and not 'offset=' in line: + line = line.replace('', '> ') + + # tika extensions, not supported + if 'type="unicodeLE"' in line or 'type="regex"' in line or '' in line.lower(): + line = line.replace('/', ' case-sensitive="true"/') + line = line.replace('>', '> ') + + # Add aliases needed by the unittest + if ' + + + Empty document + + + + Desktop file + + + + + Qt Markup Language file + + + + + + + + + + + + + + + + + Compressed postscript + + + + + Core dump + + + + + BZip2 compressed tar file + + + + + Directory + + + + +""" + out.write(line) + diff --git a/src/corelib/mimetypes/3rdparty/qt_attribution.json b/src/corelib/mimetypes/3rdparty/qt_attribution.json new file mode 100644 index 00000000000..7ed6c198b9f --- /dev/null +++ b/src/corelib/mimetypes/3rdparty/qt_attribution.json @@ -0,0 +1,26 @@ +[ + { + "Id": "tika-mimetypes", + "Name": "Apache Tika MimeType Definitions", + "QDocModule": "qtcore", + "QtUsage": + "Qt Core uses a copy of the Apache Tika MimeType Definitions if shared-mime-info isn't installed on the system.", + "Comment": { + "Files": + "For update, see qtbase/src/corelib/mimetypes/3rdparty/process_tika_mimetypes.py" + }, + "Files": [ + "tika-mimetypes.xml" + ], + "Description": + "The Apache Tika MimeTypes list many known MIME types and how to match files (using globs and/or 'magic' rules for the file contents)", + "Homepage": + "https://github.com/apache/tika/tree/main/tika-core/src/main/resources/org/apache/tika/mime", + "Version": "019041117149667bc4d18fabf222a0670d407959", + "DownloadLocation": + "https://github.com/apache/tika/blob/019041117149667bc4d18fabf222a0670d407959/tika-core/src/main/resources/org/apache/tika/mime/tika-mimetypes.xml", + "License": "Apache License 2.0", + "LicenseId": "Apache-2.0", + "Copyright": "Copyright 2011 The Apache Software Foundation" + } +] diff --git a/src/corelib/mimetypes/3rdparty/tika-mimetypes.xml b/src/corelib/mimetypes/3rdparty/tika-mimetypes.xml new file mode 100644 index 00000000000..739877cc4eb --- /dev/null +++ b/src/corelib/mimetypes/3rdparty/tika-mimetypes.xml @@ -0,0 +1,8304 @@ + + + + + + + + + Empty document + + + + Desktop file + + + + + Qt Markup Language file + + + + + + + + + + + + + + + + + Compressed postscript + + + + + Core dump + + + + + BZip2 compressed tar file + + + + + Directory + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Windows Batch / Command File + + + + + + + + + + + + + + + BizAgi Process Modeler + + + + + + + + CBOR + Concise Binary Object Representation container + http://tools.ietf.org/html/rfc7049 + + + + + + + + + + + + + + + + + + + + + + CorelDraw + cdr: CorelDraw + des: CorelDraw X4 and newer + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + DICOM medical imaging data + + + + + + + + Darwin Information Typing Architecture + + + + IFO + DVD information file + + + + + + + + + + EBU-STL + EBU-STL subtitles + https://tech.ebu.ch/docs/tech/tech3264.pdf + + + + + + + + + + + + + + + + + + + + + + + + EPUB + Electronic Publication + + + + + + + + + + + + + + + FITS + Flexible Image Transport System + http://www.digitalpreservation.gov/formats/fdd/fdd000317.shtml + + + + + + + + + + + + + + + + + + + + + + + + AI + Adobe Illustrator Artwork + http://en.wikipedia.org/wiki/Adobe_Illustrator_Artwork + + + + + AI + Adobe Illustrator Artwork -- the older postscript based AI files + + http://justsolve.archiveteam.org/wiki/Adobe_Illustrator_Artwork + + + + + + + + + + + + + + + Windows setup INFormation + http://msdn.microsoft.com/en-us/library/windows/hardware/ff549520(v=vs.85).aspx + + + + + + + + + + + + + + + Java Archive + http://en.wikipedia.org/wiki/.jar + com.sun.java-archive + + + + + + + + + + + + + + + + + + + + + + + + + + + + JavaScript Source Code + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Web Application Manifest file + + + + + + Java Class File + + + + + + + + + + Java Native Library for OSX + + + + + + + + + + + + Java hprof text file + + + + + + + Java hprof text file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Wolfram Mathematica + + + + + + + + + + + + + Wolfram Language + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Adobe MIF File + + + + + + + + + + + + + QTFF + QuickTime container format + + + + MP4 container format + + + + + + + + + + + + + Microsoft Word Document + http://en.wikipedia.org/wiki/.doc + com.microsoft.word.doc + + + + + + + + + + + + + + + + + + + + + Microsoft Word 2 Document + + + + + + + + Microsoft Word 5 Document + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + OneNote + + + + OneNote Package + + + + + + + + + + + + + PDF + Portable Document Format + http://en.wikipedia.org/wiki/PDF + http://www.adobe.com/devnet/pdf/pdf_reference_archive.html + com.adobe.pdf + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + PostScript + + + + + + + + + + + + + + + + + + + + + + + + + + Excel 2003 xml format, pre-ooxml + glob pattern typically *.xls + + + + + + Word 2003 xml format, pre-ooxml + glob pattern typically *.doc + + + + + Word 2006 xml format, pre-ooxml + glob pattern typically *.xml + + + + + + + RDF/XML + XML syntax for RDF graphs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Rich Text Format File + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Sereal binary serialization format + https://github.com/Sereal/Sereal/blob/master/sereal_spec.pod + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SMIL Multimedia + + + + + + + + + + + + SolidWorks CAD program + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Password Protected iWorks File + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + web archive frictionless zip + + + + frictionless data package zip package + + + + frictionless data package - standalong datapackage.json + + + + frictionless data package - gzip of standalone datapackage.json + + + + + + + + + + http://support.digilite.eu/?digilite=library + digilite.eu Prolights configuration file + Note glob clash with Adobe's .fdf + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ASiC-E + Extended Associated Signature Container + + + + + + + + + + + + ASiC-S + Simple Associated Signature Container + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + FDF + Forms Data Format + http://en.wikipedia.org/wiki/Forms_Data_Format + http://www.adobe.com/devnet/acrobat/fdftoolkit.html + com.adobe.fdf + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + KML + Keyhole Markup Language + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + XML syntax for IPTC NewsMessages + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + KChart File + + + + + + + + + + + + + + + + + + KPresenter File + + + + + + + KSpread File + + + + + + KWord File + + + + + + + + + + + + + + + + + SSEYO Koan File + + + + + + + + + + + + + + + + + + + Lotus 1-2-3 + + + + + + + + + + + Lotus 1-2-3, version 1 + + + + + + + + + + Lotus 1-2-3, version 2 + + + + + + + + + + + Lotus 1-2-3, version 3 + + + + + + + + + + Lotus 1-2-3, version 4-5 + + + + + + + + + + Lotus 1-2-3, version 97/9.x + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + FrameMaker Interchange Format + + + + + + + + + + + + + + + + MindManager + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Microsoft Excel Spreadsheet + + + + + + + + + + + + + + + + + + + + + + Office Open XML Workbook Add-in (macro-enabled) + + + + + + Office Open XML Workbook (macro-enabled) + + + + + + Microsoft Excel 2007 Binary Spreadsheet + + + + + + Microsoft Excel 4 Worksheet + + + + + + + + + + + Microsoft Excel 4 Workspace + + + + + + + + + + Microsoft Excel 3 Worksheet + + + + + + + + + + + Microsoft Excel 3 Workspace + + + + + + + + + + Microsoft Excel 2 Worksheet + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Microsoft Outlook Message + + + + + + Outlook Personal Folders File Format + + + + + + + + + https://en.wikipedia.org/wiki/3D_Manufacturing_Format + 3D manufacturing format + + + + + + + + + + + + + + + + + Microsoft Powerpoint Presentation + + + + + + + + + + + + + + + Office Open XML Presentation Add-in (macro-enabled) + + + + + + Office Open XML Presentation (macro-enabled) + + + + + + + + + + + Office Open XML Presentation Slideshow (macro-enabled) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Office Open XML Document (macro-enabled) + + + + + + Office Open XML Document Template (macro-enabled) + + + + + + + + + + + + + + + + + + + + + + + Open XML Paper Specification + + + + + + + Magic Shadow Archiver + http://justsolve.archiveteam.org/wiki/MSA_(Magic_Shadow_Archiver) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + OpenDocument v1.0: Chart document + + + + + + + + + + + + OpenDocument v1.0: Chart document used as template + + + + + + + + + + + + + + + + + OpenDocument v1.0: Formula document + + + + + + + + + + + + OpenDocument v1.0: Formula document used as template + + + + + + + + + + + + OpenDocument v1.0: Graphics document (Drawing) + + + + + + + + + + + + OpenDocument v1.0: Graphics document used as template + + + + + + + + + + + + OpenDocument v1.0: Image document + + + + + + + + + + + + OpenDocument v1.0: Image document used as template + + + + + + + + + + + + OpenDocument v1.0: Presentation document + + + + + + + + + + + + OpenDocument v1.0: Presentation document used as template + + + + + + + + + + + + OpenDocument v1.0: Spreadsheet document + + + + + + + + + + + + OpenDocument v1.0: Spreadsheet document used as template + + + + + + + + + + + + OpenDocument v1.0: Text document + + + + + + + + + + + + OpenDocument v1.0: Flat Text document + + + + + + OpenDocument v1.0: Flat Text document + + + + + + OpenDocument v1.0: Flat Presentation document + + + + + + OpenDocument v1.0: Flat Spreadsheet document + + + + + + + OpenDocument v1.0: Global Text document + + + + + + + + + + + + OpenDocument v1.0: Text document used as template + + + + + + + + + + + + OpenDocument v1.0: Text document used as template for HTML documents + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Office Open XML Presentation + + + + + + + + + + + + Office Open XML Presentation Template + + + + + + Office Open XML Presentation Slideshow + + + + + + Office Open XML Workbook + + + + + + Office Open XML Workbook Template + + + + + + Office Open XML Workbook Template (macro-enabled) + + + + + + Office Open XML Document + + + + + + Office Open XML Document Template + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SubRip (srt) subtitles + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + OpenOffice v1.0: Writer Document + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TCPDump pcap packet capture + + + + + + + + + + TCPDump next gen pcap packet capture + https://www.ietf.org/staging/draft-tuexen-opsawg-pcapng-02.html + + + + + + + + + + + + + + + + + TMX Translation Memory + https://www.gala-global.org/tmx-14b + TMX + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Microsoft Visio Diagram + + + + + + + + + Office Open XML Visio Drawing (macro-free) + + + + + Office Open XML Visio Template (macro-free) + + + + + Office Open XML Visio Stencil (macro-free) + + + + + Office Open XML Visio Drawing (macro-enabled) + + + + + Office Open XML Visio Template (macro-enabled) + + + + + Office Open XML Visio Stencil (macro-enabled) + + + + + + + + + + + + + + + + + + + + Compiled WML Document + + + + + Compiled WML Script + + + + + + + + + + + WPD + WordPerfect - Corel Word Processing + http://en.wikipedia.org/wiki/WordPerfect + com.corel.wordperfect.doc + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + WARC + WARC + + + + + + + + WARC + WARC + + + + + Wasm + Web Assembly + + + + + + + + + + + + + + + + + + + + + + + + + + Targa image data + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + https://en.wikipedia.org/wiki/Additive_manufacturing_file_format + + + + + + http://fileformats.archiveteam.org/wiki/ATR + + + + + + + + + + + + + AxCrypt + + + + + + + + + + + INDD + Adobe InDesign document + + + + + + + Flow Cytometry Standard File + + + + + + + + IDML + + + + + INX + Adobe InDesign Interchange format + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ASPRS Lidar Data Exchange Format + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Berkeley DB + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + CD Audio + + + + + + + GNU tar Compressed File Archive (GNU Tape Archive) + + + + + + + + + Guitar Pro + https://dguitar.sourceforge.net/GP4format.html + + + + + + + + Amiga Disk File + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Bzip 2 UNIX Compressed File + + + + + + + + + + Virtual CD-ROM CD Image File + + + + + + + + + + + + + CRX + Chrome Extension Package + https://developer.chrome.com/extensions/crx + + + + + + + + + + + + + + + + + + + + UNIX CPIO Archive + + + + + + + + + + + + + + + + + + + + + + + + + + + + DEX + Dalvik Executable Format + http://source.android.com/devices/tech/dalvik/dex-format.html + + + + + + + + + + Shockwave Movie + + + + + + + + + + + + + + + + + + + + + + + + + + TeX Device Independent Document + + + + + + + + + + Emacs Lisp bytecode + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + fat disk image; extensions: ima, img, dsk + https://www.nationalarchives.gov.uk/PRONOM/fmt/1087 + + + + + + + + + + + KIllustrator File + + + + + + + + + + + + + + https://openscad.org/index.html + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Modified Maximum Method Digisonde Portable Sounder File format + http://www.alliancepermanentaccess.org/wp-content/uploads/temp/ionosonde-case-study.pdf + + + + + + + + + DOS/Windows executable (EXE) + + + + + + + + + + + + + + FP7 + FileMaker Pro 7 + + + + + + + + + + + + + + + + + + + + + + + + + + OTF + OpenType Font + + + + + + + + + + + + + + + + + TTF + TrueType Font + + + + + + + + + + + + + + + + + + + + Adobe Font Metric + + + + + + + + + + Printer Font Metric + + + + + + + + + + Foxmail Email File + + + + + + + Macromedia FutureSplash File + + + + + + + + + + + + + + + + + GRIB + General Regularly-distributed Information in Binary form + http://en.wikipedia.org/wiki/GRIB + + + + + + + + + + Gzip Compressed Archive + + + + + + + + + + + + + + + + https://en.wikipedia.org/wiki/Zstandard + https://tools.ietf.org/id/draft-kucherawy-dispatch-zstd-01.html + + + + + + + ESRI Layer file + + + + + Hierarchical Data Format File + + + + + + + + + + + + + Hangul Word Processor File + + + + + + + Hangul Word Processor File v5 + + + + Hangul Word Processor File, zip based + + + + + + iBooks + Apple iBooks Author publication format + + + + + + + + + NV5 Geospatial Interactive Data Language Save File + https://www.l3harrisgeospatial.com/docs/idl_savefile.html + + + + + + ARC + ARC + + + + + + + + ISA-Tab Investigation file + + + + + + + + + ISA-Tab Study file + + + + + + + + ISA-Tab Assay file + + + + + + + + ISO + ISO 9660 CD-ROM filesystem data + + + + + + + + + + Apple iTunes Binary Property List + + + + + + Apple iOS IPA AppStore file + + + + + + + + + + + + JDF NMR Spectroscopy + + + + + + + + + + Jigsaw Download + http://justsolve.archiveteam.org/wiki/Jigdo + + + + + + + + + + + + + LaTeX Source Document + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + First match LZ4 Frame + Second match Legacy Frame + + + + + + + + + Lzip (LZMA) compressed archive + + + + + + + + LZMA compressed archive + + + + Mach-O + https://www.nationalarchives.gov.uk/PRONOM/fmt/693 + + + + + + + Apple Xcode Memgraph + + + + + + MOBI + Mobipocket Ebook + + + + + + + + + + + MS-DOS compression szzd + https://www.nationalarchives.gov.uk/PRONOM/fmt/462 + + + + + + + Temporary files created by MSOffice applications + PRONOM fmt-473 + First byte and 53rd byte are the same -- the length of the name. + Based on TIKA-2469, we've added a heuristic/wild guess that the first 10 chars + after the length byte should be \x00 or a non-control character. + + + + + + Microsoft National Language Support + Should take precedence over x-ms-owner + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Microsoft Windows Installer + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MySQL Table Definition (Format) + + + + + + + + + + + + + MySQL MISAM Index + + + + + + + + MySQL MISAM Compressed Index + + + + + + + + + MySQL MISAM Data + + + + + + Nintendo Entertainment System ROM + + + + + + + + + + + + + + + + + + + + + + Planetary Data System Version 3 format + http://fileformats.archiveteam.org/wiki/PDS + + + + + + + + + + + + + + + + + + + + + + + + + + Quattro Pro - Corel Spreadsheet (part of WordPerfect Office suite) + + + + + + + + + + + + + + + + Quattro Pro for DOS, version 1-4 + + + + + + + + + + + Quattro Pro for DOS, version 5 + + + + + + + + + + + + + Quattro Pro for Windows, version 1, 5 + + + + + + + + + + Quattro Pro for Windows, version 6 + + + + + + + + + + + XQuery source code + + + + + + + RAR archive + + + + + + + + + RAR archive + + + + + + + RAR archive + + + + + + + + + + + + RedHat Package Manager + + + + + + + + SAS Program + + + + + SAS Stored Program (DATA Step) + + + + + SAS Audit + + + + + SAS v6 Data Set + + + + + + + + + + SAS Data Set + + + + + + + + SAS Data Set View + + + + + SAS Data Set Index + + + + + SAS Catalog + + + + + SAS Access Descriptor + + + + + SAS FDB Consolidation Database File + + + + + SAS MDDB Multi-Dimensional Database File + + + + + SAS DMDB Data Mining Database File + + + + + SAS Item Store (ItemStor) File + + + + + SAS Utility + + + + + SAS Permanent Utility + + + + + SAS Transport File + + + + SAS Backup + + + + SAS XPORT Transfer File + + + + + + + + SPSS Data File + + + + + + + + + + + + + + + UNIX/LINUX Shell Script + + + + + + + + + + + + + + + + + ESRI Shapefiles + ESRI Shapefiles + + + + + + + + Flash + Adobe Flash + + + + + + + + Sibelius + + + + + + + + + + + Snappy Framed + + + + + + + + Standard Formatted Data Units (SFDUs) data + + + + + + TAP (ZX Spectrum) + + + + + + + + + + + + + + + https://www.geopackage.org/ + + + + + + + + + + + + https://www.geopackage.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Stata DTA Script + DO + http://www.stata.com/help.cgi?do + + + + + Stata DTA Dataset + DTA + http://www.stata.com/help.cgi?dta + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TeX Source + + + + + + + + + + + + + + + + + + + + + + + + + + + + + TeX Virtual Font format + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Pre-OLE2 (Old) Microsoft Excel Worksheets + + + + + + + + + + + + + + + + + + + + + + + Password Protected OOXML File + + + + + Visio OOXML File + + + + + + + + + + + + + + + + + + + VHD + Virtual PC Virtual Hard Disk + http://en.wikipedia.org/wiki/VHD_%28file_format%29 + + + + + + + VMDK + Virtual Disk Format + http://en.wikipedia.org/wiki/VMDK + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + XMind Pro + + + + + + + + + + + + + + Zeno IMproved (ZIM) + https://en.wikipedia.org/wiki/ZIM_(file_format) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + XML + Extensible Markup Language + http://en.wikipedia.org/wiki/Xml + public.xml + + + + + + + + + + + + + + + + + + + + + + + + XML Document Type Definition + + + + + + + + + + + + + + + + + XSLFO + XSL Format + + + + + + + + XSLT + XSL Transformations + + + + + + XSPF + XML Shareable Playlist Format + + + + + + + + + + + + + Compressed Archive File + http://en.wikipedia.org/wiki/ZIP_(file_format) + com.pkware.zip-archive + + + + + + + + + + + + ZLIB Compressed Data Format + http://tools.ietf.org/html/rfc1950 + + + + + + + + + + + + + + 7zip + 7-zip archive + + + + + + + + + + + + + + + AC3 + Dolby Digital Audio Compression File + + + + + + + + + + + + + + + + + + + + + + EAC3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + uLaw/AU Audio File + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MIDI + Musical Instrument Digital Interface + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MP3 + MPEG-1 Audio Layer 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Ogg Vorbis Audio + + + + + + Ogg Vorbis Codec Compressed WAV File + + + + + + + + + + + + Portable Sound Format + http://web.archive.org/web/20140125155137/http://wiki.neillcorlett.com/PSFFormat + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Slight Atari Player + https://asap.sourceforge.net/sap-format.html + + + + + + + Ogg Packaged Free Lossless Audio Codec + + + + + + + + + + + + Ogg Packaged Unompressed WAV File + + + + + + + + + + + + Ogg Opus Codec Compressed WAV File + + + + + + + + + + + + Ogg Speex Codec Compressed WAV File + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AIFF + Audio Interchange File Format + + + + + + + + + + + + + + Core Audio Format + com.apple.coreaudio-format + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + FLAC + Free Lossless Audio Codec + + + + + + + + MOD + + + + + + + + + + + + + + + + + + + + + MP3 Playlist File + + + + + + + + + + + + + + + + + + + Real Audio + + + + + + + + + + RealMedia Player Plug-in + + + + + + + + + WAV + + + + + + + + + + + + + + + + + + + + + + + + + + + Brookhaven Protein Databank File + + + + + + + + 3D Studio (V1) + + + + + + + + + + + ACES Image Container File + + + + + + + + + OS2 bitmap array + http://fileformats.archiveteam.org/wiki/OS/2_Bitmap_Array + + + + + + + + + + + + + + BMP + Windows bitmap + http://en.wikipedia.org/wiki/BMP_file_format + com.microsoft.bmp + + + + + + + + + + + + + + + + + + + BPG + Better Portable Graphics + + + + + + + + + CGM + Computer Graphics Metafile + + + + + + + + + + + + + + DPX + Digital Picture Exchange from SMPTE + + + + + + + + + + + EMF + Enhanced Metafile + https://msdn.microsoft.com/en-us/library/cc230711.aspx + + + + + + + + + + + + EMZ + Compressed Enhanced Metafile + + + + + + + + + + + + + + + + + + GIF + Graphics Interchange Format + http://en.wikipedia.org/wiki/Gif + com.compuserve.gif + + + + + + + + + AV1 Image File + AVIF + https://en.wikipedia.org/wiki/AV1#AV1_Image_File_Format_(AVIF) + + + + + + + HEIF - High Efficiency Image File + HEIF + https://en.wikipedia.org/wiki/High_Efficiency_Image_File_Format + + + + + + + + HEIF Sequence - High Efficiency Image Sequence + + + + + + + + + HEIF Image using HEVC Codec + HEIC + + + + + + + + + + HEIF Sequence using HEVC Codec + HEVC + + + + + + + + + Apple Icon Image Format + + + + + + + + + + + + + JP2 + JPEG 2000 Part 1 (JP2) + + + + + + + + + + JPEG + Joint Photographic Experts Group + http://en.wikipedia.org/wiki/Jpeg + public.jpeg + + + + + + + + + + + + + + + + + JP2 + JPEG 2000 Part 6 (JPM) + + + + + + + + + + + + JP2 + JPEG 2000 Part 2 (JPX) + + + + + + + + + + + + + + + + + + + + + + + PNG + Portable Network Graphics + + + + + + + + + + + + + + SVG + Scalable Vector Graphics + + + + + + + + + + + + + + + TIFF + Tagged Image File Format + + + + + + + + + + + + + + + + PSD + Photoshop Image + + + + + + + + + + + + + + + + + + + + + + + + + + + MicroStation v7 drawing + Sometimes first byte is C8, sometimes it is 08. + + + + + + + MicroStation v8 drawing; requires ole2 detector + + + + + + + + + + + + + + DWG + AutoCad Drawing + http://en.wikipedia.org/wiki/.dwg + + + + + + + + + + + + + + + + + + + + + + + + DXB + AutoCAD DXF simplified Binary + http://en.wikipedia.org/wiki/AutoCAD_DXF + + + + + + + + DXF + AutoCAD DXF + http://en.wikipedia.org/wiki/AutoCAD_DXF + + + + + + + + + + + + + + + + + + + + + + ICO + http://en.wikipedia.org/wiki/.ico + com.microsoft.ico + + + + + + + + + + + + Microsoft Document Imaging + + + + + + + + + + + + + + + + Wireless Bitmap File Format + + + + + DCX + ZSoft Multi-Page Paintbrush + + + + + + + + + PCX + ZSoft Paintbrush PiCture eXchange + + + + + + + + + + + + + + + + WEBP + http://en.wikipedia.org/wiki/WebP + + + + + + + + + https://en.wikipedia.org/wiki/High_Efficiency_Image_File_Format + + + + + + + + + https://en.wikipedia.org/wiki/High_Efficiency_Image_File_Format + + + + + + + + https://en.wikipedia.org/wiki/High_Efficiency_Image_File_Format + + + + + + + https://en.wikipedia.org/wiki/High_Efficiency_Image_File_Format + + + + + + + + + + WMF + Windows Metafile + + + + + + + + + + + + + + + + + + + FreeHand image + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + JBIG2 + + A lossless image compression standard from the + Joint Bi-level Image Experts Group. + + http://www.itu.int/rec/T-REC-T.88/en + + + + + + + + + JPEG 2000 Codestream + + + + + + + + JPEG 2000 Container Format + + + + + + + JPEG XL + + + + + + + + + Navy Interchange File Format + + + + + + + Apple Macintosh QuickDraw/PICT Format + + + + + + + + + + PNM + Portable Any Map + + + + + + PBM + Portable Bit Map + + + + + + + + + + + + + + + + + + PGM + Portable Graymap Graphic + + + + + + + + + + + + + + + + + + PXM + UNIX Portable Bitmap Graphic + + + + + + + + + + + + + + + + + PAM + UNIX Portable Bitmap Graphic Arbitrary Map + + + + + + + + + + + + + DNG + Adobe Digital Negative + + + + + Hasselblad raw image + + + + + Fuji raw image + + + + + + Canon raw image + + + + + + + + Canon raw image, version 2, TIFF-based + + + + + + + + + + + + + + + + + + + + + Canon raw image, version 3, Quicktime-based + + + + + + + + + + Kodak raw image + + + + + + + + Minolta raw image + + + + + Nikon raw image + + + + + + Olympus raw image + + + + + + + + Pentax raw image + + + + + + Sony raw image + + + + + + + Sigma raw image + + + + + Epson raw image + + + + + Mamiya raw image + + + + + Leaf raw image + + + + + Panasonic raw image + + + + + + Phase One raw image + + + + + Red raw image + + + + + Imacon raw image + + + + + Logitech raw image + + + + + Casio raw image + + + + + Rawzor raw image + + + + + Silicon Graphics RGB Bitmap + + + + + + + + + + + + + + + + GIMP Image File + + + + + + + + + + + + + X Windows Dump + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MHTML + MIME Encapsulation of Aggregate HTML Documents + http://tools.ietf.org/html/rfc2557 + + + + + + + + + + + + + + + + + + + + + + 3d imaging data exchange + + + + + + + + Initial Graphics Exchange Specification Format + + + + + + + + + + + + + + + + + + no magic available + + + + DWF + AutoCAD Design Web Format + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AutoCAD Design Web Format + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ONline Information eXchange (ONIX) for books + + + + + + + + + + ONline Information eXchange (ONIX) for books + + + + + + + + ActionScript source code + + + + + + Ada source code + + + + + + + + AppleScript source code + + + + + + Active Server Page + + + + + + ASP .NET + + + + + + AspectJ source code + + + + + + + Assembler source code + + + + + + + + + + + + + + + + + + + + + + + + + + + Cascading Style Sheet + + + + + + + + + + + + + + + + + HyperText Markup Language + HTML + public.html + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Makefile build file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Roff/nroff/troff/groff Unformatted Manual Page (UNIX) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Graphviz Graph Visualization Software + + + + + + + + + + + + + + + + + ANPA + American Newspaper Publishers Association Wire Feeds + + + + + + + + + + + + + + + + + + + + + + + + WML Script + + + + + Web Video Text Tracks Format + WebVTT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AWK script + + + + + + + + + + + + + + + + + + Basic source code + + + + + + + + C++ source code header + + + + + + + + + + + + C++ source code + + + + + + + + + + + CGI script + + + + + + C source code header + + + + + + + + + Clojure source code + + + + + + CoffeeScript source code + + + + + + + C source code + + + + + + + + + C# source code + + + + + + COBOL source code + + + + + + + + + + + ColdFusion source code + + + + + + + + Common Lisp source code + + + + + + + + + + + + + + + + + + + + + + + Eiffel source code + + + + + + Emacs Lisp source code + + + + + + Erlang source code + + + + + + Expect Script + + + + + + Forth source code + + + + + + Fortran source code + + + + + + + + + + Go source code + + + + + + Groovy source code + + + + + + Haskell source code + + + + + + + Interface Definition Language + + + + + + Configuration file + + + + + + Java source code + + + + + + + Java Properties + + + + + + + + Java Server Page + + + + + + + + + + + LESS source code + + + + + + Lex/Flex source code + + + + + + application log + + + + + + Lua source code + + + + + + ML source code + + + + + + Matlab source code + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MATLAB data file + + + + + + + + + Modula source code + + + + + + + + + Objective-C source code + + + + + + Ocaml source code + + + + + + + Pascal source code + + + + + + + + + + Perl script + + + + + + + + + + + + + + + + PHP script + + + + + + + + + + + Prolog source code + + + + + + + Python script + + + + + + + + + + + + + + + + + + reStructuredText source code + + + + + + + + Rexx source code + + + + + + Ruby source code + + + + + + Scala source code + + + + + + Scheme source code + + + + + + Sed code + + + + + + SQL code + + + + + + + + + + + Smalltalk source code + + + + + + + Tcl script + + + + + + + + Text-based (non-binary) Message + + + + + + + + Visual basic source code + + + + + + + + + + + VB.NET source code + + + + + + VBScript source code + + + + + + + + + + + + + + + + + + + + + + + + Verilog source code + + + + + + VHDL source code + + + + + + + Markdown source code + + + + + + + + + Yacc/Bison source code + + + + + + YAML source code + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MJ2 + JPEG 2000 Part 3 (Motion JPEG, MJ2) + + + + + + + + + + + + + + + + + + + + + + + + + + + MPEG Movie Clip + + + + + + + + + + + + + + + + + Ogg Vorbis Video + + + + + + Ogg Daala Video + + + + + + + + + + + + Ogg Theora Video + + + + + + + + + + + + Ogg Packaged Dirac Video + + + + + + + + + + + Ogg Packaged OGM Video + + + + + + + + + + + + Ogg Packaged Raw UVS Video + + + + + + + + + + + Ogg Packaged Raw YUV Video + + + + + + + + + + + Ogg Packaged Raw RGB Video + + + + + + + + + + + + + + QuickTime Video + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Windows Media Metafile + + + + + + + + + + + + + + + + + + + + + + + + + + Audio Video Interleave File + + + + + + + + + + + + + + + + + + + + + + Matroska Media Container + + + + + + + + + + + + + + + + + + + + + + + + + + + Cooltalk Audio + + + + + FictionBook document + + + + + + + Asciidoc source code + + + + + + + + + + D source code + + + + + + HAML source code + + + + + + Haxe source code + + + + + + + XLIFF 1.2 document + + + + + + + + XLZ Archive + + + + + R source code + + + + + diff --git a/src/corelib/mimetypes/mimetypes_resources.cmake b/src/corelib/mimetypes/mimetypes_resources.cmake index 00fa4f52716..1bec50e46b4 100644 --- a/src/corelib/mimetypes/mimetypes_resources.cmake +++ b/src/corelib/mimetypes/mimetypes_resources.cmake @@ -7,17 +7,17 @@ # file with the same information set(corelib_mimetypes_resource_file - "${CMAKE_CURRENT_LIST_DIR}/mime/packages/freedesktop.org.xml" + "${CMAKE_CURRENT_LIST_DIR}/3rdparty/tika-mimetypes.xml" ) function(corelib_add_mimetypes_resources target) set(source_file "${corelib_mimetypes_resource_file}") set_source_files_properties("${source_file}" - PROPERTIES QT_RESOURCE_ALIAS "freedesktop.org.xml" + PROPERTIES QT_RESOURCE_ALIAS "tika-mimetypes.xml" ) qt_internal_add_resource(${target} "mimetypes" PREFIX - "/qt-project.org/qmime/packages" + "/qt-project.org/qmime/tika/packages" FILES "${source_file}" ) diff --git a/src/corelib/mimetypes/qmimetypeparser.cpp b/src/corelib/mimetypes/qmimetypeparser.cpp index 3f1e53b25d1..c3fb80f3b94 100644 --- a/src/corelib/mimetypes/qmimetypeparser.cpp +++ b/src/corelib/mimetypes/qmimetypeparser.cpp @@ -286,6 +286,7 @@ bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString ruleMatcher.addRules(rules); processMagicMatcher(ruleMatcher); rules.clear(); + ps = ParseOtherMimeTypeSubTag; // in case of an empty glob tag } break; } diff --git a/src/corelib/mimetypes/mime/packages/freedesktop.org.xml b/tests/auto/corelib/mimetypes/qmimedatabase/3rdparty/freedesktop.org.xml similarity index 100% rename from src/corelib/mimetypes/mime/packages/freedesktop.org.xml rename to tests/auto/corelib/mimetypes/qmimedatabase/3rdparty/freedesktop.org.xml diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/CMakeLists.txt b/tests/auto/corelib/mimetypes/qmimedatabase/CMakeLists.txt index 26aab786c27..91d1f98c3e5 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/CMakeLists.txt +++ b/tests/auto/corelib/mimetypes/qmimedatabase/CMakeLists.txt @@ -2,8 +2,10 @@ # SPDX-License-Identifier: BSD-3-Clause if(TARGET Qt::Concurrent) - add_subdirectory(qmimedatabase-xml) + add_subdirectory(qmimedatabase-xml-builtin) + add_subdirectory(qmimedatabase-xml-fdoxml) endif() if(TARGET Qt::Concurrent AND UNIX AND NOT APPLE AND NOT QNX) - add_subdirectory(qmimedatabase-cache) + add_subdirectory(qmimedatabase-cache-builtin) + add_subdirectory(qmimedatabase-cache-fdoxml) endif() diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/CMakeLists.txt b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache-builtin/CMakeLists.txt similarity index 71% rename from tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/CMakeLists.txt rename to tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache-builtin/CMakeLists.txt index a267640a506..2994dd64cec 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/CMakeLists.txt +++ b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache-builtin/CMakeLists.txt @@ -12,23 +12,21 @@ if(NOT QT_FEATURE_private_tests) endif() ##################################################################### -## tst_qmimedatabase-cache Test: +## tst_qmimedatabase-cache-builtin Test: ##################################################################### -qt_internal_add_test(tst_qmimedatabase-cache +qt_internal_add_test(tst_qmimedatabase-cache-builtin + RUN_SERIAL SOURCES ../tst_qmimedatabase.h - tst_qmimedatabase-cache.cpp + tst_qmimedatabase-cache-builtin.cpp LIBRARIES Qt::CorePrivate Qt::Concurrent ) # Resources: -# the freedesktop resources are handled manually below via mimetypes_resources.cmake -#set(mimetypes_resource_files - #"mime/packages/freedesktop.org.xml" -#) +# the builtin mimetype xml is handled manually below via mimetypes_resources.cmake set(testdata_resource_files "../add-extension.xml" "../circular-inheritance.xml" @@ -46,16 +44,16 @@ set(testdata_resource_files "../yast2-metapackage-handler-mimetypes.xml" ) -qt_internal_add_resource(tst_qmimedatabase-cache "testdata" +qt_internal_add_resource(tst_qmimedatabase-cache-builtin "testdata" PREFIX - "/qt-project.org/qmime" + "/tst_qmimedatabase/qmime" BASE ".." FILES ${testdata_resource_files} ) -qt_internal_add_resource(tst_qmimedatabase-cache "testfiles" +qt_internal_add_resource(tst_qmimedatabase-cache-builtin "testfiles" PREFIX "/files" FILES @@ -65,12 +63,12 @@ qt_internal_add_resource(tst_qmimedatabase-cache "testfiles" set(corelib_source_dir ../../../../../../src/corelib) include(${corelib_source_dir}/mimetypes/mimetypes_resources.cmake) -corelib_add_mimetypes_resources(tst_qmimedatabase-cache) +corelib_add_mimetypes_resources(tst_qmimedatabase-cache-builtin) ## Scopes: ##################################################################### -qt_internal_extend_target(tst_qmimedatabase-cache CONDITION GCC +qt_internal_extend_target(tst_qmimedatabase-cache-builtin CONDITION GCC COMPILE_OPTIONS -W -Wall @@ -80,7 +78,7 @@ qt_internal_extend_target(tst_qmimedatabase-cache CONDITION GCC -Wshadow ) -qt_internal_extend_target(tst_qmimedatabase-cache CONDITION UNIX AND NOT APPLE AND NOT QNX +qt_internal_extend_target(tst_qmimedatabase-cache-builtin CONDITION UNIX AND NOT APPLE AND NOT QNX DEFINES USE_XDG_DATA_DIRS ) diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache-builtin/tst_qmimedatabase-cache-builtin.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache-builtin/tst_qmimedatabase-cache-builtin.cpp new file mode 100644 index 00000000000..8e3df1c3341 --- /dev/null +++ b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache-builtin/tst_qmimedatabase-cache-builtin.cpp @@ -0,0 +1,25 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "../tst_qmimedatabase.cpp" + +void tst_QMimeDatabase::initTestCaseInternal() +{ +#if !QT_CONFIG(process) + QSKIP("No qprocess support", SkipAll); +#else + const QString mimeDirName = m_globalXdgDir + QStringLiteral("/mime"); + runUpdateMimeDatabase(mimeDirName); + QVERIFY(QFile::exists(mimeDirName + QStringLiteral("/mime.cache"))); +#endif +} + +bool tst_QMimeDatabase::useCacheProvider() const +{ + return true; +} + +bool tst_QMimeDatabase::useFreeDesktopOrgXml() const +{ + return false; +} diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache-fdoxml/CMakeLists.txt b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache-fdoxml/CMakeLists.txt new file mode 100644 index 00000000000..3a3af6cc212 --- /dev/null +++ b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache-fdoxml/CMakeLists.txt @@ -0,0 +1,95 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qmimedatabase LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +if(NOT QT_FEATURE_private_tests) + return() +endif() + +##################################################################### +## tst_qmimedatabase-cache-fdoxml Test: +##################################################################### + +qt_internal_add_test(tst_qmimedatabase-cache-fdoxml + RUN_SERIAL + SOURCES + ../tst_qmimedatabase.h + tst_qmimedatabase-cache-fdoxml.cpp + LIBRARIES + Qt::CorePrivate + Qt::Concurrent +) + +# Resources: +set(mimetypes_resource_files + "../3rdparty/freedesktop.org.xml" +) +set(testdata_resource_files + "../add-extension.xml" + "../circular-inheritance.xml" + "../invalid-magic1.xml" + "../invalid-magic2.xml" + "../invalid-magic3.xml" + "../magic-and-hierarchy.foo" + "../magic-and-hierarchy.xml" + "../magic-and-hierarchy2.foo" + "../qml-again.xml" + "../test.qml" + "../text-x-objcsrc.xml" + "../text-plain-subclass.xml" + "../webm-glob-deleteall.xml" + "../yast2-metapackage-handler-mimetypes.xml" +) + +qt_internal_add_resource(tst_qmimedatabase-cache-fdoxml "testdata" + PREFIX + "/tst_qmimedatabase/qmime" + BASE + ".." + FILES + ${testdata_resource_files} +) + +qt_internal_add_resource(tst_qmimedatabase-cache-fdoxml "testdata-fdoxml" + PREFIX + "/tst_qmimedatabase/qmime" + BASE + "../3rdparty" + FILES + ${mimetypes_resource_files} +) + +qt_internal_add_resource(tst_qmimedatabase-cache-fdoxml "testfiles" + PREFIX + "/files" + FILES + "../test.txt" + "../test.qml" +) + +set(corelib_source_dir ../../../../../../src/corelib) +include(${corelib_source_dir}/mimetypes/mimetypes_resources.cmake) +corelib_add_mimetypes_resources(tst_qmimedatabase-cache-fdoxml) + +## Scopes: +##################################################################### + +qt_internal_extend_target(tst_qmimedatabase-cache-fdoxml CONDITION GCC + COMPILE_OPTIONS + -W + -Wall + -Wextra + -Wno-long-long + -Wnon-virtual-dtor + -Wshadow +) + +qt_internal_extend_target(tst_qmimedatabase-cache-fdoxml CONDITION UNIX AND NOT APPLE AND NOT QNX + DEFINES + USE_XDG_DATA_DIRS +) diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/tst_qmimedatabase-cache.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache-fdoxml/tst_qmimedatabase-cache-fdoxml.cpp similarity index 76% rename from tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/tst_qmimedatabase-cache.cpp rename to tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache-fdoxml/tst_qmimedatabase-cache-fdoxml.cpp index e923cc1d506..957d36affb2 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache/tst_qmimedatabase-cache.cpp +++ b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-cache-fdoxml/tst_qmimedatabase-cache-fdoxml.cpp @@ -13,3 +13,13 @@ void tst_QMimeDatabase::initTestCaseInternal() QVERIFY(QFile::exists(mimeDirName + QStringLiteral("/mime.cache"))); #endif } + +bool tst_QMimeDatabase::useCacheProvider() const +{ + return true; +} + +bool tst_QMimeDatabase::useFreeDesktopOrgXml() const +{ + return true; +} diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/CMakeLists.txt b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml-builtin/CMakeLists.txt similarity index 72% rename from tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/CMakeLists.txt rename to tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml-builtin/CMakeLists.txt index 729ac3933a0..d36c0c0b4ea 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/CMakeLists.txt +++ b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml-builtin/CMakeLists.txt @@ -12,23 +12,21 @@ if(NOT QT_FEATURE_private_tests) endif() ##################################################################### -## tst_qmimedatabase-xml Test: +## tst_qmimedatabase-xml-builtin Test: ##################################################################### -qt_internal_add_test(tst_qmimedatabase-xml +qt_internal_add_test(tst_qmimedatabase-xml-builtin + RUN_SERIAL SOURCES ../tst_qmimedatabase.h - tst_qmimedatabase-xml.cpp + tst_qmimedatabase-xml-builtin.cpp LIBRARIES Qt::Concurrent Qt::CorePrivate ) # Resources: -# the freedesktop resources are handled manually below via mimetypes_resources.cmake -#set(mimetypes_resource_files - #"mime/packages/freedesktop.org.xml" -#) +# the builtin mimetype xml is handled manually below via mimetypes_resources.cmake set(testdata_resource_files "../add-extension.xml" "../circular-inheritance.xml" @@ -46,16 +44,16 @@ set(testdata_resource_files "../yast2-metapackage-handler-mimetypes.xml" ) -qt_internal_add_resource(tst_qmimedatabase-xml "testdata" +qt_internal_add_resource(tst_qmimedatabase-xml-builtin "testdata" PREFIX - "/qt-project.org/qmime" + "/tst_qmimedatabase/qmime" BASE ".." FILES ${testdata_resource_files} ) -qt_internal_add_resource(tst_qmimedatabase-xml "testfiles" +qt_internal_add_resource(tst_qmimedatabase-xml-builtin "testfiles" PREFIX "/files" FILES @@ -65,12 +63,12 @@ qt_internal_add_resource(tst_qmimedatabase-xml "testfiles" set(corelib_source_dir ../../../../../../src/corelib) include(${corelib_source_dir}/mimetypes/mimetypes_resources.cmake) -corelib_add_mimetypes_resources(tst_qmimedatabase-xml) +corelib_add_mimetypes_resources(tst_qmimedatabase-xml-builtin) ## Scopes: ##################################################################### -qt_internal_extend_target(tst_qmimedatabase-xml CONDITION GCC +qt_internal_extend_target(tst_qmimedatabase-xml-builtin CONDITION GCC COMPILE_OPTIONS -W -Wall @@ -80,7 +78,7 @@ qt_internal_extend_target(tst_qmimedatabase-xml CONDITION GCC -Wshadow ) -qt_internal_extend_target(tst_qmimedatabase-xml CONDITION UNIX AND NOT APPLE AND NOT QNX +qt_internal_extend_target(tst_qmimedatabase-xml-builtin CONDITION UNIX AND NOT APPLE AND NOT QNX DEFINES USE_XDG_DATA_DIRS ) diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml-builtin/tst_qmimedatabase-xml-builtin.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml-builtin/tst_qmimedatabase-xml-builtin.cpp new file mode 100644 index 00000000000..18192ba35b2 --- /dev/null +++ b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml-builtin/tst_qmimedatabase-xml-builtin.cpp @@ -0,0 +1,19 @@ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "../tst_qmimedatabase.cpp" + +void tst_QMimeDatabase::initTestCaseInternal() +{ + qputenv("QT_NO_MIME_CACHE", "1"); +} + +bool tst_QMimeDatabase::useCacheProvider() const +{ + return false; +} + +bool tst_QMimeDatabase::useFreeDesktopOrgXml() const +{ + return false; +} diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml-fdoxml/CMakeLists.txt b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml-fdoxml/CMakeLists.txt new file mode 100644 index 00000000000..d178ff7b345 --- /dev/null +++ b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml-fdoxml/CMakeLists.txt @@ -0,0 +1,95 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qmimedatabase LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +if(NOT QT_FEATURE_private_tests) + return() +endif() + +##################################################################### +## tst_qmimedatabase-xml-fdoxml Test: +##################################################################### + +qt_internal_add_test(tst_qmimedatabase-xml-fdoxml + RUN_SERIAL + SOURCES + ../tst_qmimedatabase.h + tst_qmimedatabase-xml-fdoxml.cpp + LIBRARIES + Qt::CorePrivate + Qt::Concurrent +) + +# Resources: +set(mimetypes_resource_files + "../3rdparty/freedesktop.org.xml" +) +set(testdata_resource_files + "../add-extension.xml" + "../circular-inheritance.xml" + "../invalid-magic1.xml" + "../invalid-magic2.xml" + "../invalid-magic3.xml" + "../magic-and-hierarchy.foo" + "../magic-and-hierarchy.xml" + "../magic-and-hierarchy2.foo" + "../qml-again.xml" + "../test.qml" + "../text-x-objcsrc.xml" + "../text-plain-subclass.xml" + "../webm-glob-deleteall.xml" + "../yast2-metapackage-handler-mimetypes.xml" +) + +qt_internal_add_resource(tst_qmimedatabase-xml-fdoxml "testdata" + PREFIX + "/tst_qmimedatabase/qmime" + BASE + ".." + FILES + ${testdata_resource_files} +) + +qt_internal_add_resource(tst_qmimedatabase-xml-fdoxml "testdata-fdoxml" + PREFIX + "/tst_qmimedatabase/qmime" + BASE + "../3rdparty" + FILES + ${mimetypes_resource_files} +) + +qt_internal_add_resource(tst_qmimedatabase-xml-fdoxml "testfiles" + PREFIX + "/files" + FILES + "../test.txt" + "../test.qml" +) + +set(corelib_source_dir ../../../../../../src/corelib) +include(${corelib_source_dir}/mimetypes/mimetypes_resources.cmake) +corelib_add_mimetypes_resources(tst_qmimedatabase-xml-fdoxml) + +## Scopes: +##################################################################### + +qt_internal_extend_target(tst_qmimedatabase-xml-fdoxml CONDITION GCC + COMPILE_OPTIONS + -W + -Wall + -Wextra + -Wno-long-long + -Wnon-virtual-dtor + -Wshadow +) + +qt_internal_extend_target(tst_qmimedatabase-xml-fdoxml CONDITION UNIX AND NOT APPLE AND NOT QNX + DEFINES + USE_XDG_DATA_DIRS +) diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/tst_qmimedatabase-xml.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml-fdoxml/tst_qmimedatabase-xml-fdoxml.cpp similarity index 62% rename from tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/tst_qmimedatabase-xml.cpp rename to tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml-fdoxml/tst_qmimedatabase-xml-fdoxml.cpp index f86c8b88399..2e63a60aa0c 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml/tst_qmimedatabase-xml.cpp +++ b/tests/auto/corelib/mimetypes/qmimedatabase/qmimedatabase-xml-fdoxml/tst_qmimedatabase-xml-fdoxml.cpp @@ -8,3 +8,12 @@ void tst_QMimeDatabase::initTestCaseInternal() qputenv("QT_NO_MIME_CACHE", "1"); } +bool tst_QMimeDatabase::useCacheProvider() const +{ + return false; +} + +bool tst_QMimeDatabase::useFreeDesktopOrgXml() const +{ + return true; +} diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp index 9c7f5fa8207..d8c89b56c4e 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp +++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp @@ -52,6 +52,7 @@ static const std::array additionalLocalMimeFiles = { "webm-glob-deleteall.xml", }; +static const auto s_additionalFilesResourcePrefix = ":/tst_qmimedatabase/qmime/"_L1; static const auto s_resourcePrefix = ":/qt-project.org/qmime/"_L1; static const auto s_inodeMimetype = "inode/directory"_L1; @@ -131,9 +132,14 @@ void tst_QMimeDatabase::initTestCase() QVERIFY2(QDir(m_localMimeDir).removeRecursively(), qPrintable(m_localMimeDir + ": " + qt_error_string())); } + m_isUsingCacheProvider = useCacheProvider(); + m_hasFreedesktopOrg = useFreeDesktopOrgXml(); + #ifdef USE_XDG_DATA_DIRS - // Create a temporary "global" XDG data dir for later use - // It will initially contain a copy of freedesktop.org.xml + // Create a temporary "global" XDG data dir. It's used + // 1) to install new global mimetypes later on + // 2) to run update-mime-database right away when testing the cache provider + // 3) to host a copy of freedesktop.org.xml in tst_qmimedatabase-xml-fdoxml QVERIFY2(m_temporaryDir.isValid(), ("Could not create temporary subdir: " + m_temporaryDir.errorString()).toUtf8()); const QDir here = QDir(m_temporaryDir.path()); @@ -144,19 +150,27 @@ void tst_QMimeDatabase::initTestCase() qputenv("XDG_DATA_DIRS", QFile::encodeName(m_globalXdgDir)); qDebug() << "\nGlobal XDG_DATA_DIRS: " << m_globalXdgDir; - const QString freeDesktopXml = QStringLiteral("freedesktop.org.xml"); - const QString xmlFileName = s_resourcePrefix + "packages/"_L1 + freeDesktopXml; - const QString xmlTargetFileName = globalPackageDir + QLatin1Char('/') + freeDesktopXml; - QString errorMessage; - QVERIFY2(copyResourceFile(xmlFileName, xmlTargetFileName, &errorMessage), qPrintable(errorMessage)); + if (m_isUsingCacheProvider || m_hasFreedesktopOrg) { + const QString xmlFileName = m_hasFreedesktopOrg + ? (s_additionalFilesResourcePrefix + "/freedesktop.org.xml"_L1) + : (s_resourcePrefix + "/tika/packages/tika-mimetypes.xml"_L1); + QVERIFY2(QFileInfo::exists(xmlFileName), qPrintable(xmlFileName)); + const QString xmlTargetFileName = + globalPackageDir + '/' + QFileInfo(xmlFileName).fileName(); + QString errorMessage; + QVERIFY2(copyResourceFile(xmlFileName, xmlTargetFileName, &errorMessage), + qPrintable(errorMessage)); + } #endif - m_testSuite = QFINDTESTDATA("../s-m-i/tests/mime-detection"); - if (m_testSuite.isEmpty()) - qWarning("%s", qPrintable(testSuiteWarning())); + if (m_hasFreedesktopOrg) { + m_testSuite = QFINDTESTDATA("../s-m-i/tests/mime-detection"); + if (m_testSuite.isEmpty()) { + qWarning().noquote() << testSuiteWarning(); + } + } initTestCaseInternal(); - m_isUsingCacheProvider = !qEnvironmentVariableIsSet("QT_NO_MIME_CACHE"); } void tst_QMimeDatabase::init() @@ -185,17 +199,19 @@ void tst_QMimeDatabase::mimeTypeForName() QVERIFY(s1.isValid()); QCOMPARE(s1.name(), QString::fromLatin1("text/plain")); - QMimeType krita = db.mimeTypeForName(QString::fromLatin1("application/x-krita")); - QVERIFY(krita.isValid()); + QMimeType cbor = db.mimeTypeForName(QString::fromLatin1("application/cbor")); + QVERIFY(cbor.isValid()); // Test parsing with application/rdf+xml which has the english comment after the other ones QMimeType rdf = db.mimeTypeForName(QString::fromLatin1("application/rdf+xml")); QVERIFY(rdf.isValid()); - QCOMPARE(rdf.comment(), QString::fromLatin1("RDF file")); + QVERIFY(rdf.comment() == QLatin1String("RDF file") + || rdf.comment() == QLatin1String("XML syntax for RDF graphs") /*tika*/); QMimeType bzip2 = db.mimeTypeForName(QString::fromLatin1("application/x-bzip2")); QVERIFY(bzip2.isValid()); - QCOMPARE(bzip2.comment(), QString::fromLatin1("Bzip2 archive")); + QVERIFY(bzip2.comment() == QLatin1String("Bzip2 archive") + || bzip2.comment() == QLatin1String("Bzip 2 UNIX Compressed File") /*tika*/); QMimeType defaultMime = db.mimeTypeForName(QString::fromLatin1("application/octet-stream")); QVERIFY(defaultMime.isValid()); @@ -206,17 +222,17 @@ void tst_QMimeDatabase::mimeTypeForName() QCOMPARE(doesNotExist.comment(), QString()); QCOMPARE(doesNotExist.aliases(), QStringList()); - // TODO move to findByFile #ifdef Q_OS_LINUX - QString exePath = QStandardPaths::findExecutable(QLatin1String("ls")); - if (exePath.isEmpty()) - qWarning() << "ls not found"; - else { - const QString executableType = QString::fromLatin1("application/x-executable"); - const QString sharedLibType = QString::fromLatin1("application/x-sharedlib"); - //QTest::newRow("executable") << exePath << executableType; - QVERIFY(db.mimeTypeForFile(exePath).name() == executableType || - db.mimeTypeForFile(exePath).name() == sharedLibType); + if (m_hasFreedesktopOrg) { + QString exePath = QStandardPaths::findExecutable(QLatin1String("ls")); + if (exePath.isEmpty()) + qWarning() << "ls not found"; + else { + const QString executableType = QString::fromLatin1("application/x-executable"); + const QString sharedLibType = QString::fromLatin1("application/x-sharedlib"); + QVERIFY(db.mimeTypeForFile(exePath).name() == executableType + || db.mimeTypeForFile(exePath).name() == sharedLibType); + } } #endif @@ -239,8 +255,8 @@ void tst_QMimeDatabase::mimeTypeForFileName_data() QTest::newRow("case-sensitive-only-match-core") << "core" << "application/x-core"; QTest::newRow("case-sensitive-only-match-Core") << "Core" << "application/octet-stream"; // #198477 - QTest::newRow("desktop file") << "foo.desktop" << "application/x-desktop"; - QTest::newRow("old kdelnk file is x-desktop too") << "foo.kdelnk" << "application/x-desktop"; + QTest::newRow("desktop file") << "foo.desktop" + << "application/x-desktop"; QTest::newRow("double-extension file") << "foo.tar.bz2" << "application/x-bzip2-compressed-tar"; QTest::newRow("single-extension file") << "foo.bz2" @@ -248,12 +264,22 @@ void tst_QMimeDatabase::mimeTypeForFileName_data() QTest::newRow(".doc should assume msword") << "somefile.doc" << "application/msword"; // #204139 QTest::newRow("glob that uses [] syntax, 1") << "Makefile" << "text/x-makefile"; QTest::newRow("glob that uses [] syntax, 2") << "makefile" << "text/x-makefile"; - QTest::newRow("glob that ends with *, no extension") << "README" << "text/x-readme"; - QTest::newRow("glob that ends with *, extension") << "README.foo" << "text/x-readme"; - QTest::newRow("glob that ends with *, also matches *.txt. Higher weight wins.") << "README.txt" << "text/plain"; - QTest::newRow("glob that ends with *, also matches *.nfo. Higher weight wins.") << "README.nfo" << "text/x-nfo"; - // fdo bug 15436, needs shared-mime-info >= 0.40 (and this tests the globs2-parsing code). - QTest::newRow("glob that ends with *, also matches *.pdf. *.pdf has higher weight") << "README.pdf" << "application/pdf"; + if (m_hasFreedesktopOrg) { + QTest::newRow("glob that ends with *, no extension") << "README" + << "text/x-readme"; + QTest::newRow("glob that ends with *, extension") << "README.foo" + << "text/x-readme"; + QTest::newRow("glob that ends with *, also matches *.txt. Higher weight wins.") + << "README.txt" + << "text/plain"; + QTest::newRow("glob that ends with *, also matches *.nfo. Higher weight wins.") + << "README.nfo" + << "text/x-nfo"; + // fdo bug 15436, needs shared-mime-info >= 0.40 (and this tests the globs2-parsing code). + QTest::newRow("glob that ends with *, also matches *.pdf. *.pdf has higher weight") + << "README.pdf" + << "application/pdf"; + } QTest::newRow("directory") << "/" << "inode/directory"; QTest::newRow("resource-directory") << ":/files/" << "inode/directory"; QTest::newRow("doesn't exist, no extension") << "IDontExist" << "application/octet-stream"; @@ -301,7 +327,11 @@ void tst_QMimeDatabase::mimeTypesForFileName_data() QTest::newRow("txt, 1 hit") << "foo.txt" << (QStringList() << "text/plain"); QTest::newRow("txtfoobar, 0 hit") << "foo.foobar" << QStringList(); QTest::newRow("m, 2 hits") << "foo.m" << (QStringList() << "text/x-matlab" << "text/x-objcsrc"); - QTest::newRow("sub, 3 hits") << "foo.sub" << (QStringList() << "text/x-microdvd" << "text/x-mpsub" << "text/x-subviewer"); + if (m_hasFreedesktopOrg) + QTest::newRow("sub, 3 hits") << "foo.sub" + << (QStringList() << "text/x-microdvd" + << "text/x-mpsub" + << "text/x-subviewer"); QTest::newRow("non_ascii") << QString::fromUtf8("AİİA.pdf") << (QStringList() << "application/pdf"); } @@ -334,15 +364,19 @@ void tst_QMimeDatabase::inheritance() QCOMPARE(wordperfect.parentMimeTypes().join(QString::fromLatin1(",")), QString::fromLatin1("application/octet-stream")); QVERIFY(wordperfect.inherits(QLatin1String("application/octet-stream"))); - QVERIFY(db.mimeTypeForName(QString::fromLatin1("image/svg+xml-compressed")).inherits(QLatin1String("application/x-gzip"))); + if (m_hasFreedesktopOrg) { + QVERIFY(db.mimeTypeForName(QString::fromLatin1("image/svg+xml-compressed")) + .inherits(QLatin1String("application/x-gzip"))); - // Check that msword derives from ole-storage - const QMimeType msword = db.mimeTypeForName(QString::fromLatin1("application/msword")); - QVERIFY(msword.isValid()); - const QMimeType olestorage = db.mimeTypeForName(QString::fromLatin1("application/x-ole-storage")); - QVERIFY(olestorage.isValid()); - QVERIFY(msword.inherits(olestorage.name())); - QVERIFY(msword.inherits(QLatin1String("application/octet-stream"))); + // Check that msword derives from ole-storage + const QMimeType msword = db.mimeTypeForName(QString::fromLatin1("application/msword")); + QVERIFY(msword.isValid()); + const QMimeType olestorage = + db.mimeTypeForName(QString::fromLatin1("application/x-ole-storage")); + QVERIFY(olestorage.isValid()); + QVERIFY(msword.inherits(olestorage.name())); + QVERIFY(msword.inherits(QLatin1String("application/octet-stream"))); + } const QMimeType directory = db.mimeTypeForName(s_inodeMimetype); QVERIFY(directory.isValid()); @@ -379,22 +413,27 @@ void tst_QMimeDatabase::inheritance() QCOMPARE(allSvgAncestors, QStringList() << QLatin1String("application/xml") << QLatin1String("text/plain") << QLatin1String("application/octet-stream")); // Check that text/x-mrml knows that it inherits from text/plain (implicitly) - const QMimeType mrml = db.mimeTypeForName(QString::fromLatin1("text/x-mrml")); + const QMimeType mrml = db.mimeTypeForName(QString::fromLatin1( + m_hasFreedesktopOrg ? "text/x-mrml" : "text/vnd.trolltech.linguist")); QVERIFY(mrml.isValid()); QVERIFY(mrml.inherits(QLatin1String("text/plain"))); QVERIFY(mrml.inherits(QLatin1String("application/octet-stream"))); - // Check that msword-template inherits msword - const QMimeType mswordTemplate = db.mimeTypeForName(QString::fromLatin1("application/msword-template")); - QVERIFY(mswordTemplate.isValid()); - QVERIFY(mswordTemplate.inherits(QLatin1String("application/msword"))); + if (m_hasFreedesktopOrg) { + // Check that msword-template inherits msword + const QMimeType mswordTemplate = + db.mimeTypeForName(QString::fromLatin1("application/msword-template")); + QVERIFY(mswordTemplate.isValid()); + QVERIFY(mswordTemplate.inherits(QLatin1String("application/msword"))); - // Check that buggy type definitions that have circular inheritance don't cause an infinite - // loop, especially when resolving a conflict between the file's name and its contents - const QMimeType ecmascript = db.mimeTypeForName(QString::fromLatin1("application/ecmascript")); - QVERIFY(ecmascript.allAncestors().contains("text/plain")); - const QMimeType javascript = db.mimeTypeForFileNameAndData("xml.js", ""); - QVERIFY(javascript.inherits(QString::fromLatin1("text/javascript"))); + // Check that buggy type definitions that have circular inheritance don't cause an infinite + // loop, especially when resolving a conflict between the file's name and its contents + const QMimeType ecmascript = + db.mimeTypeForName(QString::fromLatin1("application/ecmascript")); + QVERIFY(ecmascript.allAncestors().contains("text/plain")); + const QMimeType javascript = db.mimeTypeForFileNameAndData("xml.js", ""); + QVERIFY(javascript.inherits(QString::fromLatin1("text/javascript"))); + } } void tst_QMimeDatabase::aliases() @@ -421,9 +460,20 @@ void tst_QMimeDatabase::listAliases_data() QTest::addColumn("inputMime"); QTest::addColumn("expectedAliases"); - QTest::newRow("csv") << "text/csv" << "text/x-csv,text/x-comma-separated-values"; - QTest::newRow("xml") << "application/xml" << "text/xml"; - QTest::newRow("xml2") << "text/xml" /* gets resolved to application/xml */ << "text/xml"; + if (m_hasFreedesktopOrg) { + QTest::newRow("csv") << "text/csv" + << "text/x-csv,text/x-comma-separated-values"; + QTest::newRow("xml") << "application/xml" + << "text/xml"; + QTest::newRow("xml2") << "text/xml" /* gets resolved to application/xml */ << "text/xml"; + } else { + QTest::newRow("csv") << "text/csv" + << ""; + QTest::newRow("xml") << "application/xml" + << "text/xml,application/x-xml"; + QTest::newRow("xml2") << "text/xml" /* gets resolved to application/xml */ + << "text/xml,application/x-xml"; + } QTest::newRow("no_mime") << "message/news" << ""; } @@ -452,11 +502,15 @@ void tst_QMimeDatabase::icons() QMimeType pub = db.mimeTypeForFile(QString::fromLatin1("foo.epub"), QMimeDatabase::MatchExtension); QCOMPARE(pub.name(), QString::fromLatin1("application/epub+zip")); QCOMPARE(pub.iconName(), QString::fromLatin1("application-epub+zip")); - QCOMPARE(pub.genericIconName(), QString::fromLatin1("x-office-document")); + if (m_hasFreedesktopOrg) + QCOMPARE(pub.genericIconName(), QString::fromLatin1("x-office-document")); } void tst_QMimeDatabase::comment() { + if (!m_hasFreedesktopOrg) + QSKIP("Translations not yet available for tika mimetypes"); + struct RestoreLocale { ~RestoreLocale() { QLocale::setDefault(QLocale::c()); } @@ -513,7 +567,7 @@ void tst_QMimeDatabase::mimeTypeForFileWithContent() // Now the case where extension differs from contents, but contents has >80 magic rule // XDG spec says: contents wins. But we can't sniff all files... - { + if (m_hasFreedesktopOrg) { QTemporaryFile txtTempFile(QDir::tempPath() + QLatin1String("/tst_QMimeDatabase_XXXXXX.txt")); QVERIFY(txtTempFile.open()); txtTempFile.write("= 0.20") << QByteArray("\x78\x9f\x3e\x22") << "application/vnd.ms-tnef"; QTest::newRow("PDF magic") << QByteArray("%PDF-") << "application/pdf"; - QTest::newRow("PHP, High-priority rule") << QByteArray("= 0.22 const QByteArray oleData("\320\317\021\340\241\261\032\341"); // same as \xD0\xCF\x11\xE0 \xA1\xB1\x1A\xE1 - QTest::newRow("msword file, unknown extension") << QString::fromLatin1("mswordfile") << oleData << "application/x-ole-storage"; + if (m_hasFreedesktopOrg) + QTest::newRow("msword file, unknown extension") + << QString::fromLatin1("mswordfile") << oleData << "application/x-ole-storage"; QTest::newRow("excel file, found by extension") << QString::fromLatin1("excelfile.xls") << oleData << "application/vnd.ms-excel"; QTest::newRow("text.xls, found by extension, user is in control") << QString::fromLatin1("text.xls") << oleData << "application/vnd.ms-excel"; } @@ -654,6 +714,9 @@ void tst_QMimeDatabase::mimeTypeForUnixSpecials_data() #ifndef AT_FDCWD QSKIP("fdopendir and fstatat are not available"); #else + if (!m_hasFreedesktopOrg) + QSKIP("Special devices are not available in tika"); + QTest::addColumn("name"); QTest::addColumn("expected"); @@ -735,7 +798,10 @@ void tst_QMimeDatabase::allMimeTypes() QVERIFY(!lst.isEmpty()); // Hardcoding this is the only way to check both providers find the same number of mimetypes. - QCOMPARE(lst.size(), 908); + if (m_hasFreedesktopOrg) + QCOMPARE(lst.size(), 908); + else + QCOMPARE(lst.size(), 1640); // interestingly, tika has more mimetypes (but many are empty) for (const QMimeType &mime : lst) { const QString name = mime.name(); @@ -757,15 +823,27 @@ void tst_QMimeDatabase::suffixes_data() QTest::newRow("mimetype-with-multiple-patterns-kpr") << "application/x-kpresenter" << "*.kpr;*.kpt" << "kpr"; // The preferred suffix for image/jpeg is *.jpg, as per https://bugs.kde.org/show_bug.cgi?id=176737 QTest::newRow("jpeg") << "image/jpeg" - << "*.jfif;*.jpe;*.jpg;*.jpeg" + << (m_hasFreedesktopOrg ? "*.jfif;*.jpe;*.jpg;*.jpeg" + : "*.jfi;*.jfif;*.jif;*.jpe;*.jpeg;*.jpg") << "jpg"; - QTest::newRow("mimetype with many patterns") << "application/vnd.wordperfect" << "*.wp;*.wp4;*.wp5;*.wp6;*.wpd;*.wpp" << "wp"; + QTest::newRow("mimetype with many patterns") + << "application/vnd.wordperfect" + << (m_hasFreedesktopOrg ? "*.wp;*.wp4;*.wp5;*.wp6;*.wpd;*.wpp" + : "*.w60;*.wp;*.wp5;*.wp6;*.wp61;*.wpd;*.wpt") + << (m_hasFreedesktopOrg ? "wp" : "wpd"); QTest::newRow("oasis text mimetype") << "application/vnd.oasis.opendocument.text" << "*.odt" << "odt"; QTest::newRow("oasis presentation mimetype") << "application/vnd.oasis.opendocument.presentation" << "*.odp" << "odp"; - QTest::newRow("mimetype-multiple-patterns-text-plain") << "text/plain" << "*.asc;*.txt;*,v" << "txt"; - QTest::newRow("mimetype with uncommon pattern") << "text/x-readme" << "README*" << QString(); - QTest::newRow("mimetype with no patterns") << "application/x-ole-storage" << QString() << QString(); - QTest::newRow("default_mimetype") << "application/octet-stream" << QString() << QString(); + if (m_hasFreedesktopOrg) { // tika has a very very long list of patterns for text/plain + QTest::newRow("mimetype-multiple-patterns-text-plain") << "text/plain" + << "*.asc;*.txt;*,v" + << "txt"; + QTest::newRow("mimetype with uncommon pattern") << "text/x-readme" + << "README*" << QString(); + } + QTest::newRow("mimetype with no patterns") + << "application/x-zerosize" << QString() << QString(); + if (m_hasFreedesktopOrg) // tika has a long list of patterns for application/octet-stream + QTest::newRow("default_mimetype") << "application/octet-stream" << QString() << QString(); } void tst_QMimeDatabase::suffixes() @@ -793,8 +871,13 @@ void tst_QMimeDatabase::knownSuffix() QCOMPARE(db.suffixForFileName(QString::fromLatin1("foo.bar.bz2")), QString::fromLatin1("bz2")); QCOMPARE(db.suffixForFileName(QString::fromLatin1("foo.tar.bz2")), QString::fromLatin1("tar.bz2")); QCOMPARE(db.suffixForFileName(QString::fromLatin1("foo.TAR")), QString::fromLatin1("TAR")); // preserve case - QCOMPARE(db.suffixForFileName(QString::fromLatin1("foo.flatpakrepo")), QString::fromLatin1("flatpakrepo")); - QCOMPARE(db.suffixForFileName(QString::fromLatin1("foo.anim2")), QString()); // the glob is anim[0-9], no way to extract the extension without expensive regexp capturing + if (m_hasFreedesktopOrg) { + QCOMPARE(db.suffixForFileName(QString::fromLatin1("foo.flatpakrepo")), + QString::fromLatin1("flatpakrepo")); + QCOMPARE(db.suffixForFileName(QString::fromLatin1("foo.anim2")), + QString()); // the glob is anim[0-9], no way to extract the extension without + // expensive regexp capturing + } } void tst_QMimeDatabase::filterString_data() @@ -802,10 +885,15 @@ void tst_QMimeDatabase::filterString_data() QTest::addColumn("mimeType"); QTest::addColumn("expectedFilterString"); - QTest::newRow("single-pattern") << "application/pdf" - << "PDF document (*.pdf)"; - QTest::newRow("multiple-patterns-text-plain") << "text/plain" - << "Plain text document (*.txt *.asc *,v)"; + QTest::newRow("single-pattern") + << "application/pdf" + << (m_hasFreedesktopOrg ? "PDF document (*.pdf)" : "Portable Document Format (*.pdf)"); + if (m_hasFreedesktopOrg) + QTest::newRow("multiple-patterns-text-plain") << "text/plain" + << "Plain text document (*.txt *.asc *,v)"; + else + QTest::newRow("multiple-patterns-kword") << "application/vnd.kde.kword" + << "KWord File (*.kwd *.kwt)"; } void tst_QMimeDatabase::filterString() @@ -820,6 +908,9 @@ void tst_QMimeDatabase::filterString() void tst_QMimeDatabase::symlinkToFifo() // QTBUG-48529 { #if defined(Q_OS_UNIX) && !defined(Q_OS_INTEGRITY) + if (!m_hasFreedesktopOrg) + QSKIP("Special devices are not available in tika"); + QTemporaryDir tempDir; QVERIFY(tempDir.isValid()); const QString dir = tempDir.path(); @@ -1081,7 +1172,7 @@ void copyFiles(const QSpan &additionalMimeFiles, const QStrin { const QString notFoundErrorMessage = QString::fromLatin1("Cannot find '%1'"); for (const char *mimeFile : additionalMimeFiles) { - const QString resourceFilePath = s_resourcePrefix + QLatin1String(mimeFile); + const QString resourceFilePath = s_additionalFilesResourcePrefix + QLatin1String(mimeFile); QVERIFY2(QFile::exists(resourceFilePath), qPrintable(notFoundErrorMessage.arg(resourceFilePath))); @@ -1131,17 +1222,17 @@ void tst_QMimeDatabase::installNewGlobalMimeType() checkHasMimeType("text/x-suse-ymp"); // Test that a double-definition of a mimetype doesn't lead to sniffing ("conflicting globs"). - const QString qmlTestFile = s_resourcePrefix + "test.qml"_L1; + const QString qmlTestFile = s_additionalFilesResourcePrefix + "test.qml"_L1; QVERIFY2(!qmlTestFile.isEmpty(), qPrintable(QString::fromLatin1("Cannot find '%1' starting from '%2'"). arg("test.qml", QDir::currentPath()))); QCOMPARE(db.mimeTypeForFile(qmlTestFile).name(), QString::fromLatin1("text/x-qml")); - const QString fooTestFile = s_resourcePrefix + "magic-and-hierarchy.foo"_L1; + const QString fooTestFile = s_additionalFilesResourcePrefix + "magic-and-hierarchy.foo"_L1; QCOMPARE(db.mimeTypeForFile(fooTestFile).name(), QString::fromLatin1("application/foo")); - const QString fooTestFile2 = s_resourcePrefix + "magic-and-hierarchy2.foo"_L1; + const QString fooTestFile2 = s_additionalFilesResourcePrefix + "magic-and-hierarchy2.foo"_L1; QCOMPARE(db.mimeTypeForFile(fooTestFile2).name(), QString::fromLatin1("application/vnd.qnx.bar-descriptor")); // Test if we can use the default comment @@ -1235,7 +1326,7 @@ void tst_QMimeDatabase::installNewLocalMimeType() QString::fromLatin1("text/plain")); // Test that a double-definition of a mimetype doesn't lead to sniffing ("conflicting globs"). - const QString qmlTestFile = s_resourcePrefix + "test.qml"_L1; + const QString qmlTestFile = s_additionalFilesResourcePrefix + "test.qml"_L1; QVERIFY2(!qmlTestFile.isEmpty(), qPrintable(QString::fromLatin1("Cannot find '%1' starting from '%2'"). arg("test.qml", QDir::currentPath()))); @@ -1255,7 +1346,9 @@ void tst_QMimeDatabase::installNewLocalMimeType() // QTBUG-116905: globPatterns() should merge all locations // add-extension.xml adds *.jnewext - const QStringList expectedJpegPatterns{ "*.jpg", "*.jpeg", "*.jpe", "*.jfif", "*.jnewext" }; + const auto expectedJpegPatterns = m_hasFreedesktopOrg + ? QStringList{ "*.jpg", "*.jpeg", "*.jpe", "*.jfif", "*.jnewext" } + : QStringList{ "*.jpg", "*.jpeg", "*.jpe", "*.jif", "*.jfif", "*.jfi", "*.jnewext" }; QCOMPARE(db.mimeTypeForName(QStringLiteral("image/jpeg")).globPatterns(), expectedJpegPatterns); // Now that we have two directories with mime definitions, check that everything still works diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h index 415c2e3e379..4e68099f3b4 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h +++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.h @@ -69,6 +69,8 @@ private slots: private: void initTestCaseInternal(); // test-specific + bool useCacheProvider() const; // test-specific + bool useFreeDesktopOrgXml() const; // test-specific QString m_globalXdgDir; QString m_localMimeDir; @@ -77,6 +79,7 @@ private: QTemporaryDir m_temporaryDir; QString m_testSuite; bool m_isUsingCacheProvider; + bool m_hasFreedesktopOrg = false; }; #endif // TST_QMIMEDATABASE_H