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 "testnamespace.h"
30 #include <QtTest/QTest>
31 #include "testutil.h"
32 #include <abstractmetalang.h>
33 #include <typesystem.h>
34 
testNamespaceMembers()35 void NamespaceTest::testNamespaceMembers()
36 {
37     const char* cppCode = "\
38     namespace Namespace\n\
39     {\n\
40         enum Option {\n\
41             OpZero,\n\
42             OpOne\n\
43         };\n\
44         void foo(Option opt);\n\
45     };\n";
46     const char* xmlCode = "\
47     <typesystem package='Foo'>\n\
48         <namespace-type name='Namespace'>\n\
49             <enum-type name='Option' />\n\
50         </namespace-type>\n\
51     </typesystem>\n";
52     QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false));
53     QVERIFY(!builder.isNull());
54     AbstractMetaClassList classes = builder->classes();
55     AbstractMetaClass *ns = AbstractMetaClass::findClass(classes, QLatin1String("Namespace"));
56     QVERIFY(ns);
57     const AbstractMetaEnum* metaEnum = ns->findEnum(QLatin1String("Option"));
58     QVERIFY(metaEnum);
59     const AbstractMetaFunction* func = ns->findFunction(QLatin1String("foo"));
60     QVERIFY(func);
61 }
62 
testNamespaceInnerClassMembers()63 void NamespaceTest::testNamespaceInnerClassMembers()
64 {
65     const char* cppCode = "\
66     namespace OuterNamespace\n\
67     {\n\
68         namespace InnerNamespace {\n\
69             struct SomeClass {\n\
70                 void method();\n\
71             };\n\
72         };\n\
73     };\n";
74     const char* xmlCode = "\
75     <typesystem package='Foo'>\n\
76         <namespace-type name='OuterNamespace'>\n\
77             <namespace-type name='InnerNamespace'>\n\
78                 <value-type name='SomeClass'/>\n\
79             </namespace-type>\n\
80         </namespace-type>\n\
81     </typesystem>\n";
82     QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false));
83     QVERIFY(!builder.isNull());
84     AbstractMetaClassList classes = builder->classes();
85     const AbstractMetaClass *ons = AbstractMetaClass::findClass(classes, QLatin1String("OuterNamespace"));
86     QVERIFY(ons);
87     const AbstractMetaClass *ins = AbstractMetaClass::findClass(classes, QLatin1String("OuterNamespace::InnerNamespace"));
88     QVERIFY(ins);
89     const AbstractMetaClass *sc = AbstractMetaClass::findClass(classes, QLatin1String("OuterNamespace::InnerNamespace::SomeClass"));
90     QVERIFY(sc);
91     const AbstractMetaFunction* meth = sc->findFunction(QLatin1String("method"));
92     QVERIFY(meth);
93 }
94 
95 QTEST_APPLESS_MAIN(NamespaceTest)
96 
97