Mir

Merge lp:~josharenson/mir/command_line_config into lp:mir

Proposed by Josh Arenson
Status: Merged
Approved by: Alan Griffiths
Approved revision: no longer in the source branch.
Merged at revision: 1643
Proposed branch: lp:~josharenson/mir/command_line_config
Merge into: lp:mir
Diff against target: 164 lines (+97/-18)
4 files modified
include/test/mir_test_framework/command_line_server_configuration.h (+38/-0)
tests/mir_test_framework/CMakeLists.txt (+1/-0)
tests/mir_test_framework/command_line_server_configuration.cpp (+56/-0)
tests/mir_test_framework/stubbed_server_configuration.cpp (+2/-18)
To merge this branch: bzr merge lp:~josharenson/mir/command_line_config
Reviewer Review Type Date Requested Status
Alberto Aguirre (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Alan Griffiths Approve
Review via email: mp+219619@code.launchpad.net

Commit message

Implements a command_line_server_configuration that allows for creating a DefaultServerConfiguration, but respects command line arguments

Fixes lp:1316987

Description of the change

Implements a command_line_server_configuration that allows for creating a DefaultServerConfiguration, but respects command line arguments

Fixes lp:1316987

To post a comment you must log in.
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

~~~
6 + * Copyright © 2012 Canonical Ltd.
~~~

s/2012/2014

~~~
26 +#include "mir/options/default_configuration.h"
~~~

Foward declare instead:

namespace mir
{
namespace options
{
class DefaultConfiguration;
}
}

~~~
28 +namespace mo=mir::options;
~~~

I believe we avoid using namespace aliases in headers.

~~~
33 + -> std::shared_ptr<mo::DefaultConfiguration>;
~~~

Missing #include <memory> for shared_ptr

~~~
36 +int main(int argc, char** argv);
~~~

Not needed.

~~~
57 + * Copyright © 2012 Canonical Ltd.
~~~

s/2012/2014

~~~
74 +#include "mir/default_configuration.h"
76 +#include "mir/default_server_configuration.h"
83 +#include <memory>
~~~

^-- Not needed

~~~
87 +int argc;
88 +char const** argv;
~~~

Mark them static?

~~~
107 + [](char const* arg) { return !strncmp(arg, "--gtest_", 8); }) - argv;
~~~

Because of the use of strncmp there should be a corresponding #include <cstring>

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

23 +#ifndef COMMAND_LINE_SERVER_CONFIGURATION
24 +#define COMMAND_LINE_SERVER_CONFIGURATION

Missing MIR_TEST_FRAMEWORK_ prefix

~~~~

26 +#include "mir/options/default_configuration.h"

We only need a declaration: namespace mir { namespace options { class mo::Configuration; } }

But we do need

#include <memory>

~~~~

28 +namespace mo=mir::options;

Not in a header.

~~~~

30 +namespace mir_test_framework
31 +{
32 + auto configuration_from_commandline()
33 + -> std::shared_ptr<mo::DefaultConfiguration>;

The return type should be mir::options::Configuration;

~~~~

36 +int main(int argc, char** argv);

not wanted.

~~~~

74 +#include "mir/default_configuration.h"
75 +#include "mir/options/default_configuration.h"
76 +#include "mir/default_server_configuration.h"
77 +#include "mir_test_framework/command_line_server_configuration.h"

The first header should be the one that corresponds to the .cpp (which proves the header is self-contained)

~~~~

74 +#include "mir/default_configuration.h"
...
76 +#include "mir/default_server_configuration.h"
...
79 +#include <boost/algorithm/string.hpp>

Unused headers

~~~~

125 +#include "mir_test_framework/command_line_server_configuration.h"
126 #include "mir_test_framework/stubbed_server_configuration.h"

The first header should be the one that corresponds to the .cpp (which proves the header is self-contained)

~~~~

stubbed_server_configuration.cpp no longer needs:

#include "mir/options/default_configuration.h"

It does need "mir/options/configuration.h"

review: Needs Fixing
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> ~~~
> 87 +int argc;
> 88 +char const** argv;
> ~~~
>
> Mark them static?

No put them in an anonymous namespace (as they were in the "before" code).

review: Needs Fixing
Revision history for this message
Josh Arenson (josharenson) wrote :

>
> ~~~~
>
> 30 +namespace mir_test_framework
> 31 +{
> 32 + auto configuration_from_commandline()
> 33 + -> std::shared_ptr<mo::DefaultConfiguration>;
>
> The return type should be mir::options::Configuration;

If Configuration is returned, can options be added later (using boost::options)?

Revision history for this message
Alberto Aguirre (albaguirre) wrote :

Just some more minor nits:

~~~
23 +#ifndef COMMAND_LINE_SERVER_CONFIGURATION
~~~

Like Alan mentioned, the convention is:

MIR_TEST_FRAMEWORK_COMMAND_LINE_SERVER_CONFIGURATION_H_

~~~
78 +#include "mir/default_configuration.h"
~~~
Not needed.

~~~
100 + return make_shared<mo::DefaultConfiguration>(::argc, ::argv);
~~~
Per the style guide: http://unity.ubuntu.com/mir/cppguide/index.html?showone=Spaces_vs._Tabs#Spaces_vs._Tabs

It should be indented 4 spaces from the curly bracket.

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> > The return type should be mir::options::Configuration;
>
>
> If Configuration is returned, can options be added later (using
> boost::options)?

Ack

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

78 +#include "mir/default_configuration.h"

Not used

~~~~

126 +#include "mir_test_framework/command_line_server_configuration.h"
127 #include "mir_test_framework/stubbed_server_configuration.h"

The first header should be the one that corresponds to the .cpp (which proves the header is self-contained)

~~~~

96 + using namespace std;

Just use std::make_shared a few lines later.

~~~~

97 + auto configuration_from_commandline()
98 + -> shared_ptr<mo::DefaultConfiguration>
99 + {
100 + return make_shared<mo::DefaultConfiguration>(::argc, ::argv);
101 + }
...
107 + std::cout << "Running main() from " << basename(__FILE__) << std::endl;
108 + ::argc = std::remove_if(
109 + argv,
110 + argv+argc,
111 + [](char const* arg) { return !strncmp(arg, "--gtest_", 8); }) - argv;
112 + ::argv = const_cast<char const**>(argv);
113 +
114 + ::testing::InitGoogleTest(&argc, argv);
115 +
116 + return RUN_ALL_TESTS();

We don't use tabs on this codebase.

~~~~

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

89 +int argc;
90 +char const** argv;

I'm curious that these are now uninitialized when they were previously initialized with "safe" defaults. Was this intentional? And why?

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

> 89 +int argc;
> 90 +char const** argv;
>
> I'm curious that these are now uninitialized when they were previously
> initialized with "safe" defaults. Was this intentional? And why?

Since this _should always_ be called from a command line application, and since a program cannot have more than one main function, argv will always be populated with _at least_ the executable name. I thought it might be confusing to initialize variables that are typically not initialized, however, there isn't any harm in initializing them as such:

132 -char const* dummy[] = {0};
133 -int argc = 0;
134 -char const** argv = dummy;

for safety's sake. Thoughts?

Revision history for this message
Alberto Aguirre (albaguirre) wrote :

LGTM

review: Approve

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/command_line_server_configuration.h'
2--- include/test/mir_test_framework/command_line_server_configuration.h 1970-01-01 00:00:00 +0000
3+++ include/test/mir_test_framework/command_line_server_configuration.h 2014-05-16 15:47:38 +0000
4@@ -0,0 +1,38 @@
5+/*
6+ * Copyright © 2014 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 more details.
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: Josh Arenson <joshua.arenson@canonical.com>
21+ */
22+
23+#ifndef MIR_TEST_FRAMEWORK_COMMAND_LINE_SERVER_CONFIGURATION
24+#define MIR_TEST_FRAMEWORK_COMMAND_LINE_SERVER_CONFIGURATION
25+
26+#include <memory>
27+
28+namespace mir
29+{
30+namespace options
31+{
32+class DefaultConfiguration;
33+}
34+}
35+
36+namespace mir_test_framework
37+{
38+ auto configuration_from_commandline()
39+ -> std::shared_ptr<mir::options::DefaultConfiguration>;
40+}
41+
42+#endif /* MIR_TEST_FRAMEWORK_COMMAND_LINE_SERVER_CONFIGURATION */
43
44=== modified file 'tests/mir_test_framework/CMakeLists.txt'
45--- tests/mir_test_framework/CMakeLists.txt 2014-05-14 06:34:25 +0000
46+++ tests/mir_test_framework/CMakeLists.txt 2014-05-16 15:47:38 +0000
47@@ -8,6 +8,7 @@
48 set(
49 TEST_FRAMEWORK_SRCS
50
51+ command_line_server_configuration.cpp
52 cross_process_sync.cpp
53 in_process_server.cpp
54 testing_server_options.cpp
55
56=== added file 'tests/mir_test_framework/command_line_server_configuration.cpp'
57--- tests/mir_test_framework/command_line_server_configuration.cpp 1970-01-01 00:00:00 +0000
58+++ tests/mir_test_framework/command_line_server_configuration.cpp 2014-05-16 15:47:38 +0000
59@@ -0,0 +1,56 @@
60+/*
61+ * Copyright © 2014 Canonical Ltd.
62+ *
63+ * This program is free software: you can redistribute it and/or modify it
64+ * under the terms of the GNU General Public License version 3,
65+ * as published by the Free Software Foundation.
66+ *
67+ * This program is distributed in the hope that it will be useful,
68+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
69+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70+ * GNU General Public License for more details.
71+ *
72+ * You should have received a copy of the GNU General Public License
73+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
74+ *
75+ */
76+
77+#include "mir_test_framework/command_line_server_configuration.h"
78+#include "mir/options/default_configuration.h"
79+
80+#include <gtest/gtest.h>
81+
82+#include <algorithm>
83+#include <cstring>
84+
85+namespace mo=mir::options;
86+
87+namespace
88+{
89+int argc;
90+char const** argv;
91+}
92+
93+namespace mir_test_framework
94+{
95+ auto configuration_from_commandline()
96+ -> std::shared_ptr<mo::DefaultConfiguration>
97+ {
98+ return std::make_shared<mo::DefaultConfiguration>(::argc, ::argv);
99+ }
100+}
101+
102+int main(int argc, char** argv)
103+{
104+ // Override this standard gtest message
105+ std::cout << "Running main() from " << basename(__FILE__) << std::endl;
106+ ::argc = std::remove_if(
107+ argv,
108+ argv+argc,
109+ [](char const* arg) { return !strncmp(arg, "--gtest_", 8); }) - argv;
110+ ::argv = const_cast<char const**>(argv);
111+
112+ ::testing::InitGoogleTest(&argc, argv);
113+
114+ return RUN_ALL_TESTS();
115+}
116
117=== modified file 'tests/mir_test_framework/stubbed_server_configuration.cpp'
118--- tests/mir_test_framework/stubbed_server_configuration.cpp 2014-05-12 04:29:42 +0000
119+++ tests/mir_test_framework/stubbed_server_configuration.cpp 2014-05-16 15:47:38 +0000
120@@ -17,6 +17,7 @@
121 */
122
123 #include "mir_test_framework/stubbed_server_configuration.h"
124+#include "mir_test_framework/command_line_server_configuration.h"
125
126 #include "mir/options/default_configuration.h"
127 #include "mir/geometry/rectangle.h"
128@@ -58,10 +59,6 @@
129
130 namespace
131 {
132-char const* dummy[] = {0};
133-int argc = 0;
134-char const** argv = dummy;
135-
136 class StubFDBuffer : public mtd::StubBuffer
137 {
138 public:
139@@ -222,7 +219,7 @@
140 mtf::StubbedServerConfiguration::StubbedServerConfiguration() :
141 DefaultServerConfiguration([]
142 {
143- auto result = std::make_shared<mo::DefaultConfiguration>(::argc, ::argv);
144+ auto result = mtf::configuration_from_commandline();
145
146 namespace po = boost::program_options;
147
148@@ -278,16 +275,3 @@
149 else
150 return std::make_shared<mi::NullInputDispatcherConfiguration>();
151 }
152-
153-int main(int argc, char** argv)
154-{
155- ::argc = std::remove_if(
156- argv,
157- argv+argc,
158- [](char const* arg) { return !strncmp(arg, "--gtest_", 8); }) - argv;
159- ::argv = const_cast<char const**>(argv);
160-
161- ::testing::InitGoogleTest(&argc, argv);
162-
163- return RUN_ALL_TESTS();
164-}

Subscribers

People subscribed via source and target branches