Willy Tu | a2056e9 | 2021-10-10 13:36:16 -0700 | [diff] [blame] | 1 | // Copyright 2021 Google LLC |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
Willy Tu | 3b1b427 | 2021-03-02 17:58:10 -0800 | [diff] [blame] | 15 | #include "commands.hpp" |
| 16 | #include "flash_size.hpp" |
| 17 | #include "handler_mock.hpp" |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 18 | #include "helper.hpp" |
Willy Tu | 3b1b427 | 2021-03-02 17:58:10 -0800 | [diff] [blame] | 19 | |
| 20 | #include <cstdint> |
| 21 | #include <cstring> |
| 22 | #include <string> |
| 23 | #include <vector> |
| 24 | |
| 25 | #include <gtest/gtest.h> |
| 26 | |
Willy Tu | 3b1b427 | 2021-03-02 17:58:10 -0800 | [diff] [blame] | 27 | using ::testing::Return; |
| 28 | |
| 29 | namespace google |
| 30 | { |
| 31 | namespace ipmi |
| 32 | { |
| 33 | |
Willy Tu | 3b1b427 | 2021-03-02 17:58:10 -0800 | [diff] [blame] | 34 | TEST(FlashSizeCommandTest, ValidRequest) |
| 35 | { |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 36 | std::vector<std::uint8_t> request = {}; |
Willy Tu | 3b1b427 | 2021-03-02 17:58:10 -0800 | [diff] [blame] | 37 | uint32_t flashSize = 5422312; // 0x52BCE8 |
| 38 | |
| 39 | HandlerMock hMock; |
| 40 | EXPECT_CALL(hMock, getFlashSize()).WillOnce(Return(flashSize)); |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 41 | |
| 42 | auto reply = getFlashSize(request, &hMock); |
| 43 | auto result = ValidateReply(reply); |
| 44 | auto& data = result.second; |
| 45 | |
| 46 | EXPECT_EQ(sizeof(struct GetFlashSizeReply), data.size()); |
| 47 | EXPECT_EQ(SysOEMCommands::SysGetFlashSize, result.first); |
| 48 | EXPECT_EQ(0, data[3]); |
| 49 | EXPECT_EQ(0x52, data[2]); |
| 50 | EXPECT_EQ(0xBC, data[1]); |
| 51 | EXPECT_EQ(0xE8, data[0]); |
Willy Tu | 3b1b427 | 2021-03-02 17:58:10 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | } // namespace ipmi |
| 55 | } // namespace google |