Added Haltest for zigbee-manager 06/186106/3 accepted/tizen/unified/20180813.152517 submit/tizen/20180813.055629
authorAbhishek Sansanwal <abhishek.s94@samsung.com>
Tue, 7 Aug 2018 08:55:31 +0000 (14:25 +0530)
committerAbhishek Sansanwal <abhishek.s94@samsung.com>
Fri, 10 Aug 2018 09:14:20 +0000 (14:44 +0530)
Signed-off-by: Abhishek Sansanwal <abhishek.s94@samsung.com>
Change-Id: I59d59c6ae328b9b372d2ca106b90be0f9a67a884

CMakeLists.txt
haltest/CMakeLists.txt [new file with mode: 0644]
haltest/common.h [new file with mode: 0644]
haltest/gdbus.cpp [new file with mode: 0644]
haltest/gdbus.h [new file with mode: 0644]
haltest/zbl.cpp [new file with mode: 0644]
haltest/zbl.h [new file with mode: 0644]
haltest/zigbee_manager_hal_tc.cpp [new file with mode: 0644]
packaging/zigbee-manager.spec

index 329ad66..24cdefa 100644 (file)
@@ -40,3 +40,5 @@ ADD_SUBDIRECTORY(zigbee-daemon)
 IF(BUILD_GTESTS)
        ADD_SUBDIRECTORY(unittest)
 ENDIF(BUILD_GTESTS)
+
+ADD_SUBDIRECTORY(haltest)
diff --git a/haltest/CMakeLists.txt b/haltest/CMakeLists.txt
new file mode 100644 (file)
index 0000000..2c081de
--- /dev/null
@@ -0,0 +1,33 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(gtest-haltest-zigbee-manager C CXX)
+
+SET(HALTEST "zigbee_manager_hal_tc")
+ADD_DEFINITIONS("-DUSE_DLOG")
+
+SET(REQUIRES_LIST ${REQUIRES_LIST}
+       glib-2.0
+       gio-2.0
+       gmock
+       dlog
+       capi-system-info
+)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(HALTEST_PKG REQUIRED ${REQUIRES_LIST})
+
+FOREACH(flag ${HALTEST_PKG_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+
+FILE(GLOB HALTEST_SRCS *.cpp)
+SET(HALTEST_SRCS ${HALTEST_SRCS})
+
+ADD_EXECUTABLE(${HALTEST} ${HALTEST_SRCS})
+TARGET_LINK_LIBRARIES(${HALTEST} ${HALTEST_LDFLAGS} ${HALTEST_PKG_LDFLAGS} -ldl -lgcov)
+
+INSTALL(TARGETS ${HALTEST} RUNTIME DESTINATION bin)
diff --git a/haltest/common.h b/haltest/common.h
new file mode 100644 (file)
index 0000000..e2707a7
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2017 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.
+ */
+#ifndef __COMMON_H__
+#define __COMMON_H__
+
+#include <tizen_error.h>
+
+#ifdef USE_DLOG
+#include <dlog.h>
+#undef LOG_TAG
+#define LOG_TAG "ZIGBEE_GTEST"
+#define GLOGD(format, args...) LOGD(format, ##args)
+#else
+#define GLOGD(format, args...)
+#endif
+
+#ifndef TIZEN_ERROR_ZIGBEE
+#define TIZEN_ERROR_ZIGBEE -0x02F70000
+#endif
+
+typedef enum {
+       ZIGBEE_ERROR_NONE = TIZEN_ERROR_NONE,                            /**< Successful */
+       ZIGBEE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,  /**< Invalid parameter */
+       ZIGBEE_ERROR_PARAMETER_OUT_OF_RANGE = TIZEN_ERROR_RESULT_OUT_OF_RANGE, /**< Out of range */
+       ZIGBEE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY,          /**< Out of memory */
+       ZIGBEE_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR,                    /**< DBus error */
+       ZIGBEE_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA,                      /**< No data available */
+       ZIGBEE_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED,          /**< Not supported */
+       ZIGBEE_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED,  /**< Permission denied */
+       ZIGBEE_ERROR_INVALID_ENDPOINT = TIZEN_ERROR_ZIGBEE | 0x01,       /**< Endpoint 0 is reserved for ZDP */
+       ZIGBEE_ERROR_INVALID_ADDRESS = TIZEN_ERROR_ZIGBEE | 0x02,        /**< Wrong address */
+       ZIGBEE_ERROR_OPERATION_FAILED = TIZEN_ERROR_ZIGBEE | 0x03,       /**< Operation failed */
+} zb_error_e;
+#endif /* __COMMON_H__ */
diff --git a/haltest/gdbus.cpp b/haltest/gdbus.cpp
new file mode 100644 (file)
index 0000000..81432df
--- /dev/null
@@ -0,0 +1,462 @@
+/*
+ * Copyright (c) 2017 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 <stdio.h>
+#include <stdlib.h>
+#include <iostream>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "zbl.h"
+
+GDbus::GDbus()
+{
+       this->m_pConnection = NULL;
+       this->m_pCancellable = NULL;
+       this->service_gproxy = NULL;
+       this->on_off_gproxy = NULL;
+       this->door_lock_gproxy = NULL;
+       this->level_control_gproxy = NULL;
+       this->thermostat_gproxy = NULL;
+       this->alarm_gproxy = NULL;
+       this->fan_control_gproxy = NULL;
+
+       this->mfglib_gproxy = NULL;
+       this->zcl_global_proxy = NULL;
+       this->zdo_dev_proxy = NULL;
+       this->zcl_basic_proxy = NULL;
+       this->zcl_identify_proxy = NULL;
+       this->zcl_ias_zone_proxy = NULL;
+       this->zcl_poll_control_proxy = NULL;
+       this->zcl_group_proxy = NULL;
+       this->zcl_scene_proxy = NULL;
+       this->zdo_bind_proxy = NULL;
+       this->zcl_color_control_proxy = NULL;
+       this->custom_gproxy = NULL;
+}
+
+GDbus::~GDbus()
+{
+       GDBusConnection *conn = this->m_pConnection;
+       GCancellable *cancel = this->m_pCancellable;
+
+       if (cancel) {
+               g_cancellable_cancel(cancel);
+               g_object_unref(cancel);
+               cancel = NULL;
+       }
+
+       if (conn) {
+               g_object_unref(this->service_gproxy);
+               this->service_gproxy = NULL;
+               g_object_unref(this->on_off_gproxy);
+               this->on_off_gproxy = NULL;
+               g_object_unref(this->door_lock_gproxy);
+               this->door_lock_gproxy = NULL;
+               g_object_unref(this->level_control_gproxy);
+               this->level_control_gproxy = NULL;
+               g_object_unref(this->thermostat_gproxy);
+               this->thermostat_gproxy = NULL;
+               g_object_unref(this->alarm_gproxy);
+               this->alarm_gproxy = NULL;
+               g_object_unref(this->fan_control_gproxy);
+               this->fan_control_gproxy = NULL;
+
+               g_object_unref(this->mfglib_gproxy);
+               this->mfglib_gproxy = NULL;
+               g_object_unref(this->zcl_global_proxy);
+               this->zcl_global_proxy = NULL;
+
+               g_object_unref(this->zdo_dev_proxy);
+               this->zdo_dev_proxy = NULL;
+               g_object_unref(this->zcl_basic_proxy);
+               this->zcl_basic_proxy = NULL;
+               g_object_unref(this->zcl_identify_proxy);
+               this->zcl_identify_proxy = NULL;
+               g_object_unref(this->zcl_ias_zone_proxy);
+               this->zcl_ias_zone_proxy = NULL;
+               g_object_unref(this->zcl_poll_control_proxy);
+               this->zcl_poll_control_proxy = NULL;
+               g_object_unref(this->zcl_group_proxy);
+               this->zcl_group_proxy = NULL;
+               g_object_unref(this->zcl_scene_proxy);
+               this->zcl_scene_proxy = NULL;
+               g_object_unref(this->zdo_bind_proxy);
+               this->zdo_bind_proxy = NULL;
+
+               g_object_unref(this->zcl_color_control_proxy);
+               this->zcl_color_control_proxy = NULL;
+               g_object_unref(this->custom_gproxy);
+               this->custom_gproxy = NULL;
+
+               g_object_unref(conn);
+               conn = NULL;
+       }
+}
+
+zb_error_e GDbus::Create(void)
+{
+       GError *err = NULL;
+       GDBusConnection *gdbus_conn;
+
+#if !GLIB_CHECK_VERSION(2, 36, 0)
+       g_type_init();
+#endif
+
+       this->m_pConnection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+       if (this->m_pConnection == NULL) {
+               if (err != NULL) {
+                       GLOGD("Failed to connect to the D-BUS daemon [%s]", err->message);
+                       g_error_free(err);
+               }
+
+               return ZIGBEE_ERROR_OPERATION_FAILED;
+       }
+
+       gdbus_conn = this->m_pConnection;
+
+       this->service_gproxy = g_dbus_proxy_new_sync(gdbus_conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       ZIGBEE_SERVER_NAME, ZIGBEE_CONTROL_OBJECT_PATH, ZIGBEE_SERVICE_INTERFACE,
+                       NULL, NULL);
+
+       this->on_off_gproxy = g_dbus_proxy_new_sync(gdbus_conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       ZIGBEE_SERVER_NAME, ZIGBEE_CONTROL_OBJECT_PATH,
+                       ZIGBEE_ZCL_ON_OFF_INTERFACE, NULL, NULL);
+
+       this->door_lock_gproxy = g_dbus_proxy_new_sync(gdbus_conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       ZIGBEE_SERVER_NAME, ZIGBEE_CONTROL_OBJECT_PATH,
+                       ZIGBEE_ZCL_DOOR_LOCK_INTERFACE, NULL, NULL);
+
+       this->level_control_gproxy = g_dbus_proxy_new_sync(gdbus_conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       ZIGBEE_SERVER_NAME, ZIGBEE_CONTROL_OBJECT_PATH,
+                       ZIGBEE_ZCL_LEVEL_CONTROL_INTERFACE, NULL, NULL);
+
+       this->thermostat_gproxy = g_dbus_proxy_new_sync(gdbus_conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       ZIGBEE_SERVER_NAME, ZIGBEE_CONTROL_OBJECT_PATH,
+                       ZIGBEE_ZCL_THERMOSTAT_INTERFACE, NULL, NULL);
+
+       this->alarm_gproxy = g_dbus_proxy_new_sync(gdbus_conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       ZIGBEE_SERVER_NAME, ZIGBEE_CONTROL_OBJECT_PATH, ZIGBEE_ZCL_ALARM_INTERFACE,
+                       NULL, NULL);
+
+       this->fan_control_gproxy = g_dbus_proxy_new_sync(gdbus_conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       ZIGBEE_SERVER_NAME, ZIGBEE_CONTROL_OBJECT_PATH,
+                       ZIGBEE_ZCL_FAN_CONTROL_INTERFACE, NULL, NULL);
+
+       this->mfglib_gproxy = g_dbus_proxy_new_sync(gdbus_conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       ZIGBEE_SERVER_NAME, ZIGBEE_CONTROL_OBJECT_PATH,
+                       ZIGBEE_MFGLIB_CONTROL_INTERFACE, NULL, NULL);
+
+       this->zcl_global_proxy = g_dbus_proxy_new_sync(gdbus_conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       ZIGBEE_SERVER_NAME, ZIGBEE_CONTROL_OBJECT_PATH,
+                       ZIGBEE_ZCL_GLOBAL_CONTROL_INTERFACE, NULL, NULL);
+
+       this->zdo_dev_proxy = g_dbus_proxy_new_sync(gdbus_conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       ZIGBEE_SERVER_NAME, ZIGBEE_CONTROL_OBJECT_PATH,
+                       ZIGBEE_ZDO_DEV_CONTROL_INTERFACE, NULL, NULL);
+
+       this->zcl_basic_proxy = g_dbus_proxy_new_sync(gdbus_conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       ZIGBEE_SERVER_NAME, ZIGBEE_CONTROL_OBJECT_PATH, ZIGBEE_ZCL_BASIC_INTERFACE,
+                       NULL, NULL);
+
+       this->zcl_identify_proxy = g_dbus_proxy_new_sync(gdbus_conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       ZIGBEE_SERVER_NAME, ZIGBEE_CONTROL_OBJECT_PATH,
+                       ZIGBEE_ZCL_IDENTIFY_INTERFACE, NULL, NULL);
+
+       this->zcl_ias_zone_proxy = g_dbus_proxy_new_sync(gdbus_conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       ZIGBEE_SERVER_NAME, ZIGBEE_CONTROL_OBJECT_PATH,
+                       ZIGBEE_ZCL_IAS_ZONE_INTERFACE, NULL, NULL);
+
+       this->zcl_poll_control_proxy = g_dbus_proxy_new_sync(gdbus_conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       ZIGBEE_SERVER_NAME, ZIGBEE_CONTROL_OBJECT_PATH,
+                       ZIGBEE_ZCL_POLL_CONTROL_INTERFACE, NULL, NULL);
+
+       this->zcl_group_proxy = g_dbus_proxy_new_sync(gdbus_conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       ZIGBEE_SERVER_NAME, ZIGBEE_CONTROL_OBJECT_PATH, ZIGBEE_ZCL_GROUP_INTERFACE,
+                       NULL, NULL);
+
+       this->zcl_scene_proxy = g_dbus_proxy_new_sync(gdbus_conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       ZIGBEE_SERVER_NAME, ZIGBEE_CONTROL_OBJECT_PATH, ZIGBEE_ZCL_SCENE_INTERFACE,
+                       NULL, NULL);
+
+       this->zdo_bind_proxy = g_dbus_proxy_new_sync(gdbus_conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       ZIGBEE_SERVER_NAME, ZIGBEE_CONTROL_OBJECT_PATH, ZIGBEE_ZDO_BIND_INTERFACE,
+                       NULL, NULL);
+
+       this->zcl_color_control_proxy = g_dbus_proxy_new_sync(gdbus_conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       ZIGBEE_SERVER_NAME, ZIGBEE_CONTROL_OBJECT_PATH,
+                       ZIGBEE_ZCL_COLOR_CONTROL_INTERFACE, NULL, NULL);
+
+       this->custom_gproxy = g_dbus_proxy_new_sync(gdbus_conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       ZIGBEE_SERVER_NAME, ZIGBEE_CONTROL_OBJECT_PATH, ZIGBEE_CUSTOM_INTERFACE,
+                       NULL, NULL);
+
+       this->m_pCancellable = g_cancellable_new();
+
+       return ZIGBEE_ERROR_NONE;
+}
+
+zb_error_e GDbus::Destroy(void)
+{
+       g_object_unref(this->service_gproxy);
+       this->service_gproxy = NULL;
+       g_object_unref(this->on_off_gproxy);
+       this->on_off_gproxy = NULL;
+       g_object_unref(this->door_lock_gproxy);
+       this->door_lock_gproxy = NULL;
+       g_object_unref(this->level_control_gproxy);
+       this->level_control_gproxy = NULL;
+       g_object_unref(this->thermostat_gproxy);
+       this->thermostat_gproxy = NULL;
+       g_object_unref(this->alarm_gproxy);
+       this->alarm_gproxy = NULL;
+       g_object_unref(this->fan_control_gproxy);
+       this->fan_control_gproxy = NULL;
+
+       g_object_unref(this->mfglib_gproxy);
+       this->mfglib_gproxy = NULL;
+       g_object_unref(this->zcl_global_proxy);
+       this->zcl_global_proxy = NULL;
+
+       g_object_unref(this->zdo_dev_proxy);
+       this->zdo_dev_proxy = NULL;
+       g_object_unref(this->zcl_basic_proxy);
+       this->zcl_basic_proxy = NULL;
+       g_object_unref(this->zcl_identify_proxy);
+       this->zcl_identify_proxy = NULL;
+       g_object_unref(this->zcl_ias_zone_proxy);
+       this->zcl_ias_zone_proxy = NULL;
+       g_object_unref(this->zcl_poll_control_proxy);
+       this->zcl_poll_control_proxy = NULL;
+       g_object_unref(this->zcl_group_proxy);
+       this->zcl_group_proxy = NULL;
+       g_object_unref(this->zcl_scene_proxy);
+       this->zcl_scene_proxy = NULL;
+       g_object_unref(this->zdo_bind_proxy);
+       this->zdo_bind_proxy = NULL;
+       g_object_unref(this->zcl_color_control_proxy);
+       this->zcl_color_control_proxy = NULL;
+       g_object_unref(this->custom_gproxy);
+       this->custom_gproxy = NULL;
+
+       g_cancellable_cancel(this->m_pCancellable);
+       g_object_unref(this->m_pCancellable);
+       this->m_pCancellable = NULL;
+
+       g_object_unref(this->m_pConnection);
+       this->m_pConnection = NULL;
+
+       return ZIGBEE_ERROR_NONE;
+}
+
+GDBusConnection *GDbus::GetConnection(void)
+{
+       return this->m_pConnection;
+}
+
+GCancellable *GDbus::GetCancellable(void)
+{
+       return this->m_pCancellable;
+}
+
+GDBusProxy *GDbus::get_proxy_type(gproxy_type_e type)
+{
+       GDBusProxy *proxy = NULL;
+
+       switch (type)
+       {
+               case SERVICE_GPROXY:
+                       proxy = this->service_gproxy;
+                       break;
+               case ON_OFF_GPROXY:
+                       proxy = this->on_off_gproxy;
+                       break;
+               case DOOR_LOCK_GPROXY:
+                       proxy = this->door_lock_gproxy;
+                       break;
+               case LEVEL_CONTROL_GPROXY:
+                       proxy = this->level_control_gproxy;
+                       break;
+               case THERMOSTAT_GPROXY:
+                       proxy = this->thermostat_gproxy;
+                       break;
+               case ALARM_GPROXY:
+                       proxy = this->alarm_gproxy;
+                       break;
+               case FAN_CONTROL_GPROXY:
+                       proxy = this->fan_control_gproxy;
+                       break;
+               case MFGLIB_GPROXY:
+                       proxy = this->mfglib_gproxy;
+                       break;
+               case ZCL_GLOBAL_PROXY:
+                       proxy = this->zcl_global_proxy;
+                       break;
+               case ZDO_DEV_PROXY:
+                       proxy = this->zdo_dev_proxy;
+                       break;
+               case ZCL_BASIC_PROXY:
+                       proxy = this->zcl_basic_proxy;
+                       break;
+               case ZCL_IDENTIFY_PROXY:
+                       proxy = this->zcl_identify_proxy;
+                       break;
+               case ZCL_IAS_ZONE_PROXY:
+                       proxy = this->zcl_ias_zone_proxy;
+                       break;
+               case ZCL_POLL_CONTROL_PROXY:
+                       proxy = this->zcl_poll_control_proxy;
+                       break;
+               case ZCL_GROUP_PROXY:
+                       proxy = this->zcl_group_proxy;
+                       break;
+               case ZCL_SCENE_PROXY:
+                       proxy = this->zcl_scene_proxy;
+                       break;
+               case ZDO_BIND_PROXY:
+                       proxy = this->zdo_bind_proxy;
+                       break;
+               case ZCL_COLOR_CONTROL_PROXY:
+                       proxy = this->zcl_color_control_proxy;
+                       break;
+               case CUSTOM_GPROXY:
+                       proxy = this->custom_gproxy;
+                       break;
+       }
+
+       return proxy;
+}
+
+GVariant *GDbus::invoke_proxy_method(gproxy_type_e type, const char *method, GVariant *params, int *error)
+{
+       GError *dbus_error = NULL;
+       GVariant *reply = NULL;
+       GDBusConnection *connection = NULL;
+       GDBusProxy *proxy = NULL;
+
+       connection = GetConnection();
+       if (connection == NULL) {
+               GLOGD("GDBusconnection is NULL");
+               *error = ZIGBEE_ERROR_IO_ERROR;
+               return reply;
+       }
+
+       proxy = get_proxy_type(type);
+       if (proxy == NULL) {
+               GLOGD("GDBusProxy is NULL");
+               *error = ZIGBEE_ERROR_IO_ERROR;
+               return reply;
+       }
+
+       reply = g_dbus_proxy_call_sync(proxy,
+                       method,
+                       params,
+                       G_DBUS_CALL_FLAGS_NONE,
+                       ZIGBEE_BROADCAST_TIMEOUT,
+                       GetCancellable(),
+                       &dbus_error);
+
+       if (reply == NULL) {
+               if (dbus_error != NULL) {
+                       GLOGD("g_dbus_connection_call_sync() failed "
+                                       "error [%d: %s]", dbus_error->code, dbus_error->message);
+                       if (strstr(dbus_error->message, "AccessDenied"))
+                               *error = ZIGBEE_ERROR_PERMISSION_DENIED;
+                       else
+                               *error = ZIGBEE_ERROR_IO_ERROR;
+                       g_error_free(dbus_error);
+               } else {
+                       GLOGD("g_dbus_connection_call_sync() failed");
+                       *error = ZIGBEE_ERROR_OPERATION_FAILED;
+               }
+               return NULL;
+       }
+
+       return reply;
+}
+
+GVariant *GDbus::InvokeMethod(const char *dest, const char *path,
+               const char *iface_name, const char *method, GVariant *params, int *error)
+{
+       GError *dbus_error = NULL;
+       GVariant *reply = NULL;
+       GDBusConnection *connection = NULL;
+
+       connection = GetConnection();
+       if (connection == NULL) {
+               GLOGD("GDBusconnection is NULL");
+               *error = ZIGBEE_ERROR_IO_ERROR;
+               return reply;
+       }
+
+       reply = g_dbus_connection_call_sync(connection,
+                       dest,
+                       path,
+                       iface_name,
+                       method,
+                       params,
+                       NULL,
+                       G_DBUS_CALL_FLAGS_NONE,
+                       ZIGBEE_BROADCAST_TIMEOUT,
+                       GetCancellable(),
+                       &dbus_error);
+
+       if (reply == NULL) {
+               if (dbus_error != NULL) {
+                       GLOGD("g_dbus_connection_call_sync() failed "
+                                       "error [%d: %s]", dbus_error->code, dbus_error->message);
+                       if (strstr(dbus_error->message, "AccessDenied"))
+                               *error = ZIGBEE_ERROR_PERMISSION_DENIED;
+                       else
+                               *error = ZIGBEE_ERROR_IO_ERROR;
+                       g_error_free(dbus_error);
+               } else {
+                       GLOGD("g_dbus_connection_call_sync() failed");
+                       *error = ZIGBEE_ERROR_OPERATION_FAILED;
+               }
+               return NULL;
+       }
+
+       return reply;
+}
+
+zb_error_e GDbus::InvokeMethodNonblock(const char *dest, const char *path,
+               const char *iface_name, const char *method, GVariant *params, int timeout,
+               GAsyncReadyCallback notify_func, void *user_data)
+{
+       GDBusConnection *connection = NULL;
+
+       connection = GetConnection();
+       if (connection == NULL) {
+               GLOGD("GDBusconnection is NULL");
+               return ZIGBEE_ERROR_IO_ERROR;
+       }
+
+       g_dbus_connection_call(connection,
+                       dest,
+                       path,
+                       iface_name,
+                       method,
+                       params,
+                       NULL,
+                       G_DBUS_CALL_FLAGS_NONE,
+                       timeout,
+                       GetCancellable(),
+                       (GAsyncReadyCallback) notify_func,
+                       (gpointer)user_data);
+
+       return ZIGBEE_ERROR_NONE;
+}
diff --git a/haltest/gdbus.h b/haltest/gdbus.h
new file mode 100644 (file)
index 0000000..2c0775b
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2017 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.
+ */
+#ifndef __ZIGBEE_GDBUS_H__
+#define __ZIGBEE_GDBUS_H__
+
+#include <glib.h>
+#include "common.h"
+
+#define GMAINTIMEOUT 10000
+#define ZIGBEE_BROADCAST_TIMEOUT (9.5 + 2) * 1000 /**< default timeout for gdbus */
+
+
+#ifndef ZIGBEE_DBUS_INTERFACE
+#define ZIGBEE_DBUS_INTERFACE "org.tizen.zigbee"
+#endif
+
+#ifndef ZIGBEE_DBUS_OBJPATH
+#define ZIGBEE_DBUS_OBJPATH "/org/tizen/zigbee"
+#endif
+
+#define ZIGBEE_SERVER_NAME "org.tizen.zigbee"
+#define ZIGBEE_CONTROL_OBJECT_PATH "/org/tizen/zigbee/control"
+
+#define ZIGBEE_MANAGER_INTERFACE "org.tizen.zigbee.manager"
+#define ZIGBEE_SERVICE_INTERFACE "org.tizen.zigbee.service"
+#define ZIGBEE_SERVICE_OBJECT_PATH "/org/tizen/zigbee/service"
+
+#define ZIGBEE_ZDO_DEV_CONTROL_INTERFACE "org.tizen.zigbee.zdo_dev_control"
+#define ZIGBEE_ZDO_BIND_INTERFACE "org.tizen.zigbee.zdo_bind"
+#define ZIGBEE_ZCL_GLOBAL_CONTROL_INTERFACE "org.tizen.zigbee.zcl_global_control"
+#define ZIGBEE_ZCL_ALARM_INTERFACE "org.tizen.zigbee.zcl_alarm"
+#define ZIGBEE_ZCL_BASIC_INTERFACE "org.tizen.zigbee.zcl_basic"
+#define ZIGBEE_ZCL_COLOR_CONTROL_INTERFACE "org.tizen.zigbee.zcl_color_control"
+#define ZIGBEE_ZCL_ON_OFF_INTERFACE "org.tizen.zigbee.zcl_on_off"
+#define ZIGBEE_ZCL_DOOR_LOCK_INTERFACE "org.tizen.zigbee.zcl_door_lock"
+#define ZIGBEE_ZCL_GROUP_INTERFACE "org.tizen.zigbee.zcl_group"
+#define ZIGBEE_ZCL_FAN_CONTROL_INTERFACE "org.tizen.zigbee.zcl_fan_control"
+#define ZIGBEE_ZCL_IAS_ZONE_INTERFACE "org.tizen.zigbee.zcl_ias_zone"
+#define ZIGBEE_ZCL_IDENTIFY_INTERFACE "org.tizen.zigbee.zcl_identify"
+#define ZIGBEE_ZCL_LEVEL_CONTROL_INTERFACE "org.tizen.zigbee.zcl_level_control"
+#define ZIGBEE_ZCL_POLL_CONTROL_INTERFACE "org.tizen.zigbee.zcl_poll_control"
+#define ZIGBEE_ZCL_SCENE_INTERFACE "org.tizen.zigbee.zcl_scene"
+#define ZIGBEE_ZCL_THERMOSTAT_INTERFACE "org.tizen.zigbee.zcl_thermostat"
+#define ZIGBEE_CUSTOM_INTERFACE "org.tizen.zigbee.custom"
+#define ZIGBEE_MFGLIB_CONTROL_INTERFACE "org.tizen.zigbee.mfglib_control"
+
+typedef enum {
+       SERVICE_GPROXY,
+       ON_OFF_GPROXY,
+       DOOR_LOCK_GPROXY,
+       LEVEL_CONTROL_GPROXY,
+       THERMOSTAT_GPROXY,
+       ALARM_GPROXY,
+       FAN_CONTROL_GPROXY,
+       MFGLIB_GPROXY,
+       ZCL_GLOBAL_PROXY,
+       ZDO_DEV_PROXY,
+       ZCL_BASIC_PROXY,
+       ZCL_IDENTIFY_PROXY,
+       ZCL_IAS_ZONE_PROXY,
+       ZCL_POLL_CONTROL_PROXY,
+       ZCL_GROUP_PROXY,
+       ZCL_SCENE_PROXY,
+       ZDO_BIND_PROXY,
+       ZCL_COLOR_CONTROL_PROXY,
+       CUSTOM_GPROXY,
+} gproxy_type_e;
+
+class GDbus {
+       private:
+               GDBusConnection *m_pConnection;
+               GDBusProxy *service_gproxy;
+               GDBusProxy *on_off_gproxy;
+               GDBusProxy *door_lock_gproxy;
+               GDBusProxy *level_control_gproxy;
+               GDBusProxy *thermostat_gproxy;
+               GDBusProxy *alarm_gproxy;
+               GDBusProxy *fan_control_gproxy;
+               GDBusProxy *mfglib_gproxy;
+               GDBusProxy *zcl_global_proxy;
+               GDBusProxy *zdo_dev_proxy;
+               GDBusProxy *zcl_basic_proxy;
+               GDBusProxy *zcl_identify_proxy;
+               GDBusProxy *zcl_ias_zone_proxy;
+               GDBusProxy *zcl_poll_control_proxy;
+               GDBusProxy *zcl_group_proxy;
+               GDBusProxy *zcl_scene_proxy;
+               GDBusProxy *zdo_bind_proxy;
+               GDBusProxy *zcl_color_control_proxy;
+               GDBusProxy *custom_gproxy;
+               GCancellable *m_pCancellable;
+               GDBusProxy *get_proxy_type(gproxy_type_e type);
+
+       public:
+               GDbus();
+               ~GDbus();
+               zb_error_e Create(void);
+               zb_error_e Destroy(void);
+               GDBusConnection *GetConnection(void);
+               GCancellable *GetCancellable(void);
+
+               GVariant *invoke_proxy_method(gproxy_type_e type, const char *method, GVariant *params, int *error);
+               GVariant *InvokeMethod(const char *dest, const char *path,
+                               const char *iface_name, const char *method, GVariant *params, int *error);
+               zb_error_e InvokeMethodNonblock(const char *dest, const char *path,
+                               const char *iface_name, const char *method, GVariant *params, int timeout,
+                               GAsyncReadyCallback notify_func, void *user_data);
+};
+#endif /* __ZIGBEE_GDBUS_H__ */
diff --git a/haltest/zbl.cpp b/haltest/zbl.cpp
new file mode 100644 (file)
index 0000000..c274ceb
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 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.
+ */
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "zbl.h"
+
+Zigbee::Zigbee(void)
+{
+       Create();
+}
+
+Zigbee::~Zigbee(void)
+{
+       Destroy();
+}
+
+int Zigbee::zbl_enable(void)
+{
+       int error = ZIGBEE_ERROR_NONE;
+       GVariant *message;
+
+       GLOGD("zbl_enable()");
+
+       message = InvokeMethod(ZIGBEE_MANAGER_INTERFACE,
+                       ZIGBEE_DBUS_OBJPATH,
+                       ZIGBEE_MANAGER_INTERFACE,
+                       "enable", NULL, &error);
+
+       if (message)
+               g_variant_unref(message);
+
+       return error;
+}
+
+int Zigbee::zbl_disable(void)
+{
+       int error = ZIGBEE_ERROR_NONE;
+       GVariant *message = NULL;
+
+       GLOGD("zbl_disable()");
+
+       message = InvokeMethod(ZIGBEE_MANAGER_INTERFACE,
+                       ZIGBEE_DBUS_OBJPATH,
+                       ZIGBEE_MANAGER_INTERFACE,
+                       "disable", NULL, &error);
+
+       if (message) {
+               g_variant_get(message, "(i)", &error);
+               GLOGD("ret = 0x%x", error);
+               g_variant_unref(message);
+       }
+
+       return error;
+}
diff --git a/haltest/zbl.h b/haltest/zbl.h
new file mode 100644 (file)
index 0000000..9cccb1f
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2017 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.
+ */
+#ifndef __ZIGBEE_MANAGER_H__
+#define __ZIGBEE_MANAGER_H__
+
+#include <glib.h>
+#include <gio/gio.h>
+
+#include "gdbus.h"
+#include "common.h"
+
+#define MAX_ENDPOINT_CLUSTERS 32
+#define ZB_802_15_4_CHANNELS_MASK 0x07FFF800UL
+
+typedef unsigned char ieee_addr[8];
+typedef unsigned short nwk_addr;
+typedef unsigned char aes128_key[16];
+
+typedef enum {
+       ZB_ZDP_ALTERNATIVE_PAN_COORDINATOR = (1 << 0),
+       ZB_ZDP_DEVICE_TYPE = (1 << 1),
+       ZB_ZDP_POWER_SOURCE = (1 << 2),
+       ZB_ZDP_RECEIVER_ON_WHEN_IDLE = (1 << 3),
+       ZB_ZDP_SECURITY_CAPABILITY = (1 << 6),
+       ZB_ZDP_ALLOCATE_ADDRESS = (1 << 7),
+} zb_zdo_mac_capability_field_e;
+
+typedef enum {
+       ZB_APS_NO_ACK_REQUEST = (0 << 6),
+       ZB_APS_ACK_REQUEST = (1 << 6),
+} zb_aps_ack_request_e;
+
+typedef enum {
+       ZB_APS_DELIVERY_UNICAST = 0,
+       ZB_APS_DELIVERY_INDIRECT = 1,
+       ZB_APS_DELIVERY_BROADCAST = 2,
+       ZB_APS_DELIVERY_MULTICAST = 3,
+} zb_aps_delivery_mode_e;
+
+typedef enum {
+       ZB_ZCL_FC_GLOBALLY_USED = (0 << 0),
+       ZB_APS_FC_CLUSTER_SPECIFIC = (1 << 0),
+} zb_zcl_fc_type_e;
+
+typedef enum {
+       ZB_ZCL_CLIENT_TO_SERVER = (0 << 3),
+       ZB_ZCL_SERVER_TO_CLIENT = (1 << 3),
+} zb_zcl_fc_direction_e;
+
+typedef enum {
+       ZB_ZCL_LEAVE_WELL_ALONE = (0 << 4),
+       ZB_ZCL_DISABLE_DEFAULT_RESPONSE = (1 << 4),
+} zb_zcl_fc_disable_default_response_e;
+
+typedef enum {
+       ZB_ZCL_FC_NOT_MANUFACTURER = (0 << 2),
+       ZB_ZCL_FC_MANUFACTURER = (1 << 2),
+} zb_zcl_fc_manufacturer_present_e;
+
+class Zigbee:public GDbus {
+       private:
+       public:
+               Zigbee();
+               ~Zigbee();
+               int zbl_enable(void);
+               int zbl_disable(void);
+};
+#endif /* __ZIGBEE_MANAGER_H__ */
diff --git a/haltest/zigbee_manager_hal_tc.cpp b/haltest/zigbee_manager_hal_tc.cpp
new file mode 100644 (file)
index 0000000..52de0dd
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2017 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 <stdio.h>
+#include <stdlib.h>
+#include <iostream>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <unistd.h>
+#include <system_info.h>
+
+#include "zbl.h"
+
+#define FEATURE_ZIGBEE       "http://tizen.org/feature/network.zigbee"
+static bool g_bFeatureZb = false;
+
+using ::testing::InitGoogleTest;
+using ::testing::Test;
+using ::testing::TestCase;
+
+static bool __check_feature_supported(char *key)
+{
+       bool value = false;
+       int ret = system_info_get_platform_bool(key, &value);
+
+       EXPECT_EQ(SYSTEM_INFO_ERROR_NONE, ret) << "system_info_get_platform_bool failed";
+       EXPECT_EQ(true, value) << key << " feature is not supported";
+
+       return value;
+}
+
+/*
+@testcase      Enable_p
+@since_tizen   5.0
+@author                SRID(abhishek.s94)
+@reviewer      HQ(saerome.kim)
+@type          auto
+@description   Positive, Enable zigbee manager
+@apicovered    "enable" method on "org.tizen.zigbee.manager" interface
+@passcase      when zbl_enable returns ZIGBEE_ERROR_NONE
+@failcase      when zbl_enable does not return ZIGBEE_ERROR_NONE
+@precondition  __check_feature_supported must return true for zigbee feature
+@postcondition None
+*/
+TEST(ZigbeeManager, Enable_p)
+{
+       g_bFeatureZb = __check_feature_supported((char*)FEATURE_ZIGBEE);
+       ASSERT_EQ(true, g_bFeatureZb) << FEATURE_ZIGBEE << " feature is not supported";
+
+       int ret = ZIGBEE_ERROR_NONE;
+       Zigbee zb_mgr;
+
+       ret = zb_mgr.zbl_enable();
+       EXPECT_EQ(ZIGBEE_ERROR_NONE, ret);
+}
+
+/*
+@testcase      Disable_p
+@since_tizen   5.0
+@author                SRID(abhishek.s94)
+@reviewer      HQ(saerome.kim)
+@type          auto
+@description   Positive, Disable zigbee manager
+@apicovered    "disable" method on "org.tizen.zigbee.manager" interface
+@passcase      when zbl_disable returns ZIGBEE_ERROR_NONE
+@failcase      when zbl_disable does not return ZIGBEE_ERROR_NONE
+@precondition  __check_feature_supported must return true for zigbee feature
+@postcondition None
+*/
+TEST(ZigbeeManager, Disable_p)
+{
+       g_bFeatureZb = __check_feature_supported((char*)FEATURE_ZIGBEE);
+       ASSERT_EQ(true, g_bFeatureZb) << FEATURE_ZIGBEE << " feature is not supported";
+
+       int ret = ZIGBEE_ERROR_NONE;
+       Zigbee zb_mgr;
+
+       ret = zb_mgr.zbl_disable();
+       EXPECT_EQ(ZIGBEE_ERROR_NONE, ret);
+}
+
+int main(int argc, char **argv)
+{
+       int ret = 0;
+       try {
+               testing::InitGoogleTest(&argc, argv);
+       } catch (const ::testing::internal::GoogleTestFailureException& ex) {
+               std::cerr << "Caught: GoogleTestFailureException& " << ex.what() << std::endl;
+       } catch (...) {
+               std::cerr << "Caught: unknown exception" << std::endl;
+       }
+
+       try {
+               ret = RUN_ALL_TESTS();
+       } catch (const ::testing::internal::GoogleTestFailureException& ex) {
+               std::cerr << "Caught: GoogleTestFailureException& " << ex.what() << std::endl;
+       } catch (...) {
+               std::cerr << "Caught: unknown exception" << std::endl;
+       }
+       return ret;
+}
index b6e9346..479dacb 100644 (file)
@@ -31,6 +31,17 @@ Requires: awk
 %description
 Description: ZigBee Manager
 
+%package haltests
+Summary:       zigbee-manager extension for HAL test
+BuildRequires: pkgconfig(gmock)
+BuildRequires: pkgconfig(capi-system-info)
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(gio-2.0)
+Requires:       %{name} = %{version}-%{release}
+%description haltests
+TIZEN zigbee-manager extension for HAL test.
+
 %package -n zigbee-lib
 Summary:         ZigBee library
 Group:           System/Libraries
@@ -126,3 +137,7 @@ cp %{SOURCE3} %{buildroot}%{_sysconfdir}/dbus-1/system.d/zigbee.conf
 %{_includedir}/zigbee/common/*.h
 %{_libdir}/pkgconfig/zigbee-lib.pc
 %{_libdir}/libzigbee-lib.so
+
+%files haltests
+%manifest %{name}.manifest
+%{_bindir}/*hal_tc