CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(asp-manager C)
+PROJECT(asp-manager C CXX)
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
ENDFOREACH(flag)
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fpic -Wall -Werror-implicit-function-declaration -fvisibility=hidden")
+IF(BUILD_GTESTS)
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fpic -Wall -Werror-implicit-function-declaration -fvisibility=hidden")
+ELSE(BUILD_GTESTS)
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fpic -Wall -Werror-implicit-function-declaration")
+ENDIF(BUILD_GTESTS)
SET(ARM_CFLAGS "${ARM_CFLAGS} -mapcs -mabi=aapcs-linux -msoft-float -Uarm -fpic")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(interfaces)
+
+IF(BUILD_GTESTS)
+ ADD_SUBDIRECTORY(unittest)
+ENDIF(BUILD_GTESTS)
+
Name: asp-manager
Summary: ASP(application service platform) manager
-Version: 0.0.27
+Version: 0.0.28
Release: 1
Group: Network & Connectivity/Other
License: Apache-2.0
BuildRequires: python-xml
Requires: security-config
+%if 0%{?gtests:1}
+BuildRequires: pkgconfig(gmock)
+%endif
+
%description
An application service platform manager to manage services and sessions
export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
%cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \
+-DBUILD_GTESTS=%{?gtests:1}%{!?gtests:0} \
-DBIN_DIR=%{_bindir}
make %{?_smp_mflags}
%license LICENSE
%defattr(-,network_fw,network_fw,-)
%attr(500,network_fw,network_fw) %{_bindir}/*
+%if 0%{?gtests:1}
+ %{_bindir}/gtest-asp-manager
+%endif
#DBus DAC
%attr(644,root,root) %{_sysconfdir}/dbus-1/system.d/asp-manager.conf
--- /dev/null
+# Copyright (c) 2014-2015 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.
+#
+# @file CMakeLists.txt
+#
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+SET(GTEST_TEST "gtest-asp-manager")
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(gtest_pkgs REQUIRED glib-2.0 gmock)
+
+INCLUDE_DIRECTORIES(${gtest_pkgs_INCLUDE_DIRS})
+LINK_DIRECTORIES(${gtest_pkgs_LIBRARY_DIRS})
+
+INCLUDE_DIRECTORIES(${asp_pkgs_INCLUDE_DIRS})
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/interfaces)
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/unittest)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpie")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpie")
+
+SET(SRCS
+ ${CMAKE_SOURCE_DIR}/src/asp-manager.c
+ ${CMAKE_SOURCE_DIR}/src/asp-manager-event.c
+ ${CMAKE_SOURCE_DIR}/src/asp-manager-gdbus.c
+ ${CMAKE_SOURCE_DIR}/src/asp-manager-util.c
+ ${CMAKE_SOURCE_DIR}/interfaces/generated-code.c
+ )
+
+SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/interfaces/generated-code.c PROPERTIES GENERATED TRUE)
+
+FILE(GLOB SERVICE_SRCS ${CMAKE_SOURCE_DIR}/src/service/*.c)
+FILE(GLOB SESSION_SRCS ${CMAKE_SOURCE_DIR}/src/session/*.c)
+FILE(GLOB TECH_SRCS ${CMAKE_SOURCE_DIR}/src/tech/*.c)
+FILE(GLOB GTEST_SRCS
+ ${CMAKE_SOURCE_DIR}/unittest/*.cpp
+ ${CMAKE_SOURCE_DIR}/unittest/service/*.cpp
+ ${CMAKE_SOURCE_DIR}/unittest/session/*.cpp
+ )
+
+ADD_DEFINITIONS("-DUSE_DLOG")
+
+ADD_EXECUTABLE(${GTEST_TEST} ${SRCS} ${SERVICE_SRCS} ${SESSION_SRCS} ${TECH_SRCS} ${GTEST_SRCS})
+ADD_DEPENDENCIES(${GTEST_TEST} GENERATED_DBUS_CODE)
+
+TARGET_LINK_LIBRARIES(${GTEST_TEST} ${gtest_pkgs_LIBRARIES} ${asp_pkgs_LDFLAGS} -ldl)
+
+INSTALL(TARGETS ${GTEST_TEST} RUNTIME DESTINATION ${BIN_DIR})
--- /dev/null
+#ifndef __ASP_MANAGER_FIXTURE_H__
+#define __ASP_MANAGER_FIXTURE_H__
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "asp-manager.h"
+
+class AspManager : public ::testing::Test
+{
+protected:
+ virtual void SetUp() {
+ asp_manager_load();
+ }
+
+ virtual void TearDown() {
+ asp_manager_unload();
+ }
+};
+
+#endif
--- /dev/null
+#ifndef __ASP_MANAGER_TEST_UTIL_H__
+#define __ASP_MANAGER_TEST_UTIL_H__
+
+#include <dlog.h>
+
+#include "asp-manager-util.h"
+
+//#undef LOG_TAG
+//#define LOG_TAG "ASP_MANAGER_TEST"
+
+#define __ASP_MANAGER_TEST_ENTER__ ASP_LOGD("Testcase %s Start", __PRETTY_FUNCTION__)
+#define __ASP_MANAGER_TEST_EXIT__ ASP_LOGD("Testcase %s Done", __PRETTY_FUNCTION__)
+
+#endif
--- /dev/null
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "asp-manager.h"
+
+using ::testing::EmptyTestEventListener;
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+using ::testing::TestEventListeners;
+using ::testing::TestInfo;
+using ::testing::TestPartResult;
+using ::testing::UnitTest;
+
+TEST(asp_manager, __asp_manager_load_unload_p)
+{
+ int ret = 0;
+ ret = asp_manager_load();
+ ASSERT_EQ(ret, 0);
+ asp_manager_unload();
+ ASSERT_TRUE(1);
+}
--- /dev/null
+#include "asp-service-factory.h"
+
+#define CONVERT_TECH(a) (1 << ((a) - 1))
+asp_service_advertise_s*
+ServiceFactory::CreateAdvertiseService(asp_tech_e tech)
+{
+ asp_service_advertise_s* service = new asp_service_advertise_s;
+// SetP2PService(service);
+ switch (tech) {
+ case ASP_TECH_P2P:
+ SetP2PService(service);
+ break;
+ case ASP_TECH_INFRA:
+ SetInfraService(service);
+ break;
+ default:
+ ReleaseAdvertiseService(service);
+ return NULL;
+ }
+ return service;
+}
+
+void
+ServiceFactory::SetP2PService(asp_service_advertise_s* service)
+{
+ service->adv_id = 0;
+ service->discovery_tech = CONVERT_TECH(ASP_TECH_P2P);
+ service->preferred_connection = CONVERT_TECH(ASP_TECH_P2P);
+ service->auto_accept = 1;
+ service->status = 0;
+ service->role = ASP_SERVICE_P2P_ROLE_NEW;
+ service->config_method = 0;
+ service->instance_name = g_strdup("test_service_name");
+ service->service_type = g_strdup("_http._tcp");
+ // service->service_info_map --> g_hash_table
+ // service->rsp_info --> string
+}
+
+void
+ServiceFactory::SetInfraService(asp_service_advertise_s* service)
+{
+ service->adv_id = 0;
+ service->discovery_tech = CONVERT_TECH(ASP_TECH_INFRA);
+ service->preferred_connection = CONVERT_TECH(ASP_TECH_P2P);
+ service->auto_accept = 1;
+ service->status = 0;
+ service->config_method = 0;
+ service->instance_name = g_strdup("test_service_name");
+ service->service_type = g_strdup("_http._tcp");
+ // service->service_info_map --> g_hash_table
+ // service->rsp_info --> string
+}
+
+void
+ServiceFactory::ReleaseAdvertiseService(asp_service_advertise_s* service)
+{
+ g_free(service->instance_name);
+ g_free(service->service_type);
+
+ delete service;
+}
+
+asp_service_seek_s*
+ServiceFactory::CreateSeekService(asp_tech_e tech)
+{
+ asp_service_seek_s* service = new asp_service_seek_s;
+// SetP2PService(service);
+ switch (tech) {
+ case ASP_TECH_P2P:
+ SetP2PService(service);
+ break;
+ case ASP_TECH_INFRA:
+ SetInfraService(service);
+ break;
+ default:
+ ReleaseSeekService(service);
+ return NULL;
+ }
+ return service;
+}
+
+void
+ServiceFactory::SetP2PService(asp_service_seek_s* service)
+{
+ service->discovery_tech = CONVERT_TECH(ASP_TECH_P2P);
+ service->preferred_connection = CONVERT_TECH(ASP_TECH_P2P);
+ service->status = 0;
+ service->config_method = 0;
+ service->service_type = g_strdup("_http._tcp");
+ // service->service_info_map --> g_hash_table
+ // service->rsp_info --> string
+}
+
+void
+ServiceFactory::SetInfraService(asp_service_seek_s* service)
+{
+ service->discovery_tech = CONVERT_TECH(ASP_TECH_INFRA);
+ service->preferred_connection = CONVERT_TECH(ASP_TECH_INFRA);
+ service->status = 0;
+ service->service_type = g_strdup("_http._tcp");
+ // service->service_info_map --> g_hash_table
+ // service->rsp_info --> string
+}
+
+void
+ServiceFactory::ReleaseSeekService(asp_service_seek_s* service)
+{
+ g_free(service->service_type);
+
+ delete service;
+}
+
--- /dev/null
+#ifndef __ASP_SERVICE_FACTORY_H__
+#define __ASP_SERVICE_FACTORY_H__
+
+#include "asp-service.h"
+#include "asp-tech.h"
+
+class ServiceFactory
+{
+public:
+ static asp_service_advertise_s* CreateAdvertiseService(asp_tech_e tech);
+ static void ReleaseAdvertiseService(asp_service_advertise_s* service);
+
+ static asp_service_seek_s* CreateSeekService(asp_tech_e tech);
+ static void ReleaseSeekService(asp_service_seek_s* service);
+private:
+ static void SetP2PService(asp_service_advertise_s* service);
+ static void SetInfraService(asp_service_advertise_s* service);
+ static void SetP2PService(asp_service_seek_s* service);
+ static void SetInfraService(asp_service_seek_s* service);
+};
+#endif
--- /dev/null
+#ifndef __ASP_SERVICE_FIXTURE_H__
+#define __ASP_SERVICE_FIXTURE_H__
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "asp-manager-fixture.h"
+class AspManager_AspService : public AspManager
+{
+ /*
+private:
+ asp_s *manager = NULL;
+ GMainLoop *main_loop = NULL;
+ */
+protected:
+ virtual void SetUp() {
+ AspManager::SetUp();
+ /*
+ manager = asp_get_manager();
+ if (!manager) {
+ ASP_LOGE("Failed to get asp_s");
+ return;
+ }
+ main_loop = g_main_loop_new(NULL, FALSE);
+ manager->main_loop = main_loop;
+ g_main_loop_run(main_loop);
+ */
+ }
+
+ virtual void TearDown() {
+ AspManager::TearDown();
+// g_main_loop_unref(main_loop);
+ }
+};
+
+#endif
--- /dev/null
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include <glib.h>
+
+#include "asp-service.h"
+#include "asp-tech.h"
+#include "asp-manager-util.h"
+
+#include "asp-service-fixture.h"
+#include "asp-service-factory.h"
+#include "asp-manager-test-util.h"
+
+using ::testing::EmptyTestEventListener;
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+using ::testing::TestEventListeners;
+using ::testing::TestInfo;
+using ::testing::TestPartResult;
+using ::testing::UnitTest;
+
+TEST_F(AspManager_AspService, asp_service_init_deinit_p)
+{
+ __ASP_MANAGER_TEST_ENTER__;
+ int ret = 0;
+ ret = asp_service_init();
+ ASSERT_EQ(ret, ASP_ERROR_NONE) << "FAIL asp_service_init " << ret;
+ asp_service_deinit();
+ __ASP_MANAGER_TEST_EXIT__;
+}
+
+TEST_F(AspManager_AspService, asp_service_advertise_infra_p)
+{
+ __ASP_MANAGER_TEST_ENTER__;
+ int ret = 0;
+ asp_service_advertise_s* service = ServiceFactory::CreateAdvertiseService(ASP_TECH_INFRA);
+ ASSERT_TRUE(service) << "FAIL asp_service_advertise_s " << ret;
+
+ ret = asp_service_advertise(service, 0);
+ ASSERT_GE(ret, ASP_ERROR_NONE) << "FAIL asp_service_advertise " << ret;
+
+ ret = asp_service_cancel_advertise(service);
+ ASSERT_EQ(ret, ASP_ERROR_NONE) << "FAIL asp_service_cancel_advertise " << ret;
+
+ ServiceFactory::ReleaseAdvertiseService(service);
+ __ASP_MANAGER_TEST_EXIT__;
+}
+
+TEST_F(AspManager_AspService, asp_service_seek_infra_p)
+{
+ __ASP_MANAGER_TEST_ENTER__;
+ int ret = 0;
+ guint64 search_id = 0;
+ asp_service_seek_s* service = ServiceFactory::CreateSeekService(ASP_TECH_INFRA);
+ ASSERT_TRUE(service) << "FAIL CreateSeekService";
+
+ ret = asp_service_seek(service, &search_id);
+ ASSERT_GE(ret, ASP_ERROR_NONE) << "FAIL asp_service_seek " << ret;
+ ASSERT_GE(search_id, 0) << "FAIL invalid search_id " << search_id;
+
+ ret = asp_service_cancel_seek(service);
+ ASSERT_EQ(ret, ASP_ERROR_NONE) << "FAIL asp_service_cancel_seek";
+
+ ServiceFactory::ReleaseSeekService(service);
+ __ASP_MANAGER_TEST_EXIT__;
+}
+
+TEST_F(AspManager_AspService, asp_service_notify_advertise_status_p)
+{
+ __ASP_MANAGER_TEST_ENTER__;
+ int ret = 0;
+ int adv_id = 1;
+ asp_service_advertise_status_e status = ASP_SERVICE_ADV_STATUS_ADVERTISED;
+ asp_service_advertise_reason_e reason = ASP_SERVICE_ADVERTISE_REASON_SUCCESS;
+
+ ret = asp_service_notify_advertise_status(adv_id, status, reason);
+ ASSERT_EQ(ret, ASP_ERROR_NONE) << "FAIL asp_service_notify_advertise_status (ADVERTISED) " << ret;
+
+ status = ASP_SERVICE_ADV_STATUS_NOT_ADVERTISED;
+ reason = ASP_SERVICE_ADVERTISE_REASON_OTHER;
+ ret = asp_service_notify_advertise_status(adv_id, status, reason);
+ ASSERT_EQ(ret, ASP_ERROR_NONE) << "FAIL asp_service_notify_advertise_status (NOT_ADVERTISED) " << ret;
+
+ __ASP_MANAGER_TEST_EXIT__;
+}
+
+TEST_F(AspManager_AspService, asp_service_notify_search_result_p)
+{
+ __ASP_MANAGER_TEST_ENTER__;
+ int ret = 0;
+ int search_id = 1;
+ int adv_id = 1;
+ char service_mac[20] = "12:34:56:78:90:ab";
+ char instance_name[10] = "service";
+ char device[10] = "dev";
+ asp_service_status_e status = ASP_SERVICE_STATUS_AVAILABLE;
+
+ ret = asp_service_notify_search_result(search_id, service_mac,
+ device, adv_id, instance_name, NULL, status);
+ ASSERT_EQ(ret, ASP_ERROR_NONE) << "FAIL asp_service_notify_search_result " << ret;
+ __ASP_MANAGER_TEST_EXIT__;
+}
+
--- /dev/null
+#ifndef __ASP_SERVICE_FIXTURE_H__
+#define __ASP_SERVICE_FIXTURE_H__
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "asp-manager-fixture.h"
+class AspManager_AspSession : public AspManager
+{
+protected:
+ virtual void SetUp() {
+ AspManager::SetUp();
+ }
+
+ virtual void TearDown() {
+ AspManager::TearDown();
+ }
+};
+
+#endif
--- /dev/null
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include <glib.h>
+
+#include "asp-session.h"
+#include "asp-tech.h"
+#include "asp-manager-util.h"
+
+#include "asp-session-fixture.h"
+#include "asp-manager-test-util.h"
+
+#define MAC_LEN 6
+#define MACSTR_LEN 17
+
+using ::testing::EmptyTestEventListener;
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+using ::testing::TestEventListeners;
+using ::testing::TestInfo;
+using ::testing::TestPartResult;
+using ::testing::UnitTest;
+
+TEST(asp_session, asp_session_init_deinit_p)
+{
+ __ASP_MANAGER_TEST_ENTER__;
+
+ gboolean ret = false;
+ ret = asp_session_initialize();
+ ASSERT_TRUE(ret) << "FAIL asp_session_initialize";
+ ret = asp_session_deinitialize();
+ ASSERT_TRUE(ret) << "FAIL asp_session_deinitialize";
+
+ __ASP_MANAGER_TEST_EXIT__;
+}
+
+TEST_F(AspManager_AspSession, asp_session_connect_session_over_p2p_p)
+{
+ __ASP_MANAGER_TEST_ENTER__;
+
+ gboolean ret = false;
+ guint8 service_mac[MAC_LEN] = {0, };
+ gchar service_mac_str[MACSTR_LEN + 1] = "12:34:56:78:90:ab";
+ guint32 adv_id = 1;
+ guint8* session_info = NULL;
+ size_t info_length = 0;
+ guint8 network_role = 0;
+ guint8 network_config = 0;
+ guint8 session_mac[MAC_LEN] = {0, };
+ gchar session_mac_str[MACSTR_LEN + 1] = "ab:cd:ef:12:34:56";
+ guint32 p_session_id;
+ macaddr_atoe(service_mac_str, service_mac);
+ macaddr_atoe(session_mac_str, session_mac);
+ ret = asp_session_connect_session_over_p2p(
+ service_mac,
+ adv_id,
+ session_info,
+ info_length,
+ network_role,
+ network_config,
+ session_mac,
+ &p_session_id);
+ ASSERT_TRUE(ret) << "FAIL asp_session_connect_session_over_p2p";;
+}
--- /dev/null
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include "asp-manager.h"
+
+using ::testing::EmptyTestEventListener;
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+using ::testing::TestEventListeners;
+using ::testing::TestInfo;
+using ::testing::TestPartResult;
+using ::testing::UnitTest;
+
+int main(int argc, char **argv)
+{
+ InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}