Tweak ObbFile class

* Move error messages around to clarify the errors.

* Add extra error check when reading a file.

* Seek to the end of a file when writing the signature so the users of
  the API don't have to remember to do it.

Change-Id: I2337051b9f9fa8147c5900237deec790dcd92436
diff --git a/libs/utils/tests/ObbFile_test.cpp b/libs/utils/tests/ObbFile_test.cpp
index 05aaf08..29bb70a 100644
--- a/libs/utils/tests/ObbFile_test.cpp
+++ b/libs/utils/tests/ObbFile_test.cpp
@@ -22,6 +22,8 @@
 
 #include <gtest/gtest.h>
 
+#include <fcntl.h>
+
 namespace android {
 
 #define TEST_FILENAME "/test.obb"
@@ -39,6 +41,11 @@
         const int totalLen = strlen(mExternalStorage) + strlen(TEST_FILENAME) + 1;
         mFileName = new char[totalLen];
         snprintf(mFileName, totalLen, "%s%s", mExternalStorage, TEST_FILENAME);
+
+        int fd = ::open(mFileName, O_CREAT | O_TRUNC);
+        if (fd < 0) {
+            FAIL() << "Couldn't create " << mFileName << " for tests";
+        }
     }
 
     virtual void TearDown() {
@@ -46,8 +53,8 @@
 };
 
 TEST_F(ObbFileTest, ReadFailure) {
-	EXPECT_FALSE(mObbFile->readFrom(-1))
-			<< "No failure on invalid file descriptor";
+    EXPECT_FALSE(mObbFile->readFrom(-1))
+            << "No failure on invalid file descriptor";
 }
 
 TEST_F(ObbFileTest, WriteThenRead) {
@@ -66,10 +73,10 @@
             << "couldn't read from fake .obb file";
 
     EXPECT_EQ(versionNum, mObbFile->getVersion())
-			<< "version didn't come out the same as it went in";
+            << "version didn't come out the same as it went in";
     const char* currentPackageName = mObbFile->getPackageName().string();
     EXPECT_STREQ(packageName, currentPackageName)
-			<< "package name didn't come out the same as it went in";
+            << "package name didn't come out the same as it went in";
 }
 
 }