10e552da7Schristos /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
20e552da7Schristos *
30e552da7Schristos * Permission is hereby granted, free of charge, to any person obtaining a copy
40e552da7Schristos * of this software and associated documentation files (the "Software"), to
50e552da7Schristos * deal in the Software without restriction, including without limitation the
60e552da7Schristos * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
70e552da7Schristos * sell copies of the Software, and to permit persons to whom the Software is
80e552da7Schristos * furnished to do so, subject to the following conditions:
90e552da7Schristos *
100e552da7Schristos * The above copyright notice and this permission notice shall be included in
110e552da7Schristos * all copies or substantial portions of the Software.
120e552da7Schristos *
130e552da7Schristos * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
140e552da7Schristos * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
150e552da7Schristos * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
160e552da7Schristos * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
170e552da7Schristos * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
180e552da7Schristos * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
190e552da7Schristos * IN THE SOFTWARE.
200e552da7Schristos */
210e552da7Schristos
220e552da7Schristos #include "uv.h"
230e552da7Schristos #include "task.h"
240e552da7Schristos #include <stdio.h>
250e552da7Schristos #include <stdlib.h>
260e552da7Schristos
270e552da7Schristos
280e552da7Schristos #ifdef _WIN32
290e552da7Schristos # define BAD_PIPENAME "bad-pipe"
300e552da7Schristos #else
310e552da7Schristos # define BAD_PIPENAME "/path/to/unix/socket/that/really/should/not/be/there"
320e552da7Schristos #endif
330e552da7Schristos
340e552da7Schristos
350e552da7Schristos static int close_cb_called = 0;
360e552da7Schristos static int connect_cb_called = 0;
370e552da7Schristos
380e552da7Schristos
close_cb(uv_handle_t * handle)390e552da7Schristos static void close_cb(uv_handle_t* handle) {
40*5f2f4271Schristos ASSERT_NOT_NULL(handle);
410e552da7Schristos close_cb_called++;
420e552da7Schristos }
430e552da7Schristos
440e552da7Schristos
connect_cb(uv_connect_t * connect_req,int status)450e552da7Schristos static void connect_cb(uv_connect_t* connect_req, int status) {
460e552da7Schristos ASSERT(status == UV_ENOENT);
470e552da7Schristos uv_close((uv_handle_t*)connect_req->handle, close_cb);
480e552da7Schristos connect_cb_called++;
490e552da7Schristos }
500e552da7Schristos
510e552da7Schristos
connect_cb_file(uv_connect_t * connect_req,int status)520e552da7Schristos static void connect_cb_file(uv_connect_t* connect_req, int status) {
530e552da7Schristos ASSERT(status == UV_ENOTSOCK || status == UV_ECONNREFUSED);
540e552da7Schristos uv_close((uv_handle_t*)connect_req->handle, close_cb);
550e552da7Schristos connect_cb_called++;
560e552da7Schristos }
570e552da7Schristos
580e552da7Schristos
TEST_IMPL(pipe_connect_bad_name)590e552da7Schristos TEST_IMPL(pipe_connect_bad_name) {
600e552da7Schristos uv_pipe_t client;
610e552da7Schristos uv_connect_t req;
620e552da7Schristos int r;
630e552da7Schristos
640e552da7Schristos r = uv_pipe_init(uv_default_loop(), &client, 0);
650e552da7Schristos ASSERT(r == 0);
660e552da7Schristos uv_pipe_connect(&req, &client, BAD_PIPENAME, connect_cb);
670e552da7Schristos
680e552da7Schristos uv_run(uv_default_loop(), UV_RUN_DEFAULT);
690e552da7Schristos
700e552da7Schristos ASSERT(close_cb_called == 1);
710e552da7Schristos ASSERT(connect_cb_called == 1);
720e552da7Schristos
730e552da7Schristos MAKE_VALGRIND_HAPPY();
740e552da7Schristos return 0;
750e552da7Schristos }
760e552da7Schristos
770e552da7Schristos
TEST_IMPL(pipe_connect_to_file)780e552da7Schristos TEST_IMPL(pipe_connect_to_file) {
790e552da7Schristos const char* path = "test/fixtures/empty_file";
800e552da7Schristos uv_pipe_t client;
810e552da7Schristos uv_connect_t req;
820e552da7Schristos int r;
830e552da7Schristos
840e552da7Schristos r = uv_pipe_init(uv_default_loop(), &client, 0);
850e552da7Schristos ASSERT(r == 0);
860e552da7Schristos uv_pipe_connect(&req, &client, path, connect_cb_file);
870e552da7Schristos
880e552da7Schristos uv_run(uv_default_loop(), UV_RUN_DEFAULT);
890e552da7Schristos
900e552da7Schristos ASSERT(close_cb_called == 1);
910e552da7Schristos ASSERT(connect_cb_called == 1);
920e552da7Schristos
930e552da7Schristos MAKE_VALGRIND_HAPPY();
940e552da7Schristos return 0;
950e552da7Schristos }
96