~pete-woods/ubuntu-app-launch/port-some-c-to-cpp

« back to all changes in this revision

Viewing changes to tests/libual-cpp-test.cc

  • Committer: Bileto Bot
  • Author(s): Ted Gould
  • Date: 2017-04-04 21:47:13 UTC
  • mfrom: (307.2.33 system-app-watch)
  • Revision ID: ci-train-bot@canonical.com-20170404214713-eyjiw88wlq49ueoe
Watch system folders for apps added and removed (LP: #1630997, #1672392)

Approved by: Marcus Tomlinson, Pete Woods

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
#include "snapd-mock.h"
45
45
#include "spew-master.h"
46
46
#include "systemd-mock.h"
 
47
#include "test-directory.h"
47
48
#include "zg-mock.h"
48
49
 
49
50
#define LOCAL_SNAPD_TEST_SOCKET (SNAPD_TEST_SOCKET "-libual-cpp-test")
1154
1155
    g_spawn_command_line_sync("rm -rf " CMAKE_BINARY_DIR "/libual-proc", NULL, NULL, NULL, NULL);
1155
1156
}
1156
1157
 
 
1158
TEST_F(LibUAL, AppInfoSignals)
 
1159
{
 
1160
    /* Setup the stores mock */
 
1161
    auto mockstore = std::make_shared<MockStore>(registry->impl);
 
1162
    registry =
 
1163
        std::make_shared<RegistryMock>(std::list<std::shared_ptr<ubuntu::app_launch::app_store::Base>>{mockstore},
 
1164
                                       std::shared_ptr<ubuntu::app_launch::jobs::manager::Base>{});
 
1165
 
 
1166
    /* Build an app */
 
1167
    auto singleappid = ubuntu::app_launch::AppID::find(registry, "single");
 
1168
    auto myapp = std::make_shared<MockApp>(singleappid, registry->impl);
 
1169
 
 
1170
    /* Setup an app added signal handler */
 
1171
    std::promise<ubuntu::app_launch::AppID> addedAppId;
 
1172
    ubuntu::app_launch::Registry::appAdded(registry).connect(
 
1173
        [&](const std::shared_ptr<ubuntu::app_launch::Application>& app) { addedAppId.set_value(app->appId()); });
 
1174
 
 
1175
    mockstore->mock_signalAppAdded(myapp);
 
1176
 
 
1177
    EXPECT_EVENTUALLY_FUTURE_EQ(singleappid, addedAppId.get_future());
 
1178
 
 
1179
    /* Setup an info changed signal handler */
 
1180
    std::promise<ubuntu::app_launch::AppID> changedAppId;
 
1181
    ubuntu::app_launch::Registry::appInfoUpdated(registry).connect(
 
1182
        [&](const std::shared_ptr<ubuntu::app_launch::Application>& app) { changedAppId.set_value(app->appId()); });
 
1183
 
 
1184
    mockstore->mock_signalAppInfoChanged(myapp);
 
1185
 
 
1186
    EXPECT_EVENTUALLY_FUTURE_EQ(singleappid, changedAppId.get_future());
 
1187
 
 
1188
    /* Setup an app removed signal handler */
 
1189
    std::promise<ubuntu::app_launch::AppID> removedAppId;
 
1190
    ubuntu::app_launch::Registry::appRemoved(registry).connect(
 
1191
        [&](const ubuntu::app_launch::AppID& appid) { removedAppId.set_value(appid); });
 
1192
 
 
1193
    mockstore->mock_signalAppRemoved(singleappid);
 
1194
 
 
1195
    EXPECT_EVENTUALLY_FUTURE_EQ(singleappid, removedAppId.get_future());
 
1196
}
 
1197
 
1157
1198
TEST_F(LibUAL, OOMSet)
1158
1199
{
1159
1200
    g_setenv("UBUNTU_APP_LAUNCH_OOM_PROC_PATH", CMAKE_BINARY_DIR "/libual-proc", 1);
1277
1318
    });
1278
1319
    t.detach();
1279
1320
 
1280
 
    auto outputfuture = outputpromise.get_future();
1281
 
    while (outputfuture.wait_for(std::chrono::milliseconds{1}) != std::future_status::ready)
1282
 
    {
1283
 
        pause();
1284
 
    }
1285
 
 
1286
 
    ASSERT_STREQ(filedata, outputfuture.get().c_str());
 
1321
    EXPECT_EVENTUALLY_FUTURE_EQ(std::string{filedata}, outputpromise.get_future());
1287
1322
 
1288
1323
    return;
1289
1324
}
1376
1411
    std::vector<std::string> execList{"Foo", "Bar", "Really really really long value", "Another value"};
1377
1412
    ubuntu::app_launch::Helper::setExec(execList);
1378
1413
 
1379
 
    EXPECT_EQ(execList, socketpromise.get_future().get());
 
1414
    EXPECT_EVENTUALLY_FUTURE_EQ(execList, socketpromise.get_future());
1380
1415
}
1381
1416
 
1382
1417
TEST_F(LibUAL, AppInfo)