| #include "util/state_machine/discovery/rde/dictionary.hpp" |
| |
| #include <stdplus/print.hpp> |
| |
| #include <memory> |
| |
| #include <gmock/gmock.h> |
| #include <gtest/gtest.h> |
| |
| using ::testing::_; |
| using ::testing::Return; |
| |
| class DictionaryTest : public ::testing::Test |
| { |
| protected: |
| uint32_t resourceIdTest = 0x00000; |
| std::unique_ptr<Dictionary> dictionary = |
| std::make_unique<Dictionary>(resourceIdTest); |
| }; |
| |
| TEST_F(DictionaryTest, GetDictionaryBytesSuccess) |
| { |
| std::vector<uint8_t> payloadPart1 = {0x01, 0x02, 0x03}; |
| std::vector<uint8_t> payloadPart2 = {0x04, 0x05}; |
| std::vector<uint8_t> payloadPart3 = {0x06, 0x07, 0x08, 0x09}; |
| |
| std::vector<uint8_t> expectedDictionary = {0x01, 0x02, 0x03, 0x04, 0x05, |
| 0x06, 0x07, 0x08, 0x09}; |
| OperationStatus status = dictionary->addToDictionaryBytes( |
| std::span<const uint8_t>(payloadPart1.data(), payloadPart1.size()), |
| false); |
| EXPECT_EQ(OperationStatus::Success, status); |
| |
| status = dictionary->addToDictionaryBytes( |
| std::span<const uint8_t>(payloadPart2.data(), payloadPart2.size()), |
| false); |
| EXPECT_EQ(OperationStatus::Success, status); |
| |
| dictionary->addToDictionaryBytes( |
| std::span<const uint8_t>(payloadPart3.data(), payloadPart3.size()), |
| false); |
| EXPECT_EQ(OperationStatus::Success, status); |
| |
| std::span<const uint8_t> resultDictionary = |
| dictionary->getDictionaryBytes(); |
| EXPECT_EQ(expectedDictionary, std::vector<uint8_t>(resultDictionary.begin(), |
| resultDictionary.end())); |
| } |
| |
| TEST_F(DictionaryTest, ChecksumFailure) |
| { |
| std::vector<uint8_t> payloadPart1 = {0x01, 0x02, 0x03}; |
| std::vector<uint8_t> payloadPart2 = {0x04, 0x05, 0x04, 0x05}; |
| |
| OperationStatus status = dictionary->addToDictionaryBytes( |
| std::span<const uint8_t>(payloadPart1.data(), payloadPart1.size()), |
| false); |
| EXPECT_EQ(OperationStatus::Success, status); |
| |
| status = dictionary->addToDictionaryBytes( |
| std::span<const uint8_t>(payloadPart2.data(), payloadPart2.size()), |
| true); |
| EXPECT_EQ(OperationStatus::ChecksumFailure, status); |
| } |
| |
| TEST_F(DictionaryTest, ChecksumSuccess) |
| { |
| std::vector<uint8_t> payload = {0x01, 0x02, 0x03, 0x04, 0x05}; |
| std::vector<uint8_t> payloadWithChecksum = {0xf4, 0x99, 0x0b, 0x47}; |
| |
| OperationStatus status = dictionary->addToDictionaryBytes( |
| std::span<const uint8_t>(payload.data(), payload.size()), false); |
| EXPECT_EQ(OperationStatus::Success, status); |
| |
| status = dictionary->addToDictionaryBytes( |
| std::span<const uint8_t>(payloadWithChecksum.data(), |
| payloadWithChecksum.size()), |
| true); |
| EXPECT_EQ(OperationStatus::Success, status); |
| } |