Browse code

webkernel_test: add a test for uri_urldecode

Dario Rodriguez authored on 23/07/2014 20:36:55
Showing 1 changed files
... ...
@@ -31,6 +31,7 @@ char *socklib_sselect(test_action action);
31 31
 char *sbuf_memory(test_action action);
32 32
 char *webkernel_basic(test_action action);
33 33
 char *webkernel_dual(test_action action);
34
+char *webkernel_urldecode(test_action action);
34 35
 
35 36
 
36 37
 struct {
... ...
@@ -41,6 +42,7 @@ struct {
41 42
            {sbuf_memory},
42 43
            {webkernel_basic},
43 44
            {webkernel_dual},
45
+           {webkernel_urldecode},
44 46
           };
45 47
 
46 48
 int
... ...
@@ -632,3 +634,31 @@ Connection: keep-alive\r\n\
632 634
         return(STRING_OK);
633 635
 }
634 636
 
637
+/* webkernel_urldecode */
638
+char *
639
+webkernel_urldecode(test_action action)
640
+{
641
+	static struct {
642
+		char *encoded;
643
+		char *decoded;
644
+	} strs[]={{"my%40emailservice.com","my@emailservice.com"}};
645
+	int i;
646
+	char buf[1024];
647
+	static char myerror[1024];
648
+        if(action==test_name)
649
+                return("webkernel_urldecode");
650
+        else if(action==test_description)
651
+                return("check some strings against uri_urldecode");
652
+        /* run test */
653
+	for(i=0;i<(sizeof(strs)/sizeof(strs[0]));i++) {
654
+		strncpy(buf,strs[i].encoded,sizeof(buf));
655
+		buf[sizeof(buf)-1]='\0';
656
+		uri_urldecode(buf);
657
+		if(strcmp(buf,strs[i].decoded)!=0) {
658
+			snprintf(myerror,sizeof(myerror),"%s: incorrect decoding of string \"%s\" (\"%s\"!=\"%s\")\n",STRING_FAIL,strs[i].encoded,buf,strs[i].decoded);
659
+			myerror[sizeof(myerror)-1]='\0';
660
+			return(myerror);
661
+		}
662
+	}
663
+        return(STRING_OK);
664
+}