14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd.
34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License.
54514f5e3Sopenharmony_ci * You may obtain a copy of the License at
64514f5e3Sopenharmony_ci *
74514f5e3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
84514f5e3Sopenharmony_ci *
94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and
134514f5e3Sopenharmony_ci * limitations under the License.
144514f5e3Sopenharmony_ci */
154514f5e3Sopenharmony_ciexport function testCommon(proxy, res) {
164514f5e3Sopenharmony_ci    // test keys: true
174514f5e3Sopenharmony_ci    let iteratorKey1 = proxy.keys();
184514f5e3Sopenharmony_ci    res.set("test keys:", iteratorKey1.next().value == "a" && iteratorKey1.next().value == "b" &&
194514f5e3Sopenharmony_ci            iteratorKey1.next().value == "c" && iteratorKey1.next().value == undefined);
204514f5e3Sopenharmony_ci    // test values: true
214514f5e3Sopenharmony_ci    let iteratorValues1 = proxy.values();
224514f5e3Sopenharmony_ci    res.set("test values:", iteratorValues1.next().value == "aa" && iteratorValues1.next().value == "bb" &&
234514f5e3Sopenharmony_ci            iteratorValues1.next().value == "cc" && iteratorValues1.next().value == undefined);
244514f5e3Sopenharmony_ci    // test entries: [c,cc], undefined
254514f5e3Sopenharmony_ci    let iteratorEntries1 = proxy.entries();
264514f5e3Sopenharmony_ci    iteratorEntries1.next().value;
274514f5e3Sopenharmony_ci    iteratorEntries1.next().value;
284514f5e3Sopenharmony_ci    res.set("test entries1:", iteratorEntries1.next().value != undefined);
294514f5e3Sopenharmony_ci    res.set("itest entries2:", iteratorEntries1.next().value == undefined);
304514f5e3Sopenharmony_ci
314514f5e3Sopenharmony_ci    // test forof: [a, aa], [b, bb], [c, cc]
324514f5e3Sopenharmony_ci    let arr1 = ["aa", "bb", "cc"];
334514f5e3Sopenharmony_ci    let j = 0;
344514f5e3Sopenharmony_ci    for (const item of proxy) {
354514f5e3Sopenharmony_ci        res.set(arr1[j], item[1] == arr1[j]);
364514f5e3Sopenharmony_ci        j++;
374514f5e3Sopenharmony_ci    }
384514f5e3Sopenharmony_ci    // test forin:
394514f5e3Sopenharmony_ci    for (const item in proxy) {
404514f5e3Sopenharmony_ci        res.set("test forin", false);
414514f5e3Sopenharmony_ci    }
424514f5e3Sopenharmony_ci}
434514f5e3Sopenharmony_ci
444514f5e3Sopenharmony_ciexport function testdProxySet(proxy, res, dProxy) {
454514f5e3Sopenharmony_ci    // test setAll: 3
464514f5e3Sopenharmony_ci    dProxy.setAll(proxy);
474514f5e3Sopenharmony_ci    res.set("test setAll:", dProxy.length == 3);
484514f5e3Sopenharmony_ci    // test remove: true
494514f5e3Sopenharmony_ci    res.set("test remove:", dProxy.remove("a") == "aa" && dProxy.length == 2);
504514f5e3Sopenharmony_ci    // test replace: true
514514f5e3Sopenharmony_ci    res.set("test replace:", dProxy.replace("b", "dd") && dProxy.get("b") == "dd");
524514f5e3Sopenharmony_ci    // test clear: 0
534514f5e3Sopenharmony_ci    dProxy.clear();
544514f5e3Sopenharmony_ci    res.set("test clear:", dProxy.length == 0);
554514f5e3Sopenharmony_ci}
564514f5e3Sopenharmony_ci
574514f5e3Sopenharmony_ciexport function testdProxyIterator(map, res) {
584514f5e3Sopenharmony_ci    // test keys: true
594514f5e3Sopenharmony_ci    let iteratorKey = map.keys();
604514f5e3Sopenharmony_ci    res.set("test keys:", iteratorKey.next().value == "a" && iteratorKey.next().value == "b" &&
614514f5e3Sopenharmony_ci            iteratorKey.next().value == "c" && iteratorKey.next().value == undefined);
624514f5e3Sopenharmony_ci    // test values: true
634514f5e3Sopenharmony_ci    let iteratorValues = map.values();
644514f5e3Sopenharmony_ci    res.set("test values:", iteratorValues.next().value == "aa" && iteratorValues.next().value == "bb" &&
654514f5e3Sopenharmony_ci            iteratorValues.next().value == "cc" && iteratorValues.next().value == undefined);
664514f5e3Sopenharmony_ci    // test entries: [c,cc], undefined
674514f5e3Sopenharmony_ci    let iteratorEntries = map.entries();
684514f5e3Sopenharmony_ci    iteratorEntries.next().value;
694514f5e3Sopenharmony_ci    iteratorEntries.next().value;
704514f5e3Sopenharmony_ci    res.set("test entries1:", iteratorEntries.next().value != undefined);
714514f5e3Sopenharmony_ci    res.set("itest entries2:", iteratorEntries.next().value == undefined);
724514f5e3Sopenharmony_ci
734514f5e3Sopenharmony_ci    // test forof: [a, aa], [b, bb], [c, cc]
744514f5e3Sopenharmony_ci    let arr = ["aa", "bb", "cc"];
754514f5e3Sopenharmony_ci    let i = 0;
764514f5e3Sopenharmony_ci    for (const item of map) {
774514f5e3Sopenharmony_ci        res.set(arr[i], item[1] == arr[i]);
784514f5e3Sopenharmony_ci        i++;
794514f5e3Sopenharmony_ci    }
804514f5e3Sopenharmony_ci    // test forin:
814514f5e3Sopenharmony_ci    for (const item in map) {
824514f5e3Sopenharmony_ci        res.set("test forin", false);
834514f5e3Sopenharmony_ci    }
844514f5e3Sopenharmony_ci    // test forEach:
854514f5e3Sopenharmony_ci    let flag = false;
864514f5e3Sopenharmony_ci    function TestForEach(value, key, map) {
874514f5e3Sopenharmony_ci        flag = map.get(key) === value;
884514f5e3Sopenharmony_ci        res.set("test forEach" + key, flag);
894514f5e3Sopenharmony_ci    }
904514f5e3Sopenharmony_ci    map.forEach(TestForEach);
914514f5e3Sopenharmony_ci}
924514f5e3Sopenharmony_ci
934514f5e3Sopenharmony_ciexport function testdProxyArray1(proxy, res, testArray) {
944514f5e3Sopenharmony_ci    let itr = proxy[Symbol.iterator]();
954514f5e3Sopenharmony_ci    let tmp = undefined;
964514f5e3Sopenharmony_ci    let testArray1 = [];
974514f5e3Sopenharmony_ci    do {
984514f5e3Sopenharmony_ci        tmp = itr.next().value;
994514f5e3Sopenharmony_ci        testArray1.push(tmp);
1004514f5e3Sopenharmony_ci        } while (tmp != undefined);
1014514f5e3Sopenharmony_ci
1024514f5e3Sopenharmony_ci    for (let k = 0; k < proxy.length; k++) {
1034514f5e3Sopenharmony_ci        if (testArray1[k] !== testArray[k]) {
1044514f5e3Sopenharmony_ci            res = false;
1054514f5e3Sopenharmony_ci        }
1064514f5e3Sopenharmony_ci    }
1074514f5e3Sopenharmony_ci}