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
15 #include "commands.hpp"
16 #include "handler_mock.hpp"
17 #include "helper.hpp"
18 #include "host_power_off.hpp"
19
20 #include <cstdint>
21 #include <cstring>
22 #include <vector>
23
24 #include <gtest/gtest.h>
25
26 namespace google
27 {
28 namespace ipmi
29 {
30
TEST(PowerOffCommandTest,InvalidRequestLength)31 TEST(PowerOffCommandTest, InvalidRequestLength)
32 {
33 std::vector<std::uint8_t> request = {SysOEMCommands::SysHostPowerOff};
34 HandlerMock hMock;
35
36 EXPECT_EQ(::ipmi::responseReqDataLenInvalid(),
37 hostPowerOff(request, &hMock));
38 }
39
TEST(PowerOffCommandTest,ValidRequest)40 TEST(PowerOffCommandTest, ValidRequest)
41 {
42 // Set the dealy to 15 mins
43 std::uint32_t delayValue = 0x384;
44 struct HostPowerOffRequest requestContents;
45 requestContents.delay = delayValue;
46
47 std::vector<std::uint8_t> request(sizeof(requestContents));
48 std::memcpy(request.data(), &requestContents, sizeof(requestContents));
49
50 HandlerMock hMock;
51 EXPECT_CALL(hMock, hostPowerOffDelay(delayValue));
52
53 auto reply = hostPowerOff(request, &hMock);
54 auto result = ValidateReply(reply, false);
55 EXPECT_EQ(SysOEMCommands::SysHostPowerOff, result.first);
56 }
57
58 } // namespace ipmi
59 } // namespace google
60