Mir

Merge lp:~alan-griffiths/mir/introducing-mir_test_framework-main into lp:mir

Proposed by Alan Griffiths
Status: Merged
Approved by: Alan Griffiths
Approved revision: no longer in the source branch.
Merged at revision: 2707
Proposed branch: lp:~alan-griffiths/mir/introducing-mir_test_framework-main
Merge into: lp:mir
Diff against target: 129 lines (+83/-5)
4 files modified
include/test/mir_test_framework/main.h (+43/-0)
tests/mir_test_framework/CMakeLists.txt (+1/-0)
tests/mir_test_framework/command_line_server_configuration.cpp (+9/-5)
tests/mir_test_framework/main.cpp (+30/-0)
To merge this branch: bzr merge lp:~alan-griffiths/mir/introducing-mir_test_framework-main
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alexandros Frantzis (community) Approve
Review via email: mp+262998@code.launchpad.net

Commit message

tests: make it simple for a libmir-test-assist.a user to provide main()

Description of the change

tests: make it simple for a libmir-test-assist.a user to provide main()

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
Alexandros Frantzis (afrantzis) wrote :

Although a step in the right direction, I think this approach is still too restrictive; we are still forcing *our* way of running the tests, allowing no alternative. For example, this approach doesn't allow users to set some custom googletest behavior, like event handlers.

We should provide a way for users to use our infrastructure independently of any particular (google)test initialization. Since the only prerequisite for using the infrastructure is setting up the test server command line, we would just need to offer an mtf::init() or similar function.

I don't mind offering a convenience mtf::main() as this branch does (but I don't think it's necessary either), but that should be in addition to an mtf::init() type function.

Need discussion

review: Needs Information
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Looks good.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'include/test/mir_test_framework/main.h'
2--- include/test/mir_test_framework/main.h 1970-01-01 00:00:00 +0000
3+++ include/test/mir_test_framework/main.h 2015-06-26 08:23:20 +0000
4@@ -0,0 +1,43 @@
5+/*
6+ * Copyright © 2015 Canonical Ltd.
7+ *
8+ * This program is free software: you can redistribute it and/or modify it
9+ * under the terms of the GNU General Public License version 3,
10+ * as published by the Free Software Foundation.
11+ *
12+ * This program is distributed in the hope that it will be useful,
13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+ * GNU General Public License for moredetails.
16+ *
17+ * You should have received a copy of the GNU General Public License
18+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
19+ *
20+ * Authored by: Alan Griffiths <alan@octopull.co.uk>
21+ */
22+
23+#ifndef MIR_TEST_FRAMEWORK_MAIN_H
24+#define MIR_TEST_FRAMEWORK_MAIN_H
25+
26+namespace mir_test_framework
27+{
28+/**
29+ * Initialize and run the mir test framework as follows:
30+ *
31+ * ::testing::InitGoogleTest(&argc, argv);
32+ * set_commandline(argc, argv);
33+ * return RUN_ALL_TESTS();
34+ *
35+ * \attention If you override main() for your own purposes call this or do
36+ * something equivalent to run the tests.
37+ */
38+int main(int argc, char* argv[]);
39+
40+/**
41+ * Note the commandline for use in the mir test framework. The parameter list
42+ * referenced by argv must remain valid during the tests.
43+ */
44+void set_commandline(int argc, char* argv[]);
45+}
46+
47+#endif //MIR_TEST_FRAMEWORK_MAIN_H
48
49=== modified file 'tests/mir_test_framework/CMakeLists.txt'
50--- tests/mir_test_framework/CMakeLists.txt 2015-06-25 13:55:28 +0000
51+++ tests/mir_test_framework/CMakeLists.txt 2015-06-26 08:23:20 +0000
52@@ -30,6 +30,7 @@
53 headless_nested_server_runner.cpp
54 headless_test.cpp
55 interprocess_client_server_test.cpp
56+ main.cpp
57 placement_applying_shell.cpp
58 process.cpp
59 server_runner.cpp
60
61=== modified file 'tests/mir_test_framework/command_line_server_configuration.cpp'
62--- tests/mir_test_framework/command_line_server_configuration.cpp 2015-06-17 05:20:42 +0000
63+++ tests/mir_test_framework/command_line_server_configuration.cpp 2015-06-26 08:23:20 +0000
64@@ -16,6 +16,8 @@
65 */
66
67 #include "mir_test_framework/command_line_server_configuration.h"
68+#include "mir_test_framework/main.h"
69+
70 #include "mir/options/default_configuration.h"
71 #include "mir/server.h"
72
73@@ -44,14 +46,16 @@
74 server.set_command_line(::argc, ::argv);
75 }
76
77-int main(int argc, char** argv)
78+void mir_test_framework::set_commandline(int argc, char* argv[])
79 {
80- // Override this standard gtest message
81- std::cout << "Running main() from " << basename(__FILE__) << std::endl;
82- ::testing::InitGoogleTest(&argc, argv);
83-
84 ::argv = const_cast<char const**>(argv);
85 ::argc = argc;
86+}
87
88+int mir_test_framework::main(int argc, char* argv[])
89+{
90+ ::testing::InitGoogleTest(&argc, argv);
91+ set_commandline(argc, argv);
92 return RUN_ALL_TESTS();
93 }
94+
95
96=== added file 'tests/mir_test_framework/main.cpp'
97--- tests/mir_test_framework/main.cpp 1970-01-01 00:00:00 +0000
98+++ tests/mir_test_framework/main.cpp 2015-06-26 08:23:20 +0000
99@@ -0,0 +1,30 @@
100+/*
101+ * Copyright © 2015 Canonical Ltd.
102+ *
103+ * This program is free software: you can redistribute it and/or modify it
104+ * under the terms of the GNU General Public License version 3,
105+ * as published by the Free Software Foundation.
106+ *
107+ * This program is distributed in the hope that it will be useful,
108+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
109+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
110+ * GNU General Public License for more details.
111+ *
112+ * You should have received a copy of the GNU General Public License
113+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
114+ *
115+ * Authored by: Alan Griffiths <alan@octopull.co.uk>
116+ */
117+
118+#include "mir_test_framework/main.h"
119+
120+#include <cstring>
121+#include <iostream>
122+
123+int main(int argc, char* argv[])
124+{
125+ // Override this standard gtest message
126+ std::cout << "Running main() from " << basename(__FILE__) << std::endl;
127+
128+ mir_test_framework::main(argc, argv);
129+}

Subscribers

People subscribed via source and target branches