// ----------------------------------------------------------------------------
void ctkAppLauncherTest1er::testSetArguments()
{
    QFETCH(bool, shouldSetArguments);
    QFETCH(QStringList, argumentsToSet);
    QFETCH(QStringList, expectedArguments);

    ctkAppLauncher appLauncher(*qApp);

    if (shouldSetArguments)
    {
        appLauncher.setArguments(argumentsToSet);
    }

    QCOMPARE(appLauncher.arguments(), expectedArguments);
}
// ----------------------------------------------------------------------------
void ctkAppLauncherTest1er::testDisplayHelp()
{
    QFETCH(bool, initialize);
    QFETCH(QString, expectedDisplayText);

    ctkAppLauncher appLauncher(*qApp);

    if (initialize)
    {
        QVERIFY(appLauncher.initialize());
    }

    std::ostringstream helpText;
    appLauncher.displayHelp(helpText);

    QCOMPARE(QString::fromLatin1(helpText.str().c_str()), expectedDisplayText);
}
Exemplo n.º 3
0
int main(int argc, char** argv)
{
  #ifdef QT_MAC_USE_COCOA
  // See http://doc.trolltech.com/4.7/qt.html#ApplicationAttribute-enum
  // Setting the application to be a plugin will avoid the loading of qt_menu.nib files
  QCoreApplication::setAttribute(Qt::AA_MacPluginApplication, true);
  #endif
  QApplication app(argc, argv);
  
  // Initialize resources in static libs
  Q_INIT_RESOURCE(CTKAppLauncherBase);
  
  ctkAppLauncher appLauncher(app);
  
  QTimer::singleShot(0, &appLauncher, SLOT(startLauncher()));

  return app.exec();
}
Exemplo n.º 4
0
int ctkAppLauncherTest1(int argc, char* argv[])
{
  #ifdef QT_MAC_USE_COCOA
  // See http://doc.trolltech.com/4.7/qt.html#ApplicationAttribute-enum
  // Setting the application to be a plugin will avoid the loading of qt_menu.nib files
  QCoreApplication::setAttribute(Qt::AA_MacPluginApplication, true);
  #endif
  QApplication app(argc, argv);

  ctkAppLauncher appLauncher(app);

  // Test0 - verbose()
  // By default, verbose flag should be Off
  if (appLauncher.verbose())
    {
    qCritical() << "Test0a - Problem with verbose() function";
    return EXIT_FAILURE;
    }
//  appLauncher.setVerbose(true);
//  if (!appLauncher.verbose())
//    {
//    qCritical() << "Test0b - Problem with verbose() function";
//    return EXIT_FAILURE;
//    }

//  appLauncher.setVerbose(false);
//  if (appLauncher.verbose())
//    {
//    qCritical() << "Test0c - Problem with verbose() function";
//    return EXIT_FAILURE;
//    }

  // Test1 - displayHelp() before initialize()
  std::ostringstream helpText;
  appLauncher.displayHelp(helpText);

  if (helpText.str().length() != 0)
    {
    // Since the command line parser hasn't been initialized, displayHelp is expected
    // to return an empty string.
    qCritical() << "Test1 - Problem with displayHelp() function";
    return EXIT_FAILURE;
    }

  // Test2 - initialize()
  bool status = appLauncher.initialize();
  if (!status)
    {
    qCritical() << "Test2 - Problem with initialize() function";
    return EXIT_FAILURE;
    }

  // Test3 - displayHelp() after initialize()
  QString expectedHelpText;
  QTextStream expectedHelpTextStream(&expectedHelpText);

  expectedHelpTextStream << "Usage\n"
    << "  CTKAppLauncherBaseCppTests [options]\n\n"
    << "Options\n"
    << "  --launcher-help                Display help\n"
    << "  --launcher-verbose             Verbose mode\n"
    << "  --launch                       Specify the application to launch\n"
    << "  --launcher-detach              Launcher will NOT wait for the application to finish\n"
    << "  --launcher-no-splash           Hide launcher splash\n"
    << "  --launcher-timeout             Specify the time in second before the launcher kills "
       "the application. -1 means no timeout (default: -1)\n"
    << "  --launcher-generate-template   Generate an example of setting file\n";

  helpText.clear();
  appLauncher.displayHelp(helpText);
  if (expectedHelpText != QString(helpText.str().c_str()))
    {
    qCritical() << "Test3 - Problem with displayHelp() function - expected\n-----\n"
        << expectedHelpText << "\n-----\ncurrent\n-----\n" << QString(helpText.str().c_str());
    return EXIT_FAILURE;
    }

  return EXIT_SUCCESS;
}
// ----------------------------------------------------------------------------
void ctkAppLauncherTest1er::testVerbose()
{
    ctkAppLauncher appLauncher(*qApp);
    QVERIFY2(!appLauncher.verbose(), "Disabled by default");
}
Exemplo n.º 6
0
int main(int argc, char** argv)
{
  #ifdef QT_MAC_USE_COCOA
  // See http://doc.trolltech.com/4.7/qt.html#ApplicationAttribute-enum
  // Setting the application to be a plugin will avoid the loading of qt_menu.nib files
  QCoreApplication::setAttribute(Qt::AA_MacPluginApplication, true);
  #endif

  ctkAppArguments appArguments(argc, argv);

  // See http://qt-project.org/doc/qt-4.8/qapplication.html#QApplication
  appArguments.setArgumentToFilterList(
        ctkAppArguments::ArgToFilterListType()
        << ctkAppArguments::ArgToFilterType("-style", ctkAppArguments::ARG_TO_FILTER_EQUAL_VALUE | ctkAppArguments::ARG_TO_FILTER_SPACE_VALUE)
        << ctkAppArguments::ArgToFilterType("-stylesheet", ctkAppArguments::ARG_TO_FILTER_EQUAL_VALUE | ctkAppArguments::ARG_TO_FILTER_SPACE_VALUE)
        << ctkAppArguments::ArgToFilterType("-session", ctkAppArguments::ARG_TO_FILTER_EQUAL_VALUE | ctkAppArguments::ARG_TO_FILTER_SPACE_VALUE)
        << ctkAppArguments::ArgToFilterType("-widgetcount")
        << ctkAppArguments::ArgToFilterType("-reverse")
        << ctkAppArguments::ArgToFilterType("-graphicssystem")
        << ctkAppArguments::ArgToFilterType("-qmljsdebugger=", ctkAppArguments::ARG_TO_FILTER_EQUAL_VALUE)
#ifdef QT_DEBUG
        << ctkAppArguments::ArgToFilterType("-nograb")
#endif
#ifdef Q_WS_X11
        << ctkAppArguments::ArgToFilterType("-display")
        << ctkAppArguments::ArgToFilterType("-geometry")
        << ctkAppArguments::ArgToFilterType("-fn")
        << ctkAppArguments::ArgToFilterType("-font")
        << ctkAppArguments::ArgToFilterType("-bg")
        << ctkAppArguments::ArgToFilterType("-background")
        << ctkAppArguments::ArgToFilterType("-fg")
        << ctkAppArguments::ArgToFilterType("-foreground")
        << ctkAppArguments::ArgToFilterType("-btn")
        << ctkAppArguments::ArgToFilterType("-button")
        << ctkAppArguments::ArgToFilterType("-name")
        << ctkAppArguments::ArgToFilterType("-title")
        << ctkAppArguments::ArgToFilterType("-visual")
        << ctkAppArguments::ArgToFilterType("-ncols")
        << ctkAppArguments::ArgToFilterType("-cmap")
        << ctkAppArguments::ArgToFilterType("-im")
        << ctkAppArguments::ArgToFilterType("-inputstyle")
# ifdef QT_DEBUG
        << ctkAppArguments::ArgToFilterType("-dograb")
        << ctkAppArguments::ArgToFilterType("-sync")
# endif
#endif
        );

  QApplication app(appArguments.argumentCount(ctkAppArguments::ARG_REGULAR_LIST),
                   appArguments.argumentValues(ctkAppArguments::ARG_REGULAR_LIST));

  // Initialize resources in static libs
  Q_INIT_RESOURCE(CTKAppLauncherBase);

  ctkAppLauncher appLauncher(app);
  appLauncher.setArguments(appArguments.arguments());

  QTimer::singleShot(0, &appLauncher, SLOT(startLauncher()));

  return app.exec();
}
Exemplo n.º 7
0
// --------------------------------------------------------------------------
int appLauncherMain(int argc, char** argv)
{
  #ifdef QT_MAC_USE_COCOA
  // See http://doc.trolltech.com/4.7/qt.html#ApplicationAttribute-enum
  // Setting the application to be a plugin will avoid the loading of qt_menu.nib files
  QCoreApplication::setAttribute(Qt::AA_MacPluginApplication, true);
  #endif

  ctkAppArguments appArguments(argc, argv);

  // See http://qt-project.org/doc/qt-4.8/qapplication.html#QApplication
  appArguments.setArgumentToFilterList(
        ctkAppArguments::ArgToFilterListType()
        << ctkAppArguments::ArgToFilterType("-style", ctkAppArguments::ARG_TO_FILTER_EQUAL_VALUE | ctkAppArguments::ARG_TO_FILTER_SPACE_VALUE)
        << ctkAppArguments::ArgToFilterType("-stylesheet", ctkAppArguments::ARG_TO_FILTER_EQUAL_VALUE | ctkAppArguments::ARG_TO_FILTER_SPACE_VALUE)
        << ctkAppArguments::ArgToFilterType("-session", ctkAppArguments::ARG_TO_FILTER_EQUAL_VALUE | ctkAppArguments::ARG_TO_FILTER_SPACE_VALUE)
        << ctkAppArguments::ArgToFilterType("-widgetcount")
        << ctkAppArguments::ArgToFilterType("-reverse")
        << ctkAppArguments::ArgToFilterType("-graphicssystem")
        << ctkAppArguments::ArgToFilterType("-qmljsdebugger=", ctkAppArguments::ARG_TO_FILTER_EQUAL_VALUE)
#ifdef QT_DEBUG
        << ctkAppArguments::ArgToFilterType("-nograb")
#endif
#ifdef Q_WS_X11
        << ctkAppArguments::ArgToFilterType("-display")
        << ctkAppArguments::ArgToFilterType("-geometry")
        << ctkAppArguments::ArgToFilterType("-fn")
        << ctkAppArguments::ArgToFilterType("-font")
        << ctkAppArguments::ArgToFilterType("-bg")
        << ctkAppArguments::ArgToFilterType("-background")
        << ctkAppArguments::ArgToFilterType("-fg")
        << ctkAppArguments::ArgToFilterType("-foreground")
        << ctkAppArguments::ArgToFilterType("-btn")
        << ctkAppArguments::ArgToFilterType("-button")
        << ctkAppArguments::ArgToFilterType("-name")
        << ctkAppArguments::ArgToFilterType("-title")
        << ctkAppArguments::ArgToFilterType("-visual")
        << ctkAppArguments::ArgToFilterType("-ncols")
        << ctkAppArguments::ArgToFilterType("-cmap")
        << ctkAppArguments::ArgToFilterType("-im")
        << ctkAppArguments::ArgToFilterType("-inputstyle")
# ifdef QT_DEBUG
        << ctkAppArguments::ArgToFilterType("-dograb")
        << ctkAppArguments::ArgToFilterType("-sync")
# endif
#endif
        );

  QFileInfo launcherFile(QDir::current(), QString(argv[0]));
  // Initialize resources in static libs
  Q_INIT_RESOURCE(CTKAppLauncherBase);

  QScopedPointer<ctkAppLauncher> appLauncher(new ctkAppLauncher);
  appLauncher->setArguments(appArguments.arguments());
  bool exec = appLauncher->initialize(launcherFile.absoluteFilePath());
  exec = appLauncher->configure() && exec;

  if (!exec)
    {
    return EXIT_SUCCESS;
    }

  QScopedPointer<QCoreApplication> app;
  if (appLauncher->disableSplash())
    {
    app.reset(new QCoreApplication(
                appArguments.argumentCount(ctkAppArguments::ARG_REGULAR_LIST),
                appArguments.argumentValues(ctkAppArguments::ARG_REGULAR_LIST)));
    }
  else
    {
    app.reset(new QApplication(
                appArguments.argumentCount(ctkAppArguments::ARG_REGULAR_LIST),
                appArguments.argumentValues(ctkAppArguments::ARG_REGULAR_LIST)));
    }
  appLauncher->setApplication(*app.data());

  QTimer::singleShot(0, appLauncher.data(), SLOT(startLauncher()));

  int res = app->exec();

  // Delete application launcher appLauncher before the application app so that
  // graphical items such as pixmaps, widgets, etc can be released.
  appLauncher.reset();

  return res;
}