• 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 { DataShareResultSetMock } from "./ohos_data_DataShareResultSet"
18
19
20export function mockDataShare() {
21  const getFileTypesArrayMock = [
22    paramMock.paramStringMock
23  ]
24  const PacMapTypeMock = {
25    PacMap: new Map([["[PC Preview] unknow PacMapKey", "[PC Preview] unknow PacMapValue"]])
26  }
27  const DataShareHelperMock = {
28    on: function (...args) {
29      console.warn("DataShareHelper.on interface mocked in the Previewer. How this interface works on the Previewer" +
30        " may be different from that on a real device.")
31      const len = args.length
32      if (typeof args[len - 1] === 'function') {
33        args[len - 1].call(this, paramMock.businessErrorMock)
34      }
35    },
36    off: function (...args) {
37      console.warn("DataShareHelper.off interface mocked in the Previewer. How this interface works on the Previewer" +
38        " may be different from that on a real device.")
39      const len = args.length
40      if (typeof args[len - 1] === 'function') {
41        args[len - 1].call(this, paramMock.businessErrorMock)
42      }
43    },
44    getType: function (...args) {
45      console.warn("DataShareHelper.getType interface mocked in the Previewer. How this interface works on the Previewer" +
46        " may be different from that on a real device.")
47      const len = args.length
48      if (typeof args[len - 1] === 'function') {
49        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock)
50      } else {
51        return new Promise((resolve, reject) => {
52          resolve(paramMock.paramStringMock);
53        })
54      }
55    },
56    getFileTypes: function (...args) {
57      console.warn("DataShareHelper.getFileTypes interface mocked in the Previewer. How this interface works on the Previewer" +
58        " may be different from that on a real device.")
59      const len = args.length
60      if (typeof args[len - 1] === 'function') {
61        args[len - 1].call(this, paramMock.businessErrorMock, getFileTypesArrayMock)
62      } else {
63        return new Promise((resolve, reject) => {
64          resolve(getFileTypesArrayMock);
65        })
66      }
67    },
68    normalizeUri: function (...args) {
69      console.warn("DataShareHelper.normalizeUri interface mocked in the Previewer. How this interface works on the Previewer" +
70        " may be different from that on a real device.")
71      const len = args.length
72      if (typeof args[len - 1] === 'function') {
73        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock)
74      } else {
75        return new Promise((resolve, reject) => {
76          resolve(paramMock.paramStringMock);
77        })
78      }
79    },
80    denormalizeUri: function (...args) {
81      console.warn("DataShareHelper.denormalizeUri interface mocked in the Previewer. How this interface works on the Previewer" +
82        " may be different from that on a real device.")
83      const len = args.length
84      if (typeof args[len - 1] === 'function') {
85        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock)
86      } else {
87        return new Promise((resolve, reject) => {
88          resolve(paramMock.paramStringMock);
89        })
90      }
91    },
92    notifyChange: function (...args) {
93      console.warn("DataShareHelper.notifyChange interface mocked in the Previewer. How this interface works on the Previewer" +
94        " may be different from that on a real device.")
95      const len = args.length
96      if (typeof args[len - 1] === 'function') {
97        args[len - 1].call(this, paramMock.businessErrorMock)
98      } else {
99        return new Promise((resolve, reject) => {
100          resolve();
101        })
102      }
103    },
104    insert: function (...args) {
105      console.warn("DataShareHelper.insert interface mocked in the Previewer. How this interface works on the Previewer" +
106        " may be different from that on a real device.")
107      const len = args.length
108      if (typeof args[len - 1] === 'function') {
109        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock)
110      } else {
111        return new Promise((resolve, reject) => {
112          resolve(paramMock.paramNumberMock);
113        })
114      }
115    },
116    batchInsert: function (...args) {
117      console.warn("DataShareHelper.batchInsert interface mocked in the Previewer. How this interface works on the Previewer" +
118        " may be different from that on a real device.")
119      const len = args.length
120      if (typeof args[len - 1] === 'function') {
121        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock)
122      } else {
123        return new Promise((resolve, reject) => {
124          resolve(paramMock.paramNumberMock);
125        })
126      }
127    },
128    delete: function (...args) {
129      console.warn("DataShareHelper.delete interface mocked in the Previewer. How this interface works on the Previewer" +
130        " may be different from that on a real device.")
131      const len = args.length
132      if (typeof args[len - 1] === 'function') {
133        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock)
134      } else {
135        return new Promise((resolve, reject) => {
136          resolve(paramMock.paramNumberMock);
137        })
138      }
139    },
140    update: function (...args) {
141      console.warn("DataShareHelper.update interface mocked in the Previewer. How this interface works on the Previewer" +
142        " may be different from that on a real device.")
143      const len = args.length
144      if (typeof args[len - 1] === 'function') {
145        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock)
146      } else {
147        return new Promise((resolve, reject) => {
148          resolve(paramMock.paramNumberMock);
149        })
150      }
151    },
152    query: function (...args) {
153      console.warn("DataShareHelper.query interface mocked in the Previewer. How this interface works on the Previewer" +
154        " may be different from that on a real device.")
155      const len = args.length
156      if (typeof args[len - 1] === 'function') {
157        args[len - 1].call(this, paramMock.businessErrorMock, DataShareResultSetMock)
158      } else {
159        return new Promise((resolve, reject) => {
160          resolve(DataShareResultSetMock);
161        })
162      }
163    },
164    openFile: function (...args) {
165      console.warn("DataShareHelper.OpenFile interface mocked in the Previewer. How this interface works on the Previewer" +
166        " may be different from that on a real device.")
167      const len = args.length
168      if (typeof args[len - 1] === 'function') {
169        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock)
170      } else {
171        return new Promise((resolve, reject) => {
172          resolve(paramMock.paramNumberMock);
173        })
174      }
175    }
176  }
177  const dataShareMock = {
178    createDataShareHelper: function (...args) {
179      console.warn("data.dataShare.createDataShareHelper mocked in the Previewer. How this interface works on the Previewer may be" +
180        " different from that on a real device.")
181        const len = args.length
182        if (typeof args[len - 1] === 'function') {
183          args[len - 1].call(this, paramMock.businessErrorMock, DataShareHelperMock)
184        } else {
185          return new Promise((resolve, reject) => {
186            resolve(DataShareHelperMock);
187          })
188        }
189     }
190  }
191  return dataShareMock;
192}