switched to 3.9.7 defaults
[psensor-pkg-ubuntu.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 #include <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <sys/stat.h>
24
25 #include "../src/lib/url.h"
26
27 int test_url_encode(char *url, char *ref_url)
28 {
29         char *res_url;
30         int ret;
31
32         res_url = url_encode(url);
33
34         if (strcmp(ref_url, res_url)) {
35                 fprintf(stderr,
36                         "FAILURE: url_encode(%s) returns %s instead of %s\n",
37                         url, res_url, ref_url);
38                 ret = 0;
39         } else {
40                 ret = 1;
41         }
42
43         free(res_url);
44
45         return ret;
46 }
47
48 int tests_url_encode()
49 {
50         int failures;
51
52         failures = 0;
53
54         if (!test_url_encode("abcdef12345", "abcdef12345"))
55                 failures++;
56
57         if (!test_url_encode("a b", "a%20b"))
58                 failures++;
59
60         if (!test_url_encode("ab-_.~", "ab-_.~"))
61                 failures++;
62
63         return failures;
64 }
65
66
67 int main(int argc, char **argv)
68 {
69         int failures;
70
71         failures = 0;
72
73         failures += tests_url_encode();
74
75         if (failures) 
76                 exit(EXIT_FAILURE);
77         else
78                 exit(EXIT_SUCCESS);
79 }