summaryrefslogtreecommitdiff
path: root/test/network_tests/application_tests/application_test_daemon.cpp
blob: 2f0b24409b3b7fbe274747723170c86ac3a27017 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (C) 2014-2017 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <gtest/gtest.h>
#include <future>

#include <vsomeip/vsomeip.hpp>
#include <vsomeip/internal/logger.hpp>

class application_test_daemon {
public:
    application_test_daemon() :
            app_(vsomeip::runtime::get()->create_application("daemon")) {
        if (!app_->init()) {
            ADD_FAILURE() << "Couldn't initialize application";
            return;
        }
        std::promise<bool> its_promise;
        application_thread_ = std::thread([&](){
            its_promise.set_value(true);
            app_->start();
        });
        EXPECT_TRUE(its_promise.get_future().get());
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
        VSOMEIP_INFO << "Daemon starting";
    }

    ~application_test_daemon() {
        application_thread_.join();
    }

    void stop() {
        VSOMEIP_INFO << "Daemon stopping";
        app_->stop();
    }

private:
    std::shared_ptr<vsomeip::application> app_;
    std::thread application_thread_;
};