2
* Copyright (C) 2013 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
19
#include<internal/gobj_memory.h>
20
#include<gdk-pixbuf/gdk-pixbuf.h>
26
unique_gobj<GdkPixbuf> basic(gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480));
28
assert(gdk_pixbuf_get_width(basic.get()) == 640);
29
assert(gdk_pixbuf_get_height(basic.get()) == 480);
33
GdkPixbuf *pb1 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
34
GdkPixbuf *pb2 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
39
unique_gobj<GdkPixbuf> u1(pb1);
40
unique_gobj<GdkPixbuf> u2(pb2);
42
assert(!(u1 == nullptr));
43
assert(u1 != nullptr);
54
// This is its own thing due to need to avoid double release.
56
void equality_test() {
57
GdkPixbuf *pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
58
unique_gobj<GdkPixbuf> u1(pb);
59
g_object_ref(G_OBJECT(pb));
60
unique_gobj<GdkPixbuf> u2(pb);
68
GdkPixbuf *pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
69
unique_gobj<GdkPixbuf> u(pb);
71
assert(u.get() != nullptr);
72
assert(pb == u.release());
74
assert(u.get() == nullptr);
78
void sub_func(GdkPixbuf *pb) {
79
assert(G_OBJECT(pb)->ref_count == 2);
80
unique_gobj<GdkPixbuf> u(pb);
81
assert(G_OBJECT(pb)->ref_count == 2);
82
// Now it dies and refcount is reduced.
85
void refcount_test() {
86
GdkPixbuf *pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
87
assert(G_OBJECT(pb)->ref_count == 1);
88
g_object_ref(G_OBJECT(pb));
90
assert(G_OBJECT(pb)->ref_count == 1);
91
g_object_unref(G_OBJECT(pb));
95
GdkPixbuf *pb1 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
96
GdkPixbuf *pb2 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
97
unique_gobj<GdkPixbuf> u1(pb1);
98
unique_gobj<GdkPixbuf> u2(pb2);
101
assert(u1.get() == pb2);
102
assert(u2.get() == pb1);
105
assert(u1.get() == pb1);
106
assert(u2.get() == pb2);
109
void floating_test() {
110
GdkPixbuf *pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
111
bool got_exception = false;
112
g_object_force_floating(G_OBJECT(pb));
114
unique_gobj<GdkPixbuf> u(pb);
115
} catch(const invalid_argument &c) {
116
got_exception = true;
118
g_object_unref(G_OBJECT(pb));
119
assert(got_exception);
123
GdkPixbuf *pb1 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
124
GdkPixbuf *pb2 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
125
g_object_ref(G_OBJECT(pb1));
126
unique_gobj<GdkPixbuf> u1(pb1);
127
unique_gobj<GdkPixbuf> u2(pb2);
129
assert(u1.get() == pb2);
131
assert(G_OBJECT(pb1)->ref_count == 1);
132
g_object_unref(G_OBJECT(pb1));
136
GdkPixbuf *pb1 = NULL;
137
GdkPixbuf *pb3 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
138
unique_gobj<GdkPixbuf> u1(pb1);
139
unique_gobj<GdkPixbuf> u2(nullptr);
140
unique_gobj<GdkPixbuf> u3(pb3);
149
GdkPixbuf *pb1 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
150
GdkPixbuf *pb2 = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 640, 480);
151
unique_gobj<GdkPixbuf> u(pb1);
154
assert(u.get() == pb2);
160
assert(sizeof(GdkPixbuf*) == sizeof(unique_gobj<GdkPixbuf>));
163
void deleter_test() {
164
unique_gobj<GdkPixbuf> u1;
165
assert(u1.get_deleter() == g_object_unref);
169
g_type_init(); // Still needed in precise.
171
fprintf(stderr, "NDEBUG defined, tests will not work.\n");