~andreas-pokorny/mir/activate-pointer-acceleration

« back to all changes in this revision

Viewing changes to tests/unit-tests/client/test_client_buffer_stream.cpp

  • Committer: Christopher James Halse Rogers
  • Date: 2015-02-12 05:55:17 UTC
  • mfrom: (2314 development-branch)
  • mto: This revision was merged to the branch mainline in revision 2326.
  • Revision ID: christopher.halse.rogers@canonical.com-20150212055517-4ebh62tbmq4co2m8
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include "src/client/buffer_stream.h"
20
20
#include "src/client/perf_report.h"
21
21
 
22
 
#include "mir/egl_native_window_factory.h"
 
22
#include "mir/client_platform.h"
23
23
 
24
24
#include "mir_test_doubles/null_client_buffer.h"
25
25
#include "mir_test_doubles/mock_client_buffer_factory.h"
27
27
#include "mir_test_doubles/null_logger.h"
28
28
#include "mir_test/fake_shared.h"
29
29
 
30
 
#include <mir_toolkit/mir_client_library.h>
 
30
#include "mir_toolkit/mir_client_library.h"
31
31
 
32
32
#include <gtest/gtest.h>
33
33
#include <gmock/gmock.h>
36
36
 
37
37
namespace mp = mir::protobuf;
38
38
namespace ml = mir::logging;
 
39
namespace mg = mir::graphics;
39
40
namespace mcl = mir::client;
40
41
namespace geom = mir::geometry;
41
42
 
59
60
                      google::protobuf::Closure* /*done*/));
60
61
};
61
62
 
62
 
struct StubEGLNativeWindowFactory : public mcl::EGLNativeWindowFactory
 
63
struct StubClientPlatform : public mcl::ClientPlatform
63
64
{
64
 
    std::shared_ptr<EGLNativeWindowType>
65
 
        create_egl_native_window(mcl::EGLNativeSurface*)
 
65
    StubClientPlatform(
 
66
        std::shared_ptr<mcl::ClientBufferFactory> const& bf)
 
67
        : buffer_factory(bf)
 
68
    {
 
69
    }
 
70
    MirPlatformType platform_type() const override
 
71
    {
 
72
        return MirPlatformType();
 
73
    }
 
74
    void populate(MirPlatformPackage& /* package */) const override
 
75
    {
 
76
    }
 
77
    std::shared_ptr<EGLNativeWindowType> create_egl_native_window(mcl::EGLNativeSurface * /* surface */) override
66
78
    {
67
79
        return std::make_shared<EGLNativeWindowType>(egl_native_window);
68
80
    }
 
81
    std::shared_ptr<EGLNativeDisplayType> create_egl_native_display() override
 
82
    {
 
83
        return nullptr;
 
84
    }
 
85
    MirNativeBuffer* convert_native_buffer(mg::NativeBuffer*) const override
 
86
    {
 
87
        return nullptr;
 
88
    }
69
89
 
 
90
    std::shared_ptr<mcl::ClientBufferFactory> create_buffer_factory() override
 
91
    {
 
92
        return buffer_factory;
 
93
    }
 
94
    MirPlatformMessage* platform_operation(MirPlatformMessage const* /* request */)
 
95
    {
 
96
        return nullptr;
 
97
    }
70
98
    static EGLNativeWindowType egl_native_window;
 
99
    std::shared_ptr<mcl::ClientBufferFactory> const buffer_factory;
71
100
};
72
101
 
73
102
struct MockPerfReport : public mcl::PerfReport
82
111
    MOCK_METHOD0(secure_for_cpu_write, std::shared_ptr<mcl::MemoryRegion>());
83
112
};
84
113
 
85
 
EGLNativeWindowType StubEGLNativeWindowFactory::egl_native_window{
86
 
    reinterpret_cast<EGLNativeWindowType>(&StubEGLNativeWindowFactory::egl_native_window)};
 
114
EGLNativeWindowType StubClientPlatform::egl_native_window{
 
115
    reinterpret_cast<EGLNativeWindowType>(&StubClientPlatform::egl_native_window)};
87
116
 
88
117
struct ClientBufferStreamTest : public testing::Test
89
118
{
90
119
    mtd::MockClientBufferFactory mock_client_buffer_factory;
91
120
    mtd::StubClientBufferFactory stub_client_buffer_factory;
92
121
 
93
 
    StubEGLNativeWindowFactory stub_native_window_factory;
94
122
    MockProtobufServer mock_protobuf_server;
95
123
 
96
124
    MirPixelFormat const default_pixel_format = mir_pixel_format_argb_8888;
107
135
        mcl::ClientBufferFactory& buffer_factory,
108
136
        mcl::BufferStreamMode mode=mcl::BufferStreamMode::Producer)
109
137
    {
110
 
        return std::make_shared<mcl::BufferStream>(mock_protobuf_server, mode, mt::fake_shared(buffer_factory),
111
 
            mt::fake_shared(stub_native_window_factory), protobuf_bs, perf_report, "");
 
138
        return std::make_shared<mcl::BufferStream>(mock_protobuf_server, mode,
 
139
            std::make_shared<StubClientPlatform>(mt::fake_shared(buffer_factory)), protobuf_bs, perf_report, "");
112
140
    }
113
141
};
114
142
 
386
414
    auto bs = make_buffer_stream(protobuf_bs);
387
415
    auto egl_native_window = bs->egl_native_window();
388
416
 
389
 
    EXPECT_EQ(StubEGLNativeWindowFactory::egl_native_window, egl_native_window);
 
417
    EXPECT_EQ(StubClientPlatform::egl_native_window, egl_native_window);
390
418
}
391
419
 
392
420
TEST_F(ClientBufferStreamTest, map_graphics_region)
424
452
    EXPECT_CALL(mock_perf_report, name_surface(StrEq(name))).Times(1);
425
453
 
426
454
    auto bs = std::make_shared<mcl::BufferStream>(mock_protobuf_server, mcl::BufferStreamMode::Producer,
427
 
                  mt::fake_shared(stub_client_buffer_factory), mt::fake_shared(stub_native_window_factory),
428
 
                  protobuf_bs, mt::fake_shared(mock_perf_report), name);
 
455
        std::make_shared<StubClientPlatform>(mt::fake_shared(stub_client_buffer_factory)),
 
456
        protobuf_bs, mt::fake_shared(mock_perf_report), name);
429
457
}