<commit_before>// Copyright (c) 2020 by <NAME>. 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.

#include "iceoryx_posh/iceoryx_posh_types.hpp"
#include "iceoryx_posh/popo/modern_api/base_subscriber.hpp"
#include "iceoryx_utils/cxx/expected.hpp"
#include "iceoryx_utils/cxx/optional.hpp"
#include "iceoryx_utils/cxx/unique_ptr.hpp"

#include "mocks/subscriber_mock.hpp"
#include "test.hpp"

using namespace ::testing;
using ::testing::_;

struct DummyData
{
    uint64_t val = 42;
};

template <typename T, typename port_t>
class StubbedBaseSubscriber : public iox::popo::BaseSubscriber<T, port_t>
{
  public:
    StubbedBaseSubscriber(iox::capro::ServiceDescription)
        : iox::popo::BaseSubscriber<T, port_t>::BaseSubscriber()
    {
    }
    uid_t getUid() const noexcept
    {
        return iox::popo::BaseSubscriber<T, port_t>::getUid();
    }
    iox::capro::ServiceDescription getServiceDescription() const noexcept
    {
        return iox::popo::BaseSubscriber<T, port_t>::getServiceDescription();
    }
    void subscribe(const uint64_t queueCapacity = iox::MAX_SUBSCRIBER_QUEUE_CAPACITY) noexcept
    {
        return iox::popo::BaseSubscriber<T, port_t>::subscribe(queueCapacity);
    }
    iox::SubscribeState getSubscriptionState() const noexcept
    {
        return iox::popo::BaseSubscriber<T, port_t>::getSubscriptionState();
    }
    void unsubscribe() noexcept
    {
        return iox::popo::BaseSubscriber<T, port_t>::unsubscribe();
    }
    bool hasNewSamples() const noexcept
    {
        return iox::popo::BaseSubscriber<T, port_t>::hasNewSamples();
    }
    bool hasMissedSamples() noexcept
    {
        return iox::popo::BaseSubscriber<T, port_t>::hasMissedSamples();
    }
    iox::cxx::expected<iox::cxx::optional<iox::popo::Sample<const T>>, iox::popo::ChunkReceiveError> take() noexcept
    {
        return iox::popo::BaseSubscriber<T, port_t>::take();
    }
    iox::cxx::optional<iox::cxx::unique_ptr<iox::mepoo::ChunkHeader>> receiveHeader() noexcept
    {
        return iox::popo::BaseSubscriber<T, port_t>::receiveHeader();
    }
    void releaseQueuedSamples() noexcept
    {
        return iox::popo::BaseSubscriber<T, port_t>::releaseQueuedSamples();
    }
    void setConditionVariable(iox::popo::ConditionVariableData* const conditionVariableDataPtr) noexcept override
    {
        iox::popo::BaseSubscriber<T, port_t>::setConditionVariable(conditionVariableDataPtr);
    }
    void unsetConditionVariable() noexcept override
    {
        iox::popo::BaseSubscriber<T, port_t>::unsetConditionVariable();
    }
    virtual bool hasTriggered() const noexcept override
    {
        return iox::popo::BaseSubscriber<T, port_t>::hasTriggered();
    }
    port_t& getMockedPort()
    {
        return iox::popo::BaseSubscriber<T, port_t>::m_port;
    }
};

using TestBaseSubscriber = StubbedBaseSubscriber<DummyData, MockSubscriberPortUser>;

// ========================= Base Publisher Tests ========================= //

class BaseSubscriberTest : public Test
{
  public:
    BaseSubscriberTest()
    {
    }

    void SetUp()
    {
    }

    void TearDown()
    {
    }

  protected:
    TestBaseSubscriber sut{{"", "", ""}};
};

TEST_F(BaseSubscriberTest, SubscribeCallForwardedToUnderlyingSubscriberPort)
{
    // ===== Setup ===== //
    EXPECT_CALL(sut.getMockedPort(), subscribe(iox::MAX_SUBSCRIBER_QUEUE_CAPACITY)).Times(1);
    // ===== Test ===== //
    sut.subscribe();
    // ===== Verify ===== //
    // ===== Cleanup ===== //
}

TEST_F(BaseSubscriberTest, GetSubscriptionStateCallForwardedToUnderlyingSubscriberPort)
{
    // ===== Setup ===== //
    EXPECT_CALL(sut.getMockedPort(), getSubscriptionState).Times(1);
    // ===== Test ===== //<commit_msg>iox-#252 Use "using" to expose protected methods in tests.<commit_after>// Copyright (c) 2020 by <NAME>. 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.

#include "iceoryx_posh/iceoryx_posh_types.hpp"
#include "iceoryx_posh/popo/modern_api/base_subscriber.hpp"
#include "iceoryx_utils/cxx/expected.hpp"
#include "iceoryx_utils/cxx/optional.hpp"
#include "iceoryx_utils/cxx/unique_ptr.hpp"

#include "mocks/subscriber_mock.hpp"
#include "test.hpp"

using namespace ::testing;
using ::testing::_;

struct DummyData
{
    uint64_t val = 42;
};

template <typename T, typename port_t>
class StubbedBaseSubscriber : public iox::popo::BaseSubscriber<T, port_t>
{
  public:
    using iox::popo::BaseSubscriber<T, port_t>::getServiceDescription;
    using iox::popo::BaseSubscriber<T, port_t>::getSubscriptionState;
    using iox::popo::BaseSubscriber<T, port_t>::getUid;
    using iox::popo::BaseSubscriber<T, port_t>::hasMissedSamples;
    using iox::popo::BaseSubscriber<T, port_t>::hasNewSamples;
    using iox::popo::BaseSubscriber<T, port_t>::hasTriggered;
    using iox::popo::BaseSubscriber<T, port_t>::releaseQueuedSamples;
    using iox::popo::BaseSubscriber<T, port_t>::setConditionVariable;
    using iox::popo::BaseSubscriber<T, port_t>::subscribe;
    using iox::popo::BaseSubscriber<T, port_t>::take;
    using iox::popo::BaseSubscriber<T, port_t>::unsetConditionVariable;
    using iox::popo::BaseSubscriber<T, port_t>::unsubscribe;
    port_t& getMockedPort()
    {
        return iox::popo::BaseSubscriber<T, port_t>::m_port;
    }
};

using TestBaseSubscriber = StubbedBaseSubscriber<DummyData, MockSubscriberPortUser>;

// ========================= Base Publisher Tests ========================= //

class BaseSubscriberTest : public Test
{
  public:
    BaseSubscriberTest()
    {
    }

    void SetUp()
    {
    }

    void TearDown()
    {
    }

  protected:
    TestBaseSubscriber sut{};
};

TEST_F(BaseSubscriberTest, SubscribeCallForwardedToUnderlyingSubscriberPort)
{
    // ===== Setup ===== //
    EXPECT_CALL(sut.getMockedPort(), subscribe(iox::MAX_SUBSCRIBER_QUEUE_CAPACITY)).Times(1);
    // ===== Test ===== //
    sut.subscribe();
    // ===== Verify ===== //
    // ===== Cleanup ===== //
}

TEST_F(BaseSubscriberTest, GetSubscriptionStateCallForwardedToUnderlyingSubscriberPort)
{
    // ===== Setup ===== //
    EXPECT_CALL(sut.getMockedPort(), getSubscriptionState).Times(1);
    // ===== Test ===== //
{'fraction_non_alphanumeric': 0.1524390243902439, 'fraction_numerical': 0.004573170731707317, 'mean_word_length': 4.25254730713246, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7148464', 'n_tokens_mistral': 2366, 'n_tokens_neox': 2316, 'n_words': 463}