summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2013-12-23 13:35:08 +0100
committerMichael Vogt <mvo@debian.org>2013-12-23 13:35:08 +0100
commita077861ad0f2e643307c2380a060a3b11914aa34 (patch)
treeca2045f4fa9be147e8e41a5530ecc3314dcf6546
parent68e0172140872d8044b3c768a6bea3ac58d426c4 (diff)
add basic tests for GetTempDir()
-rw-r--r--apt-pkg/contrib/fileutl.cc2
-rw-r--r--test/libapt/fileutl_test.cc13
2 files changed, 14 insertions, 1 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 847d8b47f..efbf7aaf4 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -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);
diff --git a/test/libapt/fileutl_test.cc b/test/libapt/fileutl_test.cc
index b6b8ac579..462bdefd9 100644
--- a/test/libapt/fileutl_test.cc
+++ b/test/libapt/fileutl_test.cc
@@ -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;
}