~3v1n0/unity/light-shortcuts

« back to all changes in this revision

Viewing changes to tests/test_result_renderer.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
 
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2
 
/*
3
 
 * Copyright 2012 Canonical Ltd.
4
 
 *
5
 
 * This program is free software: you can redistribute it and/or modify it
6
 
 * under the terms of the GNU Lesser General Public License version 3, as
7
 
 * published by the  Free Software Foundation.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful, but
10
 
 * WITHOUT ANY WARRANTY; without even the implied warranties of
11
 
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12
 
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
13
 
 * License for more details.
14
 
 *
15
 
 * You should have received a copy of both the GNU Lesser General Public
16
 
 * License version 3 along with this program.  If not, see
17
 
 * <http://www.gnu.org/licenses/>
18
 
 *
19
 
 * Authored by: Nick Dedekind <nick.dedekind@canonical.com>
20
 
 *
21
 
 */
22
 
#include <gmock/gmock.h>
23
 
#include <glib-object.h>
24
 
 
25
 
#include "unity-shared/DashStyle.h"
26
 
#include "unity-shared/UnitySettings.h"
27
 
#include "UnityCore/Result.h"
28
 
#include "dash/ResultRendererTile.h"
29
 
 
30
 
#include "test_utils.h"
31
 
 
32
 
using namespace std;
33
 
using namespace unity;
34
 
using namespace testing;
35
 
 
36
 
namespace unity
37
 
{
38
 
 
39
 
namespace
40
 
{
41
 
 
42
 
#define DEFAULT_GICON ". GThemedIcon text-x-preview"
43
 
 
44
 
GdkPixbuf* GetIconData(std::string icon_hint, int size)
45
 
{
46
 
  GdkPixbuf *pbuf;
47
 
  GtkIconTheme *theme;
48
 
  GError *error = NULL;
49
 
 
50
 
  theme = gtk_icon_theme_get_default();
51
 
  glib::Object<GIcon> icon(g_icon_new_for_string(icon_hint.c_str(), NULL));
52
 
 
53
 
  if (icon.IsType(G_TYPE_ICON))
54
 
  {
55
 
    GtkIconInfo *info = gtk_icon_theme_lookup_by_gicon(theme, icon, size, (GtkIconLookupFlags)0);
56
 
    pbuf = gtk_icon_info_load_icon(info, &error);
57
 
    if (error != NULL)
58
 
    {
59
 
      g_error_free (error);
60
 
      pbuf = NULL;
61
 
    }
62
 
    gtk_icon_info_free(info);
63
 
  }
64
 
 
65
 
  return pbuf;
66
 
}
67
 
 
68
 
} // namespace [anonymous]
69
 
 
70
 
class TestResultRenderer : public testing::Test
71
 
{
72
 
public:
73
 
  TestResultRenderer() {}
74
 
 
75
 
  unity::Settings settings;
76
 
  dash::Style style;
77
 
};
78
 
 
79
 
class MockResult : public dash::Result
80
 
{
81
 
public:
82
 
  MockResult()
83
 
  : Result(NULL, NULL, NULL)
84
 
  , renderer_(new dash::TextureContainer())
85
 
  {
86
 
    ON_CALL (*this, GetURI ()).WillByDefault (Return ("file:///result_render_test"));
87
 
    ON_CALL (*this, GetIconHint()).WillByDefault (Return (DEFAULT_GICON));
88
 
    ON_CALL (*this, GetCategoryIndex ()).WillByDefault (Return (0));
89
 
    ON_CALL (*this, GetName ()).WillByDefault (Return ("Result Render Test"));
90
 
    ON_CALL (*this, GetDndURI ()).WillByDefault (Return ("file:///result_render_test_dnd"));
91
 
  }
92
 
 
93
 
  MOCK_CONST_METHOD0(GetURI, std::string());
94
 
  MOCK_CONST_METHOD0(GetIconHint, std::string());
95
 
  MOCK_CONST_METHOD0(GetCategoryIndex, std::size_t());
96
 
  MOCK_CONST_METHOD0(GetMimeType, std::string());
97
 
  MOCK_CONST_METHOD0(GetName, std::string());
98
 
  MOCK_CONST_METHOD0(GetComment, std::string());
99
 
  MOCK_CONST_METHOD0(GetDndURI, std::string());
100
 
 
101
 
  virtual gpointer get_model_tag() const
102
 
  {
103
 
    return renderer_.get();
104
 
  }
105
 
 
106
 
private:
107
 
  std::auto_ptr<dash::TextureContainer> renderer_;
108
 
};
109
 
 
110
 
TEST_F(TestResultRenderer, TestConstruction)
111
 
{
112
 
  dash::ResultRendererTile renderer;
113
 
}
114
 
 
115
 
TEST_F(TestResultRenderer, TestDndIcon)
116
 
{
117
 
  dash::ResultRendererTile renderer;
118
 
  NiceMock<MockResult> result;
119
 
 
120
 
  nux::NBitmapData* bitmap = renderer.GetDndImage(result);
121
 
  ASSERT_NE(bitmap, nullptr);
122
 
}
123
 
 
124
 
}