+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "muse_server_private.h"
-#include "muse_gtest_socket.h"
-
-struct sockaddr_un addr;
-const char *UDS_files[MUSE_CHANNEL_MAX] = {GTEST_MUSE_SOCK_FILE0, GTEST_MUSE_SOCK_FILE1};
-
-static int _server_open(muse_channel_e channel);
-static int _client_open(muse_channel_e channel);
-static gboolean _connect(int fd);
-static int _accept(int fd);
-static gboolean _client_close(int fd);
-static gboolean _server_close(int fd);
-
-static int _server_open(muse_channel_e channel)
-{
- int fd;
- socklen_t address_len;
-
- if (channel >= MUSE_CHANNEL_MAX)
- return MM_ERROR_INVALID_ARGUMENT;
-
- unlink(UDS_files[channel]);
-
- /* create socket */
- fd = socket(AF_UNIX, SOCK_STREAM, 0); /* Unix Domain Socket */
- if (!muse_core_fd_is_valid(fd)) {
- LOGE("socket failed sock");
- return MUSE_ERR;
- }
-
- LOGD("gtest muse server fd : %d", fd);
-
- memset(&addr, 0, sizeof(addr));
- addr.sun_family = AF_UNIX;
- strncpy(addr.sun_path, UDS_files[channel], sizeof(addr.sun_path) - 1);
- address_len = sizeof(addr);
-
- /* bind to filename */
- if (bind(fd, (struct sockaddr *)&addr, address_len) < 0) {
- LOGE("socket bind failed");
- if (errno == EADDRINUSE)
- unlink(addr.sun_path);
- close(fd);
- return MUSE_ERR;
- }
-
- /* setup listen queue */
- if (listen(fd, 5) == MUSE_ERR) {
- LOGE("listen failed");
- close(fd);
- return MUSE_ERR;
- }
-
- if (muse_core_set_nonblocking(fd, false) < 0) /* blocking */
- LOGE("failed to set server socket to blocking");
-
- return fd;
-}
-
-static int _client_open(muse_channel_e channel)
-{
- int sock_fd;
-
- LOGI("Enter");
- muse_return_val_if_fail(channel < MUSE_CHANNEL_MAX, MM_ERROR_INVALID_ARGUMENT);
-
- /* create socket */
- sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
- if (!muse_core_fd_is_valid(sock_fd)) {
- LOGE("[socket failure] %d socket", errno);
- return MUSE_ERR;
- }
- LOGD("gtest muse client fd : %d", sock_fd);
-
- if (fcntl(sock_fd, F_SETFD, FD_CLOEXEC) < 0) {
- LOGE("unable to set on ctrl socket fd %d", sock_fd);
- close(sock_fd);
- return MUSE_ERR;
- }
- LOGD("fcntl");
-
- if (muse_core_set_nonblocking(sock_fd, false) != MM_ERROR_NONE) {
- LOGE("Error - fd (%d) set blocking", sock_fd);
- close(sock_fd);
- return MUSE_ERR;
- }
-
- LOGI("Leave");
-
- return sock_fd;
-}
-
-static gboolean _connect(int fd)
-{
- int ret = MUSE_ERR;
-
- LOGI("Enter");
-
- ret = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
- if (ret < 0) {
- LOGE("[Critical Error : %d] connect failure", errno);
- close(fd);
- return FALSE;
- }
-
- close(fd);
-
- LOGI("Leave");
-
- return TRUE;
-}
-
-static int _accept(int fd)
-{
- int client_sockfd;
- socklen_t len = sizeof(addr);
-
- client_sockfd = accept(fd, (struct sockaddr *)&addr, &len);
- LOGD("gtest muse client fd : %d", client_sockfd);
-
- return client_sockfd;
-}
-
-static gboolean _client_close(int fd)
-{
- if (shutdown(fd, SHUT_RDWR) == MUSE_ERR) {
- LOGE("[%d] failed to shutdown [error %d]", fd, errno);
- return FALSE;
- }
-
- if (close(fd) == MUSE_ERR) {
- LOGE("[%d] failed to close [error %d]", fd, errno);
- return FALSE;
- }
-
- return TRUE;
-}
-
-static gboolean _server_close(int fd)
-{
- if (close(fd) == MUSE_ERR) {
- LOGE("[%d] failed to close [error %d]", fd, errno);
- return FALSE;
- }
-
- return TRUE;
-}
-
-bool muse_gtest_socket(muse_channel_e channel)
-{
- int server_sockfd, client_sockfd;
-
- server_sockfd = _server_open(channel);
- if (!muse_core_fd_is_valid(server_sockfd)) {
- LOGE("server open failed");
- return false;
- }
-
- client_sockfd = _client_open(channel);
- if (!muse_core_fd_is_valid(client_sockfd)) {
- LOGE("client open failed");
- return false;
- }
-
- if (!_connect(client_sockfd)) {
- LOGE("fail to connect");
- return false;
- }
-
- client_sockfd = _accept(server_sockfd);
- if (!muse_core_fd_is_valid(client_sockfd)) {
- LOGE("fail to accept");
- return false;
- }
-
- if (!_client_close(client_sockfd)) {
- LOGE("client close failed");
- return false;
- }
-
- if (!_server_close(server_sockfd)) {
- LOGE("server close failed");
- return false;
- }
-
- unlink(UDS_files[channel]);
-
- return true;
-}
*/
#include "muse_gtest_json.h"
-#include "muse_gtest_socket.h"
using ::testing::InitGoogleTest;
using ::testing::Test;
EXPECT_EQ(ret, FALSE);
}
-TEST(MusedTest, muse_gtest_socket_p)
+TEST(MusedTest, muse_client_new_p)
{
- gboolean ret;
+ int client_sockfd = muse_client_new();
+ ASSERT_TRUE(muse_core_fd_is_valid(client_sockfd));
- ret = muse_gtest_socket(MUSE_CHANNEL_MSG);
- EXPECT_EQ(ret, TRUE);
+ EXPECT_EQ(muse_client_close(client_sockfd), MM_ERROR_NONE);
}
-TEST(MusedTest, muse_gtest_socket_n)
-{
- gboolean ret;
-
- ret = muse_gtest_socket(MUSE_CHANNEL_MAX);
- EXPECT_EQ(ret, FALSE);
-}
-
-/*
-TEST( {PKG}_{MODULE_NAME}, {FUNCTION}_n )
+TEST(MusedTest, muse_client_new_data_ch_p)
{
+ int client_sockfd = muse_client_new_data_ch();
+ ASSERT_TRUE(muse_core_fd_is_valid(client_sockfd));
+ EXPECT_EQ(muse_client_close(client_sockfd), MM_ERROR_NONE);
}
-*/
gint main(gint argc, gchar **argv)
{