From 27e91734a085d58f07828179be78217536a56091 Mon Sep 17 00:00:00 2001 From: zhuangkudecha Date: Wed, 25 Dec 2024 15:08:03 +0800 Subject: [PATCH] Add Interop Demos Unblock EACoroutine Demos Signed-off-by: zhuangkudecha --- .../shopping/arktsconfig-run-unmemoized.json | 4 + arkoala-arkts/shopping/package.json | 8 +- .../src/ets/arkcompilerPOC/interopTests.ets | 38 + .../GiteeHelper.ts} | 0 .../GiteeHelperData.ts} | 0 .../concurrency.ts} | 11 +- .../concurrency2.ts} | 0 .../ets/arkcompilerPOCFiles/interopTests.ts | 887 ++++++++++++++++++ .../src/ets/pages/homePage/informance.ets | 21 + .../shopping/tsconfig-unmemoize.json | 3 +- 10 files changed, 966 insertions(+), 6 deletions(-) create mode 100644 arkoala-arkts/shopping/src/ets/arkcompilerPOC/interopTests.ets rename arkoala-arkts/shopping/src/ets/{arkcompilerPOC/GiteeHelper.ets => arkcompilerPOCFiles/GiteeHelper.ts} (100%) rename arkoala-arkts/shopping/src/ets/{arkcompilerPOC/GiteeHelperData.ets => arkcompilerPOCFiles/GiteeHelperData.ts} (100%) rename arkoala-arkts/shopping/src/ets/{arkcompilerPOC/concurrency.sts => arkcompilerPOCFiles/concurrency.ts} (95%) rename arkoala-arkts/shopping/src/ets/{arkcompilerPOC/concurrency2.sts => arkcompilerPOCFiles/concurrency2.ts} (100%) create mode 100644 arkoala-arkts/shopping/src/ets/arkcompilerPOCFiles/interopTests.ts diff --git a/arkoala-arkts/shopping/arktsconfig-run-unmemoized.json b/arkoala-arkts/shopping/arktsconfig-run-unmemoized.json index 0ff90ba8a..b8bb89872 100644 --- a/arkoala-arkts/shopping/arktsconfig-run-unmemoized.json +++ b/arkoala-arkts/shopping/arktsconfig-run-unmemoized.json @@ -36,6 +36,10 @@ "#arkcompat": [ "../../arkoala/arkui-common/build/unmemoized/src/arkts" ] + }, + "dynamicPaths":{ + "@ohos.hilog":{"language" : "js", "hasDecl" : false}, + "@bundle:com.arkoala.app/entry/ets/jsFiles/pure" : {"language" : "js", "hasDecl" : false} } } } diff --git a/arkoala-arkts/shopping/package.json b/arkoala-arkts/shopping/package.json index 75c62fbd1..f39558fb1 100644 --- a/arkoala-arkts/shopping/package.json +++ b/arkoala-arkts/shopping/package.json @@ -11,14 +11,16 @@ "unmemoize:arkui-no-common": "npm run unmemoize --prefix ../arkui", "unmemoize:arkui-common": "npm run unmemoize --prefix ../../arkoala/arkui-common", "unmemoize:all": "npm run unmemoize:runtime && npm run unmemoize:arkui-no-common && npm run unmemoize:arkui-common && npm run unmemoize", - "build:shopping": "npm run interface-sdk:download --prefix ../../arkoala/arkui-common && npm run unmemoize:all && npm run build:shopping:prepare-non-subset && npm run build:shopping:inc", - "build:shopping:prepare-non-subset": "rm ./build/unmemoized/build/generated/arkcompilerPOC/concurrency.ts && cp ./src/ets/arkcompilerPOC/concurrency.sts ./build/unmemoized/build/generated/arkcompilerPOC/concurrency.ts && cp ./src/ets/arkcompilerPOC/concurrency2.sts ./build/unmemoized/build/generated/arkcompilerPOC/concurrency2.ts", + "build:shopping": "npm run interface-sdk:download --prefix ../../arkoala/arkui-common && npm run unmemoize:all && npm run build:shopping:inc", "build:shopping:inc": "fast-arktsc --input-files ./arktsconfig-run-unmemoized.json --output-dir ./build --compiler ../../incremental/tools/panda/arkts/arktsc --link-name shopping && ninja -f build/build.ninja", + + "build:shopping:prepare-non-subset": "rm -r ./build/unmemoized/build/generated/arkcompilerPOC/ && cp -r ./src/ets/arkcompilerPOCFiles/ ./build/unmemoized/build/generated/ && mv ./build/unmemoized/build/generated/arkcompilerPOCFiles ./build/unmemoized/build/generated/arkcompilerPOC", + "build:shopping:interop": "npm run unmemoize:all && npm run build:shopping:prepare-non-subset && npm run build:shopping:inc", "pack": "npm run cli-tools:check && cd app && DEVECO_SDK_HOME=../../../arkoala/ohos-sdk/ohos-sdk ../command-line-tools/hvigor/bin/hvigorw --no-daemon --mode module -p product=default -p module=shopping@default assembleHar", "har-arm32": "npm run build:shopping && npm run --prefix ../../arkoala/ohos-sdk download && node scripts/build-har.mjs --name shopping --arch arm32 && npm run pack", "har-arm64": "npm run build:shopping && npm run --prefix ../../arkoala/ohos-sdk download && node scripts/build-har.mjs --name shopping --arch arm64 && npm run pack", - + "har-arm64-interop": "npm run build:shopping:interop && npm run --prefix ../../arkoala/ohos-sdk download && node scripts/build-har.mjs --name shopping --arch arm64 && npm run pack", "cli-tools:chmod:bz": "node ../../arkoala/ohos-sdk/scripts/openlab-cli.mjs chmod -p ./command-line-tools/ohpm/bin -b 755 && node ../../arkoala/ohos-sdk/scripts/openlab-cli.mjs chmod -p ./command-line-tools/hvigor/bin -b 755", "cli-tools:chmod:yz": "node ../../../sdk/scripts/gitlab/gitlab-cli.mjs chmod -p ./command-line-tools/ohpm/bin -b 755 && node ../../../sdk/scripts/gitlab/gitlab-cli.mjs chmod -p ./command-line-tools/hvigor/bin -b 755", "cli-tools:download:bz": "node ../../arkoala/ohos-sdk/scripts/openlab-cli.mjs download -p command-line-tools -v 5.0.3502 -f command-line-tools.5.0.3502.zip -d command-line-tools && npm run cli-tools:chmod:bz", diff --git a/arkoala-arkts/shopping/src/ets/arkcompilerPOC/interopTests.ets b/arkoala-arkts/shopping/src/ets/arkcompilerPOC/interopTests.ets new file mode 100644 index 000000000..5f433568d --- /dev/null +++ b/arkoala-arkts/shopping/src/ets/arkcompilerPOC/interopTests.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export function TestMethodCallReturnType(): void { +} + +export function TestMethodCallArg(): void { +} + +export function TestConversion(): void { +} + +export function TestFuncCallArg(): void { +} + +export function TestFuncCallReturnType(): void { +} + +export function TestImportStatements(): void { +} + +export function TestOperators(): void { +} + +export function TestSimpleException(): void { +} \ No newline at end of file diff --git a/arkoala-arkts/shopping/src/ets/arkcompilerPOC/GiteeHelper.ets b/arkoala-arkts/shopping/src/ets/arkcompilerPOCFiles/GiteeHelper.ts similarity index 100% rename from arkoala-arkts/shopping/src/ets/arkcompilerPOC/GiteeHelper.ets rename to arkoala-arkts/shopping/src/ets/arkcompilerPOCFiles/GiteeHelper.ts diff --git a/arkoala-arkts/shopping/src/ets/arkcompilerPOC/GiteeHelperData.ets b/arkoala-arkts/shopping/src/ets/arkcompilerPOCFiles/GiteeHelperData.ts similarity index 100% rename from arkoala-arkts/shopping/src/ets/arkcompilerPOC/GiteeHelperData.ets rename to arkoala-arkts/shopping/src/ets/arkcompilerPOCFiles/GiteeHelperData.ts diff --git a/arkoala-arkts/shopping/src/ets/arkcompilerPOC/concurrency.sts b/arkoala-arkts/shopping/src/ets/arkcompilerPOCFiles/concurrency.ts similarity index 95% rename from arkoala-arkts/shopping/src/ets/arkcompilerPOC/concurrency.sts rename to arkoala-arkts/shopping/src/ets/arkcompilerPOCFiles/concurrency.ts index 0c98320cf..34808e12b 100644 --- a/arkoala-arkts/shopping/src/ets/arkcompilerPOC/concurrency.sts +++ b/arkoala-arkts/shopping/src/ets/arkcompilerPOCFiles/concurrency.ts @@ -105,11 +105,18 @@ function eaTask() { ea2coro.push(fetch()); NativeModule._NativeLog(LOG_TAG + "EACoroutine fetch data end"); } +let eaw:EAWorker; +let isEAInitialized = false; function EACoroutineFetchData() { NativeModule._NativeLog(LOG_TAG + "request data from EACoroutine"); - // todo need add EACoroutine Demo when code merged to yz. - // ExclusiveLauncher.elaunch(eaTask); + if (!isEAInitialized) { + isEAInitialized = true; + eaw = new EAWorker(true); + } + eaw.run(()=>{ + return eaTask(); + }) NativeModule._NativeLog(LOG_TAG + "Post eaTask done"); let p = ea2coro.pop(); NativeModule._NativeLog(LOG_TAG + "EACoroutine fetch data done: " + p[0].title); diff --git a/arkoala-arkts/shopping/src/ets/arkcompilerPOC/concurrency2.sts b/arkoala-arkts/shopping/src/ets/arkcompilerPOCFiles/concurrency2.ts similarity index 100% rename from arkoala-arkts/shopping/src/ets/arkcompilerPOC/concurrency2.sts rename to arkoala-arkts/shopping/src/ets/arkcompilerPOCFiles/concurrency2.ts diff --git a/arkoala-arkts/shopping/src/ets/arkcompilerPOCFiles/interopTests.ts b/arkoala-arkts/shopping/src/ets/arkcompilerPOCFiles/interopTests.ts new file mode 100644 index 000000000..96598b45c --- /dev/null +++ b/arkoala-arkts/shopping/src/ets/arkcompilerPOCFiles/interopTests.ts @@ -0,0 +1,887 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { info } from "@ohos.hilog"; + +import { + Fruits, + Person, + arr, + numbers, + man, + myMap, + jsonVal, + calculator, + globalVar, + err, + call, + anonymousFunction, + arrowFunction, + Order, + MethodCallTestClass, + jsNull, + jsUndefined, + jsBoolean, + jsNumber, + jsBigint, + jsString, + jsSymbol, + jsInst, + funcReturnTypeNull, + funcReturnTypeUndefined, + funcReturnTypeBoolean, + funcReturnTypeNumber, + funcReturnTypeBigint, + funcReturnTypeString, + funcArgType, + subtract, + multiply, + funcError, + funcUserDefinedError, + MyError +} from "@bundle:com.arkoala.app/entry/ets/jsFiles/pure"; + +function Log(msg: String) { + info(0, "[LOG]", msg); +} + +export function TestOperators(): void { + Log('Panda Test[S2D]: ============ test operators return type begin ============'); + + const newConstructor = new Fruits('apple', 10); + if (newConstructor.kinds as string == "apple" && newConstructor.weight as number == 10) { + Log('Panda Test[S2D]: Passed the test for funcNewConstructor!'); + } else { + Log('Panda Test[S2D]: Failed the test for funcNewConstructor!'); + } + + const newClassInstance = new Person('Alice', 30); + if (newClassInstance.name as string == "Alice" && newClassInstance.age as number == 30) { + Log('Panda Test[S2D]: Passed the test for funcNewClassInstance!'); + } else { + Log('Panda Test[S2D]: Failed the test for funcNewClassInstance!'); + } + + if (arr.length as number == 3) { + Log('Panda Test[S2D]: Passed the test for funcNewBuiltIn!'); + } else { + Log('Panda Test[S2D]: Failed the test for funcNewBuiltIn!'); + } + + if (numbers[0] as number == 10) { + Log('Panda Test[S2D]: Passed the test for funcAccessArrElement!'); + } else { + Log('Panda Test[S2D]: Failed the test for funcAccessArrElement!'); + } + +// if (man["name"] as string == "John") { compile error +// Log('Panda Test[S2D]: Passed the test for funcAccessObjValByKey!'); +// } else { +// Log('Panda Test[S2D]: Failed the test for funcAccessObjValByKey!'); +// } + +// if (myMap[name] as string == "Alice") { compile error +// Log('Panda Test[S2D]: Passed the test for funcAccessMapValByKey!'); +// } else { +// Log('Panda Test[S2D]: Failed the test for funcAccessMapValByKey!'); +// } + + let p = new Person('Doe', 30); + if (p.name as string == "Doe") { + Log('Panda Test[S2D]: Passed the test for funcAccessClassInstanceAttr!'); + } else { + Log('Panda Test[S2D]: Failed the test for funcAccessClassInstanceAttr!'); + } + + if (jsonVal as number == 30) { + Log('Panda Test[S2D]: Passed the test for funcAccessJsonValByKey!'); + } else { + Log('Panda Test[S2D]: Failed the test for funcAccessJsonValByKey!'); + } + + if (calculator.add(1, 2) as number == 3) { + Log('Panda Test[S2D]: Passed the test for funcObjMethod!'); + } else { + Log('Panda Test[S2D]: Failed the test for funcObjMethod!'); + } + + let p1 = new Person('Doe', 30); + if (p1.add(1, 2) as number == 3) { + Log('Panda Test[S2D]: Passed the test for funcClassInstanceMethod!'); + } else { + Log('Panda Test[S2D]: Failed the test for funcClassInstanceMethod!'); + } + + if (Person.staticProp as string == "static prop") { + Log('Panda Test[S2D]: Passed the test for funcClassInstanceStaticProp!'); + } else { + Log('Panda Test[S2D]: Failed the test for funcClassInstanceStaticProp!'); + } + + if (Person.staticMethod() as string == "static method") { + Log('Panda Test[S2D]: Passed the test for funcClassInstanceStaticMethod!'); + } else { + Log('Panda Test[S2D]: Failed the test for funcClassInstanceStaticMethod!'); + } + + if (globalVar as string == "global variable") { + Log('Panda Test[S2D]: Passed the test for funcGlobalObjProp!'); + } else { + Log('Panda Test[S2D]: Failed the test for funcGlobalObjProp!'); + } + + if (err.message as string == "Something went wrong!") { + Log('Panda Test[S2D]: Passed the test for funcErrorProp!'); + } else { + Log('Panda Test[S2D]: Failed the test for funcErrorProp!'); + } + + if (call() as string == "call") { + Log('Panda Test[S2D]: Passed the test for funcCall!'); + } else { + Log('Panda Test[S2D]: Failed the test for funcCall!'); + } + + if (p1.add(3, 3) as number == 6) { + Log('Panda Test[S2D]: Passed the test for funcClassCall!'); + } else { + Log('Panda Test[S2D]: Failed the test for funcClassCall!'); + } + + if (anonymousFunction() as string == "anonymous") { + Log('Panda Test[S2D]: Passed the test for funcAnonymousCall!'); + } else { + Log('Panda Test[S2D]: Failed the test for funcAnonymousCall!'); + } + + if (arrowFunction() as string == "arrow") { + Log('Panda Test[S2D]: Passed the test for funcArrowCall!'); + } else { + Log('Panda Test[S2D]: Failed the test for funcArrowCall!'); + } + + let order = new Order(101,10); + if (order.id as number == 101) { + Log('Panda Test[S2D]: Passed the test for funcConstructorCall!'); + } else { + Log('Panda Test[S2D]: Failed the test for funcConstructorCall!'); + } +} + +const PI: double = 3.14; + +const jsonString: string = '{"name": "John", "age": 30, "city": "New York"}'; + +// export function TestNewConstructor(age: number) :void { +// this.age = age; +// } + +export class TestOperatorClass { + name: string; + arr: number[] = [1, 2, 3]; + // map: Map; + jsonStr: string = jsonString; + static pi: double = PI; + arrow = (): string => { + return "arrow return"; + }; + constructor(name: string) { + this.name = name + // this.map = new Map(); + // this.map["aaa"] = 2; + } + myMethod(): number { + return 10; + } + static getPI(): double { + return PI; + } + // myAnonymous() { + // let a = function(arg) { + // return arg + // } + // return a; + // } +} + +enum Color { + Green = 'green', + Red = 'red' +} +const etsInt = 1; + +export class ConversionsClass { + name: string; + stsNumber: number = 1; + stsByte: byte = 1; + stsShort: short = 0; + stsInt: int = 0; + stsLong: long = 0; + stsFloat: float = 0.0; + stsDouble: double = 0.0; + stsChar: char = 3; + stsBoolean: boolean = true; + stsString: string = "hello"; + stsBigint: bigint = 10n; + // stsEnum: enum = Color.Green; + // stsLiteral: literal = etsInt; + stsUndefined: undefined = undefined; + stsNull: null = null; + constructor(name: string) { + this.name = name; + }; +} + +export function ErrorFunc(): number { + throw new Error('Panda: throw new error in sts!'); + // return 2; +} + +export class CustomError extends Error { + code: number; + constructor(message: string, code: number) { + super(message); + this.name = "CustomError"; + this.code = code; + } +} + +export function CustomErrorFunc(): number { + throw new CustomError("Panda: Something went wrong!", 1001); + // return 3; +} + +export function nullArgFunc(arg: null): null { + return arg; +} +export function undefinedArgFunc(arg: undefined): undefined { + return arg; +} +export function booleanArgFunc(arg: boolean): boolean { + return arg; +} +export function numberArgFunc(arg: number): number { + return arg; +} +export function bigintArgFunc(arg: bigint): bigint { + return arg; +} +export function stringArgFunc(arg: string): string { + return arg; +} +export function classInstArgFunc(arg: number): number { + return arg; +} +export function numberRetValFunc(): number { + return 1; +} +export function byteRetValFunc(): byte { + return 1; +} +export function shortRetValFunc(): short { + return 0; +} +export function intRetValFunc(): int { + return 1; +} +export function longRetValFunc(): long { + return 0; +} +export function floatRetValFunc(): float { + return 0.0; +} +export function doubleRetValFunc(): double { + return 0.0; +} +export function charRetValFunc(): char { + return 3; +} +export function booleanRetValFunc(): boolean { + return false; +} +export function stringRetValFunc(): string { + return "hi"; +} +export function bigintRetValFunc(): bigint { + return 0n; +} +export function nullRetValFunc(): null { + return null; +} +export function undefinedRetValFunc(): undefined { + return undefined; +} + +export class TestMyClass { + name: string; + constructor(name: string) { + this.name = name; + } + nullArgMethod(arg: null): null { + return arg; + } + undefinedArgMethod(arg: undefined): undefined { + return arg; + } + booleanArgMethod(arg: boolean): boolean { + return arg; + } + numberArgMethod(arg: number): number { + return arg; + } + bigintArgMethod(arg: bigint): bigint { + return arg; + } + stringArgMethod(arg: string): string { + return arg; + } + classInstArgMethod(arg: number): number { + return arg; + } + numberRetValMethod(): number { + return 1; + } + byteRetValMethod(): byte { + return 1; + } + shortRetValMethod(): short { + return 0; + } + intRetValMethod(): int { + return 1; + } + longRetValMethod(): long { + return 0; + } + floatRetValMethod(): float { + return 0.0; + } + doubleRetValMethod(): double { + return 0.0; + } + charRetValMethod(): char { + return 3; + } + booleanRetValMethod(): boolean { + return false; + } + stringRetValMethod(): string { + return "hi"; + } + bigintRetValMethod(): bigint { + return 0n; + } + // enumRetValMethod(): enum { + // return Color.Green; + // } + // literalRetValMethod(): literal { + // const etsInt = 1; + // return etsInt; + // } + nullRetValMethod(): null { + return null; + } + undefinedRetValMethod(): undefined { + return undefined; + } +} + +export function TestMethodCallReturnType(): void { + Log('Panda Test[S2D]: ================== test method call return type begin =================='); + let inst = new MethodCallTestClass(); + + if (inst.nullRetValMethod() as null == null) { + Log('Panda Test[S2D]: Passed the test for method call with return type null!'); + } else { + Log('Panda Test[S2D]: Failed the test for method call with return type null!'); + } + + if (inst.undefinedRetValMethod() as undefined == undefined) { + Log('Panda Test[S2D]: Passed the test for method call with return type undefined!'); + } else { + Log('Panda Test[S2D]: Failed the test for method call with return type undefined!'); + } + + if (inst.booleanRetValMethod() as boolean == true) { + Log('Panda Test[S2D]: Passed the test for method call with return type boolean!'); + } else { + Log('Panda Test[S2D]: Failed the test for method call with return type boolean!'); + } + + if (inst.numberRetValMethod() as number == 1) { + Log('Panda Test[S2D]: Passed the test for method call with return type number!'); + } else { + Log('Panda Test[S2D]: Failed the test for method call with return type number!'); + } + + if (inst.bigintRetValMethod() as bigint == 0n) { + Log('Panda Test[S2D]: Passed the test for method call with return type bigint!'); + } else { + Log('Panda Test[S2D]: Failed the test for method call with return type bigint!'); + } + + if (inst.stringRetValMethod() as string == "hi") { + Log('Panda Test[S2D]: Passed the test for method call with return type string!'); + } else { + Log('Panda Test[S2D]: Failed the test for method call with return type string!'); + } + + // if (inst.symbolRetValMethod() as ESObject == "id") { TODO + // Log('Panda Test[S2D]: Passed the test for method call with return type symbol!'); + // } else { + // Log('Panda Test[S2D]: Failed the test for method call with return type symbol!'); + // } + + // compile error -> cannot find type 'ESObject' + // let jsInst: ESObject = inst.classInstRetValMethod() as ESObject; + // if (jsInst.num as number == 123) { + // Log('Panda Test[S2D]: Passed the test for method call with return type class instance!'); + // } else { + // Log('Panda Test[S2D]: Failed the test for method call with return type class instance!'); + // } + + // let obj: ESObject = inst.objRetValMethod() as ESObject; + // if (obj.a as string == '123') { + // Log('Panda Test[S2D]: Passed the test for method call with return type array!'); + // } else { + // Log('Panda Test[S2D]: Failed the test for method call with return type array!'); + // } + + // let arr: ESObject = inst.funcReturnTypeArr() as ESObject; + // if (arr[0] as number == 1) { + // Log('Panda Test[S2D]: Passed the test for method call with return type array!'); + // } else { + // Log('Panda Test[S2D]: Failed the test for method call with return type array!'); + // } +} + +export function TestMethodCallArg(): void { + Log('Panda Test[S2D]: ================== test method call arg type begin =================='); + let inst = new MethodCallTestClass(); + + let arg0: number = 1; + if (inst.argTypeMethod(arg0) as number == 1) { + Log('Panda Test[S2D]: Passed the test for method call with parameter type number!'); + } else { + Log('Panda Test[S2D]: Failed the test for method call with parameter type number!'); + } + + let arg1: byte = 1; + if (inst.argTypeMethod(arg1) as byte == 1) { + Log('Panda Test[S2D]: Passed the test for method call with parameter type byte!'); + } else { + Log('Panda Test[S2D]: Failed the test for method call with parameter type byte!'); + } + + let arg2: short = 0; + if (inst.argTypeMethod(arg2) as short == 0) { + Log('Panda Test[S2D]: Passed the test for method call with parameter type short!'); + } else { + Log('Panda Test[S2D]: Failed the test for method call with parameter type short!'); + } + + let arg3: int = 1; + if (inst.argTypeMethod(arg3) as int == 1) { + Log('Panda Test[S2D]: Passed the test for method call with parameter type int!'); + } else { + Log('Panda Test[S2D]: Failed the test for method call with parameter type int!'); + } + + let arg4: long = 0; + if (inst.argTypeMethod(arg4) as long == 0) { + Log('Panda Test[S2D]: Passed the test for method call with parameter type long!'); + } else { + Log('Panda Test[S2D]: Failed the test for method call with parameter type long!'); + } + + let arg5: float = 0.0; + if (inst.argTypeMethod(arg5) as float == 0.0) { + Log('Panda Test[S2D]: Passed the test for method call with parameter type float!'); + } else { + Log('Panda Test[S2D]: Failed the test for method call with parameter type float!'); + } + + let arg6: double = 0.0; + if (inst.argTypeMethod(arg6) as double == 0.0) { + Log('Panda Test[S2D]: Passed the test for method call with parameter type double!'); + } else { + Log('Panda Test[S2D]: Failed the test for method call with parameter type double!'); + } + + let arg7: char = 3; + if (inst.argTypeMethod(arg7) as char == 3) { + Log('Panda Test[S2D]: Passed the test for method call with parameter type char!'); + } else { + Log('Panda Test[S2D]: Failed the test for method call with parameter type char!'); + } + + let arg8: boolean = true; + if (inst.argTypeMethod(arg8) as boolean == true) { + Log('Panda Test[S2D]: Passed the test for method call with parameter type boolean!'); + } else { + Log('Panda Test[S2D]: Failed the test for method call with parameter type boolean!'); + } + + let arg9: string = "hello"; + if (inst.argTypeMethod(arg9) as string == "hello") { + Log('Panda Test[S2D]: Passed the test for method call with parameter type string!'); + } else { + Log('Panda Test[S2D]: Failed the test for method call with parameter type string!'); + } + + let arg10: bigint = 0n; + if (inst.argTypeMethod(arg10) as bigint == 0n) { + Log('Panda Test[S2D]: Passed the test for method call with parameter type bigint!'); + } else { + Log('Panda Test[S2D]: Failed the test for method call with parameter type bigint!'); + } + + // enum Color { runtime error + // Green = 'green', + // Red = 'red' + // } + // if (inst.argTypeMethod(Color.Green) as string == "green") { + // Log('Panda Test[S2D]: Passed the test for method call with parameter type enum!'); + // } else { + // Log('Panda Test[S2D]: Failed the test for method call with parameter type enum!'); + // } + + // const etsInt = 1; compile error -> cannot find type 'literal' + // let arg12: literal = etsInt; + // if (inst.argTypeMethod(arg12) as literal == etsInt) { + // Log('Panda Test[S2D]: Passed the test for method call with parameter type literal!'); + // } else { + // Log('Panda Test[S2D]: Failed the test for method call with parameter type literal!'); + // } + + let arg13: undefined = undefined; + if (inst.argTypeMethod(arg13) as undefined == undefined) { + Log('Panda Test[S2D]: Passed the test for method call with parameter type undefined!'); + } else { + Log('Panda Test[S2D]: Failed the test for method call with parameter type undefined!'); + } + + let arg14: null = null; + if (inst.argTypeMethod(arg14) as null == null) { + Log('Panda Test[S2D]: Passed the test for method call with parameter type null!'); + } else { + Log('Panda Test[S2D]: Failed the test for method call with parameter type null!'); + } +} + +export function TestConversion(): void { + Log('Panda Test[S2D]: ================== test conversion begin =================='); + + // test-conversions-null compile error + // let stsNull: null = jsNull; + // if (typeof stsNull == 'object') { // null? + // Log('Panda Test[S2D]: Passed the test to convert jsNull to stsNull!'); + // } else { + // Log('Panda Test[S2D]: Failed the test to convert jsNull to stsNull!'); + // } + + // test-conversions-undefined compile error + // let stsUndefined: undefined = jsUndefined; + // if (typeof stsUndefined == 'undefined') { + // Log('Panda Test[S2D]: Passed the test to convert jsUndefined to stsUndefined!'); + // } else { + // Log('Panda Test[S2D]: Failed the test to convert jsUndefined to stsUndefined!'); + // } + + // test-conversions-boolean + let stsBoolean: boolean = jsBoolean; + if (typeof stsBoolean == 'boolean') { + Log('Panda Test[S2D]: Passed the test to convert jsBoolean to stsBoolean!'); + } else { + Log('Panda Test[S2D]: Failed the test to convert jsBoolean to stsBoolean!'); + } + + // test-conversions-number + let stsNumber: number = jsNumber; + if (typeof stsNumber == 'number') { + Log('Panda Test[S2D]: Passed the test to convert jsNumber to stsNumber!'); + } else { + Log('Panda Test[S2D]: Failed the test to convert jsNumber to stsNumber!'); + } + + // test-conversions-bigint + let stsBigint: bigint = jsBigint; + if (typeof stsBigint == 'bigint') { + Log('Panda Test[S2D]: Passed the test to convert jsBigint to stsBigint!'); + } else { + Log('Panda Test[S2D]: Failed the test to convert jsBigint to stsBigint!'); + } + + // test-conversions-string + let stsString: string = jsString; + if (typeof stsString == 'string') { + Log('Panda Test[S2D]: Passed the test to convert jsString to stsString!'); + } else { + Log('Panda Test[S2D]: Failed the test to convert jsString to stsString!'); + } + + // test-conversions-symbol + // let stsSymbol: ESObejct = jsSymbol; TODO + // if (typeof stsSymbol == 'ESObejct') { + // Log('Panda Test[S2D]: Passed the test to convert jsSymbol to stsSymbol!'); + // } else { + // Log('Panda Test[S2D]: Failed the test to convert jsSymbol to stsSymbol!'); + // } + + // test-conversions: a.v + try { + let stsNum = jsInst.num; + Log('Panda Test[S2D]: Get num from js class instance: expected 123 actually ' + stsNum); + } catch(e) { + Log('Panda Test[S2D]: Get num from js class instance throw error'); + } + // test-conversions: a[index] + try { + jsInst[0]; + Log('Panda Test[S2D]: jsInst[0] expected RT error actually no error'); + } catch(e) { + Log('Panda Test[S2D]: jsInst[0] expected RT error actually throw error'); + } + // test-conversions: a() + try { + jsInst(); + Log('Panda Test[S2D]: jsInst() expected RT error actually no error'); + } catch(e) { + Log('Panda Test[S2D]: jsInst() expected RT error actually throw error'); + } + // test-conversions: new a() + try { + new jsInst(); + Log('Panda Test[S2D]: new jsInst() expected no error actually no error'); + } catch(e) { + Log('Panda Test[S2D]: new jsInst() expected no error actually throw error'); + } +} + +export function TestFuncCallReturnType(): void { + Log('Panda Test[S2D]: ================== test function call return type begin =================='); + if (funcReturnTypeNull() as null == null) { + Log('Panda Test[S2D]: Passed the test for function call with return type null!'); + } else { + Log('Panda Test[S2D]: Failed the test for function call with return type null!'); + } + + if (funcReturnTypeUndefined() as undefined == undefined) { + Log('Panda Test[S2D]: Passed the test for function call with return type undefined!'); + } else { + Log('Panda Test[S2D]: Failed the test for function call with return type undefined!'); + } + + if (funcReturnTypeBoolean() as boolean == true) { + Log('Panda Test[S2D]: Passed the test for function call with return type boolean!'); + } else { + Log('Panda Test[S2D]: Failed the test for function call with return type boolean!'); + } + + if (funcReturnTypeNumber() as number == 1) { + Log('Panda Test[S2D]: Passed the test for function call with return type number!'); + } else { + Log('Panda Test[S2D]: Failed the test for function call with return type number!'); + } + + if (funcReturnTypeBigint() as bigint == 0n) { + Log('Panda Test[S2D]: Passed the test for function call with return type bigint!'); + } else { + Log('Panda Test[S2D]: Failed the test for function call with return type bigint!'); + } + + if (funcReturnTypeString() as string == "hello") { + Log('Panda Test[S2D]: Passed the test for function call with return type string!'); + } else { + Log('Panda Test[S2D]: Failed the test for function call with return type string!'); + } + + // if (funcReturnTypeSymbol() as ESObject == "hello") { TODO + // Log('Panda Test[S2D]: Passed the test for function call with return type symbol!'); + // } else { + // Log('Panda Test[S2D]: Failed the test for function call with return type symbol!'); + // } + + // compile error -> cannot find type 'ESObject' + // let inst: ESObject = funcReturnTypeClassInst() as ESObject; + // if (inst.num as number == 123) { + // Log('Panda Test[S2D]: Passed the test for function call with return type class instance!'); + // } else { + // Log('Panda Test[S2D]: Failed the test for function call with return type class instance!'); + // } + + // let arr: ESObject = funcReturnTypeArr() as ESObject; + // if (arr[0] as number == 1) { + // Log('Panda Test[S2D]: Passed the test for function call with return type array!'); + // } else { + // Log('Panda Test[S2D]: Failed the test for function call with return type array!'); + // } +} + +export function TestFuncCallArg(): void { + Log('Panda Test[S2D]: ================== test function call arg type begin =================='); + let arg0: number = 1; + if (funcArgType(arg0) as number == 1) { + Log('Panda Test[S2D]: Passed the test for function call with parameter type number!'); + } else { + Log('Panda Test[S2D]: Failed the test for function call with parameter type number!'); + } + + let arg1: byte = 1; + if (funcArgType(arg1) as byte == 1) { + Log('Panda Test[S2D]: Passed the test for function call with parameter type byte!'); + } else { + Log('Panda Test[S2D]: Failed the test for function call with parameter type byte!'); + } + + let arg2: short = 0; + if (funcArgType(arg2) as short == 0) { + Log('Panda Test[S2D]: Passed the test for function call with parameter type short!'); + } else { + Log('Panda Test[S2D]: Failed the test for function call with parameter type short!'); + } + + let arg3: int = 1; + if (funcArgType(arg3) as int == 1) { + Log('Panda Test[S2D]: Passed the test for function call with parameter type int!'); + } else { + Log('Panda Test[S2D]: Failed the test for function call with parameter type int!'); + } + + let arg4: long = 0; + if (funcArgType(arg4) as long == 0) { + Log('Panda Test[S2D]: Passed the test for function call with parameter type long!'); + } else { + Log('Panda Test[S2D]: Failed the test for function call with parameter type long!'); + } + + let arg5: float = 0.0; + if (funcArgType(arg5) as float == 0.0) { + Log('Panda Test[S2D]: Passed the test for function call with parameter type float!'); + } else { + Log('Panda Test[S2D]: Failed the test for function call with parameter type float!'); + } + + let arg6: double = 0.0; + if (funcArgType(arg6) as double == 0.0) { + Log('Panda Test[S2D]: Passed the test for function call with parameter type double!'); + } else { + Log('Panda Test[S2D]: Failed the test for function call with parameter type double!'); + } + + let arg7: char = 3; + if (funcArgType(arg7) as char == 3) { + Log('Panda Test[S2D]: Passed the test for function call with parameter type char!'); + } else { + Log('Panda Test[S2D]: Failed the test for function call with parameter type char!'); + } + + let arg8: boolean = true; + if (funcArgType(arg8) as boolean == true) { + Log('Panda Test[S2D]: Passed the test for function call with parameter type boolean!'); + } else { + Log('Panda Test[S2D]: Failed the test for function call with parameter type boolean!'); + } + + let arg9: string = "hello"; + if (funcArgType(arg9) as string == "hello") { + Log('Panda Test[S2D]: Passed the test for function call with parameter type string!'); + } else { + Log('Panda Test[S2D]: Failed the test for function call with parameter type string!'); + } + + let arg10: bigint = 0n; + if (funcArgType(arg10) as bigint == 0n) { + Log('Panda Test[S2D]: Passed the test for function call with parameter type bigint!'); + } else { + Log('Panda Test[S2D]: Failed the test for function call with parameter type bigint!'); + } + + // enum Color { runtime error + // Green = 'green', + // Red = 'red' + // } + // if (funcArgType(Color.Green) as string == "green") { + // Log('Panda Test[S2D]: Passed the test for function call with parameter type enum!'); + // } else { + // Log('Panda Test[S2D]: Failed the test for function call with parameter type enum!'); + // } + + // const etsInt = 1; compile error -> cannot find type 'literal' + // let arg12: literal = etsInt; + // if (funcArgType(arg12) as literal == etsInt) { + // Log('Panda Test[S2D]: Passed the test for function call with parameter type literal!'); + // } else { + // Log('Panda Test[S2D]: Failed the test for function call with parameter type literal!'); + // } + + let arg13: undefined = undefined; + if (funcArgType(arg13) as undefined == undefined) { + Log('Panda Test[S2D]: Passed the test for function call with parameter type undefined!'); + } else { + Log('Panda Test[S2D]: Failed the test for function call with parameter type undefined!'); + } + + let arg14: null = null; + if (funcArgType(arg14) as null == null) { + Log('Panda Test[S2D]: Passed the test for function call with parameter type null!'); + } else { + Log('Panda Test[S2D]: Failed the test for function call with parameter type null!'); + } +} + +export function TestImportStatements(): void { + Log('Panda Test[S2D]: ============ test import statements return type begin ============'); + + try { + const result = subtract(9, 1); + if (result as number == 8) { + Log('Panda Test[S2D]: Passed the test for funcImportAll!'); + } else { + Log('Panda Test[S2D]: Failed the test for funcImportAll!'); + } + } catch (error) { + Log(`Panda Test[S2D]: Failed the test for funcImportAll with error`); + } + + try { + const result = multiply(3, 3); + if (result as number == 9) { + Log('Panda Test[S2D]: Passed the test for funcImport!'); + } else { + Log('Panda Test[S2D]: Failed the test for funcImport!'); + } + } catch (error) { + Log(`Panda Test[S2D]: Failed the test for funcImport with error`); + } +} + +export function TestSimpleException(): void { + Log('Panda Test[S2D]: ============ test simple exception return type begin ============'); + + try { + funcError(); + Log('Panda Test[S2D]: Failed the test for funcError! It did not throw an error.'); + } catch (error) { + Log('Panda Test[S2D]: Passed the test for funcError!'); + } + + try { + funcUserDefinedError(); + Log('Panda Test[S2D]: Failed the test for funcUserDefinedError! It did not throw an error.'); + } catch (MyError) { + Log('Panda Test[S2D]: Passed the test for funcUserDefinedError!'); + } +} \ No newline at end of file diff --git a/arkoala-arkts/shopping/src/ets/pages/homePage/informance.ets b/arkoala-arkts/shopping/src/ets/pages/homePage/informance.ets index 422ed7629..ff32a9df1 100644 --- a/arkoala-arkts/shopping/src/ets/pages/homePage/informance.ets +++ b/arkoala-arkts/shopping/src/ets/pages/homePage/informance.ets @@ -18,6 +18,15 @@ import { informationData } from '../../data/homeData' import { callFetchWithEACoroutine, callFetchWithCoroutine, callFetchWithTaskPool} from '../../arkcompilerPOC/concurrency' import { callRDBWithManagedEACoroutine, callRDBWithNativeEACoroutine, GetAll } from '../../arkcompilerPOC/concurrency2' +import { TestOperators, + TestConversion, + TestFuncCallArg, + TestFuncCallReturnType, + TestImportStatements, + TestMethodCallArg, + TestMethodCallReturnType, + TestSimpleException + } from '../../arkcompilerPOC/interopTests' @Component export struct Information { @State color1: string = '#ff0000' @@ -54,6 +63,18 @@ export struct Information { console.log(`inserted prs: ${prs}`) }) }) + }) + Button("RunInteropTest") + .width(200).height(100) + .onClick((e?: ClickEvent) => { + TestOperators(); + TestMethodCallArg(); + TestMethodCallReturnType(); + TestConversion(); + TestFuncCallArg(); + TestFuncCallReturnType(); + TestImportStatements(); + TestSimpleException(); }) } .width('100%').height('100%') diff --git a/arkoala-arkts/shopping/tsconfig-unmemoize.json b/arkoala-arkts/shopping/tsconfig-unmemoize.json index 94b28dd1f..7ae54a23c 100644 --- a/arkoala-arkts/shopping/tsconfig-unmemoize.json +++ b/arkoala-arkts/shopping/tsconfig-unmemoize.json @@ -48,7 +48,8 @@ "../arkui/src/generated/arkts", "../arkui/src/generated/common.ts", "../arkui/src/generated/test_utils.ts", - "../arkui/src/generated/main.ts" + "../arkui/src/generated/main.ts", + "./src/ets/arkcompilerPOCFiles/*" ], "references": [ { "path": "../../arkoala/arkui-common" }, -- Gitee