File indexing completed on 2024-05-12 15:47:07
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2008 Michael Leupold <lemma@confuego.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "kwalletmany.h" 0009 0010 #include <QApplication> 0011 #include <QTest> 0012 #include <QTextStream> 0013 #include <QThread> 0014 #include <kwallet.h> 0015 0016 #define NUMWALLETS 10 0017 0018 using namespace KWallet; 0019 0020 static QTextStream _out(stdout, QIODevice::WriteOnly); 0021 0022 KWalletMany::KWalletMany() 0023 : QObject() 0024 , _pending(10) 0025 { 0026 } 0027 0028 KWalletMany::~KWalletMany() 0029 { 0030 } 0031 0032 void KWalletMany::init() 0033 { 0034 if (!qEnvironmentVariableIsSet("DISPLAY")) { 0035 QSKIP("$DISPLAY is not set. These tests cannot be done without a graphical system."); 0036 } 0037 } 0038 0039 void KWalletMany::walletOpened(bool open) 0040 { 0041 _out << "Got async wallet: " << (open) << '\n'; 0042 _out.flush(); 0043 --_pending; 0044 } 0045 0046 void KWalletMany::openWallet() 0047 { 0048 // open plenty of wallets in synchronous and asynchronous mode 0049 for (int i = 0; i < NUMWALLETS; ++i) { 0050 // request asynchronous wallet 0051 _out << "About to ask for wallet async" << '\n'; 0052 Wallet *wallet; 0053 wallet = Wallet::openWallet(Wallet::NetworkWallet(), 0, Wallet::Asynchronous); 0054 QVERIFY(wallet != nullptr); 0055 connect(wallet, &KWallet::Wallet::walletOpened, this, &KWalletMany::walletOpened); 0056 _wallets.append(wallet); 0057 } 0058 _out.flush(); 0059 0060 // wait for 30s to receive the wallet opened replies from kwalletd 0061 QTRY_VERIFY_WITH_TIMEOUT(_pending == 0, 30000); 0062 0063 while (!_wallets.isEmpty()) { 0064 delete _wallets.takeFirst(); 0065 } 0066 QApplication::quit(); 0067 } 0068 0069 QTEST_GUILESS_MAIN(KWalletMany) 0070 0071 #include "moc_kwalletmany.cpp"