summaryrefslogtreecommitdiffstats
path: root/xbmc/filesystem/test/TestDirectory.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 18:07:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 18:07:22 +0000
commitc04dcc2e7d834218ef2d4194331e383402495ae1 (patch)
tree7333e38d10d75386e60f336b80c2443c1166031d /xbmc/filesystem/test/TestDirectory.cpp
parentInitial commit. (diff)
downloadkodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz
kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xbmc/filesystem/test/TestDirectory.cpp')
-rw-r--r--xbmc/filesystem/test/TestDirectory.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/xbmc/filesystem/test/TestDirectory.cpp b/xbmc/filesystem/test/TestDirectory.cpp
new file mode 100644
index 0000000..e99408c
--- /dev/null
+++ b/xbmc/filesystem/test/TestDirectory.cpp
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2005-2018 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#include "FileItem.h"
+#include "filesystem/Directory.h"
+#include "filesystem/IDirectory.h"
+#include "filesystem/SpecialProtocol.h"
+#include "test/TestUtils.h"
+#include "utils/URIUtils.h"
+
+#include <gtest/gtest.h>
+
+TEST(TestDirectory, General)
+{
+ std::string tmppath1, tmppath2, tmppath3;
+ CFileItemList items;
+ CFileItemPtr itemptr;
+ tmppath1 = CSpecialProtocol::TranslatePath("special://temp/");
+ tmppath1 = URIUtils::AddFileToFolder(tmppath1, "TestDirectory");
+ tmppath2 = tmppath1;
+ tmppath2 = URIUtils::AddFileToFolder(tmppath2, "subdir");
+ EXPECT_TRUE(XFILE::CDirectory::Create(tmppath1));
+ EXPECT_TRUE(XFILE::CDirectory::Exists(tmppath1));
+ EXPECT_FALSE(XFILE::CDirectory::Exists(tmppath2));
+ EXPECT_TRUE(XFILE::CDirectory::Create(tmppath2));
+ EXPECT_TRUE(XFILE::CDirectory::Exists(tmppath2));
+ EXPECT_TRUE(XFILE::CDirectory::GetDirectory(tmppath1, items, "", XFILE::DIR_FLAG_DEFAULTS));
+ XFILE::CDirectory::FilterFileDirectories(items, "");
+ tmppath3 = tmppath2;
+ URIUtils::AddSlashAtEnd(tmppath3);
+ itemptr = items[0];
+ EXPECT_STREQ(tmppath3.c_str(), itemptr->GetPath().c_str());
+ EXPECT_TRUE(XFILE::CDirectory::Remove(tmppath2));
+ EXPECT_FALSE(XFILE::CDirectory::Exists(tmppath2));
+ EXPECT_TRUE(XFILE::CDirectory::Exists(tmppath1));
+ EXPECT_TRUE(XFILE::CDirectory::Remove(tmppath1));
+ EXPECT_FALSE(XFILE::CDirectory::Exists(tmppath1));
+}
+
+TEST(TestDirectory, CreateRecursive)
+{
+ auto path1 = URIUtils::AddFileToFolder(
+ CSpecialProtocol::TranslatePath("special://temp/"),
+ "level1");
+ auto path2 = URIUtils::AddFileToFolder(path1,
+ "level2",
+ "level3");
+
+ EXPECT_TRUE(XFILE::CDirectory::Create(path2));
+ EXPECT_TRUE(XFILE::CDirectory::RemoveRecursive(path1));
+}