diff options
Diffstat (limited to 'tests')
151 files changed, 11838 insertions, 5675 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 4bb160e3d4..449876b36e 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -9,7 +9,6 @@ SUBDIRS += \ environment \ fakevim \ generichighlighter \ -# icheckbuild \ profilewriter \ ioutils \ qtcprocess \ diff --git a/tests/auto/cplusplus/ast/tst_ast.cpp b/tests/auto/cplusplus/ast/tst_ast.cpp index 3b88e82a5e..e1da51d9c8 100644 --- a/tests/auto/cplusplus/ast/tst_ast.cpp +++ b/tests/auto/cplusplus/ast/tst_ast.cpp @@ -136,6 +136,16 @@ private slots: void assignment_1(); void assignment_2(); + // constructor declarations + void cpp_constructor_one_unamed_arg(); + void cpp_constructor_one_unamed_arg_namespace(); + void cpp_constructor_one_knowntype_arg(); + void cpp_constructor_one_const_arg(); + void cpp_constructor_one_ref_arg(); + void cpp_constructor_one_named_arg(); + void cpp_constructor_no_arg(); + void cpp_constructor_multiple_args(); + // objc++ void objc_simple_class(); void objc_attributes_followed_by_at_keyword(); @@ -1050,6 +1060,150 @@ void tst_AST::cpp_initializer_or_function_declaration() QCOMPARE(param->type_specifier_list->value->asNamedTypeSpecifier()->name->asSimpleName()->identifier_token, 4U); } +void tst_AST::cpp_constructor_one_unamed_arg() +{ + QSharedPointer<TranslationUnit> unit(parseDeclaration("QFileInfo::QFileInfo(QString /*name*/) {}")); + AST *ast = unit->ast(); + QVERIFY(ast != 0); + + FunctionDefinitionAST *funDef = ast->asFunctionDefinition(); + QVERIFY(funDef != 0); + QVERIFY(funDef->declarator != 0); + QVERIFY(funDef->declarator->postfix_declarator_list != 0); + QVERIFY(funDef->declarator->postfix_declarator_list->lastValue() != 0); + + FunctionDeclaratorAST *funDecl = funDef->declarator->postfix_declarator_list->lastValue()->asFunctionDeclarator(); + QVERIFY(funDecl != 0); + QVERIFY(funDecl->parameter_declaration_clause != 0); + QVERIFY(funDecl->parameter_declaration_clause->parameter_declaration_list != 0); +} + +void tst_AST::cpp_constructor_one_unamed_arg_namespace() +{ + QSharedPointer<TranslationUnit> unit(parseDeclaration("Foo::QFileInfo::QFileInfo(QString /*name*/) {}")); + AST *ast = unit->ast(); + QVERIFY(ast != 0); + + FunctionDefinitionAST *funDef = ast->asFunctionDefinition(); + QVERIFY(funDef != 0); + QVERIFY(funDef->declarator != 0); + QVERIFY(funDef->declarator->postfix_declarator_list != 0); + QVERIFY(funDef->declarator->postfix_declarator_list->lastValue() != 0); + + FunctionDeclaratorAST *funDecl = funDef->declarator->postfix_declarator_list->lastValue()->asFunctionDeclarator(); + QVERIFY(funDecl != 0); + QVERIFY(funDecl->parameter_declaration_clause != 0); + QVERIFY(funDecl->parameter_declaration_clause->parameter_declaration_list != 0); +} + +void tst_AST::cpp_constructor_one_named_arg() +{ + QSharedPointer<TranslationUnit> unit(parseDeclaration("QFileInfo::QFileInfo(QString name) {}")); + AST *ast = unit->ast(); + QVERIFY(ast != 0); + + FunctionDefinitionAST *funDef = ast->asFunctionDefinition(); + QVERIFY(funDef != 0); + QVERIFY(funDef->declarator != 0); + QVERIFY(funDef->declarator->postfix_declarator_list != 0); + QVERIFY(funDef->declarator->postfix_declarator_list->lastValue() != 0); + + FunctionDeclaratorAST *funDecl = funDef->declarator->postfix_declarator_list->lastValue()->asFunctionDeclarator(); + QVERIFY(funDecl != 0); + QVERIFY(funDecl->parameter_declaration_clause != 0); + QVERIFY(funDecl->parameter_declaration_clause->parameter_declaration_list != 0); +} + +void tst_AST::cpp_constructor_one_knowntype_arg() +{ + QSharedPointer<TranslationUnit> unit(parseDeclaration("QFileInfo::QFileInfo(int /*name*/) {}")); + AST *ast = unit->ast(); + QVERIFY(ast != 0); + + FunctionDefinitionAST *funDef = ast->asFunctionDefinition(); + QVERIFY(funDef != 0); + QVERIFY(funDef->declarator != 0); + QVERIFY(funDef->declarator->postfix_declarator_list != 0); + QVERIFY(funDef->declarator->postfix_declarator_list->lastValue() != 0); + + FunctionDeclaratorAST *funDecl = funDef->declarator->postfix_declarator_list->lastValue()->asFunctionDeclarator(); + QVERIFY(funDecl != 0); + QVERIFY(funDecl->parameter_declaration_clause != 0); + QVERIFY(funDecl->parameter_declaration_clause->parameter_declaration_list != 0); +} + + +void tst_AST::cpp_constructor_one_const_arg() +{ + QSharedPointer<TranslationUnit> unit(parseDeclaration("QFileInfo::QFileInfo(const QString /*name*/) {}")); + AST *ast = unit->ast(); + QVERIFY(ast != 0); + + FunctionDefinitionAST *funDef = ast->asFunctionDefinition(); + QVERIFY(funDef != 0); + QVERIFY(funDef->declarator != 0); + QVERIFY(funDef->declarator->postfix_declarator_list != 0); + QVERIFY(funDef->declarator->postfix_declarator_list->lastValue() != 0); + + FunctionDeclaratorAST *funDecl = funDef->declarator->postfix_declarator_list->lastValue()->asFunctionDeclarator(); + QVERIFY(funDecl != 0); + QVERIFY(funDecl->parameter_declaration_clause != 0); + QVERIFY(funDecl->parameter_declaration_clause->parameter_declaration_list != 0); +} + +void tst_AST::cpp_constructor_one_ref_arg() +{ + QSharedPointer<TranslationUnit> unit(parseDeclaration("QFileInfo::QFileInfo(QString & /*name*/) {}")); + AST *ast = unit->ast(); + QVERIFY(ast != 0); + + FunctionDefinitionAST *funDef = ast->asFunctionDefinition(); + QVERIFY(funDef != 0); + QVERIFY(funDef->declarator != 0); + QVERIFY(funDef->declarator->postfix_declarator_list != 0); + QVERIFY(funDef->declarator->postfix_declarator_list->lastValue() != 0); + + FunctionDeclaratorAST *funDecl = funDef->declarator->postfix_declarator_list->lastValue()->asFunctionDeclarator(); + QVERIFY(funDecl != 0); + QVERIFY(funDecl->parameter_declaration_clause != 0); + QVERIFY(funDecl->parameter_declaration_clause->parameter_declaration_list != 0); +} + +void tst_AST::cpp_constructor_no_arg() +{ + QSharedPointer<TranslationUnit> unit(parseDeclaration("QFileInfo::QFileInfo() {}")); + AST *ast = unit->ast(); + QVERIFY(ast != 0); + + FunctionDefinitionAST *funDef = ast->asFunctionDefinition(); + QVERIFY(funDef != 0); + QVERIFY(funDef->declarator != 0); + QVERIFY(funDef->declarator->postfix_declarator_list != 0); + QVERIFY(funDef->declarator->postfix_declarator_list->lastValue() != 0); + + FunctionDeclaratorAST *funDecl = funDef->declarator->postfix_declarator_list->lastValue()->asFunctionDeclarator(); + QVERIFY(funDecl != 0); + QVERIFY(funDecl->parameter_declaration_clause == 0); +} + +void tst_AST::cpp_constructor_multiple_args() +{ + QSharedPointer<TranslationUnit> unit(parseDeclaration("QFileInfo::QFileInfo(QString /*name*/, QString /*type*/) {}")); + AST *ast = unit->ast(); + QVERIFY(ast != 0); + + FunctionDefinitionAST *funDef = ast->asFunctionDefinition(); + QVERIFY(funDef != 0); + QVERIFY(funDef->declarator != 0); + QVERIFY(funDef->declarator->postfix_declarator_list != 0); + QVERIFY(funDef->declarator->postfix_declarator_list->lastValue() != 0); + + FunctionDeclaratorAST *funDecl = funDef->declarator->postfix_declarator_list->lastValue()->asFunctionDeclarator(); + QVERIFY(funDecl != 0); + QVERIFY(funDecl->parameter_declaration_clause != 0); + QVERIFY(funDecl->parameter_declaration_clause->parameter_declaration_list != 0); +} + void tst_AST::objc_simple_class() { QSharedPointer<TranslationUnit> unit(parseDeclaration("\n" diff --git a/tests/auto/cplusplus/checksymbols/checksymbols.pro b/tests/auto/cplusplus/checksymbols/checksymbols.pro new file mode 100644 index 0000000000..c7ea673be8 --- /dev/null +++ b/tests/auto/cplusplus/checksymbols/checksymbols.pro @@ -0,0 +1,4 @@ +include(../../qttest.pri) +include(../shared/shared.pri) +include(../../../../src/plugins/cpptools/cpptools.pri) +SOURCES += tst_checksymbols.cpp diff --git a/tests/auto/cplusplus/checksymbols/tst_checksymbols.cpp b/tests/auto/cplusplus/checksymbols/tst_checksymbols.cpp new file mode 100644 index 0000000000..ff43c68e3b --- /dev/null +++ b/tests/auto/cplusplus/checksymbols/tst_checksymbols.cpp @@ -0,0 +1,452 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include <CppDocument.h> +#include <pp.h> + +#include <cpptools/cppchecksymbols.h> +#include <cpptools/cppsemanticinfo.h> +#include <texteditor/semantichighlighter.h> +#include <utils/fileutils.h> + +#include <QDebug> +#include <QDir> +#include <QList> +#include <QtTest> + +/*! + Tests CheckSymbols, the "data provider" of the semantic highlighter. + */ + +using namespace CPlusPlus; +using namespace CppTools; + +typedef CheckSymbols::Use Use; +typedef CheckSymbols::UseKind UseKind; + +static QString useKindToString(UseKind useKind) +{ + switch (useKind) { + case SemanticInfo::Unknown: + return QLatin1String("SemanticInfo::Unknown"); + case SemanticInfo::TypeUse: + return QLatin1String("SemanticInfo::TypeUse"); + case SemanticInfo::LocalUse: + return QLatin1String("SemanticInfo::LocalUse"); + case SemanticInfo::FieldUse: + return QLatin1String("SemanticInfo::FieldUse"); + case SemanticInfo::EnumerationUse: + return QLatin1String("SemanticInfo::EnumerationUse"); + case SemanticInfo::VirtualMethodUse: + return QLatin1String("SemanticInfo::VirtualMethodUse"); + case SemanticInfo::LabelUse: + return QLatin1String("SemanticInfo::LabelUse"); + case SemanticInfo::MacroUse: + return QLatin1String("SemanticInfo::MacroUse"); + case SemanticInfo::FunctionUse: + return QLatin1String("SemanticInfo::FunctionUse"); + case SemanticInfo::PseudoKeywordUse: + return QLatin1String("SemanticInfo::PseudoKeywordUse"); + default: + return QLatin1String("Unknown Kind"); + } +} + +// The following two functions are "enhancements" for QCOMPARE(). +namespace QTest { + +bool operator==(const Use& lhs, const Use& rhs) +{ + return + lhs.line == rhs.line && + lhs.column == rhs.column && + lhs.length == rhs.length && + lhs.kind == rhs.kind; +} + +template<> +char *toString(const Use &use) +{ + QByteArray ba = "Use("; + ba += QByteArray::number(use.line); + ba += ", " + QByteArray::number(use.column); + ba += ", " + QByteArray::number(use.length); + ba += ", " + useKindToString(static_cast<UseKind>(use.kind)).toLatin1(); + ba += ")"; + return qstrdup(ba.data()); +} + +} // namespace QTest + +namespace { + +class TestData +{ +public: + Snapshot snapshot; + Document::Ptr document; + + TestData(const QByteArray &source, + Document::ParseMode parseMode = Document::ParseTranlationUnit) + { + // Write source to temprorary file + const QString filePath = QDir::tempPath() + QLatin1String("/file.h"); + document = Document::create(filePath); + Utils::FileSaver documentSaver(document->fileName()); + documentSaver.write(source); + documentSaver.finalize(); + + // Preprocess source + Environment env; + Preprocessor preprocess(0, &env); + const QByteArray preprocessedSource = preprocess.run(filePath, QLatin1String(source)); + document->setUtf8Source(preprocessedSource); + QVERIFY(document->parse(parseMode)); + document->check(); + snapshot.insert(document); + } + + static void check(QByteArray source, QList<Use> expectedUses, + QList<Use> macroUses = QList<Use>()) + { + TestData env(source); + + // Collect symbols + LookupContext context(env.document, env.snapshot); + CheckSymbols::Future future = CheckSymbols::go(env.document, context, macroUses); + future.waitForFinished(); + + const int resultCount = future.resultCount(); + QList<Use> actualUses; + for (int i = 0; i < resultCount; ++i) { + const Use use = future.resultAt(i); + // When adding tests, you may want to uncomment the + // following line in order to print out all found uses. +// qDebug() << QTest::toString(use); + actualUses.append(use); + } + + // Checks + QVERIFY(resultCount > 0); + QCOMPARE(resultCount, expectedUses.count()); + + for (int i = 0; i < resultCount; ++i) { + const Use actualUse = actualUses.at(i); + const Use expectedUse = expectedUses.at(i); + QVERIFY(actualUse.isValid()); + QVERIFY(expectedUse.isValid()); + QCOMPARE(actualUse, expectedUse); + } + } +}; + +} // anonymous namespace + +class tst_CheckSymbols: public QObject +{ + Q_OBJECT + +private slots: + void test_checksymbols_TypeUse(); + void test_checksymbols_LocalUse(); + void test_checksymbols_FieldUse(); + void test_checksymbols_EnumerationUse(); + void test_checksymbols_VirtualMethodUse(); + void test_checksymbols_LabelUse(); + void test_checksymbols_MacroUse(); + void test_checksymbols_FunctionUse(); + void test_checksymbols_PseudoKeywordUse(); + void test_checksymbols_StaticUse(); + void test_checksymbols_VariableHasTheSameNameAsEnumUse(); + void test_checksymbols_NestedClassOfEnclosingTemplateUse(); +}; + +void tst_CheckSymbols::test_checksymbols_TypeUse() +{ + const QByteArray source = + "namespace N {}\n" + "using namespace N;\n"; + const QList<Use> expectedUses = QList<Use>() + << Use(1, 11, 1, SemanticInfo::TypeUse) + << Use(2, 17, 1, SemanticInfo::TypeUse); + + TestData::check(source, expectedUses); +} + +void tst_CheckSymbols::test_checksymbols_LocalUse() +{ + const QByteArray source = + "int f()\n" + "{\n" + " int i;\n" + "}\n"; + const QList<Use> expectedUses = QList<Use>() + << Use(1, 5, 1, SemanticInfo::FunctionUse) + << Use(3, 8, 1, SemanticInfo::LocalUse); + + TestData::check(source, expectedUses); +} + +void tst_CheckSymbols::test_checksymbols_FieldUse() +{ + const QByteArray source = + "struct F {\n" + " int i;\n" + " F() { i = 0; }\n" + "};\n" + "int f()\n" + "{\n" + " F s;\n" + " s.i = 2;\n" + "}\n"; + const QList<Use> expectedUses = QList<Use>() + << Use(1, 8, 1, SemanticInfo::TypeUse) + << Use(2, 9, 1, SemanticInfo::FieldUse) + << Use(3, 5, 1, SemanticInfo::TypeUse) + << Use(3, 11, 1, SemanticInfo::FieldUse) + << Use(5, 5, 1, SemanticInfo::FunctionUse) + << Use(7, 5, 1, SemanticInfo::TypeUse) + << Use(7, 7, 1, SemanticInfo::LocalUse) + << Use(8, 7, 1, SemanticInfo::FieldUse) + << Use(8, 5, 1, SemanticInfo::LocalUse); + + TestData::check(source, expectedUses); +} + +void tst_CheckSymbols::test_checksymbols_EnumerationUse() +{ + const QByteArray source = + "enum E { Red, Green, Blue };\n" + "E e = Red\n"; + const QList<Use> expectedUses = QList<Use>() + << Use(1, 22, 4, SemanticInfo::EnumerationUse) + << Use(1, 15, 5, SemanticInfo::EnumerationUse) + << Use(1, 6, 1, SemanticInfo::TypeUse) + << Use(1, 10, 3, SemanticInfo::EnumerationUse); + + TestData::check(source, expectedUses); +} + +void tst_CheckSymbols::test_checksymbols_VirtualMethodUse() +{ + const QByteArray source = + "class B {\n" + " virtual isThere();\n" + "};\n" + "class D: public B {\n" + " isThere();\n" + "};\n"; + const QList<Use> expectedUses = QList<Use>() + << Use(1, 7, 1, SemanticInfo::TypeUse) + << Use(2, 13, 7, SemanticInfo::VirtualMethodUse) + << Use(4, 17, 1, SemanticInfo::TypeUse) + << Use(4, 7, 1, SemanticInfo::TypeUse) + << Use(5, 5, 7, SemanticInfo::VirtualMethodUse); + + TestData::check(source, expectedUses); +} + +void tst_CheckSymbols::test_checksymbols_LabelUse() +{ + const QByteArray source = + "int f()\n" + "{\n" + " goto g;\n" + " g: return 1;\n" + "}\n"; + const QList<Use> expectedUses = QList<Use>() + << Use(1, 5, 1, SemanticInfo::FunctionUse) + << Use(3, 9, 1, SemanticInfo::LabelUse) + << Use(4, 4, 1, SemanticInfo::LabelUse); + + TestData::check(source, expectedUses); +} + +void tst_CheckSymbols::test_checksymbols_MacroUse() +{ + const QByteArray source = + "#define FOO 1+1\n" + "int f() { FOO }\n"; + const QList<Use> macroUses = QList<Use>() + << Use(1, 9, 3, SemanticInfo::MacroUse) + << Use(2, 11, 3, SemanticInfo::MacroUse); + const QList<Use> expectedUses = QList<Use>() + << Use(1, 9, 3, SemanticInfo::MacroUse) + << Use(2, 11, 3, SemanticInfo::MacroUse) + << Use(2, 5, 1, SemanticInfo::FunctionUse); + + TestData::check(source, expectedUses, macroUses); +} + +void tst_CheckSymbols::test_checksymbols_FunctionUse() +{ + const QByteArray source = + "int f();\n" + "int g() { f(); }\n"; + const QList<Use> expectedUses = QList<Use>() + << Use(1, 5, 1, SemanticInfo::FunctionUse) + << Use(2, 5, 1, SemanticInfo::FunctionUse) + << Use(2, 11, 1, SemanticInfo::FunctionUse); + + TestData::check(source, expectedUses); +} + +void tst_CheckSymbols::test_checksymbols_PseudoKeywordUse() +{ + const QByteArray source = + "class D : public B {" + " virtual void f() override {}\n" + " virtual void f() final {}\n" + "};\n"; + const QList<Use> expectedUses = QList<Use>() + << Use(1, 7, 1, SemanticInfo::TypeUse) + << Use(1, 37, 1, SemanticInfo::VirtualMethodUse) + << Use(1, 41, 8, SemanticInfo::PseudoKeywordUse) + << Use(2, 17, 1, SemanticInfo::VirtualMethodUse) + << Use(2, 21, 5, SemanticInfo::PseudoKeywordUse); + + TestData::check(source, expectedUses); +} + +void tst_CheckSymbols::test_checksymbols_StaticUse() +{ + const QByteArray source = + "struct Outer\n" + "{\n" + " static int Foo;\n" + " struct Inner\n" + " {\n" + " Outer *outer;\n" + " void foo();\n" + " };\n" + "};\n" + "\n" + "int Outer::Foo = 42;\n" + "\n" + "void Outer::Inner::foo()\n" + "{\n" + " Foo = 7;\n" + " Outer::Foo = 7;\n" + " outer->Foo = 7;\n" + "}\n" + ; + + const QList<Use> expectedUses = QList<Use>() + << Use(1, 8, 5, SemanticInfo::TypeUse) + << Use(3, 16, 3, SemanticInfo::FieldUse) + << Use(4, 12, 5, SemanticInfo::TypeUse) + << Use(6, 16, 5, SemanticInfo::FieldUse) + << Use(6, 9, 5, SemanticInfo::TypeUse) + << Use(7, 14, 3, SemanticInfo::FunctionUse) + << Use(11, 12, 3, SemanticInfo::FieldUse) + << Use(11, 5, 5, SemanticInfo::TypeUse) + << Use(13, 20, 3, SemanticInfo::FunctionUse) + << Use(13, 6, 5, SemanticInfo::TypeUse) + << Use(13, 13, 5, SemanticInfo::TypeUse) + << Use(15, 5, 3, SemanticInfo::FieldUse) + << Use(16, 12, 3, SemanticInfo::FieldUse) + << Use(16, 5, 5, SemanticInfo::TypeUse) + << Use(17, 5, 5, SemanticInfo::FieldUse) + << Use(17, 12, 3, SemanticInfo::FieldUse) + ; + + TestData::check(source, expectedUses); +} + +void tst_CheckSymbols::test_checksymbols_VariableHasTheSameNameAsEnumUse() +{ + const QByteArray source = + "struct Foo\n" + "{\n" + " enum E { bar, baz };\n" + "};\n" + "\n" + "struct Boo\n" + "{\n" + " int foo;\n" + " int bar;\n" + " int baz;\n" + "};\n" + ; + const QList<Use> expectedUses = QList<Use>() + << Use(1, 8, 3, SemanticInfo::TypeUse) + << Use(3, 19, 3, SemanticInfo::EnumerationUse) + << Use(3, 14, 3, SemanticInfo::EnumerationUse) + << Use(3, 10, 1, SemanticInfo::TypeUse) + << Use(6, 8, 3, SemanticInfo::TypeUse) + << Use(8, 9, 3, SemanticInfo::FieldUse) + << Use(9, 9, 3, SemanticInfo::FieldUse) + << Use(10, 9, 3, SemanticInfo::FieldUse) + ; + + TestData::check(source, expectedUses); +} + +void tst_CheckSymbols::test_checksymbols_NestedClassOfEnclosingTemplateUse() +{ + const QByteArray source = + "struct Foo { int bar; };\n" + "\n" + "template<typename T>\n" + "struct Outer\n" + "{\n" + " struct Nested { T nt; } nested;\n" + "};\n" + "\n" + "void fun()\n" + "{\n" + " Outer<Foo> list;\n" + " list.nested.nt.bar;\n" + "}\n" + ; + + const QList<Use> expectedUses = QList<Use>() + << Use(1, 8, 3, SemanticInfo::TypeUse) + << Use(1, 18, 3, SemanticInfo::FieldUse) + << Use(3, 19, 1, SemanticInfo::TypeUse) + << Use(4, 8, 5, SemanticInfo::TypeUse) + << Use(6, 23, 2, SemanticInfo::FieldUse) + << Use(6, 12, 6, SemanticInfo::TypeUse) + << Use(6, 29, 6, SemanticInfo::FieldUse) + << Use(6, 21, 1, SemanticInfo::TypeUse) + << Use(9, 6, 3, SemanticInfo::FunctionUse) + << Use(11, 11, 3, SemanticInfo::TypeUse) + << Use(11, 16, 4, SemanticInfo::LocalUse) + << Use(11, 5, 5, SemanticInfo::TypeUse) + << Use(12, 20, 3, SemanticInfo::FieldUse) + << Use(12, 17, 2, SemanticInfo::FieldUse) + << Use(12, 10, 6, SemanticInfo::FieldUse) + << Use(12, 5, 4, SemanticInfo::LocalUse) + ; + + TestData::check(source, expectedUses); +} + +QTEST_APPLESS_MAIN(tst_CheckSymbols) +#include "tst_checksymbols.moc" diff --git a/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp b/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp index 63b049d689..ba0eb2dfff 100644 --- a/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp +++ b/tests/auto/cplusplus/codeformatter/tst_codeformatter.cpp @@ -116,6 +116,7 @@ private Q_SLOTS: void functionBodyAndBraces4(); void constructor1(); void constructor2(); + void constructor3(); void caseBody1(); void caseBody2(); void caseBody3(); @@ -1875,6 +1876,42 @@ void tst_CodeFormatter::constructor2() checkIndent(data); } +void tst_CodeFormatter::constructor3() +{ + QList<Line> data; + data << Line("class Foo {") + << Line(" Foo() : _a{0}, _b{1, {2, {3, \"foo\"}, 3}}") + << Line(" {") + << Line(" _b = 0") + << Line(" }") + << Line(" int _a;") + << Line(" Foo()") + << Line(" ~ : _foo{1},") + << Line(" ~ _bar{2},") + << Line(" ~ _carooooo(") + << Line(" ~ foo() + 12),") + << Line(" ~ _carooooo{foo(),") + << Line(" ~ 12}") + << Line(" {") + << Line(" _b = 0") + << Line(" }") + << Line(" int _b;") + << Line(" Foo()") + << Line(" ~ : _foo{1}") + << Line(" ~ , _bar{2}") + << Line(" ~ , _carooooo{") + << Line(" ~ foo() + 12}") + << Line(" ~ , _carooooo{foo(),") + << Line(" ~ 12}") + << Line(" {") + << Line(" _b = 0") + << Line(" }") + << Line("};") + ; + CppCodeStyleSettings codeStyle; + checkIndent(data); +} + void tst_CodeFormatter::caseBody1() { QList<Line> data; diff --git a/tests/auto/cplusplus/cplusplus.pro b/tests/auto/cplusplus/cplusplus.pro index 6a7091a552..f5d49f3b2d 100644 --- a/tests/auto/cplusplus/cplusplus.pro +++ b/tests/auto/cplusplus/cplusplus.pro @@ -11,4 +11,5 @@ SUBDIRS = \ typeprettyprinter \ simplifytypes \ misc \ - cxx11 + cxx11 \ + checksymbols diff --git a/tests/auto/cplusplus/cxx11/data/aliasDecl.1.cpp b/tests/auto/cplusplus/cxx11/data/aliasDecl.1.cpp new file mode 100644 index 0000000000..99384acaa1 --- /dev/null +++ b/tests/auto/cplusplus/cxx11/data/aliasDecl.1.cpp @@ -0,0 +1,4 @@ +using Foo = int; +using Bar = std::vector<int>::value_type; +using A [[foo]] = const float; +using B alignas(void*) = C *; diff --git a/tests/auto/cplusplus/cxx11/data/alignofAlignas.1.cpp b/tests/auto/cplusplus/cxx11/data/alignofAlignas.1.cpp new file mode 100644 index 0000000000..5ba43661ed --- /dev/null +++ b/tests/auto/cplusplus/cxx11/data/alignofAlignas.1.cpp @@ -0,0 +1,2 @@ +int i = alignof(int); +int t = alignof(C::foo) * 7 + alignof(Foo *); diff --git a/tests/auto/cplusplus/cxx11/data/braceInitializers.1.cpp b/tests/auto/cplusplus/cxx11/data/braceInitializers.1.cpp new file mode 100644 index 0000000000..94e8fae241 --- /dev/null +++ b/tests/auto/cplusplus/cxx11/data/braceInitializers.1.cpp @@ -0,0 +1,18 @@ +Type var1 = { 1, 2, 3}; +Type var2{1, 2, 3}; +Type var3({1, 2, 3}); + +class C { + Type var1 = {1, 2, 3}; + Type var2{1, 2, 3}; +}; + +void main() { + var1 = {1, 2, {3, 4} }; + Type var2{{1, 2, 3}, 4}; + var3 += {1, 2}; +} + +T foo() { + return {1, 2, {"foo", 7}}; +} diff --git a/tests/auto/cplusplus/cxx11/data/braceInitializers.1.errors.txt b/tests/auto/cplusplus/cxx11/data/braceInitializers.1.errors.txt new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/auto/cplusplus/cxx11/data/braceInitializers.1.errors.txt diff --git a/tests/auto/cplusplus/cxx11/data/braceInitializers.2.cpp b/tests/auto/cplusplus/cxx11/data/braceInitializers.2.cpp new file mode 100644 index 0000000000..4dc183d8f5 --- /dev/null +++ b/tests/auto/cplusplus/cxx11/data/braceInitializers.2.cpp @@ -0,0 +1,7 @@ +class C { + C() : _x{12}, _y({12}) {} + C(int i) : _x{{{12, 2}, {"foo"}}, {bar}}... {} + C(int i) : _x({{12, 2}, {"foo"}}, {bar})... {} +}; + +void foo(int i = {1, 2, 3}); diff --git a/tests/auto/cplusplus/cxx11/data/braceInitializers.3.cpp b/tests/auto/cplusplus/cxx11/data/braceInitializers.3.cpp new file mode 100644 index 0000000000..5105b4690c --- /dev/null +++ b/tests/auto/cplusplus/cxx11/data/braceInitializers.3.cpp @@ -0,0 +1,6 @@ +auto x = int{}; +auto y = Foo{}; +auto z = typename Foo<T>{}; + +auto d = new C(1, abc...); +auto e = new C{1, 2, 3}; diff --git a/tests/auto/cplusplus/cxx11/data/declType.1.cpp b/tests/auto/cplusplus/cxx11/data/declType.1.cpp new file mode 100644 index 0000000000..fd86589abf --- /dev/null +++ b/tests/auto/cplusplus/cxx11/data/declType.1.cpp @@ -0,0 +1,11 @@ +template <class T, class R> +auto foo(T t, R r) -> decltype(t + r) +{} + +int x; +decltype(x) foo; +decltype(x) foo(); + +// this does not work yet, as decltype is only parsed as a simple-specifier +// and not also as a nested-name-specifier +//decltype(vec)::value_type a; diff --git a/tests/auto/cplusplus/cxx11/data/defaultdeleteInitializer.1.cpp b/tests/auto/cplusplus/cxx11/data/defaultdeleteInitializer.1.cpp new file mode 100644 index 0000000000..7ec9e9b91e --- /dev/null +++ b/tests/auto/cplusplus/cxx11/data/defaultdeleteInitializer.1.cpp @@ -0,0 +1,8 @@ +class C { + C() = default; + C(const C &) = delete; + C &operator=(const C &) = default; + + void foo() = delete; + template <class T> void bar(T) = delete; +}; diff --git a/tests/auto/cplusplus/cxx11/data/enums.1.cpp b/tests/auto/cplusplus/cxx11/data/enums.1.cpp new file mode 100644 index 0000000000..c8cd725ad0 --- /dev/null +++ b/tests/auto/cplusplus/cxx11/data/enums.1.cpp @@ -0,0 +1,11 @@ +enum { A, B }; +enum : int; +enum : int { A, B }; +enum Foo1 { A, B }; +enum Foo2 : int; +enum Foo3 : int { A, B }; +enum class Foo4 : int; +enum struct Foo5; +enum class Foo6 { A, B }; +enum struct Foo7 { A, B }; +enum struct Foo8 : long long; diff --git a/tests/auto/cplusplus/cxx11/data/packExpansion.1.cpp b/tests/auto/cplusplus/cxx11/data/packExpansion.1.cpp new file mode 100644 index 0000000000..eca6796e38 --- /dev/null +++ b/tests/auto/cplusplus/cxx11/data/packExpansion.1.cpp @@ -0,0 +1,4 @@ +template <class ... Args> +int foo(Args args...) { + bar(args..., {args...}, e, f); +} diff --git a/tests/auto/cplusplus/cxx11/data/rangeFor.1.cpp b/tests/auto/cplusplus/cxx11/data/rangeFor.1.cpp new file mode 100644 index 0000000000..3a9a2e7d4f --- /dev/null +++ b/tests/auto/cplusplus/cxx11/data/rangeFor.1.cpp @@ -0,0 +1,5 @@ +int main() { + for (int x : {1, 2, 3}) {} + for (int x : foo) ; + for (int& x : array) x += 2; +} diff --git a/tests/auto/cplusplus/cxx11/data/refQualifier.1.cpp b/tests/auto/cplusplus/cxx11/data/refQualifier.1.cpp new file mode 100644 index 0000000000..172ede9ae0 --- /dev/null +++ b/tests/auto/cplusplus/cxx11/data/refQualifier.1.cpp @@ -0,0 +1,21 @@ +void foo() noexcept; +class C { + void foo() const noexcept final override; + void foo() const & noexcept final override; + void foo() const && noexcept final override; + auto foo() const noexcept -> void final override; + auto foo() const & noexcept -> void final override; + auto foo() const && noexcept -> void final override; + void foo(); + void foo() &; + void foo() &&; +}; + +int main() { + void (C::*p)() const; + void (C::*p)() const &; + void (C::*p)() const &&; + void (C::*p)(); + void (C::*p)() &; + void (C::*p)() &&; +} diff --git a/tests/auto/cplusplus/cxx11/data/templateGreaterGreater.1.cpp b/tests/auto/cplusplus/cxx11/data/templateGreaterGreater.1.cpp new file mode 100644 index 0000000000..c07d0a0e4f --- /dev/null +++ b/tests/auto/cplusplus/cxx11/data/templateGreaterGreater.1.cpp @@ -0,0 +1,10 @@ +template <class i, int j = 1> +class Y {}; +template <int i> +class X {}; + +Y<X<6>, 7> x; +Y<X<1>> y; +X< (1 >> 2) > z; +auto a = static_cast<X<1>>(X<1>()); + diff --git a/tests/auto/cplusplus/cxx11/tst_cxx11.cpp b/tests/auto/cplusplus/cxx11/tst_cxx11.cpp index 82b99336cd..51a9f05aeb 100644 --- a/tests/auto/cplusplus/cxx11/tst_cxx11.cpp +++ b/tests/auto/cplusplus/cxx11/tst_cxx11.cpp @@ -39,11 +39,13 @@ using namespace CPlusPlus; #define VERIFY_ERRORS() \ do { \ - QFile e(testdata(errorFile)); \ QByteArray expectedErrors; \ - if (e.open(QFile::ReadOnly)) \ - expectedErrors = QTextStream(&e).readAll().toUtf8(); \ - QCOMPARE(errors, expectedErrors); \ + if (!errorFile.isEmpty()) { \ + QFile e(testdata(errorFile)); \ + if (e.open(QFile::ReadOnly)) \ + expectedErrors = QTextStream(&e).readAll().toUtf8(); \ + } \ + QCOMPARE(QString::fromLatin1(errors), QString::fromLatin1(expectedErrors)); \ } while (0) @@ -106,6 +108,8 @@ class tst_cxx11: public QObject doc->translationUnit()->setCxxOxEnabled(true); doc->check(); doc->control()->setDiagnosticClient(0); + } else { + qWarning() << "could not read file" << fileName; } return doc; } @@ -114,12 +118,8 @@ private Q_SLOTS: // // checks for the syntax // - void inlineNamespace_data(); - void inlineNamespace(); - void staticAssert(); - void staticAssert_data(); - void noExcept(); - void noExcept_data(); + void parse_data(); + void parse(); // // checks for the semantic @@ -128,15 +128,29 @@ private Q_SLOTS: }; -void tst_cxx11::inlineNamespace_data() +void tst_cxx11::parse_data() { QTest::addColumn<QString>("file"); QTest::addColumn<QString>("errorFile"); QTest::newRow("inlineNamespace.1") << "inlineNamespace.1.cpp" << "inlineNamespace.1.errors.txt"; + QTest::newRow("staticAssert.1") << "staticAssert.1.cpp" << "staticAssert.1.errors.txt"; + QTest::newRow("noExcept.1") << "noExcept.1.cpp" << "noExcept.1.errors.txt"; + QTest::newRow("braceInitializers.1") << "braceInitializers.1.cpp" << "braceInitializers.1.errors.txt"; + QTest::newRow("braceInitializers.2") << "braceInitializers.2.cpp" << ""; + QTest::newRow("braceInitializers.3") << "braceInitializers.3.cpp" << ""; + QTest::newRow("defaultdeleteInitializer.1") << "defaultdeleteInitializer.1.cpp" << ""; + QTest::newRow("refQualifier.1") << "refQualifier.1.cpp" << ""; + QTest::newRow("alignofAlignas.1") << "alignofAlignas.1.cpp" << ""; + QTest::newRow("rangeFor.1") << "rangeFor.1.cpp" << ""; + QTest::newRow("aliasDecl.1") << "aliasDecl.1.cpp" << ""; + QTest::newRow("enums.1") << "enums.1.cpp" << ""; + QTest::newRow("templateGreaterGreater.1") << "templateGreaterGreater.1.cpp" << ""; + QTest::newRow("packExpansion.1") << "packExpansion.1.cpp" << ""; + QTest::newRow("declType.1") << "declType.1.cpp" << ""; } -void tst_cxx11::inlineNamespace() +void tst_cxx11::parse() { QFETCH(QString, file); QFETCH(QString, errorFile); @@ -166,49 +180,5 @@ void tst_cxx11::inlineNamespaceLookup() QCOMPARE(results.size(), 1); // the symbol is visible from the global scope } -void tst_cxx11::staticAssert_data() -{ - QTest::addColumn<QString>("file"); - QTest::addColumn<QString>("errorFile"); - - QTest::newRow("staticAssert.1") << "staticAssert.1.cpp" << "staticAssert.1.errors.txt"; -} - -void tst_cxx11::staticAssert() -{ - QFETCH(QString, file); - QFETCH(QString, errorFile); - - QByteArray errors; - Document::Ptr doc = document(file, &errors); - - if (! qgetenv("DEBUG").isNull()) - printf("%s\n", errors.constData()); - - VERIFY_ERRORS(); -} - -void tst_cxx11::noExcept_data() -{ - QTest::addColumn<QString>("file"); - QTest::addColumn<QString>("errorFile"); - - QTest::newRow("noExcept.1") << "noExcept.1.cpp" << "noExcept.1.errors.txt"; -} - -void tst_cxx11::noExcept() -{ - QFETCH(QString, file); - QFETCH(QString, errorFile); - - QByteArray errors; - Document::Ptr doc = document(file, &errors); - - if (! qgetenv("DEBUG").isNull()) - printf("%s\n", errors.constData()); - - VERIFY_ERRORS(); -} - QTEST_APPLESS_MAIN(tst_cxx11) #include "tst_cxx11.moc" diff --git a/tests/auto/cplusplus/findusages/tst_findusages.cpp b/tests/auto/cplusplus/findusages/tst_findusages.cpp index b80087a139..339d852ca0 100644 --- a/tests/auto/cplusplus/findusages/tst_findusages.cpp +++ b/tests/auto/cplusplus/findusages/tst_findusages.cpp @@ -77,8 +77,11 @@ class tst_FindUsages: public QObject private Q_SLOTS: void inlineMethod(); + void lambdaCaptureByValue(); + void lambdaCaptureByReference(); void shadowedNames_1(); void shadowedNames_2(); + void staticVariables(); // Qt keywords void qproperty_1(); @@ -88,6 +91,9 @@ private Q_SLOTS: // void objc_methods(); // void objc_fields(); // void objc_classes(); + + // templates + void instantiateTemplateWithNestedClass(); }; void tst_FindUsages::inlineMethod() @@ -125,6 +131,70 @@ void tst_FindUsages::inlineMethod() QCOMPARE(findUsages.references().size(), 2); } +void tst_FindUsages::lambdaCaptureByValue() +{ + const QByteArray src = "\n" + "void f() {\n" + " int test;\n" + " [test] { ++test; };\n" + "}\n"; + Document::Ptr doc = Document::create("lambdaCaptureByValue"); + doc->setUtf8Source(src); + doc->parse(); + doc->check(); + + QVERIFY(doc->diagnosticMessages().isEmpty()); + QCOMPARE(doc->globalSymbolCount(), 1U); + + Snapshot snapshot; + snapshot.insert(doc); + + Function *f = doc->globalSymbolAt(0)->asFunction(); + QVERIFY(f); + QCOMPARE(f->memberCount(), 1U); + Block *b = f->memberAt(0)->asBlock(); + QCOMPARE(b->memberCount(), 2U); + Declaration *d = b->memberAt(0)->asDeclaration(); + QVERIFY(d); + QCOMPARE(d->name()->identifier()->chars(), "test"); + + FindUsages findUsages(src, doc, snapshot); + findUsages(d); + QCOMPARE(findUsages.usages().size(), 3); +} + +void tst_FindUsages::lambdaCaptureByReference() +{ + const QByteArray src = "\n" + "void f() {\n" + " int test;\n" + " [&test] { ++test; };\n" + "}\n"; + Document::Ptr doc = Document::create("lambdaCaptureByReference"); + doc->setUtf8Source(src); + doc->parse(); + doc->check(); + + QVERIFY(doc->diagnosticMessages().isEmpty()); + QCOMPARE(doc->globalSymbolCount(), 1U); + + Snapshot snapshot; + snapshot.insert(doc); + + Function *f = doc->globalSymbolAt(0)->asFunction(); + QVERIFY(f); + QCOMPARE(f->memberCount(), 1U); + Block *b = f->memberAt(0)->asBlock(); + QCOMPARE(b->memberCount(), 2U); + Declaration *d = b->memberAt(0)->asDeclaration(); + QVERIFY(d); + QCOMPARE(d->name()->identifier()->chars(), "test"); + + FindUsages findUsages(src, doc, snapshot); + findUsages(d); + QCOMPARE(findUsages.usages().size(), 3); +} + void tst_FindUsages::shadowedNames_1() { const QByteArray src = "\n" @@ -188,6 +258,52 @@ void tst_FindUsages::shadowedNames_2() QCOMPARE(findUsages.usages().size(), 3); } +void tst_FindUsages::staticVariables() +{ + const QByteArray src = "\n" + "struct Outer\n" + "{\n" + " static int Foo;\n" + " struct Inner\n" + " {\n" + " Outer *outer;\n" + " void foo();\n" + " };\n" + "};\n" + "\n" + "int Outer::Foo = 42;\n" + "\n" + "void Outer::Inner::foo()\n" + "{\n" + " Foo = 7;\n" + " Outer::Foo = 7;\n" + " outer->Foo = 7;\n" + "}\n" + ; + Document::Ptr doc = Document::create("staticVariables"); + doc->setUtf8Source(src); + doc->parse(); + doc->check(); + + QVERIFY(doc->diagnosticMessages().isEmpty()); + QCOMPARE(doc->globalSymbolCount(), 3U); + + Snapshot snapshot; + snapshot.insert(doc); + + Class *c = doc->globalSymbolAt(0)->asClass(); + QVERIFY(c); + QCOMPARE(c->name()->identifier()->chars(), "Outer"); + QCOMPARE(c->memberCount(), 2U); + Declaration *d = c->memberAt(0)->asDeclaration(); + QVERIFY(d); + QCOMPARE(d->name()->identifier()->chars(), "Foo"); + + FindUsages findUsages(src, doc, snapshot); + findUsages(d); + QCOMPARE(findUsages.usages().size(), 5); +} + #if 0 @interface Clazz {} +(void)method:(int)arg; @end @implementation Clazz +(void)method:(int)arg { @@ -285,5 +401,48 @@ void tst_FindUsages::qproperty_1() QCOMPARE(findUsages.references().size(), 2); } +void tst_FindUsages::instantiateTemplateWithNestedClass() +{ + const QByteArray src = "\n" + "struct Foo\n" + "{ int bar; };\n" + "template <typename T>\n" + "struct Template\n" + "{\n" + " struct Nested\n" + " {\n" + " T t;\n" + " }nested;\n" + "};\n" + "void f()\n" + "{\n" + " Template<Foo> templateFoo;\n" + " templateFoo.nested.t.bar;\n" + "}\n" + ; + + Document::Ptr doc = Document::create("simpleTemplate"); + doc->setUtf8Source(src); + doc->parse(); + doc->check(); + + QVERIFY(doc->diagnosticMessages().isEmpty()); + QCOMPARE(doc->globalSymbolCount(), 3U); + + Snapshot snapshot; + snapshot.insert(doc); + + Class *classFoo = doc->globalSymbolAt(0)->asClass(); + QVERIFY(classFoo); + QCOMPARE(classFoo->memberCount(), 1U); + Declaration *barDeclaration = classFoo->memberAt(0)->asDeclaration(); + QVERIFY(barDeclaration); + QCOMPARE(barDeclaration->name()->identifier()->chars(), "bar"); + + FindUsages findUsages(src, doc, snapshot); + findUsages(barDeclaration); + QCOMPARE(findUsages.usages().size(), 2); +} + QTEST_APPLESS_MAIN(tst_FindUsages) #include "tst_findusages.moc" diff --git a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp index b1c90f0c39..2a985f5a09 100644 --- a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp +++ b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp @@ -216,6 +216,12 @@ public: *m_output = m_pp.run(fileName, src, nolines, true); } + virtual void markAsIncludeGuard(const QByteArray ¯oName) + { m_includeGuardMacro = macroName; } + + QByteArray includeGuard() const + { return m_includeGuardMacro; } + QList<Block> skippedBlocks() const { return m_skippedBlocks; } @@ -246,6 +252,7 @@ private: Preprocessor m_pp; QList<QDir> m_includePaths; unsigned m_includeDepth; + QByteArray m_includeGuardMacro; QList<Block> m_skippedBlocks; QList<Include> m_recordedIncludes; QList<QByteArray> m_expandedMacros; @@ -329,6 +336,7 @@ private slots: void dont_eagerly_expand_data(); void comparisons_data(); void comparisons(); + void comments_before_args(); void comments_within(); void comments_within_data(); void comments_within2(); @@ -339,6 +347,8 @@ private slots: void multiline_strings_data(); void skip_unknown_directives(); void skip_unknown_directives_data(); + void include_guard(); + void include_guard_data(); }; // Remove all #... lines, and 'simplify' string, to allow easily comparing the result @@ -1239,6 +1249,28 @@ void tst_Preprocessor::comments_within_data() QTest::newRow("case 7") << original << expected; } +void tst_Preprocessor::comments_before_args() +{ + Client *client = 0; // no client. + Environment env; + + Preprocessor preprocess(client, &env); + preprocess.setKeepComments(true); + QByteArray preprocessed = preprocess.run(QLatin1String("<stdin>"), + "\n#define foo(a,b) int a = b;" + "\nfoo/*C comment*/(a,1)\n" + "\nfoo/**Doxygen comment*/(b,2)\n" + "\nfoo//C++ comment\n(c,3)\n" + "\nfoo///Doxygen C++ comment\n(d,4)\n" + "\nfoo/*multiple*///comments\n/**as well*/(e,5)\n", + true, false); + + preprocessed = preprocessed.simplified(); +// DUMP_OUTPUT(preprocessed); + QCOMPARE(simplified(preprocessed), + QString("int a=1;int b=2;int c=3;int d=4;int e=5;")); +} + void tst_Preprocessor::comments_within2() { compare_input_output(true); @@ -1458,6 +1490,88 @@ void tst_Preprocessor::skip_unknown_directives_data() QTest::newRow("case 1") << original << expected; } +void tst_Preprocessor::include_guard() +{ + QFETCH(QString, includeGuard); + QFETCH(QString, input); + + QByteArray output; + Environment env; + MockClient client(&env, &output); + Preprocessor preprocess(&client, &env); + preprocess.setKeepComments(true); + /*QByteArray prep =*/ preprocess.run(QLatin1String("<test-case>"), input); + QCOMPARE(QString::fromUtf8(client.includeGuard()), includeGuard); +} + +void tst_Preprocessor::include_guard_data() +{ + QTest::addColumn<QString>("includeGuard"); + QTest::addColumn<QString>("input"); + + QTest::newRow("basic-test") << "BASIC_TEST" + << "#ifndef BASIC_TEST\n" + "#define BASIC_TEST\n" + "\n" + "#endif // BASIC_TEST\n"; + QTest::newRow("comments-1") << "GUARD" + << "/* some\n" + " * copyright\n" + " * header.\n" + " */\n" + "#ifndef GUARD\n" + "#define GUARD\n" + "\n" + "#endif // GUARD\n"; + QTest::newRow("comments-2") << "GUARD" + << "#ifndef GUARD\n" + "#define GUARD\n" + "\n" + "#endif // GUARD\n" + "/* some\n" + " * trailing\n" + " * comments.\n" + " */\n" + ; + QTest::newRow("nested-ifdef") << "GUARD" + << "#ifndef GUARD\n" + "#define GUARD\n" + "#ifndef NOT_GUARD\n" + "#define NOT_GUARD\n" + "#endif // NOT_GUARD\n" + "\n" + "#endif // GUARD\n" + ; + QTest::newRow("leading-tokens") << "" + << "int i;\n" + "#ifndef GUARD\n" + "#define GUARD\n" + "\n" + "#endif // GUARD\n" + ; + QTest::newRow("trailing-tokens") << "" + << "#ifndef GUARD\n" + "#define GUARD\n" + "\n" + "#endif // GUARD\n" + "int i;\n" + ; + QTest::newRow("surprising-but-correct") << "GUARD" + << "#ifndef GUARD\n" + "int i;\n" + "\n" + "#define GUARD\n" + "#endif // GUARD\n" + ; + QTest::newRow("incomplete-1") << "" + << "#ifndef GUARD\n" + ; + QTest::newRow("incomplete-2") << "GUARD" + << "#ifndef GUARD\n" + "#define GUARD\n" + ; +} + void tst_Preprocessor::compare_input_output(bool keepComments) { QFETCH(QByteArray, input); diff --git a/tests/auto/cplusplus/semantic/tst_semantic.cpp b/tests/auto/cplusplus/semantic/tst_semantic.cpp index bdc77773f1..fa17702461 100644 --- a/tests/auto/cplusplus/semantic/tst_semantic.cpp +++ b/tests/auto/cplusplus/semantic/tst_semantic.cpp @@ -481,12 +481,12 @@ void tst_Semantic::template_instance_1() QVERIFY(decl); FullySpecifiedType templArgs[] = { control->integerType(IntegerType::Int) }; - const Name *templId = control->templateNameId(control->identifier("QList"), templArgs, 1); + const Name *templId = control->templateNameId(control->identifier("QList"), false, templArgs, 1); FullySpecifiedType genTy = DeprecatedGenTemplateInstance::instantiate(templId, decl, control); Overview oo; - oo.setShowReturnTypes(true); + oo.showReturnTypes = true; const QString genDecl = oo.prettyType(genTy); QCOMPARE(genDecl, QString::fromLatin1("void (const int &)")); diff --git a/tests/auto/cplusplus/typeprettyprinter/tst_typeprettyprinter.cpp b/tests/auto/cplusplus/typeprettyprinter/tst_typeprettyprinter.cpp index 6444bedb8d..f5bc5e4674 100644 --- a/tests/auto/cplusplus/typeprettyprinter/tst_typeprettyprinter.cpp +++ b/tests/auto/cplusplus/typeprettyprinter/tst_typeprettyprinter.cpp @@ -27,25 +27,23 @@ ** ****************************************************************************/ -#include <QtTest> #include <QObject> -#include <QList> +#include <QtTest> -#include <FullySpecifiedType.h> -#include <Type.h> #include <CoreTypes.h> -#include <Symbols.h> -#include <TranslationUnit.h> -#include <Control.h> -#include <Names.h> +#include <FullySpecifiedType.h> #include <Literals.h> #include <Overview.h> -#include <Scope.h> +#include <Symbols.h> +#include <Type.h> #include <TypePrettyPrinter.h> //TESTED_COMPONENT=src/libs/cplusplus using namespace CPlusPlus; +Q_DECLARE_METATYPE(CPlusPlus::FullySpecifiedType) +Q_DECLARE_METATYPE(Overview::StarBindFlags) + class tst_TypePrettyPrinter: public QObject { Q_OBJECT @@ -55,160 +53,359 @@ private Q_SLOTS: void basic_data(); }; -Q_DECLARE_METATYPE(CPlusPlus::FullySpecifiedType); - -TranslationUnit *unit; - -const Identifier *nameId(const QString &name) +static const Identifier *nameId(const QString &name) { return new Identifier(name.toLatin1().constData(), name.toLatin1().size()); } -Argument *arg(const QString &name, const FullySpecifiedType &ty) +static Argument *arg(const QString &name, const FullySpecifiedType &ty) { - Argument *a = new Argument(unit, 0, nameId(name)); + Argument *a = new Argument(0, 0, nameId(name)); a->setType(ty); return a; } -FullySpecifiedType voidTy() +static FullySpecifiedType voidTy() { return FullySpecifiedType(new VoidType); } -FullySpecifiedType intTy() +static FullySpecifiedType intTy() { return FullySpecifiedType(new IntegerType(IntegerType::Int)); } -FullySpecifiedType fnTy(const QString &name, const FullySpecifiedType &ret) +static FullySpecifiedType fnTy(const QString &name, const FullySpecifiedType &ret) { - Function *fn = new Function(unit, 0, nameId(name)); + Function *fn = new Function(0, 0, nameId(name)); fn->setReturnType(ret); return FullySpecifiedType(fn); } -FullySpecifiedType fnTy(const QString &name, const FullySpecifiedType &ret, const FullySpecifiedType &a0) +static FullySpecifiedType fnTy(const QString &name, const FullySpecifiedType &ret, + const FullySpecifiedType &a0) { - Function *fn = new Function(unit, 0, nameId(name)); + Function *fn = new Function(0, 0, nameId(name)); fn->setReturnType(ret); fn->addMember(arg("a0", a0)); return FullySpecifiedType(fn); } -FullySpecifiedType ptr(const FullySpecifiedType &el) +static FullySpecifiedType fnTy(const QString &name, const FullySpecifiedType &ret, + const FullySpecifiedType &a0, const FullySpecifiedType &a1, + const FullySpecifiedType &a2) +{ + Function *fn = new Function(0, 0, nameId(name)); + fn->setReturnType(ret); + fn->addMember(arg("a0", a0)); + fn->addMember(arg("a1", a1)); + fn->addMember(arg("a1", a2)); + return FullySpecifiedType(fn); +} + +static FullySpecifiedType ptr(const FullySpecifiedType &el) { return FullySpecifiedType(new PointerType(el)); } -FullySpecifiedType ref(const FullySpecifiedType &el) +static FullySpecifiedType ref(const FullySpecifiedType &el) { return FullySpecifiedType(new ReferenceType(el, false)); } -FullySpecifiedType rref(const FullySpecifiedType &el) +static FullySpecifiedType rref(const FullySpecifiedType &el) { return FullySpecifiedType(new ReferenceType(el, true)); } -FullySpecifiedType arr(const FullySpecifiedType &el) +static FullySpecifiedType arr(const FullySpecifiedType &el) { return FullySpecifiedType(new ArrayType(el, 4)); } -FullySpecifiedType cnst(const FullySpecifiedType &el) +static FullySpecifiedType cnst(const FullySpecifiedType &el) { FullySpecifiedType r(el); r.setConst(true); return r; } +static QString toString(Overview::StarBindFlags starBindFlags) +{ + QString result; + if (starBindFlags & Overview::BindToIdentifier) + result += QLatin1Char('n'); + if (starBindFlags & Overview::BindToTypeName) + result += QLatin1Char('t'); + if (starBindFlags & Overview::BindToLeftSpecifier) + result += QLatin1String("Sl"); + if (starBindFlags & Overview::BindToRightSpecifier) + result += QLatin1String("Sr"); + return result; +} - -void addRow(const FullySpecifiedType &f, QString result, QString name = QString()) +static void addRow(const FullySpecifiedType &f, Overview::StarBindFlags starBindFlags, + const QString &result, const QString &name = QString()) { - QTest::newRow(result.toLatin1().constData()) << f << name << result; + const QString dataTag + = QString::fromLatin1("'%1' with star binding '%2'").arg(result, toString(starBindFlags)); + QTest::newRow(dataTag.toLatin1().constData()) << f << starBindFlags << name << result; } void tst_TypePrettyPrinter::basic_data() { - // seems it now works without a translation unit -// Control c; -// TranslationUnit t(&c, 0); -// unit = 0; - QTest::addColumn<FullySpecifiedType>("type"); + QTest::addColumn<Overview::StarBindFlags>("starBindFlags"); QTest::addColumn<QString>("name"); QTest::addColumn<QString>("result"); - addRow(voidTy(), "void"); - addRow(cnst(voidTy()), "const void"); - addRow(ptr(fnTy("foo", voidTy())), "void (*)()"); - addRow(ptr(fnTy("foo", voidTy())), "void (*foo)()", "foo"); - - // named types - addRow(voidTy(), "void foo", "foo"); - addRow(ptr(voidTy()), "void *foo", "foo"); - addRow(cnst(ptr(voidTy())), "void *const foo", "foo"); - addRow(arr(voidTy()), "void foo[]", "foo"); - addRow(ptr(arr(voidTy())), "void (*foo)[]", "foo"); - - // pointers - addRow(ptr(voidTy()), "void *"); - addRow(ptr(ptr(voidTy())), "void **"); - - addRow(ptr(cnst(voidTy())), "const void *"); - addRow(cnst(ptr(cnst(voidTy()))), "const void *const"); - addRow(cnst(ptr(voidTy())), "void *const"); - - addRow(ptr(ptr(cnst(voidTy()))), "const void **"); - addRow(ptr(cnst(ptr(cnst(voidTy())))), "const void *const*"); - addRow(cnst(ptr(ptr(cnst(voidTy())))), "const void **const"); - addRow(cnst(ptr(cnst(ptr(cnst(voidTy()))))), "const void *const*const"); - addRow(ptr(cnst(ptr(voidTy()))), "void *const*"); - addRow(cnst(ptr(ptr(voidTy()))), "void **const"); - addRow(cnst(ptr(cnst(ptr(voidTy())))), "void *const*const"); - - addRow(arr(voidTy()), "void[]"); - addRow(arr(ptr(voidTy())), "void *[]"); - addRow(ptr(arr(voidTy())), "void (*)[]"); - addRow(ptr(arr(arr(voidTy()))), "void (*)[][]"); - addRow(ptr(arr(ptr(voidTy()))), "void *(*)[]"); - addRow(arr(ptr(arr(voidTy()))), "void (*[])[]"); - - // references - addRow(ref(voidTy()), "void &"); - addRow(ref(ref(voidTy())), "void & &"); - - addRow(ref(cnst(voidTy())), "const void &"); - addRow(cnst(ref(cnst(voidTy()))), "const void &const"); - addRow(cnst(ref(voidTy())), "void &const"); - - addRow(ref(ref(cnst(voidTy()))), "const void & &"); - addRow(ref(cnst(ref(cnst(voidTy())))), "const void &const&"); - addRow(cnst(ref(ref(cnst(voidTy())))), "const void & &const"); - addRow(cnst(ref(cnst(ref(cnst(voidTy()))))), "const void &const&const"); - addRow(ref(cnst(ref(voidTy()))), "void &const&"); - addRow(cnst(ref(ref(voidTy()))), "void & &const"); - addRow(cnst(ref(cnst(ref(voidTy())))), "void &const&const"); - - addRow(arr(voidTy()), "void[]"); - addRow(arr(ref(voidTy())), "void &[]"); - addRow(ref(arr(voidTy())), "void (&)[]"); - addRow(ref(arr(arr(voidTy()))), "void (&)[][]"); - addRow(ref(arr(ref(voidTy()))), "void &(&)[]"); - addRow(arr(ref(arr(voidTy()))), "void (&[])[]"); - - // rvalue references - addRow(rref(voidTy()), "void &&"); - addRow(rref(cnst(voidTy())), "const void &&"); - - addRow(rref(arr(voidTy())), "void (&&)[]"); - addRow(rref(arr(arr(voidTy()))), "void (&&)[][]"); - - // simple functions - addRow(ptr(fnTy("foo", voidTy(), intTy())), "void (*foo)(int)", "foo"); - addRow(ptr(fnTy("foo", voidTy(), ptr(voidTy()))), "void (*foo)(void *)", "foo"); - addRow(fnTy("foo", voidTy(), intTy()), "void foo(int)", "foo"); - addRow(fnTy("foo", voidTy(), ptr(voidTy())), "void foo(void *)", "foo"); - - // functions with ptr or ref returns - addRow(ptr(fnTy("foo", ptr(voidTy()), intTy())), "void *(*foo)(int)", "foo"); - addRow(ptr(fnTy("foo", ref(voidTy()), ptr(voidTy()))), "void &(*foo)(void *)", "foo"); - addRow(fnTy("foo", ptr(voidTy()), intTy()), "void *foo(int)", "foo"); - addRow(fnTy("foo", ref(voidTy()), ptr(voidTy())), "void &foo(void *)", "foo"); + // Define some often used flag combinations. + const Overview::StarBindFlags bindToNothing = 0; + const Overview::StarBindFlags bindToBothSpecifiers + = Overview::StarBindFlags(Overview::BindToLeftSpecifier | Overview::BindToRightSpecifier); + const Overview::StarBindFlags bindToNameAndType + = Overview::StarBindFlags(Overview::BindToIdentifier | Overview::BindToTypeName); + const Overview::StarBindFlags bindToTypeAndRightSpecifier + = Overview::StarBindFlags(Overview::BindToTypeName | Overview::BindToRightSpecifier); + const Overview::StarBindFlags bindToAll = Overview::StarBindFlags(Overview::BindToIdentifier + | Overview::BindToTypeName | Overview::BindToLeftSpecifier | Overview::BindToRightSpecifier); + + // The star bindings should not affect declarations without a star or reference sign. + addRow(voidTy(), bindToNothing, "void"); + addRow(voidTy(), bindToAll, "void"); + addRow(voidTy(), bindToAll, "void foo", "foo"); + addRow(voidTy(), bindToNothing, "void foo", "foo"); + + addRow(cnst(voidTy()), bindToNothing, "const void"); + addRow(cnst(voidTy()), bindToAll, "const void"); + addRow(cnst(voidTy()), bindToNothing, "const void foo", "foo"); + addRow(cnst(voidTy()), bindToAll, "const void foo", "foo"); + + addRow(arr(voidTy()), bindToNothing, "void[]"); + addRow(arr(voidTy()), bindToAll, "void[]"); + addRow(arr(voidTy()), bindToNothing, "void foo[]", "foo"); + addRow(arr(voidTy()), bindToAll, "void foo[]", "foo"); + + addRow(fnTy("foo", voidTy(), intTy()), bindToNothing, "void foo(int)", "foo"); + addRow(fnTy("foo", voidTy(), intTy()), bindToAll, "void foo(int)", "foo"); + + // Pointers to functions and arrays are also excluded. It seems to be quite unusal to have + // a space there. + addRow(ptr(fnTy("foo", voidTy())), bindToAll, "void (*)()"); + addRow(ptr(fnTy("foo", voidTy())), bindToNothing, "void (*)()"); + addRow(ptr(fnTy("foo", voidTy())), bindToAll, "void (*foo)()", "foo"); + addRow(ptr(fnTy("foo", voidTy())), bindToNothing, "void (*foo)()", "foo"); + + addRow(ptr(arr(voidTy())), bindToNothing, "void (*)[]"); + addRow(ptr(arr(voidTy())), bindToAll, "void (*)[]"); + + addRow(ptr(arr(arr(voidTy()))), bindToNothing, "void (*)[][]"); + addRow(ptr(arr(arr(voidTy()))), bindToAll, "void (*)[][]"); + + // Pointers only + addRow(ptr(voidTy()), Overview::BindToTypeName, "void*"); + addRow(ptr(voidTy()), bindToAll, "void*"); + addRow(ptr(voidTy()), bindToNothing, "void *"); + addRow(ptr(voidTy()), Overview::BindToIdentifier, "void *foo", "foo"); + addRow(ptr(voidTy()), Overview::BindToTypeName, "void* foo", "foo"); + addRow(ptr(voidTy()), bindToNameAndType, "void*foo", "foo"); + addRow(ptr(voidTy()), bindToAll, "void*foo", "foo"); + addRow(ptr(voidTy()), bindToNothing, "void * foo", "foo"); + + addRow(ptr(ptr(voidTy())), Overview::BindToTypeName, "void**"); + addRow(ptr(ptr(voidTy())), bindToAll, "void**"); + addRow(ptr(ptr(voidTy())), bindToNothing, "void **"); + addRow(ptr(ptr(voidTy())), Overview::BindToIdentifier, "void **foo", "foo"); + addRow(ptr(ptr(voidTy())), Overview::BindToTypeName, "void** foo", "foo"); + addRow(ptr(ptr(voidTy())), bindToNameAndType, "void**foo", "foo"); + addRow(ptr(ptr(voidTy())), bindToAll, "void**foo", "foo"); + addRow(ptr(ptr(voidTy())), bindToNothing, "void ** foo", "foo"); + + addRow(ptr(cnst(voidTy())), bindToAll, "const void*"); + addRow(ptr(cnst(voidTy())), bindToNothing, "const void *"); + + addRow(cnst(ptr(voidTy())), Overview::BindToIdentifier, "void * const foo", "foo"); + addRow(cnst(ptr(voidTy())), Overview::BindToTypeName, "void* const foo", "foo"); + addRow(cnst(ptr(voidTy())), Overview::BindToRightSpecifier, "void *const foo", "foo"); + addRow(cnst(ptr(voidTy())), bindToTypeAndRightSpecifier, "void*const foo", "foo"); + addRow(cnst(ptr(voidTy())), bindToAll, "void*const foo", "foo"); + addRow(cnst(ptr(voidTy())), bindToNothing, "void * const foo", "foo"); + + addRow(cnst(ptr(cnst(voidTy()))), bindToAll, "const void*const"); + addRow(cnst(ptr(cnst(voidTy()))), Overview::BindToTypeName, "const void* const"); + addRow(cnst(ptr(cnst(voidTy()))), Overview::BindToRightSpecifier, "const void *const"); + addRow(cnst(ptr(cnst(voidTy()))), bindToNothing, "const void * const"); + + addRow(cnst(ptr(voidTy())), Overview::BindToIdentifier, "void * const"); + addRow(cnst(ptr(voidTy())), Overview::BindToTypeName, "void* const"); + addRow(cnst(ptr(voidTy())), Overview::BindToRightSpecifier, "void *const"); + addRow(cnst(ptr(voidTy())), bindToTypeAndRightSpecifier, "void*const"); + addRow(cnst(ptr(voidTy())), bindToAll, "void*const"); + addRow(cnst(ptr(voidTy())), bindToNothing, "void * const"); + + addRow(ptr(ptr(cnst(voidTy()))), Overview::BindToIdentifier, "const void **"); + addRow(ptr(cnst(ptr(cnst(voidTy())))), Overview::BindToIdentifier, "const void * const *"); + addRow(cnst(ptr(ptr(cnst(voidTy())))), Overview::BindToIdentifier, "const void ** const"); + + addRow(ptr(cnst(ptr(voidTy()))), bindToNothing, "void * const *"); + addRow(ptr(cnst(ptr(voidTy()))), bindToAll, "void*const*"); + addRow(cnst(ptr(ptr(voidTy()))), bindToNothing, "void ** const"); + addRow(cnst(ptr(ptr(voidTy()))), bindToAll, "void**const"); + + addRow(cnst(ptr(cnst(ptr(voidTy())))), bindToNothing, "void * const * const"); + addRow(cnst(ptr(cnst(ptr(voidTy())))), bindToAll, "void*const*const"); + addRow(cnst(ptr(ptr(cnst(ptr(voidTy()))))), bindToNothing, "void * const ** const"); + addRow(cnst(ptr(ptr(cnst(ptr(voidTy()))))), bindToAll, "void*const**const"); + + addRow(cnst(ptr(cnst(ptr(cnst(voidTy()))))), Overview::BindToLeftSpecifier, "const void * const* const"); + addRow(cnst(ptr(cnst(ptr(cnst(voidTy()))))), Overview::BindToRightSpecifier, "const void *const *const"); + addRow(cnst(ptr(cnst(ptr(cnst(voidTy()))))), bindToBothSpecifiers, "const void *const*const"); + addRow(cnst(ptr(cnst(ptr(cnst(voidTy()))))), bindToNothing, "const void * const * const"); + addRow(cnst(ptr(cnst(ptr(cnst(voidTy()))))), bindToAll, "const void*const*const"); + + // Pointers and arrays + addRow(arr(ptr(voidTy())), bindToNothing, "void * argv[]", "argv"); + addRow(arr(ptr(voidTy())), bindToAll, "void*argv[]", "argv"); + + addRow(arr(ptr(voidTy())), bindToNothing, "void *[]"); + addRow(arr(ptr(voidTy())), bindToAll, "void*[]"); + + addRow(ptr(arr(ptr(voidTy()))), bindToNothing, "void *(*)[]"); + addRow(ptr(arr(ptr(voidTy()))), bindToAll, "void*(*)[]"); + + addRow(arr(ptr(arr(voidTy()))), bindToNothing, "void (*[])[]"); + addRow(arr(ptr(arr(voidTy()))), bindToAll, "void (*[])[]"); + + addRow(ptr(arr(voidTy())), bindToAll, "void (*foo)[]", "foo"); + addRow(ptr(arr(voidTy())), bindToNothing, "void (*foo)[]", "foo"); + + // Pointers to functions + addRow(ptr(fnTy("foo", voidTy(), intTy())), bindToNothing, "void (*foo)(int)", "foo"); + addRow(ptr(fnTy("foo", voidTy(), intTy())), bindToAll, "void (*foo)(int)", "foo"); + + addRow(ptr(fnTy("foo", voidTy(), ptr(voidTy()))), bindToNothing, "void (*foo)(void *)", "foo"); + addRow(ptr(fnTy("foo", voidTy(), ptr(voidTy()))), bindToAll, "void (*foo)(void*)", "foo"); + + // Pointers in more complex declarations + FullySpecifiedType complexType1 + = ptr(fnTy("foo", voidTy(), intTy(), ptr(voidTy()), ptr(ptr(intTy())))); + addRow(complexType1, bindToNothing, "void (*foo)(int, void *, int **)", "foo"); + addRow(complexType1, bindToAll, "void (*foo)(int, void*, int**)", "foo"); + + FullySpecifiedType complexType2 = ptr(fnTy("foo", voidTy(), + intTy(), cnst(ptr(cnst(voidTy()))), cnst(ptr(cnst(ptr(intTy())))))); + addRow(complexType2, Overview::BindToLeftSpecifier, + "void (*foo)(int, const void * const, int * const* const)", "foo"); + addRow(complexType2, Overview::BindToRightSpecifier, + "void (*foo)(int, const void *const, int *const *const)", "foo"); + addRow(complexType2, bindToBothSpecifiers, + "void (*foo)(int, const void *const, int *const*const)", "foo"); + addRow(complexType2, bindToNothing, + "void (*foo)(int, const void * const, int * const * const)", "foo"); + addRow(complexType2, bindToAll, + "void (*foo)(int, const void*const, int*const*const)", "foo"); + + // References only + addRow(ref(voidTy()), bindToNothing, "void &"); + addRow(ref(voidTy()), bindToAll, "void&"); + + addRow(ref(ref(voidTy())), bindToNothing, "void & &"); + addRow(ref(ref(voidTy())), bindToAll, "void& &"); + + addRow(ref(cnst(voidTy())), bindToNothing, "const void &"); + addRow(ref(cnst(voidTy())), bindToAll, "const void&"); + + addRow(cnst(ref(cnst(voidTy()))), Overview::BindToRightSpecifier, "const void &const"); + addRow(cnst(ref(cnst(voidTy()))), Overview::BindToTypeName, "const void& const"); + addRow(cnst(ref(cnst(voidTy()))), bindToNothing, "const void & const"); + addRow(cnst(ref(cnst(voidTy()))), bindToAll, "const void&const"); + + addRow(cnst(ref(voidTy())), Overview::BindToRightSpecifier, "void &const"); + addRow(cnst(ref(voidTy())), Overview::BindToTypeName, "void& const"); + addRow(cnst(ref(voidTy())), bindToNothing, "void & const"); + addRow(cnst(ref(voidTy())), bindToAll, "void&const"); + + addRow(ref(ref(cnst(voidTy()))), bindToNothing, "const void & &"); + addRow(ref(ref(cnst(voidTy()))), bindToAll, "const void& &"); + + addRow(ref(cnst(ref(cnst(voidTy())))), Overview::BindToTypeName, "const void& const &"); + addRow(ref(cnst(ref(cnst(voidTy())))), Overview::BindToLeftSpecifier, "const void & const&"); + addRow(ref(cnst(ref(cnst(voidTy())))), Overview::BindToRightSpecifier, "const void &const &"); + addRow(ref(cnst(ref(cnst(voidTy())))), bindToBothSpecifiers, "const void &const&"); + addRow(ref(cnst(ref(cnst(voidTy())))), bindToNothing, "const void & const &"); + addRow(ref(cnst(ref(cnst(voidTy())))), bindToAll, "const void&const&"); + + addRow(cnst(ref(ref(cnst(voidTy())))), bindToBothSpecifiers, "const void & &const"); + addRow(cnst(ref(ref(cnst(voidTy())))), bindToNothing, "const void & & const"); + addRow(cnst(ref(ref(cnst(voidTy())))), bindToAll, "const void& &const"); + + addRow(cnst(ref(cnst(ref(cnst(voidTy()))))), Overview::BindToLeftSpecifier, "const void & const& const"); + addRow(cnst(ref(cnst(ref(cnst(voidTy()))))), Overview::BindToRightSpecifier, "const void &const &const"); + addRow(cnst(ref(cnst(ref(cnst(voidTy()))))), bindToBothSpecifiers, "const void &const&const"); + addRow(cnst(ref(cnst(ref(cnst(voidTy()))))), bindToNothing, "const void & const & const"); + addRow(cnst(ref(cnst(ref(cnst(voidTy()))))), bindToAll, "const void&const&const"); + + addRow(ref(cnst(ref(voidTy()))), bindToNothing, "void & const &"); + addRow(ref(cnst(ref(voidTy()))), bindToAll, "void&const&"); + + addRow(cnst(ref(ref(voidTy()))), bindToNothing, "void & & const"); + addRow(cnst(ref(ref(voidTy()))), bindToAll, "void& &const"); + + addRow(cnst(ref(cnst(ref(voidTy())))), Overview::BindToLeftSpecifier, "void & const& const"); + addRow(cnst(ref(cnst(ref(voidTy())))), Overview::BindToRightSpecifier, "void &const &const"); + addRow(cnst(ref(cnst(ref(voidTy())))), bindToBothSpecifiers, "void &const&const"); + addRow(cnst(ref(cnst(ref(voidTy())))), bindToNothing, "void & const & const"); + addRow(cnst(ref(cnst(ref(voidTy())))), bindToAll, "void&const&const"); + + addRow(ref(fnTy("foo", voidTy())), bindToNothing, "void (&foo)()", "foo"); + addRow(ref(fnTy("foo", voidTy())), bindToAll, "void (&foo)()", "foo"); + + addRow(arr(ref(voidTy())), bindToNothing, "void &[]"); + addRow(arr(ref(voidTy())), bindToAll, "void&[]"); + + addRow(ref(arr(voidTy())), bindToNothing, "void (&)[]"); + addRow(ref(arr(voidTy())), bindToAll, "void (&)[]"); + + addRow(ref(arr(arr(voidTy()))), bindToNothing, "void (&)[][]"); + addRow(ref(arr(arr(voidTy()))), bindToAll, "void (&)[][]"); + + addRow(ref(arr(ref(voidTy()))), bindToNothing, "void &(&)[]"); + addRow(ref(arr(ref(voidTy()))), bindToAll, "void&(&)[]"); + + addRow(arr(ref(arr(voidTy()))), bindToNothing, "void (&[])[]"); + addRow(arr(ref(arr(voidTy()))), bindToAll, "void (&[])[]"); + + // Rvalue References + addRow(rref(voidTy()), bindToNothing, "void &&"); + addRow(rref(voidTy()), bindToAll, "void&&"); + + addRow(rref(cnst(voidTy())), bindToNothing, "const void &&"); + addRow(rref(cnst(voidTy())), bindToAll, "const void&&"); + + addRow(rref(cnst(voidTy())), bindToNothing, "const void && foo", "foo"); + addRow(rref(cnst(voidTy())), bindToAll, "const void&&foo", "foo"); + + addRow(rref(arr(voidTy())), bindToNothing, "void (&&)[]"); + addRow(rref(arr(voidTy())), bindToAll, "void (&&)[]"); + + addRow(rref(arr(arr(voidTy()))), bindToNothing, "void (&&)[][]"); + addRow(rref(arr(arr(voidTy()))), bindToAll, "void (&&)[][]"); + + // Pointers and references mixed + addRow(cnst(ref(ptr(voidTy()))), bindToBothSpecifiers, "void *&const"); + addRow(cnst(ref(ptr(voidTy()))), bindToNothing, "void *& const"); + addRow(cnst(ref(ptr(voidTy()))), bindToAll, "void*&const"); + + // Functions with pointer parameters + addRow(fnTy("foo", voidTy(), ptr(voidTy())), bindToNothing, "void foo(void *)", "foo"); + addRow(fnTy("foo", voidTy(), ptr(voidTy())), bindToAll, "void foo(void*)", "foo"); + + // Functions with pointer or reference returns + addRow(ptr(fnTy("foo", ptr(voidTy()), intTy())), bindToNothing, "void *(*foo)(int)", "foo"); + addRow(ptr(fnTy("foo", ptr(voidTy()), intTy())), bindToAll, "void*(*foo)(int)", "foo"); + + addRow(ptr(fnTy("foo", ref(voidTy()), ptr(voidTy()))), bindToNothing, "void &(*foo)(void *)", "foo"); + addRow(ptr(fnTy("foo", ref(voidTy()), ptr(voidTy()))), bindToAll, "void&(*foo)(void*)", "foo"); + + addRow(fnTy("foo", ptr(voidTy()), intTy()), bindToNothing, "void *foo(int)", "foo"); + addRow(fnTy("foo", ptr(voidTy()), intTy()), bindToAll, "void*foo(int)", "foo"); + + addRow(fnTy("foo", ref(voidTy()), ptr(voidTy())), bindToNothing, "void &foo(void *)", "foo"); + addRow(fnTy("foo", ref(voidTy()), ptr(voidTy())), bindToAll, "void&foo(void*)", "foo"); } void tst_TypePrettyPrinter::basic() { QFETCH(FullySpecifiedType, type); + QFETCH(Overview::StarBindFlags, starBindFlags); QFETCH(QString, name); QFETCH(QString, result); Overview o; - o.setShowReturnTypes(true); + o.showReturnTypes = true; + o.starBindFlags = starBindFlags; TypePrettyPrinter pp(&o); QCOMPARE(pp(type, name), result); } diff --git a/tests/auto/debugger/debugger.pro b/tests/auto/debugger/debugger.pro index e3cebaa8f0..fa95b89dca 100644 --- a/tests/auto/debugger/debugger.pro +++ b/tests/auto/debugger/debugger.pro @@ -1,7 +1,10 @@ TEMPLATE = subdirs -SUBDIRS = dumpers.pro version.pro namedemangler.pro +SUBDIRS += version.pro +SUBDIRS += dumpers.pro +#SUBDIRS += olddumpers.pro +SUBDIRS += namedemangler.pro !win32-msvc*: SUBDIRS += gdb.pro diff --git a/tests/auto/debugger/dumpers.pro b/tests/auto/debugger/dumpers.pro index 3f7e295972..26594b5f0c 100644 --- a/tests/auto/debugger/dumpers.pro +++ b/tests/auto/debugger/dumpers.pro @@ -1,23 +1,25 @@ -greaterThan(QT_MAJOR_VERSION, 4): QT += core-private + include(../qttest.pri) -include($$IDE_SOURCE_TREE/src/libs/utils/utils.pri) DEBUGGERDIR = $$IDE_SOURCE_TREE/src/plugins/debugger -UTILSDIR = $$IDE_SOURCE_TREE/src/libs/utils -MACROSDIR = $$IDE_SOURCE_TREE/share/qtcreator/dumper +DUMPERDIR = $$IDE_SOURCE_TREE/share/qtcreator/dumper SOURCES += \ - $$DEBUGGERDIR/gdb/gdbmi.cpp \ - $$MACROSDIR/dumper.cpp \ + $$DEBUGGERDIR/debuggerprotocol.cpp \ + $$DEBUGGERDIR/watchdata.cpp \ + $$DEBUGGERDIR/watchutils.cpp \ tst_dumpers.cpp -exists($$QMAKE_INCDIR_QT/QtCore/private/qobject_p.h):DEFINES += USE_PRIVATE - -DEFINES += MACROSDEBUG - -win32:DEFINES += _CRT_SECURE_NO_WARNINGS +HEADERS += \ + $$DEBUGGERDIR/debuggerprotocol.h \ + $$DEBUGGERDIR/watchdata.h \ + $$DEBUGGERDIR/watchutils.h \ -DEFINES -= QT_USE_FAST_CONCATENATION QT_USE_FAST_OPERATOR_PLUS -DEFINES -= QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII +!isEmpty(vcproj) { + DEFINES += DUMPERDIR=\"$$DUMPERDIR\" +} else { + DEFINES += DUMPERDIR=\\\"$$DUMPERDIR\\\" +} -INCLUDEPATH += $$DEBUGGERDIR $$UTILSDIR $$MACROSDIR +INCLUDEPATH += $$DEBUGGERDIR +DEFINES += QT_NO_CAST_FROM_ASCII diff --git a/tests/auto/debugger/gdb.pro b/tests/auto/debugger/gdb.pro index 164bb5b75e..7fc000fbc9 100644 --- a/tests/auto/debugger/gdb.pro +++ b/tests/auto/debugger/gdb.pro @@ -9,4 +9,4 @@ INCLUDEPATH += $$DEBUGGERDIR $$UTILSDIR SOURCES += \ tst_gdb.cpp \ - $$DEBUGGERDIR/gdb/gdbmi.cpp \ + $$DEBUGGERDIR/debuggerprotocol.cpp \ diff --git a/tests/auto/debugger/namedemangler.pro b/tests/auto/debugger/namedemangler.pro index d175689fca..da9dba3a30 100644 --- a/tests/auto/debugger/namedemangler.pro +++ b/tests/auto/debugger/namedemangler.pro @@ -1,10 +1,9 @@ include(../qttest.pri) -LIBS *= -L$$IDE_LIBRARY_PATH -lUtils - DEBUGGERDIR = $$IDE_SOURCE_TREE/src/plugins/debugger INCLUDEPATH += $$DEBUGGERDIR SOURCES = tst_namedemangler.cpp include($$DEBUGGERDIR/namedemangler/namedemangler.pri) +include($$IDE_SOURCE_TREE/src/libs/utils/utils.pri) diff --git a/tests/auto/debugger/olddumpers.pro b/tests/auto/debugger/olddumpers.pro new file mode 100644 index 0000000000..82c17f71ea --- /dev/null +++ b/tests/auto/debugger/olddumpers.pro @@ -0,0 +1,23 @@ +greaterThan(QT_MAJOR_VERSION, 4): QT += core-private +include(../qttest.pri) +include($$IDE_SOURCE_TREE/src/libs/utils/utils.pri) + +DEBUGGERDIR = $$IDE_SOURCE_TREE/src/plugins/debugger +UTILSDIR = $$IDE_SOURCE_TREE/src/libs/utils +MACROSDIR = $$IDE_SOURCE_TREE/share/qtcreator/dumper + +SOURCES += \ + $$DEBUGGERDIR/gdb/gdbmi.cpp \ + $$MACROSDIR/dumper.cpp \ + tst_olddumpers.cpp + +exists($$QMAKE_INCDIR_QT/QtCore/private/qobject_p.h):DEFINES += USE_PRIVATE + +DEFINES += MACROSDEBUG + +win32:DEFINES += _CRT_SECURE_NO_WARNINGS + +DEFINES -= QT_USE_FAST_CONCATENATION QT_USE_FAST_OPERATOR_PLUS +DEFINES -= QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII + +INCLUDEPATH += $$DEBUGGERDIR $$UTILSDIR $$MACROSDIR diff --git a/tests/auto/debugger/tst_dumpers.cpp b/tests/auto/debugger/tst_dumpers.cpp index e8b04646a3..d5e88b3252 100644 --- a/tests/auto/debugger/tst_dumpers.cpp +++ b/tests/auto/debugger/tst_dumpers.cpp @@ -27,2475 +27,3924 @@ ** ****************************************************************************/ -#define private public // Give us access to private 'backward' member of QMapNode. -# include <QMap> -#undef private - -#include "gdb/gdbmi.h" -#include "dumper.h" -#include "dumper_p.h" - -#include "json.h" - -#ifdef USE_PRIVATE -#include <private/qobject_p.h> -#else -#warning "No private headers for this Qt version available" -#endif - -#include <QStandardItemModel> -#include <QStringListModel> +#include "debuggerprotocol.h" +#include "watchdata.h" +#include "watchutils.h" #include <QtTest> -//#include <QtTest/qtest_gui.h> - -//TESTED_COMPONENT=src/plugins/debugger/gdb - -static const char *pointerPrintFormat() -{ - return sizeof(quintptr) == sizeof(long) ? "0x%lx" : "0x%llx"; -} - -#undef NS -#ifdef QT_NAMESPACE -# define STRINGIFY0(s) #s -# define STRINGIFY1(s) STRINGIFY0(s) -# define NS STRINGIFY1(QT_NAMESPACE) "::" -#else -# define NS "" -#endif +#include <QTemporaryFile> +#include <QTemporaryDir> using namespace Debugger; -using namespace Debugger::Internal; +using namespace Internal; -static QByteArray operator<<(QByteArray ba, const QByteArray &replacement) +static QByteArray noValue = "\001"; + +static QByteArray nameFromIName(const QByteArray &iname) { - int pos = ba.indexOf('%'); - Q_ASSERT(pos != -1); - return ba.replace(pos, 1, replacement); + int pos = iname.lastIndexOf('.'); + return pos == -1 ? iname : iname.mid(pos + 1); } -static QByteArray &operator<<=(QByteArray &ba, const QByteArray &replacement) +static QByteArray parentIName(const QByteArray &iname) { - int pos = ba.indexOf('%'); - Q_ASSERT(pos != -1); - return ba.replace(pos, 1, replacement); + int pos = iname.lastIndexOf('.'); + return pos == -1 ? QByteArray() : iname.left(pos); } - -template <typename T> -inline QByteArray N(T t) { return QByteArray::number(t); } - -static const char gdbmi1[] = - "[frame={level=\"0\",addr=\"0x00000000004061ca\"," - "func=\"main\",file=\"test1.cpp\"," - "fullname=\"/home/apoenitz/work/test1/test1.cpp\",line=\"209\"}]"; - -static const char gdbmi2[] = - "[frame={level=\"0\",addr=\"0x00002ac058675840\"," - "func=\"QApplication\",file=\"/home/apoenitz/dev/qt/src/gui/kernel/qapplication.cpp\"," - "fullname=\"/home/apoenitz/dev/qt/src/gui/kernel/qapplication.cpp\",line=\"592\"}," - "frame={level=\"1\",addr=\"0x00000000004061e0\",func=\"main\",file=\"test1.cpp\"," - "fullname=\"/home/apoenitz/work/test1/test1.cpp\",line=\"209\"}]"; - -static const char gdbmi3[] = - "[stack={frame={level=\"0\",addr=\"0x00000000004061ca\"," - "func=\"main\",file=\"test1.cpp\"," - "fullname=\"/home/apoenitz/work/test1/test1.cpp\",line=\"209\"}}]"; - -static const char gdbmi4[] = - "&\"source /home/apoenitz/dev/ide/main/bin/gdb/qt4macros\\n\"" - "4^done\n"; - -static const char gdbmi5[] = - "[reason=\"breakpoint-hit\",bkptno=\"1\",thread-id=\"1\"," - "frame={addr=\"0x0000000000405738\",func=\"main\"," - "args=[{name=\"argc\",value=\"1\"},{name=\"argv\",value=\"0x7fff1ac78f28\"}]," - "file=\"test1.cpp\",fullname=\"/home/apoenitz/work/test1/test1.cpp\"," - "line=\"209\"}]"; - -static const char gdbmi8[] = - "[data={locals={{name=\"a\"},{name=\"w\"}}}]"; - -static const char gdbmi9[] = - "[data={locals=[name=\"baz\",name=\"urgs\",name=\"purgs\"]}]"; - -static const char gdbmi10[] = - "[name=\"urgs\",numchild=\"1\",type=\"Urgs\"]"; - -static const char gdbmi11[] = - "[{name=\"size\",value=\"1\",type=\"size_t\",readonly=\"true\"}," - "{name=\"0\",value=\"one\",type=\"QByteArray\"}]"; - -static const char gdbmi12[] = - "[{iname=\"local.hallo\",value=\"\\\"\\\\\\00382\\t\\377\",type=\"QByteArray\"," - "numchild=\"0\"}]"; - - -static const char jsont1[] = - "{\"Size\":100564,\"UID\":0,\"GID\":0,\"Permissions\":33261," - "\"ATime\":1242370878000,\"MTime\":1239154689000}"; - -struct Int3 { - Int3() { i1 = 42; i2 = 43; i3 = 44; } - int i1, i2, i3; -}; - -struct QString3 { - QString3() { s1 = "a"; s2 = "b"; s3 = "c"; } - QString s1, s2, s3; -}; - -class tst_Dumpers : public QObject +struct Value { - Q_OBJECT - -public: - tst_Dumpers() {} + Value() + : value(noValue), hasPtrSuffix(false) + {} + Value(const char *str) + : value(str), hasPtrSuffix(false) + {} + Value(const QByteArray &ba) + : value(ba), hasPtrSuffix(false) + {} - void testMi(const char* input) + bool matches(const QString &actualValue0) const { - GdbMi gdbmi; - gdbmi.fromString(QByteArray(input)); - QCOMPARE('\n' + QString::fromLatin1(gdbmi.toString(false)), - '\n' + QString(input)); + if (value == noValue) + return true; + QString actualValue = actualValue0; + if (actualValue == QLatin1String(" ")) + actualValue.clear(); // FIXME: Remove later. + QString self = QString::fromLatin1(value.data(), value.size()); + if (hasPtrSuffix) + return actualValue.startsWith(self + QLatin1String(" @0x")) + || actualValue.startsWith(self + QLatin1String("@0x")); + return actualValue == self; } - void testJson(const char* input) - { - QCOMPARE('\n' + Utils::JsonStringValue(QLatin1String(input)).value(), - '\n' + QString(input)); - } - -private slots: - void mi1() { testMi(gdbmi1); } - void mi2() { testMi(gdbmi2); } - void mi3() { testMi(gdbmi3); } - //void mi4() { testMi(gdbmi4); } - void mi5() { testMi(gdbmi5); } - void mi8() { testMi(gdbmi8); } - void mi9() { testMi(gdbmi9); } - void mi10() { testMi(gdbmi10); } - void mi11() { testMi(gdbmi11); } - //void mi12() { testMi(gdbmi12); } - - void json1() { testJson(jsont1); } - - void infoBreak(); - void niceType(); - void niceType_data(); - - void dumperCompatibility(); - void dumpQAbstractItemAndModelIndex(); - void dumpQAbstractItemModel(); - void dumpQByteArray(); - void dumpQChar(); - void dumpQDateTime(); - void dumpQDir(); - void dumpQFile(); - void dumpQFileInfo(); - void dumpQHash(); - void dumpQHashNode(); - void dumpQImage(); - void dumpQImageData(); - void dumpQLinkedList(); - void dumpQList_int(); - void dumpQList_int_star(); - void dumpQList_char(); - void dumpQList_QString(); - void dumpQList_QString3(); - void dumpQList_Int3(); - void dumpQLocale(); - void dumpQMap(); - void dumpQMapNode(); -#ifdef USE_PRIVATE - void dumpQObject(); - void dumpQObjectChildList(); - void dumpQObjectMethodList(); - void dumpQObjectPropertyList(); - void dumpQObjectSignal(); - void dumpQObjectSignalList(); - void dumpQObjectSlot(); - void dumpQObjectSlotList(); -#endif - void dumpQPixmap(); - void dumpQSharedPointer(); - void dumpQString(); - void dumpQTextCodec(); - void dumpQVariant_invalid(); - void dumpQVariant_QString(); - void dumpQVariant_QStringList(); -#ifndef Q_CC_MSVC - void dumpStdVector(); -#endif // !Q_CC_MSVC - void dumpQWeakPointer(); - void initTestCase(); - -private: - void dumpQAbstractItemHelper(QModelIndex &index); - void dumpQAbstractItemModelHelper(QAbstractItemModel &m); - template <typename K, typename V> void dumpQHashNodeHelper(QHash<K, V> &hash); - void dumpQImageHelper(const QImage &img); - void dumpQImageDataHelper(QImage &img); - template <typename T> void dumpQLinkedListHelper(QLinkedList<T> &l); - void dumpQLocaleHelper(QLocale &loc); - template <typename K, typename V> void dumpQMapHelper(QMap<K, V> &m); - template <typename K, typename V> void dumpQMapNodeHelper(QMap<K, V> &m); - void dumpQObjectChildListHelper(QObject &o); - void dumpQObjectSignalHelper(QObject &o, int sigNum); -#if QT_VERSION >= 0x040500 - template <typename T> - void dumpQSharedPointerHelper(QSharedPointer<T> &ptr); - template <typename T> - void dumpQWeakPointerHelper(QWeakPointer<T> &ptr); -#endif - void dumpQTextCodecHelper(QTextCodec *codec); + QByteArray value; + bool hasPtrSuffix; }; -void tst_Dumpers::infoBreak() -{ - // This tests the regular expression used in GdbEngine::extractDataFromInfoBreak - // to discover breakpoints in constructors. - - // Copied from gdbengine.cpp: - - QRegExp re("MULTIPLE.*(0x[0-9a-f]+) in (.*)\\s+at (.*):([\\d]+)([^\\d]|$)"); - re.setMinimal(true); - - QCOMPARE(re.indexIn( - "2 breakpoint keep y <MULTIPLE> 0x0040168e\n" - "2.1 y 0x0040168e " - "in MainWindow::MainWindow(QWidget*) at mainwindow.cpp:7\n" - "2.2 y 0x00401792 " - "in MainWindow::MainWindow(QWidget*) at mainwindow.cpp:7\n"), 33); - QCOMPARE(re.cap(1), QString("0x0040168e")); - QCOMPARE(re.cap(2).trimmed(), QString("MainWindow::MainWindow(QWidget*)")); - QCOMPARE(re.cap(3), QString("mainwindow.cpp")); - QCOMPARE(re.cap(4), QString("7")); - - - QCOMPARE(re.indexIn( - "Num Type Disp Enb Address What" - "4 breakpoint keep y <MULTIPLE> 0x00000000004066ad" - "4.1 y 0x00000000004066ad in CTorTester" - " at /main/tests/manual/gdbdebugger/simple/app.cpp:124"), 88); - - QCOMPARE(re.cap(1), QString("0x00000000004066ad")); - QCOMPARE(re.cap(2).trimmed(), QString("CTorTester")); - QCOMPARE(re.cap(3), QString("/main/tests/manual/gdbdebugger/simple/app.cpp")); - QCOMPARE(re.cap(4), QString("124")); -} - -// -// type simplification -// - -static QString chopConst(QString type) -{ - while (1) { - if (type.startsWith("const")) - type = type.mid(5); - else if (type.startsWith(' ')) - type = type.mid(1); - else if (type.endsWith("const")) - type.chop(5); - else if (type.endsWith(' ')) - type.chop(1); - else - break; - } - return type; -} - -QString niceType(QString type) -{ - type.replace('*', '@'); - - for (int i = 0; i < 10; ++i) { - int start = type.indexOf("std::allocator<"); - if (start == -1) - break; - // search for matching '>' - int pos; - int level = 0; - for (pos = start + 12; pos < type.size(); ++pos) { - int c = type.at(pos).unicode(); - if (c == '<') { - ++level; - } else if (c == '>') { - --level; - if (level == 0) - break; - } - } - QString alloc = type.mid(start, pos + 1 - start).trimmed(); - QString inner = alloc.mid(15, alloc.size() - 16).trimmed(); - //qDebug() << "MATCH: " << pos << alloc << inner; - - if (inner == QLatin1String("char")) - // std::string - type.replace(QLatin1String("basic_string<char, std::char_traits<char>, " - "std::allocator<char> >"), QLatin1String("string")); - else if (inner == QLatin1String("wchar_t")) - // std::wstring - type.replace(QLatin1String("basic_string<wchar_t, std::char_traits<wchar_t>, " - "std::allocator<wchar_t> >"), QLatin1String("wstring")); - - // std::vector, std::deque, std::list - QRegExp re1(QString("(vector|list|deque)<%1, %2\\s*>").arg(inner, alloc)); - if (re1.indexIn(type) != -1) - type.replace(re1.cap(0), QString("%1<%2>").arg(re1.cap(1), inner)); - - - // std::stack - QRegExp re6(QString("stack<%1, std::deque<%2> >").arg(inner, inner)); - re6.setMinimal(true); - if (re6.indexIn(type) != -1) - type.replace(re6.cap(0), QString("stack<%1>").arg(inner)); - - // std::set - QRegExp re4(QString("set<%1, std::less<%2>, %3\\s*>").arg(inner, inner, alloc)); - re4.setMinimal(true); - if (re4.indexIn(type) != -1) - type.replace(re4.cap(0), QString("set<%1>").arg(inner)); - - - // std::map - if (inner.startsWith("std::pair<")) { - // search for outermost ',' - int pos; - int level = 0; - for (pos = 10; pos < inner.size(); ++pos) { - int c = inner.at(pos).unicode(); - if (c == '<') - ++level; - else if (c == '>') - --level; - else if (c == ',' && level == 0) - break; - } - QString ckey = inner.mid(10, pos - 10); - QString key = chopConst(ckey); - QString value = inner.mid(pos + 2, inner.size() - 3 - pos); - - QRegExp re5(QString("map<%1, %2, std::less<%3>, %4\\s*>") - .arg(key, value, key, alloc)); - re5.setMinimal(true); - if (re5.indexIn(type) != -1) - type.replace(re5.cap(0), QString("map<%1, %2>").arg(key, value)); - else { - QRegExp re7(QString("map<const %1, %2, std::less<const %3>, %4\\s*>") - .arg(key, value, key, alloc)); - re7.setMinimal(true); - if (re7.indexIn(type) != -1) - type.replace(re7.cap(0), QString("map<const %1, %2>").arg(key, value)); - } - } - } - type.replace('@', '*'); - type.replace(QLatin1String(" >"), QString(QLatin1Char('>'))); - return type; -} - -void tst_Dumpers::niceType() -{ - // cf. watchutils.cpp - QFETCH(QString, input); - QFETCH(QString, simplified); - QCOMPARE(::niceType(input), simplified); -} - -void tst_Dumpers::niceType_data() +struct Pointer : Value { - QTest::addColumn<QString>("input"); - QTest::addColumn<QString>("simplified"); - - QTest::newRow("list") - << "std::list<int, std::allocator<int> >" - << "std::list<int>"; - - QTest::newRow("combined") - << "std::vector<std::list<int, std::allocator<int> >*, " - "std::allocator<std::list<int, std::allocator<int> >*> >" - << "std::vector<std::list<int>*>"; - - QTest::newRow("stack") - << "std::stack<int, std::deque<int, std::allocator<int> > >" - << "std::stack<int>"; - - QTest::newRow("map") - << "std::map<myns::QString, Foo, std::less<myns::QString>, " - "std::allocator<std::pair<const myns::QString, Foo> > >" - << "std::map<myns::QString, Foo>"; - - QTest::newRow("map2") - << "std::map<const char*, Foo, std::less<const char*>, " - "std::allocator<std::pair<const char* const, Foo> > >" - << "std::map<const char*, Foo>"; -} - -// -// Dumpers -// + Pointer() { hasPtrSuffix = true; } + Pointer(const QByteArray &value) : Value(value) { hasPtrSuffix = true; } +}; -static void testDumper(QByteArray expected0, const void *data, QByteArray outertype, - bool dumpChildren, QByteArray innertype = "", QByteArray exp = "", - int extraInt0 = 0, int extraInt1 = 0, int extraInt2 = 0, int extraInt3 = 0) -{ - sprintf(xDumpInBuffer, "%s%c%s%c%s%c%s%c%s%c", - outertype.data(), 0, "iname", 0, exp.data(), 0, - innertype.data(), 0, "iname", 0); - //qDebug() << "FIXME qDumpObjectData440 signature to use const void *"; - void *res = qDumpObjectData440(2, 42, data, dumpChildren, - extraInt0, extraInt1, extraInt2, extraInt3); - QString expected(expected0); - char buf[100]; - sprintf(buf, pointerPrintFormat(), (quintptr)data); - if ((!expected.startsWith('t') && !expected.startsWith('f')) - || expected.startsWith("type")) - expected = "tiname='$I',addr='$A'," + expected; - expected.replace("$I", "iname"); - expected.replace("$T", QByteArray(outertype)); - expected.replace("$A", QByteArray(buf)); - expected.replace('\'', '"'); - QString actual____ = QString::fromLatin1(xDumpOutBuffer); - actual____.replace('\'', '"'); - QCOMPARE(res, xDumpOutBuffer); - if (actual____ != expected) { - QStringList l1 = actual____.split(","); - QStringList l2 = expected.split(","); - for (int i = 0; i < l1.size() && i < l2.size(); ++i) { - if (l1.at(i) == l2.at(i)) - qWarning() << "== " << l1.at(i); - else - //qWarning() << "!= " << l1.at(i).right(30) << l2.at(i).right(30); - qWarning() << "!= " << l1.at(i) << l2.at(i); - } - if (l1.size() != l2.size()) - qWarning() << "!= size: " << l1.size() << l2.size(); +struct Type +{ + Type() + {} + Type(const char *str) + : type(str) + {} + Type(const QByteArray &ba) + : type(ba) + {} + bool matches(const QByteArray &actualType0, const QByteArray &nameSpace) const + { + QByteArray actualType = actualType0; + actualType.replace(' ', ""); + QByteArray expectedType = type; + expectedType.replace(' ', ""); + expectedType.replace('@', nameSpace); + return actualType == expectedType; } - QCOMPARE(actual____, expected); -} - -QByteArray str(const void *p) -{ - char buf[100]; - sprintf(buf, pointerPrintFormat(), (quintptr)p); - return buf; -} + QByteArray type; +}; -static const void *deref(const void *p) +struct Deque : Type { - return *reinterpret_cast<const char* const*>(p); -} + Deque(const QByteArray &inner) + : Type("std::deque<" + inner + ", std::allocator<" + inner + ">>") + {} +}; -void tst_Dumpers::dumperCompatibility() +struct Check { - // Ensure that no arbitrary padding is introduced by QVectorTypedData. - const size_t qVectorDataSize = 16; - QCOMPARE(sizeof(QVectorData), qVectorDataSize); - QVectorTypedData<int> *v = 0; - QCOMPARE(size_t(&v->array), qVectorDataSize); -} + Check() {} -static const QByteArray utfToBase64(const QString &string) -{ - return QByteArray(reinterpret_cast<const char *>(string.utf16()), 2 * string.size()).toBase64(); -} + Check(const QByteArray &iname, const Value &value, + const Type &type) + : iname(iname), expectedName(nameFromIName(iname)), + expectedValue(value), expectedType(type) + {} -static const char *boolToVal(bool b) -{ - return b ? "'true'" : "'false'"; -} + Check(const QByteArray &iname, const QByteArray &name, + const Value &value, const Type &type) + : iname(iname), expectedName(name), + expectedValue(value), expectedType(type) + {} -static const QByteArray ptrToBa(const void *p, bool symbolicNull = true) -{ - return QByteArray().append(p == 0 && symbolicNull ? - "<null>" : - QByteArray("0x") + QByteArray::number((quintptr) p, 16)); -} + QByteArray iname; + QByteArray expectedName; + Value expectedValue; + Type expectedType; +}; -static const QByteArray generateQStringSpec(const QString &str, bool isNull = false) +struct CheckType : public Check { - if (isNull) - return QByteArray("value='IiIgKG51bGwp',valueencoded='5'," - "type='" NS "QString',numchild='0'"); - return - QByteArray("value='%',valueencoded='2',type='" NS "QString',numchild='0'") - << utfToBase64(str); -} + CheckType(const QByteArray &iname, const QByteArray &name, + const Type &type) + : Check(iname, name, noValue, type) + {} -static const QByteArray generateQCharSpec(const QChar& ch) -{ - return QByteArray("value='%',valueencoded='2',type='" NS "QChar',numchild='0'") - << utfToBase64(QString(QLatin1String("'%1' (%2, 0x%3)")). - arg(ch).arg(ch.unicode()).arg(ch.unicode(), 0, 16)); -} + CheckType(const QByteArray &iname, const Type &type) + : Check(iname, noValue, type) + {} +}; -static const QByteArray generateBoolSpec(bool b) +struct Profile { - return QByteArray("value=%,type='bool',numchild='0'") - << boolToVal(b); -} + Profile(const QByteArray &contents) : contents(contents) {} -static const QByteArray generateLongSpec(long n) -{ - return QByteArray("value='%',type='long',numchild='0'") - << N(qlonglong(n)); -} + QByteArray contents; +}; -static const QByteArray generateIntSpec(int n) +struct GuiProfile : public Profile { - return QByteArray("value='%',type='int',numchild='0'") - << N(n); -} + GuiProfile() : Profile("QT+=gui\ngreaterThan(QT_MAJOR_VERSION, 4):QT *= widgets\n") {} +}; -const QByteArray createExp(const void *ptr, - const QByteArray &type, const QByteArray &method) +struct Cxx11Profile : public Profile { - return QByteArray("exp='((" NSX "%" NSY "*)%)->%'") - << type << ptrToBa(ptr) << method; -} + //Cxx11Profile() : Profile("CONFIG += c++11") {} + Cxx11Profile() : Profile("QMAKE_CXXFLAGS += -std=c++0x") {} +}; -// Helper functions. +struct ForceC {}; -template <typename T> static const char *typeToString() -{ - return "<unknown type>"; -} -template <typename T> const QByteArray valToString(const T &) -{ - return "<unknown value>"; -} -template <> const QByteArray valToString(const int &n) +class Data { - return QByteArray().append(N(n)); -} -template <> const QByteArray valToString(const QString &s) -{ - return QByteArray(utfToBase64(s)).append("',valueencoded='2"); -} -template <> const QByteArray valToString(int * const &p) -{ - return ptrToBa(p); -} -template <typename T> const QByteArray derefValToString(const T &v) -{ - return valToString(v); -} -template <> const QByteArray derefValToString(int * const &ptr) -{ - return valToString(*ptr); -} -const QString stripPtrType(const QString &ptrTypeStr) -{ - return ptrTypeStr.mid(0, ptrTypeStr.size() - 2); -} -template <> const char *typeToString<int>() -{ - return "int"; -} -template <> const char *typeToString<QString>() -{ - return NS"QString"; -} -template <> const char *typeToString<int *>() -{ - return "int *"; -} -template <typename T> bool isSimpleType() -{ - return false; -} -template <> bool isSimpleType<int>() -{ - return true; -} -template <typename T> bool isPointer() -{ - return false; -} -template <> bool isPointer<int *>() -{ - return true; -} - -template <typename T> static const char *typeToNumchild() -{ - return "1"; -} -template <> const char *typeToNumchild<int>() -{ - return "0"; -} -template <> const char *typeToNumchild<QString>() -{ - return "0"; -} -template <typename K, typename V> -QByteArray getMapType() -{ - return QByteArray(typeToString<K>()) + "@" + QByteArray(typeToString<V>()); -} -template <typename K, typename V> -void getMapNodeParams(size_t &nodeSize, size_t &valOffset) -{ -#if QT_VERSION >= 0x040500 - typedef QMapNode<K, V> NodeType; - NodeType *node = 0; - nodeSize = sizeof(NodeType); - valOffset = size_t(&node->value); -#else - nodeSize = sizeof(K) + sizeof(V) + 2*sizeof(void *); - valOffset = sizeof(K); -#endif -} +public: + Data() {} + Data(const QByteArray &code) : code(code), forceC(false) {} -void tst_Dumpers::dumpQAbstractItemHelper(QModelIndex &index) -{ - const QAbstractItemModel *model = index.model(); - const QString &rowStr = N(index.row()); - const QString &colStr = N(index.column()); - const QByteArray &internalPtrStrSymbolic = ptrToBa(index.internalPointer()); - const QByteArray &internalPtrStrValue = ptrToBa(index.internalPointer(), false); - const QByteArray &modelPtrStr = ptrToBa(model); - QByteArray indexSpecSymbolic = QByteArray().append(rowStr + "," + colStr + ","). - append(internalPtrStrSymbolic + "," + modelPtrStr); - QByteArray indexSpecValue = QByteArray().append(rowStr + "," + colStr + ","). - append(internalPtrStrValue + "," + modelPtrStr); - QByteArray expected = QByteArray("tiname='iname',addr='").append(ptrToBa(&index)). - append("',type='" NS "QAbstractItem',addr='$").append(indexSpecSymbolic). - append("',value='").append(valToString(model->data(index).toString())). - append("',numchild='%',children=["); - int rowCount = model->rowCount(index); - int columnCount = model->columnCount(index); - expected <<= N(rowCount * columnCount); - for (int row = 0; row < rowCount; ++row) { - for (int col = 0; col < columnCount; ++col) { - const QModelIndex &childIndex = model->index(row, col, index); - expected.append("{name='[").append(valToString(row)).append(","). - append(N(col)).append("]',numchild='%',addr='$"). - append(N(childIndex.row())).append(","). - append(N(childIndex.column())).append(","). - append(ptrToBa(childIndex.internalPointer())).append(","). - append(modelPtrStr).append("',type='" NS "QAbstractItem',value='"). - append(valToString(model->data(childIndex).toString())).append("'}"); - expected <<= N(model->rowCount(childIndex) - * model->columnCount(childIndex)); - if (col < columnCount - 1 || row < rowCount - 1) - expected.append(","); - } - } - expected.append("]"); - testDumper(expected, &index, NS"QAbstractItem", true, indexSpecValue); -} + Data(const QByteArray &includes, const QByteArray &code) + : includes(includes), code(code), forceC(false) + {} -void tst_Dumpers::dumpQAbstractItemAndModelIndex() -{ - class PseudoTreeItemModel : public QAbstractItemModel + const Data &operator%(const Check &check) const { - public: - PseudoTreeItemModel() : QAbstractItemModel(), parent1(0), - parent1Child(1), parent2(10), parent2Child1(11), parent2Child2(12) - {} - - int columnCount(const QModelIndex &parent = QModelIndex()) const - { - Q_UNUSED(parent); - return 1; - } - - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const - { - return !index.isValid() || role != Qt::DisplayRole ? - QVariant() : *static_cast<int *>(index.internalPointer()); - } - - QModelIndex index(int row, int column, - const QModelIndex & parent = QModelIndex()) const - { - QModelIndex index; - if (column == 0) { - if (!parent.isValid()) { - if (row == 0) - index = createIndex(row, column, &parent1); - else if (row == 1) - index = createIndex(row, column, &parent2); - } else if (parent.internalPointer() == &parent1 && row == 0) { - index = createIndex(row, column, &parent1Child); - } else if (parent.internalPointer() == &parent2) { - index = createIndex(row, column, - row == 0 ? &parent2Child1 : &parent2Child2); - } - } - return index; - } - - QModelIndex parent(const QModelIndex & index) const - { - QModelIndex parent; - if (index.isValid()) { - if (index.internalPointer() == &parent1Child) - parent = createIndex(0, 0, &parent1); - else if (index.internalPointer() == &parent2Child1 || - index.internalPointer() == &parent2Child2) - parent = createIndex(1, 0, &parent2); - } - return parent; - } - - int rowCount(const QModelIndex &parent = QModelIndex()) const - { - int rowCount; - if (!parent.isValid() || parent.internalPointer() == &parent2) - rowCount = 2; - else if (parent.internalPointer() == &parent1) - rowCount = 1; - else - rowCount = 0; - return rowCount; - } - - private: - mutable int parent1; - mutable int parent1Child; - mutable int parent2; - mutable int parent2Child1; - mutable int parent2Child2; - }; - - PseudoTreeItemModel m2; - - // Case 1: ModelIndex with no children. - QStringListModel m(QStringList() << "item1" << "item2" << "item3"); - QModelIndex index = m.index(2, 0); - - testDumper(QByteArray("type='$T',value='(2, 0)',numchild='5',children=[" - "{name='row',value='2',type='int',numchild='0'}," - "{name='column',value='0',type='int',numchild='0'}," - "{name='parent',value='<invalid>',exp='(('$T'*)$A)->parent()'," - "type='$T',numchild='1'}," - "{name='internalId',%}," - "{name='model',value='%',type='" NS "QAbstractItemModel*'," - "numchild='1'}]") - << generateQStringSpec(N(index.internalId())) - << ptrToBa(&m), - &index, NS"QModelIndex", true); - - // Case 2: ModelIndex with one child. - QModelIndex index2 = m2.index(0, 0); - dumpQAbstractItemHelper(index2); - - qDebug() << "FIXME: invalid indices should not have children"; - testDumper(QByteArray("type='$T',value='(0, 0)',numchild='5',children=[" - "{name='row',value='0',type='int',numchild='0'}," - "{name='column',value='0',type='int',numchild='0'}," - "{name='parent',value='<invalid>',exp='(('$T'*)$A)->parent()'," - "type='$T',numchild='1'}," - "{name='internalId',%}," - "{name='model',value='%',type='" NS "QAbstractItemModel*'," - "numchild='1'}]") - << generateQStringSpec(N(index2.internalId())) - << ptrToBa(&m2), - &index2, NS"QModelIndex", true); - - - // Case 3: ModelIndex with two children. - QModelIndex index3 = m2.index(1, 0); - dumpQAbstractItemHelper(index3); - - testDumper(QByteArray("type='$T',value='(1, 0)',numchild='5',children=[" - "{name='row',value='1',type='int',numchild='0'}," - "{name='column',value='0',type='int',numchild='0'}," - "{name='parent',value='<invalid>',exp='(('$T'*)$A)->parent()'," - "type='$T',numchild='1'}," - "{name='internalId',%}," - "{name='model',value='%',type='" NS "QAbstractItemModel*'," - "numchild='1'}]") - << generateQStringSpec(N(index3.internalId())) - << ptrToBa(&m2), - &index3, NS"QModelIndex", true); - - - // Case 4: ModelIndex with a parent. - index = m2.index(0, 0, index3); - testDumper(QByteArray("type='$T',value='(0, 0)',numchild='5',children=[" - "{name='row',value='0',type='int',numchild='0'}," - "{name='column',value='0',type='int',numchild='0'}," - "{name='parent',value='(1, 0)',exp='(('$T'*)$A)->parent()'," - "type='$T',numchild='1'}," - "{name='internalId',%}," - "{name='model',value='%',type='" NS "QAbstractItemModel*'," - "numchild='1'}]") - << generateQStringSpec(N(index.internalId())) - << ptrToBa(&m2), - &index, NS"QModelIndex", true); - - - // Case 5: Empty ModelIndex - QModelIndex index4; - testDumper("type='$T',value='<invalid>',numchild='0'", - &index4, NS"QModelIndex", true); -} - -void tst_Dumpers::dumpQAbstractItemModelHelper(QAbstractItemModel &m) -{ - QByteArray address = ptrToBa(&m); - QByteArray expected = QByteArray("tiname='iname',addr='%'," - "type='" NS "QAbstractItemModel',value='(%,%)',numchild='1',children=[" - "{numchild='1',name='" NS "QObject',addr='%',value='%'," - "valueencoded='2',type='" NS "QObject',displayedtype='%'}") - << address - << N(m.rowCount()) - << N(m.columnCount()) - << address - << utfToBase64(m.objectName()) - << m.metaObject()->className(); - - for (int row = 0; row < m.rowCount(); ++row) { - for (int column = 0; column < m.columnCount(); ++column) { - QModelIndex mi = m.index(row, column); - expected.append(QByteArray(",{name='[%,%]',value='%'," - "valueencoded='2',numchild='%',addr='$%,%,%,%'," - "type='" NS "QAbstractItem'}") - << N(row) - << N(column) - << utfToBase64(m.data(mi).toString()) - << N(row * column) - << N(mi.row()) - << N(mi.column()) - << ptrToBa(mi.internalPointer()) - << ptrToBa(mi.model())); - } + checks.insert("local." + check.iname, check); + return *this; } - expected.append("]"); - testDumper(expected, &m, NS"QAbstractItemModel", true); -} - -void tst_Dumpers::dumpQAbstractItemModel() -{ - // Case 1: No rows, one column. - QStringList strList; - QStringListModel model(strList); - dumpQAbstractItemModelHelper(model); - - // Case 2: One row, one column. - strList << "String 1"; - model.setStringList(strList); - dumpQAbstractItemModelHelper(model); - - // Case 3: Two rows, one column. - strList << "String 2"; - model.setStringList(strList); - dumpQAbstractItemModelHelper(model); - - // Case 4: No rows, two columns. - QStandardItemModel model2(0, 2); - dumpQAbstractItemModelHelper(model2); - - // Case 5: One row, two columns. - QStandardItem item1("Item (0,0)"); - QStandardItem item2("(Item (0,1)"); - model2.appendRow(QList<QStandardItem *>() << &item1 << &item2); - dumpQAbstractItemModelHelper(model2); - - // Case 6: Two rows, two columns - QStandardItem item3("Item (1,0"); - QStandardItem item4("Item (1,1)"); - model2.appendRow(QList<QStandardItem *>() << &item3 << &item4); - dumpQAbstractItemModelHelper(model); -} - -void tst_Dumpers::dumpQByteArray() -{ - // Case 1: Empty object. - QByteArray ba; - testDumper("value='',valueencoded='1',type='" NS "QByteArray',numchild='0'," - "childtype='char',childnumchild='0',children=[]", - &ba, NS"QByteArray", true); - - // Case 2: One element. - ba.append('a'); - testDumper("value='YQ==',valueencoded='1',type='" NS "QByteArray',numchild='1'," - "childtype='char',childnumchild='0',children=[{value='61 (97 'a')'}]", - &ba, NS"QByteArray", true); - - // Case 3: Two elements. - ba.append('b'); - testDumper("value='YWI=',valueencoded='1',type='" NS "QByteArray',numchild='2'," - "childtype='char',childnumchild='0',children=[" - "{value='61 (97 'a')'},{value='62 (98 'b')'}]", - &ba, NS"QByteArray", true); - - // Case 4: > 100 elements. - ba = QByteArray(101, 'a'); - QByteArray children; - for (int i = 0; i < 101; i++) - children.append("{value='61 (97 'a')'},"); - children.chop(1); - testDumper(QByteArray("value='YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh" - "YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh" - "YWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ== <size: 101, cut...>'," - "valueencoded='1',type='" NS "QByteArray',numchild='101'," - "childtype='char',childnumchild='0',children=[%]") << children, - &ba, NS"QByteArray", true); - - // Case 5: Regular and special characters and the replacement character. - ba = QByteArray("abc\a\n\r\033\'\"?"); - testDumper("value='YWJjBwoNGyciPw==',valueencoded='1',type='" NS "QByteArray'," - "numchild='10',childtype='char',childnumchild='0',children=[" - "{value='61 (97 'a')'},{value='62 (98 'b')'}," - "{value='63 (99 'c')'},{value='07 (7 '?')'}," - "{value='0a (10 '?')'},{value='0d (13 '?')'}," - "{value='1b (27 '?')'},{value='27 (39 '?')'}," - "{value='22 (34 '?')'},{value='3f (63 '?')'}]", - &ba, NS"QByteArray", true); -} - -void tst_Dumpers::dumpQChar() -{ - // Case 1: Printable ASCII character. - QChar c('X'); - testDumper("value=''X', ucs=88',numchild='0'", - &c, NS"QChar", false); - - // Case 2: Printable non-ASCII character. - c = QChar(0x600); - testDumper("value=''?', ucs=1536',numchild='0'", - &c, NS"QChar", false); - - // Case 3: Non-printable ASCII character. - c = QChar::fromAscii('\a'); - testDumper("value=''?', ucs=7',numchild='0'", - &c, NS"QChar", false); - - // Case 4: Non-printable non-ASCII character. - c = QChar(0x9f); - testDumper("value=''?', ucs=159',numchild='0'", - &c, NS"QChar", false); - - // Case 5: Printable ASCII Character that looks like the replacement character. - c = QChar::fromAscii('?'); - testDumper("value=''?', ucs=63',numchild='0'", - &c, NS"QChar", false); -} - -void tst_Dumpers::dumpQDateTime() -{ - // Case 1: Null object. - QDateTime d; - testDumper("value='(null)',type='$T',numchild='0'", - &d, NS"QDateTime", true); - - // Case 2: Non-null object. - d = QDateTime::currentDateTime(); - testDumper(QByteArray("value='%',valueencoded='2'," - "type='$T',numchild='1',children=[" - "{name='toTime_t',%}," - "{name='toString',%}," - "{name='toString_(ISO)',%}," - "{name='toString_(SystemLocale)',%}," - "{name='toString_(Locale)',%}]") - << utfToBase64(d.toString()) - << generateLongSpec((d.toTime_t())) - << generateQStringSpec(d.toString()) - << generateQStringSpec(d.toString(Qt::ISODate)) - << generateQStringSpec(d.toString(Qt::SystemLocaleDate)) - << generateQStringSpec(d.toString(Qt::LocaleDate)), - &d, NS"QDateTime", true); - -} - -void tst_Dumpers::dumpQDir() -{ - // Case 1: Current working directory. - QDir dir = QDir::current(); - testDumper(QByteArray("value='%',valueencoded='2',type='" NS "QDir',numchild='3'," - "children=[{name='absolutePath',%},{name='canonicalPath',%}]") - << utfToBase64(dir.absolutePath()) - << generateQStringSpec(dir.absolutePath()) - << generateQStringSpec(dir.canonicalPath()), - &dir, NS"QDir", true); - - // Case 2: Root directory. - dir = QDir::root(); - testDumper(QByteArray("value='%',valueencoded='2',type='" NS "QDir',numchild='3'," - "children=[{name='absolutePath',%},{name='canonicalPath',%}]") - << utfToBase64(dir.absolutePath()) - << generateQStringSpec(dir.absolutePath()) - << generateQStringSpec(dir.canonicalPath()), - &dir, NS"QDir", true); -} - - -void tst_Dumpers::dumpQFile() -{ - // Case 1: Empty file name => Does not exist. - QFile file1(""); - testDumper(QByteArray("value='',valueencoded='2',type='$T',numchild='2'," - "children=[{name='fileName',value='',valueencoded='2',type='" NS "QString'," - "numchild='0'}," - "{name='exists',value='false',type='bool',numchild='0'}]"), - &file1, NS"QFile", true); - - // Case 2: File that is known to exist. - QTemporaryFile file2; - file2.open(); - testDumper(QByteArray("value='%',valueencoded='2',type='$T',numchild='2'," - "children=[{name='fileName',value='%',valueencoded='2',type='" NS "QString'," - "numchild='0'}," - "{name='exists',value='true',type='bool',numchild='0'}]") - << utfToBase64(file2.fileName()) << utfToBase64(file2.fileName()), - &file2, NS"QFile", true); - - // Case 3: File with a name that most likely does not exist. - QFile file3("jfjfdskjdflsdfjfdls"); - testDumper(QByteArray("value='%',valueencoded='2',type='$T',numchild='2'," - "children=[{name='fileName',value='%',valueencoded='2',type='" NS "QString'," - "numchild='0'}," - "{name='exists',value='false',type='bool',numchild='0'}]") - << utfToBase64(file3.fileName()) << utfToBase64(file3.fileName()), - &file3, NS"QFile", true); -} - -void tst_Dumpers::dumpQFileInfo() -{ - QFileInfo fi("."); - QByteArray expected("value='%',valueencoded='2',type='$T',numchild='3'," - "children=[" - "{name='absolutePath',%}," - "{name='absoluteFilePath',%}," - "{name='canonicalPath',%}," - "{name='canonicalFilePath',%}," - "{name='completeBaseName',%}," - "{name='completeSuffix',%}," - "{name='baseName',%}," -#ifdef QX - "{name='isBundle',%}," - "{name='bundleName',%}," -#endif - "{name='fileName',%}," - "{name='filePath',%}," - "{name='group',%}," - "{name='owner',%}," - "{name='path',%}," - "{name='groupid',%}," - "{name='ownerid',%}," - "{name='permissions',value=' ',type='%',numchild='10'," - "children=[{name='ReadOwner',%},{name='WriteOwner',%}," - "{name='ExeOwner',%},{name='ReadUser',%},{name='WriteUser',%}," - "{name='ExeUser',%},{name='ReadGroup',%},{name='WriteGroup',%}," - "{name='ExeGroup',%},{name='ReadOther',%},{name='WriteOther',%}," - "{name='ExeOther',%}]}," - "{name='caching',%}," - "{name='exists',%}," - "{name='isAbsolute',%}," - "{name='isDir',%}," - "{name='isExecutable',%}," - "{name='isFile',%}," - "{name='isHidden',%}," - "{name='isReadable',%}," - "{name='isRelative',%}," - "{name='isRoot',%}," - "{name='isSymLink',%}," - "{name='isWritable',%}," - "{name='created',value='%',valueencoded='2',%," - "type='" NS "QDateTime',numchild='1'}," - "{name='lastModified',value='%',valueencoded='2',%," - "type='" NS "QDateTime',numchild='1'}," - "{name='lastRead',value='%',valueencoded='2',%," - "type='" NS "QDateTime',numchild='1'}]"); - expected <<= utfToBase64(fi.filePath()); - expected <<= generateQStringSpec(fi.absolutePath()); - expected <<= generateQStringSpec(fi.absoluteFilePath()); - expected <<= generateQStringSpec(fi.canonicalPath()); - expected <<= generateQStringSpec(fi.canonicalFilePath()); - expected <<= generateQStringSpec(fi.completeBaseName()); - expected <<= generateQStringSpec(fi.completeSuffix(), true); - expected <<= generateQStringSpec(fi.baseName()); -#ifdef Q_OS_MACX - expected <<= generateBoolSpec(fi.isBundle()); - expected <<= generateQStringSpec(fi.bundleName()); -#endif - expected <<= generateQStringSpec(fi.fileName()); - expected <<= generateQStringSpec(fi.filePath()); - expected <<= generateQStringSpec(fi.group()); - expected <<= generateQStringSpec(fi.owner()); - expected <<= generateQStringSpec(fi.path()); - expected <<= generateLongSpec(fi.groupId()); - expected <<= generateLongSpec(fi.ownerId()); - QFile::Permissions perms = fi.permissions(); - expected <<= QByteArray(NS"QFile::Permissions"); - expected <<= generateBoolSpec((perms & QFile::ReadOwner) != 0); - expected <<= generateBoolSpec((perms & QFile::WriteOwner) != 0); - expected <<= generateBoolSpec((perms & QFile::ExeOwner) != 0); - expected <<= generateBoolSpec((perms & QFile::ReadUser) != 0); - expected <<= generateBoolSpec((perms & QFile::WriteUser) != 0); - expected <<= generateBoolSpec((perms & QFile::ExeUser) != 0); - expected <<= generateBoolSpec((perms & QFile::ReadGroup) != 0); - expected <<= generateBoolSpec((perms & QFile::WriteGroup) != 0); - expected <<= generateBoolSpec((perms & QFile::ExeGroup) != 0); - expected <<= generateBoolSpec((perms & QFile::ReadOther) != 0); - expected <<= generateBoolSpec((perms & QFile::WriteOther) != 0); - expected <<= generateBoolSpec((perms & QFile::ExeOther) != 0); - expected <<= generateBoolSpec(fi.caching()); - expected <<= generateBoolSpec(fi.exists()); - expected <<= generateBoolSpec(fi.isAbsolute()); - expected <<= generateBoolSpec(fi.isDir()); - expected <<= generateBoolSpec(fi.isExecutable()); - expected <<= generateBoolSpec(fi.isFile()); - expected <<= generateBoolSpec(fi.isHidden()); - expected <<= generateBoolSpec(fi.isReadable()); - expected <<= generateBoolSpec(fi.isRelative()); - expected <<= generateBoolSpec(fi.isRoot()); - expected <<= generateBoolSpec(fi.isSymLink()); - expected <<= generateBoolSpec(fi.isWritable()); - expected <<= utfToBase64(fi.created().toString()); - expected <<= createExp(&fi, "QFileInfo", "created()"); - expected <<= utfToBase64(fi.lastModified().toString()); - expected <<= createExp(&fi, "QFileInfo", "lastModified()"); - expected <<= utfToBase64(fi.lastRead().toString()); - expected <<= createExp(&fi, "QFileInfo", "lastRead()"); - - testDumper(expected, &fi, NS"QFileInfo", true); -} - -void tst_Dumpers::dumpQHash() -{ - QHash<QString, QList<int> > hash; - hash.insert("Hallo", QList<int>()); - hash.insert("Welt", QList<int>() << 1); - hash.insert("!", QList<int>() << 1 << 2); - hash.insert("!", QList<int>() << 1 << 2); -} - -template <typename K, typename V> -void tst_Dumpers::dumpQHashNodeHelper(QHash<K, V> &hash) -{ - typename QHash<K, V>::iterator it = hash.begin(); - typedef QHashNode<K, V> HashNode; - HashNode *dummy = 0; - HashNode *node = - reinterpret_cast<HashNode *>(reinterpret_cast<char *>(const_cast<K *>(&it.key())) - - size_t(&dummy->key)); - const K &key = it.key(); - const V &val = it.value(); - QByteArray expected("value='"); - if (isSimpleType<V>()) - expected.append(valToString(val)); - expected.append("',numchild='2',children=[{name='key',type='"). - append(typeToString<K>()).append("',addr='").append(ptrToBa(&key)). - append("'},{name='value',type='").append(typeToString<V>()). - append("',addr='").append(ptrToBa(&val)).append("'}]"); - testDumper(expected, node, NS"QHashNode", true, - getMapType<K, V>(), "", sizeof(it.key()), sizeof(it.value())); -} - -void tst_Dumpers::dumpQHashNode() -{ - // Case 1: simple type -> simple type. - QHash<int, int> hash1; - hash1[2] = 3; - dumpQHashNodeHelper(hash1); - - // Case 2: simple type -> composite type. - QHash<int, QString> hash2; - hash2[5] = "String 7"; - dumpQHashNodeHelper(hash2); - - // Case 3: composite type -> simple type - QHash<QString, int> hash3; - hash3["String 11"] = 13; - dumpQHashNodeHelper(hash3); - - // Case 4: composite type -> composite type - QHash<QString, QString> hash4; - hash4["String 17"] = "String 19"; - dumpQHashNodeHelper(hash4); -} - -void tst_Dumpers::dumpQImageHelper(const QImage &img) -{ - QByteArray expected = "value='(%x%)',type='" NS "QImage',numchild='0'" - << N(img.width()) - << N(img.height()); - testDumper(expected, &img, NS"QImage", true); -} - -void tst_Dumpers::dumpQImage() -{ - // Case 1: Null image. - QImage img; - dumpQImageHelper(img); - - // Case 2: Normal image. - img = QImage(3, 700, QImage::Format_RGB555); - dumpQImageHelper(img); - - // Case 3: Invalid image. - img = QImage(100, 0, QImage::Format_Invalid); - dumpQImageHelper(img); -} -void tst_Dumpers::dumpQImageDataHelper(QImage &img) -{ -#if QT_VERSION >= 0x050000 - QSKIP("QImage::numBytes deprecated"); -#else - const QByteArray ba(QByteArray::fromRawData((const char*) img.bits(), img.numBytes())); - QByteArray expected = QByteArray("tiname='$I',addr='$A',type='" NS "QImageData',"). - append("numchild='0',value='<hover here>',valuetooltipencoded='1',"). - append("valuetooltipsize='").append(N(ba.size())).append("',"). - append("valuetooltip='").append(ba.toBase64()).append("'"); - testDumper(expected, &img, NS"QImageData", false); -#endif -} - -void tst_Dumpers::dumpQImageData() -{ - // Case 1: Null image. - QImage img; - dumpQImageDataHelper(img); - - // Case 2: Normal image. - img = QImage(3, 700, QImage::Format_RGB555); - dumpQImageDataHelper(img); - - // Case 3: Invalid image. - img = QImage(100, 0, QImage::Format_Invalid); - dumpQImageDataHelper(img); -} - -template <typename T> - void tst_Dumpers::dumpQLinkedListHelper(QLinkedList<T> &l) -{ - const int size = qMin(l.size(), 1000); - const QString &sizeStr = N(size); - const QByteArray elemTypeStr = typeToString<T>(); - QByteArray expected = QByteArray("value='<").append(sizeStr). - append(" items>',valueeditable='false',numchild='").append(sizeStr). - append("',childtype='").append(elemTypeStr).append("',childnumchild='"). - append(typeToNumchild<T>()).append("',children=["); - typename QLinkedList<T>::const_iterator iter = l.constBegin(); - for (int i = 0; i < size; ++i, ++iter) { - expected.append("{"); - const T &curElem = *iter; - if (isPointer<T>()) { - const QString typeStr = stripPtrType(typeToString<T>()); - const QByteArray addrStr = valToString(curElem); - if (curElem != 0) { - expected.append("addr='").append(addrStr).append("',type='"). - append(typeStr).append("',value='"). - append(derefValToString(curElem)).append("'"); - } else { - expected.append("addr='").append(ptrToBa(&curElem)).append("',type='"). - append(typeStr).append("',value='<null>',numchild='0'"); - } - } else { - expected.append("addr='").append(ptrToBa(&curElem)). - append("',value='").append(valToString(curElem)).append("'"); - } - expected.append("}"); - if (i < size - 1) - expected.append(","); + const Data &operator%(const Profile &profile) const + { + profileExtra += profile.contents; + return *this; } - if (size < l.size()) - expected.append(",..."); - expected.append("]"); - testDumper(expected, &l, NS"QLinkedList", true, elemTypeStr); -} - -void tst_Dumpers::dumpQLinkedList() -{ - // Case 1: Simple element type. - QLinkedList<int> l; - - // Case 1.1: Empty list. - dumpQLinkedListHelper(l); - - // Case 1.2: One element. - l.append(2); - dumpQLinkedListHelper(l); - - // Case 1.3: Two elements - l.append(3); - dumpQLinkedListHelper(l); - - // Case 2: Composite element type. - QLinkedList<QString> l2; - // Case 2.1: Empty list. - dumpQLinkedListHelper(l2); - - // Case 2.2: One element. - l2.append("Teststring 1"); - dumpQLinkedListHelper(l2); - - // Case 2.3: Two elements. - l2.append("Teststring 2"); - dumpQLinkedListHelper(l2); - - // Case 2.4: > 1000 elements. - for (int i = 3; i <= 1002; ++i) - l2.append("Test " + N(i)); - - // Case 3: Pointer type. - QLinkedList<int *> l3; - l3.append(new int(5)); - l3.append(new int(7)); - l3.append(0); - dumpQLinkedListHelper(l3); -} - -# if 0 - void tst_Debugger::dumpQLinkedList() + const Data &operator%(const ForceC &) const { - // Case 1: Simple element type. - QLinkedList<int> l; - - // Case 1.1: Empty list. - testDumper("value='<0 items>',valueeditable='false',numchild='0'," - "childtype='int',childnumchild='0',children=[]", - &l, NS"QLinkedList", true, "int"); - - // Case 1.2: One element. - l.append(2); - testDumper("value='<1 items>',valueeditable='false',numchild='1'," - "childtype='int',childnumchild='0',children=[{addr='%',value='2'}]" - << ptrToBa(l.constBegin().operator->()), - &l, NS"QLinkedList", true, "int"); - - // Case 1.3: Two elements - l.append(3); - QByteArray it0 = ptrToBa(l.constBegin().operator->()); - QByteArray it1 = ptrToBa(l.constBegin().operator++().operator->()); - testDumper("value='<2 items>',valueeditable='false',numchild='2'," - "childtype='int',childnumchild='0',children=[{addr='%',value='2'}," - "{addr='%',value='3'}]" << it0 << it1, - &l, NS"QLinkedList", true, "int"); - - // Case 2: Composite element type. - QLinkedList<QString> l2; - QLinkedList<QString>::const_iterator iter; - - // Case 2.1: Empty list. - testDumper("value='<0 items>',valueeditable='false',numchild='0'," - "childtype='" NS "QString',childnumchild='0',children=[]", - &l2, NS"QLinkedList", true, NS"QString"); - - // Case 2.2: One element. - l2.append("Teststring 1"); - iter = l2.constBegin(); - qDebug() << *iter; - testDumper("value='<1 items>',valueeditable='false',numchild='1'," - "childtype='" NS "QString',childnumchild='0',children=[{addr='%',value='%',}]" - << ptrToBa(iter.operator->()) << utfToBase64(*iter), - &l2, NS"QLinkedList", true, NS"QString"); - - // Case 2.3: Two elements. - QByteArray expected = "value='<2 items>',valueeditable='false',numchild='2'," - "childtype='int',childnumchild='0',children=["; - iter = l2.constBegin(); - expected.append("{addr='%',%}," - << ptrToBa(iter.operator->()) << utfToBase64(*iter)); - ++iter; - expected.append("{addr='%',%}]" - << ptrToBa(iter.operator->()) << utfToBase64(*iter)); - testDumper(expected, - &l, NS"QLinkedList", true, NS"QString"); - - // Case 2.4: > 1000 elements. - for (int i = 3; i <= 1002; ++i) - l2.append("Test " + N(i)); - - expected = "value='<1002 items>',valueeditable='false'," - "numchild='1002',childtype='" NS "QString',childnumchild='0',children=['"; - iter = l2.constBegin(); - for (int i = 0; i < 1002; ++i, ++iter) - expected.append("{addr='%',value='%'}," - << ptrToBa(iter.operator->()) << utfToBase64(*iter)); - expected.append(",...]"); - testDumper(expected, &l, NS"QLinkedList", true, NS"QString"); - - - // Case 3: Pointer type. - QLinkedList<int *> l3; - l3.append(new int(5)); - l3.append(new int(7)); - l3.append(0); - //dumpQLinkedListHelper(l3); - testDumper("", &l, NS"QLinkedList", true, NS"QString"); + forceC = true; + return *this; } -# endif -void tst_Dumpers::dumpQList_int() -{ - QList<int> ilist; - testDumper("value='<0 items>',valueeditable='false',numchild='0'," - "internal='1',children=[]", - &ilist, NS"QList", true, "int"); - ilist.append(1); - ilist.append(2); - testDumper("value='<2 items>',valueeditable='false',numchild='2'," - "internal='1',childtype='int',childnumchild='0',children=[" - "{addr='" + str(&ilist.at(0)) + "',value='1'}," - "{addr='" + str(&ilist.at(1)) + "',value='2'}]", - &ilist, NS"QList", true, "int"); -} - -void tst_Dumpers::dumpQList_int_star() -{ - QList<int *> ilist; - testDumper("value='<0 items>',valueeditable='false',numchild='0'," - "internal='1',children=[]", - &ilist, NS"QList", true, "int*"); - ilist.append(new int(1)); - ilist.append(0); - testDumper("value='<2 items>',valueeditable='false',numchild='2'," - "internal='1',childtype='int*',childnumchild='1',children=[" - "{addr='" + str(deref(&ilist.at(0))) + - "',type='int',value='1'}," - "{value='<null>',numchild='0'}]", - &ilist, NS"QList", true, "int*"); -} - -void tst_Dumpers::dumpQList_char() -{ - QList<char> clist; - testDumper("value='<0 items>',valueeditable='false',numchild='0'," - "internal='1',children=[]", - &clist, NS"QList", true, "char"); - clist.append('a'); - clist.append('b'); - testDumper("value='<2 items>',valueeditable='false',numchild='2'," - "internal='1',childtype='char',childnumchild='0',children=[" - "{addr='" + str(&clist.at(0)) + "',value=''a', ascii=97'}," - "{addr='" + str(&clist.at(1)) + "',value=''b', ascii=98'}]", - &clist, NS"QList", true, "char"); -} - -void tst_Dumpers::dumpQList_QString() -{ - QList<QString> slist; - testDumper("value='<0 items>',valueeditable='false',numchild='0'," - "internal='1',children=[]", - &slist, NS"QList", true, NS"QString"); - slist.append("a"); - slist.append("b"); - testDumper("value='<2 items>',valueeditable='false',numchild='2'," - "internal='1',childtype='" NS "QString',childnumchild='0',children=[" - "{addr='" + str(&slist.at(0)) + "',value='YQA=',valueencoded='2'}," - "{addr='" + str(&slist.at(1)) + "',value='YgA=',valueencoded='2'}]", - &slist, NS"QList", true, NS"QString"); -} - -void tst_Dumpers::dumpQList_Int3() -{ - QList<Int3> i3list; - testDumper("value='<0 items>',valueeditable='false',numchild='0'," - "internal='0',children=[]", - &i3list, NS"QList", true, "Int3"); - i3list.append(Int3()); - i3list.append(Int3()); - testDumper("value='<2 items>',valueeditable='false',numchild='2'," - "internal='0',childtype='Int3',children=[" - "{addr='" + str(&i3list.at(0)) + "'}," - "{addr='" + str(&i3list.at(1)) + "'}]", - &i3list, NS"QList", true, "Int3"); -} - -void tst_Dumpers::dumpQList_QString3() -{ - QList<QString3> s3list; - testDumper("value='<0 items>',valueeditable='false',numchild='0'," - "internal='0',children=[]", - &s3list, NS"QList", true, "QString3"); - s3list.append(QString3()); - s3list.append(QString3()); - testDumper("value='<2 items>',valueeditable='false',numchild='2'," - "internal='0',childtype='QString3',children=[" - "{addr='" + str(&s3list.at(0)) + "'}," - "{addr='" + str(&s3list.at(1)) + "'}]", - &s3list, NS"QList", true, "QString3"); -} +public: + mutable QByteArray profileExtra; + QByteArray includes; + QByteArray code; + mutable bool forceC; + mutable QMap<QByteArray, Check> checks; +}; -void tst_Dumpers::dumpQLocaleHelper(QLocale &loc) -{ - QByteArray expected = QByteArray("value='%',type='$T',numchild='8'," - "children=[{name='country',%}," - "{name='language',%}," - "{name='measurementSystem',%}," - "{name='numberOptions',%}," - "{name='timeFormat_(short)',%}," - "{name='timeFormat_(long)',%}," - "{name='decimalPoint',%}," - "{name='exponential',%}," - "{name='percent',%}," - "{name='zeroDigit',%}," - "{name='groupSeparator',%}," - "{name='negativeSign',%}]") - << valToString(loc.name()) - << createExp(&loc, "QLocale", "country()") - << createExp(&loc, "QLocale", "language()") - << createExp(&loc, "QLocale", "measurementSystem()") - << createExp(&loc, "QLocale", "numberOptions()") - << generateQStringSpec(loc.timeFormat(QLocale::ShortFormat)) - << generateQStringSpec(loc.timeFormat()) - << generateQCharSpec(loc.decimalPoint()) - << generateQCharSpec(loc.exponential()) - << generateQCharSpec(loc.percent()) - << generateQCharSpec(loc.zeroDigit()) - << generateQCharSpec(loc.groupSeparator()) - << generateQCharSpec(loc.negativeSign()); - testDumper(expected, &loc, NS"QLocale", true); -} +Q_DECLARE_METATYPE(Data) -void tst_Dumpers::dumpQLocale() +class tst_Dumpers : public QObject { - QLocale english(QLocale::English); - dumpQLocaleHelper(english); - - QLocale german(QLocale::German); - dumpQLocaleHelper(german); + Q_OBJECT - QLocale chinese(QLocale::Chinese); - dumpQLocaleHelper(chinese); +public: + tst_Dumpers() {} - QLocale swahili(QLocale::Swahili); - dumpQLocaleHelper(swahili); -} +private slots: + void dumper(); + void dumper_data(); +}; -template <typename K, typename V> - void tst_Dumpers::dumpQMapHelper(QMap<K, V> &map) -{ - QByteArray sizeStr(valToString(map.size())); - size_t nodeSize; - size_t valOff; - getMapNodeParams<K, V>(nodeSize, valOff); - int transKeyOffset = static_cast<int>(2*sizeof(void *)) - static_cast<int>(nodeSize); - int transValOffset = transKeyOffset + valOff; - bool simpleKey = isSimpleType<K>(); - bool simpleVal = isSimpleType<V>(); - QByteArray expected = QByteArray("value='<").append(sizeStr).append(" items>',numchild='"). - append(sizeStr).append("',extra='simplekey: ").append(N(simpleKey)). - append(" isSimpleValue: ").append(N(simpleVal)). - append(" keyOffset: ").append(N(transKeyOffset)).append(" valueOffset: "). - append(N(transValOffset)).append(" mapnodesize: "). - append(N(qulonglong(nodeSize))).append("',children=["); // 64bit Linux hack - typedef typename QMap<K, V>::iterator mapIter; - for (mapIter it = map.begin(); it != map.end(); ++it) { - if (it != map.begin()) - expected.append(","); - const QByteArray keyString = - QByteArray(valToString(it.key())).replace("valueencoded","keyencoded"); - expected.append("{key='").append(keyString).append("',value='"). - append(valToString(it.value())).append("',"); - if (simpleKey && simpleVal) { - expected.append("type='").append(typeToString<V>()). - append("',addr='").append(ptrToBa(&it.value())).append("'"); - } else { - QByteArray keyTypeStr = typeToString<K>(); - QByteArray valTypeStr = typeToString<V>(); -#if QT_VERSION >= 0x040500 - QMapNode<K, V> *node = 0; - size_t backwardOffset = size_t(&node->backward) - valOff; - char *addr = reinterpret_cast<char *>(&(*it)) + backwardOffset; - expected.append("addr='").append(ptrToBa(addr)). - append("',type='" NS "QMapNode<").append(keyTypeStr).append(","). - append(valTypeStr).append(" >").append("'"); -#else - expected.append("type='" NS "QMapData::Node<").append(keyTypeStr). - append(",").append(valTypeStr).append(" >"). - append("',exp='*('" NS "QMapData::Node<").append(keyTypeStr). - append(",").append(valTypeStr).append(" >"). - append(" >'*)").append(ptrToBa(&(*it))).append("'"); -#endif +void tst_Dumpers::dumper() +{ + QFETCH(Data, data); + + bool ok; + QString cmd; + QByteArray output; + QByteArray error; + + QTemporaryDir buildDir(QLatin1String("qt_tst_dumpers_")); + const bool keepTemp = qgetenv("QTC_KEEP_TEMP").toInt(); + buildDir.setAutoRemove(!keepTemp); + //qDebug() << "Temp dir: " << buildDir.path(); + QVERIFY(!buildDir.path().isEmpty()); + + const char *mainFile = data.forceC ? "main.c" : "main.cpp"; + + QFile proFile(buildDir.path() + QLatin1String("/doit.pro")); + ok = proFile.open(QIODevice::ReadWrite); + QVERIFY(ok); + proFile.write("SOURCES = "); + proFile.write(mainFile); + proFile.write("\nTARGET = doit\n"); + proFile.write("QT -= widgets gui\n"); + proFile.write(data.profileExtra); + proFile.close(); + + QFile source(buildDir.path() + QLatin1Char('/') + QLatin1String(mainFile)); + ok = source.open(QIODevice::ReadWrite); + QVERIFY(ok); + source.write( + "\n\nvoid dummyStatement(void *first,...) { (void) first; }" + "\n\n" + data.includes + + "\n\nvoid stopper() {}" + "\n\nint main(int argc, char *argv[])" + "\n{" + "\n dummyStatement(&argc, &argv);\n" + "\n " + data.code + + "\n stopper();" + "\n return 0;" + "\n}\n"); + source.close(); + + QProcess qmake; + qmake.setWorkingDirectory(buildDir.path()); + cmd = QString::fromLatin1("qmake"); + //qDebug() << "Starting qmake: " << cmd; + qmake.start(cmd); + ok = qmake.waitForFinished(); + QVERIFY(ok); + output = qmake.readAllStandardOutput(); + error = qmake.readAllStandardError(); + //qDebug() << "stdout: " << output; + if (!error.isEmpty()) { qDebug() << error; QVERIFY(false); } + + QProcess make; + make.setWorkingDirectory(buildDir.path()); + cmd = QString::fromLatin1("make"); + //qDebug() << "Starting make: " << cmd; + make.start(cmd); + ok = make.waitForFinished(); + QVERIFY(ok); + output = make.readAllStandardOutput(); + error = make.readAllStandardError(); + //qDebug() << "stdout: " << output; + if (!error.isEmpty()) { qDebug() << error; QVERIFY(false); } + + QByteArray dumperDir = DUMPERDIR; + + QSet<QByteArray> expandedINames; + expandedINames.insert("local"); + foreach (const Check &check, data.checks) { + QByteArray parent = check.iname; + while (true) { + parent = parentIName(parent); + if (parent.isEmpty()) + break; + expandedINames.insert("local." + parent); } - expected.append("}"); } - expected.append("]"); - mapIter it = map.begin(); - testDumper(expected, *reinterpret_cast<QMapData **>(&it), NS"QMap", - true, getMapType<K,V>(), "", 0, 0, nodeSize, valOff); -} - -void tst_Dumpers::dumpQMap() -{ - qDebug() << "QMap<int, int>"; - // Case 1: Simple type -> simple type. - QMap<int, int> map1; - - // Case 1.1: Empty map. - dumpQMapHelper(map1); - - // Case 1.2: One element. - map1[2] = 3; - dumpQMapHelper(map1); - - // Case 1.3: Two elements. - map1[3] = 5; - dumpQMapHelper(map1); - - // Case 2: Simple type -> composite type. - qDebug() << "QMap<int, QString>"; - QMap<int, QString> map2; - - // Case 2.1: Empty Map. - dumpQMapHelper(map2); - - // Case 2.2: One element. - map2[5] = "String 7"; - dumpQMapHelper(map2); - - // Case 2.3: Two elements. - map2[7] = "String 11"; - dumpQMapHelper(map2); - - // Case 3: Composite type -> simple type. - qDebug() << "QMap<QString, int>"; - QMap<QString, int> map3; - - // Case 3.1: Empty map. - dumpQMapHelper(map3); - // Case 3.2: One element. - map3["String 13"] = 11; - dumpQMapHelper(map3); - - // Case 3.3: Two elements. - map3["String 17"] = 13; - dumpQMapHelper(map3); - - // Case 4: Composite type -> composite type. - QMap<QString, QString> map4; - - // Case 4.1: Empty map. - dumpQMapHelper(map4); - - // Case 4.2: One element. - map4["String 19"] = "String 23"; - dumpQMapHelper(map4); - - // Case 4.3: Two elements. - map4["String 29"] = "String 31"; - dumpQMapHelper(map4); - - // Case 4.4: Different value, same key (multimap functionality). - map4["String 29"] = "String 37"; - dumpQMapHelper(map4); -} - -template <typename K, typename V> - void tst_Dumpers::dumpQMapNodeHelper(QMap<K, V> &m) -{ - typename QMap<K, V>::iterator it = m.begin(); - const K &key = it.key(); - const V &val = it.value(); - //const char * const keyType = typeToString(key); - QByteArray expected = QByteArray("value='',numchild='2'," - "children=[{name='key',addr='").append(ptrToBa(&key)). - append("',type='").append(typeToString<K>()).append("',value='"). - append(valToString(key)).append("'},{name='value',addr='"). - append(ptrToBa(&val)).append("',type='").append(typeToString<V>()). - append("',value='").append(valToString(val)). - append("'}]"); - size_t nodeSize; - size_t valOffset; - getMapNodeParams<K, V>(nodeSize, valOffset); - testDumper(expected, *reinterpret_cast<QMapData **>(&it), NS"QMapNode", - true, getMapType<K,V>(), "", 0, 0, nodeSize, valOffset); -} - -void tst_Dumpers::dumpQMapNode() -{ - // Case 1: simple type -> simple type. - QMap<int, int> map; - map[2] = 3; - dumpQMapNodeHelper(map); - - // Case 2: simple type -> composite type. - QMap<int, QString> map2; - map2[3] = "String 5"; - dumpQMapNodeHelper(map2); - - // Case 3: composite type -> simple type. - QMap<QString, int> map3; - map3["String 7"] = 11; - dumpQMapNodeHelper(map3); - - // Case 4: composite type -> composite type. - QMap<QString, QString> map4; - map4["String 13"] = "String 17"; - dumpQMapNodeHelper(map4); -} - -#ifdef USE_PRIVATE -void tst_Dumpers::dumpQObject() -{ - QObject parent; - testDumper("value='',valueencoded='2',type='$T',displayedtype='QObject'," - "numchild='4'", - &parent, NS"QObject", false); - testDumper("value='',valueencoded='2',type='$T',displayedtype='QObject'," - "numchild='4',children=[" - "{name='properties',addr='$A',type='$TPropertyList'," - "value='<1 items>',numchild='1'}," - "{name='signals',addr='$A',type='$TSignalList'," - "value='<2 items>',numchild='2'}," - "{name='slots',addr='$A',type='$TSlotList'," - "value='<2 items>',numchild='2'}," - "{name='parent',value='0x0',type='$T *',numchild='0'}," - "{name='className',value='QObject',type='',numchild='0'}]", - &parent, NS"QObject", true); - -#if 0 - testDumper("numchild='2',value='<2 items>',type='QObjectSlotList'," - "children=[{name='2',value='deleteLater()'," - "numchild='0',addr='$A',type='QObjectSlot'}," - "{name='3',value='_q_reregisterTimers(void*)'," - "numchild='0',addr='$A',type='QObjectSlot'}]", - &parent, NS"QObjectSlotList", true); -#endif - - parent.setObjectName("A Parent"); - testDumper("value='QQAgAFAAYQByAGUAbgB0AA==',valueencoded='2',type='$T'," - "displayedtype='QObject',numchild='4'", - &parent, NS"QObject", false); - QObject child(&parent); - testDumper("value='',valueencoded='2',type='$T'," - "displayedtype='QObject',numchild='4'", - &child, NS"QObject", false); - child.setObjectName("A Child"); - QByteArray ba ="value='QQAgAEMAaABpAGwAZAA=',valueencoded='2',type='$T'," - "displayedtype='QObject',numchild='4',children=[" - "{name='properties',addr='$A',type='$TPropertyList'," - "value='<1 items>',numchild='1'}," - "{name='signals',addr='$A',type='$TSignalList'," - "value='<2 items>',numchild='2'}," - "{name='slots',addr='$A',type='$TSlotList'," - "value='<2 items>',numchild='2'}," - "{name='parent',addr='" + str(&parent) + "'," - "value='QQAgAFAAYQByAGUAbgB0AA==',valueencoded='2',type='$T'," - "displayedtype='QObject',numchild='1'}," - "{name='className',value='QObject',type='',numchild='0'}]"; - testDumper(ba, &child, NS"QObject", true); - connect(&child, SIGNAL(destroyed()), qApp, SLOT(quit())); - testDumper(ba, &child, NS"QObject", true); - disconnect(&child, SIGNAL(destroyed()), qApp, SLOT(quit())); - testDumper(ba, &child, NS"QObject", true); - child.setObjectName("A renamed Child"); - testDumper("value='QQAgAHIAZQBuAGEAbQBlAGQAIABDAGgAaQBsAGQA',valueencoded='2'," - "type='$T',displayedtype='QObject',numchild='4'", - &child, NS"QObject", false); -} - -void tst_Dumpers::dumpQObjectChildListHelper(QObject &o) -{ - const QObjectList children = o.children(); - const int size = children.size(); - const QString sizeStr = N(size); - QByteArray expected = QByteArray("numchild='").append(sizeStr).append("',value='<"). - append(sizeStr).append(" items>',type='" NS "QObjectChildList',children=["); - for (int i = 0; i < size; ++i) { - const QObject *child = children.at(i); - expected.append("{addr='").append(ptrToBa(child)).append("',value='"). - append(utfToBase64(child->objectName())). - append("',valueencoded='2',type='" NS "QObject',displayedtype='"). - append(child->metaObject()->className()).append("',numchild='1'}"); - if (i < size - 1) - expected.append(","); + QByteArray expanded; + foreach (const QByteArray &iname, expandedINames) { + if (!expanded.isEmpty()) + expanded.append(','); + expanded += iname; } - expected.append("]"); - testDumper(expected, &o, NS"QObjectChildList", true); -} - -void tst_Dumpers::dumpQObjectChildList() -{ - // Case 1: Object with no children. - QObject o; - dumpQObjectChildListHelper(o); - - // Case 2: Object with one child. - QObject o2(&o); - dumpQObjectChildListHelper(o); - // Case 3: Object with two children. - QObject o3(&o); - dumpQObjectChildListHelper(o); -} - -void tst_Dumpers::dumpQObjectMethodList() -{ - QStringListModel m; - testDumper("addr='<synthetic>',type='$T',numchild='24'," - "childtype='" NS "QMetaMethod::Method',childnumchild='0',children=[" - "{name='0 0 destroyed(QObject*)',value='<Signal> (1)'}," - "{name='1 1 destroyed()',value='<Signal> (1)'}," - "{name='2 2 deleteLater()',value='<Slot> (2)'}," - "{name='3 3 _q_reregisterTimers(void*)',value='<Slot> (2)'}," - "{name='4 4 dataChanged(QModelIndex,QModelIndex)',value='<Signal> (1)'}," - "{name='5 5 headerDataChanged(Qt::Orientation,int,int)',value='<Signal> (1)'}," - "{name='6 6 layoutChanged()',value='<Signal> (1)'}," - "{name='7 7 layoutAboutToBeChanged()',value='<Signal> (1)'}," - "{name='8 8 rowsAboutToBeInserted(QModelIndex,int,int)',value='<Signal> (1)'}," - "{name='9 9 rowsInserted(QModelIndex,int,int)',value='<Signal> (1)'}," - "{name='10 10 rowsAboutToBeRemoved(QModelIndex,int,int)',value='<Signal> (1)'}," - "{name='11 11 rowsRemoved(QModelIndex,int,int)',value='<Signal> (1)'}," - "{name='12 12 columnsAboutToBeInserted(QModelIndex,int,int)',value='<Signal> (1)'}," - "{name='13 13 columnsInserted(QModelIndex,int,int)',value='<Signal> (1)'}," - "{name='14 14 columnsAboutToBeRemoved(QModelIndex,int,int)',value='<Signal> (1)'}," - "{name='15 15 columnsRemoved(QModelIndex,int,int)',value='<Signal> (1)'}," - "{name='16 16 modelAboutToBeReset()',value='<Signal> (1)'}," - "{name='17 17 modelReset()',value='<Signal> (1)'}," - "{name='18 18 rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)',value='<Signal> (1)'}," - "{name='19 19 rowsMoved(QModelIndex,int,int,QModelIndex,int)',value='<Signal> (1)'}," - "{name='20 20 columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)',value='<Signal> (1)'}," - "{name='21 21 columnsMoved(QModelIndex,int,int,QModelIndex,int)',value='<Signal> (1)'}," - "{name='22 22 submit()',value='<Slot> (2)'}," - "{name='23 23 revert()',value='<Slot> (2)'}]", - &m, NS"QObjectMethodList", true); -} - -void tst_Dumpers::dumpQObjectPropertyList() -{ - // Case 1: Model without a parent. - QStringListModel m(QStringList() << "Test1" << "Test2"); - testDumper("addr='<synthetic>',type='$T',numchild='1',value='<1 items>'," - "children=[{name='objectName',type='QString',value=''," - "valueencoded='2',numchild='0'}]", - &m, NS"QObjectPropertyList", true); - - // Case 2: Model with a parent. - QStringListModel m2(&m); - testDumper("addr='<synthetic>',type='$T',numchild='1',value='<1 items>'," - "children=[{name='objectName',type='QString',value=''," - "valueencoded='2',numchild='0'}]", - &m2, NS"QObjectPropertyList", true); -} - -static const char *connectionType(uint type) -{ - Qt::ConnectionType connType = static_cast<Qt::ConnectionType>(type); - const char *output = "unknown"; - switch (connType) { - case Qt::AutoConnection: output = "auto"; break; - case Qt::DirectConnection: output = "direct"; break; - case Qt::QueuedConnection: output = "queued"; break; - case Qt::BlockingQueuedConnection: output = "blockingqueued"; break; - case 3: output = "autocompat"; break; -#if QT_VERSION >= 0x040600 - case Qt::UniqueConnection: break; // Can't happen. -#endif - default: - qWarning() << "Unknown connection type: " << type; - break; - }; - return output; -}; - -class Cheater : public QObject -{ -public: - static const QObjectPrivate *getPrivate(const QObject &o) - { - const Cheater &cheater = static_cast<const Cheater&>(o); -#if QT_VERSION >= 0x040600 - return dynamic_cast<const QObjectPrivate *>(cheater.d_ptr.data()); -#else - return dynamic_cast<const QObjectPrivate *>(cheater.d_ptr); -#endif + QByteArray nograb = "-nograb"; + + QByteArray cmds = + "set confirm off\n" + "file doit\n" + "break stopper\n" + "set auto-load python-scripts off\n" + "python execfile('" + dumperDir + "/bridge.py')\n" + "python execfile('" + dumperDir + "/dumper.py')\n" + "python execfile('" + dumperDir + "/qttypes.py')\n" + "bbsetup\n" + "run " + nograb + "\n" + "up\n" + "python print('@%sS@%s@' % ('N', qtNamespace()))\n" + "bb options:fancy,autoderef,dyntype vars: expanded:" + expanded + " typeformats:\n" + "quit\n"; + + if (keepTemp) { + QFile logger(buildDir.path() + QLatin1String("/input.txt")); + ok = logger.open(QIODevice::ReadWrite); + logger.write(cmds); } -}; - -typedef QVector<QObjectPrivate::ConnectionList> ConnLists; -void tst_Dumpers::dumpQObjectSignalHelper(QObject &o, int sigNum) -{ - //qDebug() << o.objectName() << sigNum; - QByteArray expected("addr='<synthetic>',numchild='1',type='" NS "QObjectSignal'"); -#if QT_VERSION >= 0x040400 && QT_VERSION <= 0x040700 - expected.append(",children=["); - const QObjectPrivate *p = Cheater::getPrivate(o); - Q_ASSERT(p != 0); - const ConnLists *connLists = reinterpret_cast<const ConnLists *>(p->connectionLists); - QObjectPrivate::ConnectionList connList = - connLists != 0 && connLists->size() > sigNum ? - connLists->at(sigNum) : QObjectPrivate::ConnectionList(); - int i = 0; - // FIXME: 4.6 only - for (QObjectPrivate::Connection *conn = connList.first; conn != 0; - ++i, conn = conn->nextConnectionList) { - const QString iStr = N(i); - expected.append("{name='").append(iStr).append(" receiver',"); - if (conn->receiver == &o) - expected.append("value='<this>',type='"). - append(o.metaObject()->className()). - append("',numchild='0',addr='").append(ptrToBa(&o)).append("'"); - else if (conn->receiver == 0) - expected.append("value='0x0',type='" NS "QObject *',numchild='0'"); - else - expected.append("addr='").append(ptrToBa(conn->receiver)).append("',value='"). - append(utfToBase64(conn->receiver->objectName())).append("',valueencoded='2',"). - append("type='" NS "QObject',displayedtype='"). - append(conn->receiver->metaObject()->className()).append("',numchild='1'"); - expected.append("},{name='").append(iStr).append(" slot',type='',value='"); - if (conn->receiver != 0) - expected.append(conn->receiver->metaObject()->method(conn->method).signature()); - else - expected.append("<invalid receiver>"); - expected.append("',numchild='0'},{name='").append(iStr).append(" type',type='',value='<"). - append(connectionType(conn->connectionType)).append(" connection>',"). - append("numchild='0'}"); - if (conn != connList.last) - expected.append(","); + QProcess debugger; + debugger.setWorkingDirectory(buildDir.path()); + //qDebug() << "Starting debugger "; + debugger.start(QLatin1String("gdb -i mi -quiet -nx")); + ok = debugger.waitForStarted(); + debugger.write(cmds); + ok = debugger.waitForFinished(); + QVERIFY(ok); + output = debugger.readAllStandardOutput(); + //qDebug() << "stdout: " << output; + error = debugger.readAllStandardError(); + if (!error.isEmpty()) { qDebug() << error; } + + if (keepTemp) { + QFile logger(buildDir.path() + QLatin1String("/output.txt")); + ok = logger.open(QIODevice::ReadWrite); + logger.write("=== STDOUT ===\n"); + logger.write(output); + logger.write("\n=== STDERR ===\n"); + logger.write(error); } - expected.append("],numchild='").append(N(i)).append("'"); -#endif - testDumper(expected, &o, NS"QObjectSignal", true, "", "", sigNum); -} - -void tst_Dumpers::dumpQObjectSignal() -{ - // Case 1: Simple QObject. - QObject o; - o.setObjectName("Test"); - testDumper("addr='<synthetic>',numchild='1',type='" NS "QObjectSignal'," - "children=[],numchild='0'", - &o, NS"QObjectSignal", true, "", "", 0); - - // Case 2: QAbstractItemModel with no connections. - QStringListModel m(QStringList() << "Test1" << "Test2"); - for (int signalIndex = 0; signalIndex < 17; ++signalIndex) - dumpQObjectSignalHelper(m, signalIndex); - - // Case 3: QAbstractItemModel with connections to itself and to another - // object, using different connection types. - qRegisterMetaType<QModelIndex>("QModelIndex"); - connect(&m, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), - &o, SLOT(deleteLater()), Qt::DirectConnection); - connect(&m, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), - &m, SLOT(revert()), Qt::QueuedConnection); - connect(&m, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), - &m, SLOT(submit()), Qt::QueuedConnection); - connect(&m, SIGNAL(columnsInserted(QModelIndex,int,int)), - &m, SLOT(submit()), Qt::BlockingQueuedConnection); - connect(&m, SIGNAL(columnsRemoved(QModelIndex,int,int)), - &m, SLOT(deleteLater()), Qt::AutoConnection); -#if QT_VERSION >= 0x040600 - connect(&m, SIGNAL(dataChanged(QModelIndex,QModelIndex)), - &m, SLOT(revert()), Qt::UniqueConnection); -#endif - for (int signalIndex = 0; signalIndex < 17; ++signalIndex) - dumpQObjectSignalHelper(m, signalIndex); -} -void tst_Dumpers::dumpQObjectSignalList() -{ - // Case 1: Simple QObject. - QObject o; - o.setObjectName("Test"); - - testDumper("type='" NS "QObjectSignalList',value='<2 items>'," - "addr='$A',numchild='2',children=[" - "{name='0',value='destroyed(QObject*)',numchild='0'," - "addr='$A',type='" NS "QObjectSignal'}," - "{name='1',value='destroyed()',numchild='0'," - "addr='$A',type='" NS "QObjectSignal'}]", - &o, NS"QObjectSignalList", true); - - // Case 2: QAbstractItemModel with no connections. - QStringListModel m(QStringList() << "Test1" << "Test2"); - QByteArray expected = "type='" NS "QObjectSignalList',value='<20 items>'," - "addr='$A',numchild='20',children=[" - "{name='0',value='destroyed(QObject*)',numchild='0'," - "addr='$A',type='" NS "QObjectSignal'}," - "{name='1',value='destroyed()',numchild='0'," - "addr='$A',type='" NS "QObjectSignal'}," - "{name='4',value='dataChanged(QModelIndex,QModelIndex)',numchild='0'," - "addr='$A',type='" NS "QObjectSignal'}," - "{name='5',value='headerDataChanged(Qt::Orientation,int,int)'," - "numchild='0',addr='$A',type='" NS "QObjectSignal'}," - "{name='6',value='layoutChanged()',numchild='0'," - "addr='$A',type='" NS "QObjectSignal'}," - "{name='7',value='layoutAboutToBeChanged()',numchild='0'," - "addr='$A',type='" NS "QObjectSignal'}," - "{name='8',value='rowsAboutToBeInserted(QModelIndex,int,int)'," - "numchild='0',addr='$A',type='" NS "QObjectSignal'}," - "{name='9',value='rowsInserted(QModelIndex,int,int)'," - "numchild='0',addr='$A',type='" NS "QObjectSignal'}," - "{name='10',value='rowsAboutToBeRemoved(QModelIndex,int,int)'," - "numchild='%',addr='$A',type='" NS "QObjectSignal'}," - "{name='11',value='rowsRemoved(QModelIndex,int,int)'," - "numchild='%',addr='$A',type='" NS "QObjectSignal'}," - "{name='12',value='columnsAboutToBeInserted(QModelIndex,int,int)'," - "numchild='%',addr='$A',type='" NS "QObjectSignal'}," - "{name='13',value='columnsInserted(QModelIndex,int,int)'," - "numchild='%',addr='$A',type='" NS "QObjectSignal'}," - "{name='14',value='columnsAboutToBeRemoved(QModelIndex,int,int)'," - "numchild='%',addr='$A',type='" NS "QObjectSignal'}," - "{name='15',value='columnsRemoved(QModelIndex,int,int)'," - "numchild='%',addr='$A',type='" NS "QObjectSignal'}," - "{name='16',value='modelAboutToBeReset()'," - "numchild='0',addr='$A',type='" NS "QObjectSignal'}," - "{name='17',value='modelReset()'," - "numchild='0',addr='$A',type='" NS "QObjectSignal'}," - "{name='18',value='rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)'," - "numchild='0',addr='$A',type='" NS "QObjectSignal'}," - "{name='19',value='rowsMoved(QModelIndex,int,int,QModelIndex,int)'," - "numchild='0',addr='$A',type='" NS "QObjectSignal'}," - "{name='20',value='columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)'," - "numchild='0',addr='$A',type='" NS "QObjectSignal'}," - "{name='21',value='columnsMoved(QModelIndex,int,int,QModelIndex,int)'," - "numchild='0',addr='$A',type='" NS "QObjectSignal'}]"; - - - testDumper(expected << "0" << "0" << "0" << "0" << "0" << "0", - &m, NS"QObjectSignalList", true); - - - // Case 3: QAbstractItemModel with connections to itself and to another - // object, using different connection types. - qRegisterMetaType<QModelIndex>("QModelIndex"); - connect(&m, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), - &o, SLOT(deleteLater()), Qt::DirectConnection); - connect(&m, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), - &m, SLOT(revert()), Qt::QueuedConnection); - connect(&m, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), - &m, SLOT(submit()), Qt::QueuedConnection); - connect(&m, SIGNAL(columnsInserted(QModelIndex,int,int)), - &m, SLOT(submit()), Qt::BlockingQueuedConnection); - connect(&m, SIGNAL(columnsRemoved(QModelIndex,int,int)), - &m, SLOT(deleteLater()), Qt::AutoConnection); - - testDumper(expected << "1" << "1" << "2" << "1" << "0" << "0", - &m, NS"QObjectSignalList", true); -} - -QByteArray slotIndexList(const QObject *ob) -{ - QByteArray slotIndices; - const QMetaObject *mo = ob->metaObject(); - for (int i = 0; i < mo->methodCount(); ++i) { - const QMetaMethod &mm = mo->method(i); - if (mm.methodType() == QMetaMethod::Slot) { - int slotIndex = mo->indexOfSlot(mm.signature()); - Q_ASSERT(slotIndex != -1); - slotIndices.append(N(slotIndex)); - slotIndices.append(','); - } + int pos1 = output.indexOf("data="); + QVERIFY(pos1 != -1); + int pos2 = output.indexOf(",typeinfo", pos1); + QVERIFY(pos2 != -1); + QByteArray contents = output.mid(pos1, pos2 - pos1); + contents.replace("\\\"", "\""); + + int pos3 = output.indexOf("@NS@"); + QVERIFY(pos3 != -1); + pos3 += sizeof("@NS@") - 1; + int pos4 = output.indexOf("@", pos3); + QVERIFY(pos4 != -1); + QByteArray nameSpace = output.mid(pos3, pos4 - pos3); + //qDebug() << "FOUND NS: " << nameSpace; + if (nameSpace == "::") + nameSpace.clear(); + + GdbMi actual; + actual.fromString(contents); + ok = false; + WatchData local; + local.iname = "local"; + + QList<WatchData> list; + foreach (const GdbMi &child, actual.children()) { + WatchData dummy; + dummy.iname = child.findChild("iname").data(); + dummy.name = QLatin1String(child.findChild("name").data()); + parseWatchData(expandedINames, dummy, child, &list); } - slotIndices.chop(1); - return slotIndices; -} -void tst_Dumpers::dumpQObjectSlot() -{ - // Case 1: Simple QObject. - QObject o; - o.setObjectName("Test"); - - QByteArray slotIndices = slotIndexList(&o); - QCOMPARE(slotIndices, QByteArray("2,3")); - QCOMPARE(o.metaObject()->indexOfSlot("deleteLater()"), 2); - - QByteArray expected = QByteArray("addr='$A',numchild='1',type='$T'," - //"children=[{name='1 sender'}],numchild='1'"); - "children=[],numchild='0'"); - qDebug() << "FIXME!"; - testDumper(expected, &o, NS"QObjectSlot", true, "", "", 2); - - - // Case 2: QAbstractItemModel with no connections. - QStringListModel m(QStringList() << "Test1" << "Test2"); - slotIndices = slotIndexList(&o); - - QCOMPARE(slotIndices, QByteArray("2,3")); - QCOMPARE(o.metaObject()->indexOfSlot("deleteLater()"), 2); - - expected = QByteArray("addr='$A',numchild='1',type='$T'," - //"children=[{name='1 sender'}],numchild='1'"); - "children=[],numchild='0'"); - qDebug() << "FIXME!"; - testDumper(expected, &o, NS"QObjectSlot", true, "", "", 2); - - - // Case 3: QAbstractItemModel with connections to itself and to another - // o, using different connection types. - qRegisterMetaType<QModelIndex>("QModelIndex"); - connect(&m, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), - &o, SLOT(deleteLater()), Qt::DirectConnection); - connect(&o, SIGNAL(destroyed(QObject*)), - &m, SLOT(revert()), Qt::QueuedConnection); - connect(&m, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), - &m, SLOT(submit()), Qt::QueuedConnection); - connect(&m, SIGNAL(columnsInserted(QModelIndex,int,int)), - &m, SLOT(submit()), Qt::BlockingQueuedConnection); - connect(&m, SIGNAL(columnsRemoved(QModelIndex,int,int)), - &m, SLOT(deleteLater()), Qt::AutoConnection); -#if QT_VERSION >= 0x040600 - connect(&m, SIGNAL(dataChanged(QModelIndex,QModelIndex)), - &m, SLOT(revert()), Qt::UniqueConnection); -#endif - expected = QByteArray("addr='$A',numchild='1',type='$T'," - //"children=[{name='1 sender'}],numchild='1'"); - "children=[],numchild='0'"); - qDebug() << "FIXME!"; - testDumper(expected, &o, NS"QObjectSlot", true, "", "", 2); - -} - -void tst_Dumpers::dumpQObjectSlotList() -{ - // Case 1: Simple QObject. - QObject o; - o.setObjectName("Test"); - testDumper("numchild='2',value='<2 items>',type='$T'," - "children=[{name='2',value='deleteLater()',numchild='0'," - "addr='$A',type='" NS "QObjectSlot'}," - "{name='3',value='_q_reregisterTimers(void*)',numchild='0'," - "addr='$A',type='" NS "QObjectSlot'}]", - &o, NS"QObjectSlotList", true); - - // Case 2: QAbstractItemModel with no connections. - QStringListModel m(QStringList() << "Test1" << "Test2"); - testDumper("numchild='4',value='<4 items>',type='$T'," - "children=[{name='2',value='deleteLater()',numchild='0'," - "addr='$A',type='" NS "QObjectSlot'}," - "{name='3',value='_q_reregisterTimers(void*)',numchild='0'," - "addr='$A',type='" NS "QObjectSlot'}," - "{name='22',value='submit()',numchild='0'," - "addr='$A',type='" NS "QObjectSlot'}," - "{name='23',value='revert()',numchild='0'," - "addr='$A',type='" NS "QObjectSlot'}]", - &m, NS"QObjectSlotList", true); - - // Case 3: QAbstractItemModel with connections to itself and to another - // object, using different connection types. - qRegisterMetaType<QModelIndex>("QModelIndex"); - connect(&m, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), - &o, SLOT(deleteLater()), Qt::DirectConnection); - connect(&m, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), - &m, SLOT(revert()), Qt::QueuedConnection); - connect(&m, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), - &m, SLOT(submit()), Qt::QueuedConnection); - connect(&m, SIGNAL(columnsInserted(QModelIndex,int,int)), - &m, SLOT(submit()), Qt::BlockingQueuedConnection); - connect(&m, SIGNAL(columnsRemoved(QModelIndex,int,int)), - &m, SLOT(deleteLater()), Qt::AutoConnection); - connect(&o, SIGNAL(destroyed(QObject*)), &m, SLOT(submit())); - testDumper("numchild='4',value='<4 items>',type='$T'," - "children=[{name='2',value='deleteLater()',numchild='0'," - "addr='$A',type='" NS "QObjectSlot'}," - "{name='3',value='_q_reregisterTimers(void*)',numchild='0'," - "addr='$A',type='" NS "QObjectSlot'}," - "{name='22',value='submit()',numchild='0'," - "addr='$A',type='" NS "QObjectSlot'}," - "{name='23',value='revert()',numchild='0'," - "addr='$A',type='" NS "QObjectSlot'}]", - &m, NS"QObjectSlotList", true); -} -#endif - -void tst_Dumpers::dumpQPixmap() -{ - // Case 1: Null Pixmap. - QPixmap p; - - testDumper("value='(0x0)',type='$T',numchild='0'", - &p, NS"QPixmap", true); - - - // Case 2: Uninitialized non-null pixmap. - p = QPixmap(20, 100); - testDumper("value='(20x100)',type='$T',numchild='0'", - &p, NS"QPixmap", true); - - - // Case 3: Initialized non-null pixmap. - const char * const pixmap[] = { - "2 24 3 1", " c None", ". c #DBD3CB", "+ c #FCFBFA", - " ", " ", " ", ".+", ".+", ".+", ".+", ".+", ".+", ".+", ".+", ".+", - ".+", ".+", ".+", ".+", ".+", ".+", ".+", ".+", ".+", " ", " ", " " - }; - p = QPixmap(pixmap); - testDumper("value='(2x24)',type='$T',numchild='0'", - &p, NS"QPixmap", true); -} - -#if QT_VERSION >= 0x040500 -template<typename T> -void tst_Dumpers::dumpQSharedPointerHelper(QSharedPointer<T> &ptr) -{ - struct Cheater : public QSharedPointer<T> - { - static const typename QSharedPointer<T>::Data *getData(const QSharedPointer<T> &p) - { - return static_cast<const Cheater &>(p).d; + foreach (const WatchData &item, list) { + if (data.checks.contains(item.iname)) { + Check check = data.checks.take(item.iname); + if (item.name.toLatin1() != check.expectedName) { + qDebug() << "INAME : " << item.iname; + qDebug() << "NAME ACTUAL : " << item.name; + qDebug() << "NAME EXPECTED: " << check.expectedName; + qDebug() << "CONTENTS : " << contents; + QVERIFY(false); + } + if (!check.expectedValue.matches(item.value)) { + qDebug() << "INAME : " << item.iname; + qDebug() << "VALUE ACTUAL : " << item.value << item.value.toLatin1().toHex(); + qDebug() << "VALUE EXPECTED: " << check.expectedValue.value << check.expectedValue.value.toHex(); + qDebug() << "CONTENTS : " << contents; + QVERIFY(false); + } + if (!check.expectedType.matches(item.type, nameSpace)) { + qDebug() << "INAME : " << item.iname; + qDebug() << "TYPE ACTUAL : " << item.type; + qDebug() << "TYPE EXPECTED: " << check.expectedType.type; + qDebug() << "CONTENTS : " << contents; + QVERIFY(false); + } } - }; - - QByteArray expected("value='"); - QString val1 = ptr.isNull() ? "<null>" : valToString(*ptr.data()); - QString val2 = isSimpleType<T>() ? val1 : ""; -/* - const int *weakAddr; - const int *strongAddr; - int weakValue; - int strongValue; - if (!ptr.isNull()) { - weakAddr = reinterpret_cast<const int *>(&Cheater::getData(ptr)->weakref); - strongAddr = reinterpret_cast<const int *>(&Cheater::getData(ptr)->strongref); - weakValue = *weakAddr; - strongValue = *strongAddr; - } else { - weakAddr = strongAddr = 0; - weakValue = strongValue = 0; } - expected.append(val2).append("',valueeditable='false',numchild='1',children=["). - append("{name='data',addr='").append(ptrToBa(ptr.data())). - append("',type='").append(typeToString<T>()).append("',value='").append(val1). - append("'},{name='weakref',value='").append(N(weakValue)). - append("',type='int',addr='").append(ptrToBa(weakAddr)).append("',numchild='0'},"). - append("{name='strongref',value='").append(N(strongValue)). - append("',type='int',addr='").append(ptrToBa(strongAddr)).append("',numchild='0'}]"); - testDumper(expected, &ptr, NS"QSharedPointer", true, typeToString<T>()); -*/ -} -#endif - -void tst_Dumpers::dumpQSharedPointer() -{ -#if QT_VERSION >= 0x040500 - // Case 1: Simple type. - // Case 1.1: Null pointer. - QSharedPointer<int> simplePtr; - dumpQSharedPointerHelper(simplePtr); - - // Case 1.2: Non-null pointer, - QSharedPointer<int> simplePtr2(new int(99)); - dumpQSharedPointerHelper(simplePtr2); - - // Case 1.3: Shared pointer. - QSharedPointer<int> simplePtr3 = simplePtr2; - dumpQSharedPointerHelper(simplePtr2); - - // Case 1.4: Weak pointer. - QWeakPointer<int> simplePtr4(simplePtr2); - dumpQSharedPointerHelper(simplePtr2); - - // Case 2: Composite type. - // Case 1.1: Null pointer. - QSharedPointer<QString> compositePtr; - // TODO: This case is not handled in dumper.cpp (segfault!) - //dumpQSharedPointerHelper(compoistePtr); - - // Case 1.2: Non-null pointer, - QSharedPointer<QString> compositePtr2(new QString("Test")); - dumpQSharedPointerHelper(compositePtr2); - - // Case 1.3: Shared pointer. - QSharedPointer<QString> compositePtr3 = compositePtr2; - dumpQSharedPointerHelper(compositePtr2); - - // Case 1.4: Weak pointer. - QWeakPointer<QString> compositePtr4(compositePtr2); - dumpQSharedPointerHelper(compositePtr2); -#endif -} - -void tst_Dumpers::dumpQString() -{ - QString s; - testDumper("value='IiIgKG51bGwp',valueencoded='5',type='$T',numchild='0'", - &s, NS"QString", false); - s = "abc"; - testDumper("value='YQBiAGMA',valueencoded='2',type='$T',numchild='0'", - &s, NS"QString", false); -} - -void tst_Dumpers::dumpQVariant_invalid() -{ - QVariant v; - testDumper("value='(invalid)',type='$T',numchild='0'", - &v, NS"QVariant", false); -} - -void tst_Dumpers::dumpQVariant_QString() -{ - QVariant v = "abc"; - testDumper("value='KFFTdHJpbmcpICJhYmMi',valueencoded='5',type='$T'," - "numchild='0'", - &v, NS"QVariant", true); -/* - FIXME: the QString version should have a child: - testDumper("value='KFFTdHJpbmcpICJhYmMi',valueencoded='5',type='$T'," - "numchild='1',children=[{name='value',value='IgBhAGIAYwAiAA=='," - "valueencoded='4',type='QString',numchild='0'}]", - &v, NS"QVariant", true); -*/ -} - -void tst_Dumpers::dumpQVariant_QStringList() -{ - QVariant v = QStringList() << "Hi"; - testDumper("value='(QStringList) ',type='$T',numchild='1'," - "children=[{name='value',exp='(*('" NS "QStringList'*)%)'," - "type='QStringList',numchild='1'}]" - << QByteArray::number(quintptr(&v)), - &v, NS"QVariant", true); -} - -#ifndef Q_CC_MSVC - -void tst_Dumpers::dumpStdVector() -{ - std::vector<std::list<int> *> vector; - QByteArray inner = "std::list<int> *"; - QByteArray innerp = "std::list<int>"; - testDumper("value='<0 items>',valueeditable='false',numchild='0'", - &vector, "std::vector", false, inner, "", sizeof(std::list<int> *)); - std::list<int> list; - vector.push_back(new std::list<int>(list)); - testDumper("value='<1 items>',valueeditable='false',numchild='1'," - "childtype='" + inner + "',childnumchild='1'," - "children=[{addr='" + str(deref(&vector[0])) + "',type='" + innerp + "'}]", - &vector, "std::vector", true, inner, "", sizeof(std::list<int> *)); - vector.push_back(0); - list.push_back(45); - testDumper("value='<2 items>',valueeditable='false',numchild='2'," - "childtype='" + inner + "',childnumchild='1'," - "children=[{addr='" + str(deref(&vector[0])) + "',type='" + innerp + "'}," - "{addr='" + str(&vector[1]) + "'," - "type='" + innerp + "',value='<null>',numchild='0'}]", - &vector, "std::vector", true, inner, "", sizeof(std::list<int> *)); - vector.push_back(new std::list<int>(list)); - vector.push_back(0); -} -#endif // !Q_CC_MSVC - -void tst_Dumpers::dumpQTextCodecHelper(QTextCodec *codec) -{ - const QByteArray name = codec->name().toBase64(); - QByteArray expected = QByteArray("value='%',valueencoded='1',type='$T'," - "numchild='2',children=[{name='name',value='%',type='" NS "QByteArray'," - "numchild='0',valueencoded='1'},{name='mibEnum',%}]") - << name << name << generateIntSpec(codec->mibEnum()); - testDumper(expected, codec, NS"QTextCodec", true); -} - -void tst_Dumpers::dumpQTextCodec() -{ - const QList<QByteArray> &codecNames = QTextCodec::availableCodecs(); - foreach (const QByteArray &codecName, codecNames) - dumpQTextCodecHelper(QTextCodec::codecForName(codecName)); -} - -#if QT_VERSION >= 0x040500 -template <typename T1, typename T2> - size_t offsetOf(const T1 *klass, const T2 *member) -{ - return static_cast<size_t>(reinterpret_cast<const char *>(member) - - reinterpret_cast<const char *>(klass)); + if (!data.checks.isEmpty()) { + qDebug() << "SOME TESTS NOT EXECUTED: "; + foreach (const Check &check, data.checks) + qDebug() << " TEST NOT FOUND FOR INAME: " << check.iname; + qDebug() << "CONTENTS : " << contents; + qDebug() << "EXPANDED : " << expanded; + QVERIFY(false); + } } -template <typename T> -void tst_Dumpers::dumpQWeakPointerHelper(QWeakPointer<T> &ptr) -{ - typedef QtSharedPointer::ExternalRefCountData Data; - const size_t dataOffset = 0; - const Data *d = *reinterpret_cast<const Data **>( - reinterpret_cast<const char **>(&ptr) + dataOffset); - const int *weakRefPtr = reinterpret_cast<const int *>(&d->weakref); - const int *strongRefPtr = reinterpret_cast<const int *>(&d->strongref); - T *data = ptr.toStrongRef().data(); - const QString dataStr = valToString(*data); - QByteArray expected("value='"); - if (isSimpleType<T>()) - expected.append(dataStr); - expected.append("',valueeditable='false',numchild='1',children=[{name='data',addr='"). - append(ptrToBa(data)).append("',type='").append(typeToString<T>()). - append("',value='").append(dataStr).append("'},{name='weakref',value='"). - append(valToString(*weakRefPtr)).append("',type='int',addr='"). - append(ptrToBa(weakRefPtr)).append("',numchild='0'},{name='strongref',value='"). - append(valToString(*strongRefPtr)).append("',type='int',addr='"). - append(ptrToBa(strongRefPtr)).append("',numchild='0'}]"); - testDumper(expected, &ptr, NS"QWeakPointer", true, typeToString<T>()); -} +void tst_Dumpers::dumper_data() +{ + QTest::addColumn<Data>("data"); + + QByteArray fooData = + "#include <QHash>\n" + "#include <QMap>\n" + "#include <QObject>\n" + "#include <QString>\n" + "class Foo\n" + "{\n" + "public:\n" + " Foo(int i = 0)\n" + " : a(i), b(2)\n" + " {}\n" + " virtual ~Foo()\n" + " {\n" + " a = 5;\n" + " }\n" + " void doit()\n" + " {\n" + " static QObject ob;\n" + " m[\"1\"] = \"2\";\n" + " h[&ob] = m.begin();\n" + " --b;\n" + " }\n" + "public:\n" + " int a, b;\n" + " char x[6];\n" + "private:\n" + " typedef QMap<QString, QString> Map;\n" + " Map m;\n" + " QHash<QObject *, Map::iterator> h;\n" + "};\n"; + + QByteArray nsData = + "namespace nsA {\n" + "namespace nsB {\n" + " struct SomeType\n" + " {\n" + " SomeType(int a) : a(a) {}\n" + " int a;\n" + " };\n" + " } // namespace nsB\n" + " } // namespace nsA\n"; + + QTest::newRow("AnonymousStruct") + << Data("union {\n" + " struct { int i; int b; };\n" + " struct { float f; };\n" + " double d;\n" + " } a = { { 42, 43 } };\n (void)a;") + % CheckType("a", "a", "union {...}") + % Check("a.b", "43", "int") + % Check("a.d", "9.1245819032257467e-313", "double") + % Check("a.f", "5.88545355e-44", "float") + % Check("a.i", "42", "int"); + + QTest::newRow("QByteArray0") + << Data("#include <QByteArray>\n", + "QByteArray ba;") + % Check("ba", "ba", "\"\"", "@QByteArray"); + + QTest::newRow("QByteArray1") + << Data("#include <QByteArray>\n", + "QByteArray ba = \"Hello\\\"World\";\n" + "ba += char(0);\n" + "ba += 1;\n" + "ba += 2;\n") + % Check("ba", "\"Hello\"World\"", "@QByteArray") + % Check("ba.0", "[0]", "72", "char") + % Check("ba.11", "[11]", "0", "char") + % Check("ba.12", "[12]", "1", "char") + % Check("ba.13", "[13]", "2", "char"); + + QTest::newRow("QByteArray2") + << Data("#include <QByteArray>\n" + "#include <QString>\n" + "#include <string>\n", + "QByteArray ba;\n" + "for (int i = 256; --i >= 0; )\n" + " ba.append(char(i));\n" + "QString s(10000, 'x');\n" + "std::string ss(10000, 'c');\n" + "dummyStatement(&ba, &s, &ss);\n") + % CheckType("ba", "@QByteArray") + % Check("s", '"' + QByteArray(10000, 'x') + '"', "@QString") + % Check("ss", '"' + QByteArray(10000, 'c') + '"', "std::string"); + + QTest::newRow("QByteArray3") + << Data("#include <QByteArray>\n", + "const char *str1 = \"\356\";\n" + "const char *str2 = \"\xee\";\n" + "const char *str3 = \"\\ee\";\n" + "QByteArray buf1(str1);\n" + "QByteArray buf2(str2);\n" + "QByteArray buf3(str3);\n" + "dummyStatement(&buf1, &buf2, &buf3);\n") + % Check("buf1", "\"î\"", "@QByteArray") + % Check("buf2", "\"î\"", "@QByteArray") + % Check("buf3", "\"\ee\"", "@QByteArray") + % CheckType("str1", "char *"); + + QTest::newRow("QByteArray4") + << Data("#include <QByteArray>\n", + "char data[] = { 'H', 'e', 'l', 'l', 'o' };\n" + "QByteArray ba1 = QByteArray::fromRawData(data, 4);\n" + "QByteArray ba2 = QByteArray::fromRawData(data + 1, 4);\n") + % Check("ba1", "\"Hell\"", "@QByteArray") + % Check("ba2", "\"ello\"", "@QByteArray"); + + QTest::newRow("QDate0") + << Data("#include <QDate>\n", + "QDate date;\n" + "dummyStatement(&date);\n") + % CheckType("date", "@QDate") + % Check("date.(ISO)", "", "@QString") + % Check("date.(Locale)", "", "@QString") + % Check("date.(SystemLocale)", "", "@QString") + % Check("date.toString", "", "@QString"); + + QTest::newRow("QDate1") + << Data("#include <QDate>\n", + "QDate date;\n" + "date.setDate(1980, 1, 1);\n" + "dummyStatement(&date);\n") + % CheckType("date", "@QDate") + % Check("date.(ISO)", "\"1980-01-01\"", "@QString") + % CheckType("date.(Locale)", "@QString") + % CheckType("date.(SystemLocale)", "@QString") + % Check("date.toString", "\"Tue Jan 1 1980\"", "@QString"); + + QTest::newRow("QTime0") + << Data("#include <QTime>\n", + "QTime time;\n") + % CheckType("time", "@QTime") + % Check("time.(ISO)", "", "@QString") + % CheckType("time.(Locale)", "@QString") + % CheckType("time.(SystemLocale)", "@QString") + % Check("time.toString", "", "@QString"); + + QTest::newRow("QTime1") + << Data("#include <QTime>\n", + "QTime time(13, 15, 32);") + % Check("time", "13:15:32", "@QTime") + % Check("time.(ISO)", "\"13:15:32\"", "@QString") + % CheckType("time.(Locale)", "@QString") + % CheckType("time.(SystemLocale)", "@QString") + % Check("time.toString", "\"13:15:32\"", "@QString"); + + QTest::newRow("QDateTime") + << Data("#include <QDateTime>\n", + "QDateTime date;\n") + % CheckType("date", "@QDateTime") + % Check("date.(ISO)", "", "@QString") + % Check("date.(Locale)", "", "@QString") + % Check("date.(SystemLocale)", "", "@QString") + % Check("date.toString", "\"\"", "@QString") + % Check("date.toUTC", "", "@QDateTime"); + + QTest::newRow("QDir") +#ifdef Q_OS_WIN + << Data("#include <QDir>\n", + "QDir dir(\"C:\\\\Program Files\");") + % Check("dir", "C:/Program Files", "@QDir") + % Check("dir.absolutePath", "C:/Program Files", "@QString") + % Check("dir.canonicalPath", "C:/Program Files", "@QString"); +#else + << Data("#include <QDir>\n", + "QDir dir(\"/tmp\"); QString s = dir.absolutePath();") + % Check("dir", "/tmp", "@QDir") + % Check("dir.absolutePath", "\"/tmp\"", "@QString") + % Check("dir.canonicalPath", "\"/tmp\"", "@QString"); #endif -void tst_Dumpers::dumpQWeakPointer() -{ -#if QT_VERSION >= 0x040500 - // Case 1: Simple type. - - // Case 1.1: Null pointer. - QSharedPointer<int> spNull; - QWeakPointer<int> wp = spNull.toWeakRef(); - testDumper("value='<null>',valueeditable='false',numchild='0'", - &wp, NS"QWeakPointer", true, "int"); - - // Case 1.2: Weak pointer is unique. - QSharedPointer<int> sp(new int(99)); - wp = sp.toWeakRef(); - dumpQWeakPointerHelper(wp); - - // Case 1.3: There are other weak pointers. - QWeakPointer<int> wp2 = sp.toWeakRef(); - dumpQWeakPointerHelper(wp); - - // Case 1.4: There are other strong shared pointers as well. - QSharedPointer<int> sp2(sp); - dumpQWeakPointerHelper(wp); - - // Case 2: Composite type. - QSharedPointer<QString> spS(new QString("Test")); - QWeakPointer<QString> wpS = spS.toWeakRef(); - dumpQWeakPointerHelper(wpS); + QTest::newRow("QFileInfo") +#ifdef Q_OS_WIN + << Data("#include <QFile>\n" + "#include <QFileInfo>\n", + "QFile file(\"C:\\\\Program Files\\t\");\n" + "file.setObjectName(\"A QFile instance\");\n" + "QFileInfo fi(\"C:\\Program Files\\tt\");\n" + "QString s = fi.absoluteFilePath();\n") + % Check("fi", "\"C:/Program Files/tt\"", "QFileInfo") + % Check("file", "\"C:\Program Files\t\"", "QFile") + % Check("s", "\"C:/Program Files/tt\"", "QString"); +#else + << Data("#include <QFile>\n" + "#include <QFileInfo>\n", + "QFile file(\"/tmp/t\");\n" + "file.setObjectName(\"A QFile instance\");\n" + "QFileInfo fi(\"/tmp/tt\");\n" + "QString s = fi.absoluteFilePath();\n") + % Check("fi", "\"/tmp/tt\"", "@QFileInfo") + % Check("file", "\"/tmp/t\"", "@QFile") + % Check("s", "\"/tmp/tt\"", "@QString"); #endif -} -#define VERIFY_OFFSETOF(member) \ -do { \ - QObjectPrivate *qob = 0; \ - ObjectPrivate *ob = 0; \ - QVERIFY(size_t(&qob->member) == size_t(&ob->member)); \ -} while (0) - - -void tst_Dumpers::initTestCase() -{ - QVERIFY(sizeof(QWeakPointer<int>) == 2*sizeof(void *)); - QVERIFY(sizeof(QSharedPointer<int>) == 2*sizeof(void *)); -#if QT_VERSION < 0x050000 - QtSharedPointer::ExternalRefCountData d; - d.weakref = d.strongref = 0; // That's what the destructor expects. - QVERIFY(sizeof(int) == sizeof(d.weakref)); - QVERIFY(sizeof(int) == sizeof(d.strongref)); -#endif -#ifdef USE_PRIVATE - const size_t qObjectPrivateSize = sizeof(QObjectPrivate); - const size_t objectPrivateSize = sizeof(ObjectPrivate); - QVERIFY2(qObjectPrivateSize == objectPrivateSize, QString::fromLatin1("QObjectPrivate=%1 ObjectPrivate=%2").arg(qObjectPrivateSize).arg(objectPrivateSize).toLatin1().constData()); - VERIFY_OFFSETOF(threadData); - VERIFY_OFFSETOF(extraData); - VERIFY_OFFSETOF(objectName); - VERIFY_OFFSETOF(connectionLists); - VERIFY_OFFSETOF(senders); - VERIFY_OFFSETOF(currentSender); - VERIFY_OFFSETOF(eventFilters); - VERIFY_OFFSETOF(currentChildBeingDeleted); - VERIFY_OFFSETOF(connectedSignals); - //VERIFY_OFFSETOF(deleteWatch); -#ifdef QT3_SUPPORT -#if QT_VERSION < 0x040600 - VERIFY_OFFSETOF(pendingChildInsertedEvents); -#endif -#endif -#if QT_VERSION >= 0x040600 - VERIFY_OFFSETOF(sharedRefcount); -#endif -#endif + QTest::newRow("QHash1") + << Data("#include <QHash>\n", + "QHash<QString, QList<int> > hash;\n" + "hash.insert(\"Hallo\", QList<int>());\n" + "hash.insert(\"Welt\", QList<int>() << 1);\n" + "hash.insert(\"!\", QList<int>() << 1 << 2);\n") + % Check("hash", "<3 items>", "@QHash<@QString, @QList<int> >") + % Check("hash.0", "[0]", "", "@QHashNode<@QString, @QList<int>>") + % Check("hash.0.key", "\"Hallo\"", "@QString") + % Check("hash.0.value", "<0 items>", "@QList<int>") + % Check("hash.1", "[1]", "", "@QHashNode<@QString, @QList<int>>") + % Check("hash.1.key", "key", "\"Welt\"", "@QString") + % Check("hash.1.value", "value", "<1 items>", "@QList<int>") + % Check("hash.1.value.0", "[0]", "1", "int") + % Check("hash.2", "[2]", "", "@QHashNode<@QString, @QList<int>>") + % Check("hash.2.key", "key", "\"!\"", "@QString") + % Check("hash.2.value", "value", "<2 items>", "@QList<int>") + % Check("hash.2.value.0", "[0]", "1", "int") + % Check("hash.2.value.1", "[1]", "2", "int"); + + QTest::newRow("QHash2") + << Data("#include <QHash>\n", + "QHash<int, float> hash;\n" + "hash[11] = 11.0;\n" + "hash[22] = 22.0;\n") + % Check("hash", "hash", "<2 items>", "@QHash<int, float>") + % Check("hash.22", "[22]", "22", "float") + % Check("hash.11", "[11]", "11", "float"); + + QTest::newRow("QHash3") + << Data("#include <QHash>\n", + "QHash<QString, int> hash;\n" + "hash[\"22.0\"] = 22.0;\n" + "hash[\"123.0\"] = 22.0;\n" + "hash[\"111111ss111128.0\"] = 28.0;\n" + "hash[\"11124.0\"] = 22.0;\n" + "hash[\"1111125.0\"] = 22.0;\n" + "hash[\"11111126.0\"] = 22.0;\n" + "hash[\"111111127.0\"] = 27.0;\n" + "hash[\"111111111128.0\"] = 28.0;\n" + "hash[\"111111111111111111129.0\"] = 29.0;\n") + % Check("hash", "hash", "<9 items>", "@QHash<@QString, int>") + % Check("hash.0", "[0]", "", "@QHashNode<@QString, int>") + % Check("hash.0.key", "key", "\"123.0\"", "@QString") + % Check("hash.0.value", "22", "int") + % Check("hash.8", "[8]", "", "@QHashNode<@QString, int>") + % Check("hash.8.key", "key", "\"11124.0\"", "@QString") + % Check("hash.8.value", "value", "22", "int"); + + QTest::newRow("QHash4") + << Data("#include <QHash>\n", + "QHash<QByteArray, float> hash;\n" + "hash[\"22.0\"] = 22.0;\n" + "hash[\"123.0\"] = 22.0;\n" + "hash[\"111111ss111128.0\"] = 28.0;\n" + "hash[\"11124.0\"] = 22.0;\n" + "hash[\"1111125.0\"] = 22.0;\n" + "hash[\"11111126.0\"] = 22.0;\n" + "hash[\"111111127.0\"] = 27.0;\n" + "hash[\"111111111128.0\"] = 28.0;\n" + "hash[\"111111111111111111129.0\"] = 29.0;\n") + % Check("hash", "<9 items>", "@QHash<@QByteArray, float>") + % Check("hash.0", "[0]", "", "@QHashNode<@QByteArray, float>") + % Check("hash.0.key", "\"123.0\"", "@QByteArray") + % Check("hash.0.value", "22", "float") + % Check("hash.8", "[8]", "", "@QHashNode<@QByteArray, float>") + % Check("hash.8.key", "\"11124.0\"", "@QByteArray") + % Check("hash.8.value", "22", "float"); + + QTest::newRow("QHash5") + << Data("#include <QHash>\n", + "QHash<int, QString> hash;\n" + "hash[22] = \"22.0\";\n") + % Check("hash", "<1 items>", "@QHash<int, @QString>") + % Check("hash.0", "[0]", "", "@QHashNode<int, @QString>") + % Check("hash.0.key", "22", "int") + % Check("hash.0.value", "\"22.0\"", "@QString"); + + QTest::newRow("QHash6") + << Data("#include <QHash>\n" + fooData, + "QHash<QString, Foo> hash;\n" + "hash[\"22.0\"] = Foo(22);\n" + "hash[\"33.0\"] = Foo(33);\n") + % Check("hash", "<2 items>", "@QHash<@QString, Foo>") + % Check("hash.0", "[0]", "", "@QHashNode<@QString, Foo>") + % Check("hash.0.key", "\"22.0\"", "@QString") + % CheckType("hash.0.value", "Foo") + % Check("hash.0.value.a", "22", "int") + % Check("hash.1", "[1]", "", "@QHashNode<@QString, Foo>") + % Check("hash.1.key", "\"33.0\"", "@QString") + % CheckType("hash.1.value", "Foo"); + + QTest::newRow("QHash7") + << Data("#include <QHash>\n" + "#include <QPointer>\n", + "QObject ob;\n" + "QHash<QString, QPointer<QObject> > hash;\n" + "hash.insert(\"Hallo\", QPointer<QObject>(&ob));\n" + "hash.insert(\"Welt\", QPointer<QObject>(&ob));\n" + "hash.insert(\".\", QPointer<QObject>(&ob));\n") + % Check("hash", "<3 items>", "@QHash<@QString, @QPointer<@QObject>>") + % Check("hash.0", "[0]", "", "@QHashNode<@QString, @QPointer<@QObject>>") + % Check("hash.0.key", "\"Hallo\"", "@QString") + % CheckType("hash.0.value", "@QPointer<@QObject>") + % CheckType("hash.0.value.o", "@QObject") + % Check("hash.2", "[2]", "", "@QHashNode<@QString, @QPointer<@QObject>>") + % Check("hash.2.key", "\".\"", "@QString") + % CheckType("hash.2.value", "@QPointer<@QObject>"); + + QTest::newRow("QHashIntFloatIterator") + << Data("#include <QHash>\n", + "typedef QHash<int, float> Hash;\n" + "Hash hash;\n" + "hash[11] = 11.0;\n" + "hash[22] = 22.0;\n" + "hash[33] = 33.0;\n" + "hash[44] = 44.0;\n" + "hash[55] = 55.0;\n" + "hash[66] = 66.0;\n" + "Hash::iterator it1 = hash.begin();\n" + "Hash::iterator it2 = it1; ++it2;\n" + "Hash::iterator it3 = it2; ++it3;\n" + "Hash::iterator it4 = it3; ++it4;\n" + "Hash::iterator it5 = it4; ++it5;\n" + "Hash::iterator it6 = it5; ++it6;\n") + % Check("hash", "<6 items>", "Hash") + % Check("hash.11", "[11]", "11", "float") + % Check("it1.key", "55", "int") + % Check("it1.value", "55", "float") + % Check("it6.key", "33", "int") + % Check("it6.value", "33", "float"); + + QTest::newRow("QHostAddress") + << Data("#include <QHostAddress>\n", + "QHostAddress ha1(129u * 256u * 256u * 256u + 130u);\n" + "QHostAddress ha2(\"127.0.0.1\");\n") + % Profile("QT += network\n") + % Check("ha1", "129.0.0.130", "@QHostAddress") + % Check("ha2", "\"127.0.0.1\"", "@QHostAddress"); + + QTest::newRow("QImage") + << Data("#include <QImage>\n" + "#include <QPainter>\n", + "QImage im(QSize(200, 200), QImage::Format_RGB32);\n" + "im.fill(QColor(200, 100, 130).rgba());\n" + "QPainter pain;\n" + "pain.begin(&im);\n") + % GuiProfile() + % Check("im", "(200x200)", "@QImage") + % CheckType("pain", "@QPainter"); + + QTest::newRow("QPixmap") + << Data("#include <QImage>\n" + "#include <QPainter>\n" + "#include <QApplication>\n", + "QApplication app(argc, argv);\n" + "QImage im(QSize(200, 200), QImage::Format_RGB32);\n" + "im.fill(QColor(200, 100, 130).rgba());\n" + "QPainter pain;\n" + "pain.begin(&im);\n" + "pain.drawLine(2, 2, 130, 130);\n" + "pain.end();\n" + "QPixmap pm = QPixmap::fromImage(im);\n" + "dummyStatement(&pm);\n") + % GuiProfile() + % Check("im", "(200x200)", "@QImage") + % CheckType("pain", "@QPainter") + % Check("pm", "(200x200)", "@QPixmap"); + + QTest::newRow("QLinkedListInt") + << Data("#include <QLinkedList>\n", + "QLinkedList<int> list;\n" + "list.append(101);\n" + "list.append(102);\n") + % Check("list", "<2 items>", "@QLinkedList<int>") + % Check("list.0", "[0]", "101", "int") + % Check("list.1", "[1]", "102", "int"); + + QTest::newRow("QLinkedListUInt") + << Data("#include <QLinkedList>\n", + "QLinkedList<uint> list;\n" + "list.append(103);\n" + "list.append(104);\n") + % Check("list", "<2 items>", "@QLinkedList<unsigned int>") + % Check("list.0", "[0]", "103", "unsigned int") + % Check("list.1", "[1]", "104", "unsigned int"); + + QTest::newRow("QLinkedListFooStar") + << Data("#include <QLinkedList>\n" + fooData, + "QLinkedList<Foo *> list;\n" + "list.append(new Foo(1));\n" + "list.append(0);\n" + "list.append(new Foo(3));\n") + % Check("list", "<3 items>", "@QLinkedList<Foo*>") + % CheckType("list.0", "[0]", "Foo") + % Check("list.0.a", "1", "int") + % Check("list.1", "[1]", "0x0", "Foo *") + % CheckType("list.2", "[2]", "Foo") + % Check("list.2.a", "3", "int"); + + QTest::newRow("QLinkedListULongLong") + << Data("#include <QLinkedList>\n", + "QLinkedList<qulonglong> list;\n" + "list.append(42);\n" + "list.append(43);\n") + % Check("list", "<2 items>", "@QLinkedList<unsigned long long>") + % Check("list.0", "[0]", "42", "unsigned long long") + % Check("list.1", "[1]", "43", "unsigned long long"); + + QTest::newRow("QLinkedListFoo") + << Data("#include <QLinkedList>\n" + fooData, + "QLinkedList<Foo> list;\n" + "list.append(Foo(1));\n" + "list.append(Foo(2));\n") + % Check("list", "<2 items>", "@QLinkedList<Foo>") + % CheckType("list.0", "[0]", "Foo") + % Check("list.0.a", "1", "int") + % CheckType("list.1", "[1]", "Foo") + % Check("list.1.a", "2", "int"); + + QTest::newRow("QLinkedListStdString") + << Data("#include <QLinkedList>\n" + "#include <string>\n", + "QLinkedList<std::string> list;\n" + "list.push_back(\"aa\");\n" + "list.push_back(\"bb\");\n") + % Check("list", "<2 items>", "@QLinkedList<std::string>") + % Check("list.0", "[0]", "\"aa\"", "std::string") + % Check("list.1", "[1]", "\"bb\"", "std::string"); + + QTest::newRow("QListInt") + << Data("#include <QList>\n", + "QList<int> big;\n" + "for (int i = 0; i < 10000; ++i)\n" + " big.push_back(i);\n") + % Check("big", "<10000 items>", "@QList<int>") + % Check("big.0", "[0]", "0", "int") + % Check("big.1999", "[1999]", "1999", "int"); + + QTest::newRow("QListIntTakeFirst") + << Data("#include <QList>\n", + "QList<int> l;\n" + "l.append(0);\n" + "l.append(1);\n" + "l.append(2);\n" + "l.takeFirst();\n") + % Check("l", "<2 items>", "@QList<int>") + % Check("l.0", "[0]", "1", "int"); + + QTest::newRow("QListStringTakeFirst") + << Data("#include <QList>\n" + "#include <QString>\n", + "QList<QString> l;\n" + "l.append(\"0\");\n" + "l.append(\"1\");\n" + "l.append(\"2\");\n" + "l.takeFirst();\n") + % Check("l", "<2 items>", "@QList<@QString>") + % Check("l.0", "[0]", "\"1\"", "@QString"); + + QTest::newRow("QStringListTakeFirst") + << Data("#include <QStringList>\n", + "QStringList l;\n" + "l.append(\"0\");\n" + "l.append(\"1\");\n" + "l.append(\"2\");\n" + "l.takeFirst();\n") + % Check("l", "<2 items>", "@QStringList") + % Check("l.0", "[0]", "\"1\"", "@QString"); + + QTest::newRow("QListIntStar") + << Data("#include <QList>\n", + "QList<int *> l0, l;\n" + "l.append(new int(1));\n" + "l.append(new int(2));\n" + "l.append(new int(3));\n") + % Check("l0", "<0 items>", "@QList<int*>") + % Check("l", "<3 items>", "@QList<int*>") + % CheckType("l.0", "[0]", "int") + % CheckType("l.2", "[2]", "int"); + + QTest::newRow("QListUInt") + << Data("#include <QList>\n", + "QList<uint> l0,l;\n" + "l.append(101);\n" + "l.append(102);\n" + "l.append(102);\n") + % Check("l0", "<0 items>", "@QList<unsigned int>") + % Check("l", "<3 items>", "@QList<unsigned int>") + % Check("l.0", "[0]", "101", "unsigned int") + % Check("l.2", "[2]", "102", "unsigned int"); + + QTest::newRow("QListUShort") + << Data("#include <QList>\n", + "QList<ushort> l0,l;\n" + "l.append(101);\n" + "l.append(102);\n" + "l.append(102);\n") + % Check("l0", "<0 items>", "@QList<unsigned short>") + % Check("l", "<3 items>", "@QList<unsigned short>") + % Check("l.0", "[0]", "101", "unsigned short") + % Check("l.2", "[2]", "102", "unsigned short"); + + QTest::newRow("QListQChar") + << Data("#include <QList>\n" + "#include <QChar>\n", + "QList<QChar> l0, l;\n" + "l.append(QChar('a'));\n" + "l.append(QChar('b'));\n" + "l.append(QChar('c'));\n") + % Check("l0", "<0 items>", "@QList<@QChar>") + % Check("l", "<3 items>", "@QList<@QChar>") + % Check("l.0", "[0]", "'a' (97)", "@QChar") + % Check("l.2", "[2]", "'c' (99)", "@QChar"); + + QTest::newRow("QListQULongLong") + << Data("#include <QList>\n", + "QList<qulonglong> l0, l;\n" + "l.append(101);\n" + "l.append(102);\n" + "l.append(102);\n") + % Check("l0", "<0 items>", "@QList<unsigned long long>") + % Check("l", "<3 items>", "@QList<unsigned long long>") + % Check("l.0", "[0]", "101", "unsigned long long") + % Check("l.2", "[2]", "102", "unsigned long long"); + + QTest::newRow("QListStdString") + << Data("#include <QList>\n" + "#include <string>\n", + "QList<std::string> l0, l;\n" + "l.push_back(\"aa\");\n" + "l.push_back(\"bb\");\n" + "l.push_back(\"cc\");\n" + "l.push_back(\"dd\");") + % Check("l0", "<0 items>", "@QList<std::string>") + % Check("l", "<4 items>", "@QList<std::string>") + % CheckType("l.0", "[0]", "std::string") + % Check("l.3", "[3]" ,"\"dd\"", "std::string"); + + QTest::newRow("QListFoo") + << Data("#include <QList>\n" + fooData, + "QList<Foo> l0, l;\n" + "for (int i = 0; i < 100; ++i)\n" + " l.push_back(i + 15);\n") + % Check("l0", "<0 items>", "@QList<Foo>") + % Check("l", "<100 items>", "@QList<Foo>") + % Check("l.0", "[0]", "", "Foo") + % Check("l.99", "[99]", "", "Foo"); + + QTest::newRow("QListReverse") + << Data("#include <QList>\n", + "QList<int> l = QList<int>() << 1 << 2 << 3;\n" + "typedef std::reverse_iterator<QList<int>::iterator> Reverse;\n" + "Reverse rit(l.end());\n" + "Reverse rend(l.begin());\n" + "QList<int> r;\n" + "while (rit != rend)\n" + " r.append(*rit++);\n") + % Check("l", "<3 items>", "@QList<int>") + % Check("l.0", "[0]", "1", "int") + % Check("l.1", "[1]", "2", "int") + % Check("l.2", "[2]", "3", "int") + % Check("r", "<3 items>", "@QList<int>") + % Check("r.0", "[0]", "3", "int") + % Check("r.1", "[1]", "2", "int") + % Check("r.2", "[2]", "1", "int") + % Check("rend", "", "Reverse") + % Check("rit", "", "Reverse"); + + QTest::newRow("QLocale") + << Data("#include <QLocale>\n", + "QLocale loc = QLocale::system();\n" + "QLocale::MeasurementSystem m = loc.measurementSystem();\n" + "dummyStatement(&m);\n") + % Check("loc", "", "@QLocale") + % Check("m", "", "@QLocale::MeasurementSystem"); + + + QTest::newRow("QMapUIntStringList") + << Data("#include <QMap>\n" + "#include <QStringList>\n", + "QMap<uint, QStringList> map;\n" + "map[11] = QStringList() << \"11\";\n" + "map[22] = QStringList() << \"22\";\n") + % Check("map", "<2 items>", "@QMap<unsigned int, @QStringList>") + % Check("map.0", "[0]", "", "@QMapNode<unsigned int, @QStringList>") + % Check("map.0.key", "11", "unsigned int") + % Check("map.0.value", "<1 items>", "@QStringList") + % Check("map.0.value.0", "[0]", "\"11\"", "@QString") + % Check("map.1", "[1]", "", "@QMapNode<unsigned int, @QStringList>") + % Check("map.1.key", "22", "unsigned int") + % Check("map.1.value", "<1 items>", "@QStringList") + % Check("map.1.value.0", "[0]", "\"22\"", "@QString"); + + QTest::newRow("QMapUIntStringListTypedef") + << Data("#include <QMap>\n" + "#include <QStringList>\n", + "typedef QMap<uint, QStringList> T;\n" + "T map;\n" + "map[11] = QStringList() << \"11\";\n" + "map[22] = QStringList() << \"22\";\n") + % Check("map", "<2 items>", "T") + % Check("map.0", "[0]", "", "@QMapNode<unsigned int, @QStringList>"); + + QTest::newRow("QMapUIntFloat") + << Data("#include <QMap>\n", + "QMap<uint, float> map;\n" + "map[11] = 11.0;\n" + "map[22] = 22.0;\n") + % Check("map", "<2 items>", "@QMap<unsigned int, float>") + % Check("map.11", "[11]", "11", "float") + % Check("map.22", "[22]", "22", "float"); + + QTest::newRow("QMapStringFloat") + << Data("#include <QMap>\n" + "#include <QString>\n", + "QMap<QString, float> map;\n" + "map[\"22.0\"] = 22.0;\n") + % Check("map", "<1 items>", "@QMap<@QString, float>") + % Check("map.0", "[0]", "", "@QMapNode<@QString, float>") + % Check("map.0.key", "\"22.0\"", "@QString") + % Check("map.0.value", "22", "float"); + + QTest::newRow("QMapIntString") + << Data("#include <QMap>\n" + "#include <QString>\n", + "QMap<int, QString> map;\n" + "map[22] = \"22.0\";\n") + % Check("map", "<1 items>", "@QMap<int, @QString>") + % Check("map.0", "[0]", "", "@QMapNode<int, @QString>") + % Check("map.0.key", "22", "int") + % Check("map.0.value", "\"22.0\"", "@QString"); + + QTest::newRow("QMapStringFoo") + << Data("#include <QMap>\n" + fooData + + "#include <QString>\n", + "QMap<QString, Foo> map;\n" + "map[\"22.0\"] = Foo(22);\n" + "map[\"33.0\"] = Foo(33);\n") + % Check("map", "<2 items>", "@QMap<@QString, Foo>") + % Check("map.0", "[0]", "", "@QMapNode<@QString, Foo>") + % Check("map.0.key", "\"22.0\"", "@QString") + % Check("map.0.value", "", "Foo") + % Check("map.0.value.a", "22", "int") + % Check("map.1", "[1]", "", "@QMapNode<@QString, Foo>") + % Check("map.1.key", "\"33.0\"", "@QString") + % Check("map.1.value", "", "Foo") + % Check("map.1.value.a", "33", "int"); + + QTest::newRow("QMapStringPointer") + << Data("#include <QMap>\n" + "#include <QObject>\n" + "#include <QPointer>\n" + "#include <QString>\n", + "QObject ob;\n" + "QMap<QString, QPointer<QObject> > map;\n" + "map.insert(\"Hallo\", QPointer<QObject>(&ob));\n" + "map.insert(\"Welt\", QPointer<QObject>(&ob));\n" + "map.insert(\".\", QPointer<QObject>(&ob));\n") + % Check("map", "<3 items>", "@QMap<@QString, @QPointer<@QObject>>") + % Check("map.0", "[0]", "", "@QMapNode<@QString, @QPointer<@QObject>>") + % Check("map.0.key", "\".\"", "@QString") + % Check("map.0.value", "", "@QPointer<@QObject>") + % Check("map.0.value.o", "", "@QObject") + % Check("map.1", "[1]", "", "@QMapNode<@QString, @QPointer<@QObject>>") + % Check("map.1.key", "\"Hallo\"", "@QString") + % Check("map.2", "[2]", "", "@QMapNode<@QString, @QPointer<@QObject>>") + % Check("map.2.key", "\"Welt\"", "@QString"); + + QTest::newRow("QMapStringList") + << Data("#include <QMap>\n" + "#include <QList>\n" + "#include <QString>\n" + nsData, + "QList<nsA::nsB::SomeType *> x;\n" + "x.append(new nsA::nsB::SomeType(1));\n" + "x.append(new nsA::nsB::SomeType(2));\n" + "x.append(new nsA::nsB::SomeType(3));\n" + "QMap<QString, QList<nsA::nsB::SomeType *> > map;\n" + "map[\"foo\"] = x;\n" + "map[\"bar\"] = x;\n" + "map[\"1\"] = x;\n" + "map[\"2\"] = x;\n") + % Check("map", "<4 items>", "@QMap<@QString, @QList<nsA::nsB::SomeType*>>") + % Check("map.0", "[0]", "", "@QMapNode<@QString, @QList<nsA::nsB::SomeType*>>") + % Check("map.0.key", "\"1\"", "@QString") + % Check("map.0.value", "<3 items>", "@QList<nsA::nsB::SomeType*>") + % Check("map.0.value.0", "[0]", "", "nsA::nsB::SomeType") + % Check("map.0.value.0.a", "1", "int") + % Check("map.0.value.1", "[1]", "", "nsA::nsB::SomeType") + % Check("map.0.value.1.a", "2", "int") + % Check("map.0.value.2", "[2]", "", "nsA::nsB::SomeType") + % Check("map.0.value.2.a", "3", "int") + % Check("map.3", "[3]", "", "@QMapNode<@QString, @QList<nsA::nsB::SomeType*>>") + % Check("map.3.key", "\"foo\"", "@QString") + % Check("map.3.value", "<3 items>", "@QList<nsA::nsB::SomeType*>") + % Check("map.3.value.2", "[2]", "", "nsA::nsB::SomeType") + % Check("map.3.value.2.a", "3", "int") + % Check("x", "<3 items>", "@QList<nsA::nsB::SomeType*>"); + + QTest::newRow("QMultiMapUintFloat") + << Data("#include <QMap>\n", + "QMultiMap<uint, float> map;\n" + "map.insert(11, 11.0);\n" + "map.insert(22, 22.0);\n" + "map.insert(22, 33.0);\n" + "map.insert(22, 34.0);\n" + "map.insert(22, 35.0);\n" + "map.insert(22, 36.0);\n") + % Check("map", "<6 items>", "@QMultiMap<unsigned int, float>") + % Check("map.0", "[0]", "11", "float") + % Check("map.5", "[5]", "22", "float"); + + QTest::newRow("QMultiMapStringFloat") + << Data("#include <QMap>\n" + "#include <QString>\n", + "QMultiMap<QString, float> map;\n" + "map.insert(\"22.0\", 22.0);\n") + % Check("map", "<1 items>", "@QMultiMap<@QString, float>") + % Check("map.0", "[0]", "", "@QMapNode<@QString, float>") + % Check("map.0.key", "\"22.0\"", "@QString") + % Check("map.0.value", "22", "float"); + + QTest::newRow("QMultiMapIntString") + << Data("#include <QMap>\n" + "#include <QString>\n", + "QMultiMap<int, QString> map;\n" + "map.insert(22, \"22.0\");\n") + % Check("map", "<1 items>", "@QMultiMap<int, @QString>") + % Check("map.0", "[0]", "", "@QMapNode<int, @QString>") + % Check("map.0.key", "22", "int") + % Check("map.0.value", "\"22.0\"", "@QString"); + + QTest::newRow("QMultiMapStringFoo") + << Data("#include <QMultiMap>\n" + fooData, + "QMultiMap<QString, Foo> map;\n" + "map.insert(\"22.0\", Foo(22));\n" + "map.insert(\"33.0\", Foo(33));\n" + "map.insert(\"22.0\", Foo(22));\n") + % Check("map", "<3 items>", "@QMultiMap<@QString, Foo>") + % Check("map.0", "[0]", "", "@QMapNode<@QString, Foo>") + % Check("map.0.key", "\"22.0\"", "@QString") + % Check("map.0.value", "", "Foo") + % Check("map.0.value.a", "22", "int") + % Check("map.2", "[2]", "", "@QMapNode<@QString, Foo>"); + + QTest::newRow("QMultiMapStringPointer") + << Data("#include <QMap>\n" + "#include <QObject>\n" + "#include <QPointer>\n" + "#include <QString>\n", + "QObject ob;\n" + "QMultiMap<QString, QPointer<QObject> > map;\n" + "map.insert(\"Hallo\", QPointer<QObject>(&ob));\n" + "map.insert(\"Welt\", QPointer<QObject>(&ob));\n" + "map.insert(\".\", QPointer<QObject>(&ob));\n" + "map.insert(\".\", QPointer<QObject>(&ob));\n") + % Check("map", "<4 items>", "@QMultiMap<@QString, @QPointer<@QObject>>") + % Check("map.0", "[0]", "", "@QMapNode<@QString, @QPointer<@QObject>>") + % Check("map.0.key", "\".\"", "@QString") + % Check("map.0.value", "", "@QPointer<@QObject>") + % Check("map.1", "[1]", "", "@QMapNode<@QString, @QPointer<@QObject>>") + % Check("map.1.key", "\".\"", "@QString") + % Check("map.2", "[2]", "", "@QMapNode<@QString, @QPointer<@QObject>>") + % Check("map.2.key", "\"Hallo\"", "@QString") + % Check("map.3", "[3]", "", "@QMapNode<@QString, @QPointer<@QObject>>") + % Check("map.3.key", "\"Welt\"", "@QString"); + + + QTest::newRow("QObject1") + << Data("#include <QObject>\n", + "QObject parent;\n" + "parent.setObjectName(\"A Parent\");\n" + "QObject child(&parent);\n" + "child.setObjectName(\"A Child\");\n" + "QObject::connect(&child, SIGNAL(destroyed()), &parent, SLOT(deleteLater()));\n" + "QObject::disconnect(&child, SIGNAL(destroyed()), &parent, SLOT(deleteLater()));\n" + "child.setObjectName(\"A renamed Child\");\n") + % Check("child", "\"A renamed Child\"", "@QObject") + % Check("parent", "\"A Parent\"", "@QObject"); + + QByteArray objectData = + "#include <QWidget>\n" + " namespace Names {\n" + " namespace Bar {\n" + " struct Ui { Ui() { w = 0; } QWidget *w; };\n" + " class TestObject : public QObject\n" + " {\n" + " Q_OBJECT\n" + " public:\n" + " TestObject(QObject *parent = 0)\n" + " : QObject(parent)\n" + " {\n" + " m_ui = new Ui;\n" + " #if USE_GUILIB\n" + " m_ui->w = new QWidget;\n" + " #else\n" + " m_ui->w = 0;\n" + " #endif\n" + " }\n" + " Q_PROPERTY(QString myProp1 READ myProp1 WRITE setMyProp1)\n" + " QString myProp1() const { return m_myProp1; }\n" + " Q_SLOT void setMyProp1(const QString&mt) { m_myProp1 = mt; }\n" + " Q_PROPERTY(QString myProp2 READ myProp2 WRITE setMyProp2)\n" + " QString myProp2() const { return m_myProp2; }\n" + " Q_SLOT void setMyProp2(const QString&mt) { m_myProp2 = mt; }\n" + " public:\n" + " Ui *m_ui;\n" + " QString m_myProp1;\n" + " QString m_myProp2;\n" + " };\n" + " } // namespace Bar\n" + " } // namespace Names\n" + "\n"; + + QTest::newRow("QObject2") + << Data(objectData, + "Names::Bar::TestObject test;\n" + "test.setMyProp1(\"HELLO\");\n" + "test.setMyProp2(\"WORLD\");\n" + "QString s = test.myProp1();\n" + "s += test.myProp2();\n") + % Check("s", "\"HELLOWORLD\"", "@QString") + % Check("test", "", "Names::Bar::TestObject"); + + QTest::newRow("QObject2") + << Data("QWidget ob;\n" + "ob.setObjectName(\"An Object\");\n" + "ob.setProperty(\"USER DEFINED 1\", 44);\n" + "ob.setProperty(\"USER DEFINED 2\", QStringList() << \"FOO\" << \"BAR\");\n" + "" + "QObject ob1;\n" + "ob1.setObjectName(\"Another Object\");\n" + "QObject::connect(&ob, SIGNAL(destroyed()), &ob1, SLOT(deleteLater()));\n" + "QObject::connect(&ob, SIGNAL(destroyed()), &ob1, SLOT(deleteLater()));\n" + "//QObject::connect(&app, SIGNAL(lastWindowClosed()), &ob, SLOT(deleteLater()));\n" + "" + "QList<QObject *> obs;\n" + "obs.append(&ob);\n" + "obs.append(&ob1);\n" + "obs.append(0);\n" + "obs.append(&app);\n" + "ob1.setObjectName(\"A Subobject\");\n") + % GuiProfile() + % Check("ob", "An Object", "@QObject"); + + QByteArray senderData = + " class Sender : public QObject\n" + " {\n" + " Q_OBJECT\n" + " public:\n" + " Sender() { setObjectName(\"Sender\"); }\n" + " void doEmit() { emit aSignal(); }\n" + " signals:\n" + " void aSignal();\n" + " };\n" + "\n" + " class Receiver : public QObject\n" + " {\n" + " Q_OBJECT\n" + " public:\n" + " Receiver() { setObjectName(\"Receiver\"); }\n" + " public slots:\n" + " void aSlot() {\n" + " QObject *s = sender();\n" + " if (s) {\n" + " qDebug() << \"SENDER: \" << s;\n" + " } else {\n" + " qDebug() << \"NO SENDER\";\n" + " }\n" + " }\n" + " };\n"; + + QByteArray derivedData = + " class DerivedObjectPrivate : public QObjectPrivate\n" + " {\n" + " public:\n" + " DerivedObjectPrivate() {\n" + " m_extraX = 43;\n" + " m_extraY.append(\"xxx\");\n" + " m_extraZ = 1;\n" + " }\n" + " int m_extraX;\n" + " QStringList m_extraY;\n" + " uint m_extraZ : 1;\n" + " bool m_extraA : 1;\n" + " bool m_extraB;\n" + " };\n" + "\n" + " class DerivedObject : public QObject\n" + " {\n" + " Q_OBJECT\n" + "\n" + " public:\n" + " DerivedObject() : QObject(*new DerivedObjectPrivate, 0) {}\n" + "\n" + " Q_PROPERTY(int x READ x WRITE setX)\n" + " Q_PROPERTY(QStringList y READ y WRITE setY)\n" + " Q_PROPERTY(uint z READ z WRITE setZ)\n" + "\n" + " int x() const;\n" + " void setX(int x);\n" + " QStringList y() const;\n" + " void setY(QStringList y);\n" + " uint z() const;\n" + " void setZ(uint z);\n" + "\n" + " private:\n" + " Q_DECLARE_PRIVATE(DerivedObject)\n" + " };\n" + "\n" + " int DerivedObject::x() const\n" + " {\n" + " Q_D(const DerivedObject);\n" + " return d->m_extraX;\n" + " }\n" + "\n" + " void DerivedObject::setX(int x)\n" + " {\n" + " Q_D(DerivedObject);\n" + " d->m_extraX = x;\n" + " d->m_extraA = !d->m_extraA;\n" + " d->m_extraB = !d->m_extraB;\n" + " }\n" + "\n" + " QStringList DerivedObject::y() const\n" + " {\n" + " Q_D(const DerivedObject);\n" + " return d->m_extraY;\n" + " }\n" + "\n" + " void DerivedObject::setY(QStringList y)\n" + " {\n" + " Q_D(DerivedObject);\n" + " d->m_extraY = y;\n" + " }\n" + "\n" + " uint DerivedObject::z() const\n" + " {\n" + " Q_D(const DerivedObject);\n" + " return d->m_extraZ;\n" + " }\n" + "\n" + " void DerivedObject::setZ(uint z)\n" + " {\n" + " Q_D(DerivedObject);\n" + " d->m_extraZ = z;\n" + " }\n" + "\n" + " #endif\n" + "\n"; + + QTest::newRow("QObjectData") + << Data(derivedData, + "DerivedObject ob;\n" + "ob.setX(26);\n") + % Check("ob.properties.x", "26", "@QVariant (int)"); + + + QTest::newRow("QRegExp") + << Data("#include <QRegExp>\n", + "QRegExp re(QString(\"a(.*)b(.*)c\"));\n" + "QString str1 = \"a1121b344c\";\n" + "QString str2 = \"Xa1121b344c\";\n" + "int pos2 = re.indexIn(str2);\n" + "int pos1 = re.indexIn(str1);\n") + % Check("re", "\"a(.*)b(.*)c\"", "@QRegExp") + % Check("str1", "\"a1121b344c\"", "@QString") + % Check("str2", "\"Xa1121b344c\"", "@QString") + % Check("pos1", "0", "int") + % Check("pos2", "1", "int"); + + QTest::newRow("QPoint") + << Data("#include <QPoint>\n", + "QPoint s0, s;\n" + "s = QPoint(100, 200);\n") + % Check("s0", "(0, 0)", "@QPoint") + % Check("s", "(100, 200)", "@QPoint"); + + QTest::newRow("QPointF") + << Data("#include <QPointF>\n", + "QPointF s0, s;\n" + "s = QPointF(100, 200);\n") + % Check("s0", "(0, 0)", "@QPointF") + % Check("s", "(100, 200)", "@QPointF"); + + QTest::newRow("QRect") + << Data("#include <QRect>\n", + "QRect rect0, rect;\n" + "rect = QRect(100, 100, 200, 200);\n") + % Check("rect", "0x0+0+0", "@QRect") + % Check("rect", "200x200+100+100", "@QRect"); + + QTest::newRow("QRectF") + << Data("#include <QRectF>\n", + "QRectF rect0, rect;\n" + "rect = QRectF(100, 100, 200, 200);\n") + % Check("rect", "0x0+0+0", "@QRectF") + % Check("rect", "200x200+100+100", "@QRectF"); + + QTest::newRow("QSize") + << Data("#include <QSize>\n", + "QSize s0, s;\n" + "s = QSize(100, 200);\n") + % Check("s0", "(-1, -1)", "@QSize") + % Check("s", "(100, 200)", "@QSize"); + + QTest::newRow("QSizeF") + << Data("#include <QSizeF>\n", + "QSizeF s0, s;\n" + "s = QSizeF(100, 200);\n") + % Check("s0", "(-1, -1)", "@QSizeF") + % Check("s", "(100, 200)", "@QSizeF"); + + QTest::newRow("QRegion") + << Data("#include <QRegion>\n", + "QRegion region, region0, region1, region2, region4;\n" + "region += QRect(100, 100, 200, 200);\n" + "region0 = region;\n" + "region += QRect(300, 300, 400, 500);\n" + "region1 = region;\n" + "region += QRect(500, 500, 600, 600);\n" + "region2 = region;\n") + % Check("region", "<empty>", "@QRegion") + % Check("region", "<1 items>", "@QRegion") + % Check("region.extents", "", "@QRect") + % Check("region.innerArea", "40000", "int") + % Check("region.innerRect", "", "@QRect") + % Check("region.numRects", "1", "int") + % Check("region.rects", "<0 items>", "@QVector<@QRect>") + % Check("region", "<2 items>", "@QRegion") + % Check("region.extents", "", "@QRect") + % Check("region.innerArea", "200000", "int") + % Check("region.innerRect", "", "@QRect") + % Check("region.numRects", "2", "int") + % Check("region.rects", "<2 items>", "@QVector<@QRect>") + % Check("region", "<4 items>", "@QRegion") + % Check("region.extents", "", "@QRect") + % Check("region.innerArea", "360000", "int") + % Check("region.innerRect", "", "@QRect") + % Check("region.numRects", "4", "int") + % Check("region.rects", "<8 items>", "@QVector<@QRect>") + % Check("region", "<4 items>", "@QRegion"); + + QTest::newRow("QSettings") + << Data("#include <QRegExp>\n", + "QCoreApplication app(argc, argv);\n" + "QSettings settings(\"/tmp/test.ini\", QSettings::IniFormat);\n" + "QVariant value = settings.value(\"item1\", \"\").toString();\n") + % Check("settings", "", "@QSettings") + % Check("settings.@1", "", "@QObject") + % Check("value", "", "@QVariant (QString)"); + + QTest::newRow("QSet1") + << Data("#include <QRegExp>\n", + "QSet<int> s;\n" + "s.insert(11);\n" + "s.insert(22);\n") + % Check("s", "<2 items>", "@QSet<int>") + % Check("s.22", "22", "int") + % Check("s.11", "11", "int"); + + QTest::newRow("QSet2") + << Data("#include <QSet>\n" + "#include <QString>\n", + "QSet<QString> s;\n" + "s.insert(\"11.0\");\n" + "s.insert(\"22.0\");\n") + % Check("s", "<2 items>", "@QSet<@QString>") + % Check("s.0", "[0]", "\"11.0\"", "@QString") + % Check("s.1", "[1]", "\"22.0\"", "@QString"); + + QTest::newRow("QSet3") + << Data("#include <QObject>\n" + "#include <QPointer>\n" + "#include <QSet>\n", + "QObject ob;\n" + "QSet<QPointer<QObject> > s;\n" + "QPointer<QObject> ptr(&ob);\n" + "s.insert(ptr);\n" + "s.insert(ptr);\n" + "s.insert(ptr);\n") + % Check("s", "<1 items>", "@QSet<@QPointer<@QObject>>") + % Check("s.0", "[0]", "", "@QPointer<@QObject>"); + + + QByteArray sharedData = + " class EmployeeData : public QSharedData\n" + " {\n" + " public:\n" + " EmployeeData() : id(-1) { name.clear(); }\n" + " EmployeeData(const EmployeeData &other)\n" + " : QSharedData(other), id(other.id), name(other.name) { }\n" + " ~EmployeeData() { }\n" + "\n" + " int id;\n" + " QString name;\n" + " };\n" + "\n" + " class Employee\n" + " {\n" + " public:\n" + " Employee() { d = new EmployeeData; }\n" + " Employee(int id, QString name) {\n" + " d = new EmployeeData;\n" + " setId(id);\n" + " setName(name);\n" + " }\n" + " Employee(const Employee &other)\n" + " : d (other.d)\n" + " {\n" + " }\n" + " void setId(int id) { d->id = id; }\n" + " void setName(QString name) { d->name = name; }\n" + "\n" + " int id() const { return d->id; }\n" + " QString name() const { return d->name; }\n" + "\n" + " private:\n" + " QSharedDataPointer<EmployeeData> d;\n" + " };\n"; + + + QTest::newRow("QSharedPointer1") + << Data("#include <QSharedPointer>\n", + "QSharedPointer<int> ptr2 = ptr;\n" + "QSharedPointer<int> ptr3 = ptr;\n"); + + QTest::newRow("QSharedPointer2") + << Data("#include <QSharedPointer>\n", + "QSharedPointer<QString> ptr(new QString(\"hallo\"));\n" + "QSharedPointer<QString> ptr2 = ptr;\n" + "QSharedPointer<QString> ptr3 = ptr;\n"); + + QTest::newRow("QSharedPointer3") + << Data("#include <QSharedPointer>\n", + "QSharedPointer<int> iptr(new int(43));\n" + "QWeakPointer<int> ptr(iptr);\n" + "QWeakPointer<int> ptr2 = ptr;\n" + "QWeakPointer<int> ptr3 = ptr;\n"); + + QTest::newRow("QSharedPointer4") + << Data("#include <QSharedPointer>\n" + "#include <QString>\n", + "QSharedPointer<QString> sptr(new QString(\"hallo\"));\n" + "QWeakPointer<QString> ptr(sptr);\n" + "QWeakPointer<QString> ptr2 = ptr;\n" + "QWeakPointer<QString> ptr3 = ptr;\n"); + + QTest::newRow("QSharedPointer5") + << Data("#include <QSharedPointer>\n" + fooData, + "QSharedPointer<Foo> fptr(new Foo(1));\n" + "QWeakPointer<Foo> ptr(fptr);\n" + "QWeakPointer<Foo> ptr2 = ptr;\n" + "QWeakPointer<Foo> ptr3 = ptr;\n"); + + QTest::newRow("QXmlAttributes") + << Data("#include <QXmlAttributes>\n", + "QXmlAttributes atts;\n" + "atts.append(\"name1\", \"uri1\", \"localPart1\", \"value1\");\n" + "atts.append(\"name2\", \"uri2\", \"localPart2\", \"value2\");\n" + "atts.append(\"name3\", \"uri3\", \"localPart3\", \"value3\");\n") + % Check("atts", "", "QXmlAttributes") + % CheckType("atts.[vptr]", "") + % Check("atts.attList", "<3 items>", "@QXmlAttributes::AttributeList") + % Check("atts.attList.0", "[0]", "", "QXmlAttributes::Attribute") + % Check("atts.attList.0.localname", "\"localPart1\"", "@QString") + % Check("atts.attList.0.qname", "\"name1\"", "@QString") + % Check("atts.attList.0.uri", "\"uri1\"", "@QString") + % Check("atts.attList.0.value", "\"value1\"", "@QString") + % Check("atts.attList.1", "[1]", "", "@QXmlAttributes::Attribute") + % Check("atts.attList.1.localname", "\"localPart2\"", "@QString") + % Check("atts.attList.1.qname", "\"name2\"", "@QString") + % Check("atts.attList.1.uri", "\"uri2\"", "@QString") + % Check("atts.attList.1.value", "\"value2\"", "@QString") + % Check("atts.attList.2", "[2]", "", "@QXmlAttributes::Attribute") + % Check("atts.attList.2.localname", "\"localPart3\"", "@QString") + % Check("atts.attList.2.qname", "\"name3\"", "@QString") + % Check("atts.attList.2.uri", "\"uri3\"", "@QString") + % Check("atts.attList.2.value", "\"value3\"", "@QString") + % Check("atts.d", "", "@QXmlAttributesPrivate"); + + QTest::newRow("StdArray") + << Data("#include <memory>\n" + "#include <QString>\n", + "std::array<int, 4> a = { { 1, 2, 3, 4} };\n" + "std::array<QString, 4> b = { { \"1\", \"2\", \"3\", \"4\"} };\n") + % Check("a", "<4 items>", "std::array<int, 4u>") + % Check("a", "<4 items>", "std::array<QString, 4u>"); + + QTest::newRow("StdComplex") + << Data("#include <complex>\n", + "std::complex<double> c(1, 2);\n") + % Check("c", "(1.000000, 2.000000)", "std::complex<double>"); + + QTest::newRow("CComplex") + << Data("#include <complex.h>\n", + "// Doesn't work when compiled as C++.\n" + "double complex a = 0;\n" + "double _Complex b = 0;\n" + "dummyStatement(&a, &b);\n") + % ForceC() + % Check("a", "0 + 0 * I", "complex double") + % Check("b", "0 + 0 * I", "complex double"); + + QTest::newRow("StdDequeInt") + << Data("#include <deque>\n", + "std::deque<int> deque;\n" + "deque.push_back(1);\n" + "deque.push_back(2);\n") + % Check("deque", "<2 items>", Deque("int")) + % Check("deque.0", "[0]", "1", "int") + % Check("deque.1", "[1]", "2", "int"); + + QTest::newRow("StdDequeIntStar") + << Data("#include <deque>\n", + "std::deque<int *> deque;\n" + "deque.push_back(new int(1));\n" + "deque.push_back(0);\n" + "deque.push_back(new int(2));\n" + "deque.push_back(new int(3));\n" + "deque.pop_back();\n" + "deque.pop_front();\n") + % Check("deque", "<2 items>", Deque("int *")) + % Check("deque.0", "[0]", "0x0", "int *") + % Check("deque.1", "[1]", "2", "int"); + + QTest::newRow("StdDequeFoo") + << Data("#include <deque>\n" + fooData, + "std::deque<Foo> deque;\n" + "deque.push_back(1);\n" + "deque.push_front(2);\n") + % Check("deque", "<2 items>", Deque("Foo")) + % Check("deque.0", "[0]", "", "Foo") + % Check("deque.0.a", "2", "int") + % Check("deque.1", "[1]", "", "Foo") + % Check("deque.1.a", "1", "int"); + + QTest::newRow("StdDequeFooStar") + << Data("#include <deque>\n" + fooData, + "std::deque<Foo *> deque;\n" + "deque.push_back(new Foo(1));\n" + "deque.push_back(new Foo(2));\n") + % Check("deque", "<2 items>", Deque("Foo*")) + % Check("deque.0", "[0]", "", "Foo") + % Check("deque.0.a", "1", "int") + % Check("deque.1", "[1]", "", "Foo") + % Check("deque.1.a", "2", "int"); + + QTest::newRow("StdHashSet") + << Data("#include <hash_set>\n" + "using namespace __gnu_cxx;\n", + "hash_set<int> h;\n" + "h.insert(1);\n" + "h.insert(194);\n" + "h.insert(2);\n" + "h.insert(3);\n") + % Check("h", "<4 items>", "__gnu__cxx::hash_set<int>") + % Check("h.0", "194", "int") + % Check("h.1", "1", "int") + % Check("h.2", "2", "int") + % Check("h.3", "3", "int"); + + QTest::newRow("StdListInt") + << Data("#include <list>\n", + "std::list<int> list;\n" + "list.push_back(1);\n" + "list.push_back(2);\n") + % Check("list", "<2 items>", "std::list<int>") + % Check("list.0", "[0]", "1", "int") + % Check("list.1", "[1]", "2", "int"); + + QTest::newRow("StdListIntStar") + << Data("#include <list>\n", + "std::list<int *> list;\n" + "list.push_back(new int(1));\n" + "list.push_back(0);\n" + "list.push_back(new int(2));\n") + % Check("list", "<3 items>", "std::list<int*>") + % Check("list.0", "[0]", "", "int") + % Check("list.1", "[1]", "0x0", "int *") + % Check("list.2", "[2]", "", "int"); + + QTest::newRow("StdListIntBig") + << Data("#include <list>\n", + "std::list<int> list;\n" + "for (int i = 0; i < 10000; ++i)\n" + " list.push_back(i);\n") + % Check("list", "<more than 1000 items>", "std::list<int>") + % Check("list.0", "[0]", "0", "int") + % Check("list.999", "[999]", "999", "int"); + + QTest::newRow("StdListFoo") + << Data("#include <list>\n", + "std::list<Foo> list;\n" + "list.push_back(15);\n" + "list.push_back(16);\n") + % Check("list", "<2 items>", "std::list<Foo>") + % Check("list.0", "[0]", "", "Foo") + % Check("list.0.a", "15", "int") + % Check("list.1", "[1]", "", "Foo") + % Check("list.1.a", "16", "int"); + + QTest::newRow("StdListFooStar") + << Data("#include <list>\n", + "std::list<Foo *> list;\n" + "list.push_back(new Foo(1));\n" + "list.push_back(0);\n" + "list.push_back(new Foo(2));\n") + % Check("list", "<3 items>", "std::list<Foo*>") + % Check("list.0", "[0]", "", "Foo") + % Check("list.0.a", "1", "int") + % Check("list.1", "0x0", "Foo *") + % Check("list.2", "[2]", "", "Foo") + % Check("list.2.a", "2", "int"); + + QTest::newRow("StdListBool") + << Data("#include <list>\n", + "std::list<bool> list;\n" + "list.push_back(true);\n" + "list.push_back(false);\n") + % Check("list", "<2 items>", "std::list<bool>") + % Check("list.0", "[0]", "true", "bool") + % Check("list.1", "[1]", "false", "bool"); + + QTest::newRow("StdMapStringFoo") + << Data("#include <map>\n" + "#include <QString>\n", + "std::map<QString, Foo> map;\n" + "map[\"22.0\"] = Foo(22);\n" + "map[\"33.0\"] = Foo(33);\n" + "map[\"44.0\"] = Foo(44);\n") + % Check("map", "<3 items>", "std::map<@QString, Foo>") + % Check("map.0", "[0]", "", "std::pair<@QString const, Foo>") + % Check("map.0.first", "\"22.0\"", "@QString") + % Check("map.0.second", "", "Foo") + % Check("map.0.second.a", "22", "int") + % Check("map.1", "[1]", "", "std::pair<@QString const, Foo>") + % Check("map.2.first", "\"44.0\"", "@QString") + % Check("map.2.second", "", "Foo") + % Check("map.2.second.a", "44", "int"); + + QTest::newRow("StdMapCharStarFoo") + << Data("#include <map>\n" + fooData, + "std::map<const char *, Foo> map;\n" + "map[\"22.0\"] = Foo(22);\n" + "map[\"33.0\"] = Foo(33);\n") + % Check("map", "<2 items>", "std::map<char const*, Foo>") + % Check("map.0", "[0]", "", "std::pair<char const* const, Foo>") + % CheckType("map.0.first", "char *") + % Check("map.0.first.*first", "50 '2'", "char") + % Check("map.0.second", "", "Foo") + % Check("map.0.second.a", "22", "int") + % Check("map.1", "[1]", "", "std::pair<char const* const, Foo>") + % CheckType("map.1.first", "char *") + % Check("map.1.first.*first", "51 '3'", "char") + % Check("map.1.second", "", "Foo") + % Check("map.1.second.a", "33", "int"); + + QTest::newRow("StdMapUIntUInt") + << Data("#include <map>\n", + "std::map<uint, uint> map;\n" + "map[11] = 1;\n" + "map[22] = 2;\n") + % Check("map", "<2 items>", "std::map<unsigned int, unsigned int>") + % Check("map.11", "[11]", "1", "unsigned int") + % Check("map.22", "[22]", "2", "unsigned int"); + + QTest::newRow("StdMapUIntStringList") + << Data("#include <map>\n" + "#include <QStringList>\n", + "std::map<uint, QStringList> map;\n" + "map[11] = QStringList() << \"11\";\n" + "map[22] = QStringList() << \"22\";\n") + % Check("map", "<2 items>", "std::map<unsigned int, @QStringList>") + % Check("map.0", "", "std::pair<unsigned int const, @QStringList>") + % Check("map.0.first", "11", "unsigned int") + % Check("map.0.second", "<1 items>", "@QStringList") + % Check("map.0.second.0", "\"11\"", "@QString") + % Check("map.1", "", "std::pair<unsigned int const, @QStringList>") + % Check("map.1.first", "22", "unsigned int") + % Check("map.1.second", "<1 items>", "@QStringList") + % Check("map.1.second.0", "\"22\"", "@QString"); + + QTest::newRow("StdMapUIntStringListTypedef") + << Data("#include <map>\n", + "typedef std::map<uint, QStringList> T;\n" + "T map;\n" + "map[11] = QStringList() << \"11\";\n" + "map[22] = QStringList() << \"22\";\n"); + + QTest::newRow("StdMapUIntFloat") + << Data("#include <map>\n", + "std::map<uint, float> map;\n" + "map[11] = 11.0;\n" + "map[22] = 22.0;\n") + % Check("map", "<2 items>", "std::map<unsigned int, float>") + % Check("map.11", "[11]", "11", "float") + % Check("map.22", "[22]", "22", "float"); + + QTest::newRow("StdMapUIntFloatIterator") + << Data("#include <map>\n", + "typedef std::map<int, float> Map;\n" + "Map map;\n" + "map[11] = 11.0;\n" + "map[22] = 22.0;\n" + "map[33] = 33.0;\n" + "map[44] = 44.0;\n" + "map[55] = 55.0;\n" + "map[66] = 66.0;\n" + "Map::iterator it1 = map.begin();\n" + "Map::iterator it2 = it1; ++it2;\n" + "Map::iterator it3 = it2; ++it3;\n" + "Map::iterator it4 = it3; ++it4;\n" + "Map::iterator it5 = it4; ++it5;\n" + "Map::iterator it6 = it5; ++it6;\n") + % Check("map", "<6 items>", "Map") + % Check("map.11", "[11]", "11", "float") + % Check("it1.first", "11", "int") + % Check("it1.second", "11", "float") + % Check("it6.first", "66", "int") + % Check("it6.second", "66", "float"); + + QTest::newRow("StdMapStringFloat") + << Data("#include <map>\n", + "std::map<QString, float> map;\n" + "map[\"11.0\"] = 11.0;\n" + "map[\"22.0\"] = 22.0;\n") + % Check("map", "<2 items>", "std::map<@QString, float>") + % Check("map.0", "[0]", "", "std::pair<@QString const, float>") + % Check("map.0.first", "\"11.0\"", "@QString") + % Check("map.0.second", "11", "float") + % Check("map.1", "[1]", "", "std::pair<@QString const, float>") + % Check("map.1.first", "\"22.0\"", "@QString") + % Check("map.1.second", "22", "float"); + + QTest::newRow("StdMapIntString") + << Data("#include <map>\n" + "#include <QString>\n", + "std::map<int, QString> map;\n" + "map[11] = \"11.0\";\n" + "map[22] = \"22.0\";\n") + % Check("map", "<2 items>", "std::map<int, @QString>") + % Check("map.0", "[0]", "", "std::pair<int const, @QString>") + % Check("map.0.first", "11", "int") + % Check("map.0.second", "\"11.0\"", "@QString") + % Check("map.1", "[1]", "", "std::pair<int const, @QString>") + % Check("map.1.first", "22", "int") + % Check("map.1.second", "\"22.0\"", "@QString"); + + QTest::newRow("StdMapStringPointer") + << Data("#include <QPointer>\n" + "#include <QObject>\n" + "#include <QString>\n" + "#include <map>\n", + "QObject ob;\n" + "std::map<QString, QPointer<QObject> > map;\n" + "map[\"Hallo\"] = QPointer<QObject>(&ob);\n" + "map[\"Welt\"] = QPointer<QObject>(&ob);\n" + "map[\".\"] = QPointer<QObject>(&ob);\n") + % Check("map", "<3 items>", "std::map<@QString, @QPointer<@QObject>>") + % Check("map.0", "[0]", "", "std::pair<@QString const, @QPointer<@QObject>>") + % Check("map.0.first", "", "@QString") + % Check("map.0.second", "", "@QPointer<@QObject>") + % Check("map.2", "[2]", "", "std::pair<@QString const, @QPointer<@QObject>>") + % Check("map.2.first", "\"Welt\"", "@QString"); + + QTest::newRow("StdUniquePtr") + << Data("#include <memory>\n" + fooData, + "std::unique_ptr<int> pi(new int(32));\n" + "std::unique_ptr<Foo> pf(new Foo);\n") + % Cxx11Profile() + % Check("pi", Pointer("32"), "std::unique_ptr<int, std::default_delete<int> >") + % Check("pf", Pointer(), "std::unique_ptr<Foo, std::default_delete<Foo> >"); + + QTest::newRow("StdSharedPtr") + << Data("#include <memory>\n" + fooData, + "std::shared_ptr<int> pi(new int(32));\n" + "std::shared_ptr<Foo> pf(new Foo);\n") + % Cxx11Profile() + % Check("pi", Pointer("32"), "std::shared_ptr<int, std::default_delete<int> >") + % Check("pf", Pointer(), "std::shared_ptr<Foo, std::default_delete<int> >"); + + QTest::newRow("StdSetInt") + << Data("#include <set>\n", + "std::set<int> set;\n" + "set.insert(11);\n" + "set.insert(22);\n" + "set.insert(33);\n") + % Check("set", "<3 items>", "std::set<int>"); + + QTest::newRow("StdSetIntIterator") + << Data("#include <set>\n", + "typedef std::set<int> Set;\n" + "Set set;\n" + "set.insert(11.0);\n" + "set.insert(22.0);\n" + "set.insert(33.0);\n" + "set.insert(44.0);\n" + "set.insert(55.0);\n" + "set.insert(66.0);\n" + "Set::iterator it1 = set.begin();\n" + "Set::iterator it2 = it1; ++it2;\n" + "Set::iterator it3 = it2; ++it3;\n" + "Set::iterator it4 = it3; ++it4;\n" + "Set::iterator it5 = it4; ++it5;\n" + "Set::iterator it6 = it5; ++it6;\n") + % Check("set", "<6 items>", "Set") + % Check("it1.value", "11", "int") + % Check("it6.value", "66", "int"); + + QTest::newRow("StdSetString") + << Data("#include <set>\n" + "#include <QString>\n", + "std::set<QString> set;\n" + "set.insert(\"22.0\");\n") + % Check("set", "<1 items>", "std::set<Q@String>") + % Check("set.0", "[0]", "\"22.0\"", "@QString"); + + QTest::newRow("StdSetPointer") + << Data("#include <set>\n", + "#include <QPointer>\n" + "#include <QObject>\n" + "QObject ob;\n" + "std::set<QPointer<QObject> > hash;\n" + "QPointer<QObject> ptr(&ob);\n") + % Check("hash", "<0 items>", "std::set<@QPointer<@QObject>, std::less<@QPointer<@QObject>>, std::allocator<@QPointer<@QObject>>>") + % Check("ob", "\"\"", "@QObject") + % Check("ptr", "", "@QPointer<@QObject>"); + + QTest::newRow("StdStack1") + << Data("#include <stack>\n", + "std::stack<int *> s0, s;\n" + "s.push(new int(1));\n" + "s.push(0);\n" + "s.push(new int(2));\n") + % Check("s0", "<0 items>", "std::stack<int*>") + % Check("s", "<3 items>", "std::stack<int*>") + % Check("s.0", "[0]", "", "int") + % Check("s.1", "[1]", "0x0", "int *") + % Check("s.2", "[2]", "", "int"); + + QTest::newRow("StdStack2") + << Data("#include <stack>\n", + "std::stack<int> s0, s;\n" + "s.push(1);\n" + "s.push(2);\n") + % Check("s0", "<0 items>", "std::stack<int>") + % Check("s", "<2 items>", "std::stack<int>") + % Check("s.0", "1", "int") + % Check("s.1", "2", "int"); + + QTest::newRow("StdStack3") + << Data("#include <stack>\n", + "std::stack<Foo *> s, s0;\n" + "s.push(new Foo(1));\n" + "s.push(new Foo(2));\n") + % Check("s", "<2 items>", "std::stack<Foo*>") + % Check("s.0", "[0]", "", "Foo") + % Check("s.0.a", "1", "int") + % Check("s.1", "[1]", "", "Foo") + % Check("s.1.a", "2", "int"); + + QTest::newRow("StdStack4") + << Data("#include <stack>\n", + "std::stack<Foo> s0, s;\n" + "s.push(1);\n" + "s.push(2);\n") + % Check("s0", "<0 items>", "std::stack<Foo>") + % Check("s", "<2 items>", "std::stack<Foo>") + % Check("s.0", "[0]", "", "Foo") + % Check("s.0.a", "1", "int") + % Check("s.1", "[1]", "", "Foo") + % Check("s.1.a", "2", "int"); + + QTest::newRow("StdString1") + << Data("#include <string>\n", + "std::string str0, str;\n" + "std::wstring wstr0, wstr;\n" + "str += \"b\";\n" + "wstr += wchar_t('e');\n" + "str += \"d\";\n" + "wstr += wchar_t('e');\n" + "str += \"e\";\n" + "str += \"b\";\n" + "str += \"d\";\n" + "str += \"e\";\n" + "wstr += wchar_t('e');\n" + "wstr += wchar_t('e');\n" + "str += \"e\";\n") + % Check("str0", "\"\"", "std::string") + % Check("wstr0", "\"\"", "std::wstring") + % Check("str", "\"bdebdee\"", "std::string") + % Check("wstr", "\"eeee\"", "std::wstring"); + + QTest::newRow("StdString2") + << Data("#include <string>\n" + "#include <vector>\n" + "#include <QList>\n", + "std::string str = \"foo\";\n" + "std::vector<std::string> v;\n" + "QList<std::string> l0, l;\n" + "v.push_back(str);\n" + "v.push_back(str);\n" + "l.push_back(str);\n" + "l.push_back(str);\n") + % Check("l0", "<0 items>", "@QList<std::string>") + % Check("l", "<2 items>", "@QList<std::string>") + % Check("str", "\"foo\"", "std::string") + % Check("v", "<2 items>", "std::vector<std::string>") + % Check("v.0", "[0]", "\"foo\"", "std::string"); + + QTest::newRow("StdVector1") + << Data("#include <vector>\n", + "std::vector<int *> v0, v;\n" + "v.push_back(new int(1));\n" + "v.push_back(0);\n" + "v.push_back(new int(2));\n") + % Check("v0", "<0 items>", "std::vector<int*>") + % Check("v", "<3 items>", "std::vector<int*>") + % Check("v.0", "[1]", "1", "int") + % Check("v.1", "0x0", "int *") + % Check("v.2", "[2]", "2", "int"); + + QTest::newRow("StdVector2") + << Data("#include <vector>\n", + "std::vector<int> v;\n" + "v.push_back(1);\n" + "v.push_back(2);\n" + "v.push_back(3);\n" + "v.push_back(4);\n") + % Check("v", "<4 items>", "std::vector<int>") + % Check("v.0", "[0]", "1", "int") + % Check("v.3", "[3]", "4", "int"); + + QTest::newRow("StdVector3") + << Data("#include <vector>\n", + "std::vector<Foo *> v;\n" + "v.push_back(new Foo(1));\n" + "v.push_back(0);\n" + "v.push_back(new Foo(2));\n") + % Check("v", "<3 items>", "std::vector<Foo*>") + % Check("v.0", "[0]", "", "Foo") + % Check("v.0.a", "1", "int") + % Check("v.1", "[1]", "0x0", "Foo *") + % Check("v.2", "[2]", "", "Foo") + % Check("v.2.a", "2", "int"); + + QTest::newRow("StdVector4") + << Data("#include <vector>\n", + "std::vector<Foo> v;\n" + "v.push_back(1);\n" + "v.push_back(2);\n" + "v.push_back(3);\n" + "v.push_back(4);\n") + % Check("v", "<4 items>", "std::vector<Foo>") + % Check("v.0", "[0]", "", "Foo") + % Check("v.1.a", "2", "int") + % Check("v.3", "[3]", "", "Foo"); + + QTest::newRow("StdVectorBool1") + << Data("#include <vector>\n", + "std::vector<bool> v;\n" + "v.push_back(true);\n" + "v.push_back(false);\n" + "v.push_back(false);\n" + "v.push_back(true);\n" + "v.push_back(false);\n") + % Check("v", "<5 items>", "std::vector<bool>") + % Check("v.0", "[0]", "true", "bool") + % Check("v.1", "[1]", "false", "bool") + % Check("v.2", "[2]", "false", "bool") + % Check("v.3", "[3]", "true", "bool") + % Check("v.4", "[4]", "false", "bool"); + + QTest::newRow("StdVectorBool2") + << Data("#include <vector>\n", + "std::vector<bool> v1(65, true);\n" + "std::vector<bool> v2(65);\n") + % Check("v1", "<65 items>", "std::vector<bool>") + % Check("v1.0", "[0]", "true", "bool") + % Check("v1.64", "[64]", "true", "bool") + % Check("v2", "<65 items>", "std::vector<bool>") + % Check("v2.0", "[0]", "false", "bool") + % Check("v2.64", "[64]", "false", "bool"); + + QTest::newRow("StdVector6") + << Data("#include <vector>\n" + "#include <list>\n", + "std::vector<std::list<int> *> vector;\n" + "std::list<int> list;\n" + "vector.push_back(new std::list<int>(list));\n" + "vector.push_back(0);\n" + "list.push_back(45);\n" + "vector.push_back(new std::list<int>(list));\n" + "vector.push_back(0);\n") + % Check("list", "<1 items>", "std::list<int>") + % Check("list.0", "[0]", "45", "int") + % Check("vector", "<4 items>", "std::vector<std::list<int>*>") + % Check("vector.0", "[0]", "<0 items>", "std::list<int>") + % Check("vector.2", "[2]", "<1 items>", "std::list<int>") + % Check("vector.2.0", "45", "int") + % Check("vector.3", "[3]", "0x0", "std::list<int> *"); + + QTest::newRow("StdStream") + << Data("#include <ifstream>\n", + "using namespace std;\n" + "ifstream is0, is;\n" + "#ifdef Q_OS_WIN\n" + " is.open(\"C:\\\\Program Files\\\\Windows NT\\\\Accessories\\\\wordpad.exe\");\n" + "#else\n" + " is.open(\"/etc/passwd\");\n" + "#endif\n" + " bool ok = is.good();\n") + % Check("is", "", "std::ifstream") + % Check("ok", "true", "bool"); + + QTest::newRow("ItemModel") + << Data("#include <QStandardItemModel>\n", + "QStandardItemModel m;\n" + "QStandardItem *i1, *i2, *i11;\n" + "m.appendRow(QList<QStandardItem *>()\n" + " << (i1 = new QStandardItem(\"1\")) << (new QStandardItem(\"a\")) << (new QStandardItem(\"a2\")));\n" + "QModelIndex mi = i1->index();\n" + "m.appendRow(QList<QStandardItem *>()\n" + " << (i2 = new QStandardItem(\"2\")) << (new QStandardItem(\"b\")));\n" + "i1->appendRow(QList<QStandardItem *>()\n" + " << (i11 = new QStandardItem(\"11\")) << (new QStandardItem(\"aa\")));\n") + % Check("i1", "", "@QStandardItem") + % Check("i11", "", "@QStandardItem") + % Check("i2", "", "@QStandardItem") + % Check("m", "", "@QStandardItemModel") + % Check("mi", "\"1\"", "@QModelIndex"); + + QTest::newRow("QStackInt") + << Data("#include <QStack>", + "QStack<int> s;\n" + "s.append(1);\n" + "s.append(2);\n") + % Check("s", "<2 items>", "@QStack<int>") + % Check("s.0", "[0]", "1", "int") + % Check("s.1", "[1]", "2", "int"); + + QTest::newRow("QStackBig") + << Data("#include <QStack>", + "QStack<int> s;\n" + "for (int i = 0; i != 10000; ++i)\n" + " s.append(i);\n") + % Check("s", "<10000 items>", "@QStack<int>") + % Check("s.0", "[0]", "0", "int") + % Check("s.1999", "[1999]", "1999", "int"); + + QTest::newRow("QStackFooPointer") + << Data("#include <QStack>", + "QStack<Foo *> s;\n" + "s.append(new Foo(1));\n" + "s.append(0);\n" + "s.append(new Foo(2));\n") + % Check("s", "<3 items>", "@QStack<Foo*>") + % Check("s.0", "[0]", "", "Foo") + % Check("s.0.a", "1", "int") + % Check("s.1", "[1]", "0x0", "Foo *") + % Check("s.2", "[2]", "", "Foo") + % Check("s.2.a", "2", "int"); + + QTest::newRow("QStackFoo") + << Data("#include <QStack>" + fooData, + "QStack<Foo> s;\n" + "s.append(1);\n" + "s.append(2);\n" + "s.append(3);\n" + "s.append(4);\n") + % Check("s", "<4 items>", "@QStack<Foo>") + % Check("s.0", "[0]", "", "Foo") + % Check("s.0.a", "1", "int") + % Check("s.3", "[3]", "", "Foo") + % Check("s.3.a", "4", "int"); + + QTest::newRow("QStackBool") + << Data("#include <QStack>", + "QStack<bool> s;\n" + "s.append(true);\n" + "s.append(false);\n") + % Check("s", "<2 items>", "@QStack<bool>") + % Check("s.0", "true", "bool") + % Check("s.1", "false", "bool"); + + QTest::newRow("QUrl") + << Data("#include <QUrl>", + "QUrl url(QString(\"http://qt-project.org\"));\n") + % Check("url", "\"http://qt-project.org\"", "@QUrl"); + + QTest::newRow("QStringQuotes") + << Data("QString str1(\"Hello Qt\");\n" + // --> Value: \"Hello Qt\" + "QString str2(\"Hello\\nQt\");\n" + // --> Value: \\"\"Hello\nQt"" (double quote not expected) + "QString str3(\"Hello\\rQt\");\n" + // --> Value: ""HelloQt"" (double quote and missing \r not expected) + "QString str4(\"Hello\\tQt\");\n") + // --> Value: "Hello\9Qt" (expected \t instead of \9) + % Check("str1", "\"Hello Qt\"", "@QString") + % Check("str2", "\"Hello\nQt\"", "@QString") + % Check("str3", "\"Hello\rQt\"", "@QString") + % Check("str4", "\"Hello\tQt\"", "@QString"); + + QByteArray stringData = "QString str = \"Hello \";\n" + "str += '\\t';\n" + "str += '\\r';\n" + "str += '\\n';\n" + "str += QLatin1Char(0);\n" + "str += QLatin1Char(1);\n" + "str += \" World\";\n" + "str.prepend(\"Prefix: \");\n"; + + QTest::newRow("QString1") + << Data(stringData) + % Check("str", "\"Prefix: Hello big, \\t\\r\\n\\000\\001 World\"", "@QString"); + + QTest::newRow("QString2") + << Data("QChar data[] = { 'H', 'e', 'l', 'l', 'o' };\n" + "QString str1 = QString::fromRawData(data, 4);\n" + "QString str2 = QString::fromRawData(data + 1, 4);\n") + % Check("str1", "\"Hell\"", "@QString") + % Check("str2", "\"ello\"", "@QString"); + + QTest::newRow("QString3") + << Data("#include <QString>\n" + "void stringRefTest(const QString &refstring) { stopper(); }\n", + "stringRefTest(QString(\"Ref String Test\"));\n") + % Check("refstring", "\"Ref String Test\"", "@QString &"); + + QTest::newRow("QString4") + << Data("#include <QString>\n" + "QString str = \"Hello \";\n" + "QString string(\"String Test\");\n" + "QString *pstring = new QString(\"Pointer String Test\");\n" + "dummyStatement(&str, &string, &pstring);\n") + % Check("pstring", "\"Pointer String Test\"", "@QString") + % Check("str", "\"Hello \"", "@QString") + % Check("string", "\"String Test\"", "@QString"); + + QTest::newRow("QStringRef1") + << Data("#include <QStringRef>\n", + "QString str = \"Hello\";\n" + "QStringRef ref(&str, 1, 2);") + % Check("ref", "\"el\"", "@QStringRef"); + + QTest::newRow("QStringList") + << Data("#include <QStringList>\n", + "QStringList l;\n" + "l << \"Hello \";\n" + "l << \" big, \";\n" + "l.takeFirst();\n" + "l << \" World \";\n") + % Check("l", "<2 items>", "@QStringList") + % Check("l.0", "\" big, \"", "@QString") + % Check("l.1", "\" World \"", "@QString"); + + QTest::newRow("String") + << Data("#include <QString>", + "const wchar_t *w = L\"aöa\";\n" + "QString u;\n" + "if (sizeof(wchar_t) == 4)\n" + " u = QString::fromUcs4((uint *)w);\n" + "else\n" + " u = QString::fromUtf16((ushort *)w);\n") + % Check("u", "\"aöa\"", "@QString") + % CheckType("w", "", "wchar_t *"); + + // All: Select UTF-8 in "Change Format for Type" in L&W context menu"); + // Windows: Select UTF-16 in "Change Format for Type" in L&W context menu"); + // Other: Select UCS-6 in "Change Format for Type" in L&W context menu"); + + + // These tests should result in properly displayed umlauts in the + // Locals&Watchers view. It is only support on gdb with Python"); + QTest::newRow("CharPointers") + << Data("const char *s = \"aöa\";\n" + "const char *t = \"a\\xc3\\xb6\";\n" + "const unsigned char uu[] = { 'a', 153 /* ö Latin1 */, 'a' };\n" + "const unsigned char *u = uu;\n" + "const wchar_t *w = L\"aöa\";\n") + % CheckType("u", "unsigned char *") + % CheckType("uu", "unsigned char [3]") + % CheckType("s", "char *") + % CheckType("t", "char *") + % CheckType("w", "wchar_t *"); + + // All: Select UTF-8 in "Change Format for Type" in L&W context menu"); + // Windows: Select UTF-16 in "Change Format for Type" in L&W context menu"); + // Other: Select UCS-6 in "Change Format for Type" in L&W context menu"); + + + QTest::newRow("CharArrays") + << Data("const char s[] = \"aöa\";\n" + "const char t[] = \"aöax\";\n" + "const wchar_t w[] = L\"aöa\";\n") + % CheckType("s", "char [5]") + % CheckType("t", "char [6]") + % CheckType("w", "wchar_t [4]"); + + + QTest::newRow("Text") + << Data("#include <QApplication>\n" + "#include <QTextCursor>\n" + "#include <QTextDocument>\n", + "QApplication app(arrc, argv)\n" + "QTextDocument doc;\n" + "doc.setPlainText(\"Hallo\\nWorld\");\n" + "QTextCursor tc;\n" + "tc = doc.find(\"all\");\n" + "int pos = tc.position();\n" + "int anc = tc.anchor();\n") + % CheckType("doc", "QTextDocument") + % Check("tc", "4", "QTextCursor") + % Check("pos", "4", "int") + % Check("anc", "1", "int"); + + QTest::newRow("QThread") + << Data("#include <QThread>\n", + "const int N = 14;\n" + "Thread thread[N];\n" + "for (int i = 0; i != N; ++i) {\n" + " thread[i].setId(i);\n" + " thread[i].setObjectName(\"This is thread #\" + QString::number(i));\n" + " thread[i].start();\n" + "}\n") + % CheckType("thread", "Thread [14]") + % Check("thread.0", "", "Thread") + % Check("thread.0.@1.@1", "\"This is thread #0\"", "Thread") + % Check("thread.13", "", "Thread") + % Check("thread.13.@1.@1", "\"This is thread #13\"", "Thread"); + + QByteArray variantData = + "Q_DECLARE_METATYPE(QHostAddress)\n" + "Q_DECLARE_METATYPE(QList<int>)\n" + "Q_DECLARE_METATYPE(QStringList)\n" + "#define COMMA ,\n" + "Q_DECLARE_METATYPE(QMap<uint COMMA QStringList>)\n"; + + QTest::newRow("QVariant1") + << Data("#include <QVariant>\n", + "QVariant value;\n" + "QVariant::Type t = QVariant::String;\n" + "value = QVariant(t, (void*)0);\n" + "*(QString*)value.data() = QString(\"Some string\");\n" + "int i = 1;\n") + % Check("t", "QVariant::String (10)", "@QVariant::Type") + % Check("value", "\"Some string\"", "@QVariant (QString)"); + + QTest::newRow("QVariant2") + << Data("#include <QVariant>\n" + variantData, + "QVariant var; // Type 0, invalid\n" + "QVariant var1(true); // 1, bool\n" + "QVariant var2(2); // 2, int\n" + "QVariant var3(3u); // 3, uint\n" + "QVariant var4(qlonglong(4)); // 4, qlonglong\n" + "QVariant var5(qulonglong(5)); // 5, qulonglong\n" + "QVariant var6(double(6)); // 6, double\n" + "QVariant var7(QChar(7)); // 7, QChar\n" + //None, # 8, QVariantMap + // None, # 9, QVariantList + "QVariant var10(QString(\"Hello 10\")); // 10, QString\n" + "QVariant var19(QRect(100, 200, 300, 400)); // 19 QRect\n" + "QVariant var20(QRectF(100, 200, 300, 400)); // 20 QRectF\n" + ) + % Check("var", "(invalid)", "@QVariant (invalid)") + % Check("var1", "true", "@QVariant (bool)") + % Check("var2", "2", "@QVariant (int)") + % Check("var3", "3", "@QVariant (uint)") + % Check("var4", "4", "@QVariant (qlonglong)") + % Check("var5", "5", "@QVariant (qulonglong)") + % Check("var6", "6", "@QVariant (double)") + % Check("var7", "'?' (7)", "@QVariant (QChar)") + % Check("var10", "\"Hello 10\"", "@QVariant (QString)") + % Check("var19", "300x400+100+200", "@QVariant (QRect)") + % Check("var20", "300x400+100+200", "@QVariant (QRectF)"); + + /* + "QStringList", # 11 + "QByteArray", # 12 + "QBitArray", # 13 + "QDate", # 14 + "QTime", # 15 + "QDateTime", # 16 + "QUrl", # 17 + "QLocale", # 18 + "QRect", # 19 + "QRectF", # 20 + "QSize", # 21 + "QSizeF", # 22 + "QLine", # 23 + "QLineF", # 24 + "QPoint", # 25 + "QPointF", # 26 + "QRegExp", # 27 + */ + +// QTest::newRow("QVariant3") +// << Data( +// "QVariant var;\n" +// % Check("var (invalid) QVariant (invalid)"); +// % Check("the list is updated properly"); +// "var.setValue(QStringList() << "World");\n" +// % Check("var <1 items> QVariant (QStringList)"); +// % Check("var.0 "World" QString"); +// "var.setValue(QStringList() << "World" << "Hello");\n" +// % Check("var <2 items> QVariant (QStringList)"); +// % Check("var.1 "Hello" QString"); +// "var.setValue(QStringList() << "Hello" << "Hello");\n" +// % Check("var <2 items> QVariant (QStringList)"); +// % Check("var.0 "Hello" QString"); +// % Check("var.1 "Hello" QString"); +// "var.setValue(QStringList() << "World" << "Hello" << "Hello");\n" +// % Check("var <3 items> QVariant (QStringList)"); +// % Check("var.0 "World" QString"); + + QTest::newRow("QVariant4") + << Data("#include <QHostAddress>\n" + "#include <QVariant>\n", + "QVariant var;\n" + "QHostAddress ha(\"127.0.0.1\");\n" + "var.setValue(ha);\n" + "QHostAddress ha1 = var.value<QHostAddress>();\n") + % Check("ha", "\"127.0.0.1\"", "@QHostAddress") + % Check("ha.a", "0", "quint32") + % Check("ha.a6", "", "Q_IPV6ADDR") + % Check("ha.ipString", "\"127.0.0.1\"", "@QString") + % Check("ha.isParsed", "false", "bool") + % Check("ha.protocol", "QAbstractSocket::UnknownNetworkLayerProtocol (-1)", + "@QAbstractSocket::NetworkLayerProtocol") + % Check("ha.scopeId", "", "@QString") + % Check("ha1", "\"127.0.0.1\"", "@QHostAddress") + % Check("ha1.a", "0", "quint32") + % Check("ha1.a6", "", "Q_IPV6ADDR") + % Check("ha1.ipString", "\"127.0.0.1\"", "@QString") + % Check("ha1.isParsed", "false", "bool") + % Check("ha1.protocol", "QAbstractSocket::UnknownNetworkLayerProtocol (-1)", + "@QAbstractSocket::NetworkLayerProtocol") + % Check("ha1.scopeId", "", "@QString") + % CheckType("var", "", "@QVariant (QHostAddress)") + % Check("var.data", "\"127.0.0.1\"", "@QHostAddress"); + +// QTest::newRow("QVariant5") +// << Data( +// // This checks user defined types in QVariants"); +// "typedef QMap<uint, QStringList>\n" MyType; +// "MyType my;\n" +// "my[1] = (QStringList() << "Hello");\n" +// "my[3] = (QStringList() << "World");\n" +// "QVariant var;\n" +// "var.setValue(my);\n" +// // FIXME: Known to break\n" +// //QString type = var.typeName();\n" +// "var.setValue(my);\n" +// % Check("my <2 items> qvariant::MyType"); +// % Check("my.0 QMapNode<unsigned int, QStringList>"); +// % Check("my.0.key 1 unsigned int"); +// % Check("my.0.value <1 items> QStringList"); +// % Check("my.0.value.0 "Hello" QString"); +// % Check("my.1 QMapNode<unsigned int, QStringList>"); +// % Check("my.1.key 3 unsigned int"); +// % Check("my.1.value <1 items> QStringList"); +// % Check("my.1.value.0 "World" QString"); +// % CheckType("var QVariant (QMap<unsigned int , QStringList>)"); +// % Check("var.data <2 items> QMap<unsigned int, QStringList>"); +// % Check("var.data.0 QMapNode<unsigned int, QStringList>"); +// % Check("var.data.0.key 1 unsigned int"); +// % Check("var.data.0.value <1 items> QStringList"); +// % Check("var.0.value.0 "Hello" QString"); +// % Check("var.data.1 QMapNode<unsigned int, QStringList>"); +// % Check("var.data.1.key 3 unsigned int"); +// % Check("var.data.1.value <1 items> QStringList"); +// % Check("var.data.1.value.0 "World" QString"); +// // Continue"); +// var.setValue(my); + +// QTest::newRow("QVariant6") +// << Data( +// "QList<int> list;\n" +// "list << 1 << 2 << 3;\n" +// "QVariant variant = qVariantFromValue(list);\n" +// % Check("list <3 items> QList<int>"); +// % Check("list.0", "1", "int"); +// % Check("list.1", "2", "int"); +// % Check("list.2", "3", "int"); +// % CheckType("variant QVariant (QList<int>)"); +// % Check("variant.data <3 items> QList<int>"); +// % Check("variant.data.0", "1", "int"); +// % Check("variant.data.1", "2", "int"); +// % Check("variant.data.2", "3", "int"); +// // Continue"); +// list.clear();\n" +// list = variant.value<QList<int> >();\n" +// % Check("list <3 items> QList<int>");\n" +// % Check("list.0", "1", "int"); +// % Check("list.1", "2", "int"); +// % Check("list.2", "3", "int"); + +// QTest::newRow("QVariantList") +// << Data( +// "QVariantList vl;\n" +// " % Check("vl <0 items> QVariantList");\n" +// "// Continue");\n" +// "vl.append(QVariant(1));\n" +// "vl.append(QVariant(2));\n" +// "vl.append(QVariant("Some String"));\n" +// "vl.append(QVariant(21));\n" +// "vl.append(QVariant(22));\n" +// "vl.append(QVariant("2Some String"));\n" +// % Check("vl <6 items> QVariantList"); +// % CheckType("vl.0 QVariant (int)"); +// % CheckType("vl.2 QVariant (QString)"); + +// QTest::newRow("QVariantMap") +// << Data( +// "QVariantMap vm;\n" +// % Check("vm <0 items> QVariantMap"); +// "// Continue");\n" +// "vm["a"] = QVariant(1);\n" +// "vm["b"] = QVariant(2);\n" +// "vm["c"] = QVariant("Some String");\n" +// "vm["d"] = QVariant(21);\n" +// "vm["e"] = QVariant(22);\n" +// "vm["f"] = QVariant("2Some String");\n" +// % Check("vm <6 items> QVariantMap"); +// % Check("vm.0 QMapNode<QString, QVariant>"); +// % Check("vm.0.key "a" QString"); +// % Check("vm.0.value 1 QVariant (int)"); +// % Check("vm.5 QMapNode<QString, QVariant>"); +// % Check("vm.5.key "f" QString"); +// % Check("vm.5.value "2Some String" QVariant (QString)"); + +// QTest::newRow("QVectorIntBig") +// << Data( +// // This tests the display of a big vector"); +// QVector<int> vec(10000); +// for (int i = 0; i != vec.size(); ++i) +// vec[i] = i * i; +// % Check("vec <10000 items> QVector<int>"); +// % Check("vec.0", "0", "int"); +// % Check("vec.1999", "3996001", "int"); +// // Continue"); + +// // step over +// // check that the display updates in reasonable time +// vec[1] = 1; +// vec[2] = 2; +// vec.append(1); +// vec.append(1); +// % Check("vec <10002 items> QVector<int>"); +// % Check("vec.1", "1", "int"); +// % Check("vec.2", "2", "int"); + +// QTest::newRow("QVectorFoo") +// << Data( +// // This tests the display of a vector of pointers to custom structs");\n" +// "QVector<Foo> vec;\n" +// % Check("vec <0 items> QVector<Foo>"); +// // Continue");\n" +// // step over, check display");\n" +// "vec.append(1);\n" +// "vec.append(2);\n" +// % Check("vec <2 items> QVector<Foo>"); +// % Check("vec.0", "Foo"); +// % Check("vec.0.a", "1", "int"); +// % Check("vec.1", "Foo"); +// % Check("vec.1.a", "2", "int"); + +// typedef QVector<Foo> FooVector; + +// QTest::newRow("QVectorFooTypedef") +// << Data( +// { +// "FooVector vec;\n" +// "vec.append(Foo(2));\n" +// "vec.append(Foo(3));\n" +// dummyStatement(&vec); +// } + +// QTest::newRow("QVectorFooStar") +// << Data( +// { +// // This tests the display of a vector of pointers to custom structs"); +// "QVector<Foo *> vec;\n" +// % Check("vec <0 items> QVector<Foo*>"); +// // Continue");\n" +// // step over\n" +// // check that the display is ok");\n" +// "vec.append(new Foo(1));\n" +// "vec.append(0);\n" +// "vec.append(new Foo(2));\n" +// "vec.append(new Fooooo(3));\n" +// // switch "Auto derefencing pointers" in Locals context menu\n" +// // off and on again, and check result looks sane");\n" +// % Check("vec <4 items> QVector<Foo*>"); +// % Check("vec.0", "Foo"); +// % Check("vec.0.a", "1", "int"); +// % Check("vec.1 0x0 Foo *"); +// % Check("vec.2", "Foo"); +// % Check("vec.2.a", "2", "int"); +// % Check("vec.3", "Fooooo"); +// % Check("vec.3.a", "5", "int"); + +// QTest::newRow("QVectorBool") +// << Data( +// QVector<bool> vec; +// % Check("vec <0 items> QVector<bool>"); +// // Continue"); +// // step over +// // check that the display is ok"); +// vec.append(true); +// vec.append(false); +// % Check("vec <2 items> QVector<bool>"); +// % Check("vec.0", "true", "bool"); +// % Check("vec.1", "false", "bool"); + +// QTest::newRow("QVectorListInt") +// << Data( +// "QVector<QList<int> > vec; +// "QVector<QList<int> > *pv = &vec; +// % Check("pv", "QVector<QList<int>>"); +// % Check("vec <0 items> QVector<QList<int>>"); +// // Continue"); +// "vec.append(QList<int>() << 1); +// "vec.append(QList<int>() << 2 << 3); +// % Check("pv", "QVector<QList<int>>"); +// % Check("pv.0 <1 items> QList<int>"); +// % Check("pv.0.0", "1", "int"); +// % Check("pv.1 <2 items> QList<int>"); +// % Check("pv.1.0", "2", "int"); +// % Check("pv.1.1", "3", "int"); +// % Check("vec <2 items> QVector<QList<int>>"); +// % Check("vec.0 <1 items> QList<int>"); +// % Check("vec.0.0", "1", "int"); +// % Check("vec.1 <2 items> QList<int>"); +// % Check("vec.1.0", "2", "int"); +// % Check("vec.1.1", "3", "int"); + +//namespace noargs { + +// class Goo +// { +// public: +// Goo(const QString &str, const int n) : str_(str), n_(n) {} +// private: +// QString str_; +// int n_; +// }; + +// typedef QList<Goo> GooList; + +// QTest::newRow("NoArgumentName(int i, int, int k) +// { +// // This is not supposed to work with the compiled dumpers"); +// "GooList list; +// "list.append(Goo("Hello", 1)); +// "list.append(Goo("World", 2)); + +// "QList<Goo> list2; +// "list2.append(Goo("Hello", 1)); +// "list2.append(Goo("World", 2)); + +// % Check("i", "1", "int"); +// % Check("k", "3", "int"); +// % Check("list <2 items> noargs::GooList"); +// % Check("list.0", "noargs::Goo"); +// % Check("list.0.n_", "1", "int"); +// % Check("list.0.str_ "Hello" QString"); +// % Check("list.1", "noargs::Goo"); +// % Check("list.1.n_", "2", "int"); +// % Check("list.1.str_ "World" QString"); +// % Check("list2 <2 items> QList<noargs::Goo>"); +// % Check("list2.0", "noargs::Goo"); +// % Check("list2.0.n_", "1", "int"); +// % Check("list2.0.str_ "Hello" QString"); +// % Check("list2.1", "noargs::Goo"); +// % Check("list2.1.n_", "2", "int"); +// % Check("list2.1.str_ "World" QString"); + + +//"void foo() {}\n" +//"void foo(int) {}\n" +//"void foo(QList<int>) {}\n" +//"void foo(QList<QVector<int> >) {}\n" +//"void foo(QList<QVector<int> *>) {}\n" +//"void foo(QList<QVector<int *> *>) {}\n" +//"\n" +//"template <class T>\n" +//"void foo(QList<QVector<T> *>) {}\n" +//"\n" +//"\n" +//"namespace namespc {\n" +//"\n" +//" class MyBase : public QObject\n" +//" {\n" +//" public:\n" +//" MyBase() {}\n" +//" virtual void doit(int i)\n" +//" {\n" +//" n = i;\n" +//" }\n" +//" protected:\n" +//" int n;\n" +//" };\n" +//"\n" +//" namespace nested {\n" +//"\n" +//" class MyFoo : public MyBase\n" +//" {\n" +//" public:\n" +//" MyFoo() {}\n" +//" virtual void doit(int i)\n" +//" {\n" +//" // Note there's a local 'n' and one in the base class");\n" +//" n = i;\n" +//" }\n" +//" protected:\n" +//" int n;\n" +//" };\n" +//"\n" +//" class MyBar : public MyFoo\n" +//" {\n" +//" public:\n" +//" virtual void doit(int i)\n" +//" {\n" +//" n = i + 1;\n" +//" }\n" +//" };\n" +//"\n" +//" namespace {\n" +//"\n" +//" class MyAnon : public MyBar\n" +//" {\n" +//" public:\n" +//" virtual void doit(int i)\n" +//" {\n" +//" n = i + 3;\n" +//" }\n" +//" };\n" +//"\n" +//" namespace baz {\n" +//"\n" +//" class MyBaz : public MyAnon\n" +//" {\n" +//" public:\n" +//" virtual void doit(int i)\n" +//" {\n" +//" n = i + 5;\n" +//" }\n" +//" };\n" +//"\n" +//" } // namespace baz\n" +//"\n" +//" } // namespace anon\n" +//"\n" +//" } // namespace nested\n" +//"\n" +// QTest::newRow("Namespace() +// { +// // This checks whether classes with "special" names are +// // properly displayed"); +// "using namespace nested;\n" +// "MyFoo foo;\n" +// "MyBar bar;\n" +// "MyAnon anon;\n" +// "baz::MyBaz baz;\n" +// % CheckType("anon namespc::nested::(anonymous namespace)::MyAnon"); +// % Check("bar", "namespc::nested::MyBar"); +// % CheckType("baz namespc::nested::(anonymous namespace)::baz::MyBaz"); +// % Check("foo", "namespc::nested::MyFoo"); +// // Continue"); +// // step into the doit() functions + +// baz.doit(1);\n" +// anon.doit(1);\n" +// foo.doit(1);\n" +// bar.doit(1);\n" +// dummyStatement();\n" +// } + + +// QTest::newRow("GccExtensions") +// "#ifdef __GNUC__\n" +// "char v[8] = { 1, 2 };\n" +// "char w __attribute__ ((vector_size (8))) = { 1, 2 };\n" +// "int y[2] = { 1, 2 };\n" +// "int z __attribute__ ((vector_size (8))) = { 1, 2 };\n" +// "#endif\n" +// % Check("v.0", "1", "char"); +// % Check("v.1", "2", "char"); +// % Check("w.0", "1", "char"); +// % Check("w.1", "2", "char"); +// % Check("y.0", "1", "int"); +// % Check("y.1", "2", "int"); +// % Check("z.0", "1", "int"); +// % Check("z.1", "2", "int"); + + +//class Z : public QObject +//{ +//public: +// Z() { +// f = new Foo(); +// i = 0; +// i = 1; +// i = 2; +// i = 3; +// } +// int i; +// Foo *f; +//}; + +//QString fooxx() +//{ +// return "bababa"; +//} + + + QTest::newRow("Int") + << Data("#include <qglobal.h>\n" + "#include <limits.h>\n" + "#include <QString>\n", + "quint64 u64 = ULLONG_MAX;\n" + "qint64 s64 = LLONG_MAX;\n" + "quint32 u32 = ULONG_MAX;\n" + "qint32 s32 = LONG_MAX;\n" + "quint64 u64s = 0;\n" + "qint64 s64s = LLONG_MIN;\n" + "quint32 u32s = 0;\n" + "qint32 s32s = LONG_MIN;\n" + "QString dummy; // needed to get namespace\n" + "dummyStatement(&u64, &s64, &u32, &s32, &u64s, &s64s, &u32s, &s32s, &dummy);\n") + % Check("u64", "18446744073709551615", "@quint64") + % Check("s64", "9223372036854775807", "@qint64") + % Check("u32", "4294967295", "@quint32") + % Check("s32", "2147483647", "@qint32") + % Check("u64s", "0", "@quint64") + % Check("s64s", "-9223372036854775808", "@qint64") + % Check("u32s", "0", "@quint32") + % Check("s32s", "-2147483648", "@qint32"); + + +// QTest::newRow("Array1") +// << Data( +// "double d[3][3];\n" +// "for (int i = 0; i != 3; ++i)\n" +// " for (int j = 0; j != 3; ++j)\n" +// " d[i][j] = i + j;\n" +// % CheckType("d double [3][3]"); +// % CheckType("d.0 double [3]"); +// % Check("d.0.0", "0", "double"); +// % Check("d.0.2", "2", "double"); +// % CheckType("d.2 double [3]"); + +// QTest::newRow("Array2") +// << Data( +// "char c[20];\n" +// "c[0] = 'a';\n" +// "c[1] = 'b';\n" +// "c[2] = 'c';\n" +// "c[3] = 'd';\n" +// % CheckType("c char [20]"); +// % Check("c.0 97 'a' char"); +// % Check("c.3 100 'd' char"); + +// QTest::newRow("Array3") +// << Data( +// "QString s[20]; +// "s[0] = "a";\n" +// "s[1] = "b";\n" +// "s[2] = "c";\n" +// "s[3] = "d";\n" +// % CheckType("s QString [20]"); +// % Check("s.0 "a" QString"); +// % Check("s.3 "d" QString"); +// % Check("s.4 "" QString"); +// % Check("s.19 "" QString"); + +// QTest::newRow("Array4") +// << Data( +// "QByteArray b[20];\n" +// "b[0] = "a";\n" +// "b[1] = "b";\n" +// "b[2] = "c";\n" +// "b[3] = "d";\n" +// % CheckType("b QByteArray [20]"); +// % Check("b.0 "a" QByteArray"); +// % Check("b.3 "d" QByteArray"); +// % Check("b.4 "" QByteArray"); +// % Check("b.19 "" QByteArray"); + + QTest::newRow("Array5") + << Data(fooData, + "Foo foo[10];\n" + "for (int i = 0; i < 5; ++i)\n" + " foo[i].a = i;\n") + % CheckType("foo", "Foo [10]") + % Check("foo.0", "[0]", "", "Foo") + % Check("foo.9", "[9]", "", "Foo"); + + + QTest::newRow("Bitfields") + << Data("struct S\n" + "{\n" + " S() : x(0), y(0), c(0), b(0), f(0), d(0), i(0) {}\n" + " unsigned int x : 1;\n" + " unsigned int y : 1;\n" + " bool c : 1;\n" + " bool b;\n" + " float f;\n" + " double d;\n" + " int i;\n" + "} s;\n" + "dummyStatement(&s);\n") + % Check("s", "", "S") + % Check("s.b", "false", "bool") + % Check("s.c", "false", "bool") + % Check("s.d", "0", "double") + % Check("s.f", "0", "float") + % Check("s.i", "0", "int") + % Check("s.x", "0", "unsigned int") + % Check("s.y", "0", "unsigned int"); + + + QTest::newRow("Function") + << Data("#include <QByteArray>\n" + "struct Function\n" + "{\n" + " Function(QByteArray var, QByteArray f, double min, double max)\n" + " : var(var), f(f), min(min), max(max) {}\n" + " QByteArray var;\n" + " QByteArray f;\n" + " double min;\n" + " double max;\n" + "};\n", + "// In order to use this, switch on the 'qDump__Function' in dumper.py\n" + "Function func(\"x\", \"sin(x)\", 0, 1);\n" + "func.max = 10;\n" + "func.f = \"cos(x)\";\n" + "func.max = 4;\n" + "func.max = 5;\n" + "func.max = 6;\n" + "func.max = 7;\n") + % Check("func", "", "Function") + % Check("func.f", "sin(x)", "@QByteArray") + % Check("func.max", "1", "double") + % Check("func.min", "0", "double") + % Check("func.var", "\"x\"", "@QByteArray") + % Check("func", "", "Function") + % Check("func.f", "\"cos(x)\"", "@QByteArray") + % Check("func.max", "7", "double"); + +// QTest::newRow("AlphabeticSorting") +// << Data( +// "// This checks whether alphabetic sorting of structure\n" +// "// members work");\n" +// "struct Color\n" +// "{\n" +// " int r,g,b,a;\n" +// " Color() { r = 1, g = 2, b = 3, a = 4; }\n" +// "};\n" +// " Color c;\n" +// % Check("c", "basic::Color"); +// % Check("c.a", "4", "int"); +// % Check("c.b", "3", "int"); +// % Check("c.g", "2", "int"); +// % Check("c.r", "1", "int"); + +// // Manual: Toogle "Sort Member Alphabetically" in context menu +// // Manual: of "Locals and Expressions" view"); +// // Manual: Check that order of displayed members changes"); + +// QTest::newRow("Typedef") +// << Data( +// "namespace ns {\n" +// " typedef unsigned long long vl;\n" +// " typedef vl verylong;\n" +// "}\n" + +// "typedef quint32 myType1;\n" +// "typedef unsigned int myType2;\n" +// "myType1 t1 = 0;\n" +// "myType2 t2 = 0;\n" +// "ns::vl j = 1000;\n" +// "ns::verylong k = 1000;\n" +// % Check("j", "1000", "basic::ns::vl"); +// % Check("k", "1000", "basic::ns::verylong"); +// % Check("t1", "0", "basic::myType1"); +// % Check("t2", "0", "basic::myType2"); + +// QTest::newRow("Struct") +// << Data( +// "Foo f(2);\n" +// "f.doit();\n" +// "f.doit();\n" +// "f.doit();\n" +// % Check("f", "Foo"); +// % Check("f.a", "5", "int"); +// % Check("f.b", "2", "int"); + +// QTest::newRow("Union") +// << Data( +// "union U\n" +// "{\n" +// " int a;\n" +// " int b;\n" +// "} u;\n" +// % Check("u", "basic::U"); +// % Check("u.a", "int"); +// % Check("u.b", "int"); + +// QTest::newRow("TypeFormats") +// << Data( +// "// These tests should result in properly displayed umlauts in the\n" +// "// Locals and Expressions view. It is only support on gdb with Python");\n" +// "const char *s = "aöa";\n" +// "const wchar_t *w = L"aöa";\n" +// "QString u;\n" +// "// All: Select UTF-8 in "Change Format for Type" in L&W context menu");\n" +// "// Windows: Select UTF-16 in "Change Format for Type" in L&W context menu");\n" +// "// Other: Select UCS-6 in "Change Format for Type" in L&W context menu");\n" +// "if (sizeof(wchar_t) == 4)\n" +// " u = QString::fromUcs4((uint *)w);\n" +// "else\n" +// " u = QString::fromUtf16((ushort *)w);\n" +// % CheckType("s char *"); +// % Check("u "" QString"); +// % CheckType("w wchar_t *"); + + + +// typedef void *VoidPtr; +// typedef const void *CVoidPtr; + +// struct A +// { +// A() : test(7) {} +// int test; +// void doSomething(CVoidPtr cp) const; +// }; + +// void A::doSomething(CVoidPtr cp) const +// % Check("cp", "basic::CVoidPtr"); + +// QTest::newRow("Pointer") +// << Data( +// "Foo *f = new Foo();\n" +// % Check("f", "Foo"); +// % Check("f.a", "0", "int"); +// % Check("f.b", "5", "int"); + +// QTest::newRow("PointerTypedef") +// << Data( +// "A a;\n" +// "VoidPtr p = &a;\n" +// "CVoidPtr cp = &a;\n" +// % Check("a", "basic::A"); +// % Check("cp", "basic::CVoidPtr"); +// % Check("p", "basic::VoidPtr"); + +// QTest::newRow("StringWithNewline") +// << Data( +// "QString hallo = "hallo\nwelt";\n" +// % Check("hallo "hallo\nwelt" QString"); +// % Check("that string is properly displayed"); + +// QTest::newRow("Reference1") +// << Data( +// "int a = 43;\n" +// "const int &b = a;\n" +// "typedef int &Ref;\n" +// "const int c = 44;\n" +// "const Ref d = a;\n" +// % Check("a", "43", "int"); +// % Check("b 43 int &"); +// % Check("c", "44", "int"); +// % Check("d", "43", "basic::Ref"); + +// QTest::newRow("Reference2") +// << Data( +// "QString a = "hello";\n" +// "const QString &b = fooxx();\n" +// "typedef QString &Ref;\n" +// "const QString c = "world";\n" +// "const Ref d = a;\n" +// % Check("a "hello" QString"); +// % Check("b "bababa" QString &"); +// % Check("c "world" QString"); +// % Check("d "hello" basic::Ref"); + + QTest::newRow("Reference3") + << Data("#include <QString>\n", + "const QString &b = a;\n" + "typedef QString &Ref;\n" + "const Ref d = const_cast<Ref>(a);\n") + % Check("a", "\"hello\"", "@QString &") + % Check("b", "\"hello\"", "@QString &") + % Check("d", "\"hello\"", "Ref"); + + QTest::newRow("DynamicReference") + << Data("DerivedClass d;\n" + "BaseClass *b1 = &d;\n" + "BaseClass &b2 = d;\n" + "dummyStatement(&b1, &b2);\n") + % CheckType("b1", "DerivedClass *") + % CheckType("b2", "DerivedClass &"); + +// QTest::newRow("LongEvaluation1") +// << Data( +// "QDateTime time = QDateTime::currentDateTime();\n" +// "const int N = 10000;\n" +// "QDateTime bigv[N];\n" +// "for (int i = 0; i < 10000; ++i) {\n" +// " bigv[i] = time;\n" +// " time = time.addDays(1);\n" +// "}\n" +// % Check("N", "10000", "int"); +// % CheckType("bigv QDateTime [10000]"); +// % Check("bigv.0", "QDateTime"); +// % Check("bigv.9999", "QDateTime"); +// % Check("time", "QDateTime"); + +// QTest::newRow("LongEvaluation2") +// << Data( +// "const int N = 10000;\n" +// "int bigv[N];\n" +// "for (int i = 0; i < 10000; ++i)\n" +// " bigv[i] = i;\n" +// % Check("N", "10000", "int"); +// % CheckType("bigv int [10000]"); +// % Check("bigv.0", "0", "int"); +// % Check("bigv.9999", "9999", "int"); + +// QTest::newRow("Fork") +// << Data( +// "QProcess proc;\n" +// "proc.start("/bin/ls");\n" +// "proc.waitForFinished();\n" +// "QByteArray ba = proc.readAllStandardError();\n" +// "ba.append('x');\n" +// % Check("ba "x" QByteArray"); +// % Check("proc QProcess"); + + +// QTest::newRow("FunctionPointer") +// << Data( +// "int testFunctionPointerHelper(int x) { return x; }\n" +// "typedef int (*func_t)(int);\n" +// "func_t f = testFunctionPointerHelper;\n" +// "int a = f(43);\n" +// % Check("f", "basic::func_t"); + +// QByteArray dataClass = "struct Class +// "{\n" +// " Class() : a(34) {}\n" +// " int testFunctionPointerHelper(int x) { return x; }\n" +// " int a;\n" +// "};\n" + +// QTest::newRow("MemberFunctionPointer") +// << Data( + +// "Class x;\n" +// "typedef int (Class::*func_t)(int);\n" +// "func_t f = &Class::testFunctionPointerHelper;\n" +// "int a = (x.*f)(43);\n" +// % Check("f", "basic::func_t"); + +// QTest::newRow("MemberPointer") +// << Data( +// Class x;\n" +// typedef int (Class::*member_t);\n" +// member_t m = &Class::a;\n" +// int a = x.*m;\n" +// % Check("m", "basic::member_t");\n" +// // Continue");\n" + +// % Check("there's a valid display for m"); + +// QTest::newRow("PassByReferenceHelper(Foo &f) +// % CheckType("f Foo &");\n" +// % Check("f.a", "12", "int");\n" +// // Continue");\n" +// ++f.a;\n" +// % CheckType("f Foo &");\n" +// % Check("f.a", "13", "int");\n" + +// QTest::newRow("PassByReference") +// << Data( +// "Foo f(12);\n" +// "testPassByReferenceHelper(f);\n" + +// QTest::newRow("BigInt") +// << Data( +// "qint64 a = Q_INT64_C(0xF020304050607080);\n" +// "quint64 b = Q_UINT64_C(0xF020304050607080);\n" +// "quint64 c = std::numeric_limits<quint64>::max() - quint64(1);\n" +// % Check("a", "-1143861252567568256", "qint64"); +// % Check("b", "-1143861252567568256", "quint64"); +// % Check("c", "-2", "quint64"); + +// QTest::newRow("Hidden") +// << Data( +// { +// int n = 1;\n" +// n = 2;\n" +// BREAK_HERE;\n" +// % Check("n", "2", "int");\n" +// // Continue");\n" +// n = 3;\n" +// BREAK_HERE;\n" +// % Check("n", "3", "int");\n" +// // Continue");\n" +// {\n" +// QString n = "2";\n" +// BREAK_HERE;\n" +// % Check("n "2" QString");\n" +// % Check("n@1", "3", "int");\n" +// // Continue");\n" +// n = "3";\n" +// BREAK_HERE;\n" +// % Check("n "3" QString");\n" +// % Check("n@1", "3", "int");\n" +// // Continue");\n" +// {\n" +// double n = 3.5;\n" +// BREAK_HERE;\n" +// % Check("n", "3.5", "double");\n" +// % Check("n@1 "3" QString");\n" +// % Check("n@2", "3", "int");\n" +// // Continue");\n" +// ++n;\n" +// BREAK_HERE;\n" +// % Check("n", "4.5", "double");\n" +// % Check("n@1 "3" QString");\n" +// % Check("n@2", "3", "int");\n" +// // Continue");\n" +// dummyStatement(&n);\n" +// }\n" +// BREAK_HERE;\n" +// % Check("n "3" QString");\n" +// % Check("n@1", "3", "int");\n" +// // Continue");\n" +// n = "3";\n" +// n = "4"; +// BREAK_HERE;\n" +// % Check("n "4" QString");\n" +// % Check("n@1", "3", "int");\n" +// // Continue");\n" +// dummyStatement(&n);\n" +// }\n" +// ++n;\n" +// dummyStatement(&n);\n" +// }\n" +//\n" +// int testReturnInt") +// << Data( +// { +// return 1; +// } + +// bool testReturnBool") +// << Data( +// { +// return true; +// } + +// QString testReturnQString") +// << Data( +// { +// return "string"; +// } + +// QTest::newRow("Return") +// << Data( +// { +// bool b = testReturnBool(); +// BREAK_HERE; +// % Check("b", "true", "bool"); +// // Continue"); +// int i = testReturnInt(); +// BREAK_HERE; +// % Check("i", "1", "int"); +// // Continue"); +// QString s = testReturnQString(); +// BREAK_HERE; +// % Check("s "string" QString"); +// // Continue"); +// dummyStatement(&i, &b, &s); +// } + +// #ifdef Q_COMPILER_RVALUE_REFS\n" +// struct X { X() : a(2), b(3) {} int a, b; };\n" +//\n" +// X testRValueReferenceHelper1()\n" +// {\n" +// return X();\n" +// }\n" +//\n" +// X testRValueReferenceHelper2(X &&x)\n" +// {\n" +// return x;\n" +// }\n" +//\n" +// QTest::newRow("RValueReference()\n" +// {\n" +// X &&x1 = testRValueReferenceHelper1();\n" +// X &&x2 = testRValueReferenceHelper2(std::move(x1));\n" +// X &&x3 = testRValueReferenceHelper2(testRValueReferenceHelper1());\n" +//\n" +// X y1 = testRValueReferenceHelper1();\n" +// X y2 = testRValueReferenceHelper2(std::move(y1));\n" +// X y3 = testRValueReferenceHelper2(testRValueReferenceHelper1());\n" +//\n" +// BREAK_HERE;\n" +// // Continue");\n" +// dummyStatement(&x1, &x2, &x3, &y1, &y2, &y3);\n" +// }\n" + +// QTest::newRow("SSE") +// << Data( +// { +// #ifdef __SSE__\n" +// float a[4];\n" +// float b[4];\n" +// int i;\n" +// for (i = 0; i < 4; i++) {\n" +// a[i] = 2 * i;\n" +// b[i] = 2 * i;\n" +// }\n" +// __m128 sseA, sseB;\n" +// sseA = _mm_loadu_ps(a);\n" +// sseB = _mm_loadu_ps(b);\n" +// % Check("sseA", "__m128"); +// % Check("sseB", "__m128"); +// // Continue"); +// dummyStatement(&i, &sseA, &sseB); +// #endif +// } + +//} // namespace sse + + +//namespace qscript { + +// QTest::newRow("QScript") +// << Data( +//" QScriptEngine engine;n" +//" QDateTime date = QDateTime::currentDateTime();n" +//" QScriptValue s;n" +//"n" +//" % Check("engine QScriptEngine");n" +//" % Check("s", "(invalid)", "QScriptValue");n" +//" % Check("x1 <not accessible> QString");n" +//" // Continue");n" +//" s = QScriptValue(33);n" +//" int x = s.toInt32();n" +//"n" +//" s = QScriptValue(QString("34"));n" +//" QString x1 = s.toString();n" +//"n" +//" s = engine.newVariant(QVariant(43));n" +//" QVariant v = s.toVariant();n" +//"n" +//" s = engine.newVariant(QVariant(43.0));n" +//" s = engine.newVariant(QVariant(QString("sss")));n" +//" s = engine.newDate(date);n" +//" date = s.toDateTime();n" +//" s.setProperty("a", QScriptValue());n" +//" QScriptValue d = s.data();n" +// % Check("d", "(invalid)", "QScriptValue"); +// % Check("v 43 QVariant (int)"); +// % Check("x", "33", "int"); +// % Check("x1 "34" QString"); + + +// QTest::newRow("WTFString") +// << Data( +// "QWebPage p; +// % Check("p", "QWebPage"); + +// QTest::newRow("BoostOptional1") +// << Data( +// "boost::optional<int> i0, i; +// "i = 1; +// % Check("i0", "<uninitialized>", "boost::optional<int>"); +// % Check("i", "1", "boost::optional<int>"); + +// QTest::newRow("BoostOptional2") +// << Data( +// "boost::optional<QStringList> sl0, sl;\n" +// "sl = (QStringList() << "xxx" << "yyy");\n" +// "sl.get().append("zzz");\n" +// % Check("sl", "<uninitialized>", "boost::optional<QStringList>"); +// % Check("sl <3 items> boost::optional<QStringList>"); + +// QTest::newRow("BoostSharedPtr") +// << Data( +// "boost::shared_ptr<int> s;\n" +// "boost::shared_ptr<int> i(new int(43));\n" +// "boost::shared_ptr<int> j = i;\n" +// "boost::shared_ptr<QStringList> sl(new QStringList(QStringList() << "HUH!")); +// % Check("s", "(null)", "boost::shared_ptr<int>"); +// % Check("i", "43", "boost::shared_ptr<int>"); +// % Check("j", "43", "boost::shared_ptr<int>"); +// % Check("sl boost::shared_ptr<QStringList>"); +// % Check("sl.data <1 items> QStringList + +// QTest::newRow("BoostGregorianDate") +// << Data( +// "using namespace boost;\n" +// "using namespace gregorian;\n" +// "date d(2005, Nov, 29);\n" +// "d += months(1);\n" +// "d += months(1);\n" +// "// snap-to-end-of-month behavior kicks in:\n" +// "d += months(1);\n" +// "// Also end of the month (expected in boost)\n" +// "d += months(1);\n" +// "// Not where we started (expected in boost)\n" +// "d -= months(4);\n" +// % Check("d Tue Nov 29 2005 boost::gregorian::date"); +// % Check("d Thu Dec 29 2005 boost::gregorian::date"); +// % Check("d Sun Jan 29 2006 boost::gregorian::date"); +// % Check("d Tue Feb 28 2006 boost::gregorian::date"); +// % Check("d Fri Mar 31 2006 boost::gregorian::date"); +// % Check("d Wed Nov 30 2005 boost::gregorian::date"); + +// QTest::newRow("BoostPosixTimeTimeDuration") +// << Data( +// "using namespace boost;\n" +// "using namespace posix_time;\n" +// "time_duration d1(1, 0, 0);\n" +// "time_duration d2(0, 1, 0);\n" +// "time_duration d3(0, 0, 1);\n" +// % Check("d1", "01:00:00", "boost::posix_time::time_duration"); +// % Check("d2", "00:01:00", "boost::posix_time::time_duration"); +// % Check("d3", "00:00:01", "boost::posix_time::time_duration"); + +// QTest::newRow("BoostBimap") +// << Data( +// "typedef boost::bimap<int, int> B;\n" +// "B b;\n" +// "b.left.insert(B::left_value_type(1, 2));\n" +// "B::left_const_iterator it = b.left.begin();\n" +// "int l = it->first;\n" +// "int r = it->second;\n" +// % Check("b <0 items> boost::B"); +// % Check("b <1 items> boost::B"); + +// QTest::newRow("BoostPosixTimePtime") +// << Data( +// "using namespace boost;\n" +// "using namespace gregorian;\n" +// "using namespace posix_time;\n" +// "ptime p1(date(2002, 1, 10), time_duration(1, 0, 0));\n" +// "ptime p2(date(2002, 1, 10), time_duration(0, 0, 0));\n" +// "ptime p3(date(1970, 1, 1), time_duration(0, 0, 0));\n" +// % Check("p1 Thu Jan 10 01:00:00 2002 boost::posix_time::ptime"); +// % Check("p2 Thu Jan 10 00:00:00 2002 boost::posix_time::ptime"); +// % Check("p3 Thu Jan 1 00:00:00 1970 boost::posix_time::ptime"); + + + +// // This tests qdump__KRBase in dumpers/qttypes.py which uses +// // a static typeflag to dispatch to subclasses"); + +// QTest::newRow("KR") +// << Data( +// "namespace kr {\n" +//\n" +// " // FIXME: put in namespace kr, adjust qdump__KRBase in dumpers/qttypes.py\n" +// " struct KRBase\n" +// " {\n" +// " enum Type { TYPE_A, TYPE_B } type;\n" +// " KRBase(Type _type) : type(_type) {}\n" +// " };\n" +//\n" +// " struct KRA : KRBase { int x; int y; KRA():KRBase(TYPE_A), x(1), y(32) {} };\n" +// " struct KRB : KRBase { KRB():KRBase(TYPE_B) {} };\n" + +// "/} // namespace kr\n" + +// "KRBase *ptr1 = new KRA;\n" +// "KRBase *ptr2 = new KRB;\n" +// "ptr2 = new KRB;\n" +// % Check("ptr1", "KRBase"); +// % Check("ptr1.type KRBase::TYPE_A (0) KRBase::Type"); +// % Check("ptr2", "KRBase"); +// % Check("ptr2.type KRBase::TYPE_B (1) KRBase::Type"); + + + +// QTest::newRow("Eigen") +// << Data( +// "using namespace Eigen;\n" + +// "Vector3d test = Vector3d::Zero();\n" + +// "Matrix3d myMatrix = Matrix3d::Constant(5);\n" +// "MatrixXd myDynamicMatrix(30, 10);\n" + +// "myDynamicMatrix(0, 0) = 0;\n" +// "myDynamicMatrix(1, 0) = 1;\n" +// "myDynamicMatrix(2, 0) = 2;\n" + +// "Matrix<double, 12, 15, ColMajor> colMajorMatrix;\n" +// "Matrix<double, 12, 15, RowMajor> rowMajorMatrix;\n" + +// "int k = 0;\n" +// "for (int i = 0; i != 12; ++i) {\n" +// " for (int j = 0; j != 15; ++j) {\n" +// " colMajorMatrix(i, j) = k;\n" +// " rowMajorMatrix(i, j) = k;\n" +// " ++k;\n" +// " }\n" +// "}\n" + + + +// QTest::newRow("https://bugreports.qt-project.org/browse/QTCREATORBUG-3611") +// "typedef unsigned char byte;\n" +// "byte f = '2';\n" +// "int *x = (int*)&f;\n" +// % Check("f 50 '2' bug3611::byte"); + + + +// QTest::newRow("https://bugreports.qt-project.org/browse/QTCREATORBUG-4904") +// << Data( + +// "struct CustomStruct {\n" +// " int id;\n" +// " double dvalue;\n" +// "};", +// "QMap<int, CustomStruct> map;\n" +// "CustomStruct cs1;\n" +// "cs1.id = 1;\n" +// "cs1.dvalue = 3.14;\n" +// "CustomStruct cs2 = cs1;\n" +// "cs2.id = -1;\n" +// "map.insert(cs1.id, cs1);\n" +// "map.insert(cs2.id, cs2);\n" +// "QMap<int, CustomStruct>::iterator it = map.begin();\n" +// % Check("map <2 items> QMap<int, bug4904::CustomStruct>"); +// % Check("map.0 QMapNode<int, bug4904::CustomStruct>"); +// % Check("map.0.key", "-1", "int"); +// % Check("map.0.value", "bug4904::CustomStruct"); +// % Check("map.0.value.dvalue", "3.1400000000000001", "double"); +// % Check("map.0.value.id", "-1", "int"); + + +// QTest::newRow("// https://bugreports.qt-project.org/browse/QTCREATORBUG-5106") +// << Data( +// "class A5106\n" +// "{\n" +// "public:\n" +// " A5106(int a, int b) : m_a(a), m_b(b) {}\n" +// " virtual int test() { return 5; }\n" +// "private:\n" +// " int m_a, m_b;\n" +// "};\n" + +// "class B5106 : public A5106\n" +// "{\n" +// "public:\n" +// " B5106(int c, int a, int b) : A5106(a, b), m_c(c) {}\n" +// " virtual int test() { return 4; BREAK_HERE; }\n" +// "private:\n" +// " int m_c;\n" +// "};\n" +// , +// " B5106 b(1,2,3);\n" +// " b.test();\n" +// " b.A5106::test();\n" +// } + + +// // https://bugreports.qt-project.org/browse/QTCREATORBUG-5184 + +// // Note: The report there shows type field "QUrl &" instead of QUrl"); +// // It's unclear how this can happen. It should never have been like +// // that with a stock 7.2 and any version of Creator"); + +// void helper(const QUrl &url)\n" +// {\n" +// QNetworkRequest request(url);\n" +// QList<QByteArray> raw = request.rawHeaderList();\n" +// % Check("raw <0 items> QList<QByteArray>"); +// % Check("request", "QNetworkRequest"); +// % Check("url "http://127.0.0.1/" QUrl &"); +// } + +// QTest::newRow("5184() +// { +// QUrl url(QString("http://127.0.0.1/"));\n" +// helper(url);\n" +// } + + +//namespace qc42170 { + +// // http://www.qtcentre.org/threads/42170-How-to-watch-data-of-actual-type-in-debugger + +// struct Object +// { +// Object(int id_) : id(id_) {} +// virtual ~Object() {} +// int id; +// }; + +// struct Point : Object +// { +// Point(double x_, double y_) : Object(1), x(x_), y(y_) {} +// double x, y; +// }; + +// struct Circle : Point +// { +// Circle(double x_, double y_, double r_) : Point(x_, y_), r(r_) { id = 2; } +// double r; +// }; + +// void helper(Object *obj) +// { +// % Check("obj", "qc42170::Circle"); +// // Continue"); + +// % Check("that obj is shown as a 'Circle' object"); +// dummyStatement(obj); +// } + +// QTest::newRow("42170") +// << Data( +// { +// Circle *circle = new Circle(1.5, -2.5, 3.0); +// Object *obj = circle; +// helper(circle); +// helper(obj); +// } + +//} // namespace qc42170 + + +//namespace bug5799 { + +// // https://bugreports.qt-project.org/browse/QTCREATORBUG-5799 + +// QTest::newRow("5799() +// "typedef struct { int m1; int m2; } S1;\n" +// "struct S2 : S1 { };\n" +// "typedef struct S3 { int m1; int m2; } S3;\n" +// "struct S4 : S3 { };\n" + +// "S2 s2;\n" +// "s2.m1 = 5;\n" +// "S4 s4;\n" +// "s4.m1 = 5;\n" +// "S1 a1[10];\n" +// "typedef S1 Array[10];\n" +// "Array a2;\n" +// % CheckType("a1 bug5799::S1 [10]"); +// % Check("a2", "bug5799::Array"); +// % Check("s2", "bug5799::S2"); +// % Check("s2.@1", "bug5799::S1"); +// % Check("s2.@1.m1", "5", "int"); +// % Check("s2.@1.m2", "int"); +// % Check("s4", "bug5799::S4"); +// % Check("s4.@1", "bug5799::S3"); +// % Check("s4.@1.m1", "5", "int"); +// % Check("s4.@1.m2", "int"); + + +// // http://www.qtcentre.org/threads/41700-How-to-watch-STL-containers-iterators-during-debugging + +// QTest::newRow("41700") +// << Data( +// { +// "using namespace std;\n" +// "typedef map<string, list<string> > map_t;\n" +// "map_t m;\n" +// "m["one"].push_back("a");\n" +// "m["one"].push_back("b");\n" +// "m["one"].push_back("c");\n" +// "m["two"].push_back("1");\n" +// "m["two"].push_back("2");\n" +// "m["two"].push_back("3");\n" +// "map_t::const_iterator it = m.begin(); +// % Check("m <2 items> qc41700::map_t"); +// % Check("m.0 std::pair<std::string const, std::list<std::string>>"); +// % Check("m.0.first "one" std::string"); +// % Check("m.0.second <3 items> std::list<std::string>"); +// % Check("m.0.second.0 "a" std::string"); +// % Check("m.0.second.1 "b" std::string"); +// % Check("m.0.second.2 "c" std::string"); +// % Check("m.1 std::pair<std::string const, std::list<std::string>>"); +// % Check("m.1.first "two" std::string"); +// % Check("m.1.second <3 items> std::list<std::string>"); +// % Check("m.1.second.0 "1" std::string"); +// % Check("m.1.second.1 "2" std::string"); +// % Check("m.1.second.2 "3" std::string"); + + +// // http://codepaster.europe.nokia.com/?id=42895 + +// QTest::newRow("42895() +// "void g(int c, int d)\n" +// "{\n" +// "qDebug() << c << d;\n" +// "stopper()"\n" +//\n" +// "void f(int a, int b)\n" +// "{\n" +// " g(a, b);\n" +// "}\n" + +// " f(3, 4);\n" + +// % Check("c", "3", "int"); +// % Check("d", "4", "int"); +// % Check("there are frames for g and f in the stack view"); + + + + +// // https://bugreports.qt-project.org/browse/QTCREATORBUG-6465 + +// QTest::newRow("6465()\n" +// {\n" +// typedef char Foo[20];\n" +// Foo foo = "foo";\n" +// char bar[20] = "baz"; + +//namespace bug6857 { + +// class MyFile : public QFile +// { +// public: +// MyFile(const QString &fileName) +// : QFile(fileName) {} +// }; + +// QTest::newRow("6857") +// << Data( +// MyFile file("/tmp/tt"); +// file.setObjectName("A file"); +// % Check("file bug6857::MyFile"); +// % Check("file.@1 "/tmp/tt" QFile"); +// % Check("file.@1.@1.@1 "A file" QObject"); + + +//namespace bug6858 { + +// class MyFile : public QFile\n" +// {\n" +// public:\n" +// MyFile(const QString &fileName)\n" +// : QFile(fileName) {}\n" +// };\n" + +// QTest::newRow("6858") +// << Data( +// MyFile file("/tmp/tt");\n" +// file.setObjectName("Another file");\n" +// QFile *pfile = &file;\n" +// % Check("pfile bug6858::MyFile"); +// % Check("pfile.@1 "/tmp/tt" QFile"); +// % Check("pfile.@1.@1.@1 "Another file" QObject"); + +//namespace bug6863 { + +// class MyObject : public QObject\n" +// {\n" +// Q_OBJECT\n" +// public:\n" +// MyObject() {}\n" +// };\n" +//\n" +// void setProp(QObject *obj)\n" +// {\n" +// obj->setProperty("foo", "bar"); +// % Check("obj.[QObject].properties", "<2", "items>"); +// // Continue"); +// dummyStatement(&obj); +// } + +// QTest::newRow("6863") +// << Data( +// { +// QFile file("/tmp/tt");\n" +// setProp(&file);\n" +// MyObject obj;\n" +// setProp(&obj);\n" +// }\n" + +//} + + + +// QTest::newRow("6933") +// << Data( +// "class Base\n" +// "{\n" +// "public:\n" +// " Base() : a(21) {}\n" +// " virtual ~Base() {}\n" +// " int a;\n" +// "};\n" + +// "class Derived : public Base\n" +// "{\n" +// "public:\n" +// " Derived() : b(42) {}\n" +// " int b;\n" +// "};\n" + +// "Derived d;\n" +// "Base *b = &d;\n" +// % Check("b.[bug6933::Base].[vptr] +// % Check("b.b", "42", "int"); + + + QTest::newRow("valist") + << Data("#include <stdarg.h>\n" + "void test(const char *format, ...)\n" + "{\n" + " va_list arg;\n" + " va_start(arg, format);\n" + " int i = va_arg(arg, int);\n" + " double f = va_arg(arg, double);\n" + " dummyStatement(&i, &f);\n" + " va_end(arg);\n" + " stopper();\n" + "}\n", + "test(\"abc\", 1, 2.0);\n") + % Check("i", "1", "int") + % Check("f", "2", "double"); + + + QTest::newRow("gdb13393") + << Data( + "struct Base {\n" + " Base() : a(1) {}\n" + " virtual ~Base() {} // Enforce type to have RTTI\n" + " int a;\n" + "};\n" + "struct Derived : public Base {\n" + " Derived() : b(2) {}\n" + " int b;\n" + "};\n" + "struct S\n" + "{\n" + " Base *ptr;\n" + " const Base *ptrConst;\n" + " Base &ref;\n" + " const Base &refConst;\n" + " S(Derived &d)\n" + " : ptr(&d), ptrConst(&d), ref(d), refConst(d)\n" + " {}\n" + " };\n" + , + "Derived d;\n" + "S s(d);\n" + "Base *ptr = &d;\n" + "const Base *ptrConst = &d;\n" + "Base &ref = d;\n" + "const Base &refConst = d;\n" + "Base **ptrToPtr = &ptr;\n" + "#if USE_BOOST\n" + "boost::shared_ptr<Base> sharedPtr(new Derived());\n" + "#else\n" + "int sharedPtr = 1;\n" + "#endif\n" + "dummyStatement(&ptrConst, &ref, &refConst, &ptrToPtr, &sharedPtr);\n") + % Check("d", "", "Derived") + % Check("d.@1", "[Base]", "", "Base") + % Check("d.b", "2", "int") + % Check("ptr", "", "Derived") + % Check("ptr.@1", "[Base]", "", "Base") + % Check("ptr.@1.a", "1", "int") + % Check("ptrConst", "", "Derived") + % Check("ptrConst.@1", "[Base]", "", "Base") + % Check("ptrConst.b", "2", "int") + % Check("ptrToPtr", "", "Derived") + //% CheckType("ptrToPtr.[vptr]", " ") + % Check("ptrToPtr.@1.a", "1", "int") + % Check("ref", "", "Derived &") + //% CheckType("ref.[vptr]", "") + % Check("ref.@1.a", "1", "int") + % Check("refConst", "", "Derived &") + //% CheckType("refConst.[vptr]", "") + % Check("refConst.@1.a", "1", "int") + % Check("s", "", "S") + % Check("s.ptr", "", "Derived") + % Check("s.ptrConst", "", "Derived") + % Check("s.ref", "", "Derived &") + % Check("s.refConst", "", "Derived &") + % Check("sharedPtr", "1", "int"); + + + // http://sourceware.org/bugzilla/show_bug.cgi?id=10586. fsf/MI errors out + // on -var-list-children on an anonymous union. mac/MI was fixed in 2006"); + // The proposed fix has been reported to crash gdb steered from eclipse"); + // http://sourceware.org/ml/gdb-patches/2011-12/msg00420.html + QTest::newRow("gdb10586mi") + << Data("struct Test {\n" + " struct { int a; float b; };\n" + " struct { int c; float d; };\n" + "} v = {{1, 2}, {3, 4}};\n" + "dummyStatement(&v);\n") + % Check("v", "", "Test") + % Check("v.a", "1", "int"); + + QTest::newRow("gdb10586eclipse") + << Data("struct { int x; struct { int a; }; struct { int b; }; } v = {1, {2}, {3}};\n" + "struct S { int x, y; } n = {10, 20};\n" + "dummyStatement(&v, &n);\n") + % Check("v", "", "{...}") + % Check("n", "", "S") + % Check("v.a", "2", "int") + % Check("v.b", "3", "int") + % Check("v.x", "1", "int") + % Check("n.x", "10", "int") + % Check("n.y", "20", "int"); } @@ -2507,4 +3956,3 @@ int main(int argc, char *argv[]) } #include "tst_dumpers.moc" - diff --git a/tests/auto/debugger/tst_gdb.cpp b/tests/auto/debugger/tst_gdb.cpp index 347832e378..6367c9cba6 100644 --- a/tests/auto/debugger/tst_gdb.cpp +++ b/tests/auto/debugger/tst_gdb.cpp @@ -36,7 +36,7 @@ bool checkUninitialized = false; #define DO_DEBUG 1 //TESTED_COMPONENT=src/plugins/debugger/gdb -#include "gdb/gdbmi.h" +#include "debuggerprotocol.h" #ifdef QT_GUI_LIB #include <QBitmap> @@ -97,6 +97,14 @@ QString gdbBinary = "c:\\MinGw\\bin\\gdb.exe"; QString gdbBinary = "gdb"; #endif +#if QT_VERSION >= 0x050000 +#define MSKIP_SINGLE(x) QSKIP(x) +#define MSKIP_ALL(x) QSKIP(x); +#else +#define MSKIP_SINGLE(x) QSKIP(x, SkipSingle) +#define MSKIP_ALL(x) QSKIP(x, SkipAll) +#endif + void nothing() {} template <typename T> QByteArray N(T v) { return QByteArray::number(v); } @@ -329,11 +337,13 @@ QByteArray str(const void *p) void tst_Gdb::dumperCompatibility() { +#ifdef Q_OS_MACX // Ensure that no arbitrary padding is introduced by QVectorTypedData. const size_t qVectorDataSize = 16; QCOMPARE(sizeof(QVectorData), qVectorDataSize); QVectorTypedData<int> *v = 0; QCOMPARE(size_t(&v->array), qVectorDataSize); +#endif } static const QByteArray utfToHex(const QString &string) @@ -369,7 +379,7 @@ GdbWrapper::GdbWrapper(tst_Gdb *test) : m_test(test) { qWarning() << "SETUP START\n\n"; #ifndef Q_CC_GNU - QSKIP("gdb test not applicable for compiler", SkipAll); + MSKIP_ALL("gdb test not applicable for compiler"); #endif //qDebug() << "\nRUN" << getpid() << gettid(); QStringList args; @@ -381,7 +391,7 @@ GdbWrapper::GdbWrapper(tst_Gdb *test) : m_test(test) if (!m_proc.waitForStarted()) { const QString msg = QString::fromLatin1("Unable to run %1: %2") .arg(gdbBinary, m_proc.errorString()); - QSKIP(msg.toLatin1().constData(), SkipAll); + MSKIP_ALL(msg.toLatin1().constData()); } connect(&m_proc, SIGNAL(error(QProcess::ProcessError)), @@ -540,7 +550,7 @@ void tst_Gdb::initTestCase() if (!file.open(QIODevice::ReadOnly)) { const QString msg = QString::fromLatin1("Unable to open %1: %2") .arg(fileName, file.errorString()); - QSKIP(msg.toLatin1().constData(), SkipAll); + MSKIP_ALL(msg.toLatin1().constData()); } QByteArray funcName; diff --git a/tests/auto/debugger/tst_namedemangler.cpp b/tests/auto/debugger/tst_namedemangler.cpp index c7eeb303ee..7622b29976 100644 --- a/tests/auto/debugger/tst_namedemangler.cpp +++ b/tests/auto/debugger/tst_namedemangler.cpp @@ -34,7 +34,7 @@ #define TEST_CORRECTLY_MANGLED_NAME(mangled, expectedDemangled) \ do { \ - QVERIFY2(demangler.demangle(mangled), qPrintable(demangler.errorString())); \ + QVERIFY2(demangler.demangle(QLatin1String(mangled)), qPrintable(demangler.errorString())); \ QCOMPARE(demangler.demangledName(), QLatin1String(expectedDemangled)); \ } while (0) @@ -58,7 +58,8 @@ private: void NameDemanglerAutoTest::testUnmangledName() { - QVERIFY(demangler.demangle("f") && demangler.demangledName() == "f"); + QVERIFY(demangler.demangle(QLatin1String("f")) + && demangler.demangledName() == QLatin1String("f")); } void NameDemanglerAutoTest::testCorrectlyMangledNames() diff --git a/tests/auto/debugger/tst_olddumpers.cpp b/tests/auto/debugger/tst_olddumpers.cpp new file mode 100644 index 0000000000..ab38245301 --- /dev/null +++ b/tests/auto/debugger/tst_olddumpers.cpp @@ -0,0 +1,2510 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#define private public // Give us access to private 'backward' member of QMapNode. +# include <QMap> +#undef private + +#include "gdb/gdbmi.h" +#include "dumper.h" +#include "dumper_p.h" + +#include "json.h" + +#ifdef USE_PRIVATE +#include <private/qobject_p.h> +#else +#warning "No private headers for this Qt version available" +#endif + +#include <QStandardItemModel> +#include <QStringListModel> + +#include <QtTest> +//#include <QtTest/qtest_gui.h> + +//TESTED_COMPONENT=src/plugins/debugger/gdb + +static const char *pointerPrintFormat() +{ + return sizeof(quintptr) == sizeof(long) ? "0x%lx" : "0x%llx"; +} + +#undef NS +#ifdef QT_NAMESPACE +# define STRINGIFY0(s) #s +# define STRINGIFY1(s) STRINGIFY0(s) +# define NS STRINGIFY1(QT_NAMESPACE) "::" +#else +# define NS "" +#endif + +using namespace Debugger; +using namespace Debugger::Internal; + +static QByteArray operator<<(QByteArray ba, const QByteArray &replacement) +{ + int pos = ba.indexOf('%'); + Q_ASSERT(pos != -1); + return ba.replace(pos, 1, replacement); +} + +static QByteArray &operator<<=(QByteArray &ba, const QByteArray &replacement) +{ + int pos = ba.indexOf('%'); + Q_ASSERT(pos != -1); + return ba.replace(pos, 1, replacement); +} + + +template <typename T> +inline QByteArray N(T t) { return QByteArray::number(t); } + +static const char gdbmi1[] = + "[frame={level=\"0\",addr=\"0x00000000004061ca\"," + "func=\"main\",file=\"test1.cpp\"," + "fullname=\"/home/apoenitz/work/test1/test1.cpp\",line=\"209\"}]"; + +static const char gdbmi2[] = + "[frame={level=\"0\",addr=\"0x00002ac058675840\"," + "func=\"QApplication\",file=\"/home/apoenitz/dev/qt/src/gui/kernel/qapplication.cpp\"," + "fullname=\"/home/apoenitz/dev/qt/src/gui/kernel/qapplication.cpp\",line=\"592\"}," + "frame={level=\"1\",addr=\"0x00000000004061e0\",func=\"main\",file=\"test1.cpp\"," + "fullname=\"/home/apoenitz/work/test1/test1.cpp\",line=\"209\"}]"; + +static const char gdbmi3[] = + "[stack={frame={level=\"0\",addr=\"0x00000000004061ca\"," + "func=\"main\",file=\"test1.cpp\"," + "fullname=\"/home/apoenitz/work/test1/test1.cpp\",line=\"209\"}}]"; + +static const char gdbmi4[] = + "&\"source /home/apoenitz/dev/ide/main/bin/gdb/qt4macros\\n\"" + "4^done\n"; + +static const char gdbmi5[] = + "[reason=\"breakpoint-hit\",bkptno=\"1\",thread-id=\"1\"," + "frame={addr=\"0x0000000000405738\",func=\"main\"," + "args=[{name=\"argc\",value=\"1\"},{name=\"argv\",value=\"0x7fff1ac78f28\"}]," + "file=\"test1.cpp\",fullname=\"/home/apoenitz/work/test1/test1.cpp\"," + "line=\"209\"}]"; + +static const char gdbmi8[] = + "[data={locals={{name=\"a\"},{name=\"w\"}}}]"; + +static const char gdbmi9[] = + "[data={locals=[name=\"baz\",name=\"urgs\",name=\"purgs\"]}]"; + +static const char gdbmi10[] = + "[name=\"urgs\",numchild=\"1\",type=\"Urgs\"]"; + +static const char gdbmi11[] = + "[{name=\"size\",value=\"1\",type=\"size_t\",readonly=\"true\"}," + "{name=\"0\",value=\"one\",type=\"QByteArray\"}]"; + +static const char gdbmi12[] = + "[{iname=\"local.hallo\",value=\"\\\"\\\\\\00382\\t\\377\",type=\"QByteArray\"," + "numchild=\"0\"}]"; + + +static const char jsont1[] = + "{\"Size\":100564,\"UID\":0,\"GID\":0,\"Permissions\":33261," + "\"ATime\":1242370878000,\"MTime\":1239154689000}"; + +struct Int3 { + Int3() { i1 = 42; i2 = 43; i3 = 44; } + int i1, i2, i3; +}; + +struct QString3 { + QString3() { s1 = "a"; s2 = "b"; s3 = "c"; } + QString s1, s2, s3; +}; + +class tst_Dumpers : public QObject +{ + Q_OBJECT + +public: + tst_Dumpers() {} + + void testMi(const char* input) + { + GdbMi gdbmi; + gdbmi.fromString(QByteArray(input)); + QCOMPARE('\n' + QString::fromLatin1(gdbmi.toString(false)), + '\n' + QString(input)); + } + + void testJson(const char* input) + { + QCOMPARE('\n' + Utils::JsonStringValue(QLatin1String(input)).value(), + '\n' + QString(input)); + } + +private slots: + void mi1() { testMi(gdbmi1); } + void mi2() { testMi(gdbmi2); } + void mi3() { testMi(gdbmi3); } + //void mi4() { testMi(gdbmi4); } + void mi5() { testMi(gdbmi5); } + void mi8() { testMi(gdbmi8); } + void mi9() { testMi(gdbmi9); } + void mi10() { testMi(gdbmi10); } + void mi11() { testMi(gdbmi11); } + //void mi12() { testMi(gdbmi12); } + + void json1() { testJson(jsont1); } + + void infoBreak(); + void niceType(); + void niceType_data(); + + void dumperCompatibility(); + void dumpQAbstractItemAndModelIndex(); + void dumpQAbstractItemModel(); + void dumpQByteArray(); + void dumpQChar(); + void dumpQDateTime(); + void dumpQDir(); + void dumpQFile(); + void dumpQFileInfo(); + void dumpQHash(); + void dumpQHashNode(); + void dumpQImage(); + void dumpQImageData(); + void dumpQLinkedList(); + void dumpQList_int(); + void dumpQList_int_star(); + void dumpQList_char(); + void dumpQList_QString(); + void dumpQList_QString3(); + void dumpQList_Int3(); + void dumpQLocale(); + void dumpQMap(); + void dumpQMapNode(); +#ifdef USE_PRIVATE + void dumpQObject(); + void dumpQObjectChildList(); + void dumpQObjectMethodList(); + void dumpQObjectPropertyList(); + void dumpQObjectSignal(); + void dumpQObjectSignalList(); + void dumpQObjectSlot(); + void dumpQObjectSlotList(); +#endif + void dumpQPixmap(); + void dumpQSharedPointer(); + void dumpQString(); + void dumpQTextCodec(); + void dumpQVariant_invalid(); + void dumpQVariant_QString(); + void dumpQVariant_QStringList(); +#ifndef Q_CC_MSVC + void dumpStdVector(); +#endif // !Q_CC_MSVC + void dumpQWeakPointer(); + void initTestCase(); + +private: + void dumpQAbstractItemHelper(QModelIndex &index); + void dumpQAbstractItemModelHelper(QAbstractItemModel &m); + template <typename K, typename V> void dumpQHashNodeHelper(QHash<K, V> &hash); + void dumpQImageHelper(const QImage &img); + void dumpQImageDataHelper(QImage &img); + template <typename T> void dumpQLinkedListHelper(QLinkedList<T> &l); + void dumpQLocaleHelper(QLocale &loc); + template <typename K, typename V> void dumpQMapHelper(QMap<K, V> &m); + template <typename K, typename V> void dumpQMapNodeHelper(QMap<K, V> &m); + void dumpQObjectChildListHelper(QObject &o); + void dumpQObjectSignalHelper(QObject &o, int sigNum); +#if QT_VERSION >= 0x040500 + template <typename T> + void dumpQSharedPointerHelper(QSharedPointer<T> &ptr); + template <typename T> + void dumpQWeakPointerHelper(QWeakPointer<T> &ptr); +#endif + void dumpQTextCodecHelper(QTextCodec *codec); +}; + +void tst_Dumpers::infoBreak() +{ + // This tests the regular expression used in GdbEngine::extractDataFromInfoBreak + // to discover breakpoints in constructors. + + // Copied from gdbengine.cpp: + + QRegExp re("MULTIPLE.*(0x[0-9a-f]+) in (.*)\\s+at (.*):([\\d]+)([^\\d]|$)"); + re.setMinimal(true); + + QCOMPARE(re.indexIn( + "2 breakpoint keep y <MULTIPLE> 0x0040168e\n" + "2.1 y 0x0040168e " + "in MainWindow::MainWindow(QWidget*) at mainwindow.cpp:7\n" + "2.2 y 0x00401792 " + "in MainWindow::MainWindow(QWidget*) at mainwindow.cpp:7\n"), 33); + QCOMPARE(re.cap(1), QString("0x0040168e")); + QCOMPARE(re.cap(2).trimmed(), QString("MainWindow::MainWindow(QWidget*)")); + QCOMPARE(re.cap(3), QString("mainwindow.cpp")); + QCOMPARE(re.cap(4), QString("7")); + + + QCOMPARE(re.indexIn( + "Num Type Disp Enb Address What" + "4 breakpoint keep y <MULTIPLE> 0x00000000004066ad" + "4.1 y 0x00000000004066ad in CTorTester" + " at /main/tests/manual/gdbdebugger/simple/app.cpp:124"), 88); + + QCOMPARE(re.cap(1), QString("0x00000000004066ad")); + QCOMPARE(re.cap(2).trimmed(), QString("CTorTester")); + QCOMPARE(re.cap(3), QString("/main/tests/manual/gdbdebugger/simple/app.cpp")); + QCOMPARE(re.cap(4), QString("124")); +} + +// +// type simplification +// + +static QString chopConst(QString type) +{ + while (1) { + if (type.startsWith("const")) + type = type.mid(5); + else if (type.startsWith(' ')) + type = type.mid(1); + else if (type.endsWith("const")) + type.chop(5); + else if (type.endsWith(' ')) + type.chop(1); + else + break; + } + return type; +} + +QString niceType(QString type) +{ + type.replace('*', '@'); + + for (int i = 0; i < 10; ++i) { + int start = type.indexOf("std::allocator<"); + if (start == -1) + break; + // search for matching '>' + int pos; + int level = 0; + for (pos = start + 12; pos < type.size(); ++pos) { + int c = type.at(pos).unicode(); + if (c == '<') { + ++level; + } else if (c == '>') { + --level; + if (level == 0) + break; + } + } + QString alloc = type.mid(start, pos + 1 - start).trimmed(); + QString inner = alloc.mid(15, alloc.size() - 16).trimmed(); + //qDebug() << "MATCH: " << pos << alloc << inner; + + if (inner == QLatin1String("char")) + // std::string + type.replace(QLatin1String("basic_string<char, std::char_traits<char>, " + "std::allocator<char> >"), QLatin1String("string")); + else if (inner == QLatin1String("wchar_t")) + // std::wstring + type.replace(QLatin1String("basic_string<wchar_t, std::char_traits<wchar_t>, " + "std::allocator<wchar_t> >"), QLatin1String("wstring")); + + // std::vector, std::deque, std::list + QRegExp re1(QString("(vector|list|deque)<%1, %2\\s*>").arg(inner, alloc)); + if (re1.indexIn(type) != -1) + type.replace(re1.cap(0), QString("%1<%2>").arg(re1.cap(1), inner)); + + + // std::stack + QRegExp re6(QString("stack<%1, std::deque<%2> >").arg(inner, inner)); + re6.setMinimal(true); + if (re6.indexIn(type) != -1) + type.replace(re6.cap(0), QString("stack<%1>").arg(inner)); + + // std::set + QRegExp re4(QString("set<%1, std::less<%2>, %3\\s*>").arg(inner, inner, alloc)); + re4.setMinimal(true); + if (re4.indexIn(type) != -1) + type.replace(re4.cap(0), QString("set<%1>").arg(inner)); + + + // std::map + if (inner.startsWith("std::pair<")) { + // search for outermost ',' + int pos; + int level = 0; + for (pos = 10; pos < inner.size(); ++pos) { + int c = inner.at(pos).unicode(); + if (c == '<') + ++level; + else if (c == '>') + --level; + else if (c == ',' && level == 0) + break; + } + QString ckey = inner.mid(10, pos - 10); + QString key = chopConst(ckey); + QString value = inner.mid(pos + 2, inner.size() - 3 - pos); + + QRegExp re5(QString("map<%1, %2, std::less<%3>, %4\\s*>") + .arg(key, value, key, alloc)); + re5.setMinimal(true); + if (re5.indexIn(type) != -1) + type.replace(re5.cap(0), QString("map<%1, %2>").arg(key, value)); + else { + QRegExp re7(QString("map<const %1, %2, std::less<const %3>, %4\\s*>") + .arg(key, value, key, alloc)); + re7.setMinimal(true); + if (re7.indexIn(type) != -1) + type.replace(re7.cap(0), QString("map<const %1, %2>").arg(key, value)); + } + } + } + type.replace('@', '*'); + type.replace(QLatin1String(" >"), QString(QLatin1Char('>'))); + return type; +} + +void tst_Dumpers::niceType() +{ + // cf. watchutils.cpp + QFETCH(QString, input); + QFETCH(QString, simplified); + QCOMPARE(::niceType(input), simplified); +} + +void tst_Dumpers::niceType_data() +{ + QTest::addColumn<QString>("input"); + QTest::addColumn<QString>("simplified"); + + QTest::newRow("list") + << "std::list<int, std::allocator<int> >" + << "std::list<int>"; + + QTest::newRow("combined") + << "std::vector<std::list<int, std::allocator<int> >*, " + "std::allocator<std::list<int, std::allocator<int> >*> >" + << "std::vector<std::list<int>*>"; + + QTest::newRow("stack") + << "std::stack<int, std::deque<int, std::allocator<int> > >" + << "std::stack<int>"; + + QTest::newRow("map") + << "std::map<myns::QString, Foo, std::less<myns::QString>, " + "std::allocator<std::pair<const myns::QString, Foo> > >" + << "std::map<myns::QString, Foo>"; + + QTest::newRow("map2") + << "std::map<const char*, Foo, std::less<const char*>, " + "std::allocator<std::pair<const char* const, Foo> > >" + << "std::map<const char*, Foo>"; +} + +// +// Dumpers +// + +static void testDumper(QByteArray expected0, const void *data, QByteArray outertype, + bool dumpChildren, QByteArray innertype = "", QByteArray exp = "", + int extraInt0 = 0, int extraInt1 = 0, int extraInt2 = 0, int extraInt3 = 0) +{ + sprintf(xDumpInBuffer, "%s%c%s%c%s%c%s%c%s%c", + outertype.data(), 0, "iname", 0, exp.data(), 0, + innertype.data(), 0, "iname", 0); + //qDebug() << "FIXME qDumpObjectData440 signature to use const void *"; + void *res = qDumpObjectData440(2, 42, data, dumpChildren, + extraInt0, extraInt1, extraInt2, extraInt3); + QString expected(expected0); + char buf[100]; + sprintf(buf, pointerPrintFormat(), (quintptr)data); + if ((!expected.startsWith('t') && !expected.startsWith('f')) + || expected.startsWith("type")) + expected = "tiname='$I',addr='$A'," + expected; + expected.replace("$I", "iname"); + expected.replace("$T", QByteArray(outertype)); + expected.replace("$A", QByteArray(buf)); + expected.replace('\'', '"'); + QString actual____ = QString::fromLatin1(xDumpOutBuffer); + actual____.replace('\'', '"'); + QCOMPARE(res, xDumpOutBuffer); + if (actual____ != expected) { + QStringList l1 = actual____.split(","); + QStringList l2 = expected.split(","); + for (int i = 0; i < l1.size() && i < l2.size(); ++i) { + if (l1.at(i) == l2.at(i)) + qWarning() << "== " << l1.at(i); + else + //qWarning() << "!= " << l1.at(i).right(30) << l2.at(i).right(30); + qWarning() << "!= " << l1.at(i) << l2.at(i); + } + if (l1.size() != l2.size()) + qWarning() << "!= size: " << l1.size() << l2.size(); + } + QCOMPARE(actual____, expected); +} + +QByteArray str(const void *p) +{ + char buf[100]; + sprintf(buf, pointerPrintFormat(), (quintptr)p); + return buf; +} + +static const void *deref(const void *p) +{ + return *reinterpret_cast<const char* const*>(p); +} + +void tst_Dumpers::dumperCompatibility() +{ + // Ensure that no arbitrary padding is introduced by QVectorTypedData. + const size_t qVectorDataSize = 16; + QCOMPARE(sizeof(QVectorData), qVectorDataSize); + QVectorTypedData<int> *v = 0; + QCOMPARE(size_t(&v->array), qVectorDataSize); +} + +static const QByteArray utfToBase64(const QString &string) +{ + return QByteArray(reinterpret_cast<const char *>(string.utf16()), 2 * string.size()).toBase64(); +} + +static const char *boolToVal(bool b) +{ + return b ? "'true'" : "'false'"; +} + +static const QByteArray ptrToBa(const void *p, bool symbolicNull = true) +{ + return QByteArray().append(p == 0 && symbolicNull ? + "<null>" : + QByteArray("0x") + QByteArray::number((quintptr) p, 16)); +} + +static const QByteArray generateQStringSpec(const QString &str, bool isNull = false) +{ + if (isNull) + return QByteArray("value='IiIgKG51bGwp',valueencoded='5'," + "type='" NS "QString',numchild='0'"); + return + QByteArray("value='%',valueencoded='2',type='" NS "QString',numchild='0'") + << utfToBase64(str); +} + +static const QByteArray generateQCharSpec(const QChar& ch) +{ + return QByteArray("value='%',valueencoded='2',type='" NS "QChar',numchild='0'") + << utfToBase64(QString(QLatin1String("'%1' (%2, 0x%3)")). + arg(ch).arg(ch.unicode()).arg(ch.unicode(), 0, 16)); +} + +static const QByteArray generateBoolSpec(bool b) +{ + return QByteArray("value=%,type='bool',numchild='0'") + << boolToVal(b); +} + +static const QByteArray generateLongSpec(long n) +{ + return QByteArray("value='%',type='long',numchild='0'") + << N(qlonglong(n)); +} + +static const QByteArray generateIntSpec(int n) +{ + return QByteArray("value='%',type='int',numchild='0'") + << N(n); +} + +const QByteArray createExp(const void *ptr, + const QByteArray &type, const QByteArray &method) +{ + return QByteArray("exp='((" NSX "%" NSY "*)%)->%'") + << type << ptrToBa(ptr) << method; +} + +// Helper functions. + +template <typename T> static const char *typeToString() +{ + return "<unknown type>"; +} +template <typename T> const QByteArray valToString(const T &) +{ + return "<unknown value>"; +} +template <> const QByteArray valToString(const int &n) +{ + return QByteArray().append(N(n)); +} +template <> const QByteArray valToString(const QString &s) +{ + return QByteArray(utfToBase64(s)).append("',valueencoded='2"); +} +template <> const QByteArray valToString(int * const &p) +{ + return ptrToBa(p); +} +template <typename T> const QByteArray derefValToString(const T &v) +{ + return valToString(v); +} +template <> const QByteArray derefValToString(int * const &ptr) +{ + return valToString(*ptr); +} +const QString stripPtrType(const QString &ptrTypeStr) +{ + return ptrTypeStr.mid(0, ptrTypeStr.size() - 2); +} +template <> const char *typeToString<int>() +{ + return "int"; +} +template <> const char *typeToString<QString>() +{ + return NS"QString"; +} +template <> const char *typeToString<int *>() +{ + return "int *"; +} +template <typename T> bool isSimpleType() +{ + return false; +} +template <> bool isSimpleType<int>() +{ + return true; +} +template <typename T> bool isPointer() +{ + return false; +} +template <> bool isPointer<int *>() +{ + return true; +} + +template <typename T> static const char *typeToNumchild() +{ + return "1"; +} +template <> const char *typeToNumchild<int>() +{ + return "0"; +} +template <> const char *typeToNumchild<QString>() +{ + return "0"; +} +template <typename K, typename V> +QByteArray getMapType() +{ + return QByteArray(typeToString<K>()) + "@" + QByteArray(typeToString<V>()); +} +template <typename K, typename V> +void getMapNodeParams(size_t &nodeSize, size_t &valOffset) +{ +#if QT_VERSION >= 0x040500 + typedef QMapNode<K, V> NodeType; + NodeType *node = 0; + nodeSize = sizeof(NodeType); + valOffset = size_t(&node->value); +#else + nodeSize = sizeof(K) + sizeof(V) + 2*sizeof(void *); + valOffset = sizeof(K); +#endif +} + +void tst_Dumpers::dumpQAbstractItemHelper(QModelIndex &index) +{ + const QAbstractItemModel *model = index.model(); + const QString &rowStr = N(index.row()); + const QString &colStr = N(index.column()); + const QByteArray &internalPtrStrSymbolic = ptrToBa(index.internalPointer()); + const QByteArray &internalPtrStrValue = ptrToBa(index.internalPointer(), false); + const QByteArray &modelPtrStr = ptrToBa(model); + QByteArray indexSpecSymbolic = QByteArray().append(rowStr + "," + colStr + ","). + append(internalPtrStrSymbolic + "," + modelPtrStr); + QByteArray indexSpecValue = QByteArray().append(rowStr + "," + colStr + ","). + append(internalPtrStrValue + "," + modelPtrStr); + QByteArray expected = QByteArray("tiname='iname',addr='").append(ptrToBa(&index)). + append("',type='" NS "QAbstractItem',addr='$").append(indexSpecSymbolic). + append("',value='").append(valToString(model->data(index).toString())). + append("',numchild='%',children=["); + int rowCount = model->rowCount(index); + int columnCount = model->columnCount(index); + expected <<= N(rowCount * columnCount); + for (int row = 0; row < rowCount; ++row) { + for (int col = 0; col < columnCount; ++col) { + const QModelIndex &childIndex = model->index(row, col, index); + expected.append("{name='[").append(valToString(row)).append(","). + append(N(col)).append("]',numchild='%',addr='$"). + append(N(childIndex.row())).append(","). + append(N(childIndex.column())).append(","). + append(ptrToBa(childIndex.internalPointer())).append(","). + append(modelPtrStr).append("',type='" NS "QAbstractItem',value='"). + append(valToString(model->data(childIndex).toString())).append("'}"); + expected <<= N(model->rowCount(childIndex) + * model->columnCount(childIndex)); + if (col < columnCount - 1 || row < rowCount - 1) + expected.append(","); + } + } + expected.append("]"); + testDumper(expected, &index, NS"QAbstractItem", true, indexSpecValue); +} + +void tst_Dumpers::dumpQAbstractItemAndModelIndex() +{ + class PseudoTreeItemModel : public QAbstractItemModel + { + public: + PseudoTreeItemModel() : QAbstractItemModel(), parent1(0), + parent1Child(1), parent2(10), parent2Child1(11), parent2Child2(12) + {} + + int columnCount(const QModelIndex &parent = QModelIndex()) const + { + Q_UNUSED(parent); + return 1; + } + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const + { + return !index.isValid() || role != Qt::DisplayRole ? + QVariant() : *static_cast<int *>(index.internalPointer()); + } + + QModelIndex index(int row, int column, + const QModelIndex & parent = QModelIndex()) const + { + QModelIndex index; + if (column == 0) { + if (!parent.isValid()) { + if (row == 0) + index = createIndex(row, column, &parent1); + else if (row == 1) + index = createIndex(row, column, &parent2); + } else if (parent.internalPointer() == &parent1 && row == 0) { + index = createIndex(row, column, &parent1Child); + } else if (parent.internalPointer() == &parent2) { + index = createIndex(row, column, + row == 0 ? &parent2Child1 : &parent2Child2); + } + } + return index; + } + + QModelIndex parent(const QModelIndex & index) const + { + QModelIndex parent; + if (index.isValid()) { + if (index.internalPointer() == &parent1Child) + parent = createIndex(0, 0, &parent1); + else if (index.internalPointer() == &parent2Child1 || + index.internalPointer() == &parent2Child2) + parent = createIndex(1, 0, &parent2); + } + return parent; + } + + int rowCount(const QModelIndex &parent = QModelIndex()) const + { + int rowCount; + if (!parent.isValid() || parent.internalPointer() == &parent2) + rowCount = 2; + else if (parent.internalPointer() == &parent1) + rowCount = 1; + else + rowCount = 0; + return rowCount; + } + + private: + mutable int parent1; + mutable int parent1Child; + mutable int parent2; + mutable int parent2Child1; + mutable int parent2Child2; + }; + + PseudoTreeItemModel m2; + + // Case 1: ModelIndex with no children. + QStringListModel m(QStringList() << "item1" << "item2" << "item3"); + QModelIndex index = m.index(2, 0); + + testDumper(QByteArray("type='$T',value='(2, 0)',numchild='5',children=[" + "{name='row',value='2',type='int',numchild='0'}," + "{name='column',value='0',type='int',numchild='0'}," + "{name='parent',value='<invalid>',exp='(('$T'*)$A)->parent()'," + "type='$T',numchild='1'}," + "{name='internalId',%}," + "{name='model',value='%',type='" NS "QAbstractItemModel*'," + "numchild='1'}]") + << generateQStringSpec(N(index.internalId())) + << ptrToBa(&m), + &index, NS"QModelIndex", true); + + // Case 2: ModelIndex with one child. + QModelIndex index2 = m2.index(0, 0); + dumpQAbstractItemHelper(index2); + + qDebug() << "FIXME: invalid indices should not have children"; + testDumper(QByteArray("type='$T',value='(0, 0)',numchild='5',children=[" + "{name='row',value='0',type='int',numchild='0'}," + "{name='column',value='0',type='int',numchild='0'}," + "{name='parent',value='<invalid>',exp='(('$T'*)$A)->parent()'," + "type='$T',numchild='1'}," + "{name='internalId',%}," + "{name='model',value='%',type='" NS "QAbstractItemModel*'," + "numchild='1'}]") + << generateQStringSpec(N(index2.internalId())) + << ptrToBa(&m2), + &index2, NS"QModelIndex", true); + + + // Case 3: ModelIndex with two children. + QModelIndex index3 = m2.index(1, 0); + dumpQAbstractItemHelper(index3); + + testDumper(QByteArray("type='$T',value='(1, 0)',numchild='5',children=[" + "{name='row',value='1',type='int',numchild='0'}," + "{name='column',value='0',type='int',numchild='0'}," + "{name='parent',value='<invalid>',exp='(('$T'*)$A)->parent()'," + "type='$T',numchild='1'}," + "{name='internalId',%}," + "{name='model',value='%',type='" NS "QAbstractItemModel*'," + "numchild='1'}]") + << generateQStringSpec(N(index3.internalId())) + << ptrToBa(&m2), + &index3, NS"QModelIndex", true); + + + // Case 4: ModelIndex with a parent. + index = m2.index(0, 0, index3); + testDumper(QByteArray("type='$T',value='(0, 0)',numchild='5',children=[" + "{name='row',value='0',type='int',numchild='0'}," + "{name='column',value='0',type='int',numchild='0'}," + "{name='parent',value='(1, 0)',exp='(('$T'*)$A)->parent()'," + "type='$T',numchild='1'}," + "{name='internalId',%}," + "{name='model',value='%',type='" NS "QAbstractItemModel*'," + "numchild='1'}]") + << generateQStringSpec(N(index.internalId())) + << ptrToBa(&m2), + &index, NS"QModelIndex", true); + + + // Case 5: Empty ModelIndex + QModelIndex index4; + testDumper("type='$T',value='<invalid>',numchild='0'", + &index4, NS"QModelIndex", true); +} + +void tst_Dumpers::dumpQAbstractItemModelHelper(QAbstractItemModel &m) +{ + QByteArray address = ptrToBa(&m); + QByteArray expected = QByteArray("tiname='iname',addr='%'," + "type='" NS "QAbstractItemModel',value='(%,%)',numchild='1',children=[" + "{numchild='1',name='" NS "QObject',addr='%',value='%'," + "valueencoded='2',type='" NS "QObject',displayedtype='%'}") + << address + << N(m.rowCount()) + << N(m.columnCount()) + << address + << utfToBase64(m.objectName()) + << m.metaObject()->className(); + + for (int row = 0; row < m.rowCount(); ++row) { + for (int column = 0; column < m.columnCount(); ++column) { + QModelIndex mi = m.index(row, column); + expected.append(QByteArray(",{name='[%,%]',value='%'," + "valueencoded='2',numchild='%',addr='$%,%,%,%'," + "type='" NS "QAbstractItem'}") + << N(row) + << N(column) + << utfToBase64(m.data(mi).toString()) + << N(row * column) + << N(mi.row()) + << N(mi.column()) + << ptrToBa(mi.internalPointer()) + << ptrToBa(mi.model())); + } + } + expected.append("]"); + testDumper(expected, &m, NS"QAbstractItemModel", true); +} + +void tst_Dumpers::dumpQAbstractItemModel() +{ + // Case 1: No rows, one column. + QStringList strList; + QStringListModel model(strList); + dumpQAbstractItemModelHelper(model); + + // Case 2: One row, one column. + strList << "String 1"; + model.setStringList(strList); + dumpQAbstractItemModelHelper(model); + + // Case 3: Two rows, one column. + strList << "String 2"; + model.setStringList(strList); + dumpQAbstractItemModelHelper(model); + + // Case 4: No rows, two columns. + QStandardItemModel model2(0, 2); + dumpQAbstractItemModelHelper(model2); + + // Case 5: One row, two columns. + QStandardItem item1("Item (0,0)"); + QStandardItem item2("(Item (0,1)"); + model2.appendRow(QList<QStandardItem *>() << &item1 << &item2); + dumpQAbstractItemModelHelper(model2); + + // Case 6: Two rows, two columns + QStandardItem item3("Item (1,0"); + QStandardItem item4("Item (1,1)"); + model2.appendRow(QList<QStandardItem *>() << &item3 << &item4); + dumpQAbstractItemModelHelper(model); +} + +void tst_Dumpers::dumpQByteArray() +{ + // Case 1: Empty object. + QByteArray ba; + testDumper("value='',valueencoded='1',type='" NS "QByteArray',numchild='0'," + "childtype='char',childnumchild='0',children=[]", + &ba, NS"QByteArray", true); + + // Case 2: One element. + ba.append('a'); + testDumper("value='YQ==',valueencoded='1',type='" NS "QByteArray',numchild='1'," + "childtype='char',childnumchild='0',children=[{value='61 (97 'a')'}]", + &ba, NS"QByteArray", true); + + // Case 3: Two elements. + ba.append('b'); + testDumper("value='YWI=',valueencoded='1',type='" NS "QByteArray',numchild='2'," + "childtype='char',childnumchild='0',children=[" + "{value='61 (97 'a')'},{value='62 (98 'b')'}]", + &ba, NS"QByteArray", true); + + // Case 4: > 100 elements. + ba = QByteArray(101, 'a'); + QByteArray children; + for (int i = 0; i < 101; i++) + children.append("{value='61 (97 'a')'},"); + children.chop(1); + testDumper(QByteArray("value='YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh" + "YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh" + "YWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ== <size: 101, cut...>'," + "valueencoded='1',type='" NS "QByteArray',numchild='101'," + "childtype='char',childnumchild='0',children=[%]") << children, + &ba, NS"QByteArray", true); + + // Case 5: Regular and special characters and the replacement character. + ba = QByteArray("abc\a\n\r\033\'\"?"); + testDumper("value='YWJjBwoNGyciPw==',valueencoded='1',type='" NS "QByteArray'," + "numchild='10',childtype='char',childnumchild='0',children=[" + "{value='61 (97 'a')'},{value='62 (98 'b')'}," + "{value='63 (99 'c')'},{value='07 (7 '?')'}," + "{value='0a (10 '?')'},{value='0d (13 '?')'}," + "{value='1b (27 '?')'},{value='27 (39 '?')'}," + "{value='22 (34 '?')'},{value='3f (63 '?')'}]", + &ba, NS"QByteArray", true); +} + +void tst_Dumpers::dumpQChar() +{ + // Case 1: Printable ASCII character. + QChar c('X'); + testDumper("value=''X', ucs=88',numchild='0'", + &c, NS"QChar", false); + + // Case 2: Printable non-ASCII character. + c = QChar(0x600); + testDumper("value=''?', ucs=1536',numchild='0'", + &c, NS"QChar", false); + + // Case 3: Non-printable ASCII character. + c = QChar::fromAscii('\a'); + testDumper("value=''?', ucs=7',numchild='0'", + &c, NS"QChar", false); + + // Case 4: Non-printable non-ASCII character. + c = QChar(0x9f); + testDumper("value=''?', ucs=159',numchild='0'", + &c, NS"QChar", false); + + // Case 5: Printable ASCII Character that looks like the replacement character. + c = QChar::fromAscii('?'); + testDumper("value=''?', ucs=63',numchild='0'", + &c, NS"QChar", false); +} + +void tst_Dumpers::dumpQDateTime() +{ + // Case 1: Null object. + QDateTime d; + testDumper("value='(null)',type='$T',numchild='0'", + &d, NS"QDateTime", true); + + // Case 2: Non-null object. + d = QDateTime::currentDateTime(); + testDumper(QByteArray("value='%',valueencoded='2'," + "type='$T',numchild='1',children=[" + "{name='toTime_t',%}," + "{name='toString',%}," + "{name='toString_(ISO)',%}," + "{name='toString_(SystemLocale)',%}," + "{name='toString_(Locale)',%}]") + << utfToBase64(d.toString()) + << generateLongSpec((d.toTime_t())) + << generateQStringSpec(d.toString()) + << generateQStringSpec(d.toString(Qt::ISODate)) + << generateQStringSpec(d.toString(Qt::SystemLocaleDate)) + << generateQStringSpec(d.toString(Qt::LocaleDate)), + &d, NS"QDateTime", true); + +} + +void tst_Dumpers::dumpQDir() +{ + // Case 1: Current working directory. + QDir dir = QDir::current(); + testDumper(QByteArray("value='%',valueencoded='2',type='" NS "QDir',numchild='3'," + "children=[{name='absolutePath',%},{name='canonicalPath',%}]") + << utfToBase64(dir.absolutePath()) + << generateQStringSpec(dir.absolutePath()) + << generateQStringSpec(dir.canonicalPath()), + &dir, NS"QDir", true); + + // Case 2: Root directory. + dir = QDir::root(); + testDumper(QByteArray("value='%',valueencoded='2',type='" NS "QDir',numchild='3'," + "children=[{name='absolutePath',%},{name='canonicalPath',%}]") + << utfToBase64(dir.absolutePath()) + << generateQStringSpec(dir.absolutePath()) + << generateQStringSpec(dir.canonicalPath()), + &dir, NS"QDir", true); +} + + +void tst_Dumpers::dumpQFile() +{ + // Case 1: Empty file name => Does not exist. + QFile file1(""); + testDumper(QByteArray("value='',valueencoded='2',type='$T',numchild='2'," + "children=[{name='fileName',value='',valueencoded='2',type='" NS "QString'," + "numchild='0'}," + "{name='exists',value='false',type='bool',numchild='0'}]"), + &file1, NS"QFile", true); + + // Case 2: File that is known to exist. + QTemporaryFile file2; + file2.open(); + testDumper(QByteArray("value='%',valueencoded='2',type='$T',numchild='2'," + "children=[{name='fileName',value='%',valueencoded='2',type='" NS "QString'," + "numchild='0'}," + "{name='exists',value='true',type='bool',numchild='0'}]") + << utfToBase64(file2.fileName()) << utfToBase64(file2.fileName()), + &file2, NS"QFile", true); + + // Case 3: File with a name that most likely does not exist. + QFile file3("jfjfdskjdflsdfjfdls"); + testDumper(QByteArray("value='%',valueencoded='2',type='$T',numchild='2'," + "children=[{name='fileName',value='%',valueencoded='2',type='" NS "QString'," + "numchild='0'}," + "{name='exists',value='false',type='bool',numchild='0'}]") + << utfToBase64(file3.fileName()) << utfToBase64(file3.fileName()), + &file3, NS"QFile", true); +} + +void tst_Dumpers::dumpQFileInfo() +{ + QFileInfo fi("."); + QByteArray expected("value='%',valueencoded='2',type='$T',numchild='3'," + "children=[" + "{name='absolutePath',%}," + "{name='absoluteFilePath',%}," + "{name='canonicalPath',%}," + "{name='canonicalFilePath',%}," + "{name='completeBaseName',%}," + "{name='completeSuffix',%}," + "{name='baseName',%}," +#ifdef QX + "{name='isBundle',%}," + "{name='bundleName',%}," +#endif + "{name='fileName',%}," + "{name='filePath',%}," + "{name='group',%}," + "{name='owner',%}," + "{name='path',%}," + "{name='groupid',%}," + "{name='ownerid',%}," + "{name='permissions',value=' ',type='%',numchild='10'," + "children=[{name='ReadOwner',%},{name='WriteOwner',%}," + "{name='ExeOwner',%},{name='ReadUser',%},{name='WriteUser',%}," + "{name='ExeUser',%},{name='ReadGroup',%},{name='WriteGroup',%}," + "{name='ExeGroup',%},{name='ReadOther',%},{name='WriteOther',%}," + "{name='ExeOther',%}]}," + "{name='caching',%}," + "{name='exists',%}," + "{name='isAbsolute',%}," + "{name='isDir',%}," + "{name='isExecutable',%}," + "{name='isFile',%}," + "{name='isHidden',%}," + "{name='isReadable',%}," + "{name='isRelative',%}," + "{name='isRoot',%}," + "{name='isSymLink',%}," + "{name='isWritable',%}," + "{name='created',value='%',valueencoded='2',%," + "type='" NS "QDateTime',numchild='1'}," + "{name='lastModified',value='%',valueencoded='2',%," + "type='" NS "QDateTime',numchild='1'}," + "{name='lastRead',value='%',valueencoded='2',%," + "type='" NS "QDateTime',numchild='1'}]"); + expected <<= utfToBase64(fi.filePath()); + expected <<= generateQStringSpec(fi.absolutePath()); + expected <<= generateQStringSpec(fi.absoluteFilePath()); + expected <<= generateQStringSpec(fi.canonicalPath()); + expected <<= generateQStringSpec(fi.canonicalFilePath()); + expected <<= generateQStringSpec(fi.completeBaseName()); + expected <<= generateQStringSpec(fi.completeSuffix(), true); + expected <<= generateQStringSpec(fi.baseName()); +#ifdef Q_OS_MACX + expected <<= generateBoolSpec(fi.isBundle()); + expected <<= generateQStringSpec(fi.bundleName()); +#endif + expected <<= generateQStringSpec(fi.fileName()); + expected <<= generateQStringSpec(fi.filePath()); + expected <<= generateQStringSpec(fi.group()); + expected <<= generateQStringSpec(fi.owner()); + expected <<= generateQStringSpec(fi.path()); + expected <<= generateLongSpec(fi.groupId()); + expected <<= generateLongSpec(fi.ownerId()); + QFile::Permissions perms = fi.permissions(); + expected <<= QByteArray(NS"QFile::Permissions"); + expected <<= generateBoolSpec((perms & QFile::ReadOwner) != 0); + expected <<= generateBoolSpec((perms & QFile::WriteOwner) != 0); + expected <<= generateBoolSpec((perms & QFile::ExeOwner) != 0); + expected <<= generateBoolSpec((perms & QFile::ReadUser) != 0); + expected <<= generateBoolSpec((perms & QFile::WriteUser) != 0); + expected <<= generateBoolSpec((perms & QFile::ExeUser) != 0); + expected <<= generateBoolSpec((perms & QFile::ReadGroup) != 0); + expected <<= generateBoolSpec((perms & QFile::WriteGroup) != 0); + expected <<= generateBoolSpec((perms & QFile::ExeGroup) != 0); + expected <<= generateBoolSpec((perms & QFile::ReadOther) != 0); + expected <<= generateBoolSpec((perms & QFile::WriteOther) != 0); + expected <<= generateBoolSpec((perms & QFile::ExeOther) != 0); + expected <<= generateBoolSpec(fi.caching()); + expected <<= generateBoolSpec(fi.exists()); + expected <<= generateBoolSpec(fi.isAbsolute()); + expected <<= generateBoolSpec(fi.isDir()); + expected <<= generateBoolSpec(fi.isExecutable()); + expected <<= generateBoolSpec(fi.isFile()); + expected <<= generateBoolSpec(fi.isHidden()); + expected <<= generateBoolSpec(fi.isReadable()); + expected <<= generateBoolSpec(fi.isRelative()); + expected <<= generateBoolSpec(fi.isRoot()); + expected <<= generateBoolSpec(fi.isSymLink()); + expected <<= generateBoolSpec(fi.isWritable()); + expected <<= utfToBase64(fi.created().toString()); + expected <<= createExp(&fi, "QFileInfo", "created()"); + expected <<= utfToBase64(fi.lastModified().toString()); + expected <<= createExp(&fi, "QFileInfo", "lastModified()"); + expected <<= utfToBase64(fi.lastRead().toString()); + expected <<= createExp(&fi, "QFileInfo", "lastRead()"); + + testDumper(expected, &fi, NS"QFileInfo", true); +} + +void tst_Dumpers::dumpQHash() +{ + QHash<QString, QList<int> > hash; + hash.insert("Hallo", QList<int>()); + hash.insert("Welt", QList<int>() << 1); + hash.insert("!", QList<int>() << 1 << 2); + hash.insert("!", QList<int>() << 1 << 2); +} + +template <typename K, typename V> +void tst_Dumpers::dumpQHashNodeHelper(QHash<K, V> &hash) +{ + typename QHash<K, V>::iterator it = hash.begin(); + typedef QHashNode<K, V> HashNode; + HashNode *dummy = 0; + HashNode *node = + reinterpret_cast<HashNode *>(reinterpret_cast<char *>(const_cast<K *>(&it.key())) - + size_t(&dummy->key)); + const K &key = it.key(); + const V &val = it.value(); + QByteArray expected("value='"); + if (isSimpleType<V>()) + expected.append(valToString(val)); + expected.append("',numchild='2',children=[{name='key',type='"). + append(typeToString<K>()).append("',addr='").append(ptrToBa(&key)). + append("'},{name='value',type='").append(typeToString<V>()). + append("',addr='").append(ptrToBa(&val)).append("'}]"); + testDumper(expected, node, NS"QHashNode", true, + getMapType<K, V>(), "", sizeof(it.key()), sizeof(it.value())); +} + +void tst_Dumpers::dumpQHashNode() +{ + // Case 1: simple type -> simple type. + QHash<int, int> hash1; + hash1[2] = 3; + dumpQHashNodeHelper(hash1); + + // Case 2: simple type -> composite type. + QHash<int, QString> hash2; + hash2[5] = "String 7"; + dumpQHashNodeHelper(hash2); + + // Case 3: composite type -> simple type + QHash<QString, int> hash3; + hash3["String 11"] = 13; + dumpQHashNodeHelper(hash3); + + // Case 4: composite type -> composite type + QHash<QString, QString> hash4; + hash4["String 17"] = "String 19"; + dumpQHashNodeHelper(hash4); +} + +void tst_Dumpers::dumpQImageHelper(const QImage &img) +{ + QByteArray expected = "value='(%x%)',type='" NS "QImage',numchild='0'" + << N(img.width()) + << N(img.height()); + testDumper(expected, &img, NS"QImage", true); +} + +void tst_Dumpers::dumpQImage() +{ + // Case 1: Null image. + QImage img; + dumpQImageHelper(img); + + // Case 2: Normal image. + img = QImage(3, 700, QImage::Format_RGB555); + dumpQImageHelper(img); + + // Case 3: Invalid image. + img = QImage(100, 0, QImage::Format_Invalid); + dumpQImageHelper(img); +} + +void tst_Dumpers::dumpQImageDataHelper(QImage &img) +{ +#if QT_VERSION >= 0x050000 + QSKIP("QImage::numBytes deprecated"); +#else + const QByteArray ba(QByteArray::fromRawData((const char*) img.bits(), img.numBytes())); + QByteArray expected = QByteArray("tiname='$I',addr='$A',type='" NS "QImageData',"). + append("numchild='0',value='<hover here>',valuetooltipencoded='1',"). + append("valuetooltipsize='").append(N(ba.size())).append("',"). + append("valuetooltip='").append(ba.toBase64()).append("'"); + testDumper(expected, &img, NS"QImageData", false); +#endif +} + +void tst_Dumpers::dumpQImageData() +{ + // Case 1: Null image. + QImage img; + dumpQImageDataHelper(img); + + // Case 2: Normal image. + img = QImage(3, 700, QImage::Format_RGB555); + dumpQImageDataHelper(img); + + // Case 3: Invalid image. + img = QImage(100, 0, QImage::Format_Invalid); + dumpQImageDataHelper(img); +} + +template <typename T> + void tst_Dumpers::dumpQLinkedListHelper(QLinkedList<T> &l) +{ + const int size = qMin(l.size(), 1000); + const QString &sizeStr = N(size); + const QByteArray elemTypeStr = typeToString<T>(); + QByteArray expected = QByteArray("value='<").append(sizeStr). + append(" items>',valueeditable='false',numchild='").append(sizeStr). + append("',childtype='").append(elemTypeStr).append("',childnumchild='"). + append(typeToNumchild<T>()).append("',children=["); + typename QLinkedList<T>::const_iterator iter = l.constBegin(); + for (int i = 0; i < size; ++i, ++iter) { + expected.append("{"); + const T &curElem = *iter; + if (isPointer<T>()) { + const QString typeStr = stripPtrType(typeToString<T>()); + const QByteArray addrStr = valToString(curElem); + if (curElem != 0) { + expected.append("addr='").append(addrStr).append("',type='"). + append(typeStr).append("',value='"). + append(derefValToString(curElem)).append("'"); + } else { + expected.append("addr='").append(ptrToBa(&curElem)).append("',type='"). + append(typeStr).append("',value='<null>',numchild='0'"); + } + } else { + expected.append("addr='").append(ptrToBa(&curElem)). + append("',value='").append(valToString(curElem)).append("'"); + } + expected.append("}"); + if (i < size - 1) + expected.append(","); + } + if (size < l.size()) + expected.append(",..."); + expected.append("]"); + testDumper(expected, &l, NS"QLinkedList", true, elemTypeStr); +} + +void tst_Dumpers::dumpQLinkedList() +{ + // Case 1: Simple element type. + QLinkedList<int> l; + + // Case 1.1: Empty list. + dumpQLinkedListHelper(l); + + // Case 1.2: One element. + l.append(2); + dumpQLinkedListHelper(l); + + // Case 1.3: Two elements + l.append(3); + dumpQLinkedListHelper(l); + + // Case 2: Composite element type. + QLinkedList<QString> l2; + + // Case 2.1: Empty list. + dumpQLinkedListHelper(l2); + + // Case 2.2: One element. + l2.append("Teststring 1"); + dumpQLinkedListHelper(l2); + + // Case 2.3: Two elements. + l2.append("Teststring 2"); + dumpQLinkedListHelper(l2); + + // Case 2.4: > 1000 elements. + for (int i = 3; i <= 1002; ++i) + l2.append("Test " + N(i)); + + // Case 3: Pointer type. + QLinkedList<int *> l3; + l3.append(new int(5)); + l3.append(new int(7)); + l3.append(0); + dumpQLinkedListHelper(l3); +} + +# if 0 + void tst_Debugger::dumpQLinkedList() + { + // Case 1: Simple element type. + QLinkedList<int> l; + + // Case 1.1: Empty list. + testDumper("value='<0 items>',valueeditable='false',numchild='0'," + "childtype='int',childnumchild='0',children=[]", + &l, NS"QLinkedList", true, "int"); + + // Case 1.2: One element. + l.append(2); + testDumper("value='<1 items>',valueeditable='false',numchild='1'," + "childtype='int',childnumchild='0',children=[{addr='%',value='2'}]" + << ptrToBa(l.constBegin().operator->()), + &l, NS"QLinkedList", true, "int"); + + // Case 1.3: Two elements + l.append(3); + QByteArray it0 = ptrToBa(l.constBegin().operator->()); + QByteArray it1 = ptrToBa(l.constBegin().operator++().operator->()); + testDumper("value='<2 items>',valueeditable='false',numchild='2'," + "childtype='int',childnumchild='0',children=[{addr='%',value='2'}," + "{addr='%',value='3'}]" << it0 << it1, + &l, NS"QLinkedList", true, "int"); + + // Case 2: Composite element type. + QLinkedList<QString> l2; + QLinkedList<QString>::const_iterator iter; + + // Case 2.1: Empty list. + testDumper("value='<0 items>',valueeditable='false',numchild='0'," + "childtype='" NS "QString',childnumchild='0',children=[]", + &l2, NS"QLinkedList", true, NS"QString"); + + // Case 2.2: One element. + l2.append("Teststring 1"); + iter = l2.constBegin(); + qDebug() << *iter; + testDumper("value='<1 items>',valueeditable='false',numchild='1'," + "childtype='" NS "QString',childnumchild='0',children=[{addr='%',value='%',}]" + << ptrToBa(iter.operator->()) << utfToBase64(*iter), + &l2, NS"QLinkedList", true, NS"QString"); + + // Case 2.3: Two elements. + QByteArray expected = "value='<2 items>',valueeditable='false',numchild='2'," + "childtype='int',childnumchild='0',children=["; + iter = l2.constBegin(); + expected.append("{addr='%',%}," + << ptrToBa(iter.operator->()) << utfToBase64(*iter)); + ++iter; + expected.append("{addr='%',%}]" + << ptrToBa(iter.operator->()) << utfToBase64(*iter)); + testDumper(expected, + &l, NS"QLinkedList", true, NS"QString"); + + // Case 2.4: > 1000 elements. + for (int i = 3; i <= 1002; ++i) + l2.append("Test " + N(i)); + + expected = "value='<1002 items>',valueeditable='false'," + "numchild='1002',childtype='" NS "QString',childnumchild='0',children=['"; + iter = l2.constBegin(); + for (int i = 0; i < 1002; ++i, ++iter) + expected.append("{addr='%',value='%'}," + << ptrToBa(iter.operator->()) << utfToBase64(*iter)); + expected.append(",...]"); + testDumper(expected, &l, NS"QLinkedList", true, NS"QString"); + + + // Case 3: Pointer type. + QLinkedList<int *> l3; + l3.append(new int(5)); + l3.append(new int(7)); + l3.append(0); + //dumpQLinkedListHelper(l3); + testDumper("", &l, NS"QLinkedList", true, NS"QString"); + } +# endif + +void tst_Dumpers::dumpQList_int() +{ + QList<int> ilist; + testDumper("value='<0 items>',valueeditable='false',numchild='0'," + "internal='1',children=[]", + &ilist, NS"QList", true, "int"); + ilist.append(1); + ilist.append(2); + testDumper("value='<2 items>',valueeditable='false',numchild='2'," + "internal='1',childtype='int',childnumchild='0',children=[" + "{addr='" + str(&ilist.at(0)) + "',value='1'}," + "{addr='" + str(&ilist.at(1)) + "',value='2'}]", + &ilist, NS"QList", true, "int"); +} + +void tst_Dumpers::dumpQList_int_star() +{ + QList<int *> ilist; + testDumper("value='<0 items>',valueeditable='false',numchild='0'," + "internal='1',children=[]", + &ilist, NS"QList", true, "int*"); + ilist.append(new int(1)); + ilist.append(0); + testDumper("value='<2 items>',valueeditable='false',numchild='2'," + "internal='1',childtype='int*',childnumchild='1',children=[" + "{addr='" + str(deref(&ilist.at(0))) + + "',type='int',value='1'}," + "{value='<null>',numchild='0'}]", + &ilist, NS"QList", true, "int*"); +} + +void tst_Dumpers::dumpQList_char() +{ + QList<char> clist; + testDumper("value='<0 items>',valueeditable='false',numchild='0'," + "internal='1',children=[]", + &clist, NS"QList", true, "char"); + clist.append('a'); + clist.append('b'); + testDumper("value='<2 items>',valueeditable='false',numchild='2'," + "internal='1',childtype='char',childnumchild='0',children=[" + "{addr='" + str(&clist.at(0)) + "',value=''a', ascii=97'}," + "{addr='" + str(&clist.at(1)) + "',value=''b', ascii=98'}]", + &clist, NS"QList", true, "char"); +} + +void tst_Dumpers::dumpQList_QString() +{ + QList<QString> slist; + testDumper("value='<0 items>',valueeditable='false',numchild='0'," + "internal='1',children=[]", + &slist, NS"QList", true, NS"QString"); + slist.append("a"); + slist.append("b"); + testDumper("value='<2 items>',valueeditable='false',numchild='2'," + "internal='1',childtype='" NS "QString',childnumchild='0',children=[" + "{addr='" + str(&slist.at(0)) + "',value='YQA=',valueencoded='2'}," + "{addr='" + str(&slist.at(1)) + "',value='YgA=',valueencoded='2'}]", + &slist, NS"QList", true, NS"QString"); +} + +void tst_Dumpers::dumpQList_Int3() +{ + QList<Int3> i3list; + testDumper("value='<0 items>',valueeditable='false',numchild='0'," + "internal='0',children=[]", + &i3list, NS"QList", true, "Int3"); + i3list.append(Int3()); + i3list.append(Int3()); + testDumper("value='<2 items>',valueeditable='false',numchild='2'," + "internal='0',childtype='Int3',children=[" + "{addr='" + str(&i3list.at(0)) + "'}," + "{addr='" + str(&i3list.at(1)) + "'}]", + &i3list, NS"QList", true, "Int3"); +} + +void tst_Dumpers::dumpQList_QString3() +{ + QList<QString3> s3list; + testDumper("value='<0 items>',valueeditable='false',numchild='0'," + "internal='0',children=[]", + &s3list, NS"QList", true, "QString3"); + s3list.append(QString3()); + s3list.append(QString3()); + testDumper("value='<2 items>',valueeditable='false',numchild='2'," + "internal='0',childtype='QString3',children=[" + "{addr='" + str(&s3list.at(0)) + "'}," + "{addr='" + str(&s3list.at(1)) + "'}]", + &s3list, NS"QList", true, "QString3"); +} + +void tst_Dumpers::dumpQLocaleHelper(QLocale &loc) +{ + QByteArray expected = QByteArray("value='%',type='$T',numchild='8'," + "children=[{name='country',%}," + "{name='language',%}," + "{name='measurementSystem',%}," + "{name='numberOptions',%}," + "{name='timeFormat_(short)',%}," + "{name='timeFormat_(long)',%}," + "{name='decimalPoint',%}," + "{name='exponential',%}," + "{name='percent',%}," + "{name='zeroDigit',%}," + "{name='groupSeparator',%}," + "{name='negativeSign',%}]") + << valToString(loc.name()) + << createExp(&loc, "QLocale", "country()") + << createExp(&loc, "QLocale", "language()") + << createExp(&loc, "QLocale", "measurementSystem()") + << createExp(&loc, "QLocale", "numberOptions()") + << generateQStringSpec(loc.timeFormat(QLocale::ShortFormat)) + << generateQStringSpec(loc.timeFormat()) + << generateQCharSpec(loc.decimalPoint()) + << generateQCharSpec(loc.exponential()) + << generateQCharSpec(loc.percent()) + << generateQCharSpec(loc.zeroDigit()) + << generateQCharSpec(loc.groupSeparator()) + << generateQCharSpec(loc.negativeSign()); + testDumper(expected, &loc, NS"QLocale", true); +} + +void tst_Dumpers::dumpQLocale() +{ + QLocale english(QLocale::English); + dumpQLocaleHelper(english); + + QLocale german(QLocale::German); + dumpQLocaleHelper(german); + + QLocale chinese(QLocale::Chinese); + dumpQLocaleHelper(chinese); + + QLocale swahili(QLocale::Swahili); + dumpQLocaleHelper(swahili); +} + +template <typename K, typename V> + void tst_Dumpers::dumpQMapHelper(QMap<K, V> &map) +{ + QByteArray sizeStr(valToString(map.size())); + size_t nodeSize; + size_t valOff; + getMapNodeParams<K, V>(nodeSize, valOff); + int transKeyOffset = static_cast<int>(2*sizeof(void *)) - static_cast<int>(nodeSize); + int transValOffset = transKeyOffset + valOff; + bool simpleKey = isSimpleType<K>(); + bool simpleVal = isSimpleType<V>(); + QByteArray expected = QByteArray("value='<").append(sizeStr).append(" items>',numchild='"). + append(sizeStr).append("',extra='simplekey: ").append(N(simpleKey)). + append(" isSimpleValue: ").append(N(simpleVal)). + append(" keyOffset: ").append(N(transKeyOffset)).append(" valueOffset: "). + append(N(transValOffset)).append(" mapnodesize: "). + append(N(qulonglong(nodeSize))).append("',children=["); // 64bit Linux hack + typedef typename QMap<K, V>::iterator mapIter; + for (mapIter it = map.begin(); it != map.end(); ++it) { + if (it != map.begin()) + expected.append(","); + const QByteArray keyString = + QByteArray(valToString(it.key())).replace("valueencoded","keyencoded"); + expected.append("{key='").append(keyString).append("',value='"). + append(valToString(it.value())).append("',"); + if (simpleKey && simpleVal) { + expected.append("type='").append(typeToString<V>()). + append("',addr='").append(ptrToBa(&it.value())).append("'"); + } else { + QByteArray keyTypeStr = typeToString<K>(); + QByteArray valTypeStr = typeToString<V>(); +#if QT_VERSION >= 0x040500 + QMapNode<K, V> *node = 0; + size_t backwardOffset = size_t(&node->backward) - valOff; + char *addr = reinterpret_cast<char *>(&(*it)) + backwardOffset; + expected.append("addr='").append(ptrToBa(addr)). + append("',type='" NS "QMapNode<").append(keyTypeStr).append(","). + append(valTypeStr).append(" >").append("'"); +#else + expected.append("type='" NS "QMapData::Node<").append(keyTypeStr). + append(",").append(valTypeStr).append(" >"). + append("',exp='*('" NS "QMapData::Node<").append(keyTypeStr). + append(",").append(valTypeStr).append(" >"). + append(" >'*)").append(ptrToBa(&(*it))).append("'"); +#endif + } + expected.append("}"); + } + expected.append("]"); + mapIter it = map.begin(); + testDumper(expected, *reinterpret_cast<QMapData **>(&it), NS"QMap", + true, getMapType<K,V>(), "", 0, 0, nodeSize, valOff); +} + +void tst_Dumpers::dumpQMap() +{ + qDebug() << "QMap<int, int>"; + // Case 1: Simple type -> simple type. + QMap<int, int> map1; + + // Case 1.1: Empty map. + dumpQMapHelper(map1); + + // Case 1.2: One element. + map1[2] = 3; + dumpQMapHelper(map1); + + // Case 1.3: Two elements. + map1[3] = 5; + dumpQMapHelper(map1); + + // Case 2: Simple type -> composite type. + qDebug() << "QMap<int, QString>"; + QMap<int, QString> map2; + + // Case 2.1: Empty Map. + dumpQMapHelper(map2); + + // Case 2.2: One element. + map2[5] = "String 7"; + dumpQMapHelper(map2); + + // Case 2.3: Two elements. + map2[7] = "String 11"; + dumpQMapHelper(map2); + + // Case 3: Composite type -> simple type. + qDebug() << "QMap<QString, int>"; + QMap<QString, int> map3; + + // Case 3.1: Empty map. + dumpQMapHelper(map3); + + // Case 3.2: One element. + map3["String 13"] = 11; + dumpQMapHelper(map3); + + // Case 3.3: Two elements. + map3["String 17"] = 13; + dumpQMapHelper(map3); + + // Case 4: Composite type -> composite type. + QMap<QString, QString> map4; + + // Case 4.1: Empty map. + dumpQMapHelper(map4); + + // Case 4.2: One element. + map4["String 19"] = "String 23"; + dumpQMapHelper(map4); + + // Case 4.3: Two elements. + map4["String 29"] = "String 31"; + dumpQMapHelper(map4); + + // Case 4.4: Different value, same key (multimap functionality). + map4["String 29"] = "String 37"; + dumpQMapHelper(map4); +} + +template <typename K, typename V> + void tst_Dumpers::dumpQMapNodeHelper(QMap<K, V> &m) +{ + typename QMap<K, V>::iterator it = m.begin(); + const K &key = it.key(); + const V &val = it.value(); + //const char * const keyType = typeToString(key); + QByteArray expected = QByteArray("value='',numchild='2'," + "children=[{name='key',addr='").append(ptrToBa(&key)). + append("',type='").append(typeToString<K>()).append("',value='"). + append(valToString(key)).append("'},{name='value',addr='"). + append(ptrToBa(&val)).append("',type='").append(typeToString<V>()). + append("',value='").append(valToString(val)). + append("'}]"); + size_t nodeSize; + size_t valOffset; + getMapNodeParams<K, V>(nodeSize, valOffset); + testDumper(expected, *reinterpret_cast<QMapData **>(&it), NS"QMapNode", + true, getMapType<K,V>(), "", 0, 0, nodeSize, valOffset); +} + +void tst_Dumpers::dumpQMapNode() +{ + // Case 1: simple type -> simple type. + QMap<int, int> map; + map[2] = 3; + dumpQMapNodeHelper(map); + + // Case 2: simple type -> composite type. + QMap<int, QString> map2; + map2[3] = "String 5"; + dumpQMapNodeHelper(map2); + + // Case 3: composite type -> simple type. + QMap<QString, int> map3; + map3["String 7"] = 11; + dumpQMapNodeHelper(map3); + + // Case 4: composite type -> composite type. + QMap<QString, QString> map4; + map4["String 13"] = "String 17"; + dumpQMapNodeHelper(map4); +} + +#ifdef USE_PRIVATE +void tst_Dumpers::dumpQObject() +{ + QObject parent; + testDumper("value='',valueencoded='2',type='$T',displayedtype='QObject'," + "numchild='4'", + &parent, NS"QObject", false); + testDumper("value='',valueencoded='2',type='$T',displayedtype='QObject'," + "numchild='4',children=[" + "{name='properties',addr='$A',type='$TPropertyList'," + "value='<1 items>',numchild='1'}," + "{name='signals',addr='$A',type='$TSignalList'," + "value='<2 items>',numchild='2'}," + "{name='slots',addr='$A',type='$TSlotList'," + "value='<2 items>',numchild='2'}," + "{name='parent',value='0x0',type='$T *',numchild='0'}," + "{name='className',value='QObject',type='',numchild='0'}]", + &parent, NS"QObject", true); + +#if 0 + testDumper("numchild='2',value='<2 items>',type='QObjectSlotList'," + "children=[{name='2',value='deleteLater()'," + "numchild='0',addr='$A',type='QObjectSlot'}," + "{name='3',value='_q_reregisterTimers(void*)'," + "numchild='0',addr='$A',type='QObjectSlot'}]", + &parent, NS"QObjectSlotList", true); +#endif + + parent.setObjectName("A Parent"); + testDumper("value='QQAgAFAAYQByAGUAbgB0AA==',valueencoded='2',type='$T'," + "displayedtype='QObject',numchild='4'", + &parent, NS"QObject", false); + QObject child(&parent); + testDumper("value='',valueencoded='2',type='$T'," + "displayedtype='QObject',numchild='4'", + &child, NS"QObject", false); + child.setObjectName("A Child"); + QByteArray ba ="value='QQAgAEMAaABpAGwAZAA=',valueencoded='2',type='$T'," + "displayedtype='QObject',numchild='4',children=[" + "{name='properties',addr='$A',type='$TPropertyList'," + "value='<1 items>',numchild='1'}," + "{name='signals',addr='$A',type='$TSignalList'," + "value='<2 items>',numchild='2'}," + "{name='slots',addr='$A',type='$TSlotList'," + "value='<2 items>',numchild='2'}," + "{name='parent',addr='" + str(&parent) + "'," + "value='QQAgAFAAYQByAGUAbgB0AA==',valueencoded='2',type='$T'," + "displayedtype='QObject',numchild='1'}," + "{name='className',value='QObject',type='',numchild='0'}]"; + testDumper(ba, &child, NS"QObject", true); + connect(&child, SIGNAL(destroyed()), qApp, SLOT(quit())); + testDumper(ba, &child, NS"QObject", true); + disconnect(&child, SIGNAL(destroyed()), qApp, SLOT(quit())); + testDumper(ba, &child, NS"QObject", true); + child.setObjectName("A renamed Child"); + testDumper("value='QQAgAHIAZQBuAGEAbQBlAGQAIABDAGgAaQBsAGQA',valueencoded='2'," + "type='$T',displayedtype='QObject',numchild='4'", + &child, NS"QObject", false); +} + +void tst_Dumpers::dumpQObjectChildListHelper(QObject &o) +{ + const QObjectList children = o.children(); + const int size = children.size(); + const QString sizeStr = N(size); + QByteArray expected = QByteArray("numchild='").append(sizeStr).append("',value='<"). + append(sizeStr).append(" items>',type='" NS "QObjectChildList',children=["); + for (int i = 0; i < size; ++i) { + const QObject *child = children.at(i); + expected.append("{addr='").append(ptrToBa(child)).append("',value='"). + append(utfToBase64(child->objectName())). + append("',valueencoded='2',type='" NS "QObject',displayedtype='"). + append(child->metaObject()->className()).append("',numchild='1'}"); + if (i < size - 1) + expected.append(","); + } + expected.append("]"); + testDumper(expected, &o, NS"QObjectChildList", true); +} + +void tst_Dumpers::dumpQObjectChildList() +{ + // Case 1: Object with no children. + QObject o; + dumpQObjectChildListHelper(o); + + // Case 2: Object with one child. + QObject o2(&o); + dumpQObjectChildListHelper(o); + + // Case 3: Object with two children. + QObject o3(&o); + dumpQObjectChildListHelper(o); +} + +void tst_Dumpers::dumpQObjectMethodList() +{ + QStringListModel m; + testDumper("addr='<synthetic>',type='$T',numchild='24'," + "childtype='" NS "QMetaMethod::Method',childnumchild='0',children=[" + "{name='0 0 destroyed(QObject*)',value='<Signal> (1)'}," + "{name='1 1 destroyed()',value='<Signal> (1)'}," + "{name='2 2 deleteLater()',value='<Slot> (2)'}," + "{name='3 3 _q_reregisterTimers(void*)',value='<Slot> (2)'}," + "{name='4 4 dataChanged(QModelIndex,QModelIndex)',value='<Signal> (1)'}," + "{name='5 5 headerDataChanged(Qt::Orientation,int,int)',value='<Signal> (1)'}," + "{name='6 6 layoutChanged()',value='<Signal> (1)'}," + "{name='7 7 layoutAboutToBeChanged()',value='<Signal> (1)'}," + "{name='8 8 rowsAboutToBeInserted(QModelIndex,int,int)',value='<Signal> (1)'}," + "{name='9 9 rowsInserted(QModelIndex,int,int)',value='<Signal> (1)'}," + "{name='10 10 rowsAboutToBeRemoved(QModelIndex,int,int)',value='<Signal> (1)'}," + "{name='11 11 rowsRemoved(QModelIndex,int,int)',value='<Signal> (1)'}," + "{name='12 12 columnsAboutToBeInserted(QModelIndex,int,int)',value='<Signal> (1)'}," + "{name='13 13 columnsInserted(QModelIndex,int,int)',value='<Signal> (1)'}," + "{name='14 14 columnsAboutToBeRemoved(QModelIndex,int,int)',value='<Signal> (1)'}," + "{name='15 15 columnsRemoved(QModelIndex,int,int)',value='<Signal> (1)'}," + "{name='16 16 modelAboutToBeReset()',value='<Signal> (1)'}," + "{name='17 17 modelReset()',value='<Signal> (1)'}," + "{name='18 18 rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)',value='<Signal> (1)'}," + "{name='19 19 rowsMoved(QModelIndex,int,int,QModelIndex,int)',value='<Signal> (1)'}," + "{name='20 20 columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)',value='<Signal> (1)'}," + "{name='21 21 columnsMoved(QModelIndex,int,int,QModelIndex,int)',value='<Signal> (1)'}," + "{name='22 22 submit()',value='<Slot> (2)'}," + "{name='23 23 revert()',value='<Slot> (2)'}]", + &m, NS"QObjectMethodList", true); +} + +void tst_Dumpers::dumpQObjectPropertyList() +{ + // Case 1: Model without a parent. + QStringListModel m(QStringList() << "Test1" << "Test2"); + testDumper("addr='<synthetic>',type='$T',numchild='1',value='<1 items>'," + "children=[{name='objectName',type='QString',value=''," + "valueencoded='2',numchild='0'}]", + &m, NS"QObjectPropertyList", true); + + // Case 2: Model with a parent. + QStringListModel m2(&m); + testDumper("addr='<synthetic>',type='$T',numchild='1',value='<1 items>'," + "children=[{name='objectName',type='QString',value=''," + "valueencoded='2',numchild='0'}]", + &m2, NS"QObjectPropertyList", true); +} + +static const char *connectionType(uint type) +{ + Qt::ConnectionType connType = static_cast<Qt::ConnectionType>(type); + const char *output = "unknown"; + switch (connType) { + case Qt::AutoConnection: output = "auto"; break; + case Qt::DirectConnection: output = "direct"; break; + case Qt::QueuedConnection: output = "queued"; break; + case Qt::BlockingQueuedConnection: output = "blockingqueued"; break; + case 3: output = "autocompat"; break; +#if QT_VERSION >= 0x040600 + case Qt::UniqueConnection: break; // Can't happen. +#endif + default: + qWarning() << "Unknown connection type: " << type; + break; + }; + return output; +}; + +class Cheater : public QObject +{ +public: + static const QObjectPrivate *getPrivate(const QObject &o) + { + const Cheater &cheater = static_cast<const Cheater&>(o); +#if QT_VERSION >= 0x040600 + return dynamic_cast<const QObjectPrivate *>(cheater.d_ptr.data()); +#else + return dynamic_cast<const QObjectPrivate *>(cheater.d_ptr); +#endif + } +}; + +typedef QVector<QObjectPrivate::ConnectionList> ConnLists; + +void tst_Dumpers::dumpQObjectSignalHelper(QObject &o, int sigNum) +{ + //qDebug() << o.objectName() << sigNum; + QByteArray expected("addr='<synthetic>',numchild='1',type='" NS "QObjectSignal'"); +#if QT_VERSION >= 0x040400 && QT_VERSION <= 0x040700 + expected.append(",children=["); + const QObjectPrivate *p = Cheater::getPrivate(o); + Q_ASSERT(p != 0); + const ConnLists *connLists = reinterpret_cast<const ConnLists *>(p->connectionLists); + QObjectPrivate::ConnectionList connList = + connLists != 0 && connLists->size() > sigNum ? + connLists->at(sigNum) : QObjectPrivate::ConnectionList(); + int i = 0; + // FIXME: 4.6 only + for (QObjectPrivate::Connection *conn = connList.first; conn != 0; + ++i, conn = conn->nextConnectionList) { + const QString iStr = N(i); + expected.append("{name='").append(iStr).append(" receiver',"); + if (conn->receiver == &o) + expected.append("value='<this>',type='"). + append(o.metaObject()->className()). + append("',numchild='0',addr='").append(ptrToBa(&o)).append("'"); + else if (conn->receiver == 0) + expected.append("value='0x0',type='" NS "QObject *',numchild='0'"); + else + expected.append("addr='").append(ptrToBa(conn->receiver)).append("',value='"). + append(utfToBase64(conn->receiver->objectName())).append("',valueencoded='2',"). + append("type='" NS "QObject',displayedtype='"). + append(conn->receiver->metaObject()->className()).append("',numchild='1'"); + expected.append("},{name='").append(iStr).append(" slot',type='',value='"); + if (conn->receiver != 0) + expected.append(conn->receiver->metaObject()->method(conn->method).signature()); + else + expected.append("<invalid receiver>"); + expected.append("',numchild='0'},{name='").append(iStr).append(" type',type='',value='<"). + append(connectionType(conn->connectionType)).append(" connection>',"). + append("numchild='0'}"); + if (conn != connList.last) + expected.append(","); + } + expected.append("],numchild='").append(N(i)).append("'"); +#endif + testDumper(expected, &o, NS"QObjectSignal", true, "", "", sigNum); +} + +void tst_Dumpers::dumpQObjectSignal() +{ + // Case 1: Simple QObject. + QObject o; + o.setObjectName("Test"); + testDumper("addr='<synthetic>',numchild='1',type='" NS "QObjectSignal'," + "children=[],numchild='0'", + &o, NS"QObjectSignal", true, "", "", 0); + + // Case 2: QAbstractItemModel with no connections. + QStringListModel m(QStringList() << "Test1" << "Test2"); + for (int signalIndex = 0; signalIndex < 17; ++signalIndex) + dumpQObjectSignalHelper(m, signalIndex); + + // Case 3: QAbstractItemModel with connections to itself and to another + // object, using different connection types. + qRegisterMetaType<QModelIndex>("QModelIndex"); + connect(&m, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), + &o, SLOT(deleteLater()), Qt::DirectConnection); + connect(&m, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), + &m, SLOT(revert()), Qt::QueuedConnection); + connect(&m, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), + &m, SLOT(submit()), Qt::QueuedConnection); + connect(&m, SIGNAL(columnsInserted(QModelIndex,int,int)), + &m, SLOT(submit()), Qt::BlockingQueuedConnection); + connect(&m, SIGNAL(columnsRemoved(QModelIndex,int,int)), + &m, SLOT(deleteLater()), Qt::AutoConnection); +#if QT_VERSION >= 0x040600 + connect(&m, SIGNAL(dataChanged(QModelIndex,QModelIndex)), + &m, SLOT(revert()), Qt::UniqueConnection); +#endif + for (int signalIndex = 0; signalIndex < 17; ++signalIndex) + dumpQObjectSignalHelper(m, signalIndex); +} + +void tst_Dumpers::dumpQObjectSignalList() +{ + // Case 1: Simple QObject. + QObject o; + o.setObjectName("Test"); + + testDumper("type='" NS "QObjectSignalList',value='<2 items>'," + "addr='$A',numchild='2',children=[" + "{name='0',value='destroyed(QObject*)',numchild='0'," + "addr='$A',type='" NS "QObjectSignal'}," + "{name='1',value='destroyed()',numchild='0'," + "addr='$A',type='" NS "QObjectSignal'}]", + &o, NS"QObjectSignalList", true); + + // Case 2: QAbstractItemModel with no connections. + QStringListModel m(QStringList() << "Test1" << "Test2"); + QByteArray expected = "type='" NS "QObjectSignalList',value='<20 items>'," + "addr='$A',numchild='20',children=[" + "{name='0',value='destroyed(QObject*)',numchild='0'," + "addr='$A',type='" NS "QObjectSignal'}," + "{name='1',value='destroyed()',numchild='0'," + "addr='$A',type='" NS "QObjectSignal'}," + "{name='4',value='dataChanged(QModelIndex,QModelIndex)',numchild='0'," + "addr='$A',type='" NS "QObjectSignal'}," + "{name='5',value='headerDataChanged(Qt::Orientation,int,int)'," + "numchild='0',addr='$A',type='" NS "QObjectSignal'}," + "{name='6',value='layoutChanged()',numchild='0'," + "addr='$A',type='" NS "QObjectSignal'}," + "{name='7',value='layoutAboutToBeChanged()',numchild='0'," + "addr='$A',type='" NS "QObjectSignal'}," + "{name='8',value='rowsAboutToBeInserted(QModelIndex,int,int)'," + "numchild='0',addr='$A',type='" NS "QObjectSignal'}," + "{name='9',value='rowsInserted(QModelIndex,int,int)'," + "numchild='0',addr='$A',type='" NS "QObjectSignal'}," + "{name='10',value='rowsAboutToBeRemoved(QModelIndex,int,int)'," + "numchild='%',addr='$A',type='" NS "QObjectSignal'}," + "{name='11',value='rowsRemoved(QModelIndex,int,int)'," + "numchild='%',addr='$A',type='" NS "QObjectSignal'}," + "{name='12',value='columnsAboutToBeInserted(QModelIndex,int,int)'," + "numchild='%',addr='$A',type='" NS "QObjectSignal'}," + "{name='13',value='columnsInserted(QModelIndex,int,int)'," + "numchild='%',addr='$A',type='" NS "QObjectSignal'}," + "{name='14',value='columnsAboutToBeRemoved(QModelIndex,int,int)'," + "numchild='%',addr='$A',type='" NS "QObjectSignal'}," + "{name='15',value='columnsRemoved(QModelIndex,int,int)'," + "numchild='%',addr='$A',type='" NS "QObjectSignal'}," + "{name='16',value='modelAboutToBeReset()'," + "numchild='0',addr='$A',type='" NS "QObjectSignal'}," + "{name='17',value='modelReset()'," + "numchild='0',addr='$A',type='" NS "QObjectSignal'}," + "{name='18',value='rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)'," + "numchild='0',addr='$A',type='" NS "QObjectSignal'}," + "{name='19',value='rowsMoved(QModelIndex,int,int,QModelIndex,int)'," + "numchild='0',addr='$A',type='" NS "QObjectSignal'}," + "{name='20',value='columnsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)'," + "numchild='0',addr='$A',type='" NS "QObjectSignal'}," + "{name='21',value='columnsMoved(QModelIndex,int,int,QModelIndex,int)'," + "numchild='0',addr='$A',type='" NS "QObjectSignal'}]"; + + + testDumper(expected << "0" << "0" << "0" << "0" << "0" << "0", + &m, NS"QObjectSignalList", true); + + + // Case 3: QAbstractItemModel with connections to itself and to another + // object, using different connection types. + qRegisterMetaType<QModelIndex>("QModelIndex"); + connect(&m, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), + &o, SLOT(deleteLater()), Qt::DirectConnection); + connect(&m, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), + &m, SLOT(revert()), Qt::QueuedConnection); + connect(&m, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), + &m, SLOT(submit()), Qt::QueuedConnection); + connect(&m, SIGNAL(columnsInserted(QModelIndex,int,int)), + &m, SLOT(submit()), Qt::BlockingQueuedConnection); + connect(&m, SIGNAL(columnsRemoved(QModelIndex,int,int)), + &m, SLOT(deleteLater()), Qt::AutoConnection); + + testDumper(expected << "1" << "1" << "2" << "1" << "0" << "0", + &m, NS"QObjectSignalList", true); +} + +QByteArray slotIndexList(const QObject *ob) +{ + QByteArray slotIndices; + const QMetaObject *mo = ob->metaObject(); + for (int i = 0; i < mo->methodCount(); ++i) { + const QMetaMethod &mm = mo->method(i); + if (mm.methodType() == QMetaMethod::Slot) { + int slotIndex = mo->indexOfSlot(mm.signature()); + Q_ASSERT(slotIndex != -1); + slotIndices.append(N(slotIndex)); + slotIndices.append(','); + } + } + slotIndices.chop(1); + return slotIndices; +} + +void tst_Dumpers::dumpQObjectSlot() +{ + // Case 1: Simple QObject. + QObject o; + o.setObjectName("Test"); + + QByteArray slotIndices = slotIndexList(&o); + QCOMPARE(slotIndices, QByteArray("2,3")); + QCOMPARE(o.metaObject()->indexOfSlot("deleteLater()"), 2); + + QByteArray expected = QByteArray("addr='$A',numchild='1',type='$T'," + //"children=[{name='1 sender'}],numchild='1'"); + "children=[],numchild='0'"); + qDebug() << "FIXME!"; + testDumper(expected, &o, NS"QObjectSlot", true, "", "", 2); + + + // Case 2: QAbstractItemModel with no connections. + QStringListModel m(QStringList() << "Test1" << "Test2"); + slotIndices = slotIndexList(&o); + + QCOMPARE(slotIndices, QByteArray("2,3")); + QCOMPARE(o.metaObject()->indexOfSlot("deleteLater()"), 2); + + expected = QByteArray("addr='$A',numchild='1',type='$T'," + //"children=[{name='1 sender'}],numchild='1'"); + "children=[],numchild='0'"); + qDebug() << "FIXME!"; + testDumper(expected, &o, NS"QObjectSlot", true, "", "", 2); + + + // Case 3: QAbstractItemModel with connections to itself and to another + // o, using different connection types. + qRegisterMetaType<QModelIndex>("QModelIndex"); + connect(&m, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), + &o, SLOT(deleteLater()), Qt::DirectConnection); + connect(&o, SIGNAL(destroyed(QObject*)), + &m, SLOT(revert()), Qt::QueuedConnection); + connect(&m, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), + &m, SLOT(submit()), Qt::QueuedConnection); + connect(&m, SIGNAL(columnsInserted(QModelIndex,int,int)), + &m, SLOT(submit()), Qt::BlockingQueuedConnection); + connect(&m, SIGNAL(columnsRemoved(QModelIndex,int,int)), + &m, SLOT(deleteLater()), Qt::AutoConnection); +#if QT_VERSION >= 0x040600 + connect(&m, SIGNAL(dataChanged(QModelIndex,QModelIndex)), + &m, SLOT(revert()), Qt::UniqueConnection); +#endif + expected = QByteArray("addr='$A',numchild='1',type='$T'," + //"children=[{name='1 sender'}],numchild='1'"); + "children=[],numchild='0'"); + qDebug() << "FIXME!"; + testDumper(expected, &o, NS"QObjectSlot", true, "", "", 2); + +} + +void tst_Dumpers::dumpQObjectSlotList() +{ + // Case 1: Simple QObject. + QObject o; + o.setObjectName("Test"); + testDumper("numchild='2',value='<2 items>',type='$T'," + "children=[{name='2',value='deleteLater()',numchild='0'," + "addr='$A',type='" NS "QObjectSlot'}," + "{name='3',value='_q_reregisterTimers(void*)',numchild='0'," + "addr='$A',type='" NS "QObjectSlot'}]", + &o, NS"QObjectSlotList", true); + + // Case 2: QAbstractItemModel with no connections. + QStringListModel m(QStringList() << "Test1" << "Test2"); + testDumper("numchild='4',value='<4 items>',type='$T'," + "children=[{name='2',value='deleteLater()',numchild='0'," + "addr='$A',type='" NS "QObjectSlot'}," + "{name='3',value='_q_reregisterTimers(void*)',numchild='0'," + "addr='$A',type='" NS "QObjectSlot'}," + "{name='22',value='submit()',numchild='0'," + "addr='$A',type='" NS "QObjectSlot'}," + "{name='23',value='revert()',numchild='0'," + "addr='$A',type='" NS "QObjectSlot'}]", + &m, NS"QObjectSlotList", true); + + // Case 3: QAbstractItemModel with connections to itself and to another + // object, using different connection types. + qRegisterMetaType<QModelIndex>("QModelIndex"); + connect(&m, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), + &o, SLOT(deleteLater()), Qt::DirectConnection); + connect(&m, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), + &m, SLOT(revert()), Qt::QueuedConnection); + connect(&m, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), + &m, SLOT(submit()), Qt::QueuedConnection); + connect(&m, SIGNAL(columnsInserted(QModelIndex,int,int)), + &m, SLOT(submit()), Qt::BlockingQueuedConnection); + connect(&m, SIGNAL(columnsRemoved(QModelIndex,int,int)), + &m, SLOT(deleteLater()), Qt::AutoConnection); + connect(&o, SIGNAL(destroyed(QObject*)), &m, SLOT(submit())); + testDumper("numchild='4',value='<4 items>',type='$T'," + "children=[{name='2',value='deleteLater()',numchild='0'," + "addr='$A',type='" NS "QObjectSlot'}," + "{name='3',value='_q_reregisterTimers(void*)',numchild='0'," + "addr='$A',type='" NS "QObjectSlot'}," + "{name='22',value='submit()',numchild='0'," + "addr='$A',type='" NS "QObjectSlot'}," + "{name='23',value='revert()',numchild='0'," + "addr='$A',type='" NS "QObjectSlot'}]", + &m, NS"QObjectSlotList", true); +} +#endif + +void tst_Dumpers::dumpQPixmap() +{ + // Case 1: Null Pixmap. + QPixmap p; + + testDumper("value='(0x0)',type='$T',numchild='0'", + &p, NS"QPixmap", true); + + + // Case 2: Uninitialized non-null pixmap. + p = QPixmap(20, 100); + testDumper("value='(20x100)',type='$T',numchild='0'", + &p, NS"QPixmap", true); + + + // Case 3: Initialized non-null pixmap. + const char * const pixmap[] = { + "2 24 3 1", " c None", ". c #DBD3CB", "+ c #FCFBFA", + " ", " ", " ", ".+", ".+", ".+", ".+", ".+", ".+", ".+", ".+", ".+", + ".+", ".+", ".+", ".+", ".+", ".+", ".+", ".+", ".+", " ", " ", " " + }; + p = QPixmap(pixmap); + testDumper("value='(2x24)',type='$T',numchild='0'", + &p, NS"QPixmap", true); +} + +#if QT_VERSION >= 0x040500 +template<typename T> +void tst_Dumpers::dumpQSharedPointerHelper(QSharedPointer<T> &ptr) +{ + struct Cheater : public QSharedPointer<T> + { + static const typename QSharedPointer<T>::Data *getData(const QSharedPointer<T> &p) + { + return static_cast<const Cheater &>(p).d; + } + }; + + QByteArray expected("value='"); + QString val1 = ptr.isNull() ? "<null>" : valToString(*ptr.data()); + QString val2 = isSimpleType<T>() ? val1 : ""; +/* + const int *weakAddr; + const int *strongAddr; + int weakValue; + int strongValue; + if (!ptr.isNull()) { + weakAddr = reinterpret_cast<const int *>(&Cheater::getData(ptr)->weakref); + strongAddr = reinterpret_cast<const int *>(&Cheater::getData(ptr)->strongref); + weakValue = *weakAddr; + strongValue = *strongAddr; + } else { + weakAddr = strongAddr = 0; + weakValue = strongValue = 0; + } + expected.append(val2).append("',valueeditable='false',numchild='1',children=["). + append("{name='data',addr='").append(ptrToBa(ptr.data())). + append("',type='").append(typeToString<T>()).append("',value='").append(val1). + append("'},{name='weakref',value='").append(N(weakValue)). + append("',type='int',addr='").append(ptrToBa(weakAddr)).append("',numchild='0'},"). + append("{name='strongref',value='").append(N(strongValue)). + append("',type='int',addr='").append(ptrToBa(strongAddr)).append("',numchild='0'}]"); + testDumper(expected, &ptr, NS"QSharedPointer", true, typeToString<T>()); +*/ +} +#endif + +void tst_Dumpers::dumpQSharedPointer() +{ +#if QT_VERSION >= 0x040500 + // Case 1: Simple type. + // Case 1.1: Null pointer. + QSharedPointer<int> simplePtr; + dumpQSharedPointerHelper(simplePtr); + + // Case 1.2: Non-null pointer, + QSharedPointer<int> simplePtr2(new int(99)); + dumpQSharedPointerHelper(simplePtr2); + + // Case 1.3: Shared pointer. + QSharedPointer<int> simplePtr3 = simplePtr2; + dumpQSharedPointerHelper(simplePtr2); + + // Case 1.4: Weak pointer. + QWeakPointer<int> simplePtr4(simplePtr2); + dumpQSharedPointerHelper(simplePtr2); + + // Case 2: Composite type. + // Case 1.1: Null pointer. + QSharedPointer<QString> compositePtr; + // TODO: This case is not handled in dumper.cpp (segfault!) + //dumpQSharedPointerHelper(compoistePtr); + + // Case 1.2: Non-null pointer, + QSharedPointer<QString> compositePtr2(new QString("Test")); + dumpQSharedPointerHelper(compositePtr2); + + // Case 1.3: Shared pointer. + QSharedPointer<QString> compositePtr3 = compositePtr2; + dumpQSharedPointerHelper(compositePtr2); + + // Case 1.4: Weak pointer. + QWeakPointer<QString> compositePtr4(compositePtr2); + dumpQSharedPointerHelper(compositePtr2); +#endif +} + +void tst_Dumpers::dumpQString() +{ + QString s; + testDumper("value='IiIgKG51bGwp',valueencoded='5',type='$T',numchild='0'", + &s, NS"QString", false); + s = "abc"; + testDumper("value='YQBiAGMA',valueencoded='2',type='$T',numchild='0'", + &s, NS"QString", false); +} + +void tst_Dumpers::dumpQVariant_invalid() +{ + QVariant v; + testDumper("value='(invalid)',type='$T',numchild='0'", + &v, NS"QVariant", false); +} + +void tst_Dumpers::dumpQVariant_QString() +{ + QVariant v = "abc"; + testDumper("value='KFFTdHJpbmcpICJhYmMi',valueencoded='5',type='$T'," + "numchild='0'", + &v, NS"QVariant", true); +/* + FIXME: the QString version should have a child: + testDumper("value='KFFTdHJpbmcpICJhYmMi',valueencoded='5',type='$T'," + "numchild='1',children=[{name='value',value='IgBhAGIAYwAiAA=='," + "valueencoded='4',type='QString',numchild='0'}]", + &v, NS"QVariant", true); +*/ +} + +void tst_Dumpers::dumpQVariant_QStringList() +{ + QVariant v = QStringList() << "Hi"; + testDumper("value='(QStringList) ',type='$T',numchild='1'," + "children=[{name='value',exp='(*('" NS "QStringList'*)%)'," + "type='QStringList',numchild='1'}]" + << QByteArray::number(quintptr(&v)), + &v, NS"QVariant", true); +} + +#ifndef Q_CC_MSVC + +void tst_Dumpers::dumpStdVector() +{ + std::vector<std::list<int> *> vector; + QByteArray inner = "std::list<int> *"; + QByteArray innerp = "std::list<int>"; + testDumper("value='<0 items>',valueeditable='false',numchild='0'", + &vector, "std::vector", false, inner, "", sizeof(std::list<int> *)); + std::list<int> list; + vector.push_back(new std::list<int>(list)); + testDumper("value='<1 items>',valueeditable='false',numchild='1'," + "childtype='" + inner + "',childnumchild='1'," + "children=[{addr='" + str(deref(&vector[0])) + "',type='" + innerp + "'}]", + &vector, "std::vector", true, inner, "", sizeof(std::list<int> *)); + vector.push_back(0); + list.push_back(45); + testDumper("value='<2 items>',valueeditable='false',numchild='2'," + "childtype='" + inner + "',childnumchild='1'," + "children=[{addr='" + str(deref(&vector[0])) + "',type='" + innerp + "'}," + "{addr='" + str(&vector[1]) + "'," + "type='" + innerp + "',value='<null>',numchild='0'}]", + &vector, "std::vector", true, inner, "", sizeof(std::list<int> *)); + vector.push_back(new std::list<int>(list)); + vector.push_back(0); +} + +#endif // !Q_CC_MSVC + +void tst_Dumpers::dumpQTextCodecHelper(QTextCodec *codec) +{ + const QByteArray name = codec->name().toBase64(); + QByteArray expected = QByteArray("value='%',valueencoded='1',type='$T'," + "numchild='2',children=[{name='name',value='%',type='" NS "QByteArray'," + "numchild='0',valueencoded='1'},{name='mibEnum',%}]") + << name << name << generateIntSpec(codec->mibEnum()); + testDumper(expected, codec, NS"QTextCodec", true); +} + +void tst_Dumpers::dumpQTextCodec() +{ + const QList<QByteArray> &codecNames = QTextCodec::availableCodecs(); + foreach (const QByteArray &codecName, codecNames) + dumpQTextCodecHelper(QTextCodec::codecForName(codecName)); +} + +#if QT_VERSION >= 0x040500 +template <typename T1, typename T2> + size_t offsetOf(const T1 *klass, const T2 *member) +{ + return static_cast<size_t>(reinterpret_cast<const char *>(member) - + reinterpret_cast<const char *>(klass)); +} + +template <typename T> +void tst_Dumpers::dumpQWeakPointerHelper(QWeakPointer<T> &ptr) +{ + typedef QtSharedPointer::ExternalRefCountData Data; + const size_t dataOffset = 0; + const Data *d = *reinterpret_cast<const Data **>( + reinterpret_cast<const char **>(&ptr) + dataOffset); + const int *weakRefPtr = reinterpret_cast<const int *>(&d->weakref); + const int *strongRefPtr = reinterpret_cast<const int *>(&d->strongref); + T *data = ptr.toStrongRef().data(); + const QString dataStr = valToString(*data); + QByteArray expected("value='"); + if (isSimpleType<T>()) + expected.append(dataStr); + expected.append("',valueeditable='false',numchild='1',children=[{name='data',addr='"). + append(ptrToBa(data)).append("',type='").append(typeToString<T>()). + append("',value='").append(dataStr).append("'},{name='weakref',value='"). + append(valToString(*weakRefPtr)).append("',type='int',addr='"). + append(ptrToBa(weakRefPtr)).append("',numchild='0'},{name='strongref',value='"). + append(valToString(*strongRefPtr)).append("',type='int',addr='"). + append(ptrToBa(strongRefPtr)).append("',numchild='0'}]"); + testDumper(expected, &ptr, NS"QWeakPointer", true, typeToString<T>()); +} +#endif + +void tst_Dumpers::dumpQWeakPointer() +{ +#if QT_VERSION >= 0x040500 + // Case 1: Simple type. + + // Case 1.1: Null pointer. + QSharedPointer<int> spNull; + QWeakPointer<int> wp = spNull.toWeakRef(); + testDumper("value='<null>',valueeditable='false',numchild='0'", + &wp, NS"QWeakPointer", true, "int"); + + // Case 1.2: Weak pointer is unique. + QSharedPointer<int> sp(new int(99)); + wp = sp.toWeakRef(); + dumpQWeakPointerHelper(wp); + + // Case 1.3: There are other weak pointers. + QWeakPointer<int> wp2 = sp.toWeakRef(); + dumpQWeakPointerHelper(wp); + + // Case 1.4: There are other strong shared pointers as well. + QSharedPointer<int> sp2(sp); + dumpQWeakPointerHelper(wp); + + // Case 2: Composite type. + QSharedPointer<QString> spS(new QString("Test")); + QWeakPointer<QString> wpS = spS.toWeakRef(); + dumpQWeakPointerHelper(wpS); +#endif +} + +#define VERIFY_OFFSETOF(member) \ +do { \ + QObjectPrivate *qob = 0; \ + ObjectPrivate *ob = 0; \ + QVERIFY(size_t(&qob->member) == size_t(&ob->member)); \ +} while (0) + + +void tst_Dumpers::initTestCase() +{ + QVERIFY(sizeof(QWeakPointer<int>) == 2*sizeof(void *)); + QVERIFY(sizeof(QSharedPointer<int>) == 2*sizeof(void *)); +#if QT_VERSION < 0x050000 + QtSharedPointer::ExternalRefCountData d; + d.weakref = d.strongref = 0; // That's what the destructor expects. + QVERIFY(sizeof(int) == sizeof(d.weakref)); + QVERIFY(sizeof(int) == sizeof(d.strongref)); +#endif +#ifdef USE_PRIVATE + const size_t qObjectPrivateSize = sizeof(QObjectPrivate); + const size_t objectPrivateSize = sizeof(ObjectPrivate); + QVERIFY2(qObjectPrivateSize == objectPrivateSize, QString::fromLatin1("QObjectPrivate=%1 ObjectPrivate=%2").arg(qObjectPrivateSize).arg(objectPrivateSize).toLatin1().constData()); + VERIFY_OFFSETOF(threadData); + VERIFY_OFFSETOF(extraData); + VERIFY_OFFSETOF(objectName); + VERIFY_OFFSETOF(connectionLists); + VERIFY_OFFSETOF(senders); + VERIFY_OFFSETOF(currentSender); + VERIFY_OFFSETOF(eventFilters); + VERIFY_OFFSETOF(currentChildBeingDeleted); + VERIFY_OFFSETOF(connectedSignals); + //VERIFY_OFFSETOF(deleteWatch); +#ifdef QT3_SUPPORT +#if QT_VERSION < 0x040600 + VERIFY_OFFSETOF(pendingChildInsertedEvents); +#endif +#endif +#if QT_VERSION >= 0x040600 + VERIFY_OFFSETOF(sharedRefcount); +#endif +#endif +} + + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + tst_Dumpers test; + return QTest::qExec(&test, argc, argv); +} + +#include "tst_dumpers.moc" + diff --git a/tests/auto/debugger/tst_version.cpp b/tests/auto/debugger/tst_version.cpp index 5d53aab1ac..afb23d329e 100644 --- a/tests/auto/debugger/tst_version.cpp +++ b/tests/auto/debugger/tst_version.cpp @@ -27,7 +27,7 @@ ** ****************************************************************************/ -#include "gdb/gdbmi.h" +#include "debuggerprotocol.h" #include <QtTest> diff --git a/tests/auto/debugger/version.pro b/tests/auto/debugger/version.pro index aeb0b4e542..bc158b8c98 100644 --- a/tests/auto/debugger/version.pro +++ b/tests/auto/debugger/version.pro @@ -8,5 +8,5 @@ INCLUDEPATH += $$DEBUGGERDIR $$UTILSDIR SOURCES += \ tst_version.cpp \ - $$DEBUGGERDIR/gdb/gdbmi.cpp \ + $$DEBUGGERDIR/debuggerprotocol.cpp \ diff --git a/tests/auto/filesearch/tst_filesearch.cpp b/tests/auto/filesearch/tst_filesearch.cpp index 0e1157c615..dd5f82f78a 100644 --- a/tests/auto/filesearch/tst_filesearch.cpp +++ b/tests/auto/filesearch/tst_filesearch.cpp @@ -51,6 +51,7 @@ private slots: void multipleResults(); void caseSensitive(); void caseInSensitive(); + void matchCaseReplacement(); }; namespace { @@ -99,6 +100,49 @@ void tst_FileSearch::caseInSensitive() test_helper(expectedResults, QLatin1String("CaseSensitive"), QTextDocument::FindFlags(0)); } +void tst_FileSearch::matchCaseReplacement() +{ + QCOMPARE(Utils::matchCaseReplacement("", "foobar"), QString("foobar")); //empty string + + QCOMPARE(Utils::matchCaseReplacement("testpad", "foobar"), QString("foobar")); //lower case + QCOMPARE(Utils::matchCaseReplacement("TESTPAD", "foobar"), QString("FOOBAR")); //upper case + QCOMPARE(Utils::matchCaseReplacement("Testpad", "foobar"), QString("Foobar")); //capitalized + QCOMPARE(Utils::matchCaseReplacement("tESTPAD", "foobar"), QString("fOOBAR")); //un-capitalized + QCOMPARE(Utils::matchCaseReplacement("tEsTpAd", "foobar"), QString("foobar")); //mixed case, use replacement as specified + QCOMPARE(Utils::matchCaseReplacement("TeStPaD", "foobar"), QString("foobar")); //mixed case, use replacement as specified + + QCOMPARE(Utils::matchCaseReplacement("testpad", "fooBar"), QString("foobar")); //lower case + QCOMPARE(Utils::matchCaseReplacement("TESTPAD", "fooBar"), QString("FOOBAR")); //upper case + QCOMPARE(Utils::matchCaseReplacement("Testpad", "fooBar"), QString("Foobar")); //capitalized + QCOMPARE(Utils::matchCaseReplacement("tESTPAD", "fooBar"), QString("fOOBAR")); //un-capitalized + QCOMPARE(Utils::matchCaseReplacement("tEsTpAd", "fooBar"), QString("fooBar")); //mixed case, use replacement as specified + QCOMPARE(Utils::matchCaseReplacement("TeStPaD", "fooBar"), QString("fooBar")); //mixed case, use replacement as specified + + //with common prefix + QCOMPARE(Utils::matchCaseReplacement("pReFiXtestpad", "prefixfoobar"), QString("pReFiXfoobar")); //lower case + QCOMPARE(Utils::matchCaseReplacement("pReFiXTESTPAD", "prefixfoobar"), QString("pReFiXFOOBAR")); //upper case + QCOMPARE(Utils::matchCaseReplacement("pReFiXTestpad", "prefixfoobar"), QString("pReFiXFoobar")); //capitalized + QCOMPARE(Utils::matchCaseReplacement("pReFiXtESTPAD", "prefixfoobar"), QString("pReFiXfOOBAR")); //un-capitalized + QCOMPARE(Utils::matchCaseReplacement("pReFiXtEsTpAd", "prefixfoobar"), QString("pReFiXfoobar")); //mixed case, use replacement as specified + QCOMPARE(Utils::matchCaseReplacement("pReFiXTeStPaD", "prefixfoobar"), QString("pReFiXfoobar")); //mixed case, use replacement as specified + + //with common suffix + QCOMPARE(Utils::matchCaseReplacement("testpadSuFfIx", "foobarsuffix"), QString("foobarSuFfIx")); //lower case + QCOMPARE(Utils::matchCaseReplacement("TESTPADSuFfIx", "foobarsuffix"), QString("FOOBARSuFfIx")); //upper case + QCOMPARE(Utils::matchCaseReplacement("TestpadSuFfIx", "foobarsuffix"), QString("FoobarSuFfIx")); //capitalized + QCOMPARE(Utils::matchCaseReplacement("tESTPADSuFfIx", "foobarsuffix"), QString("fOOBARSuFfIx")); //un-capitalized + QCOMPARE(Utils::matchCaseReplacement("tEsTpAdSuFfIx", "foobarsuffix"), QString("foobarSuFfIx")); //mixed case, use replacement as specified + QCOMPARE(Utils::matchCaseReplacement("TeStPaDSuFfIx", "foobarsuffix"), QString("foobarSuFfIx")); //mixed case, use replacement as specified + + //with common prefix and suffix + QCOMPARE(Utils::matchCaseReplacement("pReFiXtestpadSuFfIx", "prefixfoobarsuffix"), QString("pReFiXfoobarSuFfIx")); //lower case + QCOMPARE(Utils::matchCaseReplacement("pReFiXTESTPADSuFfIx", "prefixfoobarsuffix"), QString("pReFiXFOOBARSuFfIx")); //upper case + QCOMPARE(Utils::matchCaseReplacement("pReFiXTestpadSuFfIx", "prefixfoobarsuffix"), QString("pReFiXFoobarSuFfIx")); //capitalized + QCOMPARE(Utils::matchCaseReplacement("pReFiXtESTPADSuFfIx", "prefixfoobarsuffix"), QString("pReFiXfOOBARSuFfIx")); //un-capitalized + QCOMPARE(Utils::matchCaseReplacement("pReFiXtEsTpAdSuFfIx", "prefixfoobarsuffix"), QString("pReFiXfoobarSuFfIx")); //mixed case, use replacement as specified + QCOMPARE(Utils::matchCaseReplacement("pReFiXTeStPaDSuFfIx", "prefixfoobarsuffix"), QString("pReFiXfoobarSuFfIx")); //mixed case, use replacement as specified +} + QTEST_MAIN(tst_FileSearch) #include "tst_filesearch.moc" diff --git a/tests/auto/icheckbuild/icheckbuild.pro b/tests/auto/icheckbuild/icheckbuild.pro deleted file mode 100644 index e7ea6b4b96..0000000000 --- a/tests/auto/icheckbuild/icheckbuild.pro +++ /dev/null @@ -1,20 +0,0 @@ -CONFIG += testcase - -include(../../../qtcreator.pri) -include($$IDE_SOURCE_TREE/src/libs/cplusplus/cplusplus.pri) -include($$IDE_SOURCE_TREE/src/plugins/cpptools/cpptools.pri) - -QT += testlib - -DEFINES += ICHECK_BUILD ICHECK_APP_BUILD - -INCLUDEPATH += $$IDE_SOURCE_TREE/src/libs/cplusplus -INCLUDEPATH += $$IDE_SOURCE_TREE/src/plugins -LIBS += $$IDE_SOURCE_TREE/lib/qtcreator/plugins - -HEADERS += ichecklib.h \ - ichecklib_global.h \ - parsemanager.h -SOURCES += ichecklib.cpp \ - parsemanager.cpp \ - tst_icheckbuild.cpp diff --git a/tests/auto/icheckbuild/ichecklib.cpp b/tests/auto/icheckbuild/ichecklib.cpp deleted file mode 100644 index 8e17867938..0000000000 --- a/tests/auto/icheckbuild/ichecklib.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "ichecklib.h" -#include "parsemanager.h" -#include <QCoreApplication> -#include <QString> -#include <QStringList> -#include <iostream> -#include <QDebug> -#include <QDir> -#include <QFile> -#include <QFileInfo> -#include <QProcess> - -QStringList getQTIncludePath() -{ - QStringList ret; - QStringList processevironment = QProcess::systemEnvironment(); - foreach(QString item, processevironment){ - if(item.indexOf("QTDIR=") == 0){ - QString qtpath = item.remove("QTDIR="); - ret << qtpath + "/include"; - ret << qtpath + "/include/ActiveQt"; - ret << qtpath + "/include/phonon"; - ret << qtpath + "/include/phonon_compat"; - ret << qtpath + "/include/Qt"; - ret << qtpath + "/include/Qt3Support"; - ret << qtpath + "/include/QtAssistant"; - ret << qtpath + "/include/QtCore"; - ret << qtpath + "/include/QtDBus"; - ret << qtpath + "/include/QtDeclarative"; - ret << qtpath + "/include/QtDesigner"; - ret << qtpath + "/include/QtGui"; - ret << qtpath + "/include/QtHelp"; - ret << qtpath + "/include/QtMultimedia"; - ret << qtpath + "/include/QtNetwork"; - ret << qtpath + "/include/QtOpenGL"; - ret << qtpath + "/include/QtOpenVG"; - ret << qtpath + "/include/QtScript"; - ret << qtpath + "/include/QtScriptTools"; - ret << qtpath + "/include/QtSql"; - ret << qtpath + "/include/QtSvg"; - ret << qtpath + "/include/QtTest"; - ret << qtpath + "/include/QtUiTools"; - ret << qtpath + "/include/QtWebKit"; - ret << qtpath + "/include/QtXml"; - ret << qtpath + "/include/QtXmlPatterns"; - break; - } - } - return ret; -} - -ICheckLib::ICheckLib() -: pParseManager(0) -{ -} - -void ICheckLib::ParseHeader(const QStringList& includePath, const QStringList& filelist) -{ - if(pParseManager) - delete pParseManager; - pParseManager = 0; - pParseManager = new CPlusPlus::ParseManager(); - pParseManager->setIncludePath(includePath); - pParseManager->parse(filelist); -} - -bool ICheckLib::check(const ICheckLib& ichecklib /*ICheckLib from interface header*/, QString outputfile) -{ - if(pParseManager){ - CPlusPlus::ParseManager* cpparsemanager = ichecklib.pParseManager; - return pParseManager->checkAllMetadatas(cpparsemanager, outputfile); - } - return false; -} - -QStringList ICheckLib::getErrorMsg() -{ - QStringList ret; - if(pParseManager){ - ret.append(pParseManager->getErrorMsg()); - } - else - ret << "no file was parsed."; - return ret; -} diff --git a/tests/auto/icheckbuild/ichecklib_global.h b/tests/auto/icheckbuild/ichecklib_global.h deleted file mode 100644 index 597805bfc2..0000000000 --- a/tests/auto/icheckbuild/ichecklib_global.h +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#ifndef ICHECKLIB_GLOBAL_H -#define ICHECKLIB_GLOBAL_H - -#include <qglobal.h> - - -#ifdef ICHECK_APP_BUILD -# define ICHECKLIBSHARED_EXPORT -#else -# if defined(ICHECKLIB_LIBRARY) -# define ICHECKLIBSHARED_EXPORT Q_DECL_EXPORT -# else -# define ICHECKLIBSHARED_EXPORT Q_DECL_IMPORT -# endif -#endif - -#endif // ICHECKLIB_GLOBAL_H diff --git a/tests/auto/icheckbuild/parsemanager.cpp b/tests/auto/icheckbuild/parsemanager.cpp deleted file mode 100644 index 1b5607ab01..0000000000 --- a/tests/auto/icheckbuild/parsemanager.cpp +++ /dev/null @@ -1,1528 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -#include "parsemanager.h" -#include "cplusplus/CppDocument.h" -#include "Control.h" -#include "Literals.h" -#include "Overview.h" -#include "Scope.h" -#include "TranslationUnit.h" -#include "AST.h" -#include "Symbols.h" -#include "Bind.h" -#include <QDebug> -#include "Name.h" -#include "cpptools/cppmodelmanager.h" -#include <QTextStream> - -using namespace CppTools; -using namespace CppTools::Internal; - - -using namespace CPlusPlus; - -//<------------------------------------------------------- Compare function for the internal structures -/********************************** -Compares function with function -with return type, function name -and their arguments and arguments -types. -**********************************/ -bool FUNCTIONITEM::isEqualTo(FUNCTIONITEM *cpfct, bool ignoreName/* = true*/) -{ - if(ignoreName) - return function->isEqualTo(cpfct->function, true); - return function->isEqualTo(cpfct->function); -} - -/***************************************************************** -Compares two property regarding -of their function definition, -type definition, function arguments -and function types. - -Q_PROPERTY( ConnectionState state READ state NOTIFY stateChanged); -******************************************************************/ -bool PROPERTYITEM::isEqualTo(PROPERTYITEM *cpppt) -{ - if (!ast->type_id || !cpppt->ast->type_id) - return false; - if (type != cpppt->type) - return false; - - if (!ast->property_name || !ast->property_name->name || !ast->property_name->name->identifier()) - return false; - QString thistypename = ast->property_name->name->identifier()->chars(); - - if (!cpppt->ast->property_name || !cpppt->ast->property_name->name || !cpppt->ast->property_name->name->identifier()) - return false; - QString cppttypename = cpppt->ast->property_name->name->identifier()->chars(); - if(thistypename != cppttypename) - return false; - - if ((this->readAst == 0) != (cpppt->readAst == 0)) - return false; - if((this->writeAst == 0) != (cpppt->writeAst == 0)) - return false; - if((this->resetAst == 0) != (cpppt->resetAst == 0)) - return false; - if((this->notifyAst == 0) != (cpppt->notifyAst == 0)) - return false; - //check for read function - if(this->readAst){ - if(!this->readFct || !cpppt->readFct) - return false; - if(!this->readFct->isEqualTo(cpppt->readFct)) - return false; - } - //check for write function - if(this->writeAst){ - if(!this->writeFct || !cpppt->writeFct) - return false; - if(!this->writeFct->isEqualTo(cpppt->writeFct)) - return false; - } - //check for reset function - if(this->resetAst){ - if(!this->resetFct || !cpppt->resetFct) - return false; - if(!this->resetFct->isEqualTo(cpppt->resetFct)) - return false; - } - //check for notify function - if(this->notifyAst){ - if(!this->notifyFct || !cpppt->notifyFct) - return false; - if(!this->notifyFct->isEqualTo(cpppt->notifyFct)) - return false; - } - return true; -} - -/***************************************************************** -Compares two enums regarding -of their values created by the getEnumValueStringList function. -*****************************************************************/ -bool QENUMITEM::isEqualTo(QENUMITEM *cpenum) -{ - if(this->values.count() != cpenum->values.count()) - return false; - foreach(QString str, this->values){ - if(!cpenum->values.contains(str)) - return false; - } - return true; -} - -/***************************************************************** -Compares two flags regarding -of their enum definitions and their -values created by the getEnumValueStringList function. -*****************************************************************/ -bool QFLAGITEM::isEqualTo(QFLAGITEM *cpflag) -{ - if(this->enumvalues.count() != cpflag->enumvalues.count()) - return false; - foreach(QString str, this->enumvalues){ - if(!cpflag->enumvalues.contains(str)) - return false; - } - return true; -} - - - -ParseManager::ParseManager() -: pCppPreprocessor(0) -{ - -} - -ParseManager::~ParseManager() -{ - if(pCppPreprocessor) - delete pCppPreprocessor; - if(::m_resultFile){ - ::m_resultFile->close(); - delete ::m_resultFile; - ::m_resultFile = 0; - } -} - -/************************************** -Function for setting the include -Paths -**************************************/ -void ParseManager::setIncludePath(const QStringList &includePath) -{ - m_includePaths = includePath; -} - -/************************************** -public Function that starts the parsing -all of the files in the sourceFiles -string list. -**************************************/ -void ParseManager::parse(const QStringList &sourceFiles) -{ - m_errormsgs.clear(); - if(pCppPreprocessor){ - delete pCppPreprocessor; - pCppPreprocessor = 0; - } - - if (! sourceFiles.isEmpty()) { - m_strHeaderFile = sourceFiles[0]; - pCppPreprocessor = new CppTools::Internal::CppPreprocessor(QPointer<CPlusPlus::ParseManager>(this)); - pCppPreprocessor->setIncludePaths(m_includePaths); - pCppPreprocessor->setFrameworkPaths(m_frameworkPaths); - parse(pCppPreprocessor, sourceFiles); - } -} - -/********************************************* -private function that prepare the filelist -to parse and starts the parser. -*********************************************/ -void ParseManager::parse(CppTools::Internal::CppPreprocessor *preproc, - const QStringList &files) -{ - if (files.isEmpty()) - return; - - //check if file is C++ header file - QStringList headers; - foreach (const QString &file, files) { - const QFileInfo fileInfo(file); - QString ext = fileInfo.suffix(); - if (ext.toLower() == "h") - headers.append(file); - } - - foreach (const QString &file, files) { - preproc->snapshot.remove(file); - } - preproc->setTodo(headers); - QString conf = QLatin1String("<configuration>"); - - preproc->run(conf); - for (int i = 0; i < headers.size(); ++i) { - QString fileName = headers.at(i); - preproc->run(fileName); - } -} - -//This function creates a class list for each class and its base classes in -//the header file that needs to be checked. -//e.g. -// Cl1 Cl2 -// __|__ __|__ -// | | | | -// Cl11 Cl12 Cl21 Cl22 -// -//==> list[0] = {Cl1, Cl11, Cl12} -// list[1] = {Cl2, Cl21, Cl22} - -QList<CLASSTREE*> ParseManager::CreateClassLists(bool isInterfaceHeader) -{ - QList<CLASSTREE*>ret; - QList<CLASSLISTITEM*> classlist; - QList<CLASSLISTITEM*> allclasslist; - - Trace("Following classes scaned for header file: " + m_strHeaderFile); - //Iteration over all parsed documents - if(getPreProcessor()){ - for (Snapshot::const_iterator it = getPreProcessor()->snapshot.begin() - ; it != getPreProcessor()->snapshot.end(); ++it) - { - Document::Ptr doc = (*it); - if(doc){ - QFileInfo fileinf(doc->fileName()); - QFileInfo fileinf1(m_strHeaderFile); - //Get the Translated unit - Control* ctrl = doc->control(); - TranslationUnit* trlUnit = ctrl->translationUnit(); - AST* pAst = trlUnit->ast(); - TranslationUnitAST *ptrAst = 0; - if(pAst && (ptrAst = pAst->asTranslationUnit())){ - //iteration over all translated declaration in this document - for (DeclarationListAST *pDecllist = ptrAst->declaration_list; pDecllist; pDecllist = pDecllist->next) { - if(pDecllist->value){ - SimpleDeclarationAST *pSimpleDec = pDecllist->value->asSimpleDeclaration(); - if(pSimpleDec){ - //Iteration over class specifier - for (SpecifierListAST *pSimpleDecDecllist = pSimpleDec->decl_specifier_list; pSimpleDecDecllist; pSimpleDecDecllist = pSimpleDecDecllist->next) { - ClassSpecifierAST * pclassspec = pSimpleDecDecllist->value->asClassSpecifier(); - if(pclassspec){ - CLASSLISTITEM* item = new CLASSLISTITEM(); - item->classspec = pclassspec; - item->trlUnit = trlUnit; - allclasslist.push_back(item); - QString classname = item->trlUnit->spell(item->classspec->name->firstToken()); - Trace("- " + classname + " class scaned"); - - //We found a class that is defined in the header file that needs to be checked - if(fileinf.fileName().toLower() == fileinf1.fileName().toLower()){ - CLASSTREE* cltree = new CLASSTREE(); - cltree->highestlevelclass = item; - cltree->classlist.push_back(item); - ret.push_back(cltree); - } - } - } - } - } - } - } - } - } - } - //after we search for the classes we need to search for the baseclasses - Trace("Following classes found in Header file: " + m_strHeaderFile); - foreach(CLASSTREE *cltree, ret){ - QString classname = cltree->highestlevelclass->trlUnit->spell(cltree->highestlevelclass->classspec->name->firstToken()); - Trace("- " + classname + " class found"); - QList<CLASSLISTITEM*> baseclasslist; - getBaseClasses(cltree->highestlevelclass, baseclasslist, allclasslist, 0, isInterfaceHeader); - cltree->classlist.append(baseclasslist); - } - return ret; -} - -/******************************************** -Gets all the baseclass from a class and -add those base classes into the baseclasslist -********************************************/ -void ParseManager::getBaseClasses(const CLASSLISTITEM* pclass - , QList<CLASSLISTITEM*> &baseclasslist - , const QList<CLASSLISTITEM*> &allclasslist - , int level - , bool isInterfaceHeader) -{ - //iteration over the base_clause_list of the current class - QString levelmarker = " "; - for(int i = 0; i < level; i++) - levelmarker += " "; - levelmarker += "|- "; - QList<CLASSLISTITEM*>child; - - for(BaseSpecifierListAST *pBaseSpecList = pclass->classspec->base_clause_list; pBaseSpecList; pBaseSpecList = pBaseSpecList->next) - { - BaseSpecifierAST *pBaseSpec = pBaseSpecList->value; - bool found = false; - foreach(CLASSLISTITEM* pclspec, allclasslist) - { - if(pclspec->classspec->symbol->name() - && pBaseSpec->symbol->name() - && pclspec->classspec->symbol->name()->isEqualTo(pBaseSpec->symbol->name())) - { - child.push_back(pclspec); - baseclasslist.push_back(pclspec); - QString classname = pclspec->trlUnit->spell(pclspec->classspec->name->firstToken()); - Trace(levelmarker + classname + " class found"); - found = true; - break; - } - } - if(!found && pBaseSpec->name){ - QString classname = pclass->trlUnit->spell(pBaseSpec->name->firstToken()); - if(isInterfaceHeader) - Trace(levelmarker + classname + " class not found! Interface classes should not be inherited from Qt Objects!"); - else - Trace(levelmarker + classname + " class not found!"); - } - } - //call the function recursive because all the basclasses can have other base classes - foreach(CLASSLISTITEM* pchclass, child){ - getBaseClasses(pchclass, baseclasslist, allclasslist, ++level, isInterfaceHeader); - } -} - -/************************************************** -This function finds and creates all Elements wich -are significant for MetaDatas. -Those element will be added in the aparameter -lists. -**************************************************/ -void ParseManager::getElements(QList<FUNCTIONITEM*> &functionlist - , QList<PROPERTYITEM*> &propertylist - , QList<QENUMITEM*> &qenumlist - , QList<ENUMITEM*> &enumlist - , QList<QFLAGITEM*> &qflaglist - , QList<QDECLAREFLAGSITEM*> &qdeclareflaglist - , const QList<CLASSLISTITEM*> classitems - , const CLASSLISTITEM* highestlevelclass) -{ - foreach(CLASSLISTITEM* classitem, classitems){ - QString classname = ""; - if(classitem->classspec->name) - classname = classitem->trlUnit->spell(classitem->classspec->name->firstToken()); - for (DeclarationListAST *pmemberlist = classitem->classspec->member_specifier_list; pmemberlist; pmemberlist = pmemberlist->next) { - /********** - Functions - **********/ - if (FunctionDefinitionAST *pfctdef = pmemberlist->value->asFunctionDefinition()){ - FUNCTIONITEM* item = new FUNCTIONITEM; - item->trlUnit = classitem->trlUnit; - item->function = pfctdef->symbol; - item->classAst = classitem->classspec; - item->highestlevelclass = highestlevelclass; - functionlist.push_back(item); - if(isMetaObjFunction(item)) - Trace(" - " + getTraceFuntionString(item, classname) + " found"); - } - - SimpleDeclarationAST *pdecl = pmemberlist->value->asSimpleDeclaration(); - if(pdecl){ - for(List<Symbol*>* decllist = pdecl->symbols; decllist; decllist = decllist->next) - { - Function* pfct = decllist->value->type()->asFunctionType(); - if(pfct){ - FUNCTIONITEM* item = new FUNCTIONITEM(); - item->trlUnit = classitem->trlUnit; - item->function = pfct; - item->classAst = classitem->classspec; - item->highestlevelclass = highestlevelclass; - functionlist.push_back(item); - if(isMetaObjFunction(item)) - Trace(" - " + getTraceFuntionString(item, classname) + " found"); - } - } - /****** - enum - ******/ - for(List<SpecifierAST*>* decllist = pdecl->decl_specifier_list; decllist; decllist = decllist->next) - { - EnumSpecifierAST * penum = decllist->value->asEnumSpecifier(); - if(penum){ - ENUMITEM* item = new ENUMITEM(); - item->ast = penum; - item->highestlevelclass = highestlevelclass; - item->trlUnit = classitem->trlUnit; - enumlist.push_back(item); - } - } - } - else{ - /********** - Q_PROPERTY - **********/ - if(QtPropertyDeclarationAST *ppdecl = pmemberlist->value->asQtPropertyDeclaration()) { - propertylist.push_back(PROPERTYITEM::create(ppdecl, highestlevelclass)); - if (ppdecl->property_name && ppdecl->property_name->name && ppdecl->property_name->name->identifier()) { - Trace(" - Q_PROPERTY: " + QLatin1String(ppdecl->property_name->name->identifier()->chars()) + " found"); - } - } else{ - /********** - Q_ENUM - **********/ - if (QtEnumDeclarationAST *pqenum = pmemberlist->value->asQtEnumDeclaration()) { - for (NameListAST *plist = pqenum->enumerator_list; plist; plist = plist->next) { - QENUMITEM* item = new QENUMITEM; - item->name = plist->value->name->identifier()->chars(); - item->highestlevelclass = highestlevelclass; - qenumlist.push_back(item); - Trace(" - Q_ENUM: " + classname + "::" + item->name + " found"); - } - } - else{ - /********** - Q_FLAGS - **********/ - if (QtFlagsDeclarationAST *pqflags = pmemberlist->value->asQtFlagsDeclaration()){ - for (NameListAST *plist = pqflags->flag_enums_list; plist; plist = plist->next) { - QFLAGITEM* item = new QFLAGITEM; - item->name = plist->value->name; - item->highestlevelclass = highestlevelclass; - qflaglist.push_back(item); - Trace(" - Q_FLAGS: " + classname + "::" + item->name->identifier()->chars() + " found"); - } - } -#if 0 - /*The code for Q_DECLARE_FLAGS was wrong. It's optional, and only does a typedef. - That means, if you do the typedef yourself and not use Q_DECLARE_FLAGS, that *is* valid. - Meaning, if one would want to do a check like the ones in this app, one has to check the defined types in the class scope.*/ - else { - /**************** - Q_DECLARE_FLAGS - ****************/ - QtDeclareFlagsDeclarationAST *pqdeclflags = pmemberlist->value->asQDeclareFlagsDeclarationAST(); - if(pqdeclflags){ - QDECLAREFLAGSITEM* item = new QDECLAREFLAGSITEM(); - item->ast = pqdeclflags; - item->highestlevelclass = highestlevelclass; - item->trlUnit = classitem->trlUnit; - qdeclareflaglist.push_back(item); - } - } -#endif - } - } - } - } - } -} - -/********************************************* -Function that starts the comare between the -parser result and their metadata content. -*********************************************/ -bool ParseManager::checkAllMetadatas(ParseManager* pInterfaceParserManager, QString resultfile) -{ - bool ret = true; - - //Create output file - if(resultfile != "" && ::m_resultFile == 0){ - ::m_resultFile = new QFile(resultfile); - if (!::m_resultFile->open(QFile::WriteOnly | QFile::Truncate)) { - delete ::m_resultFile; - ::m_resultFile = 0; - } - } - - /************************************************ - Get all elements from the interface header file - ************************************************/ - Trace("### Get all elements from the interface header file ###"); - QList<CLASSTREE*> ilookuplist = pInterfaceParserManager->CreateClassLists(true); - QList<QList<FUNCTIONITEM*> > ifunctionslookuplist; - QList<QList<PROPERTYITEM*> > ipropertieslookuplist; - QList<QList<QENUMITEM*> > iqenumlookuplist; - QList<QList<ENUMITEM*> > ienumlookuplist; - QList<QList<QFLAGITEM*> > iqflaglookuplist; - QList<QList<QDECLAREFLAGSITEM*> > iqdeclareflaglookuplist; - Trace("Following MetaData found:"); - foreach(CLASSTREE* iclasstree, ilookuplist){ - QList<FUNCTIONITEM*>functionlist; - QList<PROPERTYITEM*>propertylist; - QList<QENUMITEM*>qenumlist; - QList<ENUMITEM*>enumlist; - QList<QFLAGITEM*> qflaglist; - QList<QDECLAREFLAGSITEM*> qdeclareflag; - getElements(functionlist - , propertylist - , qenumlist - , enumlist - , qflaglist - , qdeclareflag - , iclasstree->classlist - , iclasstree->highestlevelclass); - if(functionlist.size() > 0) - ifunctionslookuplist.append(functionlist); - if(propertylist.size() > 0) - ipropertieslookuplist.append(propertylist); - if(qenumlist.size() > 0) - iqenumlookuplist.append(qenumlist); - if(enumlist.size() > 0) - ienumlookuplist.append(enumlist); - if(qflaglist.size() > 0) - iqflaglookuplist.append(qflaglist); - if(qdeclareflag.size() > 0) - iqdeclareflaglookuplist.append(qdeclareflag); - } - - /************************************************ - Get all elements from the compare header file - ************************************************/ - Trace("\n"); - Trace("### Get all elements from the compare header file ###"); - QList<CLASSTREE*> lookuplist = CreateClassLists(false); - QList<QList<FUNCTIONITEM*> > functionslookuplist; - QList<QList<PROPERTYITEM*> > propertieslookuplist; - QList<QList<QENUMITEM*> > qenumlookuplist; - QList<QList<ENUMITEM*> > enumlookuplist; - QList<QList<QFLAGITEM*> > qflaglookuplist; - QList<QList<QDECLAREFLAGSITEM*> > qdeclareflaglookuplist; - Trace("Following MetaData found:"); - foreach(CLASSTREE* classtree, lookuplist){ - QList<FUNCTIONITEM*>functionlist; - QList<PROPERTYITEM*>propertylist; - QList<QENUMITEM*>qenumlist; - QList<ENUMITEM*>enumlist; - QList<QFLAGITEM*> qflaglist; - QList<QDECLAREFLAGSITEM*> qdeclareflag; - getElements(functionlist - , propertylist - , qenumlist - , enumlist - , qflaglist - , qdeclareflag - , classtree->classlist - , classtree->highestlevelclass); - if(functionlist.size() > 0) - functionslookuplist.append(functionlist); - if(propertylist.size() > 0) - propertieslookuplist.append(propertylist); - if(qenumlist.size() > 0) - qenumlookuplist.append(qenumlist); - if(enumlist.size() > 0) - enumlookuplist.append(enumlist); - if(qflaglist.size() > 0) - qflaglookuplist.append(qflaglist); - if(qdeclareflag.size() > 0) - qdeclareflaglookuplist.append(qdeclareflag); - } - - Trace("\n"); - Trace("### Result: ###"); - /****************************** - Check for function - ******************************/ - Trace("Compare all interface MetaData functions:"); - QList<FUNCTIONITEM*> missingifcts = checkMetadataFunctions(functionslookuplist, ifunctionslookuplist); - if(missingifcts.size() > 0){ - foreach(FUNCTIONITEM* ifct, missingifcts){ - m_errormsgs.append(getErrorMessage(ifct)); - } - ret = false; - Trace("- Failed!"); - } - else{ - Trace("- OK"); - } - - /****************************** - Check for properies - ******************************/ - Trace("Compare all interface MetaData properties:"); - QList<PROPERTYITEM*> missingippts = checkMetadataProperties(propertieslookuplist, functionslookuplist, ipropertieslookuplist, ifunctionslookuplist); - if(missingippts.size() > 0){ - foreach(PROPERTYITEM* ippt, missingippts){ - m_errormsgs.append(getErrorMessage(ippt)); - } - ret = false; - Trace("- Failed!"); - } - else{ - Trace("- OK"); - } - - /****************************** - Check for enums - ******************************/ - Trace("Compare all interface MetaData enums:"); - QList<QENUMITEM*> missingiqenums = checkMetadataEnums(qenumlookuplist, enumlookuplist, iqenumlookuplist, ienumlookuplist); - if(missingiqenums.size() > 0){ - foreach(QENUMITEM* ienum, missingiqenums){ - m_errormsgs.append(getErrorMessage(ienum)); - } - ret = false; - Trace("- Failed!"); - } - else{ - Trace("- OK"); - } - - /****************************** - Check for flags - ******************************/ - Trace("Compare all interface MetaData flags:"); - QList<QFLAGITEM*> missingiqflags = checkMetadataFlags(qflaglookuplist, qdeclareflaglookuplist, enumlookuplist - , iqflaglookuplist, iqdeclareflaglookuplist, ienumlookuplist); - if(missingiqflags.size() > 0){ - foreach(QFLAGITEM* iflags, missingiqflags){ - m_errormsgs.append(getErrorMessage(iflags)); - } - ret = false; - Trace("- Failed!"); - } - else{ - Trace("- OK"); - } - - /****************************** - Add summary - ******************************/ - Trace("\n"); - Trace("### summary ###"); - if(m_errormsgs.size() > 0){ - Trace("- Folowing interface items are missing:"); - foreach(QString msg, m_errormsgs) - Trace(" - " + msg); - } - else - Trace("Interface is full defined."); - - //now delet all Classitems - foreach(CLASSTREE* l, ilookuplist){ - l->classlist.clear(); - } - foreach(CLASSTREE* l, lookuplist){ - l->classlist.clear(); - } - //delete all functionitems - foreach(QList<FUNCTIONITEM*>l, ifunctionslookuplist){ - l.clear(); - } - foreach(QList<FUNCTIONITEM*>l, functionslookuplist){ - l.clear(); - } - //delete all properties - foreach(QList<PROPERTYITEM*>l, ipropertieslookuplist){ - l.clear(); - } - foreach(QList<PROPERTYITEM*>l, propertieslookuplist){ - l.clear(); - } - //delete all qenums - foreach(QList<QENUMITEM*>l, iqenumlookuplist){ - l.clear(); - } - foreach(QList<QENUMITEM*>l, iqenumlookuplist){ - l.clear(); - } - //delete all enums - foreach(QList<ENUMITEM*>l, ienumlookuplist){ - l.clear(); - } - foreach(QList<ENUMITEM*>l, enumlookuplist){ - l.clear(); - } - //delete all qflags - foreach(QList<QFLAGITEM*>l, iqflaglookuplist){ - l.clear(); - } - foreach(QList<QFLAGITEM*>l, qflaglookuplist){ - l.clear(); - } - //delete all qdeclareflags - foreach(QList<QDECLAREFLAGSITEM*>l, iqdeclareflaglookuplist){ - l.clear(); - } - foreach(QList<QDECLAREFLAGSITEM*>l, qdeclareflaglookuplist){ - l.clear(); - } - - return ret; -} - -//<------------------------------------------------------- Start of MetaData functions -/*********************************** -Function that checks all functions -which will occur in the MetaData -***********************************/ -QList<FUNCTIONITEM*> ParseManager::checkMetadataFunctions(const QList<QList<FUNCTIONITEM*> > &classfctlist, const QList<QList<FUNCTIONITEM*> > &iclassfctlist) -{ - QList<FUNCTIONITEM*> missingifcts; - //Compare each function from interface with function from header (incl. baseclass functions) - QList<FUNCTIONITEM*> ifcts; - foreach(QList<FUNCTIONITEM*>ifunctionlist, iclassfctlist){ - ifcts.clear(); - //check if one header class contains all function from one interface header class - if(classfctlist.count() > 0){ - foreach(QList<FUNCTIONITEM*>functionlist, classfctlist){ - QList<FUNCTIONITEM*> tmpl = containsAllMetadataFunction(functionlist, ifunctionlist); - if(tmpl.size() == 0){ - ifcts.clear(); - break; - } - else - ifcts.append(tmpl); - } - } - else { - foreach(FUNCTIONITEM *pfct, ifunctionlist) - pfct->classWichIsNotFound << "<all classes>"; - ifcts.append(ifunctionlist); - } - missingifcts.append(ifcts); - } - return missingifcts; -} - -/********************************************* -Helper function to check if a function will -occure in the MetaData. -*********************************************/ -bool ParseManager::isMetaObjFunction(FUNCTIONITEM* fct) -{ - if(fct->function->isInvokable() - || fct->function->isSignal() - || fct->function->isSlot()) - return true; - return false; -} - -/**************************************************** -Check if all function from iclassfctlist are defined -in the classfctlist as well. -It will return all the function they are missing. -****************************************************/ -QList<FUNCTIONITEM*> ParseManager::containsAllMetadataFunction(const QList<FUNCTIONITEM*> &classfctlist, const QList<FUNCTIONITEM*> &iclassfctlist) -{ - QList<FUNCTIONITEM*> ret; - foreach(FUNCTIONITEM* ifct, iclassfctlist){ - if(isMetaObjFunction(ifct)){ - bool found = false; - QStringList missingimplinclasses; - ClassSpecifierAST* clspec = 0; - QString classname = ""; - foreach(FUNCTIONITEM* fct, classfctlist){ - if(clspec != fct->highestlevelclass->classspec){ - clspec = fct->highestlevelclass->classspec; - //get the classname - unsigned int firsttoken = clspec->name->firstToken(); - classname += fct->trlUnit->spell(firsttoken); - if(missingimplinclasses.indexOf(classname) < 0) - missingimplinclasses.push_back(classname); - } - if(fct->isEqualTo(ifct, false)){ - found = true; - missingimplinclasses.clear(); - Trace("- " + getTraceFuntionString(fct, classname) + " implemented"); - break; - } - } - if(!found){ - ifct->classWichIsNotFound.append(missingimplinclasses); - ret.push_back(ifct); - QString classname = ifct->trlUnit->spell(ifct->highestlevelclass->classspec->name->firstToken()); - Trace("- " + getTraceFuntionString(ifct, classname) + " not implemented!"); - } - } - } - return ret; -} - -/************************************ -Function that gives back an error -string for a MetaData function -mismatch. -************************************/ -QStringList ParseManager::getErrorMessage(FUNCTIONITEM* fct) -{ - QStringList ret; - QString fctstring = ""; - QString fcttype = ""; - - foreach(QString classname, fct->classWichIsNotFound){ - QString tmp; - QTextStream out(&tmp); - - fcttype = ""; - fctstring = classname; - fctstring += "::"; - - unsigned int token = fct->function->sourceLocation() - 1; - while(fct->trlUnit->tokenAt(token).isNot(T_EOF_SYMBOL)){ - fctstring += fct->trlUnit->tokenAt(token).spell(); - if(*fct->trlUnit->tokenAt(token).spell() == ')') - break; - fctstring += " "; - token++; - } - - Function* pfct = fct->function; - if(pfct){ - fcttype = "type: "; - //Check for private, protected and public - if(pfct->isPublic()) - fcttype = "public "; - if(pfct->isProtected()) - fcttype = "protected "; - if(pfct->isPrivate()) - fcttype = "private "; - - if(pfct->isVirtual()) - fcttype += "virtual "; - if(pfct->isPureVirtual()) - fcttype += "pure virtual "; - - if(pfct->isSignal()) - fcttype += "Signal "; - if(pfct->isSlot()) - fcttype += "Slot "; - if(pfct->isNormal()) - fcttype += "Normal "; - if(pfct->isInvokable()) - fcttype += "Invokable "; - } - out << fcttype << fctstring; - ret << tmp; - } - return ret; -} -//---> - -//<------------------------------------------------------- Start of Q_PROPERTY checks -/*********************************** -Function that checks all Property -which will occur in the MetaData -***********************************/ -QList<PROPERTYITEM*> ParseManager::checkMetadataProperties(const QList<QList<PROPERTYITEM*> > &classproplist - , const QList<QList<FUNCTIONITEM*> > &classfctlist - , const QList<QList<PROPERTYITEM*> > &iclassproplist - , const QList<QList<FUNCTIONITEM*> > &iclassfctlist) -{ - QList<PROPERTYITEM*> missingiprops; - //assign the property functions - foreach(QList<PROPERTYITEM*>proplist, classproplist){ - foreach(PROPERTYITEM* prop, proplist){ - assignPropertyFunctions(prop, classfctlist); - } - } - - foreach(QList<PROPERTYITEM*>proplist, iclassproplist){ - foreach(PROPERTYITEM* prop, proplist){ - assignPropertyFunctions(prop, iclassfctlist); - } - } - - //Compare each qproperty from interface with qproperty from header (incl. baseclass functions) - QList<PROPERTYITEM*> ippts; - foreach(QList<PROPERTYITEM*>ipropertylist, iclassproplist){ - ippts.clear(); - //check if one header class contains all function from one interface header class - if(classproplist.count() > 0){ - foreach(QList<PROPERTYITEM*>propertylist, classproplist){ - QList<PROPERTYITEM*> tmpl = containsAllPropertyFunction(propertylist, ipropertylist); - if(tmpl.size() == 0) - ippts.clear(); - else - ippts.append(tmpl); - } - } - else { - foreach(PROPERTYITEM *pprop, ipropertylist){ - pprop->classWichIsNotFound << "<all classes>"; - QString name = pprop->ast->property_name->name->identifier()->chars(); - Trace("- Property: <all classes>::" + name + " not found!"); - } - ippts.append(ipropertylist); - } - missingiprops.append(ippts); - } - return missingiprops; -} - -static QString findName(ExpressionAST *ast) -{ - // The "old" icheck code assumed that functions were only a single identifier, so I'll assume the same: - if (NameAST *nameAST = ast->asName()) - return nameAST->name->identifier()->chars(); - else - return QString(); -} - -/************************************** -Function that resolves the dependensies -between Q_PROPERTY -and thier READ, WRITE, NOTIFY and RESET -functions. -***************************************/ -void ParseManager::assignPropertyFunctions(PROPERTYITEM* prop, const QList<QList<FUNCTIONITEM*> > &fctlookuplist) -{ - //get the name of the needed functions - QString readfctname; - QString writefctname; - QString resetfctname; - QString notifyfctname; - - int needtofind = 0; - if(prop->readAst){ - readfctname = findName(prop->readAst); - needtofind++; - } - if(prop->writeAst){ - writefctname = findName(prop->writeAst); - needtofind++; - } - if(prop->resetAst){ - resetfctname = findName(prop->resetAst); - needtofind++; - } - if(prop->notifyAst){ - notifyfctname = findName(prop->notifyAst); - needtofind++; - } - //Now iterate over all function to find all functions wich are defined in the Q_PROPERTY macro - if(needtofind > 0){ - prop->foundalldefinedfct = false; - foreach(QList<FUNCTIONITEM*> fctlist, fctlookuplist){ - foreach(FUNCTIONITEM* pfct, fctlist){ - QString fctname = pfct->trlUnit->spell(pfct->function->sourceLocation()); - //check the function type against the property type - FullySpecifiedType retTy = pfct->function->returnType(); - - if (!fctname.isEmpty() && retTy.isValid()) { - if(prop->readAst && fctname == readfctname){ - if (prop->type != retTy) - continue; - prop->readFct = pfct; - needtofind--; - } - if(prop->writeAst && fctname == writefctname){ - prop->writeFct = pfct; - needtofind--; - } - if(prop->resetAst && fctname == resetfctname){ - prop->resetFct = pfct; - needtofind--; - } - if(prop->notifyAst && fctname == notifyfctname){ - prop->notifyFct = pfct; - needtofind--; - } - if(needtofind <= 0){ - //a flag that indicates if a function was missing - prop->foundalldefinedfct = true; - return; - } - } - } - } - } -} - -/************************************** -Function that checks if all functions -dependencies in Q_PROPERTY have the -same arguments and retunr value. -***************************************/ -QList<PROPERTYITEM*> ParseManager::containsAllPropertyFunction(const QList<PROPERTYITEM*> &classproplist, const QList<PROPERTYITEM*> &iclassproplist) -{ - QList<PROPERTYITEM*> ret; - foreach(PROPERTYITEM* ipropt, iclassproplist){ - if(ipropt->foundalldefinedfct){ - bool found = false; - QStringList missingimplinclasses; - ClassSpecifierAST* clspec = 0; - QString classname = ""; - foreach(PROPERTYITEM* propt, classproplist){ - if(clspec != propt->highestlevelclass->classspec){ - clspec = propt->highestlevelclass->classspec; - //get the classname - unsigned int firsttoken = clspec->name->firstToken(); - classname += propt->trlUnit->spell(firsttoken); - if(missingimplinclasses.indexOf(classname) < 0) - missingimplinclasses.push_back(classname); - } - if(propt->isEqualTo(ipropt)){ - found = true; - missingimplinclasses.clear(); - Trace("- Property: " + classname + "::" + propt->ast->property_name->name->identifier()->chars() + " found"); - break; - } - } - if(!found){ - ipropt->classWichIsNotFound.append(missingimplinclasses); - ret.push_back(ipropt); - QString classname = ipropt->trlUnit->spell(ipropt->highestlevelclass->classspec->name->firstToken()); - Trace("- Property: " + classname + "::" + ipropt->ast->property_name->name->identifier()->chars() + " not found!"); - } - } - else{ - QString classname = ipropt->trlUnit->spell(ipropt->highestlevelclass->classspec->name->firstToken()); - Overview oo; - QString proptype = oo(ipropt->type); - Trace("- Property: " + classname + "::" + proptype + " functions are missing!"); - ret.push_back(ipropt); - } - } - return ret; -} - -/************************************ -Function that gives back an error -string for a Q_PROPERTY mismatch. -************************************/ -QStringList ParseManager::getErrorMessage(PROPERTYITEM* ppt) -{ - QStringList ret; - QString pptstring = ""; - - if(!ppt->foundalldefinedfct) - { - QString tmp; - QTextStream out(&tmp); - - unsigned int firsttoken = ppt->highestlevelclass->classspec->name->firstToken(); - unsigned int lasttoken = ppt->highestlevelclass->classspec->name->lastToken(); - for(unsigned int i = firsttoken; i < lasttoken; i++){ - out << ppt->trlUnit->spell(i); - } - out << "::"; - firsttoken = ppt->ast->firstToken(); - lasttoken = ppt->ast->lastToken(); - for(unsigned int i = firsttoken; i <= lasttoken; i++){ - out << ppt->trlUnit->spell(i) << " "; - } - out << endl << " -"; - if(ppt->readAst && !ppt->readFct) - out << "READ "; - if(ppt->writeAst && !ppt->writeFct) - out << "WRITE "; - if(ppt->resetAst && !ppt->resetFct) - out << "RESET."; - if(ppt->notifyAst && !ppt->notifyFct) - out << "NOTIFY "; - out << "functions missing." << endl; - ret << tmp; - } - for(int i = 0; i < ppt->classWichIsNotFound.size(); i++){ - QString tmp; - QTextStream out(&tmp); - - pptstring = ppt->classWichIsNotFound[i]; - pptstring += "::"; - - unsigned int firsttoken = ppt->ast->firstToken(); - unsigned int lasttoken = ppt->ast->lastToken(); - for(unsigned int i = firsttoken; i <= lasttoken; i++){ - pptstring += ppt->trlUnit->spell(i); - pptstring += " "; - } - - out << pptstring; - ret << tmp; - } - return ret; -} -//---> - - -//<------------------------------------------------------- Start of Q_ENUMS checks -/*********************************** -Function that checks all enums -which will occur in the MetaData -***********************************/ -QList<QENUMITEM*> ParseManager::checkMetadataEnums(const QList<QList<QENUMITEM*> > &classqenumlist - , const QList<QList<ENUMITEM*> > &classenumlist - , const QList<QList<QENUMITEM*> > &iclassqenumlist - , const QList<QList<ENUMITEM*> > &iclassenumlist) -{ - QList<QENUMITEM*> missingiqenums; - //assign the property functions - foreach(QList<QENUMITEM*>qenumlist, classqenumlist){ - foreach(QENUMITEM* qenum, qenumlist){ - assignEnumValues(qenum, classenumlist); - } - } - foreach(QList<QENUMITEM*>qenumlist, iclassqenumlist){ - foreach(QENUMITEM* qenum, qenumlist){ - assignEnumValues(qenum, iclassenumlist); - } - } - - //Compare each qenum from interface with qenum from header (incl. baseclass functions) - QList<QENUMITEM*> iqenums; - foreach(QList<QENUMITEM*>iqenumlist, iclassqenumlist){ - iqenums.clear(); - //check if one header class contains all function from one interface header class - if(classqenumlist.count() > 0){ - foreach(QList<QENUMITEM*>qenumlist, classqenumlist){ - QList<QENUMITEM*> tmpl = containsAllEnums(qenumlist, iqenumlist); - if(tmpl.size() == 0) - iqenums.clear(); - else - iqenums.append(tmpl); - - } - } - else { - foreach(QENUMITEM *qenum, iqenumlist){ - qenum->classWichIsNotFound << "<all classes>"; - Trace("- Enum: <all classes>::" + qenum->name + " not found!"); - } - iqenums.append(iqenumlist); - } - missingiqenums.append(iqenums); - } - - return missingiqenums; -} - -/********************************************* -Helper function which creates a string out of -an enumerator including its values. -*********************************************/ -QStringList ParseManager::getEnumValueStringList(ENUMITEM *penum, QString mappedenumname/* = ""*/) -{ - QStringList ret; - EnumSpecifierAST *penumsec = penum->ast; - QString enumname = penum->trlUnit->spell(penumsec->name->firstToken()); - int enumvalue = 0; - //now iterrate over all enumitems and create a string like following: - //EnumName.EnumItemName.Value - //ConnectionState.disconnected.0 - for (EnumeratorListAST *plist = penum->ast->enumerator_list; plist; plist = plist->next) { - QString value = enumname; - if(mappedenumname.size() > 0) - value = mappedenumname; - value += "."; - value += penum->trlUnit->spell(plist->value->identifier_token); - value += "."; - if(plist->value->equal_token > 0 && plist->value->expression){ - QString v = penum->trlUnit->spell(plist->value->expression->firstToken()); - bool ch; - int newval = enumvalue; - if(v.indexOf("0x") >= 0) - newval = v.toInt(&ch, 16); - else - newval = v.toInt(&ch, 10); - if(ch) - enumvalue = newval; - } - value += QString::number(enumvalue); - enumvalue++; - // now add this enumitem string in the VALUE list - ret << value; - } - return ret; -} - -/************************************** -Function that resolves the dependensies -between Q_ENUMS and enums. -***************************************/ -void ParseManager::assignEnumValues(QENUMITEM* qenum, const QList<QList<ENUMITEM*> > &enumlookuplist) -{ - //iterate over all enums and find the one with the same name like enumname - bool found = false; - foreach (QList<ENUMITEM*> penumlist, enumlookuplist) { - foreach(ENUMITEM *penum, penumlist){ - EnumSpecifierAST *penumsec = penum->ast; - QString enumname1 = penum->trlUnit->spell(penumsec->name->firstToken()); - if(qenum->name == enumname1){ - qenum->values << getEnumValueStringList(penum); - found = true; - break; - } - } - if(!found) - qenum->foundallenums = false; - } -} - -/*********************************** -Function that checkt if the Q_ENUMS -are completed defined and if the -Enum values are the same. -***********************************/ -QList<QENUMITEM*> ParseManager::containsAllEnums(const QList<QENUMITEM*> &classqenumlist, const QList<QENUMITEM*> &iclassqenumlist) -{ - Overview oo; - - QList<QENUMITEM*> ret; - foreach(QENUMITEM* iqenum, iclassqenumlist){ - bool found = false; - QStringList missingimplinclasses; - ClassSpecifierAST* clspec = 0; - QString classname = ""; - foreach(QENUMITEM* qenum, classqenumlist){ - if(clspec != qenum->highestlevelclass->classspec){ - clspec = qenum->highestlevelclass->classspec; - //get the classname - classname += oo(clspec->symbol); - if(missingimplinclasses.indexOf(classname) < 0) - missingimplinclasses.push_back(classname); - } - if(qenum->isEqualTo(iqenum)){ - found = true; - missingimplinclasses.clear(); - Trace("- Enum: " + classname + "::" + qenum->name + " found"); - break; - } - } - if(!found){ - iqenum->classWichIsNotFound.append(missingimplinclasses); - ret.push_back(iqenum); - QString classname = oo(iqenum->highestlevelclass->classspec->symbol); - Trace("- Enum: " + classname + "::" + iqenum->name + " not found!"); - } - } - return ret; -} - -/************************************ -Function that gives back an error -string for a Q_ENUMS mismatch. -************************************/ -QStringList ParseManager::getErrorMessage(QENUMITEM* qenum) -{ - Overview oo; - QStringList ret; - - if(!qenum->foundallenums) - { - QString tmp; - QTextStream out(&tmp); - - out << oo(qenum->highestlevelclass->classspec->symbol); - out << "::Q_ENUMS " << qenum->name << " enum missing."; - ret << tmp; - } - - for (int i = 0; i < qenum->classWichIsNotFound.size(); i++){ - QString tmp; - QTextStream out(&tmp); - - out << qenum->classWichIsNotFound[i] << "::Q_ENUMS " - << qenum->name; - ret << tmp; - } - return ret; -} -//---> - -//<------------------------------------------------------- Start of Q_FLAGS checks -/*********************************** -Function that checks all flags -which will occur in the MetaData -***********************************/ -QList<QFLAGITEM*> ParseManager::checkMetadataFlags(const QList<QList<QFLAGITEM*> > &classqflaglist - , const QList<QList<QDECLAREFLAGSITEM*> > &classqdeclareflaglist - , const QList<QList<ENUMITEM*> > &classenumlist - , const QList<QList<QFLAGITEM*> > &iclassqflaglist - , const QList<QList<QDECLAREFLAGSITEM*> > &iclassqdeclareflaglist - , const QList<QList<ENUMITEM*> > &iclassenumlist) -{ - QList<QFLAGITEM*> missingqflags; - //assign the enums to the flags - foreach(QList<QFLAGITEM*>qflaglist, classqflaglist){ - foreach(QFLAGITEM* qflag, qflaglist){ - assignFlagValues(qflag, classqdeclareflaglist, classenumlist); - } - } - foreach(QList<QFLAGITEM*>qflaglist, iclassqflaglist){ - foreach(QFLAGITEM* qflag, qflaglist){ - assignFlagValues(qflag, iclassqdeclareflaglist, iclassenumlist); - } - } - - //Compare each qenum from interface with qenum from header (incl. baseclass functions) - QList<QFLAGITEM*> iqflags; - foreach(QList<QFLAGITEM*>iqflaglist, iclassqflaglist){ - iqflags.clear(); - //check if one header class contains all function from one interface header class - if(classqflaglist.count() >0){ - foreach(QList<QFLAGITEM*>qflaglist, classqflaglist){ - QList<QFLAGITEM*> tmpl = containsAllFlags(qflaglist, iqflaglist); - if(tmpl.size() == 0) - iqflags.clear(); - else - iqflags.append(tmpl); - - } - } - else { - foreach(QFLAGITEM *pflag, iqflaglist){ - pflag->classWichIsNotFound << "<all classes>"; - QString name= pflag->name->identifier()->chars(); - Trace("- Flag: <all classes>::" + name + " not found!"); - } - iqflags.append(iqflaglist); - } - missingqflags.append(iqflags); - } - return missingqflags; -} - -/************************************** -Function that resolves the dependensies -between Q_FLAG, Q_DECLARE_FLAGS -and enums. -***************************************/ -void ParseManager::assignFlagValues(QFLAGITEM* qflags, const QList<QList<QDECLAREFLAGSITEM*> > &qdeclareflagslookuplist, const QList<QList<ENUMITEM*> > &enumlookuplist) -{ - QString enumname; - - //try to find if there is a deflare flag macro with the same name as in qflagname - Scope *classMembers = qflags->highestlevelclass->classspec->symbol; - Symbol *s = classMembers->find(qflags->name); - if (s->isTypedef()) { - FullySpecifiedType ty = s->type(); - if (Enum *e = ty->asEnumType()) { - enumname = e->name()->identifier()->chars(); - } - } - - //now we have the right enum name now we need to find the enum - bool found = false; - foreach(QList<ENUMITEM*> enumitemlist, enumlookuplist){ - foreach(ENUMITEM* enumitem, enumitemlist){ - EnumSpecifierAST *penumspec = enumitem->ast; - QString enumspecname = enumitem->trlUnit->spell(penumspec->name->firstToken()); - if(enumspecname == enumname){ - qflags->enumvalues << getEnumValueStringList(enumitem, qflags->name->identifier()->chars()); - found = true; - break; - } - } - if(found) - break; - } - if(!found) - qflags->foundallenums = false; -} - -/***************************************** -Function that compares if all enums -and flags assigned by using the Q_FLAGS -are complete defined. -*****************************************/ -QList<QFLAGITEM*> ParseManager::containsAllFlags(const QList<QFLAGITEM*> &classqflaglist, const QList<QFLAGITEM*> &iclassqflaglist) -{ - QList<QFLAGITEM*> ret; - foreach(QFLAGITEM* iqflags, iclassqflaglist){ - if(iqflags->foundallenums){ - bool found = false; - QStringList missingimplinclasses; - ClassSpecifierAST* clspec = 0; - QString classname = ""; - foreach(QFLAGITEM* qflags, classqflaglist){ - if(clspec != qflags->highestlevelclass->classspec){ - clspec = qflags->highestlevelclass->classspec; - //get the classname - classname += clspec->symbol->name()->identifier()->chars(); - if(missingimplinclasses.indexOf(classname) < 0) - missingimplinclasses.push_back(classname); - } - if(qflags->isEqualTo(iqflags)){ - found = true; - missingimplinclasses.clear(); - Trace("- Flag: " + classname + "::" + qflags->name->identifier()->chars() + " found"); - break; - } - } - if(!found){ - iqflags->classWichIsNotFound.append(missingimplinclasses); - ret.push_back(iqflags); - QString classname = iqflags->highestlevelclass->classspec->symbol->name()->identifier()->chars(); - Trace("- Flag: " + classname + "::" + iqflags->name->identifier()->chars() + " not found!"); - } - } - else - ret.push_back(iqflags); - } - return ret; -} - -/************************************ -Function that gives back an error -string for a Q_FLAGS mismatch. -************************************/ -QStringList ParseManager::getErrorMessage(QFLAGITEM* pfg) -{ - Overview oo; - QStringList ret; - - if(!pfg->foundallenums) - { - QString tmp; - QTextStream out(&tmp); - - out << oo(pfg->highestlevelclass->classspec->symbol->name()); - out << "::Q_FLAGS "<<pfg->name->identifier()->chars()<< ": enum missing."; - ret << tmp; - } - for(int i = 0; i < pfg->classWichIsNotFound.size(); i++){ - QString tmp; - QTextStream out(&tmp); - - out << pfg->classWichIsNotFound[i] << "::Q_FLAGS " << oo(pfg->name); - ret << tmp; - } - return ret; -} - -inline QString ParseManager::getTraceFuntionString(const FUNCTIONITEM *fctitem, const QString& classname) -{ - QString ret; - - if(fctitem->function->isPublic()) - ret = "public "; - if(fctitem->function->isProtected()) - ret = "protected "; - if(fctitem->function->isPrivate()) - ret = "private "; - - if(fctitem->function->isVirtual()) - ret += "virtual "; - if(fctitem->function->isPureVirtual()) - ret += "pure virtual "; - - if(fctitem->function->isSignal()) - ret += "Signal "; - if(fctitem->function->isSlot()) - ret += "Slot "; - if(fctitem->function->isNormal()) - ret += "Normal "; - if(fctitem->function->isInvokable()) - ret += "Invokable "; - - ret += classname; - ret += "::"; - ret += fctitem->trlUnit->spell(fctitem->function->sourceLocation()); - return ret; -} - -void ParseManager::Trace(QString value) -{ - if(::m_resultFile){ - QTextStream out(::m_resultFile); - if(value == "\n") - out << endl; - else - out << value << endl; - } -} - -PROPERTYITEM *PROPERTYITEM::create(QtPropertyDeclarationAST *ast, const CLASSLISTITEM *clazz) -{ - PROPERTYITEM *item = new PROPERTYITEM; - item->ast = ast; - item->highestlevelclass = clazz; - item->trlUnit = clazz->trlUnit; - - if (ast->type_id) { - Bind bind(item->trlUnit); - item->type = bind(ast->type_id, clazz->classspec->symbol); - } - - for (QtPropertyDeclarationItemListAST *it = ast->property_declaration_items; - it; it = it->next) { - if (!it->value->item_name_token) - continue; - const char *name = item->trlUnit->spell(it->value->item_name_token); - if (!qstrcmp(name, "READ")) - item->readAst = it->value->expression; - else if (!qstrcmp(name, "WRITE")) - item->writeAst = it->value->expression; - else if (!qstrcmp(name, "RESET")) - item->resetAst = it->value->expression; - else if (!qstrcmp(name, "NOTIFY")) - item->notifyAst = it->value->expression; - } - - return item; -} - -//---> diff --git a/tests/auto/icheckbuild/parsemanager.h b/tests/auto/icheckbuild/parsemanager.h deleted file mode 100644 index 7dd5b0b0b8..0000000000 --- a/tests/auto/icheckbuild/parsemanager.h +++ /dev/null @@ -1,304 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -****************************************************************************/ - -/* -** Description: -** -** The ParseManager parses and compares to different header files -** of its metadata. This can be used for checking if an Interface -** is implemented complete. -** -** How to use it: -** -** //Parse the interface header -** ParseManager* iParseManager = new ParseManager(); -** iParseManager->setIncludePath(iIncludepathlist); -** iParseManager->parse(iFilelist); -** -** //Parse the header that needs to be compared against the interface header -** ParseManager* chParseManager = new ParseManager(); -** chIncludepathlist << getQTIncludePath(); -* chParseManager->setIncludePath(chIncludepathlist); -** chParseManager->parse(chFilelist); -** -** if(!chParseManager->checkAllMetadatas(iParseManager)){ -** cout << "Following interface items are missing:" << endl; -** QStringList errorlist = chParseManager->getErrorMsg(); -** foreach(QString msg, errorlist){ -** cout << (const char *)msg.toLatin1() << endl; -** } -** return -1; -** } -** else -** cout << "Interface is full defined."; -*/ - -#ifndef PARSEMANAGER_H -#define PARSEMANAGER_H - -#include "cplusplus/CppDocument.h" -#include "ASTfwd.h" -#include "FullySpecifiedType.h" - -#include <QObject> -#include <QList> -#include <QFuture> -#include <QStringList> -#include <QFile> - -namespace CppTools{ - namespace Internal{ - class CppPreprocessor; - } -} - -namespace CPlusPlus { - class CLASSLISTITEM - { - public: - CPlusPlus::TranslationUnit* trlUnit; - ClassSpecifierAST* classspec; - }; - class CLASSTREE - { - public: - CLASSLISTITEM* highestlevelclass; - QList<CLASSLISTITEM*> classlist; - }; - class FUNCTIONITEM - { - public: - const CLASSLISTITEM* highestlevelclass; - CPlusPlus::TranslationUnit* trlUnit; - ClassSpecifierAST* classAst; - QStringList classWichIsNotFound; - CPlusPlus::Function* function; - - bool isEqualTo(FUNCTIONITEM* cpfct, bool ignoreName = true); - - FUNCTIONITEM() - { - highestlevelclass = 0; - trlUnit = 0; - classAst = 0; - function = 0; - } - }; - class PROPERTYITEM - { - public: - const CLASSLISTITEM* highestlevelclass; - QStringList classWichIsNotFound; - QtPropertyDeclarationAST *ast; - CPlusPlus::TranslationUnit* trlUnit; - FullySpecifiedType type; - ExpressionAST *readAst; - FUNCTIONITEM *readFct; - ExpressionAST *writeAst; - FUNCTIONITEM *writeFct; - ExpressionAST *resetAst; - FUNCTIONITEM *resetFct; - ExpressionAST *notifyAst; - FUNCTIONITEM *notifyFct; - bool foundalldefinedfct; - - bool isEqualTo(PROPERTYITEM* cpppt); - PROPERTYITEM() - { - highestlevelclass = 0; - ast = 0; - trlUnit = 0; - readAst = 0; - readFct = 0; - writeAst = 0; - writeFct = 0; - resetAst = 0; - resetFct = 0; - notifyAst = 0; - notifyFct = 0; - foundalldefinedfct = false; - } - - static PROPERTYITEM *create(QtPropertyDeclarationAST *ast, const CLASSLISTITEM *clazz); - }; - - class QENUMITEM - { - public: - const CLASSLISTITEM* highestlevelclass; - QStringList classWichIsNotFound; - QString name; - //an item in this list will be shown like: - //EnumName.EnumItemName.Value - //ConnectionState.disconnected.0 - QStringList values; - bool foundallenums; - - bool isEqualTo(QENUMITEM *cpenum); - QENUMITEM() - { - highestlevelclass = 0; - values.clear(); - foundallenums = true; - } - }; - - class ENUMITEM - { - public: - const CLASSLISTITEM* highestlevelclass; - CPlusPlus::TranslationUnit* trlUnit; - QStringList classWichIsNotFound; - EnumSpecifierAST* ast; - - ENUMITEM() - { - highestlevelclass = 0; - trlUnit = 0; - ast = 0; - } - }; - - class QFLAGITEM - { - public: - const CLASSLISTITEM* highestlevelclass; - const Name *name; - QStringList classWichIsNotFound; - QStringList enumvalues; - bool foundallenums; - - bool isEqualTo(QFLAGITEM *cpflag); - QFLAGITEM() - { - highestlevelclass = 0; - enumvalues.clear(); - foundallenums = true; - } - }; - - class QDECLAREFLAGSITEM - { - public: - const CLASSLISTITEM* highestlevelclass; - CPlusPlus::TranslationUnit* trlUnit; - QStringList classWichIsNotFound; - QtFlagsDeclarationAST* ast; - - QDECLAREFLAGSITEM() - { - highestlevelclass = 0; - trlUnit = 0; - ast = 0; - } - }; - - static QFile* m_resultFile = 0; - class ParseManager : public QObject - { - Q_OBJECT - public: - ParseManager(); - virtual ~ParseManager(); - void setIncludePath(const QStringList &includePath); - void parse(const QStringList &sourceFiles); - bool checkAllMetadatas(ParseManager* pInterfaceParserManager, QString resultfile); - CppTools::Internal::CppPreprocessor *getPreProcessor() { return pCppPreprocessor; } - QList<CLASSTREE*> CreateClassLists(bool isInterfaceHeader); - QStringList getErrorMsg() { return m_errormsgs; } - - private: - void parse(CppTools::Internal::CppPreprocessor *preproc, const QStringList &files); - void Trace(QString value); - inline QString getTraceFuntionString(const FUNCTIONITEM* fctitem, const QString& classname); - void getBaseClasses(const CLASSLISTITEM* pclass - , QList<CLASSLISTITEM*> &baseclasslist - , const QList<CLASSLISTITEM*> &allclasslist - , int level - , bool isInterfaceHeader); - void getElements(QList<FUNCTIONITEM*> &functionlist - , QList<PROPERTYITEM*> &propertylist - , QList<QENUMITEM*> &qenumlist - , QList<ENUMITEM*> &enumlist - , QList<QFLAGITEM*> &qflaglist - , QList<QDECLAREFLAGSITEM*> &qdeclareflaglist - , const QList<CLASSLISTITEM*> classitems - , const CLASSLISTITEM* highestlevelclass); - - //<--- for Metadata functions checks - QList<FUNCTIONITEM*> checkMetadataFunctions(const QList<QList<FUNCTIONITEM*> > &classfctlist, const QList<QList<FUNCTIONITEM*> > &iclassfctlist); - bool isMetaObjFunction(FUNCTIONITEM* fct); - QList<FUNCTIONITEM*> containsAllMetadataFunction(const QList<FUNCTIONITEM*> &classfctlist, const QList<FUNCTIONITEM*> &iclassfctlist); - QStringList getErrorMessage(FUNCTIONITEM* fct); - //---> - - //<--- for Q_PROPERTY functions checks - QList<PROPERTYITEM*> checkMetadataProperties(const QList<QList<PROPERTYITEM*> > &classproplist - , const QList<QList<FUNCTIONITEM*> > &classfctlist - , const QList<QList<PROPERTYITEM*> > &iclassproplist - , const QList<QList<FUNCTIONITEM*> > &iclassfctlist); - void assignPropertyFunctions(PROPERTYITEM* prop, const QList<QList<FUNCTIONITEM*> > &fctlookuplist); - QList<PROPERTYITEM*> containsAllPropertyFunction(const QList<PROPERTYITEM*> &classproplist, const QList<PROPERTYITEM*> &iclassproplist); - QStringList getErrorMessage(PROPERTYITEM* ppt); - //---> - - //<--- for Q_ENUMS checks - QList<QENUMITEM*> checkMetadataEnums(const QList<QList<QENUMITEM*> > &classqenumlist - , const QList<QList<ENUMITEM*> > &classenumlist - , const QList<QList<QENUMITEM*> > &iclassqenumlist - , const QList<QList<ENUMITEM*> > &iclassenumlist); - QStringList getEnumValueStringList(ENUMITEM *penum, QString mappedenumname = ""); - void assignEnumValues(QENUMITEM* qenum, const QList<QList<ENUMITEM*> > &enumlookuplist); - QList<QENUMITEM*> containsAllEnums(const QList<QENUMITEM*> &classqenumlist, const QList<QENUMITEM*> &iclassqenumlist); - QStringList getErrorMessage(QENUMITEM* qenum); - //---> - - //<--- for QFlags checks ---> - QList<QFLAGITEM*> checkMetadataFlags(const QList<QList<QFLAGITEM*> > &classqflaglist - , const QList<QList<QDECLAREFLAGSITEM*> > &classqdeclareflaglist - , const QList<QList<ENUMITEM*> > &classenumlist - , const QList<QList<QFLAGITEM*> > &iclassqflaglist - , const QList<QList<QDECLAREFLAGSITEM*> > &iclassqdeclareflaglist - , const QList<QList<ENUMITEM*> > &iclassenumlist); - void assignFlagValues(QFLAGITEM* qflags, const QList<QList<QDECLAREFLAGSITEM*> > &qdeclareflagslookuplist, const QList<QList<ENUMITEM*> > &enumlookuplist); - QList<QFLAGITEM*> containsAllFlags(const QList<QFLAGITEM*> &classqflaglist, const QList<QFLAGITEM*> &iclassqflaglist); - QStringList getErrorMessage(QFLAGITEM* pfg); - //---> - - private: - // cache - QStringList m_includePaths; - QStringList m_frameworkPaths; - QByteArray m_definedMacros; - CppTools::Internal::CppPreprocessor* pCppPreprocessor; - QString m_strHeaderFile; - QStringList m_errormsgs; - }; -} -#endif // PARSEMANAGER_H diff --git a/tests/auto/ioutils/tst_ioutils.cpp b/tests/auto/ioutils/tst_ioutils.cpp index 6cba3949e7..4ccb1efca2 100644 --- a/tests/auto/ioutils/tst_ioutils.cpp +++ b/tests/auto/ioutils/tst_ioutils.cpp @@ -75,7 +75,7 @@ void tst_IoUtils::quoteArg() QFETCH(QString, in); QFETCH(QString, out); - QCOMPARE(ProFileEvaluatorInternal::IoUtils::shellQuote(in), out); + QCOMPARE(QMakeInternal::IoUtils::shellQuote(in), out); } QTEST_MAIN(tst_IoUtils) diff --git a/tests/auto/profilewriter/tst_profilewriter.cpp b/tests/auto/profilewriter/tst_profilewriter.cpp index 8c23c09f42..85c6ec6fdd 100644 --- a/tests/auto/profilewriter/tst_profilewriter.cpp +++ b/tests/auto/profilewriter/tst_profilewriter.cpp @@ -38,8 +38,10 @@ static void print(const QString &fileName, int lineNo, const QString &msg) { - if (lineNo) + if (lineNo > 0) qWarning("%s(%d): %s", qPrintable(fileName), lineNo, qPrintable(msg)); + else if (lineNo) + qWarning("%s: %s", qPrintable(fileName), qPrintable(msg)); else qWarning("%s", qPrintable(msg)); } diff --git a/tests/auto/qml/persistenttrie/completion.data b/tests/auto/qml/persistenttrie/completion.data new file mode 100644 index 0000000000..b94aeb1819 --- /dev/null +++ b/tests/auto/qml/persistenttrie/completion.data @@ -0,0 +1,10 @@ +com.bla.Pippo 0.1 +com.bla.Pippo 2.0 +com.bla.Pippo 2.1 +com.bla.Pallino 0.1 +QtQuick 1.0 + +pa +com.bla.Pallino 0.1 + +13 diff --git a/tests/auto/qml/persistenttrie/intersect.data b/tests/auto/qml/persistenttrie/intersect.data new file mode 100644 index 0000000000..a388f08078 --- /dev/null +++ b/tests/auto/qml/persistenttrie/intersect.data @@ -0,0 +1,81 @@ +abbc +a +acc +tzk +ttk +mm + +a +artz +tzj +tzg +art +tzg + +abbc +a +acc +tzk +ttk +mm + +abbc +ab +mmk +ab +abc +ab + +abbc +a +acc +tzk +ttk +mm + +com.bla.Pippo 0.1 +com.bla.Pippo 2.0 +com.bla.Pippo 2.1 +com.bla.Pallino 0.1 +QtQuick 1.0 + +a +artz +tzj +tzg +art +tzg + +abbc +ab +mmk +ab +abc +ab + +a +artz +tzj +tzg +art +tzg + +com.bla.Pippo 0.1 +com.bla.Pippo 2.0 +com.bla.Pippo 2.1 +com.bla.Pallino 0.1 +QtQuick 1.0 + +abbc +ab +mmk +ab +abc +ab + +a +artz +tzj +tzg +art +tzg diff --git a/tests/auto/qml/persistenttrie/listAll.data b/tests/auto/qml/persistenttrie/listAll.data new file mode 100644 index 0000000000..79a3477b2e --- /dev/null +++ b/tests/auto/qml/persistenttrie/listAll.data @@ -0,0 +1,26 @@ +abbc +a +acc +tzk +ttk +mm + +a +artz +tzj +tzg +art +tzg + +abbc +ab +mmk +ab +abc +ab + +com.bla.Pippo 0.1 +com.bla.Pippo 2.0 +com.bla.Pippo 2.1 +com.bla.Pallino 0.1 +QtQuick 1.0 diff --git a/tests/auto/qml/persistenttrie/merge.data b/tests/auto/qml/persistenttrie/merge.data new file mode 100644 index 0000000000..a388f08078 --- /dev/null +++ b/tests/auto/qml/persistenttrie/merge.data @@ -0,0 +1,81 @@ +abbc +a +acc +tzk +ttk +mm + +a +artz +tzj +tzg +art +tzg + +abbc +a +acc +tzk +ttk +mm + +abbc +ab +mmk +ab +abc +ab + +abbc +a +acc +tzk +ttk +mm + +com.bla.Pippo 0.1 +com.bla.Pippo 2.0 +com.bla.Pippo 2.1 +com.bla.Pallino 0.1 +QtQuick 1.0 + +a +artz +tzj +tzg +art +tzg + +abbc +ab +mmk +ab +abc +ab + +a +artz +tzj +tzg +art +tzg + +com.bla.Pippo 0.1 +com.bla.Pippo 2.0 +com.bla.Pippo 2.1 +com.bla.Pallino 0.1 +QtQuick 1.0 + +abbc +ab +mmk +ab +abc +ab + +a +artz +tzj +tzg +art +tzg diff --git a/tests/auto/qml/persistenttrie/persistenttrie.pro b/tests/auto/qml/persistenttrie/persistenttrie.pro new file mode 100644 index 0000000000..03f039fcb7 --- /dev/null +++ b/tests/auto/qml/persistenttrie/persistenttrie.pro @@ -0,0 +1,25 @@ +include(../../qttest.pri) + +DEFINES+=QTCREATORDIR=\\\"$$IDE_SOURCE_TREE\\\" +DEFINES+=TESTSRCDIR=\\\"$$PWD\\\" + +include($$IDE_SOURCE_TREE/src/libs/utils/utils.pri) +include($$IDE_SOURCE_TREE/src/libs/languageutils/languageutils.pri) +include($$IDE_SOURCE_TREE/src/libs/qmljs/qmljs.pri) + +TARGET = tst_trie_check + +HEADERS += tst_testtrie.h + +SOURCES += \ + tst_testtrie.cpp + +TEMPLATE = app +TARGET = tester +DEFINES += QMLJS_BUILD_DIR QT_CREATOR + +OTHER_FILES += \ + listAll.data \ + intersect.data \ + merge.data \ + completion.data diff --git a/tests/auto/qml/persistenttrie/tst_testtrie.cpp b/tests/auto/qml/persistenttrie/tst_testtrie.cpp new file mode 100644 index 0000000000..601f9e1635 --- /dev/null +++ b/tests/auto/qml/persistenttrie/tst_testtrie.cpp @@ -0,0 +1,374 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "tst_testtrie.h" +#include <qmljs/persistenttrie.h> + +#include <QCoreApplication> +#include <QDebug> +#include <QLatin1String> +#include <QMap> +#include <QString> +#include <QStringList> +#include <QTextStream> + +using namespace QmlJS::PersistentTrie; + +void tst_TestTrie::initTestCase() { +} + +const bool VERBOSE=false; + +tst_TestTrie::tst_TestTrie() { QObject::QObject(); } + +void tst_TestTrie::testListAll_data() +{ + QTest::addColumn<QStringList>("strs"); + + QFile f(QString(TESTSRCDIR)+QString("/listAll.data")); + if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) + return; + QTextStream stream(&f); + int iline = 0; + while (true) { + QStringList list; + QString line; + while (true) { + line=stream.readLine(); + if (line.isEmpty()) + break; + list.append(line); + } + QTest::newRow(QString::number(iline++).toLatin1()) << list; + list.clear(); + if (stream.atEnd()) + break; + } +} + +void tst_TestTrie::testListAll() +{ + QFETCH(QStringList, strs); + Trie trie; + foreach (const QString &s, strs) + trie.insert(s); + QStringList ref=strs; + ref.sort(); + ref.removeDuplicates(); + QStringList content=trie.stringList(); + content.sort(); + if (VERBOSE && ref != content) { + QDebug dbg = qDebug(); + dbg << "ERROR inserting ["; + bool comma = false; + foreach (const QString &s, strs) { + if (comma) + dbg << ","; + else + comma = true; + dbg << s; + } + dbg << "] one gets " << trie; + } + QCOMPARE(ref, content); + foreach (const QString &s,strs) { + if (VERBOSE && ! trie.contains(s)) { + qDebug() << "ERROR could not find " << s << "in" << trie; + } + QVERIFY(trie.contains(s)); + } +} + +void tst_TestTrie::testMerge_data() +{ + QTest::addColumn<QStringList>("str1"); + QTest::addColumn<QStringList>("str2"); + + QFile f(QString(TESTSRCDIR)+QString("/merge.data")); + if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) + return; + QTextStream stream(&f); + int iline = 0; + while (true) { + QStringList list1; + QString line; + while (true) { + line=stream.readLine(); + if (line.isEmpty()) + break; + list1.append(line); + } + QStringList list2; + while (true) { + line=stream.readLine(); + if (line.isEmpty()) + break; + list2.append(line); + } + QTest::newRow(QString::number(iline++).toLatin1()) << list1 << list2; + list1.clear(); + list2.clear(); + if (stream.atEnd()) + break; + } +} + +void tst_TestTrie::testMerge() +{ + QFETCH(QStringList, str1); + QFETCH(QStringList, str2); + Trie trie1; + foreach (const QString &s, str1) + trie1.insert(s); + Trie trie2; + foreach (const QString &s, str2) + trie2.insert(s); + QStringList ref=str1; + ref.append(str2); + ref.sort(); + ref.removeDuplicates(); + Trie trie3 = trie1.mergeF(trie2); + QStringList content=trie3.stringList(); + content.sort(); + if (VERBOSE && ref != content) { + QDebug dbg=qDebug(); + dbg << "ERROR merging ["; + bool comma = false; + foreach (const QString &s, str1) { + if (comma) + dbg << ","; + else + comma = true; + dbg << s; + } + dbg << "] => " << trie1 << " and ["; + comma = false; + foreach (const QString &s, str2) { + if (comma) + dbg << ","; + else + comma = true; + dbg << s; + } + dbg << "] => " << trie2 + << " to " << trie3; + } + QCOMPARE(ref, content); +} + +void tst_TestTrie::testIntersect_data() +{ + QTest::addColumn<QStringList>("str1"); + QTest::addColumn<QStringList>("str2"); + + QFile f(QString(TESTSRCDIR)+QString("/intersect.data")); + if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) + return; + QTextStream stream(&f); + int iline = 0; + while (true) { + QStringList list1; + QString line; + while (true) { + line=stream.readLine(); + if (line.isEmpty()) + break; + list1.append(line); + } + QStringList list2; + while (true) { + line=stream.readLine(); + if (line.isEmpty()) + break; + list2.append(line); + } + QTest::newRow(QString::number(iline++).toLatin1()) << list1 << list2; + list1.clear(); + list2.clear(); + if (stream.atEnd()) + break; + } +} + +void tst_TestTrie::testIntersect() +{ + QFETCH(QStringList, str1); + QFETCH(QStringList, str2); + Trie trie1; + foreach (const QString &s, str1) + trie1.insert(s); + Trie trie2; + foreach (const QString &s, str2) + trie2.insert(s); + QSet<QString> ref1; + foreach (const QString &s, str1) + ref1.insert(s); + QSet<QString> ref2; + foreach (const QString &s, str2) + ref2.insert(s); + ref1.intersect(ref2); + Trie trie3 = trie1.intersectF(trie2); + ref2.clear(); + foreach (const QString &s, trie3.stringList()) + ref2.insert(s); + if (VERBOSE && ref1 != ref2) { + QDebug dbg=qDebug(); + dbg << "ERROR intersecting ["; + bool comma = false; + foreach (const QString &s, str1) { + if (comma) + dbg << ","; + else + comma = true; + dbg << s; + } + dbg << "] => " << trie1 << " and ["; + comma = false; + foreach (const QString &s, str2) { + if (comma) + dbg << ","; + else + comma = true; + dbg << s; + } + dbg << "] => " << trie2 + << " to " << trie3; + } + QCOMPARE(ref1, ref2); +} + +void tst_TestTrie::testCompletion_data() +{ + QTest::addColumn<QStringList>("trieContents"); + QTest::addColumn<QString>("str"); + QTest::addColumn<QStringList>("completions"); + QTest::addColumn<int>("flags"); + + QFile f(QString(TESTSRCDIR)+QString("/completion.data")); + if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) + return; + QTextStream stream(&f); + int iline = 0; + while (true) { + QStringList list1; + QString line; + while (true) { + line = stream.readLine(); + if (line.isEmpty()) + break; + list1.append(line); + } + QString str = stream.readLine(); + QStringList list2; + while (true) { + line = stream.readLine(); + if (line.isEmpty()) + break; + list2.append(line); + } + int flags = stream.readLine().toInt(); + QTest::newRow(QString::number(iline++).toLatin1()) << list1 << str << list2 << flags; + list1.clear(); + list2.clear(); + if (stream.atEnd()) + break; + } +} + +void tst_TestTrie::testCompletion() { + QFETCH(QStringList, trieContents); + QFETCH(QString, str); + QFETCH(QStringList, completions); + QFETCH(int, flags); + + Trie trie; + foreach (const QString &s, trieContents) + trie.insert(s); + QStringList res = trie.complete(str, QString(), LookupFlags(flags)); + res = matchStrengthSort(str, res); + if (VERBOSE && res != completions) { + qDebug() << "unexpected completions for " << str + << " in " << trie; + qDebug() << "expected :["; + foreach (const QString &s, completions) { + qDebug() << s; + } + qDebug() << "] got ["; + foreach (const QString &s, res) { + qDebug() << s; + } + qDebug() << "]"; + } + QCOMPARE(res, completions); +} + +void interactiveCompletionTester(){ + Trie trie; + qDebug() << "interactive completion tester, insert the strings int the trie (empty line to stop)"; + QTextStream stream(stdin); + QString line; + while (true) { + line=stream.readLine(); + if (line.isEmpty()) + break; + trie.insert(line); + } + qDebug() << "testing Complete on " << trie; + while (true) { + qDebug() << "insert a string to complete (empty line to stop)"; + line=stream.readLine(); + if (line.isEmpty()) + break; + QStringList res=trie.complete(line, QString(), + LookupFlags(CaseInsensitive|SkipChars|SkipSpaces)); + res = matchStrengthSort(line,res); + qDebug() << "possible completions:["; + foreach (const QString &s, res) { + qDebug() << s; + } + qDebug() << "]"; + } +} + +#ifdef INTERACTIVE_COMPLETION_TEST + +int main(int , const char *[]) +{ + interactiveCompletionTester(); + + return 0; +} + +#else + +QTEST_MAIN(tst_TestTrie); + +//#include "moc_tst_testtrie.cpp" + +#endif diff --git a/tests/auto/icheckbuild/ichecklib.h b/tests/auto/qml/persistenttrie/tst_testtrie.h index 4133c03d22..2559e4a0c0 100644 --- a/tests/auto/icheckbuild/ichecklib.h +++ b/tests/auto/qml/persistenttrie/tst_testtrie.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of Qt Creator. @@ -27,23 +27,30 @@ ** ****************************************************************************/ -#ifndef ICHECKLIB_H -#define ICHECKLIB_H +#include <QtTest> +#include <QObject> -#include <QStringList> -#include "ichecklib_global.h" +QT_FORWARD_DECLARE_CLASS(QStringList) -namespace CPlusPlus{ - class ParseManager; -} -class ICHECKLIBSHARED_EXPORT ICheckLib { +class tst_TestTrie : public QObject +{ + Q_OBJECT public: - ICheckLib(); - void ParseHeader(const QStringList& includePath, const QStringList& filelist); - bool check(const ICheckLib& ichecklib /*ICheckLib from interface header*/, QString outputfile); - QStringList getErrorMsg(); -private: - CPlusPlus::ParseManager* pParseManager; -}; + tst_TestTrie(); + +private slots: + void initTestCase(); + //void cleanupTestCase(); + //void init(); + //void cleanup(); -#endif // ICHECKLIB_H + void testListAll_data(); + void testMerge_data(); + void testIntersect_data(); + void testCompletion_data(); + + void testListAll(); + void testMerge(); + void testIntersect(); + void testCompletion(); +}; diff --git a/tests/auto/qml/qmldesigner/common/statichelpers.cpp b/tests/auto/qml/qmldesigner/common/statichelpers.cpp index 7b8ae206c7..5970e697db 100644 --- a/tests/auto/qml/qmldesigner/common/statichelpers.cpp +++ b/tests/auto/qml/qmldesigner/common/statichelpers.cpp @@ -69,19 +69,6 @@ static QString bareTemplate("import Qt 4.6\n" "}"); static QString contentsTemplate(bareTemplate.arg("Text { id: textChild; x:10; y: 10; text: \"%1\"; %2 }")); - -void printErrors(const QList<QDeclarativeError> &errors, const QString &fileName) -{ - if (errors.isEmpty()) - return; - - qDebug() << "Error loading file \"" << fileName << "\":"; - - foreach (const QDeclarativeError &error, errors) { - qDebug() << error.line() << ":" << error.column() << ": " << error.description(); - } -} - // TODO: this need to e updated for states static bool compareProperty(const AbstractProperty &property1, const AbstractProperty &property2) { diff --git a/tests/auto/qml/qmldesigner/coretests/coretests.pro b/tests/auto/qml/qmldesigner/coretests/coretests.pro index b82c68f5a6..8924538412 100644 --- a/tests/auto/qml/qmldesigner/coretests/coretests.pro +++ b/tests/auto/qml/qmldesigner/coretests/coretests.pro @@ -1,33 +1,43 @@ -include(../../../qttest.pri) - -QTCREATOR_SOURCE=$$PWD/../../../../.. -QTCREATOR_BUILD=$$OUT_PWD/../../../../.. +IDE_SOURCE_TREE=$$PWD/../../../../.. +IDE_BUILD_TREE=$$OUT_PWD/../../../../.. # can we check that this is a valid build dir? - OUT_PWD_SAVE=$$OUT_PWD -OUT_PWD=QTCREATOR_BUILD +OUT_PWD=IDE_BUILD_TREE include($$IDE_SOURCE_TREE/src/plugins/qmldesigner/config.pri) +include(../../../qttest.pri) OUT_PWD=$$OUT_PWD_SAVE - LIBS += -L$$IDE_PLUGIN_PATH/QtProject +LIBS += -L$$IDE_LIBRARY_PATH unix: QMAKE_LFLAGS += \'-Wl,-rpath,$${IDE_LIBRARY_PATH}\' \'-Wl,-rpath,$${IDE_PLUGIN_PATH}/QtProject\' QT += script \ - network \ - declarative \ - webkit + network + +greaterThan(QT_MAJOR_VERSION, 4) { + QT += printsupport + !isEmpty(QT.webkitwidgets.name): QT += webkitwidgets webkit + else: DEFINES += QT_NO_WEBKIT +} else { + contains(QT_CONFIG, webkit): QT += webkit +} + # DEFINES+=QTCREATOR_UTILS_STATIC_LIB QML_BUILD_STATIC_LIB DEFINES+=QTCREATORDIR=\\\"$$IDE_BUILD_TREE\\\" -DEFINES+=QT_CREATOR QTCREATOR_TEST +DEFINES+=QT_CREATOR QTCREATOR_TEST QMLDESIGNER_TEST INCLUDEPATH += $$IDE_SOURCE_TREE/src/plugins/qmldesigner/designercore/include INCLUDEPATH += $$IDE_SOURCE_TREE/src/plugins/qmldesigner/designercore +INCLUDEPATH += $$IDE_SOURCE_TREE//share/qtcreator/qml/qmlpuppet +INCLUDEPATH += $$IDE_SOURCE_TREE/src/plugins/qmldesigner -include($$IDE_SOURCE_TREE/src/plugins/qmldesigner/designercore/designercore.pri) -include($$IDE_SOURCE_TREE/src/libs/utils/utils.pri) + +include($$IDE_SOURCE_TREE/src/plugins/qmldesigner/designercore/designercore-lib.pri) include($$IDE_SOURCE_TREE/src/plugins/qmljstools/qmljstools.pri) +include($$IDE_SOURCE_TREE/src/libs/utils/utils.pri) +include($$IDE_SOURCE_TREE/src/libs/qmljs/qmljs.pri) +include($$IDE_SOURCE_TREE/src/libs/cplusplus/cplusplus.pri) CONFIG += console CONFIG -= app_bundle diff --git a/tests/auto/qml/qmldesigner/coretests/setupPath.bat b/tests/auto/qml/qmldesigner/coretests/setupPath.bat new file mode 100644 index 0000000000..7355f3c099 --- /dev/null +++ b/tests/auto/qml/qmldesigner/coretests/setupPath.bat @@ -0,0 +1 @@ +@set path=%PATH%;%CD%\..\..\..\..\..\lib\qtcreator\plugins\QtProject\ diff --git a/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp b/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp index bab2419b12..10f89ace88 100644 --- a/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp +++ b/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp @@ -32,6 +32,8 @@ #include <QScopedPointer> #include <QLatin1String> #include <QGraphicsObject> +#include <QTest> +#include <QVariant> #include <metainfo.h> #include <model.h> @@ -55,17 +57,22 @@ #include <nodelistproperty.h> #include <nodeabstractproperty.h> #include <componenttextmodifier.h> -#include <instances/objectnodeinstance.h> #include <bytearraymodifier.h> #include "testrewriterview.h" +#include <utils/fileutils.h> #include <qmljs/qmljsinterpreter.h> #include <QPlainTextEdit> -#include <private/qdeclarativestate_p.h> -#include <private/qdeclarativemetatype_p.h> -#include <QDeclarativeItem> + +#if QT_VERSION >= 0x050000 +#define MSKIP_SINGLE(x) QSKIP(x) +#define MSKIP_ALL(x) QSKIP(x); +#else +#define MSKIP_SINGLE(x) QSKIP(x, SkipSingle) +#define MSKIP_ALL(x) QSKIP(x, SkipAll) +#endif //TESTED_COMPONENT=src/plugins/qmldesigner/designercore @@ -74,6 +81,7 @@ using namespace QmlDesigner; #include "../common/statichelpers.cpp" #include <qmljstools/qmljsmodelmanager.h> +#include <qmljs/qmljsinterpreter.h> #ifdef Q_OS_MAC # define SHARE_PATH "/Resources" @@ -93,10 +101,17 @@ public: { loadQmlTypeDescriptions(resourcePath()); } - void loadFile(QString fileName) + void updateSourceFiles(const QStringList &files, bool emitDocumentOnDiskChanged) { - refreshSourceFiles(QStringList() << fileName, false).waitForFinished(); + refreshSourceFiles(files, emitDocumentOnDiskChanged).waitForFinished(); } + + QmlJS::LibraryInfo builtins(const QmlJS::Document::Ptr &) const + { + return QmlJS::LibraryInfo(); + } + + }; static void initializeMetaTypeSystem(const QString &resourcePath) @@ -107,9 +122,36 @@ static void initializeMetaTypeSystem(const QString &resourcePath) QDir::Files, QDir::Name); - const QStringList errors = QmlJS::Interpreter::CppQmlTypesLoader::loadQmlTypes(qmlFiles); - foreach (const QString &error, errors) - qWarning() << qPrintable(error); + QStringList errorsAndWarnings; + QmlJS::CppQmlTypesLoader::loadQmlTypes(qmlFiles, &errorsAndWarnings, &errorsAndWarnings); + foreach (const QString &errorAndWarning, errorsAndWarnings) + qWarning() << qPrintable(errorAndWarning); +} + +static QmlDesigner::Model* createModel(const QString &typeName, int major = 1, int minor = 1, Model *metaInfoPropxyModel = 0) +{ + QApplication::processEvents(); + + QmlDesigner::Model *model = QmlDesigner::Model::create(typeName, major, minor, metaInfoPropxyModel); + + QPlainTextEdit *textEdit = new QPlainTextEdit; + QObject::connect(model, SIGNAL(destroyed()), textEdit, SLOT(deleteLater())); + textEdit->setPlainText(QString("import %1 %3.%4; %2{}").arg(typeName.split(".").first()) + .arg(typeName.split(".").last()) + .arg(major) + .arg(minor)); + + NotIndentingTextEditModifier *modifier = new NotIndentingTextEditModifier(textEdit); + modifier->setParent(textEdit); + + QmlDesigner::RewriterView *rewriterView = new QmlDesigner::RewriterView(QmlDesigner::RewriterView::Validate, model); + rewriterView->setCheckSemanticErrors(false); + rewriterView->setTextModifier(modifier); + + model->attachView(rewriterView); + + return model; + } tst_TestCore::tst_TestCore() @@ -130,9 +172,9 @@ void tst_TestCore::initTestCase() // Load plugins #ifdef Q_OS_MAC - const QString pluginPath = QTCREATORDIR "/bin/Qt Creator.app/Contents/PlugIns/QmlDesigner"; + const QString pluginPath = QTCREATORDIR "/bin/Qt Creator.app/Contents/PlugIns/QtCreator/QmlDesigner"; #else - const QString pluginPath = QTCREATORDIR "/lib/qmldesigner"; + const QString pluginPath = QTCREATORDIR "/lib/qtcreator/qmldesigner"; #endif qDebug() << pluginPath; @@ -147,9 +189,18 @@ void tst_TestCore::cleanupTestCase() MetaInfo::clearGlobal(); } +void tst_TestCore::init() +{ + QApplication::processEvents(); +} +void tst_TestCore::cleanup() +{ + QApplication::processEvents(); +} + void tst_TestCore::testModelCreateCoreModel() { - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> testView(new TestView(model.data())); @@ -168,17 +219,17 @@ void tst_TestCore::loadEmptyCoreModel() textEdit1.setPlainText(file.readAll()); NotIndentingTextEditModifier modifier1(&textEdit1); - QScopedPointer<Model> model1(Model::create("Qt/Item")); + QScopedPointer<Model> model1(Model::create("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView1(new TestRewriterView()); testRewriterView1->setTextModifier(&modifier1); model1->attachView(testRewriterView1.data()); QPlainTextEdit textEdit2; - textEdit2.setPlainText("import Qt 4.7; Item{}"); + textEdit2.setPlainText("import QtQuick 1.1; Item{}"); NotIndentingTextEditModifier modifier2(&textEdit2); - QScopedPointer<Model> model2(Model::create("Qt/item")); + QScopedPointer<Model> model2(Model::create("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView2(new TestRewriterView()); testRewriterView2->setTextModifier(&modifier2); @@ -191,10 +242,10 @@ void tst_TestCore::testRewriterView() { try { QPlainTextEdit textEdit; - textEdit.setPlainText("import Qt 4.7;\n\nItem {\n}\n"); + textEdit.setPlainText("import QtQuick 1.1;\n\nItem {\n}\n"); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -207,15 +258,15 @@ void tst_TestCore::testRewriterView() testRewriterView->setTextModifier(&textModifier); model->attachView(testRewriterView.data()); - ModelNode childNode(addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data")); + ModelNode childNode(addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data")); QVERIFY(childNode.isValid()); childNode.setId("childNode"); - ModelNode childNode2(addNodeListChild(childNode, "Qt/Rectangle", 4, 7, "data")); + ModelNode childNode2(addNodeListChild(childNode, "QtQuick.Rectangle", 1, 0, "data")); childNode2.setId("childNode2"); - ModelNode childNode3(addNodeListChild(childNode2, "Qt/Rectangle", 4, 7, "data")); + ModelNode childNode3(addNodeListChild(childNode2, "QtQuick.Rectangle", 1, 0, "data")); childNode3.setId("childNode3"); - ModelNode childNode4(addNodeListChild(childNode3, "Qt/Rectangle", 4, 7, "data")); + ModelNode childNode4(addNodeListChild(childNode3, "QtQuick.Rectangle", 1, 0, "data")); childNode4.setId("childNode4"); QVERIFY(childNode.isValid()); @@ -241,7 +292,7 @@ void tst_TestCore::testRewriterView() testRewriterView->modelToTextMerger()->applyChanges(); - childNode = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); + childNode = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); QVERIFY(testRewriterView->modelToTextMerger()->isNodeScheduledForAddition(childNode)); testRewriterView->modelToTextMerger()->applyChanges(); @@ -261,10 +312,10 @@ void tst_TestCore::testRewriterView() void tst_TestCore::testRewriterErrors() { QPlainTextEdit textEdit; - textEdit.setPlainText("import Qt 4.7;\n\nItem {\n}\n"); + textEdit.setPlainText("import QtQuick 1.1;\n\nItem {\n}\n"); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -278,16 +329,15 @@ void tst_TestCore::testRewriterErrors() model->attachView(testRewriterView.data()); QVERIFY(testRewriterView->errors().isEmpty()); - textEdit.setPlainText("import Qt 4.7;\n\nError {\n}\n"); + textEdit.setPlainText("import QtQuick 1.1;\nRectangle {\ntest: blah\n}\n"); QVERIFY(!testRewriterView->errors().isEmpty()); - textEdit.setPlainText("import Qt 4.7;\n\nItem {\n}\n"); + textEdit.setPlainText("import QtQuick 1.1;\n\nItem {\n}\n"); QVERIFY(testRewriterView->errors().isEmpty()); } void tst_TestCore::saveEmptyCoreModel() { - QList<QDeclarativeError> errors; QFile file(":/fx/empty.qml"); QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); @@ -295,7 +345,7 @@ void tst_TestCore::saveEmptyCoreModel() textEdit1.setPlainText(file.readAll()); NotIndentingTextEditModifier modifier1(&textEdit1); - QScopedPointer<Model> model1(Model::create("Qt/Item")); + QScopedPointer<Model> model1(Model::create("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView1(new TestRewriterView()); testRewriterView1->setTextModifier(&modifier1); @@ -307,10 +357,10 @@ void tst_TestCore::saveEmptyCoreModel() modifier1.save(&buffer); QPlainTextEdit textEdit2; - textEdit2.setPlainText("import Qt 4.7; Item{}"); + textEdit2.setPlainText("import QtQuick 1.1; Item{}"); NotIndentingTextEditModifier modifier2(&textEdit2); - QScopedPointer<Model> model2(Model::create("Qt/item")); + QScopedPointer<Model> model2(Model::create("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView2(new TestRewriterView()); testRewriterView2->setTextModifier(&modifier2); @@ -322,7 +372,6 @@ void tst_TestCore::saveEmptyCoreModel() void tst_TestCore::loadAttributesInCoreModel() { - QList<QDeclarativeError> errors; QFile file(":/fx/attributes.qml"); QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); @@ -330,17 +379,17 @@ void tst_TestCore::loadAttributesInCoreModel() textEdit1.setPlainText(file.readAll()); NotIndentingTextEditModifier modifier1(&textEdit1); - QScopedPointer<Model> model1(Model::create("Qt/Item")); + QScopedPointer<Model> model1(Model::create("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView1(new TestRewriterView()); testRewriterView1->setTextModifier(&modifier1); model1->attachView(testRewriterView1.data()); QPlainTextEdit textEdit2; - textEdit2.setPlainText("import Qt 4.7; Item{}"); + textEdit2.setPlainText("import QtQuick 1.1; Item{}"); NotIndentingTextEditModifier modifier2(&textEdit2); - QScopedPointer<Model> model2(Model::create("Qt/item")); + QScopedPointer<Model> model2(Model::create("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView2(new TestRewriterView()); testRewriterView2->setTextModifier(&modifier2); @@ -365,7 +414,7 @@ void tst_TestCore::saveAttributesInCoreModel() textEdit1.setPlainText(file.readAll()); NotIndentingTextEditModifier modifier1(&textEdit1); - QScopedPointer<Model> model1(Model::create("Qt/Item")); + QScopedPointer<Model> model1(Model::create("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView1(new TestRewriterView()); testRewriterView1->setTextModifier(&modifier1); @@ -381,7 +430,7 @@ void tst_TestCore::saveAttributesInCoreModel() textEdit2.setPlainText(buffer.data()); NotIndentingTextEditModifier modifier2(&textEdit2); - QScopedPointer<Model> model2(Model::create("Qt/Item")); + QScopedPointer<Model> model2(Model::create("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView2(new TestRewriterView()); testRewriterView2->setTextModifier(&modifier2); @@ -396,7 +445,7 @@ void tst_TestCore::testModelCreateRect() { try { - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -404,7 +453,7 @@ void tst_TestCore::testModelCreateRect() model->attachView(view.data()); QVERIFY(view->rootModelNode().isValid()); - ModelNode childNode = addNodeListChild(view->rootModelNode(), "Qt/Rectangle", 4, 7, "data"); + ModelNode childNode = addNodeListChild(view->rootModelNode(), "QtQuick.Rectangle", 1, 0, "data"); QVERIFY(childNode.isValid()); QVERIFY(view->rootModelNode().allDirectSubModelNodes().contains(childNode)); QVERIFY(childNode.parentProperty().parentModelNode() == view->rootModelNode()); @@ -423,7 +472,7 @@ void tst_TestCore::testModelCreateRect() QCOMPARE(childNode.propertyNames().count(), 4); QCOMPARE(childNode.variantProperty("scale").value(), QVariant()); - } catch (Exception &exception) { + } catch (Exception &) { QFAIL("Exception thrown"); } @@ -432,7 +481,7 @@ void tst_TestCore::testModelCreateRect() void tst_TestCore::testRewriterDynamicProperties() { const QLatin1String qmlString("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " property int i\n" @@ -459,7 +508,7 @@ void tst_TestCore::testRewriterDynamicProperties() textEdit1.setPlainText(qmlString); NotIndentingTextEditModifier modifier1(&textEdit1); - QScopedPointer<Model> model1(Model::create("Qt/Item")); + QScopedPointer<Model> model1(Model::create("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView1(new TestRewriterView()); testRewriterView1->setTextModifier(&modifier1); @@ -549,10 +598,10 @@ void tst_TestCore::testRewriterDynamicProperties() // test model2text // QPlainTextEdit textEdit2; -// textEdit2.setPlainText("import Qt 4.7; Item{}"); +// textEdit2.setPlainText("import QtQuick 1.1; Item{}"); // NotIndentingTextEditModifier modifier2(&textEdit2); // -// QScopedPointer<Model> model2(Model::create("Qt/Item")); +// QScopedPointer<Model> model2(Model::create("QtQuick.Item")); // // QScopedPointer<TestRewriterView> testRewriterView2(new TestRewriterView()); // testRewriterView2->setTextModifier(&modifier2); @@ -566,7 +615,7 @@ void tst_TestCore::testRewriterDynamicProperties() void tst_TestCore::testRewriterGroupedProperties() { const QLatin1String qmlString("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Text {\n" " font {\n" @@ -579,7 +628,7 @@ void tst_TestCore::testRewriterGroupedProperties() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier modifier1(&textEdit); - QScopedPointer<Model> model1(Model::create("Qt/Text")); + QScopedPointer<Model> model1(Model::create("QtQuick.Text")); QScopedPointer<TestRewriterView> testRewriterView1(new TestRewriterView()); testRewriterView1->setTextModifier(&modifier1); @@ -603,7 +652,7 @@ void tst_TestCore::testRewriterGroupedProperties() rootModelNode.removeProperty(QLatin1String("font.pointSize")); const QLatin1String expected("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Text {\n" "}\n"); @@ -614,7 +663,7 @@ void tst_TestCore::testRewriterGroupedProperties() void tst_TestCore::testRewriterPreserveOrder() { const QLatin1String qmlString1("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" "width: 640\n" @@ -635,7 +684,7 @@ void tst_TestCore::testRewriterPreserveOrder() "}\n" "}\n"); const QLatin1String qmlString2("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" "width: 640\n" @@ -661,7 +710,7 @@ void tst_TestCore::testRewriterPreserveOrder() textEdit.setPlainText(qmlString2); NotIndentingTextEditModifier modifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Text")); + QScopedPointer<Model> model(Model::create("QtQuick.Text")); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); testRewriterView->setTextModifier(&modifier); @@ -674,7 +723,7 @@ void tst_TestCore::testRewriterPreserveOrder() RewriterTransaction transaction = testRewriterView->beginRewriterTransaction(); - ModelNode newModelNode = testRewriterView->createModelNode("Qt/Rectangle", 4, 7); + ModelNode newModelNode = testRewriterView->createModelNode("QtQuick.Rectangle", 1, 0); newModelNode.setParentProperty(rootModelNode.nodeAbstractProperty("data")); @@ -696,7 +745,7 @@ void tst_TestCore::testRewriterPreserveOrder() textEdit.setPlainText(qmlString1); NotIndentingTextEditModifier modifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Text")); + QScopedPointer<Model> model(Model::create("QtQuick.Text")); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); testRewriterView->setTextModifier(&modifier); @@ -709,7 +758,7 @@ void tst_TestCore::testRewriterPreserveOrder() RewriterTransaction transaction = testRewriterView->beginRewriterTransaction(); - ModelNode newModelNode = testRewriterView->createModelNode("Qt/Rectangle", 4, 7); + ModelNode newModelNode = testRewriterView->createModelNode("QtQuick.Rectangle", 1, 0); newModelNode.setParentProperty(rootModelNode.nodeAbstractProperty("data")); @@ -730,7 +779,7 @@ void tst_TestCore::testRewriterPreserveOrder() void tst_TestCore::testRewriterActionCompression() { const QLatin1String qmlString("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " id: root\n" @@ -750,7 +799,7 @@ void tst_TestCore::testRewriterActionCompression() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier modifier1(&textEdit); - QScopedPointer<Model> model1(Model::create("Qt/Rectangle")); + QScopedPointer<Model> model1(Model::create("QtQuick.Rectangle")); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); testRewriterView->setTextModifier(&modifier1); @@ -776,7 +825,7 @@ void tst_TestCore::testRewriterActionCompression() transaction.commit(); const QLatin1String expected("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " id: root\n" @@ -804,7 +853,7 @@ void tst_TestCore::testRewriterImports() textEdit.setPlainText(file.readAll()); NotIndentingTextEditModifier modifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); model->setFileUrl(QUrl::fromLocalFile(fileName)); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); @@ -815,12 +864,12 @@ void tst_TestCore::testRewriterImports() QVERIFY(model->imports().size() == 3); - // import Qt 4.7 + // import QtQuick 1.1 Import import = model->imports().at(0); QVERIFY(import.isLibraryImport()); - QCOMPARE(import.url(), QString("Qt")); + QCOMPARE(import.url(), QString("QtQuick")); QVERIFY(import.hasVersion()); - QCOMPARE(import.version(), QString("4.7")); + QCOMPARE(import.version(), QString("1.0")); QVERIFY(!import.hasAlias()); // import "subitems" @@ -843,7 +892,7 @@ void tst_TestCore::testRewriterImports() void tst_TestCore::testRewriterChangeImports() { const QLatin1String qmlString("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {}\n"); @@ -851,7 +900,7 @@ void tst_TestCore::testRewriterChangeImports() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier modifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Rectangle")); + QScopedPointer<Model> model(Model::create("QtQuick.Rectangle")); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView(0, RewriterView::Amend)); testRewriterView->setTextModifier(&modifier); @@ -870,7 +919,7 @@ void tst_TestCore::testRewriterChangeImports() model->changeImports(importList, QList<Import>()); const QLatin1String qmlWithImport("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "import QtWebKit 1.0\n" "\n" "Rectangle {}\n"); @@ -879,7 +928,7 @@ void tst_TestCore::testRewriterChangeImports() model->changeImports(QList<Import>(), importList); QCOMPARE(model->imports().size(), 1); - QCOMPARE(model->imports().first(), Import::createLibraryImport("Qt", "4.7")); + QCOMPARE(model->imports().first(), Import::createLibraryImport("QtQuick", "1.1")); QCOMPARE(textEdit.toPlainText(), qmlString); @@ -887,45 +936,45 @@ void tst_TestCore::testRewriterChangeImports() // // Add / Remove an import in the model (with alias) // - model->changeImports(importList, QList<Import>()); + + Import webkitImportAlias = Import::createLibraryImport("QtWebKit", "1.0", "Web"); + + model->changeImports(QList<Import>() << webkitImportAlias, QList<Import>() << webkitImport); const QLatin1String qmlWithAliasImport("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "import QtWebKit 1.0 as Web\n" "\n" "Rectangle {}\n"); QCOMPARE(textEdit.toPlainText(), qmlWithAliasImport); - model->changeImports(QList<Import>(), importList); - - QCOMPARE(model->imports().size(), 1); - QCOMPARE(model->imports().first(), Import::createLibraryImport("Qt", "4.7")); + model->changeImports(QList<Import>(), QList<Import>() << webkitImportAlias); + QCOMPARE(model->imports().first(), Import::createLibraryImport("QtQuick", "1.1")); QCOMPARE(textEdit.toPlainText(), qmlString); - // // Add / Remove an import in text // textEdit.setPlainText(qmlWithImport); QCOMPARE(model->imports().size(), 2); - QCOMPARE(model->imports().first(), Import::createLibraryImport("Qt", "4.7")); + QCOMPARE(model->imports().first(), Import::createLibraryImport("QtQuick", "1.1")); QCOMPARE(model->imports().last(), Import::createLibraryImport("QtWebKit", "1.0")); textEdit.setPlainText(qmlWithAliasImport); QCOMPARE(model->imports().size(), 2); - QCOMPARE(model->imports().first(), Import::createLibraryImport("Qt", "4.7")); + QCOMPARE(model->imports().first(), Import::createLibraryImport("QtQuick", "1.1")); QCOMPARE(model->imports().last(), Import::createLibraryImport("QtWebKit", "1.0", "Web")); textEdit.setPlainText(qmlString); QCOMPARE(model->imports().size(), 1); - QCOMPARE(model->imports().first(), Import::createLibraryImport("Qt", "4.7")); + QCOMPARE(model->imports().first(), Import::createLibraryImport("QtQuick", "1.1")); } void tst_TestCore::testRewriterForGradientMagic() { const QLatin1String qmlString("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " id: root\n" @@ -963,7 +1012,7 @@ void tst_TestCore::testRewriterForGradientMagic() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier modifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Text")); + QScopedPointer<Model> model(Model::create("QtQuick.Text")); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); testRewriterView->setTextModifier(&modifier); @@ -979,7 +1028,7 @@ void tst_TestCore::testRewriterForGradientMagic() myRect.variantProperty("rotation") = QVariant(45); QVERIFY(myRect.isValid()); - QScopedPointer<Model> model1(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model1(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model1.data()); QScopedPointer<TestView> view1(new TestView(model1.data())); @@ -987,7 +1036,7 @@ void tst_TestCore::testRewriterForGradientMagic() QScopedPointer<TestRewriterView> testRewriterView1(new TestRewriterView()); QPlainTextEdit textEdit1; - textEdit1.setPlainText("import Qt 4.7; Item {}"); + textEdit1.setPlainText("import QtQuick 1.1; Item {}"); NotIndentingTextEditModifier modifier1(&textEdit1); testRewriterView1->setTextModifier(&modifier1); @@ -1013,7 +1062,7 @@ void tst_TestCore::loadSubItems() textEdit1.setPlainText(file.readAll()); NotIndentingTextEditModifier modifier1(&textEdit1); - QScopedPointer<Model> model1(Model::create("Qt/Item")); + QScopedPointer<Model> model1(Model::create("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView1(new TestRewriterView()); testRewriterView1->setTextModifier(&modifier1); @@ -1022,16 +1071,16 @@ void tst_TestCore::loadSubItems() void tst_TestCore::createInvalidCoreModel() { - QScopedPointer<Model> invalidModel(Model::create("ItemSUX")); + QScopedPointer<Model> invalidModel(createModel("ItemSUX")); //QVERIFY(!invalidModel.data()); //#no direct ype checking in model atm - QScopedPointer<Model> invalidModel2(Model::create("InvalidNode")); + QScopedPointer<Model> invalidModel2(createModel("InvalidNode")); //QVERIFY(!invalidModel2.data()); } void tst_TestCore::testModelCreateSubNode() { - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -1043,7 +1092,7 @@ void tst_TestCore::testModelCreateSubNode() QCOMPARE(view->methodCalls(), expectedCalls); QVERIFY(view->rootModelNode().isValid()); - ModelNode childNode = addNodeListChild(view->rootModelNode(), "Qt/Rectangle", 4, 7, "data"); + ModelNode childNode = addNodeListChild(view->rootModelNode(), "QtQuick.Rectangle", 1, 0, "data"); QVERIFY(childNode.isValid()); QVERIFY(view->rootModelNode().allDirectSubModelNodes().contains(childNode)); QVERIFY(childNode.parentProperty().parentModelNode() == view->rootModelNode()); @@ -1077,7 +1126,7 @@ void tst_TestCore::testModelCreateSubNode() void tst_TestCore::testTypicalRewriterOperations() { - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -1087,46 +1136,46 @@ void tst_TestCore::testTypicalRewriterOperations() ModelNode rootModelNode = view->rootModelNode(); QCOMPARE(rootModelNode.allDirectSubModelNodes().count(), 0); - QVERIFY(rootModelNode.property("test").isValid()); - QVERIFY(!rootModelNode.property("test").isVariantProperty()); - QVERIFY(!rootModelNode.property("test").isBindingProperty()); + QVERIFY(rootModelNode.property("x").isValid()); + QVERIFY(!rootModelNode.property("x").isVariantProperty()); + QVERIFY(!rootModelNode.property("x").isBindingProperty()); - QVERIFY(rootModelNode.variantProperty("test").isValid()); - QVERIFY(!rootModelNode.hasProperty("test")); + QVERIFY(rootModelNode.variantProperty("x").isValid()); + QVERIFY(!rootModelNode.hasProperty("x")); - rootModelNode.variantProperty("test") = 70; + rootModelNode.variantProperty("x") = 70; - QVERIFY(rootModelNode.hasProperty("test")); - QVERIFY(rootModelNode.property("test").isVariantProperty()); - QCOMPARE(rootModelNode.variantProperty("test").value(), QVariant(70)); + QVERIFY(rootModelNode.hasProperty("x")); + QVERIFY(rootModelNode.property("x").isVariantProperty()); + QCOMPARE(rootModelNode.variantProperty("x").value(), QVariant(70)); - rootModelNode.bindingProperty("test") = "parent.x"; - QVERIFY(!rootModelNode.property("test").isVariantProperty()); - QVERIFY(rootModelNode.property("test").isBindingProperty()); + rootModelNode.bindingProperty("x") = "parent.x"; + QVERIFY(!rootModelNode.property("x").isVariantProperty()); + QVERIFY(rootModelNode.property("x").isBindingProperty()); - QCOMPARE(rootModelNode.bindingProperty("test").expression(), QString("parent.x")); + QCOMPARE(rootModelNode.bindingProperty("x").expression(), QString("parent.x")); - ModelNode childNode(addNodeListChild(rootModelNode, "Qt/Rectangle", 4 ,6, "data")); - rootModelNode.nodeListProperty("test").reparentHere(childNode); - QCOMPARE(childNode.parentProperty(), rootModelNode.nodeAbstractProperty("test")); - QVERIFY(rootModelNode.property("test").isNodeAbstractProperty()); - QVERIFY(rootModelNode.property("test").isNodeListProperty()); - QVERIFY(!rootModelNode.property("test").isBindingProperty()); + ModelNode childNode(addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1 ,0, "data")); + rootModelNode.nodeListProperty("data").reparentHere(childNode); + QCOMPARE(childNode.parentProperty(), rootModelNode.nodeAbstractProperty("data")); + QVERIFY(rootModelNode.property("data").isNodeAbstractProperty()); + QVERIFY(rootModelNode.property("data").isNodeListProperty()); + QVERIFY(!rootModelNode.property("data").isBindingProperty()); QVERIFY(childNode.parentProperty().isNodeListProperty()); QCOMPARE(childNode, childNode.parentProperty().toNodeListProperty().toModelNodeList().first()); QCOMPARE(rootModelNode, childNode.parentProperty().parentModelNode()); - QCOMPARE(childNode.parentProperty().name(), QString("test")); + QCOMPARE(childNode.parentProperty().name(), QString("data")); - QVERIFY(!rootModelNode.property("test").isVariantProperty()); - rootModelNode.variantProperty("test") = 90; - QVERIFY(rootModelNode.property("test").isVariantProperty()); - QCOMPARE(rootModelNode.variantProperty("test").value(), QVariant(90)); + QVERIFY(!rootModelNode.property("x").isVariantProperty()); + rootModelNode.variantProperty("x") = 90; + QVERIFY(rootModelNode.property("x").isVariantProperty()); + QCOMPARE(rootModelNode.variantProperty("x").value(), QVariant(90)); } void tst_TestCore::testBasicStates() { - char qmlString[] = "import Qt 4.7\n" + char qmlString[] = "import QtQuick 1.1\n" "Rectangle {\n" "id: root;\n" "Rectangle {\n" @@ -1165,7 +1214,7 @@ void tst_TestCore::testBasicStates() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -1174,13 +1223,13 @@ void tst_TestCore::testBasicStates() ModelNode rootModelNode(view->rootModelNode()); QVERIFY(rootModelNode.isValid()); - QCOMPARE(rootModelNode.type(), QString("Qt/Item")); + QCOMPARE(rootModelNode.type(), QString("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); testRewriterView->setTextModifier(&textModifier); model->attachView(testRewriterView.data()); QVERIFY(rootModelNode.isValid()); - QCOMPARE(rootModelNode.type(), QString("Qt/Rectangle")); + QCOMPARE(rootModelNode.type(), QString("QtQuick.Rectangle")); QVERIFY(rootModelNode.hasProperty("data")); @@ -1213,6 +1262,7 @@ void tst_TestCore::testBasicStates() QCOMPARE(state1.propertyChanges().count(), 2); QCOMPARE(state2.propertyChanges().count(), 2); + QVERIFY(state1.propertyChanges().first().modelNode().metaInfo().isSubclassOf("<cpp>.QDeclarative1StateOperation", -1, -1)); QVERIFY(!state1.hasPropertyChanges(rootModelNode)); QVERIFY(state1.propertyChanges(rect1).isValid()); @@ -1275,10 +1325,117 @@ void tst_TestCore::testBasicStates() // QCOMPARE(rect2Instance.property("x").toInt(), 0); } +void tst_TestCore::testBasicStatesQtQuick20() +{ + char qmlString[] = "import QtQuick 2.0\n" + "Rectangle {\n" + "id: root;\n" + "Rectangle {\n" + "id: rect1;\n" + "}\n" + "Rectangle {\n" + "id: rect2;\n" + "}\n" + "states: [\n" + "State {\n" + "name: \"state1\"\n" + "PropertyChanges {\n" + "target: rect1\n" + "}\n" + "PropertyChanges {\n" + "target: rect2\n" + "}\n" + "}\n" + "," + "State {\n" + "name: \"state2\"\n" + "PropertyChanges {\n" + "target: rect1\n" + "}\n" + "PropertyChanges {\n" + "target: rect2;\n" + "x: 10;\n" + "}\n" + "}\n" + "]\n" + "}\n"; + + Exception::setShouldAssert(true); + + QPlainTextEdit textEdit; + textEdit.setPlainText(qmlString); + NotIndentingTextEditModifier textModifier(&textEdit); + + QScopedPointer<Model> model(Model::create("QtQuick.Item")); + QVERIFY(model.data()); + + QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); + testRewriterView->setTextModifier(&textModifier); + model->attachView(testRewriterView.data()); + + ModelNode rootModelNode(testRewriterView->rootModelNode()); + QVERIFY(rootModelNode.isValid()); + QCOMPARE(rootModelNode.type(), QString("QtQuick.Rectangle")); + QCOMPARE(rootModelNode.majorVersion(), 2); + QCOMPARE(rootModelNode.majorQtQuickVersion(), 2); + + qDebug() << rootModelNode.nodeListProperty("states").toModelNodeList().first().metaInfo().majorVersion(); + qDebug() << rootModelNode.nodeListProperty("states").toModelNodeList().first().metaInfo().typeName(); + + MSKIP_ALL("No qml2puppet"); + + QScopedPointer<TestView> view(new TestView(model.data())); + QVERIFY(view.data()); + model->attachView(view.data()); + + QVERIFY(rootModelNode.hasProperty("data")); + + QVERIFY(rootModelNode.property("data").isNodeListProperty()); + + QCOMPARE(rootModelNode.nodeListProperty("data").toModelNodeList().count(), 2); + + ModelNode rect1 = rootModelNode.nodeListProperty("data").toModelNodeList().first(); + ModelNode rect2 = rootModelNode.nodeListProperty("data").toModelNodeList().last(); + + QVERIFY(QmlItemNode(rect1).isValid()); + QVERIFY(QmlItemNode(rect2).isValid()); + + QVERIFY(QmlItemNode(rootModelNode).isValid()); + + QCOMPARE(QmlItemNode(rootModelNode).states().allStates().count(), 2); + QCOMPARE(QmlItemNode(rootModelNode).states().names().count(), 2); + QCOMPARE(QmlItemNode(rootModelNode).states().names().first(), QString("state1")); + QCOMPARE(QmlItemNode(rootModelNode).states().names().last(), QString("state2")); + + // + // QmlModelState API tests + // + QmlModelState state1 = QmlItemNode(rootModelNode).states().state("state1"); + QmlModelState state2 = QmlItemNode(rootModelNode).states().state("state2"); + + QVERIFY(state1.isValid()); + QVERIFY(state2.isValid()); + + QCOMPARE(state1.propertyChanges().count(), 2); + QCOMPARE(state2.propertyChanges().count(), 2); + + QVERIFY(!state1.hasPropertyChanges(rootModelNode)); + + QVERIFY(state1.propertyChanges(rect1).isValid()); + QVERIFY(state1.propertyChanges(rect2).isValid()); + + state1.propertyChanges(rect2).modelNode().hasProperty("x"); + + QCOMPARE(QmlItemNode(rect1).allAffectingStates().count(), 2); + QCOMPARE(QmlItemNode(rect2).allAffectingStates().count(), 2); + QCOMPARE(QmlItemNode(rootModelNode).allAffectingStates().count(), 0); + QCOMPARE(QmlItemNode(rect1).allAffectingStatesOperations().count(), 2); + QCOMPARE(QmlItemNode(rect2).allAffectingStatesOperations().count(), 2); +} + void tst_TestCore::testModelBasicOperations() { - QSKIP("Fix MetaInfo", SkipAll); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Flipable")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -1299,8 +1456,8 @@ void tst_TestCore::testModelBasicOperations() QVERIFY(!rootModelNode.hasProperty("width")); QVERIFY(!rootModelNode.hasProperty("children")); - ModelNode childNode1(addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "children")); - ModelNode childNode2(addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data")); + ModelNode childNode1(addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "children")); + ModelNode childNode2(addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data")); QVERIFY(childNode1.isValid()); QVERIFY(childNode2.isValid()); @@ -1338,7 +1495,7 @@ void tst_TestCore::testModelBasicOperations() void tst_TestCore::testModelResolveIds() { - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -1348,47 +1505,47 @@ void tst_TestCore::testModelResolveIds() ModelNode rootNode = view->rootModelNode(); rootNode.setId("rootNode"); - ModelNode childNode1(addNodeListChild(rootNode, "Qt/Rectangle", 4, 7, "children")); + ModelNode childNode1(addNodeListChild(rootNode, "QtQuick.Rectangle", 1, 0, "children")); - ModelNode childNode2(addNodeListChild(childNode1, "Qt/Rectangle", 4, 7, "children")); + ModelNode childNode2(addNodeListChild(childNode1, "QtQuick.Flipable", 1, 0, "children")); childNode2.setId("childNode2"); - childNode2.bindingProperty("test").setExpression("parent.parent"); + childNode2.bindingProperty("anchors.fill").setExpression("parent.parent"); - QCOMPARE(childNode2.bindingProperty("test").resolveToModelNode(), rootNode); + QCOMPARE(childNode2.bindingProperty("anchors.fill").resolveToModelNode(), rootNode); childNode1.setId("childNode1"); - childNode2.bindingProperty("test").setExpression("childNode1.parent"); - QCOMPARE(childNode2.bindingProperty("test").resolveToModelNode(), rootNode); - childNode2.bindingProperty("test").setExpression("rootNode"); - QCOMPARE(childNode2.bindingProperty("test").resolveToModelNode(), rootNode); + childNode2.bindingProperty("anchors.fill").setExpression("childNode1.parent"); + QCOMPARE(childNode2.bindingProperty("anchors.fill").resolveToModelNode(), rootNode); + childNode2.bindingProperty("anchors.fill").setExpression("rootNode"); + QCOMPARE(childNode2.bindingProperty("anchors.fill").resolveToModelNode(), rootNode); - ModelNode childNode3(addNodeListChild(childNode2, "Qt/Rectangle", 4, 7, "children")); + ModelNode childNode3(addNodeListChild(childNode2, "QtQuick.Rectangle", 1, 0, "children")); childNode3.setId("childNode3"); childNode2.nodeProperty("front").setModelNode(childNode3); - childNode2.bindingProperty("test").setExpression("childNode3.parent"); - QCOMPARE(childNode2.bindingProperty("test").resolveToModelNode(), childNode2); - childNode2.bindingProperty("test").setExpression("childNode3.parent.parent"); - QCOMPARE(childNode2.bindingProperty("test").resolveToModelNode(), childNode1); - childNode2.bindingProperty("test").setExpression("childNode3.parent.parent.parent"); - QCOMPARE(childNode2.bindingProperty("test").resolveToModelNode(), rootNode); - childNode2.bindingProperty("test").setExpression("childNode3"); - QCOMPARE(childNode2.bindingProperty("test").resolveToModelNode(), childNode3); - childNode2.bindingProperty("test").setExpression("front"); - QCOMPARE(childNode2.bindingProperty("test").resolveToModelNode(), childNode3); - childNode2.bindingProperty("test").setExpression("back"); - QVERIFY(!childNode2.bindingProperty("test").resolveToModelNode().isValid()); - childNode2.bindingProperty("test").setExpression("childNode3.parent.front"); - QCOMPARE(childNode2.bindingProperty("test").resolveToModelNode(), childNode3); + childNode2.bindingProperty("anchors.fill").setExpression("childNode3.parent"); + QCOMPARE(childNode2.bindingProperty("anchors.fill").resolveToModelNode(), childNode2); + childNode2.bindingProperty("anchors.fill").setExpression("childNode3.parent.parent"); + QCOMPARE(childNode2.bindingProperty("anchors.fill").resolveToModelNode(), childNode1); + childNode2.bindingProperty("anchors.fill").setExpression("childNode3.parent.parent.parent"); + QCOMPARE(childNode2.bindingProperty("anchors.fill").resolveToModelNode(), rootNode); + childNode2.bindingProperty("anchors.fill").setExpression("childNode3"); + QCOMPARE(childNode2.bindingProperty("anchors.fill").resolveToModelNode(), childNode3); + childNode2.bindingProperty("anchors.fill").setExpression("front"); + QCOMPARE(childNode2.bindingProperty("anchors.fill").resolveToModelNode(), childNode3); + childNode2.bindingProperty("anchors.fill").setExpression("back"); + QVERIFY(!childNode2.bindingProperty("anchors.fill").resolveToModelNode().isValid()); + childNode2.bindingProperty("anchors.fill").setExpression("childNode3.parent.front"); + QCOMPARE(childNode2.bindingProperty("anchors.fill").resolveToModelNode(), childNode3); childNode2.variantProperty("x") = 10; QCOMPARE(childNode2.variantProperty("x").value().toInt(), 10); - childNode2.bindingProperty("test").setExpression("childNode3.parent.x"); - QVERIFY(childNode2.bindingProperty("test").resolveToProperty().isVariantProperty()); - QCOMPARE(childNode2.bindingProperty("test").resolveToProperty().toVariantProperty().value().toInt(), 10); + childNode2.bindingProperty("width").setExpression("childNode3.parent.x"); + QVERIFY(childNode2.bindingProperty("width").resolveToProperty().isVariantProperty()); + QCOMPARE(childNode2.bindingProperty("width").resolveToProperty().toVariantProperty().value().toInt(), 10); - childNode2.bindingProperty("test").setExpression("childNode3.parent.test"); - QVERIFY(childNode2.bindingProperty("test").resolveToProperty().isBindingProperty()); - QCOMPARE(childNode2.bindingProperty("test").resolveToProperty().toBindingProperty().expression(), QString("childNode3.parent.test")); + childNode2.bindingProperty("width").setExpression("childNode3.parent.width"); + QVERIFY(childNode2.bindingProperty("width").resolveToProperty().isBindingProperty()); + QCOMPARE(childNode2.bindingProperty("width").resolveToProperty().toBindingProperty().expression(), QString("childNode3.parent.width")); } void tst_TestCore::testModelNodeListProperty() @@ -1396,7 +1553,7 @@ void tst_TestCore::testModelNodeListProperty() // // Test NodeListProperty API // - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -1414,7 +1571,7 @@ void tst_TestCore::testModelNodeListProperty() QVERIFY(!rootChildren.isNodeListProperty()); QVERIFY(rootChildren.isEmpty()); - ModelNode rectNode = view->createModelNode("Qt/Rectangle", 4, 7); + ModelNode rectNode = view->createModelNode("QtQuick.Rectangle", 1, 0); rootChildren.reparentHere(rectNode); // @@ -1425,7 +1582,7 @@ void tst_TestCore::testModelNodeListProperty() QVERIFY(rootChildren.isNodeListProperty()); QVERIFY(!rootChildren.isEmpty()); - ModelNode mouseAreaNode = view->createModelNode("Qt/Item", 4, 7); + ModelNode mouseAreaNode = view->createModelNode("QtQuick.Item", 1, 1); NodeListProperty rectChildren = rectNode.nodeListProperty("children"); rectChildren.reparentHere(mouseAreaNode); @@ -1453,7 +1610,7 @@ void tst_TestCore::testModelNodeListProperty() void tst_TestCore::testBasicOperationsWithView() { - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -1467,10 +1624,6 @@ void tst_TestCore::testBasicOperationsWithView() QCOMPARE(rootModelNode.allDirectSubModelNodes().count(), 0); NodeInstance rootInstance = nodeInstanceView->instanceForNode(rootModelNode); - // no width, height specified implicitly is set to 100x100 - QCOMPARE(rootInstance.size().width(), 100.0); - QCOMPARE(rootInstance.size().height(), 100.0); - QVERIFY(rootInstance.isValid()); QVERIFY(rootModelNode.isValid()); @@ -1484,8 +1637,8 @@ void tst_TestCore::testBasicOperationsWithView() QCOMPARE(rootInstance.size().width(), 10.0); QCOMPARE(rootInstance.size().height(), 10.0); - ModelNode childNode(addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data")); - ModelNode childNode2(addNodeListChild(childNode, "Qt/Rectangle", 4, 7, "data")); + ModelNode childNode(addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data")); + ModelNode childNode2(addNodeListChild(childNode, "QtQuick.Rectangle", 1, 0, "data")); QVERIFY(childNode2.parentProperty().parentModelNode() == childNode); QVERIFY(childNode.isValid()); @@ -1519,10 +1672,10 @@ void tst_TestCore::testBasicOperationsWithView() QVERIFY(!childInstance2.isValid()); } - childNode = addNodeListChild(rootModelNode, "Qt/Image", 4, 7, "data"); + childNode = addNodeListChild(rootModelNode, "QtQuick.Image", 1, 0, "data"); QVERIFY(childNode.isValid()); - QCOMPARE(childNode.type(), QString("Qt/Image")); - childNode2 = addNodeListChild(childNode, "Qt/Rectangle", 4, 7, "data"); + QCOMPARE(childNode.type(), QString("QtQuick.Image")); + childNode2 = addNodeListChild(childNode, "QtQuick.Rectangle", 1, 0, "data"); QVERIFY(childNode2.isValid()); childNode2.setParentProperty(rootModelNode, "data"); QVERIFY(childNode2.isValid()); @@ -1560,7 +1713,7 @@ void tst_TestCore::testBasicOperationsWithView() void tst_TestCore::testQmlModelView() { - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); QmlModelView *view = new TestView(model.data()); @@ -1578,7 +1731,7 @@ void tst_TestCore::testQmlModelView() propertyList.append(qMakePair(QString("width"), QVariant(20))); propertyList.append(qMakePair(QString("height"), QVariant(20))); - QmlObjectNode node1 = view->createQmlObjectNode("Qt/Rectangle", 4, 7, propertyList); + QmlObjectNode node1 = view->createQmlObjectNode("QtQuick.Rectangle", 1, 0, propertyList); QVERIFY(node1.isValid()); QVERIFY(!node1.hasNodeParent()); @@ -1594,7 +1747,7 @@ void tst_TestCore::testQmlModelView() QVERIFY(node1.instanceParent() == view->rootQmlObjectNode()); - QmlObjectNode node2 = view->createQmlObjectNode("Qt/Rectangle", 4, 7, propertyList); + QmlObjectNode node2 = view->createQmlObjectNode("QtQuick.Rectangle", 1, 0, propertyList); QVERIFY(node2.isValid()); QVERIFY(!node2.hasNodeParent()); @@ -1622,12 +1775,12 @@ void tst_TestCore::testQmlModelView() QCOMPARE(node1.instanceValue("x").toInt(), 2); - QmlObjectNode node3 = view->createQmlObjectNode("Qt/Rectangle", 4, 7, propertyList); - QmlObjectNode node4 = view->createQmlObjectNode("Qt/Rectangle", 4, 7, propertyList); - QmlObjectNode node5 = view->createQmlObjectNode("Qt/Rectangle", 4, 7, propertyList); - QmlObjectNode node6 = view->createQmlObjectNode("Qt/Rectangle", 4, 7, propertyList); - QmlObjectNode node7 = view->createQmlObjectNode("Qt/Rectangle", 4, 7, propertyList); - QmlObjectNode node8 = view->createQmlObjectNode("Qt/Rectangle", 4, 7, propertyList); + QmlObjectNode node3 = view->createQmlObjectNode("QtQuick.Rectangle", 1, 0, propertyList); + QmlObjectNode node4 = view->createQmlObjectNode("QtQuick.Rectangle", 1, 0, propertyList); + QmlObjectNode node5 = view->createQmlObjectNode("QtQuick.Rectangle", 1, 0, propertyList); + QmlObjectNode node6 = view->createQmlObjectNode("QtQuick.Rectangle", 1, 0, propertyList); + QmlObjectNode node7 = view->createQmlObjectNode("QtQuick.Rectangle", 1, 0, propertyList); + QmlObjectNode node8 = view->createQmlObjectNode("QtQuick.Rectangle", 1, 0, propertyList); node3.setParentProperty(node2.nodeAbstractProperty("children")); node4.setParentProperty(node3.nodeAbstractProperty("children")); @@ -1655,21 +1808,20 @@ void tst_TestCore::testQmlModelView() QCOMPARE(node2.instanceValue("x").toInt(), 10); // is this right? or should it be a invalid qvariant? - node1 = view->createQmlObjectNode("Qt/Rectangle", 4, 7, propertyList); + node1 = view->createQmlObjectNode("QtQuick.Rectangle", 1, 0, propertyList); node1.setId("node1"); QCOMPARE(node2.instanceValue("x").toInt(), 20); - node3 = view->createQmlObjectNode("Qt/Rectangle", 4, 7, propertyList); + node3 = view->createQmlObjectNode("QtQuick.Rectangle", 1, 0, propertyList); node3.setParentProperty(node2.nodeAbstractProperty("children")); QCOMPARE(node3.instanceValue("width").toInt(), 20); node3.setVariantProperty("width", 0); QCOMPARE(node3.instanceValue("width").toInt(), 0); QCOMPARE(node3.instanceValue("x").toInt(), 20); - QVERIFY(!QDeclarativeMetaType::toQObject(node3.instanceValue("anchors.fill"))); + //QVERIFY(!QDeclarativeMetaType::toQObject(node3.instanceValue("anchors.fill"))); node3.setBindingProperty("anchors.fill", "parent"); - QVERIFY(QDeclarativeMetaType::toQObject(node3.instanceValue("anchors.fill"))); QCOMPARE(node3.instanceValue("x").toInt(), 0); QCOMPARE(node3.instanceValue("width").toInt(), 20); @@ -1682,7 +1834,7 @@ void tst_TestCore::testQmlModelView() void tst_TestCore::testModelRemoveNode() { - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -1695,7 +1847,7 @@ void tst_TestCore::testModelRemoveNode() QCOMPARE(view->rootModelNode().allDirectSubModelNodes().count(), 0); - ModelNode childNode = addNodeListChild(view->rootModelNode(), "Qt/Rectangle", 4, 7, "data"); + ModelNode childNode = addNodeListChild(view->rootModelNode(), "QtQuick.Rectangle", 1, 0, "data"); QVERIFY(childNode.isValid()); QCOMPARE(view->rootModelNode().allDirectSubModelNodes().count(), 1); QVERIFY(view->rootModelNode().allDirectSubModelNodes().contains(childNode)); @@ -1707,7 +1859,7 @@ void tst_TestCore::testModelRemoveNode() QVERIFY(childInstance.parentId() == view->rootModelNode().internalId()); } - ModelNode subChildNode = addNodeListChild(childNode, "Qt/Rectangle", 4, 7, "data"); + ModelNode subChildNode = addNodeListChild(childNode, "QtQuick.Rectangle", 1, 0, "data"); QVERIFY(subChildNode.isValid()); QCOMPARE(childNode.allDirectSubModelNodes().count(), 1); QVERIFY(childNode.allDirectSubModelNodes().contains(subChildNode)); @@ -1738,7 +1890,7 @@ void tst_TestCore::testModelRemoveNode() QVERIFY(view->rootModelNode().isValid()); // delete node not in hierarchy - childNode = view->createModelNode("Qt/Item", 4, 7); + childNode = view->createModelNode("QtQuick.Item", 1, 1); childNode.destroy(); model->detachView(nodeInstanceView); @@ -1746,7 +1898,7 @@ void tst_TestCore::testModelRemoveNode() void tst_TestCore::reparentingNode() { - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); @@ -1763,7 +1915,7 @@ void tst_TestCore::reparentingNode() NodeInstanceView *nodeInstanceView = new NodeInstanceView(model.data(), NodeInstanceServerInterface::TestModus); model->attachView(nodeInstanceView); - ModelNode childNode = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); + ModelNode childNode = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); QCOMPARE(childNode.parentProperty().parentModelNode(), rootModelNode); QVERIFY(rootModelNode.allDirectSubModelNodes().contains(childNode)); @@ -1773,7 +1925,7 @@ void tst_TestCore::reparentingNode() QVERIFY(childInstance.parentId() == view->rootModelNode().internalId()); } - ModelNode childNode2 = addNodeListChild(rootModelNode, "Qt/Item", 4, 7, "data"); + ModelNode childNode2 = addNodeListChild(rootModelNode, "QtQuick.Item", 1, 1, "data"); QCOMPARE(childNode2.parentProperty().parentModelNode(), rootModelNode); QVERIFY(rootModelNode.allDirectSubModelNodes().contains(childNode2)); @@ -1808,16 +1960,17 @@ void tst_TestCore::reparentingNode() QCOMPARE(childNode.parentProperty().parentModelNode(), childNode2); + QApplication::processEvents(); model->detachView(nodeInstanceView); } void tst_TestCore::reparentingNodeLikeDragAndDrop() { QPlainTextEdit textEdit; - textEdit.setPlainText("import Qt 4.7;\n\nItem {\n}\n"); + textEdit.setPlainText("import QtQuick 1.1;\n\nItem {\n}\n"); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); @@ -1833,7 +1986,7 @@ void tst_TestCore::reparentingNodeLikeDragAndDrop() view->rootModelNode().setId("rootModelNode"); QCOMPARE(view->rootModelNode().id(), QString("rootModelNode")); - ModelNode rectNode = addNodeListChild(view->rootModelNode(), "Qt/Rectangle", 4, 7, "data"); + ModelNode rectNode = addNodeListChild(view->rootModelNode(), "QtQuick.Rectangle", 1, 0, "data"); rectNode.setId("rect_1"); rectNode.variantProperty("x").setValue(20); rectNode.variantProperty("y").setValue(30); @@ -1842,7 +1995,7 @@ void tst_TestCore::reparentingNodeLikeDragAndDrop() RewriterTransaction transaction(view->beginRewriterTransaction()); - ModelNode textNode = addNodeListChild(view->rootModelNode(), "Qt/Text", 4, 7, "data"); + ModelNode textNode = addNodeListChild(view->rootModelNode(), "QtQuick.Text", 1, 1, "data"); QCOMPARE(textNode.parentProperty().parentModelNode(), view->rootModelNode()); QVERIFY(view->rootModelNode().allDirectSubModelNodes().contains(textNode)); @@ -1925,12 +2078,14 @@ void tst_TestCore::reparentingNodeLikeDragAndDrop() QCOMPARE(textNode.parentProperty().parentModelNode(), rectNode); QVERIFY(rectNode.allDirectSubModelNodes().contains(textNode)); + QApplication::processEvents(); + model->detachView(nodeInstanceView); } void tst_TestCore::testModelReorderSiblings() { - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -1943,11 +2098,11 @@ void tst_TestCore::testModelReorderSiblings() ModelNode rootModelNode = view->rootModelNode(); QVERIFY(rootModelNode.isValid()); - ModelNode a = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); + ModelNode a = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); QVERIFY(a.isValid()); - ModelNode b = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); + ModelNode b = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); QVERIFY(b.isValid()); - ModelNode c = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); + ModelNode c = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); QVERIFY(c.isValid()); { @@ -1976,12 +2131,14 @@ void tst_TestCore::testModelReorderSiblings() QVERIFY(nodeInstanceView->instanceForNode(c).parentId() == rootModelNode.internalId()); } + QApplication::processEvents(); + model->detachView(nodeInstanceView); } void tst_TestCore::testModelRootNode() { - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -1992,10 +2149,10 @@ void tst_TestCore::testModelRootNode() ModelNode rootModelNode = view->rootModelNode(); QVERIFY(rootModelNode.isValid()); QVERIFY(rootModelNode.isRootNode()); - ModelNode topChildNode = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); + ModelNode topChildNode = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); QVERIFY(topChildNode.isValid()); QVERIFY(rootModelNode.isRootNode()); - ModelNode childNode = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); + ModelNode childNode = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); QVERIFY(childNode.isValid()); QVERIFY(rootModelNode.isValid()); QVERIFY(rootModelNode.isRootNode()); @@ -2008,19 +2165,20 @@ void tst_TestCore::testModelRootNode() QString errorMsg = tr("Exception: %1 %2 %3:%4").arg(exception.type(), exception.function(), exception.file()).arg(exception.line()); QFAIL(errorMsg.toLatin1().constData()); } + QApplication::processEvents(); } void tst_TestCore::reparentingNodeInModificationGroup() { - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); QVERIFY(view.data()); model->attachView(view.data()); - ModelNode childNode = addNodeListChild(view->rootModelNode(), "Qt/Rectangle", 4, 7, "data"); - ModelNode childNode2 = addNodeListChild(view->rootModelNode(), "Qt/Item", 4, 7, "data"); + ModelNode childNode = addNodeListChild(view->rootModelNode(), "QtQuick.Rectangle", 1, 0, "data"); + ModelNode childNode2 = addNodeListChild(view->rootModelNode(), "QtQuick.Item", 1, 1, "data"); childNode.variantProperty("x").setValue(10); childNode.variantProperty("y").setValue(10); @@ -2058,11 +2216,13 @@ void tst_TestCore::reparentingNodeInModificationGroup() QCOMPARE(childNode2.parentProperty().parentModelNode(), view->rootModelNode()); QVERIFY(childNode2.isValid()); QVERIFY(view->rootModelNode().allDirectSubModelNodes().contains(childNode2)); + + QApplication::processEvents(); } void tst_TestCore::testModelAddAndRemoveProperty() { - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -2098,12 +2258,14 @@ void tst_TestCore::testModelAddAndRemoveProperty() QVERIFY(node.hasProperty("foo")); QCOMPARE(node.variantProperty("foo").value().toString(), QString("bar")); + QApplication::processEvents(); + model->detachView(nodeInstanceView); } void tst_TestCore::testModelViewNotification() { - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view1(new TestView(model.data())); @@ -2125,7 +2287,7 @@ void tst_TestCore::testModelViewNotification() QCOMPARE(view1->methodCalls(), expectedCalls); QCOMPARE(view2->methodCalls(), expectedCalls); - ModelNode childNode = addNodeListChild(view2->rootModelNode(), "Qt/Rectangle", 4, 7, "data"); + ModelNode childNode = addNodeListChild(view2->rootModelNode(), "QtQuick.Rectangle", 1, 0, "data"); expectedCalls << TestView::MethodCall("nodeCreated", QStringList() << ""); expectedCalls << TestView::MethodCall("nodeReparented", QStringList() << "" << "data" << "" << "PropertiesAdded"); QCOMPARE(view1->methodCalls(), expectedCalls); @@ -2155,7 +2317,7 @@ void tst_TestCore::testModelViewNotification() QCOMPARE(view1->methodCalls(), expectedCalls); QCOMPARE(view2->methodCalls(), expectedCalls); - childNode.bindingProperty("visible").setExpression("false"); + childNode.bindingProperty("visible").setExpression("false && true"); expectedCalls << TestView::MethodCall("propertiesAboutToBeRemoved", QStringList() << "visible"); expectedCalls << TestView::MethodCall("bindingPropertiesChanged", QStringList() << "visible" << "PropertiesAdded"); QCOMPARE(view1->methodCalls(), expectedCalls); @@ -2170,12 +2332,14 @@ void tst_TestCore::testModelViewNotification() model->detachView(view1.data()); expectedCalls << TestView::MethodCall("modelAboutToBeDetached", QStringList() << QString::number(reinterpret_cast<long>(model.data()))); QCOMPARE(view1->methodCalls(), expectedCalls); + + QApplication::processEvents(); } void tst_TestCore::testRewriterTransaction() { - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -2185,7 +2349,7 @@ void tst_TestCore::testRewriterTransaction() RewriterTransaction transaction = view->beginRewriterTransaction(); QVERIFY(transaction.isValid()); - ModelNode childNode = addNodeListChild(view->rootModelNode(), "Qt/Rectangle", 4, 7, "data"); + ModelNode childNode = addNodeListChild(view->rootModelNode(), "QtQuick.Rectangle", 1, 0, "data"); QVERIFY(childNode.isValid()); childNode.destroy(); @@ -2195,7 +2359,7 @@ void tst_TestCore::testRewriterTransaction() RewriterTransaction transaction2 = view->beginRewriterTransaction(); QVERIFY(transaction2.isValid()); - ModelNode childNode = addNodeListChild(view->rootModelNode(), "Qt/Rectangle", 4, 7, "data"); + ModelNode childNode = addNodeListChild(view->rootModelNode(), "QtQuick.Rectangle", 1, 0, "data"); QVERIFY(childNode.isValid()); childNode.destroy(); @@ -2222,7 +2386,7 @@ void tst_TestCore::testRewriterTransaction() void tst_TestCore::testRewriterId() { - char qmlString[] = "import Qt 4.7\n" + char qmlString[] = "import QtQuick 1.1\n" "Rectangle {\n" "}\n"; @@ -2230,7 +2394,7 @@ void tst_TestCore::testRewriterId() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -2245,16 +2409,16 @@ void tst_TestCore::testRewriterId() model->attachView(testRewriterView.data()); - QCOMPARE(rootModelNode.type(), QString("Qt/Rectangle")); + QCOMPARE(rootModelNode.type(), QString("QtQuick.Rectangle")); QVERIFY(rootModelNode.isValid()); - ModelNode newNode(view->createModelNode("Qt/Rectangle", 4, 7)); + ModelNode newNode(view->createModelNode("QtQuick.Rectangle", 1, 0)); newNode.setId("testId"); rootModelNode.nodeListProperty("data").reparentHere(newNode); - const QLatin1String expected("import Qt 4.7\n" + const QLatin1String expected("import QtQuick 1.1\n" "Rectangle {\n" "Rectangle {\n" " id: testId\n" @@ -2266,7 +2430,7 @@ void tst_TestCore::testRewriterId() void tst_TestCore::testRewriterNodeReparentingTransaction1() { - char qmlString[] = "import Qt 4.7\n" + char qmlString[] = "import QtQuick 1.1\n" "Rectangle {\n" "}\n"; @@ -2274,7 +2438,7 @@ void tst_TestCore::testRewriterNodeReparentingTransaction1() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -2283,7 +2447,7 @@ void tst_TestCore::testRewriterNodeReparentingTransaction1() ModelNode rootModelNode(view->rootModelNode()); QVERIFY(rootModelNode.isValid()); - QCOMPARE(rootModelNode.type(), QString("Qt/Item")); + QCOMPARE(rootModelNode.type(), QString("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); testRewriterView->setTextModifier(&textModifier); @@ -2291,12 +2455,12 @@ void tst_TestCore::testRewriterNodeReparentingTransaction1() QVERIFY(rootModelNode.isValid()); - ModelNode childNode1 = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); - ModelNode childNode2 = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); - ModelNode childNode3 = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); - ModelNode childNode4 = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); + ModelNode childNode1 = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); + ModelNode childNode2 = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); + ModelNode childNode3 = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); + ModelNode childNode4 = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); - ModelNode reparentNode = addNodeListChild(childNode1, "Qt/Rectangle", 4, 7, "data"); + ModelNode reparentNode = addNodeListChild(childNode1, "QtQuick.Rectangle", 1, 0, "data"); RewriterTransaction rewriterTransaction = view->beginRewriterTransaction(); @@ -2311,7 +2475,7 @@ void tst_TestCore::testRewriterNodeReparentingTransaction1() void tst_TestCore::testRewriterNodeReparentingTransaction2() { - char qmlString[] = "import Qt 4.7\n" + char qmlString[] = "import QtQuick 1.1\n" "Rectangle {\n" "}\n"; @@ -2319,7 +2483,7 @@ void tst_TestCore::testRewriterNodeReparentingTransaction2() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -2328,7 +2492,7 @@ void tst_TestCore::testRewriterNodeReparentingTransaction2() ModelNode rootModelNode(view->rootModelNode()); QVERIFY(rootModelNode.isValid()); - QCOMPARE(rootModelNode.type(), QString("Qt/Item")); + QCOMPARE(rootModelNode.type(), QString("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); testRewriterView->setTextModifier(&textModifier); @@ -2336,8 +2500,8 @@ void tst_TestCore::testRewriterNodeReparentingTransaction2() QVERIFY(rootModelNode.isValid()); - ModelNode childNode1 = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); - ModelNode childNode2 = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); + ModelNode childNode1 = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); + ModelNode childNode2 = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); childNode2.variantProperty("x") = 200; childNode2.variantProperty("y") = 50; @@ -2377,7 +2541,7 @@ void tst_TestCore::testRewriterNodeReparentingTransaction2() void tst_TestCore::testRewriterNodeReparentingTransaction3() { - char qmlString[] = "import Qt 4.7\n" + char qmlString[] = "import QtQuick 1.1\n" "Rectangle {\n" "}\n"; @@ -2385,7 +2549,7 @@ void tst_TestCore::testRewriterNodeReparentingTransaction3() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -2394,7 +2558,7 @@ void tst_TestCore::testRewriterNodeReparentingTransaction3() ModelNode rootModelNode(view->rootModelNode()); QVERIFY(rootModelNode.isValid()); - QCOMPARE(rootModelNode.type(), QString("Qt/Item")); + QCOMPARE(rootModelNode.type(), QString("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); testRewriterView->setTextModifier(&textModifier); @@ -2402,10 +2566,10 @@ void tst_TestCore::testRewriterNodeReparentingTransaction3() QVERIFY(rootModelNode.isValid()); - ModelNode childNode1 = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); - ModelNode childNode2 = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); - ModelNode childNode3 = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); - ModelNode childNode4 = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); + ModelNode childNode1 = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); + ModelNode childNode2 = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); + ModelNode childNode3 = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); + ModelNode childNode4 = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); RewriterTransaction rewriterTransaction = view->beginRewriterTransaction(); @@ -2427,7 +2591,7 @@ void tst_TestCore::testRewriterNodeReparentingTransaction3() void tst_TestCore::testRewriterNodeReparentingTransaction4() { - char qmlString[] = "import Qt 4.7\n" + char qmlString[] = "import QtQuick 1.1\n" "Rectangle {\n" "}\n"; @@ -2435,7 +2599,7 @@ void tst_TestCore::testRewriterNodeReparentingTransaction4() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -2444,7 +2608,7 @@ void tst_TestCore::testRewriterNodeReparentingTransaction4() ModelNode rootModelNode(view->rootModelNode()); QVERIFY(rootModelNode.isValid()); - QCOMPARE(rootModelNode.type(), QString("Qt/Item")); + QCOMPARE(rootModelNode.type(), QString("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); testRewriterView->setTextModifier(&textModifier); @@ -2452,11 +2616,11 @@ void tst_TestCore::testRewriterNodeReparentingTransaction4() QVERIFY(rootModelNode.isValid()); - ModelNode childNode1 = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); - ModelNode childNode2 = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); - ModelNode childNode3 = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); - ModelNode childNode4 = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); - ModelNode childNode5 = addNodeListChild(childNode2, "Qt/Rectangle", 4, 7, "data"); + ModelNode childNode1 = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); + ModelNode childNode2 = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); + ModelNode childNode3 = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); + ModelNode childNode4 = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); + ModelNode childNode5 = addNodeListChild(childNode2, "QtQuick.Rectangle", 1, 0, "data"); RewriterTransaction rewriterTransaction = view->beginRewriterTransaction(); @@ -2478,7 +2642,7 @@ void tst_TestCore::testRewriterNodeReparentingTransaction4() void tst_TestCore::testRewriterAddNodeTransaction() { - char qmlString[] = "import Qt 4.7\n" + char qmlString[] = "import QtQuick 1.1\n" "Rectangle {\n" "}\n"; @@ -2486,7 +2650,7 @@ void tst_TestCore::testRewriterAddNodeTransaction() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -2495,7 +2659,7 @@ void tst_TestCore::testRewriterAddNodeTransaction() ModelNode rootModelNode(view->rootModelNode()); QVERIFY(rootModelNode.isValid()); - QCOMPARE(rootModelNode.type(), QString("Qt/Item")); + QCOMPARE(rootModelNode.type(), QString("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); testRewriterView->setTextModifier(&textModifier); @@ -2504,11 +2668,11 @@ void tst_TestCore::testRewriterAddNodeTransaction() QVERIFY(rootModelNode.isValid()); - ModelNode childNode = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); + ModelNode childNode = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); RewriterTransaction rewriterTransaction = view->beginRewriterTransaction(); - ModelNode newNode = view->createModelNode("Qt/Rectangle", 4, 7); + ModelNode newNode = view->createModelNode("QtQuick.Rectangle", 1, 0); newNode.variantProperty("x") = 100; newNode.variantProperty("y") = 100; @@ -2520,7 +2684,7 @@ void tst_TestCore::testRewriterAddNodeTransaction() void tst_TestCore::testRewriterComponentId() { - char qmlString[] = "import Qt 4.7\n" + char qmlString[] = "import QtQuick 1.1\n" "Rectangle {\n" " Component {\n" " id: testComponent\n" @@ -2533,7 +2697,7 @@ void tst_TestCore::testRewriterComponentId() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -2546,17 +2710,17 @@ void tst_TestCore::testRewriterComponentId() ModelNode rootModelNode(view->rootModelNode()); QVERIFY(rootModelNode.isValid()); - QCOMPARE(rootModelNode.type(), QString("Qt/Rectangle")); + QCOMPARE(rootModelNode.type(), QString("QtQuick.Rectangle")); ModelNode component(rootModelNode.allDirectSubModelNodes().first()); QVERIFY(component.isValid()); - QCOMPARE(component.type(), QString("Qt/Component")); + QCOMPARE(component.type(), QString("QtQuick.Component")); QCOMPARE(component.id(), QString("testComponent")); } void tst_TestCore::testRewriterTransactionRewriter() { - char qmlString[] = "import Qt 4.7\n" + char qmlString[] = "import QtQuick 1.1\n" "Rectangle {\n" "}\n"; @@ -2564,7 +2728,7 @@ void tst_TestCore::testRewriterTransactionRewriter() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -2573,7 +2737,7 @@ void tst_TestCore::testRewriterTransactionRewriter() ModelNode rootModelNode(view->rootModelNode()); QVERIFY(rootModelNode.isValid()); - QCOMPARE(rootModelNode.type(), QString("Qt/Item")); + QCOMPARE(rootModelNode.type(), QString("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); testRewriterView->setTextModifier(&textModifier); @@ -2586,7 +2750,7 @@ void tst_TestCore::testRewriterTransactionRewriter() { RewriterTransaction transaction = view->beginRewriterTransaction(); - childNode1 = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); + childNode1 = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); childNode1.variantProperty("x") = 10; childNode1.variantProperty("y") = 10; } @@ -2598,7 +2762,7 @@ void tst_TestCore::testRewriterTransactionRewriter() { RewriterTransaction transaction = view->beginRewriterTransaction(); - childNode2 = addNodeListChild(childNode1, "Qt/Rectangle", 4, 7, "data"); + childNode2 = addNodeListChild(childNode1, "QtQuick.Rectangle", 1, 0, "data"); childNode2.destroy(); } @@ -2623,7 +2787,7 @@ void tst_TestCore::testRewriterPropertyDeclarations() // property variant myArray: [ Rectangle {} ] // property variant someGradient: Gradient {} - char qmlString[] = "import Qt 4.7\n" + char qmlString[] = "import QtQuick 1.1\n" "Item {\n" " property int intProperty\n" " property bool boolProperty: true\n" @@ -2636,7 +2800,7 @@ void tst_TestCore::testRewriterPropertyDeclarations() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -2654,7 +2818,7 @@ void tst_TestCore::testRewriterPropertyDeclarations() // ModelNode rootModelNode(view->rootModelNode()); QVERIFY(rootModelNode.isValid()); - QCOMPARE(rootModelNode.type(), QString("Qt/Item")); + QCOMPARE(rootModelNode.type(), QString("QtQuick.Item")); QCOMPARE(rootModelNode.properties().size(), 4); @@ -2687,7 +2851,7 @@ void tst_TestCore::testRewriterPropertyAliases() // where type is (int | bool | double | real | string | url | color | date | variant) // - char qmlString[] = "import Qt 4.7\n" + char qmlString[] = "import QtQuick 1.1\n" "Item {\n" " property alias theText: t.text\n" " default alias property yPos: t.y\n" @@ -2698,7 +2862,7 @@ void tst_TestCore::testRewriterPropertyAliases() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -2711,7 +2875,7 @@ void tst_TestCore::testRewriterPropertyAliases() ModelNode rootModelNode(view->rootModelNode()); QVERIFY(rootModelNode.isValid()); - QCOMPARE(rootModelNode.type(), QString("Qt/Item")); + QCOMPARE(rootModelNode.type(), QString("QtQuick.Item")); QList<AbstractProperty> properties = rootModelNode.properties(); QCOMPARE(properties.size(), 0); // TODO: How to represent alias properties? As Bindings? @@ -2720,7 +2884,7 @@ void tst_TestCore::testRewriterPropertyAliases() void tst_TestCore::testRewriterPositionAndOffset() { const QLatin1String qmlString("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " id: root\n" @@ -2758,7 +2922,7 @@ void tst_TestCore::testRewriterPositionAndOffset() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -2771,7 +2935,7 @@ void tst_TestCore::testRewriterPositionAndOffset() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QLatin1String("Qt/Rectangle")); + QCOMPARE(rootNode.type(), QLatin1String("QtQuick.Rectangle")); QString string = QString(qmlString).mid(testRewriterView->nodeOffset(rootNode), testRewriterView->nodeLength(rootNode)); const QString qmlExpected0("Rectangle {\n" @@ -2837,7 +3001,7 @@ void tst_TestCore::testRewriterPositionAndOffset() void tst_TestCore::testRewriterComponentTextModifier() { - const QString qmlString("import Qt 4.7\n" + const QString qmlString("import QtQuick 1.1\n" "Rectangle {\n" " id: root\n" " x: 10;\n" @@ -2860,7 +3024,7 @@ void tst_TestCore::testRewriterComponentTextModifier() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -2873,7 +3037,7 @@ void tst_TestCore::testRewriterComponentTextModifier() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QLatin1String("Qt/Rectangle")); + QCOMPARE(rootNode.type(), QLatin1String("QtQuick.Rectangle")); ModelNode componentNode = rootNode.allDirectSubModelNodes().last(); @@ -2884,7 +3048,7 @@ void tst_TestCore::testRewriterComponentTextModifier() ComponentTextModifier componentTextModifier(&textModifier, componentStartOffset, componentEndOffset, rootStartOffset); - const QString qmlExpected("import Qt 4.7\n" + const QString qmlExpected("import QtQuick 1.1\n" " " " " " " @@ -2905,19 +3069,20 @@ void tst_TestCore::testRewriterComponentTextModifier() QCOMPARE(componentTextModifier.text(), qmlExpected); - QScopedPointer<Model> componentModel(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> componentModel(Model::create("QtQuick.Item", 1, 1)); QScopedPointer<TestRewriterView> testRewriterViewComponent(new TestRewriterView()); testRewriterViewComponent->setTextModifier(&componentTextModifier); componentModel->attachView(testRewriterViewComponent.data()); ModelNode componentrootNode = testRewriterViewComponent->rootModelNode(); QVERIFY(componentrootNode.isValid()); - QCOMPARE(componentrootNode.type(), QLatin1String("Qt/Component")); + //The <Component> node is skipped + QCOMPARE(componentrootNode.type(), QLatin1String("QtQuick.Rectangle")); } void tst_TestCore::testRewriterPreserveType() { - const QString qmlString("import Qt 4.7\n" + const QString qmlString("import QtQuick 1.1\n" "Rectangle {\n" " id: root\n" " Text {\n" @@ -2930,7 +3095,7 @@ void tst_TestCore::testRewriterPreserveType() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -2943,7 +3108,7 @@ void tst_TestCore::testRewriterPreserveType() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QLatin1String("Qt/Rectangle")); + QCOMPARE(rootNode.type(), QLatin1String("QtQuick.Rectangle")); ModelNode textNode = rootNode.allDirectSubModelNodes().first(); QCOMPARE(QVariant::Bool, textNode.variantProperty("font.bold").value().type()); @@ -2952,7 +3117,7 @@ void tst_TestCore::testRewriterPreserveType() textNode.variantProperty("font.bold") = QVariant(true); textNode.variantProperty("font.pointSize") = QVariant(13.0); - ModelNode newTextNode = addNodeListChild(rootNode, "Qt/Text", 4, 7, "data"); + ModelNode newTextNode = addNodeListChild(rootNode, "QtQuick.Text", 1, 1, "data"); newTextNode.variantProperty("font.bold") = QVariant(true); newTextNode.variantProperty("font.pointSize") = QVariant(13.0); @@ -2964,7 +3129,7 @@ void tst_TestCore::testRewriterPreserveType() void tst_TestCore::testRewriterForArrayMagic() { try { - const QLatin1String qmlString("import Qt 4.7\n" + const QLatin1String qmlString("import QtQuick 1.1\n" "\n" "Rectangle {\n" " states: State {\n" @@ -2975,7 +3140,7 @@ void tst_TestCore::testRewriterForArrayMagic() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -2988,16 +3153,16 @@ void tst_TestCore::testRewriterForArrayMagic() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QString("Qt/Rectangle")); + QCOMPARE(rootNode.type(), QString("QtQuick.Rectangle")); QVERIFY(rootNode.property(QLatin1String("states")).isNodeListProperty()); QmlItemNode rootItem(rootNode); QVERIFY(rootItem.isValid()); QmlModelState state1(rootItem.states().addState("s2")); - QCOMPARE(state1.modelNode().type(), QString("Qt/State")); + QCOMPARE(state1.modelNode().type(), QString("QtQuick.State")); - const QLatin1String expected("import Qt 4.7\n" + const QLatin1String expected("import QtQuick 1.1\n" "\n" "Rectangle {\n" " states: [\n" @@ -3018,7 +3183,7 @@ void tst_TestCore::testRewriterForArrayMagic() void tst_TestCore::testRewriterWithSignals() { - const QLatin1String qmlString("import Qt 4.7\n" + const QLatin1String qmlString("import QtQuick 1.1\n" "\n" "TextEdit {\n" " onTextChanged: { print(\"foo\"); }\n" @@ -3027,7 +3192,7 @@ void tst_TestCore::testRewriterWithSignals() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -3040,7 +3205,7 @@ void tst_TestCore::testRewriterWithSignals() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QString("Qt/TextEdit")); + QCOMPARE(rootNode.type(), QString("QtQuick.TextEdit")); QmlItemNode rootItem(rootNode); QVERIFY(rootItem.isValid()); @@ -3050,7 +3215,7 @@ void tst_TestCore::testRewriterWithSignals() void tst_TestCore::testRewriterNodeSliding() { - const QLatin1String qmlString("import Qt 4.7\n" + const QLatin1String qmlString("import QtQuick 1.1\n" "Rectangle {\n" " id: root\n" " Rectangle {\n" @@ -3070,7 +3235,7 @@ void tst_TestCore::testRewriterNodeSliding() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -3083,7 +3248,7 @@ void tst_TestCore::testRewriterNodeSliding() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QLatin1String("Qt/Rectangle")); + QCOMPARE(rootNode.type(), QLatin1String("QtQuick.Rectangle")); QCOMPARE(rootNode.id(), QLatin1String("root")); QCOMPARE(rootNode.nodeListProperty(QLatin1String("data")).toModelNodeList().at(0).id(), QLatin1String("rectangle1")); @@ -3102,7 +3267,7 @@ void tst_TestCore::testRewriterNodeSliding() void tst_TestCore::testRewriterExceptionHandling() { - const QLatin1String qmlString("import Qt 4.7\n" + const QLatin1String qmlString("import QtQuick 1.1\n" "Text {\n" "}"); @@ -3110,7 +3275,7 @@ void tst_TestCore::testRewriterExceptionHandling() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Text", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Text", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -3123,7 +3288,7 @@ void tst_TestCore::testRewriterExceptionHandling() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QLatin1String("Qt/Text")); + QCOMPARE(rootNode.type(), QLatin1String("QtQuick.Text")); try { @@ -3132,9 +3297,9 @@ void tst_TestCore::testRewriterExceptionHandling() rootNode.variantProperty("bla") = QVariant("blah"); transaction.commit(); QFAIL("RewritingException should be thrown"); - } catch (RewritingException &e) { + } catch (RewritingException &) { QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QLatin1String("Qt/Text")); + QCOMPARE(rootNode.type(), QLatin1String("QtQuick.Text")); QVERIFY(!rootNode.hasProperty("bla")); QVERIFY(!rootNode.hasProperty("text")); } @@ -3142,7 +3307,7 @@ void tst_TestCore::testRewriterExceptionHandling() void tst_TestCore::testRewriterFirstDefinitionInside() { - const QString qmlString("import Qt 4.7\n" + const QString qmlString("import QtQuick 1.1\n" "Rectangle {\n" " id: root\n" " x: 10;\n" @@ -3166,7 +3331,7 @@ void tst_TestCore::testRewriterFirstDefinitionInside() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -3179,7 +3344,7 @@ void tst_TestCore::testRewriterFirstDefinitionInside() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QLatin1String("Qt/Rectangle")); + QCOMPARE(rootNode.type(), QLatin1String("QtQuick.Rectangle")); ModelNode componentNode = rootNode.allDirectSubModelNodes().last(); @@ -3198,7 +3363,7 @@ void tst_TestCore::testRewriterFirstDefinitionInside() void tst_TestCore::testCopyModelRewriter1() { const QLatin1String qmlString("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " id: root\n" @@ -3236,7 +3401,7 @@ void tst_TestCore::testCopyModelRewriter1() textEdit1.setPlainText(qmlString); NotIndentingTextEditModifier textModifier1(&textEdit1); - QScopedPointer<Model> model1(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model1(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model1.data()); QScopedPointer<TestView> view1(new TestView(model1.data())); @@ -3249,13 +3414,13 @@ void tst_TestCore::testCopyModelRewriter1() ModelNode rootNode1 = view1->rootModelNode(); QVERIFY(rootNode1.isValid()); - QCOMPARE(rootNode1.type(), QLatin1String("Qt/Rectangle")); + QCOMPARE(rootNode1.type(), QLatin1String("QtQuick.Rectangle")); QPlainTextEdit textEdit2; textEdit2.setPlainText(qmlString); NotIndentingTextEditModifier textModifier2(&textEdit2); - QScopedPointer<Model> model2(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model2(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model2.data()); QScopedPointer<TestView> view2(new TestView(model2.data())); @@ -3268,7 +3433,7 @@ void tst_TestCore::testCopyModelRewriter1() ModelNode rootNode2 = view2->rootModelNode(); QVERIFY(rootNode2.isValid()); - QCOMPARE(rootNode2.type(), QLatin1String("Qt/Rectangle")); + QCOMPARE(rootNode2.type(), QLatin1String("QtQuick.Rectangle")); // @@ -3293,7 +3458,7 @@ void tst_TestCore::testCopyModelRewriter1() const QLatin1String expected( "\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " id: root\n" @@ -3368,7 +3533,7 @@ void tst_TestCore::testCopyModelRewriter1() void tst_TestCore::testCopyModelRewriter2() { const QLatin1String qmlString1("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" "id: root\n" @@ -3408,7 +3573,7 @@ void tst_TestCore::testCopyModelRewriter2() const QLatin1String qmlString2("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" "}"); @@ -3417,7 +3582,7 @@ void tst_TestCore::testCopyModelRewriter2() textEdit1.setPlainText(qmlString1); NotIndentingTextEditModifier textModifier1(&textEdit1); - QScopedPointer<Model> model1(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model1(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model1.data()); QScopedPointer<TestView> view1(new TestView(model1.data())); @@ -3430,7 +3595,7 @@ void tst_TestCore::testCopyModelRewriter2() ModelNode rootNode1 = view1->rootModelNode(); QVERIFY(rootNode1.isValid()); - QCOMPARE(rootNode1.type(), QLatin1String("Qt/Rectangle")); + QCOMPARE(rootNode1.type(), QLatin1String("QtQuick.Rectangle")); // read in 2 @@ -3439,7 +3604,7 @@ void tst_TestCore::testCopyModelRewriter2() textEdit2.setPlainText(qmlString2); NotIndentingTextEditModifier textModifier2(&textEdit2); - QScopedPointer<Model> model2(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model2(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model2.data()); QScopedPointer<TestView> view2(new TestView(model2.data())); @@ -3451,7 +3616,7 @@ void tst_TestCore::testCopyModelRewriter2() ModelNode rootNode2 = view2->rootModelNode(); QVERIFY(rootNode2.isValid()); - QCOMPARE(rootNode2.type(), QLatin1String("Qt/Rectangle")); + QCOMPARE(rootNode2.type(), QLatin1String("QtQuick.Rectangle")); // @@ -3460,7 +3625,7 @@ void tst_TestCore::testCopyModelRewriter2() merger.replaceModel(rootNode1); QVERIFY(rootNode2.isValid()); - QCOMPARE(rootNode2.type(), QLatin1String("Qt/Rectangle")); + QCOMPARE(rootNode2.type(), QLatin1String("QtQuick.Rectangle")); QCOMPARE(textEdit2.toPlainText(), qmlString1); } @@ -3475,9 +3640,9 @@ void tst_TestCore::testSubComponentManager() textEdit.setPlainText(file.readAll()); NotIndentingTextEditModifier modifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); model->setFileUrl(QUrl::fromLocalFile(fileName)); - QScopedPointer<SubComponentManager> subComponentManager(new SubComponentManager(model->metaInfo(), 0)); + QScopedPointer<SubComponentManager> subComponentManager(new SubComponentManager(model.data())); subComponentManager->update(QUrl::fromLocalFile(fileName), model->imports()); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); @@ -3489,9 +3654,9 @@ void tst_TestCore::testSubComponentManager() QVERIFY(testRewriterView->rootModelNode().isValid()); - QVERIFY(model->metaInfo("Qt/Rectangle").propertyNames().contains("border.width")); + QVERIFY(model->metaInfo("QtQuick.Rectangle").propertyNames().contains("border.width")); - QVERIFY(model->metaInfo("Qt/Pen").isValid()); + QVERIFY(model->metaInfo("<cpp>.QDeclarative1Pen").isValid()); NodeMetaInfo myButtonMetaInfo = model->metaInfo("MyButton"); QVERIFY(myButtonMetaInfo.isValid()); QVERIFY(myButtonMetaInfo.propertyNames().contains("border.width")); @@ -3500,7 +3665,7 @@ void tst_TestCore::testSubComponentManager() void tst_TestCore::testAnchorsAndRewriting() { - const QString qmlString("import Qt 4.7\n" + const QString qmlString("import QtQuick 1.1\n" "Rectangle {\n" " id: root\n" " x: 10;\n" @@ -3523,7 +3688,7 @@ void tst_TestCore::testAnchorsAndRewriting() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -3536,7 +3701,7 @@ void tst_TestCore::testAnchorsAndRewriting() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QLatin1String("Qt/Rectangle")); + QCOMPARE(rootNode.type(), QLatin1String("QtQuick.Rectangle")); QmlItemNode rootItemNode = view->rootQmlItemNode(); QVERIFY(rootItemNode.isValid()); @@ -3561,7 +3726,7 @@ void tst_TestCore::testAnchorsAndRewriting() void tst_TestCore::testAnchorsAndRewritingCenter() { - const QString qmlString("import Qt 4.7\n" + const QString qmlString("import QtQuick 1.1\n" "Rectangle {\n" " id: root\n" " x: 10;\n" @@ -3584,7 +3749,7 @@ void tst_TestCore::testAnchorsAndRewritingCenter() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -3597,7 +3762,7 @@ void tst_TestCore::testAnchorsAndRewritingCenter() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QLatin1String("Qt/Rectangle")); + QCOMPARE(rootNode.type(), QLatin1String("QtQuick.Rectangle")); QmlItemNode rootItemNode = view->rootQmlItemNode(); QVERIFY(rootItemNode.isValid()); @@ -3611,7 +3776,7 @@ void tst_TestCore::testAnchorsAndRewritingCenter() void tst_TestCore::loadQml() { -char qmlString[] = "import Qt 4.7\n" +char qmlString[] = "import QtQuick 1.1\n" "Rectangle {\n" "id: root;\n" "width: 200;\n" @@ -3652,7 +3817,7 @@ char qmlString[] = "import Qt 4.7\n" textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -3661,14 +3826,14 @@ char qmlString[] = "import Qt 4.7\n" ModelNode rootModelNode(view->rootModelNode()); QVERIFY(rootModelNode.isValid()); - QCOMPARE(rootModelNode.type(), QString("Qt/Item")); + QCOMPARE(rootModelNode.type(), QString("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); testRewriterView->setTextModifier(&textModifier); model->attachView(testRewriterView.data()); QVERIFY(rootModelNode.isValid()); - QCOMPARE(rootModelNode.type(), QString("Qt/Rectangle")); + QCOMPARE(rootModelNode.type(), QString("QtQuick.Rectangle")); QCOMPARE(rootModelNode.id(), QString("root")); QCOMPARE(rootModelNode.variantProperty("width").value().toInt(), 200); QCOMPARE(rootModelNode.variantProperty("height").value().toInt(), 200); @@ -3678,7 +3843,7 @@ char qmlString[] = "import Qt 4.7\n" QCOMPARE(rootModelNode.nodeListProperty("data").toModelNodeList().count(), 3); ModelNode textNode1 = rootModelNode.nodeListProperty("data").toModelNodeList().first(); QVERIFY(textNode1.isValid()); - QCOMPARE(textNode1.type(), QString("Qt/Text")); + QCOMPARE(textNode1.type(), QString("QtQuick.Text")); QCOMPARE(textNode1.id(), QString("text1")); QCOMPARE(textNode1.variantProperty("text").value().toString(), QString("Hello World")); QVERIFY(textNode1.hasProperty("anchors.centerIn")); @@ -3694,13 +3859,13 @@ char qmlString[] = "import Qt 4.7\n" ModelNode rectNode = rootModelNode.nodeListProperty("data").toModelNodeList().at(1); QVERIFY(rectNode.isValid()); - QCOMPARE(rectNode.type(), QString("Qt/Rectangle")); + QCOMPARE(rectNode.type(), QString("QtQuick.Rectangle")); QCOMPARE(rectNode.id(), QString("rectangle")); QVERIFY(rectNode.hasProperty("gradient")); QVERIFY(rectNode.property("gradient").isNodeProperty()); ModelNode gradientNode = rectNode.nodeProperty("gradient").modelNode(); QVERIFY(gradientNode.isValid()); - QCOMPARE(gradientNode.type(), QString("Qt/Gradient")); + QCOMPARE(gradientNode.type(), QString("QtQuick.Gradient")); QVERIFY(gradientNode.hasProperty("stops")); QVERIFY(gradientNode.property("stops").isNodeListProperty()); QCOMPARE(gradientNode.nodeListProperty("stops").toModelNodeList().count(), 2); @@ -3711,15 +3876,15 @@ char qmlString[] = "import Qt 4.7\n" QVERIFY(stop1.isValid()); QVERIFY(stop2.isValid()); - QCOMPARE(stop1.type(), QString("Qt/GradientStop")); - QCOMPARE(stop2.type(), QString("Qt/GradientStop")); + QCOMPARE(stop1.type(), QString("QtQuick.GradientStop")); + QCOMPARE(stop2.type(), QString("QtQuick.GradientStop")); QCOMPARE(stop1.variantProperty("position").value().toInt(), 0); QCOMPARE(stop2.variantProperty("position").value().toInt(), 1); ModelNode textNode2 = rootModelNode.nodeListProperty("data").toModelNodeList().last(); QVERIFY(textNode2.isValid()); - QCOMPARE(textNode2.type(), QString("Qt/Text")); + QCOMPARE(textNode2.type(), QString("QtQuick.Text")); QCOMPARE(textNode2.id(), QString("text2")); QCOMPARE(textNode2.variantProperty("width").value().toInt(), 80); QCOMPARE(textNode2.variantProperty("height").value().toInt(), 20); @@ -3730,105 +3895,83 @@ char qmlString[] = "import Qt 4.7\n" void tst_TestCore::testMetaInfo() { - QSKIP("Fix metainfo", SkipAll); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); + model->changeImports(QList<Import>() << Import::createLibraryImport("QtWebKit", "1.0"), QList<Import>()); // test whether default type is registered - QVERIFY(model->metaInfo("Qt/Item", 4, 7).isValid()); + QVERIFY(model->metaInfo("QtQuick.Item", -1, -1).isValid()); // test whether types from plugins are registered - QVERIFY(model->hasNodeMetaInfo("QtWebKit/WebView", 1, 0)); + QVERIFY(model->hasNodeMetaInfo("QtWebKit.WebView", -1, -1)); // test whether non-qml type is registered - QVERIFY(model->hasNodeMetaInfo("QGraphicsObject", 4, 7)); // Qt 4.7 namespace - QVERIFY(model->hasNodeMetaInfo("QGraphicsObject", 1, 0)); // webkit 1.0 namespace + QVERIFY(model->hasNodeMetaInfo("<cpp>.QGraphicsObject", -1, -1)); // Qt 4.7 namespace } void tst_TestCore::testMetaInfoSimpleType() { - QSKIP("Fix metainfo", SkipAll); - // - // Test type registered with qmlRegisterType: - // - // qmlRegisterType<QDeclarativeItem>("Qt",4,7,"Item") - // - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); - QVERIFY(model->hasNodeMetaInfo("Qt/Item", 4, 7)); - QVERIFY(model->hasNodeMetaInfo("Qt/Item", 4, 7)); + QVERIFY(model->hasNodeMetaInfo("QtQuick.Item", 1, 1)); + QVERIFY(model->hasNodeMetaInfo("QtQuick.Item", 1, 1)); - NodeMetaInfo itemMetaInfo = model->metaInfo("Qt/Item", 4, 7); - NodeMetaInfo itemMetaInfo2 = model->metaInfo("Qt/Item", 4, 7); + NodeMetaInfo itemMetaInfo = model->metaInfo("QtQuick.Item", 1, 1); + NodeMetaInfo itemMetaInfo2 = model->metaInfo("QtQuick.Item", 1, 1); QVERIFY(itemMetaInfo.isValid()); - QCOMPARE(itemMetaInfo.typeName(), QLatin1String("Qt/Item")); - QCOMPARE(itemMetaInfo.majorVersion(), 4); - QCOMPARE(itemMetaInfo.minorVersion(), 7); + QCOMPARE(itemMetaInfo.typeName(), QLatin1String("QtQuick.Item")); + QCOMPARE(itemMetaInfo.majorVersion(), 1); + QCOMPARE(itemMetaInfo.minorVersion(), 1); // super classes NodeMetaInfo graphicsObjectInfo = itemMetaInfo.directSuperClass(); QVERIFY(graphicsObjectInfo.isValid()); - QCOMPARE(graphicsObjectInfo.typeName(), QLatin1String("QGraphicsObject")); + QCOMPARE(graphicsObjectInfo.typeName(), QLatin1String("QtQuick.QGraphicsObject")); QCOMPARE(graphicsObjectInfo.majorVersion(), -1); QCOMPARE(graphicsObjectInfo.minorVersion(), -1); - QCOMPARE(itemMetaInfo.superClasses().size(), 2); // QGraphicsObject, Qt/QtObject - QVERIFY(itemMetaInfo.isSubclassOf("QGraphicsObject", 4, 7)); - QVERIFY(itemMetaInfo.isSubclassOf("Qt/QtObject", 4, 7)); + QCOMPARE(itemMetaInfo.superClasses().size(), 3); // Item, QGraphicsObject, QtQuick.QtObject + QVERIFY(itemMetaInfo.isSubclassOf("QtQuick.QGraphicsObject", -1, -1)); + QVERIFY(itemMetaInfo.isSubclassOf("<cpp>.QObject", -1, -1)); // availableInVersion - QVERIFY(itemMetaInfo.availableInVersion(4, 7)); - QVERIFY(itemMetaInfo.availableInVersion(4, 8)); - QVERIFY(itemMetaInfo.availableInVersion(5, 0)); + QVERIFY(itemMetaInfo.availableInVersion(1, 1)); + QVERIFY(itemMetaInfo.availableInVersion(1, 0)); QVERIFY(itemMetaInfo.availableInVersion(-1, -1)); - QVERIFY(!itemMetaInfo.availableInVersion(4, 6)); - QVERIFY(!itemMetaInfo.availableInVersion(3, 7)); } void tst_TestCore::testMetaInfoUncreatableType() { - QSKIP("Fix metainfo", SkipAll); - // Test type registered with qmlRegisterUncreatableType or qmlRegisterTypeNotAvailable: - // - // qmlRegisterUncreatableType<QDeclarativeAbstractAnimation>("Qt",4,7,"Animation",QDeclarativeAbstractAnimation::tr("Animation is an abstract class")); - // - - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); - QVERIFY(model->hasNodeMetaInfo("Qt/Animation")); - NodeMetaInfo animationTypeInfo = model->metaInfo("Qt/Animation", 4, 7); + QVERIFY(model->hasNodeMetaInfo("QtQuick.Animation")); + NodeMetaInfo animationTypeInfo = model->metaInfo("QtQuick.Animation", 1, 1); QVERIFY(animationTypeInfo.isValid()); QVERIFY(animationTypeInfo.isValid()); - QCOMPARE(animationTypeInfo.typeName(), QLatin1String("Qt/Animation")); - QCOMPARE(animationTypeInfo.majorVersion(), 4); - QCOMPARE(animationTypeInfo.minorVersion(), 7); + QCOMPARE(animationTypeInfo.typeName(), QLatin1String("QtQuick.Animation")); + QCOMPARE(animationTypeInfo.majorVersion(), 1); + QCOMPARE(animationTypeInfo.minorVersion(), 1); NodeMetaInfo qObjectTypeInfo = animationTypeInfo.directSuperClass(); QVERIFY(qObjectTypeInfo.isValid()); - QCOMPARE(qObjectTypeInfo.typeName(), QLatin1String("Qt/QtObject")); - QCOMPARE(qObjectTypeInfo.majorVersion(), 4); - QCOMPARE(qObjectTypeInfo.minorVersion(), 7); - QCOMPARE(animationTypeInfo.superClasses().size(), 1); + QCOMPARE(qObjectTypeInfo.typeName(), QLatin1String("QtQuick.QtObject")); + QCOMPARE(qObjectTypeInfo.majorVersion(), 1); + QCOMPARE(qObjectTypeInfo.minorVersion(), 0); + QCOMPARE(animationTypeInfo.superClasses().size(), 2); } void tst_TestCore::testMetaInfoExtendedType() { - QSKIP("Fix metainfo", SkipAll); - // Test type registered with qmlRegisterExtendedType - // - // qmlRegisterExtendedType<QGraphicsWidget,QDeclarativeGraphicsWidget>("Qt",4,7,"QGraphicsWidget"); - // - - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); - QVERIFY(model->hasNodeMetaInfo("Qt/QGraphicsWidget")); - NodeMetaInfo graphicsWidgetTypeInfo = model->metaInfo("Qt/QGraphicsWidget", 4, 7); + QVERIFY(model->hasNodeMetaInfo("QtQuick.QGraphicsWidget")); + NodeMetaInfo graphicsWidgetTypeInfo = model->metaInfo("QtQuick.QGraphicsWidget", 1, 1); QVERIFY(graphicsWidgetTypeInfo.isValid()); QVERIFY(graphicsWidgetTypeInfo.hasProperty("layout")); // from QGraphicsWidgetDeclarativeUI QVERIFY(graphicsWidgetTypeInfo.hasProperty("font")); // from QGraphicsWidget @@ -3836,10 +3979,10 @@ void tst_TestCore::testMetaInfoExtendedType() NodeMetaInfo graphicsObjectTypeInfo = graphicsWidgetTypeInfo.directSuperClass(); QVERIFY(graphicsObjectTypeInfo.isValid()); - QCOMPARE(graphicsObjectTypeInfo.typeName(), QLatin1String("QGraphicsObject")); + QCOMPARE(graphicsObjectTypeInfo.typeName(), QLatin1String("<cpp>.QGraphicsObject")); QCOMPARE(graphicsObjectTypeInfo.majorVersion(), -1); QCOMPARE(graphicsObjectTypeInfo.minorVersion(), -1); - QCOMPARE(graphicsWidgetTypeInfo.superClasses().size(), 2); + QCOMPARE(graphicsWidgetTypeInfo.superClasses().size(), 3); } void tst_TestCore::testMetaInfoInterface() @@ -3847,22 +3990,16 @@ void tst_TestCore::testMetaInfoInterface() // Test type registered with qmlRegisterInterface // - QSKIP("TODO: Test not implemented yet", SkipAll); + MSKIP_ALL("TODO: Test not implemented yet"); } void tst_TestCore::testMetaInfoCustomType() { - QSKIP("Fix metainfo", SkipAll); - - // Test type registered with qmlRegisterCustomType: - // - // qmlRegisterCustomType<QDeclarativePropertyChanges>("Qt", 4, 7, "PropertyChanges", new QDeclarativePropertyChangesParser); - - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); - QVERIFY(model->hasNodeMetaInfo("Qt/PropertyChanges")); - NodeMetaInfo propertyChangesInfo = model->metaInfo("Qt/PropertyChanges", 4, 7); + QVERIFY(model->hasNodeMetaInfo("QtQuick.PropertyChanges")); + NodeMetaInfo propertyChangesInfo = model->metaInfo("QtQuick.PropertyChanges", 1, 1); QVERIFY(propertyChangesInfo.isValid()); QVERIFY(propertyChangesInfo.hasProperty("target")); // from QDeclarativePropertyChanges QVERIFY(propertyChangesInfo.hasProperty("restoreEntryValues")); // from QDeclarativePropertyChanges @@ -3870,27 +4007,27 @@ void tst_TestCore::testMetaInfoCustomType() NodeMetaInfo stateOperationInfo = propertyChangesInfo.directSuperClass(); QVERIFY(stateOperationInfo.isValid()); - QCOMPARE(stateOperationInfo.typeName(), QLatin1String("QDeclarativeStateOperation")); + QCOMPARE(stateOperationInfo.typeName(), QLatin1String("QtQuick.QDeclarative1StateOperation")); QCOMPARE(stateOperationInfo.majorVersion(), -1); QCOMPARE(stateOperationInfo.minorVersion(), -1); - QCOMPARE(propertyChangesInfo.superClasses().size(), 2); + QCOMPARE(propertyChangesInfo.superClasses().size(), 3); // DeclarativePropertyChanges just has 3 properties QCOMPARE(propertyChangesInfo.propertyNames().size() - stateOperationInfo.propertyNames().size(), 3); + + QApplication::processEvents(); } void tst_TestCore::testMetaInfoEnums() { - QSKIP("Fix metainfo", SkipAll); - - QScopedPointer<Model> model(Model::create("Qt/Text")); + QScopedPointer<Model> model(createModel("QtQuick.Text")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); QVERIFY(view.data()); model->attachView(view.data()); - QCOMPARE(view->rootModelNode().metaInfo().typeName(), QString("Qt/Text")); + QCOMPARE(view->rootModelNode().metaInfo().typeName(), QString("QtQuick.Text")); QVERIFY(view->rootModelNode().metaInfo().hasProperty("transformOrigin")); @@ -3903,42 +4040,107 @@ void tst_TestCore::testMetaInfoEnums() QCOMPARE(view->rootModelNode().metaInfo().propertyTypeName("horizontalAlignment"), QLatin1String("HAlignment")); QVERIFY(view->rootModelNode().metaInfo().propertyKeysForEnum("horizontalAlignment").contains(QLatin1String("AlignLeft"))); QVERIFY(view->rootModelNode().metaInfo().propertyKeysForEnum("horizontalAlignment").contains(QLatin1String("AlignRight"))); + + QApplication::processEvents(); } -void tst_TestCore::testMetaInfoProperties() +void tst_TestCore::testMetaInfoQtQuick1Vs2() { - QSKIP("Fix metainfo", SkipAll); + char qmlString[] = "import QtQuick 2.0\n" + "Rectangle {\n" + "id: root;\n" + "width: 200;\n" + "height: 200;\n" + "color: \"white\";\n" + "Text {\n" + "id: text1\n" + "text: \"Hello World\"\n" + "anchors.centerIn: parent\n" + "Item {\n" + "id: item\n" + "}\n" + "}\n" + "Rectangle {\n" + "id: rectangle;\n" + "gradient: Gradient {\n" + "GradientStop {\n" + "position: 0\n" + "color: \"white\"\n" + "}\n" + "GradientStop {\n" + "position: 1\n" + "color: \"black\"\n" + "}\n" + "}\n" + "}\n" + "Text {\n" + "text: \"text\"\n" + "x: 66\n" + "y: 43\n" + "width: 80\n" + "height: 20\n" + "id: text2\n" + "}\n" + "}\n"; + + QPlainTextEdit textEdit; + textEdit.setPlainText(qmlString); + NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Text")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); - NodeMetaInfo textNodeMetaInfo = model->metaInfo("Qt/TextEdit", 4, 7); + QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); + testRewriterView->setTextModifier(&textModifier); + + model->attachView(testRewriterView.data()); + + ModelNode rootModelNode = testRewriterView->rootModelNode(); + QVERIFY(rootModelNode.isValid()); + QCOMPARE(rootModelNode.type(), QString("QtQuick.Rectangle")); + + QVERIFY(!model->metaInfo("Rectangle", 1, 0).isValid()); + QVERIFY(model->metaInfo("Rectangle", -1, -1).isValid()); + QVERIFY(model->metaInfo("Rectangle", 2, 0).isValid()); + + QVERIFY(!model->metaInfo("QtQuick.Rectangle", 1, 0).isValid()); + QVERIFY(model->metaInfo("QtQuick.Rectangle", -1, -1).isValid()); + QVERIFY(model->metaInfo("QtQuick.Rectangle", 2, 0).isValid()); +} + +void tst_TestCore::testMetaInfoProperties() +{ + QScopedPointer<Model> model(createModel("QtQuick.Text")); + QVERIFY(model.data()); + + NodeMetaInfo textNodeMetaInfo = model->metaInfo("QtQuick.TextEdit", 1, 1); QVERIFY(textNodeMetaInfo.hasProperty("text")); // QDeclarativeTextEdit QVERIFY(textNodeMetaInfo.hasProperty("parent")); // QDeclarativeItem QVERIFY(textNodeMetaInfo.hasProperty("x")); // QGraphicsObject - QVERIFY(textNodeMetaInfo.hasProperty("objectName")); // Qt/QObject + QVERIFY(textNodeMetaInfo.hasProperty("objectName")); // QtQuick.QObject QVERIFY(!textNodeMetaInfo.hasProperty("bla")); QVERIFY(textNodeMetaInfo.propertyIsWritable("text")); QVERIFY(textNodeMetaInfo.propertyIsWritable("x")); + + QApplication::processEvents(); } void tst_TestCore::testMetaInfoDotProperties() { - QSKIP("Fix metainfo", SkipAll); - - QScopedPointer<Model> model(Model::create("Qt/Text")); + QScopedPointer<Model> model(createModel("QtQuick.Text")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); QVERIFY(view.data()); model->attachView(view.data()); - QVERIFY(model->hasNodeMetaInfo("Qt/Text")); + QVERIFY(model->hasNodeMetaInfo("QtQuick.Text")); - QVERIFY(model->hasNodeMetaInfo("Qt/Pen")); + QVERIFY(model->metaInfo("QtQuick.Rectangle").hasProperty("border")); + QCOMPARE(model->metaInfo("QtQuick.Rectangle").propertyTypeName("border"), QString("<cpp>.QDeclarative1Pen")); - QCOMPARE(view->rootModelNode().metaInfo().typeName(), QString("Qt/Text")); + QCOMPARE(view->rootModelNode().metaInfo().typeName(), QString("QtQuick.Text")); QVERIFY(view->rootModelNode().metaInfo().hasProperty("font")); QVERIFY(view->rootModelNode().metaInfo().hasProperty("font.bold")); @@ -3946,32 +4148,30 @@ void tst_TestCore::testMetaInfoDotProperties() QVERIFY(view->rootModelNode().metaInfo().propertyNames().contains("font.pointSize")); QVERIFY(view->rootModelNode().metaInfo().hasProperty("font.pointSize")); - ModelNode rectNode(addNodeListChild(view->rootModelNode(), "Qt/Rectangle", 4, 7, "data")); - + ModelNode rectNode(addNodeListChild(view->rootModelNode(), "QtQuick.Rectangle", 1, 0, "data")); - QVERIFY(rectNode.metaInfo().propertyNames().contains("pos.x")); - QVERIFY(!rectNode.metaInfo().propertyNames().contains("pos.x")); + QVERIFY(rectNode.metaInfo().propertyNames().contains("pos")); QVERIFY(rectNode.metaInfo().propertyNames().contains("pos.y")); - QVERIFY(!rectNode.metaInfo().propertyNames().contains("pos.y")); - QVERIFY(!rectNode.metaInfo().propertyNames().contains("anchors.topMargin")); + QVERIFY(rectNode.metaInfo().propertyNames().contains("pos.x")); + QVERIFY(rectNode.metaInfo().propertyNames().contains("anchors.topMargin")); QVERIFY(rectNode.metaInfo().propertyNames().contains("border.width")); QVERIFY(rectNode.metaInfo().hasProperty("border")); QVERIFY(rectNode.metaInfo().hasProperty("border.width")); + + QApplication::processEvents(); } void tst_TestCore::testMetaInfoListProperties() { - QSKIP("Fix metainfo", SkipAll); - - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); QVERIFY(view.data()); model->attachView(view.data()); - QVERIFY(model->hasNodeMetaInfo("Qt/Item")); - QCOMPARE(view->rootModelNode().metaInfo().typeName(), QString("Qt/Item")); + QVERIFY(model->hasNodeMetaInfo("QtQuick.Item")); + QCOMPARE(view->rootModelNode().metaInfo().typeName(), QString("QtQuick.Item")); QVERIFY(view->rootModelNode().metaInfo().hasProperty("states")); QVERIFY(view->rootModelNode().metaInfo().propertyIsListProperty("states")); @@ -3990,15 +4190,65 @@ void tst_TestCore::testMetaInfoListProperties() QVERIFY(!view->rootModelNode().metaInfo().propertyIsListProperty("effect")); QVERIFY(view->rootModelNode().metaInfo().hasProperty("parent")); QVERIFY(!view->rootModelNode().metaInfo().propertyIsListProperty("parent")); + + QApplication::processEvents(); +} + +void tst_TestCore::testQtQuick20Basic() +{ + QPlainTextEdit textEdit; + textEdit.setPlainText("\nimport QtQuick 2.0\n\nItem {\n}\n"); + NotIndentingTextEditModifier modifier(&textEdit); + + QScopedPointer<Model> model(Model::create("QtQuick.Item")); + QVERIFY(model.data()); + + TestRewriterView *testRewriterView = new TestRewriterView(model.data()); + testRewriterView->setTextModifier(&modifier); + model->attachView(testRewriterView); + + QVERIFY(testRewriterView->errors().isEmpty()); + ModelNode rootModelNode(testRewriterView->rootModelNode()); + QVERIFY(rootModelNode.isValid()); + QCOMPARE(rootModelNode.metaInfo().majorVersion(), 2); + QCOMPARE(rootModelNode.metaInfo().minorVersion(), 0); + QCOMPARE(rootModelNode.majorQtQuickVersion(), 2); + QCOMPARE(rootModelNode.majorVersion(), 2); +} + +void tst_TestCore::testQtQuick20BasicRectangle() +{ + QPlainTextEdit textEdit; + textEdit.setPlainText("\nimport QtQuick 2.0\nRectangle {\n}\n"); + NotIndentingTextEditModifier modifier(&textEdit); + + QScopedPointer<Model> model(Model::create("QtQuick.Item")); + QVERIFY(model.data()); + + TestRewriterView *testRewriterView = new TestRewriterView(model.data()); + testRewriterView->setTextModifier(&modifier); + model->attachView(testRewriterView); + + QTest::qSleep(1000); + QApplication::processEvents(); + + QVERIFY(testRewriterView->errors().isEmpty()); + ModelNode rootModelNode(testRewriterView->rootModelNode()); + QVERIFY(rootModelNode.isValid()); + QCOMPARE(rootModelNode.type(), QString("QtQuick.Rectangle")); + QCOMPARE(rootModelNode.metaInfo().majorVersion(), 2); + QCOMPARE(rootModelNode.metaInfo().minorVersion(), 0); + QCOMPARE(rootModelNode.majorQtQuickVersion(), 2); + QCOMPARE(rootModelNode.majorVersion(), 2); } void tst_TestCore::testStatesRewriter() { QPlainTextEdit textEdit; - textEdit.setPlainText("import Qt 4.7; Item {}\n"); + textEdit.setPlainText("import QtQuick 1.1; Item {}\n"); NotIndentingTextEditModifier modifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); QVERIFY(view.data()); @@ -4042,10 +4292,10 @@ void tst_TestCore::testStatesRewriter() void tst_TestCore::testGradientsRewriter() { QPlainTextEdit textEdit; - textEdit.setPlainText("\nimport Qt 4.7\n\nItem {\n}\n"); + textEdit.setPlainText("\nimport QtQuick 1.1\n\nItem {\n}\n"); NotIndentingTextEditModifier modifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); QVERIFY(view.data()); @@ -4061,9 +4311,9 @@ void tst_TestCore::testGradientsRewriter() QVERIFY(rootModelNode.isValid()); - ModelNode rectNode(addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data")); + ModelNode rectNode(addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data")); - const QLatin1String expected1("\nimport Qt 4.7\n" + const QLatin1String expected1("\nimport QtQuick 1.1\n" "\n" "Item {\n" "Rectangle {\n" @@ -4071,11 +4321,11 @@ void tst_TestCore::testGradientsRewriter() "}\n"); QCOMPARE(textEdit.toPlainText(), expected1); - ModelNode gradientNode(addNodeChild(rectNode, "Qt/Gradient", 4, 7, "gradient")); + ModelNode gradientNode(addNodeChild(rectNode, "QtQuick.Gradient", 1, 0, "gradient")); QVERIFY(rectNode.hasNodeProperty("gradient")); - const QLatin1String expected2("\nimport Qt 4.7\n" + const QLatin1String expected2("\nimport QtQuick 1.1\n" "\n" "Item {\n" "Rectangle {\n" @@ -4092,11 +4342,11 @@ void tst_TestCore::testGradientsRewriter() propertyList.append(qMakePair(QString("position"), QVariant::fromValue(0))); propertyList.append(qMakePair(QString("color"), QVariant::fromValue(QColor(Qt::red)))); - ModelNode gradientStop1(gradientNode.view()->createModelNode("Qt/GradientStop", 4, 7, propertyList)); + ModelNode gradientStop1(gradientNode.view()->createModelNode("QtQuick.GradientStop", 1, 0, propertyList)); QVERIFY(gradientStop1.isValid()); stops.reparentHere(gradientStop1); - const QLatin1String expected3("\nimport Qt 4.7\n" + const QLatin1String expected3("\nimport QtQuick 1.1\n" "\n" "Item {\n" "Rectangle {\n" @@ -4115,11 +4365,11 @@ void tst_TestCore::testGradientsRewriter() propertyList.append(qMakePair(QString("position"), QVariant::fromValue(0.5))); propertyList.append(qMakePair(QString("color"), QVariant::fromValue(QColor(Qt::blue)))); - ModelNode gradientStop2(gradientNode.view()->createModelNode("Qt/GradientStop", 4, 7, propertyList)); + ModelNode gradientStop2(gradientNode.view()->createModelNode("QtQuick.GradientStop", 1, 0, propertyList)); QVERIFY(gradientStop2.isValid()); stops.reparentHere(gradientStop2); - const QLatin1String expected4("\nimport Qt 4.7\n" + const QLatin1String expected4("\nimport QtQuick 1.1\n" "\n" "Item {\n" "Rectangle {\n" @@ -4143,11 +4393,11 @@ void tst_TestCore::testGradientsRewriter() propertyList.append(qMakePair(QString("position"), QVariant::fromValue(0.8))); propertyList.append(qMakePair(QString("color"), QVariant::fromValue(QColor(Qt::yellow)))); - ModelNode gradientStop3(gradientNode.view()->createModelNode("Qt/GradientStop", 4, 7, propertyList)); + ModelNode gradientStop3(gradientNode.view()->createModelNode("QtQuick.GradientStop", 1, 0, propertyList)); QVERIFY(gradientStop3.isValid()); stops.reparentHere(gradientStop3); - const QLatin1String expected5("\nimport Qt 4.7\n" + const QLatin1String expected5("\nimport QtQuick 1.1\n" "\n" "Item {\n" "Rectangle {\n" @@ -4174,7 +4424,7 @@ void tst_TestCore::testGradientsRewriter() gradientNode.removeProperty("stops"); - const QLatin1String expected6("\nimport Qt 4.7\n" + const QLatin1String expected6("\nimport QtQuick 1.1\n" "\n" "Item {\n" "Rectangle {\n" @@ -4191,7 +4441,7 @@ void tst_TestCore::testGradientsRewriter() propertyList.append(qMakePair(QString("position"), QVariant::fromValue(0))); propertyList.append(qMakePair(QString("color"), QVariant::fromValue(QColor(Qt::blue)))); - gradientStop1 = gradientNode.view()->createModelNode("Qt/GradientStop", 4, 7, propertyList); + gradientStop1 = gradientNode.view()->createModelNode("QtQuick.GradientStop", 1, 0, propertyList); QVERIFY(gradientStop1.isValid()); stops.reparentHere(gradientStop1); @@ -4199,7 +4449,7 @@ void tst_TestCore::testGradientsRewriter() void tst_TestCore::testQmlModelStates() { - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); QVERIFY(view.data()); @@ -4232,7 +4482,7 @@ void tst_TestCore::testQmlModelStates() void tst_TestCore::testInstancesStates() { // -// import Qt 4.7 +// import QtQuick 1.1 // // Rectangle { // Text { @@ -4260,7 +4510,7 @@ void tst_TestCore::testInstancesStates() // } // -// QScopedPointer<Model> model(Model::create("Qt/Rectangle", 4, 7)); +// QScopedPointer<Model> model(createModel("QtQuick.Rectangle", 1, 1)); // QVERIFY(model.data()); // QScopedPointer<TestView> view(new TestView(model.data())); // QVERIFY(view.data()); @@ -4271,28 +4521,28 @@ void tst_TestCore::testInstancesStates() // // // ModelNode rootNode = view->rootModelNode(); -// ModelNode textNode = view->createModelNode("Qt/Text", 4, 7); +// ModelNode textNode = view->createModelNode("QtQuick.Text", 1, 1); // textNode.setId("targetObject"); // textNode.variantProperty("text").setValue("base state"); // rootNode.nodeListProperty("data").reparentHere(textNode); -// ModelNode propertyChanges1Node = view->createModelNode("Qt/PropertyChanges", 4, 7); +// ModelNode propertyChanges1Node = view->createModelNode("QtQuick.PropertyChanges", 1, 1); // propertyChanges1Node.bindingProperty("target").setExpression("targetObject"); // propertyChanges1Node.variantProperty("x").setValue(10); // propertyChanges1Node.variantProperty("text").setValue("state1"); -// ModelNode state1Node = view->createModelNode("Qt/State", 4, 7); +// ModelNode state1Node = view->createModelNode("QtQuick.State", 1, 1); // state1Node.variantProperty("name").setValue("state1"); // state1Node.nodeListProperty("changes").reparentHere(propertyChanges1Node); // rootNode.nodeListProperty("states").reparentHere(state1Node); -// ModelNode propertyChanges2Node = view->createModelNode("Qt/PropertyChanges", 4, 7); +// ModelNode propertyChanges2Node = view->createModelNode("QtQuick.PropertyChanges", 1, 1); // propertyChanges2Node.bindingProperty("target").setExpression("targetObject"); // propertyChanges2Node.variantProperty("text").setValue("state2"); -// ModelNode state2Node = view->createModelNode("Qt/State", 4, 7); +// ModelNode state2Node = view->createModelNode("QtQuick.State", 1, 1); // state2Node.variantProperty("name").setValue("state2"); // state2Node.nodeListProperty("changes").reparentHere(propertyChanges2Node); @@ -4389,7 +4639,7 @@ void tst_TestCore::testInstancesStates() // // // // move property changes of current state out of state -// ModelNode state3Node = view->createModelNode("Qt/State", 4, 7); +// ModelNode state3Node = view->createModelNode("QtQuick.State", 1, 1); // QDeclarativeListReference changes(state1, "changes"); // QCOMPARE(changes.count(), 1); // state3Node.nodeListProperty("changes").reparentHere(propertyChanges1Node); @@ -4412,7 +4662,7 @@ void tst_TestCore::testInstancesStates() // textNode.variantProperty("text").setValue("base state"); // // expressions -// ModelNode textNode2 = view->createModelNode("Qt/Text", 4, 7); +// ModelNode textNode2 = view->createModelNode("QtQuick.Text", 1, 1); // textNode2.setId("targetObject2"); // textNode2.variantProperty("text").setValue("textNode2"); @@ -4472,7 +4722,7 @@ void tst_TestCore::testInstancesStates() void tst_TestCore::testStates() { // -// import Qt 4.7 +// import QtQuick 1.1 // // Rectangle { // Text { @@ -4491,7 +4741,7 @@ void tst_TestCore::testStates() // } // -// QScopedPointer<Model> model(Model::create("Qt/Rectangle", 4, 7)); +// QScopedPointer<Model> model(createModel("QtQuick.Rectangle", 1, 1)); // QVERIFY(model.data()); // QScopedPointer<TestView> view(new TestView(model.data())); // QVERIFY(view.data()); @@ -4500,7 +4750,7 @@ void tst_TestCore::testStates() // // build up model // ModelNode rootNode = view->rootModelNode(); -// ModelNode textNode = view->createModelNode("Qt/Text", 4, 7); +// ModelNode textNode = view->createModelNode("QtQuick.Text", 1, 1); // textNode.setId("targetObject"); // textNode.variantProperty("text").setValue("base state"); @@ -4516,7 +4766,7 @@ void tst_TestCore::testStates() // QVERIFY(textItem.isValid()); // QmlModelState state1(rootItem.states().addState("state 1")); //add state "state 1" -// QCOMPARE(state1.modelNode().type(), QString("Qt/State")); +// QCOMPARE(state1.modelNode().type(), QString("QtQuick.State")); // QVERIFY(view->currentState().isBaseState()); @@ -4549,7 +4799,7 @@ void tst_TestCore::testStates() // QCOMPARE(changes.modelNode().variantProperty("text").value(), QVariant("state 1")); // QCOMPARE(changes.modelNode().bindingProperty("target").expression(), QString("targetObject")); // QCOMPARE(changes.target(), textNode); -// QCOMPARE(changes.modelNode().type(), QString("Qt/PropertyChanges")); +// QCOMPARE(changes.modelNode().type(), QString("QtQuick.PropertyChanges")); // QCOMPARE(changes.modelNode().parentProperty().name(), QString("changes")); // QCOMPARE(changes.modelNode().parentProperty().parentModelNode(), state1.modelNode()); @@ -4568,7 +4818,7 @@ void tst_TestCore::testStates() void tst_TestCore::testStatesBaseState() { // -// import Qt 4.7 +// import QtQuick 1.1 // // Rectangle { // Text { @@ -4587,7 +4837,7 @@ void tst_TestCore::testStatesBaseState() // } // - QScopedPointer<Model> model(Model::create("Qt/Rectangle", 4, 7)); + QScopedPointer<Model> model(createModel("QtQuick.Rectangle", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); QVERIFY(view.data()); @@ -4596,7 +4846,7 @@ void tst_TestCore::testStatesBaseState() // build up model ModelNode rootNode = view->rootModelNode(); - ModelNode textNode = view->createModelNode("Qt/Text", 4, 7); + ModelNode textNode = view->createModelNode("QtQuick.Text", 1, 1); textNode.setId("targetObject"); textNode.variantProperty("text").setValue("base state"); @@ -4612,17 +4862,19 @@ void tst_TestCore::testStatesBaseState() QVERIFY(textItem.isValid()); QmlModelState state1(rootItem.states().addState("state 1")); //add state "state 1" - QCOMPARE(state1.modelNode().type(), QString("Qt/State")); + QCOMPARE(state1.modelNode().type(), QString("QtQuick.State")); QVERIFY(view->currentState().isBaseState()); view->setCurrentState(state1); //set currentState "state 1" QCOMPARE(view->currentState(), state1); + QApplication::processEvents(); textItem.setVariantProperty("text", QVariant("state 1")); //set text in state ! QVERIFY(textItem.propertyAffectedByCurrentState("text")); + QApplication::processEvents(); QCOMPARE(textItem.instanceValue("text"), QVariant("state 1")); - ModelNode newNode = view->createModelNode("Qt/Rectangle", 4, 7); + ModelNode newNode = view->createModelNode("QtQuick.Rectangle", 1, 0); QVERIFY(!QmlObjectNode(newNode).currentState().isBaseState()); view->setCurrentState(view->baseState()); //set currentState base state @@ -4644,13 +4896,13 @@ void tst_TestCore::testStatesBaseState() void tst_TestCore::testInstancesIdResolution() { - QScopedPointer<Model> model(Model::create("Qt/Rectangle", 4, 7)); + QScopedPointer<Model> model(createModel("QtQuick.Rectangle", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); QVERIFY(view.data()); model->attachView(view.data()); - // import Qt 4.7 + // import QtQuick 1.1 // // Rectangle { // id: root @@ -4668,7 +4920,7 @@ void tst_TestCore::testInstancesIdResolution() rootNode.variantProperty("width").setValue(100); rootNode.variantProperty("height").setValue(100); - ModelNode item1Node = view->createModelNode("Qt/Rectangle", 4, 7); + ModelNode item1Node = view->createModelNode("QtQuick.Rectangle", 1, 0); item1Node.setId("item1"); item1Node.bindingProperty("width").setExpression("root.width"); item1Node.bindingProperty("height").setExpression("item2.height"); @@ -4688,7 +4940,7 @@ void tst_TestCore::testInstancesIdResolution() // height: root.height // } - ModelNode item2Node = view->createModelNode("Qt/Rectangle", 4, 7); + ModelNode item2Node = view->createModelNode("QtQuick.Rectangle", 1, 0); item2Node.setId("item2"); item2Node.bindingProperty("width").setExpression("root.width / 2"); item2Node.bindingProperty("height").setExpression("root.height"); @@ -4713,7 +4965,7 @@ void tst_TestCore::testInstancesIdResolution() // height: 80 // } - ModelNode item3Node = view->createModelNode("Qt/Rectangle", 4, 7); + ModelNode item3Node = view->createModelNode("QtQuick.Rectangle", 1, 0); item3Node.setId("item3"); item3Node.variantProperty("height").setValue(80); rootNode.nodeListProperty("data").reparentHere(item3Node); @@ -4731,16 +4983,16 @@ void tst_TestCore::testInstancesNotInScene() // test whether deleting an instance which is not in the scene crashes // - QScopedPointer<Model> model(Model::create("Qt/Rectangle", 4, 7)); + QScopedPointer<Model> model(createModel("QtQuick.Rectangle", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); QVERIFY(view.data()); model->attachView(view.data()); - ModelNode node1 = view->createModelNode("Qt/Item", 4, 7); + ModelNode node1 = view->createModelNode("QtQuick.Item", 1, 1); node1.setId("node1"); - ModelNode node2 = view->createModelNode("Qt/Item", 4, 7); + ModelNode node2 = view->createModelNode("QtQuick.Item", 1, 1); node2.setId("node2"); node1.nodeListProperty("children").reparentHere(node2); @@ -4752,21 +5004,21 @@ void tst_TestCore::testInstancesBindingsInStatesStress() { //This is a stress test to provoke a crash for (int j=0;j<20;j++) { - QScopedPointer<Model> model(Model::create("Qt/Rectangle", 4, 7)); + QScopedPointer<Model> model(createModel("QtQuick.Rectangle", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); QVERIFY(view.data()); model->attachView(view.data()); - ModelNode node1 = view->createModelNode("Qt/Item", 4, 7); + ModelNode node1 = view->createModelNode("QtQuick.Item", 1, 1); node1.setId("node1"); view->rootModelNode().nodeListProperty("children").reparentHere(node1); - ModelNode node2 = view->createModelNode("Qt/Rectangle", 4, 7); + ModelNode node2 = view->createModelNode("QtQuick.Rectangle", 1, 0); node2.setId("node2"); - ModelNode node3 = view->createModelNode("Qt/Rectangle", 4, 7); + ModelNode node3 = view->createModelNode("QtQuick.Rectangle", 1, 0); node3.setId("node3"); node1.nodeListProperty("children").reparentHere(node2); @@ -4857,21 +5109,21 @@ void tst_TestCore::testInstancesPropertyChangeTargets() //this tests checks if a change of the target of a CropertyChange //node is handled correctly - QScopedPointer<Model> model(Model::create("Qt/Rectangle", 4, 7)); + QScopedPointer<Model> model(createModel("QtQuick.Rectangle", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); QVERIFY(view.data()); model->attachView(view.data()); - ModelNode node1 = view->createModelNode("Qt/Item", 4, 7); + ModelNode node1 = view->createModelNode("QtQuick.Item", 1, 1); node1.setId("node1"); view->rootModelNode().nodeListProperty("children").reparentHere(node1); - ModelNode node2 = view->createModelNode("Qt/Rectangle", 4, 7); + ModelNode node2 = view->createModelNode("QtQuick.Rectangle", 1, 0); node2.setId("node2"); - ModelNode node3 = view->createModelNode("Qt/Rectangle", 4, 7); + ModelNode node3 = view->createModelNode("QtQuick.Rectangle", 1, 0); node3.setId("node3"); node1.nodeListProperty("children").reparentHere(node2); @@ -4963,21 +5215,21 @@ void tst_TestCore::testInstancesPropertyChangeTargets() void tst_TestCore::testInstancesDeletePropertyChanges() { - QScopedPointer<Model> model(Model::create("Qt/Rectangle", 4, 7)); + QScopedPointer<Model> model(createModel("QtQuick.Rectangle", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); QVERIFY(view.data()); model->attachView(view.data()); - ModelNode node1 = view->createModelNode("Qt/Item", 4, 7); + ModelNode node1 = view->createModelNode("QtQuick.Item", 1, 1); node1.setId("node1"); view->rootModelNode().nodeListProperty("children").reparentHere(node1); - ModelNode node2 = view->createModelNode("Qt/Rectangle", 4, 7); + ModelNode node2 = view->createModelNode("QtQuick.Rectangle", 1, 0); node2.setId("node2"); - ModelNode node3 = view->createModelNode("Qt/Rectangle", 4, 7); + ModelNode node3 = view->createModelNode("QtQuick.Rectangle", 1, 0); node3.setId("node3"); node1.nodeListProperty("children").reparentHere(node2); @@ -5052,7 +5304,7 @@ void tst_TestCore::testInstancesDeletePropertyChanges() void tst_TestCore::testInstancesChildrenLowLevel() { -// QScopedPointer<Model> model(Model::create("Qt/Rectangle", 4, 7)); +// QScopedPointer<Model> model(createModel("QtQuick.Rectangle", 1, 1)); // QVERIFY(model.data()); // QScopedPointer<NodeInstanceView> view(new NodeInstanceView); @@ -5064,11 +5316,11 @@ void tst_TestCore::testInstancesChildrenLowLevel() // rootModelNode.setId("rootModelNode"); -// ModelNode childNode1 = addNodeListChild(rootModelNode, "Qt/Text", 4, 7, "data"); +// ModelNode childNode1 = addNodeListChild(rootModelNode, "QtQuick.Text", 1, 1, "data"); // QVERIFY(childNode1.isValid()); // childNode1.setId("childNode1"); -// ModelNode childNode2 = addNodeListChild(rootModelNode, "Qt/TextEdit", 4, 7, "data"); +// ModelNode childNode2 = addNodeListChild(rootModelNode, "QtQuick.TextEdit", 1, 1, "data"); // QVERIFY(childNode2.isValid()); // childNode2.setId("childNode2"); @@ -5142,7 +5394,7 @@ void tst_TestCore::testInstancesChildrenLowLevel() void tst_TestCore::testInstancesResourcesLowLevel() { -// QScopedPointer<Model> model(Model::create("Qt/Rectangle", 4, 7)); +// QScopedPointer<Model> model(createModel("QtQuick.Rectangle", 1, 1)); // QVERIFY(model.data()); // QScopedPointer<NodeInstanceView> view(new NodeInstanceView); @@ -5154,15 +5406,15 @@ void tst_TestCore::testInstancesResourcesLowLevel() // rootModelNode.setId("rootModelNode"); -// ModelNode childNode1 = addNodeListChild(rootModelNode, "Qt/Text", 4, 7, "data"); +// ModelNode childNode1 = addNodeListChild(rootModelNode, "QtQuick.Text", 1, 1, "data"); // QVERIFY(childNode1.isValid()); // childNode1.setId("childNode1"); -// ModelNode childNode2 = addNodeListChild(rootModelNode, "Qt/TextEdit", 4, 7, "data"); +// ModelNode childNode2 = addNodeListChild(rootModelNode, "QtQuick.TextEdit", 1, 1, "data"); // QVERIFY(childNode2.isValid()); // childNode2.setId("childNode2"); -// ModelNode listModel = addNodeListChild(rootModelNode, "Qt/ListModel", 4, 7, "data"); +// ModelNode listModel = addNodeListChild(rootModelNode, "QtQuick.ListModel", 1, 1, "data"); // QVERIFY(listModel.isValid()); // listModel.setId("listModel"); @@ -5241,7 +5493,7 @@ void tst_TestCore::testInstancesResourcesLowLevel() // QCOMPARE(listReferenceData.at(1), child1Item); // QCOMPARE(listReferenceData.at(2), child2Item); -// ModelNode listModel2 = addNodeListChild(rootModelNode, "Qt/ListModel", 4, 7, "data"); +// ModelNode listModel2 = addNodeListChild(rootModelNode, "QtQuick.ListModel", 1, 1, "data"); // QVERIFY(listModel2.isValid()); // listModel2.setId("listModel2"); @@ -5289,7 +5541,7 @@ void tst_TestCore::testInstancesResourcesLowLevel() void tst_TestCore::testInstancesFlickableLowLevel() { -// QScopedPointer<Model> model(Model::create("Qt/Flickable", 4, 7)); +// QScopedPointer<Model> model(createModel("QtQuick.Flickable", 1, 1)); // QVERIFY(model.data()); // QScopedPointer<NodeInstanceView> view(new NodeInstanceView); @@ -5301,15 +5553,15 @@ void tst_TestCore::testInstancesFlickableLowLevel() // rootModelNode.setId("rootModelNode"); -// ModelNode childNode1 = addNodeListChild(rootModelNode, "Qt/Text", 4, 7, "flickableData"); +// ModelNode childNode1 = addNodeListChild(rootModelNode, "QtQuick.Text", 1, 1, "flickableData"); // QVERIFY(childNode1.isValid()); // childNode1.setId("childNode1"); -// ModelNode childNode2 = addNodeListChild(rootModelNode, "Qt/TextEdit", 4, 7, "flickableData"); +// ModelNode childNode2 = addNodeListChild(rootModelNode, "QtQuick.TextEdit", 1, 1, "flickableData"); // QVERIFY(childNode2.isValid()); // childNode2.setId("childNode2"); -// ModelNode listModel = addNodeListChild(rootModelNode, "Qt/ListModel", 4, 7, "flickableData"); +// ModelNode listModel = addNodeListChild(rootModelNode, "QtQuick.ListModel", 1, 1, "flickableData"); // QVERIFY(listModel.isValid()); // listModel.setId("listModel"); @@ -5377,7 +5629,7 @@ void tst_TestCore::testInstancesFlickableLowLevel() void tst_TestCore::testInstancesReorderChildrenLowLevel() { -// QScopedPointer<Model> model(Model::create("Qt/Rectangle", 4, 7)); +// QScopedPointer<Model> model(createModel("QtQuick.Rectangle", 1, 1)); // QVERIFY(model.data()); // QScopedPointer<NodeInstanceView> view(new NodeInstanceView); @@ -5389,23 +5641,23 @@ void tst_TestCore::testInstancesReorderChildrenLowLevel() // rootModelNode.setId("rootModelNode"); -// ModelNode childNode1 = addNodeListChild(rootModelNode, "Qt/Text", 4, 7, "data"); +// ModelNode childNode1 = addNodeListChild(rootModelNode, "QtQuick.Text", 1, 1, "data"); // QVERIFY(childNode1.isValid()); // childNode1.setId("childNode1"); -// ModelNode childNode2 = addNodeListChild(rootModelNode, "Qt/TextEdit", 4, 7, "data"); +// ModelNode childNode2 = addNodeListChild(rootModelNode, "QtQuick.TextEdit", 1, 1, "data"); // QVERIFY(childNode2.isValid()); // childNode2.setId("childNode2"); -// ModelNode listModel = addNodeListChild(rootModelNode, "Qt/ListModel", 4, 7, "data"); +// ModelNode listModel = addNodeListChild(rootModelNode, "QtQuick.ListModel", 1, 1, "data"); // QVERIFY(listModel.isValid()); // listModel.setId("listModel"); -// ModelNode childNode3 = addNodeListChild(rootModelNode, "Qt/TextEdit", 4, 7, "data"); +// ModelNode childNode3 = addNodeListChild(rootModelNode, "QtQuick.TextEdit", 1, 1, "data"); // QVERIFY(childNode3.isValid()); // childNode3.setId("childNode3"); -// ModelNode childNode4 = addNodeListChild(rootModelNode, "Qt/TextEdit", 4, 7, "data"); +// ModelNode childNode4 = addNodeListChild(rootModelNode, "QtQuick.TextEdit", 1, 1, "data"); // QVERIFY(childNode4.isValid()); // childNode4.setId("childNode4"); @@ -5476,7 +5728,7 @@ void tst_TestCore::testInstancesReorderChildrenLowLevel() void tst_TestCore::testQmlModelStatesInvalidForRemovedNodes() { - QScopedPointer<Model> model(Model::create("Qt/Rectangle", 4, 7)); + QScopedPointer<Model> model(createModel("QtQuick.Rectangle", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -5493,11 +5745,11 @@ void tst_TestCore::testQmlModelStatesInvalidForRemovedNodes() QVERIFY(state1.isValid()); QCOMPARE(state1.name(), QString("state1")); - ModelNode childNode = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); + ModelNode childNode = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); QVERIFY(childNode.isValid()); childNode.setId("childNode"); - ModelNode subChildNode = addNodeListChild(childNode, "Qt/Rectangle", 4, 7, "data"); + ModelNode subChildNode = addNodeListChild(childNode, "QtQuick.Rectangle", 1, 0, "data"); QVERIFY(subChildNode.isValid()); subChildNode.setId("subChildNode"); @@ -5517,7 +5769,7 @@ void tst_TestCore::testInstancesAttachToExistingModel() // Test attaching nodeinstanceview to an existing model // - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(createModel("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -5525,7 +5777,7 @@ void tst_TestCore::testInstancesAttachToExistingModel() model->attachView(view.data()); ModelNode rootNode = view->rootModelNode(); - ModelNode rectangleNode = addNodeListChild(rootNode, "Qt/Rectangle", 4, 7, "data"); + ModelNode rectangleNode = addNodeListChild(rootNode, "QtQuick.Rectangle", 1, 0, "data"); rectangleNode.variantProperty("width").setValue(100); @@ -5534,7 +5786,7 @@ void tst_TestCore::testInstancesAttachToExistingModel() // Attach NodeInstanceView - QScopedPointer<NodeInstanceView> instanceView(new NodeInstanceView); + QScopedPointer<NodeInstanceView> instanceView(new NodeInstanceView(0, NodeInstanceServerInterface::TestModus)); QVERIFY(instanceView.data()); model->attachView(instanceView.data()); @@ -5549,7 +5801,7 @@ void tst_TestCore::testInstancesAttachToExistingModel() void tst_TestCore::testQmlModelAddMultipleStates() { - QScopedPointer<Model> model(Model::create("Qt/Rectangle", 4, 7)); + QScopedPointer<Model> model(createModel("QtQuick.Rectangle", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -5580,7 +5832,7 @@ void tst_TestCore::testQmlModelAddMultipleStates() void tst_TestCore::testQmlModelRemoveStates() { - QScopedPointer<Model> model(Model::create("Qt/Rectangle", 4, 7)); + QScopedPointer<Model> model(createModel("QtQuick.Rectangle", 1, 1)); QScopedPointer<TestView> view(new TestView(model.data())); QVERIFY(view.data()); @@ -5610,10 +5862,10 @@ void tst_TestCore::testQmlModelRemoveStates() void tst_TestCore::testQmlModelStateWithName() { QPlainTextEdit textEdit1; - textEdit1.setPlainText("import Qt 4.7; Rectangle { id: theRect; width: 100; states: [ State { name: \"a\"; PropertyChanges { target: theRect; width: 200; } } ] }\n"); + textEdit1.setPlainText("import QtQuick 1.1; Rectangle { id: theRect; width: 100; states: [ State { name: \"a\"; PropertyChanges { target: theRect; width: 200; } } ] }\n"); NotIndentingTextEditModifier modifier1(&textEdit1); - QScopedPointer<Model> model1(Model::create("Qt/Item")); + QScopedPointer<Model> model1(Model::create("QtQuick.Item")); TestRewriterView *testRewriterView1 = new TestRewriterView(model1.data()); testRewriterView1->setTextModifier(&modifier1); @@ -5635,7 +5887,7 @@ void tst_TestCore::testQmlModelStateWithName() view->setCurrentState(rootNode.states().allStates().at(0)); rootNode.setVariantProperty("width", 112); - const QLatin1String expected1("import Qt 4.7; Rectangle { id: theRect; width: 100; states: [ State { name: \"a\"; PropertyChanges { target: theRect; width: 112 } } ] }\n"); + const QLatin1String expected1("import QtQuick 1.1; Rectangle { id: theRect; width: 100; states: [ State { name: \"a\"; PropertyChanges { target: theRect; width: 112 } } ] }\n"); QCOMPARE(textEdit1.toPlainText(), expected1); QVERIFY(!rootNode.isInBaseState()); @@ -5655,10 +5907,10 @@ void tst_TestCore::testQmlModelStateWithName() void tst_TestCore::testRewriterAutomaticSemicolonAfterChangedProperty() { QPlainTextEdit textEdit1; - textEdit1.setPlainText("import Qt 4.7; Rectangle {\n width: 640\n height: 480\n}\n"); + textEdit1.setPlainText("import QtQuick 1.1; Rectangle {\n width: 640\n height: 480\n}\n"); NotIndentingTextEditModifier modifier1(&textEdit1); - QScopedPointer<Model> model1(Model::create("Qt/Item")); + QScopedPointer<Model> model1(Model::create("QtQuick.Item")); TestRewriterView *testRewriterView1 = new TestRewriterView(model1.data()); testRewriterView1->setTextModifier(&modifier1); @@ -5675,7 +5927,7 @@ void tst_TestCore::testRewriterAutomaticSemicolonAfterChangedProperty() void tst_TestCore::defaultPropertyValues() { - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -5685,12 +5937,12 @@ void tst_TestCore::defaultPropertyValues() QCOMPARE(view->rootModelNode().variantProperty("x").value().toDouble(), 0.0); QCOMPARE(view->rootModelNode().variantProperty("width").value().toDouble(), 0.0); - ModelNode rectNode(addNodeListChild(view->rootModelNode(), "Qt/Rectangle", 4, 7, "data")); + ModelNode rectNode(addNodeListChild(view->rootModelNode(), "QtQuick.Rectangle", 1, 0, "data")); QCOMPARE(rectNode.variantProperty("y").value().toDouble(), 0.0); QCOMPARE(rectNode.variantProperty("width").value().toDouble(), 0.0); - ModelNode imageNode(addNodeListChild(view->rootModelNode(), "Qt/Image", 4, 7, "data")); + ModelNode imageNode(addNodeListChild(view->rootModelNode(), "QtQuick.Image", 1, 0, "data")); QCOMPARE(imageNode.variantProperty("y").value().toDouble(), 0.0); QCOMPARE(imageNode.variantProperty("width").value().toDouble(), 0.0); @@ -5699,10 +5951,10 @@ void tst_TestCore::defaultPropertyValues() void tst_TestCore::testModelPropertyValueTypes() { QPlainTextEdit textEdit1; - textEdit1.setPlainText("import Qt 4.7; Rectangle { width: 100; radius: 1.5; color: \"red\"; }"); + textEdit1.setPlainText("import QtQuick 1.1; Rectangle { width: 100; radius: 1.5; color: \"red\"; }"); NotIndentingTextEditModifier modifier1(&textEdit1); - QScopedPointer<Model> model1(Model::create("Qt/Item")); + QScopedPointer<Model> model1(Model::create("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView1(new TestRewriterView()); testRewriterView1->setTextModifier(&modifier1); @@ -5720,7 +5972,7 @@ void tst_TestCore::testModelPropertyValueTypes() void tst_TestCore::testModelNodeInHierarchy() { - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -5728,9 +5980,9 @@ void tst_TestCore::testModelNodeInHierarchy() model->attachView(view.data()); QVERIFY(view->rootModelNode().isInHierarchy()); - ModelNode node1 = addNodeListChild(view->rootModelNode(), "Qt/Item", 4, 7, "data"); + ModelNode node1 = addNodeListChild(view->rootModelNode(), "QtQuick.Item", 1, 1, "data"); QVERIFY(node1.isInHierarchy()); - ModelNode node2 = view->createModelNode("Qt/Item", 4, 7); + ModelNode node2 = view->createModelNode("QtQuick.Item", 1, 1); QVERIFY(!node2.isInHierarchy()); node2.nodeListProperty("data").reparentHere(node1); QVERIFY(!node2.isInHierarchy()); @@ -5741,11 +5993,11 @@ void tst_TestCore::testModelNodeInHierarchy() void tst_TestCore::testModelNodeIsAncestorOf() { - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); // - // import Qt 4.7 + // import QtQuick 1.1 // Item { // Item { // id: item2 @@ -5763,11 +6015,11 @@ void tst_TestCore::testModelNodeIsAncestorOf() model->attachView(view.data()); view->rootModelNode().setId("item1"); - ModelNode item2 = addNodeListChild(view->rootModelNode(), "Qt/Item", 4, 7, "data"); + ModelNode item2 = addNodeListChild(view->rootModelNode(), "QtQuick.Item", 1, 1, "data"); item2.setId("item2"); - ModelNode item3 = addNodeListChild(view->rootModelNode(), "Qt/Item", 4, 7, "data"); + ModelNode item3 = addNodeListChild(view->rootModelNode(), "QtQuick.Item", 1, 1, "data"); item3.setId("item3"); - ModelNode item4 = addNodeListChild(item3, "Qt/Item", 4, 7, "data"); + ModelNode item4 = addNodeListChild(item3, "QtQuick.Item", 1, 1, "data"); item4.setId("item4"); QVERIFY(view->rootModelNode().isAncestorOf(item2)); @@ -5780,8 +6032,7 @@ void tst_TestCore::testModelNodeIsAncestorOf() void tst_TestCore::testModelDefaultProperties() { - QSKIP("Fix metainfo", SkipAll); - QScopedPointer<Model> model(Model::create("Qt/Rectangle")); + QScopedPointer<Model> model(createModel("QtQuick.Rectangle")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -5797,10 +6048,10 @@ void tst_TestCore::testModelDefaultProperties() void tst_TestCore::loadAnchors() { QPlainTextEdit textEdit1; - textEdit1.setPlainText("import Qt 4.7; Item { width: 100; height: 100; Rectangle { anchors.left: parent.left; anchors.horizontalCenter: parent.horizontalCenter; anchors.rightMargin: 20; }}"); + textEdit1.setPlainText("import QtQuick 1.1; Item { width: 100; height: 100; Rectangle { anchors.left: parent.left; anchors.horizontalCenter: parent.horizontalCenter; anchors.rightMargin: 20; }}"); NotIndentingTextEditModifier modifier1(&textEdit1); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView1(new TestRewriterView()); testRewriterView1->setTextModifier(&modifier1); @@ -5836,10 +6087,10 @@ void tst_TestCore::loadAnchors() void tst_TestCore::changeAnchors() { QPlainTextEdit textEdit1; - textEdit1.setPlainText("import Qt 4.7; Item { width: 100; height: 100; Rectangle { anchors.left: parent.left; anchors.horizontalCenter: parent.horizontalCenter; anchors.rightMargin: 20; }}"); + textEdit1.setPlainText("import QtQuick 1.1; Item { width: 100; height: 100; Rectangle { anchors.left: parent.left; anchors.horizontalCenter: parent.horizontalCenter; anchors.rightMargin: 20; }}"); NotIndentingTextEditModifier modifier1(&textEdit1); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView1(new TestRewriterView()); testRewriterView1->setTextModifier(&modifier1); @@ -5897,10 +6148,10 @@ void tst_TestCore::changeAnchors() void tst_TestCore::anchorToSibling() { QPlainTextEdit textEdit1; - textEdit1.setPlainText("import Qt 4.7; Item { Rectangle {} Rectangle { id: secondChild } }"); + textEdit1.setPlainText("import QtQuick 1.1; Item { Rectangle {} Rectangle { id: secondChild } }"); NotIndentingTextEditModifier modifier1(&textEdit1); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView1(new TestRewriterView()); testRewriterView1->setTextModifier(&modifier1); @@ -5941,10 +6192,10 @@ void tst_TestCore::anchorToSibling() void tst_TestCore::removeFillAnchorByDetaching() { QPlainTextEdit textEdit1; - textEdit1.setPlainText("import Qt 4.7; Item { width: 100; height: 100; Rectangle { id: child; anchors.fill: parent } }"); + textEdit1.setPlainText("import QtQuick 1.1; Item { width: 100; height: 100; Rectangle { id: child; anchors.fill: parent } }"); NotIndentingTextEditModifier modifier1(&textEdit1); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView1(new TestRewriterView()); testRewriterView1->setTextModifier(&modifier1); @@ -6021,10 +6272,10 @@ void tst_TestCore::removeFillAnchorByDetaching() void tst_TestCore::removeFillAnchorByChanging() { QPlainTextEdit textEdit1; - textEdit1.setPlainText("import Qt 4.7; Item { width: 100; height: 100; Rectangle { id: child; anchors.fill: parent } }"); + textEdit1.setPlainText("import QtQuick 1.1; Item { width: 100; height: 100; Rectangle { id: child; anchors.fill: parent } }"); NotIndentingTextEditModifier modifier1(&textEdit1); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView1(new TestRewriterView()); testRewriterView1->setTextModifier(&modifier1); @@ -6101,7 +6352,7 @@ void tst_TestCore::removeFillAnchorByChanging() void tst_TestCore::testModelBindings() { - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(createModel("QtQuick.Item", 1, 1)); QVERIFY(model.data()); NodeInstanceView *nodeInstanceView = new NodeInstanceView(model.data(), NodeInstanceServerInterface::TestModus); @@ -6111,9 +6362,9 @@ void tst_TestCore::testModelBindings() QCOMPARE(rootModelNode.allDirectSubModelNodes().count(), 0); NodeInstance rootInstance = nodeInstanceView->instanceForNode(rootModelNode); - // default width/height is forced to 100 - QCOMPARE(rootInstance.size().width(), 100.0); - QCOMPARE(rootInstance.size().height(), 100.0); + // default width/height is 0 + QCOMPARE(rootInstance.size().width(), 0.0); + QCOMPARE(rootInstance.size().height(), 0.0); rootModelNode.variantProperty("width") = 200; rootModelNode.variantProperty("height") = 100; @@ -6121,7 +6372,7 @@ void tst_TestCore::testModelBindings() QCOMPARE(rootInstance.size().width(), 200.0); QCOMPARE(rootInstance.size().height(), 100.0); - ModelNode childNode = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); + ModelNode childNode = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); childNode.variantProperty("width") = 100; childNode.variantProperty("height") = 100; @@ -6159,7 +6410,8 @@ void tst_TestCore::testModelBindings() void tst_TestCore::testModelDynamicProperties() { - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + MSKIP_ALL("Fix rewriter dynamic properties writing"); + QScopedPointer<Model> model(createModel("QtQuick.Item", 1, 1)); QVERIFY(model.data()); TestView *testView = new TestView(model.data()); @@ -6169,15 +6421,15 @@ void tst_TestCore::testModelDynamicProperties() ModelNode rootModelNode = rootQmlItemNode.modelNode(); rootModelNode.variantProperty("x") = 10; - rootModelNode.variantProperty("myDouble") = qMakePair(QString("real"), QVariant(10)); - rootModelNode.variantProperty("myColor").setDynamicTypeNameAndValue("color", Qt::red); + rootModelNode.variantProperty("myColor").setDynamicTypeNameAndValue("color", QVariant(QColor(Qt::red))); + rootModelNode.variantProperty("myDouble").setDynamicTypeNameAndValue("real", 10); QVERIFY(!rootModelNode.property("x").isDynamic()); QVERIFY(rootModelNode.property("myColor").isDynamic()); QVERIFY(rootModelNode.property("myDouble").isDynamic()); QCOMPARE(rootModelNode.property("myColor").dynamicTypeName(), QString("color")); - QCOMPARE(rootModelNode.variantProperty("myColor").value(), QVariant(Qt::red)); + QCOMPARE(rootModelNode.variantProperty("myColor").value(), QVariant(QColor(Qt::red))); //QCOMPARE(rootQmlItemNode.instanceValue("myColor"), QVariant(Qt::red)); //not working yet QCOMPARE(rootModelNode.property("myDouble").dynamicTypeName(), QString("real")); QCOMPARE(rootModelNode.variantProperty("myDouble").value(), QVariant(10)); @@ -6203,7 +6455,7 @@ void tst_TestCore::testModelDynamicProperties() void tst_TestCore::testModelSliding() { - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -6212,10 +6464,10 @@ void tst_TestCore::testModelSliding() ModelNode rootModelNode(view->rootModelNode()); - ModelNode rect00(addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data")); - ModelNode rect01(addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data")); - ModelNode rect02(addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data")); - ModelNode rect03(addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data")); + ModelNode rect00(addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data")); + ModelNode rect01(addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data")); + ModelNode rect02(addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data")); + ModelNode rect03(addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data")); QVERIFY(rect00.isValid()); QVERIFY(rect01.isValid()); @@ -6271,13 +6523,13 @@ void tst_TestCore::testModelSliding() void tst_TestCore::testRewriterChangeId() { - const char* qmlString = "import Qt 4.7\nRectangle { }"; + const char* qmlString = "import QtQuick 1.1\nRectangle { }"; QPlainTextEdit textEdit; textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -6296,25 +6548,25 @@ void tst_TestCore::testRewriterChangeId() QCOMPARE(rootModelNode.id(), QString("rectId")); - QString expected = "import Qt 4.7\n" + QString expected = "import QtQuick 1.1\n" "Rectangle { id: rectId }"; QCOMPARE(textEdit.toPlainText(), expected); // change id for node outside of hierarchy - ModelNode node = view->createModelNode("Qt/Item", 4, 7); + ModelNode node = view->createModelNode("QtQuick.Item", 1, 1); node.setId("myId"); } void tst_TestCore::testRewriterRemoveId() { - const char* qmlString = "import Qt 4.7\nRectangle { id: rect }"; + const char* qmlString = "import QtQuick 1.1\nRectangle { id: rect }"; QPlainTextEdit textEdit; textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -6332,7 +6584,7 @@ void tst_TestCore::testRewriterRemoveId() // // remove id in text // - const char* qmlString2 = "import Qt 4.7\nRectangle { }"; + const char* qmlString2 = "import QtQuick 1.1\nRectangle { }"; textEdit.setPlainText(qmlString2); QCOMPARE(rootModelNode.id(), QString()); @@ -6340,13 +6592,13 @@ void tst_TestCore::testRewriterRemoveId() void tst_TestCore::testRewriterChangeValueProperty() { - const char* qmlString = "import Qt 4.7\nRectangle { x: 10; y: 10 }"; + const char* qmlString = "import QtQuick 1.1\nRectangle { x: 10; y: 10 }"; QPlainTextEdit textEdit; textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -6369,14 +6621,14 @@ void tst_TestCore::testRewriterChangeValueProperty() // change property for node outside of hierarchy PropertyListType properties; properties.append(QPair<QString,QVariant>("x", 10)); - ModelNode node = view->createModelNode("Qt/Item", 4, 7, properties); + ModelNode node = view->createModelNode("QtQuick.Item", 1, 1, properties); node.variantProperty("x").setValue(20); } void tst_TestCore::testRewriterRemoveValueProperty() { const QLatin1String qmlString("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "Rectangle {\n" " x: 10\n" " y: 10;\n" @@ -6386,7 +6638,7 @@ void tst_TestCore::testRewriterRemoveValueProperty() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -6407,7 +6659,7 @@ void tst_TestCore::testRewriterRemoveValueProperty() rootModelNode.removeProperty("x"); const QLatin1String expected("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "Rectangle {\n" " y: 10;\n" "}\n"); @@ -6416,19 +6668,19 @@ void tst_TestCore::testRewriterRemoveValueProperty() // remove property for node outside of hierarchy PropertyListType properties; properties.append(QPair<QString,QVariant>("x", 10)); - ModelNode node = view->createModelNode("Qt/Item", 4, 7, properties); + ModelNode node = view->createModelNode("QtQuick.Item", 1, 1, properties); node.removeProperty("x"); } void tst_TestCore::testRewriterSignalProperty() { - const char* qmlString = "import Qt 4.7\nRectangle { onColorChanged: {} }"; + const char* qmlString = "import QtQuick 1.1\nRectangle { onColorChanged: {} }"; QPlainTextEdit textEdit; textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -6448,13 +6700,13 @@ void tst_TestCore::testRewriterSignalProperty() void tst_TestCore::testRewriterObjectTypeProperty() { - const char* qmlString = "import Qt 4.7\nRectangle { x: 10; y: 10 }"; + const char* qmlString = "import QtQuick 1.1\nRectangle { x: 10; y: 10 }"; QPlainTextEdit textEdit; textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -6468,11 +6720,11 @@ void tst_TestCore::testRewriterObjectTypeProperty() ModelNode rootModelNode(view->rootModelNode()); QVERIFY(rootModelNode.isValid()); - QCOMPARE(rootModelNode.type(), QLatin1String("Qt/Rectangle")); + QCOMPARE(rootModelNode.type(), QLatin1String("QtQuick.Rectangle")); - view->changeRootNodeType(QLatin1String("Qt/Text"), 4, 7); + view->changeRootNodeType(QLatin1String("QtQuick.Text"), 1, 1); - QCOMPARE(rootModelNode.type(), QLatin1String("Qt/Text")); + QCOMPARE(rootModelNode.type(), QLatin1String("QtQuick.Text")); } void tst_TestCore::testRewriterPropertyChanges() @@ -6482,7 +6734,7 @@ void tst_TestCore::testRewriterPropertyChanges() // Use a slightly more complicated example so that target properties are not resolved in default scope const char* qmlString - = "import Qt 4.7\n" + = "import QtQuick 1.1\n" "Rectangle {\n" " Text {\n" " id: targetObj\n" @@ -6502,7 +6754,7 @@ void tst_TestCore::testRewriterPropertyChanges() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -6515,7 +6767,7 @@ void tst_TestCore::testRewriterPropertyChanges() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QString("Qt/Rectangle")); + QCOMPARE(rootNode.type(), QString("QtQuick.Rectangle")); QVERIFY(rootNode.propertyNames().contains(QLatin1String("data"))); QVERIFY(rootNode.propertyNames().contains(QLatin1String("states"))); QCOMPARE(rootNode.propertyNames().count(), 2); @@ -6526,7 +6778,7 @@ void tst_TestCore::testRewriterPropertyChanges() ModelNode stateNode = statesProperty.toModelNodeList().first(); QVERIFY(stateNode.isValid()); - QCOMPARE(stateNode.type(), QString("Qt/State")); + QCOMPARE(stateNode.type(), QString("QtQuick.State")); QCOMPARE(stateNode.propertyNames(), QStringList("changes")); NodeListProperty stateChangesProperty = stateNode.property("changes").toNodeListProperty(); @@ -6549,17 +6801,17 @@ void tst_TestCore::testRewriterPropertyChanges() void tst_TestCore::testRewriterListModel() { - QSKIP("See BAUHAUS-157", SkipAll); + MSKIP_ALL("See BAUHAUS-157"); try { // ListModel uses a custom parser - const char* qmlString = "import Qt 4.7; ListModel {\n ListElement {\n age: 12\n} \n}"; + const char* qmlString = "import QtQuick 1.1; ListModel {\n ListElement {\n age: 12\n} \n}"; QPlainTextEdit textEdit; textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); @@ -6588,7 +6840,7 @@ void tst_TestCore::testRewriterListModel() void tst_TestCore::testRewriterAddProperty() { const QLatin1String qmlString("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" "}"); @@ -6596,7 +6848,7 @@ void tst_TestCore::testRewriterAddProperty() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -6609,7 +6861,7 @@ void tst_TestCore::testRewriterAddProperty() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QString("Qt/Rectangle")); + QCOMPARE(rootNode.type(), QString("QtQuick.Rectangle")); rootNode.variantProperty(QLatin1String("x")).setValue(123); @@ -6618,7 +6870,7 @@ void tst_TestCore::testRewriterAddProperty() QCOMPARE(rootNode.variantProperty(QLatin1String("x")).value(), QVariant(123)); const QLatin1String expected("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" "x: 123\n" @@ -6629,7 +6881,7 @@ void tst_TestCore::testRewriterAddProperty() void tst_TestCore::testRewriterAddPropertyInNestedObject() { const QLatin1String qmlString("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " Rectangle {\n" @@ -6640,7 +6892,7 @@ void tst_TestCore::testRewriterAddPropertyInNestedObject() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -6653,18 +6905,18 @@ void tst_TestCore::testRewriterAddPropertyInNestedObject() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QLatin1String("Qt/Rectangle")); + QCOMPARE(rootNode.type(), QLatin1String("QtQuick.Rectangle")); ModelNode childNode = rootNode.nodeListProperty(QLatin1String("data")).toModelNodeList().at(0); QVERIFY(childNode.isValid()); - QCOMPARE(childNode.type(), QLatin1String("Qt/Rectangle")); + QCOMPARE(childNode.type(), QLatin1String("QtQuick.Rectangle")); QCOMPARE(childNode.id(), QLatin1String("rectangle1")); childNode.variantProperty(QLatin1String("x")).setValue(10); childNode.variantProperty(QLatin1String("y")).setValue(10); const QLatin1String expected("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " Rectangle {\n" @@ -6678,7 +6930,7 @@ void tst_TestCore::testRewriterAddPropertyInNestedObject() void tst_TestCore::testRewriterAddObjectDefinition() { - const QLatin1String qmlString("import Qt 4.7\n" + const QLatin1String qmlString("import QtQuick 1.1\n" "\n" "Rectangle {\n" "}"); @@ -6686,7 +6938,7 @@ void tst_TestCore::testRewriterAddObjectDefinition() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -6699,20 +6951,20 @@ void tst_TestCore::testRewriterAddObjectDefinition() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QString("Qt/Rectangle")); + QCOMPARE(rootNode.type(), QString("QtQuick.Rectangle")); - ModelNode childNode = view->createModelNode("Qt/MouseArea", 4, 7); + ModelNode childNode = view->createModelNode("QtQuick.MouseArea", 1, 1); rootNode.nodeAbstractProperty(QLatin1String("data")).reparentHere(childNode); QCOMPARE(rootNode.nodeProperty(QLatin1String("data")).toNodeListProperty().toModelNodeList().size(), 1); childNode = rootNode.nodeProperty(QLatin1String("data")).toNodeListProperty().toModelNodeList().at(0); - QCOMPARE(childNode.type(), QString(QLatin1String("Qt/MouseArea"))); + QCOMPARE(childNode.type(), QString(QLatin1String("QtQuick.MouseArea"))); } void tst_TestCore::testRewriterAddStatesArray() { const QLatin1String qmlString("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" "}"); @@ -6720,7 +6972,7 @@ void tst_TestCore::testRewriterAddStatesArray() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -6732,13 +6984,13 @@ void tst_TestCore::testRewriterAddStatesArray() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QString("Qt/Rectangle")); + QCOMPARE(rootNode.type(), QString("QtQuick.Rectangle")); - ModelNode stateNode = view->createModelNode("Qt/State", 4, 7); + ModelNode stateNode = view->createModelNode("QtQuick.State", 1, 0); rootNode.nodeListProperty(QLatin1String("states")).reparentHere(stateNode); const QString expected1 = QLatin1String("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" "states: [\n" @@ -6748,11 +7000,11 @@ void tst_TestCore::testRewriterAddStatesArray() "}"); QCOMPARE(textEdit.toPlainText(), expected1); - ModelNode stateNode2 = view->createModelNode("Qt/State", 4, 7); + ModelNode stateNode2 = view->createModelNode("QtQuick.State", 1, 0); rootNode.nodeListProperty(QLatin1String("states")).reparentHere(stateNode2); const QString expected2 = QLatin1String("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" "states: [\n" @@ -6768,7 +7020,7 @@ void tst_TestCore::testRewriterAddStatesArray() void tst_TestCore::testRewriterRemoveStates() { const QLatin1String qmlString("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " states: [\n" @@ -6782,7 +7034,7 @@ void tst_TestCore::testRewriterRemoveStates() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -6794,7 +7046,7 @@ void tst_TestCore::testRewriterRemoveStates() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QString("Qt/Rectangle")); + QCOMPARE(rootNode.type(), QString("QtQuick.Rectangle")); NodeListProperty statesProperty = rootNode.nodeListProperty(QLatin1String("states")); QVERIFY(statesProperty.isValid()); @@ -6804,7 +7056,7 @@ void tst_TestCore::testRewriterRemoveStates() state.destroy(); const QLatin1String expected1("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " states: [\n" @@ -6818,7 +7070,7 @@ void tst_TestCore::testRewriterRemoveStates() state.destroy(); const QLatin1String expected2("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" "}"); @@ -6828,7 +7080,7 @@ void tst_TestCore::testRewriterRemoveStates() void tst_TestCore::testRewriterRemoveObjectDefinition() { const QLatin1String qmlString("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " MouseArea {\n" @@ -6840,7 +7092,7 @@ void tst_TestCore::testRewriterRemoveObjectDefinition() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -6853,24 +7105,24 @@ void tst_TestCore::testRewriterRemoveObjectDefinition() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QString("Qt/Rectangle")); + QCOMPARE(rootNode.type(), QString("QtQuick.Rectangle")); QCOMPARE(rootNode.nodeProperty(QLatin1String("data")).toNodeListProperty().toModelNodeList().size(), 2); ModelNode childNode = rootNode.nodeProperty(QLatin1String("data")).toNodeListProperty().toModelNodeList().at(1); - QCOMPARE(childNode.type(), QString(QLatin1String("Qt/MouseArea"))); + QCOMPARE(childNode.type(), QString(QLatin1String("QtQuick.MouseArea"))); childNode.destroy(); QCOMPARE(rootNode.nodeProperty(QLatin1String("data")).toNodeListProperty().toModelNodeList().size(), 1); childNode = rootNode.nodeProperty(QLatin1String("data")).toNodeListProperty().toModelNodeList().at(0); - QCOMPARE(childNode.type(), QString(QLatin1String("Qt/MouseArea"))); + QCOMPARE(childNode.type(), QString(QLatin1String("QtQuick.MouseArea"))); childNode.destroy(); QVERIFY(!rootNode.hasProperty(QLatin1String("data"))); const QString expected = QLatin1String("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " // some comment here\n" @@ -6878,9 +7130,9 @@ void tst_TestCore::testRewriterRemoveObjectDefinition() QCOMPARE(textEdit.toPlainText(), expected); // don't crash when deleting nodes not in any hierarchy - ModelNode node1 = view->createModelNode("Qt/Rectangle", 4, 7); - ModelNode node2 = addNodeListChild(node1, "Qt/Item", 4, 7, "data"); - ModelNode node3 = addNodeListChild(node2, "Qt/Item", 4, 7, "data"); + ModelNode node1 = view->createModelNode("QtQuick.Rectangle", 1, 0); + ModelNode node2 = addNodeListChild(node1, "QtQuick.Item", 1, 1, "data"); + ModelNode node3 = addNodeListChild(node2, "QtQuick.Item", 1, 1, "data"); node3.destroy(); node1.destroy(); @@ -6889,7 +7141,7 @@ void tst_TestCore::testRewriterRemoveObjectDefinition() void tst_TestCore::testRewriterRemoveScriptBinding() { const QLatin1String qmlString("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " x: 10; // some comment\n" @@ -6899,7 +7151,7 @@ void tst_TestCore::testRewriterRemoveScriptBinding() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -6912,7 +7164,7 @@ void tst_TestCore::testRewriterRemoveScriptBinding() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QString("Qt/Rectangle")); + QCOMPARE(rootNode.type(), QString("QtQuick.Rectangle")); QCOMPARE(rootNode.properties().size(), 2); QVERIFY(rootNode.hasProperty(QLatin1String("x"))); @@ -6929,7 +7181,7 @@ void tst_TestCore::testRewriterRemoveScriptBinding() QCOMPARE(rootNode.properties().size(), 0); const QString expected = QLatin1String("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " // some comment\n" @@ -6940,7 +7192,7 @@ void tst_TestCore::testRewriterRemoveScriptBinding() void tst_TestCore::testRewriterNodeReparenting() { const QLatin1String qmlString("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " Item {\n" @@ -6952,7 +7204,7 @@ void tst_TestCore::testRewriterNodeReparenting() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -6965,15 +7217,15 @@ void tst_TestCore::testRewriterNodeReparenting() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QString("Qt/Rectangle")); + QCOMPARE(rootNode.type(), QString("QtQuick.Rectangle")); ModelNode itemNode = rootNode.nodeListProperty("data").toModelNodeList().at(0); QVERIFY(itemNode.isValid()); - QCOMPARE(itemNode.type(), QLatin1String("Qt/Item")); + QCOMPARE(itemNode.type(), QLatin1String("QtQuick.Item")); ModelNode mouseArea = itemNode.nodeListProperty("data").toModelNodeList().at(0); QVERIFY(mouseArea.isValid()); - QCOMPARE(mouseArea.type(), QLatin1String("Qt/MouseArea")); + QCOMPARE(mouseArea.type(), QLatin1String("QtQuick.MouseArea")); rootNode.nodeListProperty("data").reparentHere(mouseArea); @@ -6981,7 +7233,7 @@ void tst_TestCore::testRewriterNodeReparenting() QCOMPARE(rootNode.nodeListProperty("data").toModelNodeList().size(), 2); QString expected = "\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " Item {\n" @@ -6993,9 +7245,9 @@ void tst_TestCore::testRewriterNodeReparenting() QCOMPARE(textEdit.toPlainText(), expected); // reparenting outside of the hierarchy - ModelNode node1 = view->createModelNode("Qt/Rectangle", 4, 7); - ModelNode node2 = view->createModelNode("Qt/Item", 4, 7); - ModelNode node3 = view->createModelNode("Qt/Item", 4, 7); + ModelNode node1 = view->createModelNode("QtQuick.Rectangle", 1, 0); + ModelNode node2 = view->createModelNode("QtQuick.Item", 1, 1); + ModelNode node3 = view->createModelNode("QtQuick.Item", 1, 1); node2.nodeListProperty("data").reparentHere(node3); node1.nodeListProperty("data").reparentHere(node2); @@ -7003,7 +7255,7 @@ void tst_TestCore::testRewriterNodeReparenting() rootNode.nodeListProperty("data").reparentHere(node1); expected = "\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " Item {\n" @@ -7023,11 +7275,11 @@ void tst_TestCore::testRewriterNodeReparenting() QCOMPARE(textEdit.toPlainText(), expected); // reparent out of the hierarchy - ModelNode node4 = view->createModelNode("Qt/Rectangle", 4, 7); + ModelNode node4 = view->createModelNode("QtQuick.Rectangle", 1, 0); node4.nodeListProperty("data").reparentHere(node1); expected = "\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " Item {\n" @@ -7043,7 +7295,7 @@ void tst_TestCore::testRewriterNodeReparenting() void tst_TestCore::testRewriterNodeReparentingWithTransaction() { const QLatin1String qmlString("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " id: rootItem\n" @@ -7060,7 +7312,7 @@ void tst_TestCore::testRewriterNodeReparentingWithTransaction() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -7073,17 +7325,17 @@ void tst_TestCore::testRewriterNodeReparentingWithTransaction() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QLatin1String("Qt/Rectangle")); + QCOMPARE(rootNode.type(), QLatin1String("QtQuick.Rectangle")); QCOMPARE(rootNode.id(), QLatin1String("rootItem")); ModelNode item1Node = rootNode.nodeListProperty("data").toModelNodeList().at(0); QVERIFY(item1Node.isValid()); - QCOMPARE(item1Node.type(), QLatin1String("Qt/Item")); + QCOMPARE(item1Node.type(), QLatin1String("QtQuick.Item")); QCOMPARE(item1Node.id(), QLatin1String("firstItem")); ModelNode item2Node = rootNode.nodeListProperty("data").toModelNodeList().at(1); QVERIFY(item2Node.isValid()); - QCOMPARE(item2Node.type(), QLatin1String("Qt/Item")); + QCOMPARE(item2Node.type(), QLatin1String("QtQuick.Item")); QCOMPARE(item2Node.id(), QLatin1String("secondItem")); RewriterTransaction transaction = testRewriterView->beginRewriterTransaction(); @@ -7094,7 +7346,7 @@ void tst_TestCore::testRewriterNodeReparentingWithTransaction() transaction.commit(); const QLatin1String expected("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " id: rootItem\n" @@ -7113,7 +7365,7 @@ void tst_TestCore::testRewriterNodeReparentingWithTransaction() void tst_TestCore::testRewriterMovingInOut() { const QLatin1String qmlString("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" "}"); @@ -7121,7 +7373,7 @@ void tst_TestCore::testRewriterMovingInOut() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -7134,13 +7386,13 @@ void tst_TestCore::testRewriterMovingInOut() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QString("Qt/Rectangle")); + QCOMPARE(rootNode.type(), QString("QtQuick.Rectangle")); - ModelNode newNode = view->createModelNode("Qt/MouseArea", 4, 7); + ModelNode newNode = view->createModelNode("QtQuick.MouseArea", 1, 1); rootNode.nodeListProperty(QLatin1String("data")).reparentHere(newNode); const QLatin1String expected1("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" "MouseArea {\n" @@ -7159,17 +7411,19 @@ void tst_TestCore::testRewriterMovingInOut() newNode.destroy(); const QLatin1String expected2("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" "}"); QCOMPARE(textEdit.toPlainText(), expected2); + + QApplication::processEvents(); } void tst_TestCore::testRewriterMovingInOutWithTransaction() { const QLatin1String qmlString("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" "}"); @@ -7177,7 +7431,7 @@ void tst_TestCore::testRewriterMovingInOutWithTransaction() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -7190,11 +7444,11 @@ void tst_TestCore::testRewriterMovingInOutWithTransaction() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QString("Qt/Rectangle")); + QCOMPARE(rootNode.type(), QString("QtQuick.Rectangle")); RewriterTransaction transaction = view->beginRewriterTransaction(); - ModelNode newNode = view->createModelNode("Qt/MouseArea", 4, 7); + ModelNode newNode = view->createModelNode("QtQuick.MouseArea", 1, 1); rootNode.nodeListProperty(QLatin1String("data")).reparentHere(newNode); #define move(node, x, y) {\ @@ -7210,17 +7464,18 @@ void tst_TestCore::testRewriterMovingInOutWithTransaction() transaction.commit(); const QLatin1String expected2("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" "}"); QCOMPARE(textEdit.toPlainText(), expected2); + QApplication::processEvents(); } void tst_TestCore::testRewriterComplexMovingInOut() { const QLatin1String qmlString("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " Item {\n" @@ -7230,7 +7485,7 @@ void tst_TestCore::testRewriterComplexMovingInOut() textEdit.setPlainText(qmlString); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -7243,14 +7498,14 @@ void tst_TestCore::testRewriterComplexMovingInOut() ModelNode rootNode = view->rootModelNode(); QVERIFY(rootNode.isValid()); - QCOMPARE(rootNode.type(), QString("Qt/Rectangle")); + QCOMPARE(rootNode.type(), QString("QtQuick.Rectangle")); ModelNode itemNode = rootNode.nodeListProperty(QLatin1String("data")).toModelNodeList().at(0); - ModelNode newNode = view->createModelNode("Qt/MouseArea", 4, 7); + ModelNode newNode = view->createModelNode("QtQuick.MouseArea", 1, 1); rootNode.nodeListProperty(QLatin1String("data")).reparentHere(newNode); const QLatin1String expected1("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " Item {\n" @@ -7270,7 +7525,7 @@ void tst_TestCore::testRewriterComplexMovingInOut() move(newNode, 3, 3); const QLatin1String expected2("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " Item {\n" @@ -7286,7 +7541,7 @@ void tst_TestCore::testRewriterComplexMovingInOut() itemNode.nodeListProperty(QLatin1String("data")).reparentHere(newNode); const QLatin1String expected3("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " Item {\n" @@ -7306,22 +7561,23 @@ void tst_TestCore::testRewriterComplexMovingInOut() newNode.destroy(); const QLatin1String expected4("\n" - "import Qt 4.7\n" + "import QtQuick 1.1\n" "\n" "Rectangle {\n" " Item {\n" " }\n" "}"); QCOMPARE(textEdit.toPlainText(), expected4); + QApplication::processEvents(); } void tst_TestCore::removeCenteredInAnchorByDetaching() { QPlainTextEdit textEdit1; - textEdit1.setPlainText("import Qt 4.7; Item { Rectangle { id: child; anchors.centerIn: parent } }"); + textEdit1.setPlainText("import QtQuick 1.1; Item { Rectangle { id: child; anchors.centerIn: parent } }"); NotIndentingTextEditModifier modifier1(&textEdit1); - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(Model::create("QtQuick.Item")); QScopedPointer<TestRewriterView> testRewriterView1(new TestRewriterView()); testRewriterView1->setTextModifier(&modifier1); @@ -7372,7 +7628,7 @@ void tst_TestCore::removeCenteredInAnchorByDetaching() void tst_TestCore::changePropertyBinding() { - QScopedPointer<Model> model(Model::create("Qt/Item")); + QScopedPointer<Model> model(createModel("QtQuick.Item")); QVERIFY(model.data()); QScopedPointer<TestView> view(new TestView(model.data())); @@ -7381,7 +7637,7 @@ void tst_TestCore::changePropertyBinding() ModelNode rootModelNode(view->rootModelNode()); rootModelNode.variantProperty("width") = 20; - ModelNode firstChild = addNodeListChild(rootModelNode, "Qt/Rectangle", 4, 7, "data"); + ModelNode firstChild = addNodeListChild(rootModelNode, "QtQuick.Rectangle", 1, 0, "data"); firstChild.bindingProperty("width").setExpression(QString("parent.width")); firstChild.variantProperty("height")= 10; QVERIFY(firstChild.isValid()); @@ -7421,7 +7677,7 @@ void tst_TestCore::loadTestFiles() textEdit.setPlainText(QString(file.readAll())); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); @@ -7432,7 +7688,7 @@ void tst_TestCore::loadTestFiles() QVERIFY(model.data()); ModelNode rootModelNode(testRewriterView->rootModelNode()); QVERIFY(rootModelNode.isValid()); - QCOMPARE(rootModelNode.type(), QLatin1String("Qt/Item")); + QCOMPARE(rootModelNode.type(), QLatin1String("QtQuick.Item")); QVERIFY(rootModelNode.allDirectSubModelNodes().isEmpty()); } @@ -7444,7 +7700,7 @@ void tst_TestCore::loadTestFiles() textEdit.setPlainText(QString(file.readAll())); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); @@ -7455,14 +7711,14 @@ void tst_TestCore::loadTestFiles() QVERIFY(model.data()); ModelNode rootModelNode(testRewriterView->rootModelNode()); QVERIFY(rootModelNode.isValid()); - QCOMPARE(rootModelNode.type(), QLatin1String("Qt/Rectangle")); + QCOMPARE(rootModelNode.type(), QLatin1String("QtQuick.Rectangle")); QCOMPARE(rootModelNode.allDirectSubModelNodes().count(), 1); QCOMPARE(rootModelNode.variantProperty("width").value().toInt(), 200); QCOMPARE(rootModelNode.variantProperty("height").value().toInt(), 200); ModelNode textNode(rootModelNode.allDirectSubModelNodes().first()); QVERIFY(textNode.isValid()); - QCOMPARE(textNode.type(), QLatin1String("Qt/Text")); + QCOMPARE(textNode.type(), QLatin1String("QtQuick.Text")); QCOMPARE(textNode.variantProperty("x").value().toInt(), 66); QCOMPARE(textNode.variantProperty("y").value().toInt(), 93); } @@ -7474,7 +7730,7 @@ void tst_TestCore::loadTestFiles() textEdit.setPlainText(QString(file.readAll())); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); @@ -7485,7 +7741,7 @@ void tst_TestCore::loadTestFiles() QVERIFY(model.data()); ModelNode rootModelNode(testRewriterView->rootModelNode()); QVERIFY(rootModelNode.isValid()); - QCOMPARE(rootModelNode.type(), QLatin1String("Qt/Rectangle")); + QCOMPARE(rootModelNode.type(), QLatin1String("QtQuick.Rectangle")); QCOMPARE(rootModelNode.allDirectSubModelNodes().count(), 4); QCOMPARE(rootModelNode.variantProperty("width").value().toInt(), 200); QCOMPARE(rootModelNode.variantProperty("height").value().toInt(), 200); @@ -7496,14 +7752,14 @@ void tst_TestCore::loadTestFiles() ModelNode textNode(rootModelNode.nodeListProperty("data").toModelNodeList().first()); QVERIFY(textNode.isValid()); QCOMPARE(textNode.id(), QLatin1String("text")); - QCOMPARE(textNode.type(), QLatin1String("Qt/Text")); + QCOMPARE(textNode.type(), QLatin1String("QtQuick.Text")); QCOMPARE(textNode.variantProperty("x").value().toInt(), 66); QCOMPARE(textNode.variantProperty("y").value().toInt(), 93); ModelNode imageNode(rootModelNode.nodeListProperty("data").toModelNodeList().last()); QVERIFY(imageNode.isValid()); QCOMPARE(imageNode.id(), QLatin1String("image1")); - QCOMPARE(imageNode.type(), QLatin1String("Qt/Image")); + QCOMPARE(imageNode.type(), QLatin1String("QtQuick.Image")); QCOMPARE(imageNode.variantProperty("x").value().toInt(), 41); QCOMPARE(imageNode.variantProperty("y").value().toInt(), 46); QCOMPARE(imageNode.variantProperty("source").value().toUrl(), QUrl("images/qtcreator.png")); @@ -7514,7 +7770,7 @@ void tst_TestCore::loadTestFiles() QCOMPARE(rootModelNode.nodeListProperty("states").toModelNodeList().count(), 2); } - QSKIP("Fails because the text editor model doesn't know about components", SkipAll); + MSKIP_ALL("Fails because the text editor model doesn't know about components"); { //usingbutton.qml QFile file(":/fx/usingbutton.qml"); QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); @@ -7523,7 +7779,7 @@ void tst_TestCore::loadTestFiles() textEdit.setPlainText(QString(file.readAll())); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); @@ -7535,12 +7791,12 @@ void tst_TestCore::loadTestFiles() QVERIFY(model.data()); ModelNode rootModelNode(testRewriterView->rootModelNode()); QVERIFY(rootModelNode.isValid()); - QCOMPARE(rootModelNode.type(), QLatin1String("Qt/Rectangle")); + QCOMPARE(rootModelNode.type(), QLatin1String("QtQuick.Rectangle")); QVERIFY(!rootModelNode.allDirectSubModelNodes().isEmpty()); } } -static QString rectWithGradient = "import Qt 4.7\n" +static QString rectWithGradient = "import QtQuick 1.1\n" "Rectangle {\n" " gradient: Gradient {\n" " id: pGradient\n" @@ -7560,7 +7816,7 @@ void tst_TestCore::loadGradient() textEdit.setPlainText(rectWithGradient); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); @@ -7579,7 +7835,7 @@ void tst_TestCore::loadGradient() QVERIFY(gradientProperty.isNodeProperty()); ModelNode gradientPropertyModelNode = gradientProperty.toNodeProperty().modelNode(); QVERIFY(gradientPropertyModelNode.isValid()); - QCOMPARE(gradientPropertyModelNode.type(), QString("Qt/Gradient")); + QCOMPARE(gradientPropertyModelNode.type(), QString("QtQuick.Gradient")); QCOMPARE(gradientPropertyModelNode.allDirectSubModelNodes().size(), 2); AbstractProperty stopsProperty = gradientPropertyModelNode.property("stops"); @@ -7592,7 +7848,7 @@ void tst_TestCore::loadGradient() ModelNode pOne = stops.first(); ModelNode pTwo = stops.last(); - QCOMPARE(pOne.type(), QString("Qt/GradientStop")); + QCOMPARE(pOne.type(), QString("QtQuick.GradientStop")); QCOMPARE(pOne.id(), QString("pOne")); QCOMPARE(pOne.allDirectSubModelNodes().size(), 0); QCOMPARE(pOne.propertyNames().size(), 2); @@ -7601,7 +7857,7 @@ void tst_TestCore::loadGradient() QCOMPARE(pOne.variantProperty("color").value().type(), QVariant::Color); QCOMPARE(pOne.variantProperty("color").value().value<QColor>(), QColor("lightsteelblue")); - QCOMPARE(pTwo.type(), QString("Qt/GradientStop")); + QCOMPARE(pTwo.type(), QString("QtQuick.GradientStop")); QCOMPARE(pTwo.id(), QString("pTwo")); QCOMPARE(pTwo.allDirectSubModelNodes().size(), 0); QCOMPARE(pTwo.propertyNames().size(), 2); @@ -7614,8 +7870,8 @@ void tst_TestCore::loadGradient() { ModelNode gradientNode = rootModelNode.allDirectSubModelNodes().last(); QVERIFY(gradientNode.isValid()); - QVERIFY(!gradientNode.metaInfo().isSubclassOf("Qt/Item", -1, -1)); - QCOMPARE(gradientNode.type(), QString("Qt/Gradient")); + QVERIFY(!gradientNode.metaInfo().isSubclassOf("QtQuick.Item", -1, -1)); + QCOMPARE(gradientNode.type(), QString("QtQuick.Gradient")); QCOMPARE(gradientNode.id(), QString("secondGradient")); QCOMPARE(gradientNode.allDirectSubModelNodes().size(), 2); @@ -7629,7 +7885,7 @@ void tst_TestCore::loadGradient() ModelNode nOne = stops.first(); ModelNode nTwo = stops.last(); - QCOMPARE(nOne.type(), QString("Qt/GradientStop")); + QCOMPARE(nOne.type(), QString("QtQuick.GradientStop")); QCOMPARE(nOne.id(), QString("nOne")); QCOMPARE(nOne.allDirectSubModelNodes().size(), 0); QCOMPARE(nOne.propertyNames().size(), 2); @@ -7638,7 +7894,7 @@ void tst_TestCore::loadGradient() QCOMPARE(nOne.variantProperty("color").value().type(), QVariant::Color); QCOMPARE(nOne.variantProperty("color").value().value<QColor>(), QColor("blue")); - QCOMPARE(nTwo.type(), QString("Qt/GradientStop")); + QCOMPARE(nTwo.type(), QString("QtQuick.GradientStop")); QCOMPARE(nTwo.id(), QString("nTwo")); QCOMPARE(nTwo.allDirectSubModelNodes().size(), 0); QCOMPARE(nTwo.propertyNames().size(), 2); @@ -7656,7 +7912,7 @@ void tst_TestCore::changeGradientId() textEdit.setPlainText(rectWithGradient); NotIndentingTextEditModifier textModifier(&textEdit); - QScopedPointer<Model> model(Model::create("Qt/Item", 4, 7)); + QScopedPointer<Model> model(Model::create("QtQuick.Item", 1, 1)); QVERIFY(model.data()); QScopedPointer<TestRewriterView> testRewriterView(new TestRewriterView()); @@ -7689,7 +7945,7 @@ void tst_TestCore::changeGradientId() firstStop.destroy(); QVERIFY(!firstStop.isValid()); - ModelNode gradientStop = addNodeListChild(gradientNode, "Qt/GradientStop", 4, 7, "stops"); + ModelNode gradientStop = addNodeListChild(gradientNode, "QtQuick.GradientStop", 1, 0, "stops"); gradientStop.variantProperty("position") = 0.5; gradientStop.variantProperty("color") = QColor("yellow"); diff --git a/tests/auto/qml/qmldesigner/coretests/tst_testcore.h b/tests/auto/qml/qmldesigner/coretests/tst_testcore.h index f8489ed54b..a8293a33ae 100644 --- a/tests/auto/qml/qmldesigner/coretests/tst_testcore.h +++ b/tests/auto/qml/qmldesigner/coretests/tst_testcore.h @@ -44,6 +44,10 @@ public: private slots: void initTestCase(); void cleanupTestCase(); + void init(); + void cleanup(); + + // // unit tests MetaInfo, NodeMetaInfo, PropertyMetaInfo @@ -57,7 +61,10 @@ private slots: void testMetaInfoEnums(); void testMetaInfoProperties(); void testMetaInfoDotProperties(); + void testMetaInfoQtQuick1Vs2(); void testMetaInfoListProperties(); + void testQtQuick20Basic(); + void testQtQuick20BasicRectangle(); // // unit tests Model, ModelNode, NodeProperty, AbstractView @@ -161,6 +168,7 @@ private slots: // integration tests // void testBasicStates(); + void testBasicStatesQtQuick20(); void testStates(); void testStatesBaseState(); void testStatesRewriter(); diff --git a/tests/auto/qml/qmldesigner/testview.cpp b/tests/auto/qml/qmldesigner/testview.cpp index b4383ecb4c..b1d0aca75a 100644 --- a/tests/auto/qml/qmldesigner/testview.cpp +++ b/tests/auto/qml/qmldesigner/testview.cpp @@ -30,6 +30,7 @@ #include "testview.h" #include <QDebug> +#include <QUrl> #include <qtestcase.h> #include <abstractproperty.h> #include <bindingproperty.h> @@ -151,10 +152,10 @@ void TestView::nodeOrderChanged(const QmlDesigner::NodeListProperty &listPropert m_methodCalls += MethodCall("nodeOrderChanged", QStringList() << listProperty.name() << movedNode.id() << QString::number(oldIndex)); } -void TestView::stateChanged(const QmlDesigner::QmlModelState &newQmlModelState, const QmlDesigner::QmlModelState &oldQmlModelState) +void TestView::actualStateChanged(const QmlDesigner::ModelNode &node) { - QmlDesigner::QmlModelView::stateChanged(newQmlModelState, oldQmlModelState); - m_methodCalls += MethodCall("stateChanged", QStringList() << newQmlModelState.name() << oldQmlModelState.name()); + QmlDesigner::QmlModelView::actualStateChanged(node); + m_methodCalls += MethodCall("actualStateChanged", QStringList() << node.id()); } QList<TestView::MethodCall> &TestView::methodCalls() diff --git a/tests/auto/qml/qmldesigner/testview.h b/tests/auto/qml/qmldesigner/testview.h index 13033402a1..a377d38d92 100644 --- a/tests/auto/qml/qmldesigner/testview.h +++ b/tests/auto/qml/qmldesigner/testview.h @@ -72,8 +72,7 @@ public: void nodeOrderChanged(const QmlDesigner::NodeListProperty &listProperty, const QmlDesigner::ModelNode &movedNode, int oldIndex); - void stateChanged(const QmlDesigner::QmlModelState &newQmlModelState, const QmlDesigner::QmlModelState &oldQmlModelState); - + void actualStateChanged(const QmlDesigner::ModelNode &node); QList<MethodCall> &methodCalls(); QString lastFunction() const; diff --git a/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp b/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp index 338015b9c1..d5358c3f61 100644 --- a/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp +++ b/tests/auto/qml/qmleditor/qmlcodeformatter/tst_qmlcodeformatter.cpp @@ -75,7 +75,8 @@ private Q_SLOTS: void ifStatementWithBraces3(); void ifStatementMixed(); void ifStatementAndComments(); - void ifStatementLongCondition(); + void ifStatementLongCondition1(); + void ifStatementLongCondition2(); void moreIfThenElse(); void strayElse(); void oneLineIf(); @@ -941,7 +942,7 @@ void tst_QMLCodeFormatter::ifStatementAndComments() checkIndent(data); } -void tst_QMLCodeFormatter::ifStatementLongCondition() +void tst_QMLCodeFormatter::ifStatementLongCondition1() { QList<Line> data; data << Line("Rectangle {") @@ -958,6 +959,23 @@ void tst_QMLCodeFormatter::ifStatementLongCondition() checkIndent(data); } +void tst_QMLCodeFormatter::ifStatementLongCondition2() +{ + QList<Line> data; + data << Line("function test() {") + << Line(" if (foo(function() {") + << Line(" if (xx) {") + << Line(" yy = yy - 1") + << Line(" } else {") + << Line(" yy = yy + 1") + << Line(" }") + << Line(" })) {") + << Line(" zz = !zz") + << Line(" }") + << Line("}"); + checkIndent(data); +} + void tst_QMLCodeFormatter::strayElse() { QList<Line> data; @@ -1572,7 +1590,7 @@ void tst_QMLCodeFormatter::bug3() checkIndent(data); } -QTEST_APPLESS_MAIN(tst_QMLCodeFormatter) +QTEST_MAIN(tst_QMLCodeFormatter) #include "tst_qmlcodeformatter.moc" diff --git a/tests/auto/qml/qmljssimplereader/qmljssimplereader.pro b/tests/auto/qml/qmljssimplereader/qmljssimplereader.pro new file mode 100644 index 0000000000..20722acddf --- /dev/null +++ b/tests/auto/qml/qmljssimplereader/qmljssimplereader.pro @@ -0,0 +1,12 @@ +include(../../qttest.pri) + +DEFINES+=QTCREATORDIR=\\\"$$IDE_SOURCE_TREE\\\" +DEFINES+=TESTSRCDIR=\\\"$$PWD\\\" + +include($$IDE_SOURCE_TREE/src/libs/utils/utils.pri) +include($$IDE_SOURCE_TREE/src/libs/qmljs/qmljs.pri) + +TARGET = tst_qmljssimplereader + +SOURCES += \ + tst_qmljssimplereader.cpp diff --git a/tests/auto/qml/qmljssimplereader/tst_qmljssimplereader.cpp b/tests/auto/qml/qmljssimplereader/tst_qmljssimplereader.cpp new file mode 100644 index 0000000000..80972ca410 --- /dev/null +++ b/tests/auto/qml/qmljssimplereader/tst_qmljssimplereader.cpp @@ -0,0 +1,257 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include <qmljs/qmljssimplereader.h> + +#include <QtTest> +#include <algorithm> + +using namespace QmlJS; + +class tst_SimpleReader : public QObject +{ + Q_OBJECT +public: + tst_SimpleReader(); + +private slots: + void testWellFormed(); + void testIllFormed01(); + void testIllFormed02(); + void testArrays(); + void testBug01(); +}; + +tst_SimpleReader::tst_SimpleReader() +{ +} + +void tst_SimpleReader::testWellFormed() +{ + char source[] = "RootNode {\n" + " ChildNode {\n" + " property01: 10\n" + " }\n" + " ChildNode {\n" + " propertyString: \"str\"\n" + " InnerChild {\n" + " test: \"test\"\n" + " }\n" + " }\n" + " propertyBlah: false\n" + "}\n"; + + QmlJS::SimpleReaderNode::WeakPtr weak01; + QmlJS::SimpleReaderNode::WeakPtr weak02; + { + QmlJS::SimpleReader reader; + QmlJS::SimpleReaderNode::Ptr rootNode = reader.readFromSource(source); + QVERIFY(reader.errors().isEmpty()); + QVERIFY(rootNode); + QVERIFY(rootNode->isValid()); + QCOMPARE(rootNode->name(), QLatin1String("RootNode")); + + QCOMPARE(rootNode->children().count(), 2); + QCOMPARE(rootNode->properties().count(), 1); + + QVERIFY(rootNode->properties().contains("propertyBlah")); + QCOMPARE(rootNode->property("property01").toBool(), false); + + QVERIFY(rootNode->children().first()->isValid()); + QVERIFY(!rootNode->children().first()->isRoot()); + + QVERIFY(rootNode->children().first()->properties().contains("property01")); + QCOMPARE(rootNode->children().first()->property("property01").toInt(), 10); + + QmlJS::SimpleReaderNode::Ptr secondChild = rootNode->children().at(1); + + QVERIFY(secondChild); + QVERIFY(secondChild->isValid()); + QVERIFY(!secondChild->isRoot()); + QCOMPARE(secondChild->name(), QLatin1String("ChildNode")); + + QVERIFY(secondChild->properties().contains("propertyString")); + QCOMPARE(secondChild->property("propertyString").toString(), QLatin1String("str")); + + QCOMPARE(secondChild->children().count(), 1); + + QmlJS::SimpleReaderNode::Ptr innerChild = secondChild->children().first(); + + QVERIFY(innerChild); + QVERIFY(innerChild->isValid()); + QVERIFY(!innerChild->isRoot()); + QCOMPARE(innerChild->name(), QLatin1String("InnerChild")); + + QVERIFY(innerChild->properties().contains("test")); + QCOMPARE(innerChild->property("test").toString(), QLatin1String("test")); + + weak01 = rootNode; + weak02 = secondChild; + } + + QVERIFY(!weak01); + QVERIFY(!weak02); +} + +void tst_SimpleReader::testIllFormed01() +{ + char source[] = "RootNode {\n" + " ChildNode {\n" + " property01: 10\n" + " }\n" + " ChildNode {\n" + " propertyString: \"str\"\n" + " InnerChild \n" //missing { + " test: \"test\"\n" + " }\n" + " }\n" + " propertyBlah: false\n" + "}\n"; + QmlJS::SimpleReader reader; + QmlJS::SimpleReaderNode::Ptr rootNode = reader.readFromSource(source); + + QVERIFY(!rootNode); + QVERIFY(!reader.errors().empty()); +} + +void tst_SimpleReader::testIllFormed02() +{ + char source[] = "RootNode {\n" + " ChildNode {\n" + " property01: 10\n" + " property01: 20\n" + " }\n" + " ChildNode {\n" + " propertyString: \"str\"\n" + " InnerChild {\n" + " test: \"test\"\n" + " test: \"test2\"\n" + " }\n" + " }\n" + "}\n"; + + QmlJS::SimpleReader reader; + QmlJS::SimpleReaderNode::Ptr rootNode = reader.readFromSource(source); + + QVERIFY(rootNode); + QVERIFY(rootNode->isValid()); + QVERIFY(rootNode->isRoot()); + + QVERIFY(!reader.errors().empty()); + QCOMPARE(reader.errors().count(), 2); + + QmlJS::SimpleReaderNode::Ptr firstChild = rootNode->children().at(0); + + QVERIFY(firstChild); + QVERIFY(firstChild->isValid()); + QVERIFY(!firstChild->isRoot()); + + QCOMPARE(firstChild->properties().count(), 1); + QVERIFY(firstChild->properties().contains("property01")); + QCOMPARE(firstChild->property("property01").toString(), QLatin1String("20")); +} + +void tst_SimpleReader::testArrays() +{ + char source[] = "RootNode {\n" + " propertyArray: [\"string01\", \"string02\" ]\n" + " ChildNode {\n" + " propertyArray: [\"string01\", \"string02\" ]\n" + " propertyArrayMixed: [\"string03\", [\"string01\", \"string02\"] ]\n" + " }\n" + "}\n"; + + QList<QVariant> variantList; + variantList << QVariant(QLatin1String("string01")) << QVariant(QLatin1String("string02")); + const QVariant variant = variantList; + + QmlJS::SimpleReader reader; + QmlJS::SimpleReaderNode::Ptr rootNode = reader.readFromSource(source); + + QVERIFY(rootNode); + QVERIFY(rootNode->isValid()); + QVERIFY(rootNode->isRoot()); + + QCOMPARE(rootNode->property("propertyArray"), variant); + + + QmlJS::SimpleReaderNode::Ptr firstChild = rootNode->children().at(0); + + QVERIFY(firstChild); + QVERIFY(firstChild->isValid()); + QVERIFY(!firstChild->isRoot()); + QCOMPARE(firstChild->property("propertyArray"), variant); + + QList<QVariant> variantList2; + variantList2 << QVariant(QLatin1String("string03")) << variant; + const QVariant variant2 = variantList2; + + QCOMPARE(firstChild->property("propertyArrayMixed"), variant2); +} + +void tst_SimpleReader::testBug01() +{ + char source[] = "\n" + "AutoTypes {\n" + " imports: [ \"import HelperWidgets 1.0\", \"import QtQuick 1.0\", \"import Bauhaus 1.0\" ]\n" + " Type {\n" + " typeNames: [\"int\"]\n" + " sourceFile: \"IntEditorTemplate.qml\"\n" + " }\n" + " Type {\n" + " typeNames: [\"real\", \"double\", \"qreal\"]\n" + " sourceFile: \"RealEditorTemplate.qml\"\n" + " }\n" + " Type {\n" + " typeNames: [\"string\", \"QString\", \"QUrl\", \"url\"]\n" + " sourceFile: \"StringEditorTemplate.qml\"\n" + " }\n" + " Type {\n" + " typeNames: [\"bool\", \"boolean\"]\n" + " sourceFile: \"BooleanEditorTemplate.qml\"\n" + " }\n" + " Type {\n" + " typeNames: [\"color\", \"QColor\"]\n" + " sourceFile: \"ColorEditorTemplate.qml\"\n" + " }\n" + "}\n"; + + QmlJS::SimpleReader reader; + QmlJS::SimpleReaderNode::Ptr rootNode = reader.readFromSource(source); + + QVERIFY(rootNode); + QVERIFY(rootNode->isValid()); + QVERIFY(rootNode->isRoot()); + + QCOMPARE(rootNode->propertyNames().count(), 1); +} + +QTEST_MAIN(tst_SimpleReader); + +#include "tst_qmljssimplereader.moc" diff --git a/tests/auto/qml/qmlprojectmanager/fileformat/fileformat.pro b/tests/auto/qml/qmlprojectmanager/fileformat/fileformat.pro index ec195534d9..639e7b7a04 100644 --- a/tests/auto/qml/qmlprojectmanager/fileformat/fileformat.pro +++ b/tests/auto/qml/qmlprojectmanager/fileformat/fileformat.pro @@ -6,6 +6,7 @@ QT += script \ PLUGIN_DIR=../../../../../src/plugins/qmlprojectmanager include($$PLUGIN_DIR/fileformat/fileformat.pri) +include($$IDE_SOURCE_TREE/src/libs/utils/utils.pri) INCLUDEPATH += $$PLUGIN_DIR/fileformat diff --git a/tests/auto/qttest.pri b/tests/auto/qttest.pri index cc4ce6888c..83a24b73e1 100644 --- a/tests/auto/qttest.pri +++ b/tests/auto/qttest.pri @@ -6,6 +6,7 @@ QT += testlib CONFIG += qt warn_on console depend_includepath testcase CONFIG -= app_bundle +DEFINES -= QT_NO_CAST_FROM_ASCII # prefix test binary with tst_ !contains(TARGET, ^tst_.*):TARGET = $$join(TARGET,,"tst_") diff --git a/tests/cppmodelmanager/testdata/frameworks/My.framework/Frameworks b/tests/cppmodelmanager/testdata/frameworks/My.framework/Frameworks new file mode 120000 index 0000000000..dc3d02e21f --- /dev/null +++ b/tests/cppmodelmanager/testdata/frameworks/My.framework/Frameworks @@ -0,0 +1 @@ +Versions/A/Frameworks
\ No newline at end of file diff --git a/tests/cppmodelmanager/testdata/frameworks/My.framework/Headers b/tests/cppmodelmanager/testdata/frameworks/My.framework/Headers new file mode 120000 index 0000000000..d5ab97c5c7 --- /dev/null +++ b/tests/cppmodelmanager/testdata/frameworks/My.framework/Headers @@ -0,0 +1 @@ +Versions/A/Headers
\ No newline at end of file diff --git a/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/A/Frameworks/Nested.framework/Headers b/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/A/Frameworks/Nested.framework/Headers new file mode 120000 index 0000000000..a177d2a6b9 --- /dev/null +++ b/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/A/Frameworks/Nested.framework/Headers @@ -0,0 +1 @@ +Versions/Current/Headers
\ No newline at end of file diff --git a/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/A/Frameworks/Nested.framework/Versions/A/Headers/IncorrectVersion.h b/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/A/Frameworks/Nested.framework/Versions/A/Headers/IncorrectVersion.h new file mode 100644 index 0000000000..8034d179c6 --- /dev/null +++ b/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/A/Frameworks/Nested.framework/Versions/A/Headers/IncorrectVersion.h @@ -0,0 +1,4 @@ +#ifndef IncorrectVersion_h +#define IncorrectVersion_h + +#endif // IncorrectVersion_h diff --git a/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/A/Frameworks/Nested.framework/Versions/A/Headers/Nested.h b/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/A/Frameworks/Nested.framework/Versions/A/Headers/Nested.h new file mode 100644 index 0000000000..fc0234ab64 --- /dev/null +++ b/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/A/Frameworks/Nested.framework/Versions/A/Headers/Nested.h @@ -0,0 +1,6 @@ +#ifndef Nested_h +#define Nested_h + +#include "IncorrectVersion.h" + +#endif // Nested_h diff --git a/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/A/Frameworks/Nested.framework/Versions/B/Headers/CorrectVersion.h b/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/A/Frameworks/Nested.framework/Versions/B/Headers/CorrectVersion.h new file mode 100644 index 0000000000..c4df20a40a --- /dev/null +++ b/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/A/Frameworks/Nested.framework/Versions/B/Headers/CorrectVersion.h @@ -0,0 +1,4 @@ +#ifndef CorrectVersion_h +#define CorrectVersion_h + +#endif // CorrectVersion_h diff --git a/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/A/Frameworks/Nested.framework/Versions/B/Headers/Nested.h b/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/A/Frameworks/Nested.framework/Versions/B/Headers/Nested.h new file mode 100644 index 0000000000..79067d54e1 --- /dev/null +++ b/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/A/Frameworks/Nested.framework/Versions/B/Headers/Nested.h @@ -0,0 +1,6 @@ +#ifndef Nested_h +#define Nested_h + +#include "CorrectVersion.h" + +#endif // Nested_h diff --git a/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/A/Frameworks/Nested.framework/Versions/Current b/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/A/Frameworks/Nested.framework/Versions/Current new file mode 120000 index 0000000000..7371f47a6f --- /dev/null +++ b/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/A/Frameworks/Nested.framework/Versions/Current @@ -0,0 +1 @@ +B
\ No newline at end of file diff --git a/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/A/Headers/MyHeader.h b/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/A/Headers/MyHeader.h new file mode 100644 index 0000000000..8ca3e6e88c --- /dev/null +++ b/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/A/Headers/MyHeader.h @@ -0,0 +1,6 @@ +#ifndef MyHeader_h +#define MyHeader_h + +#include <Nested/Nested.h> + +#endif // MyHeader_h diff --git a/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/Current b/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/Current new file mode 120000 index 0000000000..8c7e5a667f --- /dev/null +++ b/tests/cppmodelmanager/testdata/frameworks/My.framework/Versions/Current @@ -0,0 +1 @@ +A
\ No newline at end of file diff --git a/tests/cppmodelmanager/testdata/include/header.h b/tests/cppmodelmanager/testdata/include/header.h new file mode 100644 index 0000000000..689ec03871 --- /dev/null +++ b/tests/cppmodelmanager/testdata/include/header.h @@ -0,0 +1,4 @@ +#ifndef HEADER_H +#define HEADER_H + +#endif // HEADER_H diff --git a/tests/cppmodelmanager/testdata/sources/test_modelmanager_framework_headers.cpp b/tests/cppmodelmanager/testdata/sources/test_modelmanager_framework_headers.cpp new file mode 100644 index 0000000000..27a6b5e518 --- /dev/null +++ b/tests/cppmodelmanager/testdata/sources/test_modelmanager_framework_headers.cpp @@ -0,0 +1,19 @@ +#include <My/MyHeader.h> + +#ifndef MyHeader_h +bool failure_MyHeader_not_included; +#endif + +#ifndef Nested_h +bool failure_Nested_header_not_included; +#endif + +#ifdef IncorrectVersion_h +bool failure_Incorrect_version_of_nested_header_included; +#endif + +#ifdef CorrectVersion_h +bool success_is_the_only_option; +#endif + + diff --git a/tests/manual/appwizards/main.cpp b/tests/manual/appwizards/main.cpp index 00afe96a42..0e9d40f6d6 100644 --- a/tests/manual/appwizards/main.cpp +++ b/tests/manual/appwizards/main.cpp @@ -71,26 +71,6 @@ int main(int argc, char *argv[]) } { - const QString rootPath = QLatin1String("../appwizards/qmlimportscenario_02/"); - QtQuickApp sAppImport02; - sAppImport02.setProjectPath(projectPath); - sAppImport02.setProjectName(QLatin1String("qml_imported_scenario_02")); - sAppImport02.setMainQml(QtQuickApp::ModeImport, rootPath + QLatin1String("subfolder1/myqmlapp.qml")); - QStringList moduleNames; - moduleNames.append(QLatin1String("no.trolltech.QmlModule01")); - moduleNames.append(QLatin1String("com.nokia.QmlModule02")); - QStringList importPaths; - importPaths.append(rootPath + QLatin1String("subfolder2/")); - importPaths.append(rootPath + QLatin1String("subfolder3/")); - if (!sAppImport02.setExternalModules(moduleNames, importPaths)) { - qDebug() << sAppImport02.error(); - return 2; - } - if (!sAppImport02.generateFiles(&errorMessage)) - return 1; - } - - { Html5App sAppNew; sAppNew.setProjectPath(projectPath); sAppNew.setProjectName(QLatin1String("new_html5_app")); diff --git a/tests/manual/appwizards/qmlimportscenario_02/subfolder2/no/trolltech/QmlModule01/apple.svg b/tests/manual/appwizards/qmlimportscenario_02/subfolder2/no/trolltech/QmlModule01/apple.svg deleted file mode 100644 index 31288ecce4..0000000000 --- a/tests/manual/appwizards/qmlimportscenario_02/subfolder2/no/trolltech/QmlModule01/apple.svg +++ /dev/null @@ -1,16 +0,0 @@ -<svg height="100%" version="1.1" viewBox="0 0 50 50" width="100%" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg"> - <defs> - </defs> - <metadata> - <rdf:RDF> - <cc:Work rdf:about=""> - <dc:format>image/svg+xml</dc:format> - <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/> - <dc:title/> - </cc:Work> - </rdf:RDF> - </metadata> - <path d="m22.7,3.84c-1.06,3.24-1.17,7.42-0.191,12.7" fill="none" stroke="#830" stroke-width="2.5"/> - <path d="m36.8,12.9c6.24,3.02,11.1,9.74,10.3,16.9-0.548,5.22-3.35,10.1-7.3,13.5-3.99,2.83-7.36-0.79-11.9-0.037-4.75,0.587-8.68,3.8-13.3,1.88-8.57-3.18-12.1-6.91-12.2-16.4,0.0813-6.01,2.05-12,7.75-14.6,2.95-1.03,8.83-0.118,12,0.363,4.83-3.24,9.26-3.55,14.6-1.61z" fill="#3A0"/> - <path d="m14,16.1c0.683,1.19-1.08,1.56-2.56,3.1-1.48,1.53-2.28,4.13-3.78,3.92-1.5-0.21-0.485-4.18,1.47-5.74,1.95-1.56,4.19-2.47,4.87-1.28z" fill="#FFF" opacity="0.5"/> -</svg>
\ No newline at end of file diff --git a/tests/manual/appwizards/qmlimportscenario_02/subfolder2/no/trolltech/QmlModule01/qmldir b/tests/manual/appwizards/qmlimportscenario_02/subfolder2/no/trolltech/QmlModule01/qmldir deleted file mode 100644 index 3a36c14330..0000000000 --- a/tests/manual/appwizards/qmlimportscenario_02/subfolder2/no/trolltech/QmlModule01/qmldir +++ /dev/null @@ -1 +0,0 @@ -QmlComponent01 1.0 QmlComponent01.qml
\ No newline at end of file diff --git a/tests/manual/appwizards/qmlimportscenario_02/subfolder3/com/nokia/QmlModule02/qmldir b/tests/manual/appwizards/qmlimportscenario_02/subfolder3/com/nokia/QmlModule02/qmldir deleted file mode 100644 index 33f694a57e..0000000000 --- a/tests/manual/appwizards/qmlimportscenario_02/subfolder3/com/nokia/QmlModule02/qmldir +++ /dev/null @@ -1 +0,0 @@ -QmlComponent02 1.0 QmlComponent02.qml
\ No newline at end of file diff --git a/tests/manual/appwizards/qmlimportscenario_02/subfolder3/com/nokia/QmlModule02/tomato.svg b/tests/manual/appwizards/qmlimportscenario_02/subfolder3/com/nokia/QmlModule02/tomato.svg deleted file mode 100644 index c0df58c20b..0000000000 --- a/tests/manual/appwizards/qmlimportscenario_02/subfolder3/com/nokia/QmlModule02/tomato.svg +++ /dev/null @@ -1,16 +0,0 @@ -<svg height="100%" id="svg2" version="1.1" viewBox="0 0 50 50" width="100%" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg"> - <defs id="defs14"> - </defs> - <metadata id="metadata4"> - <rdf:RDF> - <cc:Work rdf:about=""> - <dc:format>image/svg+xml</dc:format> - <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/> - <dc:title/> - </cc:Work> - </rdf:RDF> - </metadata> - <path d="M24.7,5.65c-2.7,2.23-3.2,5.65-2.2,10.8" fill="none" stroke="#080" stroke-width="2.5"/> - <path d="m41.6,16.9c6.71,7.89,3.30,18.5-2.42,23.6-5.73,5.11-16.2,6.50-26.6,1.84-10.4-4.7-13.1-21.3-3.65-27,9.45-5.68,26-6.29,32.6,1.6z" fill="#F00"/> - <path d="m15.6,15.3c0.683,1.19-1.88,1.16-4.97,4.10-2.95,2.8-2.64,6.7-4.14,6.5-1.50-0.2,0.72-7,2.67-8.5,1.95-1.56,5.80-3.27,6.48-2.08z" fill="#FFF" opacity="0.5"/> -</svg>
\ No newline at end of file diff --git a/tests/manual/cplusplus-frontend/cplusplus-frontend.cpp b/tests/manual/cplusplus-frontend/cplusplus-frontend.cpp index 531f493d3f..e964b78370 100644 --- a/tests/manual/cplusplus-frontend/cplusplus-frontend.cpp +++ b/tests/manual/cplusplus-frontend/cplusplus-frontend.cpp @@ -72,11 +72,11 @@ int main(int argc, char *argv[]) bool optionVerbose = false; // Process options & arguments - if (args.contains("-v")) { + if (args.contains(QLatin1String("-v"))) { optionVerbose = true; - args.removeOne("-v"); + args.removeOne(QLatin1String("-v")); } - const bool helpRequested = args.contains("-h") || args.contains("-help"); + const bool helpRequested = args.contains(QLatin1String("-h")) || args.contains(QLatin1String("-help")); if (args.isEmpty() || helpRequested) { printUsage(); return helpRequested ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/tests/manual/debugger/simple/deep/deep/simple_test_app.h b/tests/manual/debugger/simple/deep/deep/simple_test_app.h index 504dd15e47..820fe560c7 100644 --- a/tests/manual/debugger/simple/deep/deep/simple_test_app.h +++ b/tests/manual/debugger/simple/deep/deep/simple_test_app.h @@ -149,7 +149,7 @@ namespace breakpoints { // <=== Break here. Twice<int> cc = Twice<int>(1); Twice<float> dd = Twice<float>(1.0); - dummyStatement(&a, &b, &c, &d, &e, &f, &z, bb, aa, cc, dd); + dummyStatement(&a, &b, &c, &d, &e, &f, &z, &bb, &aa, &cc, &dd); } } // namespace breakpoints diff --git a/tests/manual/debugger/simple/simple_test_app.cpp b/tests/manual/debugger/simple/simple_test_app.cpp index 04c47d4b07..8a8c18a394 100644 --- a/tests/manual/debugger/simple/simple_test_app.cpp +++ b/tests/manual/debugger/simple/simple_test_app.cpp @@ -767,13 +767,23 @@ namespace qdir { void testQDir() { +#ifdef Q_OS_WIN + QDir dir("C:\\Program Files"); + dir.absolutePath(); // Keep in to facilitate stepping + BREAK_HERE; + // Check dir "C:/Program Files" QDir. + // Check dir.absolutePath "C:/Program Files" QString. + // Check dir.canonicalPath "C:/Program Files" QString. + // Continue. +#else QDir dir("/tmp"); - dir.absolutePath(); + dir.absolutePath(); // Keep in to facilitate stepping BREAK_HERE; // Check dir "/tmp" QDir. // Check dir.absolutePath "/tmp" QString. // Check dir.canonicalPath "/tmp" QString. // Continue. +#endif dummyStatement(&dir); } @@ -784,6 +794,18 @@ namespace qfileinfo { void testQFileInfo() { +#ifdef Q_OS_WIN + QFile file("C:\\Program Files\\t"); + file.setObjectName("A QFile instance"); + QFileInfo fi("C:\\Program Files\\tt"); + QString s = fi.absoluteFilePath(); + BREAK_HERE; + // Check fi "C:/Program Files/tt" QFileInfo. + // Check file "C:\Program Files\t" QFile. + // Check s "C:/Program Files/tt" QString. + // Continue. + dummyStatement(&file, &s); +#else QFile file("/tmp/t"); file.setObjectName("A QFile instance"); QFileInfo fi("/tmp/tt"); @@ -794,6 +816,7 @@ namespace qfileinfo { // Check s "/tmp/tt" QString. // Continue. dummyStatement(&file, &s); +#endif } } // namespace qfileinfo @@ -3451,7 +3474,11 @@ namespace stdstream { BREAK_HERE; // CheckType is std::ifstream. // Continue. +#ifdef Q_OS_WIN + is.open("C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe"); +#else is.open("/etc/passwd"); +#endif BREAK_HERE; // Continue. bool ok = is.good(); @@ -3676,11 +3703,22 @@ namespace qstring { dummyStatement(&str, &string, pstring); } + void testQStringRef() + { + QString str = "Hello"; + QStringRef ref(&str, 1, 2); + BREAK_HERE; + // Check ref "el" QStringRef. + // Continue. + dummyStatement(&str, &ref); + } + void testQString() { testQString1(); testQString2(); testQString3(); + testQStringRef(); testQStringQuotes(); } @@ -3823,6 +3861,24 @@ namespace text { } // namespace text +namespace qprocess { + + void testQProcess() + { + return; + const int N = 14; + QProcess proc[N]; + for (int i = 0; i != N; ++i) { + proc[i].start("sleep 10"); + proc[i].waitForStarted(); + } + BREAK_HERE; + dummyStatement(&proc); + } + +} // namespace qprocess + + namespace qthread { class Thread : public QThread @@ -4191,11 +4247,13 @@ namespace qvector { { // This tests the display of a big vector. QVector<int> vec(10000); + for (int i = 0; i != vec.size(); ++i) + vec[i] = i * i; BREAK_HERE; // Expand vec. // Check vec <10000 items> QVector<int>. // Check vec.0 0 int. - // Check vec.1999 0 int. + // Check vec.1999 3996001 int. // Continue. // step over @@ -4486,6 +4544,31 @@ namespace namespc { } // namespace namespc +namespace gccextensions { + + void testGccExtensions() + { +#ifdef __GNUC__ + char v[8] = { 1, 2 }; + char w __attribute__ ((vector_size (8))) = { 1, 2 }; + int y[2] = { 1, 2 }; + int z __attribute__ ((vector_size (8))) = { 1, 2 }; + BREAK_HERE; + // Expand v. + // Check v.0 1 char. + // Check v.1 2 char. + // Check w.0 1 char. + // Check w.1 2 char. + // Check y.0 1 int. + // Check y.1 2 int. + // Check z.0 1 int. + // Check z.1 2 int. + // Continue. + dummyStatement(&v, &w, &y, &z); +#endif + } + +} // namespace gccextension class Z : public QObject { @@ -4519,6 +4602,32 @@ namespace basic { // This tests display of basic types. + void testInt() + { + quint64 u64 = ULLONG_MAX; + qint64 s64 = LLONG_MAX; + quint32 u32 = ULONG_MAX; + qint32 s32 = LONG_MAX; + quint64 u64s = 0; + qint64 s64s = LLONG_MIN; + quint32 u32s = 0; + qint32 s32s = LONG_MIN; + + BREAK_HERE; + // Check u64 18446744073709551615 quint64. + // Check s64 9223372036854775807 qint64. + // Check u32 4294967295 quint32. + // Check s32 2147483647 qint32. + // Check u64s 0 quint64. + // Check s64s -9223372036854775808 qint64. + // Check u32s 0 quint32. + // Check s32s -2147483648 qint32. + // Continue. + + dummyStatement(&u64, &s64, &u32, &s32, &u64s, &s64s, &u32s, &s32s); + } + + void testArray1() { double d[3][3]; @@ -5248,11 +5357,47 @@ namespace basic { dummyStatement(&i, &b, &s); } + #ifdef Q_COMPILER_RVALUE_REFS + struct X { X() : a(2), b(3) {} int a, b; }; + + X testRValueReferenceHelper1() + { + return X(); + } + + X testRValueReferenceHelper2(X &&x) + { + return x; + } + + void testRValueReference() + { + X &&x1 = testRValueReferenceHelper1(); + X &&x2 = testRValueReferenceHelper2(std::move(x1)); + X &&x3 = testRValueReferenceHelper2(testRValueReferenceHelper1()); + + X y1 = testRValueReferenceHelper1(); + X y2 = testRValueReferenceHelper2(std::move(y1)); + X y3 = testRValueReferenceHelper2(testRValueReferenceHelper1()); + + BREAK_HERE; + // Continue. + dummyStatement(&x1, &x2, &x3, &y1, &y2, &y3); + } + + #else + + void testRValueReference() {} + + #endif + void testBasic() { + testInt(); testReference1(); testReference2(); testReference3("hello"); + testRValueReference(); testDynamicReference(); testReturn(); testArray1(); @@ -5567,15 +5712,15 @@ namespace boost { using namespace posix_time; time_duration d1(1, 0, 0); BREAK_HERE; - // Check d1 01:00:00 boost::posix_time::time_duration. + // Check d1 01:00:00 boost::posix_time::time_duration. // Continue. time_duration d2(0, 1, 0); BREAK_HERE; - // Check d2 00:01:00 boost::posix_time::time_duration. + // Check d2 00:01:00 boost::posix_time::time_duration. // Continue. time_duration d3(0, 0, 1); BREAK_HERE; - // Check d3 00:00:01 boost::posix_time::time_duration. + // Check d3 00:00:01 boost::posix_time::time_duration. // Continue. dummyStatement(&d1, &d2, &d3); } @@ -5605,15 +5750,15 @@ namespace boost { using namespace posix_time; ptime p1(date(2002, 1, 10), time_duration(1, 0, 0)); BREAK_HERE; - // Check p1 Thu Jan 10 01:00:00 2002 boost::posix_time::ptime. + // Check p1 Thu Jan 10 01:00:00 2002 boost::posix_time::ptime. // Continue. ptime p2(date(2002, 1, 10), time_duration(0, 0, 0)); BREAK_HERE; - // Check p2 Thu Jan 10 00:00:00 2002 boost::posix_time::ptime. + // Check p2 Thu Jan 10 00:00:00 2002 boost::posix_time::ptime. // Continue. ptime p3(date(1970, 1, 1), time_duration(0, 0, 0)); BREAK_HERE; - // Check p3 Thu Jan 1 00:00:00 1970 boost::posix_time::ptime. + // Check p3 Thu Jan 1 00:00:00 1970 boost::posix_time::ptime. // Continue. dummyStatement(&p1, &p2, &p3); } @@ -5832,14 +5977,14 @@ namespace bug3611 { byte f = '2'; int *x = (int*)&f; BREAK_HERE; - // Check f 50 bug3611::byte. + // Check f 50 '2' bug3611::byte. // Continue. // Step. f += 1; f += 1; f += 1; BREAK_HERE; - // Check f 53 bug3611::byte. + // Check f 53 '5' bug3611::byte. // Continue. dummyStatement(&f, &x); } @@ -6566,6 +6711,7 @@ int main(int argc, char *argv[]) // Check for normal dumpers. basic::testBasic(); + gccextensions::testGccExtensions(); qhostaddress::testQHostAddress(); varargs::testVaList(); @@ -6620,6 +6766,7 @@ int main(int argc, char *argv[]) qstringlist::testQStringList(); qstring::testQString(); qthread::testQThread(); + qprocess::testQProcess(); qurl::testQUrl(); qvariant::testQVariant(); qvector::testQVector(); diff --git a/tests/manual/debugger/simple/simple_test_app.pro b/tests/manual/debugger/simple/simple_test_app.pro index e7f85a4589..12a6cc4ec7 100644 --- a/tests/manual/debugger/simple/simple_test_app.pro +++ b/tests/manual/debugger/simple/simple_test_app.pro @@ -12,6 +12,9 @@ QT += xml contains(QT_CONFIG, webkit) { QT += webkit + greaterThan(QT_MAJOR_VERSION, 4) { + QT += webkitwidgets + } } greaterThan(QT_MAJOR_VERSION, 4) { @@ -34,6 +37,11 @@ maemo5 { INSTALLS += target } +#*g++* { +# DEFINES += USE_CXX11 +# QMAKE_CXXFLAGS += -std=c++0x +#} + exists($$QMAKE_INCDIR_QT/QtCore/private/qobject_p.h):DEFINES += USE_PRIVATE exists(/usr/include/boost/optional.hpp): DEFINES += USE_BOOST exists(/usr/include/eigen2/Eigen/Core): DEFINES += USE_EIGEN diff --git a/tests/manual/preprocessor/main.cpp b/tests/manual/preprocessor/main.cpp index c44e7c45eb..6bbbc9a6eb 100644 --- a/tests/manual/preprocessor/main.cpp +++ b/tests/manual/preprocessor/main.cpp @@ -97,14 +97,16 @@ public: #endif } - virtual void passedMacroDefinitionCheck(unsigned, const Macro &) + virtual void passedMacroDefinitionCheck(unsigned, unsigned, const Macro &) { } virtual void failedMacroDefinitionCheck(unsigned, const ByteArrayRef &) { } - virtual void startExpandingMacro(unsigned, const Macro &, - const ByteArrayRef &, + virtual void notifyMacroReference(unsigned, unsigned, const Macro &) + { } + + virtual void startExpandingMacro(unsigned, unsigned, const Macro &, const QVector<MacroArgumentReference> &) { } @@ -116,6 +118,9 @@ public: virtual void stopSkippingBlocks(unsigned) { } + + virtual void sourceNeeded(unsigned, QString &, IncludeType) + { } }; int make_depend(QCoreApplication *app); diff --git a/tests/manual/preprocessor/preprocessor.pro b/tests/manual/preprocessor/preprocessor.pro index 99d588dea4..9cb836d598 100644 --- a/tests/manual/preprocessor/preprocessor.pro +++ b/tests/manual/preprocessor/preprocessor.pro @@ -2,8 +2,10 @@ QT = core macx:CONFIG -= app_bundle TARGET = pp -include(../../../qtcreator.pri) +include(../../auto/qttest.pri) + include($$IDE_SOURCE_TREE/src/libs/cplusplus/cplusplus.pri) +include($$IDE_SOURCE_TREE/src/libs/languageutils/languageutils.pri) include($$IDE_SOURCE_TREE/src/libs/utils/utils.pri) include($$IDE_SOURCE_TREE/src/libs/3rdparty/botan/botan.pri) diff --git a/tests/manual/proparser/main.cpp b/tests/manual/proparser/main.cpp index 95c7f5585d..36ee676106 100644 --- a/tests/manual/proparser/main.cpp +++ b/tests/manual/proparser/main.cpp @@ -46,8 +46,10 @@ static void print(const QString &fileName, int lineNo, int type, const QString & { QString pfx = ((type & QMakeHandler::CategoryMask) == QMakeHandler::WarningMessage) ? QString::fromLatin1("WARNING: ") : QString(); - if (lineNo) + if (lineNo > 0) qWarning("%s%s:%d: %s", qPrintable(pfx), qPrintable(fileName), lineNo, qPrintable(msg)); + else if (lineNo) + qWarning("%s%s: %s", qPrintable(pfx), qPrintable(fileName), qPrintable(msg)); else qWarning("%s%s", qPrintable(pfx), qPrintable(msg)); } @@ -67,7 +69,7 @@ public: static EvalHandler evalHandler; static int evaluate(const QString &fileName, const QString &in_pwd, const QString &out_pwd, - bool cumulative, QMakeGlobals *option, QMakeParser *parser, int level) + bool cumulative, ProFileGlobals *option, QMakeParser *parser, int level) { static QSet<QString> visited; if (visited.contains(fileName)) @@ -140,30 +142,59 @@ int main(int argc, char **argv) { QCoreApplication app(argc, argv); - QStringList args = app.arguments(); - args.removeFirst(); - int level = -1; // verbose - if (args.count() && args.first() == QLatin1String("-v")) - level = 0, args.removeFirst(); - if (args.count() < 2) - qFatal("need at least two arguments: [-v] <cumulative?> <filenme> [<out_pwd> [<qmake options>]]"); - - QMakeGlobals option; + ProFileGlobals option; QString qmake = QString::fromLocal8Bit(qgetenv("TESTREADER_QMAKE")); if (qmake.isEmpty()) qmake = QLibraryInfo::location(QLibraryInfo::BinariesPath) + QLatin1String("/qmake"); option.qmake_abslocation = QDir::cleanPath(qmake); option.initProperties(); - if (args.count() >= 4) - option.setCommandLineArguments(args.mid(3)); - QMakeParser parser(0, &evalHandler); - bool cumulative = args[0] == QLatin1String("true"); - QFileInfo infi(args[1]); - QString file = infi.absoluteFilePath(); - QString in_pwd = infi.absolutePath(); - QString out_pwd = (args.count() > 2) ? QFileInfo(args[2]).absoluteFilePath() : in_pwd; + QStringList args = app.arguments(); + args.removeFirst(); + int level = -1; // verbose + bool cumulative = false; + QString file; + QString in_pwd; + QString out_pwd; + QMakeCmdLineParserState state(QDir::currentPath()); + for (int pos = 0; ; ) { + QMakeGlobals::ArgumentReturn cmdRet = option.addCommandLineArguments(state, args, &pos); + if (cmdRet == QMakeGlobals::ArgumentsOk) + break; + if (cmdRet == QMakeGlobals::ArgumentMalformed) { + qCritical("argument %s needs a parameter", qPrintable(args.at(pos - 1))); + return 3; + } + Q_ASSERT(cmdRet == QMakeGlobals::ArgumentUnknown); + QString arg = args.at(pos++); + if (arg == QLatin1String("-v")) { + level = 0; + } else if (arg == QLatin1String("-d")) { + option.debugLevel++; + } else if (arg == QLatin1String("-c")) { + cumulative = true; + } else if (arg.startsWith(QLatin1Char('-'))) { + qCritical("unrecognized option %s", qPrintable(arg)); + return 3; + } else if (file.isEmpty()) { + QFileInfo infi(arg); + file = QDir::cleanPath(infi.absoluteFilePath()); + in_pwd = QDir::cleanPath(infi.absolutePath()); + } else if (out_pwd.isEmpty()) { + out_pwd = QDir::cleanPath(QFileInfo(arg).absoluteFilePath()); + } else { + qCritical("excess argument '%s'", qPrintable(arg)); + return 3; + } + } + if (file.isEmpty()) { + qCritical("usage: testreader [-v] [-d [-d]] [-c] <filenme> [<out_pwd>] [<variable assignments>]"); + return 3; + } + if (out_pwd.isEmpty()) + out_pwd = in_pwd; option.setDirectories(in_pwd, out_pwd); + QMakeParser parser(0, &evalHandler); return evaluate(file, in_pwd, out_pwd, cumulative, &option, &parser, level); } diff --git a/tests/manual/qml/testfiles/subcomponent.qml b/tests/manual/qml/testfiles/subcomponent.qml index 3b2d27d274..89a9d77512 100644 --- a/tests/manual/qml/testfiles/subcomponent.qml +++ b/tests/manual/qml/testfiles/subcomponent.qml @@ -30,8 +30,8 @@ import Qt 4.7 Rectangle { - x: 640 - y: 480 + width: 640 + height: 480 Component { id: redSquare Rectangle { diff --git a/tests/manual/qml/testfiles_quick2/components/MyButton.qml b/tests/manual/qml/testfiles_quick2/components/MyButton.qml new file mode 100644 index 0000000000..0aa1b1b09e --- /dev/null +++ b/tests/manual/qml/testfiles_quick2/components/MyButton.qml @@ -0,0 +1,36 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + width: 64 + height: 48 + color: "Red" +} diff --git a/tests/manual/qml/testfiles_quick2/empty.qml b/tests/manual/qml/testfiles_quick2/empty.qml new file mode 100644 index 0000000000..35e165eb5d --- /dev/null +++ b/tests/manual/qml/testfiles_quick2/empty.qml @@ -0,0 +1,35 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + width: 640 + height: 480 +} diff --git a/tests/auto/icheckbuild/tst_icheckbuild.cpp b/tests/manual/qml/testfiles_quick2/flipable.qml index c3140dfc79..e841a33736 100644 --- a/tests/auto/icheckbuild/tst_icheckbuild.cpp +++ b/tests/manual/qml/testfiles_quick2/flipable.qml @@ -27,23 +27,16 @@ ** ****************************************************************************/ -#include <QtTest> -#include "ichecklib.h" -#include <QDebug> +import QtQuick 2.0 -class tst_icheckbuild : public QObject -{ - Q_OBJECT +Flipable { + width: 640 + height: 480 + front: Text { + text: "front" + } + back: Text { + text: "back" + } -private slots: - void doTests(); -}; - -void tst_icheckbuild::doTests() -{ - qDebug() << "icheck build was successful"; } - -QTEST_MAIN(tst_icheckbuild) - -#include "tst_icheckbuild.moc" diff --git a/tests/manual/appwizards/qmlimportscenario_02/subfolder1/myqmlapp.qml b/tests/manual/qml/testfiles_quick2/helloworld.qml index f454b2a6df..c1ab8bb3b1 100644 --- a/tests/manual/appwizards/qmlimportscenario_02/subfolder1/myqmlapp.qml +++ b/tests/manual/qml/testfiles_quick2/helloworld.qml @@ -27,19 +27,14 @@ ** ****************************************************************************/ -import QtQuick 1.0 +import QtQuick 2.0 Rectangle { - width: 360 - height: 360 + width: 200 + height: 200 Text { + x: 66 + y: 93 text: "Hello World" - anchors.centerIn: parent - } - MouseArea { - anchors.fill: parent - onClicked: { - Qt.quit(); - } } } diff --git a/tests/manual/appwizards/qmlimportscenario_02/subfolder2/no/trolltech/QmlModule01/QmlComponent01.qml b/tests/manual/qml/testfiles_quick2/helloworld_inverted.qml index 863420f147..90c741da41 100644 --- a/tests/manual/appwizards/qmlimportscenario_02/subfolder2/no/trolltech/QmlModule01/QmlComponent01.qml +++ b/tests/manual/qml/testfiles_quick2/helloworld_inverted.qml @@ -27,19 +27,16 @@ ** ****************************************************************************/ -import Qt 4.7 +import QtQuick 2.0 Rectangle { - color: "#ddffdd" - - Image { - source: "apple.svg" - anchors.right: parent.right - anchors.bottom: parent.bottom - } - + width: 200 + height: 200 + color: "black" Text { - text: "QmlComponent01" - font.pointSize: 14 + x: 66 + y: 93 + text: "Hello World" + color: "white" } } diff --git a/tests/manual/qml/testfiles_quick2/images.qml b/tests/manual/qml/testfiles_quick2/images.qml new file mode 100644 index 0000000000..8a45b2b173 --- /dev/null +++ b/tests/manual/qml/testfiles_quick2/images.qml @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + width: 640 + height: 480 + + Image { + id: image1 + x: 20 + y: 18 + source: "images/qtcreator.png" + } + + Image { + id: image2 + x: 327 + y: 18 + source: "images/qtcreator.jpg" + } + + Image { + id: image3 + x: 20 + y: 288 + source: "images/qtcreator.ico" + } +} diff --git a/tests/manual/qml/testfiles_quick2/images/qtcreator.ico b/tests/manual/qml/testfiles_quick2/images/qtcreator.ico Binary files differnew file mode 100644 index 0000000000..6bca2585a6 --- /dev/null +++ b/tests/manual/qml/testfiles_quick2/images/qtcreator.ico diff --git a/tests/manual/qml/testfiles_quick2/images/qtcreator.jpg b/tests/manual/qml/testfiles_quick2/images/qtcreator.jpg Binary files differnew file mode 100644 index 0000000000..d856c51b43 --- /dev/null +++ b/tests/manual/qml/testfiles_quick2/images/qtcreator.jpg diff --git a/tests/manual/qml/testfiles_quick2/images/qtcreator.png b/tests/manual/qml/testfiles_quick2/images/qtcreator.png Binary files differnew file mode 100644 index 0000000000..1cf9f91170 --- /dev/null +++ b/tests/manual/qml/testfiles_quick2/images/qtcreator.png diff --git a/tests/manual/qml/testfiles_quick2/listmodel.qml b/tests/manual/qml/testfiles_quick2/listmodel.qml new file mode 100644 index 0000000000..667b671dd5 --- /dev/null +++ b/tests/manual/qml/testfiles_quick2/listmodel.qml @@ -0,0 +1,39 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +import QtQuick 2.0 + +ListModel { + id: myModel + ListElement { + content: "foo" + text: "bar" + } + +} diff --git a/tests/manual/qml/testfiles_quick2/listview.qml b/tests/manual/qml/testfiles_quick2/listview.qml new file mode 100644 index 0000000000..f3cbeb2a84 --- /dev/null +++ b/tests/manual/qml/testfiles_quick2/listview.qml @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +import QtQuick 2.0 + +Item { + width: 200 + height: 100 + + ListView { + anchors.fill: parent; + model: ListModel { + ListElement { + name: "BMW" + speed: 200 + } + ListElement { + name: "Mercedes" + speed: 180 + } + ListElement { + name: "Audi" + speed: 190 + } + ListElement { + name: "VW" + speed: 180 + } + } + + + delegate: Item { + height: 40 + Row { + spacing: 10 + Text { + text: name; + font.bold: true + } + + Text { text: "speed: " + speed } + } + + + } + } +} diff --git a/tests/manual/qml/testfiles_quick2/positioners.qml b/tests/manual/qml/testfiles_quick2/positioners.qml new file mode 100644 index 0000000000..c7abfd4ac8 --- /dev/null +++ b/tests/manual/qml/testfiles_quick2/positioners.qml @@ -0,0 +1,209 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + width: 232 + height: 232 + + Column { + id: column + x: 39 + y: 20 + spacing: 2 + + Rectangle { + width: 20 + height: 20 + color: "#c2d11b" + } + + Rectangle { + width: 20 + height: 20 + color: "#d11b1b" + } + + Rectangle { + width: 20 + height: 20 + color: "#1e3fd3" + } + + Rectangle { + width: 20 + height: 20 + color: "#3bd527" + } + + Rectangle { + width: 20 + height: 20 + color: "#8726b7" + } + + Rectangle { + width: 20 + height: 20 + color: "#8b8b8b" + } + } + + Row { + id: row + x: 78 + y: 20 + Rectangle { + width: 20 + height: 20 + color: "#c2d11b" + } + + Rectangle { + width: 20 + height: 20 + color: "#d11b1b" + } + + Rectangle { + width: 20 + height: 20 + color: "#1e3fd3" + } + + Rectangle { + width: 20 + height: 20 + color: "#3bd527" + } + + Rectangle { + width: 20 + height: 20 + color: "#8726b7" + } + + Rectangle { + width: 20 + height: 20 + color: "#8b8b8b" + } + spacing: 2 + } + + Flow { + id: flow + x: 78 + y: 53 + width: 84 + height: 31 + + Rectangle { + width: 20 + height: 20 + color: "#c2d11b" + } + + Rectangle { + width: 20 + height: 20 + color: "#d11b1b" + } + + Rectangle { + width: 20 + height: 20 + color: "#1e3fd3" + } + + Rectangle { + width: 20 + height: 20 + color: "#3bd527" + } + + Rectangle { + width: 20 + height: 20 + color: "#8726b7" + } + + Rectangle { + width: 20 + height: 20 + color: "#8b8b8b" + } + spacing: 2 + } + + Grid { + id: grid + x: 78 + y: 108 + columns: 3 + Rectangle { + width: 20 + height: 20 + color: "#c2d11b" + } + + Rectangle { + width: 20 + height: 20 + color: "#d11b1b" + } + + Rectangle { + width: 20 + height: 20 + color: "#1e3fd3" + } + + Rectangle { + width: 20 + height: 20 + color: "#3bd527" + } + + Rectangle { + width: 20 + height: 20 + color: "#8726b7" + } + + spacing: 2 + Rectangle { + width: 20 + height: 20 + color: "#8b8b8b" + } + } + +} diff --git a/tests/manual/qml/testfiles_quick2/states.qml b/tests/manual/qml/testfiles_quick2/states.qml new file mode 100644 index 0000000000..3b39eedb5a --- /dev/null +++ b/tests/manual/qml/testfiles_quick2/states.qml @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + id: rect + width: 200 + height: 200 + Text { + id: text + x: 66 + y: 93 + text: "Base State" + } + states: [ + State { + name: "State1" + PropertyChanges { + target: rect + color: "blue" + } + PropertyChanges { + target: text + text: "State1" + } + }, + State { + name: "State2" + PropertyChanges { + target: rect + color: "gray" + } + PropertyChanges { + target: text + text: "State2" + } + } + ] + + Image { + id: image1 + x: 41 + y: 46 + source: "images/qtcreator.png" + } +} diff --git a/tests/manual/qml/testfiles_quick2/subcomponent.qml b/tests/manual/qml/testfiles_quick2/subcomponent.qml new file mode 100644 index 0000000000..5586feb44a --- /dev/null +++ b/tests/manual/qml/testfiles_quick2/subcomponent.qml @@ -0,0 +1,46 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + width: 640 + height: 480 + Component { + id: redSquare + Rectangle { + color: "red" + width: 100 + height: 100 + } + } + + Loader { sourceComponent: redSquare;} + Loader { sourceComponent: redSquare; x: 20 } +} diff --git a/tests/manual/appwizards/qmlimportscenario_02/myqmlapp.qmlproject b/tests/manual/qml/testfiles_quick2/testfiles_quick2.qmlproject index 1040b01e31..337caca3fe 100644 --- a/tests/manual/appwizards/qmlimportscenario_02/myqmlapp.qmlproject +++ b/tests/manual/qml/testfiles_quick2/testfiles_quick2.qmlproject @@ -1,8 +1,9 @@ -import QmlProject 1.0 +import QmlProject 1.1 Project { + // Scan current directory for .qml, .js, and image files QmlFiles { - directory: "subfolder1" + directory: "." } JavaScriptFiles { directory: "." @@ -10,8 +11,4 @@ Project { ImageFiles { directory: "." } - importPaths: [ - "subfolder2", - "subfolder3" - ] } diff --git a/tests/manual/appwizards/qmlimportscenario_02/subfolder3/com/nokia/QmlModule02/QmlComponent02.qml b/tests/manual/qml/testfiles_quick2/usingbutton.qml index 841ca4e869..76dfbe7f5b 100644 --- a/tests/manual/appwizards/qmlimportscenario_02/subfolder3/com/nokia/QmlModule02/QmlComponent02.qml +++ b/tests/manual/qml/testfiles_quick2/usingbutton.qml @@ -27,19 +27,14 @@ ** ****************************************************************************/ -import Qt 4.7 +import QtQuick 2.0 +import "components" as X Rectangle { - color: "#ffdddd" + width: 640 + height: 480 - Image { - source: "tomato.svg" - anchors.right: parent.right - anchors.bottom: parent.bottom + X.MyButton { } - Text { - text: "QmlComponent02" - font.pointSize: 14 - } } diff --git a/tests/manual/qml/testfiles_quick2/views.qml b/tests/manual/qml/testfiles_quick2/views.qml new file mode 100644 index 0000000000..164b86e75a --- /dev/null +++ b/tests/manual/qml/testfiles_quick2/views.qml @@ -0,0 +1,198 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + width: 640 + height: 480 + + GridView { + id: grid_view1 + x: 35 + y: 28 + width: 140 + height: 140 + cellHeight: 70 + delegate: Item { + x: 5 + height: 50 + Column { + Rectangle { + width: 40 + height: 40 + color: colorCode + anchors.horizontalCenter: parent.horizontalCenter + } + + Text { + x: 5 + text: name + anchors.horizontalCenter: parent.horizontalCenter + font.bold: true + } + spacing: 5 + } + } + model: ListModel { + ListElement { + name: "Grey" + colorCode: "grey" + } + + ListElement { + name: "Red" + colorCode: "red" + } + + ListElement { + name: "Blue" + colorCode: "blue" + } + + ListElement { + name: "Green" + colorCode: "green" + } + } + cellWidth: 70 + } + + ListView { + id: list_view1 + x: 248 + y: 28 + width: 110 + height: 160 + delegate: Item { + x: 5 + height: 40 + Row { + id: row1 + Rectangle { + width: 40 + height: 40 + color: colorCode + } + + Text { + text: name + anchors.verticalCenter: parent.verticalCenter + font.bold: true + } + spacing: 10 + } + } + model: ListModel { + ListElement { + name: "Grey" + colorCode: "grey" + } + + ListElement { + name: "Red" + colorCode: "red" + } + + ListElement { + name: "Blue" + colorCode: "blue" + } + + ListElement { + name: "Green" + colorCode: "green" + } + } + } + + PathView { + id: path_view1 + x: 35 + y: 239 + width: 250 + height: 130 + delegate: Component { + Column { + Rectangle { + width: 40 + height: 40 + color: colorCode + anchors.horizontalCenter: parent.horizontalCenter + } + + Text { + x: 5 + text: name + anchors.horizontalCenter: parent.horizontalCenter + font.bold: true + } + spacing: 5 + } + } + model: ListModel { + ListElement { + name: "Grey" + colorCode: "grey" + } + + ListElement { + name: "Red" + colorCode: "red" + } + + ListElement { + name: "Blue" + colorCode: "blue" + } + + ListElement { + name: "Green" + colorCode: "green" + } + } + path: Path { + PathQuad { + x: 120 + y: 25 + controlY: 75 + controlX: 260 + } + + PathQuad { + x: 120 + y: 100 + controlY: 75 + controlX: -20 + } + startY: 100 + startX: 120 + } + } +} diff --git a/tests/manual/ssh/remoteprocess/argumentscollector.cpp b/tests/manual/ssh/remoteprocess/argumentscollector.cpp index a12fb4c872..3830243535 100644 --- a/tests/manual/ssh/remoteprocess/argumentscollector.cpp +++ b/tests/manual/ssh/remoteprocess/argumentscollector.cpp @@ -45,6 +45,7 @@ ArgumentsCollector::ArgumentsCollector(const QStringList &args) QSsh::SshConnectionParameters ArgumentsCollector::collect(bool &success) const { SshConnectionParameters parameters; + parameters.options &= ~SshIgnoreDefaultProxy; try { bool authTypeGiven = false; bool portGiven = false; @@ -76,13 +77,13 @@ QSsh::SshConnectionParameters ArgumentsCollector::collect(bool &success) const authTypeGiven = true; continue; } - if (!checkForNoProxy(pos, parameters.proxyType, proxySettingGiven)) + if (!checkForNoProxy(pos, parameters.options, proxySettingGiven)) throw ArgumentErrorException(QLatin1String("unknown option ") + m_arguments.at(pos)); } Q_ASSERT(pos <= m_arguments.count()); if (pos == m_arguments.count() - 1) { - if (!checkForNoProxy(pos, parameters.proxyType, proxySettingGiven)) + if (!checkForNoProxy(pos, parameters.options, proxySettingGiven)) throw ArgumentErrorException(QLatin1String("unknown option ") + m_arguments.at(pos)); } @@ -156,13 +157,13 @@ bool ArgumentsCollector::checkAndSetIntArg(int &pos, int &val, return false; } -bool ArgumentsCollector::checkForNoProxy(int &pos, - SshConnectionParameters::ProxyType &type, bool &alreadyGiven) const +bool ArgumentsCollector::checkForNoProxy(int &pos, SshConnectionOptions &options, + bool &alreadyGiven) const { if (m_arguments.at(pos) == QLatin1String("-no-proxy")) { if (alreadyGiven) throw ArgumentErrorException(QLatin1String("proxy setting given twice.")); - type = SshConnectionParameters::NoProxy; + options |= SshIgnoreDefaultProxy; alreadyGiven = true; return true; } diff --git a/tests/manual/ssh/remoteprocess/argumentscollector.h b/tests/manual/ssh/remoteprocess/argumentscollector.h index 9e6573f79c..6f3963061c 100644 --- a/tests/manual/ssh/remoteprocess/argumentscollector.h +++ b/tests/manual/ssh/remoteprocess/argumentscollector.h @@ -50,9 +50,7 @@ private: bool checkAndSetStringArg(int &pos, QString &arg, const char *opt) const; bool checkAndSetIntArg(int &pos, int &val, bool &alreadyGiven, const char *opt) const; - bool checkForNoProxy(int &pos, - QSsh::SshConnectionParameters::ProxyType &type, - bool &alreadyGiven) const; + bool checkForNoProxy(int &pos, QSsh::SshConnectionOptions &options, bool &alreadyGiven) const; const QStringList m_arguments; }; diff --git a/tests/manual/ssh/remoteprocess/remoteprocesstest.h b/tests/manual/ssh/remoteprocess/remoteprocesstest.h index 2b8122f7e1..70b7be2bf7 100644 --- a/tests/manual/ssh/remoteprocess/remoteprocesstest.h +++ b/tests/manual/ssh/remoteprocess/remoteprocesstest.h @@ -70,10 +70,10 @@ private: const QSsh::SshConnectionParameters m_sshParams; QTimer * const m_timeoutTimer; QTextStream *m_textStream; - QSsh::SshConnection *m_sshConnection; - QSsh::SshRemoteProcessRunner * const m_remoteRunner; QSsh::SshRemoteProcess::Ptr m_catProcess; QSsh::SshRemoteProcess::Ptr m_echoProcess; + QSsh::SshConnection *m_sshConnection; + QSsh::SshRemoteProcessRunner * const m_remoteRunner; QByteArray m_remoteStdout; QByteArray m_remoteStderr; QByteArray m_remoteData; diff --git a/tests/manual/ssh/sftp/argumentscollector.cpp b/tests/manual/ssh/sftp/argumentscollector.cpp index 95c8960a02..5869e3a862 100644 --- a/tests/manual/ssh/sftp/argumentscollector.cpp +++ b/tests/manual/ssh/sftp/argumentscollector.cpp @@ -43,6 +43,7 @@ ArgumentsCollector::ArgumentsCollector(const QStringList &args) Parameters ArgumentsCollector::collect(bool &success) const { Parameters parameters; + parameters.sshParams.options &= ~SshIgnoreDefaultProxy; try { bool authTypeGiven = false; bool portGiven = false; @@ -77,13 +78,13 @@ Parameters ArgumentsCollector::collect(bool &success) const authTypeGiven = true; continue; } - if (!checkForNoProxy(pos, parameters.sshParams.proxyType, proxySettingGiven)) + if (!checkForNoProxy(pos, parameters.sshParams.options, proxySettingGiven)) throw ArgumentErrorException(QLatin1String("unknown option ") + m_arguments.at(pos)); } Q_ASSERT(pos <= m_arguments.count()); if (pos == m_arguments.count() - 1) { - if (!checkForNoProxy(pos, parameters.sshParams.proxyType, proxySettingGiven)) + if (!checkForNoProxy(pos, parameters.sshParams.options, proxySettingGiven)) throw ArgumentErrorException(QLatin1String("unknown option ") + m_arguments.at(pos)); } @@ -154,13 +155,13 @@ bool ArgumentsCollector::checkAndSetIntArg(int &pos, int &val, return false; } -bool ArgumentsCollector::checkForNoProxy(int &pos, - SshConnectionParameters::ProxyType &type, bool &alreadyGiven) const +bool ArgumentsCollector::checkForNoProxy(int &pos, SshConnectionOptions &options, + bool &alreadyGiven) const { if (m_arguments.at(pos) == QLatin1String("-no-proxy")) { if (alreadyGiven) throw ArgumentErrorException(QLatin1String("proxy setting given twice.")); - type = SshConnectionParameters::NoProxy; + options |= SshIgnoreDefaultProxy; alreadyGiven = true; return true; } diff --git a/tests/manual/ssh/sftp/argumentscollector.h b/tests/manual/ssh/sftp/argumentscollector.h index 4f10a9a85c..b82e7266fe 100644 --- a/tests/manual/ssh/sftp/argumentscollector.h +++ b/tests/manual/ssh/sftp/argumentscollector.h @@ -50,7 +50,7 @@ private: bool checkAndSetStringArg(int &pos, QString &arg, const char *opt) const; bool checkAndSetIntArg(int &pos, int &val, bool &alreadyGiven, const char *opt) const; - bool checkForNoProxy(int &pos, QSsh::SshConnectionParameters::ProxyType &type, + bool checkForNoProxy(int &pos, QSsh::SshConnectionOptions &options, bool &alreadyGiven) const; const QStringList m_arguments; diff --git a/tests/manual/ssh/ssh.pro b/tests/manual/ssh/ssh.pro index 6284229802..fdfd768132 100644 --- a/tests/manual/ssh/ssh.pro +++ b/tests/manual/ssh/ssh.pro @@ -5,4 +5,4 @@ #------------------------------------------------- TEMPLATE = subdirs -SUBDIRS = errorhandling sftp remoteprocess shell sftpfsmodel +SUBDIRS = errorhandling sftp remoteprocess shell sftpfsmodel tunnel diff --git a/tests/manual/ssh/tunnel/argumentscollector.cpp b/tests/manual/ssh/tunnel/argumentscollector.cpp new file mode 100644 index 0000000000..28276dfd6b --- /dev/null +++ b/tests/manual/ssh/tunnel/argumentscollector.cpp @@ -0,0 +1,175 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ +#include "argumentscollector.h" + +#include <QDir> +#include <QProcessEnvironment> + +#include <iostream> + +using namespace QSsh; + +using namespace std; + +ArgumentsCollector::ArgumentsCollector(const QStringList &args) + : m_arguments(args) +{ +} + +QSsh::SshConnectionParameters ArgumentsCollector::collect(bool &success) const +{ + SshConnectionParameters parameters; + parameters.options &= ~SshIgnoreDefaultProxy; + parameters.host = QLatin1String("localhost"); + + try { + bool authTypeGiven = false; + bool portGiven = false; + bool timeoutGiven = false; + bool proxySettingGiven = false; + int pos; + int port; + + for (pos = 1; pos < m_arguments.count() - 1; ++pos) { + if (checkAndSetStringArg(pos, parameters.userName, "-u")) + continue; + if (checkAndSetIntArg(pos, port, portGiven, "-p") + || checkAndSetIntArg(pos, parameters.timeout, timeoutGiven, "-t")) + continue; + if (checkAndSetStringArg(pos, parameters.password, "-pwd")) { + if (!parameters.privateKeyFile.isEmpty()) + throw ArgumentErrorException(QLatin1String("-pwd and -k are mutually exclusive.")); + parameters.authenticationType + = SshConnectionParameters::AuthenticationByPassword; + authTypeGiven = true; + continue; + } + if (checkAndSetStringArg(pos, parameters.privateKeyFile, "-k")) { + if (!parameters.password.isEmpty()) + throw ArgumentErrorException(QLatin1String("-pwd and -k are mutually exclusive.")); + parameters.authenticationType + = SshConnectionParameters::AuthenticationByKey; + authTypeGiven = true; + continue; + } + if (!checkForNoProxy(pos, parameters.options, proxySettingGiven)) + throw ArgumentErrorException(QLatin1String("unknown option ") + m_arguments.at(pos)); + } + + Q_ASSERT(pos <= m_arguments.count()); + if (pos == m_arguments.count() - 1) { + if (!checkForNoProxy(pos, parameters.options, proxySettingGiven)) + throw ArgumentErrorException(QLatin1String("unknown option ") + m_arguments.at(pos)); + } + + if (!authTypeGiven) { + parameters.authenticationType = SshConnectionParameters::AuthenticationByKey; + parameters.privateKeyFile = QDir::homePath() + QLatin1String("/.ssh/id_rsa"); + } + + if (parameters.userName.isEmpty()) { + parameters.userName + = QProcessEnvironment::systemEnvironment().value(QLatin1String("USER")); + } + if (parameters.userName.isEmpty()) + throw ArgumentErrorException(QLatin1String("No user name given.")); + + if (parameters.host.isEmpty()) + throw ArgumentErrorException(QLatin1String("No host given.")); + + parameters.port = portGiven ? port : 22; + if (!timeoutGiven) + parameters.timeout = 30; + success = true; + } catch (ArgumentErrorException &ex) { + cerr << "Error: " << qPrintable(ex.error) << endl; + printUsage(); + success = false; + } + return parameters; +} + +void ArgumentsCollector::printUsage() const +{ + cerr << "Usage: " << qPrintable(m_arguments.first()) + << "[ -u <user> ] " + << "[ -pwd <password> | -k <private key file> ] [ -p <port> ] " + << "[ -t <timeout> ] [ -no-proxy ]" << endl; +} + +bool ArgumentsCollector::checkAndSetStringArg(int &pos, QString &arg, const char *opt) const +{ + if (m_arguments.at(pos) == QLatin1String(opt)) { + if (!arg.isEmpty()) { + throw ArgumentErrorException(QLatin1String("option ") + opt + + QLatin1String(" was given twice.")); + } + arg = m_arguments.at(++pos); + if (arg.isEmpty() && QLatin1String(opt) != QLatin1String("-pwd")) + throw ArgumentErrorException(QLatin1String("empty argument not allowed here.")); + return true; + } + return false; +} + +bool ArgumentsCollector::checkAndSetIntArg(int &pos, int &val, + bool &alreadyGiven, const char *opt) const +{ + if (m_arguments.at(pos) == QLatin1String(opt)) { + if (alreadyGiven) { + throw ArgumentErrorException(QLatin1String("option ") + opt + + QLatin1String(" was given twice.")); + } + bool isNumber; + val = m_arguments.at(++pos).toInt(&isNumber); + if (!isNumber) { + throw ArgumentErrorException(QLatin1String("option ") + opt + + QLatin1String(" needs integer argument")); + } + alreadyGiven = true; + return true; + } + return false; +} + +bool ArgumentsCollector::checkForNoProxy(int &pos, SshConnectionOptions &options, + bool &alreadyGiven) const +{ + if (m_arguments.at(pos) == QLatin1String("-no-proxy")) { + if (alreadyGiven) + throw ArgumentErrorException(QLatin1String("proxy setting given twice.")); + options |= SshIgnoreDefaultProxy; + alreadyGiven = true; + return true; + } + return false; +} diff --git a/tests/manual/ssh/tunnel/argumentscollector.h b/tests/manual/ssh/tunnel/argumentscollector.h new file mode 100644 index 0000000000..25f4d306ef --- /dev/null +++ b/tests/manual/ssh/tunnel/argumentscollector.h @@ -0,0 +1,61 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ + +#ifndef ARGUMENTSCOLLECTOR_H +#define ARGUMENTSCOLLECTOR_H + +#include <ssh/sshconnection.h> + +#include <QStringList> + +class ArgumentsCollector +{ +public: + ArgumentsCollector(const QStringList &args); + QSsh::SshConnectionParameters collect(bool &success) const; +private: + struct ArgumentErrorException + { + ArgumentErrorException(const QString &error) : error(error) {} + const QString error; + }; + + void printUsage() const; + bool checkAndSetStringArg(int &pos, QString &arg, const char *opt) const; + bool checkAndSetIntArg(int &pos, int &val, bool &alreadyGiven, + const char *opt) const; + bool checkForNoProxy(int &pos, QSsh::SshConnectionOptions &options, bool &alreadyGiven) const; + + const QStringList m_arguments; +}; + +#endif // ARGUMENTSCOLLECTOR_H diff --git a/tests/manual/ssh/tunnel/main.cpp b/tests/manual/ssh/tunnel/main.cpp new file mode 100644 index 0000000000..b25beb46ff --- /dev/null +++ b/tests/manual/ssh/tunnel/main.cpp @@ -0,0 +1,55 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ +#include "../remoteprocess/argumentscollector.h" +#include "tunnel.h" + +#include <ssh/sshconnection.h> + +#include <QCoreApplication> +#include <QObject> +#include <QStringList> + +#include <cstdlib> +#include <iostream> + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + bool parseSuccess; + const QSsh::SshConnectionParameters ¶meters + = ArgumentsCollector(app.arguments()).collect(parseSuccess); + if (!parseSuccess) + return EXIT_FAILURE; + Tunnel tunnel(parameters); + tunnel.run(); + return app.exec(); +} diff --git a/tests/manual/ssh/tunnel/tunnel.cpp b/tests/manual/ssh/tunnel/tunnel.cpp new file mode 100644 index 0000000000..342102a881 --- /dev/null +++ b/tests/manual/ssh/tunnel/tunnel.cpp @@ -0,0 +1,165 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** Other Usage +** +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +**************************************************************************/ +#include "tunnel.h" + +#include <ssh/sshconnection.h> +#include <ssh/sshdirecttcpiptunnel.h> + +#include <QCoreApplication> +#include <QTcpServer> +#include <QTcpSocket> +#include <QTimer> + +#include <cstdlib> +#include <iostream> + +const QByteArray ServerDataPrefix("Received the following data: "); +const QByteArray TestData("Urgsblubb?"); + +using namespace QSsh; + +Tunnel::Tunnel(const QSsh::SshConnectionParameters ¶meters, QObject *parent) + : QObject(parent), + m_connection(new SshConnection(parameters, this)), + m_tunnelServer(new QTcpServer(this)), + m_expectingChannelClose(false) +{ + connect(m_connection, SIGNAL(connected()), SLOT(handleConnected())); + connect(m_connection, SIGNAL(error(QSsh::SshError)), SLOT(handleConnectionError())); +} + +Tunnel::~Tunnel() +{ +} + +void Tunnel::run() +{ + std::cout << "Connecting to SSH server..." << std::endl; + m_connection->connectToHost(); +} + +void Tunnel::handleConnectionError() +{ + std::cerr << "SSH connection error: " << qPrintable(m_connection->errorString()) << std::endl; + qApp->exit(EXIT_FAILURE); +} + +void Tunnel::handleConnected() +{ + std::cout << "Opening server side..." << std::endl; + if (!m_tunnelServer->listen(QHostAddress::LocalHost)) { + std::cerr << "Error opening port: " + << m_tunnelServer->errorString().toLocal8Bit().constData() << std::endl; + qApp->exit(EXIT_FAILURE); + return; + } + m_forwardedPort = m_tunnelServer->serverPort(); + connect(m_tunnelServer, SIGNAL(newConnection()), SLOT(handleNewConnection())); + + m_tunnel = m_connection->createTunnel(m_forwardedPort); + connect(m_tunnel.data(), SIGNAL(initialized()), SLOT(handleInitialized())); + connect(m_tunnel.data(), SIGNAL(error(QString)), SLOT(handleTunnelError(QString))); + connect(m_tunnel.data(), SIGNAL(readyRead()), SLOT(handleServerData())); + connect(m_tunnel.data(), SIGNAL(tunnelClosed()), SLOT(handleTunnelClosed())); + + std::cout << "Initializing tunnel..." << std::endl; + m_tunnel->initialize(); +} + +void Tunnel::handleInitialized() +{ + std::cout << "Writing data into the tunnel..." << std::endl; + m_tunnel->write(TestData); + QTimer * const timeoutTimer = new QTimer(this); + connect(timeoutTimer, SIGNAL(timeout()), SLOT(handleTimeout())); + timeoutTimer->start(10000); +} + +void Tunnel::handleServerData() +{ + m_dataReceivedFromServer += m_tunnel->readAll(); + if (m_dataReceivedFromServer == ServerDataPrefix + TestData) { + std::cout << "Data exchange successful. Closing server socket..." << std::endl; + m_expectingChannelClose = true; + m_tunnelSocket->close(); + } +} + +void Tunnel::handleTunnelError(const QString &reason) +{ + std::cerr << "Tunnel error: " << reason.toLocal8Bit().constData() << std::endl; + qApp->exit(EXIT_FAILURE); +} + +void Tunnel::handleTunnelClosed() +{ + if (m_expectingChannelClose) { + std::cout << "Successfully detected channel close." << std::endl; + std::cout << "Test finished successfully." << std::endl; + qApp->quit(); + } else { + std::cerr << "Error: Remote host closed channel." << std::endl; + qApp->exit(EXIT_FAILURE); + } +} + +void Tunnel::handleNewConnection() +{ + m_tunnelSocket = m_tunnelServer->nextPendingConnection(); + m_tunnelServer->close(); + connect(m_tunnelSocket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(handleSocketError())); + connect(m_tunnelSocket, SIGNAL(readyRead()), SLOT(handleClientData())); + handleClientData(); +} + +void Tunnel::handleSocketError() +{ + std::cerr << "Socket error: " << m_tunnelSocket->errorString().toLocal8Bit().constData() + << std::endl; + qApp->exit(EXIT_FAILURE); +} + +void Tunnel::handleClientData() +{ + m_dataReceivedFromClient += m_tunnelSocket->readAll(); + if (m_dataReceivedFromClient == TestData) { + std::cout << "Client data successfully received by server, now sending data to client..." + << std::endl; + m_tunnelSocket->write(ServerDataPrefix + m_dataReceivedFromClient); + } +} + +void Tunnel::handleTimeout() +{ + std::cerr << "Error: Timeout waiting for test completion." << std::endl; + qApp->exit(EXIT_FAILURE); +} diff --git a/tests/manual/ssh/tunnel/tunnel.h b/tests/manual/ssh/tunnel/tunnel.h new file mode 100644 index 0000000000..b53cd7311a --- /dev/null +++ b/tests/manual/ssh/tunnel/tunnel.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ +#ifndef TUNNEL_H +#define TUNNEL_H + +#include <QObject> +#include <QSharedPointer> + +QT_BEGIN_NAMESPACE +class QTcpServer; +class QTcpSocket; +QT_END_NAMESPACE + +namespace QSsh { +class SshConnection; +class SshConnectionParameters; +class SshDirectTcpIpTunnel; +} + +class Tunnel : public QObject +{ + Q_OBJECT +public: + Tunnel(const QSsh::SshConnectionParameters ¶meters, QObject *parent = 0); + ~Tunnel(); + + void run(); + +private slots: + void handleConnected(); + void handleConnectionError(); + void handleServerData(); + void handleInitialized(); + void handleTunnelError(const QString &reason); + void handleTunnelClosed(); + void handleNewConnection(); + void handleSocketError(); + void handleClientData(); + void handleTimeout(); + +private: + QSsh::SshConnection * const m_connection; + QSharedPointer<QSsh::SshDirectTcpIpTunnel> m_tunnel; + QTcpServer * const m_tunnelServer; + QTcpSocket *m_tunnelSocket; + quint16 m_forwardedPort; + QByteArray m_dataReceivedFromServer; + QByteArray m_dataReceivedFromClient; + bool m_expectingChannelClose; +}; + +#endif // TUNNEL_H diff --git a/tests/manual/ssh/tunnel/tunnel.pro b/tests/manual/ssh/tunnel/tunnel.pro new file mode 100644 index 0000000000..f2f960b98a --- /dev/null +++ b/tests/manual/ssh/tunnel/tunnel.pro @@ -0,0 +1,5 @@ +include(../ssh.pri) + +TARGET=tunnel +SOURCES=main.cpp tunnel.cpp argumentscollector.cpp +HEADERS=tunnel.h argumentscollector.h diff --git a/tests/manual/utils/tcpportsgatherer/tcpportsgatherer.pro b/tests/manual/utils/tcpportsgatherer/tcpportsgatherer.pro index 1c0a7f4e6c..0e500831e2 100644 --- a/tests/manual/utils/tcpportsgatherer/tcpportsgatherer.pro +++ b/tests/manual/utils/tcpportsgatherer/tcpportsgatherer.pro @@ -24,5 +24,5 @@ SOURCES += \ $${UTILSDIR}/portlist.cpp \ $${UTILSDIR}/tcpportsgatherer.cpp -win32:LIBS += -liphlpapi -lWs2_32 +win32:LIBS += -liphlpapi -lws2_32 SOURCES += main.cpp diff --git a/tests/manual/utils/tcpportsgatherer/tcpportsgatherer.qbp b/tests/manual/utils/tcpportsgatherer/tcpportsgatherer.qbp index 4a491ff5eb..c84e9fdd3d 100644 --- a/tests/manual/utils/tcpportsgatherer/tcpportsgatherer.qbp +++ b/tests/manual/utils/tcpportsgatherer/tcpportsgatherer.qbp @@ -16,7 +16,7 @@ Application { Properties { condition: qbs.targetOS == "windows" - cpp.dynamicLibraries: [ "iphlpapi.lib", "Ws2_32.lib" ] + cpp.dynamicLibraries: [ "iphlpapi.lib", "ws2_32.lib" ] } Depends { name: "cpp" } diff --git a/tests/system/objects.map b/tests/system/objects.map index 2e50fd33c8..327d4eeff8 100644 --- a/tests/system/objects.map +++ b/tests/system/objects.map @@ -28,6 +28,7 @@ :CMake Wizard.Next_QPushButton {name='__qt__passive_wizardbutton1' text~='(Next.*|Continue)' type='QPushButton' visible='1' window=':CMake Wizard_CMakeProjectManager::Internal::CMakeOpenProjectWizard'} :CMake Wizard.Run CMake_QPushButton {text='Run CMake' type='QPushButton' unnamed='1' visible='1' window=':CMake Wizard_CMakeProjectManager::Internal::CMakeOpenProjectWizard'} :CMake Wizard_CMakeProjectManager::Internal::CMakeOpenProjectWizard {type='CMakeProjectManager::Internal::CMakeOpenProjectWizard' unnamed='1' visible='1' windowTitle='CMake Wizard'} +:CompilerPath.Utils_BaseValidatingLineEdit {container=':qt_tabwidget_stackedwidget_QWidget' name='LineEdit' type='Utils::BaseValidatingLineEdit' visible='1'} :Core__Internal__GeneralSettings.User Interface_QGroupBox {container=':qt_tabwidget_stackedwidget.Core__Internal__GeneralSettings_QWidget' name='interfaceBox' title='User Interface' type='QGroupBox' visible='1'} :CppTools__Internal__CompletionSettingsPage.Behavior_QGroupBox {container=':qt_tabwidget_stackedwidget.CppTools__Internal__CompletionSettingsPage_QWidget' name='groupBox' title='Behavior' type='QGroupBox' visible='1'} :CreateProject_QStyleItem {clip='false' container=':Qt Creator_QDeclarativeView' enabled='true' text='Create Project' type='LinkedText' unnamed='1' visible='true'} @@ -50,7 +51,7 @@ :Generator:_QComboBox {buddy=':CMake Wizard.Generator:_QLabel' type='QComboBox' unnamed='1' visible='1'} :Hits_QCLuceneResultWidget {aboveWidget=':Hits_QLabel' type='QCLuceneResultWidget' unnamed='1' visible='1' window=':Qt Creator_Core::Internal::MainWindow'} :Hits_QLabel {text~='\\\\d+ - \\\\d+ of \\\\d+ Hits' type='QLabel' unnamed='1' visible='1' window=':Qt Creator_Core::Internal::MainWindow'} -:Kits_QTreeView {container=':qt_tabwidget_stackedwidget_QWidget' type='QTreeView' unnamed='1' visible='1'} +:Kits_Or_Compilers_QTreeView {container=':qt_tabwidget_stackedwidget_QWidget' type='QTreeView' unnamed='1' visible='1'} :Kits_QtVersion_QComboBox {container=':qt_tabwidget_stackedwidget_QWidget' occurrence='4' type='QComboBox' unnamed='1' visible='1'} :New.frame_QFrame {name='frame' type='QFrame' visible='1' window=':New_Core::Internal::NewDialog'} :New.templateCategoryView_QTreeView {name='templateCategoryView' type='QTreeView' visible='1' window=':New_Core::Internal::NewDialog'} @@ -113,6 +114,7 @@ :Qt Gui Application.Source file:_QLabel {name='sourceLabel' text='Source file:' type='QLabel' visible='1' window=':Qt Gui Application_Qt4ProjectManager::Internal::GuiAppWizardDialog'} :Qt Gui Application_Qt4ProjectManager::Internal::GuiAppWizardDialog {type='Qt4ProjectManager::Internal::GuiAppWizardDialog' unnamed='1' visible='1' windowTitle='Qt Gui Application'} :QtSupport__Internal__QtVersionManager.QLabel {container=':qt_tabwidget_stackedwidget.QtSupport__Internal__QtVersionManager_QtSupport::Internal::QtOptionsPageWidget' type='QLabel' unnamed='1' visible='1'} +:QtSupport__Internal__QtVersionManager.errorLabel.QLabel {container=':qt_tabwidget_stackedwidget.QtSupport__Internal__QtVersionManager_QtSupport::Internal::QtOptionsPageWidget' name='errorLabel' type='QLabel' visible='1'} :QtSupport__Internal__QtVersionManager.qmake_QLabel {container=':qt_tabwidget_stackedwidget.QtSupport__Internal__QtVersionManager_QtSupport::Internal::QtOptionsPageWidget' name='qmakePath' type='QLabel' visible='1'} :QtSupport__Internal__QtVersionManager.qtdirList_QTreeWidget {container=':qt_tabwidget_stackedwidget.QtSupport__Internal__QtVersionManager_QtSupport::Internal::QtOptionsPageWidget' name='qtdirList' type='QTreeWidget' visible='1'} :Restart required.OK_QPushButton {text='OK' type='QPushButton' unnamed='1' visible='1' window=':Restart required_QMessageBox'} diff --git a/tests/system/shared/debugger.py b/tests/system/shared/debugger.py index 9c5b14bab0..db78d54db7 100644 --- a/tests/system/shared/debugger.py +++ b/tests/system/shared/debugger.py @@ -40,18 +40,6 @@ def takeDebuggerLog(): # on the given file,line pairs inside the given list of dicts # the lines are treated as regular expression def setBreakpointsForCurrentProject(filesAndLines): - # internal helper for setBreakpointsForCurrentProject - # double clicks the treeElement inside the given navTree - # TODO: merge with doubleClickFile() from tst_qml_editor & move to utils(?) - def __doubleClickFile__(navTree, treeElement): - waitForObjectItem(navTree, treeElement) - fileNamePattern = re.compile(".*\.(?P<file>(.*\\\..*)?)$") - fileName = fileNamePattern.search(treeElement).group("file").replace("\\.", ".") - doubleClickItem(navTree, treeElement, 5, 5, 0, Qt.LeftButton) - mainWindow = waitForObject(":Qt Creator_Core::Internal::MainWindow") - waitFor('fileName in str(mainWindow.windowTitle)', 5000) - return fileName - switchViewTo(ViewConstants.DEBUG) removeOldBreakpoints() if not filesAndLines or not isinstance(filesAndLines, (list,tuple)): @@ -61,12 +49,13 @@ def setBreakpointsForCurrentProject(filesAndLines): "window=':Qt Creator_Core::Internal::MainWindow'}") for current in filesAndLines: for curFile,curLine in current.iteritems(): - fName = __doubleClickFile__(navTree, curFile) + if not openDocument(curFile): + return False editor = getEditorForFileSuffix(curFile) if not placeCursorToLine(editor, curLine, True): return False invokeMenuItem("Debug", "Toggle Breakpoint") - test.log('Set breakpoint in %s' % fName, curLine) + test.log('Set breakpoint in %s' % curFile, curLine) try: breakPointTreeView = waitForObject(":Breakpoints_Debugger::Internal::BreakTreeView") waitFor("breakPointTreeView.model().rowCount() == len(filesAndLines)", 2000) diff --git a/tests/system/shared/editor_utils.py b/tests/system/shared/editor_utils.py index c438804429..558eef273d 100644 --- a/tests/system/shared/editor_utils.py +++ b/tests/system/shared/editor_utils.py @@ -287,14 +287,22 @@ def invokeFindUsage(editor, line, typeOperation, n=1): invokeContextMenuItem(editor, "Find Usages") return True +def addBranchWildcardToRoot(rootNode): + pos = rootNode.find(".") + return rootNode[:pos] + " (*)" + rootNode[pos:] + def openDocument(treeElement): try: selectFromCombo(":Qt Creator_Core::Internal::NavComboBox", "Open Documents") navigator = waitForObject(":Qt Creator_Utils::NavigationTreeView") - fileName = waitForObjectItem(navigator, treeElement).text + try: + item = waitForObjectItem(navigator, treeElement, 3000) + except: + treeElement = addBranchWildcardToRoot(treeElement) + item = waitForObjectItem(navigator, treeElement) doubleClickItem(navigator, treeElement, 5, 5, 0, Qt.LeftButton) mainWindow = waitForObject(":Qt Creator_Core::Internal::MainWindow") - waitFor("fileName in str(mainWindow.windowTitle)") + waitFor("item.text in str(mainWindow.windowTitle)") return True except: return False diff --git a/tests/system/shared/project_explorer.py b/tests/system/shared/project_explorer.py index aacc57bbfa..1f2a1470ac 100644 --- a/tests/system/shared/project_explorer.py +++ b/tests/system/shared/project_explorer.py @@ -155,7 +155,7 @@ def getQtInformationForQmlProject(): waitForObjectItem(":Options_QListView", "Build & Run") clickItem(":Options_QListView", "Build & Run", 14, 15, 0, Qt.LeftButton) clickTab(waitForObject(":Options.qt_tabwidget_tabbar_QTabBar"), "Kits") - targetsTreeView = waitForObject(":Kits_QTreeView") + targetsTreeView = waitForObject(":Kits_Or_Compilers_QTreeView") if not __selectTreeItemOnBuildAndRun__(targetsTreeView, "%s(\s\(default\))?" % kit, True): test.fatal("Found no matching kit - this shouldn't happen.") clickButton(waitForObject(":Options.Cancel_QPushButton")) diff --git a/tests/system/shared/utils.py b/tests/system/shared/utils.py index 3430b50d5f..4e015fd437 100644 --- a/tests/system/shared/utils.py +++ b/tests/system/shared/utils.py @@ -291,7 +291,7 @@ def getConfiguredKits(): return treeWidget.currentItem().text(0) # end of internal function for iterateQtVersions def __setQtVersionForKit__(kit, kitName, kitsQtVersionName): - treeView = waitForObject(":Kits_QTreeView") + treeView = waitForObject(":Kits_Or_Compilers_QTreeView") clickItem(treeView, kit, 5, 5, 0, Qt.LeftButton) qtVersionStr = str(waitForObject(":Kits_QtVersion_QComboBox").currentText) kitsQtVersionName[kitName] = qtVersionStr @@ -343,7 +343,7 @@ def regexVerify(text, expectedTexts): def checkDebuggingLibrary(kitIDs): def __getQtVersionForKit__(kit, kitName): - treeView = waitForObject(":Kits_QTreeView") + treeView = waitForObject(":Kits_Or_Compilers_QTreeView") clickItem(treeView, kit, 5, 5, 0, Qt.LeftButton) return str(waitForObject(":Kits_QtVersion_QComboBox").currentText) # end of internal function for iterate kits @@ -490,7 +490,7 @@ def iterateKits(keepOptionsOpen=False, alreadyOnOptionsDialog=False, waitForObjectItem(":Options_QListView", "Build & Run") clickItem(":Options_QListView", "Build & Run", 14, 15, 0, Qt.LeftButton) clickTab(waitForObject(":Options.qt_tabwidget_tabbar_QTabBar"), "Kits") - treeView = waitForObject(":Kits_QTreeView") + treeView = waitForObject(":Kits_Or_Compilers_QTreeView") model = treeView.model() test.compare(model.rowCount(), 2, "Verifying expected target section count") autoDetected = model.index(0, 0) diff --git a/tests/system/suite_CCOM/tst_CCOM02/test.py b/tests/system/suite_CCOM/tst_CCOM02/test.py index a687649f8c..02b3e93df3 100755 --- a/tests/system/suite_CCOM/tst_CCOM02/test.py +++ b/tests/system/suite_CCOM/tst_CCOM02/test.py @@ -15,7 +15,7 @@ def main(): # open example project openQmakeProject(examplePath) # create syntax error - doubleClickItem(":Qt Creator_Utils::NavigationTreeView", "propertyanimation.QML.qml.property-animation\\.qml", 5, 5, 0, Qt.LeftButton) + openDocument("propertyanimation.QML.qml.property-animation\\.qml") if not appendToLine(waitForObject(":Qt Creator_QmlJSEditor::QmlJSTextEditorWidget"), "Image {", "SyntaxError"): invokeMenuItem("File", "Exit") return diff --git a/tests/system/suite_CSUP/tst_CSUP01/test.py b/tests/system/suite_CSUP/tst_CSUP01/test.py index 10b4f3ffa6..b3ca9bdece 100644 --- a/tests/system/suite_CSUP/tst_CSUP01/test.py +++ b/tests/system/suite_CSUP/tst_CSUP01/test.py @@ -8,10 +8,11 @@ def main(): # Step 1: Open test .pro project. createNewQtQuickApplication(tempDir(), "SampleApp") waitForSignal("{type='CppTools::Internal::CppModelManager' unnamed='1'}", "sourceFilesRefreshed(QStringList)") - test.verify(waitForObjectItem(":Qt Creator_Utils::NavigationTreeView", "SampleApp"), - "Step 1: Verifying if: Project is opened.") # Step 2: Open .cpp file in Edit mode. - doubleClickItem(":Qt Creator_Utils::NavigationTreeView", "SampleApp.Sources.main\\.cpp", 5, 5, 0, Qt.LeftButton) + if not openDocument("SampleApp.Sources.main\\.cpp"): + test.fatal("Could not open main.cpp") + invokeMenuItem("File", "Exit") + return test.verify(checkIfObjectExists(":Qt Creator_CppEditor::Internal::CPPEditorWidget"), "Step 2: Verifying if: .cpp file is opened in Edit mode.") # Step 3: Insert text "re" to new line in Editor mode and press Ctrl+Space. diff --git a/tests/system/suite_CSUP/tst_CSUP02/test.py b/tests/system/suite_CSUP/tst_CSUP02/test.py index 9e5a5b9c7a..c235574b0e 100644 --- a/tests/system/suite_CSUP/tst_CSUP02/test.py +++ b/tests/system/suite_CSUP/tst_CSUP02/test.py @@ -8,10 +8,11 @@ def main(): # Step 1: Open test .pro project. createNewQtQuickApplication(tempDir(), "SampleApp") waitForSignal("{type='CppTools::Internal::CppModelManager' unnamed='1'}", "sourceFilesRefreshed(QStringList)") - test.verify(waitForObjectItem(":Qt Creator_Utils::NavigationTreeView", "SampleApp"), - "Step 1: Verifying if: Project is opened.") # Step 2: Open .cpp file in Edit mode. - doubleClickItem(":Qt Creator_Utils::NavigationTreeView", "SampleApp.Sources.main\\.cpp", 5, 5, 0, Qt.LeftButton) + if not openDocument("SampleApp.Sources.main\\.cpp"): + test.fatal("Could not open main.cpp") + invokeMenuItem("File", "Exit") + return test.verify(checkIfObjectExists(":Qt Creator_CppEditor::Internal::CPPEditorWidget"), "Step 2: Verifying if: .cpp file is opened in Edit mode.") # Steps 3&4: Insert text "class" to new line in Editor mode and press Ctrl+Space. @@ -26,7 +27,6 @@ def main(): else: type(editorWidget, "<Ctrl+Space>") type(waitForObject(":popupFrame_Proposal_QListView"), "<Down>") - type(waitForObject(":popupFrame_Proposal_QListView"), "<Down>") listView = waitForObject(":popupFrame_Proposal_QListView") test.compare("class derived from QObject", str(listView.model().data(listView.currentIndex())), "Verifying selecting the correct entry.") diff --git a/tests/system/suite_CSUP/tst_CSUP04/test.py b/tests/system/suite_CSUP/tst_CSUP04/test.py index 28d4ac145b..e60c2ba362 100644 --- a/tests/system/suite_CSUP/tst_CSUP04/test.py +++ b/tests/system/suite_CSUP/tst_CSUP04/test.py @@ -18,11 +18,11 @@ def main(): installLazySignalHandler("{type='Core::FutureProgress' unnamed='1'}", "finished()", "__handleFutureProgress__") # wait for parsing to complete waitForSignal("{type='CppTools::Internal::CppModelManager' unnamed='1'}", "sourceFilesRefreshed(QStringList)") - # open test .pro project. - test.verify(waitForObjectItem(":Qt Creator_Utils::NavigationTreeView", "propertyanimation"), - "Verifying if: Project is opened.") # open .cpp file in editor - doubleClickItem(":Qt Creator_Utils::NavigationTreeView", "propertyanimation.Sources.main\\.cpp", 5, 5, 0, Qt.LeftButton) + if not openDocument("propertyanimation.Sources.main\\.cpp"): + test.fatal("Could not open main.cpp") + invokeMenuItem("File", "Exit") + return test.verify(checkIfObjectExists(":Qt Creator_CppEditor::Internal::CPPEditorWidget"), "Verifying if: .cpp file is opened in Edit mode.") # place cursor on line "QmlApplicationViewer viewer;" @@ -39,7 +39,7 @@ def main(): test.verify(result, "Verifying if: The list of all usages of the selected text is displayed in Search Results. " "File with used text is opened.") # move cursor to the other word and test Find Usages function by pressing Ctrl+Shift+U. - doubleClickItem(":Qt Creator_Utils::NavigationTreeView", "propertyanimation.Sources.main\\.cpp", 5, 5, 0, Qt.LeftButton) + openDocument("propertyanimation.Sources.main\\.cpp") if not placeCursorToLine(editorWidget, "viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);"): return for i in range(4): diff --git a/tests/system/suite_CSUP/tst_CSUP05/test.py b/tests/system/suite_CSUP/tst_CSUP05/test.py index f3d065ed0e..9db59aec2e 100644 --- a/tests/system/suite_CSUP/tst_CSUP05/test.py +++ b/tests/system/suite_CSUP/tst_CSUP05/test.py @@ -16,10 +16,11 @@ def main(): openQmakeProject(examplePath) # wait for parsing to complete waitForSignal("{type='CppTools::Internal::CppModelManager' unnamed='1'}", "sourceFilesRefreshed(QStringList)") - test.verify(waitForObjectItem(":Qt Creator_Utils::NavigationTreeView", "propertyanimation"), - "Verifying if: Project is opened.") # open .cpp file in editor - doubleClickItem(":Qt Creator_Utils::NavigationTreeView", "propertyanimation.Sources.main\\.cpp", 5, 5, 0, Qt.LeftButton) + if not openDocument("propertyanimation.Sources.main\\.cpp"): + test.fatal("Could not open main.cpp") + invokeMenuItem("File", "Exit") + return test.verify(checkIfObjectExists(":Qt Creator_CppEditor::Internal::CPPEditorWidget"), "Verifying if: .cpp file is opened in Edit mode.") # select some word for example "viewer" and press Ctrl+F. diff --git a/tests/system/suite_QMLS/shared/qmls.py b/tests/system/suite_QMLS/shared/qmls.py index 37bcdcb622..1792c98ff4 100644 --- a/tests/system/suite_QMLS/shared/qmls.py +++ b/tests/system/suite_QMLS/shared/qmls.py @@ -6,8 +6,11 @@ def startQtCreatorWithNewAppAtQMLEditor(projectDir, projectName, line = None): # create qt quick application createNewQtQuickApplication(projectDir, projectName) # open qml file - doubleClickItem(":Qt Creator_Utils::NavigationTreeView", projectName + ".QML.qml/" + - projectName + ".main\\.qml", 5, 5, 0, Qt.LeftButton) + qmlFile = projectName + ".QML.qml/" + projectName + ".main\\.qml" + if not openDocument(qmlFile): + test.fatal("Could not open %s" % qmlFile) + invokeMenuItem("File", "Exit") + return None # get editor editorArea = waitForObject(":Qt Creator_QmlJSEditor::QmlJSTextEditorWidget") # place to line if needed diff --git a/tests/system/suite_QMLS/tst_QMLS03/test.py b/tests/system/suite_QMLS/tst_QMLS03/test.py index 4340260f65..abb3ab3a5a 100644 --- a/tests/system/suite_QMLS/tst_QMLS03/test.py +++ b/tests/system/suite_QMLS/tst_QMLS03/test.py @@ -50,7 +50,7 @@ def main(): # open example project openQmakeProject(examplePath) # open qml file - doubleClickItem(":Qt Creator_Utils::NavigationTreeView", "propertyanimation.QML.qml.color-animation\\.qml", 5, 5, 0, Qt.LeftButton) + openDocument("propertyanimation.QML.qml.color-animation\\.qml") # get editor editorArea = waitForObject(":Qt Creator_QmlJSEditor::QmlJSTextEditorWidget") # 1. check usages using context menu diff --git a/tests/system/suite_SCOM/tst_SCOM02/test.py b/tests/system/suite_SCOM/tst_SCOM02/test.py index 67e8fca6ab..517217dabd 100644 --- a/tests/system/suite_SCOM/tst_SCOM02/test.py +++ b/tests/system/suite_SCOM/tst_SCOM02/test.py @@ -7,7 +7,7 @@ def main(): # create qt quick application createNewQtQuickApplication(tempDir(), "SampleApp") # create syntax error in qml file - doubleClickItem(":Qt Creator_Utils::NavigationTreeView", "SampleApp.QML.qml/SampleApp.main\\.qml", 5, 5, 0, Qt.LeftButton) + openDocument("SampleApp.QML.qml/SampleApp.main\\.qml") if not appendToLine(waitForObject(":Qt Creator_QmlJSEditor::QmlJSTextEditorWidget"), "Text {", "SyntaxError"): invokeMenuItem("File", "Exit") return diff --git a/tests/system/suite_SCOM/tst_SCOM04/test.py b/tests/system/suite_SCOM/tst_SCOM04/test.py index 254fea1060..be20b1fd36 100644 --- a/tests/system/suite_SCOM/tst_SCOM04/test.py +++ b/tests/system/suite_SCOM/tst_SCOM04/test.py @@ -10,7 +10,7 @@ def main(): # create qt quick application checkedTargets, projectName = createNewQtQuickApplication(tempDir(), "SampleApp") # create syntax error in cpp file - doubleClickItem(":Qt Creator_Utils::NavigationTreeView", "SampleApp.Sources.main\\.cpp", 5, 5, 0, Qt.LeftButton) + openDocument("SampleApp.Sources.main\\.cpp") if not appendToLine(waitForObject(":Qt Creator_CppEditor::Internal::CPPEditorWidget"), "viewer.showExpanded();", "SyntaxError"): invokeMenuItem("File", "Exit") return diff --git a/tests/system/suite_WELP/tst_WELP02/test.py b/tests/system/suite_WELP/tst_WELP02/test.py index edf29c9dc1..1dfa303b4d 100644 --- a/tests/system/suite_WELP/tst_WELP02/test.py +++ b/tests/system/suite_WELP/tst_WELP02/test.py @@ -29,7 +29,7 @@ def main(): waitForSignal("{type='CppTools::Internal::CppModelManager' unnamed='1'}", "sourceFilesRefreshed(QStringList)") test.verify(checkIfObjectExists("{column='0' container=':Qt Creator_Utils::NavigationTreeView'" - " text='SampleApp' type='QModelIndex'}"), + " text~='SampleApp( \(.*\))?' type='QModelIndex'}"), "Verifying: The project is opened in 'Edit' mode after configuring.") # go to "Welcome page" -> "Develop" topic again. switchViewTo(ViewConstants.WELCOME) @@ -43,7 +43,7 @@ def main(): waitForSignal("{type='CppTools::Internal::CppModelManager' unnamed='1'}", "sourceFilesRefreshed(QStringList)") test.verify(checkIfObjectExists("{column='0' container=':Qt Creator_Utils::NavigationTreeView'" - " text='propertyanimation' type='QModelIndex'}"), + " text~='propertyanimation( \(.*\))?' type='QModelIndex'}"), "Verifying: The project is opened in 'Edit' mode after configuring.") # go to "Welcome page" -> "Develop" again and check if there is an information about # recent projects in "Recent Projects". diff --git a/tests/system/suite_debugger/tst_simple_debug/test.py b/tests/system/suite_debugger/tst_simple_debug/test.py index 6f8231a844..bc581174db 100644 --- a/tests/system/suite_debugger/tst_simple_debug/test.py +++ b/tests/system/suite_debugger/tst_simple_debug/test.py @@ -34,7 +34,7 @@ def main(): test.log("Setting breakpoints") result = setBreakpointsForCurrentProject(filesAndLines) if result: - expectedBreakpointsOrder = [{"main.cpp":9}, {"main.qml":13}] + expectedBreakpointsOrder = [{"main.cpp":10}, {"main.qml":13}] # Only use 4.7.4 to work around QTBUG-25187 availableConfigs = iterateBuildConfigs(len(checkedTargets), "Debug") if not availableConfigs: diff --git a/tests/system/suite_editors/shared/testdata/main.c++ b/tests/system/suite_editors/shared/testdata/main.c++ new file mode 100644 index 0000000000..b48f94ec82 --- /dev/null +++ b/tests/system/suite_editors/shared/testdata/main.c++ @@ -0,0 +1,11 @@ +#include "mainwindow.h" +#include <QApplication> + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/tests/system/suite_editors/tst_qml_indent/test.py b/tests/system/suite_editors/tst_qml_indent/test.py index e38f766906..ea20cd59da 100644 --- a/tests/system/suite_editors/tst_qml_indent/test.py +++ b/tests/system/suite_editors/tst_qml_indent/test.py @@ -15,12 +15,9 @@ def main(): invokeMenuItem("File", "Exit") def prepareQmlFile(): - # make sure the QML file is opened - navTree = waitForObject("{type='Utils::NavigationTreeView' unnamed='1' visible='1' " - "window=':Qt Creator_Core::Internal::MainWindow'}") - model = navTree.model() - waitForObjectItem(navTree, "untitled.QML.qml/untitled.main\\.qml") - doubleClickItem(navTree, "untitled.QML.qml/untitled.main\\.qml", 5, 5, 0, Qt.LeftButton) + if not openDocument("untitled.QML.qml/untitled.main\\.qml"): + test.fatal("Could not open main.qml") + return False editor = waitForObject(":Qt Creator_QmlJSEditor::QmlJSTextEditorWidget") for i in range(3): content = "%s" % editor.plainText diff --git a/tests/system/suite_general/suite.conf b/tests/system/suite_general/suite.conf index 0eebd931d6..19ee1d31df 100644 --- a/tests/system/suite_general/suite.conf +++ b/tests/system/suite_general/suite.conf @@ -7,6 +7,6 @@ HOOK_SUB_PROCESSES=false IMPLICITAUTSTART=0 LANGUAGE=Python OBJECTMAP=../objects.map -TEST_CASES=tst_build_speedcrunch tst_cmake_speedcrunch tst_create_proj_wizard tst_installed_languages tst_openqt_creator +TEST_CASES=tst_build_speedcrunch tst_cmake_speedcrunch tst_create_proj_wizard tst_default_settings tst_installed_languages tst_openqt_creator VERSION=2 WRAPPERS=Qt diff --git a/tests/system/suite_general/tst_default_settings/test.py b/tests/system/suite_general/tst_default_settings/test.py new file mode 100644 index 0000000000..c7523eba2c --- /dev/null +++ b/tests/system/suite_general/tst_default_settings/test.py @@ -0,0 +1,236 @@ +source("../../shared/qtcreator.py") + +import re +import tempfile +import __builtin__ + +currentSelectedTreeItem = None +warningOrError = re.compile('<p><b>((Error|Warning).*?)</p>') + +def main(): + emptySettings = tempDir() + __createMinimumIni__(emptySettings) + SettingsPath = ' -settingspath "%s"' % emptySettings + startApplication("qtcreator" + SettingsPath) + invokeMenuItem("Tools", "Options...") + __checkBuildAndRun__() + clickButton(waitForObject(":Options.Cancel_QPushButton")) + invokeMenuItem("File", "Exit") + __checkCreatedSettings__(emptySettings) + +def __createMinimumIni__(emptyParent): + qtProjDir = os.path.join(emptyParent, "QtProject") + os.mkdir(qtProjDir) + iniFile = open(os.path.join(qtProjDir, "QtCreator.ini"), "w") + iniFile.write("[%General]\n") + iniFile.write("OverrideLanguage=C\n") + iniFile.close() + +def __checkBuildAndRun__(): + waitForObjectItem(":Options_QListView", "Build & Run") + clickItem(":Options_QListView", "Build & Run", 14, 15, 0, Qt.LeftButton) + # check compilers + expectedCompilers = __getExpectedCompilers__() + foundCompilers = [] + foundCompilerNames = [] + clickTab(waitForObject(":Options.qt_tabwidget_tabbar_QTabBar"), "Compilers") + compilerTV = waitForObject(":Kits_Or_Compilers_QTreeView") + __iterateTree__(compilerTV, __compFunc__, foundCompilers, foundCompilerNames) + test.verify(__compareCompilers__(foundCompilers, expectedCompilers), + "Verifying found and expected compilers are equal.") + # check Qt versions + qmakePath = which("qmake") + foundQt = [] + clickTab(waitForObject(":Options.qt_tabwidget_tabbar_QTabBar"), "Qt Versions") + qtTW = waitForObject(":QtSupport__Internal__QtVersionManager.qtdirList_QTreeWidget") + __iterateTree__(qtTW, __qtFunc__, foundQt, qmakePath) + if foundQt: + foundQt = foundQt[0] + # check kits + clickTab(waitForObject(":Options.qt_tabwidget_tabbar_QTabBar"), "Kits") + kitsTV = waitForObject(":Kits_Or_Compilers_QTreeView") + __iterateTree__(kitsTV, __kitFunc__, foundQt, foundCompilerNames) + +def __iterateTree__(treeObj, additionalFunc, *additionalParameters): + global currentSelectedTreeItem + model = treeObj.model() + # 1st row: Auto-detected, 2nd row: Manual + for sect in dumpIndices(model): + sObj = "%s container=%s}" % (objectMap.realName(sect)[:-1], objectMap.realName(treeObj)) + items = dumpIndices(model, sect) + doneItems = [] + for it in items: + indexName = str(it.data().toString()) + itObj = "%s container=%s}" % (objectMap.realName(it)[:-1], sObj) + alreadyDone = doneItems.count(itObj) + doneItems.append(itObj) + if alreadyDone: + itObj = "%s occurrence='%d'}" % (itObj[:-1], alreadyDone + 1) + currentSelectedTreeItem = waitForObject(itObj, 3000) + mouseClick(currentSelectedTreeItem, 5, 5, 0, Qt.LeftButton) + additionalFunc(indexName, *additionalParameters) + currentSelectedTreeItem = None + +def __compFunc__(it, foundComp, foundCompNames): + try: + waitFor("object.exists(':CompilerPath.Utils_BaseValidatingLineEdit')", 1000) + pathLineEdit = findObject(":CompilerPath.Utils_BaseValidatingLineEdit") + foundComp.append(str(pathLineEdit.text)) + except: + label = findObject("{buddy={container=':qt_tabwidget_stackedwidget_QWidget' " + "text='Initialization:' type='QLabel' unnamed='1' visible='1'} " + "type='QLabel' unnamed='1' visible='1'}") + foundComp.append({it:str(label.text)}) + foundCompNames.append(it) + +def __qtFunc__(it, foundQt, qmakePath): + foundQt.append(it) + qtPath = str(waitForObject(":QtSupport__Internal__QtVersionManager.qmake_QLabel").text) + if platform.system() in ('Microsoft', 'Windows'): + qtPath = qtPath.lower() + qmakePath = qmakePath.lower() + test.compare(qtPath, qmakePath, "Verifying found and expected Qt version are equal.") + try: + errorLabel = findObject(":QtSupport__Internal__QtVersionManager.errorLabel.QLabel") + test.warning("Detected error or warning: '%s'" % errorLabel.text) + except: + pass + +def __kitFunc__(it, foundQt, foundCompNames): + global currentSelectedTreeItem, warningOrError + qtVersionStr = str(waitForObject(":Kits_QtVersion_QComboBox").currentText) + test.compare(it, "Desktop (default)", "Verifying whether default Desktop kit has been created.") + if foundQt: + test.compare(qtVersionStr, foundQt, "Verifying if Qt versions match.") + compilerCombo = waitForObject("{occurrence='3' type='QComboBox' unnamed='1' visible='1' " + "window=':Qt Creator_Core::Internal::MainWindow'}") + test.verify(str(compilerCombo.currentText) in foundCompNames, + "Verifying if one of the found compilers had been set.") + if currentSelectedTreeItem: + foundWarningOrError = warningOrError.search(str(currentSelectedTreeItem.toolTip)) + if foundWarningOrError: + details = str(foundWarningOrError.group(1)).replace("<br>", "\n") + details = details.replace("<b>", "").replace("</b>", "") + test.warning("Detected error and/or warning: %s" % details) + +def __getExpectedCompilers__(): + expected = [] + if platform.system() in ('Microsoft', 'Windows'): + expected.extend(__getWinCompilers__()) + compilers = ["g++"] + if platform.system() in ('Linux', 'Darwin'): + compilers.extend(["g++-4.0", "g++-4.2", "clang++"]) + for compiler in compilers: + compilerPath = which(compiler) + if compilerPath: + if compiler == 'clang++': + if subprocess.call(['clang++', '-dumpmachine']) != 0: + test.warning("clang found in PATH, but version is not supported.") + continue + expected.append(compilerPath) + return expected + +def __getWinCompilers__(): + result = [] + winEnvVars = __getWinEnvVars__() + for record in testData.dataset("win_compiler_paths.tsv"): + envvar = winEnvVars.get(testData.field(record, "envvar"), "") + compiler = os.path.abspath(os.path.join(envvar, testData.field(record, "path"), + testData.field(record, "file"))) + if os.path.exists(compiler): + parameters = testData.field(record, "displayedParameters").split(",") + usedParameters = testData.field(record, "usedParameters").split(",") + if testData.field(record, "isSDK") == "true": + for para, used in zip(parameters, usedParameters): + result.append( + {"%s \(.*?\) \(%s\)" % (testData.field(record, 'displayName'), + para) + :"%s %s" % (compiler, used)}) + else: + for para, used in zip(parameters, usedParameters): + result.append({"%s (%s)" % (testData.field(record, 'displayName'), para) + :"%s %s" % (compiler, used)}) + return result + +# using os.getenv() or getOutputFromCmdline() do not work - they would return C:\Program Files (x86) +# for %ProgramFiles% as well as for %ProgramFiles(x86)% when using Python 32bit on 64bit machines +def __getWinEnvVars__(): + result = {} + tmpF, tmpFPath = tempfile.mkstemp() + envvars = subprocess.call('set', stdout=tmpF, shell=True) + os.close(tmpF) + tmpF = open(tmpFPath, "r") + for line in tmpF: + tmp = line.split("=") + result[tmp[0]] = tmp[1] + tmpF.close() + os.remove(tmpFPath) + return result + + +def __compareCompilers__(foundCompilers, expectedCompilers): + equal = True + flags = 0 + isWin = platform.system() in ('Microsoft', 'Windows') + if isWin: + flags = re.IGNORECASE + for currentFound in foundCompilers: + if isinstance(currentFound, dict): + foundExp = False + for currentExp in expectedCompilers: + if isinstance(currentExp, (str, unicode)): + continue + key = currentExp.keys()[0] + # the regex .*? is used for the different possible version strings of the WinSDK + # if it's present a regex will be validated otherwise simple string comparison + if (((".*?" in key and re.match(key, currentFound.keys()[0], flags)) + or currentFound.keys() == currentExp.keys())): + if ((isWin and os.path.abspath(currentFound.values()[0].lower()) + == os.path.abspath(currentExp.values()[0].lower())) + or currentFound.values() == currentExp.values()): + foundExp = True + break + equal = foundExp + else: + if isWin: + equal = currentFound.lower() in __lowerStrs__(expectedCompilers) + else: + equal = currentFound in expectedCompilers + if not equal: + test.fail("Found '%s' but was not expected." % str(currentFound), + str(expectedCompilers)) + break + return equal + +def __lowerStrs__(iterable): + for it in iterable: + if isinstance(it, (str, unicode)): + yield it.lower() + else: + yield it + +def __checkCreatedSettings__(settingsFolder): + qtProj = os.path.join(settingsFolder, "QtProject") + folders = [] + files = [{os.path.join(qtProj, "QtCreator.db"):0}, + {os.path.join(qtProj, "QtCreator.ini"):30}] + folders.append(os.path.join(qtProj, "qtcreator")) + files.extend([{os.path.join(folders[0], "devices.xml"):0}, + {os.path.join(folders[0], "helpcollection.qhc"):0}, + {os.path.join(folders[0], "profiles.xml"):0}, + {os.path.join(folders[0], "qtversion.xml"):0}, + {os.path.join(folders[0], "toolchains.xml"):0}]) + folders.extend([os.path.join(folders[0], "generic-highlighter"), + os.path.join(folders[0], "json"), + os.path.join(folders[0], "macros")]) + for f in folders: + test.verify(os.path.isdir(f), + "Verifying whether folder '%s' has been created." % os.path.basename(f)) + for f in files: + fName = f.keys()[0] + fMinSize = f.values()[0] + text = "created non-empty" + if fMinSize > 0: + text = "modified" + test.verify(os.path.isfile(fName) and os.path.getsize(fName) > fMinSize, + "Verifying whether file '%s' has been %s." % (os.path.basename(fName), text)) diff --git a/tests/system/suite_general/tst_default_settings/testdata/win_compiler_paths.tsv b/tests/system/suite_general/tst_default_settings/testdata/win_compiler_paths.tsv new file mode 100644 index 0000000000..0438a4698b --- /dev/null +++ b/tests/system/suite_general/tst_default_settings/testdata/win_compiler_paths.tsv @@ -0,0 +1,19 @@ +"envvar" "path" "file" "displayName" "displayedParameters" "usedParameters" "isSDK" +"ProgramFiles" "Microsoft SDKs\Windows\v7.0\Bin" "SetEnv.cmd" "Microsoft Windows SDK for Windows 7" "x86,amd64,x86_amd64,ia64,x86_ia64" "/x86,/x64,/x64,/ia64,/ia64" "true" +"ProgramFiles(x86)" "Microsoft SDKs\Windows\v7.0\Bin" "SetEnv.cmd" "Microsoft Windows SDK for Windows 7" "x86,amd64,x86_amd64,ia64,x86_ia64" "/x86,/x64,/x64,/ia64,/ia64" "true" +"ProgramFiles" "Microsoft SDKs\Windows\v7.1\Bin" "SetEnv.cmd" "Microsoft Windows SDK for Windows 7" "x86,amd64,x86_amd64,ia64,x86_ia64" "/x86,/x64,/x64,/ia64,/ia64" "true" +"ProgramFiles(x86)" "Microsoft SDKs\Windows\v7.1\Bin" "SetEnv.cmd" "Microsoft Windows SDK for Windows 7" "x86,amd64,x86_amd64,ia64,x86_ia64" "/x86,/x64,/x64,/ia64,/ia64" "true" +"VS80COMNTOOLS" "..\..\VC\Bin" "vcvars32.bat" "Microsoft Visual C++ Compiler 8.0" "x86" "" "false" +"VS80COMNTOOLS" "..\..\VC\Bin\amd64" "vcvarsamd64.bat" "Microsoft Visual C++ Compiler 8.0" "amd64" "amd64" "false" +"VS80COMNTOOLS" "..\..\VC\Bin" "vcvarsx86_amd64.bat" "Microsoft Visual C++ Compiler 8.0" "x86_amd64" "x86_amd64" "false" +"VS80COMNTOOLS" "..\..\VC\Bin" "vcvars64.bat" "Microsoft Visual C++ Compiler 8.0" "ia64" "ia64" "false" +"VS80COMNTOOLS" "..\..\VC\Bin" "vcvarsx86_ia64.bat" "Microsoft Visual C++ Compiler 8.0" "x86_ia64" "x86_ia64" "false" +"VS90COMNTOOLS" "..\..\VC\Bin" "vcvars32.bat" "Microsoft Visual C++ Compiler 9.0" "x86" "" "false" +"VS90COMNTOOLS" "..\..\VC\Bin\amd64" "vcvarsamd64.bat" "Microsoft Visual C++ Compiler 9.0" "amd64" "amd64" "false" +"VS90COMNTOOLS" "..\..\VC\Bin" "vcvarsx86_amd64.bat" "Microsoft Visual C++ Compiler 9.0" "x86_amd64" "x86_amd64" "false" +"VS90COMNTOOLS" "..\..\VC\Bin" "vcvars64.bat" "Microsoft Visual C++ Compiler 9.0" "ia64" "ia64" "false" +"VS90COMNTOOLS" "..\..\VC\Bin" "vcvarsx86_ia64.bat" "Microsoft Visual C++ Compiler 9.0" "x86_ia64" "x86_ia64" "false" +"VS100COMNTOOLS" "..\..\VC\Bin" "vcvars32.bat" "Microsoft Visual C++ Compiler 10.0" "x86" "" "false" +"VS100COMNTOOLS" "..\..\VC" "vcvarsall.bat" "Microsoft Visual C++ Compiler 10.0" "x86,amd64,x86_amd64,ia64,x86_ia64" "x86,amd64,x86_amd64,ia64,x86_ia64" "false" +"VS110COMNTOOLS" "..\..\VC\Bin" "vcvars32.bat" "Microsoft Visual C++ Compiler 11.0" "x86" "" "false" +"VS110COMNTOOLS" "..\..\VC" "vcvarsall.bat" "Microsoft Visual C++ Compiler 11.0" "x86,amd64,x86_amd64,ia64,x86_ia64" "x86,amd64,x86_amd64,ia64,x86_ia64" "false" diff --git a/tests/system/suite_general/tst_openqt_creator/test.py b/tests/system/suite_general/tst_openqt_creator/test.py index 8d34cbc100..6708d2c0a7 100644 --- a/tests/system/suite_general/tst_openqt_creator/test.py +++ b/tests/system/suite_general/tst_openqt_creator/test.py @@ -15,9 +15,9 @@ def main(): # Wait for parsing to complete waitForSignal("{type='CppTools::Internal::CppModelManager' unnamed='1'}", "sourceFilesRefreshed(QStringList)", 300000) - naviTreeView = "{column='0' container=':Qt Creator_Utils::NavigationTreeView' text='%s' type='QModelIndex'}" - compareProjectTree(naviTreeView % "speedcrunch", "projecttree_speedcrunch.tsv") - compareProjectTree(naviTreeView % "qtcreator", "projecttree_creator.tsv") + naviTreeView = "{column='0' container=':Qt Creator_Utils::NavigationTreeView' text~='%s' type='QModelIndex'}" + compareProjectTree(naviTreeView % "speedcrunch( \(\S+\))?", "projecttree_speedcrunch.tsv") + compareProjectTree(naviTreeView % "qtcreator( \(\S+\))?", "projecttree_creator.tsv") # Now check some basic lookups in the search box selectFromLocator(": Qlist::QList", "QList::QList") diff --git a/tests/tools/cplusplus-ast2png/cplusplus-ast2png.cpp b/tests/tools/cplusplus-ast2png/cplusplus-ast2png.cpp index 3298ea4a59..308090ed09 100644 --- a/tests/tools/cplusplus-ast2png/cplusplus-ast2png.cpp +++ b/tests/tools/cplusplus-ast2png/cplusplus-ast2png.cpp @@ -57,6 +57,7 @@ #include <cstdlib> #include <fstream> #include <iostream> +#include <string> #ifdef __GNUC__ # include <cxxabi.h> #endif @@ -115,7 +116,7 @@ protected: void alignTerminals() { out<<"{ rank=same;" << std::endl; foreach (const QByteArray &terminalShape, _terminalShapes) { - out << " " << std::string(terminalShape) << ";" << std::endl; + out << " " << std::string(terminalShape.constData(), terminalShape.size()).c_str() << ";" << std::endl; } out<<"}"<<std::endl; } @@ -203,9 +204,9 @@ public: SymbolDump(TranslationUnit *unit) : translationUnit(unit) { - o.setShowArgumentNames(true); - o.setShowFunctionSignatures(true); - o.setShowReturnTypes(true); + o.showArgumentNames = true; + o.showFunctionSignatures = true; + o.showReturnTypes = true; } void operator()(Symbol *s) { @@ -383,7 +384,7 @@ QString example() #else QString::fromLatin1("$ echo \"int foo() {}\" | ./%1 && xdg-open %2.ast.png") #endif - .arg(QFileInfo(qApp->arguments().at(0)).fileName(), PATH_STDIN_FILE); + .arg(QFileInfo(qApp->arguments().at(0)).fileName(), QLatin1String(PATH_STDIN_FILE)); } void printUsage() @@ -391,7 +392,7 @@ void printUsage() std::cout << "Usage: " << qPrintable(QFileInfo(qApp->arguments().at(0)).fileName()) << " [-v] <file1> <file2> ...\n\n"; - std::cout << qPrintable(QString::fromLatin1( + std::cout << QString::fromLatin1( "Visualize AST and symbol hierarchy of given C++ files by generating png image files\n" "in the same directory as the input files. Print paths to generated image files.\n" "\n" @@ -404,7 +405,7 @@ void printUsage() "Prerequisites:\n" " 1) Make sure to have 'dot' from graphviz locatable by PATH.\n" " 2) Make sure to have an up to date dumpers file by using 'cplusplus-update-frontend'.\n" - ).arg(PATH_STDIN_FILE, example())); + ).arg(QLatin1String(PATH_STDIN_FILE), example()).toLocal8Bit().constData(); } int main(int argc, char *argv[]) @@ -417,7 +418,7 @@ int main(int argc, char *argv[]) // Data from stdin? if (!tty_for_stdin()) { - QFile file("_stdincontents.cpp"); + QFile file((QLatin1String(PATH_STDIN_FILE))); if (! file.open(QFile::WriteOnly)) { std::cerr << "Error: Cannot open file for writing\"" << qPrintable(file.fileName()) << "\"" << std::endl; @@ -429,11 +430,12 @@ int main(int argc, char *argv[]) } // Process options & arguments - if (args.contains("-v")) { + if (args.contains(QLatin1String("-v"))) { optionVerbose = true; - args.removeOne("-v"); + args.removeOne(QLatin1String("-v")); } - const bool helpRequested = args.contains("-h") || args.contains("-help"); + const bool helpRequested = args.contains(QLatin1String("-h")) + || args.contains(QLatin1String("-help")); if (args.isEmpty() || helpRequested) { printUsage(); return helpRequested ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/tests/tools/cplusplus-ast2png/cplusplus-ast2png.pro b/tests/tools/cplusplus-ast2png/cplusplus-ast2png.pro index 8a0fd726ad..c02c4dba9f 100644 --- a/tests/tools/cplusplus-ast2png/cplusplus-ast2png.pro +++ b/tests/tools/cplusplus-ast2png/cplusplus-ast2png.pro @@ -9,4 +9,5 @@ include(../../../qtcreator.pri) include(../../../src/libs/cplusplus/cplusplus-lib.pri) include(../../../src/tools/cplusplus-tools-utils/cplusplus-tools-utils.pri) +DEFINES *= QT_NO_CAST_FROM_ASCII SOURCES += cplusplus-ast2png.cpp diff --git a/tests/tools/cplusplus-ast2png/dumpers.inc b/tests/tools/cplusplus-ast2png/dumpers.inc index 0d1d8e4620..1d3d20238b 100644 --- a/tests/tools/cplusplus-ast2png/dumpers.inc +++ b/tests/tools/cplusplus-ast2png/dumpers.inc @@ -22,7 +22,7 @@ // W A R N I N G // ------------- // -// This file is automatically generated. +// This file is automatically generated by "cplusplus-update-frontend". // Changes will be lost. // @@ -359,6 +359,8 @@ virtual bool visit(ClassSpecifierAST *ast) for (SpecifierListAST *iter = ast->attribute_list; iter; iter = iter->next) nonterminal(iter->value); nonterminal(ast->name); + if (ast->final_token) + terminal(ast->final_token, ast); if (ast->colon_token) terminal(ast->colon_token, ast); for (BaseSpecifierListAST *iter = ast->base_clause_list; iter; iter = iter->next) @@ -477,6 +479,8 @@ virtual bool visit(FunctionDeclaratorAST *ast) terminal(ast->rparen_token, ast); for (SpecifierListAST *iter = ast->cv_qualifier_list; iter; iter = iter->next) nonterminal(iter->value); + if (ast->ref_qualifier_token) + terminal(ast->ref_qualifier_token, ast); nonterminal(ast->exception_specification); nonterminal(ast->trailing_return_type); nonterminal(ast->as_cpp_initializer); @@ -544,7 +548,13 @@ virtual bool visit(EnumSpecifierAST *ast) { if (ast->enum_token) terminal(ast->enum_token, ast); + if (ast->key_token) + terminal(ast->key_token, ast); nonterminal(ast->name); + if (ast->colon_token) + terminal(ast->colon_token, ast); + for (SpecifierListAST *iter = ast->type_specifier_list; iter; iter = iter->next) + nonterminal(iter->value); if (ast->lbrace_token) terminal(ast->lbrace_token, ast); for (EnumeratorListAST *iter = ast->enumerator_list; iter; iter = iter->next) @@ -649,6 +659,24 @@ virtual bool visit(ForeachStatementAST *ast) return false; } +virtual bool visit(RangeBasedForStatementAST *ast) +{ + if (ast->for_token) + terminal(ast->for_token, ast); + if (ast->lparen_token) + terminal(ast->lparen_token, ast); + for (SpecifierListAST *iter = ast->type_specifier_list; iter; iter = iter->next) + nonterminal(iter->value); + nonterminal(ast->declarator); + if (ast->colon_token) + terminal(ast->colon_token, ast); + nonterminal(ast->expression); + if (ast->rparen_token) + terminal(ast->rparen_token, ast); + nonterminal(ast->statement); + return false; +} + virtual bool visit(ForStatementAST *ast) { if (ast->for_token) @@ -727,12 +755,7 @@ virtual bool visit(LinkageSpecificationAST *ast) virtual bool visit(MemInitializerAST *ast) { nonterminal(ast->name); - if (ast->lparen_token) - terminal(ast->lparen_token, ast); - for (ExpressionListAST *iter = ast->expression_list; iter; iter = iter->next) - nonterminal(iter->value); - if (ast->rparen_token) - terminal(ast->rparen_token, ast); + nonterminal(ast->expression); return false; } @@ -831,7 +854,21 @@ virtual bool visit(NamespaceAliasDefinitionAST *ast) return false; } -virtual bool visit(NewPlacementAST *ast) +virtual bool visit(AliasDeclarationAST *ast) +{ + if (ast->using_token) + terminal(ast->using_token, ast); + if (ast->identifier_token) + terminal(ast->identifier_token, ast); + if (ast->equal_token) + terminal(ast->equal_token, ast); + nonterminal(ast->typeId); + if (ast->semicolon_token) + terminal(ast->semicolon_token, ast); + return false; +} + +virtual bool visit(ExpressionListParenAST *ast) { if (ast->lparen_token) terminal(ast->lparen_token, ast); @@ -869,16 +906,6 @@ virtual bool visit(NewExpressionAST *ast) return false; } -virtual bool visit(NewInitializerAST *ast) -{ - if (ast->lparen_token) - terminal(ast->lparen_token, ast); - nonterminal(ast->expression); - if (ast->rparen_token) - terminal(ast->rparen_token, ast); - return false; -} - virtual bool visit(NewTypeIdAST *ast) { for (SpecifierListAST *iter = ast->type_specifier_list; iter; iter = iter->next) @@ -980,12 +1007,7 @@ virtual bool visit(TypenameCallExpressionAST *ast) if (ast->typename_token) terminal(ast->typename_token, ast); nonterminal(ast->name); - if (ast->lparen_token) - terminal(ast->lparen_token, ast); - for (ExpressionListAST *iter = ast->expression_list; iter; iter = iter->next) - nonterminal(iter->value); - if (ast->rparen_token) - terminal(ast->rparen_token, ast); + nonterminal(ast->expression); return false; } @@ -993,12 +1015,7 @@ virtual bool visit(TypeConstructorCallAST *ast) { for (SpecifierListAST *iter = ast->type_specifier_list; iter; iter = iter->next) nonterminal(iter->value); - if (ast->lparen_token) - terminal(ast->lparen_token, ast); - for (ExpressionListAST *iter = ast->expression_list; iter; iter = iter->next) - nonterminal(iter->value); - if (ast->rparen_token) - terminal(ast->rparen_token, ast); + nonterminal(ast->expression); return false; } @@ -1012,6 +1029,8 @@ virtual bool visit(PointerToMemberAST *ast) terminal(ast->star_token, ast); for (SpecifierListAST *iter = ast->cv_qualifier_list; iter; iter = iter->next) nonterminal(iter->value); + if (ast->ref_qualifier_token) + terminal(ast->ref_qualifier_token, ast); return false; } @@ -1084,6 +1103,18 @@ virtual bool visit(SizeofExpressionAST *ast) return false; } +virtual bool visit(AlignofExpressionAST *ast) +{ + if (ast->alignof_token) + terminal(ast->alignof_token, ast); + if (ast->lparen_token) + terminal(ast->lparen_token, ast); + nonterminal(ast->typeId); + if (ast->rparen_token) + terminal(ast->rparen_token, ast); + return false; +} + virtual bool visit(PointerLiteralAST *ast) { if (ast->literal_token) @@ -1614,6 +1645,9 @@ virtual bool visit(LambdaCaptureAST *ast) virtual bool visit(CaptureAST *ast) { + if (ast->amper_token) + terminal(ast->amper_token, ast); + nonterminal(ast->identifier); return false; } diff --git a/tests/tools/qml-ast2dot/main.cpp b/tests/tools/qml-ast2dot/main.cpp index b79fb35ace..870ad50846 100644 --- a/tests/tools/qml-ast2dot/main.cpp +++ b/tests/tools/qml-ast2dot/main.cpp @@ -43,6 +43,7 @@ #include <cstdlib> #include <fstream> #include <iostream> +#include <string> #ifdef __GNUC__ # include <cxxabi.h> #endif @@ -83,7 +84,7 @@ protected: void alignTerminals() { out<<"{ rank=same;" << endl; foreach (const QByteArray &terminalShape, _terminalShapes) { - out << " " << string(terminalShape) << ";" << endl; + out << " " << string(terminalShape.constData(), terminalShape.size()).c_str() << ";" << endl; } out<<"}"<<endl; } diff --git a/tests/valgrind/callgrind/callgrindparsertests.cpp b/tests/valgrind/callgrind/callgrindparsertests.cpp index 3157491b1f..da909fc3b1 100644 --- a/tests/valgrind/callgrind/callgrindparsertests.cpp +++ b/tests/valgrind/callgrind/callgrindparsertests.cpp @@ -121,8 +121,8 @@ void CallgrindParserTests::testHeaderData() { QScopedPointer<const ParseData> data(parseDataFile(dataFile("simpleFunction.out"))); - QCOMPARE(data->command(), QString("ls")); - QCOMPARE(data->creator(), QString("callgrind-3.6.0.SVN-Debian")); + QCOMPARE(data->command(), QLatin1String("ls")); + QCOMPARE(data->creator(), QLatin1String("callgrind-3.6.0.SVN-Debian")); QCOMPARE(data->pid(), quint64(2992)); QCOMPARE(data->version(), 1); QCOMPARE(data->part(), 1u); @@ -144,9 +144,9 @@ void CallgrindParserTests::testSimpleFunction() { const Function *func = data->functions().at(0); - QCOMPARE(func->file(), QString("/my/file.cpp")); - QCOMPARE(func->object(), QString("/my/object")); - QCOMPARE(func->name(), QString("myFunction")); + QCOMPARE(func->file(), QLatin1String("/my/file.cpp")); + QCOMPARE(func->object(), QLatin1String("/my/object")); + QCOMPARE(func->name(), QLatin1String("myFunction")); QVERIFY(func->outgoingCalls().isEmpty()); QCOMPARE(func->called(), quint64(0)); @@ -157,7 +157,7 @@ void CallgrindParserTests::testSimpleFunction() testSimpleCostItem(func->costItems().at(2), 3, 3); testSimpleCostItem(func->costItems().at(3), 1, 1); testSimpleCostItem(func->costItems().at(4), 5, 4); - testDifferringFileCostItem(func->costItems().at(5), QString("/my/file3.h"), 1, 5); + testDifferringFileCostItem(func->costItems().at(5), QLatin1String("/my/file3.h"), 1, 5); testSimpleCostItem(func->costItems().at(6), 7, 5); QCOMPARE(func->selfCost(0), quint64(20)); QCOMPARE(func->inclusiveCost(0), quint64(20)); @@ -165,9 +165,9 @@ void CallgrindParserTests::testSimpleFunction() { const Function *func = data->functions().at(1); - QCOMPARE(func->file(), QString("/my/file.cpp")); - QCOMPARE(func->object(), QString("/my/object")); - QCOMPARE(func->name(), QString("myFunction2")); + QCOMPARE(func->file(), QLatin1String("/my/file.cpp")); + QCOMPARE(func->object(), QLatin1String("/my/object")); + QCOMPARE(func->name(), QLatin1String("myFunction2")); QVERIFY(func->incomingCalls().isEmpty()); QCOMPARE(func->called(), quint64(0)); @@ -179,9 +179,9 @@ void CallgrindParserTests::testSimpleFunction() { const Function *func = data->functions().at(2); - QCOMPARE(func->file(), QString("/my/file2.cpp")); - QCOMPARE(func->object(), QString("/my/object")); - QCOMPARE(func->name(), QString("myFunction4")); + QCOMPARE(func->file(), QLatin1String("/my/file2.cpp")); + QCOMPARE(func->object(), QLatin1String("/my/object")); + QCOMPARE(func->name(), QLatin1String("myFunction4")); QVERIFY(func->incomingCalls().isEmpty()); QCOMPARE(func->called(), quint64(0)); @@ -193,9 +193,9 @@ void CallgrindParserTests::testSimpleFunction() { const Function *func = data->functions().at(3); - QCOMPARE(func->file(), QString("/my/file.cpp")); - QCOMPARE(func->object(), QString("/my/object2")); - QCOMPARE(func->name(), QString("myFunction3")); + QCOMPARE(func->file(), QLatin1String("/my/file.cpp")); + QCOMPARE(func->object(), QLatin1String("/my/object2")); + QCOMPARE(func->name(), QLatin1String("myFunction3")); QVERIFY(func->incomingCalls().isEmpty()); QCOMPARE(func->called(), quint64(0)); @@ -213,9 +213,9 @@ void CallgrindParserTests::testCallee() // basic function data testing const Function *main = data->functions().at(0); - QCOMPARE(main->file(), QString("file1.c")); - QCOMPARE(main->object(), QString("")); - QCOMPARE(main->name(), QString("main")); + QCOMPARE(main->file(), QLatin1String("file1.c")); + QCOMPARE(main->object(), QLatin1String("")); + QCOMPARE(main->name(), QLatin1String("main")); QVERIFY(main->incomingCalls().isEmpty()); QCOMPARE(main->called(), quint64(0)); @@ -227,9 +227,9 @@ void CallgrindParserTests::testCallee() QCOMPARE(main->inclusiveCost(0), quint64(1230)); const Function *func1 = data->functions().at(1); - QCOMPARE(func1->file(), QString("file1.c")); - QCOMPARE(func1->object(), QString("")); - QCOMPARE(func1->name(), QString("func1")); + QCOMPARE(func1->file(), QLatin1String("file1.c")); + QCOMPARE(func1->object(), QLatin1String("")); + QCOMPARE(func1->name(), QLatin1String("func1")); QCOMPARE(func1->incomingCalls().size(), 1); QCOMPARE(func1->called(), quint64(1)); @@ -240,9 +240,9 @@ void CallgrindParserTests::testCallee() QCOMPARE(func1->inclusiveCost(0), quint64(400)); const Function *func2 = data->functions().at(2); - QCOMPARE(func2->file(), QString("file2.c")); - QCOMPARE(func2->object(), QString("")); - QCOMPARE(func2->name(), QString("func2")); + QCOMPARE(func2->file(), QLatin1String("file2.c")); + QCOMPARE(func2->object(), QLatin1String("")); + QCOMPARE(func2->name(), QLatin1String("func2")); QCOMPARE(func2->incomingCalls().size(), 2); QCOMPARE(func2->called(), quint64(8)); @@ -286,18 +286,18 @@ void CallgrindParserTests::testInlinedCalls() QCOMPARE(data->functions().size(), 3); const Function *main = data->functions().first(); - QCOMPARE(main->name(), QString("main")); - QCOMPARE(main->file(), QString("file1.c")); + QCOMPARE(main->name(), QLatin1String("main")); + QCOMPARE(main->file(), QLatin1String("file1.c")); QCOMPARE(main->selfCost(0), quint64(4)); QCOMPARE(main->inclusiveCost(0), quint64(804)); const Function *inlined = data->functions().at(1); - QCOMPARE(inlined->name(), QString("Something::Inlined()")); - QCOMPARE(inlined->file(), QString("file.h")); + QCOMPARE(inlined->name(), QLatin1String("Something::Inlined()")); + QCOMPARE(inlined->file(), QLatin1String("file.h")); const Function *func1 = data->functions().last(); - QCOMPARE(func1->name(), QString("func1")); - QCOMPARE(func1->file(), QString("file3.h")); + QCOMPARE(func1->name(), QLatin1String("func1")); + QCOMPARE(func1->file(), QLatin1String("file3.h")); QCOMPARE(main->outgoingCalls().size(), 2); QCOMPARE(main->costItems().at(2)->call()->callee(), inlined); @@ -395,9 +395,9 @@ void CallgrindParserTests::testCycle() QCOMPARE(b->selfCost(0), quint64(20)); QCOMPARE(data->functions(true).size(), 3); - QCOMPARE(findFunction(QString("main"), data->functions(true)), main); - QCOMPARE(findFunction(QString("A()"), data->functions(true)), a); - const FunctionCycle *cycle = dynamic_cast<const FunctionCycle*>(findFunction(QString("cycle 1"), data->functions(true))); + QCOMPARE(findFunction(QLatin1String("main"), data->functions(true)), main); + QCOMPARE(findFunction(QLatin1String("A()"), data->functions(true)), a); + const FunctionCycle *cycle = dynamic_cast<const FunctionCycle*>(findFunction(QLatin1String("cycle 1"), data->functions(true))); QVERIFY(cycle); QCOMPARE(cycle->called(), quint64(2)); QCOMPARE(cycle->inclusiveCost(0), quint64(40)); @@ -409,34 +409,34 @@ void CallgrindParserTests::testRecursiveCycle() QScopedPointer<const ParseData> data(parseDataFile(dataFile("recursiveCycle.out"))); QCOMPARE(data->functions().size(), 5); - const Function *main = findFunction(QString("main"), data->functions()); + const Function *main = findFunction(QLatin1String("main"), data->functions()); QVERIFY(main); QCOMPARE(main->inclusiveCost(0), quint64(70701765 + 3 + 4)); QCOMPARE(data->totalCost(0), main->inclusiveCost(0)); QCOMPARE(main->selfCost(0), quint64(3 + 4)); - const Function *a1 = findFunction(QString("A(int)"), data->functions()); + const Function *a1 = findFunction(QLatin1String("A(int)"), data->functions()); QVERIFY(a1); QCOMPARE(a1->inclusiveCost(0), quint64(700017 + 70001746 + 2)); QCOMPARE(a1->selfCost(0), quint64(700017 + 2)); - const Function *a2 = findFunction(QString("A(int)'2"), data->functions()); + const Function *a2 = findFunction(QLatin1String("A(int)'2"), data->functions()); QVERIFY(a2); QCOMPARE(a2->inclusiveCost(0), quint64(35000846 + 1715042679 + 100)); QCOMPARE(a2->selfCost(0), quint64(35000846 + 100)); - const Function *b1 = findFunction(QString("B(int)"), data->functions()); + const Function *b1 = findFunction(QLatin1String("B(int)"), data->functions()); QVERIFY(b1); QCOMPARE(b1->inclusiveCost(0), quint64(700014 + 69301730 + 2)); QCOMPARE(b1->selfCost(0), quint64(700014 + 2)); - const Function *b2 = findFunction(QString("B(int)'2"), data->functions()); + const Function *b2 = findFunction(QLatin1String("B(int)'2"), data->functions()); QVERIFY(b2); QCOMPARE(b2->inclusiveCost(0), quint64(34300686 + 1680741895 + 98)); QCOMPARE(b2->selfCost(0), quint64(34300686 + 98)); { // cycle detection QCOMPARE(data->functions(true).size(), 4); - QCOMPARE(findFunction(QString("main"), data->functions(true)), main); - QCOMPARE(findFunction(QString("A(int)"), data->functions(true)), a1); - QCOMPARE(findFunction(QString("B(int)"), data->functions(true)), b1); - const FunctionCycle *cycle = dynamic_cast<const FunctionCycle*>(findFunction(QString("cycle 1"), data->functions(true))); + QCOMPARE(findFunction(QLatin1String("main"), data->functions(true)), main); + QCOMPARE(findFunction(QLatin1String("A(int)"), data->functions(true)), a1); + QCOMPARE(findFunction(QLatin1String("B(int)"), data->functions(true)), b1); + const FunctionCycle *cycle = dynamic_cast<const FunctionCycle*>(findFunction(QLatin1String("cycle 1"), data->functions(true))); QVERIFY(cycle); QCOMPARE(cycle->called(), quint64(1)); const quint64 restCost = data->totalCost(0) - main->selfCost(0) - a1->selfCost(0) - b1->selfCost(0); @@ -451,17 +451,17 @@ void CallgrindParserTests::testRecursion() QCOMPARE(data->functions().size(), 3); QCOMPARE(data->totalCost(0), quint64(35700972)); - const Function *main = findFunction(QString("main"), data->functions()); + const Function *main = findFunction(QLatin1String("main"), data->functions()); QVERIFY(main); QCOMPARE(main->inclusiveCost(0), quint64(4 + 35700965 + 3)); QCOMPARE(main->selfCost(0), quint64(4 + 3)); - const Function *a1 = findFunction(QString("A(int)"), data->functions()); + const Function *a1 = findFunction(QLatin1String("A(int)"), data->functions()); QVERIFY(a1); QCOMPARE(a1->inclusiveCost(0), quint64(700010 + 35000946 + 2)); QCOMPARE(a1->selfCost(0), quint64(700010 + 2)); - const Function *a2 = findFunction(QString("A(int)'2"), data->functions()); + const Function *a2 = findFunction(QLatin1String("A(int)'2"), data->functions()); QVERIFY(a2); // inclusive cost must be the same as call-cost from a1 QCOMPARE(a2->inclusiveCost(0), quint64(35000946)); diff --git a/tests/valgrind/callgrind/callgrindparsertests.pro b/tests/valgrind/callgrind/callgrindparsertests.pro index 39b25046c4..99ccfb9bd0 100644 --- a/tests/valgrind/callgrind/callgrindparsertests.pro +++ b/tests/valgrind/callgrind/callgrindparsertests.pro @@ -1,6 +1,7 @@ include(../../auto/qttest.pri) include($$IDE_SOURCE_TREE/src/plugins/valgrind/valgrind_test.pri) include($$IDE_SOURCE_TREE/src/libs/utils/utils.pri) +include($$IDE_SOURCE_TREE/src/libs/ssh/ssh.pri) TARGET = callgrindparsertests DEFINES += "PARSERTESTS_DATA_DIR=\\\"$$PWD/data\\\"" diff --git a/tests/valgrind/memcheck/modeldemo.pro b/tests/valgrind/memcheck/modeldemo.pro index e002f36542..eb843efdf7 100644 --- a/tests/valgrind/memcheck/modeldemo.pro +++ b/tests/valgrind/memcheck/modeldemo.pro @@ -2,6 +2,7 @@ include(../../../qtcreator.pri) include(../../auto/qttestrpath.pri) include($$IDE_SOURCE_TREE/src/libs/3rdparty/botan/botan.pri) include($$IDE_SOURCE_TREE/src/libs/utils/utils.pri) +include($$IDE_SOURCE_TREE/src/libs/ssh/ssh.pri) include($$IDE_SOURCE_TREE/src/plugins/valgrind/valgrind_test.pri) TEMPLATE = app diff --git a/tests/valgrind/memcheck/parsertests.cpp b/tests/valgrind/memcheck/parsertests.cpp index eeb884587c..cf72a3f97f 100644 --- a/tests/valgrind/memcheck/parsertests.cpp +++ b/tests/valgrind/memcheck/parsertests.cpp @@ -115,7 +115,7 @@ void ParserTests::initTest(const QLatin1String &testfile, const QStringList &oth m_process->start( fakeValgrindExecutable(), QStringList() - << QString("--xml-socket=127.0.0.1:%1").arg(m_server->serverPort()) + << QString::fromLatin1("--xml-socket=127.0.0.1:%1").arg(m_server->serverPort()) << QLatin1String("-i") << dataFile(testfile) << otherArgs @@ -457,7 +457,7 @@ void ParserTests::testRealValgrind() ThreadedParser parser; Valgrind::Memcheck::MemcheckRunner runner; - runner.setValgrindExecutable(QString("valgrind")); + runner.setValgrindExecutable(QLatin1String("valgrind")); runner.setDebuggeeExecutable(executable); runner.setParser(&parser); RunnerDumper dumper(&runner, &parser); @@ -472,13 +472,14 @@ void ParserTests::testValgrindStartError_data() QTest::addColumn<QString>("debuggee"); QTest::addColumn<QString>("debuggeeArgs"); - QTest::newRow("invalid_client") << QString("valgrind") << QStringList() - << QString("please-dont-let-this-app-exist") << QString(); + QTest::newRow("invalid_client") << QString::fromLatin1("valgrind") << QStringList() + << QString::fromLatin1("please-dont-let-this-app-exist") << QString(); - QTest::newRow("invalid_valgrind") << QString("valgrind-that-does-not-exist") << QStringList() + QTest::newRow("invalid_valgrind") << QString::fromLatin1("valgrind-that-does-not-exist") << QStringList() << fakeValgrindExecutable() << QString(); - QTest::newRow("invalid_valgrind_args") << QString("valgrind") << (QStringList() << "--foobar-fail") + QTest::newRow("invalid_valgrind_args") << QString::fromLatin1("valgrind") + << (QStringList() << QString::fromLatin1("--foobar-fail")) << fakeValgrindExecutable() << QString(); } diff --git a/tests/valgrind/memcheck/parsertests.pro b/tests/valgrind/memcheck/parsertests.pro index 3170210d38..e58578dabe 100644 --- a/tests/valgrind/memcheck/parsertests.pro +++ b/tests/valgrind/memcheck/parsertests.pro @@ -1,5 +1,6 @@ include(../../auto/qttest.pri) include($$IDE_SOURCE_TREE/src/libs/3rdparty/botan/botan.pri) +include($$IDE_SOURCE_TREE/src/libs/ssh/ssh.pri) include($$IDE_SOURCE_TREE/src/libs/utils/utils.pri) include($$IDE_SOURCE_TREE/src/plugins/valgrind/valgrind_test.pri) diff --git a/tests/valgrind/memcheck/testrunner.cpp b/tests/valgrind/memcheck/testrunner.cpp index dc74f6c0a6..d445d3bdfe 100644 --- a/tests/valgrind/memcheck/testrunner.cpp +++ b/tests/valgrind/memcheck/testrunner.cpp @@ -151,11 +151,11 @@ void TestRunner::testLeak1() QCOMPARE(stack.frames().count(), 2); { const Frame frame = stack.frames().at(0); - QCOMPARE(frame.functionName(), QString("operator new(unsigned long)")); + QCOMPARE(frame.functionName(), QLatin1String("operator new(unsigned long)")); } { const Frame frame = stack.frames().at(1); - QCOMPARE(frame.functionName(), QString("main")); + QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.line(), 5); QCOMPARE(frame.object(), binary); @@ -181,15 +181,15 @@ void TestRunner::testLeak2() QCOMPARE(stack.frames().count(), 3); { const Frame frame = stack.frames().at(0); - QCOMPARE(frame.functionName(), QString("malloc")); + QCOMPARE(frame.functionName(), QLatin1String("malloc")); } { const Frame frame = stack.frames().at(1); - QCOMPARE(frame.functionName(), QString("strdup")); + QCOMPARE(frame.functionName(), QLatin1String("strdup")); } { const Frame frame = stack.frames().at(2); - QCOMPARE(frame.functionName(), QString("main")); + QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.line(), 7); QCOMPARE(frame.object(), binary); @@ -215,15 +215,15 @@ void TestRunner::testLeak3() QCOMPARE(stack.frames().count(), 3); { const Frame frame = stack.frames().at(0); - QCOMPARE(frame.functionName(), QString("malloc")); + QCOMPARE(frame.functionName(), QLatin1String("malloc")); } { const Frame frame = stack.frames().at(1); - QCOMPARE(frame.functionName(), QString("strdup")); + QCOMPARE(frame.functionName(), QLatin1String("strdup")); } { const Frame frame = stack.frames().at(2); - QCOMPARE(frame.functionName(), QString("main")); + QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.line(), 7); QCOMPARE(frame.object(), binary); @@ -254,11 +254,11 @@ void TestRunner::testLeak4() QCOMPARE(stack.frames().count(), 3); { const Frame frame = stack.frames().at(0); - QCOMPARE(frame.functionName(), QString("operator new(unsigned long)")); + QCOMPARE(frame.functionName(), QLatin1String("operator new(unsigned long)")); } { const Frame frame = stack.frames().at(2); - QCOMPARE(frame.functionName(), QString("main")); + QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.line(), 14); QCOMPARE(frame.object(), binary); @@ -267,7 +267,7 @@ void TestRunner::testLeak4() } { const Frame frame = stack.frames().at(1); - QCOMPARE(frame.functionName(), QString("Foo::Foo()")); + QCOMPARE(frame.functionName(), QLatin1String("Foo::Foo()")); QCOMPARE(frame.line(), 6); QCOMPARE(frame.object(), binary); @@ -276,7 +276,7 @@ void TestRunner::testLeak4() } { const Frame frame = stack.frames().at(2); - QCOMPARE(frame.functionName(), QString("main")); + QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.line(), 14); QCOMPARE(frame.object(), binary); @@ -296,11 +296,11 @@ void TestRunner::testLeak4() QCOMPARE(stack.frames().count(), 2); { const Frame frame = stack.frames().at(0); - QCOMPARE(frame.functionName(), QString("operator new(unsigned long)")); + QCOMPARE(frame.functionName(), QLatin1String("operator new(unsigned long)")); } { const Frame frame = stack.frames().at(1); - QCOMPARE(frame.functionName(), QString("main")); + QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.line(), 14); QCOMPARE(frame.object(), binary); @@ -329,7 +329,7 @@ void TestRunner::uninit1() QCOMPARE(stack.frames().count(), 1); const Frame frame = stack.frames().first(); - QCOMPARE(frame.functionName(), QString("main")); + QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.line(), 4); QCOMPARE(frame.object(), binary); @@ -343,7 +343,7 @@ void TestRunner::uninit1() QCOMPARE(stack.frames().count(), 1); const Frame frame = stack.frames().first(); - QCOMPARE(frame.functionName(), QString("main")); + QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.line(), 2); QCOMPARE(frame.object(), binary); @@ -374,7 +374,7 @@ void TestRunner::uninit2() QCOMPARE(stack.frames().count(), 1); const Frame frame = stack.frames().first(); - QCOMPARE(frame.functionName(), QString("main")); + QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.line(), 4); QCOMPARE(frame.object(), binary); @@ -388,7 +388,7 @@ void TestRunner::uninit2() QCOMPARE(stack.frames().count(), 1); const Frame frame = stack.frames().first(); - QCOMPARE(frame.functionName(), QString("main")); + QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.line(), 2); QCOMPARE(frame.object(), binary); @@ -407,7 +407,7 @@ void TestRunner::uninit2() QCOMPARE(stack.frames().count(), 1); const Frame frame = stack.frames().first(); - QCOMPARE(frame.functionName(), QString("main")); + QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.line(), 4); QCOMPARE(frame.object(), binary); @@ -438,7 +438,7 @@ void TestRunner::uninit3() QCOMPARE(stack.frames().count(), 1); const Frame frame = stack.frames().first(); - QCOMPARE(frame.functionName(), QString("main")); + QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.line(), 4); QCOMPARE(frame.object(), binary); @@ -452,7 +452,7 @@ void TestRunner::uninit3() QCOMPARE(stack.frames().count(), 1); const Frame frame = stack.frames().first(); - QCOMPARE(frame.functionName(), QString("main")); + QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.line(), 2); QCOMPARE(frame.object(), binary); @@ -471,7 +471,7 @@ void TestRunner::uninit3() QCOMPARE(stack.frames().count(), 1); const Frame frame = stack.frames().first(); - QCOMPARE(frame.functionName(), QString("main")); + QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.line(), 4); QCOMPARE(frame.object(), binary); @@ -501,15 +501,15 @@ void TestRunner::syscall() { ///TODO: is this platform specific? const Frame frame = stack.frames().at(0); - QCOMPARE(frame.functionName(), QString("_Exit")); + QCOMPARE(frame.functionName(), QLatin1String("_Exit")); } { const Frame frame = stack.frames().at(1); - QCOMPARE(frame.functionName(), QString("exit")); + QCOMPARE(frame.functionName(), QLatin1String("exit")); } { const Frame frame = stack.frames().at(2); - QCOMPARE(frame.functionName(), QString("(below main)")); + QCOMPARE(frame.functionName(), QLatin1String("(below main)")); } } //BEGIN second stack @@ -519,7 +519,7 @@ void TestRunner::syscall() QCOMPARE(stack.frames().count(), 1); const Frame frame = stack.frames().first(); - QCOMPARE(frame.functionName(), QString("main")); + QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.line(), 2); QCOMPARE(frame.object(), binary); @@ -548,11 +548,11 @@ void TestRunner::free1() { const Frame frame = stack.frames().first(); - QCOMPARE(frame.functionName(), QString("operator delete(void*)")); + QCOMPARE(frame.functionName(), QLatin1String("operator delete(void*)")); } { const Frame frame = stack.frames().last(); - QCOMPARE(frame.functionName(), QString("main")); + QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.line(), 7); QCOMPARE(frame.object(), binary); @@ -569,11 +569,11 @@ void TestRunner::free1() { const Frame frame = stack.frames().first(); - QCOMPARE(frame.functionName(), QString("operator delete(void*)")); + QCOMPARE(frame.functionName(), QLatin1String("operator delete(void*)")); } { const Frame frame = stack.frames().last(); - QCOMPARE(frame.functionName(), QString("main")); + QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.line(), 6); QCOMPARE(frame.object(), binary); @@ -603,11 +603,11 @@ void TestRunner::free2() { const Frame frame = stack.frames().first(); - QCOMPARE(frame.functionName(), QString("free")); + QCOMPARE(frame.functionName(), QLatin1String("free")); } { const Frame frame = stack.frames().last(); - QCOMPARE(frame.functionName(), QString("main")); + QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.line(), 6); QCOMPARE(frame.object(), binary); @@ -624,11 +624,11 @@ void TestRunner::free2() { const Frame frame = stack.frames().first(); - QCOMPARE(frame.functionName(), QString("operator new(unsigned long)")); + QCOMPARE(frame.functionName(), QLatin1String("operator new(unsigned long)")); } { const Frame frame = stack.frames().last(); - QCOMPARE(frame.functionName(), QString("main")); + QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.line(), 5); QCOMPARE(frame.object(), binary); @@ -661,7 +661,7 @@ void TestRunner::invalidjump() } { const Frame frame = stack.frames().at(1); - QCOMPARE(frame.functionName(), QString("(below main)")); + QCOMPARE(frame.functionName(), QLatin1String("(below main)")); } } @@ -684,11 +684,11 @@ void TestRunner::overlap() QCOMPARE(stack.frames().count(), 2); { const Frame frame = stack.frames().at(0); - QCOMPARE(frame.functionName(), QString("memcpy")); + QCOMPARE(frame.functionName(), QLatin1String("memcpy")); } { const Frame frame = stack.frames().last(); - QCOMPARE(frame.functionName(), QString("main")); + QCOMPARE(frame.functionName(), QLatin1String("main")); QCOMPARE(frame.line(), 6); QCOMPARE(frame.object(), binary); diff --git a/tests/valgrind/memcheck/testrunner.pro b/tests/valgrind/memcheck/testrunner.pro index 53035bbac7..fea9eebd00 100644 --- a/tests/valgrind/memcheck/testrunner.pro +++ b/tests/valgrind/memcheck/testrunner.pro @@ -1,6 +1,7 @@ include(../../auto/qttest.pri) include($$IDE_SOURCE_TREE/src/libs/utils/utils.pri) include($$IDE_SOURCE_TREE/src/libs/3rdparty/botan/botan.pri) +include($$IDE_SOURCE_TREE/src/libs/ssh/ssh.pri) include($$IDE_SOURCE_TREE/src/plugins/valgrind/valgrind_test.pri) TARGET = testrunner |