Blame tests/gtest/tcp/tcp_send.cc

Packit Service aa3af4
/*
Packit Service aa3af4
 * Copyright (c) 2001-2020 Mellanox Technologies, Ltd. All rights reserved.
Packit Service aa3af4
 *
Packit Service aa3af4
 * This software is available to you under a choice of one of two
Packit Service aa3af4
 * licenses.  You may choose to be licensed under the terms of the GNU
Packit Service aa3af4
 * General Public License (GPL) Version 2, available from the file
Packit Service aa3af4
 * COPYING in the main directory of this source tree, or the
Packit Service aa3af4
 * BSD license below:
Packit Service aa3af4
 *
Packit Service aa3af4
 *     Redistribution and use in source and binary forms, with or
Packit Service aa3af4
 *     without modification, are permitted provided that the following
Packit Service aa3af4
 *     conditions are met:
Packit Service aa3af4
 *
Packit Service aa3af4
 *      - Redistributions of source code must retain the above
Packit Service aa3af4
 *        copyright notice, this list of conditions and the following
Packit Service aa3af4
 *        disclaimer.
Packit Service aa3af4
 *
Packit Service aa3af4
 *      - Redistributions in binary form must reproduce the above
Packit Service aa3af4
 *        copyright notice, this list of conditions and the following
Packit Service aa3af4
 *        disclaimer in the documentation and/or other materials
Packit Service aa3af4
 *        provided with the distribution.
Packit Service aa3af4
 *
Packit Service aa3af4
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit Service aa3af4
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit Service aa3af4
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Packit Service aa3af4
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
Packit Service aa3af4
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
Packit Service aa3af4
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit Service aa3af4
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Packit Service aa3af4
 * SOFTWARE.
Packit Service aa3af4
 */
Packit Service aa3af4
Packit Service aa3af4
#include "common/def.h"
Packit Service aa3af4
#include "common/log.h"
Packit Service aa3af4
#include "common/sys.h"
Packit Service aa3af4
#include "common/base.h"
Packit Service aa3af4
Packit Service aa3af4
#include "tcp_base.h"
Packit Service aa3af4
Packit Service aa3af4
Packit Service aa3af4
class tcp_send : public tcp_base {};
Packit Service aa3af4
Packit Service aa3af4
/**
Packit Service aa3af4
 * @test tcp_send.ti_1
Packit Service aa3af4
 * @brief
Packit Service aa3af4
 *    send() invalid socket fd
Packit Service aa3af4
 * @details
Packit Service aa3af4
 */
Packit Service aa3af4
TEST_F(tcp_send, ti_1) {
Packit Service aa3af4
	int rc = EOK;
Packit Service aa3af4
	int fd;
Packit Service aa3af4
	char buf[] = "hello";
Packit Service aa3af4
Packit Service aa3af4
	fd = tcp_base::sock_create();
Packit Service aa3af4
	ASSERT_LE(0, fd);
Packit Service aa3af4
Packit Service aa3af4
	errno = EOK;
Packit Service aa3af4
	rc = bind(fd, (struct sockaddr *)&client_addr, sizeof(client_addr));
Packit Service aa3af4
	EXPECT_EQ(EOK, errno);
Packit Service aa3af4
	EXPECT_EQ(0, rc);
Packit Service aa3af4
Packit Service aa3af4
	errno = EOK;
Packit Service aa3af4
	rc = send(0xFF, (void *)buf, sizeof(buf), 0);
Packit Service aa3af4
	EXPECT_EQ(EBADF, errno);
Packit Service aa3af4
	EXPECT_EQ(-1, rc);
Packit Service aa3af4
Packit Service aa3af4
	close(fd);
Packit Service aa3af4
}
Packit Service aa3af4
Packit Service aa3af4
/**
Packit Service aa3af4
 * @test tcp_send.ti_2
Packit Service aa3af4
 * @brief
Packit Service aa3af4
 *    send() no connection
Packit Service aa3af4
 * @details
Packit Service aa3af4
 */
Packit Service aa3af4
TEST_F(tcp_send, ti_2) {
Packit Service aa3af4
	int rc = EOK;
Packit Service aa3af4
	int fd;
Packit Service aa3af4
	char buf[] = "hello";
Packit Service aa3af4
Packit Service aa3af4
	fd = tcp_base::sock_create();
Packit Service aa3af4
	ASSERT_LE(0, fd);
Packit Service aa3af4
Packit Service aa3af4
	errno = EOK;
Packit Service aa3af4
	rc = bind(fd, (struct sockaddr *)&client_addr, sizeof(client_addr));
Packit Service aa3af4
	EXPECT_EQ(EOK, errno);
Packit Service aa3af4
	EXPECT_EQ(0, rc);
Packit Service aa3af4
Packit Service aa3af4
	errno = EOK;
Packit Service aa3af4
	(void)signal(SIGPIPE, SIG_IGN);
Packit Service aa3af4
	rc = send(fd, (void *)buf, sizeof(buf), 0);
Packit Service aa3af4
	EXPECT_EQ(EPIPE, errno);
Packit Service aa3af4
	EXPECT_EQ(-1, rc);
Packit Service aa3af4
	(void)signal(SIGPIPE, SIG_DFL);
Packit Service aa3af4
Packit Service aa3af4
	close(fd);
Packit Service aa3af4
}