MRPT  2.0.1
enumtype_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <gtest/gtest.h>
12 
13 // Example declaration of "enum class"
14 enum class TestColors
15 {
16  Black = 0,
17  Gray = 7,
18  White = 15
19 };
20 
26 
27 // Example declaration of plain enum
29 {
34 };
35 // Example declaration of "enum class"
42 
43 TEST(TEnumType, str2value)
44 {
46 
47  EXPECT_EQ(TEnumType<TestColors>::name2value("White"), TestColors::White);
48  EXPECT_EQ(TEnumType<TestColors>::name2value("Black"), TestColors::Black);
49  EXPECT_EQ(TEnumType<TestColors>::name2value("Gray"), TestColors::Gray);
50 
51  EXPECT_EQ(TEnumType<Directions>::name2value("East"), East);
52 
53  EXPECT_THROW(TEnumType<TestColors>::name2value("Violet"), std::exception);
54 }
55 
56 TEST(TEnumType, value2str)
57 {
59 
60  EXPECT_EQ(TEnumType<TestColors>::value2name(TestColors::White), "White");
61  EXPECT_EQ(TEnumType<TestColors>::value2name(TestColors::Black), "Black");
62  EXPECT_EQ(TEnumType<TestColors>::value2name(TestColors::Gray), "Gray");
63 
64  EXPECT_EQ(TEnumType<Directions>::value2name(East), "East");
65 
66  EXPECT_THROW(
67  TEnumType<TestColors>::value2name(static_cast<TestColors>(5)),
68  std::exception);
69 }
A helper class that can convert an enum value into its textual representation, and viceversa...
#define MRPT_ENUM_TYPE_END()
Definition: TEnumType.h:78
TEST(TEnumType, str2value)
EXPECT_EQ(out.image_pair_was_used.size(), NUM_IMGS)
MRPT_FILL_ENUM_MEMBER(TestColors, Black)
#define MRPT_ENUM_TYPE_BEGIN(_ENUM_TYPE_WITH_NS)
Definition: TEnumType.h:62
MRPT_FILL_ENUM(North)



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020