summaryrefslogtreecommitdiff
path: root/src/util/test_uri.c
blob: 7c81566486334ebb2288fdbe0c44644bd8d9ee10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "gnunet_uri_lib.h"

#define KNRM  "\x1B[0m"
#define KBLU  "\x1B[34m"
#define KGRN  "\x1B[32m"
#define KERR  "\x1B[5;31;50m"

/* macro to print out the header for a new group of tests */
#define mu_group(name) printf ("%s • %s%s\n", KBLU, name, KNRM)

/* macro for asserting a statement */
#define mu_assert(message, test) do { \
    if (!(test)) { \
      printf ("\t%s× %s%s\n", KERR, message, KNRM); \
      return message; \
    } \
    printf ("\t%s• %s%s\n", KGRN, message, KNRM); \
  } while (0)

/* macro for asserting a statement without printing it unless it is a failure */
#define mu_silent_assert(message, test) do { \
    if (!(test)) { \
      printf ("\t\t%s× %s%s\n", KERR, message, KNRM); \
      return message; \
    } \
  } while (0)

/* run a test function and return result */
#define mu_run_test(test) do { \
    char *message = test (); tests_run++; \
    if (message) { return message; } \
  } while (0)


int tests_run;

static int
strcmp_wrap (const char *str,
             const char *str2)
{
  if (NULL == str && NULL == str2) {
    return 0;
  }
  if (NULL == str) {
    return 1;
  }
  if (NULL == str2) {
    return -1;
  }

  return strcmp (str, str2);
}

#define assert_struct(as_url, \
                      as_scheme, \
                      as_user, \
                      as_pass, \
                      as_host, \
                      as_port, \
                      as_path, \
                      as_query, \
                      as_fragment) \
  mu_silent_assert ("should set the scheme attribute correctly", \
                    0 == strcmp_wrap (as_url.scheme, as_scheme)); \
  mu_silent_assert ("should set the username attribute correctly", \
                    0 == strcmp_wrap (as_url.username, as_user)); \
  mu_silent_assert ("should set the password attribute correctly", \
                    0 == strcmp_wrap (as_url.password, as_pass)); \
  mu_silent_assert ("should set the host attribute correctly", \
                    0 == strcmp_wrap (as_url.host, as_host)); \
  mu_silent_assert ("should set the port attribute correctly", \
                    as_port == as_url.port); \
  mu_silent_assert ("should set the path attribute correctly", \
                    0 == strcmp_wrap (as_url.path, as_path)); \
  mu_silent_assert ("should set the query attribute correctly", \
                    0 == strcmp_wrap (as_url.query, as_query)); \
  mu_silent_assert ("should set the fragment attribute correctly", \
                    0 == strcmp_wrap (as_url.fragment, as_fragment));

static char *
test_parse_http_url_ok (void)
{
  int rc;
  struct GNUNET_Uri url;
  char *url_string;

  /* Minimal URL */
  url_string = strdup ("http://example.com");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("minimal HTTP URL", -1 != rc);
  assert_struct (url,
                 "http",
                 NULL,
                 NULL,
                 "example.com",
                 0,
                 NULL,
                 NULL,
                 NULL);
  free (url_string);

  /* With path (/) */
  url_string = strdup ("http://example.com/");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("with path ('/')", -1 != rc);
  assert_struct (url,
                 "http",
                 NULL,
                 NULL,
                 "example.com",
                 0,
                 "",
                 NULL,
                 NULL);
  free (url_string);

  /* With path */
  url_string = strdup ("http://example.com/path");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("with path ('/path')", -1 != rc);
  assert_struct (url,
                 "http",
                 NULL,
                 NULL,
                 "example.com",
                 0,
                 "path",
                 NULL,
                 NULL);
  free (url_string);

  /* With port */
  url_string = strdup ("http://example.com:80");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("with port only",
             -1 != rc);
  assert_struct (url,
                 "http",
                 NULL,
                 NULL,
                 "example.com",
                 80,
                 NULL,
                 NULL,
                 NULL);
  free (url_string);

  /* With query */
  url_string = strdup ("http://example.com?query=only");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("with query only",
             -1 != rc);
  assert_struct (url,
                 "http",
                 NULL,
                 NULL,
                 "example.com",
                 0,
                 NULL,
                 "query=only",
                 NULL);
  free (url_string);

  /* With fragment */
  url_string = strdup ("http://example.com#frag=f1");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("with fragment only",
             -1 != rc);
  assert_struct (url,
                 "http",
                 NULL,
                 NULL,
                 "example.com",
                 0,
                 NULL,
                 NULL,
                 "frag=f1");
  free (url_string);

  /* With credentials */
  url_string = strdup ("http://u:p@example.com");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("with credentials only",
             -1 != rc);
  assert_struct (url,
                 "http",
                 "u",
                 "p",
                 "example.com",
                 0,
                 NULL,
                 NULL,
                 NULL);
  free (url_string);

  /* With port and path */
  url_string = strdup ("http://example.com:8080/port/and/path");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("with port and path",
             -1 != rc);
  assert_struct (url,
                 "http",
                 NULL,
                 NULL,
                 "example.com",
                 8080,
                 "port/and/path",
                 NULL,
                 NULL);
  free (url_string);

  /* With port and query */
  url_string = strdup ("http://example.com:8080?query=portANDquery");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("with port and query",
             -1 != rc);
  assert_struct (url,
                 "http",
                 NULL,
                 NULL,
                 "example.com",
                 8080,
                 NULL,
                 "query=portANDquery",
                 NULL);
  free (url_string);

  /* With port and fragment */
  url_string = strdup ("http://example.com:8080#f1");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("with port and fragment",
             -1 != rc);
  assert_struct (url,
                 "http",
                 NULL,
                 NULL,
                 "example.com",
                 8080,
                 NULL,
                 NULL,
                 "f1");
  free (url_string);

  /* With port and credentials */
  url_string = strdup ("http://u:p@example.com:8080");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("with port and credentials",
             -1 != rc);
  assert_struct (url,
                 "http",
                 "u",
                 "p",
                 "example.com",
                 8080,
                 NULL,
                 NULL,
                 NULL);
  free (url_string);

  /* With path and query */
  url_string = strdup ("http://example.com/path/and/query?q=yes");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("with path and query",
             -1 != rc);
  assert_struct (url,
                 "http",
                 NULL,
                 NULL,
                 "example.com",
                 0,
                 "path/and/query",
                 "q=yes",
                 NULL);
  free (url_string);

  /* With path and fragment */
  url_string = strdup ("http://example.com/path/and#fragment");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("with path and fragment",
             -1 != rc);
  assert_struct (url,
                 "http",
                 NULL,
                 NULL,
                 "example.com",
                 0,
                 "path/and",
                 NULL,
                 "fragment");
  free (url_string);

  /* With query and fragment */
  url_string = strdup ("http://example.com?q=yes#f1");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("with query and fragment",
             -1 != rc);
  assert_struct (url,
                 "http",
                 NULL,
                 NULL,
                 "example.com",
                 0,
                 NULL,
                 "q=yes",
                 "f1");
  free (url_string);

  /* With query and credentials */
  url_string = strdup ("http://u:p@example.com?q=yes");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("with query and credentials",
             -1 != rc);
  assert_struct (url,
                 "http",
                 "u",
                 "p",
                 "example.com",
                 0,
                 NULL,
                 "q=yes",
                 NULL);
  free (url_string);

  /* With empty credentials */
  url_string = strdup ("http://:@example.com");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("with empty credentials",
             -1 != rc);
  assert_struct (url,
                 "http",
                 "",
                 "",
                 "example.com",
                 0,
                 NULL,
                 NULL,
                 NULL);
  free (url_string);

  /* With empty credentials and port */
  url_string = strdup ("http://:@example.com:89");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("with empty credentials and port",
             -1 != rc);
  assert_struct (url,
                 "http",
                 "",
                 "",
                 "example.com",
                 89,
                 NULL,
                 NULL,
                 NULL);
  free (url_string);

  /* Full URL */
  url_string = strdup ("https://jack:password@localhost:8989/path/to/test?query=yes&q=jack#fragment1");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("with port, path and query",
             -1 != rc);
  assert_struct (url,
                 "https",
                 "jack",
                 "password",
                 "localhost",
                 8989,
                 "path/to/test",
                 "query=yes&q=jack",
                 "fragment1");
  free (url_string);

  return NULL;
}

static char *
test_parse_http_rel_url_ok (void)
{
  int rc;
  struct GNUNET_Uri url;
  char *url_string;

  /* Minimal relative URL */
  url_string = strdup ("/");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("minimal relative URL",
             -1 != rc);
  assert_struct (url,
                 NULL,
                 NULL,
                 NULL,
                 NULL,
                 0,
                 "",
                 NULL,
                 NULL);
  free (url_string);

  /* Path only */
  url_string = strdup ("/hejsan");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("path only",
             -1 != rc);
  assert_struct (url,
                 NULL,
                 NULL,
                 NULL,
                 NULL,
                 0,
                 "hejsan",
                 NULL,
                 NULL);
  free (url_string);

  /* Path and query */
  url_string = strdup ("/hejsan?q=yes");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("path only",
             -1 != rc);
  assert_struct (url,
                 NULL,
                 NULL,
                 NULL,
                 NULL,
                 0,
                 "hejsan",
                 "q=yes",
                 NULL);
  free (url_string);

  /* Path and fragment */
  url_string = strdup ("/hejsan#fragment");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("path and fragment",
             -1 != rc);
  assert_struct (url,
                 NULL,
                 NULL,
                 NULL,
                 NULL,
                 0,
                 "hejsan",
                 NULL,
                 "fragment");
  free (url_string);

  /* Path, query and fragment */
  url_string = strdup ("/?q=yes&q2=no#fragment");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("path, query and fragment",
             -1 != rc);
  assert_struct (url,
                 NULL,
                 NULL,
                 NULL,
                 NULL,
                 0,
                 "",
                 "q=yes&q2=no",
                 "fragment");
  free (url_string);

  return NULL;
}

static char *
test_parse_url_fail (void)
{
  int rc;
  struct GNUNET_Uri url;
  char *url_string;

  /* Empty */
  url_string = strdup ("");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("empty string should return -1",
             -1 == rc);
  free (url_string);

  /* Scheme only */
  url_string = strdup ("rtsp://");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("scheme only should return -1",
             -1 == rc);
  free (url_string);

  /* Hostname only */
  url_string = strdup ("hostname");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("hostname only should return -1",
             -1 == rc);
  free (url_string);

  /* Query only */
  url_string = strdup ("?query=only");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("query only should return -1",
             -1 == rc);
  free (url_string);

  /* Missing scheme */
  url_string = strdup ("://");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("missing scheme should return -1",
             -1 == rc);
  free (url_string);

  /* Missing hostname */
  url_string = strdup ("rtsp://:8910/path");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("missing hostname should return -1",
             -1 == rc);
  free (url_string);

  /* Missing credentials */
  url_string = strdup ("rtsp://@hostname:8910/path");
  rc = GNUNET_uri_parse (&url,
                         url_string);
  mu_assert ("missing credentials should return -1",
             -1 == rc);
  free (url_string);

  return NULL;
}

static char *
test_split_path_ok (void)
{
  int rc;
  char *path;
  char *parts[10];

  /* Simple path */
  path = strdup ("/this/is/a/path");
  rc = GNUNET_uri_split_path (path,
                              parts,
                              10);
  mu_assert ("should be able to parse a regular path",
             4 == rc);
  mu_silent_assert ("first part should be 'this'",
                    0 == strcmp ("this", parts[0]));
  mu_silent_assert ("second part should be 'is'",
                    0 == strcmp ("is", parts[1]));
  mu_silent_assert ("third part should be 'a'",
                    0 == strcmp ("a", parts[2]));
  mu_silent_assert ("fourth part should be 'path'",
                    0 == strcmp ("path", parts[3]));
  free (path);

  /* Relative path */
  path = strdup ("this/is/a/path");
  rc = GNUNET_uri_split_path (path,
                              parts,
                              10);
  mu_assert ("should be able to parse a relative path",
             4 == rc);
  mu_silent_assert ("first part should be 'this'",
                    0 == strcmp ("this", parts[0]));
  mu_silent_assert ("second part should be 'is'",
                    0 == strcmp ("is", parts[1]));
  mu_silent_assert ("third part should be 'a'",
                    0 == strcmp ("a", parts[2]));
  mu_silent_assert ("fourth part should be 'path'",
                    0 == strcmp ("path", parts[3]));
  free (path);

  /* Path with empty parts */
  path = strdup ("//this//is/a/path/");
  rc = GNUNET_uri_split_path (path,
                              parts,
                              10);
  mu_assert ("should treat multiple slashes as one",
             4 == rc);
  mu_silent_assert ("first part should be 'this'",
                    0 == strcmp("this", parts[0]));
  mu_silent_assert ("second part should be 'is'",
                    0 == strcmp("is", parts[1]));
  mu_silent_assert ("third part should be 'a'",
                    0 == strcmp("a", parts[2]));
  mu_silent_assert ("fourth part should be 'path'",
                    0 == strcmp("path", parts[3]));
  free (path);

  /* Just one level */
  path = strdup("/one_level");
  rc = GNUNET_uri_split_path(path, parts, 10);
  mu_assert("should be able to parse a path with one level", 1 == rc);
  mu_silent_assert("first part should be 'this'", 0 == strcmp("one_level", parts[0]));
  free(path);

  return NULL;
}

static char *
test_parse_query_ok (void)
{
  int rc;
  char *q;
  struct GNUNET_UriParam params[10];

  /* One param query */
  q = strdup ("q=yes");
  rc = GNUNET_uri_parse_query (q,
                               '&',
                               params,
                               10);
  mu_assert ("single parameter with value",
             1 == rc);
  mu_silent_assert ("first param key should be 'q'",
                    0 == strcmp ("q", params[0].key));
  mu_silent_assert ("first param val should be 'yes'",
                    0 == strcmp ("yes", params[0].val));
  free (q);

  /* One param query without value */
  q = strdup ("q");
  rc = GNUNET_uri_parse_query (q,
                               '&',
                               params,
                               10);
  mu_assert ("single parameter without value",
             1 == rc);
  mu_silent_assert ("first param key should be 'q'",
                    0 == strcmp ("q", params[0].key));
  mu_silent_assert ("first param val should be NULL",
                    NULL == params[0].val);
  free (q);

  /* Two param query */
  q = strdup ("query=yes&a1=hello");
  rc = GNUNET_uri_parse_query (q,
                               '&',
                               params,
                               10);
  mu_assert ("multiple params with value",
             2 == rc);
  mu_silent_assert ("first param key should be 'query'",
                    0 == strcmp ("query", params[0].key));
  mu_silent_assert ("first param val should be 'yes'",
                    0 == strcmp ("yes", params[0].val));
  mu_silent_assert ("second param key should be 'a1'",
                    0 == strcmp ("a1", params[1].key));
  mu_silent_assert ("second param val should be 'hello'",
                    0 == strcmp ("hello", params[1].val));
  free (q);

  /* Two param query, one without value */
  q = strdup ("query=yes&forceHttps");
  rc = GNUNET_uri_parse_query (q,
                               '&',
                               params,
                               10);
  mu_assert ("multiple params one without value",
             2 == rc);
  mu_silent_assert ("first param key should be 'query'",
                    0 == strcmp ("query", params[0].key));
  mu_silent_assert ("first param val should be 'yes'",
                    0 == strcmp ("yes", params[0].val));
  mu_silent_assert ("second param key should be 'forceHttps'",
                    0 == strcmp ("forceHttps", params[1].key));
  mu_silent_assert ("second param val should be NULL",
                    NULL == params[1].val);
  free (q);

  /* Three param query, all without value */
  q = strdup ("query&forceHttps&log");
  rc = GNUNET_uri_parse_query (q,
                               '&',
                               params,
                               10);
  mu_assert ("multiple params all without value",
             3 == rc);
  mu_silent_assert ("first param key should be 'query'",
                    0 == strcmp ("query", params[0].key));
  mu_silent_assert ("first param val should be NULL",
                    NULL == params[0].val);
  mu_silent_assert ("second param key should be 'forceHttps'",
                    0 == strcmp ("forceHttps", params[1].key));
  mu_silent_assert ("second param val should be NULL",
                    NULL == params[1].val);
  mu_silent_assert ("third param key should be 'log'",
                    0 == strcmp ("log", params[2].key));
  mu_silent_assert ("third param val should be NULL",
                    NULL == params[2].val);
  free (q);

  /* Param with empty value */
  q = strdup ("param=&query=no");
  rc = GNUNET_uri_parse_query (q,
                               '&',
                               params,
                               10);
  mu_assert ("param with empty value",
             2 == rc);
  mu_silent_assert ("first param key should be 'param'",
                    0 == strcmp ("param", params[0].key));
  mu_silent_assert ("first param val should be ''",
                    0 == strcmp ("", params[0].val));
  mu_silent_assert ("second param key should be 'query'",
                    0 == strcmp ("query", params[1].key));
  mu_silent_assert ("second param val should be 'no'",
                    0 == strcmp ("no", params[1].val));
  free (q);

  /* Double delimiter */
  q = strdup ("param=jack&&query=no");
  rc = GNUNET_uri_parse_query (q,
                               '&',
                               params,
                               10);
  mu_assert ("double delimiter",
             3 == rc);
  mu_silent_assert ("first param key should be 'param'",
                    0 == strcmp ("param", params[0].key));
  mu_silent_assert ("first param val should be 'jack'",
                    0 == strcmp ("jack", params[0].val));
  mu_silent_assert ("second param key should be ''",
                    0 == strcmp ("", params[1].key));
  mu_silent_assert ("second param val should be NULL",
                    NULL == params[1].val);
  mu_silent_assert ("third param key should be 'query'",
                    0 == strcmp ("query", params[2].key));
  mu_silent_assert ("third param val should be 'no'",
                    0 == strcmp ("no", params[2].val));
  free (q);

  /* Delimiter in beginning */
  q = strdup ("&param=jack&query=no");
  rc = GNUNET_uri_parse_query (q,
                               '&',
                               params,
                               10);
  mu_assert ("delimiter in beginning",
             3 == rc);
  mu_silent_assert ("first param key should be ''",
                    0 == strcmp ("", params[0].key));
  mu_silent_assert ("first param val should be NULL",
                    NULL == params[0].val);
  mu_silent_assert ("second param key should be 'param'",
                    0 == strcmp ("param", params[1].key));
  mu_silent_assert ("second param val should be 'jack'",
                    0 == strcmp ("jack", params[1].val));
  mu_silent_assert ("third param key should be 'query'",
                    0 == strcmp ("query", params[2].key));
  mu_silent_assert ("third param val should be 'no'",
                    0 == strcmp ("no", params[2].val));
  free (q);

  /* Delimiter at the end */
  q = strdup ("param=jack&query=no&");
  rc = GNUNET_uri_parse_query (q,
                               '&',
                               params,
                               10);
  mu_assert ("delimiter at the end",
             3 == rc);
  mu_silent_assert ("first param key should be 'param'",
                    0 == strcmp ("param", params[0].key));
  mu_silent_assert ("first param val should be 'jack'",
                    0 == strcmp ("jack", params[0].val));
  mu_silent_assert ("second param key should be 'query'",
                    0 == strcmp ("query", params[1].key));
  mu_silent_assert ("second param val should be 'no'",
                    0 == strcmp ("no", params[1].val));
  mu_silent_assert ("third param key should be ''",
                    0 == strcmp ("", params[2].key));
  mu_silent_assert ("third param val should be NULL",
                    NULL == params[2].val);
  free (q);

  return NULL;
}

static char *
all_tests (void)
{
  mu_group ("GNUNET_uri_parse () with an HTTP URL");
  mu_run_test (test_parse_http_url_ok);

  mu_group ("GNUNET_uri_parse () with an relative URL");
  mu_run_test (test_parse_http_rel_url_ok);

  mu_group ("GNUNET_uri_parse () with faulty values");
  mu_run_test (test_parse_url_fail);

  mu_group ("GNUNET_uri_split_path ()");
  mu_run_test (test_split_path_ok);

  mu_group ("GNUNET_uri_parse_query ()");
  mu_run_test (test_parse_query_ok);

  return NULL;
}

int
main (void)
{
  char *result;

  result = all_tests ();
  if (result != NULL) {
    exit (EXIT_FAILURE);
  }

  exit (EXIT_SUCCESS);
}