1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
3
* Copyright 2012 Canonical Ltd.
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.
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.
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/>
19
* Authored by: Nick Dedekind <nick.dedekind@canonical.com>
22
#include <gmock/gmock.h>
23
#include <glib-object.h>
25
#include "unity-shared/DashStyle.h"
26
#include "unity-shared/UnitySettings.h"
27
#include "UnityCore/Result.h"
28
#include "dash/ResultRendererTile.h"
30
#include "test_utils.h"
33
using namespace unity;
34
using namespace testing;
42
#define DEFAULT_GICON ". GThemedIcon text-x-preview"
44
GdkPixbuf* GetIconData(std::string icon_hint, int size)
50
theme = gtk_icon_theme_get_default();
51
glib::Object<GIcon> icon(g_icon_new_for_string(icon_hint.c_str(), NULL));
53
if (icon.IsType(G_TYPE_ICON))
55
GtkIconInfo *info = gtk_icon_theme_lookup_by_gicon(theme, icon, size, (GtkIconLookupFlags)0);
56
pbuf = gtk_icon_info_load_icon(info, &error);
62
gtk_icon_info_free(info);
68
} // namespace [anonymous]
70
class TestResultRenderer : public testing::Test
73
TestResultRenderer() {}
75
unity::Settings settings;
79
class MockResult : public dash::Result
83
: Result(NULL, NULL, NULL)
84
, renderer_(new dash::TextureContainer())
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"));
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());
101
virtual gpointer get_model_tag() const
103
return renderer_.get();
107
std::auto_ptr<dash::TextureContainer> renderer_;
110
TEST_F(TestResultRenderer, TestConstruction)
112
dash::ResultRendererTile renderer;
115
TEST_F(TestResultRenderer, TestDndIcon)
117
dash::ResultRendererTile renderer;
118
NiceMock<MockResult> result;
120
nux::NBitmapData* bitmap = renderer.GetDndImage(result);
121
ASSERT_NE(bitmap, nullptr);