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

« back to all changes in this revision

Viewing changes to tests/unit-tests/client/mesa/test_native_surface.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-01-08 02:04:38 UTC
  • mto: This revision was merged to the branch mainline in revision 58.
  • Revision ID: package-import@ubuntu.com-20140108020438-e1npu0pm7qdv5wc4
Tags: upstream-0.1.3+14.04.20140108
Import upstream version 0.1.3+14.04.20140108

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2013 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License version 3 as
 
6
 * published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
 
17
 */
 
18
 
 
19
#include "src/client/mesa/native_surface.h"
 
20
#include "src/client/client_buffer.h"
 
21
#include "mir_test_doubles/mock_client_surface.h"
 
22
 
 
23
#include <gmock/gmock.h>
 
24
#include <gtest/gtest.h>
 
25
 
 
26
namespace mtd=mir::test::doubles;
 
27
namespace mcl=mir::client;
 
28
namespace mcl=mir::client;
 
29
namespace mclg=mir::client::mesa;
 
30
namespace geom=mir::geometry;
 
31
 
 
32
namespace
 
33
{
 
34
 
 
35
struct MockClientBuffer : public mcl::ClientBuffer
 
36
{
 
37
    MockClientBuffer()
 
38
    {
 
39
        ON_CALL(*this, native_buffer_handle())
 
40
            .WillByDefault(testing::Return(std::make_shared<MirBufferPackage>()));
 
41
    }
 
42
    ~MockClientBuffer() noexcept {}
 
43
 
 
44
    MOCK_METHOD0(secure_for_cpu_write, std::shared_ptr<mcl::MemoryRegion>());
 
45
    MOCK_CONST_METHOD0(size, geom::Size());
 
46
    MOCK_CONST_METHOD0(stride, geom::Stride());
 
47
    MOCK_CONST_METHOD0(pixel_format, MirPixelFormat());
 
48
 
 
49
    MOCK_CONST_METHOD0(age, uint32_t());
 
50
    MOCK_METHOD0(mark_as_submitted, void());
 
51
    MOCK_METHOD0(increment_age, void());
 
52
 
 
53
    MOCK_CONST_METHOD0(native_buffer_handle, std::shared_ptr<MirNativeBuffer>());
 
54
};
 
55
 
 
56
}
 
57
 
 
58
class MesaClientNativeSurfaceTest : public ::testing::Test
 
59
{
 
60
public:
 
61
    virtual void SetUp()
 
62
    {
 
63
        using namespace testing;
 
64
        surf_params.width = 530;
 
65
        surf_params.height = 715;
 
66
        surf_params.pixel_format = mir_pixel_format_abgr_8888;
 
67
 
 
68
        ON_CALL(mock_surface, get_parameters())
 
69
            .WillByDefault(Return(surf_params));
 
70
        ON_CALL(mock_surface, get_current_buffer())
 
71
            .WillByDefault(Return(
 
72
                std::make_shared<NiceMock<MockClientBuffer>>()));
 
73
    }
 
74
 
 
75
    MirSurfaceParameters surf_params;
 
76
    testing::NiceMock<mtd::MockClientSurface> mock_surface;
 
77
};
 
78
 
 
79
TEST_F(MesaClientNativeSurfaceTest, basic_parameters)
 
80
{
 
81
    mclg::NativeSurface interpreter(mock_surface);
 
82
 
 
83
    MirSurfaceParameters params;
 
84
    interpreter.surface_get_parameters(&interpreter, &params);
 
85
    EXPECT_EQ(surf_params.width, params.width);
 
86
    EXPECT_EQ(surf_params.height, params.height);
 
87
    EXPECT_EQ(surf_params.pixel_format, params.pixel_format);
 
88
}
 
89
 
 
90
TEST_F(MesaClientNativeSurfaceTest, basic_advance)
 
91
{
 
92
    using namespace testing;
 
93
    MirBufferPackage buffer_package;
 
94
    EXPECT_CALL(mock_surface, next_buffer(_,_))
 
95
        .Times(1);
 
96
    EXPECT_CALL(mock_surface, get_current_buffer())
 
97
        .Times(1);
 
98
 
 
99
    mclg::NativeSurface interpreter(mock_surface);
 
100
    interpreter.surface_advance_buffer(&interpreter, &buffer_package);
 
101
}
 
102
 
 
103
TEST_F(MesaClientNativeSurfaceTest, swapinterval_request)
 
104
{
 
105
    using namespace testing;
 
106
 
 
107
    Sequence seq;
 
108
    EXPECT_CALL(mock_surface, configure(mir_surface_attrib_swapinterval,0))
 
109
        .InSequence(seq);
 
110
    EXPECT_CALL(mock_surface, configure(mir_surface_attrib_swapinterval,1))
 
111
        .InSequence(seq);
 
112
 
 
113
    mclg::NativeSurface interpreter(mock_surface);
 
114
    interpreter.set_swapinterval(0);
 
115
    interpreter.set_swapinterval(1);
 
116
}
 
117
 
 
118
TEST_F(MesaClientNativeSurfaceTest, swapinterval_unsupported_request)
 
119
{
 
120
    mclg::NativeSurface interpreter(mock_surface);
 
121
    EXPECT_EQ(MIR_MESA_FALSE, interpreter.set_swapinterval(-1));
 
122
    EXPECT_EQ(MIR_MESA_TRUE, interpreter.set_swapinterval(0));
 
123
    EXPECT_EQ(MIR_MESA_TRUE, interpreter.set_swapinterval(1));
 
124
    EXPECT_EQ(MIR_MESA_FALSE, interpreter.set_swapinterval(2));
 
125
}