blob: 7b7e8430015bdde2659e56460ed6b8a33b5f9292 [file] [log] [blame]
Willy Tua2056e92021-10-10 13:36:16 -07001// 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
Patrick Venture0e9aae52020-08-13 13:07:09 -070015#include "commands.hpp"
Patrick Venture07f85152019-03-15 21:36:56 -070016#include "entity_name.hpp"
17#include "handler_mock.hpp"
Willy Tuff3cd8e2021-09-14 22:49:55 -070018#include "helper.hpp"
Patrick Venture07f85152019-03-15 21:36:56 -070019
20#include <cstdint>
21#include <cstring>
22#include <string>
23#include <vector>
24
25#include <gtest/gtest.h>
26
27#define MAX_IPMI_BUFFER 64
28
29using ::testing::Return;
30
31namespace google
32{
33namespace ipmi
34{
35
36TEST(EntityNameCommandTest, InvalidCommandLength)
37{
38 // GetEntityNameRequest is three bytes, let's send 2.
Willy Tuff3cd8e2021-09-14 22:49:55 -070039 std::vector<std::uint8_t> request = {0x01};
Patrick Venture07f85152019-03-15 21:36:56 -070040 HandlerMock hMock;
Willy Tuff3cd8e2021-09-14 22:49:55 -070041
42 EXPECT_EQ(::ipmi::responseReqDataLenInvalid(),
43 getEntityName(request, &hMock));
Patrick Venture07f85152019-03-15 21:36:56 -070044}
45
46TEST(EntityNameCommandTest, ValidRequest)
47{
48 std::uint8_t entityId = 3;
49 std::uint8_t entityInstance = 5;
Willy Tuff3cd8e2021-09-14 22:49:55 -070050 std::vector<std::uint8_t> request = {entityId, entityInstance};
Patrick Venture07f85152019-03-15 21:36:56 -070051 std::string entityName = "asdf";
52
53 HandlerMock hMock;
54 EXPECT_CALL(hMock, getEntityName(entityId, entityInstance))
55 .WillOnce(Return(entityName));
Willy Tuff3cd8e2021-09-14 22:49:55 -070056
57 auto reply = getEntityName(request, &hMock);
58 auto result = ValidateReply(reply);
59 auto& data = result.second;
60
61 EXPECT_EQ(sizeof(GetEntityNameReply) + entityName.size(), data.size());
62 EXPECT_EQ(SysOEMCommands::SysEntityName, result.first);
63 EXPECT_EQ(entityName.length(), data[0]);
64 EXPECT_EQ(entityName.data(),
65 std::string(data.begin() + sizeof(struct GetEntityNameReply),
66 data.end()));
Patrick Venture07f85152019-03-15 21:36:56 -070067}
68
69} // namespace ipmi
70} // namespace google