2018-05-17 06:34:01 +02:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <cpp-utils/system/homedir.h>
|
|
|
|
#include <cpp-utils/tempfile/TempDir.h>
|
|
|
|
|
|
|
|
using cpputils::system::HomeDirectory;
|
|
|
|
using cpputils::system::FakeHomeDirectoryRAII;
|
|
|
|
using cpputils::system::FakeTempHomeDirectoryRAII;
|
|
|
|
using cpputils::TempDir;
|
|
|
|
|
|
|
|
namespace bf = boost::filesystem;
|
|
|
|
|
|
|
|
TEST(HomedirTest, HomedirExists) {
|
|
|
|
EXPECT_TRUE(bf::exists(HomeDirectory::get()));
|
|
|
|
}
|
|
|
|
|
2018-05-19 08:00:37 +02:00
|
|
|
TEST(HomedirTest, AppDataDirIsValid) {
|
|
|
|
auto dir = HomeDirectory::getXDGDataDir();
|
|
|
|
EXPECT_FALSE(dir.empty());
|
2018-05-19 10:19:46 +02:00
|
|
|
EXPECT_GE(std::distance(dir.begin(), dir.end()), 2u); // has at least two components
|
2018-05-19 08:00:37 +02:00
|
|
|
for(const auto& component : dir) {
|
2018-05-21 01:20:38 +02:00
|
|
|
EXPECT_TRUE(component.string() == "/" || bf::native(component.string()));
|
2018-05-19 08:00:37 +02:00
|
|
|
}
|
2018-05-17 06:34:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(HomedirTest, FakeHomeDirectorySetsHomedirCorrectly) {
|
|
|
|
TempDir fakeHomeDir, fakeAppDataDir;
|
|
|
|
FakeHomeDirectoryRAII a(fakeHomeDir.path(), fakeAppDataDir.path());
|
|
|
|
|
|
|
|
EXPECT_EQ(fakeHomeDir.path(), HomeDirectory::get());
|
|
|
|
EXPECT_EQ(fakeAppDataDir.path(), HomeDirectory::getXDGDataDir());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(HomedirTest, FakeHomeDirectoryResetsHomedirCorrectly) {
|
|
|
|
bf::path actualHomeDir = HomeDirectory::get();
|
|
|
|
bf::path actualAppDataDir = HomeDirectory::getXDGDataDir();
|
|
|
|
|
|
|
|
{
|
|
|
|
TempDir fakeHomeDir, fakeAppDataDir;
|
|
|
|
FakeHomeDirectoryRAII a(fakeHomeDir.path(), fakeAppDataDir.path());
|
|
|
|
|
|
|
|
EXPECT_NE(actualHomeDir, HomeDirectory::get());
|
|
|
|
EXPECT_NE(actualAppDataDir, HomeDirectory::getXDGDataDir());
|
|
|
|
}
|
|
|
|
EXPECT_EQ(actualHomeDir, HomeDirectory::get());
|
|
|
|
EXPECT_EQ(actualAppDataDir, HomeDirectory::getXDGDataDir());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(HomedirTest, FakeTempHomeDirectorySetsHomedirCorrectly) {
|
|
|
|
bf::path actualHomeDir = HomeDirectory::get();
|
|
|
|
bf::path actualAppDataDir = HomeDirectory::getXDGDataDir();
|
|
|
|
|
|
|
|
FakeTempHomeDirectoryRAII a;
|
|
|
|
|
|
|
|
EXPECT_NE(actualHomeDir, HomeDirectory::get());
|
|
|
|
EXPECT_NE(actualAppDataDir, HomeDirectory::getXDGDataDir());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(HomedirTest, FakeTempHomeDirectoryResetsHomedirCorrectly) {
|
|
|
|
bf::path actualHomeDir = HomeDirectory::get();
|
|
|
|
bf::path actualAppDataDir = HomeDirectory::getXDGDataDir();
|
|
|
|
|
|
|
|
{
|
|
|
|
FakeTempHomeDirectoryRAII a;
|
|
|
|
|
|
|
|
EXPECT_NE(actualHomeDir, HomeDirectory::get());
|
|
|
|
EXPECT_NE(actualAppDataDir, HomeDirectory::getXDGDataDir());
|
|
|
|
}
|
|
|
|
EXPECT_EQ(actualHomeDir, HomeDirectory::get());
|
|
|
|
EXPECT_EQ(actualAppDataDir, HomeDirectory::getXDGDataDir());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(HomedirTest, FakeTempHomeDirectoryUsesDifferentDirsForHomedirAndAppdataDir) {
|
|
|
|
FakeTempHomeDirectoryRAII a;
|
|
|
|
|
|
|
|
EXPECT_NE(HomeDirectory::get(), HomeDirectory::getXDGDataDir());
|
|
|
|
}
|