blob: c2f3bccccd294aa046084a685f9c432856c52d02 [file] [log] [blame]
// Copyright 2022 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 <stdlib.h>
#include <flashupdate/info.hpp>
#include <flashupdate/ops.hpp>
#include <nlohmann/json.hpp>
#include <string>
#include <gtest/gtest.h>
namespace flashupdate
{
TEST_F(OperationTest, UpdateVersionInvalidVersion)
{
Args args;
args.version = "hello_world";
EXPECT_THROW(
try { ops::updateVersion(args); } catch (const std::runtime_error& e) {
EXPECT_STREQ(e.what(), "failed to convert string `hello_world` to "
"uint32_t: Invalid argument");
throw;
},
std::runtime_error);
}
TEST_F(OperationTest, UpdateVersionPass)
{
resetInfo();
Args args;
nlohmann::json expectedOutput;
std::string filename = CaseTmpDir() + "/update_version_eeprom";
createFakeEeprom(args, filename);
// Update Primary Version
args.primary = true;
args.version = "10.10.9.9";
args.checkActiveVersion = true;
args.checkStagedVersion = false;
expectedOutput["Active Version"] = args.version;
EXPECT_EQ(ops::updateVersion(args), expectedOutput.dump());
// Update Secondary Version
args.primary = false;
args.version = "5.5.6.6";
args.checkStagedVersion = true;
expectedOutput["Staged Version"] = args.version;
EXPECT_EQ(ops::updateVersion(args), expectedOutput.dump());
}
} // namespace flashupdate