• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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
16import { paramMock } from "../utils"
17import { DataAbilityHelper } from "./ability/dataAbilityHelper"
18
19export function mockParticleAbility() {
20  const particleAbility = {
21    startAbility: function (...args) {
22      console.warn("ability.particleAbility.startAbility interface mocked in the Previewer. How this interface works" +
23        " on the Previewer may be different from that on a real device.")
24      const len = args.length
25      if (typeof args[len - 1] === 'function') {
26        args[len - 1].call(this, paramMock.businessErrorMock)
27      } else {
28        return new Promise((resolve) => {
29          resolve()
30        })
31      }
32    },
33    terminateSelf: function (...args) {
34      console.warn("ability.particleAbility.terminateSelf interface mocked in the Previewer. How this interface works" +
35        " on the Previewer may be different from that on a real device.")
36      const len = args.length
37      if (typeof args[len - 1] === 'function') {
38        args[len - 1].call(this, paramMock.businessErrorMock)
39      } else {
40        return new Promise((resolve) => {
41          resolve()
42        })
43      }
44    },
45    acquireDataAbilityHelper: function (...args) {
46      console.warn("ability.particleAbility.acquireDataAbilityHelper interface mocked in the Previewer. How this interface works" +
47        " on the Previewer may be different from that on a real device.")
48      return DataAbilityHelper;
49    },
50    connectAbility: function (...args) {
51      console.warn("ability.particleAbility.connectAbility interface mocked in the Previewer. How this interface works" +
52        " on the Previewer may be different from that on a real device.")
53      return paramMock.paramNumberMock;
54    },
55    disconnectAbility: function (...args) {
56      console.warn("ability.particleAbility.disconnectAbility interface mocked in the Previewer. How this interface works" +
57        " on the Previewer may be different from that on a real device.")
58      const len = args.length
59      if (typeof args[len - 1] === 'function') {
60        args[len - 1].call(this, paramMock.businessErrorMock)
61      } else {
62        return new Promise((resolve) => {
63          resolve()
64        })
65      }
66    },
67    startBackgroundRunning: function (...args) {
68      console.warn("ability.particleAbility.startBackgroundRunning interface mocked in the Previewer. How this interface works" +
69        " on the Previewer may be different from that on a real device.")
70      const len = args.length
71      if (typeof args[len - 1] === 'function') {
72        args[len - 1].call(this, paramMock.businessErrorMock)
73      } else {
74        return new Promise((resolve) => {
75          resolve()
76        })
77      }
78    },
79    cancelBackgroundRunning: function (...args) {
80      console.warn("ability.particleAbility.cancelBackgroundRunning interface mocked in the Previewer. How this interface works" +
81        " on the Previewer may be different from that on a real device.")
82      const len = args.length
83      if (typeof args[len - 1] === 'function') {
84        args[len - 1].call(this, paramMock.businessErrorMock)
85      } else {
86        return new Promise((resolve) => {
87          resolve()
88        })
89      }
90    },
91    ErrorCode : {
92      INVALID_PARAMETER: -1,
93    }
94  }
95  return particleAbility;
96}