#include <QtTest>
#include <QtDebug>
#include <QTextDocument>
+#include <QDir>
//TESTED_COMPONENT=src/libs/cplusplus
private:
ExtensionSystem::PluginManager *pluginManager;
+ QString tempPath;
};
void tst_Codegen::initTestCase()
pluginManager->setFileExtension(QLatin1String("pluginspec"));
pluginManager->setPluginPaths(QStringList() << QLatin1String(Q_PLUGIN_PATH));
pluginManager->loadPlugins();
+
+ tempPath = QDir::tempPath();
}
void tst_Codegen::cleanupTestCase()
"int x;\n" // line 1
"\n";
- Document::Ptr src = Document::create(QLatin1String("/tmp/file.h"));
+ Document::Ptr src = Document::create(tempPath + QLatin1String("/file.h"));
Utils::FileSaver srcSaver(src->fileName());
srcSaver.write(srcText);
srcSaver.finalize();
QCOMPARE(src->diagnosticMessages().size(), 0);
QCOMPARE(src->globalSymbolCount(), 1U);
- Document::Ptr dst = Document::create(QLatin1String("/tmp/file.cpp"));
+ Document::Ptr dst = Document::create(tempPath + QLatin1String("/file.cpp"));
Utils::FileSaver dstSaver(dst->fileName());
dstSaver.write(dstText);
dstSaver.finalize();
QList<InsertionLocation> locList = find.methodDefinition(decl);
QVERIFY(locList.size() == 1);
InsertionLocation loc = locList.first();
- QCOMPARE(loc.fileName(), QLatin1String("/tmp/file.cpp"));
+ QCOMPARE(loc.fileName(), dst->fileName());
QCOMPARE(loc.prefix(), QLatin1String("\n\n"));
QCOMPARE(loc.suffix(), QString());
QCOMPARE(loc.line(), 1U);
"};\n"
"\n";
- const QByteArray dstText = "\n"
- "#include \"/tmp/file.h\"\n" // line 1
- "int x;\n"
- "\n"
- "void Foo::bar()\n" // line 4
- "{\n"
- "\n"
- "}\n"
- "\n"
- "int y;\n";
-
- Document::Ptr src = Document::create(QLatin1String("/tmp/file.h"));
+ const QByteArray dstText = QString(
+ "\n"
+ "#include \"%1/file.h\"\n" // line 1
+ "int x;\n"
+ "\n"
+ "void Foo::bar()\n" // line 4
+ "{\n"
+ "\n"
+ "}\n"
+ "\n"
+ "int y;\n").arg(tempPath).toLatin1();
+
+ Document::Ptr src = Document::create(tempPath + QLatin1String("/file.h"));
Utils::FileSaver srcSaver(src->fileName());
srcSaver.write(srcText);
srcSaver.finalize();
QCOMPARE(src->diagnosticMessages().size(), 0);
QCOMPARE(src->globalSymbolCount(), 1U);
- Document::Ptr dst = Document::create(QLatin1String("/tmp/file.cpp"));
- dst->addIncludeFile("/tmp/file.h", 1);
+ Document::Ptr dst = Document::create(tempPath + QLatin1String("/file.cpp"));
+ dst->addIncludeFile(src->fileName(), 1);
Utils::FileSaver dstSaver(dst->fileName());
dstSaver.write(dstText);
dstSaver.finalize();
QList<InsertionLocation> locList = find.methodDefinition(decl);
QVERIFY(locList.size() == 1);
InsertionLocation loc = locList.first();
- QCOMPARE(loc.fileName(), QLatin1String("/tmp/file.cpp"));
+ QCOMPARE(loc.fileName(), dst->fileName());
QCOMPARE(loc.line(), 4U);
QCOMPARE(loc.column(), 1U);
QCOMPARE(loc.suffix(), QLatin1String("\n\n"));
"};\n"
"\n";
- const QByteArray dstText = "\n"
- "#include \"/tmp/file.h\"\n" // line 1
- "int x;\n"
- "\n"
- "void Foo::foo()\n" // line 4
- "{\n"
- "\n"
- "}\n" // line 7
- "\n"
- "int y;\n";
-
- Document::Ptr src = Document::create(QLatin1String("/tmp/file.h"));
+ const QByteArray dstText = QString(
+ "\n"
+ "#include \"%1/file.h\"\n" // line 1
+ "int x;\n"
+ "\n"
+ "void Foo::foo()\n" // line 4
+ "{\n"
+ "\n"
+ "}\n" // line 7
+ "\n"
+ "int y;\n").arg(tempPath).toLatin1();
+
+ Document::Ptr src = Document::create(tempPath + QLatin1String("/file.h"));
Utils::FileSaver srcSaver(src->fileName());
srcSaver.write(srcText);
srcSaver.finalize();
QCOMPARE(src->diagnosticMessages().size(), 0);
QCOMPARE(src->globalSymbolCount(), 1U);
- Document::Ptr dst = Document::create(QLatin1String("/tmp/file.cpp"));
- dst->addIncludeFile("/tmp/file.h", 1);
+ Document::Ptr dst = Document::create(tempPath + QLatin1String("/file.cpp"));
+ dst->addIncludeFile(src->fileName(), 1);
Utils::FileSaver dstSaver(dst->fileName());
dstSaver.write(dstText);
dstSaver.finalize();
QList<InsertionLocation> locList = find.methodDefinition(decl);
QVERIFY(locList.size() == 1);
InsertionLocation loc = locList.first();
- QCOMPARE(loc.fileName(), QLatin1String("/tmp/file.cpp"));
+ QCOMPARE(loc.fileName(), dst->fileName());
QCOMPARE(loc.line(), 7U);
QCOMPARE(loc.column(), 2U);
QCOMPARE(loc.prefix(), QLatin1String("\n\n"));
"};\n"
"\n";
- const QByteArray dstText = "\n"
- "#include \"/tmp/file.h\"\n" // line 1
- "int x;\n"
- "\n"
- "void Foo::foo()\n" // line 4
- "{\n"
- "\n"
- "}\n" // line 7
- "\n"
- "void Foo::car()\n" // line 9
- "{\n"
- "\n"
- "}\n"
- "\n"
- "int y;\n";
-
- Document::Ptr src = Document::create(QLatin1String("/tmp/file.h"));
+ const QByteArray dstText = QString(
+ "\n"
+ "#include \"%1/file.h\"\n" // line 1
+ "int x;\n"
+ "\n"
+ "void Foo::foo()\n" // line 4
+ "{\n"
+ "\n"
+ "}\n" // line 7
+ "\n"
+ "void Foo::car()\n" // line 9
+ "{\n"
+ "\n"
+ "}\n"
+ "\n"
+ "int y;\n").arg(tempPath).toLatin1();
+
+ Document::Ptr src = Document::create(tempPath + QLatin1String("/file.h"));
Utils::FileSaver srcSaver(src->fileName());
srcSaver.write(srcText);
srcSaver.finalize();
QCOMPARE(src->diagnosticMessages().size(), 0);
QCOMPARE(src->globalSymbolCount(), 1U);
- Document::Ptr dst = Document::create(QLatin1String("/tmp/file.cpp"));
- dst->addIncludeFile("/tmp/file.h", 1);
+ Document::Ptr dst = Document::create(tempPath + QLatin1String("/file.cpp"));
+ dst->addIncludeFile(src->fileName(), 1);
Utils::FileSaver dstSaver(dst->fileName());
dstSaver.write(dstText);
dstSaver.finalize();
QList<InsertionLocation> locList = find.methodDefinition(decl);
QVERIFY(locList.size() == 1);
InsertionLocation loc = locList.first();
- QCOMPARE(loc.fileName(), QLatin1String("/tmp/file.cpp"));
+ QCOMPARE(loc.fileName(), dst->fileName());
QCOMPARE(loc.line(), 7U);
QCOMPARE(loc.column(), 2U);
QCOMPARE(loc.prefix(), QLatin1String("\n\n"));