• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     return GetStringFromSettingsDataShare("", key, value);
33 }
34 
GetIntFromSettingsDataShare(const std::string & key,int32_t & value)35 ErrCode EdmDataAbilityUtils::GetIntFromSettingsDataShare(const std::string &key, int32_t &value)
36 {
37     return GetIntFromSettingsDataShare("", key, value);
38 }
39 
GetStringFromSettingsDataShare(const std::string & settingsDataUri,const std::string & key,std::string & value)40 ErrCode EdmDataAbilityUtils::GetStringFromSettingsDataShare(const std::string &settingsDataUri, const std::string &key,
41     std::string &value)
42 {
43     GTEST_LOG_(INFO) << "mock EdmDataAbilityUtils GetStringFromDataShare start: " << result_.c_str();
44     if (result_ == "test Failed") {
45         GTEST_LOG_(INFO) << "mock EdmDataAbilityUtils test Failed";
46         return EdmReturnErrCode::SYSTEM_ABNORMALLY;
47     } else if (result_ == "test value nullptr") {
48         GTEST_LOG_(INFO) << "mock EdmDataAbilityUtils test nullptr";
49         return ERR_OK;
50     } else if (result_ == "power_suspend_normal") {
51         value =
52             "{\"lid\":{\"action\":1,\"delayMs\":0},\"powerkey\":{\"action\":1,\"delayMs\":0},\"switch\":{\"action\":1,"
53             "\"delayMs\":0},\"timeout\":{\"action\":1,\"delayMs\":0}}";
54         return ERR_OK;
55     } else if (result_ == "power_suspend_json_error") {
56         value = "json error";
57         return ERR_OK;
58     } else if (result_ == "power_suspend_json_no_time_out") {
59         value =
60             "{\"lid\":{\"action\":1,\"delayMs\":0},\"powerkey\":{\"action\":1,\"delayMs\":0},\"switch\":{\"action\":1,"
61             "\"delayMs\":0},\"timeerror\":{\"action\":1,\"delayMs\":0}}";
62         return ERR_OK;
63     } else if (result_ == "power_suspend_json_key_not_object") {
64         value =
65             "{\"lid\":{\"action\":1,\"delayMs\":0},\"powerkey\":{\"action\":1,\"delayMs\":0},\"switch\":{\"action\":1,"
66             "\"delayMs\":0},\"timeout\":1000}";
67         return ERR_OK;
68     }
69     GTEST_LOG_(INFO) << "mock EdmDataAbilityUtils test Success";
70     value = "test query success";
71     return ERR_OK;
72 }
73 
GetIntFromSettingsDataShare(const std::string & strUri,const std::string & key,int32_t & value)74 ErrCode EdmDataAbilityUtils::GetIntFromSettingsDataShare(const std::string &strUri, const std::string &key,
75     int32_t &value)
76 {
77     GTEST_LOG_(INFO) << "mock EdmDataAbilityUtils GetIntFromDataShare start: " << result_.c_str();
78     if (result_ == "SYSTEM_ABNORMALLY") {
79         GTEST_LOG_(INFO) << "mock EdmDataAbilityUtils result SYSTEM_ABNORMALLY";
80         return EdmReturnErrCode::SYSTEM_ABNORMALLY;
81     }
82     GTEST_LOG_(INFO) << "mock EdmDataAbilityUtils test Success";
83     value = 0;
84     return ERR_OK;
85 }
86 } // namespace EDM
87 } // namespace OHOS