]> rtime.felk.cvut.cz Git - hornmich/skoda-qr-demo.git/blob - QRScanner/mobile/jni/thirdparty/curl/tests/libtest/first.c
Add MuPDF native source codes
[hornmich/skoda-qr-demo.git] / QRScanner / mobile / jni / thirdparty / curl / tests / libtest / first.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 #ifdef HAVE_LOCALE_H
25 #include <locale.h> /* for setlocale() */
26 #endif
27
28 #ifdef CURLDEBUG
29 #  define MEMDEBUG_NODEFINES
30 #  include "memdebug.h"
31 #endif
32
33 int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc,
34                    struct timeval *tv)
35 {
36   if(nfds < 0) {
37     SET_SOCKERRNO(EINVAL);
38     return -1;
39   }
40 #ifdef USE_WINSOCK
41   /*
42    * Winsock select() requires that at least one of the three fd_set
43    * pointers is not NULL and points to a non-empty fdset. IOW Winsock
44    * select() can not be used to sleep without a single fd_set.
45    */
46   if(!nfds) {
47     Sleep(1000*tv->tv_sec + tv->tv_usec/1000);
48     return 0;
49   }
50 #endif
51   return select(nfds, rd, wr, exc, tv);
52 }
53
54 char *libtest_arg2=NULL;
55 char *libtest_arg3=NULL;
56 int test_argc;
57 char **test_argv;
58
59 struct timeval tv_test_start; /* for test timing */
60
61 #ifdef UNITTESTS
62 int unitfail; /* for unittests */
63 #endif
64
65 #ifdef CURLDEBUG
66 static void memory_tracking_init(void)
67 {
68   char *env;
69   /* if CURL_MEMDEBUG is set, this starts memory tracking message logging */
70   env = curl_getenv("CURL_MEMDEBUG");
71   if(env) {
72     /* use the value as file name */
73     char fname[CURL_MT_LOGFNAME_BUFSIZE];
74     if(strlen(env) >= CURL_MT_LOGFNAME_BUFSIZE)
75       env[CURL_MT_LOGFNAME_BUFSIZE-1] = '\0';
76     strcpy(fname, env);
77     curl_free(env);
78     curl_memdebug(fname);
79     /* this weird stuff here is to make curl_free() get called
80        before curl_memdebug() as otherwise memory tracking will
81        log a free() without an alloc! */
82   }
83   /* if CURL_MEMLIMIT is set, this enables fail-on-alloc-number-N feature */
84   env = curl_getenv("CURL_MEMLIMIT");
85   if(env) {
86     char *endptr;
87     long num = strtol(env, &endptr, 10);
88     if((endptr != env) && (endptr == env + strlen(env)) && (num > 0))
89       curl_memlimit(num);
90     curl_free(env);
91   }
92 }
93 #else
94 #  define memory_tracking_init() Curl_nop_stmt
95 #endif
96
97 int main(int argc, char **argv)
98 {
99   char *URL;
100
101   memory_tracking_init();
102
103   /*
104    * Setup proper locale from environment. This is needed to enable locale-
105    * specific behaviour by the C library in order to test for undesired side
106    * effects that could cause in libcurl.
107    */
108 #ifdef HAVE_SETLOCALE
109   setlocale(LC_ALL, "");
110 #endif
111
112   if(argc< 2 ) {
113     fprintf(stderr, "Pass URL as argument please\n");
114     return 1;
115   }
116
117   test_argc = argc;
118   test_argv = argv;
119
120   if(argc>2)
121     libtest_arg2=argv[2];
122
123   if(argc>3)
124     libtest_arg3=argv[3];
125
126   URL = argv[1]; /* provide this to the rest */
127
128   fprintf(stderr, "URL: %s\n", URL);
129
130   return test(URL);
131 }