Changeset View
Changeset View
Standalone View
Standalone View
autotests/applicationlauncherjobtest.cpp
Show First 20 Lines • Show All 150 Lines • ▼ Show 20 Line(s) | 137 | { | |||
---|---|---|---|---|---|
151 | QVERIFY(!job->exec()); | 151 | QVERIFY(!job->exec()); | ||
152 | QCOMPARE(job->error(), KJob::UserDefinedError); | 152 | QCOMPARE(job->error(), KJob::UserDefinedError); | ||
153 | QCOMPARE(job->errorString(), QStringLiteral("You are not authorized to execute this file.")); | 153 | QCOMPARE(job->errorString(), QStringLiteral("You are not authorized to execute this file.")); | ||
154 | } | 154 | } | ||
155 | 155 | | |||
156 | void ApplicationLauncherJobTest::shouldFailOnNonExistingExecutable_data() | 156 | void ApplicationLauncherJobTest::shouldFailOnNonExistingExecutable_data() | ||
157 | { | 157 | { | ||
158 | QTest::addColumn<bool>("tempFile"); | 158 | QTest::addColumn<bool>("tempFile"); | ||
159 | QTest::addColumn<bool>("fullPath"); | ||||
159 | 160 | | |||
160 | QTest::newRow("file") << false; | 161 | QTest::newRow("file") << false << false; | ||
161 | QTest::newRow("tempFile") << true; | 162 | QTest::newRow("tempFile") << true << false; | ||
163 | QTest::newRow("file_fullPath") << false << true; | ||||
164 | QTest::newRow("tempFile_fullPath") << true << true; | ||||
162 | } | 165 | } | ||
163 | 166 | | |||
164 | void ApplicationLauncherJobTest::shouldFailOnNonExistingExecutable() | 167 | void ApplicationLauncherJobTest::shouldFailOnNonExistingExecutable() | ||
165 | { | 168 | { | ||
166 | QFETCH(bool, tempFile); | 169 | QFETCH(bool, tempFile); | ||
170 | QFETCH(bool, fullPath); | ||||
167 | 171 | | |||
168 | const QString desktopFilePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kservices5/non_existing_executable.desktop"); | 172 | const QString desktopFilePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/kservices5/non_existing_executable.desktop"); | ||
169 | KDesktopFile file(desktopFilePath); | 173 | KDesktopFile file(desktopFilePath); | ||
170 | KConfigGroup group = file.desktopGroup(); | 174 | KConfigGroup group = file.desktopGroup(); | ||
171 | group.writeEntry("Name", "KRunUnittestService"); | 175 | group.writeEntry("Name", "KRunUnittestService"); | ||
172 | group.writeEntry("Type", "Service"); | 176 | group.writeEntry("Type", "Service"); | ||
177 | if (fullPath) { | ||||
178 | group.writeEntry("Exec", "/usr/bin/does_not_exist %f %d/dest_%n"); | ||||
179 | } else { | ||||
173 | group.writeEntry("Exec", "does_not_exist %f %d/dest_%n"); | 180 | group.writeEntry("Exec", "does_not_exist %f %d/dest_%n"); | ||
181 | } | ||||
174 | file.sync(); | 182 | file.sync(); | ||
175 | 183 | | |||
176 | KService::Ptr servicePtr(new KService(desktopFilePath)); | 184 | KService::Ptr servicePtr(new KService(desktopFilePath)); | ||
177 | KIO::ApplicationLauncherJob *job = new KIO::ApplicationLauncherJob(servicePtr, this); | 185 | KIO::ApplicationLauncherJob *job = new KIO::ApplicationLauncherJob(servicePtr, this); | ||
178 | job->setUrls({QUrl::fromLocalFile(desktopFilePath)}); // just to have one URL as argument, as the desktop file expects | 186 | job->setUrls({QUrl::fromLocalFile(desktopFilePath)}); // just to have one URL as argument, as the desktop file expects | ||
179 | if (tempFile) { | 187 | if (tempFile) { | ||
180 | job->setRunFlags(KIO::ApplicationLauncherJob::DeleteTemporaryFiles); | 188 | job->setRunFlags(KIO::ApplicationLauncherJob::DeleteTemporaryFiles); | ||
181 | } | 189 | } | ||
182 | QVERIFY(!job->exec()); | 190 | QVERIFY(!job->exec()); | ||
183 | QCOMPARE(job->error(), KJob::UserDefinedError); | 191 | QCOMPARE(job->error(), KJob::UserDefinedError); | ||
192 | if (fullPath) { | ||||
193 | QCOMPARE(job->errorString(), QStringLiteral("Could not find the program '/usr/bin/does_not_exist'")); | ||||
194 | } else { | ||||
184 | QCOMPARE(job->errorString(), QStringLiteral("Could not find the program 'does_not_exist'")); | 195 | QCOMPARE(job->errorString(), QStringLiteral("Could not find the program 'does_not_exist'")); | ||
185 | 196 | } | |||
186 | QFile::remove(desktopFilePath); | 197 | QFile::remove(desktopFilePath); | ||
187 | } | 198 | } | ||
188 | 199 | | |||
189 | void ApplicationLauncherJobTest::writeTempServiceDesktopFile(const QString &filePath) | 200 | void ApplicationLauncherJobTest::writeTempServiceDesktopFile(const QString &filePath) | ||
190 | { | 201 | { | ||
191 | if (!QFile::exists(filePath)) { | 202 | if (!QFile::exists(filePath)) { | ||
192 | KDesktopFile file(filePath); | 203 | KDesktopFile file(filePath); | ||
193 | KConfigGroup group = file.desktopGroup(); | 204 | KConfigGroup group = file.desktopGroup(); | ||
Show All 19 Lines |