<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_binding_c/internal/cpp2c_enum_translation.hpp"
#include "iceoryx_binding_c/internal/cpp2c_subscriber.hpp"
#include "iceoryx_posh/internal/popo/ports/subscriber_port_user.hpp"
#include "iceoryx_posh/popo/wait_set.hpp"

using namespace iox;
using namespace iox::popo;

extern "C" {
#include "iceoryx_binding_c/subscriber.h"
#include "iceoryx_binding_c/types.h"
#include "iceoryx_binding_c/wait_set.h"
}

#include "test.hpp"

using namespace ::testing;

class iox_wait_set_test : public Test
{
  public:
    void SetUp() override
    {
        iox_wait_set_init(sut, &m_condVar);
    }

    void TearDown() override
    {
        iox_wait_set_deinit(sut);
    }

    iox_sub_t CreateSubscriber()
    {
        const iox::capro::ServiceDescription TEST_SERVICE_DESCRIPTION{"a", "b", "c"};

        cpp2c_Subscriber* subscriber = new cpp2c_Subscriber();
        subscriber->m_portData = new SubscriberPortData{
            TEST_SERVICE_DESCRIPTION, "myApp", iox::cxx::VariantQueueTypes::SoFi_SingleProducerSingleConsumer};

        return subscriber;
    }

    void RemoveSubscriber(iox_sub_t subscriber)
    {
        delete subscriber->m_portData;
        delete subscriber;
    }

    ConditionVariableData m_condVar;
    struct iox_wait_set_storage_t sutStorage;
    wait_set_t sut = (wait_set_t)&sutStorage;
};

TEST_F(iox_wait_set_test, AttachSingleConditionSuccessfully)
{
    iox_sub_t subscriber = CreateSubscriber();
    //    iox_wait_set_attach_condition(sut, subscriber);
    RemoveSubscriber(subscriber);
}<commit_msg>iox-#252 wait set tests can be implemented - inheritance works<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_binding_c/internal/cpp2c_enum_translation.hpp"
#include "iceoryx_binding_c/internal/cpp2c_subscriber.hpp"
#include "iceoryx_posh/internal/popo/ports/subscriber_port_user.hpp"
#include "iceoryx_posh/popo/wait_set.hpp"

using namespace iox;
using namespace iox::popo;

extern "C" {
#include "iceoryx_binding_c/subscriber.h"
#include "iceoryx_binding_c/types.h"
#include "iceoryx_binding_c/wait_set.h"
}

#include "test.hpp"

using namespace ::testing;

class iox_wait_set_test : public Test
{
  public:
    void SetUp() override
    {
        iox_wait_set_init(sut, &m_condVar);
    }

    void TearDown() override
    {
        iox_wait_set_deinit(sut);
        for (auto s : m_subscriber)
        {
            delete s;
        }
    }

    iox_sub_t CreateSubscriber()
    {
        const iox::capro::ServiceDescription TEST_SERVICE_DESCRIPTION{"a", "b", "c"};

        cpp2c_Subscriber* subscriber = new cpp2c_Subscriber();
        subscriber->m_portData = new SubscriberPortData{
            TEST_SERVICE_DESCRIPTION, "myApp", iox::cxx::VariantQueueTypes::SoFi_SingleProducerSingleConsumer};

        m_subscriber.emplace_back(subscriber);
        return subscriber;
    }

    void RemoveSubscriber(iox_sub_t subscriber)
    {
        delete subscriber->m_portData;
        delete subscriber;
    }

    ConditionVariableData m_condVar;
    struct iox_wait_set_storage_t m_sutStorage;
    wait_set_t sut = (wait_set_t)&m_sutStorage;
    std::vector<iox_sub_t> m_subscriber;
};

TEST_F(iox_wait_set_test, AttachSingleConditionSuccessfully)
{
    iox_sub_t subscriber = CreateSubscriber();
    EXPECT_THAT(iox_wait_set_attach_condition(sut, subscriber), Eq(WaitSetResult_SUCCESS));
}

TEST_F(iox_wait_set_test, AttachSingleConditionTwiceResultsInFailure)
{
    iox_sub_t subscriber = CreateSubscriber();
    iox_wait_set_attach_condition(sut, subscriber), Eq(WaitSetResult_SUCCESS);

    EXPECT_THAT(iox_wait_set_attach_condition(sut, subscriber), Eq(WaitSetResult_CONDITION_VARIABLE_ALREADY_SET));
}
{'fraction_non_alphanumeric': 0.09479934479934479, 'fraction_numerical': 0.005528255528255528, 'mean_word_length': 4.0726895119418485, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 10, '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': '4624292', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1554, 'n_words': 368}