forked from eclipse-iceoryx/iceoryx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iox-eclipse-iceoryx#1640 Polymorphic handler test
Signed-off-by: Matthias Killat <[email protected]>
- Loading branch information
1 parent
d620da3
commit a330e09
Showing
2 changed files
with
98 additions
and
1 deletion.
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
96 changes: 96 additions & 0 deletions
96
iceoryx_hoofs/test/moduletests/test_polymorphic_handler.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,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 |