Debian Codegraph @

tests/online-accounts-service/tst_signonui_service/tst_signonui_service.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <[email protected]>
5 *
6 * This file is part of lomiri-online-accounts-service
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include <online-accounts-common/globals.h>cxx . . $ `<file>/online-accounts-common/globals.h`/
22 #include "request-manager-mock.h"cxx . . $ `<file>/tests/online-accounts-service/tst_signonui_service/request-manager-mock.h`/
23 #include "signonui-service.h"cxx . . $ `<file>/online-accounts-service/src/signonui-service.h`/
24
25 #include <QDebug>
26 #include <QSignalSpy>
27 #include <QString>
28 #include <QTemporaryDir>
29 #include <QTest>
30 #include <sys/time.h>
31
32 using namespace SignOnUi;
33
34 class ServiceTestcxx . . $ ServiceTest#: public QObjectcxx . . $ QObject#
35 {
36 Q_OBJECTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:170:9`!
37
38 public:
39 ServiceTestcxx . . $ ServiceTest#ServiceTest(49f6e7a06ebc5aa8).();
40
41 private:
42 void writeFilecxx . . $ ServiceTest#writeFile(88f4c41ca0e941aa).(const QStringcxx . . $ QString# &name, const QByteArraycxx . . $ QByteArray# &contents);
43 void setFileDatecxx . . $ ServiceTest#setFileDate(ac8c6c1470fe2fe9).(const QStringcxx . . $ QString# &name, qint64cxx . . $ qint64# timestamp);
44
45 private Q_SLOTScxx . . $ `<external>/1208926524888476972/qobjectdefs.h:92:10`!:
46 void testCookies_datacxx . . $ ServiceTest#testCookies_data(49f6e7a06ebc5aa8).();
47 void testCookiescxx . . $ ServiceTest#testCookies(49f6e7a06ebc5aa8).();
48
49 private:
50 OnlineAccountsUicxx . . $ OnlineAccountsUi/::RequestManagercxx . . $ OnlineAccountsUi/RequestManager# m_requestManagercxx . . $ ServiceTest#m_requestManager.;
51 Servicecxx . . $ SignOnUi/Service# m_servicecxx . . $ ServiceTest#m_service.;
52 };
53
54 ServiceTestcxx . . $ ServiceTest#::ServiceTestcxx . . $ ServiceTest#ServiceTest(49f6e7a06ebc5aa8).():
55 QObjectcxx . . $ QObject#QObject(749de1b6ae65bddd).(0)
56 {
57 }
58
59 void ServiceTestcxx . . $ ServiceTest#::writeFilecxx . . $ ServiceTest#writeFile(88f4c41ca0e941aa).(const QStringcxx . . $ QString# &name, const QByteArraycxx . . $ QByteArray# &contents)
60 {
61 QFilecxx . . $ QFile# filecxx . . $ QFile#QFile(3520e46b33348bf6).(name);
62 if (!file.opencxx . . $ QFile#open(dca164408be960c8).(QIODevicecxx . . $ QIODevice#::WriteOnlycxx . . $ QIODevice#WriteOnly. |cxx . . $ `operator|`(c9e45f682471e48d). QIODevicecxx . . $ QIODevice#::Textcxx . . $ QIODevice#Text.)) {
63 qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Could not write file" <<cxx . . $ QDebug#`operator<<`(4cf17434affdd8). name;
64 return;
65 }
66
67 file.writecxx . . $ QIODevice#write(4ee2750a0be83987).(contents);
68 }
69
70 void ServiceTestcxx . . $ ServiceTest#::setFileDatecxx . . $ ServiceTest#setFileDate(ac8c6c1470fe2fe9).(const QStringcxx . . $ QString# &name, qint64cxx . . $ qint64# timestamp)
71 {
72 struct timeval times[2];
73
74 times[0].tv_sec = times[1].tv_sec = timestamp;
75 times[0].tv_usec = times[1].tv_usec = 0;
76 utimes(name.toUtf8cxx . . $ QString#toUtf8(ef52b713090bc85a).().constDatacxx . . $ QByteArray#constData(a9f41ea0e82d88cf).(), times);
77 }
78
79 void ServiceTestcxx . . $ ServiceTest#::testCookies_datacxx . . $ ServiceTest#testCookies_data(49f6e7a06ebc5aa8).()
80 {
81 QTestcxx . . $ QTest/::addColumncxx . . $ QTest/addColumn(cfe4d590606f2f46).<QStringcxx . . $ QString#>("contents");
82 QTestcxx . . $ QTest/::addColumncxx . . $ QTest/addColumn(cfe4d590606f2f46).<qint64cxx . . $ qint64#>("expectedTimestamp");
83 QTestcxx . . $ QTest/::addColumncxx . . $ QTest/addColumn(cfe4d590606f2f46).<RawCookiescxx . . $ SignOnUi/RawCookies#>("expectedCookies");
84
85 RawCookiescxx . . $ SignOnUi/RawCookies# cookiescxx . . $ QList#QList(ced63f7c635d850d).;
86
87 QTestcxx . . $ QTest/::newRowcxx . . $ QTest/newRow(71534bb7a360de38).("empty") <<cxx . . $ `operator<<`(1c43a92f59c6a770).
88 "" <<cxx . . $ `operator<<`(61fb880f51a53ddf).
89 qint64cxx . . $ qint64#(1406204196) <<cxx . . $ `operator<<`(61fb880f51a53ddf).
90 cookies;
91
92 QTestcxx . . $ QTest/::newRowcxx . . $ QTest/newRow(71534bb7a360de38).("invalid-cookies") <<cxx . . $ `operator<<`(1c43a92f59c6a770).
93 "[\n"
94 " {\"path\": \"/\"},\n"
95 " {\"name\": \"C1\", \"path\": \"/\"},\n"
96 " {\"value\": \"else\", \"domain\": \"foo.com\"}\n"
97 "]" <<cxx . . $ `operator<<`(61fb880f51a53ddf).
98 qint64cxx . . $ qint64#(1406104196) <<cxx . . $ `operator<<`(61fb880f51a53ddf).
99 cookies;
100 cookies.clearcxx . . $ QList#clear(49f6e7a06ebc5aa8).();
101
102 cookies.appendcxx . . $ QList#append(77d9f17553126ecb).("C1=something"cxx . . $ QByteArray#QByteArray(34d26762b42c433a).);
103 cookies.appendcxx . . $ QList#append(77d9f17553126ecb).("C2=else; domain=foo.com"cxx . . $ QByteArray#QByteArray(34d26762b42c433a).);
104 cookies.appendcxx . . $ QList#append(77d9f17553126ecb).("C3=yes; HttpOnly"cxx . . $ QByteArray#QByteArray(34d26762b42c433a).);
105 cookies.appendcxx . . $ QList#append(77d9f17553126ecb).("C4=OK; path=/"cxx . . $ QByteArray#QByteArray(34d26762b42c433a).);
106 cookies.appendcxx . . $ QList#append(77d9f17553126ecb).("C5=no; expires=Sat, 20-Aug-2016 16:33:43 GMT"cxx . . $ QByteArray#QByteArray(34d26762b42c433a).);
107 QTestcxx . . $ QTest/::newRowcxx . . $ QTest/newRow(71534bb7a360de38).("few-cookies") <<cxx . . $ `operator<<`(1c43a92f59c6a770).
108 "[\n"
109 " {\"name\": \"C1\", \"value\": \"something\"},\n"
110 " {\"name\": \"C2\", \"value\": \"else\", \"domain\": \"foo.com\"},\n"
111 " {\"name\": \"C3\", \"value\": \"yes\", \"httponly\": \"true\"},\n"
112 " {\"name\": \"C4\", \"value\": \"OK\", \"path\": \"/\"},\n"
113 " {\"name\": \"C5\", \"value\": \"no\", \"expirationdate\": \"2016-08-20T16:33:43Z\"}\n"
114 "]" <<cxx . . $ `operator<<`(61fb880f51a53ddf).
115 qint64cxx . . $ qint64#(1406104196) <<cxx . . $ `operator<<`(61fb880f51a53ddf).
116 cookies;
117 }
118
119 void ServiceTestcxx . . $ ServiceTest#::testCookiescxx . . $ ServiceTest#testCookies(49f6e7a06ebc5aa8).()
120 {
121 QFETCHcxx . . $ `<external>/8602788698586413231/qtestcase.h:201:9`!(QString, contents);
122 QFETCHcxx . . $ `<external>/8602788698586413231/qtestcase.h:201:9`!(qint64, expectedTimestamp);
123 QFETCHcxx . . $ `<external>/8602788698586413231/qtestcase.h:201:9`!(RawCookies, expectedCookies);
124
125 QTemporaryDircxx . . $ QTemporaryDir# tempDircxx . . $ QTemporaryDir#QTemporaryDir(49f6e7a06ebc5aa8).;
126 QVERIFYcxx . . $ `<external>/8602788698586413231/qtestcase.h:63:9`!(tempDir.isValid());
127 qputenvcxx . . $ qputenv(d42e8231112a1b5b).("XDG_CACHE_HOME", tempDir.pathcxx . . $ QTemporaryDir#path(6ef7b6c27b00b43d).().toUtf8cxx . . $ QString#toUtf8(7c2073558a834e49).());
128 quint32cxx . . $ quint32# id = 47;
129
130 QStringcxx . . $ QString# subDir =
131 QStringcxx . . $ QString#QString(85c52e162fed56f9).("lomiri-online-accounts-ui/id-%2").argcxx . . $ QString#arg(173a29139b43af1f).(id);
132 QDircxx . . $ QDir# identityDircxx . . $ QDir#QDir(3520e46b33348bf6).(tempDir.pathcxx . . $ QTemporaryDir#path(6ef7b6c27b00b43d).());
133 identityDir.mkpathcxx . . $ QDir#mkpath(f3b39adf77d9c36c).(subDir);
134 identityDir.cdcxx . . $ QDir#cd(e1defb592416720d).(subDir);
135
136 QStringcxx . . $ QString# cookieFile(identityDir.filePathcxx . . $ QDir#filePath(5555d9024dcf93fb).("cookies.json"cxx . . $ QString#QString(85c52e162fed56f9).));
137 writeFilecxx . . $ ServiceTest#writeFile(88f4c41ca0e941aa).(cookieFile, contents.toUtf8cxx . . $ QString#toUtf8(ef52b713090bc85a).());
138 setFileDatecxx . . $ ServiceTest#setFileDate(ac8c6c1470fe2fe9).(cookieFile, expectedTimestamp);
139
140 RawCookiescxx . . $ SignOnUi/RawCookies# cookiescxx . . $ QList#QList(ced63f7c635d850d).;
141 qint64cxx . . $ qint64# timestamp = 0;
142 m_servicecxx . . $ ServiceTest#m_service..cookiesForIdentitycxx . . $ SignOnUi/Service#cookiesForIdentity(ab4be87f7ac152dd).(id, cookies, timestamp);
143 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(cookies, expectedCookies);
144 /* Be more tolerant about the timestamp: divide by 10, to allow a 10
145 * seconds gap */
146 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(timestamp / 10, expectedTimestamp / 10);
147 }
148
149 QTEST_MAINcxx . . $ `<external>/4204159469433502174/qtest.h:508:9`!(ServiceTest);
150
151 #include "tst_signonui_service.moc"cxx . . $ `<file>/build/tests/online-accounts-service/tst_signonui_service/tst_signonui_service_autogen/include/tst_signonui_service.moc`/