Pass the size of the new file to the PatchWriterInterface::Init()

Most patch formats include the size of the new file in the header.
To help streaming the patch to disk while generating it, this CL
passes the size of the new file to the patch writer on initialization.

To do this, we also move the Init() call to the patch writer to the
DiffEncoder, which makes more sense since the Close() call is also made
from the DiffEnconder.

Bug: None
Test: Updated tests to check for this value.
Change-Id: Idfaedbd492d68ab6e6cb2c1cb3883947f068c3aa
diff --git a/diff_encoder_unittest.cc b/diff_encoder_unittest.cc
index e3b3747..15e4331 100644
--- a/diff_encoder_unittest.cc
+++ b/diff_encoder_unittest.cc
@@ -27,7 +27,6 @@
 class DiffEncoderTest : public testing::Test {
  protected:
   void SetUp() {
-    EXPECT_TRUE(fake_patch_.Init());
     // By default, set the encoder to kHelloWorld to kHelloWorld.
     diff_encoder_.reset(new DiffEncoder(&fake_patch_, kHelloWorld,
                                         sizeof(kHelloWorld), kHelloWorld,
@@ -40,6 +39,7 @@
 
 TEST_F(DiffEncoderTest, CreateEmptyPatchTest) {
   diff_encoder_.reset(new DiffEncoder(&fake_patch_, nullptr, 0, nullptr, 0));
+  EXPECT_TRUE(diff_encoder_->Init());
   EXPECT_TRUE(diff_encoder_->Close());
 
   // Both diff and extra stream must be empty stream, and not control entries.
@@ -51,6 +51,7 @@
 TEST_F(DiffEncoderTest, AllInExtraStreamTest) {
   diff_encoder_.reset(new DiffEncoder(&fake_patch_, nullptr, 0, kHelloWorld,
                                       sizeof(kHelloWorld)));
+  EXPECT_TRUE(diff_encoder_->Init());
 
   // Write to the extra stream in two parts: first 5 bytes, then the rest.
   EXPECT_TRUE(diff_encoder_->AddControlEntry(ControlEntry(0, 5, 0)));
@@ -66,6 +67,7 @@
 }
 
 TEST_F(DiffEncoderTest, AllInDiffStreamTest) {
+  EXPECT_TRUE(diff_encoder_->Init());
   EXPECT_TRUE(
       diff_encoder_->AddControlEntry(ControlEntry(sizeof(kHelloWorld), 0, 0)));
   EXPECT_TRUE(diff_encoder_->Close());
@@ -76,6 +78,7 @@
 }
 
 TEST_F(DiffEncoderTest, OldPosNegativeErrorTest) {
+  EXPECT_TRUE(diff_encoder_->Init());
   // Referencing negative values in oldpos is fine, until you use them.
   EXPECT_TRUE(diff_encoder_->AddControlEntry(ControlEntry(0, 0, -5)));
   EXPECT_TRUE(diff_encoder_->AddControlEntry(ControlEntry(0, 0, 2)));
@@ -84,6 +87,7 @@
 
 // Test that using an oldpos past the end of the file fails.
 TEST_F(DiffEncoderTest, OldPosTooBigErrorTest) {
+  EXPECT_TRUE(diff_encoder_->Init());
   EXPECT_TRUE(
       diff_encoder_->AddControlEntry(ControlEntry(0, 0, sizeof(kHelloWorld))));
   EXPECT_FALSE(diff_encoder_->AddControlEntry(ControlEntry(1, 0, 0)));
@@ -92,6 +96,7 @@
 // Test that diffing against a section of the old file past the end of the file
 // fails.
 TEST_F(DiffEncoderTest, OldPosPlusSizeTooBigErrorTest) {
+  EXPECT_TRUE(diff_encoder_->Init());
   // The oldpos is set to a range inside the word, the we try to copy past the
   // end of it.
   EXPECT_TRUE(diff_encoder_->AddControlEntry(
@@ -101,6 +106,7 @@
 }
 
 TEST_F(DiffEncoderTest, ExtraStreamTooBigErrorTest) {
+  EXPECT_TRUE(diff_encoder_->Init());
   EXPECT_TRUE(diff_encoder_->AddControlEntry(ControlEntry(3, 0, 0)));
   // This writes too many bytes in the stream because we already have 3 bytes.
   EXPECT_FALSE(