| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). |
| 4 |
** All rights reserved. |
| 5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
| 6 |
** |
| 7 |
** This file is part of the test suite of the Qt Toolkit. |
| 8 |
** |
| 9 |
** $QT_BEGIN_LICENSE:LGPL$ |
| 10 |
** GNU Lesser General Public License Usage |
| 11 |
** This file may be used under the terms of the GNU Lesser General Public |
| 12 |
** License version 2.1 as published by the Free Software Foundation and |
| 13 |
** appearing in the file LICENSE.LGPL included in the packaging of this |
| 14 |
** file. Please review the following information to ensure the GNU Lesser |
| 15 |
** General Public License version 2.1 requirements will be met: |
| 16 |
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 17 |
** |
| 18 |
** In addition, as a special exception, Nokia gives you certain additional |
| 19 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
| 20 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 21 |
** |
| 22 |
** GNU General Public License Usage |
| 23 |
** Alternatively, this file may be used under the terms of the GNU General |
| 24 |
** Public License version 3.0 as published by the Free Software Foundation |
| 25 |
** and appearing in the file LICENSE.GPL included in the packaging of this |
| 26 |
** file. Please review the following information to ensure the GNU General |
| 27 |
** Public License version 3.0 requirements will be met: |
| 28 |
** http://www.gnu.org/copyleft/gpl.html. |
| 29 |
** |
| 30 |
** Other Usage |
| 31 |
** Alternatively, this file may be used in accordance with the terms and |
| 32 |
** conditions contained in a signed written agreement between you and Nokia. |
| 33 |
** |
| 34 |
** |
| 35 |
** |
| 36 |
** |
| 37 |
** |
| 38 |
** $QT_END_LICENSE$ |
| 39 |
** |
| 40 |
****************************************************************************/ |
| 41 |
|
| 42 |
|
| 43 |
#include <QtTest/QtTest> |
| 44 |
#include <QtCore/QDir> |
| 45 |
#include <QtCore/QFile> |
| 46 |
#include <QtCore/QProcess> |
| 47 |
|
| 48 |
class tst_MacPlist : public QObject |
| 49 |
{ |
| 50 |
Q_OBJECT |
| 51 |
public: |
| 52 |
tst_MacPlist() {} |
| 53 |
|
| 54 |
private slots: |
| 55 |
#ifdef Q_OS_MAC |
| 56 |
void test_plist_data(); |
| 57 |
void test_plist(); |
| 58 |
#endif |
| 59 |
}; |
| 60 |
|
| 61 |
#ifdef Q_OS_MAC |
| 62 |
void tst_MacPlist::test_plist_data() |
| 63 |
{ |
| 64 |
QTest::addColumn<QString>("test_plist"); |
| 65 |
|
| 66 |
QTest::newRow("control") << QString::fromLatin1( |
| 67 |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 68 |
"<!DOCTYPE plist SYSTEM \"file://localhost/System/Library/DTDs/PropertyList.dtd\">\n" |
| 69 |
"<plist version=\"0.9\">\n" |
| 70 |
"<dict>\n" |
| 71 |
" <key>CFBundleIconFile</key>\n" |
| 72 |
" <string></string>\n" |
| 73 |
" <key>CFBundlePackageType</key>\n" |
| 74 |
" <string>APPL</string>\n" |
| 75 |
" <key>CFBundleGetInfoString</key>\n" |
| 76 |
" <string>Created by Qt/QMake</string>\n" |
| 77 |
" <key>CFBundleExecutable</key>\n" |
| 78 |
" <string>app</string>\n" |
| 79 |
" <key>CFBundleIdentifier</key>\n" |
| 80 |
" <string>com.yourcompany.app</string>\n" |
| 81 |
"</dict>\n" |
| 82 |
"</plist>\n"); |
| 83 |
|
| 84 |
QTest::newRow("LSUIElement-as-string") << QString::fromLatin1( |
| 85 |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 86 |
"<!DOCTYPE plist SYSTEM \"file://localhost/System/Library/DTDs/PropertyList.dtd\">\n" |
| 87 |
"<plist version=\"0.9\">\n" |
| 88 |
"<dict>\n" |
| 89 |
" <key>CFBundleIconFile</key>\n" |
| 90 |
" <string></string>\n" |
| 91 |
" <key>CFBundlePackageType</key>\n" |
| 92 |
" <string>APPL</string>\n" |
| 93 |
" <key>CFBundleGetInfoString</key>\n" |
| 94 |
" <string>Created by Qt/QMake</string>\n" |
| 95 |
" <key>CFBundleExecutable</key>\n" |
| 96 |
" <string>app</string>\n" |
| 97 |
" <key>CFBundleIdentifier</key>\n" |
| 98 |
" <string>com.yourcompany.app</string>\n" |
| 99 |
" <key>LSUIElement</key>\n" |
| 100 |
" <string>false</string>\n" |
| 101 |
"</dict>\n" |
| 102 |
"</plist>\n"); |
| 103 |
|
| 104 |
QTest::newRow("LSUIElement-as-bool") << QString::fromLatin1( |
| 105 |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 106 |
"<!DOCTYPE plist SYSTEM \"file://localhost/System/Library/DTDs/PropertyList.dtd\">\n" |
| 107 |
"<plist version=\"0.9\">\n" |
| 108 |
"<dict>\n" |
| 109 |
" <key>CFBundleIconFile</key>\n" |
| 110 |
" <string></string>\n" |
| 111 |
" <key>CFBundlePackageType</key>\n" |
| 112 |
" <string>APPL</string>\n" |
| 113 |
" <key>CFBundleGetInfoString</key>\n" |
| 114 |
" <string>Created by Qt/QMake</string>\n" |
| 115 |
" <key>CFBundleExecutable</key>\n" |
| 116 |
" <string>app</string>\n" |
| 117 |
" <key>CFBundleIdentifier</key>\n" |
| 118 |
" <string>com.yourcompany.app</string>\n" |
| 119 |
" <key>LSUIElement</key>\n" |
| 120 |
" <false/>\n" |
| 121 |
"</dict>\n" |
| 122 |
"</plist>\n"); |
| 123 |
|
| 124 |
QTest::newRow("LSUIElement-as-int") << QString::fromLatin1( |
| 125 |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 126 |
"<!DOCTYPE plist SYSTEM \"file://localhost/System/Library/DTDs/PropertyList.dtd\">\n" |
| 127 |
"<plist version=\"0.9\">\n" |
| 128 |
"<dict>\n" |
| 129 |
" <key>CFBundleIconFile</key>\n" |
| 130 |
" <string></string>\n" |
| 131 |
" <key>CFBundlePackageType</key>\n" |
| 132 |
" <string>APPL</string>\n" |
| 133 |
" <key>CFBundleGetInfoString</key>\n" |
| 134 |
" <string>Created by Qt/QMake</string>\n" |
| 135 |
" <key>CFBundleExecutable</key>\n" |
| 136 |
" <string>app</string>\n" |
| 137 |
" <key>CFBundleIdentifier</key>\n" |
| 138 |
" <string>com.yourcompany.app</string>\n" |
| 139 |
" <key>LSUIElement</key>\n" |
| 140 |
" <real>0</real>\n" |
| 141 |
"</dict>\n" |
| 142 |
"</plist>\n"); |
| 143 |
|
| 144 |
QTest::newRow("LSUIElement-as-garbage") << QString::fromLatin1( |
| 145 |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 146 |
"<!DOCTYPE plist SYSTEM \"file://localhost/System/Library/DTDs/PropertyList.dtd\">\n" |
| 147 |
"<plist version=\"0.9\">\n" |
| 148 |
"<dict>\n" |
| 149 |
" <key>CFBundleIconFile</key>\n" |
| 150 |
" <string></string>\n" |
| 151 |
" <key>CFBundlePackageType</key>\n" |
| 152 |
" <string>APPL</string>\n" |
| 153 |
" <key>CFBundleGetInfoString</key>\n" |
| 154 |
" <string>Created by Qt/QMake</string>\n" |
| 155 |
" <key>CFBundleExecutable</key>\n" |
| 156 |
" <string>app</string>\n" |
| 157 |
" <key>CFBundleIdentifier</key>\n" |
| 158 |
" <string>com.yourcompany.app</string>\n" |
| 159 |
" <key>LSUIElement</key>\n" |
| 160 |
" <badkey>0</badkey>\n" |
| 161 |
"</dict>\n" |
| 162 |
"</plist>\n"); |
| 163 |
} |
| 164 |
|
| 165 |
void tst_MacPlist::test_plist() |
| 166 |
{ |
| 167 |
QFETCH(QString, test_plist); |
| 168 |
|
| 169 |
QString infoPlist = QLatin1String("Info.plist"); |
| 170 |
QDir dir(QCoreApplication::applicationDirPath()); |
| 171 |
QVERIFY(dir.cdUp()); |
| 172 |
QVERIFY(dir.cdUp()); |
| 173 |
QVERIFY(dir.cdUp()); |
| 174 |
QVERIFY(dir.cd(QLatin1String("app"))); |
| 175 |
QVERIFY(dir.cd(QLatin1String("app.app"))); |
| 176 |
QVERIFY(dir.cd(QLatin1String("Contents"))); |
| 177 |
QVERIFY(dir.exists(infoPlist)); |
| 178 |
{ |
| 179 |
QFile file(dir.filePath(infoPlist)); |
| 180 |
QVERIFY(file.open(QIODevice::WriteOnly)); |
| 181 |
QByteArray ba = test_plist.toUtf8(); |
| 182 |
QCOMPARE(file.write(ba), qint64(ba.size())); |
| 183 |
} |
| 184 |
QVERIFY(dir.cd(QLatin1String("MacOS"))); |
| 185 |
QVERIFY(dir.exists(QLatin1String("app"))); |
| 186 |
QProcess process; |
| 187 |
process.start(dir.filePath("app")); |
| 188 |
QCOMPARE(process.waitForFinished(), true); |
| 189 |
QCOMPARE(process.exitStatus(), QProcess::NormalExit); |
| 190 |
} |
| 191 |
#endif |
| 192 |
|
| 193 |
QTEST_MAIN(tst_MacPlist) |
| 194 |
#include "tst_macplist.moc" |