Commit d8d92670 authored by Harald Sitter's avatar Harald Sitter 🏳🌈
Browse files

smb: add a unit test for smburl

Summary:
only tests some of the obvious scenarios I can see right now.

::cd() has been changed to only support going up one path element. it's
all we need it for and the previous code was almost certainly incorrect
by calling setUrl with input that is definitely not anywhere near a valid
url

Test Plan: builds and test passes

Reviewers: ngraham

Reviewed By: ngraham

Subscribers: apol, kde-frameworks-devel, kfm-devel

Tags: #dolphin, #frameworks

Differential Revision: https://phabricator.kde.org/D27801
parent d101d916
......@@ -73,3 +73,5 @@ set_target_properties(kio_smb PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINAR
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)
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
)
/*
SPDX-FileCopyrightText: 2020 Harald Sitter <sitter@kde.org>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include <QTest>
#include <QAbstractItemModelTester>
#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"
......@@ -422,7 +422,7 @@ void SMBSlave::listDir(const QUrl &kurl)
// 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);
......
......@@ -64,15 +64,10 @@ void SMBUrl::addPath(const QString &filedir)
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()
......
......@@ -68,7 +68,7 @@ public:
*/
void addPath(const QString &filedir);
bool cd(const QString &dir);
void cdUp();
/**
* Returns the type of this SMBUrl:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment