Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1640 Polymorphic handler test
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Killat <[email protected]>
  • Loading branch information
MatthiasKillat committed Sep 19, 2022
1 parent d620da3 commit a330e09
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#include <mutex>
#include <type_traits>

namespace eh
// TODO: change namespace? but DesignPattern is a bad namespace name ...
namespace iox
{
// we lose generality now wrt. the interface (require activate, deactivate etc. in the interface)
template <typename Interface, typename Default>
Expand Down
96 changes: 96 additions & 0 deletions iceoryx_hoofs/test/moduletests/test_polymorphic_handler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright (c) 2022 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_hoofs/design_pattern/polymorphic_handler.hpp"

#include "test.hpp"
#include <iostream>

namespace
{
using namespace ::testing;

// intentionally not defined in Foo (cannot be used in tests there)
constexpr uint32_t DEFAULT_VALUE{66};

struct Foo
{
Foo()
{
++numDefaultCtorCalls;
}

explicit Foo(uint32_t v)
: value(v)
{
++numCtorCalls;
}

Foo(const Foo&) = delete;
Foo(Foo&&) = delete;
Foo& operator=(const Foo&) = delete;
Foo& operator=(Foo&&) = delete;

~Foo()
{
++numDtorCalls;
}

uint32_t value{DEFAULT_VALUE};

static uint32_t numDefaultCtorCalls;
static uint32_t numCtorCalls;
static uint32_t numDtorCalls;

static void reset()
{
numDefaultCtorCalls = 0;
numCtorCalls = 0;
numDtorCalls = 0;
}
};

uint32_t Foo::numDefaultCtorCalls;
uint32_t Foo::numCtorCalls;
uint32_t Foo::numDtorCalls;

using TestHandler = iox::PolymorphicHandler<Foo, Foo>;

class PolymorphicHandler_test : public Test
{
public:
void SetUp() override
{
internal::CaptureStderr();
Foo::reset();
}

void TearDown() override
{
std::string output = internal::GetCapturedStderr();
if (Test::HasFailure())
{
std::cout << output << std::endl;
}
}
};

TEST_F(PolymorphicHandler, create)
{
::testing::Test::RecordProperty("TEST_ID", "123");
}

} // namespace

0 comments on commit a330e09

Please sign in to comment.