File indexing completed on 2024-04-28 04:34:23
0001 /* This file is part of KDevelop 0002 Copyright 2006 Hamish Rodda <rodda@kde.org> 0003 Copyright 2008,2010 Niko Sams <niko.sams@gmail.com> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License version 2 as published by the Free Software Foundation. 0008 0009 This library 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 GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef DUCHAINTESTBASE_H 0021 #define DUCHAINTESTBASE_H 0022 0023 #include <QObject> 0024 #include <QByteArray> 0025 #include <QTest> 0026 #include <language/duchain/duchain.h> 0027 #include <language/duchain/duchainlock.h> 0028 0029 namespace KDevelop 0030 { 0031 class TopDUContext; 0032 } 0033 0034 namespace Css 0035 { 0036 /** 0037 * Manage pointer to TopDUContexts and release them properly, even if a test fails 0038 */ 0039 struct DUChainReleaser { 0040 DUChainReleaser(KDevelop::TopDUContext* top) : m_top(top) {} 0041 ~DUChainReleaser() { 0042 KDevelop::DUChainWriteLocker lock(KDevelop::DUChain::lock()); 0043 KDevelop::DUChain::self()->removeDocumentChain(m_top); 0044 } 0045 KDevelop::TopDUContext* m_top; 0046 }; 0047 0048 class DUChainTestBase : public QObject 0049 { 0050 Q_OBJECT 0051 0052 public: 0053 DUChainTestBase(); 0054 0055 public: 0056 enum DumpArea { 0057 DumpNone = 0, 0058 DumpAST = 1, 0059 DumpDUChain = 2, 0060 DumpAll = 3 0061 }; 0062 Q_DECLARE_FLAGS(DumpAreas, DumpArea) 0063 0064 public slots: 0065 void initTestCase(); 0066 void cleanupTestCase(); 0067 0068 protected: 0069 KDevelop::TopDUContext* parse(const QByteArray& unit, DumpAreas dump = static_cast<DumpAreas>(DumpAST | DumpDUChain), QString fileName = QString()); 0070 }; 0071 0072 Q_DECLARE_OPERATORS_FOR_FLAGS(DUChainTestBase::DumpAreas) 0073 } 0074 0075 #endif