~smspillaz/unity/unity.less-paint-insanity

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
 * Copyright 2012 Canonical Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3, as
 * published by the  Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of both the GNU Lesser General Public
 * License version 3 along with this program.  If not, see
 * <http://www.gnu.org/licenses/>
 *
 * Authored by: Andrea Azzarone <azzaronea@gmail.com>
 *
 */

#include <gtest/gtest.h>
#include <gmock/gmock.h>
using namespace testing;

#include "ResultViewGrid.h"
using namespace unity;

namespace
{

class MockResultViewGrid : public dash::ResultViewGrid
{
public:
  MockResultViewGrid(NUX_FILE_LINE_DECL) : dash::ResultViewGrid(NUX_FILE_LINE_PARAM) {}

  MOCK_METHOD0(QueueDraw, void());
  MOCK_METHOD2(GetIndexAtPosition, uint(int x, int y));

  void FakeMouseMoveSignal(int x = 0, int y = 0, int dx = 0, int dy = 0, unsigned long mouse_button_state = 0, unsigned long special_keys_state = 0)
  {
    EmitMouseMoveSignal(x, y, dy, dy, mouse_button_state, special_keys_state);
  }
};

class TestResultViewGrid : public Test
{
public:
  virtual void SetUp()
  {
    view.Adopt(new MockResultViewGrid(NUX_TRACKER_LOCATION));
    renderer.Adopt(new dash::ResultRenderer(NUX_TRACKER_LOCATION));

    view->SetModelRenderer(renderer.GetPointer());
    nux::GetWindowCompositor().SetKeyFocusArea(view.GetPointer());
  }

  nux::ObjectPtr<MockResultViewGrid> view;
  nux::ObjectPtr<dash::ResultRenderer> renderer;
};


TEST_F(TestResultViewGrid, TestQueueDrawMouseMoveInsideUnfocusedIcon)
{
  EXPECT_CALL(*view, QueueDraw())
    .Times(1);

  EXPECT_CALL(*view, GetIndexAtPosition(_, _))
    .WillOnce(Return(7));

  view->FakeMouseMoveSignal();
}


TEST_F(TestResultViewGrid, TestQueueDrawMouseMoveInsideFocusedIcon)
{
  EXPECT_CALL(*view, GetIndexAtPosition(_, _))
    .WillRepeatedly(Return(7));

  view->FakeMouseMoveSignal();

  EXPECT_CALL(*view, QueueDraw())
    .Times(0);

  view->FakeMouseMoveSignal();
}


TEST_F(TestResultViewGrid, TestQueueDrawMouseMoveOutside)
{
  EXPECT_CALL(*view, GetIndexAtPosition(_, _))
    .WillRepeatedly(Return(-1));

  view->FakeMouseMoveSignal();

  EXPECT_CALL(*view, QueueDraw())
    .Times(0);

  view->FakeMouseMoveSignal();
}

}