import unittest

from common import gtk


class ReferenceCountTest(unittest.TestCase):
    def test_image_constructor(self):
        image = gtk.Image()
        self.assertEqual(image.__grefcount__, 1)
        image.set_from_stock('gtk-ok', gtk.ICON_SIZE_MENU)
        self.assertEqual(image.get_stock(), ('gtk-ok', gtk.ICON_SIZE_MENU))
        self.assertEqual(image.__grefcount__, 1)

    def test_image_factory(self):
        image = gtk.image_new_from_icon_name('gtk-ok', gtk.ICON_SIZE_MENU)
        self.assertEqual(image.__grefcount__, 1)
        self.assertEqual(image.get_icon_name(), ('gtk-ok', gtk.ICON_SIZE_MENU))
        self.assertEqual(image.__grefcount__, 1)

    def test_pixbuf_method_object_returns(self):
        pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, 100, 100)
        self.assertEqual(pixbuf.__grefcount__, 1)
        (pixmap, mask) = pixbuf.render_pixmap_and_mask()
        self.assertTrue(isinstance(pixmap, gtk.gdk.Pixmap))
        self.assertTrue(isinstance(mask, gtk.gdk.Pixmap))
        self.assertEqual(pixmap.__grefcount__, 1)
        self.assertEqual(mask.__grefcount__, 1)

    def test_pixbuf_factory(self):
        image = gtk.gdk.pixbuf_new_from_data('AAABBBCCCDDD', gtk.gdk.COLORSPACE_RGB,
                False, 8, 2, 2, 1)
        self.assertTrue(isinstance(image, gtk.gdk.Pixbuf))
        self.assertEqual(image.__grefcount__, 1)

if __name__ == '__main__':
    unittest.main()
