~ubuntu-branches/ubuntu/utopic/ubuntu-app-launch/utopic

« back to all changes in this revision

Viewing changes to tests/libual-test.cc

  • Committer: Package Import Robot
  • Author(s): Łukasz 'sil2100' Zemczak
  • Date: 2014-08-19 09:52:33 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20140819095233-5mvkp2nderj92rww
Tags: 0.4+14.10.20140808.3.is.0.4+14.10.20140605.3-0ubuntu1
Temporarily revert the cgroup support introduced in the last
version, as it was causing regressions in our test infrastructure

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
        protected:
31
31
                DbusTestService * service = NULL;
32
32
                DbusTestDbusMock * mock = NULL;
33
 
                DbusTestDbusMock * cgmock = NULL;
34
33
                GDBusConnection * bus = NULL;
35
34
                std::string last_focus_appid;
36
35
                std::string last_resume_appid;
216
215
                                g_variant_new_string("untrusted-type:24034582324132:com.bar_foo_8432.13.1"),
217
216
                                NULL);
218
217
 
219
 
                        /* Create the cgroup manager mock */
220
 
                        cgmock = dbus_test_dbus_mock_new("org.test.cgmock");
221
 
                        g_setenv("UBUNTU_APP_LAUNCH_CG_MANAGER_NAME", "org.test.cgmock", TRUE);
222
 
 
223
 
                        DbusTestDbusMockObject * cgobject = dbus_test_dbus_mock_get_object(cgmock, "/org/linuxcontainers/cgmanager", "org.linuxcontainers.cgmanager0_0", NULL);
224
 
                        dbus_test_dbus_mock_object_add_method(cgmock, cgobject,
225
 
                                "GetTasks",
226
 
                                G_VARIANT_TYPE("(ss)"),
227
 
                                G_VARIANT_TYPE("ai"),
228
 
                                "ret = [100, 200, 300]",
229
 
                                NULL);
230
 
 
231
218
                        /* Put it together */
232
219
                        dbus_test_service_add_task(service, DBUS_TEST_TASK(mock));
233
 
                        dbus_test_service_add_task(service, DBUS_TEST_TASK(cgmock));
234
220
                        dbus_test_service_start_tasks(service);
235
221
 
236
222
                        bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
237
223
                        g_dbus_connection_set_exit_on_close(bus, FALSE);
238
224
                        g_object_add_weak_pointer(G_OBJECT(bus), (gpointer *)&bus);
239
225
 
240
 
                        /* Make sure we pretend the CG manager is just on our bus */
241
 
                        g_setenv("UBUNTU_APP_LAUNCH_CG_MANAGER_SESSION_BUS", "YES", TRUE);
242
 
 
243
226
                        ASSERT_TRUE(ubuntu_app_launch_observer_add_app_focus(focus_cb, this));
244
227
                        ASSERT_TRUE(ubuntu_app_launch_observer_add_app_resume(resume_cb, this));
245
228
                }
249
232
                        ubuntu_app_launch_observer_delete_app_resume(resume_cb, this);
250
233
 
251
234
                        g_clear_object(&mock);
252
 
                        g_clear_object(&cgmock);
253
235
                        g_clear_object(&service);
254
236
 
255
237
                        g_object_unref(bus);
421
403
 
422
404
TEST_F(LibUAL, ApplicationPid)
423
405
{
424
 
        /* Check bad params */
425
 
        EXPECT_EQ(0, ubuntu_app_launch_get_primary_pid(NULL));
426
 
        EXPECT_FALSE(ubuntu_app_launch_pid_in_app_id(0, "foo"));
427
 
        EXPECT_FALSE(ubuntu_app_launch_pid_in_app_id(100, NULL));
428
 
 
429
 
        /* Check primary pid, which comes from Upstart */
430
406
        EXPECT_EQ(ubuntu_app_launch_get_primary_pid("foo"), getpid());
431
407
        EXPECT_EQ(ubuntu_app_launch_get_primary_pid("bar"), 5678);
432
 
 
433
 
        /* Look at the full PID list from CG Manager */
434
 
        DbusTestDbusMockObject * cgobject = dbus_test_dbus_mock_get_object(cgmock, "/org/linuxcontainers/cgmanager", "org.linuxcontainers.cgmanager0_0", NULL);
435
 
        const DbusTestDbusMockCall * calls = NULL;
436
 
        guint len = 0;
437
 
 
438
 
        /* Click in the set */
439
 
        EXPECT_TRUE(ubuntu_app_launch_pid_in_app_id(100, "foo"));
440
 
        calls = dbus_test_dbus_mock_object_get_method_calls(cgmock, cgobject, "GetTasks", &len, NULL);
441
 
        EXPECT_EQ(1, len);
442
 
        EXPECT_STREQ("GetTasks", calls->name);
443
 
        EXPECT_TRUE(g_variant_equal(calls->params, g_variant_new("(ss)", "freezer", "upstart/application-click-foo")));
444
 
        ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(cgmock, cgobject, NULL));
445
 
 
446
 
        /* Click out of the set */
447
 
        EXPECT_FALSE(ubuntu_app_launch_pid_in_app_id(101, "foo"));
448
 
        calls = dbus_test_dbus_mock_object_get_method_calls(cgmock, cgobject, "GetTasks", &len, NULL);
449
 
        EXPECT_EQ(1, len);
450
 
        EXPECT_STREQ("GetTasks", calls->name);
451
 
        EXPECT_TRUE(g_variant_equal(calls->params, g_variant_new("(ss)", "freezer", "upstart/application-click-foo")));
452
 
        ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(cgmock, cgobject, NULL));
453
 
 
454
 
        /* Legacy Single Instance */
455
 
        EXPECT_TRUE(ubuntu_app_launch_pid_in_app_id(100, "single"));
456
 
        calls = dbus_test_dbus_mock_object_get_method_calls(cgmock, cgobject, "GetTasks", &len, NULL);
457
 
        EXPECT_EQ(1, len);
458
 
        EXPECT_STREQ("GetTasks", calls->name);
459
 
        EXPECT_TRUE(g_variant_equal(calls->params, g_variant_new("(ss)", "freezer", "upstart/application-legacy-single-")));
460
 
        ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(cgmock, cgobject, NULL));
461
 
 
462
 
        /* Legacy Multi Instance */
463
 
        EXPECT_TRUE(ubuntu_app_launch_pid_in_app_id(100, "bar"));
464
 
        calls = dbus_test_dbus_mock_object_get_method_calls(cgmock, cgobject, "GetTasks", &len, NULL);
465
 
        EXPECT_EQ(1, len);
466
 
        EXPECT_STREQ("GetTasks", calls->name);
467
 
        EXPECT_TRUE(g_variant_equal(calls->params, g_variant_new("(ss)", "freezer", "upstart/application-legacy-bar-2342345")));
468
 
        ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(cgmock, cgobject, NULL));
469
 
 
 
408
        EXPECT_TRUE(ubuntu_app_launch_pid_in_app_id(getpid(), "foo"));
 
409
        EXPECT_FALSE(ubuntu_app_launch_pid_in_app_id(5678, "foo"));
470
410
}
471
411
 
472
412
TEST_F(LibUAL, ApplicationId)