diff options
author | Pawel Bylica <chfast@gmail.com> | 2015-10-16 09:08:59 +0000 |
---|---|---|
committer | Pawel Bylica <chfast@gmail.com> | 2015-10-16 09:08:59 +0000 |
commit | 7187e4bba90943c86e3569519b997c1d6f40c72f (patch) | |
tree | 75158fd7e584674ab7b7c0055eff2f6b4b5725a9 /llvm/unittests/Support/Path.cpp | |
parent | 3f072ef82c705a67dd5c91051acf08e698767e95 (diff) | |
download | bcm5719-llvm-7187e4bba90943c86e3569519b997c1d6f40c72f.tar.gz bcm5719-llvm-7187e4bba90943c86e3569519b997c1d6f40c72f.zip |
Use Windows Vista API to get the user's home directory
Summary: This patch replaces usage of deprecated SHGetFolderPathW with SHGetKnownFolderPath. The usage of SHGetKnownFolderPath is wrapped to allow queries for other "known" folders in the near future.
Reviewers: aaron.ballman, gbedwell
Subscribers: chapuni, llvm-commits
Differential Revision: http://reviews.llvm.org/D13753
llvm-svn: 250501
Diffstat (limited to 'llvm/unittests/Support/Path.cpp')
-rw-r--r-- | llvm/unittests/Support/Path.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp index 5d883c4041c..416412f327c 100644 --- a/llvm/unittests/Support/Path.cpp +++ b/llvm/unittests/Support/Path.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/Path.h" +#include "llvm/Support/ConvertUTF.h" #include "llvm/Support/Errc.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" @@ -299,16 +300,19 @@ TEST(Support, AbsolutePathIteratorEnd) { } TEST(Support, HomeDirectory) { -#ifdef LLVM_ON_UNIX - // This test only makes sense on Unix if $HOME is set. - if (::getenv("HOME")) { -#endif - SmallString<128> HomeDir; - EXPECT_TRUE(path::home_directory(HomeDir)); - EXPECT_FALSE(HomeDir.empty()); -#ifdef LLVM_ON_UNIX - } +#ifdef LLVM_ON_WIN32 + wchar_t *path = ::_wgetenv(L"USERPROFILE"); + auto pathLen = ::wcslen(path); + ArrayRef<char> ref{reinterpret_cast<char*>(path), pathLen * sizeof(wchar_t)}; + std::string expected; + convertUTF16ToUTF8String(ref, expected); +#else + std::string expected{::getenv("HOME")}; #endif + SmallString<128> HomeDir; + auto status = path::home_directory(HomeDir); + EXPECT_TRUE(status ^ HomeDir.empty()); + EXPECT_EQ(expected, HomeDir); } class FileSystemTest : public testing::Test { |