|
| 1 | +/* |
| 2 | + * This file is part of the API Extractor project. |
| 3 | + * |
| 4 | + * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). |
| 5 | + * |
| 6 | + * Contact: PySide team <[email protected]> |
| 7 | + * |
| 8 | + * This program is free software; you can redistribute it and/or |
| 9 | + * modify it under the terms of the GNU General Public License |
| 10 | + * version 2 as published by the Free Software Foundation. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, but |
| 13 | + * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | + * General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program; if not, write to the Free Software |
| 19 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 20 | + * 02110-1301 USA |
| 21 | + * |
| 22 | + */ |
| 23 | + |
| 24 | +#include "testinserttemplate.h" |
| 25 | +#include <QtTest/QTest> |
| 26 | +#include "testutil.h" |
| 27 | + |
| 28 | +void TestInsertTemplate::testInsertTemplateOnClassInjectCode() |
| 29 | +{ |
| 30 | + const char* cppCode ="struct A{};"; |
| 31 | + const char* xmlCode = "\ |
| 32 | + <typesystem package='Foo'>\ |
| 33 | + <template name='code_template'>\ |
| 34 | + code template content\ |
| 35 | + </template>\ |
| 36 | + <value-type name='A'>\ |
| 37 | + <inject-code class='native'>\ |
| 38 | + <insert-template name='code_template'/>\ |
| 39 | + </inject-code>\ |
| 40 | + </value-type>\ |
| 41 | + </typesystem>"; |
| 42 | + TestUtil t(cppCode, xmlCode, false); |
| 43 | + AbstractMetaClassList classes = t.builder()->classes(); |
| 44 | + QCOMPARE(classes.count(), 1); |
| 45 | + AbstractMetaClass* classA = classes.findClass("A"); |
| 46 | + QVERIFY(classA); |
| 47 | + QCOMPARE(classA->typeEntry()->codeSnips().count(), 1); |
| 48 | + QString code = classA->typeEntry()->codeSnips().first().code(); |
| 49 | + QVERIFY(code.contains("code template content")); |
| 50 | +} |
| 51 | + |
| 52 | +void TestInsertTemplate::testInsertTemplateOnModuleInjectCode() |
| 53 | +{ |
| 54 | + const char* cppCode =""; |
| 55 | + const char* xmlCode = "\ |
| 56 | + <typesystem package='Foo'>\ |
| 57 | + <template name='code_template'>\ |
| 58 | + code template content\ |
| 59 | + </template>\ |
| 60 | + <inject-code class='native'>\ |
| 61 | + <insert-template name='code_template'/>\ |
| 62 | + </inject-code>\ |
| 63 | + </typesystem>"; |
| 64 | + TestUtil t(cppCode, xmlCode, false); |
| 65 | + AbstractMetaClassList classes = t.builder()->classes(); |
| 66 | + QVERIFY(classes.isEmpty()); |
| 67 | + |
| 68 | + TypeEntry* module = TypeDatabase::instance()->findType("Foo"); |
| 69 | + QVERIFY(module); |
| 70 | + QCOMPARE(module->codeSnips().count(), 1); |
| 71 | + QString code = module->codeSnips().first().code().trimmed(); |
| 72 | + QVERIFY(code.contains("code template content")); |
| 73 | +} |
| 74 | + |
| 75 | +void TestInsertTemplate::testInvalidTypeSystemTemplate() |
| 76 | +{ |
| 77 | + const char* cppCode =""; |
| 78 | + const char* xmlCode = "\ |
| 79 | + <typesystem package='Foo'>\ |
| 80 | + <inject-code class='native'>\ |
| 81 | + <insert-template name='this_code_template_does_not_exists'/>\ |
| 82 | + </inject-code>\ |
| 83 | + </typesystem>"; |
| 84 | + TestUtil t(cppCode, xmlCode, false); |
| 85 | + AbstractMetaClassList classes = t.builder()->classes(); |
| 86 | + QVERIFY(classes.isEmpty()); |
| 87 | + |
| 88 | + TypeEntry* module = TypeDatabase::instance()->findType("Foo"); |
| 89 | + QVERIFY(module); |
| 90 | + QCOMPARE(module->codeSnips().count(), 1); |
| 91 | + QString code = module->codeSnips().first().code().trimmed(); |
| 92 | + QVERIFY(code.isEmpty()); |
| 93 | +} |
| 94 | + |
| 95 | +void TestInsertTemplate::testValidAndInvalidTypeSystemTemplate() |
| 96 | +{ |
| 97 | + const char* cppCode =""; |
| 98 | + const char* xmlCode = "\ |
| 99 | + <typesystem package='Foo'>\ |
| 100 | + <template name='code_template'>\ |
| 101 | + code template content\ |
| 102 | + </template>\ |
| 103 | + <inject-code class='native'>\ |
| 104 | + <insert-template name='this_code_template_does_not_exists'/>\ |
| 105 | + <insert-template name='code_template'/>\ |
| 106 | + </inject-code>\ |
| 107 | + </typesystem>"; |
| 108 | + TestUtil t(cppCode, xmlCode, false); |
| 109 | + AbstractMetaClassList classes = t.builder()->classes(); |
| 110 | + QVERIFY(classes.isEmpty()); |
| 111 | + |
| 112 | + TypeEntry* module = TypeDatabase::instance()->findType("Foo"); |
| 113 | + QVERIFY(module); |
| 114 | + QCOMPARE(module->codeSnips().count(), 1); |
| 115 | + QString code = module->codeSnips().first().code().trimmed(); |
| 116 | + QVERIFY(code.contains("code template content")); |
| 117 | +} |
| 118 | + |
| 119 | +QTEST_APPLESS_MAIN(TestInsertTemplate) |
| 120 | + |
| 121 | +#include "testinserttemplate.moc" |
0 commit comments