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.cdUp(); + 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/kio_smb_browse.cpp b/smb/kio_smb_browse.cpp --- a/smb/kio_smb_browse.cpp +++ b/smb/kio_smb_browse.cpp @@ -422,7 +422,7 @@ // Call base class to list entry listEntry(udsentry); } - m_current_url.cd(".."); + m_current_url.cdUp(); } else if (dirp->smbc_type == SMBC_SERVER || dirp->smbc_type == SMBC_FILE_SHARE) { // Set type udsentry.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR); diff --git a/smb/smburl.h b/smb/smburl.h --- a/smb/smburl.h +++ b/smb/smburl.h @@ -68,7 +68,7 @@ */ void addPath(const QString &filedir); - bool cd(const QString &dir); + void cdUp(); /** * Returns the type of this SMBUrl: diff --git a/smb/smburl.cpp b/smb/smburl.cpp --- a/smb/smburl.cpp +++ b/smb/smburl.cpp @@ -64,15 +64,10 @@ updateCache(); } -bool SMBUrl::cd(const QString &filedir) +void SMBUrl::cdUp() { - if (filedir == "..") { - setUrl(KIO::upUrl(*this).url()); - } else { - setUrl(filedir); - } + setUrl(KIO::upUrl(*this).url()); updateCache(); - return true; } void SMBUrl::updateCache()