added test for url_normalize
[psensor.git] / tests / test_url_normalize.c
1 /*
2  * Copyright (C) 2010-2011 jeanfi@gmail.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  *02110-1301 USA
18  */
19
20
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <sys/stat.h>
25
26 #include "../src/lib/url.h"
27
28
29 int test_url_normalize(const char *url, const char *ref_url)
30 {
31         int ret;
32         char *tmp = url_normalize(url);
33
34         if (!strcmp(tmp, ref_url)) {
35                 ret = 1;
36         } else {
37                 fprintf(stderr,
38                         "FAILURE: "
39                         "url_normalize(%s) returns %s instead of %s\n",
40                         url,
41                         tmp,
42                         ref_url);
43                 ret = 0;
44         }
45
46         free(tmp);
47
48         return ret;
49 }
50
51
52 int tests_url_normalize()
53 {
54         int failures;
55
56         failures = 0;
57
58         if (!test_url_normalize("http://test/test", "http://test/test"))
59                 failures++;
60
61         if (!test_url_normalize("http://test/test/", "http://test/test"))
62                 failures++;
63
64         return failures;
65 }
66
67 int main(int argc, char **argv)
68 {
69         int failures;
70
71         failures = 0;
72
73         failures += tests_url_normalize();
74
75         if (failures) 
76                 exit(EXIT_FAILURE);
77         else
78                 exit(EXIT_SUCCESS);
79 }