~nskaggs/ubuntu-ui-toolkit/add-popover-object-support

« back to all changes in this revision

Viewing changes to tests/launcher/launcher.cpp

  • Committer: CI bot
  • Author(s): Zsombor Egri, Tarmac, Zoltán Balogh
  • Date: 2014-06-18 17:10:31 UTC
  • mfrom: (1000.76.9 landing_04-06)
  • Revision ID: ps-jenkins@lists.canonical.com-20140618171031-1s026ulaxymh2e9f
  [Leo Arias ]
  * On the autopilot helper for the header, fix the swipe to show
    when hidden.
  * Added a fixture for autopilot tests to use a fake home directory.
    Fixes: https://bugs.launchpad.net/bugs/1317639
  * Cleaned the containers in unity test using the alternate
    launcher.

  [ Christian Dywan ]   
  * Add a launcher with a switch for the QQMLEngine.

  [ Tim Peeters ]
  * Anchor the internal PageTreeNode of PageStack to fill its parent.
    Fixes: https://bugs.launchpad.net/bugs/1322527
 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2014 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * QML launcher with the ability to setup the QQuickView/ QQmlEngine differently
 
17
 *
 
18
 * Rationale: Different variants of qmlscene exist as well as C++ and Go apps
 
19
 * This is to write Autopilot test cases that exhibit specific behavior
 
20
 */
 
21
 
 
22
#include <iostream>
 
23
#include <QtCore/qdebug.h>
 
24
#include <QtQuick/QQuickView>
 
25
#include <QtGui/QGuiApplication>
 
26
#include <QtQml/QQmlEngine>
 
27
#include <QtQml/QQmlContext>
 
28
#include <QtCore/QFileInfo>
 
29
#include <QLibrary>
 
30
#include <QOpenGLContext>
 
31
#include <QtGui/private/qopenglcontext_p.h>
 
32
#include <QtQuick/private/qsgcontext_p.h>
 
33
 
 
34
int usage()
 
35
{
 
36
    QString self(QGuiApplication::instance()->arguments().at(0));
 
37
    std::cout << "Usage\n  "
 
38
        << qPrintable(self)
 
39
        << " -testability -frameless -engine"
 
40
        << " --desktop_file_path=DESKTOP_FILE"
 
41
        << " -I MODULE_PATH FILENAME\n";
 
42
    return 1;
 
43
}
 
44
 
 
45
int main(int argc, const char *argv[])
 
46
{
 
47
    // QPlatformIntegration::ThreadedOpenGL
 
48
    setenv("QML_FORCE_THREADED_RENDERER", "1", 1);
 
49
    // QPlatformIntegration::BufferQueueingOpenGL
 
50
    setenv("QML_FIXED_ANIMATION_STEP", "1", 1);
 
51
    // Oxide and QWebEngine need a shared context
 
52
    QScopedPointer<QOpenGLContext> shareContext;
 
53
    shareContext.reset(new QOpenGLContext);
 
54
#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0)
 
55
    QSGContext::setSharedOpenGLContext(shareContext.data());
 
56
#else
 
57
    QOpenGLContextPrivate::setGlobalShareContext(shareContext.data());
 
58
#endif
 
59
    QGuiApplication::setApplicationName("UITK Launcher");
 
60
    QGuiApplication application(argc, (char**)argv);
 
61
    QStringList args (application.arguments());
 
62
 
 
63
    int _testability(args.indexOf("-testability"));
 
64
    args.removeAt(_testability);
 
65
    int _frameless(args.indexOf("-frameless"));
 
66
    args.removeAt(_frameless);
 
67
    int _engine(args.indexOf("-engine"));
 
68
    args.removeAt(_engine);
 
69
 
 
70
    Q_FOREACH(QString arg, args) {
 
71
        if (arg.startsWith("--desktop_file_hint")) {
 
72
            // This will not be used - it only needs to be ignored
 
73
            int _desktop_file_hint(args.indexOf(arg));
 
74
            args.removeAt(_desktop_file_hint);
 
75
        }
 
76
    }
 
77
 
 
78
    // Testability is only supported out of the box by QApplication not QGuiApplication
 
79
    if (_testability > -1 || getenv("QT_LOAD_TESTABILITY")) {
 
80
        QLibrary testLib(QLatin1String("qttestability"));
 
81
        if (testLib.load()) {
 
82
            typedef void (*TasInitialize)(void);
 
83
            TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
 
84
            if (initFunction) {
 
85
                initFunction();
 
86
            } else {
 
87
                qCritical("Library qttestability resolve failed!");
 
88
                return 1;
 
89
            }
 
90
        } else {
 
91
            qCritical("Library qttestability load failed!");
 
92
            return 1;
 
93
        }
 
94
    }
 
95
 
 
96
    QQmlEngine* engine;
 
97
    // The default constructor affects the components tree (autopilot vis)
 
98
    QQuickView* view;
 
99
    if (_engine > -1) {
 
100
        view = new QQuickView();
 
101
        engine = view->engine();
 
102
    } else {
 
103
        engine = new QQmlEngine();
 
104
        view = new QQuickView(engine, NULL);
 
105
    }
 
106
 
 
107
    int _import(args.indexOf("-I"));
 
108
    args.removeAt(_import);
 
109
    if (_import > -1) {
 
110
        if (args.count() > _import) {
 
111
            QString importPath(args.at(_import));
 
112
            args.removeAt(_import);
 
113
            engine->addImportPath(importPath);
 
114
        }
 
115
    }
 
116
 
 
117
    view->setResizeMode(QQuickView::SizeRootObjectToView);
 
118
    view->setTitle("UI Toolkit QQuickView");
 
119
    if (_frameless > -1) {
 
120
        view->setFlags(Qt::FramelessWindowHint);
 
121
    }
 
122
 
 
123
    // The remaining unnamed argument must be a filename
 
124
    if (args.count() == 1) {
 
125
        qCritical() << "Missing filename";
 
126
        return usage();
 
127
    }
 
128
    QString filename(args.at(1));
 
129
    // The first argument is the launcher itself
 
130
    args.removeAt(0);
 
131
 
 
132
    QUrl source(QUrl::fromLocalFile(filename));
 
133
    view->setSource(source);
 
134
    if (view->errors().count() > 0) {
 
135
        return usage();
 
136
    }
 
137
    view->show();
 
138
 
 
139
    if (args.count() > 1) {
 
140
        qCritical() << "Invalid arguments passed" << args;
 
141
        return usage();
 
142
    }
 
143
 
 
144
    return application.exec();
 
145
}
 
146