add more spacing
[personal-kdebase.git] / runtime / kwalletd / tests / kwalletmany.cpp
blob222278ad0e5b8d1724ecb5014a33f50ba00dc61f
1 // -*- indent-tabs-mode: t; tab-width: 4; c-basic-offset: 4; -*-
2 /*
3 This file is part of the KDE libraries
5 Copyright (c) 2008 Michael Leupold <lemma@confuego.org>
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
24 #include <QTextStream>
25 #include <QTimer>
26 #include <QThread>
27 #include <KAboutData>
28 #include <KApplication>
29 #include <KCmdLineArgs>
30 #include <KWallet/Wallet>
32 #include "kwalletmany.h"
34 #define NUMWALLETS 10
36 using namespace KWallet;
38 static QTextStream _out(stdout, QIODevice::WriteOnly);
40 KWalletMany::KWalletMany() : QObject(), _pending(10)
44 KWalletMany::~KWalletMany()
48 void KWalletMany::walletOpened(bool open)
50 _out << "Got async wallet: " << (open) << endl;
51 --_pending;
52 if (_pending == 0) {
53 quit();
57 void KWalletMany::quit()
59 if (_pending == 0) {
60 _out << "Success!" << endl;
61 } else {
62 _out << "Failed: " << _pending << " requests were not handled!" << endl;
64 _loop.quit();
67 void KWalletMany::openWallet()
69 QEventLoop waitLoop;
71 // open plenty of wallets in synchronous and asynchronous mode
72 for (int i = 0; i < NUMWALLETS; ++i) {
73 // request asynchronous wallet
74 _out << "About to ask for wallet async" << endl;
75 Wallet *wallet;
76 wallet = Wallet::openWallet(Wallet::NetworkWallet(), 0, Wallet::Asynchronous);
77 connect(wallet, SIGNAL(walletOpened(bool)), SLOT(walletOpened(bool)));
78 _wallets.append(wallet);
80 QTimer::singleShot(500, &waitLoop, SLOT(quit()));
81 waitLoop.exec();
84 _loop.exec();
85 while (!_wallets.isEmpty()) {
86 delete _wallets.takeFirst();
90 int main(int argc, char *argv[])
92 KAboutData aboutData("kwalletmany", 0, ki18n("kwalletmany"), "version");
93 KCmdLineArgs::init(argc, argv, &aboutData);
94 KApplication app;
95 KWalletMany m;
97 QTimer::singleShot(0, &m, SLOT(openWallet()));
98 QTimer::singleShot(30000, &m, SLOT(quit()));
100 return app.exec();
103 #include "kwalletmany.moc"