summaryrefslogtreecommitdiffstats
path: root/xbmc/test/TestUtil.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/test/TestUtil.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/test/TestUtil.cpp')
-rw-r--r--xbmc/test/TestUtil.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/xbmc/test/TestUtil.cpp b/xbmc/test/TestUtil.cpp
new file mode 100644
index 0000000..827c310
--- /dev/null
+++ b/xbmc/test/TestUtil.cpp
@@ -0,0 +1,87 @@
+/*
+ * 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 "Util.h"
+
+#include <gtest/gtest.h>
+
+TEST(TestUtil, GetQualifiedFilename)
+{
+ std::string file = "../foo";
+ CUtil::GetQualifiedFilename("smb://", file);
+ EXPECT_EQ(file, "foo");
+ file = "C:\\foo\\bar";
+ CUtil::GetQualifiedFilename("smb://", file);
+ EXPECT_EQ(file, "C:\\foo\\bar");
+ file = "../foo/./bar";
+ CUtil::GetQualifiedFilename("smb://my/path", file);
+ EXPECT_EQ(file, "smb://my/foo/bar");
+ file = "smb://foo/bar/";
+ CUtil::GetQualifiedFilename("upnp://", file);
+ EXPECT_EQ(file, "smb://foo/bar/");
+}
+
+TEST(TestUtil, MakeLegalPath)
+{
+ std::string path;
+#ifdef TARGET_WINDOWS
+ path = "C:\\foo\\bar";
+ EXPECT_EQ(CUtil::MakeLegalPath(path), "C:\\foo\\bar");
+ path = "C:\\foo:\\bar\\";
+ EXPECT_EQ(CUtil::MakeLegalPath(path), "C:\\foo_\\bar\\");
+#else
+ path = "/foo/bar/";
+ EXPECT_EQ(CUtil::MakeLegalPath(path),"/foo/bar/");
+ path = "/foo?/bar";
+ EXPECT_EQ(CUtil::MakeLegalPath(path),"/foo_/bar");
+#endif
+ path = "smb://foo/bar";
+ EXPECT_EQ(CUtil::MakeLegalPath(path), "smb://foo/bar");
+ path = "smb://foo/bar?/";
+ EXPECT_EQ(CUtil::MakeLegalPath(path), "smb://foo/bar_/");
+}
+
+TEST(TestUtil, MakeShortenPath)
+{
+ std::string result;
+ EXPECT_EQ(true, CUtil::MakeShortenPath("smb://test/string/is/long/and/very/much/so", result, 10));
+ EXPECT_EQ("smb:/../so", result);
+
+ EXPECT_EQ(true, CUtil::MakeShortenPath("smb://test/string/is/long/and/very/much/so", result, 30));
+ EXPECT_EQ("smb://../../../../../../../so", result);
+
+ EXPECT_EQ(true, CUtil::MakeShortenPath("smb://test//string/is/long/and/very//much/so", result, 30));
+ EXPECT_EQ("smb:/../../../../../so", result);
+
+ EXPECT_EQ(true, CUtil::MakeShortenPath("//test//string/is/long/and/very//much/so", result, 30));
+ EXPECT_EQ("/../../../../../so", result);
+}
+
+TEST(TestUtil, ValidatePath)
+{
+ std::string path;
+#ifdef TARGET_WINDOWS
+ path = "C:/foo/bar/";
+ EXPECT_EQ(CUtil::ValidatePath(path), "C:\\foo\\bar\\");
+ path = "C:\\\\foo\\\\bar\\";
+ EXPECT_EQ(CUtil::ValidatePath(path, true), "C:\\foo\\bar\\");
+ path = "\\\\foo\\\\bar\\";
+ EXPECT_EQ(CUtil::ValidatePath(path, true), "\\\\foo\\bar\\");
+#else
+ path = "\\foo\\bar\\";
+ EXPECT_EQ(CUtil::ValidatePath(path), "/foo/bar/");
+ path = "/foo//bar/";
+ EXPECT_EQ(CUtil::ValidatePath(path, true), "/foo/bar/");
+#endif
+ path = "smb://foo/bar/";
+ EXPECT_EQ(CUtil::ValidatePath(path), "smb://foo/bar/");
+ path = "smb://foo//bar/";
+ EXPECT_EQ(CUtil::ValidatePath(path, true), "smb://foo/bar/");
+ path = "smb:\\\\foo\\\\bar\\";
+ EXPECT_EQ(CUtil::ValidatePath(path, true), "smb://foo/bar/");
+}