aboutsummaryrefslogtreecommitdiff
path: root/tests/libtest
diff options
context:
space:
mode:
authorPatrick Monnerat <patrick@monnerat.net>2017-09-02 19:08:45 +0100
committerPatrick Monnerat <patrick@monnerat.net>2017-09-02 19:08:45 +0100
commit3baf36edf6ed1d7c74d68846d79f87334b573aea (patch)
tree3946a907baae28c177dd65b4424deb7370d3d58c /tests/libtest
parentfec7a858b88c86e97e5dc96414a01feb21a2b661 (diff)
mime: tests and examples.
Additional mime-specific tests. Existing tests updated to reflect small differences (Expect: 100-continue, data size change due to empty lines, etc). Option -F headers= keyword added to tests. test1135 disabled until the entry point order change is resolved. New example smtp-mime. Examples postit2 and multi-post converted from form API to mime API.
Diffstat (limited to 'tests/libtest')
-rw-r--r--tests/libtest/Makefile.inc15
-rw-r--r--tests/libtest/lib589.c59
-rw-r--r--tests/libtest/lib643.c270
3 files changed, 343 insertions, 1 deletions
diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc
index 727582bd0..b372dfbd6 100644
--- a/tests/libtest/Makefile.inc
+++ b/tests/libtest/Makefile.inc
@@ -19,7 +19,8 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect \
lib547 lib548 lib549 lib552 lib553 lib554 lib555 lib556 lib557 lib558 \
lib559 lib560 lib562 lib564 lib565 lib566 lib567 lib568 lib569 lib570 \
lib571 lib572 lib573 lib574 lib575 lib576 lib578 lib579 lib582 \
- lib583 lib585 lib586 lib587 lib590 lib591 lib597 lib598 lib599 \
+ lib583 lib585 lib586 lib587 lib589 lib590 lib591 lib597 lib598 lib599 \
+ lib643 lib644 lib645 \
lib1500 lib1501 lib1502 lib1503 lib1504 lib1505 lib1506 lib1507 lib1508 \
lib1509 lib1510 lib1511 lib1512 lib1513 lib1514 lib1515 lib1517 \
lib1520 lib1521 \
@@ -282,6 +283,9 @@ lib586_CPPFLAGS = $(AM_CPPFLAGS)
lib587_SOURCES = lib554.c $(SUPPORTFILES)
lib587_CPPFLAGS = $(AM_CPPFLAGS) -DLIB587
+lib589_SOURCES = lib589.c $(SUPPORTFILES)
+lib589_CPPFLAGS = $(AM_CPPFLAGS)
+
lib590_SOURCES = lib590.c $(SUPPORTFILES)
lib590_CPPFLAGS = $(AM_CPPFLAGS)
@@ -299,6 +303,15 @@ lib598_CPPFLAGS = $(AM_CPPFLAGS)
lib599_SOURCES = lib599.c $(SUPPORTFILES)
lib599_CPPFLAGS = $(AM_CPPFLAGS)
+lib643_SOURCES = lib643.c $(SUPPORTFILES)
+lib643_CPPFLAGS = $(AM_CPPFLAGS)
+
+lib644_SOURCES = lib643.c $(SUPPORTFILES)
+lib644_CPPFLAGS = $(AM_CPPFLAGS) -DLIB644
+
+lib645_SOURCES = lib643.c $(SUPPORTFILES)
+lib645_CPPFLAGS = $(AM_CPPFLAGS) -DLIB645
+
lib1500_SOURCES = lib1500.c $(SUPPORTFILES) $(TESTUTIL)
lib1500_LDADD = $(TESTUTIL_LIBS)
lib1500_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/tests/libtest/lib589.c b/tests/libtest/lib589.c
new file mode 100644
index 000000000..1e5ebb1e4
--- /dev/null
+++ b/tests/libtest/lib589.c
@@ -0,0 +1,59 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at https://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+#include "test.h"
+
+#include "memdebug.h"
+
+int test(char *URL)
+{
+ CURL *curl;
+ CURLcode res=CURLE_OK;
+
+ if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
+ fprintf(stderr, "curl_global_init() failed\n");
+ return TEST_ERR_MAJOR_BAD;
+ }
+
+ curl = curl_easy_init();
+ if(!curl) {
+ fprintf(stderr, "curl_easy_init() failed\n");
+ curl_global_cleanup();
+ return TEST_ERR_MAJOR_BAD;
+ }
+
+ /* First set the URL that is about to receive our POST. */
+ test_setopt(curl, CURLOPT_URL, URL);
+ test_setopt(curl, CURLOPT_MIMEPOST, NULL);
+ test_setopt(curl, CURLOPT_VERBOSE, 1L); /* show verbose for debug */
+ test_setopt(curl, CURLOPT_HEADER, 1L); /* include header */
+
+ /* Now, we should be making a zero byte POST request */
+ res = curl_easy_perform(curl);
+
+test_cleanup:
+
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+ curl_global_cleanup();
+
+ return (int)res;
+}
diff --git a/tests/libtest/lib643.c b/tests/libtest/lib643.c
new file mode 100644
index 000000000..ea5a96740
--- /dev/null
+++ b/tests/libtest/lib643.c
@@ -0,0 +1,270 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at https://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+#include "test.h"
+
+#include "memdebug.h"
+
+static char data[]=
+#ifdef CURL_DOES_CONVERSIONS
+ /* ASCII representation with escape sequences for non-ASCII platforms */
+ "\x74\x68\x69\x73\x20\x69\x73\x20\x77\x68\x61\x74\x20\x77\x65\x20\x70"
+ "\x6f\x73\x74\x20\x74\x6f\x20\x74\x68\x65\x20\x73\x69\x6c\x6c\x79\x20"
+ "\x77\x65\x62\x20\x73\x65\x72\x76\x65\x72\x0a";
+#else
+ "this is what we post to the silly web server\n";
+#endif
+
+struct WriteThis {
+ char *readptr;
+ size_t sizeleft;
+};
+
+static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userp)
+{
+#ifdef LIB644
+ (void)ptr;
+ (void)size;
+ (void)nmemb;
+ (void)userp;
+ return CURL_READFUNC_ABORT;
+#else
+
+ struct WriteThis *pooh = (struct WriteThis *)userp;
+ int eof = !*pooh->readptr;
+
+ if(size*nmemb < 1)
+ return 0;
+
+#ifndef LIB645
+ eof = !pooh->sizeleft;
+ if(!eof)
+ pooh->sizeleft--;
+#endif
+
+ if(!eof) {
+ *ptr = *pooh->readptr; /* copy one single byte */
+ pooh->readptr++; /* advance pointer */
+ return 1; /* we return 1 byte at a time! */
+ }
+
+ return 0; /* no more data left to deliver */
+#endif
+}
+
+static int once(char *URL, bool oldstyle)
+{
+ CURL *curl;
+ CURLcode res = CURLE_OK;
+
+ curl_mime *mime = NULL;
+ curl_mimepart *part = NULL;
+ struct WriteThis pooh;
+ struct WriteThis pooh2;
+ curl_off_t datasize = -1;
+
+ pooh.readptr = data;
+#ifndef LIB645
+ datasize = strlen(data);
+#endif
+ pooh.sizeleft = datasize;
+
+ curl = curl_easy_init();
+ if(!curl) {
+ fprintf(stderr, "curl_easy_init() failed\n");
+ curl_global_cleanup();
+ return TEST_ERR_MAJOR_BAD;
+ }
+
+ mime = curl_mime_init(curl);
+ if(!mime) {
+ fprintf(stderr, "curl_mime_init() failed\n");
+ curl_easy_cleanup(curl);
+ curl_global_cleanup();
+ return TEST_ERR_MAJOR_BAD;
+ }
+
+ part = curl_mime_addpart(mime);
+ if(!part) {
+ fprintf(stderr, "curl_mime_addpart(1) failed\n");
+ curl_mime_free(mime);
+ curl_easy_cleanup(curl);
+ curl_global_cleanup();
+ return TEST_ERR_MAJOR_BAD;
+ }
+
+ /* Fill in the file upload part */
+ if(oldstyle) {
+ res = curl_mime_name(part, "sendfile", -1);
+ if(!res)
+ res = curl_mime_data_cb(part, datasize, read_callback,
+ NULL, NULL, &pooh);
+ if(!res)
+ res = curl_mime_filename(part, "postit2.c");
+ }
+ else {
+ /* new style */
+ res = curl_mime_name(part, "sendfile alternative", -1);
+ if(!res)
+ res = curl_mime_data_cb(part, datasize, read_callback,
+ NULL, NULL, &pooh);
+ if(!res)
+ res = curl_mime_filename(part, "file name 2");
+ }
+
+ if(res)
+ printf("curl_mime_xxx(1) = %s\n", curl_easy_strerror(res));
+
+ /* Now add the same data with another name and make it not look like
+ a file upload but still using the callback */
+
+ pooh2.readptr = data;
+#ifndef LIB645
+ datasize = strlen(data);
+#endif
+ pooh2.sizeleft = datasize;
+
+ part = curl_mime_addpart(mime);
+ if(!part) {
+ fprintf(stderr, "curl_mime_addpart(2) failed\n");
+ curl_mime_free(mime);
+ curl_easy_cleanup(curl);
+ curl_global_cleanup();
+ return TEST_ERR_MAJOR_BAD;
+ }
+ /* Fill in the file upload part */
+ res = curl_mime_name(part, "callbackdata", -1);
+ if(!res)
+ res = curl_mime_data_cb(part, datasize, read_callback,
+ NULL, NULL, &pooh2);
+
+ if(res)
+ printf("curl_mime_xxx(2) = %s\n", curl_easy_strerror(res));
+
+ part = curl_mime_addpart(mime);
+ if(!part) {
+ fprintf(stderr, "curl_mime_addpart(3) failed\n");
+ curl_mime_free(mime);
+ curl_easy_cleanup(curl);
+ curl_global_cleanup();
+ return TEST_ERR_MAJOR_BAD;
+ }
+
+ /* Fill in the filename field */
+ res = curl_mime_name(part, "filename", -1);
+ if(!res)
+ res = curl_mime_data(part,
+#ifdef CURL_DOES_CONVERSIONS
+ /* ASCII representation with escape
+ sequences for non-ASCII platforms */
+ "\x70\x6f\x73\x74\x69\x74\x32\x2e\x63",
+#else
+ "postit2.c",
+#endif
+ -1);
+
+ if(res)
+ printf("curl_mime_xxx(3) = %s\n", curl_easy_strerror(res));
+
+ /* Fill in a submit field too */
+ part = curl_mime_addpart(mime);
+ if(!part) {
+ fprintf(stderr, "curl_mime_addpart(4) failed\n");
+ curl_mime_free(mime);
+ curl_easy_cleanup(curl);
+ curl_global_cleanup();
+ return TEST_ERR_MAJOR_BAD;
+ }
+ res = curl_mime_name(part, "submit", -1);
+ if(!res)
+ res = curl_mime_data(part,
+#ifdef CURL_DOES_CONVERSIONS
+ /* ASCII representation with escape
+ sequences for non-ASCII platforms */
+ "\x73\x65\x6e\x64",
+#else
+ "send",
+#endif
+ -1);
+
+ if(res)
+ printf("curl_mime_xxx(4) = %s\n", curl_easy_strerror(res));
+
+ part = curl_mime_addpart(mime);
+ if(!part) {
+ fprintf(stderr, "curl_mime_addpart(5) failed\n");
+ curl_mime_free(mime);
+ curl_easy_cleanup(curl);
+ curl_global_cleanup();
+ return TEST_ERR_MAJOR_BAD;
+ }
+ res = curl_mime_name(part, "somename", -1);
+ if(!res)
+ res = curl_mime_filename(part, "somefile.txt");
+ if(!res)
+ res = curl_mime_data(part, "blah blah", 9);
+
+ if(res)
+ printf("curl_mime_xxx(5) = %s\n", curl_easy_strerror(res));
+
+ /* First set the URL that is about to receive our POST. */
+ test_setopt(curl, CURLOPT_URL, URL);
+
+ /* send a multi-part mimepost */
+ test_setopt(curl, CURLOPT_MIMEPOST, mime);
+
+ /* get verbose debug output please */
+ test_setopt(curl, CURLOPT_VERBOSE, 1L);
+
+ /* include headers in the output */
+ test_setopt(curl, CURLOPT_HEADER, 1L);
+
+ /* Perform the request, res will get the return code */
+ res = curl_easy_perform(curl);
+
+test_cleanup:
+
+ /* always cleanup */
+ curl_easy_cleanup(curl);
+
+ /* now cleanup the mimepost structure */
+ curl_mime_free(mime);
+
+ return res;
+}
+
+int test(char *URL)
+{
+ int res;
+
+ if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
+ fprintf(stderr, "curl_global_init() failed\n");
+ return TEST_ERR_MAJOR_BAD;
+ }
+
+ res = once(URL, TRUE); /* old */
+ if(!res)
+ res = once(URL, FALSE); /* new */
+
+ curl_global_cleanup();
+
+ return res;
+}