Welcome to mirror list, hosted at ThFree Co, Russian Federation.

testnetrcparser.cpp « test - github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1c8724e664f10f6ff8bb7c6b334b5926e5ab1083 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 *    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");
       netrc.write("machine frob login \"user with spaces\" password 'space pwd'\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()));
       QCOMPARE(parser.find("funnysplit"), qMakePair(QString("bar3"), QString("baz3")));
       QCOMPARE(parser.find("frob"), qMakePair(QString("user with spaces"), QString("space pwd")));
    }

    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_APPLESS_MAIN(TestNetrcParser)
#include "testnetrcparser.moc"