2 * Copyright (C) 2014, 2016 J. Ali Harlow <ali@juiblex.co.uk>
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.
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.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 static int is_ascii_letter(char c)
32 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
35 static int is_slash(char c)
37 return c == '/' || c == '\\';
40 static const char *mswin_path(const char *path)
45 if (path[0] == '/' && is_ascii_letter(path[1]) && path[2] == ':' &&
53 static int path_cmp(const char *p1, const char *p2)
57 if (*p1 == *p2 || is_slash(*p1) && is_slash(*p2)) {
66 return strcmp(p1, p2);
70 static int test_pfu(const char *uri, const char *path)
74 struct razor_error *error = NULL;
76 s = razor_path_from_uri(uri, &error);
79 path = mswin_path(path);
83 r = path_cmp(s, path);
88 fprintf(stderr, "Fail: razor_path_from_uri(\"%s\")", uri);
90 fprintf(stderr, " returns \"%s\", expected", s);
92 fprintf(stderr, " fails (%s), expected",
93 razor_error_get_msg(error));
95 fprintf(stderr, " \"%s\"\n", path);
97 fprintf(stderr, " failure\n");
102 razor_error_free(error);
110 static void cleanup_on_exit(void)
112 SetConsoleOutputCP(saved_cp);
116 int main(int argc, char *argv[])
121 atexit(cleanup_on_exit);
122 saved_cp = GetConsoleOutputCP();
123 SetConsoleOutputCP(CP_UTF8);
126 r |= test_pfu("file://localhost/etc/fstab", "/etc/fstab");
127 r |= test_pfu("file:///etc/fstab", "/etc/fstab");
128 r |= test_pfu("file://localhost/c:/WINDOWS/clock.avi",
129 "/c:/WINDOWS/clock.avi");
130 r |= test_pfu("file:///c:/WINDOWS/clock.avi",
131 "/c:/WINDOWS/clock.avi");
132 r |= test_pfu("file:///path/to/the%20file.txt",
133 "/path/to/the file.txt");
134 r |= test_pfu("file:///home/s%C3%A9bastien", "/home/sébastien");
135 r |= test_pfu("file:///home/luk%C3%A1%C5%A1", "/home/lukáš");
136 r |= test_pfu("file:///var/log/22%20%e0%b8%aa%e0%b8%b4%e0%b8%87%e0%b8%ab%e0%b8%b2%e0%b8%84%e0%b8%a1%202014",
137 "/var/log/22 สิงหาคม 2014");