|
| 1 | +// Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#include <memory> |
| 16 | +#include <string> |
| 17 | +#include <chrono> |
| 18 | +#include <thread> |
| 19 | +#include <vector> |
| 20 | + |
| 21 | +#include "rmw/error_handling.h" |
| 22 | +#include "rmw/rmw.h" |
| 23 | +#include "rmw/validate_namespace.h" |
| 24 | +#include "rmw/validate_node_name.h" |
| 25 | + |
| 26 | +#include "./rmw_base_test.hpp" |
| 27 | +#include "./test_utils.hpp" |
| 28 | + |
| 29 | +#include "rosidl_runtime_c/string.h" |
| 30 | + |
| 31 | +#define MICROXRCEDDS_PADDING sizeof(uint32_t) |
| 32 | + |
| 33 | +class TestGuardCondition : public ::testing::Test |
| 34 | +{ |
| 35 | +public: |
| 36 | + void SetUp() override |
| 37 | + { |
| 38 | + ASSERT_EQ(rmw_init_options_init(&options, rcutils_get_default_allocator()), RMW_RET_OK); |
| 39 | + ASSERT_EQ(rmw_init(&options, &context), RMW_RET_OK); |
| 40 | + } |
| 41 | + |
| 42 | + void TearDown() override |
| 43 | + { |
| 44 | + ASSERT_EQ(rmw_init_options_fini(&options), RMW_RET_OK); |
| 45 | + ASSERT_EQ(rmw_shutdown(&context), RMW_RET_OK); |
| 46 | + } |
| 47 | + |
| 48 | +protected: |
| 49 | + rmw_context_t context = rmw_get_zero_initialized_context(); |
| 50 | + rmw_init_options_t options = rmw_get_zero_initialized_init_options(); |
| 51 | +}; |
| 52 | + |
| 53 | +TEST_F(TestGuardCondition, guard_condition) |
| 54 | +{ |
| 55 | + rmw_guard_condition_t * gc = rmw_create_guard_condition(&context); |
| 56 | + ASSERT_NE(gc, nullptr); |
| 57 | + |
| 58 | + rmw_guard_conditions_t guard_conditions; |
| 59 | + void * aux[1] = {gc->data}; |
| 60 | + guard_conditions.guard_conditions = aux; |
| 61 | + guard_conditions.guard_condition_count = 1; |
| 62 | + |
| 63 | + rmw_time_t wait_timeout = (rmw_time_t) {1LL, 1LL}; |
| 64 | + |
| 65 | + rmw_ret_t rc = rmw_wait(NULL, &guard_conditions, NULL, NULL, NULL, NULL, &wait_timeout); |
| 66 | + ASSERT_EQ(rc, RMW_RET_TIMEOUT); |
| 67 | + |
| 68 | + rc = rmw_trigger_guard_condition(gc); |
| 69 | + ASSERT_EQ(rc, RMW_RET_OK); |
| 70 | + |
| 71 | + aux[0] = gc->data; |
| 72 | + guard_conditions.guard_conditions = aux; |
| 73 | + guard_conditions.guard_condition_count = 1; |
| 74 | + rc = rmw_wait(NULL, &guard_conditions, NULL, NULL, NULL, NULL, &wait_timeout); |
| 75 | + ASSERT_EQ(rc, RMW_RET_OK); |
| 76 | + |
| 77 | + rc = rmw_destroy_guard_condition(gc); |
| 78 | + ASSERT_EQ(rc, RMW_RET_OK); |
| 79 | +} |
0 commit comments