aboutsummaryrefslogtreecommitdiffstats
path: root/tests/testabstractmetaclass.cpp
blob: d7eb77ca299a7c4f82676101b533c8a4eec5d4c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* This file is part of the API Extractor project.
*
* Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
*
* Contact: PySide team <contact@pyside.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/

#include "testabstractmetaclass.h"
#include "abstractmetabuilder.h"
#include <QtTest/QTest>
#include <QBuffer>


TestAbstractMetaClass::TestAbstractMetaClass() : m_builder(0)
{
}

void TestAbstractMetaClass::init()
{
    m_builder = new AbstractMetaBuilder;
}

void TestAbstractMetaClass::cleanup()
{
    delete m_builder;
    m_builder = 0;
}

void TestAbstractMetaClass::processCode (const char* cppCode, const char* xmlCode )
{
    QBuffer buffer;
    // parse typesystem
    buffer.setData(xmlCode);
    TypeDatabase::instance()->parseFile(&buffer);
    buffer.close();
    // parse C++ code
    buffer.setData(cppCode);
    m_builder->build(&buffer);
}

void TestAbstractMetaClass::testClassName()
{
    const char* cppCode ="class ClassName {};";
    const char* xmlCode = "<typesystem package=\"Foo\"><value-type name=\"ClassName\"/></typesystem>";
    processCode(cppCode, xmlCode);
    AbstractMetaClassList classes = m_builder->classes();
    QCOMPARE(classes.count(), 1);
    QCOMPARE(classes[0]->name(), QString("ClassName"));
}

void TestAbstractMetaClass::testClassNameUnderNamespace()
{
    const char* cppCode ="namespace Namespace { class ClassName {}; }";
    const char* xmlCode = "\
    <typesystem package=\"Foo\"> \
        <namespace-type name=\"Namespace\"/> \
        <value-type name=\"Namespace::ClassName\"/> \
    </typesystem>";
    processCode(cppCode, xmlCode);
    AbstractMetaClassList classes = m_builder->classes();
    QCOMPARE(classes.count(), 2); // 1 namespace + 1 class
    QCOMPARE(classes[0]->name(), QString("ClassName"));
    QCOMPARE(classes[0]->qualifiedCppName(), QString("Namespace::ClassName"));
    QCOMPARE(classes[1]->name(), QString("Namespace"));
}


QTEST_APPLESS_MAIN(TestAbstractMetaClass)

#include "testabstractmetaclass.moc"