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

mavlink / MAVSDK / 11944365474

21 Nov 2024 12:43AM UTC coverage: 43.566% (+4.9%) from 38.691%
11944365474

Pull #2386

github

web-flow
Merge 2f8c5b774 into c963c5161
Pull Request #2386: camera: support multiple cameras within one instance

1352 of 2024 new or added lines in 47 files covered. (66.8%)

55 existing lines in 9 files now uncovered.

13857 of 31807 relevant lines covered (43.57%)

291.5 hits per line

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

94.55
/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)
4✔
13
{
14
    Mavsdk mavsdk_groundstation{Mavsdk::Configuration{ComponentType::GroundStation}};
1✔
15

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

18
    ASSERT_EQ(
3✔
19
        mavsdk_groundstation.add_any_connection("udpin://0.0.0.0:17000"),
20
        ConnectionResult::Success);
1✔
21
    ASSERT_EQ(
3✔
22
        mavsdk_camera.add_any_connection("udpout://127.0.0.1:17000"), ConnectionResult::Success);
1✔
23

24
    auto camera_server = CameraServer{mavsdk_camera.server_component()};
2✔
25

26
    CameraServer::Information information{};
1✔
27
    information.vendor_name = "CoolCameras";
1✔
28
    information.model_name = "Frozen Super";
1✔
29
    information.firmware_version = "4.0.0";
1✔
30
    information.definition_file_version = 1;
1✔
31
    information.definition_file_uri = "";
1✔
32
    camera_server.set_information(information);
1✔
33

34
    camera_server.subscribe_take_photo([&camera_server](int32_t index) {
3✔
35
        LogInfo() << "Let's take photo " << index;
1✔
36

37
        CameraServer::CaptureInfo info;
1✔
38
        info.index = index;
1✔
39
        info.is_success = true;
1✔
40

41
        camera_server.respond_take_photo(CameraServer::CameraFeedback::Ok, info);
1✔
42
    });
1✔
43

44
    camera_server.subscribe_set_mode([&](CameraServer::Mode mode) {
1✔
NEW
45
        LogInfo() << "Set mode to " << mode;
×
NEW
46
        camera_server.respond_set_mode(CameraServer::CameraFeedback::Ok);
×
NEW
47
    });
×
48

49
    auto prom = std::promise<std::shared_ptr<System>>();
1✔
50
    auto fut = prom.get_future();
1✔
51
    std::once_flag flag;
1✔
52

53
    auto handle = mavsdk_groundstation.subscribe_on_new_system([&]() {
3✔
54
        const auto system = mavsdk_groundstation.systems().back();
2✔
55
        if (system->is_connected() && system->has_camera()) {
1✔
56
            std::call_once(flag, [&]() { prom.set_value(system); });
2✔
57
        }
58
    });
2✔
59

60
    ASSERT_EQ(fut.wait_for(std::chrono::seconds(10)), std::future_status::ready);
1✔
61
    mavsdk_groundstation.unsubscribe_on_new_system(handle);
1✔
62
    auto system = fut.get();
1✔
63

64
    auto camera = Camera{system};
2✔
65

66
    std::this_thread::sleep_for(std::chrono::milliseconds(500));
1✔
67
    // We expect to find one camera.
68
    ASSERT_EQ(camera.camera_list().cameras.size(), 1);
2✔
69

70
    auto received_captured_info_prom = std::promise<void>{};
1✔
71
    auto received_captured_info_fut = received_captured_info_prom.get_future();
1✔
72

73
    Camera::CaptureInfoHandle capture_handle = camera.subscribe_capture_info(
2✔
74
        [&camera, &received_captured_info_prom, &capture_handle](Camera::CaptureInfo capture_info) {
3✔
75
            LogInfo() << "Received captured info for image: " << capture_info.index;
1✔
76
            // Unsubscribe again to prevent double setting promise.
77
            camera.unsubscribe_capture_info(capture_handle);
1✔
78
            received_captured_info_prom.set_value();
1✔
79
        });
2✔
80

81
    EXPECT_EQ(
2✔
82
        camera.take_photo(camera.camera_list().cameras[0].component_id), Camera::Result::Success);
1✔
83
    ASSERT_EQ(
1✔
84
        received_captured_info_fut.wait_for(std::chrono::seconds(10)), std::future_status::ready);
1✔
85
    received_captured_info_fut.get();
1✔
86

87
    std::this_thread::sleep_for(std::chrono::milliseconds(100));
1✔
88
}
1✔
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