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