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 mockVector() { 19 const paramVector = { 20 paramAnyMock: '[PC Preview] unknow any', 21 paramVectorMock: '[PC Preview] unknow Vector', 22 paramIterMock: '[PC Preview] unknow IterableIterator' 23 } 24 25 const VectorClass = class Vector { 26 constructor(...args) { 27 console.warn('util.Vector 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.add = function (...args) { 31 console.warn("Vector.add 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.insert = function (...args) { 36 console.warn("Vector.insert interface mocked in the Previewer. How this interface works on the Previewer" + 37 " may be different from that on a real device.") 38 }; 39 this.has = function (...args) { 40 console.warn("Vector.has interface mocked in the Previewer. How this interface works on the Previewer" + 41 " may be different from that on a real device.") 42 return paramMock.paramBooleanMock; 43 }; 44 this.get = function (...args) { 45 console.warn("Vector.get interface mocked in the Previewer. How this interface works on the Previewer" + 46 " may be different from that on a real device.") 47 return paramVector.paramAnyMock; 48 }; 49 this.getIndexOf = function (...args) { 50 console.warn("Vector.getIndexOf interface mocked in the Previewer. How this interface works on the Previewer" + 51 " may be different from that on a real device.") 52 return paramMock.paramNumberMock; 53 }; 54 this.getFirstElement = function (...args) { 55 console.warn("Vector.getFirstElement interface mocked in the Previewer. How this interface works on the Previewer" + 56 " may be different from that on a real device.") 57 return paramVector.paramAnyMock; 58 }; 59 this.getLastElement = function (...args) { 60 console.warn("Vector.getLastElement interface mocked in the Previewer. How this interface works on the Previewer" + 61 " may be different from that on a real device.") 62 return paramVector.paramAnyMock; 63 }; 64 this.removeByIndex = function (...args) { 65 console.warn("Vector.removeByIndex interface mocked in the Previewer. How this interface works on the Previewer" + 66 " may be different from that on a real device.") 67 return paramVector.paramAnyMock; 68 }; 69 this.remove = function (...args) { 70 console.warn("Vector.remove interface mocked in the Previewer. How this interface works on the Previewer" + 71 " may be different from that on a real device.") 72 return paramMock.paramBooleanMock; 73 }; 74 this.set = function (...args) { 75 console.warn("Vector.set interface mocked in the Previewer. How this interface works on the Previewer" + 76 " may be different from that on a real device.") 77 return paramVector.paramAnyMock; 78 }; 79 this.getLastIndexOf = function (...args) { 80 console.warn("Vector.getLastIndexOf interface mocked in the Previewer. How this interface works on the Previewer" + 81 " may be different from that on a real device.") 82 return paramMock.paramNumberMock; 83 }; 84 this.getLastIndexFrom = function (...args) { 85 console.warn("Vector.getLastIndexFrom interface mocked in the Previewer. How this interface works on the Previewer" + 86 " may be different from that on a real device.") 87 return paramMock.paramNumberMock; 88 }; 89 this.getIndexFrom = function (...args) { 90 console.warn("Vector.getIndexFrom interface mocked in the Previewer. How this interface works on the Previewer" + 91 " may be different from that on a real device.") 92 return paramMock.paramNumberMock; 93 }; 94 this.removeByRange = function (...args) { 95 console.warn("Vector.removeByRange interface mocked in the Previewer. How this interface works on the Previewer" + 96 " may be different from that on a real device.") 97 }; 98 this.replaceAllElements = function (...args) { 99 console.warn("Vector.replaceAllElements interface mocked in the Previewer. How this interface works on the Previewer" + 100 " may be different from that on a real device.") 101 if (typeof args[0] === 'function') { 102 args[0].call(this, paramMock.businessErrorMock, paramVector.paramAnyMock) 103 } 104 }; 105 this.forEach = function (...args) { 106 console.warn("Vector.forEach interface mocked in the Previewer. How this interface works on the Previewer" + 107 " may be different from that on a real device.") 108 if (typeof args[0] === 'function') { 109 args[0].call(this, paramMock.businessErrorMock) 110 } 111 }; 112 this.sort = function (...args) { 113 console.warn("Vector.sort interface mocked in the Previewer. How this interface works on the Previewer" + 114 " may be different from that on a real device.") 115 }; 116 this.subVector = function (...args) { 117 console.warn("Vector.subVector interface mocked in the Previewer. How this interface works on the Previewer" + 118 " may be different from that on a real device.") 119 return paramVector.paramVectorMock; 120 }; 121 this.clear = function (...args) { 122 console.warn("Vector.clear interface mocked in the Previewer. How this interface works on the Previewer" + 123 " may be different from that on a real device.") 124 }; 125 this.clone = function (...args) { 126 console.warn("Vector.clone interface mocked in the Previewer. How this interface works on the Previewer" + 127 " may be different from that on a real device.") 128 return paramVector.paramVectorMock; 129 }; 130 this.setLength = function (...args) { 131 console.warn("Vector.setLength interface mocked in the Previewer. How this interface works on the Previewer" + 132 " may be different from that on a real device.") 133 }; 134 this.getCapacity = function (...args) { 135 console.warn("Vector.getCapacity interface mocked in the Previewer. How this interface works on the Previewer" + 136 " may be different from that on a real device.") 137 return paramMock.paramNumberMock; 138 }; 139 this.convertToArray = function (...args) { 140 console.warn("Vector.convertToArray interface mocked in the Previewer. How this interface works on the Previewer" + 141 " may be different from that on a real device.") 142 return paramMock.paramArrayMock; 143 }; 144 this.isEmpty = function (...args) { 145 console.warn("Vector.isEmpty interface mocked in the Previewer. How this interface works on the Previewer" + 146 " may be different from that on a real device.") 147 return paramMock.paramBooleanMock; 148 }; 149 this.increaseCapacityTo = function (...args) { 150 console.warn("Vector.increaseCapacityTo interface mocked in the Previewer. How this interface works on the Previewer" + 151 " may be different from that on a real device.") 152 }; 153 this.toString = function (...args) { 154 console.warn("Vector.toString interface mocked in the Previewer. How this interface works on the Previewer" + 155 " may be different from that on a real device.") 156 return paramMock.paramStringMock; 157 }; 158 this.trimToCurrentLength = function (...args) { 159 console.warn("Vector.trimToCurrentLength interface mocked in the Previewer. How this interface works on the Previewer" + 160 " may be different from that on a real device.") 161 }; 162 this.copyToArray = function (...args) { 163 console.warn("Vector.copyToArray interface mocked in the Previewer. How this interface works on the Previewer" + 164 " may be different from that on a real device.") 165 }; 166 this[Symbol.iterator] = function (...args) { 167 console.warn("Vector.[Symbol.iterator] interface mocked in the Previewer. How this interface works on the Previewer" + 168 " may be different from that on a real device.") 169 let index = 0; 170 const IteratorMock = { 171 next: () => { 172 if (index < 1) { 173 index++; 174 return { 175 value: paramVector.paramAnyMock, 176 done: false 177 }; 178 } else { 179 return { 180 done: true 181 }; 182 } 183 } 184 }; 185 return IteratorMock; 186 } 187 } 188 } 189 return VectorClass; 190}