aboutsummaryrefslogtreecommitdiff
path: root/regress/iri_test.c
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2022-07-04 09:36:55 +0000
committerOmar Polo <op@omarpolo.com>2022-07-04 09:36:55 +0000
commit617ae38546228225f95507573ab21a4b5a7e9a40 (patch)
tree6ac8bd5d855bbfe85eea96671c48cae996943bff /regress/iri_test.c
parent475205fa0f2737475a17dd692b71611523b898a0 (diff)
add some more regress for the encodings
Diffstat (limited to 'regress/iri_test.c')
-rw-r--r--regress/iri_test.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/regress/iri_test.c b/regress/iri_test.c
index c6725b5..a3f6895 100644
--- a/regress/iri_test.c
+++ b/regress/iri_test.c
@@ -20,6 +20,19 @@
#include "../gmid.h"
+#define ENCTEST(buf, len, raw, exp) \
+ if (encode_path(buf, len, raw) == -1) { \
+ fprintf(stderr, "%s:%d: failed to encode: %s\n", \
+ __FILE__, __LINE__, raw); \
+ exit(1); \
+ } \
+ if (strcmp(buf, exp) != 0) { \
+ fprintf(stderr, "%s:%d: error: " \
+ "unexpected encoding: got %s, want %s\n", \
+ __FILE__, __LINE__, buf, exp); \
+ exit(1); \
+ }
+
#define TEST(iri, fail, exp, descr) \
if (!run_test(iri, fail, exp)) { \
fprintf(stderr, "%s:%d: error: %s\n", \
@@ -90,8 +103,13 @@ done:
int
main(void)
{
+ char buf[32];
struct iri empty = IRI("", "", "", "", "", "");
+ ENCTEST(buf, sizeof(buf), "hello world", "hello%20world");
+ ENCTEST(buf, sizeof(buf), "hello\nworld", "hello%0Aworld");
+ ENCTEST(buf, sizeof(buf), "hello\r\nworld", "hello%0D%0Aworld");
+
TEST("http://omarpolo.com",
PASS,
IRI("http", "omarpolo.com", "", "", "", ""),