tests/benchmarks/uimodels/GraphicsViewBenchmark/widgets/commandline.cpp
changeset 3 41300fa6a67c
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     5 **
       
     6 ** This file is part of the examples of the Qt Toolkit.
       
     7 **
       
     8 ** $QT_BEGIN_LICENSE:LGPL$
       
     9 ** No Commercial Usage
       
    10 ** This file contains pre-release code and may not be distributed.
       
    11 ** You may use this file in accordance with the terms and conditions
       
    12 ** contained in the either Technology Preview License Agreement or the
       
    13 ** Beta Release License Agreement.
       
    14 **
       
    15 ** GNU Lesser General Public License Usage
       
    16 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    17 ** General Public License version 2.1 as published by the Free Software
       
    18 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    19 ** packaging of this file.  Please review the following information to
       
    20 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    22 **
       
    23 ** In addition, as a special exception, Nokia gives you certain
       
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
       
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
       
    26 ** package.
       
    27 **
       
    28 ** GNU General Public License Usage
       
    29 ** Alternatively, this file may be used under the terms of the GNU
       
    30 ** General Public License version 3.0 as published by the Free Software
       
    31 ** Foundation and appearing in the file LICENSE.GPL included in the
       
    32 ** packaging of this file.  Please review the following information to
       
    33 ** ensure the GNU General Public License version 3.0 requirements will be
       
    34 ** met: http://www.gnu.org/copyleft/gpl.html.
       
    35 **
       
    36 ** If you are unsure which license is appropriate for your use, please
       
    37 ** contact the sales department at http://qt.nokia.com/contact.
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include <QStringList>
       
    43 #include <QDebug>
       
    44 
       
    45 #include "commandline.h"
       
    46 
       
    47 static void usage(const char *appname)
       
    48 {
       
    49     printf("%s [options]\n", appname);
       
    50     printf("Options:\n");
       
    51     printf("\t -h,-help       : This help\n");
       
    52 #ifdef AUTO_TESTS
       
    53     printf("\t -o file        : Write output to file\n");
       
    54     printf("\t -xml           : Outputs results as XML document\n");
       
    55     printf("\t -lightxml      : Outputs results as stream of XML tags\n");
       
    56     printf("\t -script-name file  : Use this script instead of internal script file\n");
       
    57 #endif
       
    58     printf("\t -resolution    : UI resolution in format WxH where width and height are positive values\n");
       
    59     printf("\t -rotation      : UI rotation in degrees\n");
       
    60     printf("\t -subtree-cache : Enables usage of subtree caching method\n");
       
    61     printf("\t -noresusage : Disables CPU and Memory usage measurement\n");
       
    62 #ifndef  AUTO_TESTS
       
    63     printf("\t -fps           : Output FPS count to stdout during application execution\n");    
       
    64     printf("\t -items         : Count of items created to the list\n");
       
    65 #endif
       
    66 #if ENABLE_OPENGL
       
    67 #ifndef QT_NO_OPENGL
       
    68     printf("\t -opengl        : Enables OpenGL usage. Building PRECONDITIONS: ENABLE_OPENGL is on. QT_NO_OPENGL is off.\n");
       
    69 #endif
       
    70 #endif
       
    71     printf("\n");
       
    72 }
       
    73 
       
    74 bool readSettingsFromCommandLine(int argc, char *argv[],
       
    75                   Settings& config)
       
    76 {
       
    77     bool builtWithOpenGL = false;
       
    78     Settings::Options options;
       
    79 
       
    80 #if ENABLE_OPENGL 
       
    81 #ifndef QT_NO_OPENGL
       
    82     builtWithOpenGL = true;
       
    83 #endif
       
    84 #endif
       
    85     for (int i=0; i<argc; ++i) {
       
    86         if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "-help") == 0) {
       
    87             usage(argv[0]);
       
    88             return false;
       
    89         }
       
    90 #ifdef AUTO_TESTS
       
    91         if (strcmp(argv[i], "-o") == 0) {
       
    92             if (i + 1 >= argc) {
       
    93                 printf("-o needs an extra parameter specifying the filename\n");
       
    94                 usage(argv[0]);
       
    95                 return false;
       
    96             } else {
       
    97                 config.setOutputFileName(QString(argv[i+1]));
       
    98                 i++;
       
    99             }
       
   100         }
       
   101         if (strcmp(argv[i], "-xml") == 0) {
       
   102             config.setResultFormat(1);  // See FileLogger::ResultFormat
       
   103         }
       
   104         if (strcmp(argv[i], "-lightxml") == 0) {
       
   105             config.setResultFormat(2);  // See FileLogger::ResultFormat
       
   106         }
       
   107         if (strcmp(argv[i], "-script-name") == 0) {
       
   108             if (i + 1 >= argc) {
       
   109                 printf("-script-name  needs an extra parameter specifying the filename\n");
       
   110                 usage(argv[0]);
       
   111                 return false;
       
   112             } else {
       
   113                 config.setScriptName(QString(argv[i+1]));
       
   114                 i++;
       
   115             }
       
   116         }
       
   117 #endif
       
   118         if (strcmp(argv[i], "-resolution") == 0) {
       
   119             if (i + 1 >= argc) {
       
   120                 printf("-resolution needs an extra parameter specifying the application UI resolution\n");
       
   121                 usage(argv[0]);
       
   122                 return false;
       
   123             }
       
   124             else {
       
   125                 QStringList res = QString(argv[i+1]).split("x");
       
   126                 if (res.count() != 2) {
       
   127                     printf("-resolution parameter UI resolution should be set in format WxH where width and height are positive values\n");
       
   128                     usage(argv[0]);
       
   129                     return false;
       
   130                 }
       
   131                 int width = res.at(0).toInt();
       
   132                 int height = res.at(1).toInt();
       
   133 
       
   134                 config.setSize(QSize(width, height));
       
   135 
       
   136                 if (width <=0 || height <=0) {
       
   137                     printf("-resolution parameter UI resolution should be set in format WxH where width and height are positive values\n");
       
   138                     usage(argv[0]);
       
   139                     return false;
       
   140                 }
       
   141                 i++;
       
   142             }        
       
   143         }
       
   144         if (strcmp(argv[i], "-rotation") == 0) {
       
   145             if (i + 1 >= argc) {
       
   146                 printf("-rotation needs an extra parameter specifying the application UI rotation in degrees\n");
       
   147                 usage(argv[0]);
       
   148                 return false;
       
   149             }
       
   150             else {
       
   151                 bool ok;
       
   152                 int angle = QString(argv[i+1]).toInt(&ok);
       
   153                 if (!ok) {
       
   154                     printf("-rotation parameter should specify rotation angle in degrees\n");
       
   155                     usage(argv[0]);
       
   156                     return false;
       
   157                 }
       
   158                 config.setAngle(angle);
       
   159                 i++;
       
   160             }        
       
   161         }
       
   162         if (strcmp(argv[i], "-subtree-cache") == 0) {
       
   163             options |= Settings::UseListItemCache;
       
   164         }
       
   165         if (strcmp(argv[i], "-opengl") == 0) {
       
   166             if (builtWithOpenGL)
       
   167                 options |= Settings::UseOpenGL;
       
   168             else {
       
   169                 printf("-opengl parameter can be used only with building PRECONDITIONS: ENABLE_OPENGL is on. QT_NO_OPENGL is off.\n");
       
   170                 usage(argv[0]);
       
   171                 return false;
       
   172             }
       
   173         }
       
   174         if (strcmp(argv[i], "-noresusage") == 0) {
       
   175              options |= Settings::NoResourceUsage;
       
   176         }
       
   177 #ifndef AUTO_TESTS
       
   178         if (strcmp(argv[i], "-fps") == 0) {
       
   179              options |= Settings::OutputFps;
       
   180         }
       
   181         if (strcmp(argv[i], "-items") == 0) {
       
   182             if (i + 1 >= argc) {
       
   183                 printf("-items needs an extra parameter specifying amount of list items\n");
       
   184                 usage(argv[0]);
       
   185                 return false;
       
   186             }
       
   187             else {
       
   188                 bool ok;
       
   189                 int amount = QString(argv[i+1]).toInt(&ok);
       
   190                 if (!ok) {
       
   191                     printf("-items needs an extra parameter specifying amount (integer) of list items\n");
       
   192                     usage(argv[0]);
       
   193                     return false;
       
   194                 }
       
   195                 config.setListItemCount(amount);
       
   196                 i++;
       
   197             }
       
   198         }
       
   199 #endif
       
   200     }
       
   201 
       
   202     config.setOptions(options);
       
   203 
       
   204     return true;
       
   205 }
       
   206