Merge lp:~mhr3/dee/introspectable-sort-methods into lp:dee
- introspectable-sort-methods
- Merge into trunk
Proposed by
Michal Hruby
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Paweł Stołowski | ||||
Approved revision: | 376 | ||||
Merged at revision: | 376 | ||||
Proposed branch: | lp:~mhr3/dee/introspectable-sort-methods | ||||
Merge into: | lp:dee | ||||
Diff against target: |
418 lines (+289/-6) 5 files modified
bindings/python/Dee.py (+20/-1) src/dee-model.c (+98/-0) src/dee-model.h (+37/-5) tests/test-model-rows.c (+130/-0) vapi/dee-1.0.vapi (+4/-0) |
||||
To merge this branch: | bzr merge lp:~mhr3/dee/introspectable-sort-methods | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Paweł Stołowski (community) | Approve | ||
Review via email: mp+118801@code.launchpad.net |
Commit message
Make the *sorted methods usable with introspection
Description of the change
Dee's find_sorted and insert_sorted were not usable from introspectable languages.
Added a delegate that's introspection friendly and tests that make sure it's working.
To post a comment you must log in.
- 376. By Michal Hruby
-
Remove fixed FIXME
Revision history for this message
Michal Hruby (mhr3) wrote : | # |
> Looks, good. Just one question:
> 30 + # FIXME: perhaps override __eq__ on ModelIter?
> is this still applicable?
Right, already fixed.
Revision history for this message
Paweł Stołowski (stolowski) wrote : | # |
Looks good, tests pass.
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'bindings/python/Dee.py' | |||
2 | --- bindings/python/Dee.py 2012-06-27 15:36:53 +0000 | |||
3 | +++ bindings/python/Dee.py 2012-08-15 13:38:19 +0000 | |||
4 | @@ -63,14 +63,20 @@ | |||
5 | 63 | def insert_before (self, iter, *args): | 63 | def insert_before (self, iter, *args): |
6 | 64 | return self.insert_row_before (iter, self._build_row(args)) | 64 | return self.insert_row_before (iter, self._build_row(args)) |
7 | 65 | 65 | ||
8 | 66 | def insert_row_sorted (self, row_spec, sort_func, data): | ||
9 | 67 | return self.insert_row_sorted_with_sizes (row_spec, sort_func, data) | ||
10 | 68 | |||
11 | 66 | def insert_sorted (self, sort_func, *args): | 69 | def insert_sorted (self, sort_func, *args): |
12 | 67 | return self.insert_row_sorted (self._build_row(args), sort_func, None) | 70 | return self.insert_row_sorted (self._build_row(args), sort_func, None) |
13 | 68 | 71 | ||
14 | 72 | def find_row_sorted (self, row_spec, sort_func, data): | ||
15 | 73 | return self.find_row_sorted_with_sizes (row_spec, sort_func, data) | ||
16 | 74 | |||
17 | 69 | def find_sorted (self, sort_func, *args): | 75 | def find_sorted (self, sort_func, *args): |
18 | 70 | return self.find_row_sorted (self._build_row(args), sort_func, None) | 76 | return self.find_row_sorted (self._build_row(args), sort_func, None) |
19 | 71 | 77 | ||
20 | 72 | def get_schema (self): | 78 | def get_schema (self): |
22 | 73 | return Dee.Model.get_schema(self)[0] | 79 | return Dee.Model.get_schema(self) |
23 | 74 | 80 | ||
24 | 75 | def get_value (self, itr, column): | 81 | def get_value (self, itr, column): |
25 | 76 | return Dee.Model.get_value (self, itr, column).unpack() | 82 | return Dee.Model.get_value (self, itr, column).unpack() |
26 | @@ -108,8 +114,21 @@ | |||
27 | 108 | return self.get_n_rows() | 114 | return self.get_n_rows() |
28 | 109 | 115 | ||
29 | 110 | 116 | ||
30 | 117 | class ModelIter(Dee.ModelIter): | ||
31 | 118 | |||
32 | 119 | def __init__(self): | ||
33 | 120 | Dee.ModelIter.__init__(self) | ||
34 | 121 | |||
35 | 122 | def __eq__ (self, other): | ||
36 | 123 | if not isinstance (other, ModelIter): | ||
37 | 124 | return False | ||
38 | 125 | return repr(self) == repr(other) | ||
39 | 126 | |||
40 | 127 | |||
41 | 111 | 128 | ||
42 | 112 | Model = override(Model) | 129 | Model = override(Model) |
43 | 113 | __all__.append('Model') | 130 | __all__.append('Model') |
44 | 131 | ModelIter = override(ModelIter) | ||
45 | 132 | __all__.append('ModelIter') | ||
46 | 114 | 133 | ||
47 | 115 | 134 | ||
48 | 116 | 135 | ||
49 | === modified file 'src/dee-model.c' | |||
50 | --- src/dee-model.c 2012-02-28 00:36:16 +0000 | |||
51 | +++ src/dee-model.c 2012-08-15 13:38:19 +0000 | |||
52 | @@ -975,6 +975,20 @@ | |||
53 | 975 | return (* iface->insert_row_before) (self, iter, row_members); | 975 | return (* iface->insert_row_before) (self, iter, row_members); |
54 | 976 | } | 976 | } |
55 | 977 | 977 | ||
56 | 978 | /* Translates DeeCompareRowFunc callback into DeeCompareRowSizedFunc */ | ||
57 | 979 | static gint | ||
58 | 980 | dee_model_cmp_func_translate_func (GVariant **row1, | ||
59 | 981 | GVariant **row2, | ||
60 | 982 | gpointer data) | ||
61 | 983 | { | ||
62 | 984 | gpointer *all_data = (gpointer*) data; | ||
63 | 985 | DeeCompareRowSizedFunc cmp_func = (DeeCompareRowSizedFunc) all_data[0]; | ||
64 | 986 | gpointer user_data = all_data[1]; | ||
65 | 987 | guint array_length = GPOINTER_TO_UINT (all_data[2]); | ||
66 | 988 | |||
67 | 989 | return cmp_func (row1, array_length, row2, array_length, user_data); | ||
68 | 990 | } | ||
69 | 991 | |||
70 | 978 | /** | 992 | /** |
71 | 979 | * dee_model_insert_row_sorted: | 993 | * dee_model_insert_row_sorted: |
72 | 980 | * @self: The model to do a sorted insert on | 994 | * @self: The model to do a sorted insert on |
73 | @@ -1009,6 +1023,41 @@ | |||
74 | 1009 | } | 1023 | } |
75 | 1010 | 1024 | ||
76 | 1011 | /** | 1025 | /** |
77 | 1026 | * dee_model_insert_row_sorted_with_sizes: | ||
78 | 1027 | * @self: The model to do a sorted insert on | ||
79 | 1028 | * @row_members: (array zero-terminated=1): An array of | ||
80 | 1029 | * #GVariants with type signature matching those of the | ||
81 | 1030 | * column schemas of @self. If any of the variants have floating | ||
82 | 1031 | * references they will be consumed. | ||
83 | 1032 | * @cmp_func: (scope call): Callback used for comparison or rows | ||
84 | 1033 | * @user_data: (closure): Arbitrary pointer passed to @cmp_func during search | ||
85 | 1034 | * | ||
86 | 1035 | * Inserts a row in @self according to the sorting specified by @cmp_func. | ||
87 | 1036 | * If you use this method for insertion you should not use other methods as this | ||
88 | 1037 | * method assumes the model to be already sorted by @cmp_func. | ||
89 | 1038 | * | ||
90 | 1039 | * Returns: (transfer none) (type Dee.ModelIter): A #DeeModelIter pointing to the new row | ||
91 | 1040 | */ | ||
92 | 1041 | DeeModelIter* | ||
93 | 1042 | dee_model_insert_row_sorted_with_sizes (DeeModel *self, | ||
94 | 1043 | GVariant **row_members, | ||
95 | 1044 | DeeCompareRowSizedFunc cmp_func, | ||
96 | 1045 | gpointer user_data) | ||
97 | 1046 | { | ||
98 | 1047 | gpointer all_data[3]; | ||
99 | 1048 | |||
100 | 1049 | g_return_val_if_fail (DEE_IS_MODEL (self), NULL); | ||
101 | 1050 | |||
102 | 1051 | all_data[0] = cmp_func; | ||
103 | 1052 | all_data[1] = user_data; | ||
104 | 1053 | all_data[2] = GUINT_TO_POINTER (dee_model_get_n_columns (self)); | ||
105 | 1054 | |||
106 | 1055 | return dee_model_insert_row_sorted (self, row_members, | ||
107 | 1056 | dee_model_cmp_func_translate_func, | ||
108 | 1057 | all_data); | ||
109 | 1058 | } | ||
110 | 1059 | |||
111 | 1060 | /** | ||
112 | 1012 | * dee_model_insert_sorted: | 1061 | * dee_model_insert_sorted: |
113 | 1013 | * @self: The model to do a sorted insert on | 1062 | * @self: The model to do a sorted insert on |
114 | 1014 | * @cmp_func: (scope call): Callback used for comparison or rows | 1063 | * @cmp_func: (scope call): Callback used for comparison or rows |
115 | @@ -1103,6 +1152,55 @@ | |||
116 | 1103 | } | 1152 | } |
117 | 1104 | 1153 | ||
118 | 1105 | /** | 1154 | /** |
119 | 1155 | * dee_model_find_row_sorted_with_sizes: | ||
120 | 1156 | * @self: The model to search | ||
121 | 1157 | * @row_spec: (array zero-terminated=1): An array of | ||
122 | 1158 | * #GVariants with type signature matching those of the | ||
123 | 1159 | * column schemas of @self. No references will be taken on the variants. | ||
124 | 1160 | * @cmp_func: (scope call): Callback used for comparison or rows | ||
125 | 1161 | * @user_data: (closure): Arbitrary pointer passed to @cmp_func during search | ||
126 | 1162 | * @out_was_found: (out): A place to store a boolean value that will be set when | ||
127 | 1163 | * this method returns. If %TRUE then an exact match was found. | ||
128 | 1164 | * If %FALSE then the returned iter points to a row just after | ||
129 | 1165 | * where @row_spec would have been inserted. | ||
130 | 1166 | * Pass %NULL to ignore. | ||
131 | 1167 | * | ||
132 | 1168 | * Like dee_model_find_row_sorted(), but uses DeeCompareRowSizedFunc and | ||
133 | 1169 | * therefore doesn't cause trouble when used from introspected languages. | ||
134 | 1170 | * | ||
135 | 1171 | * Finds a row in @self according to the sorting specified by @cmp_func. | ||
136 | 1172 | * This method will assume that @self is already sorted by @cmp_func. | ||
137 | 1173 | * | ||
138 | 1174 | * If you use this method for searching you should only use | ||
139 | 1175 | * dee_model_insert_row_sorted() (or dee_model_insert_row_sorted_with_sizes()) | ||
140 | 1176 | * to insert rows in the model. | ||
141 | 1177 | * | ||
142 | 1178 | * Returns: (transfer none) (type Dee.ModelIter): If @out_was_found is set to | ||
143 | 1179 | * %TRUE then a #DeeModelIter pointing to the first matching row. | ||
144 | 1180 | * If it is %FALSE then the iter pointing to the row just after where | ||
145 | 1181 | * @row_spec_would have been inserted. | ||
146 | 1182 | */ | ||
147 | 1183 | DeeModelIter* | ||
148 | 1184 | dee_model_find_row_sorted_with_sizes (DeeModel *self, | ||
149 | 1185 | GVariant **row_spec, | ||
150 | 1186 | DeeCompareRowSizedFunc cmp_func, | ||
151 | 1187 | gpointer user_data, | ||
152 | 1188 | gboolean *out_was_found) | ||
153 | 1189 | { | ||
154 | 1190 | gpointer all_data[3]; | ||
155 | 1191 | |||
156 | 1192 | g_return_val_if_fail (DEE_IS_MODEL (self), NULL); | ||
157 | 1193 | |||
158 | 1194 | all_data[0] = cmp_func; | ||
159 | 1195 | all_data[1] = user_data; | ||
160 | 1196 | all_data[2] = GUINT_TO_POINTER (dee_model_get_n_columns (self)); | ||
161 | 1197 | |||
162 | 1198 | return dee_model_find_row_sorted (self, row_spec, | ||
163 | 1199 | dee_model_cmp_func_translate_func, | ||
164 | 1200 | all_data, out_was_found); | ||
165 | 1201 | } | ||
166 | 1202 | |||
167 | 1203 | /** | ||
168 | 1106 | * dee_model_find_sorted: | 1204 | * dee_model_find_sorted: |
169 | 1107 | * @self: The model to search | 1205 | * @self: The model to search |
170 | 1108 | * @cmp_func: (scope call): Callback used for comparison or rows | 1206 | * @cmp_func: (scope call): Callback used for comparison or rows |
171 | 1109 | 1207 | ||
172 | === modified file 'src/dee-model.h' | |||
173 | --- src/dee-model.h 2012-03-19 11:18:50 +0000 | |||
174 | +++ src/dee-model.h 2012-08-15 13:38:19 +0000 | |||
175 | @@ -78,6 +78,27 @@ | |||
176 | 78 | GVariant** row2, | 78 | GVariant** row2, |
177 | 79 | gpointer user_data); | 79 | gpointer user_data); |
178 | 80 | 80 | ||
179 | 81 | /** | ||
180 | 82 | * DeeCompareRowSizedFunc: | ||
181 | 83 | * @row1: (array length=row1_length): Row data | ||
182 | 84 | * @row1_length: The number of elements in row1 array | ||
183 | 85 | * @row2: (array length=row2_length): Row data to compare with | ||
184 | 86 | * @row2_length: The number of elements in row2 array | ||
185 | 87 | * @user_data: (closure): User data passed to comparison function | ||
186 | 88 | * | ||
187 | 89 | * Compares @row1 and @row2. Mainly used with | ||
188 | 90 | * dee_model_insert_row_sorted_with_sizes() and | ||
189 | 91 | * dee_model_find_row_sorted_with_sizes(). | ||
190 | 92 | * | ||
191 | 93 | * Returns: -1, 0, or 1 if @row1 is respectively less than, equal, or greater | ||
192 | 94 | * than @row2. | ||
193 | 95 | */ | ||
194 | 96 | typedef gint (*DeeCompareRowSizedFunc) (GVariant** row1, | ||
195 | 97 | guint row1_length, | ||
196 | 98 | GVariant** row2, | ||
197 | 99 | guint row2_length, | ||
198 | 100 | gpointer user_data); | ||
199 | 101 | |||
200 | 81 | struct _DeeModelIface | 102 | struct _DeeModelIface |
201 | 82 | { | 103 | { |
202 | 83 | GTypeInterface g_iface; | 104 | GTypeInterface g_iface; |
203 | @@ -291,6 +312,11 @@ | |||
204 | 291 | DeeCompareRowFunc cmp_func, | 312 | DeeCompareRowFunc cmp_func, |
205 | 292 | gpointer user_data); | 313 | gpointer user_data); |
206 | 293 | 314 | ||
207 | 315 | DeeModelIter* dee_model_insert_row_sorted_with_sizes (DeeModel *self, | ||
208 | 316 | GVariant **row_members, | ||
209 | 317 | DeeCompareRowSizedFunc cmp_func, | ||
210 | 318 | gpointer user_data); | ||
211 | 319 | |||
212 | 294 | DeeModelIter* dee_model_insert_sorted (DeeModel *self, | 320 | DeeModelIter* dee_model_insert_sorted (DeeModel *self, |
213 | 295 | DeeCompareRowFunc cmp_func, | 321 | DeeCompareRowFunc cmp_func, |
214 | 296 | gpointer user_data, | 322 | gpointer user_data, |
215 | @@ -302,11 +328,17 @@ | |||
216 | 302 | gpointer user_data, | 328 | gpointer user_data, |
217 | 303 | gboolean *out_was_found); | 329 | gboolean *out_was_found); |
218 | 304 | 330 | ||
224 | 305 | DeeModelIter* dee_model_find_sorted (DeeModel *self, | 331 | DeeModelIter* dee_model_find_row_sorted_with_sizes (DeeModel *self, |
225 | 306 | DeeCompareRowFunc cmp_func, | 332 | GVariant **row_spec, |
226 | 307 | gpointer user_data, | 333 | DeeCompareRowSizedFunc cmp_func, |
227 | 308 | gboolean *out_was_found, | 334 | gpointer user_data, |
228 | 309 | ...); | 335 | gboolean *out_was_found); |
229 | 336 | |||
230 | 337 | DeeModelIter* dee_model_find_sorted (DeeModel *self, | ||
231 | 338 | DeeCompareRowFunc cmp_func, | ||
232 | 339 | gpointer user_data, | ||
233 | 340 | gboolean *out_was_found, | ||
234 | 341 | ...); | ||
235 | 310 | 342 | ||
236 | 311 | void dee_model_remove (DeeModel *self, | 343 | void dee_model_remove (DeeModel *self, |
237 | 312 | DeeModelIter *iter); | 344 | DeeModelIter *iter); |
238 | 313 | 345 | ||
239 | === modified file 'tests/test-model-rows.c' | |||
240 | --- tests/test-model-rows.c 2012-01-26 19:08:42 +0000 | |||
241 | +++ tests/test-model-rows.c 2012-08-15 13:38:19 +0000 | |||
242 | @@ -47,6 +47,7 @@ | |||
243 | 47 | static void test_iter_backwards (RowsFixture *fix, gconstpointer data); | 47 | static void test_iter_backwards (RowsFixture *fix, gconstpointer data); |
244 | 48 | static void test_illegal_access (RowsFixture *fix, gconstpointer data); | 48 | static void test_illegal_access (RowsFixture *fix, gconstpointer data); |
245 | 49 | static void test_sorted (RowsFixture *fix, gconstpointer data); | 49 | static void test_sorted (RowsFixture *fix, gconstpointer data); |
246 | 50 | static void test_sorted_with_sizes (RowsFixture *fix, gconstpointer data); | ||
247 | 50 | 51 | ||
248 | 51 | static void test_model_iter_copy (RowsFixture *fix, gconstpointer data); | 52 | static void test_model_iter_copy (RowsFixture *fix, gconstpointer data); |
249 | 52 | static void test_model_iter_free (RowsFixture *fix, gconstpointer data); | 53 | static void test_model_iter_free (RowsFixture *fix, gconstpointer data); |
250 | @@ -133,6 +134,13 @@ | |||
251 | 133 | proxy_rows_setup, test_sorted, proxy_rows_teardown); | 134 | proxy_rows_setup, test_sorted, proxy_rows_teardown); |
252 | 134 | g_test_add (TXN_DOMAIN"/Sorted", RowsFixture, 0, | 135 | g_test_add (TXN_DOMAIN"/Sorted", RowsFixture, 0, |
253 | 135 | txn_rows_setup, test_sorted, txn_rows_teardown); | 136 | txn_rows_setup, test_sorted, txn_rows_teardown); |
254 | 137 | |||
255 | 138 | g_test_add (SEQ_DOMAIN"/Sorted/WithSizes", RowsFixture, 0, | ||
256 | 139 | seq_rows_setup, test_sorted_with_sizes, seq_rows_teardown); | ||
257 | 140 | g_test_add (PROXY_DOMAIN"/Sorted/WithSizes", RowsFixture, 0, | ||
258 | 141 | proxy_rows_setup, test_sorted_with_sizes, proxy_rows_teardown); | ||
259 | 142 | g_test_add (TXN_DOMAIN"/Sorted/WithSizes", RowsFixture, 0, | ||
260 | 143 | txn_rows_setup, test_sorted_with_sizes, txn_rows_teardown); | ||
261 | 136 | } | 144 | } |
262 | 137 | 145 | ||
263 | 138 | static void | 146 | static void |
264 | @@ -560,3 +568,125 @@ | |||
265 | 560 | g_assert (was_found); | 568 | g_assert (was_found); |
266 | 561 | g_assert (result == hter); | 569 | g_assert (result == hter); |
267 | 562 | } | 570 | } |
268 | 571 | |||
269 | 572 | static gint | ||
270 | 573 | sized_cmp_col_0 (GVariant **row1, guint row1_length, | ||
271 | 574 | GVariant **row2, guint row2_length, gpointer user_data) | ||
272 | 575 | { | ||
273 | 576 | g_assert_cmpstr (user_data, ==, "test-user-data"); | ||
274 | 577 | g_assert_cmpuint (row1_length, ==, 2); | ||
275 | 578 | g_assert_cmpuint (row2_length, ==, 2); | ||
276 | 579 | g_assert_cmpuint (row1_length, ==, row2_length); | ||
277 | 580 | return g_variant_get_int32 (row2[0]) - g_variant_get_int32 (row1[0]); | ||
278 | 581 | } | ||
279 | 582 | |||
280 | 583 | static void | ||
281 | 584 | test_sorted_with_sizes (RowsFixture *fix, gconstpointer data) | ||
282 | 585 | { | ||
283 | 586 | DeeModelIter *hter, *iter, *jter, *kter; | ||
284 | 587 | gboolean was_found; | ||
285 | 588 | GVariant *row_spec[2]; | ||
286 | 589 | |||
287 | 590 | /* FINAL MODEL: [(28,s), (27,s), (26,s), (25,s)] | ||
288 | 591 | * ~= [hter, iter, jter, kter] */ | ||
289 | 592 | |||
290 | 593 | row_spec[0] = g_variant_new_int32 (0); | ||
291 | 594 | row_spec[1] = g_variant_new_string (""); | ||
292 | 595 | /* Test find() with an empty model. With NULL was_found arg */ | ||
293 | 596 | iter = dee_model_find_row_sorted_with_sizes (fix->model, row_spec, | ||
294 | 597 | sized_cmp_col_0, | ||
295 | 598 | "test-user-data", | ||
296 | 599 | NULL); | ||
297 | 600 | g_assert (iter == dee_model_get_last_iter (fix->model)); | ||
298 | 601 | |||
299 | 602 | /* Test find() with an empty model. With non-NULL was_found arg */ | ||
300 | 603 | was_found = TRUE; | ||
301 | 604 | iter = dee_model_find_row_sorted_with_sizes (fix->model, row_spec, | ||
302 | 605 | sized_cmp_col_0, | ||
303 | 606 | "test-user-data", | ||
304 | 607 | &was_found); | ||
305 | 608 | g_assert (!was_found); | ||
306 | 609 | g_assert (iter == dee_model_get_last_iter (fix->model)); | ||
307 | 610 | |||
308 | 611 | /* Insert the first row */ | ||
309 | 612 | row_spec[0] = g_variant_new_int32 (27); | ||
310 | 613 | row_spec[1] = g_variant_new_string ("Sorta sorted"); | ||
311 | 614 | iter = dee_model_insert_row_sorted_with_sizes (fix->model, row_spec, | ||
312 | 615 | sized_cmp_col_0, | ||
313 | 616 | "test-user-data"); | ||
314 | 617 | g_assert (iter != dee_model_get_last_iter (fix->model)); | ||
315 | 618 | g_assert (iter == dee_model_get_first_iter (fix->model)); | ||
316 | 619 | |||
317 | 620 | /* Test append */ | ||
318 | 621 | row_spec[0] = g_variant_new_int32 (25); | ||
319 | 622 | row_spec[1] = g_variant_new_string ("Sorta sorted"); | ||
320 | 623 | kter = dee_model_insert_row_sorted_with_sizes (fix->model, row_spec, | ||
321 | 624 | sized_cmp_col_0, | ||
322 | 625 | "test-user-data"); | ||
323 | 626 | g_assert (kter != dee_model_get_last_iter (fix->model)); | ||
324 | 627 | g_assert (kter != dee_model_get_first_iter (fix->model)); | ||
325 | 628 | g_assert (iter == dee_model_get_first_iter (fix->model)); | ||
326 | 629 | g_assert (kter != iter); | ||
327 | 630 | |||
328 | 631 | g_assert_cmpint (2, ==, dee_model_get_n_rows (fix->model)); | ||
329 | 632 | g_assert (kter == dee_model_next (fix->model, iter)); | ||
330 | 633 | |||
331 | 634 | /* Test insert in between rows */ | ||
332 | 635 | row_spec[0] = g_variant_new_int32 (26); | ||
333 | 636 | row_spec[1] = g_variant_new_string ("Sorta sorted"); | ||
334 | 637 | jter = dee_model_insert_row_sorted_with_sizes (fix->model, row_spec, | ||
335 | 638 | sized_cmp_col_0, | ||
336 | 639 | "test-user-data"); | ||
337 | 640 | g_assert (jter != dee_model_get_last_iter (fix->model)); | ||
338 | 641 | g_assert (jter != dee_model_get_first_iter (fix->model)); | ||
339 | 642 | g_assert (iter == dee_model_get_first_iter (fix->model)); | ||
340 | 643 | g_assert (jter != iter); | ||
341 | 644 | g_assert (jter != kter); | ||
342 | 645 | |||
343 | 646 | g_assert (jter == dee_model_next (fix->model, iter)); | ||
344 | 647 | g_assert (kter == dee_model_next (fix->model, jter)); | ||
345 | 648 | g_assert (dee_model_get_last_iter (fix->model) == dee_model_next (fix->model, kter)); | ||
346 | 649 | |||
347 | 650 | /* Test prepend */ | ||
348 | 651 | row_spec[0] = g_variant_new_int32 (28); | ||
349 | 652 | row_spec[1] = g_variant_new_string ("Sorta sorted"); | ||
350 | 653 | hter = dee_model_insert_row_sorted_with_sizes (fix->model, row_spec, | ||
351 | 654 | sized_cmp_col_0, | ||
352 | 655 | "test-user-data"); | ||
353 | 656 | g_assert (hter == dee_model_get_first_iter (fix->model)); | ||
354 | 657 | g_assert (iter == dee_model_next (fix->model, hter)); | ||
355 | 658 | |||
356 | 659 | g_assert_cmpint (4, ==, dee_model_get_n_rows (fix->model)); | ||
357 | 660 | |||
358 | 661 | /* Test find() again now that we have data in the model */ | ||
359 | 662 | DeeModelIter *result; | ||
360 | 663 | row_spec[0] = g_variant_new_int32 (24); | ||
361 | 664 | row_spec[1] = g_variant_new_string (""); | ||
362 | 665 | result = dee_model_find_row_sorted_with_sizes (fix->model, row_spec, | ||
363 | 666 | sized_cmp_col_0, | ||
364 | 667 | "test-user-data", NULL); | ||
365 | 668 | g_assert (result == dee_model_get_last_iter (fix->model)); | ||
366 | 669 | row_spec[0] = g_variant_new_int32 (28); | ||
367 | 670 | row_spec[1] = g_variant_new_string (""); | ||
368 | 671 | result = dee_model_find_row_sorted_with_sizes (fix->model, row_spec, | ||
369 | 672 | sized_cmp_col_0, | ||
370 | 673 | "test-user-data", NULL); | ||
371 | 674 | g_assert (result == hter); | ||
372 | 675 | |||
373 | 676 | /* Test find(). With non-NULL was_found arg */ | ||
374 | 677 | was_found = FALSE; | ||
375 | 678 | row_spec[0] = g_variant_new_int32 (24); | ||
376 | 679 | row_spec[1] = g_variant_new_string (""); | ||
377 | 680 | result = dee_model_find_row_sorted_with_sizes (fix->model, row_spec, | ||
378 | 681 | sized_cmp_col_0, | ||
379 | 682 | "test-user-data", &was_found); | ||
380 | 683 | g_assert (result == dee_model_get_last_iter (fix->model)); | ||
381 | 684 | row_spec[0] = g_variant_new_int32 (28); | ||
382 | 685 | row_spec[1] = g_variant_new_string (""); | ||
383 | 686 | result = dee_model_find_row_sorted_with_sizes (fix->model, row_spec, | ||
384 | 687 | sized_cmp_col_0, | ||
385 | 688 | "test-user-data", &was_found); | ||
386 | 689 | g_assert (was_found); | ||
387 | 690 | g_assert (result == hter); | ||
388 | 691 | } | ||
389 | 692 | |||
390 | 563 | 693 | ||
391 | === modified file 'vapi/dee-1.0.vapi' | |||
392 | --- vapi/dee-1.0.vapi 2012-03-19 11:18:50 +0000 | |||
393 | +++ vapi/dee-1.0.vapi 2012-08-15 13:38:19 +0000 | |||
394 | @@ -208,6 +208,7 @@ | |||
395 | 208 | public abstract unowned Dee.ModelIter append_row ([CCode (array_length = false, array_null_terminated = true)] GLib.Variant[] row_members); | 208 | public abstract unowned Dee.ModelIter append_row ([CCode (array_length = false, array_null_terminated = true)] GLib.Variant[] row_members); |
396 | 209 | public abstract void clear (); | 209 | public abstract void clear (); |
397 | 210 | public abstract unowned Dee.ModelIter find_row_sorted ([CCode (array_length = false, array_null_terminated = true)] GLib.Variant[] row_spec, [CCode (delegate_target_pos = 2.5)] Dee.CompareRowFunc cmp_func, out bool out_was_found); | 210 | public abstract unowned Dee.ModelIter find_row_sorted ([CCode (array_length = false, array_null_terminated = true)] GLib.Variant[] row_spec, [CCode (delegate_target_pos = 2.5)] Dee.CompareRowFunc cmp_func, out bool out_was_found); |
398 | 211 | public unowned Dee.ModelIter find_row_sorted_with_sizes ([CCode (array_length = false, array_null_terminated = true)] GLib.Variant[] row_spec, [CCode (delegate_target_pos = 2.5)] Dee.CompareRowSizedFunc cmp_func, out bool out_was_found); | ||
399 | 211 | public unowned Dee.ModelIter find_sorted ([CCode (delegate_target_pos = 1.5)] Dee.CompareRowFunc cmp_func, out bool out_was_found, ...); | 212 | public unowned Dee.ModelIter find_sorted ([CCode (delegate_target_pos = 1.5)] Dee.CompareRowFunc cmp_func, out bool out_was_found, ...); |
400 | 212 | public void @get (Dee.ModelIter iter, ...); | 213 | public void @get (Dee.ModelIter iter, ...); |
401 | 213 | public abstract bool get_bool (Dee.ModelIter iter, uint column); | 214 | public abstract bool get_bool (Dee.ModelIter iter, uint column); |
402 | @@ -235,6 +236,7 @@ | |||
403 | 235 | public abstract unowned Dee.ModelIter insert_row (uint pos, [CCode (array_length = false, array_null_terminated = true)] GLib.Variant[] row_members); | 236 | public abstract unowned Dee.ModelIter insert_row (uint pos, [CCode (array_length = false, array_null_terminated = true)] GLib.Variant[] row_members); |
404 | 236 | public abstract unowned Dee.ModelIter insert_row_before (Dee.ModelIter iter, [CCode (array_length = false, array_null_terminated = true)] GLib.Variant[] row_members); | 237 | public abstract unowned Dee.ModelIter insert_row_before (Dee.ModelIter iter, [CCode (array_length = false, array_null_terminated = true)] GLib.Variant[] row_members); |
405 | 237 | public abstract unowned Dee.ModelIter insert_row_sorted ([CCode (array_length = false, array_null_terminated = true)] GLib.Variant[] row_members, Dee.CompareRowFunc cmp_func); | 238 | public abstract unowned Dee.ModelIter insert_row_sorted ([CCode (array_length = false, array_null_terminated = true)] GLib.Variant[] row_members, Dee.CompareRowFunc cmp_func); |
406 | 239 | public unowned Dee.ModelIter insert_row_sorted_with_sizes ([CCode (array_length = false, array_null_terminated = true)] GLib.Variant[] row_members, Dee.CompareRowSizedFunc cmp_func); | ||
407 | 238 | public unowned Dee.ModelIter insert_sorted ([CCode (delegate_target_pos = 1.5)] Dee.CompareRowFunc cmp_func, ...); | 240 | public unowned Dee.ModelIter insert_sorted ([CCode (delegate_target_pos = 1.5)] Dee.CompareRowFunc cmp_func, ...); |
408 | 239 | public abstract bool is_first (Dee.ModelIter iter); | 241 | public abstract bool is_first (Dee.ModelIter iter); |
409 | 240 | public abstract bool is_last (Dee.ModelIter iter); | 242 | public abstract bool is_last (Dee.ModelIter iter); |
410 | @@ -343,6 +345,8 @@ | |||
411 | 343 | [CCode (cheader_filename = "dee.h", instance_pos = 2.9)] | 345 | [CCode (cheader_filename = "dee.h", instance_pos = 2.9)] |
412 | 344 | public delegate int CompareRowFunc ([CCode (array_length = false)] GLib.Variant[] row1, [CCode (array_length = false)] GLib.Variant[] row2); | 346 | public delegate int CompareRowFunc ([CCode (array_length = false)] GLib.Variant[] row1, [CCode (array_length = false)] GLib.Variant[] row2); |
413 | 345 | [CCode (cheader_filename = "dee.h", instance_pos = 2.9)] | 347 | [CCode (cheader_filename = "dee.h", instance_pos = 2.9)] |
414 | 348 | public delegate int CompareRowSizedFunc ([CCode (array_length_cname = "row1_length", array_length_pos = 1.5, array_length_type = "guint")] GLib.Variant[] row1, [CCode (array_length_cname = "row2_length", array_length_pos = 2.1, array_length_type = "guint")] GLib.Variant[] row2); | ||
415 | 349 | [CCode (cheader_filename = "dee.h", instance_pos = 2.9)] | ||
416 | 346 | public delegate void FilterMapFunc (Dee.Model orig_model, Dee.FilterModel filter_model); | 350 | public delegate void FilterMapFunc (Dee.Model orig_model, Dee.FilterModel filter_model); |
417 | 347 | [CCode (cheader_filename = "dee.h", instance_pos = 3.9)] | 351 | [CCode (cheader_filename = "dee.h", instance_pos = 3.9)] |
418 | 348 | public delegate bool FilterMapNotify (Dee.Model orig_model, Dee.ModelIter orig_iter, Dee.FilterModel filter_model); | 352 | public delegate bool FilterMapNotify (Dee.Model orig_model, Dee.ModelIter orig_iter, Dee.FilterModel filter_model); |
Looks, good. Just one question:
30 + # FIXME: perhaps override __eq__ on ModelIter?
is this still applicable?