diff --git a/static_core/plugins/ets/tests/ets-common-tests/namespaceImport_Toplevel/MyUtil.ets b/static_core/plugins/ets/tests/ets-common-tests/namespaceImport_Toplevel/MyUtil.ets new file mode 100644 index 0000000000000000000000000000000000000000..c51facbb4ae72d36346dd8717ffc4c9b0f4b3493 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-common-tests/namespaceImport_Toplevel/MyUtil.ets @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 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. + */ + +/*--- + tags: [not-a-test] +---*/ + +namespace MyUtil{ + + export interface PriKey { + privateKey: string + getKey(key: string): string + } + + export interface PubKey { + publicKey: string + getKey(key: string): string + } + + export interface KeyPair { + priKey: PriKey, + pubKey: PubKey + } + +} +export default MyUtil \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-common-tests/namespaceImport_Toplevel/namespace_export.ets b/static_core/plugins/ets/tests/ets-common-tests/namespaceImport_Toplevel/namespace_export.ets new file mode 100644 index 0000000000000000000000000000000000000000..a0cccabd1ce0b0b82e300063781e25df4048e71b --- /dev/null +++ b/static_core/plugins/ets/tests/ets-common-tests/namespaceImport_Toplevel/namespace_export.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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. + */ + +/*--- + files: [MyUtil.ets] + tags: [not-a-test] +---*/ + +import MyUtil from './MyUtil' + +export function DHKeyPair(priKey: MyUtil.PriKey, pubKey: MyUtil.PubKey): boolean { + return priKey.getKey(priKey.privateKey) == pubKey.getKey(pubKey.publicKey) +} \ No newline at end of file diff --git a/static_core/plugins/ets/tests/ets-common-tests/namespaceImport_Toplevel/namespace_import.ets b/static_core/plugins/ets/tests/ets-common-tests/namespaceImport_Toplevel/namespace_import.ets new file mode 100644 index 0000000000000000000000000000000000000000..8457875cd29431b70c173fae45c9a450aca2bf15 --- /dev/null +++ b/static_core/plugins/ets/tests/ets-common-tests/namespaceImport_Toplevel/namespace_import.ets @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2025 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. + */ + +/*--- + files: [MyUtil.ets] + files: [namespace_export.ets] +---*/ + +import MyUtil from './MyUtil'; +import * as compareSpecFunc from './namespace_export'; + +class MyPriKey implements MyUtil.PriKey { + public privateKey: string; + + constructor(privateKey: string) { + this.privateKey = privateKey; + } + + getKey(key: string): string { + if (key === this.privateKey) { + return 'correct'; + } else { + return 'error'; + } + } +} + +class MyPubKey implements MyUtil.PubKey { + public publicKey: string; + + constructor(publicKey: string) { + this.publicKey = publicKey; + } + + getKey(key: string): string { + if (key === this.publicKey) { + return 'correct'; + } else { + return 'error'; + } + } +} + +function main() { + let priKey = new MyPriKey('private') + let pubKey = new MyPubKey('public') + let res: boolean = compareSpecFunc.DHKeyPair(priKey, pubKey) && true; + arktest.assertTrue(res) +} \ No newline at end of file