File indexing completed on 2022-11-29 18:25:15

0001 /*  This file is part of the KDE project
0002     Copyright (C) 2011 David Faure <faure@kde.org>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Library General Public
0006     License as published by the Free Software Foundation; either
0007     version 2 of the License, or (at your option) any later version.
0008 
0009     This library is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012     Library General Public License for more details.
0013 
0014     You should have received a copy of the GNU Library General Public License
0015     along with this library; see the file COPYING.LIB.  If not, write to
0016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017     Boston, MA 02110-1301, USA.
0018 
0019 */
0020 
0021 #include <QCoreApplication>
0022 #include <QtGlobal>
0023 #include <QUrl>
0024 #include <kcomponentdata.h>
0025 #include <kmimetype.h>
0026 #include <kmessage.h>
0027 #include <kdebug.h>
0028 
0029 class KTestMessageHandler : public KMessageHandler
0030 {
0031 public:
0032     void message(KMessage::MessageType type, const QString &text, const QString &caption) override
0033     {
0034         Q_UNUSED(type);
0035         Q_UNUSED(caption);
0036         m_messages.append(text);
0037     }
0038 
0039     QStringList m_messages;
0040 };
0041 
0042 int main(int argc, char **argv)
0043 {
0044     QCoreApplication app(argc, argv);
0045 
0046     // Test what happens when there are no mimetypes installed.
0047 
0048     qputenv("XDG_DATA_DIRS", "/doesnotexist");
0049 
0050     KComponentData cData("foo");
0051 
0052     KTestMessageHandler *msgHandler = new KTestMessageHandler;
0053     KMessage::setMessageHandler(msgHandler);
0054 
0055     KMimeType::Ptr s0 = KMimeType::mimeType("application/x-zerosize");
0056     Q_ASSERT(s0); // QMimeType falls back to its own copy freedesktop.org.xml, so this works!
0057     if (!s0) {
0058         abort();
0059         return 1;
0060     }
0061 
0062     KMimeType::Ptr mime = KMimeType::findByUrl(QUrl::fromLocalFile("/"));
0063     Q_ASSERT(mime);
0064     Q_ASSERT(mime->name() == "inode/directory");
0065     if (!mime) {
0066         abort();
0067         return 2;
0068     }
0069 
0070     Q_ASSERT(msgHandler->m_messages.count() == 0);
0071 
0072     return 0;
0073 }
0074