Add gtest unittest framework.

bsdiff and bspatch are in C and had no unittest. This patch keeps
those programs as C code, but adds the C++ gtest unittest framework
to allow testing them. Two simple unittests added to validate that the
unittests work.

BUG=None
TEST=make test; ./unittests

Change-Id: I8bca6b0c6bc5d5880464183d50a602c9886d20d0
diff --git a/bsdiff_unittest.cc b/bsdiff_unittest.cc
new file mode 100644
index 0000000..9b4cd53
--- /dev/null
+++ b/bsdiff_unittest.cc
@@ -0,0 +1,60 @@
+// 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 "bsdiff.h"
+
+#include <gtest/gtest.h>
+#include <string>
+#include <vector>
+
+#include "test_utils.h"
+
+using std::string;
+using std::vector;
+using test_utils::BsdiffPatchFile;
+
+class BsdiffTest : public testing::Test {
+ protected:
+  BsdiffTest()
+    : old_file_("bsdiff_oldfile.XXXXXX"),
+      new_file_("bsdiff_newfile.XXXXXX"),
+      patch_file_("bsdiff_patchfile.XXXXXX") {
+  }
+  ~BsdiffTest() override {}
+
+  test_utils::ScopedTempFile old_file_;
+  test_utils::ScopedTempFile new_file_;
+  test_utils::ScopedTempFile patch_file_;
+};
+
+// Check that a file with no changes has a very small patch (no extra data).
+TEST_F(BsdiffTest, EqualEmptyFiles) {
+  // Empty old and new files.
+  EXPECT_EQ(0, bsdiff(old_file_.filename().c_str(),
+                      new_file_.filename().c_str(),
+                      patch_file_.filename().c_str()));
+  BsdiffPatchFile patch;
+  EXPECT_TRUE(patch.LoadFromFile(patch_file_.filename()));
+  EXPECT_TRUE(patch.IsValid());
+
+  // An empty bz2 file will have 14 bytes.
+  EXPECT_EQ(14, patch.diff_len);
+  EXPECT_EQ(14, patch.extra_len);
+}
+
+TEST_F(BsdiffTest, EqualSmallFiles) {
+  string some_text = "Hello world!";
+  vector<uint8_t> vec_some_text(some_text.begin(), some_text.end());
+  test_utils::WriteFile(old_file_.filename(), vec_some_text);
+  EXPECT_EQ(0, bsdiff(old_file_.filename().c_str(),
+                      new_file_.filename().c_str(),
+                      patch_file_.filename().c_str()));
+  BsdiffPatchFile patch;
+  EXPECT_TRUE(patch.LoadFromFile(patch_file_.filename()));
+  EXPECT_TRUE(patch.IsValid());
+
+  // An empty bz2 file will have 14 bytes.
+  EXPECT_EQ(14, patch.diff_len);
+  EXPECT_EQ(14, patch.extra_len);
+}