File: SHMSegmentTests.cpp

package info (click to toggle)
fastdds 3.1.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 58,132 kB
  • sloc: cpp: 779,516; xml: 15,119; python: 4,356; sh: 190; makefile: 93; ansic: 12
file content (81 lines) | stat: -rw-r--r-- 2,839 bytes parent folder | download
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

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

#include "fastdds/rtps/common/Types.hpp"
#include <fastdds/dds/core/policy/QosPolicies.hpp>
#include <fastdds/rtps/history/WriterHistory.hpp>
#include <fastdds/rtps/participant/RTPSParticipant.hpp>
#include <fastdds/rtps/RTPSDomain.hpp>
#include <fastdds/rtps/writer/RTPSWriter.hpp>

#include <rtps/DataSharing/WriterPool.hpp>
#include <rtps/history/BasicPayloadPool.hpp>
#include <rtps/history/CacheChangePool.h>
#include <rtps/history/PoolConfig.h>

namespace eprosima {
namespace fastdds {
namespace rtps {

using namespace testing;

// This test will attempt to create enable DataSharing while being unable to compute the segment size due to a lack
// of permissions. This should fail but not propagate an uncaught boost::interprocess::interprocess_exception
TEST(SHMSegmentTests, Writer)
{
    RTPSParticipantAttributes p_attr;
    p_attr.builtin.discovery_config.discoveryProtocol = eprosima::fastdds::rtps::DiscoveryProtocol::SIMPLE;
    p_attr.builtin.use_WriterLivelinessProtocol = true;
    RTPSParticipant* participant = RTPSDomain::createParticipant(
        0, p_attr);

    ASSERT_NE(participant, nullptr);

    HistoryAttributes history_attr;
    history_attr.payloadMaxSize = 255;
    history_attr.maximumReservedCaches = 50;

    WriterAttributes writer_attr;
    dds::DataSharingQosPolicy dsq;
    // We select a folder to force the use of SharedFileSegment
    dsq.automatic("tmp");
    writer_attr.endpoint.set_data_sharing_configuration(dsq);

    std::shared_ptr<WriterPool> payload_pool(new WriterPool(history_attr.payloadMaxSize,
            history_attr.maximumReservedCaches));

    WriterHistory* history = new WriterHistory(history_attr, payload_pool);
    RTPSWriter* writer = nullptr;
    EXPECT_NO_THROW(writer = RTPSDomain::createRTPSWriter(participant, writer_attr, history));
    // RTPSWriter creation failed, as expected.
    EXPECT_EQ(writer, nullptr);

    RTPSDomain::removeRTPSParticipant(participant);
    delete(history);
}

} // namespace rtps
} // namespace fastdds
} // namespace eprosima

int main(
        int argc,
        char** argv)
{
    testing::InitGoogleMock(&argc, argv);
    return RUN_ALL_TESTS();
}