Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[20511] Support GTest v1.14.0 #4448

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cpp/statistics/rtps/StatisticsBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct StatisticsAncillary
{
std::set<std::shared_ptr<IListener>> listeners;
std::atomic<uint32_t> enabled_writers_mask{0};
virtual ~StatisticsAncillary() = default;
};

struct StatisticsWriterAncillary
Expand Down
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Require C++ 14 for testing as both GTest v1.14.0 and ROS 2 Jazzy require it anyways
set(FORCE_CXX "14")
check_stdcxx(${FORCE_CXX})

option(PERFORMANCE_TESTS "Activate the building and execution of performance tests" OFF)
option(SYSTEM_TESTS "Activate the building and execution of system tests" OFF)
option(PROFILING_TESTS "Activate the building and execution of profiling tests" OFF)
Expand Down
77 changes: 77 additions & 0 deletions test/unittest/common/operators.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// 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.

#include <algorithm>
#include <cstdint>

#include <fastdds/rtps/common/SequenceNumber.h>

namespace eprosima {
namespace fastrtps {
namespace rtps {

// Make SequenceNumberSet_t compatible with GMock macros
bool operator ==(
const SequenceNumberSet_t& a,
const SequenceNumberSet_t& b)
{
// remember that using SequenceNumberSet_t = BitmapRange<SequenceNumber_t, SequenceNumberDiff, 256>;
// see test\unittest\utils\BitmapRangeTests.cpp method TestResult::Check

if (a.empty() && b.empty())
{
return true;
}

if (a.base() == b.base())
{
uint32_t num_bits[2];
uint32_t num_longs[2];
SequenceNumberSet_t::bitmap_type bitmap[2];

a.bitmap_get(num_bits[0], bitmap[0], num_longs[0]);
b.bitmap_get(num_bits[1], bitmap[1], num_longs[1]);

if (num_bits[0] != num_bits[1] || num_longs[0] != num_longs[1])
{
return false;
}
return std::equal(bitmap[0].cbegin(), bitmap[0].cbegin() + num_longs[0], bitmap[1].cbegin());
}
else
{
bool equal = true;

a.for_each([&b, &equal](const SequenceNumber_t& e)
{
equal &= b.is_set(e);
});

if (!equal)
{
return false;
}

b.for_each([&a, &equal](const SequenceNumber_t& e)
{
equal &= a.is_set(e);
});

return equal;
}
}

} // namespace rtps
} // namespace fastrtps
} // namespace eprosima
61 changes: 1 addition & 60 deletions test/unittest/rtps/reader/WriterProxyAcknackTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,67 +28,8 @@
#include <fastrtps/rtps/resources/TimedEvent.h>

#include <rtps/reader/WriterProxy.cpp>
// Make SequenceNumberSet_t compatible with GMock macros

namespace testing {
namespace internal {
using namespace eprosima::fastrtps::rtps;

template<>
bool AnyEq::operator ()(
const SequenceNumberSet_t& a,
const SequenceNumberSet_t& b) const
{
// remember that using SequenceNumberSet_t = BitmapRange<SequenceNumber_t, SequenceNumberDiff, 256>;
// see test\unittest\utils\BitmapRangeTests.cpp method TestResult::Check

if (a.empty() && b.empty())
{
return true;
}

if (a.base() == b.base())
{
uint32_t num_bits[2];
uint32_t num_longs[2];
SequenceNumberSet_t::bitmap_type bitmap[2];

a.bitmap_get(num_bits[0], bitmap[0], num_longs[0]);
b.bitmap_get(num_bits[1], bitmap[1], num_longs[1]);

if (num_bits[0] != num_bits[1] || num_longs[0] != num_longs[1])
{
return false;
}
return std::equal(bitmap[0].cbegin(), bitmap[0].cbegin() + num_longs[0], bitmap[1].cbegin());
}
else
{
bool equal = true;

a.for_each([&b, &equal](const SequenceNumber_t& e)
{
equal &= b.is_set(e);
});

if (!equal)
{
return false;
}

b.for_each([&a, &equal](const SequenceNumber_t& e)
{
equal &= a.is_set(e);
});

return equal;
}
}

} // namespace internal
} // namespace testing


#include "../../common/operators.hpp"

namespace eprosima {
namespace fastrtps {
Expand Down
60 changes: 1 addition & 59 deletions test/unittest/rtps/reader/WriterProxyTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,65 +30,7 @@

#include <rtps/reader/WriterProxy.cpp>

// Make SequenceNumberSet_t compatible with GMock macros

namespace testing {
namespace internal {
using namespace eprosima::fastrtps::rtps;

template<>
bool AnyEq::operator ()(
const SequenceNumberSet_t& a,
const SequenceNumberSet_t& b) const
{
// remember that using SequenceNumberSet_t = BitmapRange<SequenceNumber_t, SequenceNumberDiff, 256>;
// see test\unittest\utils\BitmapRangeTests.cpp method TestResult::Check

if (a.empty() && b.empty())
{
return true;
}

if (a.base() == b.base())
{
uint32_t num_bits[2];
uint32_t num_longs[2];
SequenceNumberSet_t::bitmap_type bitmap[2];

a.bitmap_get(num_bits[0], bitmap[0], num_longs[0]);
b.bitmap_get(num_bits[1], bitmap[1], num_longs[1]);

if (num_bits[0] != num_bits[1] || num_longs[0] != num_longs[1])
{
return false;
}
return std::equal(bitmap[0].cbegin(), bitmap[0].cbegin() + num_longs[0], bitmap[1].cbegin());
}
else
{
bool equal = true;

a.for_each([&b, &equal](const SequenceNumber_t& e)
{
equal &= b.is_set(e);
});

if (!equal)
{
return false;
}

b.for_each([&a, &equal](const SequenceNumber_t& e)
{
equal &= a.is_set(e);
});

return equal;
}
}

} // namespace internal
} // namespace testing
#include "../../common/operators.hpp"

namespace eprosima {
namespace fastrtps {
Expand Down
Loading