2 * Copyright 2020 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <gtest/gtest.h>
19 #include "service_main.h"
25 class CDummyApplicationManager : public IApplicationManager
28 CDummyApplicationManager() {};
29 ~CDummyApplicationManager() {};
31 bool is_application_running(pid_t pid) override { return false; }
32 bool is_application_running(const std::string& appid) override { return false; }
33 bool bring_app_to_foreground(const std::string& appid) override
35 brought_to_foreground_appid = appid;
38 bool launch_app_async(const std::string& appid, bool background) override
40 launched_appid = appid;
41 launched_option_background = background;
44 boost::optional<std::string> get_appid_by_pid(pid_t pid) override { return boost::optional<std::string>{}; }
46 boost::optional<std::string> launched_appid;
47 boost::optional<bool> launched_option_background;
48 boost::optional<std::string> brought_to_foreground_appid;;
51 class CDummyPreferenceManager : public IPreferenceManager
54 CDummyPreferenceManager() {}
55 ~CDummyPreferenceManager() {}
57 boost::optional<std::string> get_string(const std::string& key) override
59 boost::optional<std::string> ret;
60 const auto& iter = key_value_string.find(key);
61 if (iter != key_value_string.end()) {
66 boost::optional<int> get_int(const std::string& key) override
68 boost::optional<int> ret;
69 const auto& iter = key_value_int.find(key);
70 if (iter != key_value_int.end()) {
75 boost::optional<bool> get_bool(const std::string& key) override
77 boost::optional<bool> ret;
78 const auto& iter = key_value_bool.find(key);
79 if (iter != key_value_bool.end()) {
85 bool register_changed_callback(
86 const std::string& key, preference_changed_cb calback, void* user_data) override { return true; }
87 bool unregister_changed_callback(
88 const std::string& key, preference_changed_cb callback) override { return true; }
90 std::map<std::string, std::string> key_value_string;
91 std::map<std::string, int> key_value_int;
92 std::map<std::string, bool> key_value_bool;
95 class DefaultFixure : public testing::Test
100 virtual ~DefaultFixure() {
102 void SetUp() override {
104 void TearDown() override {
106 CDummyApplicationManager application_manager;
107 CDummyPreferenceManager preference_manager;
109 CServiceMain service{application_manager, preference_manager};
112 TEST_F(DefaultFixure, BringsDefaultAssistantToFrontOnAssistantActivatedPreprocessingStateEvent) {
113 std::string assistant_appid{"Arbitrary Assistant"};
114 ma_assistant_info_s info;
115 info.app_id = assistant_appid.c_str();
116 service.add_assistant_info(&info);
117 service.mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED);
119 bool brought = false;
120 if (application_manager.brought_to_foreground_appid) {
124 ASSERT_TRUE(brought);
127 int main(int argc, char** argv) {
128 const char* seconds = getenv("TEST_SLEEP_SECONDS");
130 sleep(atoi(seconds));
132 testing::InitGoogleTest(&argc, argv);
133 int ret = RUN_ALL_TESTS();