1 /*  This file is part of the KDE project
2     Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
3 
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Library General Public
6     License version 2 as published by the Free Software Foundation.
7 
8     This library is distributed in the hope that it will be useful,
9     but WITHOUT ANY WARRANTY; without even the implied warranty of
10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11     Library General Public License for more details.
12 
13     You should have received a copy of the GNU Library General Public License
14     along with this library; see the file COPYING.LIB.  If not, write to
15     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16     Boston, MA 02110-1301, USA.
17 
18 */
19 
20 #include <QCoreApplication>
21 #include <QtGlobal>
22 #include <kcomponentdata.h>
23 #include <ksharedconfig.h>
24 #include <kconfiggroup.h>
25 
26 class Tester
27 {
28 public:
29     void initConfig();
30     ~Tester();
31 
32 private:
33     KConfig *m_config;
34 };
35 
initConfig()36 void Tester::initConfig()
37 {
38     m_config = new KConfig("kconfigafterkglobaltest");
39 }
40 
Q_GLOBAL_STATIC(Tester,globalTestObject)41 Q_GLOBAL_STATIC(Tester, globalTestObject)
42 
43 int main(int argc, char **argv)
44 {
45     Tester *t = globalTestObject();
46     Q_UNUSED(t);
47 
48     QCoreApplication app(argc, argv);
49     KComponentData componentData("kconfigafterkglobaltest");
50 
51     KSharedConfigPtr cfg = KSharedConfig::openConfig();
52     KConfigGroup group = cfg->group("test");
53     group.writeEntry("test", 1);
54 
55     t->initConfig();
56 }
57 
~Tester()58 Tester::~Tester()
59 {
60     Q_ASSERT(!KComponentData::hasMainComponent()); // the KGlobal K_GLOBAL_STATIC should already be deleted
61     KConfigGroup group = m_config->group("test");
62     group.writeEntry("test", 1);
63     delete m_config; // this calls KConfig::sync() which needs KStandardDirs
64 }
65