~sil2100/compiz-core/scale_all-0.9.7

« back to all changes in this revision

Viewing changes to plugins/decor/src/pixmap-requests/tests/pixmap-requests/src/test-decor-pixmap-requests.cpp

  • Committer: Daniel van Vugt
  • Author(s): smspillaz
  • Date: 2012-06-19 05:31:31 UTC
  • mfrom: (3102.1.1 0.9.7)
  • Revision ID: daniel.van.vugt@canonical.com-20120619053131-7jzpk3u38wozxcrz
Cherry-picked from lp:compiz r3137:
Add synchronization primitives to the decoration protocol so that there
isn't a race where we bind a texture that's being freed.
(LP: #454218) (LP: #929989)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2012 Canonical Ltd.
 
3
 *
 
4
 * Permission to use, copy, modify, distribute, and sell this software
 
5
 * and its documentation for any purpose is hereby granted without
 
6
 * fee, provided that the above copyright notice appear in all copies
 
7
 * and that both that copyright notice and this permission notice
 
8
 * appear in supporting documentation, and that the name of
 
9
 * Canonical Ltd. not be used in advertising or publicity pertaining to
 
10
 * distribution of the software without specific, written prior permission.
 
11
 * Canonical Ltd. makes no representations about the suitability of this
 
12
 * software for any purpose. It is provided "as is" without express or
 
13
 * implied warranty.
 
14
 *
 
15
 * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
16
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
 
17
 * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
18
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
 
19
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 
20
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 
21
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
22
 *
 
23
 * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
 
24
 */
 
25
 
 
26
#include <gtest/gtest.h>
 
27
#include <gmock/gmock.h>
 
28
#include <iostream>
 
29
#include "pixmap-requests.h"
 
30
 
 
31
using ::testing::Return;
 
32
 
 
33
class DecorPixmapRequestsTest :
 
34
    public ::testing::Test
 
35
{
 
36
};
 
37
 
 
38
class MockDecorPixmapDeletor :
 
39
    public DecorPixmapDeletionInterface
 
40
{
 
41
    public:
 
42
 
 
43
        MOCK_METHOD1 (postDeletePixmap, int (Pixmap p));
 
44
};
 
45
 
 
46
class MockDecorPixmapReceiver :
 
47
    public DecorPixmapReceiverInterface
 
48
{
 
49
    public:
 
50
 
 
51
        MOCK_METHOD0 (pending, void ());
 
52
        MOCK_METHOD0 (update, void ());
 
53
};
 
54
 
 
55
class MockDecoration :
 
56
    public DecorationInterface
 
57
{
 
58
    public:
 
59
 
 
60
        MOCK_METHOD0 (receiverInterface, DecorPixmapReceiverInterface & ());
 
61
        MOCK_CONST_METHOD0 (getFrameType, unsigned int ());
 
62
        MOCK_CONST_METHOD0 (getFrameState, unsigned int ());
 
63
        MOCK_CONST_METHOD0 (getFrameActions, unsigned int ());
 
64
};
 
65
 
 
66
class MockDecorationListFindMatching :
 
67
    public DecorationListFindMatchingInterface
 
68
{
 
69
    public:
 
70
 
 
71
        MOCK_METHOD3 (findMatchingDecoration, DecorationInterface::Ptr (unsigned int, unsigned int, unsigned int));
 
72
};
 
73
 
 
74
class MockDecorPixmapRequestor :
 
75
    public DecorPixmapRequestorInterface
 
76
{
 
77
    public:
 
78
 
 
79
        MOCK_METHOD3 (postGenerateRequest, int (unsigned int, unsigned int, unsigned int));
 
80
        MOCK_METHOD1 (handlePending, void (long *));
 
81
};
 
82
 
 
83
TEST(DecorPixmapRequestsTest, TestDestroyPixmapDeletes)
 
84
{
 
85
    boost::shared_ptr <MockDecorPixmapDeletor> mockDeletor = boost::make_shared <MockDecorPixmapDeletor> ();
 
86
    DecorPixmap pm (1, boost::shared_static_cast<DecorPixmapDeletionInterface> (mockDeletor));
 
87
 
 
88
    EXPECT_CALL (*(mockDeletor.get ()), postDeletePixmap (1)).WillOnce (Return (1));
 
89
}
 
90
 
 
91
TEST(DecorPixmapRequestsTest, TestPendingGeneratesRequest)
 
92
{
 
93
    MockDecorPixmapRequestor mockRequestor;
 
94
    MockDecoration           mockDecoration;
 
95
    X11DecorPixmapReceiver   receiver (&mockRequestor, &mockDecoration);
 
96
 
 
97
    EXPECT_CALL (mockDecoration, getFrameActions ()).WillOnce (Return (3));
 
98
    EXPECT_CALL (mockDecoration, getFrameState ()).WillOnce (Return (2));
 
99
    EXPECT_CALL (mockDecoration, getFrameType ()).WillOnce (Return (1));
 
100
 
 
101
    EXPECT_CALL (mockRequestor, postGenerateRequest (1, 2, 3));
 
102
 
 
103
    receiver.pending ();
 
104
}
 
105
 
 
106
TEST(DecorPixmapRequestsTest, TestPendingGeneratesOnlyOneRequest)
 
107
{
 
108
    MockDecorPixmapRequestor mockRequestor;
 
109
    MockDecoration           mockDecoration;
 
110
    X11DecorPixmapReceiver   receiver (&mockRequestor, &mockDecoration);
 
111
 
 
112
    EXPECT_CALL (mockDecoration, getFrameActions ()).WillOnce (Return (3));
 
113
    EXPECT_CALL (mockDecoration, getFrameState ()).WillOnce (Return (2));
 
114
    EXPECT_CALL (mockDecoration, getFrameType ()).WillOnce (Return (1));
 
115
 
 
116
    EXPECT_CALL (mockRequestor, postGenerateRequest (1, 2, 3));
 
117
 
 
118
    receiver.pending ();
 
119
    receiver.pending ();
 
120
}
 
121
 
 
122
TEST(DecorPixmapRequestsTest, TestUpdateGeneratesRequestIfNewOnePending)
 
123
{
 
124
    MockDecorPixmapRequestor mockRequestor;
 
125
    MockDecoration           mockDecoration;
 
126
    X11DecorPixmapReceiver   receiver (&mockRequestor, &mockDecoration);
 
127
 
 
128
    EXPECT_CALL (mockDecoration, getFrameActions ()).WillOnce (Return (3));
 
129
    EXPECT_CALL (mockDecoration, getFrameState ()).WillOnce (Return (2));
 
130
    EXPECT_CALL (mockDecoration, getFrameType ()).WillOnce (Return (1));
 
131
 
 
132
    EXPECT_CALL (mockRequestor, postGenerateRequest (1, 2, 3));
 
133
 
 
134
    receiver.pending ();
 
135
    receiver.pending ();
 
136
 
 
137
    EXPECT_CALL (mockDecoration, getFrameActions ()).WillOnce (Return (3));
 
138
    EXPECT_CALL (mockDecoration, getFrameState ()).WillOnce (Return (2));
 
139
    EXPECT_CALL (mockDecoration, getFrameType ()).WillOnce (Return (1));
 
140
 
 
141
    EXPECT_CALL (mockRequestor, postGenerateRequest (1, 2, 3));
 
142
 
 
143
    receiver.update ();
 
144
}
 
145
 
 
146
TEST(DecorPixmapRequestsTest, TestUpdateGeneratesNoRequestIfNoNewOnePending)
 
147
{
 
148
    MockDecorPixmapRequestor mockRequestor;
 
149
    MockDecoration           mockDecoration;
 
150
    X11DecorPixmapReceiver   receiver (&mockRequestor, &mockDecoration);
 
151
 
 
152
    EXPECT_CALL (mockDecoration, getFrameActions ()).WillOnce (Return (3));
 
153
    EXPECT_CALL (mockDecoration, getFrameState ()).WillOnce (Return (2));
 
154
    EXPECT_CALL (mockDecoration, getFrameType ()).WillOnce (Return (1));
 
155
 
 
156
    EXPECT_CALL (mockRequestor, postGenerateRequest (1, 2, 3));
 
157
 
 
158
    receiver.pending ();
 
159
    receiver.update ();
 
160
}