• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mavlink / MAVSDK / 7305109977

23 Dec 2023 12:47AM UTC coverage: 36.89% (-0.2%) from 37.119%
7305109977

push

github

web-flow
Merge pull request #2197 from mavlink/pr-remove-default-ctor

Require configuration for Mavsdk ctor

116 of 122 new or added lines in 20 files covered. (95.08%)

6 existing lines in 2 files now uncovered.

9975 of 27040 relevant lines covered (36.89%)

130.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

61.29
/src/system_tests/camera_take_photo.cpp
1
#include "mavsdk.h"
2
#include "plugins/camera/camera.h"
3
#include "plugins/camera_server/camera_server.h"
4
#include "log.h"
5
#include <future>
6
#include <mutex>
7
#include <thread>
8
#include <gtest/gtest.h>
9

10
using namespace mavsdk;
11

12
TEST(SystemTest, CameraTakePhoto)
1✔
13
{
14
    Mavsdk mavsdk_groundstation{Mavsdk::Configuration{Mavsdk::ComponentType::GroundStation}};
1✔
15

16
    Mavsdk mavsdk_camera{Mavsdk::Configuration{Mavsdk::ComponentType::Camera}};
1✔
17

18
    ASSERT_EQ(mavsdk_groundstation.add_any_connection("udp://:17000"), ConnectionResult::Success);
3✔
19
    ASSERT_EQ(mavsdk_camera.add_any_connection("udp://127.0.0.1:17000"), ConnectionResult::Success);
3✔
20

21
    auto camera_server = CameraServer{mavsdk_camera.server_component()};
2✔
UNCOV
22
    camera_server.subscribe_take_photo([&camera_server](int32_t index) {
×
23
        LogInfo() << "Let's take photo " << index;
×
24

25
        CameraServer::CaptureInfo info;
×
26
        info.index = index;
×
27
        info.is_success = true;
×
28

29
        camera_server.respond_take_photo(CameraServer::TakePhotoFeedback::Ok, info);
×
30
    });
×
31

32
    auto prom = std::promise<std::shared_ptr<System>>();
1✔
33
    auto fut = prom.get_future();
1✔
34
    std::once_flag flag;
1✔
35

36
    auto handle = mavsdk_groundstation.subscribe_on_new_system([&]() {
1✔
37
        const auto system = mavsdk_groundstation.systems().back();
3✔
38
        if (system->is_connected() && system->has_camera()) {
1✔
39
            std::call_once(flag, [&]() { prom.set_value(system); });
2✔
40
        }
41
    });
1✔
42

43
    ASSERT_EQ(fut.wait_for(std::chrono::seconds(10)), std::future_status::ready);
1✔
44
    mavsdk_groundstation.unsubscribe_on_new_system(handle);
1✔
45
    auto system = fut.get();
1✔
46

47
    auto camera = Camera{system};
2✔
48
    return;
1✔
49

50
    // We want to take the picture in photo mode.
51
    // EXPECT_EQ(camera.set_mode(Camera::Mode::Photo), Camera::Result::Success);
52

53
    auto received_captured_info_prom = std::promise<void>{};
54
    auto received_captured_info_fut = received_captured_info_prom.get_future();
55

56
    Camera::CaptureInfoHandle capture_handle = camera.subscribe_capture_info(
57
        [&camera, &received_captured_info_prom, &capture_handle](Camera::CaptureInfo capture_info) {
×
58
            LogInfo() << "Received captured info for image: " << capture_info.index;
×
59
            // Unsubscribe again to prevent double setting promise.
60
            camera.unsubscribe_capture_info(capture_handle);
×
61
            received_captured_info_prom.set_value();
×
62
        });
×
63

64
    EXPECT_EQ(camera.take_photo(), Camera::Result::Success);
65
    ASSERT_EQ(
66
        received_captured_info_fut.wait_for(std::chrono::seconds(10)), std::future_status::ready);
67
    received_captured_info_fut.get();
68

69
    std::this_thread::sleep_for(std::chrono::milliseconds(100));
70
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc