add --tmpDir foo option to tests, to allow unittests that want to write/read files
use tmpDir in SkStream tests



git-svn-id: http://skia.googlecode.com/svn/trunk@7851 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tests/skia_test.cpp b/tests/skia_test.cpp
index 18c8c84..e3df2d7 100644
--- a/tests/skia_test.cpp
+++ b/tests/skia_test.cpp
@@ -7,6 +7,7 @@
  */
 #include "SkGraphics.h"
 #include "Test.h"
+#include "SkOSFile.h"
 
 #if SK_SUPPORT_GPU
 #include "GrContext.h"
@@ -82,6 +83,28 @@
     int fIndex, fTotal;
 };
 
+static const char* make_canonical_dir_path(const char* path, SkString* storage) {
+    if (path) {
+        // clean it up so it always has a trailing searator
+        size_t len = strlen(path);
+        if (0 == len) {
+            path = NULL;
+        } else if (SkPATH_SEPARATOR != path[len - 1]) {
+            // resize to len + 1, to make room for searator
+            storage->set(path, len + 1);
+            storage->writable_str()[len] = SkPATH_SEPARATOR;
+            path = storage->c_str();
+        }
+    }
+    return path;
+}
+
+static const char* gTmpDir;
+
+const char* Test::GetTmpDir() {
+    return gTmpDir;
+}
+
 int tool_main(int argc, char** argv);
 int tool_main(int argc, char** argv) {
 #if SK_ENABLE_INST_COUNT
@@ -97,15 +120,32 @@
             ++argv;
             if (argv < stop && **argv) {
                 matchStr = *argv;
+            } else {
+                SkDebugf("no following argument to --match\n");
+                return -1;
+            }
+        } else if (0 == strcmp(*argv, "--tmpDir")) {
+            ++argv;
+            if (argv < stop && **argv) {
+                gTmpDir = *argv;
+            } else {
+                SkDebugf("no following argument to --tmpDir\n");
+                return -1;
             }
         }
     }
 
+    SkString tmpDirStorage;
+    gTmpDir = make_canonical_dir_path(gTmpDir, &tmpDirStorage);
+
     {
         SkString header("Skia UnitTests:");
         if (matchStr) {
             header.appendf(" --match %s", matchStr);
         }
+        if (gTmpDir) {
+            header.appendf(" --tmpDir %s", gTmpDir);
+        }
 #ifdef SK_DEBUG
         header.append(" SK_DEBUG");
 #else