Add a test for relocations that are valid paths but would be invalid URIs if mis-interpreted
2 * Copyright (C) 2009, 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.
28 #include "razor-internal.h"
31 * This kludge is to work around an apparent bug in Fedora 10's lua package
32 * (it appears to require libm but not to include a DT_NEEDED).
35 void (*kludge)() = (void (*)())sin;
37 static void recursive_remove(const char *directory)
43 dp = opendir(directory);
44 while((dirp = readdir(dp))) {
45 if (strcmp(dirp->d_name, ".") && strcmp(dirp->d_name, "..")) {
46 buf = malloc(strlen(directory) + strlen(dirp->d_name)
48 sprintf(buf, "%s/%s", directory, dirp->d_name);
50 recursive_remove(buf);
58 int main(int argc, char *argv[])
60 char root[] = "/tmp/razor.XXXXXX";
64 char *s, *test_uri, *srcdir, *suffix, *cwd;
66 struct razor_error *error = NULL;
67 struct razor_uri base_ru, test_ru, ru;
70 fprintf(stderr, "usage: %s [TESTS-URI]\n", argv[0]);
76 test_uri = "test.lua";
83 s = malloc(strlen(root) + strlen("/testfile") + 1);
85 strcat(s, "/testfile");
91 fprintf(fp, "#!" LUA_BINARY "\n"
92 "print('Abracadabra!')\n");
94 chmod(s, S_IRUSR | S_IWUSR | S_IXUSR);
97 for (len = 32;; len *= 2) {
103 cwd = realloc(cwd, strlen(cwd) + 1);
105 s = razor_concat("file:", cwd, NULL);
106 if (razor_uri_parse(&test_ru, test_uri, &error) ||
107 razor_uri_parse(&base_ru, s, &error)) {
108 fprintf(stderr, "%s\n", razor_error_get_msg(error));
109 razor_error_free(error);
114 razor_uri_resolve(&ru, &base_ru, &test_ru);
115 razor_uri_destroy(&base_ru);
116 s = razor_uri_recompose(&ru);
117 razor_uri_destroy(&ru);
118 script = razor_uri_get_contents(s, &len, 0, &error);
121 srcdir = getenv("srcdir");
122 if (srcdir && errno == ENOENT) {
123 razor_error_free(error);
125 suffix = srcdir[strlen(srcdir) - 1] == '/' ? NULL : "/";
127 s = razor_concat("file:", srcdir, suffix, NULL);
129 s = razor_concat("file:", cwd, "/", srcdir,
131 razor_uri_parse(&base_ru, s, &error);
134 razor_uri_resolve(&ru, &base_ru, &test_ru);
135 razor_uri_destroy(&base_ru);
136 s = razor_uri_recompose(&ru);
137 razor_uri_destroy(&ru);
138 script = razor_uri_get_contents(s, &len, 0,
143 fprintf(stderr, "%s\n",
144 razor_error_get_msg(error));
145 razor_error_free(error);
149 fprintf(stderr, "%s\n", razor_error_get_msg(error));
150 razor_error_free(error);
154 razor_uri_destroy(&test_ru);
157 r = run_lua_script(root, test_uri, script, len, -1);
158 razor_uri_free_contents(script, len);
160 recursive_remove(root);