|
| 1 | +// Copyright (c) 2018 - for information on the respective copyright owner |
| 2 | +// see the NOTICE file and/or the repository https://github.com/microros/system_modes |
| 3 | +// |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | + |
| 16 | +#include <gtest/gtest.h> |
| 17 | +#include <lifecycle_msgs/msg/state.hpp> |
| 18 | + |
| 19 | +#include <string> |
| 20 | +#include <iostream> |
| 21 | + |
| 22 | +#include "system_modes/mode.hpp" |
| 23 | + |
| 24 | +using std::string; |
| 25 | +using namespace std::string_literals; |
| 26 | + |
| 27 | +using system_modes::StateAndMode; |
| 28 | +using lifecycle_msgs::msg::State; |
| 29 | + |
| 30 | +class TestStateAndMode : public ::testing::Test |
| 31 | +{ |
| 32 | +protected: |
| 33 | + void SetUp() |
| 34 | + { |
| 35 | + inactive.state = State::PRIMARY_STATE_INACTIVE; |
| 36 | + |
| 37 | + active.state = State::PRIMARY_STATE_ACTIVE; |
| 38 | + |
| 39 | + active_default.state = State::PRIMARY_STATE_ACTIVE; |
| 40 | + active_default.mode = "__DEFAULT__"; |
| 41 | + |
| 42 | + active_foo.state = State::PRIMARY_STATE_ACTIVE; |
| 43 | + active_foo.mode = "FOO"; |
| 44 | + } |
| 45 | + |
| 46 | + void TearDown() |
| 47 | + { |
| 48 | + } |
| 49 | + |
| 50 | + StateAndMode inactive, active, active_default, active_foo; |
| 51 | +}; |
| 52 | + |
| 53 | +TEST_F(TestStateAndMode, comparison) { |
| 54 | + { |
| 55 | + EXPECT_EQ(inactive, inactive); |
| 56 | + EXPECT_EQ(active, active); |
| 57 | + EXPECT_EQ(active, active_default); |
| 58 | + |
| 59 | + EXPECT_NE(active, inactive); |
| 60 | + EXPECT_NE(active, active_foo); |
| 61 | + EXPECT_NE(active_default, active_foo); |
| 62 | + EXPECT_NE(active_default, inactive); |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +TEST_F(TestStateAndMode, string_getter) { |
| 67 | + { |
| 68 | + EXPECT_EQ("active"s, active.as_string()); |
| 69 | + EXPECT_EQ("active.__DEFAULT__"s, active_default.as_string()); |
| 70 | + EXPECT_EQ("active.FOO"s, active_foo.as_string()); |
| 71 | + EXPECT_EQ("inactive"s, inactive.as_string()); |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +TEST_F(TestStateAndMode, string_setter) { |
| 76 | + { |
| 77 | + StateAndMode copy; |
| 78 | + |
| 79 | + copy.from_string("active"); |
| 80 | + EXPECT_EQ(active, copy); |
| 81 | + |
| 82 | + copy.from_string("active.__DEFAULT__"); |
| 83 | + EXPECT_EQ(active_default, copy); |
| 84 | + |
| 85 | + copy.from_string("active.FOO"); |
| 86 | + EXPECT_EQ(active_foo, copy); |
| 87 | + |
| 88 | + copy.from_string("inactive"); |
| 89 | + EXPECT_EQ(inactive, copy); |
| 90 | + |
| 91 | + copy.from_string(active.as_string()); |
| 92 | + EXPECT_EQ(active, copy); |
| 93 | + |
| 94 | + copy.from_string(active_foo.as_string()); |
| 95 | + EXPECT_EQ(active_foo, copy); |
| 96 | + |
| 97 | + copy.from_string(inactive.as_string()); |
| 98 | + EXPECT_EQ(inactive, copy); |
| 99 | + } |
| 100 | +} |
0 commit comments