1 // Copyright 2018 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <gtest/gtest.h>
6
7 #include <brillo/imageloader/manifest.h>
8
9 namespace brillo {
10 namespace imageloader {
11
12 class ManifestTest : public testing::Test {};
13
TEST_F(ManifestTest,ParseManifest)14 TEST_F(ManifestTest, ParseManifest) {
15 const std::string fs_type = R"("ext4")";
16 const std::string is_removable = R"(true)";
17 const std::string image_sha256_hash =
18 R"("4CF41BD11362CCB4707FB93939DBB5AC48745EDFC9DC8D7702852FFAA81B3B3F")";
19 const std::string table_sha256_hash =
20 R"("0E11DA3D7140C6B95496787F50D15152434EBA22B60443BFA7E054FF4C799276")";
21 const std::string version = R"("9824.0.4")";
22 const std::string manifest_version = R"(1)";
23 const std::string manifest_raw = std::string() + R"(
24 {
25 "fs-type":)" + fs_type + R"(,
26 "is-removable":)" + is_removable +
27 R"(,
28 "image-sha256-hash":)" + image_sha256_hash +
29 R"(,
30 "table-sha256-hash":)" + table_sha256_hash +
31 R"(,
32 "version":)" + version + R"(,
33 "manifest-version":)" + manifest_version +
34 R"(
35 }
36 )";
37 brillo::imageloader::Manifest manifest;
38 // Parse the manifest raw string.
39 ASSERT_TRUE(manifest.ParseManifest(manifest_raw));
40 EXPECT_EQ(manifest.fs_type(), FileSystem::kExt4);
41 EXPECT_EQ(manifest.is_removable(), true);
42 EXPECT_NE(manifest.image_sha256().size(), 0);
43 EXPECT_NE(manifest.table_sha256().size(), 0);
44 EXPECT_NE(manifest.version().size(), 0);
45 EXPECT_EQ(manifest.manifest_version(), 1);
46 }
47
48 } // namespace imageloader
49 } // namespace brillo
50