2
* Copyright (C) 2010 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by Neil Jagdish Patel <neil.patel@canonical.com>
24
namespace Unity.Tests.Unit
26
public class UnityPixbufCacheSuite : Object
28
public const string DOMAIN = "/Unit/Unity/PixbufCache";
30
public UnityPixbufCacheSuite()
32
Logging.init_fatal_handler ();
34
Test.add_data_func (DOMAIN + "/Allocation", test_allocation);
35
Test.add_data_func (DOMAIN + "/Lookup", test_lookup);
36
Test.add_data_func (DOMAIN + "/Setting", test_setting_async);
39
private void test_allocation ()
41
var cache = PixbufCache.get_default ();
42
assert (cache is PixbufCache);
43
assert (cache == PixbufCache.get_default ());
46
private void test_lookup ()
48
var pixbuf = new Pixbuf (Colorspace.RGB, true, 8, 69, 69);
49
var cache = PixbufCache.get_default ();
51
assert (cache is PixbufCache);
52
assert (cache.size == 0);
54
cache.set ("foo", pixbuf, 48);
55
assert (cache.size == 1);
56
assert (cache.get ("foo", 48) == pixbuf);
57
assert (cache.get ("foo", 24) == null);
58
assert (cache.get ("bar", 48) == null);
61
assert (cache.size == 0);
62
assert (cache.get ("foo", 48) == null);
63
assert (cache.get ("bar", 48) == null);
66
private void test_setting_async ()
68
var image = new Ctk.Image (48);
69
var pixbuf = new Pixbuf (Colorspace.RGB, true, 8, 69, 69);
70
var cache = PixbufCache.get_default ();
72
assert (cache is PixbufCache);
73
assert (cache.size == 0);
75
cache.set ("foo", pixbuf, 48);
76
assert (cache.size == 1);
77
assert (cache.get ("foo", 48) == pixbuf);
79
assert (image.get_pixbuf () != pixbuf);
81
cache.set_image_from_icon_name (image, "foo", 48);
82
while (Gtk.events_pending ())
83
Gtk.main_iteration ();
84
assert (image.get_pixbuf () == pixbuf);
87
if (trap_fork (0, TestTrapFlags.SILENCE_STDOUT | TestTrapFlags.SILENCE_STDERR))
89
cache.set_image_from_icon_name (image, "bar", 24);
90
while (Gtk.events_pending ())
91
Gtk.main_iteration ();
95
trap_assert_stderr ("*Unable to load icon_name*");
96
assert (image.get_pixbuf () == pixbuf); /* No change as failed*/