~ubuntu-branches/ubuntu/quantal/arora/quantal

« back to all changes in this revision

Viewing changes to autotests/utils/networkaccessmanagerproxy/tst_networkaccessmanagerproxy.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Roderick B. Greening
  • Date: 2009-10-01 16:08:58 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20091001160858-h1wnt3ddyzl07nih
Tags: 0.10.0-0ubuntu1
* New upstream release 
* Remove patches
  - kubuntu_01_google_lucky.diff - Open Search now used upstream
  - kubuntu_02_default_bookmarks.diff - bookmarks fixed upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2009 Benjamin C. Meyer <ben@meyerhome.net>
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
17
 * Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#include <qtest.h>
 
21
 
 
22
#include <networkaccessmanagerproxy.h>
 
23
#include <webpageproxy.h>
 
24
 
 
25
#include <qnetworkcookie.h>
 
26
#include <qnetworkrequest.h>
 
27
#include <qnetworkreply.h>
 
28
 
 
29
class tst_NetworkAccessManagerProxy : public QObject
 
30
{
 
31
    Q_OBJECT
 
32
 
 
33
public slots:
 
34
    void initTestCase();
 
35
    void cleanupTestCase();
 
36
    void init();
 
37
    void cleanup();
 
38
 
 
39
private slots:
 
40
    void networkaccessmanagerproxy_data();
 
41
    void networkaccessmanagerproxy();
 
42
 
 
43
    void primaryNetworkAccessManager();
 
44
    void webPage();
 
45
 
 
46
    void createRequest_data();
 
47
    void createRequest();
 
48
};
 
49
 
 
50
// Subclass that exposes the protected functions.
 
51
class SubNetworkAccessManagerProxy : public NetworkAccessManagerProxy
 
52
{
 
53
public:
 
54
    QNetworkReply *call_createRequest(QNetworkAccessManager::Operation op, QNetworkRequest const &request, QIODevice *outgoingData = 0)
 
55
        { return SubNetworkAccessManagerProxy::createRequest(op, request, outgoingData); }
 
56
};
 
57
 
 
58
// This will be called before the first test function is executed.
 
59
// It is only called once.
 
60
void tst_NetworkAccessManagerProxy::initTestCase()
 
61
{
 
62
}
 
63
 
 
64
// This will be called after the last test function is executed.
 
65
// It is only called once.
 
66
void tst_NetworkAccessManagerProxy::cleanupTestCase()
 
67
{
 
68
}
 
69
 
 
70
// This will be called before each test function is executed.
 
71
void tst_NetworkAccessManagerProxy::init()
 
72
{
 
73
}
 
74
 
 
75
// This will be called after every test function.
 
76
void tst_NetworkAccessManagerProxy::cleanup()
 
77
{
 
78
}
 
79
 
 
80
void tst_NetworkAccessManagerProxy::networkaccessmanagerproxy_data()
 
81
{
 
82
}
 
83
 
 
84
void tst_NetworkAccessManagerProxy::networkaccessmanagerproxy()
 
85
{
 
86
    SubNetworkAccessManagerProxy proxy;
 
87
    QVERIFY(proxy.call_createRequest(QNetworkAccessManager::GetOperation,
 
88
            QNetworkRequest(),
 
89
            (QIODevice*)0));
 
90
}
 
91
 
 
92
// public void setPrimaryNetworkAccessManager(NetworkAccessManagerProxy *primaryManager)
 
93
void tst_NetworkAccessManagerProxy::primaryNetworkAccessManager()
 
94
{
 
95
    SubNetworkAccessManagerProxy proxy;
 
96
 
 
97
    NetworkAccessManagerProxy primaryManager;
 
98
 
 
99
    proxy.setPrimaryNetworkAccessManager(&primaryManager);
 
100
    QCOMPARE(&primaryManager, proxy.primaryNetworkAccessManager());
 
101
    QVERIFY(primaryManager.cookieJar()->parent() == &primaryManager);
 
102
}
 
103
 
 
104
// public void setWebPage(WebPageProxy *page)
 
105
void tst_NetworkAccessManagerProxy::webPage()
 
106
{
 
107
    SubNetworkAccessManagerProxy proxy;
 
108
 
 
109
    WebPageProxy webPage;
 
110
    proxy.setWebPage(&webPage);
 
111
    QCOMPARE(&webPage, proxy.webPage());
 
112
}
 
113
 
 
114
void tst_NetworkAccessManagerProxy::createRequest_data()
 
115
{
 
116
    QTest::addColumn<bool>("primary");
 
117
    QTest::newRow("true") << true;
 
118
    QTest::newRow("false") << false;
 
119
}
 
120
 
 
121
// protected QNetworkReply *createRequest(QNetworkAccessManager::Operation op, QNetworkRequest const &request, QIODevice *outgoingData = 0)
 
122
void tst_NetworkAccessManagerProxy::createRequest()
 
123
{
 
124
    QFETCH(bool, primary);
 
125
 
 
126
    SubNetworkAccessManagerProxy proxy;
 
127
    SubNetworkAccessManagerProxy primaryManager;
 
128
    WebPageProxy webPage;
 
129
    if (!primary) {
 
130
        proxy.setPrimaryNetworkAccessManager(&primaryManager);
 
131
        proxy.setWebPage(&webPage);
 
132
    }
 
133
 
 
134
    QIODevice *outgoingData = 0;
 
135
    QNetworkRequest request;
 
136
    QNetworkReply *reply = proxy.call_createRequest(QNetworkAccessManager::GetOperation, request, outgoingData);
 
137
    QVERIFY(reply);
 
138
    if (primary)
 
139
        QCOMPARE(reply->request(), request);
 
140
    else
 
141
        QVERIFY(reply->request() != request);
 
142
}
 
143
 
 
144
QTEST_MAIN(tst_NetworkAccessManagerProxy)
 
145
#include "tst_networkaccessmanagerproxy.moc"
 
146