#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2021 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License // If the library is compiled as a DLL, this ensures symbols are exported #define NUCLEX_STORAGE_SOURCE 1 #include "../../../Source/FileSystem/Linux/XdgDirectoryResolver.h" #include "Nuclex/Storage/FileSystem/Path.h" #include // There are a few unit tests used to verify behavior in edge cases. // If you want them to run, add the following lines to your ~/.config/user-dirs.dirs file: // // XDG_UNITTEST1_DIR="$HOME/UnitTest" # Comment // XDG_UNITTEST2_DIR="$HOME/UnitTest # No comment" // XDG_UNITTEST3_DIR="$HOME/UnitTest # No comment, open quote // XDG_UNITTEST4_DIR=$HOME/UnitTest # Comment, no quote // #if defined(NUCLEX_STORAGE_LINUX) namespace Nuclex { namespace Storage { namespace FileSystem { namespace Linux { // ------------------------------------------------------------------------------------------- // TEST(XdgDirectoryResolverTest, CanFindHomeDirectory) { std::string homeDirectory = XdgDirectoryResolver::GetHomeDirectory(); EXPECT_GT(homeDirectory.length(), 1); } // ------------------------------------------------------------------------------------------- // TEST(XdgDirectoryResolverTest, CanFindConfigHomeDirectory) { std::string configHomeDirectory = XdgDirectoryResolver::GetConfigHomeDirectory(); EXPECT_GT(configHomeDirectory.length(), 3); } // ------------------------------------------------------------------------------------------- // TEST(XdgDirectoryResolverTest, CanFindDataHomeDirectory) { std::string dataHomeDirectory = XdgDirectoryResolver::GetDataHomeDirectory(); EXPECT_GT(dataHomeDirectory.length(), 3); } // ------------------------------------------------------------------------------------------- // TEST(XdgDirectoryResolverTest, CanLookUpUserDirectory) { std::string path; bool found = XdgDirectoryResolver::GetUserDirectory( "XDG_DESKTOP_DIR", path ); if(found) { EXPECT_GT(path.length(), 1); } } // ------------------------------------------------------------------------------------------- // TEST(XdgDirectoryResolverTest, CanLookupUnitTestDirectory1) { std::string path; bool found = XdgDirectoryResolver::GetUserDirectory( "XDG_UNITTEST1_DIR", path ); if(found) { std::string expected = Nuclex::Storage::FileSystem::Path::Join( XdgDirectoryResolver::GetHomeDirectory(), u8"UnitTest" ); EXPECT_EQ(path, expected); } } // ------------------------------------------------------------------------------------------- // TEST(XdgDirectoryResolverTest, CanLookupUnitTestDirectory2) { std::string path; bool found = XdgDirectoryResolver::GetUserDirectory( "XDG_UNITTEST2_DIR", path ); if(found) { std::string expected = Nuclex::Storage::FileSystem::Path::Join( XdgDirectoryResolver::GetHomeDirectory(), u8"UnitTest # No comment" ); EXPECT_EQ(path, expected); } } // ------------------------------------------------------------------------------------------- // TEST(XdgDirectoryResolverTest, CanLookupUnitTestDirectory3) { std::string path; bool found = XdgDirectoryResolver::GetUserDirectory( "XDG_UNITTEST3_DIR", path ); if(found) { std::string expected = Nuclex::Storage::FileSystem::Path::Join( XdgDirectoryResolver::GetHomeDirectory(), u8"UnitTest # No comment, open quote" ); EXPECT_EQ(path, expected); } } // ------------------------------------------------------------------------------------------- // TEST(XdgDirectoryResolverTest, CanLookupUnitTestDirectory4) { std::string path; bool found = XdgDirectoryResolver::GetUserDirectory( "XDG_UNITTEST4_DIR", path ); if(found) { std::string expected = Nuclex::Storage::FileSystem::Path::Join( XdgDirectoryResolver::GetHomeDirectory(), u8"UnitTest" ); EXPECT_EQ(path, expected); } } // ------------------------------------------------------------------------------------------- // }}}} // namespace Nuclex::Storage::FileSystem::Linux #endif // defined(NUCLEX_STORAGE_LINUX)