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 mockHashMap() { 19 const paramHashMap = { 20 paramAnyMock : '[PC Preview] unknow any', 21 paramHashMap : '[PC Preview] unknow hashmap', 22 paramIterMock_K : '[PC Preview] unknow iterableiterator_k', 23 paramIterMock_V : '[PC Preview] unknow iterableiterator_v' 24 } 25 const HashMapClass = class HashMap { 26 constructor(...args) { 27 console.warn('util.HashMap interface mocked in the Previewer. How this interface works on the Previewer' + 28 ' may be different from that on a real device.'); 29 this.length = '[PC preview] unknow length'; 30 this.isEmpty = function (...args) { 31 console.warn("HashMap.isEmpty interface mocked in the Previewer. How this interface works on the Previewer" + 32 " may be different from that on a real device.") 33 return paramMock.paramBooleanMock; 34 }; 35 this.hasKey = function (...args) { 36 console.warn("HashMap.hasKey interface mocked in the Previewer. How this interface works on the Previewer" + 37 " may be different from that on a real device.") 38 return paramMock.paramBooleanMock; 39 }; 40 this.hasValue = function (...args) { 41 console.warn("HashMap.hasValue interface mocked in the Previewer. How this interface works on the Previewer" + 42 " may be different from that on a real device.") 43 return paramMock.paramBooleanMock; 44 }; 45 this.get = function (...args) { 46 console.warn("HashMap.get interface mocked in the Previewer. How this interface works on the Previewer" + 47 " may be different from that on a real device.") 48 return paramHashMap.paramAnyMock; 49 }; 50 this.setAll = function (...args) { 51 console.warn("HashMap.setAll interface mocked in the Previewer. How this interface works on the Previewer" + 52 " may be different from that on a real device.") 53 }; 54 this.set = function (...args) { 55 console.warn("HashMap.set interface mocked in the Previewer. How this interface works on the Previewer" + 56 " may be different from that on a real device.") 57 return paramMock.paramObjectMock; 58 }; 59 this.remove = function (...args) { 60 console.warn("HashMap.remove interface mocked in the Previewer. How this interface works on the Previewer" + 61 " may be different from that on a real device.") 62 return paramHashMap.paramAnyMock; 63 }; 64 this.clear = function (...args) { 65 console.warn("HashMap.clear interface mocked in the Previewer. How this interface works on the Previewer" + 66 " may be different from that on a real device.") 67 }; 68 this.keys = function (...args) { 69 console.warn('HashMap.keys interface mocked in the Previewer. How this interface works on the Previewer' + 70 ' may be different from that on a real device.'); 71 const IteratorKMock = { 72 *[Symbol.iterator]() { 73 yield paramHashMap.paramIterMock_K; 74 } 75 }; 76 return IteratorKMock; 77 }; 78 this.values = function (...args) { 79 console.warn('HashMap.values interface mocked in the Previewer. How this interface works on the Previewer' + 80 ' may be different from that on a real device.'); 81 const IteratorVMock = { 82 *[Symbol.iterator]() { 83 yield paramHashMap.paramIterMock_V; 84 } 85 }; 86 return IteratorVMock; 87 }; 88 this.replace = function (...args) { 89 console.warn("HashMap.replace 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 this.forEach = function (...args) { 94 console.warn("HashMap.forEach interface mocked in the Previewer. How this interface works on the Previewer" + 95 " may be different from that on a real device.") 96 if (typeof args[0] === 'function') { 97 args[0].call(this, paramMock.businessErrorMock); 98 } 99 }; 100 this.entries = function (...args) { 101 console.warn('HashMap.entries interface mocked in the Previewer. How this interface works on the Previewer' + 102 ' may be different from that on a real device.'); 103 const IteratorEntriesMock = { 104 *[Symbol.iterator]() { 105 yield [paramHashMap.paramIterMock_K, paramHashMap.paramIterMock_V]; 106 } 107 }; 108 return IteratorEntriesMock; 109 }; 110 this[Symbol.iterator] = function (...args) { 111 console.warn("HashMap.[Symbol.iterator] interface mocked in the Previewer. How this interface works on the Previewer" + 112 " may be different from that on a real device.") 113 let index = 0; 114 const IteratorMock = { 115 next: () => { 116 if (index < 1) { 117 const returnValue = [paramHashMap.paramIterMock_K, paramHashMap.paramIterMock_V]; 118 index++; 119 return { 120 value: returnValue, 121 done: false 122 }; 123 } else { 124 return { 125 done: true 126 }; 127 } 128 } 129 }; 130 return IteratorMock; 131 } 132 } 133 } 134 return HashMapClass; 135}