blob: 6a90fc6913c75ebee017a03e6247e78814022ad2 [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
linyuny8cfa4c42021-06-16 13:53:08 -070015#include "commands.hpp"
16#include "handler_mock.hpp"
Willy Tuff3cd8e2021-09-14 22:49:55 -070017#include "helper.hpp"
linyuny8cfa4c42021-06-16 13:53:08 -070018#include "host_power_off.hpp"
19
20#include <cstdint>
21#include <cstring>
22#include <vector>
23
24#include <gtest/gtest.h>
25
linyuny8cfa4c42021-06-16 13:53:08 -070026namespace google
27{
28namespace ipmi
29{
30
31TEST(PowerOffCommandTest, InvalidRequestLength)
32{
33 std::vector<std::uint8_t> request = {SysOEMCommands::SysHostPowerOff};
linyuny8cfa4c42021-06-16 13:53:08 -070034 HandlerMock hMock;
Willy Tuff3cd8e2021-09-14 22:49:55 -070035
36 EXPECT_EQ(::ipmi::responseReqDataLenInvalid(),
37 hostPowerOff(request, &hMock));
linyuny8cfa4c42021-06-16 13:53:08 -070038}
39
40TEST(PowerOffCommandTest, ValidRequest)
41{
42 // Set the dealy to 15 mins
43 std::uint32_t delayValue = 0x384;
44 struct HostPowerOffRequest requestContents;
linyuny8cfa4c42021-06-16 13:53:08 -070045 requestContents.delay = delayValue;
46
47 std::vector<std::uint8_t> request(sizeof(requestContents));
48 std::memcpy(request.data(), &requestContents, sizeof(requestContents));
linyuny8cfa4c42021-06-16 13:53:08 -070049
50 HandlerMock hMock;
51 EXPECT_CALL(hMock, hostPowerOffDelay(delayValue));
Willy Tuff3cd8e2021-09-14 22:49:55 -070052
53 auto reply = hostPowerOff(request, &hMock);
54 auto result = ValidateReply(reply, false);
55 EXPECT_EQ(SysOEMCommands::SysHostPowerOff, result.first);
linyuny8cfa4c42021-06-16 13:53:08 -070056}
57
58} // namespace ipmi
59} // namespace google