File indexing completed on 2024-05-12 15:47:07

0001 #include "kwalletasync.h"
0002 
0003 #include <QApplication>
0004 #include <QTest>
0005 #include <QTextStream>
0006 #include <QTimer>
0007 
0008 #include <KAboutData>
0009 #include <QDBusConnection>
0010 #include <QDBusConnectionInterface>
0011 #include <kwallet.h>
0012 
0013 #include "kwallettest.h"
0014 
0015 static QTextStream _out(stdout, QIODevice::WriteOnly);
0016 
0017 void KWalletAsyncTest::init()
0018 {
0019     if (!qEnvironmentVariableIsSet("DISPLAY")) {
0020         QSKIP("$DISPLAY is not set. These tests cannot be done without a graphical system.");
0021     }
0022 }
0023 
0024 void KWalletAsyncTest::openWallet()
0025 {
0026     _out << "About to ask for wallet async\n";
0027 
0028     // we have no wallet: ask for one.
0029     KWallet::Wallet *wallet = KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(), 0, KWallet::Wallet::Asynchronous);
0030     QVERIFY(wallet != nullptr);
0031 
0032     WalletReceiver r;
0033     QVERIFY(connect(wallet, &KWallet::Wallet::walletOpened, &r, &WalletReceiver::walletOpened));
0034 
0035     _out << "About to start 30 second event loop\n";
0036 
0037     QTimer::singleShot(30000, qApp, SLOT(quit()));
0038     int ret = qApp->exec();
0039 
0040     if (ret == 0) {
0041         _out << "Timed out!\n";
0042     } else {
0043         _out << "Success!\n";
0044     }
0045     _out.flush();
0046 
0047     QVERIFY2(ret == 1, "Timeout when waiting for wallet open");
0048 }
0049 
0050 void WalletReceiver::walletOpened(bool got)
0051 {
0052     _out << "Got async wallet: " << got << '\n';
0053     _out.flush();
0054     qApp->exit(1);
0055 }
0056 
0057 QTEST_GUILESS_MAIN(KWalletAsyncTest)
0058 
0059 #include "moc_kwalletasync.cpp"