// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "cable.hpp"
#include "commands.hpp"
#include "handler_mock.hpp"

#include <cstdint>
#include <cstring>
#include <vector>

#include <gtest/gtest.h>

#define MAX_IPMI_BUFFER 64

using ::testing::Return;
using ::testing::StrEq;

namespace google
{
namespace ipmi
{

TEST(CableCommandTest, RequestTooSmall)
{
    std::vector<std::uint8_t> request = {SysOEMCommands::SysCableCheck};
    size_t dataLen = request.size();
    std::uint8_t reply[MAX_IPMI_BUFFER];

    HandlerMock hMock;

    EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID,
              cableCheck(request.data(), reply, &dataLen, &hMock));
}

TEST(CableCommandTest, FailsLengthSanityCheck)
{
    // Minimum is three bytes, but a length of zero for the string is invalid.
    std::vector<std::uint8_t> request = {SysOEMCommands::SysCableCheck, 0x00,
                                         'a'};

    size_t dataLen = request.size();
    std::uint8_t reply[MAX_IPMI_BUFFER];

    HandlerMock hMock;

    EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID,
              cableCheck(request.data(), reply, &dataLen, &hMock));
}

TEST(CableCommandTest, LengthTooLongForPacket)
{
    // The length of a the string, as specified is longer than string provided.
    std::vector<std::uint8_t> request = {SysOEMCommands::SysCableCheck, 0x02,
                                         'a'};

    size_t dataLen = request.size();
    std::uint8_t reply[MAX_IPMI_BUFFER];

    HandlerMock hMock;

    EXPECT_EQ(IPMI_CC_REQ_DATA_LEN_INVALID,
              cableCheck(request.data(), reply, &dataLen, &hMock));
}

TEST(CableCommandTest, ValidRequestValidReturn)
{
    std::vector<std::uint8_t> request = {SysOEMCommands::SysCableCheck, 0x01,
                                         'a'};

    size_t dataLen = request.size();
    std::uint8_t reply[MAX_IPMI_BUFFER];

    HandlerMock hMock;

    EXPECT_CALL(hMock, getRxPackets(StrEq("a"))).WillOnce(Return(0));
    EXPECT_EQ(IPMI_CC_OK, cableCheck(request.data(), reply, &dataLen, &hMock));

    // Check results.
    struct CableReply expectedReply, actualReply;
    expectedReply.subcommand = SysOEMCommands::SysCableCheck;
    expectedReply.value = 0;

    EXPECT_EQ(sizeof(expectedReply), dataLen);
    std::memcpy(&actualReply, reply, dataLen);

    EXPECT_EQ(expectedReply.subcommand, actualReply.subcommand);
    EXPECT_EQ(expectedReply.value, actualReply.value);
}

} // namespace ipmi
} // namespace google
