added test for url_encode
[psensor.git] / tests / test_url_encode.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 int test_url_encode(char *url, char *ref_url)
29 {
30         char *res_url;
31         int ret;
32
33         res_url = url_encode(url);
34
35         if (strcmp(ref_url, res_url)) {
36                 fprintf(stderr,
37                         "FAILURE: url_encode(%s) returns %s instead of %s\n",
38                         url, res_url, ref_url);
39                 ret = 0;
40         } else {
41                 ret = 1;
42         }
43
44         free(res_url);
45
46         return ret;
47 }
48
49 int tests_url_encode()
50 {
51         int failures;
52
53         failures = 0;
54
55         if (!test_url_encode("abcdef12345", "abcdef12345"))
56                 failures++;
57
58         if (!test_url_encode("a b", "a%20b"))
59                 failures++;
60
61         if (!test_url_encode("ab-_.~", "ab-_.~"))
62                 failures++;
63
64         return failures;
65 }
66
67
68 int main(int argc, char **argv)
69 {
70         int failures;
71
72         failures = 0;
73
74         failures += tests_url_encode();
75
76         if (failures) 
77                 exit(EXIT_FAILURE);
78         else
79                 exit(EXIT_SUCCESS);
80 }