httpd-apreq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Randy Kobes <ra...@theoryx5.uwinnipeg.ca>
Subject escape and encode_param tests
Date Sun, 18 Jul 2004 03:25:15 GMT
Here's some tests for the apreq_escape() and
apreq_encode_param() functions ...
=============================================
Index: STATUS
===================================================================
RCS file: /home/cvs/httpd-apreq-2/STATUS,v
retrieving revision 1.71
diff -u -r1.71 STATUS
--- STATUS	18 Jul 2004 03:09:57 -0000	1.71
+++ STATUS	18 Jul 2004 03:16:45 -0000
@@ -63,8 +63,6 @@
       -  apreq_merge_values()
       -  apreq_enctype()
       -  apreq_memmem()
-      -  apreq_escape()
-      -  apreq_encode_param()

     - CuTest needs va_arg to print comments for a failed unit test.

Index: t/params.c
===================================================================
RCS file: /home/cvs/httpd-apreq-2/t/params.c,v
retrieving revision 1.16
diff -u -r1.16 params.c
--- t/params.c	18 Jul 2004 03:09:57 -0000	1.16
+++ t/params.c	18 Jul 2004 03:16:46 -0000
@@ -74,10 +74,18 @@
     CuAssertStrEquals(tc,"bend it like beckham",s1);
     apreq_unescape(s1);
     CuAssertStrEquals(tc,"bend it like beckham",s1);
+    s3 = apreq_escape(p, s1, 20);
+    CuAssertStrEquals(tc,"bend+it+like+beckham",s3);
+    apreq_unescape(s3);
+    CuAssertStrEquals(tc,"bend it like beckham",s3);
+
     CuAssertStrEquals(tc,"dandy %3Edons",s2);
     apreq_unescape(s2);
     CuAssertStrEquals(tc,"dandy >dons",s2);
-
+    s3 = apreq_escape(p, s2, 11);
+    CuAssertStrEquals(tc,"dandy+%3edons",s3);
+    apreq_unescape(s3);
+    CuAssertStrEquals(tc,"dandy >dons",s3);
 }

 static void header_attributes(CuTest *tc)
@@ -125,6 +133,30 @@
     CuAssertStrEquals(tc, val, v2->data);
 }

+static void make_param(CuTest *tc)
+{
+    apreq_param_t *param, *result;
+    apr_size_t nlen = 3, vlen = 11;
+    char *name = apr_palloc(p,nlen+1);
+    char *val = apr_palloc(p,vlen+1);
+    char *encode = apr_palloc(p,vlen+nlen+1);
+    strcpy(name, "foo");
+    strcpy(val, "bar > alpha");
+
+    param = apreq_make_param(p, name, nlen, val, vlen);
+    CuAssertStrEquals(tc, name, param->v.name);
+    CuAssertIntEquals(tc, vlen, param->v.size);
+    CuAssertStrEquals(tc, val, param->v.data);
+
+    encode = apreq_encode_param(p, param);
+    CuAssertStrEquals(tc, "foo=bar+%3e+alpha", encode);
+
+    result = apreq_decode_param(p, encode, nlen, vlen+2);
+    CuAssertStrEquals(tc, name, result->v.name);
+    CuAssertIntEquals(tc, vlen, result->v.size);
+    CuAssertStrEquals(tc, val, result->v.data);
+}
+
 static void quote_strings(CuTest *tc)
 {
     apr_size_t exp_len, res_len, res_quote_len;
@@ -164,6 +196,7 @@
     SUITE_ADD_TEST(suite, header_attributes);
     SUITE_ADD_TEST(suite, make_values);
     SUITE_ADD_TEST(suite, quote_strings);
+    SUITE_ADD_TEST(suite, make_param);

     return suite;
 }

===========================================================

-- 
best regards,
randy


Mime
View raw message