tests/auto/linguist/lupdate/tst_lupdate.cpp
branchRCL_3
changeset 5 d3bac044e0f0
parent 4 3b1da2848fc7
equal deleted inserted replaced
4:3b1da2848fc7 5:d3bac044e0f0
    57     tst_lupdate();
    57     tst_lupdate();
    58 
    58 
    59 private slots:
    59 private slots:
    60     void good_data();
    60     void good_data();
    61     void good();
    61     void good();
    62     void commandline_data();
       
    63     void commandline();
       
    64 #if CHECK_SIMTEXTH
    62 #if CHECK_SIMTEXTH
    65     void simtexth();
    63     void simtexth();
    66     void simtexth_data();
    64     void simtexth_data();
    67 #endif
    65 #endif
    68 
    66 
   243 
   241 
   244     QString dir = m_basePath + "good/" + directory;
   242     QString dir = m_basePath + "good/" + directory;
   245 
   243 
   246     qDebug() << "Checking...";
   244     qDebug() << "Checking...";
   247 
   245 
   248     QString generatedtsfile(dir + QLatin1String("/project.ts"));
   246     QString workDir = dir;
   249 
   247     QStringList generatedtsfiles(QLatin1String("project.ts"));
   250     // look for a command
       
   251     QString lupdatecmd;
   248     QString lupdatecmd;
       
   249 
   252     QFile file(dir + "/lupdatecmd");
   250     QFile file(dir + "/lupdatecmd");
   253     if (file.exists()) {
   251     if (file.exists()) {
   254         QVERIFY2(file.open(QIODevice::ReadOnly | QIODevice::Text), qPrintable(file.fileName()));
   252         QVERIFY2(file.open(QIODevice::ReadOnly | QIODevice::Text), qPrintable(file.fileName()));
   255         while (!file.atEnd()) {
   253         while (!file.atEnd()) {
   256             QByteArray cmdstring = file.readLine().simplified();
   254             QByteArray cmdstring = file.readLine().simplified();
   260                 cmdstring.remove(0, 8);
   258                 cmdstring.remove(0, 8);
   261                 lupdatecmd.append(cmdstring);
   259                 lupdatecmd.append(cmdstring);
   262                 break;
   260                 break;
   263             } else if (cmdstring.startsWith("TRANSLATION:")) {
   261             } else if (cmdstring.startsWith("TRANSLATION:")) {
   264                 cmdstring.remove(0, 12);
   262                 cmdstring.remove(0, 12);
   265                 generatedtsfile = dir + QLatin1Char('/') + cmdstring.trimmed();
   263                 generatedtsfiles.clear();
       
   264                 foreach (const QByteArray &s, cmdstring.split(' '))
       
   265                     if (!s.isEmpty())
       
   266                         generatedtsfiles << s;
       
   267             } else if (cmdstring.startsWith("cd ")) {
       
   268                 cmdstring.remove(0, 3);
       
   269                 workDir = QDir::cleanPath(dir + QLatin1Char('/') + cmdstring);
   266             }
   270             }
   267         }
   271         }
   268         file.close();
   272         file.close();
   269     }
   273     }
   270 
   274 
   271     QFile::remove(generatedtsfile);
   275     foreach (const QString &ts, generatedtsfiles) {
   272     QString beforetsfile = generatedtsfile + QLatin1String(".before");
   276         QString genTs = workDir + QLatin1Char('/') + ts;
   273     if (QFile::exists(beforetsfile))
   277         QFile::remove(genTs);
   274         QVERIFY2(QFile::copy(beforetsfile, generatedtsfile), qPrintable(beforetsfile));
   278         QString beforetsfile = dir + QLatin1Char('/') + ts + QLatin1String(".before");
       
   279         if (QFile::exists(beforetsfile))
       
   280             QVERIFY2(QFile::copy(beforetsfile, genTs), qPrintable(beforetsfile));
       
   281     }
   275 
   282 
   276     if (lupdatecmd.isEmpty())
   283     if (lupdatecmd.isEmpty())
   277         lupdatecmd = QLatin1String("project.pro");
   284         lupdatecmd = QLatin1String("project.pro");
   278     lupdatecmd.prepend("-silent ");
   285     lupdatecmd.prepend("-silent ");
   279 
   286 
   280     QProcess proc;
   287     QProcess proc;
   281     proc.setWorkingDirectory(dir);
   288     proc.setWorkingDirectory(workDir);
   282     proc.setProcessChannelMode(QProcess::MergedChannels);
   289     proc.setProcessChannelMode(QProcess::MergedChannels);
   283     proc.start(m_cmdLupdate + ' ' + lupdatecmd, QIODevice::ReadWrite | QIODevice::Text);
   290     proc.start(m_cmdLupdate + ' ' + lupdatecmd, QIODevice::ReadWrite | QIODevice::Text);
   284     QVERIFY2(proc.waitForFinished(5000), qPrintable(lupdatecmd));
   291     QVERIFY2(proc.waitForFinished(5000), qPrintable(lupdatecmd));
   285     QByteArray output = proc.readAll();
   292     QByteArray output = proc.readAll();
   286     QVERIFY2(proc.exitStatus() == QProcess::NormalExit,
   293     QVERIFY2(proc.exitStatus() == QProcess::NormalExit,
   287              "\"lupdate " + lupdatecmd.toLatin1() + "\" crashed\n" + output);
   294              "\"lupdate " + lupdatecmd.toLatin1() + "\" crashed\n" + output);
   288     QVERIFY2(!proc.exitCode(),
   295     QVERIFY2(!proc.exitCode(),
   289              "\"lupdate " + lupdatecmd.toLatin1() + "\" exited with code " +
   296              "\"lupdate " + lupdatecmd.toLatin1() + "\" exited with code " +
   290              QByteArray::number(proc.exitCode()) + "\n" + proc.readAll());
   297              QByteArray::number(proc.exitCode()) + "\n" + output);
   291 
   298 
   292     // If the file expectedoutput.txt exists, compare the
   299     // If the file expectedoutput.txt exists, compare the
   293     // console output with the content of that file
   300     // console output with the content of that file
   294     QFile outfile(dir + "/expectedoutput.txt");
   301     QFile outfile(dir + "/expectedoutput.txt");
   295     if (outfile.exists()) {
   302     if (outfile.exists()) {
   297         doCompare(errslist, outfile.fileName(), true);
   304         doCompare(errslist, outfile.fileName(), true);
   298         if (QTest::currentTestFailed())
   305         if (QTest::currentTestFailed())
   299             return;
   306             return;
   300     }
   307     }
   301 
   308 
   302     QString expectedFile = generatedtsfile + QLatin1String(".result");
   309     foreach (const QString &ts, generatedtsfiles)
   303     doCompare(generatedtsfile, expectedFile, false);
   310         doCompare(workDir + QLatin1Char('/') + ts,
   304 }
   311                   dir + QLatin1Char('/') + ts + QLatin1String(".result"), false);
   305 
       
   306 void tst_lupdate::commandline_data()
       
   307 {
       
   308     QTest::addColumn<QString>("currentPath");
       
   309     QTest::addColumn<QString>("commandline");
       
   310     QTest::addColumn<QString>("generatedtsfile");
       
   311     QTest::addColumn<QString>("expectedtsfile");
       
   312 
       
   313     QTest::newRow("Recursive scan") << QString("recursivescan")
       
   314        << QString(". -ts foo.ts") << QString("foo.ts") << QString("foo.ts.result");
       
   315     QTest::newRow("Deep path argument") << QString("recursivescan")
       
   316        << QString("sub/finddialog.cpp -ts bar.ts") << QString("bar.ts") << QString("bar.ts.result");
       
   317 }
       
   318 
       
   319 void tst_lupdate::commandline()
       
   320 {
       
   321     QFETCH(QString, currentPath);
       
   322     QFETCH(QString, commandline);
       
   323     QFETCH(QString, generatedtsfile);
       
   324     QFETCH(QString, expectedtsfile);
       
   325 
       
   326     QString generated =
       
   327         m_basePath + currentPath + QLatin1Char('/') + generatedtsfile;
       
   328     QFile gen(generated);
       
   329     if (gen.exists())
       
   330         QVERIFY(gen.remove());
       
   331     QProcess proc;
       
   332     proc.setWorkingDirectory(m_basePath + currentPath);
       
   333     proc.setProcessChannelMode(QProcess::MergedChannels);
       
   334     proc.start(m_cmdLupdate + " -silent " + commandline, QIODevice::ReadWrite | QIODevice::Text);
       
   335     QVERIFY2(proc.waitForFinished(5000), qPrintable(commandline));
       
   336     QVERIFY2(proc.exitStatus() == QProcess::NormalExit,
       
   337              "\"lupdate -silent " + commandline.toLatin1() + "\" crashed\n" + proc.readAll());
       
   338     QVERIFY2(!proc.exitCode(),
       
   339              "\"lupdate -silent " + commandline.toLatin1() + "\" exited with code " +
       
   340              QByteArray::number(proc.exitCode()) + "\n" + proc.readAll());
       
   341 
       
   342     doCompare(generated, m_basePath + currentPath + QLatin1Char('/') + expectedtsfile, false);
       
   343 }
   312 }
   344 
   313 
   345 #if CHECK_SIMTEXTH
   314 #if CHECK_SIMTEXTH
   346 void tst_lupdate::simtexth()
   315 void tst_lupdate::simtexth()
   347 {
   316 {