Merge lp:~thomas-voss/trust-store/fix-1420790 into lp:trust-store

Proposed by Thomas Voß
Status: Merged
Approved by: I Ahmad
Approved revision: 92
Merged at revision: 91
Proposed branch: lp:~thomas-voss/trust-store/fix-1420790
Merge into: lp:trust-store
Diff against target: 183 lines (+60/-21)
2 files modified
src/core/trust/mir/prompt_main.cpp (+49/-21)
src/core/trust/mir/prompt_main.h (+11/-0)
To merge this branch: bzr merge lp:~thomas-voss/trust-store/fix-1420790
Reviewer Review Type Date Requested Status
I Ahmad (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+249320@code.launchpad.net

Commit message

Add support for enabling the testability driver for the trust prompt.

Description of the change

Add support for enabling the testability driver for the trust prompt.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
I Ahmad (iahmad) wrote :

Looks good to me

review: Approve
92. By Thomas Voß

Introduce namespace aliases.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/core/trust/mir/prompt_main.cpp'
2--- src/core/trust/mir/prompt_main.cpp 2014-11-06 10:38:33 +0000
3+++ src/core/trust/mir/prompt_main.cpp 2015-02-13 12:08:21 +0000
4@@ -22,6 +22,7 @@
5 // Qt
6 #include <QCommandLineParser>
7 #include <QGuiApplication>
8+#include <QLibrary>
9
10 #include <QQuickView>
11 #include <QQuickItem>
12@@ -38,6 +39,11 @@
13 #include "prompt_config.h"
14 #include "prompt_main.h"
15
16+namespace cli = core::trust::mir::cli;
17+namespace env = core::trust::mir::env;
18+
19+namespace this_env = core::posix::this_process::env;
20+
21 namespace core
22 {
23 namespace trust
24@@ -66,22 +72,22 @@
25 {
26 // We are throwing exceptions here, which immediately calls abort and still gives a
27 // helpful error message on the terminal.
28- if (vm.count(core::trust::mir::cli::option_title) == 0) throw std::logic_error
29+ if (vm.count(cli::option_title) == 0) throw std::logic_error
30 {
31 "Missing option title."
32 };
33
34- if (vm.count(core::trust::mir::cli::option_description) == 0) throw std::logic_error
35+ if (vm.count(cli::option_description) == 0) throw std::logic_error
36 {
37 "Missing option description"
38 };
39
40- if (vm.count(core::trust::mir::cli::option_server_socket) == 0) throw std::logic_error
41+ if (vm.count(cli::option_server_socket) == 0) throw std::logic_error
42 {
43 "Missing option mir_server_socket"
44 };
45
46- std::string mir_server_socket = vm[core::trust::mir::cli::option_server_socket].as<std::string>();
47+ std::string mir_server_socket = vm[cli::option_server_socket].as<std::string>();
48
49 if (mir_server_socket.find("fd://") != 0) throw std::logic_error
50 {
51@@ -91,15 +97,15 @@
52 }
53 }
54
55-
56 int main(int argc, char** argv)
57 {
58 boost::program_options::options_description options;
59 options.add_options()
60- (core::trust::mir::cli::option_server_socket, boost::program_options::value<std::string>(), "Mir server socket to connect to.")
61- (core::trust::mir::cli::option_description, boost::program_options::value<std::string>(), "Extended description of the prompt.")
62- (core::trust::mir::cli::option_title, boost::program_options::value<std::string>(), "Title of the prompt.")
63- (core::trust::mir::cli::option_testing, "Only checks command-line parameters and does not execute any actions.");
64+ (cli::option_server_socket, boost::program_options::value<std::string>(), "Mir server socket to connect to.")
65+ (cli::option_description, boost::program_options::value<std::string>(), "Extended description of the prompt.")
66+ (cli::option_title, boost::program_options::value<std::string>(), "Title of the prompt.")
67+ (cli::option_testing, "Only checks command-line parameters and does not execute any actions.")
68+ (cli::option_testability, "Loads the Qt Testability plugin if provided.");
69
70 auto parsed_options = boost::program_options::command_line_parser{argc, argv}
71 .options(options)
72@@ -117,29 +123,29 @@
73 boost::program_options::notify(vm);
74
75 // We just verify command line arguments in testing and immediately return.
76- if (vm.count(core::trust::mir::cli::option_testing) > 0)
77+ if (vm.count(cli::option_testing) > 0)
78 {
79 testing::validate_command_line_arguments(vm); return 0;
80 }
81
82 // Let's validate the arguments.
83- if (vm.count(core::trust::mir::cli::option_title) == 0)
84+ if (vm.count(cli::option_title) == 0)
85 abort(); // We have to call abort here to make sure that we get signalled.
86
87- std::string title = vm[core::trust::mir::cli::option_title].as<std::string>();
88+ std::string title = vm[cli::option_title].as<std::string>();
89
90 std::string description;
91- if (vm.count(core::trust::mir::cli::option_description) > 0)
92- description = vm[core::trust::mir::cli::option_description].as<std::string>();
93+ if (vm.count(cli::option_description) > 0)
94+ description = vm[cli::option_description].as<std::string>();
95
96- if (vm.count(core::trust::mir::cli::option_server_socket) > 0)
97+ if (vm.count(cli::option_server_socket) > 0)
98 {
99 // We make sure that the env variable is not set prior to adusting it.
100- core::posix::this_process::env::unset_or_throw(core::trust::mir::env::option_mir_socket);
101+ this_env::unset_or_throw(env::option_mir_socket);
102
103- core::posix::this_process::env::set_or_throw(
104- core::trust::mir::env::option_mir_socket,
105- vm[core::trust::mir::cli::option_server_socket].as<std::string>());
106+ this_env::set_or_throw(
107+ env::option_mir_socket,
108+ vm[cli::option_server_socket].as<std::string>());
109 }
110
111 // We install our default gettext domain prior to anything qt.
112@@ -165,6 +171,28 @@
113 // to the application.
114 QGuiApplication app{argc, argv};
115
116+ if (vm.count(cli::option_testability) > 0 ||
117+ this_env::get(env::option_testability, "0") == "1")
118+ {
119+ // This initialization code is copy'n'pasted across multiple projects. We really should _not_
120+ // do something like that and bundle initialization routines in autopilot-qt.
121+ // The testability driver is only loaded by QApplication but not by QGuiApplication.
122+ // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
123+ QLibrary testLib(QLatin1String("qttestability"));
124+ if (testLib.load())
125+ {
126+ typedef void (*TasInitialize)(void);
127+ TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
128+ if (initFunction)
129+ initFunction();
130+ else
131+ qCritical("Library qttestability resolve failed!");
132+ } else
133+ {
134+ qCritical("Library qttestability load failed!");
135+ }
136+ }
137+
138 core::trust::mir::SignalTrap signal_trap;
139
140 QQuickView* view = new QQuickView();
141@@ -174,11 +202,11 @@
142 // Make some properties known to the root context.
143 // The title of the dialog.
144 view->rootContext()->setContextProperty(
145- core::trust::mir::cli::option_title,
146+ cli::option_title,
147 title.c_str());
148 // The description of the dialog.
149 view->rootContext()->setContextProperty(
150- core::trust::mir::cli::option_description,
151+ cli::option_description,
152 description.c_str());
153
154 // Point the engine to the right directory. Please note that
155
156=== modified file 'src/core/trust/mir/prompt_main.h'
157--- src/core/trust/mir/prompt_main.h 2014-07-24 11:30:09 +0000
158+++ src/core/trust/mir/prompt_main.h 2015-02-13 12:08:21 +0000
159@@ -32,6 +32,11 @@
160 {
161 "MIR_SOCKET"
162 };
163+/** @brief Name of the environment variable that triggers loading of the testability plugin. */
164+static constexpr const char* option_testability
165+{
166+ "QT_LOAD_TESTABILITY"
167+};
168 }
169 namespace cli
170 {
171@@ -58,6 +63,12 @@
172 {
173 "testing"
174 };
175+
176+/** @brief Loads the Qt Testability plugin if provided. */
177+static constexpr const char* option_testability
178+{
179+ "testability"
180+};
181 }
182 }
183 }

Subscribers

People subscribed via source and target branches