00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "curlcheck.h"
00023
00024 #include <curl/curl.h>
00025
00026 static CURLcode unit_setup(void)
00027 {
00028 return CURLE_OK;
00029 }
00030
00031 static void unit_stop(void)
00032 {
00033
00034 }
00035
00036 static size_t print_httppost_callback(void *arg, const char *buf, size_t len)
00037 {
00038 fwrite(buf, len, 1, stdout);
00039 (*(size_t *) arg) += len;
00040 return len;
00041 }
00042
00043 UNITTEST_START
00044 int rc;
00045 struct curl_httppost *post = NULL;
00046 struct curl_httppost *last = NULL;
00047 size_t total_size = 0;
00048 char buffer[] = "test buffer";
00049
00050 rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "name",
00051 CURLFORM_COPYCONTENTS, "content", CURLFORM_END);
00052
00053 fail_unless(rc == 0, "curl_formadd returned error");
00054
00055
00056
00057 fail_unless(post == last, "post and last weren't the same");
00058
00059 rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "htmlcode",
00060 CURLFORM_COPYCONTENTS, "<HTML></HTML>",
00061 CURLFORM_CONTENTTYPE, "text/html", CURLFORM_END);
00062
00063 fail_unless(rc == 0, "curl_formadd returned error");
00064
00065 rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "name_for_ptrcontent",
00066 CURLFORM_PTRCONTENTS, buffer, CURLFORM_END);
00067
00068 fail_unless(rc == 0, "curl_formadd returned error");
00069
00070 rc = curl_formget(post, &total_size, print_httppost_callback);
00071
00072 fail_unless(rc == 0, "curl_formget returned error");
00073
00074 fail_unless(total_size == 486, "curl_formget got wrong size back");
00075
00076 curl_formfree(post);
00077
00078
00079 post = last = NULL;
00080
00081 rc = curl_formadd(&post, &last,
00082 CURLFORM_PTRNAME, "name of file field",
00083 CURLFORM_FILE, "log/test-1308",
00084 CURLFORM_FILENAME, "custom named file",
00085 CURLFORM_END);
00086
00087 fail_unless(rc == 0, "curl_formadd returned error");
00088
00089 rc = curl_formget(post, &total_size, print_httppost_callback);
00090 fail_unless(rc == 0, "curl_formget returned error");
00091 fail_unless(total_size == 847, "curl_formget got wrong size back");
00092
00093 curl_formfree(post);
00094
00095 UNITTEST_STOP