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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
//
// 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.
//
// SPDX-License-Identifier: Apache-2.0
#include "iceoryx_dds/Mempool.hpp"
#include "iceoryx_dds/dds/cyclone_data_reader.hpp"
#include "iceoryx_posh/testing/mocks/chunk_mock.hpp"
#include "test.hpp"
#include <dds/dds.hpp>
namespace
{
using namespace ::testing;
using ::testing::_;
using namespace iox::dds;
// ======================================== Helpers ======================================== //
using TestDataReader = CycloneDataReader;
struct DummyPayload
{
uint64_t a;
uint64_t b;
uint64_t c;
};
struct DummyUserHeader
{
uint64_t a;
};
// ======================================== Fixture ======================================== //
class CycloneDataReaderTest : public Test
{
public:
void SetUp(){};
void TearDown(){};
};
// ======================================== Tests ======================================== //
TEST_F(CycloneDataReaderTest, DoesNotAttemptToReadWhenDisconnected)
{
::testing::Test::RecordProperty("TEST_ID", "46fc99d7-9f7b-4b77-94c7-06778e3461f7");
// ===== Setup
ChunkMock<DummyPayload> chunkMock;
iox::dds::IoxChunkDatagramHeader datagramHeader;
datagramHeader.endianness = getEndianess();
datagramHeader.userPayloadSize = chunkMock.chunkHeader()->userPayloadSize();
datagramHeader.userPayloadAlignment = chunkMock.chunkHeader()->userPayloadAlignment();
// ===== Test
TestDataReader reader{"", "", ""};
auto takeNextResult = reader.takeNext(datagramHeader,
static_cast<uint8_t*>(chunkMock.chunkHeader()->userHeader()),
static_cast<uint8_t*>(chunkMock.chunkHeader()->userPayload()));
ASSERT_EQ(true, takeNextResult.has_error());
EXPECT_EQ(iox::dds::DataReaderError::NOT_CONNECTED, takeNextResult.get_error());
}
TEST_F(CycloneDataReaderTest, ReturnsErrorWhenAttemptingToReadIntoANullBuffer)
{
::testing::Test::RecordProperty("TEST_ID", "ddd6e55a-b4ca-4e10-838e-5a532ccadb50");
// ===== Setup
ChunkMock<DummyPayload, DummyUserHeader> chunkMock;
iox::dds::IoxChunkDatagramHeader datagramHeader;
datagramHeader.endianness = getEndianess();
datagramHeader.userHeaderId = iox::mepoo::ChunkHeader::UNKNOWN_USER_HEADER;
datagramHeader.userHeaderSize = chunkMock.chunkHeader()->userHeaderSize();
datagramHeader.userPayloadSize = chunkMock.chunkHeader()->userPayloadSize();
datagramHeader.userPayloadAlignment = chunkMock.chunkHeader()->userPayloadAlignment();
// ===== Test
TestDataReader reader{"", "", ""};
reader.connect();
auto takeNextResult1 =
reader.takeNext(datagramHeader, nullptr, static_cast<uint8_t*>(chunkMock.chunkHeader()->userPayload()));
ASSERT_EQ(true, takeNextResult1.has_error());
EXPECT_EQ(iox::dds::DataReaderError::INVALID_BUFFER_PARAMETER_FOR_USER_HEADER, takeNextResult1.get_error());
auto takeNextResult2 =
reader.takeNext(datagramHeader, static_cast<uint8_t*>(chunkMock.chunkHeader()->userHeader()), nullptr);
ASSERT_EQ(true, takeNextResult2.has_error());
EXPECT_EQ(iox::dds::DataReaderError::INVALID_BUFFER_PARAMETER_FOR_USER_PAYLOAD, takeNextResult2.get_error());
}
} // namespace
|