diff options
author | mukesh agrawal <quiche@google.com> | 2016-10-20 13:54:10 -0700 |
---|---|---|
committer | mukesh agrawal <quiche@google.com> | 2016-10-21 10:27:14 -0700 |
commit | 9cfc0379b078bdbed45bf0a3c3f5d3afc3860bdf (patch) | |
tree | 73b9c66e36f1710c79c5d185438691223409efce /tests | |
parent | 93f78dc67ade6a4ed606e31db8ce7aa5765d9909 (diff) | |
download | wifilogd-9cfc0379b078bdbed45bf0a3c3f5d3afc3860bdf.tar.gz |
local_utils: add CastEnumToInteger()
In certain debugging contexts, its helpful to
output the raw value of an enum variable.
Add CastEnumToInteger(), to meet this need.
Bug: 32315504
Test: ./runtests.sh (on angler)
Change-Id: Ie19f6643aafd733beab73de2cb50071db208fb7c
Diffstat (limited to 'tests')
-rw-r--r-- | tests/local_utils_unittest.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/local_utils_unittest.cpp b/tests/local_utils_unittest.cpp index d0955ca..50898d3 100644 --- a/tests/local_utils_unittest.cpp +++ b/tests/local_utils_unittest.cpp @@ -25,10 +25,26 @@ namespace android { namespace wifilogd { +using local_utils::CastEnumToInteger; using local_utils::CopyFromBufferOrDie; using local_utils::GetMaxVal; using local_utils::IsAsciiPrintable; +TEST(LocalUtilsTest, CastEnumToIntegerWorksForValidEnumValues) { + enum class basic_enum { VALUE0, VALUE1 }; + EXPECT_EQ(0, CastEnumToInteger(basic_enum::VALUE0)); + EXPECT_EQ(1, CastEnumToInteger(basic_enum::VALUE1)); +} + +TEST(LocalUtilsTest, CastEnumToIntegerWorksForInvalidEnumValues) { + enum class basic_enum : int { VALUE0, VALUE1 }; + constexpr int invalid_enum_value = 2; + EXPECT_EQ(0, CastEnumToInteger(basic_enum::VALUE0)); + EXPECT_EQ(1, CastEnumToInteger(basic_enum::VALUE1)); + EXPECT_EQ(2, CastEnumToInteger(CopyFromBufferOrDie<basic_enum>( + &invalid_enum_value, sizeof(invalid_enum_value)))); +} + TEST(LocalUtilsTest, CopyFromBufferOrDieCopiesData) { struct Message { int a; |