camerauis/cameraxui/cxengine/tsrc/unit/cxeunitrunner/cxetestrunner.cpp
changeset 19 d9aefe59d544
child 24 2094593137f5
equal deleted inserted replaced
3:8b2d6d0384b0 19:d9aefe59d544
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 #include <QCoreApplication>
       
    18 #include <QProcess>
       
    19 #include <QThread>
       
    20 #include <QDebug>
       
    21 #include <QDir>
       
    22 #include <QTime>
       
    23 #include <QFile>
       
    24 
       
    25 #include "cxetestrunner.h"
       
    26 
       
    27 CxeTestRunner::CxeTestRunner()
       
    28 {
       
    29 }
       
    30 
       
    31 CxeTestRunner::~CxeTestRunner()
       
    32 {
       
    33 }
       
    34 
       
    35 void CxeTestRunner::runTests()
       
    36 {
       
    37 #ifdef __WINSCW__
       
    38     QString logFileFolder("c:\\data\\cxtests\\"); // Must end in backslash
       
    39 #else
       
    40     QString logFileFolder("e:\\cxtests\\"); // Must end in backslash
       
    41 #endif
       
    42 
       
    43     QStringList tests;
       
    44     tests << "unittest_cxevideocapturecontrolsymbian"
       
    45           << "unittest_cxestillimagesymbian"
       
    46           << "unittest_cxequalitypresetssymbian"
       
    47           << "unittest_cxecameradevicecontrolsymbian"
       
    48           << "unittest_cxestatemachine"
       
    49           << "unittest_cxestate"
       
    50           << "unittest_cxefilenamegeneratorsymbian"
       
    51           << "unittest_cxeautofocuscontrolsymbian"
       
    52           << "unittest_cxeviewfindercontrolsymbian"
       
    53           << "unittest_cxetestutils"
       
    54           << "unittest_cxesettmappersymbian"
       
    55           << "unittest_cxecameradevice"
       
    56           << "unittest_cxeimagedataitemsymbian"
       
    57           << "unittest_cxeimagedataqueuesymbian"
       
    58           << "unittest_cxeerrormappersymbian"
       
    59           << "unittest_cxesettingsmodelimp"
       
    60           << "unittest_cxefilesavethreadsymbian"
       
    61           << "unittest_cxesettingscenrepstore"
       
    62           << "unittest_cxezoomcontrolsymbian"
       
    63           << "unittest_cxestillcapturecontrolsymbian"
       
    64           << "unittest_cxefeaturemanagerimp"
       
    65           << "unittest_cxeenginesymbian"
       
    66           << "unittest_cxesettingsimp"
       
    67           << "unittest_cxethumbnailmanagersymbian"
       
    68           << "unittest_cxeharvestercontrolsymbian"
       
    69           << "unittest_cxesettingscontrolsymbian";
       
    70 
       
    71     QDir dir;
       
    72     dir.mkpath(logFileFolder);
       
    73 
       
    74     // Delete old log files
       
    75     foreach(const QString &test, tests) {
       
    76         dir.remove(logFileFolder + test + ".log");
       
    77     }
       
    78     dir.remove(logFileFolder + "results.txt");
       
    79 
       
    80     // Run all tests sequentially
       
    81     foreach(const QString &test, tests) {
       
    82         QProcess p;
       
    83         QString command = test + ".exe";
       
    84         QStringList args;
       
    85         args << "-o" << (logFileFolder + test + ".log");
       
    86         qDebug() << "***** Launching" << command << "*****";
       
    87         p.start(command, args, QProcess::ReadOnly);
       
    88 
       
    89         p.waitForStarted();
       
    90         qDebug() << "***** started *****";
       
    91         QThread::yieldCurrentThread();
       
    92         QCoreApplication::processEvents();
       
    93         p.waitForFinished();
       
    94         qDebug() << "*****" << command << "completed, exit code" << p.exitCode() << "*****";
       
    95 
       
    96         parseLogFile(logFileFolder + test + ".log");
       
    97     }
       
    98 
       
    99     QFile results(logFileFolder + "results.txt");
       
   100     if (results.open(QIODevice::WriteOnly | QIODevice::Text)) {
       
   101         foreach(const QByteArray &line, mResults) {
       
   102             results.write(line);
       
   103             results.write("\n");
       
   104         }
       
   105     } else {
       
   106         qWarning() << "Cannot write results!";
       
   107     }
       
   108 
       
   109     QCoreApplication::quit();
       
   110 }
       
   111 
       
   112 void CxeTestRunner::parseLogFile(const QString& filename)
       
   113 {
       
   114     QFile log(filename);
       
   115 
       
   116     if (!log.open(QIODevice::ReadOnly | QIODevice::Text)) {
       
   117         qWarning() << "Cannot open log file" << filename << "for reading!";
       
   118         return;
       
   119     }
       
   120 
       
   121     mResults.append(filename.toAscii());
       
   122 
       
   123     while (!log.atEnd()) {
       
   124         QByteArray line = log.readLine();
       
   125         if (line.startsWith("Totals:") ||
       
   126             line.startsWith("FAIL!")) {
       
   127             line = line.replace("\n", "");
       
   128             mResults.append("    " + line);
       
   129         }
       
   130     }
       
   131 
       
   132     mResults.append(""); // add empty line to output
       
   133 }