Brad Bishop | 13fd872 | 2017-05-15 12:44:01 -0400 | [diff] [blame] | 1 | #include <array> |
| 2 | #include <string> |
| 3 | #include <gtest/gtest.h> |
| 4 | #include "data_types.hpp" |
| 5 | |
| 6 | using namespace std::string_literals; |
| 7 | using namespace phosphor::dbus::monitoring; |
| 8 | |
| 9 | using Index = std::map<std::tuple<size_t, size_t, size_t>, size_t>; |
| 10 | |
| 11 | #include "propertywatchgentest.hpp" |
| 12 | |
| 13 | auto expectedStorageCount = 16; |
| 14 | |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame^] | 15 | const std::array<Index, 4> expectedIndicies = {{ |
Brad Bishop | 13fd872 | 2017-05-15 12:44:01 -0400 | [diff] [blame] | 16 | { |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame^] | 17 | {Index::key_type{0, 0, 0}, 0}, |
| 18 | {Index::key_type{0, 1, 0}, 1}, |
| 19 | {Index::key_type{1, 0, 0}, 2}, |
| 20 | {Index::key_type{1, 1, 0}, 3}, |
| 21 | {Index::key_type{2, 0, 0}, 4}, |
| 22 | {Index::key_type{2, 1, 0}, 5}, |
| 23 | {Index::key_type{3, 0, 0}, 6}, |
| 24 | {Index::key_type{3, 1, 0}, 7}, |
| 25 | }, |
| 26 | { |
| 27 | {Index::key_type{2, 2, 1}, 8}, |
| 28 | {Index::key_type{2, 2, 2}, 9}, |
| 29 | {Index::key_type{3, 2, 1}, 10}, |
| 30 | {Index::key_type{3, 2, 2}, 11}, |
| 31 | {Index::key_type{4, 2, 1}, 12}, |
| 32 | {Index::key_type{4, 2, 2}, 13}, |
| 33 | {Index::key_type{5, 2, 1}, 14}, |
| 34 | {Index::key_type{5, 2, 2}, 15}, |
| 35 | }, |
| 36 | { |
| 37 | {Index::key_type{3, 0, 0}, 6}, |
| 38 | }, |
| 39 | { |
| 40 | {Index::key_type{3, 2, 2}, 11}, |
| 41 | {Index::key_type{5, 2, 2}, 15}, |
| 42 | }, |
| 43 | }}; |
Brad Bishop | 13fd872 | 2017-05-15 12:44:01 -0400 | [diff] [blame] | 44 | |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame^] | 45 | const std::array<std::tuple<std::string, size_t>, 4> expectedWatches = {{ |
| 46 | std::tuple<std::string, size_t>{"std::string"s, 0}, |
| 47 | std::tuple<std::string, size_t>{"uint32_t"s, 1}, |
| 48 | std::tuple<std::string, size_t>{"int32_t"s, 2}, |
| 49 | std::tuple<std::string, size_t>{"std::string"s, 3}, |
| 50 | }}; |
Brad Bishop | 13fd872 | 2017-05-15 12:44:01 -0400 | [diff] [blame] | 51 | |
| 52 | TEST(PropertyWatchGenTest, storageCount) |
| 53 | { |
| 54 | ASSERT_EQ(expectedStorageCount, storageCount); |
| 55 | } |
| 56 | |
| 57 | TEST(PropertyWatchGenTest, IndiciesSameSize) |
| 58 | { |
Gunnar Mills | 78199b4 | 2017-10-25 16:30:18 -0500 | [diff] [blame] | 59 | ASSERT_EQ(sizeof(expectedIndicies), sizeof(indices)); |
Brad Bishop | 13fd872 | 2017-05-15 12:44:01 -0400 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | TEST(PropertyWatchGenTest, WatchesSameSize) |
| 63 | { |
| 64 | ASSERT_EQ(sizeof(expectedWatches), sizeof(watches)); |
| 65 | } |
| 66 | |
| 67 | TEST(PropertyWatchGenTest, WatchesSameContent) |
| 68 | { |
| 69 | size_t i; |
| 70 | for (i = 0; i < expectedWatches.size(); ++i) |
| 71 | { |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame^] | 72 | ASSERT_EQ(watches[i], expectedWatches[i]); |
Brad Bishop | 13fd872 | 2017-05-15 12:44:01 -0400 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | |
| 76 | TEST(PropertyWatchGenTest, IndiciesSameContent) |
| 77 | { |
| 78 | size_t i; |
| 79 | for (i = 0; i < expectedIndicies.size(); ++i) |
| 80 | { |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame^] | 81 | ASSERT_EQ(indices[i], expectedIndicies[i]); |
Brad Bishop | 13fd872 | 2017-05-15 12:44:01 -0400 | [diff] [blame] | 82 | } |
| 83 | } |