-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec51752
commit 6503b29
Showing
2 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
iceoryx_posh/test/moduletests/test_popo_server_options.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |