Update the socket unittest with using muse-server by itself 60/194360/4
authorYoungHun Kim <yh8004.kim@samsung.com>
Mon, 3 Dec 2018 11:51:07 +0000 (20:51 +0900)
committerYoungHun Kim <yh8004.kim@samsung.com>
Mon, 10 Dec 2018 09:48:44 +0000 (18:48 +0900)
Change-Id: I45ba36f51d1b67e4eb925f5c8d5f2f8a325b809e

packaging/mused.spec
unittest/CMakeLists.txt
unittest/muse_gtest_socket.cpp [deleted file]
unittest/muse_gtest_socket.h [deleted file]
unittest/unittest.cpp

index 7e150f7d6ab643ae6c7f2d8c97da2d9a3830ad31..fe8b80a7d0d84e165f8a3a74ab89cb5983514a49 100644 (file)
@@ -1,6 +1,6 @@
 Name:       mused
 Summary:    A multimedia daemon
-Version:    0.3.55
+Version:    0.3.56
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index d6d033543ed5123dd9f2645413841b5acb8daa48..8fb14eb66df5c48a0eece492793932e29055edc1 100644 (file)
@@ -9,14 +9,14 @@ SET(GTEST_MUSE "gtest-muse-server")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpie")
 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpie")
 
-FILE(GLOB GTEST_MUSE_SRCS *.cpp ${CMAKE_SOURCE_DIR}/server/src/muse_server_common.c)
+FILE(GLOB GTEST_MUSE_SRCS *.cpp ${CMAKE_SOURCE_DIR}/server/src/muse_server_common.c ${CMAKE_SOURCE_DIR}/client/src/muse_client.c)
 
 PKG_CHECK_MODULES(GTEST_PKGS REQUIRED glib-2.0 dlog json-c mm-common gmock)
 INCLUDE_DIRECTORIES(${GTEST_PKGS_INCLUDE_DIRS})
 LINK_DIRECTORIES(${GTEST_PKGS_LIBRARY_DIRS})
 
 ADD_EXECUTABLE(${GTEST_MUSE} ${GTEST_MUSE_SRCS})
-TARGET_LINK_LIBRARIES(${GTEST_MUSE} ${MUSE_CORE} ${MUSE_SERVER} ${GTEST_PKGS_LDFLAGS} -lgcov)
+TARGET_LINK_LIBRARIES(${GTEST_MUSE} ${MUSE_CORE} ${MUSE_SERVER} ${GTEST_PKGS_LDFLAGS} -lgcov -liniparser)
 
 INSTALL(TARGETS ${GTEST_MUSE} DESTINATION ${BINDIR})
 
diff --git a/unittest/muse_gtest_socket.cpp b/unittest/muse_gtest_socket.cpp
deleted file mode 100644 (file)
index c9701ff..0000000
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * 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;
-}
diff --git a/unittest/muse_gtest_socket.h b/unittest/muse_gtest_socket.h
deleted file mode 100644 (file)
index d5ee8f2..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * 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.
- */
-
-#ifndef __MUSE_GTEST_SOCKET_H__
-#define __MUSE_GTEST_SOCKET_H__
-
-#include "unittest.h"
-
-bool muse_gtest_socket(muse_channel_e channel);
-
-#endif /*__MUSE_GTEST_SOCKET_H__*/
-
index 8b1f4cec8cfa765691b565e436c11e83b6028dcd..8ccac4a766d640717bf22014ef74e06cdf56df4c 100644 (file)
@@ -15,7 +15,6 @@
  */
 
 #include "muse_gtest_json.h"
-#include "muse_gtest_socket.h"
 
 using ::testing::InitGoogleTest;
 using ::testing::Test;
@@ -77,28 +76,21 @@ TEST(MusedTest, muse_gtest_multi_threaded_json_n)
        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)
 {