• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 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 "bspatch.h"
6 
7 #include <unistd.h>
8 
9 #include <gtest/gtest.h>
10 
11 #include "test_utils.h"
12 
13 namespace bsdiff {
14 
15 class BspatchTest : public testing::Test {
16  protected:
BspatchTest()17   BspatchTest()
18       : old_file_("bsdiff_oldfile.XXXXXX"),
19         new_file_("bsdiff_newfile.XXXXXX") {}
20 
21   test_utils::ScopedTempFile old_file_;
22   test_utils::ScopedTempFile new_file_;
23 };
24 
TEST_F(BspatchTest,IsOverlapping)25 TEST_F(BspatchTest, IsOverlapping) {
26   const char* old_filename = old_file_.c_str();
27   const char* new_filename = new_file_.c_str();
28   EXPECT_FALSE(IsOverlapping(old_filename, "does-not-exist", {}, {}));
29   EXPECT_FALSE(IsOverlapping(old_filename, new_filename, {}, {}));
30   EXPECT_EQ(0, unlink(new_filename));
31   EXPECT_EQ(0, symlink(old_filename, new_filename));
32   EXPECT_TRUE(IsOverlapping(old_filename, new_filename, {}, {}));
33   EXPECT_TRUE(IsOverlapping(old_filename, old_filename, {}, {}));
34   EXPECT_FALSE(IsOverlapping(old_filename, old_filename, {{0, 1}}, {{1, 1}}));
35   EXPECT_FALSE(IsOverlapping(old_filename, old_filename, {{2, 1}}, {{1, 1}}));
36   EXPECT_TRUE(IsOverlapping(old_filename, old_filename, {{0, 1}}, {{0, 1}}));
37   EXPECT_TRUE(IsOverlapping(old_filename, old_filename, {{0, 4}}, {{2, 1}}));
38   EXPECT_TRUE(IsOverlapping(old_filename, old_filename, {{1, 1}}, {{0, 2}}));
39   EXPECT_TRUE(IsOverlapping(old_filename, old_filename, {{3, 2}}, {{2, 2}}));
40 }
41 
42 }  // namespace bsdiff
43