unit_tests: fix notify unit test when /tmp does not exist

This commit is contained in:
moneromooo-monero 2018-10-27 11:19:28 +00:00
parent 4cbb476cd1
commit f48db530be
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3

View file

@ -44,7 +44,14 @@ TEST(notify, works)
#ifdef __GLIBC__ #ifdef __GLIBC__
mode_t prevmode = umask(077); mode_t prevmode = umask(077);
#endif #endif
char name_template[] = "/tmp/monero-notify-unit-test-XXXXXX"; const char *tmp = getenv("TEMP");
if (!tmp)
tmp = "/tmp";
static const char *filename = "monero-notify-unit-test-XXXXXX";
const size_t len = strlen(tmp) + 1 + strlen(filename);
char *name_template = (char*)malloc(len + 1);
ASSERT_TRUE(name_template != NULL);
snprintf(name_template, len + 1, "%s/%s", tmp, filename);
int fd = mkstemp(name_template); int fd = mkstemp(name_template);
#ifdef __GLIBC__ #ifdef __GLIBC__
umask(prevmode); umask(prevmode);
@ -68,4 +75,5 @@ TEST(notify, works)
ASSERT_TRUE(s == "1111111111111111111111111111111111111111111111111111111111111111"); ASSERT_TRUE(s == "1111111111111111111111111111111111111111111111111111111111111111");
boost::filesystem::remove(name_template); boost::filesystem::remove(name_template);
free(name_template);
} }