~sethj/ubuntu/wily/unity/fix-for-1445595

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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
 * 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: Manuel de la Pena <manuel.delapena@canonical.com>
 *
 */

#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include "unity-shared/StaticCairoText.h"

#include "dash/previews/ActionLink.cpp"
#include "test_utils.h"

using namespace nux;
using namespace unity;
using namespace unity::dash;

namespace unity
{

namespace dash
{

class ActionLinkMock : public ActionLink
{
  public:
    MOCK_METHOD0(QueueDraw, void());
    MOCK_METHOD0(ComputeContentSize, long());
    MOCK_METHOD2(CalculateBar, void(nux::GraphicsEngine&, bool));

    ActionLinkMock(std::string const& action_hint, std::string const& label, NUX_FILE_LINE_PROTO)
      : ActionLink(action_hint, label){}
    ~ActionLinkMock(){}

    nux::ObjectPtr<StaticCairoText> GetText() { return static_text_; }

    using ActionLink::GetLinkAlpha;
    using ActionLink::Draw;
    using ActionLink::DrawContent;
    using ActionLink::RecvClick;
    using ActionLink::GetName;
    using ActionLink::AddProperties;
    using ActionLink::set_aligment;
    using ActionLink::get_aligment;
    using ActionLink::set_underline;
    using ActionLink::get_underline;
    using ActionLink::set_font_hint;
    using ActionLink::get_font_hint;
    using ActionLink::action_hint_;
    using ActionLink::font_hint_;
    using ActionLink::aligment_;
    using ActionLink::underline_;
};

class TestActionLink : public ::testing::Test
{
  protected:
    TestActionLink() : Test()
    {
      action_link = new ActionLinkMock("action_id", "display_name");
    }

    nux::ObjectPtr<ActionLinkMock> action_link;
};

TEST_F(TestActionLink, AligmentCorrectlySetDifferent)
{
  ActionLinkMock link("test", "test");

  EXPECT_CALL(link, ComputeContentSize()).Times(1);
  EXPECT_CALL(link, QueueDraw()).Times(1);

  link.text_aligment.Set(StaticCairoText::NUX_ALIGN_RIGHT);
}

TEST_F(TestActionLink, AligmentCorrectlySetSame)
{
  ActionLinkMock link("test", "test");

  EXPECT_CALL(link, ComputeContentSize()).Times(0);
  EXPECT_CALL(link, QueueDraw()).Times(0);

  link.text_aligment.Set(link.text_aligment.Get());
}

TEST_F(TestActionLink, AligmentCorrectlyRetrieved)
{
  StaticCairoText::AlignState aligment =
    StaticCairoText::NUX_ALIGN_RIGHT;
  action_link->aligment_ = aligment;
  EXPECT_EQ(aligment, action_link->text_aligment.Get());
}

TEST_F(TestActionLink, UnderlineCorrectlySetDifferent)
{
  ActionLinkMock link("test", "test");

  EXPECT_CALL(link, ComputeContentSize()).Times(1);
  EXPECT_CALL(link, QueueDraw()).Times(1);
  link.underline_state.Set(StaticCairoText::NUX_UNDERLINE_NONE);
}

TEST_F(TestActionLink, UnderlineCorrectlySetSame)
{
  ActionLinkMock link("test", "test");

  EXPECT_CALL(link, ComputeContentSize()).Times(0);
  EXPECT_CALL(link, QueueDraw()).Times(0);
  link.underline_state.Set(link.underline_state.Get());
}

TEST_F(TestActionLink, UnderlineCorrectlyRetrieved)
{
  StaticCairoText::UnderlineState underline = StaticCairoText::NUX_UNDERLINE_DOUBLE;
  action_link->underline_ = underline;
  EXPECT_EQ(underline, action_link->underline_state.Get());
}

TEST_F(TestActionLink, FontCorrectlySetDifferent)
{
  ActionLinkMock link("test", "test");
  link.font_hint_ = "Ubuntu 10";

  EXPECT_CALL(link, ComputeContentSize()).Times(1);
  EXPECT_CALL(link, QueueDraw()).Times(1);
  link.font_hint.Set("Ubuntu 11");
}

TEST_F(TestActionLink, FontCorrectlySetSame)
{
  ActionLinkMock link("test", "test");
  link.font_hint_ = "Ubuntu 10";

  EXPECT_CALL(link, ComputeContentSize()).Times(0);
  EXPECT_CALL(link, QueueDraw()).Times(0);
  link.font_hint.Set(link.font_hint.Get());
}

TEST_F(TestActionLink, FontCorrectlyRetrieved)
{
  std::string font_hint = "Ubuntu 11";
  action_link->font_hint_ = font_hint;
  EXPECT_EQ(font_hint, action_link->font_hint.Get());
}

TEST_F(TestActionLink, LinkAlphaOnPressed)
{
   ButtonVisualState state = ButtonVisualState::VISUAL_STATE_PRESSED;
   EXPECT_EQ(4, action_link->GetLinkAlpha(state, false));
}

TEST_F(TestActionLink, LinkAlphaOnNormal)
{
   ButtonVisualState state = ButtonVisualState::VISUAL_STATE_NORMAL;
   EXPECT_EQ(4, action_link->GetLinkAlpha(state, false));
}

TEST_F(TestActionLink, LinkAlphaOnNormalButKeyboardFocused)
{
   ButtonVisualState state = ButtonVisualState::VISUAL_STATE_NORMAL;
   EXPECT_EQ(1, action_link->GetLinkAlpha(state, true));
}

TEST_F(TestActionLink, LinkAlphaOnPrelight)
{
   ButtonVisualState state = ButtonVisualState::VISUAL_STATE_PRELIGHT;
   EXPECT_EQ(1, action_link->GetLinkAlpha(state, false));
}

TEST_F(TestActionLink, LinkAlphaOnDisabled)
{
   ButtonVisualState state = ButtonVisualState::VISUAL_STATE_DISABLED;
   EXPECT_EQ(4, action_link->GetLinkAlpha(state, false));
}

}

}