~3v1n0/unity/light-shortcuts

« back to all changes in this revision

Viewing changes to tests/test_hud_controller.cpp

  • Committer: Marco Trevisan (Treviño)
  • Date: 2013-04-26 12:41:09 UTC
  • Revision ID: mail@3v1n0.net-20130426124109-t3b2shjah2omiqa2
Unity: Remove all the views, but the Shortcuts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2012 Canonical Ltd.
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify it
5
 
 * under the terms of the GNU Lesser 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, but
9
 
 * WITHOUT ANY WARRANTY; without even the implied warranties of
10
 
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11
 
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
12
 
 * License for more details.
13
 
 *
14
 
 * You should have received a copy of both the GNU Lesser General Public
15
 
 * License version 3 along with this program.  If not, see
16
 
 * <http://www.gnu.org/licenses/>
17
 
 *
18
 
 * Authored by: Andrea Azzarone <azzaronea@gmail.com>
19
 
 *
20
 
 */
21
 
 
22
 
#include <gmock/gmock.h>
23
 
using namespace testing;
24
 
#include <Nux/NuxTimerTickSource.h>
25
 
#include <NuxCore/AnimationController.h>
26
 
#include "HudController.h"
27
 
#include "mock-base-window.h"
28
 
#include "unity-shared/DashStyle.h"
29
 
#include "unity-shared/PanelStyle.h"
30
 
#include "unity-shared/UnitySettings.h"
31
 
#include "test_utils.h"
32
 
using namespace unity;
33
 
 
34
 
namespace
35
 
{
36
 
 
37
 
const unsigned ANIMATION_DURATION = 90 * 1000; // in microseconds
38
 
const unsigned TICK_DURATION = 10 * 1000;
39
 
 
40
 
class MockHudView : public hud::AbstractView
41
 
{
42
 
public:
43
 
  typedef nux::ObjectPtr<MockHudView> Ptr;
44
 
 
45
 
  MOCK_METHOD0(AboutToShow, void());
46
 
  MOCK_METHOD0(AboutToHide, void());
47
 
  MOCK_METHOD0(Relayout, void());
48
 
  MOCK_METHOD0(ResetToDefault, void());
49
 
  MOCK_METHOD0(SearchFinished, void());
50
 
  MOCK_METHOD4(SetIcon, void(std::string const&, unsigned int tile_size, unsigned int size, unsigned int padding));
51
 
  MOCK_METHOD1(SetQueries, void(hud::Hud::Queries queries));
52
 
  MOCK_METHOD2(SetMonitorOffset, void(int x, int y));
53
 
  MOCK_METHOD1(ShowEmbeddedIcon, void(bool show));
54
 
  MOCK_CONST_METHOD0(default_focus, nux::View*());
55
 
  MOCK_CONST_METHOD0(GetName, std::string());
56
 
  MOCK_METHOD1(AddProperties, void(GVariantBuilder*));
57
 
  MOCK_METHOD2(Draw, void(nux::GraphicsEngine&, bool));
58
 
  nux::Geometry GetContentGeometry()
59
 
  {
60
 
    return nux::Geometry();
61
 
  }
62
 
};
63
 
 
64
 
 
65
 
class TestHudController : public Test
66
 
{
67
 
public:
68
 
  TestHudController()
69
 
  : view_(new NiceMock<MockHudView>)
70
 
  , base_window_(new NiceMock<testmocks::MockBaseWindow>())
71
 
  {
72
 
    ON_CALL(*base_window_, SetOpacity(_))
73
 
      .WillByDefault(Invoke(base_window_.GetPointer(),
74
 
                     &testmocks::MockBaseWindow::RealSetOpacity));
75
 
 
76
 
    // Set expectations for creating the controller
77
 
    EXPECT_CALL(*base_window_, SetOpacity(0.0f));
78
 
 
79
 
    controller_.reset(new hud::Controller([&](){ return view_.GetPointer(); },
80
 
                                          [&](){ return base_window_.GetPointer();}));
81
 
  }
82
 
 
83
 
protected:
84
 
  hud::Controller::Ptr controller_;
85
 
  MockHudView::Ptr view_;
86
 
  testmocks::MockBaseWindow::Ptr base_window_;
87
 
 
88
 
  // required to create hidden secret global variables
89
 
  Settings unity_settings_;
90
 
  dash::Style dash_style_;
91
 
  panel::Style panel_style_;
92
 
};
93
 
 
94
 
 
95
 
TEST_F(TestHudController, TestShowAndHideHud)
96
 
{
97
 
  long long t;
98
 
  long long global_tick = 0;
99
 
  nux::NuxTimerTickSource tick_source;
100
 
  nux::animation::AnimationController animation_controller(tick_source);
101
 
 
102
 
  // Verify initial conditions
103
 
  EXPECT_EQ(base_window_->GetOpacity(), 0.0);
104
 
 
105
 
  // Set expectations for showing the HUD
106
 
  EXPECT_CALL(*view_, AboutToShow()).Times(1);
107
 
  EXPECT_CALL(*view_, ResetToDefault()).Times(1);
108
 
  {
109
 
    InSequence showing;
110
 
    EXPECT_CALL(*base_window_, SetOpacity(Eq(0.0f))).Times(AtLeast(1));
111
 
    EXPECT_CALL(*base_window_, SetOpacity(AllOf(Gt(0.0f), Lt(1.0f))))
112
 
      .Times(AtLeast(ANIMATION_DURATION/TICK_DURATION-1));
113
 
    EXPECT_CALL(*base_window_, SetOpacity(Eq(1.0f))).Times(AtLeast(1));
114
 
  }
115
 
 
116
 
  controller_->ShowHud();
117
 
  for (t = global_tick; t < global_tick + ANIMATION_DURATION+1; t += TICK_DURATION)
118
 
    tick_source.tick(t);
119
 
  global_tick += t;
120
 
 
121
 
  EXPECT_EQ(base_window_->GetOpacity(), 1.0);
122
 
 
123
 
  Mock::VerifyAndClearExpectations(view_.GetPointer());
124
 
  Mock::VerifyAndClearExpectations(base_window_.GetPointer());
125
 
 
126
 
  // Set expectations for hiding the HUD
127
 
  EXPECT_CALL(*view_, AboutToHide()).Times(1);
128
 
  {
129
 
    InSequence hiding;
130
 
    EXPECT_CALL(*base_window_, SetOpacity(Eq(1.0f))).Times(AtLeast(1));
131
 
    EXPECT_CALL(*base_window_, SetOpacity(AllOf(Lt(1.0f), Gt(0.0f))))
132
 
      .Times(AtLeast(ANIMATION_DURATION/TICK_DURATION-1));
133
 
    EXPECT_CALL(*base_window_, SetOpacity(Eq(0.0f))).Times(AtLeast(1));
134
 
  }
135
 
 
136
 
  controller_->HideHud();
137
 
  for (t = global_tick; t < global_tick + ANIMATION_DURATION+1; t += TICK_DURATION)
138
 
    tick_source.tick(t);
139
 
  global_tick += t;
140
 
 
141
 
  EXPECT_EQ(base_window_->GetOpacity(), 0.0);
142
 
}
143
 
 
144
 
}