diff options
| author | manuel <manuel@mausz.at> | 2020-10-19 00:52:24 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2020-10-19 00:52:24 +0200 |
| commit | be933ef2241d79558f91796cc5b3a161f72ebf9c (patch) | |
| tree | fe3ab2f130e20c99001f2d7a81d610c78c96a3f4 /xbmc/utils/test/TestAliasShortcutUtils.cpp | |
| parent | 5f8335c1e49ce108ef3481863833c98efa00411b (diff) | |
| download | kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.gz kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.bz2 kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.zip | |
sync with upstream
Diffstat (limited to 'xbmc/utils/test/TestAliasShortcutUtils.cpp')
| -rw-r--r-- | xbmc/utils/test/TestAliasShortcutUtils.cpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/xbmc/utils/test/TestAliasShortcutUtils.cpp b/xbmc/utils/test/TestAliasShortcutUtils.cpp new file mode 100644 index 0000000..d36fd41 --- /dev/null +++ b/xbmc/utils/test/TestAliasShortcutUtils.cpp | |||
| @@ -0,0 +1,91 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2005-2018 Team Kodi | ||
| 3 | * This file is part of Kodi - https://kodi.tv | ||
| 4 | * | ||
| 5 | * SPDX-License-Identifier: GPL-2.0-or-later | ||
| 6 | * See LICENSES/README.md for more information. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include "utils/AliasShortcutUtils.h" | ||
| 10 | #include "filesystem/File.h" | ||
| 11 | #include "test/TestUtils.h" | ||
| 12 | |||
| 13 | #if defined(TARGET_DARWIN_OSX) | ||
| 14 | #include "platform/darwin/DarwinUtils.h" | ||
| 15 | #endif | ||
| 16 | #include <gtest/gtest.h> | ||
| 17 | |||
| 18 | TEST(TestAliasShortcutUtils, IsAliasShortcut) | ||
| 19 | { | ||
| 20 | XFILE::CFile *tmpFile = XBMC_CREATETEMPFILE("noaliastest"); | ||
| 21 | std::string noalias = XBMC_TEMPFILEPATH(tmpFile); | ||
| 22 | |||
| 23 | #if defined(TARGET_DARWIN_OSX) | ||
| 24 | XFILE::CFile *aliasDestFile = XBMC_CREATETEMPFILE("aliastest"); | ||
| 25 | std::string alias = XBMC_TEMPFILEPATH(aliasDestFile); | ||
| 26 | |||
| 27 | //we only need the path here so delete the alias file | ||
| 28 | //which will be recreated as shortcut later: | ||
| 29 | XBMC_DELETETEMPFILE(aliasDestFile); | ||
| 30 | |||
| 31 | // create alias from a pointing to /Volumes | ||
| 32 | CDarwinUtils::CreateAliasShortcut(alias, "/Volumes"); | ||
| 33 | EXPECT_TRUE(IsAliasShortcut(alias, true)); | ||
| 34 | XFILE::CFile::Delete(alias); | ||
| 35 | |||
| 36 | // volumes is not a shortcut but a dir | ||
| 37 | EXPECT_FALSE(IsAliasShortcut("/Volumes", true)); | ||
| 38 | #endif | ||
| 39 | |||
| 40 | // a regular file is not a shortcut | ||
| 41 | EXPECT_FALSE(IsAliasShortcut(noalias, false)); | ||
| 42 | XBMC_DELETETEMPFILE(tmpFile); | ||
| 43 | |||
| 44 | // empty string is not an alias | ||
| 45 | std::string emptyString; | ||
| 46 | EXPECT_FALSE(IsAliasShortcut(emptyString, false)); | ||
| 47 | |||
| 48 | // non-existent file is no alias | ||
| 49 | std::string nonExistingFile="/IDontExistsNormally/somefile.txt"; | ||
| 50 | EXPECT_FALSE(IsAliasShortcut(nonExistingFile, false)); | ||
| 51 | } | ||
| 52 | |||
| 53 | TEST(TestAliasShortcutUtils, TranslateAliasShortcut) | ||
| 54 | { | ||
| 55 | XFILE::CFile *tmpFile = XBMC_CREATETEMPFILE("noaliastest"); | ||
| 56 | std::string noalias = XBMC_TEMPFILEPATH(tmpFile); | ||
| 57 | std::string noaliastemp = noalias; | ||
| 58 | |||
| 59 | #if defined(TARGET_DARWIN_OSX) | ||
| 60 | XFILE::CFile *aliasDestFile = XBMC_CREATETEMPFILE("aliastest"); | ||
| 61 | std::string alias = XBMC_TEMPFILEPATH(aliasDestFile); | ||
| 62 | |||
| 63 | //we only need the path here so delete the alias file | ||
| 64 | //which will be recreated as shortcut later: | ||
| 65 | XBMC_DELETETEMPFILE(aliasDestFile); | ||
| 66 | |||
| 67 | // create alias from a pointing to /Volumes | ||
| 68 | CDarwinUtils::CreateAliasShortcut(alias, "/Volumes"); | ||
| 69 | |||
| 70 | // resolve the shortcut | ||
| 71 | TranslateAliasShortcut(alias); | ||
| 72 | EXPECT_STREQ("/Volumes", alias.c_str()); | ||
| 73 | XFILE::CFile::Delete(alias); | ||
| 74 | #endif | ||
| 75 | |||
| 76 | // translating a non-shortcut url should result in no change... | ||
| 77 | TranslateAliasShortcut(noaliastemp); | ||
| 78 | EXPECT_STREQ(noaliastemp.c_str(), noalias.c_str()); | ||
| 79 | XBMC_DELETETEMPFILE(tmpFile); | ||
| 80 | |||
| 81 | //translate empty should stay empty | ||
| 82 | std::string emptyString; | ||
| 83 | TranslateAliasShortcut(emptyString); | ||
| 84 | EXPECT_STREQ("", emptyString.c_str()); | ||
| 85 | |||
| 86 | // translate non-existent file should result in no change... | ||
| 87 | std::string nonExistingFile="/IDontExistsNormally/somefile.txt"; | ||
| 88 | std::string resolvedNonExistingFile=nonExistingFile; | ||
| 89 | TranslateAliasShortcut(resolvedNonExistingFile); | ||
| 90 | EXPECT_STREQ(resolvedNonExistingFile.c_str(), nonExistingFile.c_str()); | ||
| 91 | } | ||
