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" 17 18export const ResultSetMock = { 19 columnNames: "[PC Preview] unknow columnNames", 20 columnCount: "[PC Preview] unknow columnCount", 21 rowCount: "[PC Preview] unknow rowCount", 22 rowIndex: "[PC Preview] unknow rowIndex", 23 isAtFirstRow: "[PC Preview] unknow isAtFirstRow", 24 isAtLastRow: "[PC Preview] unknow isAtLastRow", 25 isEnded: "[PC Preview] unknow isEnded", 26 isStarted: "[PC Preview] unknow isStarted", 27 isClose: "[PC Preview] unknow isClose", 28 getColumnIndex: function (...args) { 29 console.warn("ResultSet.getColumnIndex interface mocked in the Previewer. How this interface works on the Previewer" + 30 " may be different from that on a real device.") 31 return paramMock.paramNumberMock; 32 }, 33 getColumnName: function (...args) { 34 console.warn("ResultSet.getColumnName interface mocked in the Previewer. How this interface works on the Previewer" + 35 " may be different from that on a real device.") 36 return paramMock.paramStringMock; 37 }, 38 goTo: function (...args) { 39 console.warn("ResultSet.goTo interface mocked in the Previewer. How this interface works on the Previewer" + 40 " may be different from that on a real device.") 41 return paramMock.paramBooleanMock; 42 }, 43 goToRow: function (...args) { 44 console.warn("ResultSet.goToRow interface mocked in the Previewer. How this interface works on the Previewer" + 45 " may be different from that on a real device.") 46 return paramMock.paramBooleanMock; 47 }, 48 goToLastRow: function (...args) { 49 console.warn("ResultSet.goToLastRow interface mocked in the Previewer. How this interface works on the Previewer" + 50 " may be different from that on a real device.") 51 return paramMock.paramBooleanMock; 52 }, 53 goToFirstRow: function (...args) { 54 console.warn("ResultSet.goToFirstRow interface mocked in the Previewer. How this interface works on the Previewer" + 55 " may be different from that on a real device.") 56 return paramMock.paramBooleanMock; 57 }, 58 goToNextRow: function (...args) { 59 console.warn("ResultSet.goToNextRow interface mocked in the Previewer. How this interface works on the Previewer" + 60 " may be different from that on a real device.") 61 return paramMock.paramBooleanMock; 62 }, 63 goToPreviousRow: function (...args) { 64 console.warn("ResultSet.goToPreviousRow interface mocked in the Previewer. How this interface works on the Previewer" + 65 " may be different from that on a real device.") 66 return paramMock.paramBooleanMock; 67 }, 68 getBlob: function (...args) { 69 console.warn("ResultSet.getBlob interface mocked in the Previewer. How this interface works on the Previewer" + 70 " may be different from that on a real device.") 71 return paramMock.paramArrayMock; 72 }, 73 getString: function (...args) { 74 console.warn("ResultSet.getString interface mocked in the Previewer. How this interface works on the Previewer" + 75 " may be different from that on a real device.") 76 return paramMock.paramStringMock; 77 }, 78 getLong: function (...args) { 79 console.warn("ResultSet.getLong interface mocked in the Previewer. How this interface works on the Previewer" + 80 " may be different from that on a real device.") 81 return paramMock.paramNumberMock; 82 }, 83 getDouble: function (...args) { 84 console.warn("ResultSet.getDouble interface mocked in the Previewer. How this interface works on the Previewer" + 85 " may be different from that on a real device.") 86 return paramMock.paramNumberMock; 87 }, 88 isColumnNull: function (...args) { 89 console.warn("ResultSet.isColumnNull interface mocked in the Previewer. How this interface works on the Previewer" + 90 " may be different from that on a real device.") 91 return paramMock.paramBooleanMock; 92 }, 93 close: function () { 94 console.warn("ResultSet.isColumnNull interface mocked in the Previewer. How this interface works on the Previewer" + 95 " may be different from that on a real device.") 96 } 97} 98export function mockDataShare() { 99 const getFileTypesArrayMock = [ 100 paramMock.paramStringMock 101 ] 102 const PacMapTypeMock = { 103 PacMap: new Map([["[PC Preview] unknow PacMapKey", "[PC Preview] unknow PacMapValue"]]) 104 } 105 const DataShareHelperMock = { 106 on: function (...args) { 107 console.warn("DataShareHelper.on interface mocked in the Previewer. How this interface works on the Previewer" + 108 " may be different from that on a real device.") 109 const len = args.length 110 if (typeof args[len - 1] === 'function') { 111 args[len - 1].call(this, paramMock.businessErrorMock) 112 } 113 }, 114 off: function (...args) { 115 console.warn("DataShareHelper.off interface mocked in the Previewer. How this interface works on the Previewer" + 116 " may be different from that on a real device.") 117 const len = args.length 118 if (typeof args[len - 1] === 'function') { 119 args[len - 1].call(this, paramMock.businessErrorMock) 120 } 121 }, 122 getType: function (...args) { 123 console.warn("DataShareHelper.getType interface mocked in the Previewer. How this interface works on the Previewer" + 124 " may be different from that on a real device.") 125 const len = args.length 126 if (typeof args[len - 1] === 'function') { 127 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) 128 } else { 129 return new Promise((resolve) => { 130 resolve(paramMock.paramStringMock); 131 }) 132 } 133 }, 134 getFileTypes: function (...args) { 135 console.warn("DataShareHelper.getFileTypes interface mocked in the Previewer. How this interface works on the Previewer" + 136 " may be different from that on a real device.") 137 const len = args.length 138 if (typeof args[len - 1] === 'function') { 139 args[len - 1].call(this, paramMock.businessErrorMock, getFileTypesArrayMock) 140 } else { 141 return new Promise((resolve) => { 142 resolve(getFileTypesArrayMock); 143 }) 144 } 145 }, 146 normalizeUri: function (...args) { 147 console.warn("DataShareHelper.normalizeUri interface mocked in the Previewer. How this interface works on the Previewer" + 148 " may be different from that on a real device.") 149 const len = args.length 150 if (typeof args[len - 1] === 'function') { 151 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) 152 } else { 153 return new Promise((resolve) => { 154 resolve(paramMock.paramStringMock); 155 }) 156 } 157 }, 158 denormalizeUri: function (...args) { 159 console.warn("DataShareHelper.denormalizeUri interface mocked in the Previewer. How this interface works on the Previewer" + 160 " may be different from that on a real device.") 161 const len = args.length 162 if (typeof args[len - 1] === 'function') { 163 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) 164 } else { 165 return new Promise((resolve) => { 166 resolve(paramMock.paramStringMock); 167 }) 168 } 169 }, 170 notifyChange: function (...args) { 171 console.warn("DataShareHelper.notifyChange interface mocked in the Previewer. How this interface works on the Previewer" + 172 " may be different from that on a real device.") 173 const len = args.length 174 if (typeof args[len - 1] === 'function') { 175 args[len - 1].call(this, paramMock.businessErrorMock) 176 } else { 177 return new Promise((resolve) => { 178 resolve(); 179 }) 180 } 181 }, 182 insert: function (...args) { 183 console.warn("DataShareHelper.insert interface mocked in the Previewer. How this interface works on the Previewer" + 184 " may be different from that on a real device.") 185 const len = args.length 186 if (typeof args[len - 1] === 'function') { 187 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 188 } else { 189 return new Promise((resolve) => { 190 resolve(paramMock.paramNumberMock); 191 }) 192 } 193 }, 194 batchInsert: function (...args) { 195 console.warn("DataShareHelper.batchInsert interface mocked in the Previewer. How this interface works on the Previewer" + 196 " may be different from that on a real device.") 197 const len = args.length 198 if (typeof args[len - 1] === 'function') { 199 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 200 } else { 201 return new Promise((resolve) => { 202 resolve(paramMock.paramNumberMock); 203 }) 204 } 205 }, 206 delete: function (...args) { 207 console.warn("DataShareHelper.delete interface mocked in the Previewer. How this interface works on the Previewer" + 208 " may be different from that on a real device.") 209 const len = args.length 210 if (typeof args[len - 1] === 'function') { 211 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 212 } else { 213 return new Promise((resolve) => { 214 resolve(paramMock.paramNumberMock); 215 }) 216 } 217 }, 218 update: function (...args) { 219 console.warn("DataShareHelper.update interface mocked in the Previewer. How this interface works on the Previewer" + 220 " may be different from that on a real device.") 221 const len = args.length 222 if (typeof args[len - 1] === 'function') { 223 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) 224 } else { 225 return new Promise((resolve) => { 226 resolve(paramMock.paramNumberMock); 227 }) 228 } 229 }, 230 query: function (...args) { 231 console.warn("DataShareHelper.query interface mocked in the Previewer. How this interface works on the Previewer" + 232 " may be different from that on a real device.") 233 const len = args.length 234 if (typeof args[len - 1] === 'function') { 235 args[len - 1].call(this, paramMock.businessErrorMock, ResultSetMock) 236 } else { 237 return new Promise((resolve) => { 238 resolve(ResultSetMock); 239 }) 240 } 241 } 242 } 243 const dataShareMock = { 244 createDataShareHelper: function (...args) { 245 console.warn("data.dataShare.createDataShareHelper mocked in the Previewer. How this interface works on the Previewer may be" + 246 " different from that on a real device.") 247 return DataShareHelperMock; 248 } 249 } 250 return dataShareMock; 251}