~ubuntu-branches/ubuntu/saucy/gimp/saucy

« back to all changes in this revision

Viewing changes to app/tests/test-gimpidtable.c

  • Committer: Package Import Robot
  • Author(s): Micah Gersten
  • Date: 2012-05-20 19:21:01 UTC
  • mfrom: (1.1.26) (0.4.16 sid)
  • Revision ID: package-import@ubuntu.com-20120520192101-bs7zetx8ffoq2nfv
Tags: 2.8.0-2ubuntu1
* Merge from Debian unstable (LP: #908472). Remaining Changes:
  - debian/patches/02_help-message.patch,
    debian/patches/03_gimp.desktop.in.in.patch:
    + Update some strings for Ubuntu
  - debian/control:
    + Update description
  - debian/rules:
    + Set gettext domain and update translation templates
* Drop the following patches that were applied upstream:
  - debian/patches/ghost-cursor.patch: fix Wacom tablet cursor events
  - debian/patches/embed-page-setup-dialog.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 2011 Martin Nordholts <martinn@src.gnome.org>
 
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 as published by
 
6
 * the Free Software Foundation; either version 3 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
 */
 
17
 
 
18
#include "config.h"
 
19
 
 
20
#include <glib-object.h>
 
21
 
 
22
#include "core/core-types.h"
 
23
 
 
24
#include "core/gimpidtable.h"
 
25
 
 
26
 
 
27
#define ADD_TEST(function) \
 
28
  g_test_add ("/gimpidtable/" #function, \
 
29
              GimpTestFixture, \
 
30
              NULL, \
 
31
              gimp_test_id_table_setup, \
 
32
              function, \
 
33
              gimp_test_id_table_teardown);
 
34
 
 
35
 
 
36
typedef struct
 
37
{
 
38
  GimpIdTable *id_table;
 
39
} GimpTestFixture;
 
40
 
 
41
 
 
42
static gpointer data1 = (gpointer) 0x00000001;
 
43
static gpointer data2 = (gpointer) 0x00000002;
 
44
 
 
45
 
 
46
static void
 
47
gimp_test_id_table_setup (GimpTestFixture *fixture,
 
48
                          gconstpointer    data)
 
49
{
 
50
  fixture->id_table = gimp_id_table_new ();
 
51
}
 
52
 
 
53
static void
 
54
gimp_test_id_table_teardown (GimpTestFixture *fixture,
 
55
                             gconstpointer    data)
 
56
{
 
57
  g_object_unref (fixture->id_table);
 
58
  fixture->id_table = NULL;
 
59
}
 
60
 
 
61
/**
 
62
 * insert_and_lookup:
 
63
 *
 
64
 * Test that insert and lookup works.
 
65
 **/
 
66
static void
 
67
insert_and_lookup (GimpTestFixture *f,
 
68
                   gconstpointer    data)
 
69
{
 
70
  gint     ret_id   = gimp_id_table_insert (f->id_table, data1);
 
71
  gpointer ret_data = gimp_id_table_lookup (f->id_table, ret_id);
 
72
 
 
73
  g_assert (ret_data == data1);
 
74
}
 
75
 
 
76
/**
 
77
 * insert_twice:
 
78
 *
 
79
 * Test that two consecutive inserts generates different IDs.
 
80
 **/
 
81
static void
 
82
insert_twice (GimpTestFixture *f,
 
83
              gconstpointer    data)
 
84
{
 
85
  gint     ret_id    = gimp_id_table_insert (f->id_table, data1);
 
86
  gpointer ret_data  = gimp_id_table_lookup (f->id_table, ret_id);
 
87
  gint     ret_id2   = gimp_id_table_insert (f->id_table, data2);
 
88
  gpointer ret_data2 = gimp_id_table_lookup (f->id_table, ret_id2);
 
89
 
 
90
  g_assert (ret_id    != ret_id2);
 
91
  g_assert (ret_data  == data1);
 
92
  g_assert (ret_data2 == data2);
 
93
}
 
94
 
 
95
/**
 
96
 * insert_with_id:
 
97
 *
 
98
 * Test that it is possible to insert data with a specific ID.
 
99
 **/
 
100
static void
 
101
insert_with_id (GimpTestFixture *f,
 
102
                gconstpointer    data)
 
103
{
 
104
  const int id = 10;
 
105
 
 
106
  int      ret_id   = gimp_id_table_insert_with_id (f->id_table, id, data1);
 
107
  gpointer ret_data = gimp_id_table_lookup (f->id_table, id);
 
108
 
 
109
  g_assert (ret_id   == id);
 
110
  g_assert (ret_data == data1);
 
111
}
 
112
 
 
113
/**
 
114
 * insert_with_id_existing:
 
115
 *
 
116
 * Test that it is not possible to insert data with a specific ID if
 
117
 * that ID already is inserted.
 
118
 **/
 
119
static void
 
120
insert_with_id_existing (GimpTestFixture *f,
 
121
                         gconstpointer    data)
 
122
{
 
123
  const int id = 10;
 
124
 
 
125
  int      ret_id    = gimp_id_table_insert_with_id (f->id_table, id, data1);
 
126
  gpointer ret_data  = gimp_id_table_lookup (f->id_table, ret_id);
 
127
  int      ret_id2   = gimp_id_table_insert_with_id (f->id_table, id, data2);
 
128
  gpointer ret_data2 = gimp_id_table_lookup (f->id_table, ret_id2);
 
129
 
 
130
  g_assert (id        == ret_id);
 
131
  g_assert (ret_id2   == -1);
 
132
  g_assert (ret_data  == data1);
 
133
  g_assert (ret_data2 == NULL);
 
134
}
 
135
 
 
136
/**
 
137
 * replace:
 
138
 *
 
139
 * Test that it is possible to replace data with a given ID with
 
140
 * different data.
 
141
 **/
 
142
static void
 
143
replace (GimpTestFixture *f,
 
144
         gconstpointer    data)
 
145
{
 
146
  int ret_id = gimp_id_table_insert (f->id_table, data1);
 
147
  gpointer ret_data;
 
148
 
 
149
  gimp_id_table_replace (f->id_table, ret_id, data2);
 
150
  ret_data = gimp_id_table_lookup (f->id_table, ret_id);
 
151
 
 
152
  g_assert (ret_data  == data2);
 
153
}
 
154
 
 
155
/**
 
156
 * replace_as_insert:
 
157
 *
 
158
 * Test that replace works like insert when there is no data to
 
159
 * replace.
 
160
 **/
 
161
static void
 
162
replace_as_insert (GimpTestFixture *f,
 
163
                   gconstpointer    data)
 
164
{
 
165
  const int id = 10;
 
166
 
 
167
  gpointer ret_data;
 
168
 
 
169
  gimp_id_table_replace (f->id_table, id, data1);
 
170
  ret_data = gimp_id_table_lookup (f->id_table, id);
 
171
 
 
172
  g_assert (ret_data  == data1);
 
173
}
 
174
 
 
175
/**
 
176
 * remove:
 
177
 *
 
178
 * Test that it is possible to remove data identified by the ID:
 
179
 **/
 
180
static void
 
181
remove (GimpTestFixture *f,
 
182
        gconstpointer    data)
 
183
{
 
184
  gint     ret_id            = gimp_id_table_insert (f->id_table, data1);
 
185
  void    *ret_data          = gimp_id_table_lookup (f->id_table, ret_id);
 
186
  gboolean remove_successful = gimp_id_table_remove (f->id_table, ret_id);
 
187
  void    *ret_data2         = gimp_id_table_lookup (f->id_table, ret_id);
 
188
  
 
189
  g_assert (remove_successful);
 
190
  g_assert (ret_data == data1);
 
191
  g_assert (ret_data2 == NULL);
 
192
}
 
193
 
 
194
/**
 
195
 * remove_non_existing:
 
196
 *
 
197
 * Tests that things work properly when trying to remove data with an
 
198
 * ID that doesn't exist.
 
199
 **/
 
200
static void
 
201
remove_non_existing (GimpTestFixture *f,
 
202
                     gconstpointer    data)
 
203
{
 
204
  const int id = 10;
 
205
 
 
206
  gboolean remove_successful = gimp_id_table_remove (f->id_table, id);
 
207
  void    *ret_data          = gimp_id_table_lookup (f->id_table, id);
 
208
  
 
209
  g_assert (! remove_successful);
 
210
  g_assert (ret_data == NULL);
 
211
}
 
212
 
 
213
int main(int argc, char **argv)
 
214
{
 
215
  g_type_init ();
 
216
  g_test_init (&argc, &argv, NULL);
 
217
 
 
218
  ADD_TEST (insert_and_lookup);
 
219
  ADD_TEST (insert_twice);
 
220
  ADD_TEST (insert_with_id);
 
221
  ADD_TEST (insert_with_id_existing);
 
222
  ADD_TEST (replace);
 
223
  ADD_TEST (replace_as_insert);
 
224
  ADD_TEST (remove);
 
225
  ADD_TEST (remove_non_existing);
 
226
 
 
227
  return g_test_run ();
 
228
}