Pārlūkot izejas kodu

add basic tests for GetTempDir()

Michael Vogt 12 gadi atpakaļ
vecāks
revīzija
a077861ad0
2 mainītis faili ar 14 papildinājumiem un 1 dzēšanām
  1. 1 1
      apt-pkg/contrib/fileutl.cc
  2. 13 0
      test/libapt/fileutl_test.cc

+ 1 - 1
apt-pkg/contrib/fileutl.cc

@@ -1839,7 +1839,7 @@ std::string GetTempDir()
 
 
    // check that tmpdir is set and exists
    // check that tmpdir is set and exists
    struct stat st;
    struct stat st;
-   if (!tmpdir || stat(tmpdir, &st) != 0)
+   if (!tmpdir || strlen(tmpdir) == 0 || stat(tmpdir, &st) != 0)
       tmpdir = "/tmp";
       tmpdir = "/tmp";
 
 
    return string(tmpdir);
    return string(tmpdir);

+ 13 - 0
test/libapt/fileutl_test.cc

@@ -38,5 +38,18 @@ int main(int argc,char *argv[])
       return 1;
       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;
    return 0;
 }
 }