1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of Qt for Python.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28
29 #include "testcontainer.h"
30 #include <QtTest/QTest>
31 #include "testutil.h"
32 #include <abstractmetalang.h>
33 #include <typesystem.h>
34
testContainerType()35 void TestContainer::testContainerType()
36 {
37 const char* cppCode ="\
38 namespace std {\n\
39 template<class T>\n\
40 class list {\n\
41 T get(int x) { return 0; }\n\
42 };\n\
43 }\n\
44 class A : public std::list<int> {\n\
45 };\n";
46 const char* xmlCode = "\
47 <typesystem package='Foo'>\n\
48 <namespace-type name='std' generate='no' />\n\
49 <container-type name='std::list' type='list' />\n\
50 <object-type name='A'/>\n\
51 </typesystem>\n";
52
53 QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, true));
54 QVERIFY(!builder.isNull());
55 AbstractMetaClassList classes = builder->classes();
56 QCOMPARE(classes.count(), 2);
57 //search for class A
58 AbstractMetaClass* classA = AbstractMetaClass::findClass(classes, QLatin1String("A"));
59 QVERIFY(classA);
60 auto baseContainer = classA->typeEntry()->baseContainerType();
61 QVERIFY(baseContainer);
62 QCOMPARE(reinterpret_cast<const ContainerTypeEntry*>(baseContainer)->containerKind(),
63 ContainerTypeEntry::ListContainer);
64 }
65
testListOfValueType()66 void TestContainer::testListOfValueType()
67 {
68 const char* cppCode ="\
69 namespace std {\n\
70 template<class T>\n\
71 class list {\n\
72 T get(int x) { return 0; }\n\
73 };\n\
74 }\n\
75 class ValueType {};\n\
76 class A : public std::list<ValueType> {\n\
77 };\n";
78 const char* xmlCode = "\
79 <typesystem package='Foo'>\n\
80 <namespace-type name='std' generate='no'/>\n\
81 <container-type name='std::list' type='list'/>\n\
82 <value-type name='ValueType'/>\n\
83 <value-type name='A'/>\n\
84 </typesystem>\n";
85
86 QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, true));
87 QVERIFY(!builder.isNull());
88 AbstractMetaClassList classes = builder->classes();
89 QCOMPARE(classes.count(), 3);
90
91 const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, QLatin1String("A"));
92 QVERIFY(classA);
93 QCOMPARE(classA->templateBaseClassInstantiations().count(), 1);
94 const AbstractMetaType *templateInstanceType =
95 classA->templateBaseClassInstantiations().constFirst();
96 QVERIFY(templateInstanceType);
97
98 QCOMPARE(templateInstanceType->indirections(), 0);
99 QVERIFY(!templateInstanceType->typeEntry()->isObject());
100 QVERIFY(templateInstanceType->typeEntry()->isValue());
101 QCOMPARE(templateInstanceType->referenceType(), NoReference);
102 QVERIFY(!templateInstanceType->isObject());
103 QVERIFY(!templateInstanceType->isValuePointer());
104 QVERIFY(templateInstanceType->isValue());
105 }
106
107 QTEST_APPLESS_MAIN(TestContainer)
108
109