The softap.cpp is a very long file with 1704 lines.
This made it difficult to understand the code, so it was necessary to reduce the length of the file.
First, the functions that use vconf to get data were moved to be processed in SoftApVconf.
Test Result
[ 15s] [----------] 8 tests from SoftapVconfTest
[ 15s] [ RUN ] SoftapVconfTest.getCommonSsidP
[ 15s] [ OK ] SoftapVconfTest.getCommonSsidP (0 ms)
[ 15s] [ RUN ] SoftapVconfTest.getCommonSsidN
[ 15s] [ OK ] SoftapVconfTest.getCommonSsidN (8 ms)
[ 15s] [ RUN ] SoftapVconfTest.getSecurityTypeP
[ 15s] [ OK ] SoftapVconfTest.getSecurityTypeP (0 ms)
[ 15s] [ RUN ] SoftapVconfTest.getSecurityTypeN
[ 15s] [ OK ] SoftapVconfTest.getSecurityTypeN (0 ms)
[ 15s] [ RUN ] SoftapVconfTest.getVisibilityP
[ 15s] [ OK ] SoftapVconfTest.getVisibilityP (0 ms)
[ 15s] [ RUN ] SoftapVconfTest.getVisibilityN
[ 15s] [ OK ] SoftapVconfTest.getVisibilityN (0 ms)
[ 15s] [ RUN ] SoftapVconfTest.getVsieP
[ 15s] [ OK ] SoftapVconfTest.getVsieP (0 ms)
[ 15s] [ RUN ] SoftapVconfTest.getVsieN
[ 15s] [ OK ] SoftapVconfTest.getVsieN (0 ms)
[ 15s] [----------] 8 tests from SoftapVconfTest (11 ms total)
Change-Id: I640077183444a18bc4d9f76164522de92bfa975d
--- /dev/null
+#include "softap_dlog.h"
+#include "softap_private.h"
+#include "SoftapVconf.h"
+
+#include <glib.h>
+
+int SoftapVconf::getCommonSsid(char *ssid, unsigned int size)
+{
+ if (ssid == NULL) {
+ ERR("ssid is null!!");
+ return SOFTAP_ERROR_INVALID_PARAMETER;
+ }
+
+ char *device_name = NULL;
+ char *end = NULL;
+
+ device_name = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
+ if (device_name == NULL) {
+ ERR("vconf_get_str is failed and set default ssid!!");
+ g_strlcpy(ssid, SOFTAP_DEFAULT_SSID, size);
+ } else
+ g_strlcpy(ssid, device_name, size);
+
+ if (!g_utf8_validate(ssid, -1, (const char **)&end))
+ *end = '\0';
+
+ free(device_name);
+
+ return SOFTAP_ERROR_NONE;
+}
+
+softap_error_e SoftapVconf::getSecurityType(softap_security_type_e *security_type)
+{
+ if (security_type == NULL) {
+ ERR("Invalid param\n");
+ return SOFTAP_ERROR_INVALID_PARAMETER;
+ }
+
+ if (vconf_get_int(VCONFKEY_SOFTAP_SECURITY,
+ (int *)security_type) < 0) {
+ ERR("vconf_get_int is failed\n");
+ return SOFTAP_ERROR_OPERATION_FAILED;
+ }
+
+ return SOFTAP_ERROR_NONE;
+}
+
+softap_error_e SoftapVconf::getVisibility(bool *visible)
+{
+ if (visible == NULL) {
+ ERR("Invalid param\n");
+ return SOFTAP_ERROR_INVALID_PARAMETER;
+ }
+
+ int hide = 0;
+
+ if (vconf_get_int(VCONFKEY_SOFTAP_HIDE, &hide) < 0) {
+ ERR("vconf_get_int is failed\n");
+ return SOFTAP_ERROR_OPERATION_FAILED;
+ }
+
+ if (hide)
+ *visible = false;
+ else
+ *visible = true;
+
+ return SOFTAP_ERROR_NONE;
+}
+
+softap_error_e SoftapVconf::getVsie(char *vsie, unsigned int size)
+{
+ if (vsie == NULL) {
+ ERR("vsie is NULL\n");
+ return SOFTAP_ERROR_INVALID_PARAMETER;
+ }
+ char *ptr = NULL;
+
+ ptr = vconf_get_str(VCONFKEY_SOFTAP_VSIE);
+ if (ptr == NULL)
+ return SOFTAP_ERROR_OPERATION_FAILED;
+
+ g_strlcpy(vsie, ptr, size);
+ free(ptr);
+
+ return SOFTAP_ERROR_NONE;
+}
+
+softap_error_e SoftapVconf::getChannel(int *channel)
+{
+ if (channel == NULL) {
+ ERR("Invalid param\n");
+ return SOFTAP_ERROR_INVALID_PARAMETER;
+ }
+
+ if (vconf_get_int(VCONFKEY_SOFTAP_CHANNEL, channel) < 0) {
+ ERR("vconf_get_int is failed\n");
+ return SOFTAP_ERROR_OPERATION_FAILED;
+ }
+
+ return SOFTAP_ERROR_NONE;
+}
+
+softap_error_e SoftapVconf::getMode(softap_wireless_mode_e *mode)
+{
+ if (mode == NULL) {
+ ERR("Invalid param\n");
+ return SOFTAP_ERROR_INVALID_PARAMETER;
+ }
+
+ if (vconf_get_int(VCONFKEY_SOFTAP_MODE, (int *)mode) < 0) {
+ ERR("vconf_get_int is failed\n");
+ return SOFTAP_ERROR_OPERATION_FAILED;
+ }
+
+ return SOFTAP_ERROR_NONE;
+}
\ No newline at end of file
--- /dev/null
+#pragma once
+
+#include "softap.h"
+
+#include <vconf.h>
+
+class SoftapVconf {
+public:
+ static int getCommonSsid(char *ssid, unsigned int size);
+ static softap_error_e getSecurityType(softap_security_type_e *security_type);
+ static softap_error_e getVisibility(bool *visible);
+ static softap_error_e getVsie(char *vsie, unsigned int size);
+ static softap_error_e getChannel(int *channel);
+ static softap_error_e getMode(softap_wireless_mode_e *mode);
+};
\ No newline at end of file
#include <unistd.h>
#include <dbus/dbus.h>
#include <gio/gio.h>
-#include <vconf.h>
#include "softap_private.h"
#include "softap_gdbus.h"
#include "SoftapEventHandler.h"
#include "SoftapEventCallback.h"
+#include "SoftapVconf.h"
static int retry = 0;
-static int __get_common_ssid(char *ssid, unsigned int size)
-{
- if (ssid == NULL) {
- ERR("ssid is null!!");
- return SOFTAP_ERROR_INVALID_PARAMETER;
- }
-
- char *device_name = NULL;
- char *end = NULL;
-
- device_name = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR);
- if (device_name == NULL) {
- ERR("vconf_get_str is failed and set default ssid!!");
- g_strlcpy(ssid, SOFTAP_DEFAULT_SSID, size);
- } else
- g_strlcpy(ssid, device_name, size);
-
- if (!g_utf8_validate(ssid, -1, (const char **)&end))
- *end = '\0';
-
- free(device_name);
-
- return SOFTAP_ERROR_NONE;
-}
-
-static softap_error_e __get_security_type(softap_security_type_e *security_type)
-{
- if (security_type == NULL) {
- ERR("Invalid param\n");
- return SOFTAP_ERROR_INVALID_PARAMETER;
- }
-
- if (vconf_get_int(VCONFKEY_SOFTAP_SECURITY,
- (int *)security_type) < 0) {
- ERR("vconf_get_int is failed\n");
- return SOFTAP_ERROR_OPERATION_FAILED;
- }
-
- return SOFTAP_ERROR_NONE;
-}
-
-static softap_error_e __get_visibility(bool *visible)
-{
- if (visible == NULL) {
- ERR("Invalid param\n");
- return SOFTAP_ERROR_INVALID_PARAMETER;
- }
-
- int hide = 0;
-
- if (vconf_get_int(VCONFKEY_SOFTAP_HIDE, &hide) < 0) {
- ERR("vconf_get_int is failed\n");
- return SOFTAP_ERROR_OPERATION_FAILED;
- }
-
- if (hide)
- *visible = false;
- else
- *visible = true;
-
- return SOFTAP_ERROR_NONE;
-}
-
-static softap_error_e __get_vsie(char *vsie, unsigned int size)
-{
- char *ptr = NULL;
-
- ptr = vconf_get_str(VCONFKEY_SOFTAP_VSIE);
- if (ptr == NULL)
- return SOFTAP_ERROR_OPERATION_FAILED;
-
- g_strlcpy(vsie, ptr, size);
- free(ptr);
-
- return SOFTAP_ERROR_NONE;
-}
-
-static softap_error_e __get_channel(int *channel)
-{
- if (channel == NULL) {
- ERR("Invalid param\n");
- return SOFTAP_ERROR_INVALID_PARAMETER;
- }
-
- if (vconf_get_int(VCONFKEY_SOFTAP_CHANNEL, channel) < 0) {
- ERR("vconf_get_int is failed\n");
- return SOFTAP_ERROR_OPERATION_FAILED;
- }
-
- return SOFTAP_ERROR_NONE;
-}
-
-static softap_error_e __get_mode(softap_wireless_mode_e *mode)
-{
- if (mode == NULL) {
- ERR("Invalid param\n");
- return SOFTAP_ERROR_INVALID_PARAMETER;
- }
-
- if (vconf_get_int(VCONFKEY_SOFTAP_MODE, (int *)mode) < 0) {
- ERR("vconf_get_int is failed\n");
- return SOFTAP_ERROR_OPERATION_FAILED;
- }
-
- return SOFTAP_ERROR_NONE;
-}
-
static int __get_initial_passphrase(char *passphrase, unsigned int size)
{
if (passphrase == NULL ||
sa->sec_type = SOFTAP_SECURITY_TYPE_WPA2_PSK;
char ssid[SOFTAP_SSID_MAX_LEN + 1] = {0, };
- if (__get_common_ssid(ssid, sizeof(ssid)) != SOFTAP_ERROR_NONE) {
+ if (SoftapVconf::getCommonSsid(ssid, sizeof(ssid)) != SOFTAP_ERROR_NONE) {
ERR("Fail to get default ssid!!");
free(sa);
return SOFTAP_ERROR_OPERATION_FAILED;
_retvm_if(type == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
"parameter(type) is NULL\n");
- return __get_security_type(type);
+ return SoftapVconf::getSecurityType(type);
}
API int softap_set_ssid(softap_h softap, const char *ssid)
char val[SOFTAP_SSID_MAX_LEN + 1] = {0, };
if (__get_ssid_from_vconf(VCONFKEY_SOFTAP_SSID, val, sizeof(val)) == false) {
- if (__get_common_ssid(val, sizeof(val)) != SOFTAP_ERROR_NONE) {
+ if (SoftapVconf::getCommonSsid(val, sizeof(val)) != SOFTAP_ERROR_NONE) {
ERR("Fail to get default ssid!!");
free(sa);
return SOFTAP_ERROR_OPERATION_FAILED;
_retvm_if(visible == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
"parameter(visible) is NULL\n");
- return __get_visibility(visible);
+ return SoftapVconf::getVisibility(visible);
}
API int softap_set_passphrase(softap_h softap, const char *passphrase)
char val[SOFTAP_VENDOR_MAX_LEN + 1] = {0, };
- int ret = __get_vsie(val, sizeof(val));
+ int ret = SoftapVconf::getVsie(val, sizeof(val));
if (ret != SOFTAP_ERROR_NONE) {
ERR("Failed to get vendor elements");
return ret;
_retvm_if(channel == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
"parameter(channel) is NULL\n");
- return __get_channel(channel);
+ return SoftapVconf::getChannel(channel);
}
API int softap_set_mode(softap_h softap, softap_wireless_mode_e mode)
__softap_h *sa = (__softap_h *)softap;
*mode = sa->mode;
- return __get_mode(mode);
+ return SoftapVconf::getMode(mode);
}
API int softap_enable_dhcp(softap_h softap)
if (!softap_mock_vconf_result)
return -1;
+ *intval = 0;
if (softap_mock_enabled_state
&& strncmp(in_key, VCONFKEY_MOBILE_HOTSPOT_MODE,
strlen(VCONFKEY_MOBILE_HOTSPOT_MODE)) == 0)
*intval |= VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI_AP;
- else
- *intval = 0;
return 0;
}
--- /dev/null
+/*
+* Copyright (c) 2023 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 "SoftapVconf.h"
+#include "SoftapEventCallback.h"
+#include "softap_gdbus.h"
+
+extern "C" {
+#include "mocks/softap_memory.h"
+#include "mocks/softap_vconf.h"
+}
+
+class SoftapVconfTest: public ::testing::Test {
+ protected:
+ void SetUp() override
+ {
+ softap_mock_set_memory_result(true);
+ softap_mock_set_vconf_result(true);
+ softap_mock_set_enabled_state(true);
+ }
+
+ void TearDown() override
+ {
+ softap_mock_set_memory_result(true);
+ softap_mock_set_vconf_result(false);
+ softap_mock_set_enabled_state(false);
+ }
+};
+
+TEST_F(SoftapVconfTest, getCommonSsidP)
+{
+ char ssid[100];
+ EXPECT_EQ(SOFTAP_ERROR_NONE, SoftapVconf::getCommonSsid(ssid, 100));
+ EXPECT_STREQ("vconf result string", ssid);
+}
+
+TEST_F(SoftapVconfTest, getCommonSsidN)
+{
+ EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER,
+ SoftapVconf::getCommonSsid(NULL, 0));
+}
+
+TEST_F(SoftapVconfTest, getSecurityTypeP)
+{
+ softap_security_type_e type;
+ EXPECT_EQ(SOFTAP_ERROR_NONE, SoftapVconf::getSecurityType(&type));
+ EXPECT_EQ(0, type);
+}
+
+TEST_F(SoftapVconfTest, getSecurityTypeN)
+{
+ EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER,
+ SoftapVconf::getSecurityType(NULL));
+}
+
+TEST_F(SoftapVconfTest, getVisibilityP)
+{
+ bool visible;
+ EXPECT_EQ(SOFTAP_ERROR_NONE, SoftapVconf::getVisibility(&visible));
+ EXPECT_EQ(true, visible);
+}
+
+TEST_F(SoftapVconfTest, getVisibilityN)
+{
+ EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER,
+ SoftapVconf::getVisibility(NULL));
+}
+
+TEST_F(SoftapVconfTest, getVsieP)
+{
+ char vsie[100];
+ EXPECT_EQ(SOFTAP_ERROR_NONE, SoftapVconf::getVsie(vsie, 100));
+ EXPECT_STREQ("vconf result string", vsie);
+}
+
+TEST_F(SoftapVconfTest, getVsieN)
+{
+ EXPECT_EQ(SOFTAP_ERROR_INVALID_PARAMETER,
+ SoftapVconf::getVsie(NULL, 0));
+}