| 1 | /* |
| 2 | * Copyright (C) 2014 Canonical Ltd. |
| 3 | * |
| 4 | * Contact: Alberto Mardegan <[email protected]> |
| 5 | * |
| 6 | * This file is part of lomiri-online-accounts-ui |
| 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 "signonui-request.h"cxx . . $ `<file>/online-accounts-ui/src/signonui-request.h`/ |
| 23 | #include "mock/request-mock.h"cxx . . $ `<file>/tests/online-accounts-ui/mock/request-mock.h`/ |
| 24 | #include "mock/ui-server-mock.h"cxx . . $ `<file>/tests/online-accounts-ui/mock/ui-server-mock.h`/ |
| 25 | |
| 26 | #include <Accounts/Account> |
| 27 | #include <Accounts/Manager> |
| 28 | |
| 29 | #include <LomiriOnlineAccountsPlugin/request-handler.h>cxx . . $ `<file>/online-accounts-plugins/lib/LomiriOnlineAccountsPlugin/request-handler.h`/ |
| 30 | |
| 31 | #include <QDebug> |
| 32 | #include <QSignalSpy> |
| 33 | #include <QTemporaryDir> |
| 34 | #include <QTest> |
| 35 | |
| 36 | #include <SignOn/uisessiondata.h> |
| 37 | #include <SignOn/uisessiondata_priv.h> |
| 38 | |
| 39 | using namespace OnlineAccountsUi; |
| 40 | |
| 41 | class TestRequestcxx . . $ TestRequest#: public SignOnUicxx . . $ SignOnUi/::Requestcxx . . $ SignOnUi/Request# |
| 42 | { |
| 43 | Q_OBJECTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:170:9`! |
| 44 | |
| 45 | public: |
| 46 | TestRequestcxx . . $ TestRequest#TestRequest(8342fb91063d2b81).(const QStringcxx . . $ QString# &clientProfile, |
| 47 | const QVariantMapcxx . . $ QVariantMap# ¶meters, |
| 48 | QObjectcxx . . $ QObject# *parent = 0): |
| 49 | Requestcxx . . $ SignOnUi/Request#(0, clientProfile, parameters, parent) |
| 50 | { |
| 51 | } |
| 52 | |
| 53 | void setWindowcxx . . $ TestRequest#setWindow(35681b993d9a3c79).(QWindowcxx . . $ QWindow# *window) { Requestcxx . . $ SignOnUi/Request#::setWindowcxx . . $ SignOnUi/Request#setWindow(35681b993d9a3c79).(window); } |
| 54 | |
| 55 | void sendResultcxx . . $ TestRequest#sendResult(3e95df3e31f2cce8).(const QVariantMapcxx . . $ QVariantMap# &result) { setResultcxx . . $ OnlineAccountsUi/Request#setResult(3e95df3e31f2cce8).(result); } |
| 56 | }; |
| 57 | |
| 58 | class SignonuiRequestTestcxx . . $ SignonuiRequestTest#: public QObjectcxx . . $ QObject# |
| 59 | { |
| 60 | Q_OBJECTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:170:9`! |
| 61 | |
| 62 | public: |
| 63 | SignonuiRequestTestcxx . . $ SignonuiRequestTest#SignonuiRequestTest(49f6e7a06ebc5aa8).(); |
| 64 | |
| 65 | private Q_SLOTScxx . . $ `<external>/1208926524888476972/qobjectdefs.h:92:10`!: |
| 66 | void initTestCasecxx . . $ SignonuiRequestTest#initTestCase(49f6e7a06ebc5aa8).(); |
| 67 | void testParameters_datacxx . . $ SignonuiRequestTest#testParameters_data(49f6e7a06ebc5aa8).(); |
| 68 | void testParameterscxx . . $ SignonuiRequestTest#testParameters(49f6e7a06ebc5aa8).(); |
| 69 | void testHandlercxx . . $ SignonuiRequestTest#testHandler(49f6e7a06ebc5aa8).(); |
| 70 | |
| 71 | private: |
| 72 | bool mustCreateAccountcxx . . $ SignonuiRequestTest#mustCreateAccount(dfa6e707f7696010).(uintcxx . . $ uint# credentialsId) { return credentialsId > 10; } |
| 73 | |
| 74 | private: |
| 75 | QTemporaryDircxx . . $ QTemporaryDir# m_accountsDircxx . . $ SignonuiRequestTest#m_accountsDir.; |
| 76 | UiServercxx . . $ OnlineAccountsUi/UiServer# m_uiServercxx . . $ SignonuiRequestTest#m_uiServer.; |
| 77 | }; |
| 78 | |
| 79 | SignonuiRequestTestcxx . . $ SignonuiRequestTest#::SignonuiRequestTestcxx . . $ SignonuiRequestTest#SignonuiRequestTest(49f6e7a06ebc5aa8).(): |
| 80 | QObjectcxx . . $ QObject#QObject(749de1b6ae65bddd).(), |
| 81 | m_uiServercxx . . $ SignonuiRequestTest#m_uiServer.("fake"cxx . . $ QString#QString(85c52e162fed56f9).) |
| 82 | { |
| 83 | } |
| 84 | |
| 85 | void SignonuiRequestTestcxx . . $ SignonuiRequestTest#::initTestCasecxx . . $ SignonuiRequestTest#initTestCase(49f6e7a06ebc5aa8).() |
| 86 | { |
| 87 | QVERIFYcxx . . $ `<external>/8602788698586413231/qtestcase.h:63:9`!(m_accountsDir.isValid()); |
| 88 | |
| 89 | qputenvcxx . . $ qputenv(d42e8231112a1b5b).("ACCOUNTS", m_accountsDircxx . . $ SignonuiRequestTest#m_accountsDir..pathcxx . . $ QTemporaryDir#path(6ef7b6c27b00b43d).().toUtf8cxx . . $ QString#toUtf8(7c2073558a834e49).()); |
| 90 | qputenvcxx . . $ qputenv(d42e8231112a1b5b).("AG_APPLICATIONS", TEST_DATA_DIRcxx . . $ `<built-in>:484:9`!); |
| 91 | qputenvcxx . . $ qputenv(d42e8231112a1b5b).("AG_PROVIDERS", TEST_DATA_DIRcxx . . $ `<built-in>:484:9`!); |
| 92 | qputenvcxx . . $ qputenv(d42e8231112a1b5b).("AG_SERVICES", TEST_DATA_DIRcxx . . $ `<built-in>:484:9`!); |
| 93 | qputenvcxx . . $ qputenv(d42e8231112a1b5b).("XDG_DATA_HOME", TEST_DATA_DIRcxx . . $ `<built-in>:484:9`!); |
| 94 | } |
| 95 | |
| 96 | void SignonuiRequestTestcxx . . $ SignonuiRequestTest#::testParameters_datacxx . . $ SignonuiRequestTest#testParameters_data(49f6e7a06ebc5aa8).() |
| 97 | { |
| 98 | QTestcxx . . $ QTest/::addColumncxx . . $ QTest/addColumn(cfe4d590606f2f46).<QVariantMapcxx . . $ QVariantMap#>("parameters"); |
| 99 | QTestcxx . . $ QTest/::addColumncxx . . $ QTest/addColumn(cfe4d590606f2f46).<uintcxx . . $ uint#>("identity"); |
| 100 | QTestcxx . . $ QTest/::addColumncxx . . $ QTest/addColumn(cfe4d590606f2f46).<QStringcxx . . $ QString#>("method"); |
| 101 | QTestcxx . . $ QTest/::addColumncxx . . $ QTest/addColumn(cfe4d590606f2f46).<QStringcxx . . $ QString#>("mechanism"); |
| 102 | QTestcxx . . $ QTest/::addColumncxx . . $ QTest/addColumn(cfe4d590606f2f46).<QStringcxx . . $ QString#>("ssoId"); |
| 103 | QTestcxx . . $ QTest/::addColumncxx . . $ QTest/addColumn(cfe4d590606f2f46).<QVariantMapcxx . . $ QVariantMap#>("clientData"); |
| 104 | |
| 105 | QTestcxx . . $ QTest/::newRowcxx . . $ QTest/newRow(71534bb7a360de38).("empty") <<cxx . . $ `operator<<`(61fb880f51a53ddf). |
| 106 | QVariantMapcxx . . $ QMap#QMap(ced63f7c635d850d).() <<cxx . . $ `operator<<`(61fb880f51a53ddf). |
| 107 | uintcxx . . $ uint#(0) <<cxx . . $ `operator<<`(61fb880f51a53ddf). |
| 108 | QStringcxx . . $ QString#QString(ced63f7c635d850d).() <<cxx . . $ `operator<<`(61fb880f51a53ddf). |
| 109 | QStringcxx . . $ QString#QString(ced63f7c635d850d).() <<cxx . . $ `operator<<`(61fb880f51a53ddf). |
| 110 | QStringcxx . . $ QString#QString(ced63f7c635d850d).() <<cxx . . $ `operator<<`(61fb880f51a53ddf). |
| 111 | QVariantMapcxx . . $ QMap#QMap(ced63f7c635d850d).(); |
| 112 | |
| 113 | QVariantMapcxx . . $ QVariantMap# clientDatacxx . . $ QMap#QMap(ced63f7c635d850d).; |
| 114 | clientData.insertcxx . . $ QMap#insert(929a1ed410fe8423).("some number"cxx . . $ QString#QString(85c52e162fed56f9)., 4cxx . . $ QVariant#QVariant(d4f767463ce0a6b3).); |
| 115 | |
| 116 | QVariantMapcxx . . $ QVariantMap# parameterscxx . . $ QMap#QMap(ced63f7c635d850d).; |
| 117 | parameters.insertcxx . . $ QMap#insert(929a1ed410fe8423).(SSOUI_KEY_CLIENT_DATAcxx . . $ `<external>/351535377674478989/uisessiondata_priv.h:72:9`!, clientDatacxx . . $ QVariant#QVariant(3e95df3e31f2cce8).); |
| 118 | parameters.insertcxx . . $ QMap#insert(929a1ed410fe8423).(SSOUI_KEY_IDENTITYcxx . . $ `<external>/351535377674478989/uisessiondata_priv.h:59:9`!, uintcxx . . $ QVariant#QVariant(cb2f890c2fdad230).(45)); |
| 119 | parameters.insertcxx . . $ QMap#insert(929a1ed410fe8423).(SSOUI_KEY_METHODcxx . . $ `<external>/351535377674478989/uisessiondata_priv.h:76:9`!, QStringcxx . . $ QVariant#QVariant(3520e46b33348bf6).("a method")); |
| 120 | parameters.insertcxx . . $ QMap#insert(929a1ed410fe8423).(SSOUI_KEY_MECHANISMcxx . . $ `<external>/351535377674478989/uisessiondata_priv.h:77:9`!, QStringcxx . . $ QVariant#QVariant(3520e46b33348bf6).("a mechanism")); |
| 121 | parameters.insertcxx . . $ QMap#insert(929a1ed410fe8423).(SSOUI_KEY_REQUESTIDcxx . . $ `<external>/351535377674478989/uisessiondata_priv.h:54:9`!, QStringcxx . . $ QVariant#QVariant(3520e46b33348bf6).("/id-4")); |
| 122 | |
| 123 | |
| 124 | QTestcxx . . $ QTest/::newRowcxx . . $ QTest/newRow(71534bb7a360de38).("basic") <<cxx . . $ `operator<<`(61fb880f51a53ddf). |
| 125 | parameters <<cxx . . $ `operator<<`(61fb880f51a53ddf). |
| 126 | uintcxx . . $ uint#(45) <<cxx . . $ `operator<<`(1c43a92f59c6a770). |
| 127 | "a method" <<cxx . . $ `operator<<`(1c43a92f59c6a770). |
| 128 | "a mechanism" <<cxx . . $ `operator<<`(1c43a92f59c6a770). |
| 129 | "/id-4" <<cxx . . $ `operator<<`(61fb880f51a53ddf). |
| 130 | clientData; |
| 131 | } |
| 132 | |
| 133 | void SignonuiRequestTestcxx . . $ SignonuiRequestTest#::testParameterscxx . . $ SignonuiRequestTest#testParameters(49f6e7a06ebc5aa8).() |
| 134 | { |
| 135 | QFETCHcxx . . $ `<external>/8602788698586413231/qtestcase.h:201:9`!(QVariantMap, parameters); |
| 136 | QFETCHcxx . . $ `<external>/8602788698586413231/qtestcase.h:201:9`!(QString, method); |
| 137 | QFETCHcxx . . $ `<external>/8602788698586413231/qtestcase.h:201:9`!(QString, mechanism); |
| 138 | QFETCHcxx . . $ `<external>/8602788698586413231/qtestcase.h:201:9`!(QString, ssoId); |
| 139 | QFETCHcxx . . $ `<external>/8602788698586413231/qtestcase.h:201:9`!(QVariantMap, clientData); |
| 140 | |
| 141 | TestRequestcxx . . $ TestRequest# requestcxx . . $ TestRequest#TestRequest(8342fb91063d2b81).("unconfined"cxx . . $ QString#QString(85c52e162fed56f9)., parameters); |
| 142 | QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(request.method(), method); |
| 143 | QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(request.mechanism(), mechanism); |
| 144 | QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(request.ssoId(), ssoId); |
| 145 | QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(request.clientData(), clientData); |
| 146 | } |
| 147 | |
| 148 | void SignonuiRequestTestcxx . . $ SignonuiRequestTest#::testHandlercxx . . $ SignonuiRequestTest#testHandler(49f6e7a06ebc5aa8).() |
| 149 | { |
| 150 | QVariantMapcxx . . $ QVariantMap# parameterscxx . . $ QMap#QMap(ced63f7c635d850d).; |
| 151 | TestRequestcxx . . $ TestRequest# requestcxx . . $ TestRequest#TestRequest(8342fb91063d2b81).("unconfined"cxx . . $ QString#QString(85c52e162fed56f9)., parameters); |
| 152 | QVERIFYcxx . . $ `<external>/8602788698586413231/qtestcase.h:63:9`!(request.handler() == 0); |
| 153 | |
| 154 | SignOnUicxx . . $ SignOnUi/::RequestHandlercxx . . $ SignOnUi/RequestHandler# *handler = new SignOnUicxx . . $ SignOnUi/::RequestHandlercxx . . $ SignOnUi/RequestHandler#; |
| 155 | request.setHandlercxx . . $ SignOnUi/Request#setHandler(33a36a88f472ca4b).(handler); |
| 156 | QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(request.handler(), handler); |
| 157 | |
| 158 | /* Try to set another handler; this won't be allowed */ |
| 159 | SignOnUicxx . . $ SignOnUi/::RequestHandlercxx . . $ SignOnUi/RequestHandler# *handler2 = new SignOnUicxx . . $ SignOnUi/::RequestHandlercxx . . $ SignOnUi/RequestHandler#; |
| 160 | request.setHandlercxx . . $ SignOnUi/Request#setHandler(33a36a88f472ca4b).(handler2); |
| 161 | QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(request.handler(), handler); |
| 162 | |
| 163 | delete handler2; |
| 164 | delete handler; |
| 165 | } |
| 166 | |
| 167 | QTEST_MAINcxx . . $ `<external>/4204159469433502174/qtest.h:508:9`!(SignonuiRequestTest); |
| 168 | |
| 169 | #include "tst_signonui_request.moc"cxx . . $ `<file>/build/tests/online-accounts-ui/tst_signonui_request/tst_signonui_request_autogen/include/tst_signonui_request.moc`/ |