INSTALL(FILES ${CMAKE_SOURCE_DIR}/org.tizen.multiassistant.mauiclient.service DESTINATION ${TZ_SYS_RO_SHARE}/dbus-1/services)
INSTALL(FILES ${CMAKE_SOURCE_DIR}/multi-assistant.info DESTINATION ${TZ_SYS_RO_SHARE}/parser-plugins)
+
+## Test
+IF(NOT DEFINED MINIMUM_BUILD)
+ENABLE_TESTING()
+SET(UTC_MA multi-assistant-unittests)
+ADD_TEST(NAME ${UTC_MA} COMMAND ${UTC_MA}
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests)
+
+ADD_SUBDIRECTORY(tests)
+ENDIF(NOT DEFINED MINIMUM_BUILD)
BuildRequires: pkgconfig(libxml-2.0)
BuildRequires: pkgconfig(pkgmgr-installer)
BuildRequires: pkgconfig(vconf)
+BuildRequires: pkgconfig(gmock)
BuildRequires: cmake
+%if 0%{?gcov:1}
+BuildRequires: lcov
+BuildRequires: zip
+%endif
+
%description
Multi assistant client library and daemon
%description ui-devel
Multi assistant manager header files for MA development.
+%package unittests
+Summary: multi assistant unittests
+Group: Development/Libraries
+Requires: %{name} = %{version}-%{release}
+
+%description unittests
+GTest for multi assistant
%if 0%{?gcov:1}
%package gcov
find . -name '*.gcno' -exec cp --parents '{}' "$gcno_obj_dir" ';'
%endif
+cat << EOF > run-unittest.sh
+#!/bin/sh
+setup() {
+ echo "setup start"
+}
+
+test_main() {
+ echo "test_main start"
+ /usr/bin/multi-assistant-unittests
+}
+
+teardown() {
+ echo "teardown start"
+}
+
+main() {
+ setup
+ test_main
+ teardown
+}
+
+main "\$*"
+EOF
+
+mkdir -p %{buildroot}%{_bindir}/tizen-unittests/%{name}
+install -m 0755 run-unittest.sh %{buildroot}%{_bindir}/tizen-unittests/%{name}
+
+%check
+%if 0%{?gcov:1}
+ctest --output-on-failure %{?_smp_mflags}
+lcov -c --ignore-errors graph --no-external -q -d . -o %{name}.info
+genhtml %{name}.info -o %{name}.out
+zip -r %{name}.zip %{name}.out %{name}.info
+install -m 0644 %{name}.zip %{buildroot}%{_datadir}/gcov/
+%endif
+
%post
/sbin/ldconfig
%{_includedir}/multi_assistant_common.h
%{_includedir}/multi_assistant_settings.h
+%files unittests
+%{_bindir}/multi-assistant-unittests
+%{_bindir}/tizen-unittests/%{name}/run-unittest.sh
+
%if 0%{?gcov:1}
%files gcov
-%{_datadir}/gcov/obj/*
+%{_datadir}/gcov/*
%endif
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(ma_gtest CXX)
+
+# Find Packages
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED
+ dlog
+ ecore
+ glib-2.0
+ capi-base-common
+ capi-system-info
+ bundle
+ capi-message-port
+ dbus-1
+ cynara-client
+ cynara-session
+ libxml-2.0
+ vconf
+ json-glib-1.0
+ libtzplatform-config
+ libxml-2.0
+ vconf
+ gmock
+)
+
+FOREACH(flag ${pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIE")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Werror")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -std=c++11")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+
+SET(SOURCES "")
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../include)
+
+AUX_SOURCE_DIRECTORY(src SOURCES)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../common MA_COMMON_SOURCES)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../client MA_CLIENT_SOURCES)
+
+ADD_DEFINITIONS("-DFULLVER=\"${FULLVER}\"")
+
+ADD_EXECUTABLE(${UTC_MA}
+ ${MA_COMMON_SOURCES}
+ ${MA_CLIENT_SOURCES}
+ ${SOURCES}
+ )
+TARGET_LINK_LIBRARIES(${UTC_MA} ${GTEST_LIBRARIES} ${pkgs_LDFLAGS} ${EXTRA_LDFLAGS})
+SET_TARGET_PROPERTIES(${UTC_MA} PROPERTIES
+ COMPILE_FLAGS "-fPIE"
+ #Never add any space for LINKFLAGS
+ LINK_FLAGS "-Wl,\
+--wrap=vconf_set_bool,\
+--wrap=vconf_get_bool,\
+--wrap=vconf_set_str,\
+--wrap=vconf_get_str")
+
+INSTALL(TARGETS ${UTC_MA} DESTINATION /usr/bin)
--- /dev/null
+#ifndef __MA_TEST_COMMON_H__\r
+#define __MA_TEST_COMMON_H__\r
+\r
+#ifdef __cplusplus\r
+extern "C"\r
+{\r
+#endif\r
+\r
+static const char *TEST_VOICE_ASSISTANT_APPID = "org.tizen.bixby-test";\r
+static const char *multiple_mode_vconf_key = "db/multi-assistant/multiple_mode";\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* __MA_TEST_COMMON_H__ */
\ No newline at end of file
--- /dev/null
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+int main(int argc, char** argv) {
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
--- /dev/null
+//
+// Copyright (c) 2022 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#include <gtest/gtest.h>
+#include <multi_assistant_settings.h>
+#include <multi_assistant_common.h>
+#include <glib.h>
+#include <Ecore.h>
+#include <vconf.h>
+
+#include "common.h"
+
+class MultiAssistantSettingMultipleOffTest : public testing::Test {
+ public:
+ virtual void SetUp() {
+ vconf_set_bool(multiple_mode_vconf_key, false);
+ }
+ virtual void TearDown() {
+ }
+};
+
+TEST_F(MultiAssistantSettingMultipleOffTest, utc_ma_settings_is_multiple_mode_error_none)
+{
+ bool mode;
+ int ret = ma_settings_is_multiple_mode(&mode);
+
+ EXPECT_EQ(ret, MA_ERROR_NONE);
+ EXPECT_EQ(mode, false);
+}
+
+TEST_F(MultiAssistantSettingMultipleOffTest, utc_ma_settings_get_current_voice_assistant_operation_failed)
+{
+ char *appid;
+ int ret = ma_settings_get_current_voice_assistant(&appid);
+ EXPECT_EQ(ret, MA_ERROR_OPERATION_FAILED);
+}
+
+TEST_F(MultiAssistantSettingMultipleOffTest, utc_ma_settings_change_voice_assistant_error_none)
+{
+ int ret = ma_settings_change_voice_assistant(TEST_VOICE_ASSISTANT_APPID);
+ EXPECT_EQ(ret, MA_ERROR_NONE);
+}
+
+TEST_F(MultiAssistantSettingMultipleOffTest, utc_ma_settings_get_voice_assistant_enabled_not_supported)
+{
+ bool enabled;
+
+ int ret = ma_settings_get_voice_assistant_enabled(TEST_VOICE_ASSISTANT_APPID, &enabled);
+ EXPECT_EQ(ret, MA_ERROR_NOT_SUPPORTED);
+}
+
+TEST_F(MultiAssistantSettingMultipleOffTest, utc_ma_settings_set_voice_assistant_enabled_not_supported)
+{
+ bool enabled;
+ int ret = ma_settings_get_voice_assistant_enabled(TEST_VOICE_ASSISTANT_APPID, &enabled);
+ EXPECT_EQ(ret, MA_ERROR_NOT_SUPPORTED);
+}
+
+TEST_F(MultiAssistantSettingMultipleOffTest, utc_ma_settings_get_default_voice_assistant_operation_failed)
+{
+ char *appid = nullptr;
+ int ret = ma_settings_get_default_voice_assistant(&appid);
+ EXPECT_EQ(ret, MA_ERROR_OPERATION_FAILED);
+}
--- /dev/null
+//
+// Copyright (c) 2022 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+#include <gtest/gtest.h>
+#include <multi_assistant_settings.h>
+#include <multi_assistant_common.h>
+#include <glib.h>
+#include <Ecore.h>
+#include <vconf.h>
+
+#include "common.h"
+
+class MultiAssistantSettingMultipleOnTest : public testing::Test {
+ public:
+ virtual void SetUp() {
+ vconf_set_bool(multiple_mode_vconf_key, true);
+ }
+ virtual void TearDown() {
+ vconf_set_bool(multiple_mode_vconf_key, false);
+ }
+};
+
+TEST_F(MultiAssistantSettingMultipleOnTest, utc_ma_settings_is_multiple_mode_invalid_parameter)
+{
+ int ret = ma_settings_is_multiple_mode(NULL);
+ EXPECT_EQ(ret, MA_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(MultiAssistantSettingMultipleOnTest, utc_ma_settings_is_multiple_mode_error_none)
+{
+ bool mode;
+ int ret = ma_settings_is_multiple_mode(&mode);
+
+ EXPECT_EQ(ret, MA_ERROR_NONE);
+ EXPECT_EQ(mode, true);
+}
+
+TEST_F(MultiAssistantSettingMultipleOnTest, utc_ma_settings_get_current_voice_assistant_invalid_parameter)
+{
+ int ret = ma_settings_get_current_voice_assistant(NULL);
+ EXPECT_EQ(ret, MA_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(MultiAssistantSettingMultipleOnTest, utc_ma_settings_get_current_voice_assistant_operation_failed)
+{
+ char *appid;
+ int ret = ma_settings_get_current_voice_assistant(&appid);
+ EXPECT_EQ(ret, MA_ERROR_OPERATION_FAILED);
+}
+
+TEST_F(MultiAssistantSettingMultipleOnTest, utc_ma_settings_change_voice_assistant_invalid_parameter)
+{
+ int ret = ma_settings_change_voice_assistant(NULL);
+ EXPECT_EQ(ret, MA_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(MultiAssistantSettingMultipleOnTest, utc_ma_settings_change_voice_assistant_operation_failed)
+{
+ int ret = ma_settings_change_voice_assistant(TEST_VOICE_ASSISTANT_APPID);
+ EXPECT_EQ(ret, MA_ERROR_OPERATION_FAILED);
+}
+
+TEST_F(MultiAssistantSettingMultipleOnTest, utc_ma_settings_get_voice_assistant_enabled_invalid_parameter)
+{
+ bool enabled;
+
+ int ret = ma_settings_get_voice_assistant_enabled(TEST_VOICE_ASSISTANT_APPID, NULL);
+ EXPECT_EQ(ret, MA_ERROR_INVALID_PARAMETER);
+
+ ret = ma_settings_get_voice_assistant_enabled(NULL, &enabled);
+ EXPECT_EQ(ret, MA_ERROR_INVALID_PARAMETER);
+
+ ret = ma_settings_get_voice_assistant_enabled(NULL, NULL);
+ EXPECT_EQ(ret, MA_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(MultiAssistantSettingMultipleOnTest, utc_ma_settings_get_voice_assistant_enabled_not_supported)
+{
+ bool enabled;
+
+ int ret = ma_settings_get_voice_assistant_enabled(TEST_VOICE_ASSISTANT_APPID, &enabled);
+ EXPECT_EQ(ret, MA_ERROR_OPERATION_FAILED);
+}
+
+TEST_F(MultiAssistantSettingMultipleOnTest, utc_ma_settings_set_voice_assistant_enabled_invalid_parameter)
+{
+ int ret = ma_settings_set_voice_assistant_enabled(NULL, true);
+ EXPECT_EQ(ret, MA_ERROR_INVALID_PARAMETER);
+}
+
+TEST_F(MultiAssistantSettingMultipleOnTest, utc_ma_settings_set_voice_assistant_enabled_operation_failed)
+{
+ int ret = ma_settings_set_voice_assistant_enabled(TEST_VOICE_ASSISTANT_APPID, true);
+ EXPECT_EQ(ret, MA_ERROR_OPERATION_FAILED);
+}
+
+TEST_F(MultiAssistantSettingMultipleOnTest, utc_ma_settings_get_default_voice_assistant_operation_failed)
+{
+ char *appid = nullptr;
+ int ret = ma_settings_get_default_voice_assistant(&appid);
+ EXPECT_EQ(ret, MA_ERROR_OPERATION_FAILED);
+}
--- /dev/null
+#include "vconf_mock.h"
+#include <string.h>
+#include <stdio.h>
+#include <tizen.h>
+#include <string>
+#include <map>
+
+static bool multiple_mode = false;
+
+static std::map<std::string, std::string> vconfStrMap;
+static std::map<std::string, int> vconfBoolMap;
+
+#define VCONF_OK 0
+#define VCONF_ERROR -1
+
+void set_multiple_mode(bool mode)
+{
+ multiple_mode = mode;
+}
+
+EXPORT_API int __wrap_vconf_set_bool(const char *key, const int val)
+{
+ vconfBoolMap[key] = val;
+ return VCONF_OK;
+}
+
+EXPORT_API int __wrap_vconf_get_bool(const char *key, int *val)
+{
+ if (vconfBoolMap.find(key) != vconfBoolMap.end()) {
+ if (val) {
+ *val = vconfBoolMap[key];
+ }
+ return VCONF_OK;
+ }
+ else {
+ return VCONF_ERROR;
+ }
+}
+
+EXPORT_API int __wrap_vconf_set_str(const char *key, const char *val)
+{
+ vconfStrMap[key] = std::string(val ? val : "");
+ return VCONF_OK;
+}
+
+EXPORT_API char *__wrap_vconf_get_str(const char *key)
+{
+ if (vconfBoolMap.find(key) != vconfBoolMap.end()) {
+ return strdup(vconfStrMap[key].c_str());
+ }
+ else
+ return NULL;
+}
--- /dev/null
+#ifndef MOCK_VCONF_H_
+#define MOCK_VCONF_H_
+
+#include <sys/types.h>
+#include <unistd.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void set_multiple_mode(bool mode);
+
+int __wrap_vconf_set_bool(const char *key, const int val);
+int __wrap_vconf_get_bool(const char *key, int *val);
+int __wrap_vconf_set_str(const char *key, const char *val);
+char *__wrap_vconf_get_str(const char *key);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* MOCK_VCONF_H_ */