camerauis/cameraxui/cxengine/tsrc/unit/cxeunitrunner/cxetestrunner.cpp
branchRCL_3
changeset 24 bac7acad7cb3
parent 23 61bc0f252b2b
child 25 2c87b2808fd7
equal deleted inserted replaced
23:61bc0f252b2b 24:bac7acad7cb3
     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 
       
    45     tests << "unittest_cxevideocapturecontrolsymbian"
       
    46           << "unittest_cxestillimagesymbian"
       
    47           << "unittest_cxequalitypresetssymbian"
       
    48           << "unittest_cxecameradevicecontrolsymbian"
       
    49           << "unittest_cxestatemachine"
       
    50           << "unittest_cxestate"
       
    51           << "unittest_cxefilenamegeneratorsymbian"
       
    52           << "unittest_cxeautofocuscontrolsymbian"
       
    53           << "unittest_cxeviewfindercontrolsymbian"
       
    54           << "unittest_cxetestutils"
       
    55           << "unittest_cxesettmappersymbian"
       
    56           << "unittest_cxecameradevice"
       
    57           << "unittest_cxeimagedataitemsymbian"
       
    58           << "unittest_cxeimagedataqueuesymbian"
       
    59           << "unittest_cxeerrormappersymbian"
       
    60           << "unittest_cxefilesavethreadsymbian"
       
    61           << "unittest_cxesettingscenrepstore"
       
    62           << "unittest_cxezoomcontrolsymbian"
       
    63           << "unittest_cxestillcapturecontrolsymbian"
       
    64           << "unittest_cxefeaturemanagerimp"
       
    65           << "unittest_cxesettingsimp"
       
    66           << "unittest_cxescenemodestore"
       
    67           << "unittest_cxethumbnailmanagersymbian"
       
    68           << "unittest_cxeharvestercontrolsymbian"
       
    69           << "unittest_cxesettingscontrolsymbian"
       
    70           << "unittest_cxesnapshotcontrol"
       
    71           << "unittest_cxeenginesymbian"
       
    72           << "unittest_cxegeotaggingtrail"
       
    73           << "unittest_cxememorymonitor"
       
    74           << "unittest_cxediskmonitor";
       
    75 
       
    76     QDir dir;
       
    77     dir.mkpath(logFileFolder);
       
    78 
       
    79     // Delete old log files
       
    80     foreach(const QString &test, tests) {
       
    81         dir.remove(logFileFolder + test + ".log");
       
    82     }
       
    83     dir.remove(logFileFolder + "results.txt");
       
    84 
       
    85     // Run all tests sequentially
       
    86     foreach(const QString &test, tests) {
       
    87         QProcess p;
       
    88         QString command = test + ".exe";
       
    89         QStringList args;
       
    90         args << "-o" << (logFileFolder + test + ".log");
       
    91         qDebug() << "***** Launching" << command << "*****";
       
    92         p.start(command, args, QProcess::ReadOnly);
       
    93 
       
    94         p.waitForStarted();
       
    95         qDebug() << "***** started *****";
       
    96         QThread::yieldCurrentThread();
       
    97         QCoreApplication::processEvents();
       
    98         p.waitForFinished();
       
    99         qDebug() << "*****" << command << "completed, exit code" << p.exitCode() << "*****";
       
   100 
       
   101         parseLogFile(logFileFolder + test + ".log");
       
   102     }
       
   103 
       
   104     QFile results(logFileFolder + "results.txt");
       
   105     if (results.open(QIODevice::WriteOnly | QIODevice::Text)) {
       
   106         foreach(const QByteArray &line, mResults) {
       
   107             results.write(line);
       
   108             results.write("\n");
       
   109         }
       
   110     } else {
       
   111         qWarning() << "Cannot write results!";
       
   112     }
       
   113 
       
   114     QCoreApplication::quit();
       
   115 }
       
   116 
       
   117 void CxeTestRunner::parseLogFile(const QString& filename)
       
   118 {
       
   119     QFile log(filename);
       
   120 
       
   121     if (!log.open(QIODevice::ReadOnly | QIODevice::Text)) {
       
   122         qWarning() << "Cannot open log file" << filename << "for reading!";
       
   123         return;
       
   124     }
       
   125 
       
   126     mResults.append(filename.toAscii());
       
   127 
       
   128     while (!log.atEnd()) {
       
   129         QByteArray line = log.readLine();
       
   130         if (line.startsWith("Totals:") ||
       
   131             line.startsWith("FAIL!")) {
       
   132             line = line.replace("\n", "");
       
   133             mResults.append("    " + line);
       
   134         }
       
   135     }
       
   136 
       
   137     mResults.append(""); // add empty line to output
       
   138 }