From 094bea990eef9bd9e06cc6c8a9487fadc91b717e Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Fri, 8 Apr 2022 21:27:25 +0000 Subject: [PATCH] Mime form parser FossilOrigin-Name: adf6b4dbd19b77879f9e9b189f59c88e61a452b89f21e36dfbc101a5d311d4b1 --- test/tests | Bin 25008 -> 26184 bytes test/unit/mime_multipart.c | 38 ++++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/test/tests b/test/tests index d3d1a981f62b03884577ca6b664f5c9c9d9c99a7..3bfa6e3aba16ecc6607ead35de5dff58cdc90eb6 100755 GIT binary patch delta 8795 zcmb6;2~?a#npJ;yHGR;~2X{CcViIDcImX-}fI$2?LP!Fd8<0a#AOxCtOq@0$(P&b@O!ABh1b!F%c(j5@S{q-Oa|)b#aW^8ndGDKqpS`_f`Er0rbt=t(W{& z-+k0qSM%&Kdh#^g8|TV$64CNyN7T*z*FIq}TO?@ie>>B<(k_9OcJ88H%bjKk-pQTR z%{S3R%ebNm^PTkm)Zi=$P49PTOgs2o<*BGUTDLSV?>y3#T$p*^f8VnEz$0pDDGw^w zL`MM|h5shOzEgaoc&cFz-NXA0vAot0N7v(s-of8DX3|H+_$@&j1KNiIevqdEZBSqx zERJ%4{k`};Bfd@Idz!B{W*U!x6<$~F=6P%--^Ui4Iyzh0eNFrf8{xk)&AC~|M~Q)? zfNKun6CqJ8Esz-_nXBR40ydDJX>fN!3#3sYxd3B3m@9iNf5gF^VX^UNvw(`Q_~$Fw z&HW31&KXlQU*k82Mw^6Mo&Db2SAj&jGpp5}+!!3Hfe(G*YH#k700c8ap-`|HKF8T0 zx4DXKry+gMqrKpt_(oTJ`VoLHhJkm7VW9R_2i0Dy8u)`6cpV&hdV+b7?|0ppyba*s zVFTJI4yt{{qiWzdupL75;|5OMGyM53LWXCc8-4Tth${PXFCjVohfqlEEj|zE9}pcl z5&Ty`?HTEg1@tJOKhn@o3$!lyygHQQ13Jgt8!N3C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&cNwyHZ%rGB>8=dlgs z$=E9Gr-SEx^C=t?Q=2>nbqDQazNQj`I!FC%chdqm70yC?g5~-b7+u9O%5ekR*p?|fk UIl#^ZN{nmQ$Xp#|`);4`fB0G!VgLXD diff --git a/test/unit/mime_multipart.c b/test/unit/mime_multipart.c index 248c666..c7530c7 100644 --- a/test/unit/mime_multipart.c +++ b/test/unit/mime_multipart.c @@ -19,7 +19,7 @@ #include #include -int mime_multipart_test(void) +void mime_boundary_check(void) { char* bound, *bound2; char* mem = get_mime_boundary(BOUNDARY_CONTENT_T2, &bound); @@ -29,7 +29,43 @@ int mime_multipart_test(void) strcmp(bound2, BOUNDARY_RES_T) == 0); free(mem); free(mem2); +} + +void form_check(void) +{ + struct http_form_info info; + char* pos; + char* multipart = malloc(sizeof(MULTIPART_TEST)); + + assert(multipart != NULL); + + // Copy and test + strcpy(multipart, MULTIPART_TEST); + pos = read_form_data(BOUNDARY_RES_T, multipart, &info); + + assert(pos != NULL); + assert(strcmp(info.name, "text") == 0); + assert(strcmp(info.value, "text default") == 0); + + // test next value + pos = read_form_data(BOUNDARY_RES_T, pos, &info); + + assert(pos != NULL); + assert(strcmp(info.name, "file1") == 0); + assert(strcmp(info.filename, "a.txt") == 0); + assert(strcmp(info.content_type, "text/plain") == 0); + assert(strcmp(info.value, "Content of a.txt.\r\n") == 0); + + // TODO keep testing! + + free(multipart); +} + +int mime_multipart_test(void) +{ + mime_boundary_check(); + form_check(); return 0; }