diff options
author | Renato Filho <renato.filho@openbossa.org> | 2010-05-25 16:15:05 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-09 19:10:03 -0300 |
commit | 2060c23e8d2d80c721dd4eb31a777f4be0fefdfc (patch) | |
tree | 7f2ac2dc24ef24f63befbc51fc17e091244f3446 | |
parent | 6ddb2e91990b119017819c6290ca6de6c6b6ea21 (diff) |
Created unittest to flag "since".
-rw-r--r-- | tests/testabstractmetatype.cpp | 35 | ||||
-rw-r--r-- | tests/testabstractmetatype.h | 2 | ||||
-rw-r--r-- | tests/testaddfunction.cpp | 31 | ||||
-rw-r--r-- | tests/testaddfunction.h | 1 | ||||
-rw-r--r-- | tests/testcodeinjection.cpp | 40 | ||||
-rw-r--r-- | tests/testcodeinjection.h | 2 | ||||
-rw-r--r-- | tests/testenum.cpp | 22 | ||||
-rw-r--r-- | tests/testenum.h | 3 | ||||
-rw-r--r-- | tests/testmodifyfunction.cpp | 37 | ||||
-rw-r--r-- | tests/testmodifyfunction.h | 1 | ||||
-rw-r--r-- | tests/testrefcounttag.cpp | 35 | ||||
-rw-r--r-- | tests/testrefcounttag.h | 1 | ||||
-rw-r--r-- | tests/testutil.h | 3 |
13 files changed, 205 insertions, 8 deletions
diff --git a/tests/testabstractmetatype.cpp b/tests/testabstractmetatype.cpp index 81e194fd3..207ec88f0 100644 --- a/tests/testabstractmetatype.cpp +++ b/tests/testabstractmetatype.cpp @@ -52,6 +52,41 @@ void TestAbstractMetaType::testConstCharPtrType() QVERIFY(!rtype->isValuePointer()); } +void TestAbstractMetaType::testApiVersionSupported() +{ + const char* cppCode ="class foo {}; class foo2 {};\ + void justAtest(); void justAtest3();"; + const char* xmlCode = "<typesystem package='Foo'>\ + <value-type name='foo' since='0.1'/>\ + <value-type name='foo2' since='1.0'/>\ + <value-type name='foo3' since='1.1'/>\ + <function signature='justAtest()' since='0.1'/>\ + <function signature='justAtest2()' since='1.1'/>\ + <function signature='justAtest3()'/>\ + </typesystem>"; + TestUtil t(cppCode, xmlCode, false, 1.0); + + AbstractMetaClassList classes = t.builder()->classes(); + QCOMPARE(classes.size(), 2); + + + AbstractMetaFunctionList functions = t.builder()->globalFunctions(); + QCOMPARE(functions.size(), 2); +} + + +void TestAbstractMetaType::testApiVersionNotSupported() +{ + const char* cppCode ="class object {};"; + const char* xmlCode = "<typesystem package='Foo'>\ + <value-type name='object' since='0.1'/>\ + </typesystem>"; + TestUtil t(cppCode, xmlCode, true, 0.1); + + AbstractMetaClassList classes = t.builder()->classes(); + QCOMPARE(classes.size(), 1); +} + void TestAbstractMetaType::testCharType() { const char* cppCode ="char justAtest(); class A {};"; diff --git a/tests/testabstractmetatype.h b/tests/testabstractmetatype.h index fa3a825ef..e62e05107 100644 --- a/tests/testabstractmetatype.h +++ b/tests/testabstractmetatype.h @@ -34,6 +34,8 @@ private slots: void testCharType(); void testTypedef(); void testTypedefWithTemplates(); + void testApiVersionSupported(); + void testApiVersionNotSupported(); }; #endif diff --git a/tests/testaddfunction.cpp b/tests/testaddfunction.cpp index ed14d7b3b..e2be5a153 100644 --- a/tests/testaddfunction.cpp +++ b/tests/testaddfunction.cpp @@ -30,7 +30,7 @@ void TestAddFunction::testParsingFuncNameAndConstness() { // generic test... const char sig1[] = "func(type1, const type2, const type3* const)"; - AddedFunction f1(sig1, "void"); + AddedFunction f1(sig1, "void", 0); QCOMPARE(f1.name(), QString("func")); QCOMPARE(f1.arguments().count(), 3); AddedFunction::TypeInfo retval = f1.returnType(); @@ -41,7 +41,7 @@ void TestAddFunction::testParsingFuncNameAndConstness() // test with a ugly template as argument and other ugly stuff const char sig2[] = " _fu__nc_ ( type1, const type2, const Abc<int& , C<char*> * > * *, const type3* const ) const "; - AddedFunction f2(sig2, "const Abc<int& , C<char*> * > * *"); + AddedFunction f2(sig2, "const Abc<int& , C<char*> * > * *", 0); QCOMPARE(f2.name(), QString("_fu__nc_")); QList< AddedFunction::TypeInfo > args = f2.arguments(); QCOMPARE(args.count(), 4); @@ -58,7 +58,7 @@ void TestAddFunction::testParsingFuncNameAndConstness() // function with no args. const char sig3[] = "func()"; - AddedFunction f3(sig3, "void"); + AddedFunction f3(sig3, "void", 0); QCOMPARE(f3.name(), QString("func")); QCOMPARE(f3.arguments().count(), 0); } @@ -170,7 +170,7 @@ void TestAddFunction::testAddFunctionCodeSnippets() void TestAddFunction::testAddFunctionWithoutParenteses() { const char sig1[] = "func"; - AddedFunction f1(sig1, "void"); + AddedFunction f1(sig1, "void", 0); QCOMPARE(f1.name(), QString("func")); QCOMPARE(f1.arguments().count(), 0); @@ -199,7 +199,7 @@ void TestAddFunction::testAddFunctionWithoutParenteses() void TestAddFunction::testAddFunctionWithDefaultArgs() { const char sig1[] = "func"; - AddedFunction f1(sig1, "void"); + AddedFunction f1(sig1, "void", 0); QCOMPARE(f1.name(), QString("func")); QCOMPARE(f1.arguments().count(), 0); @@ -262,7 +262,7 @@ void TestAddFunction::testAddFunctionAtModuleLevel() void TestAddFunction::testAddFunctionWithVarargs() { const char sig1[] = "func(int,char,...)"; - AddedFunction f1(sig1, "void"); + AddedFunction f1(sig1, "void", 0); QCOMPARE(f1.name(), QString("func")); QCOMPARE(f1.arguments().count(), 3); @@ -334,6 +334,25 @@ void TestAddFunction::testAddGlobalFunction() QVERIFY(!globalFuncs[1]->injectedCodeSnips().isEmpty()); } +void TestAddFunction::testAddFunctionWithApiVersion() +{ + const char cppCode[] = ""; + const char xmlCode[] = "\ + <typesystem package='Foo'>\ + <primitive-type name='int'/> \ + <add-function signature='globalFunc(int, int)' static='yes' since='1.3'>\ + <inject-code class='target' position='beginning'>custom_code();</inject-code>\ + </add-function>\ + <add-function signature='globalFunc2(int, int)' static='yes' since='0.1'>\ + <inject-code class='target' position='beginning'>custom_code();</inject-code>\ + </add-function>\ + </typesystem>"; + TestUtil t(cppCode, xmlCode, true, 0.1); + AbstractMetaFunctionList globalFuncs = t.builder()->globalFunctions(); + QCOMPARE(globalFuncs.count(), 1); +} + + QTEST_APPLESS_MAIN(TestAddFunction) #include "testaddfunction.moc" diff --git a/tests/testaddfunction.h b/tests/testaddfunction.h index 2d529f02a..37c064cfb 100644 --- a/tests/testaddfunction.h +++ b/tests/testaddfunction.h @@ -40,6 +40,7 @@ private slots: void testAddFunctionWithVarargs(); void testAddStaticFunction(); void testAddGlobalFunction(); + void testAddFunctionWithApiVersion(); }; #endif diff --git a/tests/testcodeinjection.cpp b/tests/testcodeinjection.cpp index b056ead83..6b708eb68 100644 --- a/tests/testcodeinjection.cpp +++ b/tests/testcodeinjection.cpp @@ -50,6 +50,46 @@ void TestCodeInjections::testReadFileUtf8() QVERIFY(code.indexOf(utf8Data) != -1); } +void TestCodeInjections::testInjectWithValidApiVersion() +{ + const char* cppCode ="struct A {};"; + const char* xmlCode = "\ + <typesystem package='Foo'> \ + <value-type name='A'> \ + <inject-code class='target' since='1.0'>\ + test Inject code\ + </inject-code>\ + </value-type>\ + </typesystem>"; + + TestUtil t(cppCode, xmlCode, true, 1.0); + + AbstractMetaClassList classes = t.builder()->classes(); + AbstractMetaClass* classA = classes.findClass("A"); + QCOMPARE(classA->typeEntry()->codeSnips().count(), 1); +} + +void TestCodeInjections::testInjectWithInvalidApiVersion() +{ + const char* cppCode ="struct A {};"; + const char* xmlCode = "\ + <typesystem package=\"Foo\"> \ + <value-type name='A'> \ + <inject-code class='target' since='1.0'>\ + test Inject code\ + </inject-code>\ + </value-type>\ + </typesystem>"; + + TestUtil t(cppCode, xmlCode, true, 0.1); + + AbstractMetaClassList classes = t.builder()->classes(); + AbstractMetaClass* classA = classes.findClass("A"); + QCOMPARE(classA->typeEntry()->codeSnips().count(), 0); +} + + + QTEST_APPLESS_MAIN(TestCodeInjections) #include "testcodeinjection.moc" diff --git a/tests/testcodeinjection.h b/tests/testcodeinjection.h index 90ae72f24..e12b40d2d 100644 --- a/tests/testcodeinjection.h +++ b/tests/testcodeinjection.h @@ -33,6 +33,8 @@ class TestCodeInjections : public QObject Q_OBJECT private slots: void testReadFileUtf8(); + void testInjectWithValidApiVersion(); + void testInjectWithInvalidApiVersion(); }; #endif diff --git a/tests/testenum.cpp b/tests/testenum.cpp index 24cb4d963..a7c0d9003 100644 --- a/tests/testenum.cpp +++ b/tests/testenum.cpp @@ -75,6 +75,28 @@ void TestEnum::testEnumCppSignature() QCOMPARE(classEnums.first()->name(), QString("ClassEnum")); } +void TestEnum::testEnumWithApiVersion() +{ + const char* cppCode ="\ + struct A {\ + enum ClassEnum { EnumA, EnumB };\ + enum ClassEnum2 { EnumC, EnumD };\ + };\ + "; + const char* xmlCode = "\ + <typesystem package=\"Foo\"> \ + <value-type name='A'/> \ + <enum-type name='A::ClassEnum' since='0.1'/>\ + <enum-type name='A::ClassEnum2' since='0.2'/>\ + </typesystem>"; + + TestUtil t(cppCode, xmlCode, true, 0.1); + AbstractMetaClassList classes = t.builder()->classes(); + QCOMPARE(classes.count(), 1); + QCOMPARE(classes[0]->enums().count(), 1); +} + + QTEST_APPLESS_MAIN(TestEnum) #include "testenum.moc" diff --git a/tests/testenum.h b/tests/testenum.h index 0fa026d27..f5011b265 100644 --- a/tests/testenum.h +++ b/tests/testenum.h @@ -30,6 +30,7 @@ class TestEnum : public QObject Q_OBJECT private slots: void testEnumCppSignature(); + void testEnumWithApiVersion(); }; -#endif
\ No newline at end of file +#endif diff --git a/tests/testmodifyfunction.cpp b/tests/testmodifyfunction.cpp index 94dbc3d9a..d45815e6c 100644 --- a/tests/testmodifyfunction.cpp +++ b/tests/testmodifyfunction.cpp @@ -52,6 +52,43 @@ void TestModifyFunction::testOwnershipTransfer() QCOMPARE(func->ownership(func->ownerClass(), TypeSystem::TargetLangCode, 0), TypeSystem::CppOwnership); } +void TestModifyFunction::testWithApiVersion() +{ + const char* cppCode ="\ + struct A {};\ + struct B {\ + virtual A* method();\ + virtual B* methodB();\ + };\ + "; + const char* xmlCode = "\ + <typesystem package='Foo'> \ + <object-type name='A' /> \ + <object-type name='B'> \ + <modify-function signature='method()' since='0.1'>\ + <modify-argument index='return'>\ + <define-ownership owner='c++' /> \ + </modify-argument>\ + </modify-function>\ + <modify-function signature='methodB()' since='0.2'>\ + <modify-argument index='return'>\ + <define-ownership owner='c++' /> \ + </modify-argument>\ + </modify-function>\ + </object-type>\ + </typesystem>"; + TestUtil t(cppCode, xmlCode, false, 0.1); + AbstractMetaClassList classes = t.builder()->classes(); + AbstractMetaClass* classB = classes.findClass("B"); + const AbstractMetaFunction* func = classB->findFunction("method"); + + QCOMPARE(func->ownership(func->ownerClass(), TypeSystem::TargetLangCode, 0), TypeSystem::CppOwnership); + + func = classB->findFunction("methodB"); + QVERIFY(func->ownership(func->ownerClass(), TypeSystem::TargetLangCode, 0) != TypeSystem::CppOwnership); +} + + QTEST_APPLESS_MAIN(TestModifyFunction) #include "testmodifyfunction.moc" diff --git a/tests/testmodifyfunction.h b/tests/testmodifyfunction.h index 95900cb28..f92180c02 100644 --- a/tests/testmodifyfunction.h +++ b/tests/testmodifyfunction.h @@ -31,6 +31,7 @@ class TestModifyFunction : public QObject Q_OBJECT private slots: void testOwnershipTransfer(); + void testWithApiVersion(); }; #endif diff --git a/tests/testrefcounttag.cpp b/tests/testrefcounttag.cpp index 5d3a45c77..6f6f87367 100644 --- a/tests/testrefcounttag.cpp +++ b/tests/testrefcounttag.cpp @@ -53,6 +53,41 @@ void TestRefCountTag::testReferenceCountTag() QCOMPARE(refCount.action, ReferenceCount::Add); } +void TestRefCountTag::testWithApiVersion() +{ + const char* cppCode ="\ + struct A {};\ + struct B {\ + void keepObject(B*, B*);\ + };\ + "; + const char* xmlCode = "\ + <typesystem package=\"Foo\"> \ + <object-type name='A' /> \ + <object-type name='B'> \ + <modify-function signature='keepObject(B*, B*)'>\ + <modify-argument index='1' since='0.1'>\ + <reference-count action='add' /> \ + </modify-argument>\ + <modify-argument index='2' since='0.2'>\ + <reference-count action='add' /> \ + </modify-argument>\ + </modify-function>\ + </object-type>\ + </typesystem>"; + + TestUtil t(cppCode, xmlCode, false, 0.1); + AbstractMetaClassList classes = t.builder()->classes(); + AbstractMetaClass* classB = classes.findClass("B"); + const AbstractMetaFunction* func = classB->findFunction("keepObject"); + + ReferenceCount refCount = func->modifications().first().argument_mods.first().referenceCounts.first(); + QCOMPARE(refCount.action, ReferenceCount::Add); + + QCOMPARE(func->modifications().size(), 1); +} + + QTEST_APPLESS_MAIN(TestRefCountTag) #include "testrefcounttag.moc" diff --git a/tests/testrefcounttag.h b/tests/testrefcounttag.h index 665266238..1fcdd3dfb 100644 --- a/tests/testrefcounttag.h +++ b/tests/testrefcounttag.h @@ -31,6 +31,7 @@ class TestRefCountTag : public QObject Q_OBJECT private slots: void testReferenceCountTag(); + void testWithApiVersion(); }; #endif diff --git a/tests/testutil.h b/tests/testutil.h index 1aed98349..7639a2535 100644 --- a/tests/testutil.h +++ b/tests/testutil.h @@ -31,10 +31,11 @@ class TestUtil { public: - TestUtil(const char* cppCode, const char* xmlCode, bool silent = true) : m_builder(0) + TestUtil(const char* cppCode, const char* xmlCode, bool silent = true, double apiVersion = 0) : m_builder(0) { ReportHandler::setSilent(silent); m_builder = new AbstractMetaBuilder; + TypeDatabase::instance()->setApiVersion(apiVersion); QBuffer buffer; // parse typesystem buffer.setData(xmlCode); |