aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/ApiExtractor/tests/testprimitivetypetag.cpp
blob: 99cced09d7eeb2a6508e3b3f7ee2ff0a927dfd8a (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
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "testprimitivetypetag.h"
#include "testutil.h"
#include <abstractmetalang.h>
#include <primitivetypeentry.h>

#include <qtcompat.h>

#include <QtTest/QTest>

using namespace Qt::StringLiterals;

void TestPrimitiveTypeTag::testPrimitiveTypeDefaultConstructor()
{
    const char cppCode[] = "\
    struct A {};\n\
    struct B {};\n";
    const char xmlCode[] = "\
    <typesystem package=\"Foo\">\n\
        <primitive-type name='A' default-constructor='A()'/>\n\
        <object-type name='B'/>\n\
    </typesystem>\n";
    QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false));
    QVERIFY(builder);

    AbstractMetaClassList classes = builder->classes();
    QCOMPARE(classes.size(), 1);
    const auto classB = AbstractMetaClass::findClass(classes, "B");
    QVERIFY(classB);

    auto typeEntry = TypeDatabase::instance()->findPrimitiveType(u"A"_s);
    QVERIFY(typeEntry);
    QVERIFY(typeEntry->hasDefaultConstructor());
    QCOMPARE(typeEntry->defaultConstructor(), u"A()");
}

QTEST_APPLESS_MAIN(TestPrimitiveTypeTag)