]> git.saurik.com Git - apt.git/commitdiff
add basic tests for GetTempDir()
authorMichael Vogt <mvo@debian.org>
Mon, 23 Dec 2013 12:35:08 +0000 (13:35 +0100)
committerMichael Vogt <mvo@debian.org>
Mon, 23 Dec 2013 12:35:08 +0000 (13:35 +0100)
apt-pkg/contrib/fileutl.cc
test/libapt/fileutl_test.cc

index 847d8b47ff70605d61d05a2449696c53169b3504..efbf7aaf4c2300ac61d309c63465efb67a4430b3 100644 (file)
@@ -1839,7 +1839,7 @@ std::string GetTempDir()
 
    // check that tmpdir is set and exists
    struct stat st;
-   if (!tmpdir || stat(tmpdir, &st) != 0)
+   if (!tmpdir || strlen(tmpdir) == 0 || stat(tmpdir, &st) != 0)
       tmpdir = "/tmp";
 
    return string(tmpdir);
index b6b8ac579be0df7e7da909f6ca6e41f9ea06e139..462bdefd9ee225c53932f7e74dcf15c36412b553 100644 (file)
@@ -38,5 +38,18 @@ int main(int argc,char *argv[])
       return 1;
    }
 
+   // GetTempDir()
+   unsetenv("TMPDIR");
+   equals(GetTempDir(), "/tmp");
+
+   setenv("TMPDIR", "", 1);
+   equals(GetTempDir(), "/tmp");
+
+   setenv("TMPDIR", "/not-there-no-really-not", 1);
+   equals(GetTempDir(), "/tmp");
+
+   setenv("TMPDIR", "/usr", 1);
+   equals(GetTempDir(), "/usr");
+
    return 0;
 }