• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "test_utils.h"
17 #include <iostream>
18 #include <numeric>
19 #include <sstream>
20 #include "common_event_data.h"
21 #include "common_event_manager.h"
22 namespace OHOS {
23 namespace AppExecFwk {
24 using namespace OHOS::EventFwk;
PublishEvent(const std::string & eventName,const int & code,const std::string & data)25 bool TestUtils::PublishEvent(const std::string &eventName, const int &code, const std::string &data)
26 {
27     Want want;
28     want.SetAction(eventName);
29     CommonEventData commonData;
30     commonData.SetWant(want);
31     commonData.SetCode(code);
32     commonData.SetData(data);
33     return CommonEventManager::PublishCommonEvent(commonData);
34 }
35 
MakeWant(std::string deviceId,std::string abilityName,std::string bundleName,std::map<std::string,std::string> params)36 Want TestUtils::MakeWant(
37     std::string deviceId, std::string abilityName, std::string bundleName, std::map<std::string, std::string> params)
38 {
39     ElementName element(deviceId, bundleName, abilityName);
40     Want want;
41     want.SetElement(element);
42     for (const auto &param : params) {
43         want.SetParam(param.first, param.second);
44     }
45     return want;
46 }
47 }  // namespace AppExecFwk
48 }  // namespace OHOS