--- /dev/null
+/*
+* 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