1
2 #include <r_anal.h>
3
4 #include "minunit.h"
5
test_meta_set()6 bool test_meta_set() {
7 RAnal *anal = r_anal_new ();
8
9 r_meta_set (anal, R_META_TYPE_DATA, 0x100, 4, NULL);
10 r_meta_set_string (anal, R_META_TYPE_COMMENT, 0x100, "summer of love");
11 r_meta_set_with_subtype (anal, R_META_TYPE_STRING, R_STRING_ENC_UTF8, 0x200, 0x30, "true confessions");
12
13 bool found[3] = { 0 };
14 size_t count = 0;
15 RIntervalTreeIter it;
16 RAnalMetaItem *item;
17 r_interval_tree_foreach (&anal->meta, it, item) {
18 count++;
19 RIntervalNode *node = r_interval_tree_iter_get (&it);
20 switch (item->type) {
21 case R_META_TYPE_DATA:
22 mu_assert_eq (node->start, 0x100, "node start");
23 mu_assert_eq (node->end, 0x103, "node end (inclusive)");
24 mu_assert_null (item->str, "no string");
25 mu_assert_eq (item->subtype, 0, "no subtype");
26 found[0] = true;
27 break;
28 case R_META_TYPE_COMMENT:
29 mu_assert_eq (node->start, 0x100, "node start");
30 mu_assert_eq (node->end, 0x100, "node end (inclusive)");
31 mu_assert_streq (item->str, "summer of love", "comment string");
32 mu_assert_eq (item->subtype, 0, "no subtype");
33 found[1] = true;
34 break;
35 case R_META_TYPE_STRING:
36 mu_assert_eq (node->start, 0x200, "node start");
37 mu_assert_eq (node->end, 0x22f, "node end (inclusive)");
38 mu_assert_streq (item->str, "true confessions", "string string");
39 mu_assert_eq (item->subtype, R_STRING_ENC_UTF8, "subtype");
40 found[2] = true;
41 break;
42 default:
43 break;
44 }
45 }
46 mu_assert_eq (count, 3, "set count");
47 mu_assert ("meta 0", found[0]);
48 mu_assert ("meta 1", found[1]);
49 mu_assert ("meta 2", found[2]);
50
51 // Override an item, changing only its size
52 r_meta_set (anal, R_META_TYPE_DATA, 0x100, 8, NULL);
53
54 count = 0;
55 found[0] = found[1] = found[2] = false;
56 r_interval_tree_foreach (&anal->meta, it, item) {
57 count++;
58 RIntervalNode *node = r_interval_tree_iter_get (&it);
59 switch (item->type) {
60 case R_META_TYPE_DATA:
61 mu_assert_eq (node->start, 0x100, "node start");
62 mu_assert_eq (node->end, 0x107, "node end (inclusive)");
63 mu_assert_null (item->str, "no string");
64 mu_assert_eq (item->subtype, 0, "no subtype");
65 found[0] = true;
66 break;
67 case R_META_TYPE_COMMENT:
68 mu_assert_eq (node->start, 0x100, "node start");
69 mu_assert_eq (node->end, 0x100, "node end (inclusive)");
70 mu_assert_streq (item->str, "summer of love", "comment string");
71 mu_assert_eq (item->subtype, 0, "no subtype");
72 found[1] = true;
73 break;
74 case R_META_TYPE_STRING:
75 mu_assert_eq (node->start, 0x200, "node start");
76 mu_assert_eq (node->end, 0x22f, "node end (inclusive)");
77 mu_assert_streq (item->str, "true confessions", "string string");
78 mu_assert_eq (item->subtype, R_STRING_ENC_UTF8, "subtype");
79 found[2] = true;
80 break;
81 default:
82 break;
83 }
84 }
85 mu_assert_eq (count, 3, "set count");
86 mu_assert ("meta 0", found[0]);
87 mu_assert ("meta 1", found[1]);
88 mu_assert ("meta 2", found[2]);
89
90 // Override items, changing their contents
91 r_meta_set_string (anal, R_META_TYPE_COMMENT, 0x100, "this ain't the summer of love");
92 r_meta_set_with_subtype (anal, R_META_TYPE_STRING, R_STRING_ENC_UTF16LE, 0x200, 0x40, "e.t.i. (extra terrestrial intelligence)");
93
94 count = 0;
95 found[0] = found[1] = found[2] = false;
96 r_interval_tree_foreach (&anal->meta, it, item) {
97 count++;
98 RIntervalNode *node = r_interval_tree_iter_get (&it);
99 switch (item->type) {
100 case R_META_TYPE_DATA:
101 mu_assert_eq (node->start, 0x100, "node start");
102 mu_assert_eq (node->end, 0x107, "node end (inclusive)");
103 mu_assert_null (item->str, "no string");
104 mu_assert_eq (item->subtype, 0, "no subtype");
105 found[0] = true;
106 break;
107 case R_META_TYPE_COMMENT:
108 mu_assert_eq (node->start, 0x100, "node start");
109 mu_assert_eq (node->end, 0x100, "node end (inclusive)");
110 mu_assert_streq (item->str, "this ain't the summer of love", "comment string");
111 mu_assert_eq (item->subtype, 0, "no subtype");
112 found[1] = true;
113 break;
114 case R_META_TYPE_STRING:
115 mu_assert_eq (node->start, 0x200, "node start");
116 mu_assert_eq (node->end, 0x23f, "node end (inclusive)");
117 mu_assert_streq (item->str, "e.t.i. (extra terrestrial intelligence)", "string string");
118 mu_assert_eq (item->subtype, R_STRING_ENC_UTF16LE, "subtype");
119 found[2] = true;
120 break;
121 default:
122 break;
123 }
124 }
125 mu_assert_eq (count, 3, "set count");
126 mu_assert ("meta 0", found[0]);
127 mu_assert ("meta 1", found[1]);
128 mu_assert ("meta 2", found[2]);
129
130 r_anal_free (anal);
131 mu_end;
132 }
133
test_meta_get_at()134 bool test_meta_get_at() {
135 RAnal *anal = r_anal_new ();
136
137 r_meta_set (anal, R_META_TYPE_DATA, 0x100, 4, NULL);
138 r_meta_set_string (anal, R_META_TYPE_COMMENT, 0x100, "vera gemini");
139 r_meta_set_with_subtype (anal, R_META_TYPE_STRING, R_STRING_ENC_UTF8, 0x200, 0x30, "true confessions");
140
141 RAnalMetaItem *item = r_meta_get_at (anal, 0x100, R_META_TYPE_COMMENT, NULL);
142 mu_assert_notnull (item, "get item");
143 mu_assert_streq (item->str, "vera gemini", "get contents");
144
145 ut64 size;
146 item = r_meta_get_at (anal, 0x100, R_META_TYPE_DATA, &size);
147 mu_assert_notnull (item, "get item");
148 mu_assert_eq (item->type, R_META_TYPE_DATA, "get contents");
149 mu_assert_eq (size, 4, "get size");
150
151 item = r_meta_get_at (anal, 0x200, R_META_TYPE_ANY, NULL);
152 mu_assert_notnull (item, "get item");
153 mu_assert_streq (item->str, "true confessions", "get contents");
154
155 item = r_meta_get_at (anal, 0x100, R_META_TYPE_ANY, NULL);
156 mu_assert_notnull (item, "get item");
157 // which one we get is undefined here (intended)
158
159 item = r_meta_get_at (anal, 0x1ff, R_META_TYPE_ANY, NULL);
160 mu_assert_null (item, "get item");
161 item = r_meta_get_at (anal, 0x201, R_META_TYPE_ANY, NULL);
162 mu_assert_null (item, "get item");
163 item = r_meta_get_at (anal, 0xff, R_META_TYPE_ANY, NULL);
164 mu_assert_null (item, "get item");
165 item = r_meta_get_at (anal, 0x101, R_META_TYPE_ANY, NULL);
166 mu_assert_null (item, "get item");
167
168 r_anal_free (anal);
169 mu_end;
170 }
171
test_meta_get_in()172 bool test_meta_get_in() {
173 RAnal *anal = r_anal_new ();
174
175 r_meta_set (anal, R_META_TYPE_DATA, 0x100, 4, NULL);
176 r_meta_set_string (anal, R_META_TYPE_COMMENT, 0x100, "vera gemini");
177
178 RIntervalNode *node = r_meta_get_in (anal, 0x100, R_META_TYPE_COMMENT);
179 mu_assert_notnull (node, "get item");
180 RAnalMetaItem *item = node->data;
181 mu_assert_streq (item->str, "vera gemini", "get contents");
182 node = r_meta_get_in (anal, 0xff, R_META_TYPE_COMMENT);
183 mu_assert_null (node, "get item");
184 node = r_meta_get_in (anal, 0x101, R_META_TYPE_COMMENT);
185 mu_assert_null (node, "get item");
186
187 node = r_meta_get_in (anal, 0x100, R_META_TYPE_DATA);
188 mu_assert_notnull (node, "get item");
189 item = node->data;
190 mu_assert_eq (item->type, R_META_TYPE_DATA, "get contents");
191 node = r_meta_get_in (anal, 0xff, R_META_TYPE_DATA);
192 mu_assert_null (node, "get item");
193 node = r_meta_get_in (anal, 0x103, R_META_TYPE_DATA);
194 mu_assert_notnull (node, "get item");
195 item = node->data;
196 mu_assert_eq (item->type, R_META_TYPE_DATA, "get contents");
197 node = r_meta_get_in (anal, 0x104, R_META_TYPE_DATA);
198 mu_assert_null (node, "get item");
199
200 node = r_meta_get_in (anal, 0x103, R_META_TYPE_ANY);
201 mu_assert_notnull (node, "get item");
202 item = node->data;
203 mu_assert_eq (item->type, R_META_TYPE_DATA, "get contents");
204
205 node = r_meta_get_in (anal, 0x100, R_META_TYPE_ANY);
206 mu_assert_notnull (node, "get item");
207 // which one we get is undefined here (intended)
208
209 r_anal_free (anal);
210 mu_end;
211 }
212
test_meta_get_all_at()213 bool test_meta_get_all_at() {
214 RAnal *anal = r_anal_new ();
215
216 r_meta_set (anal, R_META_TYPE_DATA, 0x100, 4, NULL);
217 r_meta_set_string (anal, R_META_TYPE_COMMENT, 0x100, "vera gemini");
218 r_meta_set_with_subtype (anal, R_META_TYPE_STRING, R_STRING_ENC_UTF8, 0x200, 0x30, "true confessions");
219
220 RPVector *items = r_meta_get_all_at (anal, 0x100);
221 mu_assert_eq (r_pvector_len (items), 2, "all count");
222 void **it;
223 bool found[2] = { 0 };
224 r_pvector_foreach (items, it) {
225 RAnalMetaItem *item = ((RIntervalNode *)*it)->data;
226 switch (item->type) {
227 case R_META_TYPE_DATA:
228 found[0] = true;
229 break;
230 case R_META_TYPE_COMMENT:
231 found[1] = true;
232 break;
233 default:
234 break;
235 }
236 }
237 mu_assert ("meta 0", found[0]);
238 mu_assert ("meta 1", found[1]);
239 r_pvector_free (items);
240
241 items = r_meta_get_all_at (anal, 0xff);
242 mu_assert_eq (r_pvector_len (items), 0, "all count");
243 r_pvector_free (items);
244
245 items = r_meta_get_all_at (anal, 0x101);
246 mu_assert_eq (r_pvector_len (items), 0, "all count");
247 r_pvector_free (items);
248
249 r_anal_free (anal);
250 mu_end;
251 }
252
test_meta_get_all_in()253 bool test_meta_get_all_in() {
254 RAnal *anal = r_anal_new ();
255
256 r_meta_set (anal, R_META_TYPE_DATA, 0x100, 4, NULL);
257 r_meta_set_string (anal, R_META_TYPE_COMMENT, 0x100, "vera gemini");
258 r_meta_set_with_subtype (anal, R_META_TYPE_STRING, R_STRING_ENC_UTF8, 0x200, 0x30, "true confessions");
259
260 RPVector *items = r_meta_get_all_in (anal, 0x100, R_META_TYPE_ANY);
261 mu_assert_eq (r_pvector_len (items), 2, "all count");
262 void **it;
263 bool found[2] = { 0 };
264 r_pvector_foreach (items, it) {
265 RAnalMetaItem *item = ((RIntervalNode *)*it)->data;
266 switch (item->type) {
267 case R_META_TYPE_DATA:
268 found[0] = true;
269 break;
270 case R_META_TYPE_COMMENT:
271 found[1] = true;
272 break;
273 default:
274 break;
275 }
276 }
277 mu_assert ("meta 0", found[0]);
278 mu_assert ("meta 1", found[1]);
279 r_pvector_free (items);
280
281 items = r_meta_get_all_in (anal, 0x100, R_META_TYPE_COMMENT);
282 mu_assert_eq (r_pvector_len (items), 1, "all count");
283 RAnalMetaItem *item = ((RIntervalNode *)r_pvector_at (items, 0))->data;
284 mu_assert_streq (item->str, "vera gemini", "contents");
285 r_pvector_free (items);
286
287 items = r_meta_get_all_in (anal, 0x100, R_META_TYPE_DATA);
288 mu_assert_eq (r_pvector_len (items), 1, "all count");
289 item = ((RIntervalNode *)r_pvector_at (items, 0))->data;
290 mu_assert_eq (item->type, R_META_TYPE_DATA, "contents");
291 r_pvector_free (items);
292
293 items = r_meta_get_all_in (anal, 0xff, R_META_TYPE_ANY);
294 mu_assert_eq (r_pvector_len (items), 0, "all count");
295 r_pvector_free (items);
296
297 items = r_meta_get_all_in (anal, 0x101, R_META_TYPE_COMMENT);
298 mu_assert_eq (r_pvector_len (items), 0, "all count");
299 r_pvector_free (items);
300
301 items = r_meta_get_all_in (anal, 0x103, R_META_TYPE_DATA);
302 mu_assert_eq (r_pvector_len (items), 1, "all count");
303 item = ((RIntervalNode *)r_pvector_at (items, 0))->data;
304 mu_assert_eq (item->type, R_META_TYPE_DATA, "contents");
305 r_pvector_free (items);
306
307 items = r_meta_get_all_in (anal, 0x104, R_META_TYPE_DATA);
308 mu_assert_eq (r_pvector_len (items), 0, "all count");
309 r_pvector_free (items);
310
311 r_anal_free (anal);
312 mu_end;
313 }
314
test_meta_get_all_intersect()315 bool test_meta_get_all_intersect() {
316 RAnal *anal = r_anal_new ();
317
318 r_meta_set (anal, R_META_TYPE_DATA, 0x100, 4, NULL);
319 r_meta_set_string (anal, R_META_TYPE_COMMENT, 0x100, "vera gemini");
320 r_meta_set_with_subtype (anal, R_META_TYPE_STRING, R_STRING_ENC_UTF8, 0x200, 0x30, "true confessions");
321
322 RPVector *items = r_meta_get_all_intersect (anal, 0x100, 1, R_META_TYPE_ANY);
323 mu_assert_eq (r_pvector_len (items), 2, "all count");
324 void **it;
325 bool found[2] = { 0 };
326 r_pvector_foreach (items, it) {
327 RAnalMetaItem *item = ((RIntervalNode *)*it)->data;
328 switch (item->type) {
329 case R_META_TYPE_DATA:
330 found[0] = true;
331 break;
332 case R_META_TYPE_COMMENT:
333 found[1] = true;
334 break;
335 default:
336 break;
337 }
338 }
339 mu_assert ("meta 0", found[0]);
340 mu_assert ("meta 1", found[1]);
341 r_pvector_free (items);
342
343 items = r_meta_get_all_intersect (anal, 0x100, 1, R_META_TYPE_DATA);
344 mu_assert_eq (r_pvector_len (items), 1, "all count");
345 RAnalMetaItem *item = ((RIntervalNode *)r_pvector_at (items, 0))->data;
346 mu_assert_eq (item->type, R_META_TYPE_DATA, "contents");
347 r_pvector_free (items);
348
349 items = r_meta_get_all_intersect (anal, 0x100, 0x300, R_META_TYPE_DATA);
350 mu_assert_eq (r_pvector_len (items), 1, "all count");
351 item = ((RIntervalNode *)r_pvector_at (items, 0))->data;
352 mu_assert_eq (item->type, R_META_TYPE_DATA, "contents");
353 r_pvector_free (items);
354
355 items = r_meta_get_all_intersect (anal, 0x0, 0x300, R_META_TYPE_DATA);
356 mu_assert_eq (r_pvector_len (items), 1, "all count");
357 item = ((RIntervalNode *)r_pvector_at (items, 0))->data;
358 mu_assert_eq (item->type, R_META_TYPE_DATA, "contents");
359 r_pvector_free (items);
360
361 items = r_meta_get_all_intersect (anal, 0x0, 0x100, R_META_TYPE_DATA);
362 mu_assert_eq (r_pvector_len (items), 0, "all count");
363 r_pvector_free (items);
364
365 items = r_meta_get_all_intersect (anal, 0x103, 0x300, R_META_TYPE_DATA);
366 mu_assert_eq (r_pvector_len (items), 1, "all count");
367 item = ((RIntervalNode *)r_pvector_at (items, 0))->data;
368 mu_assert_eq (item->type, R_META_TYPE_DATA, "contents");
369 r_pvector_free (items);
370
371 items = r_meta_get_all_intersect (anal, 0x104, 0x300, R_META_TYPE_DATA);
372 mu_assert_eq (r_pvector_len (items), 0, "all count");
373 r_pvector_free (items);
374
375 r_anal_free (anal);
376 mu_end;
377 }
378
test_meta_del()379 bool test_meta_del() {
380 RAnal *anal = r_anal_new ();
381
382 r_meta_set (anal, R_META_TYPE_DATA, 0x100, 4, NULL);
383 r_meta_set_string (anal, R_META_TYPE_COMMENT, 0x100, "vera gemini");
384 r_meta_set_with_subtype (anal, R_META_TYPE_STRING, R_STRING_ENC_UTF8, 0x200, 0x30, "true confessions");
385
386 r_meta_del (anal, R_META_TYPE_COMMENT, 0x100, 1);
387 RAnalMetaItem *item = r_meta_get_at (anal, 0x100, R_META_TYPE_COMMENT, NULL);
388 mu_assert_null (item, "item deleted");
389 item = r_meta_get_at (anal, 0x100, R_META_TYPE_DATA, NULL);
390 mu_assert_notnull (item, "item not deleted");
391 item = r_meta_get_at (anal, 0x200, R_META_TYPE_STRING, NULL);
392 mu_assert_notnull (item, "item not deleted");
393
394 // reset
395 r_meta_set_string (anal, R_META_TYPE_COMMENT, 0x100, "vera gemini");
396
397 r_meta_del (anal, R_META_TYPE_COMMENT, 0x0, 0x500);
398 item = r_meta_get_at (anal, 0x100, R_META_TYPE_COMMENT, NULL);
399 mu_assert_null (item, "item deleted");
400 item = r_meta_get_at (anal, 0x100, R_META_TYPE_DATA, NULL);
401 mu_assert_notnull (item, "item not deleted");
402 item = r_meta_get_at (anal, 0x200, R_META_TYPE_STRING, NULL);
403 mu_assert_notnull (item, "item not deleted");
404
405 // reset
406 r_meta_set_string (anal, R_META_TYPE_COMMENT, 0x100, "vera gemini");
407
408 r_meta_del (anal, R_META_TYPE_COMMENT, 0, UT64_MAX);
409 item = r_meta_get_at (anal, 0x100, R_META_TYPE_COMMENT, NULL);
410 mu_assert_null (item, "item deleted");
411 item = r_meta_get_at (anal, 0x100, R_META_TYPE_DATA, NULL);
412 mu_assert_notnull (item, "item not deleted");
413 item = r_meta_get_at (anal, 0x200, R_META_TYPE_STRING, NULL);
414 mu_assert_notnull (item, "item not deleted");
415
416 // reset
417 r_meta_set_string (anal, R_META_TYPE_COMMENT, 0x100, "vera gemini");
418
419 r_meta_del (anal, R_META_TYPE_ANY, 0, 0x500);
420 item = r_meta_get_at (anal, 0x100, R_META_TYPE_COMMENT, NULL);
421 mu_assert_null (item, "item deleted");
422 item = r_meta_get_at (anal, 0x100, R_META_TYPE_DATA, NULL);
423 mu_assert_null (item, "item deleted");
424 item = r_meta_get_at (anal, 0x200, R_META_TYPE_STRING, NULL);
425 mu_assert_null (item, "item deleted");
426
427 // reset
428 r_meta_set (anal, R_META_TYPE_DATA, 0x100, 4, NULL);
429 r_meta_set_string (anal, R_META_TYPE_COMMENT, 0x100, "vera gemini");
430 r_meta_set_with_subtype (anal, R_META_TYPE_STRING, R_STRING_ENC_UTF8, 0x200, 0x30, "true confessions");
431
432 r_meta_del (anal, R_META_TYPE_ANY, 0, UT64_MAX);
433 item = r_meta_get_at (anal, 0x100, R_META_TYPE_COMMENT, NULL);
434 mu_assert_null (item, "item deleted");
435 item = r_meta_get_at (anal, 0x100, R_META_TYPE_DATA, NULL);
436 mu_assert_null (item, "item deleted");
437 item = r_meta_get_at (anal, 0x200, R_META_TYPE_STRING, NULL);
438 mu_assert_null (item, "item deleted");
439
440 r_anal_free (anal);
441 mu_end;
442 }
443
test_meta_rebase()444 bool test_meta_rebase() {
445 RAnal *anal = r_anal_new ();
446
447 r_meta_set (anal, R_META_TYPE_DATA, 0x200, 4, NULL);
448 r_meta_set_string (anal, R_META_TYPE_COMMENT, 0x200, "summer of love");
449 r_meta_set_with_subtype (anal, R_META_TYPE_STRING, R_STRING_ENC_UTF8, 0x300, 0x30, "true confessions");
450 r_meta_rebase (anal, -0x100);
451
452 bool found[3] = { 0 };
453 size_t count = 0;
454 RIntervalTreeIter it;
455 RAnalMetaItem *item;
456 r_interval_tree_foreach (&anal->meta, it, item) {
457 count++;
458 RIntervalNode *node = r_interval_tree_iter_get (&it);
459 switch (item->type) {
460 case R_META_TYPE_DATA:
461 mu_assert_eq (node->start, 0x100, "node start");
462 mu_assert_eq (node->end, 0x103, "node end (inclusive)");
463 mu_assert_null (item->str, "no string");
464 mu_assert_eq (item->subtype, 0, "no subtype");
465 found[0] = true;
466 break;
467 case R_META_TYPE_COMMENT:
468 mu_assert_eq (node->start, 0x100, "node start");
469 mu_assert_eq (node->end, 0x100, "node end (inclusive)");
470 mu_assert_streq (item->str, "summer of love", "comment string");
471 mu_assert_eq (item->subtype, 0, "no subtype");
472 found[1] = true;
473 break;
474 case R_META_TYPE_STRING:
475 mu_assert_eq (node->start, 0x200, "node start");
476 mu_assert_eq (node->end, 0x22f, "node end (inclusive)");
477 mu_assert_streq (item->str, "true confessions", "string string");
478 mu_assert_eq (item->subtype, R_STRING_ENC_UTF8, "subtype");
479 found[2] = true;
480 break;
481 default:
482 break;
483 }
484 }
485 mu_assert_eq (count, 3, "set count");
486 mu_assert ("meta 0", found[0]);
487 mu_assert ("meta 1", found[1]);
488 mu_assert ("meta 2", found[2]);
489
490 r_anal_free (anal);
491 mu_end;
492 }
493
test_meta_spaces()494 bool test_meta_spaces() {
495 RAnal *anal = r_anal_new ();
496
497 r_meta_set (anal, R_META_TYPE_DATA, 0x100, 4, NULL);
498 r_meta_set_string (anal, R_META_TYPE_COMMENT, 0x100, "summer of love");
499 r_meta_set_with_subtype (anal, R_META_TYPE_STRING, R_STRING_ENC_UTF8, 0x200, 0x30, "true confessions");
500
501 r_spaces_set (&anal->meta_spaces, "fear");
502
503 r_meta_set_string (anal, R_META_TYPE_COMMENT, 0x100, "reaper");
504
505 bool found[4] = { 0 };
506 size_t count = 0;
507 RIntervalTreeIter it;
508 RAnalMetaItem *item;
509 r_interval_tree_foreach (&anal->meta, it, item) {
510 count++;
511 switch (item->type) {
512 case R_META_TYPE_DATA:
513 mu_assert_null (item->space, "space");
514 found[0] = true;
515 break;
516 case R_META_TYPE_COMMENT:
517 if (item->space) {
518 mu_assert_streq (item->str, "reaper", "comment string");
519 mu_assert_ptreq (item->space, r_spaces_get (&anal->meta_spaces, "fear"), "space");
520 found[3] = true;
521 } else {
522 mu_assert_streq (item->str, "summer of love", "comment string");
523 found[1] = true;
524 }
525 break;
526 case R_META_TYPE_STRING:
527 mu_assert_null (item->space, "space");
528 found[2] = true;
529 break;
530 default:
531 break;
532 }
533 }
534 mu_assert_eq (count, 4, "set count");
535 mu_assert ("meta 0", found[0]);
536 mu_assert ("meta 1", found[1]);
537 mu_assert ("meta 2", found[2]);
538 mu_assert ("meta 3", found[3]);
539
540 RAnalMetaItem *reaper_item = r_meta_get_at (anal, 0x100, R_META_TYPE_ANY, NULL);
541 mu_assert_notnull (reaper_item, "get item");
542 mu_assert_streq (reaper_item->str, "reaper", "comment string");
543
544 item = r_meta_get_at (anal, 0x100, R_META_TYPE_DATA, NULL);
545 mu_assert_null (item, "masked by space");
546
547 RIntervalNode *node = r_meta_get_in (anal, 0x100, R_META_TYPE_COMMENT);
548 mu_assert_notnull (node, "get item");
549 mu_assert_ptreq (node->data, reaper_item, "masked by space");
550 node = r_meta_get_in (anal, 0x100, R_META_TYPE_DATA);
551 mu_assert_null (node, "masked by space");
552
553 RPVector *nodes = r_meta_get_all_at (anal, 0x100);
554 mu_assert_eq (r_pvector_len (nodes), 1, "all count");
555 mu_assert_ptreq (((RIntervalNode *)r_pvector_at (nodes, 0))->data, reaper_item, "all masked");
556 r_pvector_free (nodes);
557
558 nodes = r_meta_get_all_in (anal, 0x100, R_META_TYPE_ANY);
559 mu_assert_eq (r_pvector_len (nodes), 1, "all count");
560 mu_assert_ptreq (((RIntervalNode *)r_pvector_at (nodes, 0))->data, reaper_item, "all masked");
561 r_pvector_free (nodes);
562
563 nodes = r_meta_get_all_intersect (anal, 0x0, 0x500, R_META_TYPE_ANY);
564 mu_assert_eq (r_pvector_len (nodes), 1, "all count");
565 mu_assert_ptreq (((RIntervalNode *)r_pvector_at (nodes, 0))->data, reaper_item, "all masked");
566 r_pvector_free (nodes);
567
568 // delete
569 r_meta_del (anal, R_META_TYPE_ANY, 0, 0x500);
570 item = r_meta_get_at (anal, 0x100, R_META_TYPE_ANY, NULL);
571 mu_assert_null (item, "reaper deleted");
572 count = 0;
573 r_interval_tree_foreach (&anal->meta, it, item) {
574 count++;
575 }
576 mu_assert_eq (count, 3, "masked untouched");
577
578 // reset
579 r_meta_set_string (anal, R_META_TYPE_COMMENT, 0x100, "reaper");
580
581 r_meta_del (anal, R_META_TYPE_ANY, 0, UT64_MAX);
582 item = r_meta_get_at (anal, 0x100, R_META_TYPE_ANY, NULL);
583 mu_assert_null (item, "reaper deleted");
584 count = 0;
585 r_interval_tree_foreach (&anal->meta, it, item) {
586 count++;
587 }
588 mu_assert_eq (count, 3, "masked untouched");
589
590 r_anal_free (anal);
591 mu_end;
592 }
593
all_tests()594 bool all_tests() {
595 mu_run_test(test_meta_set);
596 mu_run_test(test_meta_get_at);
597 mu_run_test(test_meta_get_in);
598 mu_run_test(test_meta_get_all_at);
599 mu_run_test(test_meta_get_all_in);
600 mu_run_test(test_meta_get_all_intersect);
601 mu_run_test(test_meta_del);
602 mu_run_test(test_meta_rebase);
603 mu_run_test(test_meta_spaces);
604 return tests_passed != tests_run;
605 }
606
main(int argc,char ** argv)607 int main(int argc, char **argv) {
608 return all_tests();
609 }
610