• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/curl-7.21.7/tests/libtest/
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
33int select_test (int num_fds, fd_set *rd, fd_set *wr, fd_set *exc,
34                 struct timeval *tv)
35{
36#ifdef USE_WINSOCK
37  /* Winsock doesn't like no socket set in 'rd', 'wr' or 'exc'. This is
38   * case when 'num_fds <= 0. So sleep.
39   */
40  if (num_fds <= 0) {
41    Sleep(1000*tv->tv_sec + tv->tv_usec/1000);
42    return 0;
43  }
44#endif
45  return select(num_fds, rd, wr, exc, tv);
46}
47
48char *libtest_arg2=NULL;
49char *libtest_arg3=NULL;
50int test_argc;
51char **test_argv;
52
53#ifdef UNITTESTS
54int unitfail; /* for unittests */
55#endif
56
57int main(int argc, char **argv)
58{
59  char *URL;
60
61#ifdef CURLDEBUG
62  /* this sends all memory debug messages to a logfile named memdump */
63  char *env = curl_getenv("CURL_MEMDEBUG");
64  if(env) {
65    /* use the value as file name */
66    char *s = strdup(env);
67    curl_free(env);
68    curl_memdebug(s);
69    free(s);
70    /* this weird strdup() and stuff here is to make the curl_free() get
71       called before the memdebug() as otherwise the memdebug tracing will
72       with tracing a free() without an alloc! */
73  }
74  /* this enables the fail-on-alloc-number-N functionality */
75  env = curl_getenv("CURL_MEMLIMIT");
76  if(env) {
77    char *endptr;
78    long num = strtol(env, &endptr, 10);
79    if((endptr != env) && (endptr == env + strlen(env)) && (num > 0))
80      curl_memlimit(num);
81    curl_free(env);
82  }
83#endif
84
85  /*
86   * Setup proper locale from environment. This is needed to enable locale-
87   * specific behaviour by the C library in order to test for undesired side
88   * effects that could cause in libcurl.
89   */
90#ifdef HAVE_SETLOCALE
91  setlocale(LC_ALL, "");
92#endif
93
94  if(argc< 2 ) {
95    fprintf(stderr, "Pass URL as argument please\n");
96    return 1;
97  }
98
99  test_argc = argc;
100  test_argv = argv;
101
102  if(argc>2)
103    libtest_arg2=argv[2];
104
105  if(argc>3)
106    libtest_arg3=argv[3];
107
108  URL = argv[1]; /* provide this to the rest */
109
110  fprintf(stderr, "URL: %s\n", URL);
111
112  return test(URL);
113}
114