1a2056e9cSWilly Tu // Copyright 2021 Google LLC
2a2056e9cSWilly Tu //
3a2056e9cSWilly Tu // Licensed under the Apache License, Version 2.0 (the "License");
4a2056e9cSWilly Tu // you may not use this file except in compliance with the License.
5a2056e9cSWilly Tu // You may obtain a copy of the License at
6a2056e9cSWilly Tu //
7a2056e9cSWilly Tu //      http://www.apache.org/licenses/LICENSE-2.0
8a2056e9cSWilly Tu //
9a2056e9cSWilly Tu // Unless required by applicable law or agreed to in writing, software
10a2056e9cSWilly Tu // distributed under the License is distributed on an "AS IS" BASIS,
11a2056e9cSWilly Tu // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12a2056e9cSWilly Tu // See the License for the specific language governing permissions and
13a2056e9cSWilly Tu // limitations under the License.
14a2056e9cSWilly Tu 
158cfa4c44Slinyuny #include "commands.hpp"
168cfa4c44Slinyuny #include "handler_mock.hpp"
17*ff3cd8e9SWilly Tu #include "helper.hpp"
188cfa4c44Slinyuny #include "host_power_off.hpp"
198cfa4c44Slinyuny 
208cfa4c44Slinyuny #include <cstdint>
218cfa4c44Slinyuny #include <cstring>
228cfa4c44Slinyuny #include <vector>
238cfa4c44Slinyuny 
248cfa4c44Slinyuny #include <gtest/gtest.h>
258cfa4c44Slinyuny 
268cfa4c44Slinyuny namespace google
278cfa4c44Slinyuny {
288cfa4c44Slinyuny namespace ipmi
298cfa4c44Slinyuny {
308cfa4c44Slinyuny 
TEST(PowerOffCommandTest,InvalidRequestLength)318cfa4c44Slinyuny TEST(PowerOffCommandTest, InvalidRequestLength)
328cfa4c44Slinyuny {
338cfa4c44Slinyuny     std::vector<std::uint8_t> request = {SysOEMCommands::SysHostPowerOff};
348cfa4c44Slinyuny     HandlerMock hMock;
35*ff3cd8e9SWilly Tu 
36*ff3cd8e9SWilly Tu     EXPECT_EQ(::ipmi::responseReqDataLenInvalid(),
37*ff3cd8e9SWilly Tu               hostPowerOff(request, &hMock));
388cfa4c44Slinyuny }
398cfa4c44Slinyuny 
TEST(PowerOffCommandTest,ValidRequest)408cfa4c44Slinyuny TEST(PowerOffCommandTest, ValidRequest)
418cfa4c44Slinyuny {
428cfa4c44Slinyuny     // Set the dealy to 15 mins
438cfa4c44Slinyuny     std::uint32_t delayValue = 0x384;
448cfa4c44Slinyuny     struct HostPowerOffRequest requestContents;
458cfa4c44Slinyuny     requestContents.delay = delayValue;
468cfa4c44Slinyuny 
478cfa4c44Slinyuny     std::vector<std::uint8_t> request(sizeof(requestContents));
488cfa4c44Slinyuny     std::memcpy(request.data(), &requestContents, sizeof(requestContents));
498cfa4c44Slinyuny 
508cfa4c44Slinyuny     HandlerMock hMock;
518cfa4c44Slinyuny     EXPECT_CALL(hMock, hostPowerOffDelay(delayValue));
52*ff3cd8e9SWilly Tu 
53*ff3cd8e9SWilly Tu     auto reply = hostPowerOff(request, &hMock);
54*ff3cd8e9SWilly Tu     auto result = ValidateReply(reply, false);
55*ff3cd8e9SWilly Tu     EXPECT_EQ(SysOEMCommands::SysHostPowerOff, result.first);
568cfa4c44Slinyuny }
578cfa4c44Slinyuny 
588cfa4c44Slinyuny } // namespace ipmi
598cfa4c44Slinyuny } // namespace google
60