on xenial help sign in
Make method more robust in the face of weird inputs
commite0441d6e71c1a47d6d3a8cf0687a3cf9b6dff1b8 authorMichael Terry <michael.terry@canonical.com> dateFri 30 May 2014, 10:42 (12 years ago) parent5c6b4a7
7 files changed+30−2
plugins/Unity/Launcher/launchermodel.cpp+5−2 tests/CMakeLists.txt+2 tests/data/click/db/test.conf.in+2 tests/data/click/root/.click/users/test-user/com.test.good+1 tests/data/click/root/com.test.good/1.2.3+1 tests/plugins/Unity/Launcher/CMakeLists.txt+1 tests/plugins/Unity/Launcher/launchermodeltest.cpp+18
plugins/Unity/Launcher/launchermodel.cpp+5−2
@@ -202,6 +202,9 @@ QString LauncherModel::getUrlForAppId(const QString &appId) const
202202 QString url;
203203 gchar *longAppId;
204204
205+ if (appId.isEmpty())
206+ return QString();
207+
205208 // assume legacy app until proven otherwise
206209 url = "application:///" + appId + ".desktop";
207210
@@ -210,10 +213,10 @@ QString LauncherModel::getUrlForAppId(const QString &appId) const
210213 QString package = parts.value(0);
211214 QString app = parts.value(1);
212215 longAppId = upstart_app_launch_triplet_to_app_id(package.toLatin1().constData(),
213− app.toLatin1().constData(),
216+ app.isEmpty() ? nullptr : app.toLatin1().constData(),
214217 nullptr);
215218 if (longAppId != nullptr) { // it is a click app!
216− url = "appid://" + parts.join('/') + "/current-user-version";
219+ url = "appid://" + QString(longAppId).replace('_', '/');
217220 g_free(longAppId);
218221 }
219222
tests/CMakeLists.txt+2
@@ -1,3 +1,5 @@
1+configure_file("data/click/db/test.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/data/click/db/test.conf" @ONLY)
2+
13# QML tests that do not require graphical capabilities.
24add_custom_target(qmlunittests)
35
tests/data/click/db/test.conf.innew file+2
@@ -0,0 +1,2 @@
1+[Click Database]
2+root = @CMAKE_SOURCE_DIR@/tests/data/click/root
tests/data/click/root/.click/users/test-user/com.test.goodnew file+1
@@ -0,0 +1 @@
1+../../../com.test.good/1.2.3
tests/data/click/root/com.test.good/1.2.3new file+1
@@ -0,0 +1 @@
1+../../app
tests/plugins/Unity/Launcher/CMakeLists.txt+1
@@ -16,6 +16,7 @@ include_directories(
1616
1717add_definitions(-DSM_BUSNAME=sessionBus)
1818add_definitions(-DSRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
19+add_definitions(-DCMAKE_BINARY_DIR="${CMAKE_BINARY_DIR}")
1920add_definitions(-DLAUNCHER_TESTING)
2021
2122### LauncherBackendTest
tests/plugins/Unity/Launcher/launchermodeltest.cpp+18
@@ -127,6 +127,9 @@ private Q_SLOTS:
127127
128128 appManager->addApplication(new MockApp("no-icon"));
129129 QCOMPARE(launcherModel->rowCount(QModelIndex()), 2);
130+
131+ qputenv("TEST_CLICK_DB", CMAKE_BINARY_DIR "/tests/data/click/db");
132+ qputenv("TEST_CLICK_USER", "test-user");
130133 }
131134
132135 // Removing apps from appmanager and launcher as pinned ones would stick
@@ -137,6 +140,8 @@ private Q_SLOTS:
137140 while (launcherModel->rowCount(QModelIndex()) > 0) {
138141 launcherModel->requestRemove(launcherModel->get(0)->appId());
139142 }
143+ qputenv("TEST_CLICK_DB", "");
144+ qputenv("TEST_CLICK_USER", "");
140145 }
141146
142147 void testMove() {
@@ -274,6 +279,19 @@ private Q_SLOTS:
274279 QCOMPARE(launcherModel->rowCount(QModelIndex()), 1);
275280 QCOMPARE(launcherModel->get(0)->appId(), QLatin1String("abs-icon"));
276281 }
282+
283+ void testGetUrlForAppId() {
284+ QCOMPARE(launcherModel->getUrlForAppId(QString()), QString());
285+ QCOMPARE(launcherModel->getUrlForAppId(""), QString());
286+ QCOMPARE(launcherModel->getUrlForAppId("not-an-app"), QString("application:///not-an-app.desktop"));
287+ QCOMPARE(launcherModel->getUrlForAppId("not_an_app"), QString("application:///not_an_app.desktop"));
288+ QCOMPARE(launcherModel->getUrlForAppId("notes-app"), QString("application:///notes-app.desktop"));
289+ QCOMPARE(launcherModel->getUrlForAppId("com.test.good"), QString("appid://com.test.good/application/1.2.3"));
290+ QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application"), QString("appid://com.test.good/application/1.2.3"));
291+ // Note that this version change is intentional -- we want to fix old links to use latest current version
292+ QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application_0.0.0"), QString("appid://com.test.good/application/1.2.3"));
293+ QCOMPARE(launcherModel->getUrlForAppId("com.test.good_application_1.2.3"), QString("appid://com.test.good/application/1.2.3"));
294+ }
277295};
278296
279297QTEST_GUILESS_MAIN(LauncherModelTest)