140fe5222SWilly Tu // Copyright 2021 Google LLC 240fe5222SWilly Tu // 340fe5222SWilly Tu // Licensed under the Apache License, Version 2.0 (the "License"); 440fe5222SWilly Tu // you may not use this file except in compliance with the License. 540fe5222SWilly Tu // You may obtain a copy of the License at 640fe5222SWilly Tu // 740fe5222SWilly Tu // http://www.apache.org/licenses/LICENSE-2.0 840fe5222SWilly Tu // 940fe5222SWilly Tu // Unless required by applicable law or agreed to in writing, software 1040fe5222SWilly Tu // distributed under the License is distributed on an "AS IS" BASIS, 1140fe5222SWilly Tu // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1240fe5222SWilly Tu // See the License for the specific language governing permissions and 1340fe5222SWilly Tu // limitations under the License. 1440fe5222SWilly Tu 15ff3cd8e9SWilly Tu #include "helper.hpp" 16ff3cd8e9SWilly Tu 17ff3cd8e9SWilly Tu #include <ipmid/api-types.hpp> 18*444b5ea4SPatrick Williams 19ff3cd8e9SWilly Tu #include <optional> 20ff3cd8e9SWilly Tu #include <span> 21ff3cd8e9SWilly Tu #include <utility> 22ff3cd8e9SWilly Tu 23ff3cd8e9SWilly Tu namespace google 24ff3cd8e9SWilly Tu { 25ff3cd8e9SWilly Tu namespace ipmi 26ff3cd8e9SWilly Tu { 27ff3cd8e9SWilly Tu 28ff3cd8e9SWilly Tu std::pair<std::uint8_t, std::vector<std::uint8_t>> 29ff3cd8e9SWilly Tu ValidateReply(::ipmi::RspType<std::uint8_t, std::vector<uint8_t>> reply, 30ff3cd8e9SWilly Tu bool hasData) 31ff3cd8e9SWilly Tu { 32ff3cd8e9SWilly Tu // Reply is in the form of 33ff3cd8e9SWilly Tu // std::tuple<ipmi::Cc, std::optional<std::tuple<RetTypes...>>> 34ff3cd8e9SWilly Tu EXPECT_EQ(::ipmi::ccSuccess, std::get<0>(reply)); 35ff3cd8e9SWilly Tu 36ff3cd8e9SWilly Tu auto actualReply = std::get<1>(reply); 37ff3cd8e9SWilly Tu EXPECT_TRUE(actualReply.has_value()); 38ff3cd8e9SWilly Tu 39ff3cd8e9SWilly Tu auto subcommand = std::get<0>(*actualReply); 40ff3cd8e9SWilly Tu auto data = std::get<1>(*actualReply); 41ff3cd8e9SWilly Tu EXPECT_EQ(hasData, !data.empty()); 42ff3cd8e9SWilly Tu 43ff3cd8e9SWilly Tu return std::make_pair(subcommand, hasData ? data : std::vector<uint8_t>{}); 44ff3cd8e9SWilly Tu } 45ff3cd8e9SWilly Tu 46ff3cd8e9SWilly Tu } // namespace ipmi 47ff3cd8e9SWilly Tu } // namespace google 48