blob: ea44d1a01ca9b0280c4b4c0081b36c35020c6a21 [file] [log] [blame]
// 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 "utility.hpp"
#include <flashupdate/info.hpp>
#include <flashupdate/ops.hpp>
#include <nlohmann/json.hpp>
#include <fstream>
#include <sstream>
#include <string>
#include <gtest/gtest.h>
namespace flashupdate
{
TEST_F(OperationTest, InfoPass)
{
nlohmann::json expectedOutput;
resetInfo();
Args args;
std::string filename = CaseTmpDir() + "/info_test_metadata";
createFakeEeprom(args, filename);
EXPECT_EQ(ops::info(args), expectedOutput.dump());
args.checkStagedVersion = true;
expectedOutput["Staged Version"] = stageVersion.data();
EXPECT_EQ(ops::info(args), expectedOutput.dump());
args.checkActiveVersion = true;
expectedOutput["Active Version"] = activeVersion.data();
EXPECT_EQ(ops::info(args), expectedOutput.dump());
auto findState = info::stateToString.find(
static_cast<uint8_t>(info::UpdateInfo::State::ACTIVATED));
EXPECT_TRUE(findState != info::stateToString.end());
args.checkStageState = true;
expectedOutput["Staged State"] = findState->second;
EXPECT_EQ(ops::info(args), expectedOutput.dump());
args.checkStagedIndex = true;
expectedOutput["Staged Index"] = std::to_string(stagingIndex);
EXPECT_EQ(ops::info(args), expectedOutput.dump());
args.otherInfo = true;
expectedOutput["Stage CR51 Descriptor Hash"] =
"1010101010101010101010101010101010101010101010101010101010101010";
EXPECT_EQ(ops::info(args), expectedOutput.dump());
}
} // namespace flashupdate