]> rtime.felk.cvut.cz Git - hornmich/skoda-qr-demo.git/blob - QRScanner/mobile/jni/thirdparty/curl/tests/libtest/lib586.c
Add MuPDF native source codes
[hornmich/skoda-qr-demo.git] / QRScanner / mobile / jni / thirdparty / curl / tests / libtest / lib586.c
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2011, 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 http://curl.haxx.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  ***************************************************************************/
22 #include "test.h"
23
24 #include <curl/mprintf.h>
25
26 #include "memdebug.h"
27
28 #define THREADS 2
29
30 /* struct containing data of a thread */
31 struct Tdata {
32   CURLSH *share;
33   char *url;
34 };
35
36 struct userdata {
37   char *text;
38   int counter;
39 };
40
41 /* lock callback */
42 static void my_lock(CURL *handle, curl_lock_data data, curl_lock_access laccess,
43           void *useptr )
44 {
45   const char *what;
46   struct userdata *user = (struct userdata *)useptr;
47
48   (void)handle;
49   (void)laccess;
50
51   switch ( data ) {
52     case CURL_LOCK_DATA_SHARE:
53       what = "share";
54       break;
55     case CURL_LOCK_DATA_DNS:
56       what = "dns";
57       break;
58     case CURL_LOCK_DATA_COOKIE:
59       what = "cookie";
60       break;
61     case CURL_LOCK_DATA_SSL_SESSION:
62       what = "ssl_session";
63       break;
64     default:
65       fprintf(stderr, "lock: no such data: %d\n", (int)data);
66       return;
67   }
68   printf("lock:   %-6s [%s]: %d\n", what, user->text, user->counter);
69   user->counter++;
70 }
71
72 /* unlock callback */
73 static void my_unlock(CURL *handle, curl_lock_data data, void *useptr )
74 {
75   const char *what;
76   struct userdata *user = (struct userdata *)useptr;
77   (void)handle;
78   switch ( data ) {
79     case CURL_LOCK_DATA_SHARE:
80       what = "share";
81       break;
82     case CURL_LOCK_DATA_DNS:
83       what = "dns";
84       break;
85     case CURL_LOCK_DATA_COOKIE:
86       what = "cookie";
87       break;
88     case CURL_LOCK_DATA_SSL_SESSION:
89       what = "ssl_session";
90       break;
91     default:
92       fprintf(stderr, "unlock: no such data: %d\n", (int)data);
93       return;
94   }
95   printf("unlock: %-6s [%s]: %d\n", what, user->text, user->counter);
96   user->counter++;
97 }
98
99 /* the dummy thread function */
100 static void *fire(void *ptr)
101 {
102   CURLcode code;
103   struct Tdata *tdata = (struct Tdata*)ptr;
104   CURL *curl;
105   int i=0;
106
107   if ((curl = curl_easy_init()) == NULL) {
108     fprintf(stderr, "curl_easy_init() failed\n");
109     return NULL;
110   }
111
112   curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
113   curl_easy_setopt(curl, CURLOPT_VERBOSE,    1L);
114   curl_easy_setopt(curl, CURLOPT_URL,        tdata->url);
115   printf( "CURLOPT_SHARE\n" );
116   curl_easy_setopt(curl, CURLOPT_SHARE, tdata->share);
117
118   printf( "PERFORM\n" );
119   code = curl_easy_perform(curl);
120   if( code != CURLE_OK ) {
121     fprintf(stderr, "perform url '%s' repeat %d failed, curlcode %d\n",
122             tdata->url, i, (int)code);
123   }
124
125   printf( "CLEANUP\n" );
126   curl_easy_cleanup(curl);
127
128   return NULL;
129 }
130
131 /* test function */
132 int test(char *URL)
133 {
134   int res;
135   CURLSHcode scode = CURLSHE_OK;
136   char *url;
137   struct Tdata tdata;
138   CURL *curl;
139   CURLSH *share;
140   int i;
141   struct userdata user;
142
143   user.text = (char *)"Pigs in space";
144   user.counter = 0;
145
146   printf( "GLOBAL_INIT\n" );
147   if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
148     fprintf(stderr, "curl_global_init() failed\n");
149     return TEST_ERR_MAJOR_BAD;
150   }
151
152   /* prepare share */
153   printf( "SHARE_INIT\n" );
154   if ((share = curl_share_init()) == NULL) {
155     fprintf(stderr, "curl_share_init() failed\n");
156     curl_global_cleanup();
157     return TEST_ERR_MAJOR_BAD;
158   }
159
160   if ( CURLSHE_OK == scode ) {
161     printf( "CURLSHOPT_LOCKFUNC\n" );
162     scode = curl_share_setopt( share, CURLSHOPT_LOCKFUNC, my_lock);
163   }
164   if ( CURLSHE_OK == scode ) {
165     printf( "CURLSHOPT_UNLOCKFUNC\n" );
166     scode = curl_share_setopt( share, CURLSHOPT_UNLOCKFUNC, my_unlock);
167   }
168   if ( CURLSHE_OK == scode ) {
169     printf( "CURLSHOPT_USERDATA\n" );
170     scode = curl_share_setopt( share, CURLSHOPT_USERDATA, &user);
171   }
172   if ( CURLSHE_OK == scode ) {
173     printf( "CURL_LOCK_DATA_SSL_SESSION\n" );
174     scode = curl_share_setopt( share, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
175   }
176
177   if ( CURLSHE_OK != scode ) {
178     fprintf(stderr, "curl_share_setopt() failed\n");
179     curl_share_cleanup(share);
180     curl_global_cleanup();
181     return TEST_ERR_MAJOR_BAD;
182   }
183
184
185   res = 0;
186
187   /* start treads */
188   for (i=1; i<=THREADS; i++ ) {
189
190     /* set thread data */
191     tdata.url   = URL;
192     tdata.share = share;
193
194     /* simulate thread, direct call of "thread" function */
195     printf( "*** run %d\n",i );
196     fire( &tdata );
197   }
198
199
200   /* fetch a another one */
201   printf( "*** run %d\n", i );
202   if ((curl = curl_easy_init()) == NULL) {
203     fprintf(stderr, "curl_easy_init() failed\n");
204     curl_share_cleanup(share);
205     curl_global_cleanup();
206     return TEST_ERR_MAJOR_BAD;
207   }
208
209   url = URL;
210   test_setopt( curl, CURLOPT_URL,        url );
211   printf( "CURLOPT_SHARE\n" );
212   test_setopt( curl, CURLOPT_SHARE,      share );
213
214   printf( "PERFORM\n" );
215   curl_easy_perform( curl );
216
217   /* try to free share, expect to fail because share is in use*/
218   printf( "try SHARE_CLEANUP...\n" );
219   scode = curl_share_cleanup( share );
220   if ( scode==CURLSHE_OK )
221   {
222     fprintf(stderr, "curl_share_cleanup succeed but error expected\n");
223     share = NULL;
224   } else {
225     printf( "SHARE_CLEANUP failed, correct\n" );
226   }
227
228 test_cleanup:
229
230   /* clean up last handle */
231   printf( "CLEANUP\n" );
232   curl_easy_cleanup( curl );
233
234   /* free share */
235   printf( "SHARE_CLEANUP\n" );
236   scode = curl_share_cleanup( share );
237   if ( scode!=CURLSHE_OK )
238     fprintf(stderr, "curl_share_cleanup failed, code errno %d\n",
239             (int)scode);
240
241   printf( "GLOBAL_CLEANUP\n" );
242   curl_global_cleanup();
243
244   return res;
245 }
246