mirror of
https://github.com/nextcloud/desktop.git
synced 2024-12-13 06:52:39 +03:00
f427955512
Remove all configure_files: - Move all tests to cpp files - Use the QTEST_MAIN macro instead of a generated main.cpp - Include test*.moc in the cpp to let CMAKE_AUTOMOC call moc - Pass info through add_definitions instead of generating oc_bin.h with them This makes sure that build errors points to the original test source file instead of the generated one in the build directory to be able to jump and fix errors directly from the IDE's error pane.
74 lines
2.3 KiB
C++
74 lines
2.3 KiB
C++
/*
|
|
* This software is in the public domain, furnished "as is", without technical
|
|
* support, and with no warranty, express or implied, as to its usefulness for
|
|
* any purpose.
|
|
* */
|
|
|
|
#include <QtTest>
|
|
|
|
#include "cmd/netrcparser.h"
|
|
|
|
using namespace OCC;
|
|
|
|
namespace {
|
|
|
|
const char testfileC[] = "netrctest";
|
|
const char testfileWithDefaultC[] = "netrctestDefault";
|
|
const char testfileEmptyC[] = "netrctestEmpty";
|
|
|
|
}
|
|
|
|
class TestNetrcParser : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
private slots:
|
|
void initTestCase() {
|
|
QFile netrc(testfileC);
|
|
QVERIFY(netrc.open(QIODevice::WriteOnly));
|
|
netrc.write("machine foo login bar password baz\n");
|
|
netrc.write("machine broken login bar2 dontbelonghere password baz2 extratokens dontcare andanother\n");
|
|
netrc.write("machine\nfunnysplit\tlogin bar3 password baz3\n");
|
|
QFile netrcWithDefault(testfileWithDefaultC);
|
|
QVERIFY(netrcWithDefault.open(QIODevice::WriteOnly));
|
|
netrcWithDefault.write("machine foo login bar password baz\n");
|
|
netrcWithDefault.write("default login user password pass\n");
|
|
QFile netrcEmpty(testfileEmptyC);
|
|
QVERIFY(netrcEmpty.open(QIODevice::WriteOnly));
|
|
}
|
|
|
|
void cleanupTestCase() {
|
|
QVERIFY(QFile::remove(testfileC));
|
|
QVERIFY(QFile::remove(testfileWithDefaultC));
|
|
QVERIFY(QFile::remove(testfileEmptyC));
|
|
}
|
|
|
|
void testValidNetrc() {
|
|
NetrcParser parser(testfileC);
|
|
QVERIFY(parser.parse());
|
|
QCOMPARE(parser.find("foo"), qMakePair(QString("bar"), QString("baz")));
|
|
QCOMPARE(parser.find("broken"), qMakePair(QString("bar2"), QString("baz2")));
|
|
QCOMPARE(parser.find("funnysplit"), qMakePair(QString("bar3"), QString("baz3")));
|
|
}
|
|
|
|
void testEmptyNetrc() {
|
|
NetrcParser parser(testfileEmptyC);
|
|
QVERIFY(!parser.parse());
|
|
QCOMPARE(parser.find("foo"), qMakePair(QString(), QString()));
|
|
}
|
|
|
|
void testValidNetrcWithDefault() {
|
|
NetrcParser parser(testfileWithDefaultC);
|
|
QVERIFY(parser.parse());
|
|
QCOMPARE(parser.find("foo"), qMakePair(QString("bar"), QString("baz")));
|
|
QCOMPARE(parser.find("dontknow"), qMakePair(QString("user"), QString("pass")));
|
|
}
|
|
|
|
void testInvalidNetrc() {
|
|
NetrcParser parser("/invalid");
|
|
QVERIFY(!parser.parse());
|
|
}
|
|
};
|
|
|
|
QTEST_MAIN(TestNetrcParser)
|
|
#include "testnetrcparser.moc"
|