Commit 0502bb3c authored by Christian Stenger's avatar Christian Stenger Committed by Niels Weber
Browse files

Move functions to utils class



Change-Id: I8fd3d32b22976a11fd5bc5e3282e2cde0c409349
Reviewed-by: default avatarNiels Weber <niels.weber@theqtcompany.com>
parent 54d75357
......@@ -22,18 +22,34 @@
#include <QStringList>
namespace AutoTest {
namespace Autotest {
namespace Internal {
static bool isGTestMacro(const QString &macro)
class TestUtils
{
static QStringList valid = {
QStringLiteral("TEST"), QStringLiteral("TEST_F"), QStringLiteral("TEST_P")
};
return valid.contains(macro);
}
public:
static bool isGTestMacro(const QString &macro)
{
static QStringList valid = {
QStringLiteral("TEST"), QStringLiteral("TEST_F"), QStringLiteral("TEST_P")
};
return valid.contains(macro);
}
static bool isQTestMacro(const QByteArray &macro)
{
static QByteArrayList valid = {"QTEST_MAIN", "QTEST_APPLESS_MAIN", "QTEST_GUILESS_MAIN"};
return valid.contains(macro);
}
static bool isQuickTestMacro(const QByteArray &macro)
{
static const QByteArrayList valid = {"QUICK_TEST_MAIN", "QUICK_TEST_OPENGL_MAIN"};
return valid.contains(macro);
}
};
} // namespace Internal
} // namespace AutoTest
} // namespace Autotest
#endif // AUTOTEST_UTILS_H
......@@ -277,14 +277,13 @@ static QString quickTestSrcDir(const CppTools::CppModelManager *cppMM,
static QString testClass(const CppTools::CppModelManager *modelManager,
CPlusPlus::Document::Ptr &document)
{
static const QByteArray qtTestMacros[] = {"QTEST_MAIN", "QTEST_APPLESS_MAIN", "QTEST_GUILESS_MAIN"};
const QList<CPlusPlus::Document::MacroUse> macros = document->macroUses();
foreach (const CPlusPlus::Document::MacroUse &macro, macros) {
if (!macro.isFunctionLike())
continue;
const QByteArray name = macro.macro().name();
if (name == qtTestMacros[0] || name == qtTestMacros[1] || name == qtTestMacros[2]) {
if (TestUtils::isQTestMacro(name)) {
const CPlusPlus::Document::Block arg = macro.arguments().at(0);
return QLatin1String(getFileContent(document->fileName())
.mid(arg.bytesBegin(), arg.bytesEnd() - arg.bytesBegin()));
......@@ -303,14 +302,13 @@ static QString testClass(const CppTools::CppModelManager *modelManager,
static QString quickTestName(const CPlusPlus::Document::Ptr &doc)
{
static const QByteArray qtTestMacros[] = {"QUICK_TEST_MAIN", "QUICK_TEST_OPENGL_MAIN"};
const QList<CPlusPlus::Document::MacroUse> macros = doc->macroUses();
foreach (const CPlusPlus::Document::MacroUse &macro, macros) {
if (!macro.isFunctionLike())
continue;
const QByteArray name = macro.macro().name();
if (name == qtTestMacros[0] || name == qtTestMacros[1] || name == qtTestMacros[2]) {
if (TestUtils::isQuickTestMacro(name)) {
CPlusPlus::Document::Block arg = macro.arguments().at(0);
return QLatin1String(getFileContent(doc->fileName())
.mid(arg.bytesBegin(), arg.bytesEnd() - arg.bytesBegin()));
......@@ -325,7 +323,7 @@ static QSet<QString> testNames(CPlusPlus::Document::Ptr &document)
foreach (const CPlusPlus::Document::MacroUse &macro, document->macroUses()) {
if (!macro.isFunctionLike())
continue;
if (AutoTest::Internal::isGTestMacro(QLatin1String(macro.macro().name()))) {
if (TestUtils::isGTestMacro(QLatin1String(macro.macro().name()))) {
const QVector<CPlusPlus::Document::Block> args = macro.arguments();
if (args.size() != 2)
continue;
......
......@@ -359,7 +359,7 @@ bool GTestVisitor::visit(CPlusPlus::FunctionDefinitionAST *ast)
CPlusPlus::LookupContext lc;
const QString prettyName = m_overview.prettyName(lc.fullyQualifiedName(ast->symbol));
if (!AutoTest::Internal::isGTestMacro(prettyName))
if (!TestUtils::isGTestMacro(prettyName))
return false;
CPlusPlus::Argument *testCaseNameArg = ast->symbol->argumentAt(0)->asArgument();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment