Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 1 | #include "utils/conversion.hpp" |
| 2 | |
| 3 | #include <gmock/gmock.h> |
| 4 | |
| 5 | using namespace testing; |
| 6 | |
| 7 | class TestEnum : public Test |
| 8 | { |
| 9 | public: |
| 10 | enum class Enum |
| 11 | { |
| 12 | zero = 0, |
| 13 | one, |
| 14 | two |
| 15 | }; |
| 16 | |
| 17 | Enum toEnum(int x) |
| 18 | { |
| 19 | return utils::toEnum<Enum, Enum::zero, Enum::two>(x); |
| 20 | } |
| 21 | }; |
| 22 | |
| 23 | TEST_F(TestEnum, passValueInRangeExpectToGetValidOutput) |
| 24 | { |
| 25 | EXPECT_EQ(toEnum(0), Enum::zero); |
| 26 | EXPECT_EQ(toEnum(2), Enum::two); |
| 27 | } |
| 28 | |
| 29 | TEST_F(TestEnum, passInvalidValueExpectToThrowOutOfRangeException) |
| 30 | { |
| 31 | EXPECT_THROW(toEnum(-1), std::out_of_range); |
| 32 | EXPECT_THROW(toEnum(3), std::out_of_range); |
| 33 | } |