// 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 "commands.hpp"
#include "errors.hpp"
#include "handler_mock.hpp"
#include "helper.hpp"
#include "machine_name.hpp"

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

#include <gtest/gtest.h>

#define MAX_IPMI_BUFFER 64

using ::testing::Return;
using ::testing::Throw;

namespace google
{
namespace ipmi
{

TEST(MachineNameCommandTest, InvalidFile)
{
    std::vector<std::uint8_t> request = {};
    ::testing::StrictMock<HandlerMock> hMock;
    EXPECT_CALL(hMock, getMachineName()).WillOnce(Throw(IpmiException(5)));

    EXPECT_EQ(::ipmi::response(5), getMachineName(request, &hMock));
}

TEST(MachineNameCommandTest, CachesValidRequest)
{
    std::vector<std::uint8_t> request = {};
    const std::string ret = "Machine";

    ::testing::StrictMock<HandlerMock> hMock;
    EXPECT_CALL(hMock, getMachineName()).WillOnce(Return(ret));

    auto reply = getMachineName(request, &hMock);
    auto result = ValidateReply(reply);
    auto& data = result.second;

    EXPECT_EQ(sizeof(GetMachineNameReply) + ret.size(), data.size());
    EXPECT_EQ(SysOEMCommands::SysMachineName, result.first);
    EXPECT_EQ(ret.length(), data[0]);
    EXPECT_EQ(ret.data(),
              std::string(data.begin() + sizeof(struct GetMachineNameReply),
                          data.end()));
}

} // namespace ipmi
} // namespace google
