~mial/ubuntu/oneiric/unity/bug-791810

« back to all changes in this revision

Viewing changes to tests/unit/test-unity-pixbuf-cache.vala

Import the work done so far with Compiz

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2010 Canonical Ltd
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Authored by Neil Jagdish Patel <neil.patel@canonical.com>
 
17
 *
 
18
 */
 
19
using Unity;
 
20
using Unity.Testing;
 
21
using Gdk;
 
22
using GLib.Test;
 
23
 
 
24
namespace Unity.Tests.Unit
 
25
{
 
26
  public class UnityPixbufCacheSuite : Object
 
27
  {
 
28
    public const string DOMAIN = "/Unit/Unity/PixbufCache";
 
29
 
 
30
    public UnityPixbufCacheSuite()
 
31
    {
 
32
      Logging.init_fatal_handler ();
 
33
 
 
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);
 
37
    }
 
38
 
 
39
    private void test_allocation ()
 
40
    {
 
41
      var cache = PixbufCache.get_default ();
 
42
      assert (cache is PixbufCache);
 
43
      assert (cache == PixbufCache.get_default ());
 
44
    }
 
45
 
 
46
    private void test_lookup ()
 
47
    {
 
48
      var pixbuf = new Pixbuf (Colorspace.RGB, true, 8, 69, 69);
 
49
      var cache = PixbufCache.get_default ();
 
50
 
 
51
      assert (cache is PixbufCache);
 
52
      assert (cache.size == 0);
 
53
 
 
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);
 
59
 
 
60
      cache.clear ();
 
61
      assert (cache.size == 0);
 
62
      assert (cache.get ("foo", 48) == null);
 
63
      assert (cache.get ("bar", 48) == null);
 
64
    }
 
65
 
 
66
    private void test_setting_async ()
 
67
    {
 
68
      var image = new Ctk.Image (48);
 
69
      var pixbuf = new Pixbuf (Colorspace.RGB, true, 8, 69, 69);
 
70
      var cache = PixbufCache.get_default ();
 
71
 
 
72
      assert (cache is PixbufCache);
 
73
      assert (cache.size == 0);
 
74
 
 
75
      cache.set ("foo", pixbuf, 48);
 
76
      assert (cache.size == 1);
 
77
      assert (cache.get ("foo", 48) == pixbuf);
 
78
 
 
79
      assert (image.get_pixbuf () != pixbuf);
 
80
 
 
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);
 
85
 
 
86
 
 
87
      if (trap_fork (0, TestTrapFlags.SILENCE_STDOUT | TestTrapFlags.SILENCE_STDERR))
 
88
        {
 
89
          cache.set_image_from_icon_name (image, "bar", 24);
 
90
          while (Gtk.events_pending ())
 
91
            Gtk.main_iteration ();
 
92
          Posix.exit (0);
 
93
        }
 
94
        trap_has_passed ();
 
95
        trap_assert_stderr ("*Unable to load icon_name*");
 
96
        assert (image.get_pixbuf () == pixbuf); /* No change as failed*/
 
97
    }
 
98
  }
 
99
}