From a8409f4a765a8968bf7e7ce2146bd9b42cc3ec57 Mon Sep 17 00:00:00 2001 From: cheoleun moon Date: Wed, 13 Dec 2023 19:58:19 +0900 Subject: [PATCH] Extract classes for Advert/Seek roles Change-Id: Id254bda7cfdedc959a47738bd48ac7d469106cf7 --- src/CMakeLists.txt | 8 +- src/asp-advert.cpp | 141 +++++++ src/{asp-client.c => asp-client.cpp} | 517 ++++--------------------- src/{asp-dbus.c => asp-dbus.cpp} | 12 +- src/asp-seek.cpp | 89 +++++ src/asp-utils.cpp | 76 ++++ src/include/asp-advert.h | 37 ++ src/include/asp-client.h | 43 -- src/include/asp-conts.h | 13 + src/include/asp-dbus.h | 8 - src/include/{asp-util.h => asp-defs.h} | 0 src/include/asp-seek.h | 31 ++ src/include/asp-utils.h | 10 + unittest/CMakeLists.txt | 10 +- unittest/asp-gtest-advert.cpp | 105 +++++ unittest/asp-gtest-client.cpp | 61 +++ unittest/asp-gtest-seek.cpp | 55 +++ unittest/asp-gtest-util.cpp | 56 +++ unittest/mock/mock-asp-dbus.cpp | 13 + unittest/mock/mock-system-info.cpp | 17 + 20 files changed, 810 insertions(+), 492 deletions(-) create mode 100644 src/asp-advert.cpp rename src/{asp-client.c => asp-client.cpp} (85%) rename src/{asp-dbus.c => asp-dbus.cpp} (95%) create mode 100644 src/asp-seek.cpp create mode 100644 src/asp-utils.cpp create mode 100644 src/include/asp-advert.h create mode 100644 src/include/asp-conts.h rename src/include/{asp-util.h => asp-defs.h} (100%) create mode 100644 src/include/asp-seek.h create mode 100644 src/include/asp-utils.h create mode 100644 unittest/asp-gtest-advert.cpp create mode 100644 unittest/asp-gtest-client.cpp create mode 100644 unittest/asp-gtest-seek.cpp create mode 100644 unittest/asp-gtest-util.cpp create mode 100644 unittest/mock/mock-asp-dbus.cpp create mode 100644 unittest/mock/mock-system-info.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 50b66b2..47562fd 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,11 +19,15 @@ SET(ASP_PATH ${PROJECT_SOURCE_DIR}/src) INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/include ${ASP_PATH}/include + ${ASP_DEPS_INCLUDE_DIRS} ) SET(ASP_SOURCES - ${ASP_PATH}/asp-client.c - ${ASP_PATH}/asp-dbus.c + ${ASP_PATH}/asp-client.cpp + ${ASP_PATH}/asp-dbus.cpp + ${ASP_PATH}/asp-advert.cpp + ${ASP_PATH}/asp-seek.cpp + ${ASP_PATH}/asp-utils.cpp ) ADD_DEFINITIONS("-fvisibility=default") diff --git a/src/asp-advert.cpp b/src/asp-advert.cpp new file mode 100644 index 0000000..53ce92d --- /dev/null +++ b/src/asp-advert.cpp @@ -0,0 +1,141 @@ +#include "asp.h" +#include "asp-advert.h" +#include "asp-conts.h" +#include "asp-log.h" +#include "asp-utils.h" + +static __thread GList *asp_adverts = NULL; + +AspAdvert::AspAdvert() +{ + auto_accept = 0; + config_method = 1; + status = 0; + role = 1; + service_info_map = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + adv_id = (unsigned int)this & 0xffffffff; + instance_name = NULL; + serivce_name = NULL; + service_type = NULL; + rsp_info = NULL; +} + +AspAdvert::~AspAdvert() +{ + g_free(instance_name); + g_free(serivce_name); + g_free(service_type); + g_free(rsp_info); + g_hash_table_remove_all(service_info_map); + g_hash_table_destroy(service_info_map); +} + +int AspAdvert::setServiceType(const std::string &type) +{ + if (type.empty()) { + ASP_LOGE("Zero length value"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + if (!AspUtil::isValidServiceType(type)) { + ASP_LOGE("invalid service_type"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + return ASP_ERROR_NONE; +} + +int AspAdvert::addInfo(const std::string &key, const std::string &value) +{ + if (!AspUtil::isValidKey(key)) { + ASP_LOGE("invalid key!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + g_hash_table_replace(service_info_map, g_strdup(key.c_str()), g_strdup(value.c_str())); + return ASP_ERROR_NONE; +} + +int AspAdvert::setDiscoveryTech(int tech) +{ + if (!((tech & ASP_DISCOVERY_TECH_P2P) | + (tech & ASP_DISCOVERY_TECH_NFC) | + (tech & ASP_DISCOVERY_TECH_BLE) | + (tech & ASP_DISCOVERY_TECH_INFRA) | + (tech & ASP_DISCOVERY_TECH_NAN))) { + ASP_LOGE("invalid parameter!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + discovery_tech = tech; + return ASP_ERROR_NONE; +} + +AspAdvert *getAdvert(void *handle) +{ + __ASP_LOG_FUNC_START__; + AspAdvert *service = NULL; + + if (asp_adverts == NULL) { + __ASP_LOG_FUNC_END__; + return NULL; + } + + ASP_LOGD("service [%p]", handle); + + for (GList *temp = g_list_first(asp_adverts); temp != NULL; temp = g_list_next(temp)) { + service = (AspAdvert *)temp->data; + + ASP_LOGD("temp [%p]", service); + if (service != NULL && service == handle) + break; + service = NULL; + } + __ASP_LOG_FUNC_END__; + return service; +} + +AspAdvert *getAdvertById(unsigned int id) +{ + AspAdvert *advert = NULL; + GList *temp = NULL; + + for (temp = g_list_first(asp_adverts); + temp != NULL; temp = g_list_next(temp)) { + advert = (AspAdvert *)temp->data; + if (advert != NULL && advert->adv_id == id) + break; + advert = NULL; + } + + return advert; + +} + +bool removeAdvert(void *handle) +{ + AspAdvert *service = getAdvert(handle); + + if (service == NULL) { + __ASP_LOG_FUNC_END__; + return false; + } + + removeAdvertFromServiceList(service); + delete service; + + return true; +} + +void addAdvertToServiceList(AspAdvert *service) +{ + asp_adverts = g_list_prepend(asp_adverts, service); +} + +void removeAdvertFromServiceList(AspAdvert *service) +{ + asp_adverts = g_list_remove(asp_adverts, service); +} diff --git a/src/asp-client.c b/src/asp-client.cpp similarity index 85% rename from src/asp-client.c rename to src/asp-client.cpp index a3d2c1c..11c53ef 100755 --- a/src/asp-client.c +++ b/src/asp-client.cpp @@ -20,9 +20,9 @@ /** * This file implements Application Service Platform(ASP) user library. * - * @file asp-client.c - * @author Jiung Yu (jiung.yu@samsung.com) - * @version 0.1 + * @file asp-client.c + * @author Jiung Yu (jiung.yu@samsung.com) + * @version 0.1 */ @@ -60,27 +60,19 @@ *****************************************************************************/ #include "asp.h" +#include "asp-advert.h" #include "asp-client.h" +#include "asp-conts.h" +#include "asp-defs.h" #include "asp-dbus.h" #include "asp-log.h" -#include "asp-util.h" +#include "asp-seek.h" +#include "asp-utils.h" /***************************************************************************** * Macros and Typedefs *****************************************************************************/ -#define INSTANCE_NAME_LEN 63 -#define MAX_SERVICE_NAME_LEN 15 -#define MAX_SERVICE_TYPE_LEN 255 -#define PROTO_LEN 4 -#define KEY_LEN 9 /* http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt */ -#define KEY_MIN 0x20 /* RFC 20 */ -#define KEY_MAX 0x7E - -#define SERVICE_INFO_LEN 65000 -#define DEFERRED_LEN 144 -#define SESSION_INFO_LEN 144 - /***************************************************************************** * Global Variables *****************************************************************************/ @@ -104,8 +96,6 @@ static __thread asp_client_info_s g_client_info = { .user_data_for_cb_session_port_status = NULL }; -static __thread GList *asp_adverts = NULL; -static __thread GList *asp_seeks = NULL; static __thread GList *asp_sessions = NULL; /***************************************************************************** @@ -206,9 +196,9 @@ static asp_variant_s *__get_asp_variant_from_iterator(GVariantIter *iter) } else if (!g_strcmp0(key, "session_mac")) { g_variant_get(value, "&s", &variant->session_mac); } else if (!g_strcmp0(key, "session_info")) { - g_variant_get(value, "&s", &variant->session_info); - if (variant->session_info) - variant->session_info_len = strlen(variant->session_info); + g_variant_get(value, "&s", &variant->session_info); + if (variant->session_info) + variant->session_info_len = strlen(variant->session_info); } else if (!g_strcmp0(key, "device_name")) { g_variant_get(value, "&s", &variant->device_name); } else if (!g_strcmp0(key, "get_pin")) { @@ -268,40 +258,6 @@ static int __asp_err_string_to_enum(const char *error) return ASP_ERROR_OPERATION_FAILED; } -static asp_client_advert_s *get_advert_by_id(unsigned int adv_id) -{ - asp_client_advert_s *advert = NULL; - GList *temp = NULL; - - for (temp = g_list_first(asp_adverts); - temp != NULL; temp = g_list_next(temp)) { - advert = temp->data; - if (advert != NULL && advert->adv_id == adv_id) - break; - advert = NULL; - } - - return advert; - -} - -static asp_client_seek_s *get_seek_by_id(long long unsigned search_id) -{ - asp_client_seek_s *seek = NULL; - GList *temp = NULL; - - for (temp = g_list_first(asp_seeks); - temp != NULL; temp = g_list_next(temp)) { - seek = temp->data; - if (seek != NULL && seek->search_id == search_id) - break; - seek = NULL; - } - - return seek; - -} - static asp_client_session_s *get_session_by_id_mac(const char *session_mac, unsigned int session_id) { asp_client_session_s *session = NULL; @@ -309,7 +265,7 @@ static asp_client_session_s *get_session_by_id_mac(const char *session_mac, unsi for (temp = g_list_first(asp_sessions); temp != NULL; temp = g_list_next(temp)) { - session = temp->data; + session = (asp_client_session_s *)temp->data; if (session != NULL && session->session_id == session_id && memcmp(session->session_mac, session_mac, MACSTR_LEN) == 0) break; @@ -342,7 +298,7 @@ void asp_process_seek_search_result(GDBusConnection *connection, return; } - asp_client_seek_s *seek = get_seek_by_id(variant->search_id); + AspSeek *seek = getSeekById(variant->search_id); if (!seek) { ASP_LOGD("There's no related seek"); goto ERROR; @@ -367,7 +323,7 @@ void asp_process_advert_status_changed(GDBusConnection *connection, __ASP_LOG_FUNC_START__; asp_client_info_s *client = &g_client_info; - asp_client_advert_s *advert = NULL; + AspAdvert *advert = NULL; unsigned int advertisement_id = 0; unsigned char status = 0; int reason = 0; @@ -384,7 +340,7 @@ void asp_process_advert_status_changed(GDBusConnection *connection, g_variant_get(parameters, "(uyi)", &advertisement_id, &status, &reason); - advert = get_advert_by_id(advertisement_id); + advert = getAdvertById(advertisement_id); if (!advert) { ASP_LOGD("There's no related advert"); return; @@ -403,18 +359,12 @@ int __handle_session_request(unsigned int adv_id, const char *session_mac, unsigned int session_id, const char *session_info) { __ASP_LOG_FUNC_START__; - asp_client_advert_s *service = NULL; + AspAdvert *service = NULL; asp_client_session_s *session = NULL; GList *temp = NULL; int res = 0; - for (temp = g_list_first(asp_adverts); - temp != NULL; temp = g_list_next(temp)) { - service = temp->data; - if (service != NULL && service->adv_id == adv_id) - break; - service = NULL; - } + service = getAdvertById(adv_id); if (service == NULL) { ASP_LOGD("No matched local service"); @@ -427,7 +377,7 @@ int __handle_session_request(unsigned int adv_id, const char *session_mac, temp = NULL; for (temp = g_list_first(asp_sessions); temp != NULL; temp = g_list_next(temp)) { - session = temp->data; + session = (asp_client_session_s *)temp->data; if (session != NULL && session->session_id == session_id && memcmp(session->session_mac, session_mac, MACSTR_LEN) == 0) break; @@ -470,7 +420,7 @@ static void __invoke_session_request_cb(asp_variant_s *variant) return; } - asp_client_advert_s *advert = get_advert_by_id(variant->adv_id); + AspAdvert *advert = getAdvertById(variant->adv_id); if (!advert) { ASP_LOGD("There's no related advert"); return; @@ -528,6 +478,7 @@ void asp_process_session_config_request(GDBusConnection *connection, const gchar *object_path, GVariant *parameters) { __ASP_LOG_FUNC_START__; + asp_client_session_s *session = NULL; asp_client_info_s *client = &g_client_info; if (!client->session_config_request_cb) { ASP_LOGE("session_config_request_cb is NULL!!"); @@ -552,7 +503,7 @@ void asp_process_session_config_request(GDBusConnection *connection, goto ERROR; } - asp_client_session_s *session = get_session_by_id_mac(variant->session_mac, variant->session_id); + session = get_session_by_id_mac(variant->session_mac, variant->session_id); if (!session) { ASP_LOGD("There's no related session"); goto ERROR; @@ -573,6 +524,7 @@ void asp_process_session_connect_status(GDBusConnection *connection, const gchar *object_path, GVariant *parameters) { __ASP_LOG_FUNC_START__; + asp_client_session_s *session = NULL; asp_client_info_s *client = &g_client_info; if (!client->session_connect_status_cb) { ASP_LOGE("connect_status_cb is NULL!!"); @@ -597,7 +549,7 @@ void asp_process_session_connect_status(GDBusConnection *connection, goto ERROR; } - asp_client_session_s *session = get_session_by_id_mac(variant->session_mac, variant->session_id); + session = get_session_by_id_mac(variant->session_mac, variant->session_id); if (!session) { ASP_LOGD("There's no related session"); goto ERROR; @@ -619,6 +571,7 @@ void asp_process_session_status(GDBusConnection *connection, const gchar *object_path, GVariant *parameters) { __ASP_LOG_FUNC_START__; + asp_client_session_s *session = NULL; asp_client_info_s *client = &g_client_info; if (!client->session_status_cb) { ASP_LOGE("session_status_cb is NULL!!"); @@ -643,7 +596,7 @@ void asp_process_session_status(GDBusConnection *connection, goto ERROR; } - asp_client_session_s *session = get_session_by_id_mac(variant->session_mac, variant->session_id); + session = get_session_by_id_mac(variant->session_mac, variant->session_id); if (!session) { ASP_LOGD("There's no related session"); goto ERROR; @@ -664,6 +617,7 @@ void asp_process_session_port_status(GDBusConnection *connection, const gchar *object_path, GVariant *parameters) { __ASP_LOG_FUNC_START__; + asp_client_session_s *session = NULL; asp_client_info_s *client = &g_client_info; if (!client->session_port_status_cb) { ASP_LOGE("port_status_cb is NULL!!"); @@ -688,7 +642,7 @@ void asp_process_session_port_status(GDBusConnection *connection, goto ERROR; } - asp_client_session_s *session = get_session_by_id_mac(variant->session_mac, variant->session_id); + session = get_session_by_id_mac(variant->session_mac, variant->session_id); if (!session) { ASP_LOGD("There's no related session"); goto ERROR; @@ -989,50 +943,6 @@ int asp_session_unset_port_status_cb(void) typedef void (*free_func)(void *); -static void __free_advert(void *advert) -{ - __ASP_LOG_FUNC_START__; - asp_client_advert_s *service = NULL; - - service = (asp_client_advert_s *)advert; - if (service == NULL) { - ASP_LOGE("invalid parameter"); - __ASP_LOG_FUNC_END__; - return; - } - - g_free(service->instance_name); - g_free(service->serivce_name); - g_free(service->service_type); - g_free(service->rsp_info); - g_hash_table_destroy(service->service_info_map); - g_free(service); - service = NULL; - __ASP_LOG_FUNC_END__; - return; -} - -static void __free_seek(void *seek) -{ - __ASP_LOG_FUNC_START__; - asp_client_seek_s *service = NULL; - - service = (asp_client_seek_s *)seek; - if (service == NULL) { - ASP_LOGE("invalid parameter"); - __ASP_LOG_FUNC_END__; - return; - } - - g_free(service->serivce_name); - g_free(service->service_type); - g_free(service->rsp_info); - g_hash_table_destroy(service->service_info_map); - g_free(service); - service = NULL; - __ASP_LOG_FUNC_END__; - return; -} static void __free_session(void *session) { @@ -1054,58 +964,6 @@ static void __free_session(void *session) return; } -static asp_client_advert_s *__get_advert(void *handle) -{ - __ASP_LOG_FUNC_START__; - asp_client_advert_s *service = NULL; - GList *temp = NULL; - - if (asp_adverts == NULL) { - __ASP_LOG_FUNC_END__; - return NULL; - } - - ASP_LOGD("service [%p]", handle); - - temp = g_list_first(asp_adverts); - for (temp = g_list_first(asp_adverts); temp != NULL; temp = g_list_next(temp)) { - service = temp->data; - - ASP_LOGD("temp [%p]", service); - if (service != NULL && service == handle) - break; - service = NULL; - } - __ASP_LOG_FUNC_END__; - return service; -} - -static asp_client_seek_s *__get_seek(void *handle) -{ - __ASP_LOG_FUNC_START__; - asp_client_seek_s *service = NULL; - GList *temp = NULL; - - if (asp_seeks == NULL) { - __ASP_LOG_FUNC_END__; - return NULL; - } - - ASP_LOGD("service [%p]", handle); - - temp = g_list_first(asp_seeks); - for (temp = g_list_first(asp_seeks); temp != NULL; temp = g_list_next(temp)) { - service = temp->data; - - ASP_LOGD("temp [%p]", service); - if (service != NULL && service == handle) - break; - service = NULL; - } - __ASP_LOG_FUNC_END__; - return service; -} - static asp_client_session_s *__get_session(void *handle) { __ASP_LOG_FUNC_START__; @@ -1122,7 +980,7 @@ static asp_client_session_s *__get_session(void *handle) temp = g_list_first(asp_sessions); for (temp = g_list_first(asp_sessions); temp != NULL; temp = g_list_next(temp)) { - service = temp->data; + service = (asp_client_session_s *)temp->data; ASP_LOGD("temp [%p]", service); if (service != NULL && service == handle) @@ -1133,42 +991,6 @@ static asp_client_session_s *__get_session(void *handle) return service; } -static int __remove_advert(void *handle) -{ - __ASP_LOG_FUNC_START__; - asp_client_advert_s *service = NULL; - service = __get_advert(handle); - - if (service == NULL) { - __ASP_LOG_FUNC_END__; - return ASP_ERROR_OPERATION_FAILED; - } else { - asp_adverts = g_list_remove(asp_adverts, handle); - __free_advert(service); - } - - __ASP_LOG_FUNC_END__; - return ASP_ERROR_NONE; -} - -static int __remove_seek(void *handle) -{ - __ASP_LOG_FUNC_START__; - asp_client_seek_s *service = NULL; - service = __get_seek(handle); - - if (service == NULL) { - __ASP_LOG_FUNC_END__; - return ASP_ERROR_OPERATION_FAILED; - } else { - asp_seeks = g_list_remove(asp_seeks, handle); - __free_seek(service); - } - - __ASP_LOG_FUNC_END__; - return ASP_ERROR_NONE; -} - static int __remove_session(void *handle) { __ASP_LOG_FUNC_START__; @@ -1198,14 +1020,14 @@ static bool __is_valid_instance_name(char *instance_name) int asp_advert_create(char *instance_name, asp_advert_service_h *adv_service) { __ASP_LOG_FUNC_START__; - asp_client_advert_s *service = NULL; - int res = ASP_ERROR_NONE; + int res = ASP_ERROR_NONE; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); RET_ERR_IF_NOT_INITIALIZED(__ASP_LOG_FUNC_END__); RET_ERR_IF_PARAMETER_IS_NOT_VALID(adv_service, __ASP_LOG_FUNC_END__); - service = (asp_client_advert_s *)g_try_malloc0(sizeof(asp_client_advert_s)); + AspAdvert *service = new AspAdvert; + if (!service) { ASP_LOGE("malloc() failed!!!."); __ASP_LOG_FUNC_END__; @@ -1217,7 +1039,7 @@ int asp_advert_create(char *instance_name, asp_advert_service_h *adv_service) ASP_LOGD("instance_name = [%s]", instance_name); if (!__is_valid_instance_name(instance_name)) { ASP_LOGE("Not valid instance_name"); - g_free(service); + delete service; __ASP_LOG_FUNC_END__; return ASP_ERROR_INVALID_PARAMETER; } @@ -1229,20 +1051,11 @@ int asp_advert_create(char *instance_name, asp_advert_service_h *adv_service) return ASP_ERROR_OUT_OF_MEMORY; } } - asp_adverts = g_list_prepend(asp_adverts, service); - - /* TODO : consider the case if target arch is 64bit. */ - /* TODO : Make asp enable support for other methods. */ - /* Default : ASP */ - service->auto_accept = 0; - service->config_method = 1; - service->status = 0; - service->role = 1; - service->service_info_map = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); - service->adv_id = (unsigned int)service & 0xffffffff; + + addAdvertToServiceList(service); + *adv_service = (asp_advert_service_h)service; ASP_LOGD("asp_advert_create() SUCCESS"); - ASP_LOGD("advert handler [%p]", *adv_service); __ASP_LOG_FUNC_END__; return res; @@ -1251,8 +1064,6 @@ int asp_advert_create(char *instance_name, asp_advert_service_h *adv_service) int asp_advert_destroy(asp_advert_service_h adv_service) { __ASP_LOG_FUNC_START__; - asp_client_advert_s *service = NULL; - int res = ASP_ERROR_NONE; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); RET_ERR_IF_NOT_INITIALIZED(__ASP_LOG_FUNC_END__); @@ -1260,18 +1071,16 @@ int asp_advert_destroy(asp_advert_service_h adv_service) ASP_LOGD("service [%p]", adv_service); - service = __get_advert((void *)adv_service); + AspAdvert *service = getAdvert((void *)adv_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; return ASP_ERROR_SERVICE_NOT_FOUND; } - g_hash_table_remove_all(service->service_info_map); - res = __remove_advert((void *)service); - if (res != ASP_ERROR_NONE) { + if (removeAdvert((void *)service) == false) { __ASP_LOG_FUNC_END__; - return res; + return ASP_ERROR_OPERATION_FAILED; } ASP_LOGD("asp_destory_advertise_handle() SUCCESS"); @@ -1280,121 +1089,29 @@ int asp_advert_destroy(asp_advert_service_h adv_service) return ASP_ERROR_NONE; } -static bool __is_valid_service_type_for_wfds(char *service_type) -{ - int pos = 0; - - /* Wi-Fi Peer-to-Peer Services Technical Specification v1.1 - * The UTF-8 encoded service name (and therefore the contents - * of each service_name parameter) shall be 255 bytes or less - */ - if (strlen(service_type) > MAX_SERVICE_TYPE_LEN) - return false; - - while (service_type[pos] != 0) { - if (!g_ascii_isalpha(service_type[pos]) && - !g_ascii_isdigit(service_type[pos]) && - service_type[pos] != '.' && - service_type[pos] != '-') - return false; - pos++; - } - return true; -} - -static bool __is_valid_service_type(char *service_type) -{ - int srv_name_len = strlen(service_type) - PROTO_LEN - 1; - char *proto; - int pos; - - if (srv_name_len < 2) - return __is_valid_service_type_for_wfds(service_type); - - proto = &(service_type[srv_name_len + 1]); - if (strncmp(proto, "_udp", PROTO_LEN) != 0 && strncmp(proto, "_tcp", PROTO_LEN) != 0) - return __is_valid_service_type_for_wfds(service_type); - - /* Service Type = <_>service_name.<_> - * Service Name description: - * Shall be at least 1 character and no more than 15 characters long - * Shall contain only US-ASCII [ANSI.X3.4-1986] letters 'A' - 'Z' and - * 'a' - 'z', digits '0' - '9', and hyphens ('-', ASCII 0x2D or decimal 45) - * Shall contain at least one letter ('A' - 'Z' or 'a' - ‘z') - * Shall NOT begin or end with a hyphen - */ - - if (srv_name_len > MAX_SERVICE_NAME_LEN + 1) - return false; - - if (service_type[0] != '_' || service_type[1] == '-' || - service_type[srv_name_len] != '.') - return false; - - pos = 1; - while (pos < srv_name_len) { - if (!g_ascii_isalpha(service_type[pos]) && - !g_ascii_isdigit(service_type[pos]) && - service_type[pos] != '-') - return false; - pos++; - } - - return true; -} - int asp_advert_set_service_type(asp_advert_service_h adv_service, char *service_type) { __ASP_LOG_FUNC_START__; - asp_client_advert_s *service = NULL; - char *type = NULL; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); RET_ERR_IF_NOT_INITIALIZED(__ASP_LOG_FUNC_END__); RET_ERR_IF_PARAMETER_IS_NOT_VALID(adv_service, __ASP_LOG_FUNC_END__); RET_ERR_IF_PARAMETER_IS_NOT_VALID(service_type, __ASP_LOG_FUNC_END__); - if (strlen(service_type) == 0) { - ASP_LOGE("Zero length value"); - __ASP_LOG_FUNC_END__; - return ASP_ERROR_INVALID_PARAMETER; - } - - ASP_LOGD("service [%p]", adv_service); - - if (!__is_valid_service_type(service_type)) { - ASP_LOGE("invalid service_type"); - __ASP_LOG_FUNC_END__; - return ASP_ERROR_INVALID_PARAMETER; - } - - service = __get_advert((void *)adv_service); + AspAdvert *service = getAdvert((void *)adv_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; return ASP_ERROR_SERVICE_NOT_FOUND; } - type = g_strdup(service_type); - if (!type) { - ASP_LOGE("malloc() failed!!!."); - __ASP_LOG_FUNC_END__; - return ASP_ERROR_OPERATION_FAILED; - } - g_free(service->service_type); - service->service_type = type; - - ASP_LOGD("asp_advert_set_service_type() SUCCESS"); - - __ASP_LOG_FUNC_END__; - return ASP_ERROR_NONE; + return service->setServiceType(service_type); } int asp_advert_set_auto_accept(asp_advert_service_h adv_service, bool auto_accept) { __ASP_LOG_FUNC_START__; - asp_client_advert_s *service = NULL; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); RET_ERR_IF_NOT_INITIALIZED(__ASP_LOG_FUNC_END__); @@ -1402,7 +1119,7 @@ int asp_advert_set_auto_accept(asp_advert_service_h adv_service, ASP_LOGD("service [%p]", adv_service); - service = __get_advert((void *)adv_service); + AspAdvert *service = getAdvert((void *)adv_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; @@ -1416,27 +1133,10 @@ int asp_advert_set_auto_accept(asp_advert_service_h adv_service, return ASP_ERROR_NONE; } - -static bool __is_valid_key(const char *key) -{ - int pos = 0; - - if (strlen(key) > KEY_LEN) - return false; - - while (key[pos] != 0) { - if (key[pos] < KEY_MIN || key[pos] > KEY_MAX) - return false; - pos++; - } - return true; -} - int asp_advert_add_info(asp_advert_service_h adv_service, const char *key, const char *value) { __ASP_LOG_FUNC_START__; - asp_client_advert_s *service = NULL; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); RET_ERR_IF_NOT_INITIALIZED(__ASP_LOG_FUNC_END__); @@ -1445,32 +1145,21 @@ int asp_advert_add_info(asp_advert_service_h adv_service, ASP_LOGD("service [%p]", adv_service); - if (__is_valid_key(key)) { - ASP_LOGE("invalid key!"); - __ASP_LOG_FUNC_END__; - return ASP_ERROR_INVALID_PARAMETER; - } - service = __get_advert((void *)adv_service); + AspAdvert *service = getAdvert((void *)adv_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; return ASP_ERROR_SERVICE_NOT_FOUND; } - /* TODO: add advertised info */ - g_hash_table_replace(service->service_info_map, g_strdup(key), g_strdup(value)); - - ASP_LOGD("asp_advert_add_info() SUCCESS"); - __ASP_LOG_FUNC_END__; - return ASP_ERROR_NONE; + return service->addInfo(key, value); } int asp_advert_get_info(asp_advert_service_h adv_service, const char *key, int *length, char **value) { __ASP_LOG_FUNC_START__; - asp_client_advert_s *service = NULL; char *ret_val = NULL; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); @@ -1480,14 +1169,14 @@ int asp_advert_get_info(asp_advert_service_h adv_service, const char *key, ASP_LOGD("service [%p]", adv_service); - service = __get_advert((void *)adv_service); + AspAdvert *service = getAdvert((void *)adv_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; return ASP_ERROR_SERVICE_NOT_FOUND; } /* TODO: get advertised info */ - ret_val = g_hash_table_lookup(service->service_info_map, key); + ret_val = (char *)g_hash_table_lookup(service->service_info_map, key); if (ret_val == NULL) { ASP_LOGD("value is NULL"); __ASP_LOG_FUNC_END__; @@ -1506,7 +1195,6 @@ int asp_advert_get_info(asp_advert_service_h adv_service, const char *key, int asp_advert_remove_info(asp_advert_service_h adv_service, const char *key) { __ASP_LOG_FUNC_START__; - asp_client_advert_s *service = NULL; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); RET_ERR_IF_NOT_INITIALIZED(__ASP_LOG_FUNC_END__); @@ -1515,7 +1203,7 @@ int asp_advert_remove_info(asp_advert_service_h adv_service, const char *key) ASP_LOGD("service [%p]", adv_service); - service = __get_advert((void *)adv_service); + AspAdvert *service = getAdvert((void *)adv_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; @@ -1534,7 +1222,6 @@ int asp_advert_set_status(asp_advert_service_h adv_service, unsigned char status) { __ASP_LOG_FUNC_START__; - asp_client_advert_s *service = NULL; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); RET_ERR_IF_NOT_INITIALIZED(__ASP_LOG_FUNC_END__); @@ -1542,7 +1229,7 @@ int asp_advert_set_status(asp_advert_service_h adv_service, ASP_LOGD("service [%p]", adv_service); - service = __get_advert((void *)adv_service); + AspAdvert *service = getAdvert((void *)adv_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; @@ -1559,21 +1246,10 @@ int asp_advert_set_status(asp_advert_service_h adv_service, int asp_advert_set_discovery_tech(asp_advert_service_h adv_service, int discovery_tech) { __ASP_LOG_FUNC_START__; - asp_client_advert_s *service = NULL; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); RET_ERR_IF_NOT_INITIALIZED(__ASP_LOG_FUNC_END__); - if (!((discovery_tech & ASP_DISCOVERY_TECH_P2P) | - (discovery_tech & ASP_DISCOVERY_TECH_NFC) | - (discovery_tech & ASP_DISCOVERY_TECH_BLE) | - (discovery_tech & ASP_DISCOVERY_TECH_INFRA) | - (discovery_tech & ASP_DISCOVERY_TECH_NAN))) { - ASP_LOGE("invalid parameter!"); - __ASP_LOG_FUNC_END__; - return ASP_ERROR_INVALID_PARAMETER; - } - if (!adv_service) { ASP_LOGE("NULL handler!"); __ASP_LOG_FUNC_END__; @@ -1581,25 +1257,19 @@ int asp_advert_set_discovery_tech(asp_advert_service_h adv_service, int discover } ASP_LOGD("service [%p]", adv_service); - service = __get_advert((void *)adv_service); + AspAdvert *service = getAdvert((void *)adv_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; return ASP_ERROR_SERVICE_NOT_FOUND; } - service->discovery_tech = discovery_tech; - - ASP_LOGD("asp_advert_set_discovery_tech() SUCCESS"); - - __ASP_LOG_FUNC_END__; - return ASP_ERROR_NONE; + return service->setDiscoveryTech(discovery_tech); } int asp_advert_set_preferred_connection(asp_advert_service_h adv_service, unsigned char preferred_connection) { __ASP_LOG_FUNC_START__; - asp_client_advert_s *service = NULL; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); RET_ERR_IF_NOT_INITIALIZED(__ASP_LOG_FUNC_END__); @@ -1611,7 +1281,7 @@ int asp_advert_set_preferred_connection(asp_advert_service_h adv_service, } ASP_LOGD("service [%p]", adv_service); - service = __get_advert((void *)adv_service); + AspAdvert *service = getAdvert((void *)adv_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; @@ -1629,7 +1299,6 @@ int asp_advert_set_p2p_role_scheme(asp_advert_service_h adv_service, asp_advert_p2p_role_scheme_e role) { __ASP_LOG_FUNC_START__; - asp_client_advert_s *service = NULL; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); RET_ERR_IF_NOT_INITIALIZED(__ASP_LOG_FUNC_END__); @@ -1641,7 +1310,7 @@ int asp_advert_set_p2p_role_scheme(asp_advert_service_h adv_service, } ASP_LOGD("service [%p]", adv_service); - service = __get_advert((void *)adv_service); + AspAdvert *service = getAdvert((void *)adv_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; @@ -1659,7 +1328,6 @@ int asp_advert_get_p2p_role_scheme(asp_advert_service_h adv_service, asp_advert_p2p_role_scheme_e *role) { __ASP_LOG_FUNC_START__; - asp_client_advert_s *service = NULL; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); RET_ERR_IF_NOT_INITIALIZED(__ASP_LOG_FUNC_END__); @@ -1671,13 +1339,13 @@ int asp_advert_get_p2p_role_scheme(asp_advert_service_h adv_service, } ASP_LOGD("service [%p]", adv_service); - service = __get_advert((void *)adv_service); + AspAdvert *service = getAdvert((void *)adv_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; return ASP_ERROR_SERVICE_NOT_FOUND; } - *role = service->role; + *role = (asp_advert_p2p_role_scheme_e)service->role; ASP_LOGD("asp_advert_get_p2p_role_scheme() SUCCESS"); @@ -1690,7 +1358,6 @@ int asp_advert_set_p2p_config_method(asp_advert_service_h adv_service, asp_wps_type_e config_method) { __ASP_LOG_FUNC_START__; - asp_client_advert_s *service = NULL; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); RET_ERR_IF_NOT_INITIALIZED(__ASP_LOG_FUNC_END__); @@ -1708,7 +1375,7 @@ int asp_advert_set_p2p_config_method(asp_advert_service_h adv_service, } ASP_LOGD("service [%p]", adv_service); - service = __get_advert((void *)adv_service); + AspAdvert *service = getAdvert((void *)adv_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; @@ -1726,7 +1393,6 @@ int asp_advert_get_p2p_config_method(asp_advert_service_h adv_service, asp_wps_type_e *config_method) { __ASP_LOG_FUNC_START__; - asp_client_advert_s *service = NULL; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); RET_ERR_IF_NOT_INITIALIZED(__ASP_LOG_FUNC_END__); @@ -1735,14 +1401,14 @@ int asp_advert_get_p2p_config_method(asp_advert_service_h adv_service, ASP_LOGD("service [%p]", adv_service); - service = __get_advert((void *)adv_service); + AspAdvert *service = getAdvert((void *)adv_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; return ASP_ERROR_SERVICE_NOT_FOUND; } - *config_method = service->config_method; + *config_method = (asp_wps_type_e)service->config_method; ASP_LOGD("asp_advert_get_p2p_config_method() SUCCESS"); @@ -1754,7 +1420,7 @@ int asp_advert_set_p2p_response(asp_advert_service_h adv_service, char *rsp_info, int length) { __ASP_LOG_FUNC_START__; - asp_client_advert_s *service = NULL; + char *info = NULL; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); @@ -1774,7 +1440,7 @@ int asp_advert_set_p2p_response(asp_advert_service_h adv_service, } ASP_LOGD("service [%p]", adv_service); - service = __get_advert((void *)adv_service); + AspAdvert *service = getAdvert((void *)adv_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; @@ -1832,7 +1498,7 @@ static GVariant* __g_hash_table_to_g_variant(GHashTable *hash) g_hash_table_iter_init(&iter, hash); while (g_hash_table_iter_next(&iter, &key, &value)) - g_variant_builder_add(&builder, "{sv}", key, g_variant_new_string(value)); + g_variant_builder_add(&builder, "{sv}", key, g_variant_new_string((const gchar *)value)); __ASP_LOG_FUNC_END__; return g_variant_builder_end(&builder); @@ -1841,7 +1507,7 @@ static GVariant* __g_hash_table_to_g_variant(GHashTable *hash) int asp_advert_start_advertising(asp_advert_service_h adv_service) { __ASP_LOG_FUNC_START__; - asp_client_advert_s *service = NULL; + GVariantBuilder *builder = NULL; GVariant *params = NULL; GError *error = NULL; @@ -1854,7 +1520,7 @@ int asp_advert_start_advertising(asp_advert_service_h adv_service) ASP_LOGD("service [%p]", adv_service); - service = __get_advert((void *)adv_service); + AspAdvert *service = getAdvert((void *)adv_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; @@ -1907,7 +1573,7 @@ int asp_advert_start_advertising(asp_advert_service_h adv_service) int asp_advert_stop_advertising(asp_advert_service_h adv_service) { __ASP_LOG_FUNC_START__; - asp_client_advert_s *service = NULL; + GVariant *params = NULL; GError *error = NULL; GVariant *reply = NULL; @@ -1919,7 +1585,7 @@ int asp_advert_stop_advertising(asp_advert_service_h adv_service) ASP_LOGD("service [%p]", adv_service); - service = __get_advert((void *)adv_service); + AspAdvert *service = getAdvert((void *)adv_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; @@ -1953,7 +1619,7 @@ int asp_advert_change_service_status(asp_advert_service_h adv_service, unsigned char status) { __ASP_LOG_FUNC_START__; - asp_client_advert_s *service = NULL; + GVariantBuilder *builder = NULL; GVariant *params = NULL; GError *error = NULL; @@ -1966,7 +1632,7 @@ int asp_advert_change_service_status(asp_advert_service_h adv_service, ASP_LOGD("service [%p]", adv_service); - service = __get_advert((void *)adv_service); + AspAdvert *service = getAdvert((void *)adv_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; @@ -2019,13 +1685,13 @@ int asp_advert_change_service_status(asp_advert_service_h adv_service, int asp_seek_create(char *service_type, asp_seek_service_h *seek_service) { __ASP_LOG_FUNC_START__; - asp_client_seek_s *service = NULL; + int res = ASP_ERROR_NONE; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); RET_ERR_IF_NOT_INITIALIZED(__ASP_LOG_FUNC_END__); - if (!service_type || strlen(service_type) == 0 || !__is_valid_service_type(service_type)) { + if (!service_type || strlen(service_type) == 0 || !AspUtil::isValidServiceType(service_type)) { ASP_LOGE("NULL Param [service_type]!"); __ASP_LOG_FUNC_END__; return ASP_ERROR_INVALID_PARAMETER; @@ -2039,12 +1705,7 @@ int asp_seek_create(char *service_type, asp_seek_service_h *seek_service) return ASP_ERROR_INVALID_PARAMETER; } - service = (asp_client_seek_s *)g_try_malloc0(sizeof(asp_client_seek_s)); - if (!service) { - ASP_LOGE("malloc() failed!!!."); - __ASP_LOG_FUNC_END__; - return ASP_ERROR_OUT_OF_MEMORY; - } + AspSeek *service = new AspSeek; ASP_LOGD("service [%p]", service); service->service_type = g_strdup(service_type); @@ -2055,12 +1716,10 @@ int asp_seek_create(char *service_type, asp_seek_service_h *seek_service) return ASP_ERROR_OUT_OF_MEMORY; } - service->service_info_map = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); - asp_seeks = g_list_prepend(asp_seeks, service); + addSeekToServiceList(service); *seek_service = (asp_seek_service_h)service; ASP_LOGD("asp_create_seek_handle() SUCCESS"); - ASP_LOGD("seek handler [%p]", *seek_service); __ASP_LOG_FUNC_END__; return res; @@ -2069,8 +1728,6 @@ int asp_seek_create(char *service_type, asp_seek_service_h *seek_service) int asp_seek_destroy(asp_seek_service_h seek_service) { __ASP_LOG_FUNC_START__; - asp_client_seek_s *service = NULL; - int res = ASP_ERROR_NONE; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); RET_ERR_IF_NOT_INITIALIZED(__ASP_LOG_FUNC_END__); @@ -2078,18 +1735,16 @@ int asp_seek_destroy(asp_seek_service_h seek_service) ASP_LOGD("service [%p]", seek_service); - service = __get_seek((void *)seek_service); + AspSeek *service = getSeek((void *)seek_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; return ASP_ERROR_SERVICE_NOT_FOUND; } - g_hash_table_remove_all(service->service_info_map); - res = __remove_seek((void *)service); - if (res != ASP_ERROR_NONE) { + if (removeSeek(service) == false) { __ASP_LOG_FUNC_END__; - return res; + return ASP_ERROR_OPERATION_FAILED; } ASP_LOGD("asp_seek_destroy() SUCCESS"); @@ -2101,7 +1756,7 @@ int asp_seek_destroy(asp_seek_service_h seek_service) int asp_seek_add_info(asp_seek_service_h seek_service, const char *key) { __ASP_LOG_FUNC_START__; - asp_client_seek_s *service = NULL; + int res = ASP_ERROR_NONE; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); @@ -2117,7 +1772,7 @@ int asp_seek_add_info(asp_seek_service_h seek_service, const char *key) ASP_LOGD("service [%p]", seek_service); - service = __get_seek((void *)seek_service); + AspSeek *service = getSeek((void *)seek_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; @@ -2137,7 +1792,7 @@ int asp_seek_add_info(asp_seek_service_h seek_service, const char *key) int asp_seek_remove_info(asp_seek_service_h seek_service, const char *key) { __ASP_LOG_FUNC_START__; - asp_client_seek_s *service = NULL; + int res = ASP_ERROR_NONE; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); @@ -2152,7 +1807,7 @@ int asp_seek_remove_info(asp_seek_service_h seek_service, const char *key) } ASP_LOGD("service [%p]", seek_service); - service = __get_seek((void *)seek_service); + AspSeek *service = getSeek((void *)seek_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; @@ -2172,7 +1827,6 @@ int asp_seek_remove_info(asp_seek_service_h seek_service, const char *key) int asp_seek_set_discovery_tech(asp_seek_service_h seek_service, int discovery_tech) { __ASP_LOG_FUNC_START__; - asp_client_seek_s *service = NULL; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); RET_ERR_IF_NOT_INITIALIZED(__ASP_LOG_FUNC_END__); @@ -2190,7 +1844,7 @@ int asp_seek_set_discovery_tech(asp_seek_service_h seek_service, int discovery_t ASP_LOGD("service [%p]", seek_service); - service = __get_seek((void *)seek_service); + AspSeek *service = getSeek((void *)seek_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; @@ -2208,7 +1862,6 @@ int asp_seek_set_preferred_connection(asp_seek_service_h seek_service, unsigned char preferred_connection) { __ASP_LOG_FUNC_START__; - asp_client_seek_s *service = NULL; CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); RET_ERR_IF_NOT_INITIALIZED(__ASP_LOG_FUNC_END__); @@ -2216,7 +1869,7 @@ int asp_seek_set_preferred_connection(asp_seek_service_h seek_service, ASP_LOGD("service [%p]", seek_service); - service = __get_seek((void *)seek_service); + AspSeek *service = getSeek((void *)seek_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; @@ -2234,7 +1887,7 @@ int asp_seek_set_preferred_connection(asp_seek_service_h seek_service, int asp_seek_start(asp_seek_service_h seek_service) { __ASP_LOG_FUNC_START__; - asp_client_seek_s *service = NULL; + GVariantBuilder *builder = NULL; GVariant *params = NULL; GError *error = NULL; @@ -2247,7 +1900,7 @@ int asp_seek_start(asp_seek_service_h seek_service) ASP_LOGD("service [%p]", seek_service); - service = __get_seek((void *)seek_service); + AspSeek *service = getSeek((void *)seek_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; @@ -2267,7 +1920,7 @@ int asp_seek_start(asp_seek_service_h seek_service) params = g_variant_new("(a{sv})", builder); g_variant_builder_unref(builder); - ASP_LOGI("service name (%s)", service->serivce_name); + ASP_LOGI("service name (%s)", service->service_name); reply = asp_dbus_method_call_sync(ASP_DAEMON_SERVICE_INTERFACE, "SeekService", params, &error); @@ -2293,7 +1946,7 @@ int asp_seek_start(asp_seek_service_h seek_service) int asp_seek_stop(asp_seek_service_h seek_service) { __ASP_LOG_FUNC_START__; - asp_client_seek_s *service = NULL; + GVariant *params = NULL; GError *error = NULL; GVariant *reply = NULL; @@ -2303,7 +1956,7 @@ int asp_seek_stop(asp_seek_service_h seek_service) RET_ERR_IF_NOT_INITIALIZED(__ASP_LOG_FUNC_END__); RET_ERR_IF_PARAMETER_IS_NOT_VALID(seek_service, __ASP_LOG_FUNC_END__); - service = __get_seek((void *)seek_service); + AspSeek *service = getSeek((void *)seek_service); if (service == NULL) { ASP_LOGE("Service NOT registered"); __ASP_LOG_FUNC_END__; @@ -2579,7 +2232,7 @@ int asp_session_get_p2p_role_scheme(asp_session_h session, return ASP_ERROR_SESSION_NOT_FOUND; } - *role = service->network_role; + *role = (asp_advert_p2p_role_scheme_e)service->network_role; ASP_LOGD("asp_session_get_p2p_role_scheme() SUCCESS"); @@ -2639,7 +2292,7 @@ int asp_session_get_p2p_config_method(asp_session_h session, return ASP_ERROR_SESSION_NOT_FOUND; } - *config_method = service->network_config; + *config_method = (asp_wps_type_e)service->network_config; ASP_LOGD("asp_session_get_p2p_config_method() SUCCESS"); diff --git a/src/asp-dbus.c b/src/asp-dbus.cpp similarity index 95% rename from src/asp-dbus.c rename to src/asp-dbus.cpp index 680c03b..f169cc2 100644 --- a/src/asp-dbus.c +++ b/src/asp-dbus.cpp @@ -20,16 +20,16 @@ /** * This file implements asp dbus utility functions. * - * @file asp-dbus.c - * @author Jiung Yu (jiung.yu@samsung.com) - * @version 0.1 + * @file asp-dbus.c + * @author Jiung Yu (jiung.yu@samsung.com) + * @version 0.1 */ #include "asp.h" #include "asp-dbus.h" #include "asp-log.h" -#include "asp-util.h" +#include "asp-defs.h" #include "asp-client.h" const char *service_path = ASP_DAEMON_SERVICE_PATH; @@ -103,8 +103,8 @@ static void _asp_dbus_signal_cb(GDBusConnection *connection, for (i = 0; asp_dbus_signal_map[i].member != NULL; i++) { if (!g_strcmp0(signal, asp_dbus_signal_map[i].member) && - !g_strcmp0(interface, asp_dbus_signal_map[i].interface) && - asp_dbus_signal_map[i].function != NULL) { + !g_strcmp0(interface, asp_dbus_signal_map[i].interface) && + asp_dbus_signal_map[i].function != NULL) { asp_dbus_signal_map[i].function(connection, object_path, parameters); break; } diff --git a/src/asp-seek.cpp b/src/asp-seek.cpp new file mode 100644 index 0000000..a035ad4 --- /dev/null +++ b/src/asp-seek.cpp @@ -0,0 +1,89 @@ +#include "asp-seek.h" +#include "asp-log.h" + +static __thread GList *asp_seeks = NULL; + +AspSeek::AspSeek() +{ + service_name = NULL; + service_type = NULL; + rsp_info = NULL; + service_info_map = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); +} + +AspSeek::~AspSeek() +{ + g_free(service_name); + g_free(service_type); + g_free(rsp_info); + g_hash_table_remove_all(service_info_map); + g_hash_table_destroy(service_info_map); +} + +AspSeek *getSeek(void *handle) +{ + __ASP_LOG_FUNC_START__; + AspSeek *service = NULL; + GList *temp = NULL; + + if (asp_seeks == NULL) { + __ASP_LOG_FUNC_END__; + return NULL; + } + + ASP_LOGD("service [%p]", handle); + + temp = g_list_first(asp_seeks); + for (temp = g_list_first(asp_seeks); temp != NULL; temp = g_list_next(temp)) { + service = (AspSeek *)temp->data; + + ASP_LOGD("temp [%p]", service); + if (service != NULL && service == handle) + break; + service = NULL; + } + __ASP_LOG_FUNC_END__; + return service; +} + +AspSeek *getSeekById(long long unsigned id) +{ + AspSeek *seek = NULL; + GList *temp = NULL; + + for (temp = g_list_first(asp_seeks); + temp != NULL; temp = g_list_next(temp)) { + seek = (AspSeek *)temp->data; + if (seek != NULL && seek->search_id == id) + break; + seek = NULL; + } + + return seek; + +} + +bool removeSeek(void *handle) +{ + AspSeek *service = getSeek(handle); + + if (service == NULL) { + __ASP_LOG_FUNC_END__; + return false; + } + + removeSeekFromServiceList(service); + delete service; + + return true; +} + +void addSeekToServiceList(AspSeek *service) +{ + asp_seeks = g_list_prepend(asp_seeks, service); +} + +void removeSeekFromServiceList(AspSeek *service) +{ + asp_seeks = g_list_remove(asp_seeks, service); +} \ No newline at end of file diff --git a/src/asp-utils.cpp b/src/asp-utils.cpp new file mode 100644 index 0000000..f10f222 --- /dev/null +++ b/src/asp-utils.cpp @@ -0,0 +1,76 @@ +#include "asp-conts.h" +#include "asp-utils.h" +#include + +bool AspUtil::isValidServiceType(const std::string &type) +{ + const char *service_type = type.c_str(); + int srv_name_len = type.size() - PROTO_LEN - 1; + int pos; + + if (srv_name_len < 2) + return isValidServiceTypeForWfds(type); + + const char *proto = &(service_type[srv_name_len + 1]); + if (strncmp(proto, "_udp", PROTO_LEN) != 0 && strncmp(proto, "_tcp", PROTO_LEN) != 0) + return isValidServiceTypeForWfds(type); + + /* Service Type = <_>service_name.<_> + * Service Name description: + * Shall be at least 1 character and no more than 15 characters long + * Shall contain only US-ASCII [ANSI.X3.4-1986] letters 'A' - 'Z' and + * 'a' - 'z', digits '0' - '9', and hyphens ('-', ASCII 0x2D or decimal 45) + * Shall contain at least one letter ('A' - 'Z' or 'a' - ‘z') + * Shall NOT begin or end with a hyphen + */ + + if (srv_name_len > MAX_SERVICE_NAME_LEN + 1) + return false; + + if (service_type[0] != '_' || service_type[1] == '-' || + service_type[srv_name_len] != '.') + return false; + + pos = 1; + while (pos < srv_name_len) { + if (!g_ascii_isalpha(service_type[pos]) && + !g_ascii_isdigit(service_type[pos]) && + service_type[pos] != '-') + return false; + pos++; + } + + return true; +} + +bool AspUtil::isValidServiceTypeForWfds(const std::string &type) +{ + /* Wi-Fi Peer-to-Peer Services Technical Specification v1.1 + * The UTF-8 encoded service name (and therefore the contents + * of each service_name parameter) shall be 255 bytes or less + */ + if (type.size() > MAX_SERVICE_TYPE_LEN) + return false; + + for (auto c : type) { + if (!g_ascii_isalpha(c) && + !g_ascii_isdigit(c) && + c != '.' && + c != '-') + return false; + } + return true; +} + +bool AspUtil::isValidKey(const std::string &key) +{ + if (key.size() > KEY_LEN) + return false; + + for (auto c : key) { + if (c < KEY_MIN || c > KEY_MAX) + return false; + } + + return true; +} diff --git a/src/include/asp-advert.h b/src/include/asp-advert.h new file mode 100644 index 0000000..cc726c9 --- /dev/null +++ b/src/include/asp-advert.h @@ -0,0 +1,37 @@ +#pragma once + +#include +#include + +class AspAdvert { +public: + AspAdvert(); + ~AspAdvert(); + + int setServiceType(const std::string &type); + int addInfo(const std::string &key, const std::string &value); + int setDiscoveryTech(int tech); + + unsigned int adv_id; + long long unsigned search_id; + int auto_accept; + int discovery_tech; + unsigned char preferred_connection; + + unsigned char status; + unsigned char role; + unsigned int config_method; + unsigned char tran_id; + + char *instance_name; + char *serivce_name; + char *service_type; + GHashTable *service_info_map; + char *rsp_info; +}; + +AspAdvert *getAdvert(void *handle); +AspAdvert *getAdvertById(unsigned int id); +bool removeAdvert(void *hahndle); +void addAdvertToServiceList(AspAdvert *service); +void removeAdvertFromServiceList(AspAdvert *service); \ No newline at end of file diff --git a/src/include/asp-client.h b/src/include/asp-client.h index 2abeb43..7e398a4 100755 --- a/src/include/asp-client.h +++ b/src/include/asp-client.h @@ -34,49 +34,6 @@ #define MACSTR_LEN 18 #define ASP_SERVICE_INFO_MAX_LEN 200 -/** - * Application Service Platform(ASP) advertise data structure - */ -typedef struct { - unsigned int adv_id; - long long unsigned search_id; - int auto_accept; - int discovery_tech; - unsigned char preferred_connection; - - unsigned char status; - unsigned char role; - unsigned int config_method; - unsigned char tran_id; - - char *instance_name; - char *serivce_name; - char *service_type; - GHashTable *service_info_map; - char *rsp_info; -} asp_client_advert_s; - -/** - * Application Service Platform(ASP) seek data structure - */ -typedef struct { - unsigned int adv_id; - long long unsigned search_id; - int auto_accept; - int discovery_tech; - unsigned char preferred_connection; - - unsigned char status; - unsigned char role; - unsigned int config_method; - unsigned char tran_id; - - char *serivce_name; - char *service_type; - GHashTable *service_info_map; - char *rsp_info; -} asp_client_seek_s; - /** * Application Service Platform(ASP) session data structure */ diff --git a/src/include/asp-conts.h b/src/include/asp-conts.h new file mode 100644 index 0000000..d48f8d5 --- /dev/null +++ b/src/include/asp-conts.h @@ -0,0 +1,13 @@ +#pragma once + +#define INSTANCE_NAME_LEN 63 +#define MAX_SERVICE_NAME_LEN 15 +#define MAX_SERVICE_TYPE_LEN 255 +#define PROTO_LEN 4 +#define KEY_LEN 9 /* http://files.dns-sd.org/draft-cheshire-dnsext-dns-sd.txt */ +#define KEY_MIN 0x20 /* RFC 20 */ +#define KEY_MAX 0x7E + +#define SERVICE_INFO_LEN 65000 +#define DEFERRED_LEN 144 +#define SESSION_INFO_LEN 144 \ No newline at end of file diff --git a/src/include/asp-dbus.h b/src/include/asp-dbus.h index 013df35..4b8998f 100755 --- a/src/include/asp-dbus.h +++ b/src/include/asp-dbus.h @@ -28,10 +28,6 @@ #ifndef __ASP_DBUS_H__ #define __ASP_DBUS_H__ -#ifdef __cplusplus -extern "C" { -#endif - #include #define ASP_DAEMON_SERVICE "net.asp" @@ -71,8 +67,4 @@ GVariant *asp_dbus_method_call_sync_debug(const char* interface_name, int asp_dbus_unpack_ay(unsigned char *dst, GVariant *src, int size); -#ifdef __cplusplus -} -#endif - #endif /* __ASP_DBUS_H__ */ diff --git a/src/include/asp-util.h b/src/include/asp-defs.h similarity index 100% rename from src/include/asp-util.h rename to src/include/asp-defs.h diff --git a/src/include/asp-seek.h b/src/include/asp-seek.h new file mode 100644 index 0000000..e97caea --- /dev/null +++ b/src/include/asp-seek.h @@ -0,0 +1,31 @@ +#pragma once + +#include + +class AspSeek { +public: + AspSeek(); + ~AspSeek(); + unsigned int adv_id; + long long unsigned search_id; + int auto_accept; + int discovery_tech; + unsigned char preferred_connection; + + unsigned char status; + unsigned char role; + unsigned int config_method; + unsigned char tran_id; + + char *service_name; + char *service_type; + GHashTable *service_info_map; + char *rsp_info; +}; + +AspSeek *getSeek(void *handle); +AspSeek *getSeekById(long long unsigned id); + +bool removeSeek(void *handle); +void addSeekToServiceList(AspSeek *service); +void removeSeekFromServiceList(AspSeek *service); diff --git a/src/include/asp-utils.h b/src/include/asp-utils.h new file mode 100644 index 0000000..00125e5 --- /dev/null +++ b/src/include/asp-utils.h @@ -0,0 +1,10 @@ +#pragma once + +#include + +class AspUtil { +public: + static bool isValidServiceType(const std::string &type); + static bool isValidServiceTypeForWfds(const std::string &type); + static bool isValidKey(const std::string &key); +}; \ No newline at end of file diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 175903e..e394903 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -10,7 +10,15 @@ 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) +FILE(GLOB GTEST_SRCS *.cpp ${CMAKE_SOURCE_DIR}/src/*.cpp mock/*.cpp) ADD_EXECUTABLE(${ASP_GTEST} ${GTEST_SRCS}) TARGET_LINK_LIBRARIES(${ASP_GTEST} ${gtest_pkgs_LIBRARIES} ${${fw_name}_LIBRARIES}) + +SET_TARGET_PROPERTIES(${ASP_GTEST} PROPERTIES + COMPILE_FLAGS "-fPIE" + LINK_FLAGS "-Wl,\ +--wrap=asp_dbus_init,\ +--wrap=asp_dbus_deinit,\ +--wrap=system_info_get_platform_bool") + INSTALL(TARGETS ${ASP_GTEST} DESTINATION bin/) diff --git a/unittest/asp-gtest-advert.cpp b/unittest/asp-gtest-advert.cpp new file mode 100644 index 0000000..fa2c6f3 --- /dev/null +++ b/unittest/asp-gtest-advert.cpp @@ -0,0 +1,105 @@ +#include + +#include "asp.h" +#include "asp-advert.h" + +class AspAdvertTest: public ::testing::Test { +protected: + void SetUp() override + { + mAdvert = new AspAdvert; + } + + void TearDown() override + { + delete mAdvert; + } + + AspAdvert *mAdvert; +}; + +TEST_F(AspAdvertTest, getAdvertP) +{ + AspAdvert *advert = new AspAdvert; + addAdvertToServiceList(advert); + EXPECT_EQ(advert, getAdvert(advert)); + removeAdvertFromServiceList(advert); + delete advert; +} + +TEST_F(AspAdvertTest, getAdvertN) +{ + AspAdvert *advert = new AspAdvert; + EXPECT_EQ(NULL, getAdvert(advert)); + EXPECT_EQ(NULL, getAdvert(NULL)); + delete advert; +} + + +TEST_F(AspAdvertTest, addRemoveP1) +{ + AspAdvert *advert = new AspAdvert; + addAdvertToServiceList(advert); + EXPECT_EQ(true, removeAdvert(advert)); +} + +TEST_F(AspAdvertTest, addRemoveP2) +{ + AspAdvert *advert = new AspAdvert; + addAdvertToServiceList(advert); + removeAdvertFromServiceList(advert); + EXPECT_EQ(NULL, removeAdvert(advert)); + delete advert; +} + +TEST_F(AspAdvertTest, addRemoveP) +{ + AspAdvert *advert = new AspAdvert; + EXPECT_EQ(false, removeAdvert(advert)); + delete advert; +} + +TEST_F(AspAdvertTest, setServiceTypeP) +{ + EXPECT_EQ(ASP_ERROR_NONE, mAdvert->setServiceType("_http._tcp")); + EXPECT_EQ(ASP_ERROR_NONE, mAdvert->setServiceType("_test._udp")); + EXPECT_EQ(ASP_ERROR_NONE, mAdvert->setServiceType("abcde12345")); +} + +TEST_F(AspAdvertTest, setServiceTypeN) +{ + EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, mAdvert->setServiceType("")); + EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, mAdvert->setServiceType("__")); +} + +TEST_F(AspAdvertTest, addInfoP) +{ + EXPECT_EQ(ASP_ERROR_NONE, mAdvert->addInfo("12345678", "VALUE")); + EXPECT_EQ(ASP_ERROR_NONE, mAdvert->addInfo("abcdefg", "VALUE")); + EXPECT_EQ(ASP_ERROR_NONE, mAdvert->addInfo("!@#$%^&*", "VALUE")); +} + +TEST_F(AspAdvertTest, addInfoN) +{ + EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, mAdvert->addInfo("1234567890", "VALUE")); + EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, mAdvert->addInfo("abcdefghij", "VALUE")); + EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, mAdvert->addInfo("!@#$%^&*()", "VALUE")); +} + +TEST_F(AspAdvertTest, setDiscoveryTechP) +{ + EXPECT_EQ(ASP_ERROR_NONE, mAdvert->setDiscoveryTech(ASP_DISCOVERY_TECH_P2P)); + EXPECT_EQ(ASP_ERROR_NONE, mAdvert->setDiscoveryTech(ASP_DISCOVERY_TECH_NFC)); + EXPECT_EQ(ASP_ERROR_NONE, mAdvert->setDiscoveryTech(ASP_DISCOVERY_TECH_BLE)); + EXPECT_EQ(ASP_ERROR_NONE, mAdvert->setDiscoveryTech(ASP_DISCOVERY_TECH_INFRA)); + EXPECT_EQ(ASP_ERROR_NONE, mAdvert->setDiscoveryTech(ASP_DISCOVERY_TECH_NAN)); + + int tech = ASP_DISCOVERY_TECH_P2P | ASP_DISCOVERY_TECH_NFC | ASP_DISCOVERY_TECH_BLE + | ASP_DISCOVERY_TECH_INFRA | ASP_DISCOVERY_TECH_NAN; + EXPECT_EQ(ASP_ERROR_NONE, mAdvert->setDiscoveryTech(tech)); +} + +TEST_F(AspAdvertTest, setDiscoveryTechN) +{ + EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, mAdvert->setDiscoveryTech(0)); +} diff --git a/unittest/asp-gtest-client.cpp b/unittest/asp-gtest-client.cpp new file mode 100644 index 0000000..e632f6e --- /dev/null +++ b/unittest/asp-gtest-client.cpp @@ -0,0 +1,61 @@ +#include +#include + +#include "asp.h" + +extern "C" { +} + +class AspClientTest: public ::testing::Test { +protected: + void SetUp() override + { + asp_initialize(); + } + + void TearDown() override + { + asp_deinitialize(); + } + + char *INSTANCE_NAME = "INSTANCE"; + char *SERVICE_TYPE = "SERVICE"; +}; + +TEST_F(AspClientTest, asp_advert_createP) +{ + asp_advert_service_h service; + EXPECT_EQ(ASP_ERROR_NONE, asp_advert_create(INSTANCE_NAME, &service)); +} + +TEST_F(AspClientTest, asp_advert_destroyP) +{ + asp_advert_service_h service; + asp_advert_create(INSTANCE_NAME, &service); + EXPECT_EQ(ASP_ERROR_NONE, asp_advert_destroy(service)); +} + +TEST_F(AspClientTest, asp_advert_destroyN) +{ + EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_advert_destroy(NULL)); + EXPECT_EQ(ASP_ERROR_SERVICE_NOT_FOUND, asp_advert_destroy((asp_advert_service_h)0x01)); +} + +TEST_F(AspClientTest, asp_seek_createP) +{ + asp_seek_service_h service; + EXPECT_EQ(ASP_ERROR_NONE, asp_seek_create(SERVICE_TYPE, &service)); +} + +TEST_F(AspClientTest, asp_seek_destroyP) +{ + asp_seek_service_h service; + asp_seek_create(SERVICE_TYPE, &service); + EXPECT_EQ(ASP_ERROR_NONE, asp_seek_destroy(service)); +} + +TEST_F(AspClientTest, asp_seek_destroyN) +{ + EXPECT_EQ(ASP_ERROR_INVALID_PARAMETER, asp_seek_destroy(NULL)); + EXPECT_EQ(ASP_ERROR_SERVICE_NOT_FOUND, asp_seek_destroy((asp_seek_service_h)0x01)); +} \ No newline at end of file diff --git a/unittest/asp-gtest-seek.cpp b/unittest/asp-gtest-seek.cpp new file mode 100644 index 0000000..d4176d9 --- /dev/null +++ b/unittest/asp-gtest-seek.cpp @@ -0,0 +1,55 @@ +#include + +#include "asp-seek.h" + +class AspSeekTest: public ::testing::Test { +protected: + void SetUp() override + { + } + + void TearDown() override + { + } +}; + +TEST_F(AspSeekTest, getSeekP) +{ + AspSeek *seek = new AspSeek; + addSeekToServiceList(seek); + EXPECT_EQ(seek, getSeek(seek)); + removeSeekFromServiceList(seek); + delete seek; +} + +TEST_F(AspSeekTest, getSeekN) +{ + AspSeek *seek = new AspSeek; + EXPECT_EQ(NULL, getSeek(seek)); + EXPECT_EQ(NULL, getSeek(NULL)); + delete seek; +} + + +TEST_F(AspSeekTest, addRemoveP1) +{ + AspSeek *seek = new AspSeek; + addSeekToServiceList(seek); + EXPECT_EQ(true, removeSeek(seek)); +} + +TEST_F(AspSeekTest, addRemoveP2) +{ + AspSeek *seek = new AspSeek; + addSeekToServiceList(seek); + removeSeekFromServiceList(seek); + EXPECT_EQ(NULL, removeSeek(seek)); + delete seek; +} + +TEST_F(AspSeekTest, addRemoveP) +{ + AspSeek *seek = new AspSeek; + EXPECT_EQ(false, removeSeek(seek)); + delete seek; +} diff --git a/unittest/asp-gtest-util.cpp b/unittest/asp-gtest-util.cpp new file mode 100644 index 0000000..35d18c9 --- /dev/null +++ b/unittest/asp-gtest-util.cpp @@ -0,0 +1,56 @@ +#include + +#include "asp.h" +#include "asp-utils.h" + +class AspUtilTest: public ::testing::Test { +protected: + void SetUp() override + { + } + + void TearDown() override + { + } + +}; + +TEST_F(AspUtilTest, isValidServiceTypeP) +{ + EXPECT_EQ(true, AspUtil::isValidServiceType("_http._tcp")); + EXPECT_EQ(true, AspUtil::isValidServiceType("_test._udp")); + EXPECT_EQ(true, AspUtil::isValidServiceType("abcde12345")); +} + +TEST_F(AspUtilTest, isValidServiceTypeN) +{ + EXPECT_EQ(false, AspUtil::isValidServiceType("__")); +} + +TEST_F(AspUtilTest, isValidServiceTypeForWfdsP) +{ + EXPECT_EQ(true, AspUtil::isValidServiceTypeForWfds("abcdef")); + EXPECT_EQ(true, AspUtil::isValidServiceType(".....")); + EXPECT_EQ(true, AspUtil::isValidServiceType("-----")); +} + +TEST_F(AspUtilTest, isValidServiceTypeForWfdsN) +{ + EXPECT_EQ(false, AspUtil::isValidServiceTypeForWfds("__")); + EXPECT_EQ(false, AspUtil::isValidServiceTypeForWfds("**")); + EXPECT_EQ(false, AspUtil::isValidServiceTypeForWfds("abcd**efg")); +} + +TEST_F(AspUtilTest, isValidKeyP) +{ + EXPECT_EQ(true, AspUtil::isValidKey("12345678")); + EXPECT_EQ(true, AspUtil::isValidKey("abcdefg")); + EXPECT_EQ(true, AspUtil::isValidKey("!@#$%^&*")); +} + +TEST_F(AspUtilTest, isValidKeyN) +{ + EXPECT_EQ(false, AspUtil::isValidKey("1234567890")); + EXPECT_EQ(false, AspUtil::isValidKey("abcdefghij")); + EXPECT_EQ(false, AspUtil::isValidKey("!@#$%^&*()")); +} diff --git a/unittest/mock/mock-asp-dbus.cpp b/unittest/mock/mock-asp-dbus.cpp new file mode 100644 index 0000000..d0d5101 --- /dev/null +++ b/unittest/mock/mock-asp-dbus.cpp @@ -0,0 +1,13 @@ +#ifndef API +#define API __attribute__ ((visibility("default"))) +#endif + +API int __wrap_asp_dbus_init() +{ + return 1; +} + +API int __wrap_asp_dbus_deinit() +{ + return 1; +} \ No newline at end of file diff --git a/unittest/mock/mock-system-info.cpp b/unittest/mock/mock-system-info.cpp new file mode 100644 index 0000000..c106106 --- /dev/null +++ b/unittest/mock/mock-system-info.cpp @@ -0,0 +1,17 @@ +#ifndef API +#define API __attribute__ ((visibility("default"))) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +API int __wrap_system_info_get_platform_bool (const char *key, bool *value) +{ + *value = true; + return 0; +} + +#ifdef __cplusplus +} +#endif \ No newline at end of file -- 2.34.1