1 /*
2  * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "edm_data_ability_utils_mock.h"
17 
18 #include "edm_log.h"
19 
20 namespace OHOS {
21 namespace EDM {
22 
23 const std::string KEY_POWER_SUSPEND = "settings.power.suspend_sources";
24 std::string EdmDataAbilityUtils::result_;
SetResult(const std::string & result)25 void EdmDataAbilityUtils::SetResult(const std::string &result)
26 {
27     result_ = result;
28 }
29 
GetStringFromSettingsDataShare(const std::string & key,std::string & value)30 ErrCode EdmDataAbilityUtils::GetStringFromSettingsDataShare(const std::string &key, std::string &value)
31 {
32     GTEST_LOG_(INFO) << "mock EdmDataAbilityUtils GetStringFromDataShare start: " << result_.c_str();
33     if (result_ == "test Failed") {
34         GTEST_LOG_(INFO) << "mock EdmDataAbilityUtils test Failed";
35         return EdmReturnErrCode::SYSTEM_ABNORMALLY;
36     } else if (result_ == "test value nullptr") {
37         GTEST_LOG_(INFO) << "mock EdmDataAbilityUtils test nullptr";
38         return ERR_OK;
39     } else if (result_ == "power_suspend_normal") {
40         value =
41             "{\"lid\":{\"action\":1,\"delayMs\":0},\"powerkey\":{\"action\":1,\"delayMs\":0},\"switch\":{\"action\":1,"
42             "\"delayMs\":0},\"timeout\":{\"action\":1,\"delayMs\":0}}";
43         return ERR_OK;
44     } else if (result_ == "power_suspend_json_error") {
45         value = "json error";
46         return ERR_OK;
47     } else if (result_ == "power_suspend_json_no_time_out") {
48         value =
49             "{\"lid\":{\"action\":1,\"delayMs\":0},\"powerkey\":{\"action\":1,\"delayMs\":0},\"switch\":{\"action\":1,"
50             "\"delayMs\":0},\"timeerror\":{\"action\":1,\"delayMs\":0}}";
51         return ERR_OK;
52     } else if (result_ == "power_suspend_json_key_not_object") {
53         value =
54             "{\"lid\":{\"action\":1,\"delayMs\":0},\"powerkey\":{\"action\":1,\"delayMs\":0},\"switch\":{\"action\":1,"
55             "\"delayMs\":0},\"timeout\":1000}";
56         return ERR_OK;
57     }
58     GTEST_LOG_(INFO) << "mock EdmDataAbilityUtils test Success";
59     value = "test query success";
60     return ERR_OK;
61 }
62 
GetIntFromSettingsDataShare(const std::string & key,int32_t & value)63 ErrCode EdmDataAbilityUtils::GetIntFromSettingsDataShare(const std::string &key, int32_t &value)
64 {
65     GTEST_LOG_(INFO) << "mock EdmDataAbilityUtils GetIntFromDataShare start: " << result_.c_str();
66     if (result_ == "SYSTEM_ABNORMALLY") {
67         GTEST_LOG_(INFO) << "mock EdmDataAbilityUtils result SYSTEM_ABNORMALLY";
68         return EdmReturnErrCode::SYSTEM_ABNORMALLY;
69     }
70     GTEST_LOG_(INFO) << "mock EdmDataAbilityUtils test Success";
71     value = 0;
72     return ERR_OK;
73 }
74 } // namespace EDM
75 } // namespace OHOS