xref: /third_party/curl/tests/libtest/lib583.c (revision 13498266)
1/***************************************************************************
2 *                                  _   _ ____  _
3 *  Project                     ___| | | |  _ \| |
4 *                             / __| | | | |_) | |
5 *                            | (__| |_| |  _ <| |___
6 *                             \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24/*
25 * This test case is based on the sample code provided by Saqib Ali
26 * https://curl.se/mail/lib-2011-03/0066.html
27 */
28
29#include "test.h"
30
31#include <sys/stat.h>
32
33#include "memdebug.h"
34
35int test(char *URL)
36{
37  int stillRunning;
38  CURLM *multiHandle = NULL;
39  CURL *curl = NULL;
40  CURLcode res = CURLE_OK;
41  CURLMcode mres;
42
43  assert(test_argc >= 4);
44
45  global_init(CURL_GLOBAL_ALL);
46
47  multi_init(multiHandle);
48
49  easy_init(curl);
50
51  easy_setopt(curl, CURLOPT_USERPWD, libtest_arg2);
52  easy_setopt(curl, CURLOPT_SSH_PUBLIC_KEYFILE,  test_argv[3]);
53  easy_setopt(curl, CURLOPT_SSH_PRIVATE_KEYFILE, test_argv[4]);
54
55  easy_setopt(curl, CURLOPT_UPLOAD, 1L);
56  easy_setopt(curl, CURLOPT_VERBOSE, 1L);
57
58  easy_setopt(curl, CURLOPT_URL, URL);
59  easy_setopt(curl, CURLOPT_INFILESIZE, (long)5);
60
61  multi_add_handle(multiHandle, curl);
62
63  /* this tests if removing an easy handle immediately after multi
64     perform has been called succeeds or not. */
65
66  fprintf(stderr, "curl_multi_perform()...\n");
67
68  multi_perform(multiHandle, &stillRunning);
69
70  fprintf(stderr, "curl_multi_perform() succeeded\n");
71
72  fprintf(stderr, "curl_multi_remove_handle()...\n");
73  mres = curl_multi_remove_handle(multiHandle, curl);
74  if(mres) {
75    fprintf(stderr, "curl_multi_remove_handle() failed, "
76            "with code %d\n", (int)mres);
77    res = TEST_ERR_MULTI;
78  }
79  else
80    fprintf(stderr, "curl_multi_remove_handle() succeeded\n");
81
82test_cleanup:
83
84  /* undocumented cleanup sequence - type UB */
85
86  curl_easy_cleanup(curl);
87  curl_multi_cleanup(multiHandle);
88  curl_global_cleanup();
89
90  return (int)res;
91}
92