diff options
author | Alex Deymo <deymo@chromium.org> | 2015-06-03 19:06:50 +0200 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-06-04 10:43:16 +0000 |
commit | 5c6c65570013bbdbd67f9bf6391dd295ef5b5ee6 (patch) | |
tree | c2655ce831e0428ff87d3c065a9702b9b3564b82 /payload_generator/extent_utils_unittest.cc | |
parent | cef5cd6acf26b518523511f6d633a730baef4d7e (diff) |
update_engine: Split Extent utils from graph_utils.
"Graph" related utils should only concern parts of the code using the
inplace generator, since other generators don't use a dependency graph.
This patch splits the Extent related utils from the graph related ones
creating a new extent_utils.h file.
BUG=None
TEST=unittest still pass.
Change-Id: I0941698b0a47a6cc222e8dc062fc54eb3cdf4de2
Reviewed-on: https://chromium-review.googlesource.com/274899
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
Diffstat (limited to 'payload_generator/extent_utils_unittest.cc')
-rw-r--r-- | payload_generator/extent_utils_unittest.cc | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/payload_generator/extent_utils_unittest.cc b/payload_generator/extent_utils_unittest.cc new file mode 100644 index 00000000..fe1d000a --- /dev/null +++ b/payload_generator/extent_utils_unittest.cc @@ -0,0 +1,64 @@ +// Copyright 2015 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "update_engine/payload_generator/extent_utils.h" + +#include <utility> +#include <vector> + +#include <gtest/gtest.h> + +#include "update_engine/extent_ranges.h" +#include "update_engine/payload_constants.h" + +using std::vector; + +namespace chromeos_update_engine { + +class ExtentUtilsTest : public ::testing::Test {}; + +TEST(ExtentUtilsTest, AppendSparseToExtentsTest) { + vector<Extent> extents; + + EXPECT_EQ(0, extents.size()); + AppendBlockToExtents(&extents, kSparseHole); + EXPECT_EQ(1, extents.size()); + AppendBlockToExtents(&extents, 0); + EXPECT_EQ(2, extents.size()); + AppendBlockToExtents(&extents, kSparseHole); + AppendBlockToExtents(&extents, kSparseHole); + + ASSERT_EQ(3, extents.size()); + EXPECT_EQ(kSparseHole, extents[0].start_block()); + EXPECT_EQ(1, extents[0].num_blocks()); + EXPECT_EQ(0, extents[1].start_block()); + EXPECT_EQ(1, extents[1].num_blocks()); + EXPECT_EQ(kSparseHole, extents[2].start_block()); + EXPECT_EQ(2, extents[2].num_blocks()); +} + +TEST(ExtentUtilsTest, BlocksInExtentsTest) { + { + vector<Extent> extents; + EXPECT_EQ(0, BlocksInExtents(extents)); + extents.push_back(ExtentForRange(0, 1)); + EXPECT_EQ(1, BlocksInExtents(extents)); + extents.push_back(ExtentForRange(23, 55)); + EXPECT_EQ(56, BlocksInExtents(extents)); + extents.push_back(ExtentForRange(1, 2)); + EXPECT_EQ(58, BlocksInExtents(extents)); + } + { + google::protobuf::RepeatedPtrField<Extent> extents; + EXPECT_EQ(0, BlocksInExtents(extents)); + *extents.Add() = ExtentForRange(0, 1); + EXPECT_EQ(1, BlocksInExtents(extents)); + *extents.Add() = ExtentForRange(23, 55); + EXPECT_EQ(56, BlocksInExtents(extents)); + *extents.Add() = ExtentForRange(1, 2); + EXPECT_EQ(58, BlocksInExtents(extents)); + } +} + +} // namespace chromeos_update_engine |