SET(TARGET_TIZEN_ACTION_SERVICE "tizen-action-service")
SET(TARGET_TIZEN_ACTION_PLUGIN_DAEMON "tizen-action-plugin-daemon")
-#ENABLE_TESTING()
-#SET(TARGET_TIZEN_ACTION_UNIT_TEST "tizen-action-unit-test")
+ENABLE_TESTING()
+SET(TARGET_TIZEN_ACTION_UNIT_TEST "tizen-action-unit-test")
+ADD_TEST(NAME ${TARGET_TIZEN_ACTION_UNIT_TEST}
+ COMMAND ${TARGET_TIZEN_ACTION_UNIT_TEST}
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test/unit_tests)
INCLUDE(FindPkgConfig)
INCLUDE(ApplyPkgConfig)
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(tool)
+ADD_SUBDIRECTORY(test)
%__make %{?_smp_mflags}
+%check
+export LD_LIBRARY_PATH="../../src/action:../../src/common"
+ctest -V %{?_smp_mflags}
+
%install
%make_install
mkdir -p %{buildroot}%{_unitdir}/basic.target.wants
--- /dev/null
+ADD_SUBDIRECTORY(unit_tests)
--- /dev/null
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} UNIT_TEST_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/action ACTION_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/common COMMON_SRCS)
+
+ADD_EXECUTABLE(${TARGET_TIZEN_ACTION_UNIT_TEST}
+ ${UNIT_TEST_SRCS}
+ ${AUL_SRCS}
+ ${COMMON_SRCS}
+ ${ACTION_SRCS})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_TIZEN_ACTION_UNIT_TEST} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/../
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../src
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../src/action
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../src/common)
+
+APPLY_PKG_CONFIG(${TARGET_TIZEN_ACTION_UNIT_TEST} PUBLIC
+ GLIB_DEPS
+ GMOCK_DEPS
+)
+
+TARGET_LINK_LIBRARIES(${TARGET_TIZEN_ACTION_UNIT_TEST} PRIVATE ${TARGET_TIZEN_ACTION} ${TARGET_TIZEN_ACTION_COMMON})
+SET_TARGET_PROPERTIES(${TARGET_TIZEN_ACTION_UNIT_TEST} PROPERTIES
+ COMPILE_FLAGS "-fPIE")
+SET_TARGET_PROPERTIES(${TARGET_TIZEN_ACTION_UNIT_TEST} PROPERTIES
+ LINK_FLAGS "-pie")
--- /dev/null
+#include <gtest/gtest.h>
+#include "action_executor_factory.hh"
+#include "app_control_executor.hh"
+#include "plugin_executor.hh"
+#include "common/action_model.h"
+
+namespace action {
+
+class ActionExecutorFactoryTest : public ::testing::Test {
+ protected:
+ common::ActionModel app_control_action;
+ common::ActionModel plugin_action;
+ common::ActionModel default_action;
+
+ void SetUp() override {
+ app_control_action.SetType(common::ActionType::AppControl);
+
+ plugin_action.SetType(common::ActionType::Plugin);
+
+ default_action.SetType(static_cast<common::ActionType>(-1));
+ }
+};
+
+TEST_F(ActionExecutorFactoryTest, CreateAppControlExecutor) {
+ auto executor = ActionExecutorFactory::CreateExecutor("instance", app_control_action);
+ ASSERT_NE(executor, nullptr);
+
+ auto* app_control_executor = dynamic_cast<AppControlExecutor*>(executor.get());
+ ASSERT_NE(app_control_executor, nullptr);
+}
+
+TEST_F(ActionExecutorFactoryTest, CreatePluginExecutor) {
+ auto executor = ActionExecutorFactory::CreateExecutor("instance", plugin_action);
+ ASSERT_NE(executor, nullptr);
+
+ auto* plugin_executor = dynamic_cast<PluginExecutor*>(executor.get());
+ ASSERT_NE(plugin_executor, nullptr);
+}
+
+TEST_F(ActionExecutorFactoryTest, CreateDefaultExecutor) {
+ auto executor = ActionExecutorFactory::CreateExecutor("instance", default_action);
+ ASSERT_NE(executor, nullptr);
+
+ auto* appcontrol_executor = dynamic_cast<AppControlExecutor*>(executor.get());
+ ASSERT_EQ(appcontrol_executor, nullptr);
+ auto* plugin_executor = dynamic_cast<PluginExecutor*>(executor.get());
+ ASSERT_EQ(plugin_executor, nullptr);
+}
+
+} // namespace action
--- /dev/null
+#include <gtest/gtest.h>
+#include "common/action_model.h"
+
+using namespace common;
+
+TEST(ActionModelTest, SettersAndGetters) {
+ ActionModel model;
+
+ model.SetActionId("new_action");
+ model.SetAppId("new_app");
+ model.SetDescription("New Desc");
+ model.SetParameters({ActionParameter("param1", ParameterType::StringType, "type1", "desc1", true)});
+ model.SetPrivileges({"privilege2"});
+ model.SetType(ActionType::AppControl);
+
+ EXPECT_EQ("new_action", model.GetActionId());
+ EXPECT_EQ("new_app", model.GetAppId());
+ EXPECT_EQ("New Desc", model.GetDescription());
+ EXPECT_EQ(1, model.GetParameters().size());
+ EXPECT_EQ(1, model.GetPrivileges().size());
+ EXPECT_EQ(ActionType::AppControl, model.GetType());
+}
+
+TEST(ActionModelTest, EmptyInitialization) {
+ ActionModel model;
+ EXPECT_EQ("", model.GetActionId());
+ EXPECT_EQ("", model.GetAppId());
+ EXPECT_EQ("", model.GetDescription());
+ EXPECT_EQ(0, model.GetParameters().size());
+ EXPECT_EQ(0, model.GetPrivileges().size());
+}
+
+TEST(ActionModelTest, ParameterVectorTest) {
+ ActionModel model;
+ std::vector<ActionParameter> params = {
+ ActionParameter("name1", ParameterType::StringType, "type1", "desc1", true),
+ ActionParameter("name2", ParameterType::StringType, "type2", "desc2", false)
+ };
+ model.SetParameters(params);
+ EXPECT_EQ(2, model.GetParameters().size());
+ EXPECT_EQ("name1", model.GetParameters()[0].GetName());
+}
+
+TEST(ActionModelTest, PrivilegeVectorTest) {
+ ActionModel model;
+ model.SetPrivileges({"priv1", "priv2"});
+ EXPECT_EQ(2, model.GetPrivileges().size());
+ EXPECT_EQ("priv1", model.GetPrivileges()[0]);
+}
--- /dev/null
+#include <gtest/gtest.h>
+#include "common/action_parameter.h"
+
+namespace common {
+
+class ActionParameterTest : public ::testing::Test {
+protected:
+ void SetUp() override {
+ param_ = new ActionParameter("test_name", ParameterType::StringType, "test_value", "test_description", true);
+ }
+
+ void TearDown() override {
+ delete param_;
+ }
+
+ ActionParameter* param_;
+};
+
+TEST_F(ActionParameterTest, GetNameTest) {
+ EXPECT_EQ(param_->GetName(), "test_name");
+}
+
+TEST_F(ActionParameterTest, SetNameTest) {
+ param_->SetName("new_name");
+ EXPECT_EQ(param_->GetName(), "new_name");
+}
+
+TEST_F(ActionParameterTest, GetTypeTest) {
+ EXPECT_EQ(param_->GetType(), ParameterType::StringType);
+}
+
+TEST_F(ActionParameterTest, SetTypeTest) {
+ param_->SetType(ParameterType::IntType);
+ EXPECT_EQ(param_->GetType(), ParameterType::IntType);
+}
+
+TEST_F(ActionParameterTest, GetValueTest) {
+ EXPECT_EQ(param_->GetValue(), "test_value");
+}
+
+TEST_F(ActionParameterTest, SetValueTest) {
+ param_->SetValue("new_value");
+ EXPECT_EQ(param_->GetValue(), "new_value");
+}
+
+TEST_F(ActionParameterTest, GetDescriptionTest) {
+ EXPECT_EQ(param_->GetDescription(), "test_description");
+}
+
+TEST_F(ActionParameterTest, SetDescriptionTest) {
+ param_->SetDescription("new_description");
+ EXPECT_EQ(param_->GetDescription(), "new_description");
+}
+
+TEST_F(ActionParameterTest, GetIsRequiredTest) {
+ EXPECT_TRUE(param_->GetIsRequired());
+}
+
+TEST_F(ActionParameterTest, SetIsRequiredTest) {
+ param_->SetIsRequired(false);
+ EXPECT_FALSE(param_->GetIsRequired());
+}
+
+} // namespace common
--- /dev/null
+/*
+ * 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 <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <stdio.h>
+
+#ifdef LOG_INTERNAL
+#include <dlog.h>
+
+extern "C" int __dlog_print(log_id_t log_id, int prio, const char* tag,
+ const char* fmt, ...) {
+ printf("%s:", tag);
+ va_list ap;
+ va_start(ap, fmt);
+ vprintf(fmt, ap);
+ va_end(ap);
+ printf("\n");
+
+ return 0;
+}
+#endif
+
+int main(int argc, char** argv) {
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}