Skip to content

Commit

Permalink
iox-#27 Add tests for ServerOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Aug 2, 2021
1 parent ec51752 commit 6503b29
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,10 @@ inline bool ChunkDistributor<ChunkDistributorDataType>::deliverToQueue(cxx::not_
}

template <typename ChunkDistributorDataType>
inline cxx::expected<ChunkDistributorError> ChunkDistributor<ChunkDistributorDataType>::deliverToQueue(
const UniqueQueueId uniqueQueueId, uint32_t& lastKnownQueueIndex, mepoo::SharedChunk chunk) noexcept
inline cxx::expected<ChunkDistributorError>
ChunkDistributor<ChunkDistributorDataType>::deliverToQueue(const UniqueQueueId uniqueQueueId IOX_MAYBE_UNUSED,
uint32_t& lastKnownQueueIndex IOX_MAYBE_UNUSED,
mepoo::SharedChunk chunk IOX_MAYBE_UNUSED) noexcept
{
/// @todo iox-#27
/// - find queue
Expand Down
113 changes: 113 additions & 0 deletions iceoryx_posh/test/moduletests/test_popo_server_options.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// 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_posh/popo/server_options.hpp"

#include "test.hpp"

namespace
{
using namespace ::testing;

TEST(ServerOptions_test, SerializationRoundTripIsSuccessful)
{
iox::popo::ServerOptions defaultOptions;
iox::popo::ServerOptions testOptions;

testOptions.requestQueueCapacity = 42;
testOptions.nodeName = "hypnotoad";
testOptions.offerOnCreate = false;
testOptions.clientTooSlowPolicy = iox::popo::ConsumerTooSlowPolicy::WAIT_FOR_CONSUMER;

iox::popo::ServerOptions::deserialize(testOptions.serialize())
.and_then([&](auto& roundTripOptions) {
EXPECT_THAT(roundTripOptions.requestQueueCapacity, Ne(defaultOptions.requestQueueCapacity));
EXPECT_THAT(roundTripOptions.requestQueueCapacity, Eq(testOptions.requestQueueCapacity));

EXPECT_THAT(roundTripOptions.nodeName, Ne(defaultOptions.nodeName));
EXPECT_THAT(roundTripOptions.nodeName, Eq(testOptions.nodeName));

EXPECT_THAT(roundTripOptions.offerOnCreate, Ne(defaultOptions.offerOnCreate));
EXPECT_THAT(roundTripOptions.offerOnCreate, Eq(testOptions.offerOnCreate));

EXPECT_THAT(roundTripOptions.clientTooSlowPolicy, Ne(defaultOptions.clientTooSlowPolicy));
EXPECT_THAT(roundTripOptions.clientTooSlowPolicy, Eq(testOptions.clientTooSlowPolicy));
})
.or_else([&](auto&) {
constexpr bool DESERIALZATION_ERROR_OCCURED{true};
EXPECT_FALSE(DESERIALZATION_ERROR_OCCURED);
});
}

TEST(ServerOptions_test, DeserializingBogusDataFails)
{
const auto bogusSerialization = iox::cxx::Serialization::create("hypnotoad", "brain slug", "rock star");
iox::popo::ServerOptions::deserialize(bogusSerialization)
.and_then([&](auto&) {
constexpr bool DESERIALZATION_SUCCESSFUL{true};
EXPECT_FALSE(DESERIALZATION_SUCCESSFUL);
})
.or_else([&](auto&) {
constexpr bool DESERIALZATION_ERROR_OCCURED{true};
EXPECT_TRUE(DESERIALZATION_ERROR_OCCURED);
});
}

using QueueFullPolicyUT = std::underlying_type_t<iox::popo::QueueFullPolicy2>;
using ConsumerTooSlowPolicyUT = std::underlying_type_t<iox::popo::ConsumerTooSlowPolicy>;
iox::cxx::Serialization enumSerialization(ConsumerTooSlowPolicyUT clientTooSlowPolicy)
{
constexpr uint64_t REQUEST_QUEUE_CAPACITY{42U};
const iox::NodeName_t NODE_NAME{"harr-harr"};
constexpr bool OFFER_ON_CREATE{true};

return iox::cxx::Serialization::create(REQUEST_QUEUE_CAPACITY, NODE_NAME, OFFER_ON_CREATE, clientTooSlowPolicy);
}

TEST(ServerOptions_test, DeserializingValidClientTooSlowPolicyIsSuccessful)
{
constexpr ConsumerTooSlowPolicyUT CLIENT_TOO_SLOW_POLICY{
static_cast<ConsumerTooSlowPolicyUT>(iox::popo::ConsumerTooSlowPolicy::WAIT_FOR_CONSUMER)};

const auto serialized = enumSerialization(CLIENT_TOO_SLOW_POLICY);
iox::popo::ServerOptions::deserialize(serialized)
.and_then([&](auto&) {
constexpr bool DESERIALZATION_SUCCESSFUL{true};
EXPECT_TRUE(DESERIALZATION_SUCCESSFUL);
})
.or_else([&](auto&) {
constexpr bool DESERIALZATION_ERROR_OCCURED{true};
EXPECT_FALSE(DESERIALZATION_ERROR_OCCURED);
});
}

TEST(ServerOptions_test, DeserializingInvalidClientTooSlowPolicyFails)
{
constexpr ConsumerTooSlowPolicyUT CLIENT_TOO_SLOW_POLICY{111};

const auto serialized = enumSerialization(CLIENT_TOO_SLOW_POLICY);
iox::popo::ServerOptions::deserialize(serialized)
.and_then([&](auto&) {
constexpr bool DESERIALZATION_SUCCESSFUL{true};
EXPECT_FALSE(DESERIALZATION_SUCCESSFUL);
})
.or_else([&](auto&) {
constexpr bool DESERIALZATION_ERROR_OCCURED{true};
EXPECT_TRUE(DESERIALZATION_ERROR_OCCURED);
});
}

} // namespace

0 comments on commit 6503b29

Please sign in to comment.