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 function mockBuffer() { 19 const paramBuffer = { 20 paramIterMock_K : '[PC Preview] unknow iterableiterator_k', 21 paramIterMock_V : '[PC Preview] unknow iterableiterator_v' 22 } 23 const BlobClass = class Blob { 24 constructor(...args) { 25 console.warn('BlobClass.constructor interface mocked in the Previewer. How this interface works on the' + 26 ' Previewer may be different from that on a real device.'); 27 this.size = '[PC preview] unknow size'; 28 this.type = '[PC preview] unknow type'; 29 this.arrayBuffer = function (...args) { 30 console.warn("BlobClass.arrayBuffer interface mocked in the Previewer. How this interface works on the Previewer" + 31 " may be different from that on a real device.") 32 return new Promise((resolve) => { 33 resolve(paramMock.paramArrayMock) 34 }); 35 }; 36 this.slice = function (...args) { 37 console.warn("BlobClass.slice interface mocked in the Previewer. How this interface works on the Previewer" + 38 " may be different from that on a real device.") 39 return new BlobClass(); 40 }; 41 this.text = function (...args) { 42 console.warn("BlobClass.text interface mocked in the Previewer. How this interface works on the Previewer" + 43 " may be different from that on a real device.") 44 return new Promise((resolve) => { 45 resolve(paramMock.paramStringMock) 46 }); 47 }; 48 } 49 } 50 51 const buffer = { 52 alloc: function (...args) { 53 console.warn("buffer.alloc interface mocked in the Previewer. How this interface works on the Previewer" + 54 " may be different from that on a real device.") 55 return new BufferClass(); 56 }, 57 allocUninitializedFromPool: function (...args) { 58 console.warn("buffer.allocUninitializedFromPool interface mocked in the Previewer. How this interface works on the Previewer" + 59 " may be different from that on a real device.") 60 return new BufferClass(); 61 }, 62 allocUninitialized: function (...args) { 63 console.warn("buffer.allocUninitialized interface mocked in the Previewer. How this interface works on the Previewer" + 64 " may be different from that on a real device.") 65 return new BufferClass(); 66 }, 67 byteLength: function (...args) { 68 console.warn("buffer.byteLength interface mocked in the Previewer. How this interface works on the Previewer" + 69 " may be different from that on a real device.") 70 return paramMock.paramNumberMock; 71 }, 72 concat: function (...args) { 73 console.warn("buffer.concat interface mocked in the Previewer. How this interface works on the Previewer" + 74 " may be different from that on a real device.") 75 return new BufferClass(); 76 }, 77 from: function (...args) { 78 console.warn("buffer.from interface mocked in the Previewer. How this interface works on the Previewer" + 79 " may be different from that on a real device.") 80 return new BufferClass(); 81 }, 82 isBuffer: function (...args) { 83 console.warn("buffer.isBuffer interface mocked in the Previewer. How this interface works on the Previewer" + 84 " may be different from that on a real device.") 85 return paramMock.paramBooleanMock; 86 }, 87 isEncoding: function (...args) { 88 console.warn("buffer.isEncoding interface mocked in the Previewer. How this interface works on the Previewer" + 89 " may be different from that on a real device.") 90 return paramMock.paramBooleanMock; 91 }, 92 compare: function (...args) { 93 console.warn("buffer.compare interface mocked in the Previewer. How this interface works on the Previewer" + 94 " may be different from that on a real device.") 95 return paramMock.paramNumberMock; 96 }, 97 transcode: function (...args) { 98 console.warn("buffer.transcode interface mocked in the Previewer. How this interface works on the Previewer" + 99 " may be different from that on a real device.") 100 return new BufferClass(); 101 }, 102 Blob: BlobClass, 103 Buffer: BufferClass 104 } 105 106 const BufferClass = class Buffer { 107 constructor() { 108 console.warn('BufferClass.constructor interface mocked in the Previewer. How this interface works on the' + 109 ' Previewer may be different from that on a real device.'); 110 this.length = '[PC preview] unknow length', 111 this.buffer = '[PC preview] unknow buffer', 112 this.byteOffset = '[PC preview] unknow byteOffset', 113 this.fill = function (...args) { 114 console.warn("Buffer.fill interface mocked in the Previewer. How this interface works on the Previewer" + 115 " may be different from that on a real device.") 116 return new BufferClass(); 117 }, 118 this.compare = function (...args) { 119 console.warn("Buffer.compare interface mocked in the Previewer. How this interface works on the Previewer" + 120 " may be different from that on a real device.") 121 return paramMock.paramNumberMock; 122 }, 123 this.copy = function (...args) { 124 console.warn("Buffer.copy interface mocked in the Previewer. How this interface works on the Previewer" + 125 " may be different from that on a real device.") 126 return paramMock.paramNumberMock; 127 }, 128 this.equals = function (...args) { 129 console.warn("Buffer.equals interface mocked in the Previewer. How this interface works on the Previewer" + 130 " may be different from that on a real device.") 131 return paramMock.paramBooleanMock; 132 }, 133 this.includes = function (...args) { 134 console.warn("Buffer.includes interface mocked in the Previewer. How this interface works on the Previewer" + 135 " may be different from that on a real device.") 136 return paramMock.paramBooleanMock; 137 }, 138 this.indexOf = function (...args) { 139 console.warn("Buffer.indexOf interface mocked in the Previewer. How this interface works on the Previewer" + 140 " may be different from that on a real device.") 141 return paramMock.paramNumberMock; 142 }, 143 this.keys = function (...args) { 144 console.warn("Buffer.keys interface mockecd in the Previewer. How this interface works on the Previewer" + 145 "may be different from that on a real device.") 146 const IteratorKMock = { 147 *[Symbol.iterator]() { 148 yield paramBuffer.paramIterMock_K; 149 } 150 }; 151 return IteratorKMock; 152 }, 153 this.values = function (...args) { 154 console.warn("Buffer.values interface mocked in the Previewer. How this interface works on the Previewer" + 155 " may be different from that on a real device.") 156 const IteratorVMock = { 157 *[Symbol.iterator]() { 158 yield paramBuffer.paramIterMock_V; 159 } 160 }; 161 return IteratorVMock; 162 }, 163 this.entries = function (...args) { 164 console.warn("Buffer.entries interface mocked in the Previewer. How this interface works on the Previewer" + 165 " may be different from that on a real device.") 166 const IteratorEntriesMock = { 167 *[Symbol.iterator]() { 168 yield [paramBuffer.paramIterMock_K, paramBuffer.paramIterMock_V]; 169 } 170 }; 171 return IteratorEntriesMock; 172 }, 173 this.lastIndexOf = function (...args) { 174 console.warn("Buffer.lastIndexOf interface mocked in the Previewer. How this interface works on the Previewer" + 175 " may be different from that on a real device.") 176 return paramMock.paramNumberMock; 177 }, 178 this.readBigInt64BE = function (...args) { 179 console.warn("Buffer.readBigInt64BE interface mocked in the Previewer. How this interface works on the Previewer" + 180 " may be different from that on a real device.") 181 return paramMock.paramNumberMock; 182 }, 183 this.readBigInt64LE = function (...args) { 184 console.warn("Buffer.readBigInt64LE interface mocked in the Previewer. How this interface works on the Previewer" + 185 " may be different from that on a real device.") 186 return paramMock.paramNumberMock; 187 }, 188 this.readBigUInt64BE = function (...args) { 189 console.warn("Buffer.readBigUInt64BE interface mocked in the Previewer. How this interface works on the Previewer" + 190 " may be different from that on a real device.") 191 return paramMock.paramNumberMock; 192 }, 193 this.readBigUInt64LE = function (...args) { 194 console.warn("Buffer.readBigUInt64LE interface mocked in the Previewer. How this interface works on the Previewer" + 195 " may be different from that on a real device.") 196 return paramMock.paramNumberMock; 197 }, 198 this.readDoubleBE = function (...args) { 199 console.warn("Buffer.readDoubleBE interface mocked in the Previewer. How this interface works on the Previewer" + 200 " may be different from that on a real device.") 201 return paramMock.paramNumberMock; 202 }, 203 this.readDoubleLE = function (...args) { 204 console.warn("Buffer.readDoubleLE interface mocked in the Previewer. How this interface works on the Previewer" + 205 " may be different from that on a real device.") 206 return paramMock.paramNumberMock; 207 }, 208 this.readFloatBE = function (...args) { 209 console.warn("Buffer.readFloatBE interface mocked in the Previewer. How this interface works on the Previewer" + 210 " may be different from that on a real device.") 211 return paramMock.paramNumberMock; 212 }, 213 this.readFloatLE = function (...args) { 214 console.warn("Buffer.readFloatLE interface mocked in the Previewer. How this interface works on the Previewer" + 215 " may be different from that on a real device.") 216 return paramMock.paramNumberMock; 217 }, 218 this.readInt8 = function (...args) { 219 console.warn("Buffer.readInt8 interface mocked in the Previewer. How this interface works on the Previewer" + 220 " may be different from that on a real device.") 221 return paramMock.paramNumberMock; 222 }, 223 this.readInt16BE = function (...args) { 224 console.warn("Buffer.readInt16BE interface mocked in the Previewer. How this interface works on the Previewer" + 225 " may be different from that on a real device.") 226 return paramMock.paramNumberMock; 227 }, 228 this.readInt16LE = function (...args) { 229 console.warn("Buffer.readInt16LE interface mocked in the Previewer. How this interface works on the Previewer" + 230 " may be different from that on a real device.") 231 return paramMock.paramNumberMock; 232 }, 233 this.readInt32BE = function (...args) { 234 console.warn("Buffer.readInt32BE interface mocked in the Previewer. How this interface works on the Previewer" + 235 " may be different from that on a real device.") 236 return paramMock.paramNumberMock; 237 }, 238 this.readInt32LE = function (...args) { 239 console.warn("Buffer.readInt32LE interface mocked in the Previewer. How this interface works on the Previewer" + 240 " may be different from that on a real device.") 241 return paramMock.paramNumberMock; 242 }, 243 this.readIntBE = function (...args) { 244 console.warn("Buffer.readIntBE interface mocked in the Previewer. How this interface works on the Previewer" + 245 " may be different from that on a real device.") 246 return paramMock.paramNumberMock; 247 }, 248 this.readIntLE = function (...args) { 249 console.warn("Buffer.readIntLE interface mocked in the Previewer. How this interface works on the Previewer" + 250 " may be different from that on a real device.") 251 return paramMock.paramNumberMock; 252 }, 253 this.readUInt8 = function (...args) { 254 console.warn("Buffer.readUInt8 interface mocked in the Previewer. How this interface works on the Previewer" + 255 " may be different from that on a real device.") 256 return paramMock.paramNumberMock; 257 }, 258 this.readUInt16BE = function (...args) { 259 console.warn("Buffer.readUInt16BE interface mocked in the Previewer. How this interface works on the Previewer" + 260 " may be different from that on a real device.") 261 return paramMock.paramNumberMock; 262 }, 263 this.readUInt16LE = function (...args) { 264 console.warn("Buffer.readUInt16LE interface mocked in the Previewer. How this interface works on the Previewer" + 265 " may be different from that on a real device.") 266 return paramMock.paramNumberMock; 267 }, 268 this.readUInt32BE = function (...args) { 269 console.warn("Buffer.readUInt32BE interface mocked in the Previewer. How this interface works on the Previewer" + 270 " may be different from that on a real device.") 271 return paramMock.paramNumberMock; 272 }, 273 this.readUInt32LE = function (...args) { 274 console.warn("Buffer.readUInt32LE interface mocked in the Previewer. How this interface works on the Previewer" + 275 " may be different from that on a real device.") 276 return paramMock.paramNumberMock; 277 }, 278 this.readUIntBE = function (...args) { 279 console.warn("Buffer.readUIntBE interface mocked in the Previewer. How this interface works on the Previewer" + 280 " may be different from that on a real device.") 281 return paramMock.paramNumberMock; 282 }, 283 this.readUIntLE = function (...args) { 284 console.warn("Buffer.readUIntLE interface mocked in the Previewer. How this interface works on the Previewer" + 285 " may be different from that on a real device.") 286 return paramMock.paramNumberMock; 287 }, 288 this.subarray = function (...args) { 289 console.warn("Buffer.subarray interface mocked in the Previewer. How this interface works on the Previewer" + 290 " may be different from that on a real device.") 291 return new BufferClass(); 292 }, 293 this.swap16 = function (...args) { 294 console.warn("Buffer.swap16 interface mocked in the Previewer. How this interface works on the Previewer" + 295 " may be different from that on a real device.") 296 return new BufferClass(); 297 }, 298 this.swap32 = function (...args) { 299 console.warn("Buffer.swap32 interface mocked in the Previewer. How this interface works on the Previewer" + 300 " may be different from that on a real device.") 301 return new BufferClass(); 302 }, 303 this.swap64 = function (...args) { 304 console.warn("Buffer.swap64 interface mocked in the Previewer. How this interface works on the Previewer" + 305 " may be different from that on a real device.") 306 return new BufferClass(); 307 }, 308 this.toJSON = function (...args) { 309 console.warn("Buffer.toJSON interface mocked in the Previewer. How this interface works on the Previewer" + 310 " may be different from that on a real device.") 311 return paramMock.paramObjectMock; 312 }, 313 this.toString = function (...args) { 314 console.warn("Buffer.toString interface mocked in the Previewer. How this interface works on the Previewer" + 315 " may be different from that on a real device.") 316 return paramMock.paramStringMock; 317 }, 318 this.write = function (...args) { 319 console.warn("Buffer.write interface mocked in the Previewer. How this interface works on the Previewer" + 320 " may be different from that on a real device.") 321 return paramMock.paramNumberMock; 322 }, 323 this.writeBigInt64BE = function (...args) { 324 console.warn("Buffer.writeBigInt64BE interface mocked in the Previewer. How this interface works on the Previewer" + 325 " may be different from that on a real device.") 326 return paramMock.paramNumberMock; 327 }, 328 this.writeBigInt64LE = function (...args) { 329 console.warn("Buffer.writeBigInt64LE interface mocked in the Previewer. How this interface works on the Previewer" + 330 " may be different from that on a real device.") 331 return paramMock.paramNumberMock; 332 }, 333 this.writeBigUInt64BE = function (...args) { 334 console.warn("Buffer.writeBigUInt64BE interface mocked in the Previewer. How this interface works on the Previewer" + 335 " may be different from that on a real device.") 336 return paramMock.paramNumberMock; 337 }, 338 this.writeBigUInt64LE = function (...args) { 339 console.warn("Buffer.writeBigUInt64LE interface mocked in the Previewer. How this interface works on the Previewer" + 340 " may be different from that on a real device.") 341 return paramMock.paramNumberMock; 342 }, 343 this.writeDoubleBE = function (...args) { 344 console.warn("Buffer.writeDoubleBE interface mocked in the Previewer. How this interface works on the Previewer" + 345 " may be different from that on a real device.") 346 return paramMock.paramNumberMock; 347 }, 348 this.writeDoubleLE = function (...args) { 349 console.warn("Buffer.writeDoubleLE interface mocked in the Previewer. How this interface works on the Previewer" + 350 " may be different from that on a real device.") 351 return paramMock.paramNumberMock; 352 }, 353 this.writeFloatBE = function (...args) { 354 console.warn("Buffer.writeFloatBE interface mocked in the Previewer. How this interface works on the Previewer" + 355 " may be different from that on a real device.") 356 return paramMock.paramNumberMock; 357 }, 358 this.writeFloatLE = function (...args) { 359 console.warn("Buffer.writeFloatLE interface mocked in the Previewer. How this interface works on the Previewer" + 360 " may be different from that on a real device.") 361 return paramMock.paramNumberMock; 362 }, 363 this.writeInt8 = function (...args) { 364 console.warn("Buffer.writeInt8 interface mocked in the Previewer. How this interface works on the Previewer" + 365 " may be different from that on a real device.") 366 return paramMock.paramNumberMock; 367 }, 368 this.writeInt16BE = function (...args) { 369 console.warn("Buffer.writeInt16BE interface mocked in the Previewer. How this interface works on the Previewer" + 370 " may be different from that on a real device.") 371 return paramMock.paramNumberMock; 372 }, 373 this.writeInt16LE = function (...args) { 374 console.warn("Buffer.writeInt16LE interface mocked in the Previewer. How this interface works on the Previewer" + 375 " may be different from that on a real device.") 376 return paramMock.paramNumberMock; 377 }, 378 this.writeInt32BE = function (...args) { 379 console.warn("Buffer.writeInt32BE interface mocked in the Previewer. How this interface works on the Previewer" + 380 " may be different from that on a real device.") 381 return paramMock.paramNumberMock; 382 }, 383 this.writeInt32LE = function (...args) { 384 console.warn("Buffer.writeInt32LE interface mocked in the Previewer. How this interface works on the Previewer" + 385 " may be different from that on a real device.") 386 return paramMock.paramNumberMock; 387 }, 388 this.writeIntBE = function (...args) { 389 console.warn("Buffer.writeIntBE interface mocked in the Previewer. How this interface works on the Previewer" + 390 " may be different from that on a real device.") 391 return paramMock.paramNumberMock; 392 }, 393 this.writeIntLE = function (...args) { 394 console.warn("Buffer.writeIntLE interface mocked in the Previewer. How this interface works on the Previewer" + 395 " may be different from that on a real device.") 396 return paramMock.paramNumberMock; 397 }, 398 this.writeUInt8 = function (...args) { 399 console.warn("Buffer.writeUInt8 interface mocked in the Previewer. How this interface works on the Previewer" + 400 " may be different from that on a real device.") 401 return paramMock.paramNumberMock; 402 }, 403 this.writeUInt16BE = function (...args) { 404 console.warn("Buffer.writeUInt16BE interface mocked in the Previewer. How this interface works on the Previewer" + 405 " may be different from that on a real device.") 406 return paramMock.paramNumberMock; 407 }, 408 this.writeUInt16LE = function (...args) { 409 console.warn("Buffer.writeUInt16LE interface mocked in the Previewer. How this interface works on the Previewer" + 410 " may be different from that on a real device.") 411 return paramMock.paramNumberMock; 412 }, 413 this.writeUInt32BE = function (...args) { 414 console.warn("Buffer.writeUInt32BE interface mocked in the Previewer. How this interface works on the Previewer" + 415 " may be different from that on a real device.") 416 return paramMock.paramNumberMock; 417 }, 418 this.writeUInt32LE = function (...args) { 419 console.warn("Buffer.writeUInt32LE interface mocked in the Previewer. How this interface works on the Previewer" + 420 " may be different from that on a real device.") 421 return paramMock.paramNumberMock; 422 }, 423 this.writeUIntBE = function (...args) { 424 console.warn("Buffer.writeUIntBE interface mocked in the Previewer. How this interface works on the Previewer" + 425 " may be different from that on a real device.") 426 return paramMock.paramNumberMock; 427 }, 428 this.writeUIntLE = function (...args) { 429 console.warn("Buffer.writeUIntLE interface mocked in the Previewer. How this interface works on the Previewer" + 430 " may be different from that on a real device.") 431 return paramMock.paramNumberMock; 432 } 433 } 434} 435return buffer; 436} 437