1 #include "xmpp/resource.h"
2 #include "common.h"
3 #include <stdarg.h>
4 #include <stddef.h>
5 #include <setjmp.h>
6 #include <cmocka.h>
7 #include <stdlib.h>
8
9 void
replace_one_substr(void ** state)10 replace_one_substr(void** state)
11 {
12 char* string = "it is a string";
13 char* sub = "is";
14 char* new = "was";
15
16 char* result = str_replace(string, sub, new);
17
18 assert_string_equal("it was a string", result);
19
20 free(result);
21 }
22
23 void
replace_one_substr_beginning(void ** state)24 replace_one_substr_beginning(void** state)
25 {
26 char* string = "it is a string";
27 char* sub = "it";
28 char* new = "that";
29
30 char* result = str_replace(string, sub, new);
31
32 assert_string_equal("that is a string", result);
33
34 free(result);
35 }
36
37 void
replace_one_substr_end(void ** state)38 replace_one_substr_end(void** state)
39 {
40 char* string = "it is a string";
41 char* sub = "string";
42 char* new = "thing";
43
44 char* result = str_replace(string, sub, new);
45
46 assert_string_equal("it is a thing", result);
47
48 free(result);
49 }
50
51 void
replace_two_substr(void ** state)52 replace_two_substr(void** state)
53 {
54 char* string = "it is a is string";
55 char* sub = "is";
56 char* new = "was";
57
58 char* result = str_replace(string, sub, new);
59
60 assert_string_equal("it was a was string", result);
61
62 free(result);
63 }
64
65 void
replace_char(void ** state)66 replace_char(void** state)
67 {
68 char* string = "some & a thing & something else";
69 char* sub = "&";
70 char* new = "&";
71
72 char* result = str_replace(string, sub, new);
73
74 assert_string_equal("some & a thing & something else", result);
75
76 free(result);
77 }
78
79 void
replace_when_none(void ** state)80 replace_when_none(void** state)
81 {
82 char* string = "its another string";
83 char* sub = "haha";
84 char* new = "replaced";
85
86 char* result = str_replace(string, sub, new);
87
88 assert_string_equal("its another string", result);
89
90 free(result);
91 }
92
93 void
replace_when_match(void ** state)94 replace_when_match(void** state)
95 {
96 char* string = "hello";
97 char* sub = "hello";
98 char* new = "goodbye";
99
100 char* result = str_replace(string, sub, new);
101
102 assert_string_equal("goodbye", result);
103
104 free(result);
105 }
106
107 void
replace_when_string_empty(void ** state)108 replace_when_string_empty(void** state)
109 {
110 char* string = "";
111 char* sub = "hello";
112 char* new = "goodbye";
113
114 char* result = str_replace(string, sub, new);
115
116 assert_string_equal("", result);
117
118 free(result);
119 }
120
121 void
replace_when_string_null(void ** state)122 replace_when_string_null(void** state)
123 {
124 char* string = NULL;
125 char* sub = "hello";
126 char* new = "goodbye";
127
128 char* result = str_replace(string, sub, new);
129
130 assert_null(result);
131 }
132
133 void
replace_when_sub_empty(void ** state)134 replace_when_sub_empty(void** state)
135 {
136 char* string = "hello";
137 char* sub = "";
138 char* new = "goodbye";
139
140 char* result = str_replace(string, sub, new);
141
142 assert_string_equal("hello", result);
143
144 free(result);
145 }
146
147 void
replace_when_sub_null(void ** state)148 replace_when_sub_null(void** state)
149 {
150 char* string = "hello";
151 char* sub = NULL;
152 char* new = "goodbye";
153
154 char* result = str_replace(string, sub, new);
155
156 assert_string_equal("hello", result);
157
158 free(result);
159 }
160
161 void
replace_when_new_empty(void ** state)162 replace_when_new_empty(void** state)
163 {
164 char* string = "hello";
165 char* sub = "hello";
166 char* new = "";
167
168 char* result = str_replace(string, sub, new);
169
170 assert_string_equal("", result);
171
172 free(result);
173 }
174
175 void
replace_when_new_null(void ** state)176 replace_when_new_null(void** state)
177 {
178 char* string = "hello";
179 char* sub = "hello";
180 char* new = NULL;
181
182 char* result = str_replace(string, sub, new);
183
184 assert_string_equal("hello", result);
185
186 free(result);
187 }
188
189 void
test_online_is_valid_resource_presence_string(void ** state)190 test_online_is_valid_resource_presence_string(void** state)
191 {
192 assert_true(valid_resource_presence_string("online"));
193 }
194
195 void
test_chat_is_valid_resource_presence_string(void ** state)196 test_chat_is_valid_resource_presence_string(void** state)
197 {
198 assert_true(valid_resource_presence_string("chat"));
199 }
200
201 void
test_away_is_valid_resource_presence_string(void ** state)202 test_away_is_valid_resource_presence_string(void** state)
203 {
204 assert_true(valid_resource_presence_string("away"));
205 }
206
207 void
test_xa_is_valid_resource_presence_string(void ** state)208 test_xa_is_valid_resource_presence_string(void** state)
209 {
210 assert_true(valid_resource_presence_string("xa"));
211 }
212
213 void
test_dnd_is_valid_resource_presence_string(void ** state)214 test_dnd_is_valid_resource_presence_string(void** state)
215 {
216 assert_true(valid_resource_presence_string("dnd"));
217 }
218
219 void
test_available_is_not_valid_resource_presence_string(void ** state)220 test_available_is_not_valid_resource_presence_string(void** state)
221 {
222 assert_false(valid_resource_presence_string("available"));
223 }
224
225 void
test_unavailable_is_not_valid_resource_presence_string(void ** state)226 test_unavailable_is_not_valid_resource_presence_string(void** state)
227 {
228 assert_false(valid_resource_presence_string("unavailable"));
229 }
230
231 void
test_blah_is_not_valid_resource_presence_string(void ** state)232 test_blah_is_not_valid_resource_presence_string(void** state)
233 {
234 assert_false(valid_resource_presence_string("blah"));
235 }
236
237 void
utf8_display_len_null_str(void ** state)238 utf8_display_len_null_str(void** state)
239 {
240 int result = utf8_display_len(NULL);
241
242 assert_int_equal(0, result);
243 }
244
245 void
utf8_display_len_1_non_wide(void ** state)246 utf8_display_len_1_non_wide(void** state)
247 {
248 int result = utf8_display_len("1");
249
250 assert_int_equal(1, result);
251 }
252
253 void
utf8_display_len_1_wide(void ** state)254 utf8_display_len_1_wide(void** state)
255 {
256 int result = utf8_display_len("四");
257
258 assert_int_equal(2, result);
259 }
260
261 void
utf8_display_len_non_wide(void ** state)262 utf8_display_len_non_wide(void** state)
263 {
264 int result = utf8_display_len("123456789abcdef");
265
266 assert_int_equal(15, result);
267 }
268
269 void
utf8_display_len_wide(void ** state)270 utf8_display_len_wide(void** state)
271 {
272 int result = utf8_display_len("12三四56");
273
274 assert_int_equal(8, result);
275 }
276
277 void
utf8_display_len_all_wide(void ** state)278 utf8_display_len_all_wide(void** state)
279 {
280 int result = utf8_display_len("ひらがな");
281
282 assert_int_equal(8, result);
283 }
284
285 void
strip_quotes_does_nothing_when_no_quoted(void ** state)286 strip_quotes_does_nothing_when_no_quoted(void** state)
287 {
288 char* input = "/cmd test string";
289
290 char* result = strip_arg_quotes(input);
291
292 assert_string_equal("/cmd test string", result);
293
294 free(result);
295 }
296
297 void
strip_quotes_strips_first(void ** state)298 strip_quotes_strips_first(void** state)
299 {
300 char* input = "/cmd \"test string";
301
302 char* result = strip_arg_quotes(input);
303
304 assert_string_equal("/cmd test string", result);
305
306 free(result);
307 }
308
309 void
strip_quotes_strips_last(void ** state)310 strip_quotes_strips_last(void** state)
311 {
312 char* input = "/cmd test string\"";
313
314 char* result = strip_arg_quotes(input);
315
316 assert_string_equal("/cmd test string", result);
317
318 free(result);
319 }
320
321 void
strip_quotes_strips_both(void ** state)322 strip_quotes_strips_both(void** state)
323 {
324 char* input = "/cmd \"test string\"";
325
326 char* result = strip_arg_quotes(input);
327
328 assert_string_equal("/cmd test string", result);
329
330 free(result);
331 }
332
333 typedef struct
334 {
335 char* template;
336 char* url;
337 char* filename;
338 char* argv;
339 } format_call_external_argv_t;
340
341 void
format_call_external_argv_td(void ** state)342 format_call_external_argv_td(void** state)
343 {
344
345 enum table { num_tests = 4 };
346
347 format_call_external_argv_t tests[num_tests] = {
348 (format_call_external_argv_t){
349 .template = "/bin/echo %u %p",
350 .url = "https://example.org",
351 .filename = "image.jpeg",
352 .argv = "/bin/echo https://example.org image.jpeg",
353 },
354 (format_call_external_argv_t){
355 .template = "/bin/echo %p %u",
356 .url = "https://example.org",
357 .filename = "image.jpeg",
358 .argv = "/bin/echo image.jpeg https://example.org",
359 },
360 (format_call_external_argv_t){
361 .template = "/bin/echo %p",
362 .url = "https://example.org",
363 .filename = "image.jpeg",
364 .argv = "/bin/echo image.jpeg",
365 },
366 (format_call_external_argv_t){
367 .template = "/bin/echo %u",
368 .url = "https://example.org",
369 .filename = "image.jpeg",
370 .argv = "/bin/echo https://example.org",
371 },
372 };
373
374 gchar** got_argv = NULL;
375 gchar* got_argv_str = NULL;
376 for (int i = 0; i < num_tests; i++) {
377 got_argv = format_call_external_argv(
378 tests[i].template,
379 tests[i].url,
380 tests[i].filename);
381 got_argv_str = g_strjoinv(" ", got_argv);
382
383 assert_string_equal(got_argv_str, tests[i].argv);
384
385 g_strfreev(got_argv);
386 g_free(got_argv_str);
387 }
388 }
389
390 typedef struct
391 {
392 char* url;
393 char* path;
394 char* target;
395 char* basename;
396 } unique_filename_from_url_t;
397
398 void
unique_filename_from_url_td(void ** state)399 unique_filename_from_url_td(void** state)
400 {
401
402 enum table { num_tests = 15 };
403 char* pwd = g_get_current_dir();
404
405 unique_filename_from_url_t tests[num_tests] = {
406 (unique_filename_from_url_t){
407 .url = "https://host.test/image.jpeg",
408 .path = "./.",
409 .target = pwd,
410 .basename = "image.jpeg",
411 },
412 (unique_filename_from_url_t){
413 .url = "https://host.test/image.jpeg",
414 .path = NULL,
415 .target = pwd,
416 .basename = "image.jpeg",
417 },
418 (unique_filename_from_url_t){
419 .url = "https://host.test/image.jpeg#somefragment",
420 .path = "./",
421 .target = pwd,
422 .basename = "image.jpeg",
423 },
424 (unique_filename_from_url_t){
425 .url = "https://host.test/image.jpeg?query=param",
426 .path = "./",
427 .target = pwd,
428 .basename = "image.jpeg",
429 },
430 (unique_filename_from_url_t){
431 .url = "https://host.test/image.jpeg?query=param&another=one",
432 .path = "./",
433 .target = pwd,
434 .basename = "image.jpeg",
435 },
436 (unique_filename_from_url_t){
437 .url = "https://host.test/image.jpeg?query=param&another=one",
438 .path = "/tmp/",
439 .target = "/tmp/",
440 .basename = "image.jpeg",
441 },
442 (unique_filename_from_url_t){
443 .url = "https://host.test/image.jpeg?query=param&another=one",
444 .path = "/tmp/hopefully/this/file/does/not/exist",
445 .target = "/tmp/hopefully/this/file/does/not/",
446 .basename = "exist",
447 },
448 (unique_filename_from_url_t){
449 .url = "https://host.test/image.jpeg?query=param&another=one",
450 .path = "/tmp/hopefully/this/file/does/not/exist/",
451 .target = "/tmp/hopefully/this/file/does/not/exist/",
452 .basename = "image.jpeg",
453 },
454 (unique_filename_from_url_t){
455 .url = "https://host.test/images/",
456 .path = "./",
457 .target = pwd,
458 .basename = "images",
459 },
460 (unique_filename_from_url_t){
461 .url = "https://host.test/images/../../file",
462 .path = "./",
463 .target = pwd,
464 .basename = "file",
465 },
466 (unique_filename_from_url_t){
467 .url = "https://host.test/images/../../file/..",
468 .path = "./",
469 .target = pwd,
470 .basename = "index",
471 },
472 (unique_filename_from_url_t){
473 .url = "https://host.test/images/..//",
474 .path = "./",
475 .target = pwd,
476 .basename = "index",
477 },
478 (unique_filename_from_url_t){
479 .url = "https://host.test/",
480 .path = "./",
481 .target = pwd,
482 .basename = "index",
483 },
484 (unique_filename_from_url_t){
485 .url = "https://host.test",
486 .path = "./",
487 .target = pwd,
488 .basename = "index",
489 },
490 (unique_filename_from_url_t){
491 .url = "aesgcm://host.test",
492 .path = "./",
493 .target = pwd,
494 .basename = "index",
495 },
496 };
497
498 char* got_filename = NULL;
499 char* exp_filename = NULL;
500 for (int i = 0; i < num_tests; i++) {
501 got_filename = unique_filename_from_url(tests[i].url, tests[i].path);
502 exp_filename = g_build_filename(tests[i].target, tests[i].basename, NULL);
503
504 assert_string_equal(got_filename, exp_filename);
505
506 free(got_filename);
507 free(exp_filename);
508 }
509
510 g_free(pwd);
511 }
512
513 gboolean
_lists_equal(GSList * a,GSList * b)514 _lists_equal(GSList* a, GSList* b)
515 {
516 if (g_slist_length(a) != g_slist_length(b)) {
517 return FALSE;
518 }
519
520 GSList* curra = a;
521 GSList* currb = b;
522
523 while (curra) {
524 int aval = GPOINTER_TO_INT(curra->data);
525 int bval = GPOINTER_TO_INT(currb->data);
526
527 if (aval != bval) {
528 return FALSE;
529 }
530
531 curra = g_slist_next(curra);
532 currb = g_slist_next(currb);
533 }
534
535 return TRUE;
536 }
537
538 void
prof_partial_occurrences_tests(void ** state)539 prof_partial_occurrences_tests(void** state)
540 {
541 GSList* actual = NULL;
542 GSList* expected = NULL;
543 assert_true(_lists_equal(prof_occurrences(NULL, NULL, 0, FALSE, &actual), expected));
544 g_slist_free(actual);
545 actual = NULL;
546
547 assert_true(_lists_equal(prof_occurrences(NULL, "some string", 0, FALSE, &actual), expected));
548 g_slist_free(actual);
549 actual = NULL;
550 assert_true(_lists_equal(prof_occurrences("boothj5", NULL, 0, FALSE, &actual), expected));
551 g_slist_free(actual);
552 actual = NULL;
553 assert_true(_lists_equal(prof_occurrences(NULL, NULL, 0, FALSE, &actual), expected));
554 g_slist_free(actual);
555 actual = NULL;
556 assert_true(_lists_equal(prof_occurrences("boothj5", "Boothj5", 0, FALSE, &actual), expected));
557 g_slist_free(actual);
558 actual = NULL;
559 assert_true(_lists_equal(prof_occurrences("Boothj5", "boothj5", 0, FALSE, &actual), expected));
560 g_slist_free(actual);
561 actual = NULL;
562
563 expected = g_slist_append(expected, GINT_TO_POINTER(0));
564 assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5", 0, FALSE, &actual), expected));
565 g_slist_free(actual);
566 actual = NULL;
567 assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5hello", 0, FALSE, &actual), expected));
568 g_slist_free(actual);
569 actual = NULL;
570 assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5 hello", 0, FALSE, &actual), expected));
571 g_slist_free(actual);
572 actual = NULL;
573 g_slist_free(expected);
574 expected = NULL;
575
576 expected = g_slist_append(expected, GINT_TO_POINTER(5));
577 assert_true(_lists_equal(prof_occurrences("boothj5", "helloboothj5", 0, FALSE, &actual), expected));
578 g_slist_free(actual);
579 actual = NULL;
580 assert_true(_lists_equal(prof_occurrences("boothj5", "helloboothj5hello", 0, FALSE, &actual), expected));
581 g_slist_free(actual);
582 actual = NULL;
583 g_slist_free(expected);
584 expected = NULL;
585
586 expected = g_slist_append(expected, GINT_TO_POINTER(6));
587 assert_true(_lists_equal(prof_occurrences("boothj5", "hello boothj5", 0, FALSE, &actual), expected));
588 g_slist_free(actual);
589 actual = NULL;
590 assert_true(_lists_equal(prof_occurrences("boothj5", "hello boothj5 hello", 0, FALSE, &actual), expected));
591 g_slist_free(actual);
592 actual = NULL;
593 g_slist_free(expected);
594 expected = NULL;
595
596 expected = g_slist_append(expected, GINT_TO_POINTER(0));
597 expected = g_slist_append(expected, GINT_TO_POINTER(7));
598 assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5boothj5", 0, FALSE, &actual), expected));
599 g_slist_free(actual);
600 actual = NULL;
601 g_slist_free(expected);
602 expected = NULL;
603
604 expected = g_slist_append(expected, GINT_TO_POINTER(0));
605 expected = g_slist_append(expected, GINT_TO_POINTER(12));
606 assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5helloboothj5", 0, FALSE, &actual), expected));
607 g_slist_free(actual);
608 actual = NULL;
609 g_slist_free(expected);
610 expected = NULL;
611
612 expected = g_slist_append(expected, GINT_TO_POINTER(0));
613 expected = g_slist_append(expected, GINT_TO_POINTER(14));
614 assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5 hello boothj5", 0, FALSE, &actual), expected));
615 g_slist_free(actual);
616 actual = NULL;
617 g_slist_free(expected);
618 expected = NULL;
619
620 expected = g_slist_append(expected, GINT_TO_POINTER(2));
621 expected = g_slist_append(expected, GINT_TO_POINTER(16));
622 expected = g_slist_append(expected, GINT_TO_POINTER(29));
623 assert_true(_lists_equal(prof_occurrences("boothj5", "hiboothj5 hello boothj5there boothj5s", 0, FALSE, &actual), expected));
624 g_slist_free(actual);
625 actual = NULL;
626 g_slist_free(expected);
627 expected = NULL;
628 }
629
630 void
prof_whole_occurrences_tests(void ** state)631 prof_whole_occurrences_tests(void** state)
632 {
633 GSList* actual = NULL;
634 GSList* expected = NULL;
635 assert_true(_lists_equal(prof_occurrences(NULL, NULL, 0, FALSE, &actual), expected));
636 g_slist_free(actual);
637 actual = NULL;
638
639 expected = g_slist_append(expected, GINT_TO_POINTER(0));
640 assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5", 0, TRUE, &actual), expected));
641 g_slist_free(actual);
642 actual = NULL;
643 assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5 hi", 0, TRUE, &actual), expected));
644 g_slist_free(actual);
645 actual = NULL;
646 assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5: hi", 0, TRUE, &actual), expected));
647 g_slist_free(actual);
648 actual = NULL;
649 assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5, hi", 0, TRUE, &actual), expected));
650 g_slist_free(actual);
651 actual = NULL;
652 g_slist_free(expected);
653 expected = NULL;
654
655 expected = g_slist_append(expected, GINT_TO_POINTER(0));
656 assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "我能吞下玻璃而", 0, TRUE, &actual), expected));
657 g_slist_free(actual);
658 actual = NULL;
659 assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "我能吞下玻璃而 hi", 0, TRUE, &actual), expected));
660 g_slist_free(actual);
661 actual = NULL;
662 assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "我能吞下玻璃而: hi", 0, TRUE, &actual), expected));
663 g_slist_free(actual);
664 actual = NULL;
665 assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "我能吞下玻璃而, hi", 0, TRUE, &actual), expected));
666 g_slist_free(actual);
667 actual = NULL;
668 g_slist_free(expected);
669 expected = NULL;
670
671 expected = g_slist_append(expected, GINT_TO_POINTER(6));
672 assert_true(_lists_equal(prof_occurrences("boothj5", "hello boothj5", 0, TRUE, &actual), expected));
673 g_slist_free(actual);
674 actual = NULL;
675 assert_true(_lists_equal(prof_occurrences("boothj5", "hello boothj5 there", 0, TRUE, &actual), expected));
676 g_slist_free(actual);
677 actual = NULL;
678 assert_true(_lists_equal(prof_occurrences("boothj5", "heyy @boothj5, there", 0, TRUE, &actual), expected));
679 g_slist_free(actual);
680 actual = NULL;
681 g_slist_free(expected);
682 expected = NULL;
683
684 expected = g_slist_append(expected, GINT_TO_POINTER(6));
685 assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "hello 我能吞下玻璃而", 0, TRUE, &actual), expected));
686 g_slist_free(actual);
687 actual = NULL;
688 assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "hello 我能吞下玻璃而 there", 0, TRUE, &actual), expected));
689 g_slist_free(actual);
690 actual = NULL;
691 assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "heyy @我能吞下玻璃而, there", 0, TRUE, &actual), expected));
692 g_slist_free(actual);
693 actual = NULL;
694 g_slist_free(expected);
695 expected = NULL;
696
697 expected = g_slist_append(expected, GINT_TO_POINTER(6));
698 expected = g_slist_append(expected, GINT_TO_POINTER(26));
699 assert_true(_lists_equal(prof_occurrences("boothj5", "hello boothj5 some more a boothj5 stuff", 0, TRUE, &actual), expected));
700 g_slist_free(actual);
701 actual = NULL;
702 assert_true(_lists_equal(prof_occurrences("boothj5", "hello boothj5 there ands #boothj5", 0, TRUE, &actual), expected));
703 g_slist_free(actual);
704 actual = NULL;
705 assert_true(_lists_equal(prof_occurrences("boothj5", "heyy @boothj5, there hows boothj5?", 0, TRUE, &actual), expected));
706 g_slist_free(actual);
707 actual = NULL;
708 g_slist_free(expected);
709 expected = NULL;
710
711 expected = g_slist_append(expected, GINT_TO_POINTER(6));
712 expected = g_slist_append(expected, GINT_TO_POINTER(26));
713 assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "hello 我能吞下玻璃而 some more a 我能吞下玻璃而 stuff", 0, TRUE, &actual), expected));
714 g_slist_free(actual);
715 actual = NULL;
716 assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "hello 我能吞下玻璃而 there ands #我能吞下玻璃而", 0, TRUE, &actual), expected));
717 g_slist_free(actual);
718 actual = NULL;
719 assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "heyy @我能吞下玻璃而, there hows 我能吞下玻璃而?", 0, TRUE, &actual), expected));
720 g_slist_free(actual);
721 actual = NULL;
722 g_slist_free(expected);
723 expected = NULL;
724
725 expected = g_slist_append(expected, GINT_TO_POINTER(6));
726 assert_true(_lists_equal(prof_occurrences("p", "ppppp p", 0, TRUE, &actual), expected));
727 g_slist_free(actual);
728 actual = NULL;
729 g_slist_free(expected);
730 expected = NULL;
731
732 expected = g_slist_append(expected, GINT_TO_POINTER(0));
733 assert_true(_lists_equal(prof_occurrences("p", "p ppppp", 0, TRUE, &actual), expected));
734 g_slist_free(actual);
735 actual = NULL;
736 g_slist_free(expected);
737 expected = NULL;
738
739 expected = g_slist_append(expected, GINT_TO_POINTER(4));
740 assert_true(_lists_equal(prof_occurrences("p", "ppp p ppp", 0, TRUE, &actual), expected));
741 g_slist_free(actual);
742 actual = NULL;
743 g_slist_free(expected);
744 expected = NULL;
745
746 expected = NULL;
747 assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5hello", 0, TRUE, &actual), expected));
748 g_slist_free(actual);
749 actual = NULL;
750 assert_true(_lists_equal(prof_occurrences("boothj5", "heyboothj5", 0, TRUE, &actual), expected));
751 g_slist_free(actual);
752 actual = NULL;
753 assert_true(_lists_equal(prof_occurrences("boothj5", "heyboothj5hithere", 0, TRUE, &actual), expected));
754 g_slist_free(actual);
755 actual = NULL;
756 assert_true(_lists_equal(prof_occurrences("boothj5", "hey boothj5hithere", 0, TRUE, &actual), expected));
757 g_slist_free(actual);
758 actual = NULL;
759 assert_true(_lists_equal(prof_occurrences("boothj5", "hey @boothj5hithere", 0, TRUE, &actual), expected));
760 g_slist_free(actual);
761 actual = NULL;
762 assert_true(_lists_equal(prof_occurrences("boothj5", "heyboothj5 hithere", 0, TRUE, &actual), expected));
763 g_slist_free(actual);
764 actual = NULL;
765 assert_true(_lists_equal(prof_occurrences("boothj5", "heyboothj5, hithere", 0, TRUE, &actual), expected));
766 g_slist_free(actual);
767 actual = NULL;
768 assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5boothj5", 0, TRUE, &actual), expected));
769 g_slist_free(actual);
770 actual = NULL;
771 assert_true(_lists_equal(prof_occurrences("boothj5", "boothj5fillboothj5", 0, TRUE, &actual), expected));
772 g_slist_free(actual);
773 actual = NULL;
774 assert_true(_lists_equal(prof_occurrences("k", "dont know", 0, TRUE, &actual), expected));
775 g_slist_free(actual);
776 actual = NULL;
777 assert_true(_lists_equal(prof_occurrences("k", "kick", 0, TRUE, &actual), expected));
778 g_slist_free(actual);
779 actual = NULL;
780 assert_true(_lists_equal(prof_occurrences("k", "kick kick", 0, TRUE, &actual), expected));
781 g_slist_free(actual);
782 actual = NULL;
783 assert_true(_lists_equal(prof_occurrences("k", "kick kickk", 0, TRUE, &actual), expected));
784 g_slist_free(actual);
785 actual = NULL;
786 assert_true(_lists_equal(prof_occurrences("k", "kic", 0, TRUE, &actual), expected));
787 g_slist_free(actual);
788 actual = NULL;
789 assert_true(_lists_equal(prof_occurrences("k", "ick", 0, TRUE, &actual), expected));
790 g_slist_free(actual);
791 actual = NULL;
792 assert_true(_lists_equal(prof_occurrences("k", "kk", 0, TRUE, &actual), expected));
793 g_slist_free(actual);
794 actual = NULL;
795 assert_true(_lists_equal(prof_occurrences("k", "kkkkkkk", 0, TRUE, &actual), expected));
796 g_slist_free(actual);
797 actual = NULL;
798 g_slist_free(expected);
799 expected = NULL;
800
801 expected = NULL;
802 assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "我能吞下玻璃而hello", 0, TRUE, &actual), expected));
803 g_slist_free(actual);
804 actual = NULL;
805 assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "hey我能吞下玻璃而", 0, TRUE, &actual), expected));
806 g_slist_free(actual);
807 actual = NULL;
808 assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "hey我能吞下玻璃而hithere", 0, TRUE, &actual), expected));
809 g_slist_free(actual);
810 actual = NULL;
811 assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "hey 我能吞下玻璃而hithere", 0, TRUE, &actual), expected));
812 g_slist_free(actual);
813 actual = NULL;
814 assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "hey @我能吞下玻璃而hithere", 0, TRUE, &actual), expected));
815 g_slist_free(actual);
816 actual = NULL;
817 assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "hey我能吞下玻璃而 hithere", 0, TRUE, &actual), expected));
818 g_slist_free(actual);
819 actual = NULL;
820 assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "hey我能吞下玻璃而, hithere", 0, TRUE, &actual), expected));
821 g_slist_free(actual);
822 actual = NULL;
823 assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "我能吞下玻璃而我能吞下玻璃而", 0, TRUE, &actual), expected));
824 g_slist_free(actual);
825 actual = NULL;
826 assert_true(_lists_equal(prof_occurrences("我能吞下玻璃而", "我能吞下玻璃而fill我能吞下玻璃而", 0, TRUE, &actual), expected));
827 g_slist_free(actual);
828 actual = NULL;
829 g_slist_free(expected);
830 expected = NULL;
831 }
832