summaryrefslogtreecommitdiffstats
path: root/xbmc/filesystem/test/TestNfsFile.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/TestNfsFile.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/TestNfsFile.cpp')
-rw-r--r--xbmc/filesystem/test/TestNfsFile.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/xbmc/filesystem/test/TestNfsFile.cpp b/xbmc/filesystem/test/TestNfsFile.cpp
new file mode 100644
index 0000000..69b1203
--- /dev/null
+++ b/xbmc/filesystem/test/TestNfsFile.cpp
@@ -0,0 +1,84 @@
+/*
+ * 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 "URL.h"
+#include "filesystem/NFSFile.h"
+#include "test/TestUtils.h"
+
+#include <errno.h>
+#include <string>
+
+#include <gtest/gtest.h>
+
+using ::testing::Test;
+using ::testing::WithParamInterface;
+using ::testing::ValuesIn;
+
+struct SplitPath
+{
+ std::string url;
+ std::string exportPath;
+ std::string relativePath;
+ bool expectedResultExport;
+ bool expectedResultPath;
+} g_TestData[] = {
+ {"nfs://192.168.0.1:2049/srv/test/tvmedia/foo.txt", "/srv/test", "//tvmedia/foo.txt", true, true},
+ {"nfs://192.168.0.1/srv/test/tv/media/foo.txt", "/srv/test/tv", "//media/foo.txt", true, true},
+ {"nfs://192.168.0.1:2049/srv/test/tvmedia", "/srv/test", "//tvmedia", true, true},
+ {"nfs://192.168.0.1:2049/srv/test/tvmedia/", "/srv/test", "//tvmedia/", true, true},
+ {"nfs://192.168.0.1:2049/srv/test/tv/media", "/srv/test/tv", "//media", true, true},
+ {"nfs://192.168.0.1:2049/srv/test/tv/media/", "/srv/test/tv", "//media/", true, true},
+ {"nfs://192.168.0.1:2049/srv/test/tv", "/srv/test/tv", "//", true, true},
+ {"nfs://192.168.0.1:2049/srv/test/", "/srv/test", "//", true, true},
+ {"nfs://192.168.0.1:2049/", "/", "//", true, true},
+ {"nfs://192.168.0.1:2049/notexported/foo.txt", "/", "//notexported/foo.txt", true, true},
+
+ {"nfs://192.168.0.1:2049/notexported/foo.txt", "/notexported", "//foo.txt", false, false},
+ };
+
+class TestNfs : public Test,
+ public WithParamInterface<SplitPath>
+{
+};
+
+class ExportList
+{
+ public:
+ std::list<std::string> data;
+
+ ExportList()
+ {
+ data.emplace_back("/srv/test");
+ data.emplace_back("/srv/test/tv");
+ data.emplace_back("/");
+ data.sort();
+ data.reverse();
+ }
+};
+
+static ExportList exportList;
+
+TEST_P(TestNfs, splitUrlIntoExportAndPath)
+{
+ CURL url(GetParam().url);
+ std::string exportPath;
+ std::string relativePath;
+ gNfsConnection.splitUrlIntoExportAndPath(url, exportPath, relativePath, exportList.data);
+
+ if (GetParam().expectedResultExport)
+ EXPECT_STREQ(GetParam().exportPath.c_str(), exportPath.c_str());
+ else
+ EXPECT_STRNE(GetParam().exportPath.c_str(), exportPath.c_str());
+
+ if (GetParam().expectedResultPath)
+ EXPECT_STREQ(GetParam().relativePath.c_str(), relativePath.c_str());
+ else
+ EXPECT_STRNE(GetParam().relativePath.c_str(), relativePath.c_str());
+}
+
+INSTANTIATE_TEST_SUITE_P(NfsFile, TestNfs, ValuesIn(g_TestData));