2
* Copyright © 2012 Canonical Ltd.
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
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.
23
* Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
26
#include <gtest/gtest.h>
27
#include <gmock/gmock.h>
29
#include "pixmap-requests.h"
31
using ::testing::Return;
33
class DecorPixmapRequestsTest :
34
public ::testing::Test
38
class MockDecorPixmapDeletor :
39
public DecorPixmapDeletionInterface
43
MOCK_METHOD1 (postDeletePixmap, int (Pixmap p));
46
class MockDecorPixmapReceiver :
47
public DecorPixmapReceiverInterface
51
MOCK_METHOD0 (pending, void ());
52
MOCK_METHOD0 (update, void ());
55
class MockDecoration :
56
public DecorationInterface
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 ());
66
class MockDecorationListFindMatching :
67
public DecorationListFindMatchingInterface
71
MOCK_METHOD3 (findMatchingDecoration, DecorationInterface::Ptr (unsigned int, unsigned int, unsigned int));
74
class MockDecorPixmapRequestor :
75
public DecorPixmapRequestorInterface
79
MOCK_METHOD3 (postGenerateRequest, int (unsigned int, unsigned int, unsigned int));
80
MOCK_METHOD1 (handlePending, void (long *));
83
TEST(DecorPixmapRequestsTest, TestDestroyPixmapDeletes)
85
boost::shared_ptr <MockDecorPixmapDeletor> mockDeletor = boost::make_shared <MockDecorPixmapDeletor> ();
86
DecorPixmap pm (1, boost::shared_static_cast<DecorPixmapDeletionInterface> (mockDeletor));
88
EXPECT_CALL (*(mockDeletor.get ()), postDeletePixmap (1)).WillOnce (Return (1));
91
TEST(DecorPixmapRequestsTest, TestPendingGeneratesRequest)
93
MockDecorPixmapRequestor mockRequestor;
94
MockDecoration mockDecoration;
95
X11DecorPixmapReceiver receiver (&mockRequestor, &mockDecoration);
97
EXPECT_CALL (mockDecoration, getFrameActions ()).WillOnce (Return (3));
98
EXPECT_CALL (mockDecoration, getFrameState ()).WillOnce (Return (2));
99
EXPECT_CALL (mockDecoration, getFrameType ()).WillOnce (Return (1));
101
EXPECT_CALL (mockRequestor, postGenerateRequest (1, 2, 3));
106
TEST(DecorPixmapRequestsTest, TestPendingGeneratesOnlyOneRequest)
108
MockDecorPixmapRequestor mockRequestor;
109
MockDecoration mockDecoration;
110
X11DecorPixmapReceiver receiver (&mockRequestor, &mockDecoration);
112
EXPECT_CALL (mockDecoration, getFrameActions ()).WillOnce (Return (3));
113
EXPECT_CALL (mockDecoration, getFrameState ()).WillOnce (Return (2));
114
EXPECT_CALL (mockDecoration, getFrameType ()).WillOnce (Return (1));
116
EXPECT_CALL (mockRequestor, postGenerateRequest (1, 2, 3));
122
TEST(DecorPixmapRequestsTest, TestUpdateGeneratesRequestIfNewOnePending)
124
MockDecorPixmapRequestor mockRequestor;
125
MockDecoration mockDecoration;
126
X11DecorPixmapReceiver receiver (&mockRequestor, &mockDecoration);
128
EXPECT_CALL (mockDecoration, getFrameActions ()).WillOnce (Return (3));
129
EXPECT_CALL (mockDecoration, getFrameState ()).WillOnce (Return (2));
130
EXPECT_CALL (mockDecoration, getFrameType ()).WillOnce (Return (1));
132
EXPECT_CALL (mockRequestor, postGenerateRequest (1, 2, 3));
137
EXPECT_CALL (mockDecoration, getFrameActions ()).WillOnce (Return (3));
138
EXPECT_CALL (mockDecoration, getFrameState ()).WillOnce (Return (2));
139
EXPECT_CALL (mockDecoration, getFrameType ()).WillOnce (Return (1));
141
EXPECT_CALL (mockRequestor, postGenerateRequest (1, 2, 3));
146
TEST(DecorPixmapRequestsTest, TestUpdateGeneratesNoRequestIfNoNewOnePending)
148
MockDecorPixmapRequestor mockRequestor;
149
MockDecoration mockDecoration;
150
X11DecorPixmapReceiver receiver (&mockRequestor, &mockDecoration);
152
EXPECT_CALL (mockDecoration, getFrameActions ()).WillOnce (Return (3));
153
EXPECT_CALL (mockDecoration, getFrameState ()).WillOnce (Return (2));
154
EXPECT_CALL (mockDecoration, getFrameType ()).WillOnce (Return (1));
156
EXPECT_CALL (mockRequestor, postGenerateRequest (1, 2, 3));