diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2010-04-20 17:53:14 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2010-04-22 07:41:11 (GMT) |
commit | 1692e4824a6c7b255b2f7d492ca69c4092d173ad (patch) | |
tree | 934e53fe13c5f62927bdbb2a7aa0001dd94d9d5e /tests/auto | |
parent | 26eb22954b8fe766d5ad63c8d21124a8393bed17 (diff) | |
download | Qt-1692e4824a6c7b255b2f7d492ca69c4092d173ad.zip Qt-1692e4824a6c7b255b2f7d492ca69c4092d173ad.tar.gz Qt-1692e4824a6c7b255b2f7d492ca69c4092d173ad.tar.bz2 |
[networkselftest] Add a test to try the SMB server.
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/networkselftest/tst_networkselftest.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/auto/networkselftest/tst_networkselftest.cpp b/tests/auto/networkselftest/tst_networkselftest.cpp index 041765c..d40a3fa 100644 --- a/tests/auto/networkselftest/tst_networkselftest.cpp +++ b/tests/auto/networkselftest/tst_networkselftest.cpp @@ -80,6 +80,7 @@ private slots: void httpProxyNtlmAuth(); void socks5Proxy(); void socks5ProxyAuth(); + void smbServer(); // ssl supported test void supportsSsl(); @@ -731,5 +732,61 @@ void tst_NetworkSelfTest::supportsSsl() #endif } +void tst_NetworkSelfTest::smbServer() +{ + static const char contents[] = "This is 34 bytes. Do not change..."; +#ifdef Q_OS_WIN + // use Windows's native UNC support to try and open a file on the server + QString filepath = QString("\\\\%1\\testshare\\test.pri").arg(QtNetworkSettings::winServerName()); + FILE *f = fopen(filepath.toLatin1(), "rb"); + QVERIFY2(f, qt_error_string().toLocal8Bit()); + + char buf[128]; + ssize_t ret = fread(buf, sizeof buf, 1, f); + fclose(f); + + QCOMPARE(ret, strlen(contents)); + QVERIFY(memcmp(ret, contents, strlen(contents)) == 0); +#else + // try to use Samba + QString progname = "smbclient"; + QProcess smbclient; + smbclient.start(progname, QIODevice::ReadOnly); + if (!smbclient.waitForStarted(2000)) + QSKIP("Could not find smbclient (from Samba), cannot continue testing", SkipAll); + if (!smbclient.waitForFinished(2000) || smbclient.exitStatus() != QProcess::NormalExit) + QSKIP("smbclient isn't working, cannot continue testing", SkipAll); + smbclient.close(); + + // try listing the server + smbclient.start(progname, QStringList() << "-g" << "-N" << "-L" << QtNetworkSettings::winServerName(), QIODevice::ReadOnly); + QVERIFY(smbclient.waitForFinished(5000)); + if (smbclient.exitStatus() != QProcess::NormalExit) + QSKIP("smbclient crashed", SkipAll); + QVERIFY2(smbclient.exitCode() == 0, "Test server not found"); + + QByteArray output = smbclient.readAll(); + QVERIFY(output.contains("Disk|testshare|")); + QVERIFY(output.contains("Disk|testsharewritable|")); + QVERIFY(output.contains("Disk|testsharelargefile|")); + qDebug() << "Test server found and shares are correct"; + + // try getting a file + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); + env.insert("PAGER", "/bin/cat"); // just in case + smbclient.setProcessEnvironment(env); + smbclient.start(progname, QStringList() << "-N" << "-c" << "more test.pri" + << QString("\\\\%1\\testshare").arg(QtNetworkSettings::winServerName()), QIODevice::ReadOnly); + QVERIFY(smbclient.waitForFinished(5000)); + if (smbclient.exitStatus() != QProcess::NormalExit) + QSKIP("smbclient crashed", SkipAll); + QVERIFY2(smbclient.exitCode() == 0, "File //qt-test-server/testshare/test.pri not found"); + + output = smbclient.readAll(); + QCOMPARE(output.constData(), contents); + qDebug() << "Test file is correct"; +#endif +} + QTEST_MAIN(tst_NetworkSelfTest) #include "tst_networkselftest.moc" |