File indexing completed on 2024-06-23 10:37:24

0001 /*
0002     SPDX-FileCopyrightText: 2018 Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #include "ksambashareprivatetest.h"
0008 #include "ksambashare_p.h"
0009 
0010 #include <KSambaShareData>
0011 
0012 #include <QTest>
0013 
0014 QTEST_MAIN(KSambaSharePrivateTest)
0015 
0016 void KSambaSharePrivateTest::initTestCase()
0017 {
0018 }
0019 
0020 void KSambaSharePrivateTest::testParser()
0021 {
0022     QFETCH(QByteArray, usershareData);
0023     QFETCH(bool, valid);
0024     QFETCH(QString, share);
0025     QFETCH(QString, path);
0026 
0027     auto shares = KSambaSharePrivate::parse(usershareData);
0028 
0029     if (valid) {
0030         QCOMPARE(shares.size(), 1);
0031         QCOMPARE(shares.first().name(), share);
0032         QCOMPARE(shares.first().path(), path);
0033         QCOMPARE(shares.first().path(), path);
0034     } else {
0035         QCOMPARE(shares.size(), 0);
0036     }
0037 }
0038 
0039 void KSambaSharePrivateTest::testParser_data()
0040 {
0041     QTest::addColumn<QByteArray>("usershareData");
0042     QTest::addColumn<bool>("valid");
0043     QTest::addColumn<QString>("share");
0044     QTest::addColumn<QString>("path");
0045     QTest::addColumn<QString>("comment");
0046 
0047     QTest::newRow("Valid share") << QByteArrayLiteral("[share]\npath=/some/path\ncomment=\nusershare_acl=Everyone:R,\nguest_ok=y") << true << "share"
0048                                  << "/some/path"
0049                                  << "";
0050     QTest::newRow("Valid share with slash") << QByteArrayLiteral("[share]\npath=/some/path/\ncomment=\nusershare_acl=Everyone:R,\nguest_ok=y") << true
0051                                             << "share"
0052                                             << "/some/path"
0053                                             << "";
0054     QTest::newRow("Valid share with comment") << QByteArrayLiteral("[share]\npath=/some/path\ncomment=Comment\nusershare_acl=Everyone:R,\nguest_ok=y") << true
0055                                               << "share"
0056                                               << "/some/path"
0057                                               << "Comment";
0058 }
0059 
0060 #include "moc_ksambashareprivatetest.cpp"