1 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to
5 * deal in the Software without restriction, including without limitation the
6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 * sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 * IN THE SOFTWARE.
20 */
21
22 #include "uv.h"
23 #include "task.h"
24 #include <stdlib.h>
25
26 #define CONCURRENT_COUNT 10
27
28 static int fail_cb_called;
29
30
getaddrinfo_fail_cb(uv_getaddrinfo_t * req,int status,struct addrinfo * res)31 static void getaddrinfo_fail_cb(uv_getaddrinfo_t* req,
32 int status,
33 struct addrinfo* res) {
34
35 ASSERT(fail_cb_called == 0);
36 ASSERT(status < 0);
37 ASSERT_NULL(res);
38 uv_freeaddrinfo(res); /* Should not crash. */
39 fail_cb_called++;
40 }
41
42
TEST_IMPL(getaddrinfo_fail)43 TEST_IMPL(getaddrinfo_fail) {
44 /* TODO(gengjiawen): Fix test on QEMU. */
45 #if defined(__QEMU__)
46 RETURN_SKIP("Test does not currently work in QEMU");
47 #endif
48
49 uv_getaddrinfo_t req;
50
51 ASSERT(UV_EINVAL == uv_getaddrinfo(uv_default_loop(),
52 &req,
53 (uv_getaddrinfo_cb) abort,
54 NULL,
55 NULL,
56 NULL));
57
58 /* Use a FQDN by ending in a period */
59 ASSERT(0 == uv_getaddrinfo(uv_default_loop(),
60 &req,
61 getaddrinfo_fail_cb,
62 "example.invalid.",
63 NULL,
64 NULL));
65 ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT));
66 ASSERT(fail_cb_called == 1);
67
68 MAKE_VALGRIND_HAPPY();
69 return 0;
70 }
71
72
TEST_IMPL(getaddrinfo_fail_sync)73 TEST_IMPL(getaddrinfo_fail_sync) {
74 /* TODO(gengjiawen): Fix test on QEMU. */
75 #if defined(__QEMU__)
76 RETURN_SKIP("Test does not currently work in QEMU");
77 #endif
78 uv_getaddrinfo_t req;
79
80 /* Use a FQDN by ending in a period */
81 ASSERT(0 > uv_getaddrinfo(uv_default_loop(),
82 &req,
83 NULL,
84 "example.invalid.",
85 NULL,
86 NULL));
87 uv_freeaddrinfo(req.addrinfo);
88
89 MAKE_VALGRIND_HAPPY();
90 return 0;
91 }
92
93