~ubuntu-branches/ubuntu/wily/mir/wily-proposed

« back to all changes in this revision

Viewing changes to tests/unit-tests/input/test_xcursor_loader.cpp

  • Committer: Package Import Robot
  • Author(s): Alexandros Frantzis
  • Date: 2015-10-08 16:12:19 UTC
  • mto: This revision was merged to the branch mainline in revision 109.
  • Revision ID: package-import@ubuntu.com-20151008161219-emk4a1ys51yy0wjb
Tags: upstream-0.17.0+15.10.20151008.2
ImportĀ upstreamĀ versionĀ 0.17.0+15.10.20151008.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include "mir/graphics/cursor_image.h"
22
22
#include "mir_test_framework/executable_path.h"
 
23
#include "mir_test_framework/temporary_environment_value.h"
23
24
 
24
25
#include <mir_toolkit/common.h>
25
26
#include <mir_toolkit/cursors.h>
34
35
 
35
36
namespace mi = mir::input;
36
37
namespace mg = mir::graphics;
 
38
namespace mtf = mir_test_framework;
 
39
 
 
40
namespace
 
41
{
 
42
std::string const test_cursor_path{mir_test_framework::executable_path() + std::string("/testing-cursor-theme")};
 
43
}
 
44
 
 
45
// Warning, XCURSOR_PATH will only be checked ONCE by libxcursor due to static var
 
46
class XCursorLoaderTest : public ::testing::Test
 
47
{
 
48
public:
 
49
    XCursorLoaderTest()
 
50
        : xcursor_path("XCURSOR_PATH", test_cursor_path.c_str())
 
51
    {
 
52
    }
 
53
 
 
54
    mtf::TemporaryEnvironmentValue xcursor_path;
 
55
    mi::XCursorLoader loader;
 
56
};
37
57
 
38
58
namespace
39
59
{
82
102
{
83
103
    return cursor_image_is_solid_color(arg, 0xff000000);
84
104
}
85
 
 
86
 
char *old_xcursor_path = nullptr;
87
 
void set_xcursor_path()
88
 
{
89
 
    char const* old = getenv("XCURSOR_PATH");
90
 
    if (old)
91
 
        old_xcursor_path = strdup(old);
92
 
    auto test_cursor_path =mir_test_framework::executable_path() + std::string("/testing-cursor-theme");
93
 
    setenv("XCURSOR_PATH", test_cursor_path.c_str(), 1);
94
 
}
95
 
 
96
 
void restore_xcursor_path()
97
 
{
98
 
    if (old_xcursor_path)
99
 
    {
100
 
        setenv("XCURSOR_PATH", old_xcursor_path, 1);
101
 
        free(old_xcursor_path);
102
 
    }
103
 
}
104
 
 
105
 
}
106
 
 
107
 
TEST(XCursorLoader, loads_cursors_from_testing_theme)
108
 
{
109
 
    set_xcursor_path();
110
 
 
111
 
    mi::XCursorLoader loader;
112
 
    
 
105
}
 
106
 
 
107
TEST_F(XCursorLoaderTest, loads_cursors_from_testing_theme)
 
108
{
113
109
    auto size = mi::default_cursor_size;
114
110
    auto red_image = loader.image("red", size);
115
111
    auto blue_image = loader.image("blue", size);
121
117
    EXPECT_THAT(red_image, IsSolidRed());
122
118
    EXPECT_THAT(green_image, IsSolidGreen());
123
119
    EXPECT_THAT(blue_image, IsSolidBlue());
124
 
    
125
 
    restore_xcursor_path();
126
120
}
127
121
 
128
 
TEST(XCursorLoader, only_supports_the_default_size)
 
122
TEST_F(XCursorLoaderTest, only_supports_the_default_size)
129
123
{
130
 
    mi::XCursorLoader loader;
131
 
    
132
124
    EXPECT_THROW({
133
125
            loader.image("red", {100, 100});
134
126
    }, std::logic_error);
135
127
}
136
128
 
137
 
TEST(XCursorLoader, default_image_is_arrow_from_xcursor_theme)
 
129
TEST_F(XCursorLoaderTest, default_image_is_arrow_from_xcursor_theme)
138
130
{
139
 
    set_xcursor_path();
140
 
 
141
 
    mi::XCursorLoader loader;
142
 
    
143
131
    auto size = mi::default_cursor_size;
144
132
    auto arrow_image = loader.image(mir_default_cursor_name, size);
145
133
 
147
135
    // name.
148
136
    ASSERT_THAT(arrow_image, HasLoaded());
149
137
    EXPECT_THAT(arrow_image, IsSolidBlack());
150
 
    
151
 
    restore_xcursor_path();
152
138
}
153
139
 
154
 
TEST(XCursorLoader, symbolic_names_which_are_not_present_resolve_to_default)
 
140
TEST_F(XCursorLoaderTest, symbolic_names_which_are_not_present_resolve_to_default)
155
141
{
156
 
    set_xcursor_path();
157
 
 
158
 
    mi::XCursorLoader loader;
159
 
    
160
142
    auto size = mi::default_cursor_size;
161
143
    auto default_image = loader.image(mir_default_cursor_name, size);
162
144
    auto image_with_made_up_name = loader.image("Artickrumbulis", size);
163
145
 
164
146
    EXPECT_EQ(default_image, image_with_made_up_name);
165
 
    
166
 
    restore_xcursor_path();
167
147
}