Add unittest 71/299371/2
authorSeonah Moon <seonah1.moon@samsung.com>
Tue, 26 Sep 2023 14:05:20 +0000 (23:05 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Tue, 26 Sep 2023 14:06:05 +0000 (23:06 +0900)
[       OK ] AspSessionTest.BindPortWithInvalidHandle (1 ms)
[ RUN      ] AspSessionTest.ReleasePortWithInvalidParam
[       OK ] AspSessionTest.ReleasePortWithInvalidParam (0 ms)
[ RUN      ] AspSessionTest.ReleasePortWithInvalidHandle
[       OK ] AspSessionTest.ReleasePortWithInvalidHandle (1 ms)
[----------] 40 tests from AspSessionTest (350 ms total)

[----------] Global test environment tear-down
[==========] 40 tests from 1 test suite ran. (351 ms total)
[  PASSED  ] 40 tests.

Change-Id: I5e2bc03a50aa6916e9cf391768fa8d7f8801f678

CMakeLists.txt
packaging/capi-network-asp.spec
unittest/CMakeLists.txt [new file with mode: 0644]
unittest/asp-gtest-main.cpp [new file with mode: 0755]
unittest/asp-gtest-session.cpp [new file with mode: 0755]

index 65b33ec0330b6485f511785d1d9795b01494ff45..3ea88be19da955536702a6b34110b2870b4879a5 100755 (executable)
@@ -58,3 +58,6 @@ ADD_SUBDIRECTORY(include)
 ADD_SUBDIRECTORY(src)
 ADD_SUBDIRECTORY(pkgconfig)
 ADD_SUBDIRECTORY(test)
+IF(BUILD_GTESTS)
+       ADD_SUBDIRECTORY(unittest)
+ENDIF(BUILD_GTEST)
index 24d6c7ab67459bee413a61ad477287d1b4a89581..737db33f011d5c5f2ebea582225303f825d54419 100755 (executable)
@@ -22,6 +22,7 @@ BuildRequires:  pkgconfig(libsoup-2.4)
 BuildRequires:  pkgconfig(gssdp-1.0)
 BuildRequires:  pkgconfig(gupnp-1.0)
 %endif
+BuildRequires:  pkgconfig(gmock)
 
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
@@ -61,6 +62,9 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 %if "%{file_transfer_test}" == "yes"
         -DTZ_SYS_RO_ETC=%{TZ_SYS_RO_ETC} \
         -DFILE_TRANSFER_TEST=1 \
+%endif
+%if 0%{?gtests:1}
+               -DBUILD_GTESTS=ON \
 %endif
         -DCMAKE_BUILD_TYPE=%{?build_type} \
         -DCMAKE_VERBOSE_MAKEFILE=ON \
@@ -71,6 +75,7 @@ MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
         -DDATA_ROOT_DIR:PATH=%{_datadir} \
         -DFULLVER=%{version} \
         -DMAJORVER=${MAJORVER}
+
 make %{?jobs:-j%jobs}
 
 %install
@@ -97,4 +102,6 @@ rm -rf %{buildroot}
 %files test
 %manifest asp-test.manifest
 %attr(755,root,root) %{_bindir}/asp-test
-
+%if 0%{?gtests:1}
+%attr(755,root,root) %{_bindir}/asp-gtest
+%endif
diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt
new file mode 100644 (file)
index 0000000..175903e
--- /dev/null
@@ -0,0 +1,16 @@
+LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
+ADD_DEFINITIONS("-DASP_GTEST")
+
+pkg_check_modules(gtest_pkgs REQUIRED gmock ${COMMON_DEPS})
+INCLUDE_DIRECTORIES(${gtest_pkgs_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src/include)
+LINK_DIRECTORIES(${gtest_pkgs_LIBRARY_DIRS})
+
+SET(ASP_GTEST "asp-gtest")
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-lto")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-lto")
+
+FILE(GLOB GTEST_SRCS *.cpp ${CMAKE_SOURCE_DIR}/src/*.c)
+ADD_EXECUTABLE(${ASP_GTEST} ${GTEST_SRCS})
+TARGET_LINK_LIBRARIES(${ASP_GTEST} ${gtest_pkgs_LIBRARIES} ${${fw_name}_LIBRARIES})
+INSTALL(TARGETS ${ASP_GTEST} DESTINATION bin/)
diff --git a/unittest/asp-gtest-main.cpp b/unittest/asp-gtest-main.cpp
new file mode 100755 (executable)
index 0000000..4890e9c
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+* Copyright (c) 2020 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 <gtest/gtest.h>
+
+int main(int argc, char **argv)
+{
+       ::testing::InitGoogleTest(&argc, argv);
+       return RUN_ALL_TESTS();
+}
diff --git a/unittest/asp-gtest-session.cpp b/unittest/asp-gtest-session.cpp
new file mode 100755 (executable)
index 0000000..d19b7c3
--- /dev/null
@@ -0,0 +1,275 @@
+/*
+* Copyright (c) 2020 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 <gtest/gtest.h>
+
+#include "asp.h"
+
+extern "C" {
+}
+
+class AspSessionTest: public ::testing::Test {
+       protected:
+               void SetUp() override
+               {
+                       asp_initialize();
+                       asp_session_create(macAddress, advId, &session);
+               }
+
+               void TearDown() override
+               {
+                       asp_session_destroy(session);
+                       asp_deinitialize();
+               }
+
+               asp_session_h session;
+               char *macAddress = "00:11:22:33:44:55";
+               char *info = "HDCP Enable";
+               int advId = 0x01;
+};
+
+TEST_F(AspSessionTest, GetMac)
+{
+       char *mac = NULL;
+       EXPECT_EQ(ASP_ERROR_NONE, asp_session_get_mac(session, &mac));
+}
+
+TEST_F(AspSessionTest, GetMacWithInvalidParam)
+{
+       char *mac = nullptr;
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_get_mac(session, NULL));
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_get_mac(NULL, &mac));
+}
+
+TEST_F(AspSessionTest, GetMacWithInvalidHandle)
+{
+       char *mac = nullptr;
+       EXPECT_EQ(ASP_ERROR_SESSION_NOT_FOUND, asp_session_get_mac(session + 1, &mac));
+}
+
+TEST_F(AspSessionTest, GetId)
+{
+       unsigned int id;
+       EXPECT_EQ(ASP_ERROR_NONE, asp_session_get_id(session, &id));
+}
+
+TEST_F(AspSessionTest, GetIdWithInvalidParam)
+{
+       unsigned int id;
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_get_id(session, NULL));
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_get_id(NULL, &id));
+}
+
+TEST_F(AspSessionTest, GetIdWithInvalidHandle)
+{
+       unsigned int id;
+       EXPECT_EQ(ASP_ERROR_SESSION_NOT_FOUND, asp_session_get_id(session + 1, &id));
+}
+
+TEST_F(AspSessionTest, SetInfo)
+{
+       EXPECT_EQ(ASP_ERROR_NONE, asp_session_set_info(session, info));
+}
+
+TEST_F(AspSessionTest, SetInfoWithInvalidParam)
+{
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_set_info(session, NULL));
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_set_info(NULL, info));
+}
+
+TEST_F(AspSessionTest, SetInfoWithInvalidHandle)
+{
+       EXPECT_EQ(ASP_ERROR_SESSION_NOT_FOUND, asp_session_set_info(session + 1, info));
+}
+
+TEST_F(AspSessionTest, GetInfo)
+{
+       char *serviceInfo = NULL;
+       EXPECT_EQ(ASP_ERROR_NONE, asp_session_get_info(session, &serviceInfo));
+}
+
+TEST_F(AspSessionTest, GetInfoWithInvalidParam)
+{
+       char *serviceInfo = NULL;
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_get_info(NULL, &serviceInfo));
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_get_info(session, NULL));
+}
+
+TEST_F(AspSessionTest, GetInfoWithInvalidHandle)
+{
+       char *serviceInfo = NULL;
+       EXPECT_EQ(ASP_ERROR_SESSION_NOT_FOUND, asp_session_get_info(session + 1, &serviceInfo));
+}
+
+TEST_F(AspSessionTest, SetP2pRoleScheme)
+{
+       EXPECT_EQ(ASP_ERROR_NONE, asp_session_set_p2p_role_scheme(session, ASP_ADVERT_P2P_ROLE_SCHEME_GC));
+       EXPECT_EQ(ASP_ERROR_NONE, asp_session_set_p2p_role_scheme(session, ASP_ADVERT_P2P_ROLE_SCHEME_GO));
+}
+
+TEST_F(AspSessionTest, SetP2pRoleSchemeWithInvalidParam)
+{
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_set_p2p_role_scheme(NULL, ASP_ADVERT_P2P_ROLE_SCHEME_GC));
+}
+
+TEST_F(AspSessionTest, SetP2pRoleSchemeWithInvalidHandle)
+{
+       EXPECT_EQ(ASP_ERROR_SESSION_NOT_FOUND, asp_session_set_p2p_role_scheme(session + 1,
+               ASP_ADVERT_P2P_ROLE_SCHEME_GC));
+}
+
+TEST_F(AspSessionTest, GetP2pRoleScheme)
+{
+       asp_advert_p2p_role_scheme_e role;
+       EXPECT_EQ(ASP_ERROR_NONE, asp_session_get_p2p_role_scheme(session, &role));
+}
+
+TEST_F(AspSessionTest, GetP2pRoleSchemeWithInvalidParam)
+{
+       asp_advert_p2p_role_scheme_e role;
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_get_p2p_role_scheme(session, NULL));
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_get_p2p_role_scheme(NULL, &role));
+}
+
+TEST_F(AspSessionTest, GetP2pRoleSchemeWithInvalidHandle)
+{
+       asp_advert_p2p_role_scheme_e role;
+       EXPECT_EQ(ASP_ERROR_SESSION_NOT_FOUND, asp_session_get_p2p_role_scheme(session + 1, &role));
+}
+
+TEST_F(AspSessionTest, SetP2pConfigMethod)
+{
+       EXPECT_EQ(ASP_ERROR_NONE, asp_session_set_p2p_config_method(session, ASP_WPS_TYPE_DEFAULT));
+       EXPECT_EQ(ASP_ERROR_NONE, asp_session_set_p2p_config_method(session, ASP_WPS_TYPE_PIN_BOTH));
+       EXPECT_EQ(ASP_ERROR_NONE, asp_session_set_p2p_config_method(session, ASP_WPS_TYPE_PIN_DISPLAY));
+       EXPECT_EQ(ASP_ERROR_NONE, asp_session_set_p2p_config_method(session, ASP_WPS_TYPE_PIN_KEYPAD));
+}
+
+TEST_F(AspSessionTest, SetP2pConfigMethodWithInvalidParam)
+{
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_set_p2p_config_method(NULL, ASP_WPS_TYPE_DEFAULT));
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_set_p2p_config_method(session, ASP_WPS_TYPE_NONE));
+}
+
+TEST_F(AspSessionTest, SetP2pConfigMethodWithInvalidHandle)
+{
+       EXPECT_EQ(ASP_ERROR_SESSION_NOT_FOUND, asp_session_set_p2p_config_method(session + 1, ASP_WPS_TYPE_DEFAULT));
+}
+
+TEST_F(AspSessionTest, GetP2pConfigMethod)
+{
+       asp_wps_type_e config;
+       EXPECT_EQ(ASP_ERROR_NONE, asp_session_get_p2p_config_method(session, &config));
+}
+
+TEST_F(AspSessionTest, GetP2pConfigMethodWithIvalidParam)
+{
+       asp_wps_type_e config;
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_get_p2p_config_method(NULL, &config));
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_get_p2p_config_method(session, NULL));
+}
+
+TEST_F(AspSessionTest, GetP2pConfigMethodWithIvalidHandle)
+{
+       asp_wps_type_e config;
+       EXPECT_EQ(ASP_ERROR_SESSION_NOT_FOUND, asp_session_get_p2p_config_method(session + 1, &config));
+}
+
+TEST_F(AspSessionTest, GetCloseStatus)
+{
+       int status;
+       EXPECT_EQ(ASP_ERROR_NONE, asp_session_get_close_status(session, &status));
+}
+
+TEST_F(AspSessionTest, GetCloseStatusWithInvalidParam)
+{
+       int status;
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_get_close_status(NULL, &status));
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_get_close_status(session, NULL));
+}
+
+TEST_F(AspSessionTest, GetCloseStatusWithInvalidHandle)
+{
+       int status;
+       EXPECT_EQ(ASP_ERROR_SESSION_NOT_FOUND, asp_session_get_close_status(session + 1, &status));
+}
+
+TEST_F(AspSessionTest, ConnectWithInvalidParam)
+{
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_connect(NULL));
+}
+
+TEST_F(AspSessionTest, ConnectWithInvalidHandle)
+{
+       EXPECT_EQ(ASP_ERROR_SESSION_NOT_FOUND, asp_session_connect(session + 1));
+}
+
+TEST_F(AspSessionTest, ConfirmWithInvalidParam)
+{
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_confirm(NULL, 1, "12345678"));
+}
+
+TEST_F(AspSessionTest, ConfirmWithInvalidHandle)
+{
+       EXPECT_EQ(ASP_ERROR_SESSION_NOT_FOUND, asp_session_confirm(session + 1, 1, "12345678"));
+}
+
+TEST_F(AspSessionTest, GetHandleWithInvalidParam)
+{
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_get_handle(macAddress, advId, NULL));
+}
+
+TEST_F(AspSessionTest, SetStateReadyWithInvalidParam)
+{
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_set_state_ready(NULL));
+}
+
+TEST_F(AspSessionTest, SetStateReadyWithInvalidHandle)
+{
+       EXPECT_EQ(ASP_ERROR_SESSION_NOT_FOUND, asp_session_set_state_ready(session + 1));
+}
+
+TEST_F(AspSessionTest, CloseWithInvalidParam)
+{
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_close(NULL));
+}
+
+TEST_F(AspSessionTest, CloseWithInvalidHandle)
+{
+       EXPECT_EQ(ASP_ERROR_SESSION_NOT_FOUND, asp_session_close(session + 1));
+}
+
+TEST_F(AspSessionTest, BindPortWithInvalidParam)
+{
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_bind_port(NULL, "192.168.0.1", 12345, 80));
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_bind_port(session, NULL, 12345, 80));
+}
+
+TEST_F(AspSessionTest, BindPortWithInvalidHandle)
+{
+       EXPECT_EQ(ASP_ERROR_SESSION_NOT_FOUND, asp_session_bind_port(session + 1, "192.168.0.1", 12345, 80));
+}
+
+TEST_F(AspSessionTest, ReleasePortWithInvalidParam)
+{
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_release_port(NULL, "192.168.0.1", 12345, 80));
+       EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_session_release_port(session, NULL, 12345, 80));
+}
+
+TEST_F(AspSessionTest, ReleasePortWithInvalidHandle)
+{
+       EXPECT_EQ(ASP_ERROR_SESSION_NOT_FOUND, asp_session_release_port(session + 1, "192.168.0.1", 12345, 80));
+}
\ No newline at end of file