~ci-train-bot/unity/unity-ubuntu-artful-2740

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
/*
 * Copyright 2012 Canonical Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU 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 GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * version 3 along with this program.  If not, see
 * <http://www.gnu.org/licenses/>
 *
 * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
 *
 */

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

#include <Nux/Nux.h>
#include <Nux/PaintLayer.h>

#include "PlacesGroup.h"
using namespace unity;
using namespace unity::dash;

namespace {

class MockDashStyle : public dash::StyleInterface
{
public:
  MockDashStyle()
  {
    base_texture_.Adopt(nux::CreateTexture2DFromFile(SOURCEDATADIR "/album_missing.png", true, -1));
  }

  MOCK_METHOD2(FocusOverlay, nux::AbstractPaintLayer*(int width, int height));
  MOCK_CONST_METHOD0(GetCategoryBackground, nux::ObjectPtr<nux::BaseTexture> const&());
  MOCK_CONST_METHOD0(GetCategoryBackgroundNoFilters, nux::ObjectPtr<nux::BaseTexture> const&());

  MOCK_CONST_METHOD0(GetGroupExpandIcon, nux::ObjectPtr<nux::BaseTexture> const&());
  MOCK_CONST_METHOD0(GetGroupUnexpandIcon, nux::ObjectPtr<nux::BaseTexture> const&());

  MOCK_CONST_METHOD0(GetCategoryIconSize, RawPixel());
  MOCK_CONST_METHOD0(GetCategoryHeaderLeftPadding, RawPixel());

  MOCK_CONST_METHOD0(GetPlacesGroupTopSpace, RawPixel());
  MOCK_CONST_METHOD0(GetPlacesGroupResultTopPadding, RawPixel());
  MOCK_CONST_METHOD0(GetPlacesGroupResultLeftPadding, RawPixel());

  nux::ObjectPtr<nux::BaseTexture> base_texture_;
};


class TestPlacesGroup : public Test
{
public:
  void SetUp()
  {
    SetupMockDashStyle();

    places_group_ = new PlacesGroup(dash_style_);
  }

  void SetupMockDashStyle()
  {
    ON_CALL(dash_style_, FocusOverlay(_, _))
      .WillByDefault(Return(new nux::ColorLayer(nux::color::White)));

    ON_CALL(Const(dash_style_), GetCategoryBackground())
      .WillByDefault(ReturnRef(dash_style_.base_texture_));

    ON_CALL(Const(dash_style_), GetCategoryBackgroundNoFilters())
      .WillByDefault(ReturnRef(dash_style_.base_texture_));

    ON_CALL(Const(dash_style_), GetGroupExpandIcon())
      .WillByDefault(ReturnRef(dash_style_.base_texture_));

    ON_CALL(Const(dash_style_), GetGroupUnexpandIcon())
         .WillByDefault(ReturnRef(dash_style_.base_texture_));

    ON_CALL(dash_style_, GetCategoryHeaderLeftPadding())
         .WillByDefault(Return(19_em));

    ON_CALL(dash_style_, GetPlacesGroupTopSpace())
         .WillByDefault(Return(7_em));

    ON_CALL(dash_style_, GetCategoryIconSize())
         .WillByDefault(Return(0_em));

    ON_CALL(dash_style_, GetPlacesGroupResultTopPadding())
         .WillByDefault(Return(0_em));

    ON_CALL(dash_style_, GetPlacesGroupResultLeftPadding())
         .WillByDefault(Return(0_em));
  }

  NiceMock<MockDashStyle> dash_style_;
  nux::ObjectPtr<PlacesGroup> places_group_;
};


TEST_F(TestPlacesGroup, Constructor)
{
  EXPECT_CALL(dash_style_, GetGroupExpandIcon())
    .Times(1);

  EXPECT_CALL(dash_style_, GetGroupUnexpandIcon())
    .Times(0);

  PlacesGroup places_group(dash_style_);

  EXPECT_FALSE(places_group.GetExpanded());
}

}