File indexing completed on 2022-11-29 18:25:14

0001 /*  This file is part of the KDE project
0002     Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
0003 
0004     This program is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU General Public License as
0006     published by the Free Software Foundation; either version 2 of
0007     the License or (at your option) version 3 of the license.
0008 
0009     This program is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0012     GNU General Public License for more details.
0013 
0014     You should have received a copy of the GNU General Public License
0015     along with this program.  If not, see <http://www.gnu.org/licenses/>.
0016 
0017 */
0018 
0019 #include <kglobal.h>
0020 #include <QDebug>
0021 
0022 class A
0023 {
0024 public:
0025     A() : i(1) {}
0026     int i;
0027 };
0028 
0029 K_GLOBAL_STATIC(A, globalA)
0030 K_GLOBAL_STATIC(A, globalA2)
0031 
0032 class B
0033 {
0034 public:
0035     ~B()
0036     {
0037         Q_ASSERT(globalA.isDestroyed());
0038         qDebug() << "All global statics were successfully destroyed.";
0039     }
0040 };
0041 
0042 Q_GLOBAL_STATIC(B, globalB)
0043 
0044 int main(int, char **)
0045 {
0046     Q_ASSERT(globalB);
0047 
0048     Q_ASSERT(!globalA.isDestroyed());
0049     A *a = globalA;
0050     Q_ASSERT(a);
0051     A &x = *globalA;
0052     Q_ASSERT(a == &x);
0053     Q_ASSERT(a == globalA);
0054     Q_ASSERT(globalA->i == 1);
0055     Q_ASSERT(!globalA.isDestroyed());
0056 
0057     Q_ASSERT(!globalA2.isDestroyed());
0058     Q_ASSERT(globalA2);
0059     Q_ASSERT(globalA2->i == 1);
0060     Q_ASSERT(!globalA2.isDestroyed());
0061     globalA2.destroy();
0062     Q_ASSERT(globalA2.isDestroyed());
0063 
0064     // silence warnings
0065     Q_UNUSED(globalB)
0066     Q_UNUSED(a)
0067     Q_UNUSED(x)
0068 
0069     return 0;
0070 }