Mir

Merge lp:~brandontschaefer/mir/xcursor-test-cleanup into lp:mir

Proposed by Brandon Schaefer
Status: Merged
Approved by: Alan Griffiths
Approved revision: no longer in the source branch.
Merged at revision: 2968
Proposed branch: lp:~brandontschaefer/mir/xcursor-test-cleanup
Merge into: lp:mir
Diff against target: 127 lines (+27/-47)
1 file modified
tests/unit-tests/input/test_xcursor_loader.cpp (+27/-47)
To merge this branch: bzr merge lp:~brandontschaefer/mir/xcursor-test-cleanup
Reviewer Review Type Date Requested Status
Alan Griffiths Approve
Alexandros Frantzis (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+272513@code.launchpad.net

Commit message

Make a testing class + move to use a temp env variable vs manually doing it.

Description of the change

Make a testing class + move to use a temp env variable vs manually doing it.

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 :

Looks good.

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

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/unit-tests/input/test_xcursor_loader.cpp'
2--- tests/unit-tests/input/test_xcursor_loader.cpp 2015-04-28 07:54:10 +0000
3+++ tests/unit-tests/input/test_xcursor_loader.cpp 2015-09-26 05:41:49 +0000
4@@ -20,6 +20,7 @@
5
6 #include "mir/graphics/cursor_image.h"
7 #include "mir_test_framework/executable_path.h"
8+#include "mir_test_framework/temporary_environment_value.h"
9
10 #include <mir_toolkit/common.h>
11 #include <mir_toolkit/cursors.h>
12@@ -34,6 +35,25 @@
13
14 namespace mi = mir::input;
15 namespace mg = mir::graphics;
16+namespace mtf = mir_test_framework;
17+
18+namespace
19+{
20+std::string const test_cursor_path{mir_test_framework::executable_path() + std::string("/testing-cursor-theme")};
21+}
22+
23+// Warning, XCURSOR_PATH will only be checked ONCE by libxcursor due to static var
24+class XCursorLoaderTest : public ::testing::Test
25+{
26+public:
27+ XCursorLoaderTest()
28+ : xcursor_path("XCURSOR_PATH", test_cursor_path.c_str())
29+ {
30+ }
31+
32+ mtf::TemporaryEnvironmentValue xcursor_path;
33+ mi::XCursorLoader loader;
34+};
35
36 namespace
37 {
38@@ -82,34 +102,10 @@
39 {
40 return cursor_image_is_solid_color(arg, 0xff000000);
41 }
42-
43-char *old_xcursor_path = nullptr;
44-void set_xcursor_path()
45-{
46- char const* old = getenv("XCURSOR_PATH");
47- if (old)
48- old_xcursor_path = strdup(old);
49- auto test_cursor_path =mir_test_framework::executable_path() + std::string("/testing-cursor-theme");
50- setenv("XCURSOR_PATH", test_cursor_path.c_str(), 1);
51-}
52-
53-void restore_xcursor_path()
54-{
55- if (old_xcursor_path)
56- {
57- setenv("XCURSOR_PATH", old_xcursor_path, 1);
58- free(old_xcursor_path);
59- }
60-}
61-
62-}
63-
64-TEST(XCursorLoader, loads_cursors_from_testing_theme)
65-{
66- set_xcursor_path();
67-
68- mi::XCursorLoader loader;
69-
70+}
71+
72+TEST_F(XCursorLoaderTest, loads_cursors_from_testing_theme)
73+{
74 auto size = mi::default_cursor_size;
75 auto red_image = loader.image("red", size);
76 auto blue_image = loader.image("blue", size);
77@@ -121,25 +117,17 @@
78 EXPECT_THAT(red_image, IsSolidRed());
79 EXPECT_THAT(green_image, IsSolidGreen());
80 EXPECT_THAT(blue_image, IsSolidBlue());
81-
82- restore_xcursor_path();
83 }
84
85-TEST(XCursorLoader, only_supports_the_default_size)
86+TEST_F(XCursorLoaderTest, only_supports_the_default_size)
87 {
88- mi::XCursorLoader loader;
89-
90 EXPECT_THROW({
91 loader.image("red", {100, 100});
92 }, std::logic_error);
93 }
94
95-TEST(XCursorLoader, default_image_is_arrow_from_xcursor_theme)
96+TEST_F(XCursorLoaderTest, default_image_is_arrow_from_xcursor_theme)
97 {
98- set_xcursor_path();
99-
100- mi::XCursorLoader loader;
101-
102 auto size = mi::default_cursor_size;
103 auto arrow_image = loader.image(mir_default_cursor_name, size);
104
105@@ -147,21 +135,13 @@
106 // name.
107 ASSERT_THAT(arrow_image, HasLoaded());
108 EXPECT_THAT(arrow_image, IsSolidBlack());
109-
110- restore_xcursor_path();
111 }
112
113-TEST(XCursorLoader, symbolic_names_which_are_not_present_resolve_to_default)
114+TEST_F(XCursorLoaderTest, symbolic_names_which_are_not_present_resolve_to_default)
115 {
116- set_xcursor_path();
117-
118- mi::XCursorLoader loader;
119-
120 auto size = mi::default_cursor_size;
121 auto default_image = loader.image(mir_default_cursor_name, size);
122 auto image_with_made_up_name = loader.image("Artickrumbulis", size);
123
124 EXPECT_EQ(default_image, image_with_made_up_name);
125-
126- restore_xcursor_path();
127 }

Subscribers

People subscribed via source and target branches