~ubuntu-branches/ubuntu/vivid/curl/vivid

« back to all changes in this revision

Viewing changes to tests/libtest/lib558.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Schuldei
  • Date: 2009-04-02 23:35:45 UTC
  • mto: (1.2.1 upstream) (3.2.3 sid)
  • mto: This revision was merged to the branch mainline in revision 38.
  • Revision ID: james.westby@ubuntu.com-20090402233545-geixkwhe3izccjt7
Tags: upstream-7.19.4
ImportĀ upstreamĀ versionĀ 7.19.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 *                                  _   _ ____  _
 
3
 *  Project                     ___| | | |  _ \| |
 
4
 *                             / __| | | | |_) | |
 
5
 *                            | (__| |_| |  _ <| |___
 
6
 *                             \___|\___/|_| \_\_____|
 
7
 *
 
8
 * $Id: lib558.c,v 1.9 2008-11-07 12:22:43 yangtse Exp $
 
9
 */
 
10
 
 
11
#include "test.h"
 
12
 
 
13
#ifdef HAVE_SYS_SOCKET_H
 
14
#  include <sys/socket.h>
 
15
#endif
 
16
#ifdef HAVE_NETINET_IN_H
 
17
#  include <netinet/in.h>
 
18
#endif
 
19
#ifdef HAVE_NETDB_H
 
20
#  include <netdb.h>
 
21
#endif
 
22
#ifdef HAVE_ARPA_INET_H
 
23
#  include <arpa/inet.h>
 
24
#endif
 
25
 
 
26
#define ENABLE_CURLX_PRINTF
 
27
#include "curlx.h"
 
28
 
 
29
#include "hash.h"
 
30
#include "hostip.h"
 
31
 
 
32
#include "memory.h"
 
33
#include "memdebug.h"
 
34
 
 
35
/* This source file is used for test # 558 and 559 */
 
36
 
 
37
/*
 
38
 * This hacky test bypasses the library external API,
 
39
 * using internal only libcurl functions. So don't be
 
40
 * surprised if we cannot run it when the library has
 
41
 * been built with hidden symbols, exporting only the
 
42
 * ones in the public API.
 
43
 */
 
44
 
 
45
 
 
46
#if !defined(CURL_HIDDEN_SYMBOLS)
 
47
 
 
48
#ifdef LIB559
 
49
static Curl_addrinfo *fake_ai(void)
 
50
{
 
51
  Curl_addrinfo *ai;
 
52
  int ss_size;
 
53
 
 
54
  ss_size = sizeof (struct sockaddr_in);
 
55
 
 
56
  if((ai = calloc(1, sizeof(Curl_addrinfo))) == NULL)
 
57
    return NULL;
 
58
 
 
59
  if((ai->ai_canonname = strdup("dummy")) == NULL) {
 
60
    free(ai);
 
61
    return NULL;
 
62
  }
 
63
 
 
64
  if((ai->ai_addr = calloc(1, ss_size)) == NULL) {
 
65
    free(ai->ai_canonname);
 
66
    free(ai);
 
67
    return NULL;
 
68
  }
 
69
 
 
70
  ai->ai_family = AF_INET;
 
71
  ai->ai_addrlen = ss_size;
 
72
 
 
73
  return ai;
 
74
}
 
75
#endif /* LIB559 */
 
76
 
 
77
 
 
78
int test(char *URL)
 
79
{
 
80
  CURL *easyh = NULL;
 
81
  struct curl_hash *hp = NULL;
 
82
  int result = 0;
 
83
 
 
84
  if(!strcmp(URL, "check")) {
 
85
    /* test harness script verifying if this test can run */
 
86
    return 0; /* sure, run this! */
 
87
  }
 
88
 
 
89
  easyh = curl_easy_init();
 
90
  if(!easyh) {
 
91
    fprintf(stdout, "easy handle init failed\n");
 
92
    result = TEST_ERR_MAJOR_BAD;
 
93
    goto cleanup;
 
94
  }
 
95
  fprintf(stdout, "easy handle init OK\n");
 
96
 
 
97
  fprintf(stdout, "creating hash...\n");
 
98
  hp = Curl_mk_dnscache();
 
99
  if(!hp) {
 
100
    fprintf(stdout, "hash creation failed\n");
 
101
    result = TEST_ERR_MAJOR_BAD;
 
102
    goto cleanup;
 
103
  }
 
104
  fprintf(stdout, "hash creation OK\n");
 
105
 
 
106
  /**/
 
107
#ifdef LIB559
 
108
  {
 
109
    char *data_key;
 
110
    struct Curl_dns_entry *data_node;
 
111
    struct Curl_dns_entry *nodep;
 
112
    size_t key_len;
 
113
 
 
114
    data_key = aprintf("%s:%d", "dummy", 0);
 
115
    if(!data_key) {
 
116
      fprintf(stdout, "data key creation failed\n");
 
117
      result = TEST_ERR_MAJOR_BAD;
 
118
      goto cleanup;
 
119
    }
 
120
    key_len = strlen(data_key);
 
121
 
 
122
    data_node = calloc(1, sizeof(struct Curl_dns_entry));
 
123
    if(!data_node) {
 
124
      fprintf(stdout, "data node creation failed\n");
 
125
      result = TEST_ERR_MAJOR_BAD;
 
126
      free(data_key);
 
127
      goto cleanup;
 
128
    }
 
129
 
 
130
    data_node->addr = fake_ai();
 
131
    if(!data_node->addr) {
 
132
      fprintf(stdout, "actual data creation failed\n");
 
133
      result = TEST_ERR_MAJOR_BAD;
 
134
      free(data_node);
 
135
      free(data_key);
 
136
      goto cleanup;
 
137
    }
 
138
 
 
139
    nodep = Curl_hash_add(hp, data_key, key_len+1, (void *)data_node);
 
140
    if(!nodep) {
 
141
      fprintf(stdout, "insertion into hash failed\n");
 
142
      result = TEST_ERR_MAJOR_BAD;
 
143
      Curl_freeaddrinfo(data_node->addr);
 
144
      free(data_node);
 
145
      free(data_key);
 
146
      goto cleanup;
 
147
    }
 
148
 
 
149
    free(data_key);
 
150
  }
 
151
#endif /* LIB559 */
 
152
  /**/
 
153
 
 
154
cleanup:
 
155
 
 
156
  fprintf(stdout, "destroying hash...\n");
 
157
  Curl_hash_destroy(hp);
 
158
  fprintf(stdout, "hash destruction OK\n");
 
159
 
 
160
  fprintf(stdout, "destroying easy handle...\n");
 
161
  curl_easy_cleanup(easyh);
 
162
  fprintf(stdout, "easy handle destruction OK\n");
 
163
 
 
164
  curl_global_cleanup();
 
165
 
 
166
  return result;
 
167
}
 
168
 
 
169
 
 
170
#else /* !defined(CURL_HIDDEN_SYMBOLS) */
 
171
 
 
172
 
 
173
int test(char *URL)
 
174
{
 
175
  (void)URL;
 
176
  fprintf(stdout, "libcurl built with hidden symbols");
 
177
  return 1; /* skip test */
 
178
}
 
179
 
 
180
 
 
181
#endif /* !defined(CURL_HIDDEN_SYMBOLS) */