]> git.ozlabs.org Git - petitboot/blobdiff - test/urls/parse-url.c
test: Add URL parser test infrastructure
[petitboot] / test / urls / parse-url.c
diff --git a/test/urls/parse-url.c b/test/urls/parse-url.c
new file mode 100644 (file)
index 0000000..3e2f10f
--- /dev/null
@@ -0,0 +1,35 @@
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <ui/common/url.h>
+#include <log/log.h>
+
+int main(int argc, char **argv)
+{
+       struct pb_url *url;
+       FILE *null;
+
+       if (argc != 2) {
+               fprintf(stderr, "Usage: %s <URL>\n", argv[0]);
+               return EXIT_FAILURE;
+       }
+
+       /* discard log output */
+       null = fopen("/dev/null", "w");
+       pb_log_set_stream(null);
+
+       url = pb_url_parse(NULL, argv[1]);
+       if (!url)
+               return EXIT_FAILURE;
+
+       printf("%s\n", argv[1]);
+       printf("scheme\t%s\n", pb_url_scheme_name(url->scheme));
+       printf("host\t%s\n", url->host);
+       printf("port\t%s\n", url->port);
+       printf("path\t%s\n", url->path);
+       printf("dir\t%s\n", url->dir);
+       printf("file\t%s\n", url->file);
+
+       return EXIT_SUCCESS;
+}