Mir

Merge lp:~vanvugt/mir/move into lp:~mir-team/mir/trunk

Proposed by Daniel van Vugt
Status: Superseded
Proposed branch: lp:~vanvugt/mir/move
Merge into: lp:~mir-team/mir/trunk
Diff against target: 456 lines (+163/-41)
12 files modified
examples/demo-shell/CMakeLists.txt (+1/-1)
examples/demo-shell/demo_shell.cpp (+7/-6)
examples/demo-shell/window_manager.cpp (+45/-4)
examples/demo-shell/window_manager.h (+13/-8)
include/server/mir/shell/session_manager.h (+1/-0)
include/server/mir/shell/surface.h (+2/-0)
include/shared/mir/geometry/dimensions.h (+24/-20)
src/server/shell/session_manager.cpp (+5/-0)
src/server/shell/surface.cpp (+12/-0)
src/server/surfaces/surface.cpp (+2/-2)
tests/unit-tests/geometry/test-dimensions.cpp (+44/-0)
tests/unit-tests/geometry/test-displacement.cpp (+7/-0)
To merge this branch: bzr merge lp:~vanvugt/mir/move
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Alan Griffiths Approve
Robert Ancell Approve
Review via email: mp+162487@code.launchpad.net

This proposal has been superseded by a proposal from 2013-06-11.

Commit message

demo-shell: Add support for moving windows/surfaces via Alt+drag.

Only the "default" surface of the focussed app is moved. In future we
should move whichever surface is hit by the pointer.

To post a comment you must log in.
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

I don't like the name "WindowManager" either. But the good alternative is to name it Shell and merge yet more classes into that. So leaving it for now.

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 :

166 + void set_session_manager(std::shared_ptr<shell::SessionManager> const& sm);

I don't think we should be making this public - if it needs to be public in DemoServerConfiguration, then that can achieve the same effect with a "using" directive in the Demo code.

The MP as a whole introduces behavior it may be better not to expose to users. Vis: "Don't move things left or up. Surfaces will vanish if they are placed left of or above the screen."

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

> 166 + void set_session_manager(std::shared_ptr<shell::SessionManager>
> const& sm);
>
> I don't think we should be making this public - if it needs to be public in
> DemoServerConfiguration, then that can achieve the same effect with a "using"
> directive in the Demo code.

I meant, of course,

195 + virtual std::shared_ptr<shell::SessionManager> the_session_manager();

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

Oops!

review: Abstain
Revision history for this message
kevin gunn (kgunn72) wrote :

moving to WIP as this has been sitting (altho daniel's been out)

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Resubmitted. I've fixed the vanishing surfaces problem. Not really sure what Alan wanted re: "set_session_manager".

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 :

220 - typedef uint32_t ValueType;
221 + typedef int ValueType;

(and related uint_32 -> int changes)

While these changes fix the problem mentioned here, I imagine that there was a reason for choosing uint32_t, and that this change could have unintended consequences. Has this been checked?

review: Needs Information
Revision history for this message
Robert Ancell (robert-ancell) wrote :

Approve as long as racarr doesn't indicate a problem with the uint32_t -> int change.

review: Approve
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

I just noticed bug 1188451 as a result of playing with movement...

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

> 220 - typedef uint32_t ValueType;
> 221 + typedef int ValueType;
>
> (and related uint_32 -> int changes)
>
> While these changes fix the problem mentioned here, I imagine that there was a
> reason for choosing uint32_t, and that this change could have unintended
> consequences. Has this been checked?

Alan,

Yes it's been checked to some extent:
1. No test case failures.
2. No visible regressions when running mir binaries.

Furthermore, you have theoretical peace of mind:
1. All the +,-,==,!= operators are unaffected by sign. They produce the same result regardless of the signedness of the operands.
2. Only the >,<,>=,<= might be affected in theory. But you'd have to be unlucky to use them in a way that they are affected and all testing so far has shown no change in behaviour.

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 :

No point in discussing any longer

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Did I do that?...
The following tests FAILED:
  72 - memcheck(unit-tests.ProtobufCommunicator.*) (Failed)
Errors while running CTest
make[2]: *** [test] Error 8

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'examples/demo-shell/CMakeLists.txt'
--- examples/demo-shell/CMakeLists.txt 2013-05-22 14:21:16 +0000
+++ examples/demo-shell/CMakeLists.txt 2013-06-10 06:32:24 +0000
@@ -1,7 +1,7 @@
1add_executable(mir_demo_server_shell1add_executable(mir_demo_server_shell
2 demo_shell.cpp2 demo_shell.cpp
3 fullscreen_placement_strategy.cpp3 fullscreen_placement_strategy.cpp
4 application_switcher.cpp4 window_manager.cpp
5)5)
66
7target_link_libraries(mir_demo_server_shell7target_link_libraries(mir_demo_server_shell
88
=== modified file 'examples/demo-shell/demo_shell.cpp'
--- examples/demo-shell/demo_shell.cpp 2013-04-29 17:39:12 +0000
+++ examples/demo-shell/demo_shell.cpp 2013-06-10 06:32:24 +0000
@@ -18,7 +18,7 @@
1818
19/// \example demo_shell.cpp A simple mir shell19/// \example demo_shell.cpp A simple mir shell
2020
21#include "application_switcher.h"21#include "window_manager.h"
22#include "fullscreen_placement_strategy.h"22#include "fullscreen_placement_strategy.h"
2323
24#include "mir/run_mir.h"24#include "mir/run_mir.h"
@@ -76,14 +76,15 @@
76int main(int argc, char const* argv[])76int main(int argc, char const* argv[])
77try77try
78{78{
79 auto app_switcher = std::make_shared<me::ApplicationSwitcher>();79 auto wm = std::make_shared<me::WindowManager>();
80 me::DemoServerConfiguration config(argc, argv, {app_switcher});80 me::DemoServerConfiguration config(argc, argv, {wm});
81 81
82 mir::run_mir(config, [&config, &app_switcher](mir::DisplayServer&)82 mir::run_mir(config, [&config, &wm](mir::DisplayServer&)
83 {83 {
84 // We use this strange two stage initialization to avoid a circular dependency between the EventFilters84 // We use this strange two stage initialization to avoid a circular dependency between the EventFilters
85 // and the SessionStore85 // and the SessionStore
86 app_switcher->set_focus_controller(config.the_focus_controller());86 wm->set_focus_controller(config.the_focus_controller());
87 wm->set_session_manager(config.the_session_manager());
87 });88 });
88 return 0;89 return 0;
89}90}
9091
=== renamed file 'examples/demo-shell/application_switcher.cpp' => 'examples/demo-shell/window_manager.cpp'
--- examples/demo-shell/application_switcher.cpp 2013-06-06 10:03:12 +0000
+++ examples/demo-shell/window_manager.cpp 2013-06-10 06:32:24 +0000
@@ -16,9 +16,12 @@
16 * Authored by: Robert Carr <robert.carr@canonical.com>16 * Authored by: Robert Carr <robert.carr@canonical.com>
17 */17 */
1818
19#include "application_switcher.h"19#include "window_manager.h"
2020
21#include "mir/shell/focus_controller.h"21#include "mir/shell/focus_controller.h"
22#include "mir/shell/session_manager.h"
23#include "mir/shell/session.h"
24#include "mir/shell/surface.h"
2225
23#include <linux/input.h>26#include <linux/input.h>
2427
@@ -27,16 +30,22 @@
27namespace me = mir::examples;30namespace me = mir::examples;
28namespace msh = mir::shell;31namespace msh = mir::shell;
2932
30me::ApplicationSwitcher::ApplicationSwitcher()33me::WindowManager::WindowManager()
31{34{
32}35}
3336
34void me::ApplicationSwitcher::set_focus_controller(std::shared_ptr<msh::FocusController> const& controller)37void me::WindowManager::set_focus_controller(std::shared_ptr<msh::FocusController> const& controller)
35{38{
36 focus_controller = controller;39 focus_controller = controller;
37}40}
3841
39bool me::ApplicationSwitcher::handle(MirEvent const& event)42void me::WindowManager::set_session_manager(
43 std::shared_ptr<msh::SessionManager> const& sm)
44{
45 session_manager = sm;
46}
47
48bool me::WindowManager::handle(MirEvent const& event)
40{49{
41 assert(focus_controller);50 assert(focus_controller);
4251
@@ -48,5 +57,37 @@
48 focus_controller->focus_next();57 focus_controller->focus_next();
49 return true;58 return true;
50 }59 }
60 else if (event.type == mir_event_type_motion &&
61 session_manager)
62 {
63 std::shared_ptr<msh::Session> app =
64 session_manager->focussed_application().lock();
65
66 if (app)
67 {
68 // FIXME: We need to be able to select individual surfaces in
69 // future and not just the "default" one.
70 std::shared_ptr<msh::Surface> surf = app->default_surface();
71
72 if (surf &&
73 event.motion.modifiers & mir_key_modifier_alt)
74 {
75 geometry::Point cursor{
76 geometry::X{event.motion.pointer_coordinates[0].x},
77 geometry::Y{event.motion.pointer_coordinates[0].y}};
78
79 if (event.motion.button_state == 0)
80 {
81 relative_click = cursor - surf->top_left();
82 }
83 else if (event.motion.button_state & mir_motion_button_primary)
84 {
85 geometry::Point abs = cursor - relative_click;
86 surf->move_to(abs);
87 return true;
88 }
89 }
90 }
91 }
51 return false;92 return false;
52}93}
5394
=== renamed file 'examples/demo-shell/application_switcher.h' => 'examples/demo-shell/window_manager.h'
--- examples/demo-shell/application_switcher.h 2013-06-06 10:03:12 +0000
+++ examples/demo-shell/window_manager.h 2013-06-10 06:32:24 +0000
@@ -16,10 +16,11 @@
16 * Authored by: Robert Carr <robert.carr@canonical.com>16 * Authored by: Robert Carr <robert.carr@canonical.com>
17 */17 */
1818
19#ifndef MIR_EXAMPLES_APPLICATION_SWITCHER_H_19#ifndef MIR_EXAMPLES_WINDOW_MANAGER_H_
20#define MIR_EXAMPLES_APPLICATION_SWITCHER_H_20#define MIR_EXAMPLES_WINDOW_MANAGER_H_
2121
22#include "mir/input/event_filter.h"22#include "mir/input/event_filter.h"
23#include "mir/geometry/displacement.h"
2324
24#include <memory>25#include <memory>
2526
@@ -28,29 +29,33 @@
28namespace shell29namespace shell
29{30{
30class FocusController;31class FocusController;
32class SessionManager;
31}33}
32namespace examples34namespace examples
33{35{
3436
35class ApplicationSwitcher : public input::EventFilter37class WindowManager : public input::EventFilter
36{38{
37public: 39public:
38 ApplicationSwitcher();40 WindowManager();
39 ~ApplicationSwitcher() = default;41 ~WindowManager() = default;
4042
41 void set_focus_controller(std::shared_ptr<shell::FocusController> const& focus_controller);43 void set_focus_controller(std::shared_ptr<shell::FocusController> const& focus_controller);
44 void set_session_manager(std::shared_ptr<shell::SessionManager> const& sm);
42 45
43 bool handle(MirEvent const& event) override;46 bool handle(MirEvent const& event) override;
4447
45protected:48protected:
46 ApplicationSwitcher(const ApplicationSwitcher&) = delete;49 WindowManager(const WindowManager&) = delete;
47 ApplicationSwitcher& operator=(const ApplicationSwitcher&) = delete;50 WindowManager& operator=(const WindowManager&) = delete;
4851
49private:52private:
50 std::shared_ptr<shell::FocusController> focus_controller;53 std::shared_ptr<shell::FocusController> focus_controller;
54 std::shared_ptr<shell::SessionManager> session_manager;
55 geometry::Displacement relative_click; // Click location in window space
51};56};
5257
53}58}
54} // namespace mir59} // namespace mir
5560
56#endif // MIR_EXAMPLES_APPLICATION_SWITCHER_H_61#endif // MIR_EXAMPLES_WINDOW_MANAGER_H_
5762
=== modified file 'include/server/mir/shell/session_manager.h'
--- include/server/mir/shell/session_manager.h 2013-05-28 14:34:35 +0000
+++ include/server/mir/shell/session_manager.h 2013-06-10 06:32:24 +0000
@@ -59,6 +59,7 @@
59 SurfaceCreationParameters const& params);59 SurfaceCreationParameters const& params);
6060
61 void focus_next();61 void focus_next();
62 std::weak_ptr<Session> focussed_application() const;
6263
63protected:64protected:
64 SessionManager(const SessionManager&) = delete;65 SessionManager(const SessionManager&) = delete;
6566
=== modified file 'include/server/mir/shell/surface.h'
--- include/server/mir/shell/surface.h 2013-05-28 15:44:18 +0000
+++ include/server/mir/shell/surface.h 2013-06-10 06:32:24 +0000
@@ -66,6 +66,8 @@
6666
67 virtual std::string name() const;67 virtual std::string name() const;
6868
69 virtual void move_to(geometry::Point const& top_left);
70
69 virtual geometry::Size size() const;71 virtual geometry::Size size() const;
70 virtual geometry::Point top_left() const;72 virtual geometry::Point top_left() const;
7173
7274
=== modified file 'include/shared/mir/geometry/dimensions.h'
--- include/shared/mir/geometry/dimensions.h 2013-04-24 05:22:20 +0000
+++ include/shared/mir/geometry/dimensions.h 2013-06-10 06:32:24 +0000
@@ -38,13 +38,17 @@
38class IntWrapper38class IntWrapper
39{39{
40public:40public:
41 typedef uint32_t ValueType;41 typedef int ValueType;
4242
43 IntWrapper() : value(0) {}43 IntWrapper() : value(0) {}
44 template<typename AnyInteger>44 template<typename AnyInteger>
45 explicit IntWrapper(AnyInteger value) : value(static_cast<ValueType>(value)) {}45 explicit IntWrapper(AnyInteger value) : value(static_cast<ValueType>(value)) {}
4646
47 uint32_t as_uint32_t() const47 uint32_t as_uint32_t() const // TODO: Deprecate this later
48 {
49 return (uint32_t)value;
50 }
51 int as_int() const
48 {52 {
49 return value;53 return value;
50 }54 }
@@ -60,44 +64,44 @@
60template<DimensionTag Tag>64template<DimensionTag Tag>
61std::ostream& operator<<(std::ostream& out, IntWrapper<Tag> const& value)65std::ostream& operator<<(std::ostream& out, IntWrapper<Tag> const& value)
62{66{
63 out << value.as_uint32_t();67 out << value.as_int();
64 return out;68 return out;
65}69}
6670
67template<DimensionTag Tag>71template<DimensionTag Tag>
68inline bool operator == (IntWrapper<Tag> const& lhs, IntWrapper<Tag> const& rhs)72inline bool operator == (IntWrapper<Tag> const& lhs, IntWrapper<Tag> const& rhs)
69{73{
70 return lhs.as_uint32_t() == rhs.as_uint32_t();74 return lhs.as_int() == rhs.as_int();
71}75}
7276
73template<DimensionTag Tag>77template<DimensionTag Tag>
74inline bool operator != (IntWrapper<Tag> const& lhs, IntWrapper<Tag> const& rhs)78inline bool operator != (IntWrapper<Tag> const& lhs, IntWrapper<Tag> const& rhs)
75{79{
76 return lhs.as_uint32_t() != rhs.as_uint32_t();80 return lhs.as_int() != rhs.as_int();
77}81}
7882
79template<DimensionTag Tag>83template<DimensionTag Tag>
80inline bool operator <= (IntWrapper<Tag> const& lhs, IntWrapper<Tag> const& rhs)84inline bool operator <= (IntWrapper<Tag> const& lhs, IntWrapper<Tag> const& rhs)
81{85{
82 return lhs.as_uint32_t() <= rhs.as_uint32_t();86 return lhs.as_int() <= rhs.as_int();
83}87}
8488
85template<DimensionTag Tag>89template<DimensionTag Tag>
86inline bool operator >= (IntWrapper<Tag> const& lhs, IntWrapper<Tag> const& rhs)90inline bool operator >= (IntWrapper<Tag> const& lhs, IntWrapper<Tag> const& rhs)
87{91{
88 return lhs.as_uint32_t() >= rhs.as_uint32_t();92 return lhs.as_int() >= rhs.as_int();
89}93}
9094
91template<DimensionTag Tag>95template<DimensionTag Tag>
92inline bool operator < (IntWrapper<Tag> const& lhs, IntWrapper<Tag> const& rhs)96inline bool operator < (IntWrapper<Tag> const& lhs, IntWrapper<Tag> const& rhs)
93{97{
94 return lhs.as_uint32_t() < rhs.as_uint32_t();98 return lhs.as_int() < rhs.as_int();
95}99}
96100
97template<DimensionTag Tag>101template<DimensionTag Tag>
98inline bool operator > (IntWrapper<Tag> const& lhs, IntWrapper<Tag> const& rhs)102inline bool operator > (IntWrapper<Tag> const& lhs, IntWrapper<Tag> const& rhs)
99{103{
100 return lhs.as_uint32_t() > rhs.as_uint32_t();104 return lhs.as_int() > rhs.as_int();
101}105}
102} // namespace detail106} // namespace detail
103107
@@ -111,23 +115,23 @@
111typedef detail::IntWrapper<detail::dy> DeltaY;115typedef detail::IntWrapper<detail::dy> DeltaY;
112116
113// Adding deltas is fine117// Adding deltas is fine
114inline DeltaX operator+(DeltaX lhs, DeltaX rhs) { return DeltaX(lhs.as_uint32_t() + rhs.as_uint32_t()); }118inline DeltaX operator+(DeltaX lhs, DeltaX rhs) { return DeltaX(lhs.as_int() + rhs.as_int()); }
115inline DeltaY operator+(DeltaY lhs, DeltaY rhs) { return DeltaY(lhs.as_uint32_t() + rhs.as_uint32_t()); }119inline DeltaY operator+(DeltaY lhs, DeltaY rhs) { return DeltaY(lhs.as_int() + rhs.as_int()); }
116inline DeltaX operator-(DeltaX lhs, DeltaX rhs) { return DeltaX(lhs.as_uint32_t() - rhs.as_uint32_t()); }120inline DeltaX operator-(DeltaX lhs, DeltaX rhs) { return DeltaX(lhs.as_int() - rhs.as_int()); }
117inline DeltaY operator-(DeltaY lhs, DeltaY rhs) { return DeltaY(lhs.as_uint32_t() - rhs.as_uint32_t()); }121inline DeltaY operator-(DeltaY lhs, DeltaY rhs) { return DeltaY(lhs.as_int() - rhs.as_int()); }
118122
119// Adding deltas to co-ordinates is fine123// Adding deltas to co-ordinates is fine
120inline X operator+(X lhs, DeltaX rhs) { return X(lhs.as_uint32_t() + rhs.as_uint32_t()); }124inline X operator+(X lhs, DeltaX rhs) { return X(lhs.as_int() + rhs.as_int()); }
121inline Y operator+(Y lhs, DeltaY rhs) { return Y(lhs.as_uint32_t() + rhs.as_uint32_t()); }125inline Y operator+(Y lhs, DeltaY rhs) { return Y(lhs.as_int() + rhs.as_int()); }
122inline X operator-(X lhs, DeltaX rhs) { return X(lhs.as_uint32_t() - rhs.as_uint32_t()); }126inline X operator-(X lhs, DeltaX rhs) { return X(lhs.as_int() - rhs.as_int()); }
123inline Y operator-(Y lhs, DeltaY rhs) { return Y(lhs.as_uint32_t() - rhs.as_uint32_t()); }127inline Y operator-(Y lhs, DeltaY rhs) { return Y(lhs.as_int() - rhs.as_int()); }
124128
125// Subtracting coordinates is fine129// Subtracting coordinates is fine
126inline DeltaX operator-(X lhs, X rhs) { return DeltaX(lhs.as_uint32_t() - rhs.as_uint32_t()); }130inline DeltaX operator-(X lhs, X rhs) { return DeltaX(lhs.as_int() - rhs.as_int()); }
127inline DeltaY operator-(Y lhs, Y rhs) { return DeltaY(lhs.as_uint32_t() - rhs.as_uint32_t()); }131inline DeltaY operator-(Y lhs, Y rhs) { return DeltaY(lhs.as_int() - rhs.as_int()); }
128132
129template<typename Target, typename Source>133template<typename Target, typename Source>
130inline Target dim_cast(Source s) { return Target(s.as_uint32_t()); }134inline Target dim_cast(Source s) { return Target(s.as_int()); }
131}135}
132}136}
133137
134138
=== modified file 'src/server/shell/session_manager.cpp'
--- src/server/shell/session_manager.cpp 2013-05-28 14:34:35 +0000
+++ src/server/shell/session_manager.cpp 2013-06-10 06:32:24 +0000
@@ -128,6 +128,11 @@
128 set_focus_to_locked(lock, focus);128 set_focus_to_locked(lock, focus);
129}129}
130130
131std::weak_ptr<msh::Session> msh::SessionManager::focussed_application() const
132{
133 return focus_application;
134}
135
131mf::SurfaceId msh::SessionManager::create_surface_for(std::shared_ptr<mf::Session> const& session,136mf::SurfaceId msh::SessionManager::create_surface_for(std::shared_ptr<mf::Session> const& session,
132 msh::SurfaceCreationParameters const& params)137 msh::SurfaceCreationParameters const& params)
133{138{
134139
=== modified file 'src/server/shell/surface.cpp'
--- src/server/shell/surface.cpp 2013-05-28 15:44:18 +0000
+++ src/server/shell/surface.cpp 2013-06-10 06:32:24 +0000
@@ -109,6 +109,18 @@
109 }109 }
110}110}
111111
112void msh::Surface::move_to(geometry::Point const& p)
113{
114 if (auto const& s = surface.lock())
115 {
116 s->move_to(p);
117 }
118 else
119 {
120 BOOST_THROW_EXCEPTION(std::runtime_error("Invalid surface"));
121 }
122}
123
112mir::geometry::Point msh::Surface::top_left() const124mir::geometry::Point msh::Surface::top_left() const
113{125{
114 if (auto const& s = surface.lock())126 if (auto const& s = surface.lock())
115127
=== modified file 'src/server/surfaces/surface.cpp'
--- src/server/surfaces/surface.cpp 2013-05-22 17:36:47 +0000
+++ src/server/surfaces/surface.cpp 2013-06-10 06:32:24 +0000
@@ -113,8 +113,8 @@
113{113{
114 const geom::Size sz = size();114 const geom::Size sz = size();
115115
116 const glm::vec3 top_left_vec{top_left_point.x.as_uint32_t(),116 const glm::vec3 top_left_vec{top_left_point.x.as_int(),
117 top_left_point.y.as_uint32_t(),117 top_left_point.y.as_int(),
118 0.0f};118 0.0f};
119 const glm::vec3 size_vec{sz.width.as_uint32_t(),119 const glm::vec3 size_vec{sz.width.as_uint32_t(),
120 sz.height.as_uint32_t(),120 sz.height.as_uint32_t(),
121121
=== modified file 'tests/unit-tests/geometry/test-dimensions.cpp'
--- tests/unit-tests/geometry/test-dimensions.cpp 2012-09-18 09:44:45 +0000
+++ tests/unit-tests/geometry/test-dimensions.cpp 2013-06-10 06:32:24 +0000
@@ -89,3 +89,47 @@
89 EXPECT_EQ(dx1, dim_cast<DeltaX>(w1));89 EXPECT_EQ(dx1, dim_cast<DeltaX>(w1));
90 EXPECT_NE(dx1, dim_cast<DeltaX>(X()));90 EXPECT_NE(dx1, dim_cast<DeltaX>(X()));
91}91}
92
93TEST(geometry, signed_dimensions)
94{
95 using namespace geom;
96
97 X const x0{0};
98 X const x2{2};
99 X const xn5{-5};
100 Y const y0{0};
101 Y const y3{3};
102 Y const yn6{-6};
103 Y const yn7{-7};
104
105 // Compare against zero to catch regressions of signed->unsigned that
106 // wouldn't be caught using as_*int()...
107 EXPECT_GT(x0, xn5);
108 EXPECT_GT(y0, yn7);
109
110 EXPECT_LT(xn5, x0);
111 EXPECT_LT(xn5, x2);
112 EXPECT_LT(yn7, yn6);
113 EXPECT_LT(yn7, y0);
114 EXPECT_LT(yn7, y3);
115
116 EXPECT_LE(xn5, x0);
117 EXPECT_LE(xn5, x2);
118 EXPECT_LE(yn7, yn6);
119 EXPECT_LE(yn7, y0);
120 EXPECT_LE(yn7, y3);
121 EXPECT_LE(yn7, yn7);
122
123 EXPECT_GT(x0, xn5);
124 EXPECT_GT(x2, xn5);
125 EXPECT_GT(yn6, yn7);
126 EXPECT_GT(y0, yn7);
127 EXPECT_GT(y3, yn7);
128
129 EXPECT_GE(x0, xn5);
130 EXPECT_GE(x2, xn5);
131 EXPECT_GE(yn6, yn7);
132 EXPECT_GE(y0, yn7);
133 EXPECT_GE(y3, yn7);
134 EXPECT_GE(yn7, yn7);
135}
92136
=== modified file 'tests/unit-tests/geometry/test-displacement.cpp'
--- tests/unit-tests/geometry/test-displacement.cpp 2013-03-21 03:32:59 +0000
+++ tests/unit-tests/geometry/test-displacement.cpp 2013-06-10 06:32:24 +0000
@@ -62,16 +62,23 @@
62 Point const x2y4{X{2}, Y{4}};62 Point const x2y4{X{2}, Y{4}};
63 Point const x3y9{X{3}, Y{9}};63 Point const x3y9{X{3}, Y{9}};
64 Displacement const dx2dy4{DeltaX{2}, DeltaY{4}};64 Displacement const dx2dy4{DeltaX{2}, DeltaY{4}};
65 Displacement const dx7dy11{DeltaX{7}, DeltaY{11}};
6566
66 Point const expected_pd_add{X{5}, Y{13}};67 Point const expected_pd_add{X{5}, Y{13}};
67 Point const expected_pd_sub{X{1}, Y{5}};68 Point const expected_pd_sub{X{1}, Y{5}};
69 Point const expected_pd_sub2{X{-4}, Y{-2}};
68 Displacement const expected_pp_sub{DeltaX{1}, DeltaY{5}};70 Displacement const expected_pp_sub{DeltaX{1}, DeltaY{5}};
71 Displacement const expected_pp_sub2{DeltaX{-1}, DeltaY{-5}};
6972
70 Point const pd_add = x3y9 + dx2dy4;73 Point const pd_add = x3y9 + dx2dy4;
71 Point const pd_sub = x3y9 - dx2dy4;74 Point const pd_sub = x3y9 - dx2dy4;
75 Point const pd_sub2 = x3y9 - dx7dy11;
72 Displacement const pp_sub = x3y9 - x2y4;76 Displacement const pp_sub = x3y9 - x2y4;
77 Displacement const pp_sub2 = x2y4 - x3y9;
7378
74 EXPECT_EQ(expected_pd_add, pd_add);79 EXPECT_EQ(expected_pd_add, pd_add);
75 EXPECT_EQ(expected_pd_sub, pd_sub);80 EXPECT_EQ(expected_pd_sub, pd_sub);
81 EXPECT_EQ(expected_pd_sub2, pd_sub2);
76 EXPECT_EQ(expected_pp_sub, pp_sub);82 EXPECT_EQ(expected_pp_sub, pp_sub);
83 EXPECT_EQ(expected_pp_sub2, pp_sub2);
77}84}

Subscribers

People subscribed via source and target branches