diff --git a/smb/CMakeLists.txt b/smb/CMakeLists.txt --- a/smb/CMakeLists.txt +++ b/smb/CMakeLists.txt @@ -73,3 +73,5 @@ install(TARGETS kio_smb DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/kio) install(FILES smb-network.desktop DESTINATION ${KDE_INSTALL_DATADIR}/konqueror/dirtree/remote) install(FILES smb-network.desktop DESTINATION ${KDE_INSTALL_DATADIR}/remoteview) + +add_subdirectory(autotests) diff --git a/smb/autotests/CMakeLists.txt b/smb/autotests/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/smb/autotests/CMakeLists.txt @@ -0,0 +1,17 @@ +if(NOT BUILD_TESTING) + return() +endif() + +# allow coercing cstring to qstring, easier to write +remove_definitions(-DQT_NO_CAST_FROM_ASCII) + +find_package(Qt5Test ${QT_MIN_VERSION} CONFIG REQUIRED) + +include(ECMAddTests) + +ecm_add_tests( + smburltest + LINK_LIBRARIES + Qt5::Test + kio_smb_static +) diff --git a/smb/autotests/smburltest.cpp b/smb/autotests/smburltest.cpp new file mode 100644 --- /dev/null +++ b/smb/autotests/smburltest.cpp @@ -0,0 +1,69 @@ +/* + SPDX-FileCopyrightText: 2020 Harald Sitter + SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL +*/ + +#include +#include + +#include "smburl.h" + +class SMBUrlTest : public QObject +{ + Q_OBJECT +private Q_SLOTS: + void testMinimalToSmbcValid() + { + // libsmbclient is a bit picky. make sure we convert to minimal applicable form + { + SMBUrl url(QUrl("smb:/")); + QCOMPARE(url.toSmbcUrl(), "smb://"); + } + + // But at the same time it will happily deal with smb: + { + SMBUrl url(QUrl("smb:")); + QCOMPARE(url.toSmbcUrl(), "smb:"); + } + } + + void testType() + { + QCOMPARE(SMBUrl(QUrl("smb://")).getType(), SMBURLTYPE_ENTIRE_NETWORK); + QCOMPARE(SMBUrl(QUrl("smb://host")).getType(), SMBURLTYPE_WORKGROUP_OR_SERVER); + QCOMPARE(SMBUrl(QUrl("smb://host/share/file")).getType(), SMBURLTYPE_SHARE_OR_PATH); + QCOMPARE(SMBUrl(QUrl()).getType(), SMBURLTYPE_UNKNOWN); + } + + void testPart() + { + SMBUrl url(QUrl("smb://host/share/file")); + QCOMPARE(url.partUrl().toString(), "smb://host/share/file.part"); + } + + void testUp() + { + SMBUrl url(QUrl("smb://host/share/file")); + url.cd(".."); + QCOMPARE(url.toSmbcUrl(), "smb://host/share"); + } + + void testAddPath() + { + SMBUrl url(QUrl("smb://host/share")); + url.addPath("file"); + QCOMPARE(url.toSmbcUrl(), "smb://host/share/file"); + } + + void testCifs() + { + // We treat cifs as an alias but need to translate it to smb. + // https://bugs.kde.org/show_bug.cgi?id=327295 + SMBUrl url(QUrl("cifs://host/share/file")); + QCOMPARE(url.toSmbcUrl(), "smb://host/share/file"); + } +}; + +QTEST_GUILESS_MAIN(SMBUrlTest) + +#include "smburltest.moc" diff --git a/smb/smburl.cpp b/smb/smburl.cpp --- a/smb/smburl.cpp +++ b/smb/smburl.cpp @@ -69,7 +69,9 @@ if (filedir == "..") { setUrl(KIO::upUrl(*this).url()); } else { - setUrl(filedir); + // We only support going up right now! It's all we need doing! + Q_UNREACHABLE(); + return false; } updateCache(); return true;