1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2017 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the test suite of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #include <QtTest/QtTest> |
30 | #include <QtPurchasing/QInAppStore> |
31 | #include <QtPurchasing/QInAppTransaction> |
32 | |
33 | class tst_QInAppStore: public QObject |
34 | { |
35 | Q_OBJECT |
36 | private slots: |
37 | void registerUnknownProduct(); |
38 | }; |
39 | |
40 | class SignalReceiver: public QObject |
41 | { |
42 | Q_OBJECT |
43 | public: |
44 | QList<QInAppTransaction *> readyTransactions; |
45 | QList<QInAppProduct *> registeredProducts; |
46 | QList<QPair<QInAppProduct::ProductType, QString> > unknownProducts; |
47 | |
48 | public slots: |
49 | void productRegistered(QInAppProduct *product) |
50 | { |
51 | registeredProducts.append(t: product); |
52 | } |
53 | |
54 | void productUnknown(QInAppProduct::ProductType productType, const QString &identifier) |
55 | { |
56 | unknownProducts.append(t: qMakePair(x: productType, y: identifier)); |
57 | } |
58 | |
59 | void transactionReady(QInAppTransaction *transaction) |
60 | { |
61 | readyTransactions.append(t: transaction); |
62 | } |
63 | }; |
64 | |
65 | void tst_QInAppStore::registerUnknownProduct() |
66 | { |
67 | #ifdef Q_OS_DARWIN |
68 | QSKIP("This test crashes on macOS. See QTBUG-56786." ); |
69 | #endif |
70 | |
71 | QInAppStore store(this); |
72 | SignalReceiver receiver; |
73 | |
74 | connect(sender: &store, signal: &QInAppStore::productRegistered, receiver: &receiver, slot: &SignalReceiver::productRegistered); |
75 | connect(sender: &store, signal: &QInAppStore::productUnknown, receiver: &receiver, slot: &SignalReceiver::productUnknown); |
76 | connect(sender: &store, signal: &QInAppStore::transactionReady, receiver: &receiver, slot: &SignalReceiver::transactionReady); |
77 | |
78 | store.registerProduct(productType: QInAppProduct::Consumable, QStringLiteral("unknownConsumable" )); |
79 | store.registerProduct(productType: QInAppProduct::Unlockable, QStringLiteral("unknownUnlockable" )); |
80 | |
81 | //The backend is implemented on iOS, macOS, WinRT and Android, for others we expect failure. |
82 | #if !(defined(Q_OS_DARWIN) && !defined(Q_OS_WATCHOS)) && !defined(Q_OS_ANDROID) && !defined(Q_OS_WINRT) |
83 | QEXPECT_FAIL("" , "Qt Purchasing not implemented on this platform." , Abort); |
84 | #endif |
85 | |
86 | //Due to network overload or connectivity issues QTRY_COMPARE sometimes fails with timeout, |
87 | //that's why we need to increase the value, since it's better to wait than to fail. |
88 | QTRY_COMPARE_WITH_TIMEOUT(receiver.unknownProducts.size(), 2, 10000); |
89 | QCOMPARE(receiver.registeredProducts.size(), 0); |
90 | QCOMPARE(receiver.readyTransactions.size(), 0); |
91 | |
92 | int found = 0; |
93 | for (int i = 0; i < receiver.unknownProducts.size(); ++i) { |
94 | const QPair<QInAppProduct::ProductType, QString> &product = receiver.unknownProducts.at(i); |
95 | |
96 | if ((product.first == QInAppProduct::Unlockable && product.second == QStringLiteral("unknownUnlockable" )) |
97 | || (product.first == QInAppProduct::Consumable && product.second == QStringLiteral("unknownConsumable" ))) { |
98 | found++; |
99 | } |
100 | } |
101 | |
102 | QCOMPARE(found, 2); |
103 | } |
104 | |
105 | QTEST_MAIN(tst_QInAppStore) |
106 | |
107 | #include "tst_qinappstore.moc" |
108 | |