~ci-train-bot/ubuntu-app-launch/ubuntu-app-launch-ubuntu-zesty-2105

« back to all changes in this revision

Viewing changes to tests/list-apps.cpp

  • Committer: Bileto Bot
  • Author(s): Ted Gould
  • Date: 2017-02-02 15:09:43 UTC
  • mfrom: (274.1.9 snap-select-u8)
  • Revision ID: ci-train-bot@canonical.com-20170202150943-184nho6mo20cg2bs
Prioritize 'unity8' interfaces over other supported interfaces

Approved by: Charles Kerr

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
    bool findApp(const std::list<std::shared_ptr<ubuntu::app_launch::Application>>& apps,
98
98
                 const ubuntu::app_launch::AppID& appId)
99
99
    {
 
100
        try
 
101
        {
 
102
            getApp(apps, appId);
 
103
            return true;
 
104
        }
 
105
        catch (std::runtime_error& e)
 
106
        {
 
107
            return false;
 
108
        }
 
109
    }
 
110
 
 
111
    std::shared_ptr<ubuntu::app_launch::Application> getApp(
 
112
        const std::list<std::shared_ptr<ubuntu::app_launch::Application>>& apps, const std::string& appid)
 
113
    {
 
114
        return getApp(apps, ubuntu::app_launch::AppID::parse(appid));
 
115
    }
 
116
 
 
117
    std::shared_ptr<ubuntu::app_launch::Application> getApp(
 
118
        const std::list<std::shared_ptr<ubuntu::app_launch::Application>>& apps, const ubuntu::app_launch::AppID& appId)
 
119
    {
100
120
        for (auto app : apps)
101
121
        {
102
122
            if (app->appId() == appId)
103
123
            {
104
 
                return true;
 
124
                return app;
105
125
            }
106
126
        }
107
127
 
108
 
        return false;
 
128
        throw std::runtime_error{"Unable to find app: " + std::string{appId}};
109
129
    }
110
130
 
111
131
    void printApps(const std::list<std::shared_ptr<ubuntu::app_launch::Application>>& apps)
185
205
    "GET /v2/interfaces HTTP/1.1\r\nHost: snapd\r\nAccept: */*\r\n\r\n",
186
206
    SnapdMock::httpJsonResponse(
187
207
        SnapdMock::snapdOkay(SnapdMock::interfacesJson({{"unity8", "unity8-package", {"foo", "bar"}},
 
208
                                                        {"unity7", "unity8-package", {"foo"}},
188
209
                                                        {"unity7", "unity7-package", {"single", "multiple"}},
189
210
                                                        {"x11", "x11-package", {"multiple", "hidden"}}
190
211
 
205
226
TEST_F(ListApps, ListSnap)
206
227
{
207
228
    SnapdMock mock{SNAPD_LIST_APPS_SOCKET,
208
 
                   {interfaces, u7Package, u7Package, u7Package,      /* unity7 check */
209
 
                    interfaces, u8Package, u8Package, u8Package,      /* unity8 check */
210
 
                    interfaces, x11Package, x11Package, x11Package}}; /* x11 check */
 
229
                   {interfaces, u8Package, u8Package, u8Package,                       /* unity8 check */
 
230
                    interfaces, u8Package, u7Package, u7Package, u7Package, u8Package, /* unity7 check */
 
231
                    interfaces, x11Package, x11Package, x11Package}};                  /* x11 check */
211
232
    auto registry = std::make_shared<ubuntu::app_launch::Registry>();
212
233
 
213
234
    auto apps = ubuntu::app_launch::app_impls::Snap::list(registry);
225
246
    EXPECT_FALSE(findApp(apps, "unity8-package_bar_x123"));
226
247
    EXPECT_FALSE(findApp(apps, "unity7-package_scope_x123"));
227
248
    EXPECT_FALSE(findApp(apps, "x11-package_hidden_x123"));
 
249
 
 
250
    EXPECT_EQ("unity8",
 
251
              std::dynamic_pointer_cast<ubuntu::app_launch::app_impls::Snap>(getApp(apps, "unity8-package_foo_x123"))
 
252
                  ->getInterface());
 
253
    EXPECT_EQ("unity7",
 
254
              std::dynamic_pointer_cast<ubuntu::app_launch::app_impls::Snap>(getApp(apps, "unity7-package_single_x123"))
 
255
                  ->getInterface());
 
256
    EXPECT_EQ("unity7", std::dynamic_pointer_cast<ubuntu::app_launch::app_impls::Snap>(
 
257
                            getApp(apps, "unity7-package_multiple_x123"))
 
258
                            ->getInterface());
 
259
    EXPECT_EQ("x11",
 
260
              std::dynamic_pointer_cast<ubuntu::app_launch::app_impls::Snap>(getApp(apps, "x11-package_multiple_x123"))
 
261
                  ->getInterface());
228
262
}
229
263
#endif
230
264
 
232
266
{
233
267
#ifdef ENABLE_SNAPPY
234
268
    SnapdMock mock{SNAPD_LIST_APPS_SOCKET,
235
 
                   {interfaces, u7Package, u7Package, u7Package,      /* unity7 check */
236
 
                    interfaces, u8Package, u8Package, u8Package,      /* unity8 check */
237
 
                    interfaces, x11Package, x11Package, x11Package}}; /* x11 check */
 
269
                   {interfaces, u8Package, u8Package, u8Package,                       /* unity8 check */
 
270
                    interfaces, u8Package, u7Package, u7Package, u7Package, u8Package, /* unity7 check */
 
271
                    interfaces, x11Package, x11Package, x11Package}};                  /* x11 check */
238
272
#endif
239
273
    auto registry = std::make_shared<ubuntu::app_launch::Registry>();
240
274