add more spacing
[personal-kdebase.git] / runtime / kwalletd / tests / kwalletnoautoclose.cpp
blob423c66e8a6bf05c17de5f044dea3dba93156d566
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 <KAboutData>
26 #include <KApplication>
27 #include <KCmdLineArgs>
28 #include <QEventLoop>
29 #include <QtDBus>
31 static QTextStream _out(stdout, QIODevice::WriteOnly);
32 static QString _kdewallet;
34 int openAndClose()
36 QDBusInterface service("org.kde.kwalletd", "/modules/kwalletd");
37 if (!service.isValid()) {
38 _out << "Constructed service is invalid!" << endl;
39 return 1;
42 QDBusReply<int> h = service.call(QDBus::Block, "open", _kdewallet, (qlonglong)0, "kwalletnoautoclose");
43 if (!h.isValid() || h.value() < 0) {
44 _out << "Opening the wallet failed!" << endl;
45 _out << "Error: " << h.error().message() << endl;
46 return 1;
47 } else {
48 _out << "Wallet opened." << endl;
51 _out << "closing the wallet" << endl;
52 QDBusReply<int> r = service.call(QDBus::Block, "close", h.value(), false, "kwalletnoautoclose");
54 return r;
57 int main(int argc, char *argv[])
59 KAboutData aboutData("kwalletnoautoclose", 0, ki18n("kwalletnoautoclose"), "version");
60 KCmdLineArgs::init(argc, argv, &aboutData);
61 KApplication app;
63 QDBusInterface service("org.kde.kwalletd", "/modules/kwalletd");
64 if (!service.isValid()) {
65 _out << "Constructed service is invalid!" << endl;
66 return 1;
69 QDBusReply<bool> r = service.call(QDBus::Block, "isEnabled");
70 if (!r.isValid() || !r) {
71 _out << "kwalletd is disabled or not running!" << endl;
72 return 1;
75 QDBusReply<QString> kdewallet = service.call(QDBus::Block, "localWallet");
76 _kdewallet = kdewallet;
77 _out << "local wallet is " << _kdewallet << endl;
79 QDBusReply<bool> open = service.call(QDBus::Block, "isOpen", _kdewallet);
80 if (open) {
81 _out << "wallet is already open. Please close to run this test." << endl;
82 return 1;
85 int rc;
87 _out << "Opening and closing the wallet properly." << endl;
88 rc = openAndClose();
89 if (rc != 0) {
90 _out << "FAILED!" << endl;
91 return rc;
94 _out << "Opening and exiting." << endl;
95 QDBusReply<int> h = service.call(QDBus::Block, "open", _kdewallet, (qlonglong)0, "kwalletnoautoclose");
96 if (h < 0) {
97 _out << "Opening the wallet failed!" << endl;
98 return 1;
99 } else {
100 _out << "Wallet opened." << endl;
103 _out << "Exiting. Wallet should stay open." << endl;
105 return 0;