diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000000000000000000000000000000000..51c63e295e0232f7095a8ee8e03713837e37f419 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,15 @@ +*.tgz filter=lfs diff=lfs merge=lfs -text +*.trp filter=lfs diff=lfs merge=lfs -text +*.apk filter=lfs diff=lfs merge=lfs -text +*.jar filter=lfs diff=lfs merge=lfs -text +*.mp4 filter=lfs diff=lfs merge=lfs -text +*.zip filter=lfs diff=lfs merge=lfs -text +*.asm filter=lfs diff=lfs merge=lfs -text +*.8svn filter=lfs diff=lfs merge=lfs -text +*.9svn filter=lfs diff=lfs merge=lfs -text +*.dylib filter=lfs diff=lfs merge=lfs -text +*.exe filter=lfs diff=lfs merge=lfs -text +*.a filter=lfs diff=lfs merge=lfs -text +*.so filter=lfs diff=lfs merge=lfs -text +*.bin filter=lfs diff=lfs merge=lfs -text +*.dll filter=lfs diff=lfs merge=lfs -text diff --git a/.gitee/ISSUE_TEMPLATE.zh-CN.md b/.gitee/ISSUE_TEMPLATE.zh-CN.md deleted file mode 100644 index 651e02cef6e623d3385eb4c83d633d73e141cd56..0000000000000000000000000000000000000000 --- a/.gitee/ISSUE_TEMPLATE.zh-CN.md +++ /dev/null @@ -1,11 +0,0 @@ -### 该问题是怎么引起的? - - - -### 重现步骤 - - - -### 报错信息 - - diff --git a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md deleted file mode 100644 index 1bc27ea0be1312649d1f111e10285f25428ac588..0000000000000000000000000000000000000000 --- a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md +++ /dev/null @@ -1,13 +0,0 @@ -### 相关的Issue - - - -### 原因(目的、解决的问题等) - - -### 描述(做了什么,变更了什么) - - -### 测试用例(新增、改动、可能影响的功能) - - diff --git a/BUILD.gn b/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..613cfdfcbbf6176b1bbad8a2ed894309dc2b2ee1 --- /dev/null +++ b/BUILD.gn @@ -0,0 +1,30 @@ +# Copyright (C) 2021 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("//hit/build/suite.gni") +import("test_packages.gni") +ohos_test_suite("acts") { + deps = selected_packages +} + +ohos_test_suite("acts_ivi") { + deps = selected_packages_ivi +} + +ohos_test_suite("acts_intellitv") { + deps = selected_packages_intellitv +} + +ohos_test_suite("acts_wearable") { + deps = selected_packages_wearable +} diff --git a/LICENSE b/LICENSE old mode 100755 new mode 100644 diff --git a/OAT.xml b/OAT.xml new file mode 100755 index 0000000000000000000000000000000000000000..4387f302cb9c119d9e379acad94f513067c2f6f5 --- /dev/null +++ b/OAT.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + diff --git a/README.md b/README.md index fc736368afba5c8b58d98e76ca3836c01d1a6593..24396f880e05a6ed78dfcb41c8a78660ad469317 100755 --- a/README.md +++ b/README.md @@ -1,17 +1,18 @@ -# X Test Suite +# XTS - [Introduction](#section465982318513) -- [Devices](#section125090457443) +- [System Types](#section125090457443) - [Directory Structure](#section161941989596) - [Constraints](#section119744591305) - [Usage Guidelines](#section137768191623) - [Test Case Development Guidelines](#section3695134065513) - - [C-based Test Case Development and Compilation \(for Mini-System Devices\)](#section1551164914237) - - [C-based Test Case Execution \(for Mini-System Devices\)](#section10100701294) - - [C++-based Test Case Development and Compilation \(for Small-, Standard-, and Large-System Devices\)](#section5714177113113) - - [C++-based Test Case Execution \(for Small-, Standard-, and Large-System Devices\)](#section42281924184) + - [C-based Test Case Development and Compilation \(for the Mini System\)](#section198193336544) + - [C-based Test Case Execution \(for the Mini System\)](#section13820233175418) + - [C++-based Test Case Development and Compilation \(for Standard and Small Systems\)](#section3822123311540) + - [C++-based Test Case Execution \(for Standard and Small Systems\)](#section128222336544) + - [JavaScript-based Test Case Development \(for the Standard System\)](#section159801435165220) + - [JavaScript-based Test Case Packaging \(for the Standard System\)](#section445519106559) -- [Repositories Involved](#section1371113476307) ## Introduction @@ -22,26 +23,21 @@ This subsystem contains the ACTS and **tools** software package. - The **acts** directory stores the source code and configuration files of ACTS test cases. The ACTS helps device vendors detect the software incompatibility as early as possible and ensures that the software is compatible to OpenHarmony during the entire development process. - The **tools** software package stores the test case development framework related to **acts**. -## Devices +## System Types -OpenHarmony supports the following device types: +OpenHarmony supports the following system types: -- **Mini-System Devices \(reference memory ≥ 128 KB\)** +- Mini system - Such devices are equipped with MCU processors such as ARM Cortex-M and 32-bit RISC-V. They provide rich short-distance connection and peripheral bus access capabilities. Typical products include LinkIoT module devices and sensors in the smart home field. The LinkIoT module is usually used for smart Internet of Things \(IoT\) devices as the hardware module that implements connectivity functions. In the smart home field, the LinkIoT module is integrated into devices by vendors. For example, a LinkIoT module provides WLAN/Bluetooth access and data connection, and it usually communicates with the chip of smart home devices via a universal asynchronous receiver-transmitter \(UART\) or general-purpose input/output \(GPIO\) interface. + A mini system runs on the devices whose memory is greater than or equal to 128 KiB and that are equipped with MCU processors such as ARM Cortex-M and 32-bit RISC-V. This system provides multiple lightweight network protocols and graphics frameworks, and a wide range of read/write components for the IoT bus. Typical products include connection modules, sensors, and wearables for smart home. -- **Small-System Devices \(reference memory ≥ 1 MB\)** +- Small system - Such devices are equipped with application processors such as ARM Cortex-A. They provide higher security capabilities, standard graphics framework, and multimedia capabilities for video encoding and decoding. Typical products include IP cameras, electronic cat eyes, and routers in the smart home field, as well as event data recorders \(EDRs\) in the smart travel field. + A small system runs on the devices whose memory is greater than or equal to 1 MiB and that are equipped with application processors such as ARM Cortex-A. This system provides higher security capabilities, standard graphics frameworks, and video encoding and decoding capabilities. Typical products include smart home IP cameras, electronic cat eyes, and routers, and event data recorders \(EDRs\) for smart travel. +- Standard system -- **Standard-System Devices \(reference memory ≥ 128 MB\)** - - Such devices are equipped with application processors such as ARM Cortex-A. They provide a complete application framework supporting enhanced interaction, 3D GPU, hardware composer, diverse components, and rich animations. Typical products include high-end refrigerator displays. - -- **Large-System Devices \(reference memory ≥ 1 GB\)** - - Such devices are equipped with application processors such as ARM Cortex-A and provide a complete compatible application framework. Typical products include smart TVs and smart watches. + A standard system runs on the devices whose memory is greater than or equal to 128 MiB and that are equipped with application processors such as ARM Cortex-A. This system provides a complete application framework supporting the enhanced interaction, 3D GPU, hardware composer, diverse components, and rich animations. This system applies to high-end refrigerator displays. ## Directory Structure @@ -49,17 +45,17 @@ OpenHarmony supports the following device types: ``` /test/xts ├── acts # Test code -│ └── subsystem # Source code of subsystem test cases for large-system devices -│ └── subsystem_lite # Source code of subsystems test cases for mini- and small-system devices -│ └── BUILD.gn # Build configuration of test cases for large-system devices -│ └── build_lite # Build configuration of test cases for mini-and small-system devices -│ └── build_lite # Build configuration +│ └── subsystem # Source code of subsystem test cases for the standard system +│ └── subsystem_lite # Source code of subsystems test cases for mini and small systems +│ └── BUILD.gn # Build configuration of test cases for the standard system +│ └── build_lite +│ └── BUILD.gn # Build configuration of test cases for mini and small systems └── tools # Test tool code ``` ## Constraints -Test cases for mini system devices must be developed based on C, and those for small system devices must be developed based on C++. +Test cases for the mini system must be developed based on C, and those for the small system must be developed based on C++. ## Usage Guidelines @@ -216,12 +212,12 @@ Test cases for mini system devices must be developed based on C, and those for s ## Test Case Development Guidelines -You should select the appropriate programming language and your target test framework to develop test cases for the devices to test. +You should select the appropriate programming language and your target test framework to develop test cases. -**Table 4** Test frameworks and test case languages for different devices +**Table 4** Test frameworks and test case languages for different systems -

Device Type

+ @@ -229,40 +225,33 @@ You should select the appropriate programming language and your target test fram - - - - - - - - -

System

Test Framework

Mini-system devices

+

Mini

HCTest

C

Small-system devices

+

Small

HCPPTest

C++

Standard-system devices

-

HJUnit and HCPPTest

-

Java and C++

-

Large-system devices

+

Standard

HJUnit and HCPPTest

+

HJSUnit and HCPPTest

Java and C++

+

JavaScript and C++

-### C-based Test Case Development and Compilation \(for Mini-System Devices\) +### C-based Test Case Development and Compilation \(for the Mini System\) -**Developing test cases for mini-system devices** +**Developing test cases for the mini system** The HCTest framework is used to support test cases developed with the C language. HCTest is enhanced and adapted based on the open-source test framework Unity. @@ -323,7 +312,7 @@ The HCTest framework is used to support test cases developed with the C language 3. Create the configuration file \(**BUILD.gn**\) of the test module. - Create a **BUILD.gn** \(example\) compilation file in each test module directory. Specify the name of the compiled static library and its dependent header file and library in the compilation file. The format is as follows: + Create a **BUILD.gn** \(example\) build file in each test module directory. Specify the name of the built static library and its dependent header file and library in the build file. The format is as follows: ``` import("//test/xts/tools/lite/build/suite_lite.gni") @@ -337,7 +326,7 @@ The HCTest framework is used to support test cases developed with the C language } ``` -4. Add compilation options to the **BUILD.gn** file in the **acts** directory. +4. Add build options to the **BUILD.gn** file in the **acts** directory. You need to add the test module to the **test/xts/acts/build\_lite/BUILD.gn** script in the **acts** directory. @@ -353,17 +342,17 @@ The HCTest framework is used to support test cases developed with the C language } ``` -5. Run compilation commands. +5. Run build commands. - Test suites are compiled along with version compilation. The ACTS is compiled together with the debug version. + Test suites are built along with version build. The ACTS is built together with the debug version. >![](public_sys-resources/icon-note.gif) **NOTE:** - >The ACTS compiles middleware as a static library, which will be linked to the image. + >The ACTS build middleware is a static library, which will be linked to the image. -### C-based Test Case Execution \(for Mini-System Devices\) +### C-based Test Case Execution \(for the Mini System\) -**Executing test cases for mini-system devices** +**Executing test cases for the mini system** Burn the image into the development board. @@ -378,9 +367,9 @@ View the serial port logs, whose format is as follows: The log for each test suite starts with **Start to run test suite:** and ends with **xx Tests xx Failures xx Ignored**. -### C++-based Test Case Development and Compilation \(for Small-, Standard-, and Large-System Devices\) +### C++-based Test Case Development and Compilation \(for Standard and Small Systems\) -**Developing test cases for small-system devices** +**Developing test cases for small-system devices** \(For examples of the standard system, go to the **global/i18n\_standard directory**.\) The HCPPTest framework is enhanced and adapted based on the open-source framework Googletest. @@ -446,7 +435,7 @@ The HCPPTest framework is enhanced and adapted based on the open-source framewor 3. Create a configuration file \(**BUILD.gn**\) of the test module. - Create a **BUILD.gn** compilation file in each test module directory. Specify the name of the compiled static library and its dependent header file and library in the compilation file. Each test module is independently compiled into a **.bin** executable file, which can be directly mounted to the development board for testing. + Create a **BUILD.gn** build file in each test module directory. Specify the name of the built static library and its dependent header file and library in the build file. Each test module is independently built into a **.bin** executable file, which can be directly pushed to the development board for testing. Example: @@ -467,10 +456,9 @@ The HCPPTest framework is enhanced and adapted based on the open-source framewor ] cflags = [ "-Wno-error" ] } - ``` -4. Add compilation options to the **BUILD.gn** file in the **acts** directory. +4. Add build options to the **BUILD.gn** file in the **acts** directory. Add the test module to the **test/xts/acts/build\_lite/BUILD.gn** script in the **acts** directory. @@ -486,17 +474,17 @@ The HCPPTest framework is enhanced and adapted based on the open-source framewor } ``` -5. Run compilation commands. +5. Run build commands. - Test suites are compiled along with the version compilation. The ACTS is compiled together with the debug version. + Test suites are built along with the version build. The ACTS is built together with the debug version. >![](public_sys-resources/icon-note.gif) **NOTE:** - >The ACTS for a small system device is independently compiled to an executable file \(.bin\) and archived in the **suites\\acts** directory of the compilation result. + >The ACTS for the small system is independently built to an executable file \(.bin\) and archived in the **suites\\acts** directory of the build result. -### C++-based Test Case Execution \(for Small-, Standard-, and Large-System Devices\) +### C++-based Test Case Execution \(for Standard and Small Systems\) -**Executing test cases for small-system devices** +**Executing test cases for the small system** Currently, test cases are shared by the NFS and mounted to the development board for execution. @@ -520,11 +508,141 @@ Currently, test cases are shared by the NFS and mounted to the development board Execute **ActsDemoTest.bin** to trigger test case execution, and analyze serial port logs generated after the execution is complete. -## Repositories Involved +### JavaScript-based Test Case Development \(for the Standard System\) + +The HJSUnit framework is used to support automated test of OpenHarmony apps that are developed using the JavaScript language based on the JS application framework. + +**Basic syntax of test cases** + +The test cases are developed with the JavaScript language and must meet the programming specifications of the language. + +**Table 5** + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Syntax

+

Description

+

Mandatory

+

beforeAll

+

Presets a test-suite-level action executed only once before all test cases are executed. You can pass the action function as the only parameter.

+

No

+

afterAll

+

Presets a test-suite-level clear action executed only once after all test cases are executed. You can pass the clear function as the only parameter.

+

No

+

beforeEach

+

Presets a test-case-level action executed before each test case is executed. The number of execution times is the same as the number of test cases defined by it. You can pass the action function as the only parameter.

+

No

+

afterEach

+

Presets a test-case-level clear action executed after each test case is executed. The number of execution times is the same as the number of test cases defined by it. You can pass the clear function as the only parameter.

+

No

+

describe

+

Defines a test suite. You can pass two parameters: test suite name and test suite function. The describe statement supports nesting. You can use beforeall, beforeEach, afterEach, and afterAll in each describe statement.

+

Yes

+

it

+

Defines a test case. You can pass three parameters: test case name, filter parameter, and test case function.

+

Usage of the filter parameter:

+

The value of the filter parameter is a 32-bit integer. Setting different bits to 1 means different configurations:

+
  • bit 0: whether the filter parameter takes effect. 1 means that the test case is used for the function test and other settings of the parameter do not take effect.
  • Bits 0-10: test case categories
  • Bits 16-18: test case scales
  • Bits 24-28: test levels
+

Test case categories: Bits 0-10 indicate FUNCTION (function test), PERFORMANCE (performance test), POWER (power consumption test), RELIABILITY (reliability test), SECURITY (security compliance test), GLOBAL (integrity test), COMPATIBILITY (compatibility test), USER (user test), STANDARD (standard test), SAFETY (security feature test), and RESILIENCE (resilience test), respectively.

+

Test case scales: Bits 16-18 indicate SMALL (small-scale test), MEDIUM (medium-scale test), and LARGE (large-scale test), respectively.

+

Test levels: Bits 24-28 indicate LEVEL0 (level-0 test), LEVEL1 (level-1 test), LEVEL2 (level-2 test), LEVEL3 (level-3 test), and LEVEL4 (level-4 test), respectively.

+

Yes

+
+ +Use the standard syntax of Jasmine to write test cases. The ES6 specification is supported. + +1. Store the test cases in the **entry/src/main/js/test** directory, whose structure is as follows: + + ``` + ├── BUILD.gn + │ └──entry + │ │ └──src + │ │ │ └──main + │ │ │ │ └──js + │ │ │ │ │ └──default + │ │ │ │ │ │ └──pages + │ │ │ │ │ │ │ └──index + │ │ │ │ │ │ │ │ └──index.js # Entry file + │ │ │ │ │ └──test # Test code + │ │ │ └── resources # HAP resources + │ │ │ └── config.json # HAP configuration file + ``` + +2. Start the JS test framework and load test cases. The following is an example for **index.js**. + + ``` + // Start the JS test framework and load test cases. + import {Core, ExpectExtend} from 'deccjsunit/index' + + export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + core.init() + const configService = core.getDefaultService('config') + configService.setConfig(this) + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, + } + ``` + +3. Write a unit test case by referring to the following example: + + ``` + // Use HJSUnit to perform the unit test. + describe('appInfoTest', function () { + it('app_info_test_001', 0, function () { + var info = app.getInfo() + expect(info.versionName).assertEqual('1.0') + expect(info.versionCode).assertEqual('3') + }) + }) + ``` -[X Test Suite](https://gitee.com/openharmony/docs/blob/master/en/readme/x-test-suite.md) -**xts\_acts** +### JavaScript-based Test Case Packaging \(for the Standard System\) -[xts\_tools](https://gitee.com/openharmony/xts_tools/blob/master/README.md) +For details about how to build a HAP, see the JS application development guide of the standard system [Building and Creating HAPs](https://developer.harmonyos.com/en/docs/documentation/doc-guides/build_overview-0000001055075201). diff --git a/README_zh.md b/README_zh.md index 82e5939c3f8b58f0bd7ddb0997a8573209183cc2..22155059b3efcd63ec9d8e05f1b9c49e965622e7 100755 --- a/README_zh.md +++ b/README_zh.md @@ -1,15 +1,17 @@ -# XTS认证子系统 +# XTS子系统 - [简介](#section465982318513) -- [设备类型](#section125090457443) +- [系统类型](#section125090457443) - [目录](#section161941989596) - [约束](#section119744591305) - [使用说明](#section137768191623) - [用例开发指导](#section3695134065513) - - [C语言用例开发编译指导(适用于轻量系统类设备产品用例开发)](#section1551164914237) - - [C语言用例执行指导(适用于轻量系统类设备产品用例开发)](#section10100701294) - - [C++语言用例开发编译指导(适用于小型系统类设备、标准系统类设备、大型系统类设备用例开发)](#section5714177113113) - - [C++语言用例执行指导(适用于小型系统类设备、标准系统类设备、大型系统类设备用例开发)](#section42281924184) + - [C语言用例开发编译指导(适用于轻量系统产品用例开发)](#section198193336544) + - [C语言用例执行指导(适用于轻量系统产品用例开发)](#section13820233175418) + - [C++语言用例开发编译指导(适用于小型系统、标准系统用例开发)](#section3822123311540) + - [C++语言用例执行指导(适用于小型系统、标准系统用例开发)](#section128222336544) + - [JS语言用例开发指导(适用于标准系统)](#section159801435165220) + - [JS语言用例编译打包指导(适用于标准系统)](#section445519106559) - [相关仓](#section1371113476307) @@ -22,26 +24,21 @@ XTS子系统当前包括acts与tools软件包: - acts,存放acts相关测试用例源码与配置文件,其目的是帮助终端设备厂商尽早发现软件与OpenHarmony的不兼容性,确保软件在整个开发过程中满足OpenHarmony的兼容性要求。 - tools,存放acts相关测试用例开发框架。 -## 设备类型 +## 系统类型 -OpenHarmony支持如下几种设备类型: +OpenHarmony支持如下几种系统类型: -- **轻量系统类设备(参考内存≥128KB)** +- 轻量系统(mini system) - 面向MCU类处理器,例如Arm Cortex-M、RISC-V 32位的设备,资源极其有限,参考内存≥128KB,提供丰富的近距连接能力以及丰富的外设总线访问能力。典型产品有智能家居领域的联接类模组、传感器设备等。联接类模组通常应用在智能物联网设备中,负责实现联接部分的硬件模块,在智能家居领域由厂家集成到其设备中。例如:联接类模组提供WLAN/Bluetooth的接入和数据的联接,模组与厂家家居的芯片通常通过UART或GPIO等总线接口进行通信。 + 面向MCU类处理器例如Arm Cortex-M、RISC-V 32位的设备,硬件资源极其有限,支持的设备最小内存为128KiB,可以提供多种轻量级网络协议,轻量级的图形框架,以及丰富的IOT总线读写部件等。可支撑的产品如智能家居领域的连接类模组、传感器设备、穿戴类设备等。 -- **小型系统类设备(参考内存≥1MB)** +- 小型系统(small system) - 面向应用处理器,例如Arm Cortex-A的设备,参考内存≥1MB,提供更高的安全能力,提供标准的图形框架,提供视频编解码的多媒体能力。典型产品有智能家居领域的IPCamera、电子猫眼、路由器以及智慧出行域的行车记录仪等。 + 面向应用处理器例如Arm Cortex-A的设备,支持的设备最小内存为1MiB,可以提供更高的安全能力、标准的图形框架、视频编解码的多媒体能力。可支撑的产品如智能家居领域的IP Camera、电子猫眼、路由器以及智慧出行域的行车记录仪等。 +- 标准系统(standard system) -- **标准系统类设备(参考内存≥128MB)** - - 面向应用处理器,例如Arm Cortex-A的设备,参考内存≥128MB,提供增强的交互能力,提供3D GPU以及硬件合成能力,提供更多控件以及动效更丰富的图形能力,提供完整的应用框架。典型产品有高端的冰箱显示屏等。 - -- **大型系统类设备(参考内存≥1GB)** - - 面向应用处理器,例如Arm Cortex-A的设备,参考内存≥1GB,提供完整的兼容应用框架。典型的产品有智慧屏、智能手表等。 + 面向应用处理器例如Arm Cortex-A的设备,支持的设备最小内存为128MiB,可以提供增强的交互能力、3D GPU以及硬件合成能力、更多控件以及动效更丰富的图形能力、完整的应用框架。可支撑的产品如高端的冰箱显示屏。 ## 目录 @@ -49,17 +46,17 @@ OpenHarmony支持如下几种设备类型: ``` /test/xts ├── acts # 测试代码存放目录 -│ └── subsystem # 大型系统类设备子系统测试用例源码存放目录 -│ └── subsystem_lite # 轻量系统类设备、小型系统类设备子系统测试用例源码存放目录 -│ └── BUILD.gn # 大型系统类设备测试用例编译配置 -│ └── build_lite # 轻量系统类设备、小型系统类设备测试用例编译配置存放目录 -│ └── BUILD.gn # 轻量系统类设备、小型系统类设备测试用例编译配置 +│ └── subsystem # 标准系统子系统测试用例源码存放目录 +│ └── subsystem_lite # 轻量系统、小型系统子系统测试用例源码存放目录 +│ └── BUILD.gn # 标准系统测试用例编译配置 +│ └── build_lite # 轻量系统、小型系统测试用例编译配置存放目录 +│ └── BUILD.gn # 轻量系统、小型系统测试用例编译配置 └── tools # 测试工具代码存放目录 ``` ## 约束 -轻量系统类设备用例开发语言是C,小型系统类设备用例开发语言是C++。 +轻量系统用例开发语言是C,小型系统用例开发语言是C++。 ## 使用说明 @@ -216,12 +213,12 @@ OpenHarmony支持如下几种设备类型: ## 用例开发指导 -根据测试设备选择测试框架和对应测试用例语言。 +根据测试系统选择测试框架和对应测试用例语言。 -**表 4** 设备和测试框架、开发语言对应关系 +**表 4** 系统和测试框架、开发语言对应关系 -

设备

+ @@ -229,40 +226,33 @@ OpenHarmony支持如下几种设备类型: - - - - - - - - -

系统

测试框架

轻量系统类设备

+

轻量系统

hctest

c

小型系统类设备

+

小型系统

hcpptest

c++

标准系统类设备

-

HJUnit、hcpptest

-

java、c++

-

大型系统类设备

+

标准系统

HJUnit、hcpptest

+

HJSUnit、hcpptest

java、c++

+

js、c++

-### C语言用例开发编译指导(适用于轻量系统类设备产品用例开发) +### C语言用例开发编译指导(适用于轻量系统产品用例开发) -**示例:轻量系统类设备测试用例开发** +**示例:轻量系统测试用例开发** 当前使用的测试框架是hctest,hctest测试框架支持使用C语言编写测试用例,是在开源测试框架unity的基础上进行增强和适配。 @@ -361,9 +351,9 @@ OpenHarmony支持如下几种设备类型: >acts测试套件编译中间件为静态库,最终链接到版本镜像中 。 -### C语言用例执行指导(适用于轻量系统类设备产品用例开发) +### C语言用例执行指导(适用于轻量系统产品用例开发) -**示例:轻量系统类设备测试用例执行** +**示例:轻量系统测试用例执行** 将版本镜像烧录进开发板。 @@ -378,9 +368,9 @@ OpenHarmony支持如下几种设备类型: 每个测试套件执行以Start to run test suite开始,以xx Tests xx Failures xx Ignored结束。 -### C++语言用例开发编译指导(适用于小型系统类设备、标准系统类设备、大型系统类设备用例开发) +### C++语言用例开发编译指导(适用于小型系统、标准系统用例开发) -**示例:小型系统类设备测试用例开发** +**示例:小型系统测试用例开发**(标准系统参考具体样例目录:global/i18n\_standard) 当前使用的测试框架是hcpptest,hcpptest测试框架是在开源的googletest测试框架的基础上进行的增强和适配。 @@ -446,7 +436,7 @@ OpenHarmony支持如下几种设备类型: 3. 测试模块下用例配置文件(BUILD.gn)样例: - 每个测试模块目录下新建BUILD.gn编译文件,用于指定编译后可执行文件的名称、依赖的头文件、依赖的库等;具体写法如下。每个测试模块将独立编译成.bin可执行文件, 该文件可直接mount到单板上进行测试。 + 每个测试模块目录下新建BUILD.gn编译文件,用于指定编译后可执行文件的名称、依赖的头文件、依赖的库等;具体写法如下。每个测试模块将独立编译成.bin可执行文件, 该文件可直接push到单板上进行测试。 举例: @@ -491,12 +481,12 @@ OpenHarmony支持如下几种设备类型: 随版本编译,debug版本编译时会同步编译acts测试套件 >![](public_sys-resources/icon-note.gif) **说明:** - >小型系统类设备acts独立编译成可执行文件(bin格式), 在编译产物的suites\\acts目录下归档。 + >小型系统acts独立编译成可执行文件(bin格式), 在编译产物的suites\\acts目录下归档。 -### C++语言用例执行指导(适用于小型系统类设备、标准系统类设备、大型系统类设备用例开发) +### C++语言用例执行指导(适用于小型系统、标准系统用例开发) -**示例:小型系统类设备测试用例执行** +**示例:小型系统测试用例执行** 目前的用例执行采用nfs共享的方式,mount到单板去执行。 @@ -520,10 +510,146 @@ OpenHarmony支持如下几种设备类型: 测试套件执行 ActsDemoTest.bin 触发用例执行,基于串口打印日志进行分析。 +### JS语言用例开发指导(适用于标准系统) + +当前使用的测试框架是HJSUnit,用于支撑OpenHarmony application测试(特指基于JS应用框架使用 Javascript 语言开发的 APP)进行自动化测试。 + +**用例编写基础语法** + +测试用例为 js 语言,必须满足 JavaScript 语言编程规范: + +**表 5** + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

用例语法

+

描述

+

要求

+

beforeAll

+

测试套级别的预置条件,在所有测试用例开始前执行且仅执行一次,支持一个参数:预置动作函数

+

可选

+

afterAll

+

测试套级别的清理条件,在所有测试用例结束后执行且仅执行一次,支持一个参数:清理动作函数

+

可选

+

beforeEach

+

测试用例级别的预置条件,在每条测试用例开始前执行,执行次数与 it 定义的测试用例数一致,支持一个参数:预置动作函数

+

可选

+

afterEach

+

测试用例级别的清理条件,在每条测试用例结束后执行,执行次数与 it 定义的测试用例数一致,支持一个参数:清理动作函数

+

可选

+

describe

+

定义一个测试套,支持两个参数:测试套名称和测试套函数; describe 支持嵌套,每个 describe 内均可以定义 beforeAll 、beforeEach 、afterEach 和 afterAll

+

必选

+

it

+

定义一条测试用例,支持三个参数:用例名称,过滤参数和用例函数

+

备注:

+

过滤参数:过滤参数为一个 32 位的 Int 类型参数,0 位 置1表示不筛选、默认执行;0-10 位 置1表示测试用例类型;16-18 位 置1表示测试用例规模;24-28 位 置1表示测试层级

+

测试用例类型。置位0-10分别表示:FUNCTION 方法类测试、PERFORMANCE 性能类测试、POWER 功耗类测试、RELIABILITY 可靠性测试、SECURITY 安全合规测试、GLOBAL 整体性测试、COMPATIBILITY 兼容性测试、USER 用户测试、STANDARD 标准测试、SAFETY 安全特性测试,RESILIENCE 压力测试。

+

测试用例规模。置位16-18分别表示:SMALL 小型测试、MEDIUM 中型测试、LARGE 大型测试。

+

测试层级。置位24-28分别表示:LEVEL0-0 级测试、LEVEL1-1 级测试、LEVEL2-2 级测试、LEVEL3-3 级测试、LEVEL4-4 级测试。

+

必选

+
+ +用例编写语法采用 jasmine 的标准语法,格式支持ES6格式。 + +1. 规范用例目录:测试用例存储到entry/src/main/js/test目录。 + + ``` + ├── BUILD.gn + │ └──entry + │ │ └──src + │ │ │ └──main + │ │ │ │ └──js + │ │ │ │ │ └──default + │ │ │ │ │ │ └──pages + │ │ │ │ │ │ │ └──index + │ │ │ │ │ │ │ │ └──index.js # 入口文件 + │ │ │ │ │ └──test # 测试代码存放目录 + │ │ │ └── resources # hap资源存放目录 + │ │ │ └── config.json # hap配置文件 + ``` + +2. index.js示例 + + ``` + // 拉起js测试框架,加载测试用例 + import {Core, ExpectExtend} from 'deccjsunit/index' + + export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + core.init() + const configService = core.getDefaultService('config') + configService.setConfig(this) + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, + } + ``` + +3. 单元测试用例示例 + + ``` + // Example1: 使用HJSUnit进行单元测试 + describe('appInfoTest', function () { + it('app_info_test_001', 0, function () { + var info = app.getInfo() + expect(info.versionName).assertEqual('1.0') + expect(info.versionCode).assertEqual('3') + }) + }) + ``` + + +### JS语言用例编译打包指导(适用于标准系统) + +hap包编译请参考[标准系统js应用开发指导](https://developer.harmonyos.com/cn/docs/documentation/doc-guides/build_overview-0000001055075201)。 + ## 相关仓 -[XTS认证子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/XTS%E8%AE%A4%E8%AF%81%E5%AD%90%E7%B3%BB%E7%BB%9F.md) -**xts\_acts** +xts\_acts -[xts\_tools](https://gitee.com/openharmony/xts_tools/blob/master/README_zh.md) +xts\_tools diff --git a/account/BUILD.gn b/account/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..23bee6b47551d95607f8428cf58020cd1ee3aa8f --- /dev/null +++ b/account/BUILD.gn @@ -0,0 +1,25 @@ +# Copyright (C) 2021 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("//build/ohos_var.gni") +group("account") { + testonly = true + if (is_standard_system) { + deps = [ "OsAccountTest_js:osaccount_js_test" ] + } else { + deps = [ + "appaccount:appaccount_hap", + "osaccount:osaccount_hap", + ] + } +} diff --git a/account/OsAccountTest_js/BUILD.gn b/account/OsAccountTest_js/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e045b62eef6ecae760d97a4cde4e49f2205b00f8 --- /dev/null +++ b/account/OsAccountTest_js/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("osaccount_js_test") { + test_hap_name = "OsAccountJSApiTest" + hap_source_path = "hap/entry-debug-rich-signed.hap" +} diff --git a/account/OsAccountTest_js/Test.json b/account/OsAccountTest_js/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..f34a05a88235c780b01a7c110b543f5fb6ec6ab3 --- /dev/null +++ b/account/OsAccountTest_js/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for osaccount js api Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "21600000", + "package": "ohos.acts.account.osaccount", + "shell-timeout": "21600000" + }, + "kits": [ + { + "test-file-name": [ + "OsAccountJSApiTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/account/OsAccountTest_js/hap/entry-debug-rich-signed.hap b/account/OsAccountTest_js/hap/entry-debug-rich-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..5944fc0318c01de810ee28c9b2797994dc9e683b Binary files /dev/null and b/account/OsAccountTest_js/hap/entry-debug-rich-signed.hap differ diff --git a/account/OsAccountTest_js/project/entry/package.json b/account/OsAccountTest_js/project/entry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..69a88e3b65423624fe7ea8b0f8beefcc62cc3d5f --- /dev/null +++ b/account/OsAccountTest_js/project/entry/package.json @@ -0,0 +1 @@ +{} diff --git a/account/OsAccountTest_js/project/entry/src/main/config.json b/account/OsAccountTest_js/project/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..544f61fa18ec370f21f7ba274c6a77f72f4b7968 --- /dev/null +++ b/account/OsAccountTest_js/project/entry/src/main/config.json @@ -0,0 +1,59 @@ +{ + "app": { + "bundleName": "ohos.acts.account.osaccount", + "vendor": "acts", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.account.osaccount", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "ohos.acts.account.osaccount.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} diff --git a/account/OsAccountTest_js/project/entry/src/main/js/default/app.js b/account/OsAccountTest_js/project/entry/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..363f2555b1badec9fec342a93141db084083fcb8 --- /dev/null +++ b/account/OsAccountTest_js/project/entry/src/main/js/default/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 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 default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/account/OsAccountTest_js/project/entry/src/main/js/default/i18n/en-US.json b/account/OsAccountTest_js/project/entry/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/account/OsAccountTest_js/project/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/account/OsAccountTest_js/project/entry/src/main/js/default/i18n/zh-CN.json b/account/OsAccountTest_js/project/entry/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/account/OsAccountTest_js/project/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/account/OsAccountTest_js/project/entry/src/main/js/default/pages/index/index.css b/account/OsAccountTest_js/project/entry/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/account/OsAccountTest_js/project/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/account/OsAccountTest_js/project/entry/src/main/js/default/pages/index/index.hml b/account/OsAccountTest_js/project/entry/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/account/OsAccountTest_js/project/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/account/OsAccountTest_js/project/entry/src/main/js/default/pages/index/index.js b/account/OsAccountTest_js/project/entry/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..6367b2fd449b83b5baa752177423dfceeb494451 --- /dev/null +++ b/account/OsAccountTest_js/project/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2021 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 file from '@system.file' +import app from '@system.app' + +//import {Core, ExpectExtend, ReportExtend, InstrumentLog} from 'deccjsunit/index' +import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + const reportExtend = new ReportExtend(file) + // const instrumentLog = new InstrumentLog({ + // 'id': 'report' + // }) + core.addService('expect', expectExtend) + core.addService('report', reportExtend) + // core.addService('report', instrumentLog) + core.init() + // core.subscribeEvent('spec', instrumentLog) + // core.subscribeEvent('suite', instrumentLog) + // core.subscribeEvent('task', instrumentLog) + + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} diff --git a/account/OsAccountTest_js/project/entry/src/main/js/test/List.test.js b/account/OsAccountTest_js/project/entry/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..facd38d5b5e9961a17599ef0c071af933f7a7d2a --- /dev/null +++ b/account/OsAccountTest_js/project/entry/src/main/js/test/List.test.js @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2021 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. + */ + +require('./OsAccount.test.js') \ No newline at end of file diff --git a/account/OsAccountTest_js/project/entry/src/main/js/test/OsAccount.test.js b/account/OsAccountTest_js/project/entry/src/main/js/test/OsAccount.test.js new file mode 100644 index 0000000000000000000000000000000000000000..f71892a63a3c5ddac150dacf060abc98b2f790b1 --- /dev/null +++ b/account/OsAccountTest_js/project/entry/src/main/js/test/OsAccount.test.js @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2021 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. + */ + +// @ts-nocheck +import {describe, beforeEach, afterEach, it, expect} from 'deccjsunit/index' +import account from '@ohos.account.distributedAccount' + +describe('AccountTest', function () { + beforeEach(function () { + }) + afterEach(function () { + }) + /** + * @tc.number SUB_Account_distributedAccount_JS_API_0100 + * @tc.name Test distributedAccount.getDistributedAccountAbility. + * @tc.desc Test distributedAccount.getDistributedAccountAbility API functionality. + */ + it('account_getDistributedAccountAbility_test', 0, function () { + var ret = false; + const accountAbility = account.getDistributedAccountAbility() + if(accountAbility !== null){ + ret = true; + } + expect(ret).assertTrue() + }) + + /** + * @tc.number SUB_Account_distributedAccount_JS_API_0200 + * @tc.name Test distributedAccount.queryOsAccountDistributedInfo. + * @tc.desc Test distributedAccount.queryOsAccountDistributedInfo API functionality. + */ + it('account_queryOsAccountDistributedInfo_test001', 0, function () { + const accountAbility = account.getDistributedAccountAbility() + accountAbility.queryOsAccountDistributedInfo().then(function (data) { + expect(data.name).assertEqual('anonymous') + }); + }) + + /** + * @tc.number SUB_Account_distributedAccount_JS_API_0300 + * @tc.name Test distributedAccount.queryOsAccountDistributedInfo by callback. + * @tc.desc Test distributedAccount.queryOsAccountDistributedInfo API functionality by callback. + */ + it('account_queryOsAccountDistributedInfo_test002', 0, function () { + const accountAbility = account.getDistributedAccountAbility() + accountAbility.queryOsAccountDistributedInfo(function (data) { + expect(data.name).assertEqual('anonymous') + }); + }) + + /** + * @tc.number SUB_Account_distributedAccount_JS_API_0400 + * @tc.name Test distributedAccount.updateOsAccountDistributedInfo. + * @tc.desc Test distributedAccount.updateOsAccountDistributedInfo API functionality. + */ + it('account_updateOsAccountDistributedInfo_test001', 0, function () { + const accountAbility = account.getDistributedAccountAbility() + let obj = { + id: '12345', + name: 'ZhangSan', + event: 'Ohos.account.event.LOGIN' + }; + accountAbility.updateOsAccountDistributedInfo(obj).then(function (result) { + expect(result).assertTrue() + accountAbility.queryOsAccountDistributedInfo(function (data) { + expect(data.name).assertEqual('ZhangSan') + expect(data.id).assertEqual('12345') + let obj = { + id: '12345', + name: 'ZhangSan', + event: 'Ohos.account.event.LOGOUT' + }; + accountAbility.updateOsAccountDistributedInfo(obj).then(function (result) { + expect(result).assertTrue() + }); + }); + }); + }) + + /** + * @tc.number SUB_Account_distributedAccount_JS_API_0500 + * @tc.name Test distributedAccount.updateOsAccountDistributedInfo by callback. + * @tc.desc Test distributedAccount.updateOsAccountDistributedInfo API functionality by callback. + */ + it('account_updateOsAccountDistributedInfo_test002', 0, function () { + const accountAbility = account.getDistributedAccountAbility() + let obj = { + id: '12345', + name: 'ZhangSan', + event: 'Ohos.account.event.LOGIN' + }; + accountAbility.updateOsAccountDistributedInfo(obj, function (result) { + expect(result).assertTrue() + accountAbility.queryOsAccountDistributedInfo(function (data) { + expect(data.name).assertEqual('ZhangSan') + expect(data.id).assertEqual('12345') + const accountAbility = account.getDistributedAccountAbility() + let obj = { + id: '12345', + name: 'ZhangSan', + event: 'Ohos.account.event.LOGOUT' + }; + accountAbility.updateOsAccountDistributedInfo(obj).then(function (result) { + expect(result).assertTrue() + }); + }); + }); + }) +}) \ No newline at end of file diff --git a/account/OsAccountTest_js/project/entry/src/main/resources/base/element/string.json b/account/OsAccountTest_js/project/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..14f9c3a9210f78b12caf3b945dc2b2c0f63f7d3d --- /dev/null +++ b/account/OsAccountTest_js/project/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "OsAccountTest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/account/OsAccountTest_js/project/entry/src/main/resources/base/media/icon.png b/account/OsAccountTest_js/project/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/account/OsAccountTest_js/project/entry/src/main/resources/base/media/icon.png differ diff --git a/ace/BUILD.gn b/ace/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..5ce5e15cdf5eccda3df63ff73b9863921057fd88 --- /dev/null +++ b/ace/BUILD.gn @@ -0,0 +1,19 @@ +# Copyright (C) 2021 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. + +group("ace") { + testonly = true + deps = [ + "ace_standard:ace_standard_test", + ] +} diff --git a/ace/ace_standard/BUILD.gn b/ace/ace_standard/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..b6c20096db782c8297a5a9690b39ad34679aa323 --- /dev/null +++ b/ace/ace_standard/BUILD.gn @@ -0,0 +1,19 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ace_standard_test") { + test_hap_name = "ace_standard" + hap_source_path = "hap/entry-debug-signed.hap" +} diff --git a/ace/ace_standard/Test.json b/ace/ace_standard/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..36002412df1dd989929662c4dd2d4ea3d7394591 --- /dev/null +++ b/ace/ace_standard/Test.json @@ -0,0 +1,19 @@ +{ + "description": "Configuration for aceceshi Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "21600000", + "package": "com.example.aceceshi", + "abilityName": "decc.testkit.runner.JsEntryAbility", + "shell-timeout": "21600000" + }, + "kits": [ + { + "test-file-name": [ + "ace_standard.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/ace/ace_standard/hap/entry-debug-signed.hap b/ace/ace_standard/hap/entry-debug-signed.hap new file mode 100755 index 0000000000000000000000000000000000000000..a0e1f9e9e10fcc48d333831e1df7cc44710c594d Binary files /dev/null and b/ace/ace_standard/hap/entry-debug-signed.hap differ diff --git a/ace/ace_standard/project/entry/package.json b/ace/ace_standard/project/entry/package.json new file mode 100755 index 0000000000000000000000000000000000000000..69a88e3b65423624fe7ea8b0f8beefcc62cc3d5f --- /dev/null +++ b/ace/ace_standard/project/entry/package.json @@ -0,0 +1 @@ +{} diff --git a/ace/ace_standard/project/entry/src/main/config.json b/ace/ace_standard/project/entry/src/main/config.json new file mode 100755 index 0000000000000000000000000000000000000000..281225c4e81150847bf524615d37a422dc835241 --- /dev/null +++ b/ace/ace_standard/project/entry/src/main/config.json @@ -0,0 +1,52 @@ +{ + "app": { + "bundleName": "com.example.aceceshi", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 5, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.aceceshi", + "name": "testModule", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry_test", + "moduleType": "feature" + }, + "abilities": [ + { + "name": "decc.testkit.runner.JsEntryAbility", + "description": "Test Entry Ability", + "icon": "$media:icon", + "label": "TestAbility", + "launchType": "standard", + "orientation": "landscape", + "visible": true, + "type": "page" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 750, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/ace/ace_standard/project/entry/src/main/js/default/app.js b/ace/ace_standard/project/entry/src/main/js/default/app.js new file mode 100755 index 0000000000000000000000000000000000000000..f6cc8926d94f6e4c3803ae8a7be2f5f08c0f78b5 --- /dev/null +++ b/ace/ace_standard/project/entry/src/main/js/default/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 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 default { + onCreate() { + console.info('TestApplication onCreate'); + }, + onDestroy() { + console.info('TestApplication onDestroy'); + } +}; diff --git a/ace/ace_standard/project/entry/src/main/js/default/i18n/en-US.json b/ace/ace_standard/project/entry/src/main/js/default/i18n/en-US.json new file mode 100755 index 0000000000000000000000000000000000000000..55561b83737c3c31d082fbfa11e5fc987a351104 --- /dev/null +++ b/ace/ace_standard/project/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/ace/ace_standard/project/entry/src/main/js/default/i18n/zh-CN.json b/ace/ace_standard/project/entry/src/main/js/default/i18n/zh-CN.json new file mode 100755 index 0000000000000000000000000000000000000000..cce1af06761a42add0cac1a0567aa3237eda8cb4 --- /dev/null +++ b/ace/ace_standard/project/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/ace/ace_standard/project/entry/src/main/js/default/pages/index/index.css b/ace/ace_standard/project/entry/src/main/js/default/pages/index/index.css new file mode 100755 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/ace/ace_standard/project/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/ace/ace_standard/project/entry/src/main/js/default/pages/index/index.hml b/ace/ace_standard/project/entry/src/main/js/default/pages/index/index.hml new file mode 100755 index 0000000000000000000000000000000000000000..1c26cf73deab18390844a53a103458b10ed11e93 --- /dev/null +++ b/ace/ace_standard/project/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{title}} + +
diff --git a/ace/ace_standard/project/entry/src/main/js/default/pages/index/index.js b/ace/ace_standard/project/entry/src/main/js/default/pages/index/index.js new file mode 100755 index 0000000000000000000000000000000000000000..23f18c37e90df5adaa14ad210611ea10f8d0121f --- /dev/null +++ b/ace/ace_standard/project/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2021 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 file from '@system.file' +import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + const reportExtend = new ReportExtend(file) + core.addService('expect', expectExtend) + core.addService('report', reportExtend) + core.init() + + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} diff --git a/ace/ace_standard/project/entry/src/main/js/test/List.test.js b/ace/ace_standard/project/entry/src/main/js/test/List.test.js new file mode 100755 index 0000000000000000000000000000000000000000..499e4fa91a9194df2b3cc109df8fa0b4ae340e66 --- /dev/null +++ b/ace/ace_standard/project/entry/src/main/js/test/List.test.js @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2021 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. + */ + +require('./basicabilityapi.test.js') diff --git a/ace/ace_standard/project/entry/src/main/js/test/basicabilityapi.test.js b/ace/ace_standard/project/entry/src/main/js/test/basicabilityapi.test.js new file mode 100755 index 0000000000000000000000000000000000000000..61e1acacc8c608b1e91ae9ee165c47c0eee9effa --- /dev/null +++ b/ace/ace_standard/project/entry/src/main/js/test/basicabilityapi.test.js @@ -0,0 +1,305 @@ +/* + * Copyright (C) 2021 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 configuration from '@system.configuration'; +import prompt from '@system.prompt'; +import router from '@system.router'; + +describe('basicabilityapi', function() { + let testResult; + let testResultFail; + let test; + beforeAll(function() { + testResult = true; + testResultFail = false; + test="success" + }); + beforeEach(function() {}); + afterEach(function() {}); + + /** + * @tc.number SUB_ACE_BASICABILITY_JS_API_0100 + * @tc.name testClearInterval + * @tc.desc Cancel the repetitive timing tasks previously set by setInterval. + */ + it('testClearInterval', 0, function() { + console.info('testClearInterval START'); + let intervalID = setInterval(function() { + console.info('TEST do very 1s.'); + }, 1000); + clearInterval(intervalID); + expect(test).assertEqual('success'); + console.info('[clearInterval] success'); + console.info('testClearInterval END'); + }); + + /** + * @tc.number SUB_ACE_BASICABILITY_JS_API_0200 + * @tc.name testConsole + * @tc.desc Print a text message. + */ + it('testConsole', 0, function() { + console.info('testConsole START'); + const versionCode = 1.1; + console.info('[console.info] versionCode: ' + versionCode); + console.debug('[console.debug] versionCode: ' + versionCode); + console.log('[console.log] versionCode: ' + versionCode); + console.warn('[console.warn] versionCode: ' + versionCode); + console.error('[console.error] versionCode: ' + versionCode); + expect(test).assertEqual('success'); + console.info('testConsole END'); + }); + + /** + * @tc.number SUB_ACE_BASICABILITY_JS_API_0300 + * @tc.name testRouterPush + * @tc.desc Go to the specified page of the application. + */ + it('testRouterPush', 0, function() { + router.push({ + uri:'pages/routePush/index', + params: { + myData:'this is params data' + } + }); + setTimeout(() => { + let pages = router.getState(); + console.info("[router.clear] getState"+JSON.stringify(pages)); + }, 500); + expect(test).assertEqual('success'); + }); + + /** + * @tc.number SUB_ACE_BASICABILITY_JS_API_0400 + * @tc.name testRouterReplace + * @tc.desc Replace the current page with a page in the application, and destroy the replaced page. + */ + it('testRouterReplace', 0, function() { + console.info('testRouterReplace START'); + router.replace({ + uri: 'pages/routerReplace/index', + params: { + data1: 'message', + } + }); + expect(test).assertEqual('success'); + console.info("[router.replace] success"); + console.info('testRouterReplace END'); + }); + + /** + * @tc.number SUB_ACE_BASICABILITY_JS_API_0500 + * @tc.name testRouterBack + * @tc.desc Return to the previous page or the specified page. + */ + it('testRouterBack', 0, function() { + console.info('testRouterBack START'); + router.push({ + uri: 'pages/detail/detail' + }); + router.back({ + path: 'pages/mediaquery/mediaquery' + }); + expect(test).assertEqual('success'); + console.info('[router.back] success'); + console.info('testRouterBack END'); + }); + + /** + * @tc.number SUB_ACE_BASICABILITY_JS_API_0600 + * @tc.name testRouterClear + * @tc.desc Clear all historical pages in the page stack, and only keep the current page as the top page. + */ + it('testRouterClear', 0, function() { + console.info('testRouterClear START'); + new Promise(function(resolve, reject) { + router.push({ + uri:'pages/routePush/index', + params:{ + myData:'message' + } + }); + setTimeout(()=>{ + console.info("[router.clear] getLength: " + router.getLength()); + }, 2000); + resolve(); + }).then(function() { + expect(testResult).toBeTrue(); + }, function() { + console.log('[router.clear] fail'); + expect(testResultFail).toBeTrue(); + }); + console.info('testRouterClear END'); + }); + + /** + * @tc.number SUB_ACE_BASICABILITY_JS_API_0700 + * @tc.name testRouterLength + * @tc.desc Get the number of pages currently in the page stack. + */ + it('testRouterLength', 0, function() { + router.push({ + uri: 'pages/dialog/dialog', + params: { + data1: 'message', + data2: { + data3: [123, 456, 789], + data4: { + data5: 'message' + } + } + } + }); + console.info('testRouterLength START'); + let size = router.getLength(); + console.info('[router.getLength] pages stack size = ' + size); + expect(size).assertEqual('1'); + console.info('testRouterLength END'); + }); + + /** + * @tc.number SUB_ACE_BASICABILITY_JS_API_0800 + * @tc.name testRouterGetState + * @tc.desc Get the status information of the current page. + */ + it('testRouterGetState', 0, function() { + console.info('testRouterGetState START'); + let page = router.getState(); + console.info('[router.getState] index: ' + page.index); + console.info('[router.getState] name: ' + page.name); + console.info('[router.getState] path: ' + page.path); + expect(page.index).assertEqual('1'); + expect(page.name).assertEqual('index'); + expect(page.path).assertEqual('pages/index/'); + console.info('testRouterGetState END'); + }); + + /** + * @tc.number SUB_ACE_BASICABILITY_JS_API_0900 + * @tc.name testPromptShowToast + * @tc.desc Show text pop-up window. + */ + it('testPromptShowToast', 0, function() { + console.info('testPromptShowToast START'); + const delay = 5000; + prompt.showToast({ + message:'message', + duration:delay, + }); + expect(test).assertEqual('success'); + console.info('[prompt.showToast] success'); + console.info('testPromptShowToast END'); + }); + + /** + * @tc.number SUB_ACE_BASICABILITY_JS_API_1000 + * @tc.name testPromptDialog + * @tc.desc Display the dialog box in the page. + */ + it('testPromptDialog', 0, function() { + console.info('testPromptDialog START') + prompt.showDialog({ + title: 'dialog showDialog test', + message: 'message of dialog', + buttons: [ + { + text: 'OK', + color: '#0000ff', + index: 0 + } + ], + success: function(ret) { + console.info("[prompt.showDialog] ret.index " + ret.index); + expect(testResult).toBeTrue(); + }, + cancel: function() { + console.log('[prompt.showDialog] dialog cancel callback'); + expect(testResultFail).toBeTrue(); + }, + complete: function() { + console.log('[prompt.showDialog] complete'); + } + }); + console.info('testPromptDialog END'); + }); + + /** + * @tc.number SUB_ACE_BASICABILITY_JS_API_1100 + * @tc.name testConfigurationGetLocale + * @tc.desc Get the current language and region of the app. Synchronize with the language and region. + */ + it('testConfigurationGetLocale', 0, function() { + console.info('testConfigurationGetLocale START'); + const localeInfo = configuration.getLocale(); + console.info("[configuration.getLocale] language: " + localeInfo.language); + console.info("[configuration.getLocale] countryOrRegion: " + localeInfo.countryOrRegion); + console.info("[configuration.getLocale] dir: " + localeInfo.dir); + expect(localeInfo.language).assertEqual('zh'); + expect(localeInfo.countryOrRegion).assertEqual('CN'); + expect(localeInfo.dir).assertEqual('ltr'); + console.info('testConfigurationGetLocale END'); + }); + + /** + * @tc.number SUB_ACE_BASICABILITY_JS_API_1200 + * @tc.name testSetTimeout + * @tc.desc Set up a timer that executes a function or a specified piece of code after the timer expires. + */ + it('testSetTimeout', 0, function() { + console.info('testSetTimeout START'); + let start_time = new Date().getTime(); + const delay = 200; + console.info("[settimeout] start_time: " + start_time); + setTimeout(function(v1,v2) { + let end_time = new Date().getTime(); + console.info('[settimeout] delay: ' + (end_time - start_time) / 1000); + console.info('[settimeout] v1: ' + v1); + console.info('[settimeout] v2: ' + v2); + expect(testResult).toBeTrue(); + }, delay, 'test', 'message'); + console.info('testSetTimeout END'); + }); + + /** + * @tc.number SUB_ACE_BASICABILITY_JS_API_1300 + * @tc.name testClearTimeout + * @tc.desc The timer previously established by calling setTimeout() is cancelled. + */ + it('testClearTimeout', 0, function() { + console.info('testClearTimeout START'); + let timeoutID = setTimeout(function() { + console.info('delay 1s'); + }, 1000); + clearTimeout(timeoutID); + expect(test).assertEqual('success'); + console.info("[clearTimeout] success"); + console.info('testClearTimeout END'); + }); + + /** + * @tc.number SUB_ACE_BASICABILITY_JS_API_1400 + * @tc.name testSetInterval + * @tc.desc Call a function or execute a code segment repeatedly, with a fixed time delay between each call. + */ + it('testSetInterval', 0, function() { + console.info('testSetInterval START'); + let intervalID = setInterval(function() { + console.log('do very 1s.'); + expect(testResult).toBeTrue(); + }, 1000); + console.info("[setInterval] intervalID: " + intervalID); + console.info('testSetInterval END'); + }); +}); \ No newline at end of file diff --git a/ace/ace_standard/project/entry/src/main/resources/base/element/plural.json b/ace/ace_standard/project/entry/src/main/resources/base/element/plural.json new file mode 100755 index 0000000000000000000000000000000000000000..5df662491e2cba0cc4ca28cb1547351bea8a78f3 --- /dev/null +++ b/ace/ace_standard/project/entry/src/main/resources/base/element/plural.json @@ -0,0 +1,33 @@ +{ + "plural":[ + { + "name":"plural_name", + "value":[ + { + "quantity":"zero", + "value":"%d test zero" + }, + { + "quantity":"one", + "value":"%d test one" + }, + { + "quantity":"two", + "value":"%d test two" + }, + { + "quantity":"few", + "value":"%d test few" + }, + { + "quantity":"many", + "value":"%d test many" + }, + { + "quantity":"other", + "value":"%d test other" + } + ] + } + ] +} \ No newline at end of file diff --git a/ace/ace_standard/project/entry/src/main/resources/base/element/strarray.json b/ace/ace_standard/project/entry/src/main/resources/base/element/strarray.json new file mode 100755 index 0000000000000000000000000000000000000000..31980e251c888917c7cbccbcdfcb900f376f4557 --- /dev/null +++ b/ace/ace_standard/project/entry/src/main/resources/base/element/strarray.json @@ -0,0 +1,21 @@ +{ + "strarray": [ + { + "name": "sizeList", + "value":[ + { + "value":"small" + }, + { + "value":"middle" + }, + { + "value":"large" + }, + { + "value":"extra large" + } + ] + } + ] +} \ No newline at end of file diff --git a/ace/ace_standard/project/entry/src/main/resources/base/element/string.json b/ace/ace_standard/project/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..2ccebf86f7d0de51b30e05d4c53ea5f660a7b3eb --- /dev/null +++ b/ace/ace_standard/project/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "aceceshi" + }, + { + "name": "mainability_description", + "value": "hap sample empty page" + } + ] +} diff --git a/ace/ace_standard/project/entry/src/main/resources/base/media/icon.png b/ace/ace_standard/project/entry/src/main/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ace/ace_standard/project/entry/src/main/resources/base/media/icon.png differ diff --git a/appexecfwk/BUILD.gn b/appexecfwk/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..d539267c7edac2fa9014c721f64f5421cf3bb2c3 --- /dev/null +++ b/appexecfwk/BUILD.gn @@ -0,0 +1,22 @@ +# Copyright (C) 2021 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("//build/ohos_var.gni") + +group("appexecfwk") { + testonly = true + if (is_standard_system) { + } else { + deps = [ + ] + } +} diff --git a/build.sh b/build.sh new file mode 100755 index 0000000000000000000000000000000000000000..532ef03f0a21bfa3590457665a66c72ffe0d51bb --- /dev/null +++ b/build.sh @@ -0,0 +1,120 @@ +#!/bin/bash + +# Copyright (C) 2021 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. + +set -e + +usage() +{ + echo + echo "USAGE" + echo " ./build.sh [suite=BUILD_TARGET] [target_os=TARGET_OS] [target_arch=TARGET_ARCH] [variant=BUILD_VARIANT] [target_subsystem=TARGET_SUBSYSTEM]" + echo " target_platform : TARGET_PLATFORM the target platform, such as phone or ivi; Default to phone" + echo " suite : BUILD_TARGET cts/hit/vts and so on, default value is hit" + echo " target_arch : TARGET_ARCH arm64 or arm32, default value is arm64" + echo " variant : BUILD_VARIANT release or debug, default value is debug" + echo " target_subsystem : TARGET_SUBSYSTEM the target subsystem to build" + echo " system_size : SYSTEM_SIZE standard, large and son on, large is for L3-L5, standard is for L2 default value is large" + echo " product_name : PRODUCT_NAME the name of product. such as hikey960, Hi3516DV300, and so on." + echo + exit 1 +} + + +parse_cmdline() +{ + BASE_HOME=$(dirname $(cd $(dirname $0); pwd)) + BASE_HOME=${BASE_HOME}/../.. + BUILD_TOOLS_DIR=${BASE_HOME}/prebuilts/build-tools/linux-x86/bin + OUT_DIR=${BASE_HOME}/out + BUILD_SHELL=${BASE_HOME}/build.sh + # build all parts for all products by default + BUILD_TARGET="" + TARGET_PLATFORM=all + GN_ARGS="is_dbt_test=true include_all=false" + TARGET_ARCH=arm64 + BUILD_VARIANT=release + UPLOAD_API_INFO=False + SYSTEM_SIZE=large + PRODUCT_NAME="" + export PATH=${BASE_HOME}/prebuilts/python/linux-x86/3.8.3/bin:$PATH + + while [ -n "$1" ] + do + var="$1" + OPTIONS=${var%%=*} + PARAM=${var#*=} + echo "OPTIONS=$OPTIONS" + echo "PARAM=$PARAM" + echo "-------------------" + case "$OPTIONS" in + suite) BUILD_TARGET="$PARAM" + ;; + target_arch) TARGET_ARCH="$PARAM" + ;; + variant) BUILD_VARIANT="$PARAM" + ;; + target_platform) TARGET_PLATFORM="$PARAM" + ;; + target_subsystem) export target_subsystem=${PARAM} + ;; + system_size) SYSTEM_SIZE="$PARAM" + ;; + product_name) PRODUCT_NAME="$PARAM" + ;; + upload_api_info) UPLOAD_API_INFO=$(echo $PARAM |tr [a-z] [A-Z]) + ;; + *) usage + break;; + esac + shift + done + if [ "$SYSTEM_SIZE" = "standard" ]; then + BUILD_TARGET=${BUILD_TARGET:-"acts"} + PRODUCT_NAME=${PRODUCT_NAME:-"Hi3516DV300"} + else + BUILD_TARGET=${BUILD_TARGET:-"acts acts_ivi acts_intellitv acts_wearable"} + PRODUCT_NAME=${PRODUCT_NAME:-"arm64"} + fi +} + + +do_make() +{ + cd $BASE_HOME + ACTS_ROOT="$BASE_HOME/test/xts/acts" + + rm -rf "$BASE_HOME/test/xts/autogen_apiobjs" + export XTS_SUITENAME=acts + if [ "$SYSTEM_SIZE" = "standard" ]; then + ./build.sh --product-name $PRODUCT_NAME --gn-args build_xts=true --build-target $BUILD_TARGET --build-target "deploy_testtools" --gn-args is_standard_system=true + else + if [ "$BUILD_TARGET" = "acts acts_ivi acts_intellitv acts_wearable" ]; then + ./build.sh --product-name $PRODUCT_NAME --gn-args build_xts=true --build-target "acts" --build-target "acts_ivi" --build-target "acts_intellitv" --build-target "acts_wearable" --build-target "deploy_testtools" + else + ./build.sh --product-name $PRODUCT_NAME --gn-args build_xts=true --build-target $BUILD_TARGET --build-target "deploy_testtools" + fi + fi + ret=$? + + rm -rf "$BASE_HOME/test/xts/autogen_apiobjs" + if [ "$ret" != 0 ]; then + echo "build error" + exit 1 + fi +} + +parse_cmdline $@ +do_make +exit 0 diff --git a/demo/BUILD.gn b/demo/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4493027cbea35f0a9b759ed927fbdd95b92f181a --- /dev/null +++ b/demo/BUILD.gn @@ -0,0 +1,23 @@ +# Copyright (C) 2021 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("//build/ohos_var.gni") + +group("demo") { + testonly = true + if (is_standard_system) { + deps = [ + "hjsunit_sample:hjs_demo_test", + ] + } +} diff --git a/demo/hjsunit_sample/BUILD.gn b/demo/hjsunit_sample/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..bb33162e7aa049ed07d0868135b095526ff7287a --- /dev/null +++ b/demo/hjsunit_sample/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("hjs_demo_test") { + test_hap_name = "Hjsdemotest" + hap_source_path = "hap/entry-debug-signed.hap" +} diff --git a/demo/hjsunit_sample/Test.json b/demo/hjsunit_sample/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..ca085c99dec389ed19e3ed75b928bc8bc53453b9 --- /dev/null +++ b/demo/hjsunit_sample/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "21600000", + "package": "com.example.myapplication", + "shell-timeout": "21600000" + }, + "kits": [ + { + "test-file-name": [ + "Hjsdemotest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/demo/hjsunit_sample/entry/package.json b/demo/hjsunit_sample/entry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..69a88e3b65423624fe7ea8b0f8beefcc62cc3d5f --- /dev/null +++ b/demo/hjsunit_sample/entry/package.json @@ -0,0 +1 @@ +{} diff --git a/demo/hjsunit_sample/entry/src/main/config.json b/demo/hjsunit_sample/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..69e91f6f3c092c58389896b409b26353ccf442f1 --- /dev/null +++ b/demo/hjsunit_sample/entry/src/main/config.json @@ -0,0 +1,59 @@ +{ + "app": { + "bundleName": "com.example.myapplication", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 4 + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.myapplication", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "com.example.myapplication.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "MyApplication", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} diff --git a/demo/hjsunit_sample/entry/src/main/js/default/app.js b/demo/hjsunit_sample/entry/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..f796f6a0d8dde8b67d055b283776f27d4d06ac0f --- /dev/null +++ b/demo/hjsunit_sample/entry/src/main/js/default/app.js @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2021 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 device from '@system.device'; + +export default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/demo/hjsunit_sample/entry/src/main/js/default/i18n/en-US.json b/demo/hjsunit_sample/entry/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/demo/hjsunit_sample/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/demo/hjsunit_sample/entry/src/main/js/default/i18n/zh-CN.json b/demo/hjsunit_sample/entry/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/demo/hjsunit_sample/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/demo/hjsunit_sample/entry/src/main/js/default/pages/index/index.js b/demo/hjsunit_sample/entry/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..bd751ec7dbbccdac420ee21d0b1b314c836db673 --- /dev/null +++ b/demo/hjsunit_sample/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2021 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 file from '@system.file' +import app from '@system.app' + +//import {Core, ExpectExtend, ReportExtend, InstrumentLog} from 'deccjsunit/index' +import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + const reportExtend = new ReportExtend(file) +// const instrumentLog = new InstrumentLog({ +// 'id': 'report' +// }) + core.addService('expect', expectExtend) + core.addService('report', reportExtend) +// core.addService('report', instrumentLog) + core.init() +// core.subscribeEvent('spec', instrumentLog) +// core.subscribeEvent('suite', instrumentLog) +// core.subscribeEvent('task', instrumentLog) + + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} diff --git a/demo/hjsunit_sample/entry/src/main/js/test/ExampleJsunit.test.js b/demo/hjsunit_sample/entry/src/main/js/test/ExampleJsunit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..4fdf2a890581dfe125e8e196149f44118ae94134 --- /dev/null +++ b/demo/hjsunit_sample/entry/src/main/js/test/ExampleJsunit.test.js @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2021 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 app from '@system.app' +import Context from '@ohos.napi_context' + +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('appInfoTest', function () { + console.log("*************00000000000000000000000*************"); + it('app_info_test_001', 0, function () { + var info = app.getInfo() + expect(info.versionName).assertEqual('1.0') + expect(info.versionCode).assertEqual('3') + }) + it('app_info_test_002', 0, function () { + var info = app.getInfo() + expect(info.versionName).assertEqual('1.0') + expect(info.versionCode).assertEqual('2') + expect(info).assertNull() + }) + it('app_info_test_003', 0, function () { + var info = app.getInfo() + expect(info.versionName).assertEqual('1.0') + expect(info.versionCode).assertEqual('4') + }) + it('app_info_test_004', 0, function () { + var info = app.getInfo() + expect(info.versionName).assertEqual('1.0') + expect(info.versionCode).assertEqual('5') + }) + it('get_process_info_test_001', 0, async function (done) { + console.log("111") + expect(1).assertLarger(0) + Context.getProcessInfo().then(info => { + console.log("222"); + console.log("process_info: " + JSON.stringify(info)); + expect(info.processName.length).assertLarger(0); + expect(info.pid).assertLarger(0); + }); + done() + }) +}) diff --git a/demo/hjsunit_sample/entry/src/main/js/test/List.test.js b/demo/hjsunit_sample/entry/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..62e348cb74788587609d9100918745cc71635dc2 --- /dev/null +++ b/demo/hjsunit_sample/entry/src/main/js/test/List.test.js @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2021 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. + */ +require('./ExampleJsunit.test.js') diff --git a/demo/hjsunit_sample/hap/entry-debug-signed.hap b/demo/hjsunit_sample/hap/entry-debug-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..76b7653122e4d2e26c18bffa99b0a360c8aeda4d Binary files /dev/null and b/demo/hjsunit_sample/hap/entry-debug-signed.hap differ diff --git a/developtools/BUILD.gn b/developtools/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..f36cf6c3e3b0a5c37c94a7fe5f978e7f91661bd3 --- /dev/null +++ b/developtools/BUILD.gn @@ -0,0 +1,21 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +import("//build/ohos_var.gni") +group("developtoolstestacts") { + testonly = true + if (is_standard_system) { + deps = [ "hiplugintest:hipluginmoduleapitest" ] + } +} diff --git a/developtools/hiplugintest/BUILD.gn b/developtools/hiplugintest/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..dad1adf39035b2f8c43cad26ed584cd356569f70 --- /dev/null +++ b/developtools/hiplugintest/BUILD.gn @@ -0,0 +1,52 @@ +# Copyright (c) 2021 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("//build/test.gni") +import("//test/xts/tools/build/suite.gni") +import("../../../../../developtools/profiler/device/base/config.gni") + +############################################################################### +config("module_private_config") { + visibility = [":*"] +} + +ohos_moduletest_suite("hipluginmoduleapitest") { + deps = [ + "//third_party/googletest:gtest", + "${OHOS_PROFILER_DIR}/protos/types/plugins/memory_data:memory_data_cpp", + "${OHOS_PROFILER_DIR}/device/plugins/memory_plugin:memdataplugin", + ] + include_dirs = [ + "${OHOS_PROFILER_DIR}/interfaces/kits/", + "${OHOS_PROFILER_DIR}/device/plugins/memory_plugin/include", + "${OHOS_PROFILER_DIR}/device/plugins/api/include", + "${OHOS_PROFILER_DIR}/device/plugins/api/src", + "${OHOS_PROFILER_DIR}/device/base/include/", + "//third_party/googletest/googletest/include/gtest", + ] + sources = [ + "${OHOS_PROFILER_DIR}/device/plugins/memory_plugin/test/unittest/buffer_splitter_unittest.cpp", + "${OHOS_PROFILER_DIR}/device/plugins/memory_plugin/test/unittest/memory_data_plugin_unittest.cpp", + "hipluginmoduleapitest.cpp", + ] + cflags = [ + "-pthread", + "-Wno-inconsistent-missing-override", + "-Dprivate=public", #allow test code access private members + ] + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + ] + subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" + defines = [ "HAVE_HILOG", ] +} diff --git a/developtools/hiplugintest/Test.json b/developtools/hiplugintest/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..50103b74ca31244829daa0f8435dbfad3a5a05ca --- /dev/null +++ b/developtools/hiplugintest/Test.json @@ -0,0 +1,21 @@ +{ + "kits": [ + { + "push": [ + "hipluginmoduleapitest->/data/local/tmp/hipluginmoduleapitest" + ], + "type": "PushKit", + "post-push": [ + "chmod -R 777 /data/local/tmp/*" + ] + } + ], + "driver": { + "native-test-timeout": "120000", + "type": "CppTest", + "module-name": "hipluginmoduleapitest", + "runtime-hint": "1s", + "native-test-device-path": "/data/local/tmp" + }, + "description": "Configuration for hipluginmoduleapitest Tests" +} diff --git a/developtools/hiplugintest/hipluginmoduleapitest.cpp b/developtools/hiplugintest/hipluginmoduleapitest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..456c6f4c665c591c547db433a565d16397a216a4 --- /dev/null +++ b/developtools/hiplugintest/hipluginmoduleapitest.cpp @@ -0,0 +1,231 @@ +/* + * Copyright (c) 2021 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. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "logging.h" +#include "memory_plugin_config.pb.h" +#include "memory_plugin_result.pb.h" +#include "plugin_module_api.h" + +using namespace testing::ext; + +#if defined(__i386__) || defined(__x86_64__) +const std::string LIB_PATH = const_cast("./hos/out/hos-arm/clang_x64/devtools/devtools/libmemdataplugin.z.so"); +#else +const std::string LIB_PATH = const_cast("/system/lib/libmemdataplugin.z.so"); +#endif + +namespace { +enum NumType { + BIT_WIDTH = 35, + MS_S = 1000000, +}; + +class PluginModuleApiTest : public ::testing::Test { +protected: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + + void SetUp() override {} + void TearDown() override {} + + bool MatchTail(const std::string& name, const char* str) + { + int index = name.size() - strlen(str); + if (index < 0) { + return false; + } + return strncmp(name.c_str() + index, str, strlen(str)) == 0; + } + + bool MemoryPluginTest(MemoryConfig& protoConfig, const std::string libPath) + { + MemoryData memoryData; + PluginModuleStruct* memplugin; + void* handle; + int cnt = 1; + uint8_t* dataBuffer; + clock_t clockstart, clockend; + struct timeval start, end; + int timeuse; + + if (!MatchTail(libPath, ".so")) { + printf("libPath=%s\r\n", libPath.c_str()); + return false; + } + + handle = dlopen(libPath.c_str(), RTLD_LAZY); + if (handle == nullptr) { + HILOG_DEBUG(LOG_CORE, "test:dlopen err:%s.", dlerror()); + return false; + } + + memplugin = (PluginModuleStruct*)dlsym(handle, "g_pluginModule"); + dataBuffer = (uint8_t*)malloc(memplugin->resultBufferSizeHint); + + int configlength = protoConfig.ByteSizeLong(); + std::vector config(configlength); + protoConfig.SerializeToArray(config.data(), config.size()); + + if (memplugin->callbacks->onPluginSessionStart(config.data(), config.size()) < 0) { + HILOG_DEBUG(LOG_CORE, "start failed"); + dlclose(handle); + free(dataBuffer); + return false; + } + + clockstart = clock(); + gettimeofday(&start, nullptr); + + while (cnt--) { + int len = memplugin->callbacks->onPluginReportResult(dataBuffer, memplugin->resultBufferSizeHint); + if (len > 0) { + memoryData.ParseFromArray(dataBuffer, len); + } + } + + gettimeofday(&end, nullptr); + clockend = clock(); + timeuse = MS_S * (end.tv_sec - start.tv_sec) + end.tv_usec - start.tv_usec; + HILOG_DEBUG(LOG_CORE, "clock time=%.3fs, timeofday=%.3fs", (double)(clockend - clockstart) / CLOCKS_PER_SEC, + (double)timeuse / MS_S); + + memplugin->callbacks->onPluginSessionStop(); + + memplugin->callbacks->onRegisterWriterStruct(nullptr); + + dlclose(handle); + free(dataBuffer); + return true; + } +}; + +HWTEST_F(PluginModuleApiTest, ProtoConfigNullAndInvalidSo, TestSize.Level1) +{ + MemoryConfig protoConfig; + EXPECT_FALSE(PluginModuleApiTest::MemoryPluginTest(protoConfig, "1111")); +} + +HWTEST_F(PluginModuleApiTest, ProtoConfigNullAndEffectiveSo, TestSize.Level1) +{ + MemoryConfig protoConfig; + EXPECT_TRUE(PluginModuleApiTest::MemoryPluginTest(protoConfig, LIB_PATH)); +} + +HWTEST_F(PluginModuleApiTest, ProtoConfigMemAndInvalidSo, TestSize.Level1) +{ + MemoryConfig protoConfig; + protoConfig.set_report_process_mem_info(true); + EXPECT_FALSE(PluginModuleApiTest::MemoryPluginTest(protoConfig, "1111")); +} + +HWTEST_F(PluginModuleApiTest, ProtoConfigMemAndEffectiveSo, TestSize.Level1) +{ + MemoryConfig protoConfig; + protoConfig.set_report_process_mem_info(true); + EXPECT_TRUE(PluginModuleApiTest::MemoryPluginTest(protoConfig, LIB_PATH)); +} + +HWTEST_F(PluginModuleApiTest, ProtoConfigPidAndInvalidSo, TestSize.Level1) +{ + MemoryConfig protoConfig; + protoConfig.set_report_app_mem_info(true); + protoConfig.add_pid(1); + EXPECT_FALSE(PluginModuleApiTest::MemoryPluginTest(protoConfig, "1111")); +} + +HWTEST_F(PluginModuleApiTest, ProtoConfigPidAndEffectiveSo, TestSize.Level1) +{ + MemoryConfig protoConfig; + protoConfig.set_report_app_mem_info(true); + protoConfig.add_pid(1); + EXPECT_TRUE(PluginModuleApiTest::MemoryPluginTest(protoConfig, LIB_PATH)); +} + +HWTEST_F(PluginModuleApiTest, MemoryPluginTreeAndInvalidSo, TestSize.Level1) +{ + MemoryConfig protoConfig; + protoConfig.set_report_process_tree(true); + EXPECT_FALSE(PluginModuleApiTest::MemoryPluginTest(protoConfig, "1111")); +} + +HWTEST_F(PluginModuleApiTest, MemoryPluginTreeAndEffectiveSo, TestSize.Level1) +{ + MemoryConfig protoConfig; + protoConfig.set_report_process_tree(true); + EXPECT_TRUE(PluginModuleApiTest::MemoryPluginTest(protoConfig, LIB_PATH)); +} + +HWTEST_F(PluginModuleApiTest, ApiCallInvalidSoAndInvalidStruct, TestSize.Level1) +{ + PluginModuleStruct memplugin; + ASSERT_EQ(memplugin.callbacks->onPluginSessionStart(nullptr, 0), 0); + ASSERT_EQ(memplugin.callbacks->onPluginReportResult(nullptr, 0), 0); + ASSERT_EQ(memplugin.callbacks->onPluginSessionStop(), 0); + ASSERT_EQ(memplugin.callbacks->onRegisterWriterStruct(nullptr), 0); +} + +HWTEST_F(PluginModuleApiTest, ApiCallEffectiveSoAndInvalidStruct, TestSize.Level1) +{ + PluginModuleStruct* memplugin; + void* handle = dlopen(LIB_PATH.c_str(), RTLD_LAZY); + if (handle == nullptr) { + HILOG_DEBUG(LOG_CORE, "test:dlopen err:%s.", dlerror()); + } + memplugin = (PluginModuleStruct*)dlsym(handle, "g_pluginModule"); + ASSERT_EQ(memplugin->callbacks->onPluginSessionStart(nullptr, 0), 0); + ASSERT_EQ(memplugin->callbacks->onPluginReportResult(nullptr, 0), 0); + ASSERT_EQ(memplugin->callbacks->onPluginSessionStop(), 0); + ASSERT_EQ(memplugin->callbacks->onRegisterWriterStruct(nullptr), 0); +} + +HWTEST_F(PluginModuleApiTest, ApiCallInvalidSoAndEffectiveStruct, TestSize.Level1) +{ + PluginModuleStruct memplugin; + WriterStruct writer; + + ASSERT_EQ(memplugin.callbacks->onPluginSessionStart(nullptr, 0), 0); + ASSERT_EQ(memplugin.callbacks->onPluginSessionStop(), 0); + ASSERT_EQ(memplugin.callbacks->onRegisterWriterStruct(&writer), 0); +} + +HWTEST_F(PluginModuleApiTest, ApiCallEffectiveSoAndEffectiveStruct, TestSize.Level1) +{ + PluginModuleStruct* memplugin; + WriterStruct writer; + + void* handle = dlopen(LIB_PATH.c_str(), RTLD_LAZY); + if (handle == nullptr) { + HILOG_DEBUG(LOG_CORE, "test:dlopen err:%s.", dlerror()); + } + memplugin = (PluginModuleStruct*)dlsym(handle, "g_pluginModule"); + ASSERT_EQ(memplugin->callbacks->onPluginSessionStart(nullptr, 0), 0); + ASSERT_EQ(memplugin->callbacks->onPluginSessionStop(), 0); + ASSERT_EQ(memplugin->callbacks->onRegisterWriterStruct(&writer), 0); +} +} // namespace + diff --git a/distributeddatamgr/BUILD.gn b/distributeddatamgr/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..5abec885da6193710bd8701c74197b4c4198cf49 --- /dev/null +++ b/distributeddatamgr/BUILD.gn @@ -0,0 +1,30 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +group("distributeddatamgr") { + testonly = true + if (is_standard_system) { + deps = [ + "appdatamgrjstest/hap:appdatamgr_js_test", + "distributedfilejstest:distributedfile_js_test", + ] + } else { + deps = [ + "appdatamgrtest/hap:appdatamgrfunctest_hap", + "distributeddatamgrtest/hap:distributeddatamgrfunctest_hap", + "distributedfiletest/hap:distributedfilefunctest_hap", + "searchtest/hap:searchfunctest_hap", + ] + } +} diff --git a/distributeddatamgr/appdatamgrjstest/hap/BUILD.gn b/distributeddatamgr/appdatamgrjstest/hap/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..ef77ddc63956d89f311783ea7082ea3daca6a8b9 --- /dev/null +++ b/distributeddatamgr/appdatamgrjstest/hap/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("appdatamgr_js_test") { + test_hap_name = "AppdatamagrJsTest" + hap_source_path = "entry-test-signed.hap" +} diff --git a/distributeddatamgr/appdatamgrjstest/hap/Test.json b/distributeddatamgr/appdatamgrjstest/hap/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..a941b615b43a204c20648f9e541f344920338f28 --- /dev/null +++ b/distributeddatamgr/appdatamgrjstest/hap/Test.json @@ -0,0 +1,19 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "21600000", + "package": "com.example.myapplication", + "abilityName": "decc.testkit.runner.JsEntryAbility", + "shell-timeout": "21600000" + }, + "kits": [ + { + "test-file-name": [ + "AppdatamagrJsTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/distributeddatamgr/appdatamgrjstest/hap/entry-test-signed.hap b/distributeddatamgr/appdatamgrjstest/hap/entry-test-signed.hap new file mode 100755 index 0000000000000000000000000000000000000000..72bb89d604e8363299b174d76c13bcf95729871a Binary files /dev/null and b/distributeddatamgr/appdatamgrjstest/hap/entry-test-signed.hap differ diff --git a/distributeddatamgr/appdatamgrjstest/hap/entry/package.json b/distributeddatamgr/appdatamgrjstest/hap/entry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..0967ef424bce6791893e9a57bb952f80fd536e93 --- /dev/null +++ b/distributeddatamgr/appdatamgrjstest/hap/entry/package.json @@ -0,0 +1 @@ +{} diff --git a/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/config.json b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/config.json new file mode 100755 index 0000000000000000000000000000000000000000..d09b7942e10bd4dac3281d51c3151137e62bad19 --- /dev/null +++ b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/config.json @@ -0,0 +1,59 @@ +{ + "app": { + "bundleName": "com.example.myapplication", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 4 + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.myapplication", + "name": ".AppdatamgrJSTest", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "decc.testkit.runner.JsEntryAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "AppdatamgrJSTest", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} diff --git a/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/default/app.js b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/default/app.js new file mode 100755 index 0000000000000000000000000000000000000000..6a06f7f6cad18519bf28b42a2a171b69d2140f32 --- /dev/null +++ b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/default/app.js @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2021 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 default { + onCreate() { + console.info('TestApplication onCreate'); + }, + onDestroy() { + console.info('TestApplication onDestroy'); + } +}; diff --git a/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/default/i18n/en-US.json b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..55561b83737c3c31d082fbfa11e5fc987a351104 --- /dev/null +++ b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/default/i18n/zh-CN.json b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..cce1af06761a42add0cac1a0567aa3237eda8cb4 --- /dev/null +++ b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/default/pages/index/index.css b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/default/pages/index/index.css new file mode 100755 index 0000000000000000000000000000000000000000..e19021816bc61bc4cb5128677386b9789132e270 --- /dev/null +++ b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2021 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. +*/ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/default/pages/index/index.hml b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..1c26cf73deab18390844a53a103458b10ed11e93 --- /dev/null +++ b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{title}} + +
diff --git a/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/default/pages/index/index.js b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/default/pages/index/index.js new file mode 100755 index 0000000000000000000000000000000000000000..35ad585911527a3de6225937406f75a6aaa19cde --- /dev/null +++ b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2021 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 file from '@system.file' + +import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + const reportExtend = new ReportExtend(file) + + core.addService('expect', expectExtend) + core.addService('report', reportExtend) + core.init() + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} \ No newline at end of file diff --git a/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/test/List.test.js b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/test/List.test.js new file mode 100755 index 0000000000000000000000000000000000000000..7cc4d7759c6510e9967e4cc3612856b5b29e19bb --- /dev/null +++ b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/test/List.test.js @@ -0,0 +1,18 @@ +/* +* Copyright (c) 2021 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. +*/ +require('./StorageHelperJsunit.test.js') +require('./StorageSyncJsunit.test.js') +require('./StoragePromiseJsunit.test.js') +require('./StorageCallBackJsunit.test.js') diff --git a/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/test/StorageCallBackJsunit.test.js b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/test/StorageCallBackJsunit.test.js new file mode 100755 index 0000000000000000000000000000000000000000..d5fcad6fb73a34550d725da712b3cae864992c32 --- /dev/null +++ b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/test/StorageCallBackJsunit.test.js @@ -0,0 +1,212 @@ +/* +* Copyright (c) 2021 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' +import storage from '@ohos.data.storage' + +const PATH = '/data/test_storage'; +const KEY_TEST_INT_ELEMENT = 'key_test_int'; +const KEY_TEST_LONG_ELEMENT = 'key_test_long'; +const KEY_TEST_FLOAT_ELEMENT = 'key_test_float'; +const KEY_TEST_BOOLEAN_ELEMENT = 'key_test_boolean'; +const KEY_TEST_STRING_ELEMENT = 'key_test_string'; +var mPref; + +describe('storageTest', function () { + beforeAll(function () { + console.info('beforeAll') + mPref = storage.getStorageSync(PATH); + }) + + afterAll(function () { + console.info('afterAll') + storage.deleteStorageSync(PATH); + }) + + /** + * @tc.name clear callback interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0010 + * @tc.desc clear callback interface test + */ + it('testClear0012', 0, async function (done) { + mPref.putSync(KEY_TEST_STRING_ELEMENT, "test"); + mPref.flushSync(); + await mPref.clear(function (err, ret) { + expect("defaultvalue").assertEqual(mPref.getSync(KEY_TEST_STRING_ELEMENT, "defaultvalue")); + }); + done(); + }) + + /** + * @tc.name has callback interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0020 + * @tc.desc has callback interface test + */ + it('testHasKey0032', 0, async function (done) { + mPref.putSync(KEY_TEST_STRING_ELEMENT, "test"); + await mPref.has(KEY_TEST_STRING_ELEMENT, function (err, ret) { + expect(true).assertEqual(ret); + }) + done(); + }) + + /** + * @tc.name get defaultValue callback interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0030 + * @tc.desc get defaultValue callback interface test + */ + it('testGetDefValue0062', 0, async function (done) { + mPref.clearSync(); + await mPref.get(KEY_TEST_STRING_ELEMENT, "defaultValue", function (err, ret) { + expect('defaultValue').assertEqual(ret); + }) + done(); + }) + + /** + * @tc.name get float callback interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0040 + * @tc.desc get float callback interface test + */ + it('testGetFloat0072', 0, async function (done) { + mPref.clearSync(); + mPref.putSync(KEY_TEST_FLOAT_ELEMENT, 3.0); + await mPref.get(KEY_TEST_FLOAT_ELEMENT, 0.0, function (err, ret) { + expect(3.0).assertEqual(ret); + }) + done(); + }) + + /** + * @tc.name get int callback interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0050 + * @tc.desc get int callback interface test + */ + it('testGetInt0082', 0, async function (done) { + mPref.clearSync(); + mPref.putSync(KEY_TEST_INT_ELEMENT, 3); + await mPref.get(KEY_TEST_INT_ELEMENT, 0.0, function (err, ret) { + expect(3).assertEqual(ret); + }) + done(); + }) + + /** + * @tc.name get long callback interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0060 + * @tc.desc get long callback interface test + */ + it('testGetLong0092', 0, async function (done) { + mPref.clearSync(); + mPref.putSync(KEY_TEST_LONG_ELEMENT, 3); + expect(3).assertEqual(mPref.getSync(KEY_TEST_LONG_ELEMENT, 0)); + await mPref.get(KEY_TEST_LONG_ELEMENT, 0, function (err, ret) { + expect(3).assertEqual(ret); + }); + done(); + }) + + /** + * @tc.name get String callback interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0070 + * @tc.desc get String callback interface test + */ + it('testGetString102', 0, async function (done) { + mPref.clearSync(); + mPref.putSync(KEY_TEST_STRING_ELEMENT, "test"); + mPref.flushSync(); + await mPref.get(KEY_TEST_STRING_ELEMENT, "defaultvalue", function (err, ret) { + expect('test').assertEqual(ret); + }); + done(); + }) + + /** + * @tc.name put boolean callback interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0080 + * @tc.desc put boolean callback interface test + */ + it('testPutBoolean0122', 0, async function (done) { + mPref.clearSync(); + await mPref.put(KEY_TEST_BOOLEAN_ELEMENT, true, function (err, ret) { + expect(true).assertEqual(mPref.getSync(KEY_TEST_BOOLEAN_ELEMENT, false)); + mPref.flushSync(); + expect(true).assertEqual(mPref.getSync(KEY_TEST_BOOLEAN_ELEMENT, false)); + }); + done(); + }) + + /** + * @tc.name put float callback interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0090 + * @tc.desc put float callback interface test + */ + it('testPutFloat0132', 0, async function (done) { + mPref.clearSync(); + await mPref.put(KEY_TEST_FLOAT_ELEMENT, 4.0, function (err, ret) { + expect(4.0).assertEqual(mPref.getSync(KEY_TEST_FLOAT_ELEMENT, 0.0)); + mPref.flushSync(); + expect(4.0).assertEqual(mPref.getSync(KEY_TEST_FLOAT_ELEMENT, 0.0)); + }); + done(); + }) + + /** + * @tc.name put int callback interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0100 + * @tc.desc put int callback interface test + */ + it('testPutInt0142', 0, async function (done) { + mPref.clearSync(); + await mPref.put(KEY_TEST_INT_ELEMENT, 4, function (err, ret) { + expect(4).assertEqual(mPref.getSync(KEY_TEST_INT_ELEMENT, 0)); + mPref.flushSync(); + expect(4).assertEqual(mPref.getSync(KEY_TEST_INT_ELEMENT, 0)); + }); + done(); + }) + + /** + * @tc.name put long callback interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0110 + * @tc.desc put long callback interface test + */ + it('testPutLong0152', 0, async function (done) { + mPref.clearSync(); + mPref.putSync(KEY_TEST_LONG_ELEMENT, 4); + await mPref.put(KEY_TEST_LONG_ELEMENT, 4, function (err, ret) { + expect(4).assertEqual(mPref.getSync(KEY_TEST_LONG_ELEMENT, 0)); + mPref.flushSync(); + expect(4).assertEqual(mPref.getSync(KEY_TEST_LONG_ELEMENT, 0)); + }); + done(); + }) + + /** + * @tc.name put String callback interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0120 + * @tc.desc put String callback interface test + */ + it('testPutString0162', 0, async function (done) { + mPref.clearSync(); + await mPref.put(KEY_TEST_STRING_ELEMENT, "abc", function (err, ret) { + mPref.put(KEY_TEST_STRING_ELEMENT, '', function (err, ret) { + expect('').assertEqual(mPref.getSync(KEY_TEST_STRING_ELEMENT, "defaultvalue")); + mPref.flushSync(); + expect('').assertEqual(mPref.getSync(KEY_TEST_STRING_ELEMENT, "defaultvalue")); + }); + }); + done(); + }) +}) \ No newline at end of file diff --git a/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/test/StorageHelperJsunit.test.js b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/test/StorageHelperJsunit.test.js new file mode 100755 index 0000000000000000000000000000000000000000..3585fcd54eb2f4d90cf43e4eac9c2335e6f02788 --- /dev/null +++ b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/test/StorageHelperJsunit.test.js @@ -0,0 +1,127 @@ +/* +* Copyright (c) 2021 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' +import storage from '@ohos.data.storage' + +const PATH = '/data/test_storage'; +var mPref; + +describe('storageTest', function () { + beforeAll(function () { + console.info('beforeAll') + mPref = storage.getStorageSync(PATH); + }) + + afterAll(function () { + console.info('afterAll') + storage.deleteStorageSync(PATH); + }) + + /** + * @tc.name getStorageSync interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0010 + * @tc.desc getStorageSync interface test + */ + it('testGetStorageHelper001', 0, function () { + mPref = storage.getStorageSync(PATH); + mPref.putSync('test', 2); + mPref.flushSync(); + var value = mPref.getSync('test', 0); + expect(value).assertEqual(2); + }) + + /** + * @tc.name getStorage interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0020 + * @tc.desc getStorage interface test + */ + it('testGetStorageHelper002', 0, async function (done) { + const promise = storage.getStorage(PATH); + promise.then((pref) => { + pref.putSync('test', 2); + pref.flushSync(); + var value = mPref.getSync('test', 0); + expect(value).assertEqual(2); + }).catch((err) => { + expect(null).assertFail(); + }); + await promise; + done(); + }) + + /** + * @tc.name removeStorageFromCacheSync interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0030 + * @tc.desc removeStorageFromCacheSync interface test + */ + it('testRemoveStorageFromCache001', 0, function () { + let perf = storage.getStorageSync('/data/test_storage1'); + perf = null; + try { + storage.removeStorageFromCacheSync('/data/test_storage1'); + } catch (e) { + expect(null).assertFail(); + } + }) + + /** + * @tc.name removeStorageFromCache interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0040 + * @tc.desc removeStorageFromCache interface test + */ + it('testRemoveStorageFromCache002', 0, async function (done) { + let perf = storage.getStorageSync('/data/test_storage2'); + perf = null; + const promise = storage.removeStorageFromCache('/data/test_storage2'); + promise.then((pref) => { + }).catch((err) => { + expect(null).assertFail(); + }); + await promise; + done(); + }) + + /** + * @tc.name deleteStorageSync interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0050 + * @tc.desc deleteStorageSync interface test + */ + it('testDeleteStorageHelper001', 0, function () { + let perf = storage.getStorageSync('/data/test_storage3'); + perf = null; + try { + storage.deleteStorageSync('/data/test_storage3'); + } catch (e) { + expect(null).assertFail(); + } + }) + + /** + * @tc.name deleteStorage interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0060 + * @tc.desc deleteStorage interface test + */ + it('testDeleteStorageHelper002', 0, async function (done) { + let perf = storage.getStorageSync('/data/test_storage4'); + perf = null; + const promise = storage.deleteStorage('/data/test_storage4'); + promise.then((pref) => { + }).catch((err) => { + expect(null).assertFail(); + }); + await promise; + done(); + }) +}) \ No newline at end of file diff --git a/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/test/StoragePromiseJsunit.test.js b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/test/StoragePromiseJsunit.test.js new file mode 100755 index 0000000000000000000000000000000000000000..d7796c2e2d5a1c95ef54e52d2a1af91afb1ed942 --- /dev/null +++ b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/test/StoragePromiseJsunit.test.js @@ -0,0 +1,258 @@ +/* +* Copyright (c) 2021 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' +import storage from '@ohos.data.storage' + +const PATH = '/data/test_storage'; +const KEY_TEST_INT_ELEMENT = 'key_test_int'; +const KEY_TEST_LONG_ELEMENT = 'key_test_long'; +const KEY_TEST_FLOAT_ELEMENT = 'key_test_float'; +const KEY_TEST_BOOLEAN_ELEMENT = 'key_test_boolean'; +const KEY_TEST_STRING_ELEMENT = 'key_test_string'; +var mPref; + +describe('storageTest', function () { + beforeAll(function () { + console.info('beforeAll') + mPref = storage.getStorageSync(PATH); + }) + + afterAll(function () { + console.info('afterAll') + storage.deleteStorageSync(PATH); + }) + + /** + * @tc.name clear promise interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Promise_0010 + * @tc.desc clear promise interface test + */ + it('testClear0011', 0, async function (done) { + mPref.putSync(KEY_TEST_STRING_ELEMENT, "test"); + mPref.flushSync(); + const promise = mPref.clear(); + promise.then((ret) => { + expect("defaultvalue").assertEqual(mPref.getSync(KEY_TEST_STRING_ELEMENT, "defaultvalue")); + }).catch((err) => { + expect(null).assertFail(); + }); + await promise; + done(); + }) + + /** + * @tc.name has promise interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0020 + * @tc.desc has promise interface test + */ + it('testHasKey0031', 0, async function (done) { + mPref.putSync(KEY_TEST_STRING_ELEMENT, "test"); + const promise = mPref.has(KEY_TEST_STRING_ELEMENT); + promise.then((ret) => { + expect(true).assertEqual(ret); + }).catch((err) => { + expect(null).assertFail(); + }); + await promise; + done(); + }) + + /** + * @tc.name get defalut promise interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0030 + * @tc.desc deleteStorage interface test + */ + it('testGetDefValue0061', 0, async function (done) { + mPref.clearSync(); + const promise = mPref.get(KEY_TEST_STRING_ELEMENT, "defaultValue"); + promise.then((ret) => { + expect('defaultValue').assertEqual(ret); + }).catch((err) => { + expect(null).assertFail(); + }); + await promise; + done(); + }) + + /** + * @tc.name get float promise interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0040 + * @tc.desc get float promise interface test + */ + it('testGetFloat0071', 0, async function (done) { + mPref.clearSync(); + mPref.putSync(KEY_TEST_FLOAT_ELEMENT, 3.0); + const promise = mPref.get(KEY_TEST_FLOAT_ELEMENT, 0.0); + promise.then((ret) => { + expect(3.0).assertEqual(ret); + }).catch((err) => { + expect(null).assertFail(); + }); + await promise; + done(); + }) + + /** + * @tc.name get int promise interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0050 + * @tc.desc get int promise interface test + */ + it('testGetInt0081', 0, async function (done) { + mPref.clearSync(); + mPref.putSync(KEY_TEST_INT_ELEMENT, 3); + const promise = mPref.get(KEY_TEST_INT_ELEMENT, 0.0); + promise.then((ret) => { + expect(3).assertEqual(ret); + }).catch((err) => { + expect(null).assertFail(); + }); + await promise; + done(); + }) + + /** + * @tc.name get long promise interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0060 + * @tc.desc get long promise interface test + */ + it('testGetLong0091', 0, async function (done) { + mPref.clearSync(); + mPref.putSync(KEY_TEST_LONG_ELEMENT, 3); + const promise = mPref.get(KEY_TEST_LONG_ELEMENT, 0); + promise.then((ret) => { + expect(3).assertEqual(ret); + }).catch((err) => { + expect(null).assertFail(); + }); + await promise; + done(); + }) + + /** + * @tc.name get String promise interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0070 + * @tc.desc get String promise interface test + */ + it('testGetString101', 0, async function (done) { + mPref.clearSync(); + mPref.putSync(KEY_TEST_STRING_ELEMENT, "test"); + mPref.flushSync(); + const promise = mPref.get(KEY_TEST_STRING_ELEMENT, "defaultvalue"); + promise.then((ret) => { + expect('test').assertEqual(ret); + }).catch((err) => { + expect(null).assertFail(); + }); + await promise; + done(); + }) + + /** + * @tc.name get String promise interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0090 + * @tc.desc get String promise interface test + */ + it('testPutBoolean0121', 0, async function (done) { + mPref.clearSync(); + const promise = mPref.put(KEY_TEST_BOOLEAN_ELEMENT, true); + promise.then((ret) => { + expect(true).assertEqual(mPref.getSync(KEY_TEST_BOOLEAN_ELEMENT, false)); + mPref.flushSync(); + expect(true).assertEqual(mPref.getSync(KEY_TEST_BOOLEAN_ELEMENT, false)); + }).catch((err) => { + expect(null).assertFail(); + }); + await promise; + done(); + }) + + /** + * @tc.name put float promise interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0100 + * @tc.desc put float promise interface test + */ + it('testPutFloat0131', 0, async function (done) { + mPref.clearSync(); + const promise = mPref.put(KEY_TEST_FLOAT_ELEMENT, 4.0); + promise.then((ret) => { + expect(4.0).assertEqual(mPref.getSync(KEY_TEST_FLOAT_ELEMENT, 0.0)); + mPref.flushSync(); + expect(4.0).assertEqual(mPref.getSync(KEY_TEST_FLOAT_ELEMENT, 0.0)); + }).catch((err) => { + expect(null).assertFail(); + }); + await promise; + done(); + }) + + /** + * @tc.name put int promise interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0110 + * @tc.desc put int promise interface test + */ + it('testPutInt0141', 0, async function (done) { + mPref.clearSync(); + const promise = mPref.put(KEY_TEST_INT_ELEMENT, 4); + promise.then((ret) => { + expect(4).assertEqual(mPref.getSync(KEY_TEST_INT_ELEMENT, 0)); + mPref.flushSync(); + expect(4).assertEqual(mPref.getSync(KEY_TEST_INT_ELEMENT, 0)); + }).catch((err) => { + expect(null).assertFail(); + }); + await promise; + done(); + }) + + /** + * @tc.name put long promise interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0120 + * @tc.desc put long promise interface test + */ + it('testPutLong0151', 0, async function (done) { + mPref.clearSync(); + mPref.putSync(KEY_TEST_LONG_ELEMENT, 4); + const promise = mPref.put(KEY_TEST_LONG_ELEMENT, 4); + promise.then((ret) => { + expect(4).assertEqual(mPref.getSync(KEY_TEST_LONG_ELEMENT, 0)); + mPref.flushSync(); + expect(4).assertEqual(mPref.getSync(KEY_TEST_LONG_ELEMENT, 0)); + }).catch((err) => { + expect(null).assertFail(); + }); + await promise; + done(); + }) + + /** + * @tc.name put String promise interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0130 + * @tc.desc put String promise interface test + */ + it('testPutString0161', 0, async function (done) { + mPref.clearSync(); + mPref.putSync(KEY_TEST_STRING_ELEMENT, "abc"); + const promise = mPref.put(KEY_TEST_STRING_ELEMENT, ''); + promise.then((ret) => { + expect('').assertEqual(mPref.getSync(KEY_TEST_STRING_ELEMENT, "defaultvalue")); + mPref.flushSync(); + expect('').assertEqual(mPref.getSync(KEY_TEST_STRING_ELEMENT, "defaultvalue")); + }).catch((err) => { + expect(null).assertFail(); + }); + await promise; + done(); + }) +}) \ No newline at end of file diff --git a/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/test/StorageSyncJsunit.test.js b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/test/StorageSyncJsunit.test.js new file mode 100755 index 0000000000000000000000000000000000000000..486b00ddc26c3df18df3b4588e149ceac63efd43 --- /dev/null +++ b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/js/test/StorageSyncJsunit.test.js @@ -0,0 +1,249 @@ +/* +* Copyright (c) 2021 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' +import storage from '@ohos.data.storage' + +const PATH = '/data/test_storage'; +const KEY_TEST_INT_ELEMENT = 'key_test_int'; +const KEY_TEST_LONG_ELEMENT = 'key_test_long'; +const KEY_TEST_FLOAT_ELEMENT = 'key_test_float'; +const KEY_TEST_BOOLEAN_ELEMENT = 'key_test_boolean'; +const KEY_TEST_STRING_ELEMENT = 'key_test_string'; + +var mPref; + +describe('storageTest', function () { + beforeAll(function() { + console.info('beforeAll') + mPref = storage.getStorageSync(PATH); + }) + + afterAll(function () { + console.info('afterAll') + storage.deleteStorageSync(PATH); + }) + + it('testClear001', 0, function () { + mPref.putSync(KEY_TEST_STRING_ELEMENT, "test"); + mPref.putSync(KEY_TEST_INT_ELEMENT, 3); + mPref.flushSync(); + mPref.clearSync(); + expect("defaultvalue").assertEqual(mPref.getSync(KEY_TEST_STRING_ELEMENT, "defaultvalue")); + expect(0).assertEqual(mPref.getSync(KEY_TEST_INT_ELEMENT, 0)); + }) + + /** + * @tc.name Constructor test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Sync_0010 + * @tc.desc Constructor test + */ + it('testConstructor002', 0, function () { + expect(mPref).assertInstanceOf('Object'); + }) + + /** + * @tc.name has sync inteface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Sync_0020 + * @tc.desc has sync inteface test + */ + it('testHasKey003', 0, function () { + mPref.putSync(KEY_TEST_STRING_ELEMENT, "test"); + expect(true).assertEqual(mPref.hasSync(KEY_TEST_STRING_ELEMENT)); + }) + + /** + * @tc.name get boolean sync inteface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Sync_0030 + * @tc.desc get boolean sync inteface test + */ + it('testGetBoolean005', 0, function () { + mPref.putSync(KEY_TEST_BOOLEAN_ELEMENT, true); + expect(true).assertEqual(mPref.hasSync(KEY_TEST_BOOLEAN_ELEMENT)); + }) + + /** + * @tc.name get defaltValue sync inteface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Sync_0040 + * @tc.desc get defaltValue sync inteface test + */ + it('testGetDefValue006', 0, function () { + mPref.clearSync(); + expect(-1).assertEqual(mPref.getSync(KEY_TEST_INT_ELEMENT, -1)); + expect(1.0).assertEqual(mPref.getSync(KEY_TEST_FLOAT_ELEMENT, 1.0)); + expect(10000).assertEqual(mPref.getSync(KEY_TEST_LONG_ELEMENT, 10000)); + expect(true).assertEqual(mPref.getSync(KEY_TEST_BOOLEAN_ELEMENT, true)); + expect('defaultValue').assertEqual(mPref.getSync(KEY_TEST_STRING_ELEMENT, "defaultValue")); + }) + + /** + * @tc.name get float sync inteface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Sync_0050 + * @tc.desc get float sync inteface test + */ + it('testGetFloat007', 0, function () { + mPref.clearSync(); + mPref.putSync(KEY_TEST_FLOAT_ELEMENT, 3.0); + expect(3.0).assertEqual(mPref.getSync(KEY_TEST_FLOAT_ELEMENT, 0.0), 0); + expect(0.0).assertEqual(mPref.getSync(KEY_TEST_STRING_ELEMENT, 0.0), 0); + }) + + /** + * @tc.name get int sync inteface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Sync_0060 + * @tc.desc get int sync inteface test + */ + it('testGetInt008', 0, function () { + mPref.clearSync(); + mPref.putSync(KEY_TEST_INT_ELEMENT, 3); + expect(3).assertEqual(mPref.getSync(KEY_TEST_INT_ELEMENT, 0.0), 0); + }) + + /** + * @tc.name get long sync inteface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Sync_0070 + * @tc.desc get long sync inteface test + */ + it('testGetLong009', 0, function () { + mPref.clearSync(); + mPref.putSync(KEY_TEST_LONG_ELEMENT, 3); + expect(3).assertEqual(mPref.getSync(KEY_TEST_LONG_ELEMENT, 0)); + expect(0).assertEqual(mPref.getSync(KEY_TEST_STRING_ELEMENT, 0)); + }) + + /** + * @tc.name get String sync inteface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Sync_0080 + * @tc.desc get String sync inteface test + */ + it('testGetString10', 0, function () { + mPref.clearSync(); + mPref.putSync(KEY_TEST_STRING_ELEMENT, "test"); + mPref.putSync(KEY_TEST_INT_ELEMENT, 3); + mPref.flushSync(); + expect('test').assertEqual(mPref.getSync(KEY_TEST_STRING_ELEMENT, "defaultvalue")); + expect('defaultvalue').assertEqual(mPref.getSync(KEY_TEST_INT_ELEMENT, "defaultvalue")); + }) + + /** + * @tc.name put float sync inteface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Sync_0090 + * @tc.desc put float sync inteface test + */ + it('testPutBoolean012', 0, function () { + mPref.clearSync(); + mPref.putSync(KEY_TEST_BOOLEAN_ELEMENT, true); + expect(true).assertEqual(mPref.getSync(KEY_TEST_BOOLEAN_ELEMENT, false)); + mPref.flushSync(); + expect(true).assertEqual(mPref.getSync(KEY_TEST_BOOLEAN_ELEMENT, false)); + }) + + /** + * @tc.name put float sync inteface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Sync_0100 + * @tc.desc put float sync inteface test + */ + it('testPutFloat013', 0, function () { + mPref.clearSync(); + mPref.putSync(KEY_TEST_FLOAT_ELEMENT, 4.0); + expect(4.0).assertEqual(mPref.getSync(KEY_TEST_FLOAT_ELEMENT, 0.0)); + mPref.flushSync(); + expect(4.0).assertEqual(mPref.getSync(KEY_TEST_FLOAT_ELEMENT, 0.0)); + }) + + /** + * @tc.name put int sync inteface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Sync_0110 + * @tc.desc put int sync inteface test + */ + it('testPutInt014', 0, function () { + mPref.clearSync(); + mPref.putSync(KEY_TEST_INT_ELEMENT, 4); + expect(4).assertEqual(mPref.getSync(KEY_TEST_INT_ELEMENT, 0)); + mPref.flushSync(); + expect(4).assertEqual(mPref.getSync(KEY_TEST_INT_ELEMENT, 0)); + }) + + /** + * @tc.name put long sync inteface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Sync_0120 + * @tc.desc put long sync inteface test + */ + it('testPutLong015', 0, function () { + mPref.clearSync(); + mPref.putSync(KEY_TEST_LONG_ELEMENT, 4); + expect(4).assertEqual(mPref.getSync(KEY_TEST_LONG_ELEMENT, 0)); + mPref.flushSync(); + expect(4).assertEqual(mPref.getSync(KEY_TEST_LONG_ELEMENT, 0)); + }) + + /** + * @tc.name put String sync inteface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Sync_0130 + * @tc.desc put String sync inteface test + */ + it('testPutString016', 0, function () { + mPref.clearSync(); + mPref.putSync(KEY_TEST_STRING_ELEMENT, "abc"); + mPref.putSync(KEY_TEST_STRING_ELEMENT, ''); + expect('').assertEqual(mPref.getSync(KEY_TEST_STRING_ELEMENT, "defaultvalue")); + mPref.flushSync(); + expect('').assertEqual(mPref.getSync(KEY_TEST_STRING_ELEMENT, "defaultvalue")); + }) + + /** + * @tc.name on interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Sync_0140 + * @tc.desc on interface test + */ + it('testRegisterObserver001', 0, function () { + mPref.clearSync(); + var observer = function (key) { + expect('abcd').assertEqual(key); + }; + mPref.on('change', observer); + mPref.putSync(KEY_TEST_STRING_ELEMENT, "abcd"); + }) + + /** + * @tc.name repeat on interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Sync_0150 + * @tc.desc repeat on interface test + */ + it('testRegisterObserver002', 0, function () { + mPref.clearSync(); + var observer = function (key) { + console.info('testRegisterObserver001 key' + key); + expect('abc').assertEqual(key); + }; + mPref.on('change', observer); + mPref.on('change', observer); + mPref.putSync(KEY_TEST_STRING_ELEMENT, "abc"); + }) + + /** + * @tc.name off interface test + * @tc.number SUB_DDM_AppDataFWK_JSPreferences_Sync_0160 + * @tc.desc off interface test + */ + it('testUnRegisterObserver001', 0, function () { + var observer = function (key) { + console.info('testUnRegisterObserver001 key' + key); + expect('').assertEqual(key); + }; + mPref.on('change', observer); + mPref.off('change', observer); + mPref.putSync(KEY_TEST_STRING_ELEMENT, "abc"); + }) +}) \ No newline at end of file diff --git a/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/resources/base/element/string.json b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4388f588a5a0d0c4870e009ac8757faf51598432 --- /dev/null +++ b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication" + }, + { + "name": "mainability_description", + "value": "hap sample empty page" + } + ] +} diff --git a/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/resources/base/media/icon.png b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/appdatamgrjstest/hap/entry/src/main/resources/base/media/icon.png differ diff --git a/distributeddatamgr/distributedfilejstest/BUILD.gn b/distributeddatamgr/distributedfilejstest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f13847a4a3bf584ba2454a5a0fcb3654559b5aa9 --- /dev/null +++ b/distributeddatamgr/distributedfilejstest/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("distributedfile_js_test") { + test_hap_name = "DistributedfileJSTest" + hap_source_path = "hap/entry-debug-rich-signed.hap" +} diff --git a/distributeddatamgr/distributedfilejstest/Test.json b/distributeddatamgr/distributedfilejstest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..de4c6d3e61b3d856ef5cfd0de5f8c2698e2a93d6 --- /dev/null +++ b/distributeddatamgr/distributedfilejstest/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for distributed file Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "21600000", + "package": "ohos.acts.distributeddatamgr.distributedfile", + "shell-timeout": "21600000" + }, + "kits": [ + { + "test-file-name": [ + "DistributedfileJSTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/distributeddatamgr/distributedfilejstest/hap/entry-debug-rich-signed.hap b/distributeddatamgr/distributedfilejstest/hap/entry-debug-rich-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..6b577198f7e4025425dfa6c7af34434a3956cda2 Binary files /dev/null and b/distributeddatamgr/distributedfilejstest/hap/entry-debug-rich-signed.hap differ diff --git a/distributeddatamgr/distributedfilejstest/project/entry/package.json b/distributeddatamgr/distributedfilejstest/project/entry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..69a88e3b65423624fe7ea8b0f8beefcc62cc3d5f --- /dev/null +++ b/distributeddatamgr/distributedfilejstest/project/entry/package.json @@ -0,0 +1 @@ +{} diff --git a/distributeddatamgr/distributedfilejstest/project/entry/src/main/config.json b/distributeddatamgr/distributedfilejstest/project/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..21b8cd9b99c2e3997b860c575345162ede8d55be --- /dev/null +++ b/distributeddatamgr/distributedfilejstest/project/entry/src/main/config.json @@ -0,0 +1,59 @@ +{ + "app": { + "bundleName": "ohos.acts.distributeddatamgr.distributedfile", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 4 + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.distributeddatamgr.distributedfile", + "name": ".DistributedFileJSTest", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "ohos.acts.distributeddatamgr.distributedfile.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "DistributedFileJSTest", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} diff --git a/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/default/app.js b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..2e630f35bd5a9ba035f43c996db3f9a24349448f --- /dev/null +++ b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/default/app.js @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2021 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 device from '@system.device'; + +export default { + onCreate() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + }, + onDestroy() { + console.info('ohos.acts.distributeddatamgr.distributedfile onCreate'); + } +}; diff --git a/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/default/i18n/en-US.json b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/default/i18n/zh-CN.json b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/default/pages/index/index.css b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/default/pages/index/index.hml b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..1c26cf73deab18390844a53a103458b10ed11e93 --- /dev/null +++ b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{title}} + +
diff --git a/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/default/pages/index/index.js b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..5ccd313b0bbe54a8b8a316fc5509b30a2bbafbd0 --- /dev/null +++ b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2021 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 file from '@system.file' +import app from '@system.app' + +import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + const reportExtend = new ReportExtend(file) + core.addService('expect', expectExtend) + core.addService('report', reportExtend) + core.init() + + + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} \ No newline at end of file diff --git a/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/Common.js b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/Common.js new file mode 100644 index 0000000000000000000000000000000000000000..0da46e3844bcbf5190cdbfcb81b8fe3fafc76437 --- /dev/null +++ b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/Common.js @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2021 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 fileio from '@ohos.fileio' + +export const FILE_CONTENT = "hello, world" + +export function prepareFile(fpath, content) { + try { + let fd = fileio.openSync(fpath, 0o102, 0o666) + fileio.ftruncateSync(fd) + fileio.writeSync(fd, content) + fileio.fsyncSync(fd) + fileio.closeSync(fd) + return true + } catch (e) { + console.log("Failed to prepareFile for " + e) + return false + } +} + +var fileSeed = 0 +export function nextFileName(testName) { + const BASE_PATH = "/data/accounts/account_0/appdata/ohos.acts.distributeddatamgr.distributedfile/cache/" + return BASE_PATH + testName + fileSeed++ +} \ No newline at end of file diff --git a/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIO.test.js b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIO.test.js new file mode 100755 index 0000000000000000000000000000000000000000..81c6cd659a51b98db09edf521143d3f270d9b58e --- /dev/null +++ b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIO.test.js @@ -0,0 +1,1000 @@ +/* + * Copyright (C) 2021 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 fileio from '@ohos.fileio' +import bundle_mgr from '@ohos.bundle_mgr' + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' +import { FILE_CONTENT, prepareFile, nextFileName } from './Common' + +describe('fileIOTest', function () { + /** + * @tc.number SUB_DF_FileIO_UnlinkSync_0000 + * @tc.name fileio_test_unlink_sync_000 + * @tc.desc Test unlinkSync() interface. + */ + it('fileio_test_unlink_sync_000', 0, function () { + let fpath = nextFileName('fileIOTest') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_unlink_sync_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_UnlinkSync_0010 + * @tc.name fileio_test_unlink_sync_001 + * @tc.desc Test unlinkSync() interface. + */ + it('fileio_test_unlink_sync_001', 0, function () { + try { + fileio.unlinkSync() + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_UnlinkSync_0020 + * @tc.name fileio_test_unlink_sync_002 + * @tc.desc Test unlinkSync() interface. + */ + it('fileio_test_unlink_sync_002', 0, function () { + let fpath = nextFileName('fileIOTest') + + try { + fileio.unlinkSync(fpath) + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_AccessSync_0000 + * @tc.name fileio_test_access_sync_000 + * @tc.desc Test accessSync() interface. + */ + it('fileio_test_access_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_access_sync_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + expect(fileio.accessSync(fpath)).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_access_sync_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_AccessSync_0010 + * @tc.name fileio_test_access_sync_001 + * @tc.desc Test accessSync() interface. + */ + it('fileio_test_access_sync_001', 0, function () { + try { + fileio.accessSync() + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_AccessSync_0020 + * @tc.name fileio_test_access_sync_002 + * @tc.desc Test accessSync() interface. + */ + it('fileio_test_access_sync_002', 0, function () { + let fpath = nextFileName('fileIOTest') + + try { + fileio.accessSync(fpath) + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_OpenCloseSync_0000 + * @tc.name fileio_test_open_close_sync_000 + * @tc.desc Test openSync() and closeSync() interfaces. + */ + it('fileio_test_open_close_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_open_close_sync_000') + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666) + expect(fd).assertInstanceOf('Number') + expect(fileio.closeSync(fd)).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_open_close_sync_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_OpenSync_0000 + * @tc.name fileio_test_open_sync_000 + * @tc.desc Test openSync() interface. + */ + it('fileio_test_open_sync_000', 0, function () { + try { + fileio.openSync("/", 0o102, 0o666) + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_OpenSync_0010 + * @tc.name fileio_test_open_sync_001 + * @tc.desc Test openSync() interface. + */ + it('fileio_test_open_sync_001', 0, function () { + let fpath = nextFileName('fileio_test_open_sync_001') + + try { + fileio.openSync(fpath, 0o102) + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_CloseSync_0000 + * @tc.name fileio_test_close_sync_000 + * @tc.desc Test closeSync() interface. + */ + it('fileio_test_close_sync_000', 0, function () { + try { + fileio.closeSync() + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_CloseSync_0010 + * @tc.name fileio_test_close_sync_001 + * @tc.desc Test closeSync() interface. + */ + it('fileio_test_close_sync_001', 0, function () { + try { + fileio.closeSync(-1) + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_WriteSync_0000 + * @tc.name fileio_test_write_sync_000 + * @tc.desc Test writeSync() interface. + */ + it('fileio_test_write_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_write_sync_000') + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666) + expect(fd).assertInstanceOf('Number') + expect(fileio.writeSync(fd, FILE_CONTENT)).assertEqual(FILE_CONTENT.length) + expect(fileio.closeSync(fd)).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_write_sync_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_WriteSync_0010 + * @tc.name fileio_test_write_sync_001 + * @tc.desc Test writeSync() interface. + */ + it('fileio_test_write_sync_001', 0, function () { + let fpath = nextFileName('fileio_test_write_sync_001') + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666) + expect(fd).assertInstanceOf('Number') + expect(fileio.writeSync(fd, FILE_CONTENT, { + encoding: "utf-8", + })).assertEqual(FILE_CONTENT.length) + expect(fileio.closeSync(fd)).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_write_sync_001 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_WriteSync_0020 + * @tc.name fileio_test_write_sync_002 + * @tc.desc Test writeSync() interface. + */ + it('fileio_test_write_sync_002', 0, function () { + let fpath = nextFileName('fileio_test_write_sync_002') + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666) + expect(fd).assertInstanceOf('Number') + expect(fileio.writeSync(fd, FILE_CONTENT, { + offset: 1, + })).assertEqual(FILE_CONTENT.length - 1) + expect(fileio.closeSync(fd)).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_write_sync_002 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_WriteSync_0030 + * @tc.name fileio_test_write_sync_003 + * @tc.desc Test writeSync() interface. + */ + it('fileio_test_write_sync_003', 0, function () { + let fpath = nextFileName('fileio_test_write_sync_003') + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666) + expect(fd).assertInstanceOf('Number') + expect(fileio.writeSync(fd, FILE_CONTENT, { + length: FILE_CONTENT.length - 1, + })).assertEqual(FILE_CONTENT.length - 1) + expect(fileio.closeSync(fd)).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_write_sync_003 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_WriteSync_0040 + * @tc.name fileio_test_write_sync_004 + * @tc.desc Test writeSync() interface. + */ + it('fileio_test_write_sync_004', 0, function () { + let fpath = nextFileName('fileio_test_write_sync_004') + + try { + let fd = fileio.openSync(fpath, 0o102, 0o666) + expect(fd).assertInstanceOf('Number') + expect(fileio.writeSync(fd, FILE_CONTENT, { + offset: 1, + length: 1, + })).assertEqual(1) + expect(fileio.closeSync(fd)).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_write_sync_004 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_WriteSync_0050 + * @tc.name fileio_test_write_sync_005 + * @tc.desc Test writeSync() interface. + */ + it('fileio_test_write_sync_005', 0, function () { + let fpath = nextFileName('fileio_test_write_sync_005') + const invalidOffset = 999 + let fd + + try { + fd = fileio.openSync(fpath, 0o102, 0o666) + expect(fd).assertInstanceOf('Number') + expect(fileio.writeSync(fd, FILE_CONTENT, { + offset: invalidOffset, + })).assertEqual(1) + expect(null).assertFail() + } catch (e) { + expect(fileio.closeSync(fd)).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } + }) + + /** + * @tc.number SUB_DF_FileIO_WriteSync_0060 + * @tc.name fileio_test_write_sync_006 + * @tc.desc Test writeSync() interface. + */ + it('fileio_test_write_sync_006', 0, function () { + let fpath = nextFileName('fileio_test_write_sync_006') + const invalidLength = 999 + let fd + + try { + fd = fileio.openSync(fpath, 0o102, 0o666) + expect(fd).assertInstanceOf('Number') + expect(fileio.writeSync(fd, FILE_CONTENT, { + length: invalidLength, + })).assertEqual(1) + expect(null).assertFail() + } catch (e) { + expect(fileio.closeSync(fd)).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } + }) + + /** + * @tc.number SUB_DF_FileIO_WriteSync_0070 + * @tc.name fileio_test_write_sync_007 + * @tc.desc Test writeSync() interface. + */ + it('fileio_test_write_sync_007', 0, function () { + try { + fileio.writeSync() + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_WriteSync_0080 + * @tc.name fileio_test_write_sync_008 + * @tc.desc Test writeSync() interface. + */ + it('fileio_test_write_sync_008', 0, function () { + try { + fileio.writeSync(-1, FILE_CONTENT) + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_ReadSync_0000 + * @tc.name fileio_test_read_sync_000 + * @tc.desc Test readSync() interface. + */ + it('fileio_test_read_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_read_sync_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let fd = fileio.openSync(fpath, 0o2) + expect(fd).assertInstanceOf('Number') + let len = fileio.readSync(fd, new ArrayBuffer(4096)) + expect(len).assertEqual(FILE_CONTENT.length) + expect(fileio.closeSync(fd)).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_read_sync_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_ReadSync_0001 + * @tc.name fileio_test_read_sync_001 + * @tc.desc Test readSync() interface. + */ + it('fileio_test_read_sync_001', 0, function () { + let bufLen = 5 + expect(FILE_CONTENT.length).assertLarger(bufLen) + let fpath = nextFileName('fileio_test_read_sync_001') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let fd = fileio.openSync(fpath, 0o2) + expect(fd).assertInstanceOf('Number') + let len = fileio.readSync(fd, new ArrayBuffer(bufLen), { + offset: 1, + }) + expect(len).assertEqual(bufLen - 1) + expect(fileio.closeSync(fd)).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_read_sync_001 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_ReadSync_0020 + * @tc.name fileio_test_read_sync_002 + * @tc.desc Test readSync() interface. + */ + it('fileio_test_read_sync_002', 0, function () { + let fpath = nextFileName('fileio_test_read_sync_002') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let fd = fileio.openSync(fpath, 0o2) + expect(fd).assertInstanceOf('Number') + let len = fileio.readSync(fd, new ArrayBuffer(4096), { + length: 1, + }) + expect(len).assertEqual(1) + expect(fileio.closeSync(fd)).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_read_sync_002 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_ReadSync_0030 + * @tc.name fileio_test_read_sync_003 + * @tc.desc Test readSync() interface. + */ + it('fileio_test_read_sync_003', 0, function () { + let fd + const invalidOffset = 99999 + let fpath = nextFileName('fileio_test_read_sync_003') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + fd = fileio.openSync(fpath, 0o2) + expect(fd).assertInstanceOf('Number') + fileio.readSync(fd, new ArrayBuffer(4096), { + offset: invalidOffset, + }) + expect(null).assertFail() + } catch (e) { + expect(fileio.closeSync(fd)).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } + }) + + /** + * @tc.number SUB_DF_FileIO_ReadSync_0040 + * @tc.name fileio_test_read_sync_004 + * @tc.desc Test readSync() interface. + */ + it('fileio_test_read_sync_004', 0, function () { + let fd + const invalidLength = 9999 + let fpath = nextFileName('fileio_test_read_sync_004') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + fd = fileio.openSync(fpath, 0o2) + expect(fd).assertInstanceOf('Number') + fileio.readSync(fd, new ArrayBuffer(4096), { + length: invalidLength, + }) + expect(null).assertFail() + } catch (e) { + expect(fileio.closeSync(fd)).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } + }) + + /** + * @tc.number SUB_DF_FileIO_ReadSync_0050 + * @tc.name fileio_test_read_sync_005 + * @tc.desc Test readSync() interface. + */ + it('fileio_test_read_sync_005', 0, function () { + let fpath = nextFileName('fileio_test_read_sync_005') + let fd + + try { + fileio.readSync(-1, new ArrayBuffer(4096)) + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_ReadSync_0060 + * @tc.name fileio_test_read_sync_006 + * @tc.desc Test readSync() interface. + */ + it('fileio_test_read_sync_006', 0, function () { + let fpath = nextFileName('fileio_test_read_sync_006') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let fd = fileio.openSync(fpath, 0o2) + expect(fd).assertInstanceOf('Number') + let len = fileio.readSync(fd, new ArrayBuffer(4096), { + position: 1, + }) + expect(len).assertEqual(FILE_CONTENT.length - 1) + expect(fileio.closeSync(fd)).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_read_sync_006 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_ReadSync_0070 + * @tc.name fileio_test_read_sync_007 + * @tc.desc Test readSync() interface. + */ + it('fileio_test_read_sync_007', 0, function () { + let fpath = nextFileName('fileio_test_read_sync_007') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let fd = fileio.openSync(fpath, 0o2) + expect(fd).assertInstanceOf('Number') + let invalidPos = FILE_CONTENT.length + 1 + let len = fileio.readSync(fd, new ArrayBuffer(4096), { + position: invalidPos, + }) + expect(len).assertEqual(0) + expect(fileio.closeSync(fd)).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_read_sync_007 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_ChmodSync_0000 + * @tc.name fileio_test_chmod_sync_000 + * @tc.desc Test chmodSync() interface. + */ + it('fileio_test_chmod_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_chmod_sync_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + expect(fileio.chmodSync(fpath, 0o660)).assertNull() + expect(fileio.Stat.statSync(fpath).mode & 0o777).assertEqual(0o660) + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_chmod_sync_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_ChmodSync_0010 + * @tc.name fileio_test_chmod_sync_001 + * @tc.desc Test chmodSync() interface. + */ + it('fileio_test_chmod_sync_001', 0, function () { + let fpath = nextFileName('fileio_test_chmod_sync_001') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + fileio.chmodSync(fpath) + expect(null).assertFail() + } catch (e) { + expect(fileio.unlinkSync(fpath)).assertNull() + } + }) + + /** + * @tc.number SUB_DF_FileIO_ChmodSync_0020 + * @tc.name fileio_test_chmod_sync_002 + * @tc.desc Test chmodSync() interface. + */ + it('fileio_test_chmod_sync_002', 0, function () { + let fpath = nextFileName('fileio_test_chmod_sync_002') + + try { + fileio.chmodSync(fpath, 0o660) + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_CopyFileSync_0000 + * @tc.name fileio_test_copy_file_sync_000 + * @tc.desc Test copyFileSync() interface. + */ + it('fileio_test_copy_file_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_copy_file_sync_000') + let fpathTarget = fpath + 'tgt' + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + expect(fileio.copyFileSync(fpath, fpathTarget)).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + expect(fileio.unlinkSync(fpathTarget)).assertNull() + } catch (e) { + console.log("fileio_test_copy_file_sync_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_CopyFileSync_0010 + * @tc.name fileio_test_copy_file_sync_001 + * @tc.desc Test copyFileSync() interface. + */ + it('fileio_test_copy_file_sync_001', 0, function () { + let fpath = nextFileName('fileio_test_copy_file_sync_000') + let fpathTarget = fpath + 'tgt' + + try { + fileio.copyFileSync(fpath, fpathTarget) + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_CopyFileSync_0020 + * @tc.name fileio_test_copy_file_sync_002 + * @tc.desc Test copyFileSync() interface. + */ + it('fileio_test_copy_file_sync_002', 0, function () { + try { + fileio.copyFileSync() + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_TruncateSync_0000 + * @tc.name fileio_test_truncate_sync_000 + * @tc.desc Test truncateSync() interface. + */ + it('fileio_test_truncate_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_truncate_sync_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + expect(fileio.truncateSync(fpath)).assertNull() + expect(fileio.Stat.statSync(fpath).size).assertEqual(0) + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_truncate_sync_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_TruncateSync_0010 + * @tc.name fileio_test_truncate_sync_001 + * @tc.desc Test truncateSync() interface. + */ + it('fileio_test_truncate_sync_001', 0, function () { + let fpath = nextFileName('fileio_test_truncate_sync_001') + + try { + fileio.truncateSync(fpath) + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_TruncateSync_0020 + * @tc.name fileio_test_truncate_sync_002 + * @tc.desc Test truncateSync() interface. + */ + it('fileio_test_truncate_sync_002', 0, function () { + try { + fileio.truncateSync() + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_RenameSync_0000 + * @tc.name fileio_test_rename_sync_000 + * @tc.desc Test renameSync() interface. + */ + it('fileio_test_rename_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_rename_sync_000') + let fpathTarget = fpath + 'tgt' + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + expect(fileio.renameSync(fpath, fpathTarget)).assertNull() + expect(fileio.accessSync(fpathTarget)).assertNull() + expect(fileio.unlinkSync(fpathTarget)).assertNull() + } catch (e) { + console.log("fileio_test_rename_sync_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_RenameSync_0010 + * @tc.name fileio_test_rename_sync_001 + * @tc.desc Test renameSync() interface. + */ + it('fileio_test_rename_sync_001', 0, function () { + let fpath = nextFileName('fileio_test_rename_sync_001') + let fpathTarget = fpath + 'tgt' + + try { + fileio.renameSync(fpath, fpathTarget) + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_RenameSync_0020 + * @tc.name fileio_test_rename_sync_002 + * @tc.desc Test renameSync() interface. + */ + it('fileio_test_rename_sync_002', 0, function () { + let fpath = nextFileName('fileio_test_rename_sync_002') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + fileio.renameSync(fpath, "/") + } catch (e) { + expect(fileio.unlinkSync(fpath)).assertNull() + } + }) + + /** + * @tc.number SUB_DF_FileIO_FchmodSync_0000 + * @tc.name fileio_test_fchmod_sync_000 + * @tc.desc Test fchmodSync() interface. + */ + it('fileio_test_fchmod_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_fchmod_sync_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let fd = fileio.openSync(fpath, 0o2) + expect(fileio.fchmodSync(fd, 0o660)).assertNull() + expect(fileio.Stat.statSync(fpath).mode & 0o777).assertEqual(0o660) + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_fchmod_sync_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_FchmodSync_0010 + * @tc.name fileio_test_fchmod_sync_001 + * @tc.desc Test fchmodSync() interface. + */ + it('fileio_test_fchmod_sync_001', 0, function () { + try { + expect(fileio.fchmodSync(-1, 0o660)).assertNull() + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_FtruncateSync_0000 + * @tc.name fileio_test_ftruncate_sync_000 + * @tc.desc Test ftruncateSync() interface. + */ + it('fileio_test_ftruncate_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_ftruncate_sync_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let fd = fileio.openSync(fpath, 0o2) + expect(fileio.ftruncateSync(fd)).assertNull() + expect(fileio.Stat.statSync(fpath).size).assertEqual(0) + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_ftruncate_sync_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_FtruncateSync_0010 + * @tc.name fileio_test_ftruncate_sync_001 + * @tc.desc Test ftruncateSync() interface. + */ + it('fileio_test_ftruncate_sync_001', 0, function () { + try { + fileio.ftruncateSync(-1) + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_FsyncSync_0000 + * @tc.name fileio_test_fsync_sync_000 + * @tc.desc Test fsyncSync() interface. + */ + it('fileio_test_fsync_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_fsync_sync_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let fd = fileio.openSync(fpath, 0o2) + expect(fileio.fsyncSync(fd)).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_fsync_sync_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_FsyncSync_0010 + * @tc.name fileio_test_fsync_sync_001 + * @tc.desc Test fsyncSync() interface. + */ + it('fileio_test_fsync_sync_001', 0, function () { + try { + fileio.fsyncSync(-1) + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_MkdirSync_0000 + * @tc.name fileio_test_mkdir_sync_rmdir_sync_000 + * @tc.desc Test mkdirSync() interface. + */ + it('fileio_test_mkdir_sync_rmdir_sync_000', 0, function () { + let dpath = nextFileName('fileio_test_fsync_sync_000') + 'd' + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + expect(fileio.rmdirSync(dpath)).assertNull() + } catch (e) { + console.log("fileio_test_mkdir_sync_rmdir_sync_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_MkdirSync_0010 + * @tc.name fileio_test_mkdir_sync_rmdir_sync_001 + * @tc.desc Test mkdirSync() interface. + */ + it('fileio_test_mkdir_sync_rmdir_sync_001', 0, function () { + try { + expect(fileio.mkdirSync("/")).assertNull() + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_ChownSync_0000 + * @tc.name fileio_test_chown_sync_000 + * @tc.desc Test chownSync() interface. + */ + it('fileio_test_chown_sync_000', 0, async function (done) { + let fpath = nextFileName('fileio_test_chown_sync_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let bundleInfo = await bundle_mgr.getBundleInfo("ohos.acts.distributeddatamgr.distributedfile") + let UID = bundleInfo.uid + let GID = bundleInfo.gid + + try { + expect(fileio.chownSync(fpath, UID, GID)) + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_chown_sync_000 has failed for " + e) + expect(null).assertFail() + } + done() + }) + + /** + * @tc.number SUB_DF_FileIO_ChownSync_0010 + * @tc.name fileio_test_chown_sync_001 + * @tc.desc Test chownSync() interface. + */ + it('fileio_test_chown_sync_001', 0, async function (done) { + let bundleInfo = await bundle_mgr.getBundleInfo("ohos.acts.distributeddatamgr.distributedfile") + let UID = bundleInfo.uid + let GID = bundleInfo.gid + let fpath = nextFileName('fileio_test_chown_sync_001') + + try { + expect(fileio.chownSync(fpath, UID, GID)) + expect(null).assertFail() + } catch (e) { + } + done() + }) + + /** + * @tc.number SUB_DF_FileIO_ChownSync_0020 + * @tc.name fileio_test_chown_sync_002 + * @tc.desc Test chownSync() interface. + */ + it('fileio_test_chown_sync_002', 0, function () { + let fpath = nextFileName('fileio_test_chown_sync_002') + + try { + expect(fileio.chownSync(fpath, 0, 0)) + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_FchownSync_0000 + * @tc.name fileio_test_fchown_sync_000 + * @tc.desc Test fchownSync() interface. + */ + it('fileio_test_fchown_sync_000', 0, async function (done) { + let fpath = nextFileName('fileio_test_fchown_sync_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let bundleInfo = await bundle_mgr.getBundleInfo("ohos.acts.distributeddatamgr.distributedfile") + let UID = bundleInfo.uid + let GID = bundleInfo.gid + + try { + let fd = fileio.openSync(fpath, 0o2) + expect(fileio.fchownSync(fd, UID, GID)) + expect(fd).assertInstanceOf('Number') + expect(fileio.closeSync(fd)).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + + } catch (e) { + console.log("fileio_test_fchown_sync_000 has failed for " + e) + expect(null).assertFail() + } + done() + }) + + /** + * @tc.number SUB_DF_FileIO_FchownSync_0010 + * @tc.name fileio_test_fchown_sync_001 + * @tc.desc Test fchownSync() interface. + */ + it('fileio_test_fchown_sync_001', 0, async function (done) { + let bundleInfo = await bundle_mgr.getBundleInfo("ohos.acts.distributeddatamgr.distributedfile") + let UID = bundleInfo.uid + let GID = bundleInfo.gid + + try { + expect(fileio.fchownSync(-1, UID, GID)) + expect(null).assertFail() + } catch (e) { + } + done() + }) + + /** + * @tc.number SUB_DF_FileIO_FchownSync_0020 + * @tc.name fileio_test_fchown_sync_002 + * @tc.desc Test fchownSync() interface. + */ + it('fileio_test_fchown_sync_002', 0, function () { + let fd + let fpath = nextFileName('fileio_test_fchown_sync_002') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + fd = fileio.openSync(fpath, 0o2) + fileio.fchownSync(fd, 0, 0) + expect(null).assertFail() + + } catch (e) { + expect(fileio.closeSync(fd)).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } + }) +}) \ No newline at end of file diff --git a/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIODir.test.js b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIODir.test.js new file mode 100755 index 0000000000000000000000000000000000000000..08b8079b6fd223a8fab7c8181b70c37d9cc98fd6 --- /dev/null +++ b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIODir.test.js @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2021 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 fileio from '@ohos.fileio' + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' +import { FILE_CONTENT, prepareFile, nextFileName } from './Common' + +describe('fileIOTestDir', function () { + /** + * @tc.number SUB_DF_FileIO_OpenClosedirSync_0000 + * @tc.name fileio_test_dir_open_close_sync_000 + * @tc.desc Test opendirSync() and Dir.closeSync() interfaces. + */ + it('fileio_test_dir_open_close_sync_000', 0, function () { + let dpath = nextFileName('fileio_test_dir_open_close_sync_000') + 'd' + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + let dd = fileio.Dir.opendirSync(dpath) + expect(dd !== null).assertTrue() + expect(dd.closeSync()).assertNull() + expect(fileio.rmdirSync(dpath)).assertNull() + } catch (e) { + console.log("fileio_test_dir_open_close_sync_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_OpenClosedirSync_0010 + * @tc.name fileio_test_dir_open_close_sync_001 + * @tc.desc Test opendirSync() interface. + */ + it('fileio_test_dir_open_close_sync_001', 0, function () { + try { + fileio.Dir.opendirSync() + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_OpenClosedirSync_0020 + * @tc.name fileio_test_dir_open_close_sync_002 + * @tc.desc Test opendirSync() interface. + */ + it('fileio_test_dir_open_close_sync_002', 0, function () { + let dpath = nextFileName('fileio_test_dir_read_sync_000') + 'd' + + try { + fileio.Dir.opendirSync(dpath) + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadSync_0000 + * @tc.name fileio_test_dir_read_sync_000 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_test_dir_read_sync_000', 0, function () { + let dpath = nextFileName('fileio_test_dir_read_sync_000') + 'd' + let fpath = dpath + '/f1' + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let dd = fileio.Dir.opendirSync(dpath) + expect(dd !== null).assertTrue() + expect(dd.readSync() != null).assertTrue() + expect(dd.closeSync()).assertNull() + + expect(fileio.unlinkSync(fpath)).assertNull() + expect(fileio.rmdirSync(dpath)).assertNull() + } catch (e) { + console.log("fileio_test_dir_read_sync_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Dir_ReadSync_0010 + * @tc.name fileio_test_dir_read_sync_001 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_test_dir_read_sync_001', 0, function () { + let dpath = nextFileName('fileio_test_dir_read_sync_001') + 'd' + let fpath = dpath + '/f1' + let dd + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + dd = fileio.Dir.opendirSync(dpath) + expect(dd !== null).assertTrue() + expect(dd.readSync(-1) != null).assertTrue() + expect(null).assertFail() + } catch (e) { + expect(dd.closeSync()).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + expect(fileio.rmdirSync(dpath)).assertNull() + } + }) +}) \ No newline at end of file diff --git a/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIODirent.test.js b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIODirent.test.js new file mode 100755 index 0000000000000000000000000000000000000000..349cce9e3c074241182c77aab98b2d796d8ecc8e --- /dev/null +++ b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIODirent.test.js @@ -0,0 +1,411 @@ +/* + * Copyright (C) 2021 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 fileio from '@ohos.fileio' + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' +import {FILE_CONTENT, prepareFile, nextFileName} from './Common' + +describe('fileIOTestDirent', function () { + /** + * @tc.number SUB_DF_FileIO_Dir_ReadSync_0000 + * @tc.name fileio_test_dirent_name_000 + * @tc.desc Test Dir.readSync() interface. + */ + it('fileio_test_dirent_name_000', 0, function () { + let dpath = nextFileName('fileio_test_dirent_name_000') + 'd' + let fpath = dpath + '/f1' + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let dd = fileio.Dir.opendirSync(dpath) + expect(dd !== null).assertTrue() + let dirent = dd.readSync() + expect(dirent !== null).assertTrue() + expect(dirent.name).assertInstanceOf('String') + expect(dd.closeSync()).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + expect(fileio.rmdirSync(dpath)).assertNull() + } catch (e) { + console.log("fileio_test_dirent_name_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Dir_IsBlockDevice_0000 + * @tc.name fileio_test_dirent_is_block_device_000 + * @tc.desc Test Dir.isBlockDevice() interface. + */ + it('fileio_test_dirent_is_block_device_000', 0, function () { + let dpath = nextFileName('fileio_test_dirent_is_block_device_000') + 'd' + let fpath = dpath + '/f1' + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let dd = fileio.Dir.opendirSync(dpath) + expect(dd !== null).assertTrue() + let dirent = dd.readSync() + expect(dirent !== null).assertTrue() + expect(dirent.isBlockDevice()).assertInstanceOf('Boolean') + expect(dd.closeSync()).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + expect(fileio.rmdirSync(dpath)).assertNull() + } catch (e) { + console.log("fileio_test_dirent_is_block_device_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Dir_IsBlockDevice_0010 + * @tc.name fileio_test_dirent_is_block_device_001 + * @tc.desc Test Dir.isBlockDevice() interface. + */ + it('fileio_test_dirent_is_block_device_001', 0, function () { + let dpath = nextFileName('fileio_test_dirent_is_block_device_001') + 'd' + let fpath = dpath + '/f1' + let dd + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + dd = fileio.Dir.opendirSync(dpath) + expect(dd !== null).assertTrue() + let dirent = dd.readSync() + expect(dirent !== null).assertTrue() + dirent.isBlockDevice(-1) + expect(null).assertFail() + } catch (e) { + expect(dd.closeSync()).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + expect(fileio.rmdirSync(dpath)).assertNull() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Dir_IsCharacterDevice_0000 + * @tc.name fileio_test_dirent_is_character_device_000 + * @tc.desc Test Dir.isCharacterDevice() interface. + */ + it('fileio_test_dirent_is_character_device_000', 0, function () { + let dpath = nextFileName('fileio_test_dirent_is_character_device_000') + 'd' + let fpath = dpath + '/f1' + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let dd = fileio.Dir.opendirSync(dpath) + expect(dd !== null).assertTrue() + let dirent = dd.readSync() + expect(dirent !== null).assertTrue() + expect(dirent.isCharacterDevice()).assertInstanceOf('Boolean') + expect(dd.closeSync()).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + expect(fileio.rmdirSync(dpath)).assertNull() + } catch (e) { + console.log("fileio_test_dirent_is_character_device_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Dir_IsCharacterDevice_0010 + * @tc.name fileio_test_dirent_is_character_device_001 + * @tc.desc Test Dir.isCharacterDevice() interface. + */ + it('fileio_test_dirent_is_character_device_001', 0, function () { + let dpath = nextFileName('fileio_test_dirent_is_character_device_001') + 'd' + let fpath = dpath + '/f1' + let dd + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + dd = fileio.Dir.opendirSync(dpath) + expect(dd !== null).assertTrue() + let dirent = dd.readSync() + expect(dirent !== null).assertTrue() + dirent.isCharacterDevice(-1) + expect(null).assertFail() + } catch (e) { + expect(dd.closeSync()).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + expect(fileio.rmdirSync(dpath)).assertNull() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Dir_IsDirectory_0000 + * @tc.name fileio_test_dirent_is_directory_000 + * @tc.desc Test Dir.isDirectory() interface. + */ + it('fileio_test_dirent_is_directory_000', 0, function () { + let dpath = nextFileName('fileio_test_dirent_is_directory_000') + 'd' + let fpath = dpath + '/f1' + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let dd = fileio.Dir.opendirSync(dpath) + expect(dd !== null).assertTrue() + let dirent = dd.readSync() + expect(dirent !== null).assertTrue() + expect(dirent.isDirectory()).assertInstanceOf('Boolean') + expect(dd.closeSync()).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + expect(fileio.rmdirSync(dpath)).assertNull() + } catch (e) { + console.log("fileio_test_dirent_is_directory_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Dir_IsDirectory_0010 + * @tc.name fileio_test_dirent_is_directory_001 + * @tc.desc Test Dir.isDirectory() interface. + */ + it('fileio_test_dirent_is_directory_001', 0, function () { + let dpath = nextFileName('fileio_test_dirent_is_directory_001') + 'd' + let fpath = dpath + '/f1' + let dd + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + dd = fileio.Dir.opendirSync(dpath) + expect(dd !== null).assertTrue() + let dirent = dd.readSync() + expect(dirent !== null).assertTrue() + dirent.isDirectory(-1) + expect(null).assertFail() + } catch (e) { + expect(dd.closeSync()).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + expect(fileio.rmdirSync(dpath)).assertNull() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Dir_IsFIFO_0000 + * @tc.name fileio_test_dirent_is_fifo_000 + * @tc.desc Test Dir.isFIFO() interface. + */ + it('fileio_test_dirent_is_fifo_000', 0, function () { + let dpath = nextFileName('fileio_test_dirent_is_fifo_000') + 'd' + let fpath = dpath + '/f1' + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let dd = fileio.Dir.opendirSync(dpath) + expect(dd !== null).assertTrue() + let dirent = dd.readSync() + expect(dirent !== null).assertTrue() + expect(dirent.isFIFO()).assertInstanceOf('Boolean') + expect(dd.closeSync()).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + expect(fileio.rmdirSync(dpath)).assertNull() + } catch (e) { + console.log("fileio_test_dirent_is_fifo_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Dir_IsFIFO_0010 + * @tc.name fileio_test_dirent_is_fifo_001 + * @tc.desc Test Dir.isFIFO() interface. + */ + it('fileio_test_dirent_is_fifo_001', 0, function () { + let dpath = nextFileName('fileio_test_dirent_is_fifo_001') + 'd' + let fpath = dpath + '/f1' + let dd + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + dd = fileio.Dir.opendirSync(dpath) + expect(dd !== null).assertTrue() + let dirent = dd.readSync() + expect(dirent !== null).assertTrue() + dirent.isFIFO(-1) + expect(null).assertFail() + } catch (e) { + expect(dd.closeSync()).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + expect(fileio.rmdirSync(dpath)).assertNull() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Dir_IsFILE_0000 + * @tc.name fileio_test_dirent_is_file_000 + * @tc.desc Test Dir.isFILE() interface. + */ + it('fileio_test_dirent_is_file_000', 0, function () { + let dpath = nextFileName('fileio_test_dirent_is_file_000') + 'd' + let fpath = dpath + '/f1' + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let dd = fileio.Dir.opendirSync(dpath) + expect(dd !== null).assertTrue() + let dirent = dd.readSync() + expect(dirent !== null).assertTrue() + expect(dirent.isFile()).assertInstanceOf('Boolean') + expect(dd.closeSync()).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + expect(fileio.rmdirSync(dpath)).assertNull() + } catch (e) { + console.log("fileio_test_dirent_is_file_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Dir_IsFILE_0010 + * @tc.name fileio_test_dirent_is_file_001 + * @tc.desc Test Dir.isFILE() interface. + */ + it('fileio_test_dirent_is_file_001', 0, function () { + let dpath = nextFileName('fileio_test_dirent_is_file_001') + 'd' + let fpath = dpath + '/f1' + let dd + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + dd = fileio.Dir.opendirSync(dpath) + expect(dd !== null).assertTrue() + let dirent = dd.readSync() + expect(dirent !== null).assertTrue() + dirent.isFile(-1) + expect(null).assertFail() + } catch (e) { + expect(dd.closeSync()).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + expect(fileio.rmdirSync(dpath)).assertNull() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Dir_IsSocket_0000 + * @tc.name fileio_test_dirent_is_socket_000 + * @tc.desc Test Dir.isSocket() interface. + */ + it('fileio_test_dirent_is_socket_000', 0, function () { + let dpath = nextFileName('fileio_test_dirent_is_socket_000') + 'd' + let fpath = dpath + '/f1' + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let dd = fileio.Dir.opendirSync(dpath) + expect(dd !== null).assertTrue() + let dirent = dd.readSync() + expect(dirent !== null).assertTrue() + expect(dirent.isSocket()).assertInstanceOf('Boolean') + expect(dd.closeSync()).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + expect(fileio.rmdirSync(dpath)).assertNull() + } catch (e) { + console.log("fileio_test_dirent_is_socket_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Dir_IsSocket_0010 + * @tc.name fileio_test_dirent_is_socket_001 + * @tc.desc Test Dir.isSocket() interface. + */ + it('fileio_test_dirent_is_socket_001', 0, function () { + let dpath = nextFileName('fileio_test_dirent_is_socket_001') + 'd' + let fpath = dpath + '/f1' + let dd + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + dd = fileio.Dir.opendirSync(dpath) + expect(dd !== null).assertTrue() + let dirent = dd.readSync() + expect(dirent !== null).assertTrue() + dirent.isSocket(-1) + expect(null).assertFail() + } catch (e) { + expect(dd.closeSync()).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + expect(fileio.rmdirSync(dpath)).assertNull() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Dir_IsSymbolicLink_0000 + * @tc.name fileio_test_dirent_is_symbolic_link_000 + * @tc.desc Test Dir.isSymbolicLink() interface. + */ + it('fileio_test_dirent_is_symbolic_link_000', 0, function () { + let dpath = nextFileName('fileio_test_dirent_is_symbolic_link_000') + 'd' + let fpath = dpath + '/f1' + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + let dd = fileio.Dir.opendirSync(dpath) + expect(dd !== null).assertTrue() + let dirent = dd.readSync() + expect(dirent !== null).assertTrue() + expect(dirent.isSymbolicLink()).assertInstanceOf('Boolean') + expect(dd.closeSync()).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + expect(fileio.rmdirSync(dpath)).assertNull() + } catch (e) { + console.log("fileio_test_dirent_is_symbolic_link_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Dir_IsSymbolicLink_0010 + * @tc.name fileio_test_dirent_is_symbolic_link_001 + * @tc.desc Test Dir.isSymbolicLink() interface. + */ + it('fileio_test_dirent_is_symbolic_link_001', 0, function () { + let dpath = nextFileName('fileio_test_dirent_is_symbolic_link_001') + 'd' + let fpath = dpath + '/f1' + let dd + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + dd = fileio.Dir.opendirSync(dpath) + expect(dd !== null).assertTrue() + let dirent = dd.readSync() + expect(dirent !== null).assertTrue() + dirent.isSymbolicLink(-1) + expect(null).assertFail() + } catch (e) { + expect(dd.closeSync()).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + expect(fileio.rmdirSync(dpath)).assertNull() + } + }) +}) diff --git a/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIOStat.test.js b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIOStat.test.js new file mode 100755 index 0000000000000000000000000000000000000000..4dd67607d2e89ebacf9de96369e8c2528fb24c52 --- /dev/null +++ b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIOStat.test.js @@ -0,0 +1,749 @@ +/* + * Copyright (C) 2021 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 fileio from '@ohos.fileio' + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' +import { FILE_CONTENT, prepareFile, nextFileName } from './Common' + +describe('fileIOTestStat', function () { + /** + * @tc.number SUB_DF_FileIO_Stat_FstatSync_0000 + * @tc.name fileio_test_stat_fstat_sync_000 + * @tc.desc Test fileio.fstatSync() interface. + */ + it('fileio_test_stat_fstat_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_stat_fstat_sync_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let fd = fileio.openSync(fpath, 0o2) + expect(fd).assertInstanceOf('Number') + let stat = fileio.fstatSync(fd) + expect(stat !== null).assertTrue() + expect(fileio.closeSync(fd)).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_stat_sync_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_FstatSync_0010 + * @tc.name fileio_test_stat_fstat_sync_001 + * @tc.desc Test fstatSync() interface. + */ + it('fileio_test_stat_fstat_sync_001', 0, function () { + try { + let invalidFD = -1 + fileio.fstatSync(invalidFD) + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_StatSync_0000 + * @tc.name fileio_test_stat_stat_sync_000 + * @tc.desc Test Stat.statSync() interface. + */ + it('fileio_test_stat_stat_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_stat_stat_sync_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat !== null).assertTrue() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_stat_sync_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_StatSync_0010 + * @tc.name fileio_test_stat_stat_sync_001 + * @tc.desc Test Stat.statSync() interface. + */ + it('fileio_test_stat_stat_sync_001', 0, function () { + let fpath = nextFileName('fileio_test_stat_stat_sync_001') + + try { + let stat = fileio.Stat.statSync(fpath) + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_Dev_0000 + * @tc.name fileio_test_stat_dev_000 + * @tc.desc Test Stat.dev() interface. + */ + it('fileio_test_stat_dev_000', 0, function () { + let fpath = nextFileName('fileio_test_stat_dev_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.dev).assertInstanceOf('Number') + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_dev_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_Ino_0000 + * @tc.name fileio_test_stat_ino_000 + * @tc.desc Test Stat.ino() interface. + */ + it('fileio_test_stat_ino_000', 0, function () { + let fpath = nextFileName('fileio_test_stat_ino_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.ino).assertInstanceOf('Number') + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_ino_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_Mode_0000 + * @tc.name fileio_test_stat_mode_000 + * @tc.desc Test Stat.mode() interface. + */ + it('fileio_test_stat_mode_000', 0, function () { + let fpath = nextFileName('fileio_test_stat_mode_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.mode).assertInstanceOf('Number') + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_mode_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_Nlink_0000 + * @tc.name fileio_test_stat_nlink_000 + * @tc.desc Test Stat.nlink() interface. + */ + it('fileio_test_stat_nlink_000', 0, function () { + let fpath = nextFileName('fileio_test_stat_nlink_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.nlink).assertInstanceOf('Number') + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_nlink_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_Uid_0000 + * @tc.name fileio_test_stat_uid_000 + * @tc.desc Test Stat.uid() interface. + */ + it('fileio_test_stat_uid_000', 0, function () { + let fpath = nextFileName('fileio_test_stat_uid_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.uid).assertInstanceOf('Number') + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_uid_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_Gid_0000 + * @tc.name fileio_test_stat_gid_000 + * @tc.desc Test Stat.gid() interface. + */ + it('fileio_test_stat_gid_000', 0, function () { + let fpath = nextFileName('fileio_test_stat_gid_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.gid).assertInstanceOf('Number') + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_gid_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_Rdev_0000 + * @tc.name fileio_test_stat_rdev_000 + * @tc.desc Test Stat.rdev() interface. + */ + it('fileio_test_stat_rdev_000', 0, function () { + let fpath = nextFileName('fileio_test_stat_rdev_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.rdev).assertInstanceOf('Number') + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_rdev_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_Size_0000 + * @tc.name fileio_test_stat_size_000 + * @tc.desc Test Stat.size() interface. + */ + it('fileio_test_stat_size_000', 0, function () { + let fpath = nextFileName('fileio_test_stat_size_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.size).assertInstanceOf('Number') + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_size_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_Blocks_0000 + * @tc.name fileio_test_stat_blocks_000 + * @tc.desc Test Stat.blocks() interface. + */ + it('fileio_test_stat_blocks_000', 0, function () { + let fpath = nextFileName('fileio_test_stat_blocks_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.blocks).assertInstanceOf('Number') + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_blocks_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_Atime_0000 + * @tc.name fileio_test_stat_atime_000 + * @tc.desc Test Stat.atime() interface. + */ + it('fileio_test_stat_atime_000', 0, function () { + let fpath = nextFileName('fileio_test_stat_atime_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.atime).assertInstanceOf('Number') + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_atime_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_Mtime_0000 + * @tc.name fileio_test_stat_mtime_000 + * @tc.desc Test Stat.mtime() interface. + */ + it('fileio_test_stat_mtime_000', 0, function () { + let fpath = nextFileName('fileio_test_stat_mtime_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.mtime).assertInstanceOf('Number') + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_mtime_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_Ctime_0000 + * @tc.name fileio_test_stat_ctime_000 + * @tc.desc Test Stat.ctime() interface. + */ + it('fileio_test_stat_ctime_000', 0, function () { + let fpath = nextFileName('fileio_test_stat_ctime_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.ctime).assertInstanceOf('Number') + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_ctime_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsBlockDevice_0000 + * @tc.name fileio_test_stat_is_block_device_000 + * @tc.desc Test Stat.isBlockDevice() interface. + */ + it('fileio_test_stat_is_block_device_000', 0, function () { + let fpath = nextFileName('fileio_test_stat_is_block_device_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.isBlockDevice()).assertInstanceOf('Boolean') + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_is_block_device_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsBlockDevice_0010 + * @tc.name fileio_test_stat_is_block_device_001 + * @tc.desc Test Stat.isBlockDevice() interface. + */ + it('fileio_test_stat_is_block_device_001', 0, function () { + let fpath = nextFileName('fileio_test_stat_is_block_device_001') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.isBlockDevice()).assertFalse() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_is_block_device_001 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsBlockDevice_0020 + * @tc.name fileio_test_stat_is_block_device_002 + * @tc.desc Test Stat.isBlockDevice() interface. + */ + it('fileio_test_stat_is_block_device_002', 0, function () { + let fpath = nextFileName('fileio_test_stat_is_block_device_002') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.isBlockDevice(-1)).assertFalse() + expect(null).assertFail() + } catch (e) { + expect(fileio.unlinkSync(fpath)).assertNull() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsCharacterDevice_0000 + * @tc.name fileio_test_stat_is_character_device_000 + * @tc.desc Test Stat.isCharacterDevice() interface. + */ + it('fileio_test_stat_is_character_device_000', 0, function () { + let fpath = nextFileName('fileio_test_stat_is_character_device_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.isCharacterDevice()).assertInstanceOf('Boolean') + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_is_character_device_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsCharacterDevice_0010 + * @tc.name fileio_test_stat_is_character_device_001 + * @tc.desc Test Stat.isCharacterDevice() interface. + */ + it('fileio_test_stat_is_character_device_001', 0, function () { + let fpath = nextFileName('fileio_test_stat_is_character_device_001') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.isCharacterDevice()).assertFalse() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_is_character_device_001 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsCharacterDevice_0020 + * @tc.name fileio_test_stat_is_character_device_002 + * @tc.desc Test Stat.isCharacterDevice() interface. + */ + it('fileio_test_stat_is_character_device_002', 0, function () { + let fpath = nextFileName('fileio_test_stat_is_character_device_002') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.isCharacterDevice(-1)).assertFalse() + expect(null).assertFail() + } catch (e) { + expect(fileio.unlinkSync(fpath)).assertNull() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsDirectory_0000 + * @tc.name fileio_test_stat_is_directory_000 + * @tc.desc Test Stat.isDirectory() interface. + */ + it('fileio_test_stat_is_directory_000', 0, function () { + let fpath = nextFileName('fileio_test_stat_is_directory_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.isDirectory()).assertInstanceOf('Boolean') + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_is_directory_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsDirectory_0010 + * @tc.name fileio_test_stat_is_directory_001 + * @tc.desc Test Stat.isDirectory() interface. + */ + it('fileio_test_stat_is_directory_001', 0, function () { + let fpath = nextFileName('fileio_test_stat_is_directory_001') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.isDirectory()).assertFalse() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_is_directory_001 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsDirectory_0020 + * @tc.name fileio_test_stat_is_directory_002 + * @tc.desc Test Stat.isDirectory() interface. + */ + it('fileio_test_stat_is_directory_002', 0, function () { + let dpath = nextFileName('fileio_test_stat_is_directory_002') + 'd' + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + let stat = fileio.Stat.statSync(dpath) + expect(stat.isDirectory()).assertTrue() + expect(fileio.rmdirSync(dpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_is_directory_002 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsDirectory_0030 + * @tc.name fileio_test_stat_is_directory_003 + * @tc.desc Test Stat.isDirectory() interface. + */ + it('fileio_test_stat_is_directory_003', 0, function () { + let dpath = nextFileName('fileio_test_stat_is_directory_003') + 'd' + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + let stat = fileio.Stat.statSync(dpath) + expect(stat.isDirectory(-1)).assertTrue() + expect(null).assertFail() + } catch (e) { + expect(fileio.rmdirSync(dpath)).assertNull() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsFIFO_0000 + * @tc.name fileio_test_stat_is_fifo_000 + * @tc.desc Test Stat.isFIFO() interface. + */ + it('fileio_test_stat_is_fifo_000', 0, function () { + let fpath = nextFileName('fileio_test_stat_is_fifo_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.isFIFO()).assertInstanceOf('Boolean') + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_is_fifo_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsFIFO_0010 + * @tc.name fileio_test_stat_is_fifo_001 + * @tc.desc Test Stat.isFIFO() interface. + */ + it('fileio_test_stat_is_fifo_001', 0, function () { + let fpath = nextFileName('fileio_test_stat_is_fifo_001') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.isFIFO()).assertFalse() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_is_fifo_001 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsFIFO_0020 + * @tc.name fileio_test_stat_is_fifo_002 + * @tc.desc Test Stat.isFIFO() interface. + */ + it('fileio_test_stat_is_fifo_002', 0, function () { + let fpath = nextFileName('fileio_test_stat_is_fifo_001') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.isFIFO(-1)).assertFalse() + expect(null).assertFail() + } catch (e) { + expect(fileio.unlinkSync(fpath)).assertNull() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsFILE_0000 + * @tc.name fileio_test_stat_is_file_000 + * @tc.desc Test Stat.isFile() interface. + */ + it('fileio_test_stat_is_file_000', 0, function () { + let fpath = nextFileName('fileio_test_stat_is_file_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertInstanceOf('Boolean') + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.isFile()).assertInstanceOf('Boolean') + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_is_file_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsFILE_0010 + * @tc.name fileio_test_stat_is_file_001 + * @tc.desc Test Stat.isFile() interface. + */ + it('fileio_test_stat_is_file_001', 0, function () { + let fpath = nextFileName('fileio_test_stat_is_file_001') + expect(prepareFile(fpath, FILE_CONTENT)).assertInstanceOf('Boolean') + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.isFile()).assertTrue() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_is_file_001 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsFILE_0020 + * @tc.name fileio_test_stat_is_file_002 + * @tc.desc Test Stat.isFile() interface. + */ + it('fileio_test_stat_is_file_002', 0, function () { + let dpath = nextFileName('fileio_test_stat_is_file_002') + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + let stat = fileio.Stat.statSync(dpath) + expect(stat.isFile()).assertFalse() + expect(fileio.rmdirSync(dpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_is_file_002 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsFILE_0030 + * @tc.name fileio_test_stat_is_file_003 + * @tc.desc Test Stat.isFile() interface. + */ + it('fileio_test_stat_is_file_003', 0, function () { + let dpath = nextFileName('fileio_test_stat_is_file_003') + + try { + expect(fileio.mkdirSync(dpath)).assertNull() + let stat = fileio.Stat.statSync(dpath) + expect(stat.isFile(-1)).assertFalse() + expect(null).assertFail() + } catch (e) { + expect(fileio.rmdirSync(dpath)).assertNull() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsSocket_0000 + * @tc.name fileio_test_stat_is_socket_000 + * @tc.desc Test Stat.isSocket() interface. + */ + it('fileio_test_stat_is_socket_000', 0, function () { + let fpath = nextFileName('fileio_test_stat_is_socket_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.isSocket()).assertInstanceOf('Boolean') + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_is_socket_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsSocket_0010 + * @tc.name fileio_test_stat_is_socket_001 + * @tc.desc Test Stat.isSocket() interface. + */ + it('fileio_test_stat_is_socket_001', 0, function () { + let fpath = nextFileName('fileio_test_stat_is_socket_001') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.isSocket()).assertFalse() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_is_socket_001 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsSocket_0020 + * @tc.name fileio_test_stat_is_socket_002 + * @tc.desc Test Stat.isSocket() interface. + */ + it('fileio_test_stat_is_socket_002', 0, function () { + let fpath = nextFileName('fileio_test_stat_is_socket_002') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.isSocket(-1)).assertFalse() + expect(null).assertFail() + } catch (e) { + expect(fileio.unlinkSync(fpath)).assertNull() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsSymbolicLink_0000 + * @tc.name fileio_test_stat_is_symbolic_link_000 + * @tc.desc Test Stat.isSymbolicLink() interface. + */ + it('fileio_test_stat_is_symbolic_link_000', 0, function () { + let fpath = nextFileName('fileio_test_stat_is_symbolic_link_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.isSymbolicLink()).assertInstanceOf('Boolean') + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_is_symbolic_link_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsSymbolicLink_0010 + * @tc.name fileio_test_stat_is_symbolic_link_001 + * @tc.desc Test Stat.isSymbolicLink() interface. + */ + it('fileio_test_stat_is_symbolic_link_001', 0, function () { + let fpath = nextFileName('fileio_test_stat_is_symbolic_link_001') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.isSymbolicLink()).assertFalse() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stat_is_symbolic_link_001 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stat_IsSymbolicLink_0020 + * @tc.name fileio_test_stat_is_symbolic_link_002 + * @tc.desc Test Stat.isSymbolicLink() interface. + */ + it('fileio_test_stat_is_symbolic_link_002', 0, function () { + let fpath = nextFileName('fileio_test_stat_is_symbolic_link_002') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let stat = fileio.Stat.statSync(fpath) + expect(stat.isSymbolicLink(-1)).assertFalse() + expect(null).assertFail() + } catch (e) { + expect(fileio.unlinkSync(fpath)).assertNull() + } + }) +}) diff --git a/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIOStream.test.js b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIOStream.test.js new file mode 100755 index 0000000000000000000000000000000000000000..174614de1c3e4bb26eb6cb8063e9d06253f48e50 --- /dev/null +++ b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIOStream.test.js @@ -0,0 +1,172 @@ +/* + * Copyright (C) 2021 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 fileio from '@ohos.fileio' + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' +import { FILE_CONTENT, prepareFile, nextFileName } from './Common' + +describe('fileIOTestStream', function () { + /** + * @tc.number SUB_DF_FileIO_Stream_CreateStreamSync_0000 + * @tc.name fileio_test_stream_create_stream_sync_000 + * @tc.desc Test Stream.createStreamSync() interface. + */ + it('fileio_test_stream_create_stream_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_stream_create_stream_sync_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + var ss = fileio.Stream.createStreamSync(fpath, "r+") + expect(ss !== null).assertTrue() + expect(ss.closeSync()).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stream_create_stream_sync_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stream_CreateStreamSync_0010 + * @tc.name fileio_test_stream_create_stream_sync_001 + * @tc.desc Test Stream.createStreamSync() interface. + */ + it('fileio_test_stream_create_stream_sync_001', 0, function () { + let fpath = nextFileName('fileio_test_stream_create_stream_sync_001') + + try { + fileio.Stream.createStreamSync(fpath, "r+") + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stream_CreateStreamSync_0020 + * @tc.name fileio_test_stream_create_stream_sync_002 + * @tc.desc Test Stream.createStreamSync() interface. + */ + it('fileio_test_stream_create_stream_sync_002', 0, function () { + let fpath = nextFileName('fileio_test_stream_create_stream_sync_002') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + fileio.Stream.createStreamSync(fpath, "ohos") + expect(null).assertFail() + } catch (e) { + expect(fileio.unlinkSync(fpath)).assertNull() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stream_FdopenStreamSync_0000 + * @tc.name fileio_test_stream_fdopen_stream_sync_000 + * @tc.desc Test Stream.fdopenStreamSync() interface. + */ + it('fileio_test_stream_fdopen_stream_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_stream_fdopen_stream_sync_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + var fd = fileio.openSync(fpath, 0o2) + let ss = fileio.Stream.fdopenStreamSync(fd, "r+") + expect(ss !== null).assertTrue() + expect(ss.closeSync()).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stream_fdopen_stream_sync_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stream_FdopenStreamSync_0010 + * @tc.name fileio_test_stream_fdopen_stream_sync_001 + * @tc.desc Test Stream.fdopenStreamSync() interface. + */ + it('fileio_test_stream_fdopen_stream_sync_001', 0, function () { + try { + let ss = fileio.Stream.fdopenStreamSync(-1, "r+") + expect(null).assertFail() + } catch (e) { + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stream_ReadSync_0000 + * @tc.name fileio_test_stream_read_sync_000 + * @tc.desc Test Stream.readSync() interface. + */ + it('fileio_test_stream_read_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_stream_read_sync_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let ss = fileio.Stream.createStreamSync(fpath, "r+") + expect(ss !== null).assertTrue() + let len = ss.readSync(new ArrayBuffer(4096)) + expect(len).assertEqual(FILE_CONTENT.length) + expect(ss.closeSync()).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stream_read_sync_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stream_WriteSync_0000 + * @tc.name fileio_test_stream_write_sync_000 + * @tc.desc Test Stream.writeSync() interface. + */ + it('fileio_test_stream_write_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_stream_write_sync_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let ss = fileio.Stream.createStreamSync(fpath, "r+") + expect(ss !== null).assertTrue() + expect(ss.writeSync(FILE_CONTENT)).assertEqual(FILE_CONTENT.length) + expect(ss.closeSync()).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stream_write_sync_000 has failed for " + e) + expect(null).assertFail() + } + }) + + /** + * @tc.number SUB_DF_FileIO_Stream_FlushSync_0000 + * @tc.name fileio_test_stream_flush_sync_000 + * @tc.desc Test Stream.flushSync() interface. + */ + it('fileio_test_stream_flush_sync_000', 0, function () { + let fpath = nextFileName('fileio_test_stream_flush_sync_000') + expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() + + try { + let ss = fileio.Stream.createStreamSync(fpath, "r+") + expect(ss !== null).assertTrue() + expect(ss.writeSync(FILE_CONTENT)).assertEqual(FILE_CONTENT.length) + expect(ss.flushSync()).assertNull() + expect(ss.closeSync()).assertNull() + expect(fileio.unlinkSync(fpath)).assertNull() + } catch (e) { + console.log("fileio_test_stream_flush_sync_000 has failed for " + e) + expect(null).assertFail() + } + }) +}) \ No newline at end of file diff --git a/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/List.test.js b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..a0313e7c9a62553512b1cd73364c0a41af37714c --- /dev/null +++ b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/List.test.js @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2021 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. + */ + +require('./FileIO.test.js') +require('./FileIODir.test.js') +require('./FileIODirent.test.js') +require('./FileIOStat.test.js') +require('./FileIOStream.test.js') \ No newline at end of file diff --git a/distributeddatamgr/distributedfilejstest/project/entry/src/main/resources/base/element/string.json b/distributeddatamgr/distributedfilejstest/project/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e270bb102c245b6f217a8589954021d89cd9059b --- /dev/null +++ b/distributeddatamgr/distributedfilejstest/project/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "DistributedFileJSTest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/distributeddatamgr/distributedfilejstest/project/entry/src/main/resources/base/media/icon.png b/distributeddatamgr/distributedfilejstest/project/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/distributedfilejstest/project/entry/src/main/resources/base/media/icon.png differ diff --git a/figures/icon-caution.gif b/figures/icon-caution.gif new file mode 100755 index 0000000000000000000000000000000000000000..6e90d7cfc2193e39e10bb58c38d01a23f045d571 Binary files /dev/null and b/figures/icon-caution.gif differ diff --git a/figures/icon-danger.gif b/figures/icon-danger.gif new file mode 100755 index 0000000000000000000000000000000000000000..6e90d7cfc2193e39e10bb58c38d01a23f045d571 Binary files /dev/null and b/figures/icon-danger.gif differ diff --git a/figures/icon-note.gif b/figures/icon-note.gif new file mode 100755 index 0000000000000000000000000000000000000000..6314297e45c1de184204098efd4814d6dc8b1cda Binary files /dev/null and b/figures/icon-note.gif differ diff --git a/figures/icon-notice.gif b/figures/icon-notice.gif new file mode 100755 index 0000000000000000000000000000000000000000..86024f61b691400bea99e5b1f506d9d9aef36e27 Binary files /dev/null and b/figures/icon-notice.gif differ diff --git a/figures/icon-tip.gif b/figures/icon-tip.gif new file mode 100755 index 0000000000000000000000000000000000000000..93aa72053b510e456b149f36a0972703ea9999b7 Binary files /dev/null and b/figures/icon-tip.gif differ diff --git a/figures/icon-warning.gif b/figures/icon-warning.gif new file mode 100755 index 0000000000000000000000000000000000000000..6e90d7cfc2193e39e10bb58c38d01a23f045d571 Binary files /dev/null and b/figures/icon-warning.gif differ diff --git a/global/BUILD.gn b/global/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..47672c0b9de1438767133ebd6628238aa12b1374 --- /dev/null +++ b/global/BUILD.gn @@ -0,0 +1,31 @@ +# Copyright (C) 2021 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("//build/ohos_var.gni") + +group("global") { + testonly = true + if (is_standard_system) { + deps = [ + "i18n_standard/intljs:intljs_test", + "i18n_standard/zone/src:ZoneUtiltest", + "resmgr_standard/resmgrjs:resmgrjs_test", + ] + } else { + deps = [ + "i18n:i18n_test_hap", + "icu:icu_test_hap", + "resmgr:resmgr_test_hap", + ] + } +} diff --git a/global/i18n_standard/intljs/BUILD.gn b/global/i18n_standard/intljs/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..e72ce2dc8e2be6aeaac9f260776c36c07a861ec5 --- /dev/null +++ b/global/i18n_standard/intljs/BUILD.gn @@ -0,0 +1,19 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("intljs_test") { + test_hap_name = "IntlJsTest" + hap_source_path = "hap/entry-debug-rich-signed.hap" +} diff --git a/global/i18n_standard/intljs/Test.json b/global/i18n_standard/intljs/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..b6390d227479082c4bee8802581eaa7d70076004 --- /dev/null +++ b/global/i18n_standard/intljs/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for intljs Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "21600000", + "package": "ohos.intl.test", + "shell-timeout": "21600000" + }, + "kits": [ + { + "test-file-name": [ + "IntlJsTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/global/i18n_standard/intljs/hap/entry-debug-rich-signed.hap b/global/i18n_standard/intljs/hap/entry-debug-rich-signed.hap new file mode 100755 index 0000000000000000000000000000000000000000..f00342864475d6f97fb5ff98ec4b79d671870b8b Binary files /dev/null and b/global/i18n_standard/intljs/hap/entry-debug-rich-signed.hap differ diff --git a/global/i18n_standard/intljs/project/.gitignore b/global/i18n_standard/intljs/project/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..ebdd23d29a08bffe35d1c4f0a21b058393fd9dba --- /dev/null +++ b/global/i18n_standard/intljs/project/.gitignore @@ -0,0 +1,14 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx diff --git a/global/i18n_standard/intljs/project/entry/.gitignore b/global/i18n_standard/intljs/project/entry/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..3543521e9fef8e7322940a87c2b45dd0061b0f45 --- /dev/null +++ b/global/i18n_standard/intljs/project/entry/.gitignore @@ -0,0 +1 @@ +/build diff --git a/global/i18n_standard/intljs/project/entry/package.json b/global/i18n_standard/intljs/project/entry/package.json new file mode 100755 index 0000000000000000000000000000000000000000..69a88e3b65423624fe7ea8b0f8beefcc62cc3d5f --- /dev/null +++ b/global/i18n_standard/intljs/project/entry/package.json @@ -0,0 +1 @@ +{} diff --git a/global/i18n_standard/intljs/project/entry/src/main/config.json b/global/i18n_standard/intljs/project/entry/src/main/config.json new file mode 100755 index 0000000000000000000000000000000000000000..93b41af1b5ab444551db8a1fa7c535f2d6e3eced --- /dev/null +++ b/global/i18n_standard/intljs/project/entry/src/main/config.json @@ -0,0 +1,59 @@ +{ + "app": { + "bundleName": "ohos.intl.test", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 4 + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.intl.test", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "ohos.intl.test.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "MyApplication", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} diff --git a/global/i18n_standard/intljs/project/entry/src/main/js/default/app.js b/global/i18n_standard/intljs/project/entry/src/main/js/default/app.js new file mode 100755 index 0000000000000000000000000000000000000000..044bffa75e29d7a5fe32644e19cc1bbbc5e9a7b1 --- /dev/null +++ b/global/i18n_standard/intljs/project/entry/src/main/js/default/app.js @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2021 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 default { + onCreate() { + console.info('TestApplication onCreate'); + }, + onDestroy() { + console.info('TestApplication onDestroy'); + } +}; diff --git a/global/i18n_standard/intljs/project/entry/src/main/js/default/i18n/en-US.json b/global/i18n_standard/intljs/project/entry/src/main/js/default/i18n/en-US.json new file mode 100755 index 0000000000000000000000000000000000000000..55561b83737c3c31d082fbfa11e5fc987a351104 --- /dev/null +++ b/global/i18n_standard/intljs/project/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/global/i18n_standard/intljs/project/entry/src/main/js/default/i18n/zh-CN.json b/global/i18n_standard/intljs/project/entry/src/main/js/default/i18n/zh-CN.json new file mode 100755 index 0000000000000000000000000000000000000000..cce1af06761a42add0cac1a0567aa3237eda8cb4 --- /dev/null +++ b/global/i18n_standard/intljs/project/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/global/i18n_standard/intljs/project/entry/src/main/js/default/pages/index/index.css b/global/i18n_standard/intljs/project/entry/src/main/js/default/pages/index/index.css new file mode 100755 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/global/i18n_standard/intljs/project/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/global/i18n_standard/intljs/project/entry/src/main/js/default/pages/index/index.hml b/global/i18n_standard/intljs/project/entry/src/main/js/default/pages/index/index.hml new file mode 100755 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/global/i18n_standard/intljs/project/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/global/i18n_standard/intljs/project/entry/src/main/js/default/pages/index/index.js b/global/i18n_standard/intljs/project/entry/src/main/js/default/pages/index/index.js new file mode 100755 index 0000000000000000000000000000000000000000..99b0dfa952b02336bdc6f5c4cdec7c383ddd250b --- /dev/null +++ b/global/i18n_standard/intljs/project/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2021 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 file from '@system.file' +import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + const reportExtend = new ReportExtend(file) + core.addService('expect', expectExtend) + core.addService('report', reportExtend) + core.init() + + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../../test/List.test') + core.execute() + + }, + onReady() { + }, +} \ No newline at end of file diff --git a/global/i18n_standard/intljs/project/entry/src/main/js/test/I18n.test.js b/global/i18n_standard/intljs/project/entry/src/main/js/test/I18n.test.js new file mode 100755 index 0000000000000000000000000000000000000000..affd08df08afc846dd05e82702e4ea8e9e46ab18 --- /dev/null +++ b/global/i18n_standard/intljs/project/entry/src/main/js/test/I18n.test.js @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2021 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 Intl from "@ohos.intl" +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('intlTest', function () { + console.log("*************00000000000000000000000*************"); + + /* * + * @tc.number SUB_GLOBAL_I18N_JS_0100 + * @tc.name format the language in locale + * @tc.desc check the language + */ + it('locale_test_001', 0, function () { + var locale = new Intl.Locale("en-Latn-GB"); + console.log("jessie " + locale.language); + expect(locale.language).assertEqual("en"); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_JS_0200 + * @tc.name format the script in locale + * @tc.desc check the script + */ + it('locale_test_002', 0, function () { + var locale = new Intl.Locale("en-Latn-GB"); + console.log("jessie " + locale.script); + expect(locale.script).assertEqual("Latn"); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_JS_0300 + * @tc.name format the region in locale + * @tc.desc check the region + */ + it('locale_test_003', 0, function () { + var locale = new Intl.Locale("en-Latn-GB"); + console.log("jessie " + locale.region); + expect(locale.region).assertEqual("GB"); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_JS_0400 + * @tc.name format the basename in locale + * @tc.desc check the basename + */ + it('locale_test_004', 0, function () { + var locale = new Intl.Locale("en-Latn-GB"); + console.log("jessie " + locale.baseName); + expect(locale.baseName).assertEqual("en-Latn-GB"); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_JS_0500 + * @tc.name format the datetime with en-GB locale + * @tc.desc check the datetime is not null + */ + it('dateTimeFormat_test_001', 0, function () { + var datefmt = new Intl.DateTimeFormat("en-GB"); + expect(datefmt != null).assertTrue(); + }) + + /* * + * @tc.number SUB_GLOBAL_I18N_JS_0600 + * @tc.name format the date with en-GB locale + * @tc.desc check the date + */ + it('formatDateTimeFormat_test_001', 0, function () { + var date = new Date(2021, 11, 17, 3, 24, 0); + var datefmt = new Intl.DateTimeFormat("en-GB"); + expect(datefmt.format(date)).assertEqual('17 Dec 2021'); + }) + console.log("*************00000000000000000000000*************"); +}) \ No newline at end of file diff --git a/global/i18n_standard/intljs/project/entry/src/main/js/test/List.test.js b/global/i18n_standard/intljs/project/entry/src/main/js/test/List.test.js new file mode 100755 index 0000000000000000000000000000000000000000..1b82a01ce4c1af2812b7a7413455ef95e4e589b9 --- /dev/null +++ b/global/i18n_standard/intljs/project/entry/src/main/js/test/List.test.js @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2021 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. + */ +require('./I18n.test.js') \ No newline at end of file diff --git a/global/i18n_standard/intljs/project/entry/src/main/resources/base/element/string.json b/global/i18n_standard/intljs/project/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..fac1f3a7cbdd54561048bb8e4211abd3340efe97 --- /dev/null +++ b/global/i18n_standard/intljs/project/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "L2Test" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/global/i18n_standard/intljs/project/entry/src/main/resources/base/media/icon.png b/global/i18n_standard/intljs/project/entry/src/main/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/global/i18n_standard/intljs/project/entry/src/main/resources/base/media/icon.png differ diff --git a/global/i18n_standard/intljs/project/gradle.properties b/global/i18n_standard/intljs/project/gradle.properties new file mode 100755 index 0000000000000000000000000000000000000000..c555b4e6a519b939a3e954391a3f0772335ad7cf --- /dev/null +++ b/global/i18n_standard/intljs/project/gradle.properties @@ -0,0 +1,10 @@ +# Project-wide Gradle settings. +# IDE (e.g. DevEco Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# If the Chinese output is garbled, please configure the following parameter. +# org.gradle.jvmargs=-Dfile.encoding=GBK diff --git a/global/i18n_standard/intljs/project/settings.gradle b/global/i18n_standard/intljs/project/settings.gradle new file mode 100755 index 0000000000000000000000000000000000000000..28d595f2fba0d06b2025da200383d15f87c4e9f0 --- /dev/null +++ b/global/i18n_standard/intljs/project/settings.gradle @@ -0,0 +1 @@ +include ':entry' diff --git a/global/i18n_standard/zone/src/BUILD.gn b/global/i18n_standard/zone/src/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..2d372966c3b019c590f2a7af27d12304096e4986 --- /dev/null +++ b/global/i18n_standard/zone/src/BUILD.gn @@ -0,0 +1,56 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +#SUBSYSTEM_DIR = "//base/global" +module_output_path = "hit/global" + +ohos_moduletest_suite("ZoneUtiltest") { + module_out_path = module_output_path + + sources = [ + "//third_party/googletest/googletest/src/gtest-death-test.cc", + "//third_party/googletest/googletest/src/gtest-filepath.cc", + "//third_party/googletest/googletest/src/gtest-port.cc", + "//third_party/googletest/googletest/src/gtest-printers.cc", + "//third_party/googletest/googletest/src/gtest-test-part.cc", + "//third_party/googletest/googletest/src/gtest-typed-test.cc", + "//third_party/googletest/googletest/src/gtest.cc", + "//third_party/googletest/googletest/src/gtest_main.cc", + "//third_party/googletest/googletest/src/hwext/gtest-ext.cc", + "//third_party/googletest/googletest/src/hwext/gtest-filter.cc", + "//third_party/googletest/googletest/src/hwext/gtest-tag.cc", + "//third_party/googletest/googletest/src/hwext/gtest-utils.cc", + "zone_util_test.cpp", + ] + + remove_configs = [ "//build/config/compiler:no_rtti" ] + cflags_cc = [ "-frtti" ] + include_dirs = [ + "//third_party/googletest/googletest/include", + "//third_party/googletest/googletest", + "//base/global/i18n_standard/interfaces/native/innerkits/zone/include", + "//third_party/icu/icu4c/source/common/unicode", + "//third_party/icu/icu4c/source/common", + "//third_party/libphonenumber/cpp/src", + "//third_party/protobuf/src", + "//third_party/protobuf/src/google", + "//third_party/protobuf/src/google/protobuf", + ] + deps = [ + "//base/global/i18n_standard/frameworks/zone:zone_util", + "//third_party/libphonenumber/cpp:phonenumber_standard", + "//utils/native/base:utils", + ] +} diff --git a/global/i18n_standard/zone/src/Test.json b/global/i18n_standard/zone/src/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..cf093bb1027a42f84d196b29e5e0b03a01e10671 --- /dev/null +++ b/global/i18n_standard/zone/src/Test.json @@ -0,0 +1,21 @@ +{ + "kits": [ + { + "push": [ + "ZoneUtiltest->/data/local/tmp/ZoneUtiltest" + ], + "type": "PushKit", + "post-push": [ + "chmod -R 777 /data/local/tmp/*" + ] + } + ], + "driver": { + "native-test-timeout": "120000", + "type": "CppTest", + "module-name": "ZoneUtiltest", + "runtime-hint": "1s", + "native-test-device-path": "/data/local/tmp" + }, + "description": "Configuration for ZoneUtiltest Tests" +} \ No newline at end of file diff --git a/global/i18n_standard/zone/src/zone_util_test.cpp b/global/i18n_standard/zone/src/zone_util_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..b253b5780174921e4e91a8352ae18df09e5c4f60 --- /dev/null +++ b/global/i18n_standard/zone/src/zone_util_test.cpp @@ -0,0 +1,443 @@ +/* + * Copyright (C) 2021 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. + */ + +#include + +#include "zone_util_test.h" +#include "zone_util.h" + +namespace OHOS { +using namespace std; +using namespace testing; +using namespace testing::ext; +using namespace OHOS::Global::I18n; + +class ZoneUtilTest : public testing::Test {}; + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETDEFAULTZONE_ONEPARAM_0100 + * @tc.name the input country code have multiple timezones + * @tc.desc Test GetDefaultZone(country) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetDefaultZoneTest0100, Function | MediumTest | Level3) +{ + string expects[] = { "Antarctica/McMurdo", "America/Argentina/Buenos_Aires", "Australia/Sydney", "America/Noronha", + "America/St_Johns", "Africa/Kinshasa", "America/Santiago", "Asia/Shanghai", "Asia/Nicosia", "Europe/Berlin", + "America/Guayaquil", "Europe/Madrid", "Pacific/Pohnpei", "America/Godthab", "Asia/Jakarta", "Pacific/Tarawa", + "Asia/Almaty", "Pacific/Majuro", "Asia/Ulaanbaatar", "America/Mexico_City", "Asia/Kuala_Lumpur", "Pacific/Auckland", + "Pacific/Tahiti", "Pacific/Port_Moresby", "Asia/Gaza", "Europe/Lisbon", "Europe/Moscow", "Europe/Kiev", + "Pacific/Wake", "America/New_York", "Asia/Tashkent" }; + string countries[] = { "AQ", "AR", "AU", "BR", "CA", "CD", "CL", "CN", "CY", "DE", "EC", "ES", "FM", "GL", "ID", + "KI", "KZ", "MH", "MN", "MX", "MY", "NZ", "PF", "PG", "PS", "PT", "RU", "UA", "UM", "US", "UZ" }; + int count = size(expects); + ZoneUtil util; + for (int i = 0; i < count; ++i) { + string out = util.GetDefaultZone(countries[i].c_str()); + EXPECT_EQ(out, expects[i]); + } +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETDEFAULTZONE_ONEPARAM_0200 + * @tc.name the input country code have one timezone + * @tc.desc Test GetDefaultZone(country) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetDefaultZoneTest0200, Function | MediumTest | Level1) +{ + string expects[] = { "Asia/Kabul", "Europe/Sarajevo", "Africa/Abidjan", "Africa/Lusaka" }; + string countries[] = { "AF", "BA", "CI", "ZM" }; + int count = size(expects); + ZoneUtil util; + for (int i = 0; i < count; ++i) { + string out = util.GetDefaultZone(countries[i].c_str()); + EXPECT_EQ(out, expects[i]); + } +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETDEFAULTZONE_ONEPARAM_0300 + * @tc.name the input country code is lowercase style + * @tc.desc Test GetDefaultZone(country) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetDefaultZoneTest0300, Function | MediumTest | Level3) +{ + string expects[] = { "Asia/Shanghai", "America/New_York" }; + string countries[] = { "cn", "us" }; + int count = size(countries); + ZoneUtil util; + for (int i = 0; i < count; ++i) { + string out = util.GetDefaultZone(countries[i].c_str()); + EXPECT_EQ(out, expects[i]); + } +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETDEFAULTZONE_ONEPARAM_0400 + * @tc.name the input country code not exist + * @tc.desc Test GetDefaultZone(country) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetDefaultZoneTest0400, Function | MediumTest | Level3) +{ + ZoneUtil util; + string out = util.GetDefaultZone("AAA"); + EXPECT_EQ(out, ""); +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETDEFAULTZONE_ONEPARAM_0500 + * @tc.name the input country code is number + * @tc.desc Test GetDefaultZone(country) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetDefaultZoneTest0500, Function | MediumTest | Level3) +{ + ZoneUtil util; + string out = util.GetDefaultZone("123"); + EXPECT_EQ(out, ""); +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETDEFAULTZONE_ONEPARAM_0600 + * @tc.name the input country code is null + * @tc.desc Test GetDefaultZone(country) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetDefaultZoneTest0600, Function | MediumTest | Level4) +{ + ZoneUtil util; + string out = util.GetDefaultZone(""); + EXPECT_EQ(out, ""); +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETDEFAULTZONE_TWOPARAM_0100 + * @tc.name the input country code have multiple timezones,the offerset matches one timezone + * @tc.desc Test GetDefaultZone(country, offset) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetDefaultZone2Test0100, Function | MediumTest | Level3) +{ + string expects[] = { "Asia/Shanghai", "America/Detroit" }; + int32_t offsets[] = { 3600 * 1000 * 8, -3600 * 1000 * 5 }; + string countries[] = { "CN", "US" }; + int count = size(expects); + ZoneUtil util; + for (int i = 0; i < count; ++i) { + string out = util.GetDefaultZone(countries[i].c_str(), offsets[i]); + EXPECT_EQ(out, expects[i]); + } +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETDEFAULTZONE_TWOPARAM_0200 + * @tc.name the input country code have multiple timezones,the offerset not matches anyone timezone + * @tc.desc Test GetDefaultZone(country, offset) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetDefaultZone2Test0200, Function | MediumTest | Level3) +{ + int32_t offsets[] = { 3600 * 1000 * 1, -3600 * 1000 * 1 }; + string countries[] = { "CN", "US" }; + int count = size(countries); + ZoneUtil util; + for (int i = 0; i < count; ++i) { + string out = util.GetDefaultZone(countries[i].c_str(), offsets[i]); + EXPECT_EQ(out, ""); + } +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETDEFAULTZONE_TWOPARAM_0300 + * @tc.name the input country code have one timezone,the offerset matches it + * @tc.desc Test GetDefaultZone(country, offset) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetDefaultZone2Test0300, Function | MediumTest | Level1) +{ + ZoneUtil util; + string out = util.GetDefaultZone("AF", 3600 * 1000 * 4.5); + EXPECT_EQ(out, "Asia/Kabul"); +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETDEFAULTZONE_TWOPARAM_0400 + * @tc.name the input country code have one timezone,the offerset not matches it + * @tc.desc Test GetDefaultZone(country, offset) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetDefaultZone2Test0400, Function | MediumTest | Level3) +{ + ZoneUtil util; + string out = util.GetDefaultZone("AF", 3600 * 1000 * 1); + EXPECT_EQ(out, ""); +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETDEFAULTZONE_TWOPARAM_0500 + * @tc.name the input country code not exist with offset param in getDefaultZone + * @tc.desc Test GetDefaultZone(country, offset) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetDefaultZone2Test0500, Function | MediumTest | Level3) +{ + ZoneUtil util; + string out = util.GetDefaultZone("AAA", 3600 * 1000 * 8); + EXPECT_EQ(out, ""); +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETDEFAULTZONE_TWOPARAM_0600 + * @tc.name the input country code is number with offset param in getDefaultZone + * @tc.desc Test GetDefaultZone(country, offset) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetDefaultZone2Test0600, Function | MediumTest | Level3) +{ + ZoneUtil util; + string out = util.GetDefaultZone("123", 3600 * 1000 * 8); + EXPECT_EQ(out, ""); +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETDEFAULTZONE_TWOPARAM_0700 + * @tc.name the input country code is null with offset param in getDefaultZone + * @tc.desc Test GetDefaultZone(country, offset) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetDefaultZone2Test0700, Function | MediumTest | Level3) +{ + ZoneUtil util; + string out = util.GetDefaultZone("", 3600 * 1000 * 8); + EXPECT_EQ(out, ""); +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETZONELIST_TWOPARAM_0100 + * @tc.name the input country code have multiple timezones in getZoneList + * @tc.desc Test GetDefaultZone(country, offset) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetZoneListTest0100, Function | MediumTest | Level3) +{ + vector expects = { "Asia/Shanghai", "Asia/Urumqi" }; + string country = "CN"; + vector out; + ZoneUtil util; + util.GetZoneList(country, out); + EXPECT_EQ(expects.size(), out.size()); + if (expects.size() == out.size()) { + for (decltype(expects.size()) i = 0; i < expects.size(); ++i) { + EXPECT_EQ(expects[i], out[i]); + } + } +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETZONELIST_TWOPARAM_0200 + * @tc.name the input country code have one timezone in getZoneList + * @tc.desc Test GetDefaultZone(country, offset) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetZoneListTest0200, Function | MediumTest | Level1) +{ + vector expects = { "Asia/Kabul" }; + string country = "AF"; + vector out; + ZoneUtil util; + util.GetZoneList(country, out); + EXPECT_EQ(expects.size(), out.size()); + if (expects.size() == out.size()) { + for (decltype(expects.size()) i = 0; i < expects.size(); ++i) { + EXPECT_EQ(expects[i], out[i]); + } + } +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETZONELIST_TWOPARAM_0300 + * @tc.name the input country code not exist in getZoneList + * @tc.desc Test GetDefaultZone(country, offset) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetZoneListTest0300, Function | MediumTest | Level3) +{ + string country = "AAA"; + vector out; + ZoneUtil util; + util.GetZoneList(country, out); + size_t expect = 0; + EXPECT_EQ(expect, out.size()); +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETZONELIST_TWOPARAM_0400 + * @tc.name the input country code is number in getZoneList + * @tc.desc Test GetDefaultZone(country, offset) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetZoneListTest0400, Function | MediumTest | Level3) +{ + string country = "123"; + vector out; + ZoneUtil util; + util.GetZoneList(country, out); + size_t expect = 0; + EXPECT_EQ(expect, out.size()); +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETZONELIST_TWOPARAM_0500 + * @tc.name the input country code is null in getZoneList + * @tc.desc Test GetDefaultZone(country, offset) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetZoneListTest0500, Function | MediumTest | Level3) +{ + string country = ""; + vector out; + ZoneUtil util; + util.GetZoneList(country, out); + size_t expect = 0; + EXPECT_EQ(expect, out.size()); +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETZONELIST_THREEPARAM_0100 + * @tc.name the input country code have multiple timezones with three params in getZoneList ,the offset matches one + * timezone + * @tc.desc Test GetDefaultZone(country, offset) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetZoneList2Test0100, Function | MediumTest | Level3) +{ + vector expects = { "Asia/Shanghai" }; + string country = "CN"; + vector out; + ZoneUtil util; + util.GetZoneList(country, 3600 * 1000 * 8, out); + EXPECT_EQ(expects.size(), out.size()); + if (expects.size() == out.size()) { + for (decltype(expects.size()) i = 0; i < expects.size(); ++i) { + EXPECT_EQ(expects[i], out[i]); + } + } +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETZONELIST_THREEPARAM_0200 + * @tc.name the input country code have multiple timezones with three params in getZoneList ,the offset not matches + * anyone timezone + * @tc.desc Test GetDefaultZone(country, offset) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetZoneList2Test0200, Function | MediumTest | Level3) +{ + string country = "CN"; + vector out; + ZoneUtil util; + util.GetZoneList(country, 3600 * 1000 * 1, out); + size_t expect = 0; + EXPECT_EQ(expect, out.size()); +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETZONELIST_THREEPARAM_0300 + * @tc.name the input country code have one timezone with three params in getZoneList ,the offset matches + * @tc.desc Test GetDefaultZone(country, offset) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetZoneList2Test0300, Function | MediumTest | Level3) +{ + vector expects = { "Europe/London" }; + string country = "GB"; + vector out; + ZoneUtil util; + util.GetZoneList(country, 3600 * 1000 * 1, out); + EXPECT_EQ(expects.size(), out.size()); + if (expects.size() == out.size()) { + for (decltype(expects.size()) i = 0; i < expects.size(); ++i) { + EXPECT_EQ(expects[i], out[i]); + } + } +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETZONELIST_THREEPARAM_0400 + * @tc.name the input country code have one timezone with three params in getZoneList ,the offset not match + * @tc.desc Test GetDefaultZone(country, offset) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetZoneList2Test0400, Function | MediumTest | Level3) +{ + string country = "GB"; + vector out; + ZoneUtil util; + util.GetZoneList(country, 3600 * 1000 * 5, out); + size_t expect = 0; + EXPECT_EQ(expect, out.size()); +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETZONELIST_THREEPARAM_0500 + * @tc.name the input country code not exist with three params in getZoneList + * @tc.desc Test GetDefaultZone(country, offset) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetZoneList2Test0500, Function | MediumTest | Level3) +{ + string country = "GGG"; + vector out; + ZoneUtil util; + util.GetZoneList(country, 3600 * 1000 * 5, out); + size_t expect = 0; + EXPECT_EQ(expect, out.size()); +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETZONELIST_THREEPARAM_0600 + * @tc.name the input country code is number with three params in getZoneList + * @tc.desc Test GetDefaultZone(country, offset) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetZoneList2Test0600, Function | MediumTest | Level3) +{ + string country = "123"; + vector out; + ZoneUtil util; + util.GetZoneList(country, 3600 * 1000 * 5, out); + size_t expect = 0; + EXPECT_EQ(expect, out.size()); +} + +/* * + * @tc.number SUB_GLOBAL_I18N_TIMEZONE_GETZONELIST_THREEPARAM_0700 + * @tc.name the input country code is null with three params in getZoneList + * @tc.desc Test GetDefaultZone(country, offset) function. + * @tc.require SR000FK13G + */ +HWTEST_F(ZoneUtilTest, GetZoneList2Test0700, Function | MediumTest | Level3) +{ + string country = ""; + vector out; + ZoneUtil util; + util.GetZoneList(country, 3600 * 1000 * 5, out); + size_t expect = 0; + EXPECT_EQ(expect, out.size()); +} +} diff --git a/global/i18n_standard/zone/src/zone_util_test.h b/global/i18n_standard/zone/src/zone_util_test.h new file mode 100755 index 0000000000000000000000000000000000000000..b94721c9e0068b78847c48e1b8c0ed9c6db5a216 --- /dev/null +++ b/global/i18n_standard/zone/src/zone_util_test.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2021 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. + */ + +#ifndef OHOS_GLOBAL_I18N_ZONE_UTIL_TEST_H +#define OHOS_GLOBAL_I18N_ZONE_UTIL_TEST_H + +int GetDefaultZoneTest0100(); +int GetDefaultZoneTest0200(); +int GetDefaultZoneTest0300(); +int GetDefaultZoneTest0400(); +int GetDefaultZoneTest0500(); +int GetDefaultZoneTest0600(); +int GetDefaultZone2Test0100(); +int GetDefaultZone2Test0200(); +int GetDefaultZone2Test0300(); +int GetDefaultZone2Test0400(); +int GetDefaultZone2Test0500(); +int GetDefaultZone2Test0600(); +int GetDefaultZone2Test0700(); +int GetZoneListTest0100(); +int GetZoneListTest0200(); +int GetZoneListTest0300(); +int GetZoneListTest0400(); +int GetZoneListTest0500(); +int GetZoneList2Test0100(); +int GetZoneList2Test0200(); +int GetZoneList2Test0300(); +int GetZoneList2Test0400(); +int GetZoneList2Test0500(); +int GetZoneList2Test0600(); +int GetZoneList2Test0700(); + +#endif diff --git a/global/resmgr_standard/resmgrjs/BUILD.gn b/global/resmgr_standard/resmgrjs/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..e1eda731c1aa14553af8bbc900f886652a42e984 --- /dev/null +++ b/global/resmgr_standard/resmgrjs/BUILD.gn @@ -0,0 +1,19 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("resmgrjs_test") { + test_hap_name = "resmgrjs" + hap_source_path = "hap/entry-debug-signed.hap" +} diff --git a/global/resmgr_standard/resmgrjs/Test.json b/global/resmgr_standard/resmgrjs/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..fe3d2203158fa922495741c6b1af23c5ab27bd58 --- /dev/null +++ b/global/resmgr_standard/resmgrjs/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for resmgrjs Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "21600000", + "package": "ohos.resmgr.test", + "shell-timeout": "21600000" + }, + "kits": [ + { + "test-file-name": [ + "resmgrjs.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/global/resmgr_standard/resmgrjs/hap/entry-debug-signed.hap b/global/resmgr_standard/resmgrjs/hap/entry-debug-signed.hap new file mode 100755 index 0000000000000000000000000000000000000000..f4c080fefc0ad5c3cd3d285722498e0d0552471c Binary files /dev/null and b/global/resmgr_standard/resmgrjs/hap/entry-debug-signed.hap differ diff --git a/global/resmgr_standard/resmgrjs/project/.gitignore b/global/resmgr_standard/resmgrjs/project/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..ebdd23d29a08bffe35d1c4f0a21b058393fd9dba --- /dev/null +++ b/global/resmgr_standard/resmgrjs/project/.gitignore @@ -0,0 +1,14 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx diff --git a/global/resmgr_standard/resmgrjs/project/entry/.gitignore b/global/resmgr_standard/resmgrjs/project/entry/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..3543521e9fef8e7322940a87c2b45dd0061b0f45 --- /dev/null +++ b/global/resmgr_standard/resmgrjs/project/entry/.gitignore @@ -0,0 +1 @@ +/build diff --git a/global/resmgr_standard/resmgrjs/project/entry/package.json b/global/resmgr_standard/resmgrjs/project/entry/package.json new file mode 100755 index 0000000000000000000000000000000000000000..69a88e3b65423624fe7ea8b0f8beefcc62cc3d5f --- /dev/null +++ b/global/resmgr_standard/resmgrjs/project/entry/package.json @@ -0,0 +1 @@ +{} diff --git a/global/resmgr_standard/resmgrjs/project/entry/src/main/config.json b/global/resmgr_standard/resmgrjs/project/entry/src/main/config.json new file mode 100755 index 0000000000000000000000000000000000000000..1f9574bd20043477910909860e163fd117b0ed3b --- /dev/null +++ b/global/resmgr_standard/resmgrjs/project/entry/src/main/config.json @@ -0,0 +1,59 @@ +{ + "app": { + "bundleName": "ohos.resmgr.test", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 4 + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.resmgr.test", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "ohos.resmgr.test.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "MyApplication", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} diff --git a/global/resmgr_standard/resmgrjs/project/entry/src/main/js/default/app.js b/global/resmgr_standard/resmgrjs/project/entry/src/main/js/default/app.js new file mode 100755 index 0000000000000000000000000000000000000000..298a2b862eda6d614cecca0a1647a78434ab8327 --- /dev/null +++ b/global/resmgr_standard/resmgrjs/project/entry/src/main/js/default/app.js @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2021 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 device from '@system.device'; + +export default { + onCreate() { + console.info('TestApplication onCreate'); + }, + onDestroy() { + console.info('TestApplication onDestroy'); + } +}; diff --git a/global/resmgr_standard/resmgrjs/project/entry/src/main/js/default/i18n/en-US.json b/global/resmgr_standard/resmgrjs/project/entry/src/main/js/default/i18n/en-US.json new file mode 100755 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/global/resmgr_standard/resmgrjs/project/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/global/resmgr_standard/resmgrjs/project/entry/src/main/js/default/i18n/zh-CN.json b/global/resmgr_standard/resmgrjs/project/entry/src/main/js/default/i18n/zh-CN.json new file mode 100755 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/global/resmgr_standard/resmgrjs/project/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/global/resmgr_standard/resmgrjs/project/entry/src/main/js/default/pages/index/index.css b/global/resmgr_standard/resmgrjs/project/entry/src/main/js/default/pages/index/index.css new file mode 100755 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/global/resmgr_standard/resmgrjs/project/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/global/resmgr_standard/resmgrjs/project/entry/src/main/js/default/pages/index/index.hml b/global/resmgr_standard/resmgrjs/project/entry/src/main/js/default/pages/index/index.hml new file mode 100755 index 0000000000000000000000000000000000000000..1c26cf73deab18390844a53a103458b10ed11e93 --- /dev/null +++ b/global/resmgr_standard/resmgrjs/project/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{title}} + +
diff --git a/global/resmgr_standard/resmgrjs/project/entry/src/main/js/default/pages/index/index.js b/global/resmgr_standard/resmgrjs/project/entry/src/main/js/default/pages/index/index.js new file mode 100755 index 0000000000000000000000000000000000000000..23f18c37e90df5adaa14ad210611ea10f8d0121f --- /dev/null +++ b/global/resmgr_standard/resmgrjs/project/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2021 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 file from '@system.file' +import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + const reportExtend = new ReportExtend(file) + core.addService('expect', expectExtend) + core.addService('report', reportExtend) + core.init() + + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} diff --git a/global/resmgr_standard/resmgrjs/project/entry/src/main/js/test/List.test.js b/global/resmgr_standard/resmgrjs/project/entry/src/main/js/test/List.test.js new file mode 100755 index 0000000000000000000000000000000000000000..ce1ef0692f7e9d1e3b94a318dd7f39089045357c --- /dev/null +++ b/global/resmgr_standard/resmgrjs/project/entry/src/main/js/test/List.test.js @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2021 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. + */ +require('./Resmgr.test.js') diff --git a/global/resmgr_standard/resmgrjs/project/entry/src/main/js/test/Resmgr.test.js b/global/resmgr_standard/resmgrjs/project/entry/src/main/js/test/Resmgr.test.js new file mode 100755 index 0000000000000000000000000000000000000000..51f5ed36634e0cd99fa21ba5b0df3888bbf5cf5a --- /dev/null +++ b/global/resmgr_standard/resmgrjs/project/entry/src/main/js/test/Resmgr.test.js @@ -0,0 +1,246 @@ +/* + * Copyright (C) 2021 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 resmgr from "@ohos.resmgr" +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('resMgrTest', function () { + console.log("*************00000000000000000000000*************"); + + /* * + * @tc.number SUB_GLOBAL_RESMGR_JS_0100 + * @tc.name test getResourceManager method in callback mode + * @tc.desc get the resource manager in callback mode + */ + it('getResourceManager_test_001', 0, function () { + resmgr.getResourceManager((error, mgr) => { + expect(mgr != null).assertTrue(); + }) + }) + + /* * + * @tc.number SUB_GLOBAL_RESMGR_JS_0200 + * @tc.name test getResourceManager method in callback mode with bundlename + * @tc.desc get the resource manager in callback mode with bundlename + */ + it('getResourceManager_test_002', 0, function () { + resmgr.getResourceManager("com.ohos.settings", (error, mgr) => { + expect(mgr != null).assertTrue(); + }) + }) + + /* * + * @tc.number SUB_GLOBAL_RESMGR_JS_0300 + * @tc.name test getResourceManager method in promise mode + * @tc.desc get the resource manager in promise mode + */ + it('getResourceManager_test_001', 0, function () { + resmgr.getResourceManager().then(mgr => { + expect(mgr != null).assertTrue(); + }) + }) + + /* * + * @tc.number SUB_GLOBAL_RESMGR_JS_0400 + * @tc.name test getResourceManager method in promise mode with bundlename + * @tc.desc get the resource manager in promise mode with bundlename + */ + it('getResourceManager_test_002', 0, function () { + resmgr.getResourceManager("com.ohos.settings").then(mgr => { + expect(mgr != null).assertTrue(); + }) + }) + + /* * + * @tc.number SUB_GLOBAL_RESMGR_JS_0500 + * @tc.name test getString method in callback mode + * @tc.desc get the string in callback mode + */ + it('getString_test_001', 0, function () { + resmgr.getResourceManager((error, mgr) => { + mgr.getString(0x1000000, (err, value) => { + expect(value != null).assertTrue(); + }) + }) + }) + + /* * + * @tc.number SUB_GLOBAL_RESMGR_JS_0600 + * @tc.name test getString method in promise mode + * @tc.desc get the string in promise mode + */ + it('getString_test_002', 0, function () { + resmgr.getResourceManager((error, mgr) => { + mgr.getString(0x1000000).then(value => { + expect(value != null).assertTrue(); + }) + }) + }) + + /* * + * @tc.number SUB_GLOBAL_RESMGR_JS_0700 + * @tc.name test getStringArray method in callback mode + * @tc.desc get the string array in callback mode + */ + it('getStringArray_test_001', 0, function () { + resmgr.getResourceManager((error, mgr) => { + mgr.getStringArray(0x1000002, (err, value) => { + expect(value != null).assertTrue(); + }) + }) + }) + + /* * + * @tc.number SUB_GLOBAL_RESMGR_JS_0800 + * @tc.name test getStringArray method in promise mode + * @tc.desc get the string array in promise mode + */ + it('getStringArray_test_002', 0, function () { + resmgr.getResourceManager((error, mgr) => { + mgr.getStringArray(0x1000002).then(value => { + expect(value != null).assertTrue(); + }) + }) + }) + + /* * + * @tc.number SUB_GLOBAL_RESMGR_JS_0900 + * @tc.name test getMedia method in callback mode + * @tc.desc get the media in callback mode + */ + it('getMedia_test_001', 0, function () { + resmgr.getResourceManager((error, mgr) => { + mgr.getMedia(0x1000004, (err, value) => { + expect(value.length > 0).assertTrue(); + }) + }) + }) + + /* * + * @tc.number SUB_GLOBAL_RESMGR_JS_1000 + * @tc.name test getMedia method in promise mode + * @tc.desc get the media in promise mode + */ + it('getMedia_test_002', 0, function () { + resmgr.getResourceManager((error, mgr) => { + mgr.getMedia(0x1000004).then(value => { + expect(value.length > 0).assertTrue(); + }) + }) + }) + + /* * + * @tc.number SUB_GLOBAL_RESMGR_JS_1100 + * @tc.name test getMediaBase64 method in callback mode + * @tc.desc get the media base64 in callback mode + */ + it('getMediaBase64_test_001', 0, function () { + resmgr.getResourceManager((error, mgr) => { + mgr.getMediaBase64(0x1000004, (err, value) => { + expect(value.length > 0).assertTrue(); + }) + }) + }) + + /* * + * @tc.number SUB_GLOBAL_RESMGR_JS_1200 + * @tc.name test getMediaBase64 method in promise mode + * @tc.desc get the media base64 in promise mode + */ + it('getMediaBase64_test_002', 0, function () { + resmgr.getResourceManager((error, mgr) => { + mgr.getMediaBase64(0x1000004).then(value => { + expect(value.length > 0).assertTrue(); + }) + }) + }) + + /* * + * @tc.number SUB_GLOBAL_RESMGR_JS_1300 + * @tc.name test getConfiguration method in callback mode + * @tc.desc get the configuration in callback mode + */ + it('getConfiguration_test_001', 0, function () { + resmgr.getResourceManager((error, mgr) => { + mgr.getConfiguration((error, cfg) => { + expect(cfg != null).assertTrue(); + }) + }) + }) + + /* * + * @tc.number SUB_GLOBAL_RESMGR_JS_1400 + * @tc.name test getConfiguration method in promise mode + * @tc.desc get the configuration in promise mode + */ + it('getConfiguration_test_002', 0, function () { + resmgr.getResourceManager((error, mgr) => { + mgr.getConfiguration().then(cfg => { + expect(cfg != null).assertTrue(); + }) + }) + }) + + /* * + * @tc.number SUB_GLOBAL_RESMGR_JS_1500 + * @tc.name test getDeviceCapability method in callback mode + * @tc.desc get the device capability in callback mode + */ + it('getDeviceCapability_test_001', 0, function () { + resmgr.getResourceManager((error, mgr) => { + mgr.getDeviceCapability((error, dc) => { + expect(dc != null).assertTrue(); + }) + }) + }) + + /* * + * @tc.number SUB_GLOBAL_RESMGR_JS_1600 + * @tc.name test getDeviceCapability method in promise mode + * @tc.desc get the device capability in promise mode + */ + it('getDeviceCapability_test_002', 0, function () { + resmgr.getResourceManager((error, mgr) => { + mgr.getDeviceCapability().then(dc => { + expect(dc != null).assertTrue(); + }) + }) + }) + + /* * + * @tc.number SUB_GLOBAL_RESMGR_JS_1700 + * @tc.name test getPluralString method in callback mode + * @tc.desc get the plural string in callback mode + */ + it('getPluralString_test_001', 0, function () { + resmgr.getResourceManager((error, mgr) => { + mgr.getPluralString(0x1000003, 1, (error, value) => { + expect(value != null).assertTrue(); + }) + }) + }) + + /* * + * @tc.number SUB_GLOBAL_RESMGR_JS_1800 + * @tc.name test getPluralString method in promise mode + * @tc.desc get the plural string in promise mode + */ + it('getPluralString_test_002', 0, function () { + resmgr.getResourceManager((error, mgr) => { + mgr.getPluralString(0x1000003, 1).then(value => { + expect(value != null).assertTrue(); + }) + }) + }) +}) \ No newline at end of file diff --git a/global/resmgr_standard/resmgrjs/project/entry/src/main/resources/base/element/plural.json b/global/resmgr_standard/resmgrjs/project/entry/src/main/resources/base/element/plural.json new file mode 100755 index 0000000000000000000000000000000000000000..5df662491e2cba0cc4ca28cb1547351bea8a78f3 --- /dev/null +++ b/global/resmgr_standard/resmgrjs/project/entry/src/main/resources/base/element/plural.json @@ -0,0 +1,33 @@ +{ + "plural":[ + { + "name":"plural_name", + "value":[ + { + "quantity":"zero", + "value":"%d test zero" + }, + { + "quantity":"one", + "value":"%d test one" + }, + { + "quantity":"two", + "value":"%d test two" + }, + { + "quantity":"few", + "value":"%d test few" + }, + { + "quantity":"many", + "value":"%d test many" + }, + { + "quantity":"other", + "value":"%d test other" + } + ] + } + ] +} \ No newline at end of file diff --git a/global/resmgr_standard/resmgrjs/project/entry/src/main/resources/base/element/strarray.json b/global/resmgr_standard/resmgrjs/project/entry/src/main/resources/base/element/strarray.json new file mode 100755 index 0000000000000000000000000000000000000000..31980e251c888917c7cbccbcdfcb900f376f4557 --- /dev/null +++ b/global/resmgr_standard/resmgrjs/project/entry/src/main/resources/base/element/strarray.json @@ -0,0 +1,21 @@ +{ + "strarray": [ + { + "name": "sizeList", + "value":[ + { + "value":"small" + }, + { + "value":"middle" + }, + { + "value":"large" + }, + { + "value":"extra large" + } + ] + } + ] +} \ No newline at end of file diff --git a/global/resmgr_standard/resmgrjs/project/entry/src/main/resources/base/element/string.json b/global/resmgr_standard/resmgrjs/project/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..fac1f3a7cbdd54561048bb8e4211abd3340efe97 --- /dev/null +++ b/global/resmgr_standard/resmgrjs/project/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "L2Test" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/global/resmgr_standard/resmgrjs/project/entry/src/main/resources/base/media/icon.png b/global/resmgr_standard/resmgrjs/project/entry/src/main/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/global/resmgr_standard/resmgrjs/project/entry/src/main/resources/base/media/icon.png differ diff --git a/global/resmgr_standard/resmgrjs/project/gradle.properties b/global/resmgr_standard/resmgrjs/project/gradle.properties new file mode 100755 index 0000000000000000000000000000000000000000..c555b4e6a519b939a3e954391a3f0772335ad7cf --- /dev/null +++ b/global/resmgr_standard/resmgrjs/project/gradle.properties @@ -0,0 +1,10 @@ +# Project-wide Gradle settings. +# IDE (e.g. DevEco Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# If the Chinese output is garbled, please configure the following parameter. +# org.gradle.jvmargs=-Dfile.encoding=GBK diff --git a/global/resmgr_standard/resmgrjs/project/settings.gradle b/global/resmgr_standard/resmgrjs/project/settings.gradle new file mode 100755 index 0000000000000000000000000000000000000000..28d595f2fba0d06b2025da200383d15f87c4e9f0 --- /dev/null +++ b/global/resmgr_standard/resmgrjs/project/settings.gradle @@ -0,0 +1 @@ +include ':entry' diff --git a/graphic/BUILD.gn b/graphic/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..286048987a5b6e6fb280c050a37a47e843b75e10 --- /dev/null +++ b/graphic/BUILD.gn @@ -0,0 +1,25 @@ +# Copyright (C) 2021 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("//build/ohos_var.gni") +group("graphic") { + testonly = true + if (is_standard_system) { + deps = [ "windowstandard:window_hap_test" ] + } else { + deps = [ + "appaccount:appaccount_hap", + "osaccount:osaccount_hap", + ] + } +} diff --git a/graphic/windowstandard/BUILD.gn b/graphic/windowstandard/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b5a8b0a78e952096cfcf90498a7c15e8024e4af3 --- /dev/null +++ b/graphic/windowstandard/BUILD.gn @@ -0,0 +1,19 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("window_hap_test") { + test_hap_name = "windowhaptest" + hap_source_path = "hap/entry-debug-rich-signed.hap" +} diff --git a/graphic/windowstandard/Test.json b/graphic/windowstandard/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..1c6f1f05debcd3c85ec6e2bdf489b74f1433d55d --- /dev/null +++ b/graphic/windowstandard/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "21600000", + "package": "com.test.window", + "shell-timeout": "21600000" + }, + "kits": [ + { + "test-file-name": [ + "windowhaptest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/graphic/windowstandard/hap/entry-debug-rich-signed.hap b/graphic/windowstandard/hap/entry-debug-rich-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..f0d0213060f372198a3cdb793f3ba423914dad3d Binary files /dev/null and b/graphic/windowstandard/hap/entry-debug-rich-signed.hap differ diff --git a/graphic/windowstandard/project/.gitignore b/graphic/windowstandard/project/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..82dc42bd41e44f0a17e007c62feabac9a3f35d72 --- /dev/null +++ b/graphic/windowstandard/project/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +/entry/.preview +.cxx diff --git a/graphic/windowstandard/project/.idea/.gitignore b/graphic/windowstandard/project/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..eaf91e2ac647df635a09f01b8a2a254252aae8d7 --- /dev/null +++ b/graphic/windowstandard/project/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/graphic/windowstandard/project/.idea/compiler.xml b/graphic/windowstandard/project/.idea/compiler.xml new file mode 100644 index 0000000000000000000000000000000000000000..245a82c8279131bde0c8c09a1f1791c8b0312984 --- /dev/null +++ b/graphic/windowstandard/project/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/graphic/windowstandard/project/.idea/gradle.xml b/graphic/windowstandard/project/.idea/gradle.xml new file mode 100644 index 0000000000000000000000000000000000000000..3c3ca2ca42e21615fa80d3ba2ec90019fd843d3a --- /dev/null +++ b/graphic/windowstandard/project/.idea/gradle.xml @@ -0,0 +1,22 @@ + + + + + + + \ No newline at end of file diff --git a/graphic/windowstandard/project/.idea/jarRepositories.xml b/graphic/windowstandard/project/.idea/jarRepositories.xml new file mode 100644 index 0000000000000000000000000000000000000000..aa00d771aa98b60cc8db06b5e24919c06b208cda --- /dev/null +++ b/graphic/windowstandard/project/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/graphic/windowstandard/project/.idea/misc.xml b/graphic/windowstandard/project/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..9883d055f8725da2d0f5c1cecc525b815e5dfcec --- /dev/null +++ b/graphic/windowstandard/project/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/graphic/windowstandard/project/.idea/vcs.xml b/graphic/windowstandard/project/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..851444e0bd79e22cce04abf8482b2c54ebc0121e --- /dev/null +++ b/graphic/windowstandard/project/.idea/vcs.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/graphic/windowstandard/project/entry/.gitignore b/graphic/windowstandard/project/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..3543521e9fef8e7322940a87c2b45dd0061b0f45 --- /dev/null +++ b/graphic/windowstandard/project/entry/.gitignore @@ -0,0 +1 @@ +/build diff --git a/graphic/windowstandard/project/entry/package.json b/graphic/windowstandard/project/entry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..69a88e3b65423624fe7ea8b0f8beefcc62cc3d5f --- /dev/null +++ b/graphic/windowstandard/project/entry/package.json @@ -0,0 +1 @@ +{} diff --git a/graphic/windowstandard/project/entry/src/main/config.json b/graphic/windowstandard/project/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..ffdb5fff55bd401858c0b09bf8095e0ae1332252 --- /dev/null +++ b/graphic/windowstandard/project/entry/src/main/config.json @@ -0,0 +1,61 @@ +{ + "app": { + "bundleName": "com.test.window", + "vendor": "test", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 5, + "target": 5, + "releaseType": "Beta1" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.test.window", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "com.test.window.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard", + "isVisible": "true" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/graphic/windowstandard/project/entry/src/main/js/default/app.js b/graphic/windowstandard/project/entry/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..1a469fd202c18a1e070e0c088005d5bb68243a13 --- /dev/null +++ b/graphic/windowstandard/project/entry/src/main/js/default/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 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 default { + onCreate() { + console.info('AceApplication onCreate'); + + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/graphic/windowstandard/project/entry/src/main/js/default/i18n/en-US.json b/graphic/windowstandard/project/entry/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/graphic/windowstandard/project/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/graphic/windowstandard/project/entry/src/main/js/default/i18n/zh-CN.json b/graphic/windowstandard/project/entry/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/graphic/windowstandard/project/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/graphic/windowstandard/project/entry/src/main/js/default/pages/index/index.css b/graphic/windowstandard/project/entry/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/graphic/windowstandard/project/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/graphic/windowstandard/project/entry/src/main/js/default/pages/index/index.hml b/graphic/windowstandard/project/entry/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/graphic/windowstandard/project/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/graphic/windowstandard/project/entry/src/main/js/default/pages/index/index.js b/graphic/windowstandard/project/entry/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..71ab9571ed503a6e53147fdfb37bc408f774cf6d --- /dev/null +++ b/graphic/windowstandard/project/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2021 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 {Core} from 'deccjsunit/lite' +const core = Core.getInstance() +core.init() +require('../../../test/List.test.js') +core.execute() + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + } +} diff --git a/graphic/windowstandard/project/entry/src/main/js/test/List.test.js b/graphic/windowstandard/project/entry/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..a6c2cae20573f0db3c72912d67bf103cedb13e1c --- /dev/null +++ b/graphic/windowstandard/project/entry/src/main/js/test/List.test.js @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2021 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. + */ +require('./ExampleJsunit.test.js') +require('./window.test.js') diff --git a/graphic/windowstandard/project/entry/src/main/js/test/window.test.js b/graphic/windowstandard/project/entry/src/main/js/test/window.test.js new file mode 100644 index 0000000000000000000000000000000000000000..6c8c83851bc1ed1fb8929d554e03fd128fec8e42 --- /dev/null +++ b/graphic/windowstandard/project/entry/src/main/js/test/window.test.js @@ -0,0 +1,302 @@ +/* + * Copyright (C) 2021 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 app from '@system.app' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' +import window from '@ohos.window' + + +describe('window_test', function(){ + var wnd; + beforeAll(function(){ + }) + beforeEach(function(){ + }) + afterEach(function(){ + }) + afterAll(function(){ + }) + /** + * @tc.number GRAPHIC_FUNCTION_WINDOW_TESTWINDOW_JSNAPI_0100 + * @tc.name Test getTopWindowTest. + * @tc.desc Test window.getTopWindow API function test. + */ + it('getTopWindowTest', 0, function(){ + console.log('jsunittest getTopWindowTest begin') + window.getTopWindow().then(wnd => { + console.log('jsunittest getTopWindow wnd: ' + wnd) + assertTrue(wnd != null) + }) + }) + /** + * @tc.number GRAPHIC_FUNCTION_WINDOW_TESTWINDOW_JSNAPI_0200 + * @tc.name Test movetest1. + * @tc.desc Test window.moveTo API function test1. + */ + it('moveTest1', 0, function(){ + console.log('jsunittest movetest1 begin') + window.getTopWindow().then(wnd => { + console.log('jsunittest movetest1 getTopWindow wnd: ' + wnd) + wnd.moveTo(200, 200).then(()=>{ + console.log('jsunittest movetest1 wnd.moveTo(200, 200) success') + }) + }) + }) + /** + * @tc.number GRAPHIC_FUNCTION_WINDOW_TESTWINDOW_JSNAPI_0300 + * @tc.name Test moveTest2. + * @tc.desc Test window.moveTo API function test2. + */ + it('moveTest2', 0, function(){ + console.log('jsunittest movetest2 begin') + window.getTopWindow().then(wnd => { + console.log('jsunittest movetest2 getTopWindow wnd: ' + wnd) + wnd.moveTo(100, 100).then(()=>{ + console.log('jsunittest movetest2 wnd.moveTo(100, 100) success') + }) + wnd.moveTo(0, 0).then(()=>{ + console.log('jsunittest movetest2 wnd.moveTo(0, 0) success') + }) + }) + }) + /** + * @tc.number GRAPHIC_FUNCTION_WINDOW_TESTWINDOW_JSNAPI_0400 + * @tc.name Test moveTest3. + * @tc.desc Test window.moveTo API function test3. + */ + it('moveTest3', 0, function(){ + console.log('jsunittest movetest3 begin') + window.getTopWindow().then(wnd => { + console.log('jsunittest movetest3 getTopWindow wnd: ' + wnd) + wnd.moveTo(20000, 20000).then(()=>{ + console.log('jsunittest movetest3 wnd.moveTo(20000, 20000) success') + }) + }) + }) + /** + * @tc.number GRAPHIC_FUNCTION_WINDOW_TESTWINDOW_JSNAPI_0500 + * @tc.name Test moveTest4. + * @tc.desc Test window.moveTo API function test4. + */ + it('moveTest4', 0, function(){ + console.log('jsunittest movetest4 begin') + window.getTopWindow().then(wnd => { + console.log('jsunittest movetest4 getTopWindow wnd: ' + wnd) + wnd.moveTo(-200, -200).then(()=>{ + console.log('jsunittest movetest4 wnd.moveTo(-200, -200) success') + }) + }) + }) + /** + * @tc.number GRAPHIC_FUNCTION_WINDOW_TESTWINDOW_JSNAPI_0600 + * @tc.name Test moveTest5. + * @tc.desc Test window.moveTo API function test5. + */ + it('moveTest5', 0, function(){ + console.log('jsunittest movetest5 begin') + window.getTopWindow().then(wnd => { + console.log('jsunittest movetest5 getTopWindow wnd: ' + wnd) + for (var i = 1; i <= 5; i++) { + wnd.moveTo(100, 100).then(()=>{ + console.log('jsunittest movetest5 wnd.movetest5(100, 100) success, count:"%d\n"',i) + }) + } + }) + }) + /** + * @tc.number GRAPHIC_FUNCTION_WINDOW_TESTWINDOW_JSNAPI_0700 + * @tc.name Test resetSizeTest1. + * @tc.desc Test window.resetSize API function test1. + */ + it('resetSizeTest1', 0, function(){ + console.log('jsunittest resetSizeTest1 begin') + window.getTopWindow().then(wnd => { + console.log('jsunittest resetSizeTest1 getTopWindow wnd: ' + wnd) + wnd.resetSize(200, 600).then(()=>{ + console.log('jsunittest resetSizeTest wnd.resetSize(200, 600) success') + }) + }) + }) + /** + * @tc.number GRAPHIC_FUNCTION_WINDOW_TESTWINDOW_JSNAPI_0800 + * @tc.name Test resetSizeTest2. + * @tc.desc Test window.resetSize API function test2. + */ + it('resetSizeTest2', 0, function(){ + console.log('jsunittest resetSizeTest2 begin') + window.getTopWindow().then(wnd => { + console.log('jsunittest resetSizeTest2 getTopWindow wnd: ' + wnd) + wnd.resetSize(20000, 20000).then(()=>{ + console.log('jsunittest resetSizeTest2 wnd.resetSize(20000, 20000) success') + }) + }) + }) + /** + * @tc.number GRAPHIC_FUNCTION_WINDOW_TESTWINDOW_JSNAPI_0900 + * @tc.name Test resetSizeTest3. + * @tc.desc Test window.resetSize API function test3. + */ + it('resetSizeTest3', 0, function(){ + console.log('jsunittest resetSizeTest3 begin') + window.getTopWindow().then(wnd => { + console.log('jsunittest resetSizeTest3 getTopWindow wnd: ' + wnd) + wnd.resetSize(0, 0).then(()=>{ + console.log('jsunittest resetSizeTest3 wnd.resetSize(0, 0) success') + }) + }) + }) + /** + * @tc.number GRAPHIC_FUNCTION_WINDOW_TESTWINDOW_JSNAPI_1000 + * @tc.name Test resetSizeTest4. + * @tc.desc Test window.resetSize API function test4. + */ + it('resetSizeTest4', 0, function(){ + console.log('jsunittest resetSizeTest4 begin') + window.getTopWindow().then(wnd => { + console.log('jsunittest resetSizeTest4 getTopWindow wnd: ' + wnd) + wnd.resetSize(-1, -1).then(()=>{ + console.log('jsunittest resetSizeTest4 wnd.resetSize(-1, -1) success') + }) + }) + }) + /** + * @tc.number GRAPHIC_FUNCTION_WINDOW_TESTWINDOW_JSNAPI_1100 + * @tc.name Test resetSizeTest5. + * @tc.desc Test window.resetSize API function test5. + */ + it('resetSizeTest5', 0, function(){ + console.log('jsunittest resetSizeTest5 begin') + window.getTopWindow().then(wnd => { + console.log('jsunittest resetSizeTest5 getTopWindow wnd: ' + wnd) + for (var i = 1; i <= 5; i++) { + wnd.resetSize(100, 100).then(()=>{ + console.log('jsunittest resetSizeTest5 wnd.resetSize(100, 100) success, count:"%d\n"',i) + }) + } + }) + }) + /** + * @tc.number GRAPHIC_FUNCTION_WINDOW_TESTWINDOW_JSNAPI_1200 + * @tc.name Test setWindowTypeTest1. + * @tc.desc Test window.setWindowType API function test1. + */ + it('setWindowTypeTest1', 0, function(){ + console.log('jsunittest setWindowTypeTest1 begin') + window.getTopWindow().then(wnd => { + console.log('jsunittest setWindowTypeTest1 getTopWindow wnd: ' + wnd) + wnd.setWindowType(0).then(()=>{ + console.log('jsunittest setWindowTypeTest1 wnd.setWindowType(0) success') + }) + }) + }) + /** + * @tc.number GRAPHIC_FUNCTION_WINDOW_TESTWINDOW_JSNAPI_1300 + * @tc.name Test setWindowTypeTest2. + * @tc.desc Test window.setWindowType API function test2. + */ + it('setWindowTypeTest2', 0, function(){ + console.log('jsunittest setWindowTypeTest2 begin') + window.getTopWindow().then(wnd => { + console.log('jsunittest setWindowTypeTest2 getTopWindow wnd: ' + wnd) + wnd.setWindowType(0).then(()=>{ + console.log('jsunittest setWindowTypeTest2 wnd.setWindowType(0) success') + }) + wnd.moveTo(200, 200).then(()=>{ + console.log('jsunittest setWindowType1 wnd.moveTo(200, 200) success') + }) + }) + }) + /** + * @tc.number GRAPHIC_FUNCTION_WINDOW_TESTWINDOW_JSNAPI_1400 + * @tc.name Test setWindowTypeTest3. + * @tc.desc Test window.setWindowType API function test3. + */ + it('setWindowTypeTest3', 0, function(){ + console.log('jsunittest setWindowTypeTest3 begin') + window.getTopWindow().then(wnd => { + console.log('jsunittest setWindowTypeTest3 getTopWindow wnd: ' + wnd) + wnd.setWindowType(0).then(()=>{ + console.log('jsunittest setWindowTypeTest3 wnd.setWindowType(0) success') + }) + wnd.resetSize(200, 400).then(()=>{ + console.log('jsunittest setWindowTypeTest3 wnd.resetSize(200, 400) success') + }) + }) + }) + /** + * @tc.number GRAPHIC_FUNCTION_WINDOW_TESTWINDOW_JSNAPI_1500 + * @tc.name Test setWindowTypeTest4. + * @tc.desc Test window.setWindowType API function test4. + */ + it('setWindowTypeTest4', 0, function(){ + console.log('jsunittest setWindowTypeTest4 begin') + window.getTopWindow().then(wnd => { + console.log('jsunittest setWindowTypeTest4 getTopWindow wnd: ' + wnd) + wnd.setWindowType(1).then(()=>{ + console.log('jsunittest setWindowTypeTest4 wnd.setWindowType(1) success') + }) + }) + }) + /** + * @tc.number GRAPHIC_FUNCTION_WINDOW_TESTWINDOW_JSNAPI_1600 + * @tc.name Test setWindowTypeTest5. + * @tc.desc Test window.setWindowType API function test5. + */ + it('setWindowTypeTest5', 0, function(){ + console.log('jsunittest setWindowTypeTest5 begin') + window.getTopWindow().then(wnd => { + console.log('jsunittest setWindowTypeTest5 getTopWindow wnd: ' + wnd) + wnd.setWindowType(1).then(()=>{ + console.log('jsunittest setWindowTypeTest5 wnd.setWindowType(1) success') + }) + wnd.moveTo(100, 100).then(()=>{ + console.log('jsunittest setWindowTypeTest5 wnd.moveTo(100, 100) success') + }) + }) + }) + /** + * @tc.number GRAPHIC_FUNCTION_WINDOW_TESTWINDOW_JSNAPI_1700 + * @tc.name Test setWindowTypeTest6. + * @tc.desc Test window.setWindowType API function test6. + */ + it('setWindowTypeTest6', 0, function(){ + console.log('jsunittest setWindowTypeTest6 begin') + window.getTopWindow().then(wnd => { + console.log('jsunittest setWindowTypeTest6 getTopWindow wnd: ' + wnd) + wnd.setWindowType(1).then(()=>{ + console.log('jsunittest setWindowTypeTest6 wnd.setWindowType(1) success') + }) + wnd.resetSize(100, 100).then(()=>{ + console.log('jsunittest setWindowTypeTest6 wnd.resetSize(100, 100) success') + }) + }) + }) + /** + * @tc.number GRAPHIC_FUNCTION_WINDOW_TESTWINDOW_JSNAPI_1800 + * @tc.name Test setWindowTypeTest7. + * @tc.desc Test window.setWindowType API function test7. + */ + it('setWindowTypeTest7', 0, function(){ + console.log('jsunittest setWindowTypeTest7 begin') + window.getTopWindow().then(wnd => { + console.log('jsunittest setWindowTypeTest7 getTopWindow wnd: ' + wnd) + wnd.setWindowType(10).then(()=>{ + console.log('jsunittest setWindowTypeTest7 wnd.setWindowType(10) success') + }) + wnd.resetSize(400, 400).then(()=>{ + console.log('jsunittest setWindowTypeTest7 wnd.resetSize(400, 400) success') + }) + }) + }) +}) diff --git a/graphic/windowstandard/project/entry/src/main/resources/base/element/string.json b/graphic/windowstandard/project/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..2e46da39ad65d6de1c46a0778ad2ee055588836c --- /dev/null +++ b/graphic/windowstandard/project/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "window" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/graphic/windowstandard/project/entry/src/main/resources/base/media/icon.png b/graphic/windowstandard/project/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/graphic/windowstandard/project/entry/src/main/resources/base/media/icon.png differ diff --git a/hiviewdfx/BUILD.gn b/hiviewdfx/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..88d467f2b2da48acb0f8a0cf3d04378599f7aca7 --- /dev/null +++ b/hiviewdfx/BUILD.gn @@ -0,0 +1,23 @@ +# Copyright (C) 2021 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("//build/ohos_var.gni") +group("hiviewdfxtestacts") { + testonly = true + if (is_standard_system) { + deps = [ + "hiappeventtest/hiappeventjstest:hiappeventjstest", + "hilogtest/libhilogtest:libhilogtestacts", + "hisyseventtest/hisyseventcpptest:HiSysEventCPPTest", + ] + } +} diff --git a/hiviewdfx/hiappeventtest/hiappeventjstest/BUILD.gn b/hiviewdfx/hiappeventtest/hiappeventjstest/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..3693b1692d7c86d58f48ed2a4effe7310d6470c0 --- /dev/null +++ b/hiviewdfx/hiappeventtest/hiappeventjstest/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("hiappeventjstest") { + test_hap_name = "HiAppeventTest" + hap_source_path = "hap/entry-debug-signed.hap" +} diff --git a/hiviewdfx/hiappeventtest/hiappeventjstest/Test.json b/hiviewdfx/hiappeventtest/hiappeventjstest/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..c825fc467eb95aac6faabfc57b4179c218da722a --- /dev/null +++ b/hiviewdfx/hiappeventtest/hiappeventjstest/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "21600000", + "package": "ohos.acts.hiviewdfx.hilog.function", + "shell-timeout": "21600000" + }, + "kits": [ + { + "test-file-name": [ + "HiAppeventTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/hiviewdfx/hiappeventtest/hiappeventjstest/hap/entry-debug-signed.hap b/hiviewdfx/hiappeventtest/hiappeventjstest/hap/entry-debug-signed.hap new file mode 100755 index 0000000000000000000000000000000000000000..08896af72d658569d477dc4a8c05677c09c79c1f Binary files /dev/null and b/hiviewdfx/hiappeventtest/hiappeventjstest/hap/entry-debug-signed.hap differ diff --git a/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/package.json b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/package.json new file mode 100755 index 0000000000000000000000000000000000000000..69a88e3b65423624fe7ea8b0f8beefcc62cc3d5f --- /dev/null +++ b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/package.json @@ -0,0 +1 @@ +{} diff --git a/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/config.json b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/config.json new file mode 100755 index 0000000000000000000000000000000000000000..a60253424075e894a7ed06b644a0c33e2a5e07f3 --- /dev/null +++ b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/config.json @@ -0,0 +1,59 @@ +{ + "app": { + "bundleName": "ohos.acts.hiviewdfx.hilog.function", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.hiviewdfx.hilog.function", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "ohos.acts.hiviewdfx.hilog.function.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "MyApplication", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} diff --git a/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/default/app.js b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/default/app.js new file mode 100755 index 0000000000000000000000000000000000000000..3ee099f58926b1a7c42f02bb88ebb4998f9e4ac4 --- /dev/null +++ b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/default/app.js @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2021 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 default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/default/i18n/en-US.json b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/default/i18n/en-US.json new file mode 100755 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/default/i18n/zh-CN.json b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/default/i18n/zh-CN.json new file mode 100755 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/default/pages/index/index.css b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/default/pages/index/index.css new file mode 100755 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/default/pages/index/index.hml b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/default/pages/index/index.hml new file mode 100755 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/default/pages/index/index.js b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/default/pages/index/index.js new file mode 100755 index 0000000000000000000000000000000000000000..7cc3802663eedc672aed532048fd473305a193a0 --- /dev/null +++ b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2021 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 file from '@system.file' +import app from '@system.app' +import device from '@system.device' +import router from '@system.router' +import {Core, ExpectExtend, ReportExtend, Constant} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + const reportExtend = new ReportExtend(file) + core.addService('expect', expectExtend) + core.addService('report', reportExtend) + core.init() + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} \ No newline at end of file diff --git a/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/test/HiAppEvent.test.js b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/test/HiAppEvent.test.js new file mode 100755 index 0000000000000000000000000000000000000000..ccfea559c61172cb5921496546d985589a51abce --- /dev/null +++ b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/test/HiAppEvent.test.js @@ -0,0 +1,354 @@ +/* + * Copyright (C) 2021 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 HiAppEvent from '@ohos.hiappevent' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' +import Constant from 'deccjsunit/src/Constant' + +describe('HiAppEventApiTest', function () { + /** + * @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_0100 + * @tc.name testHiAppEventApi01 + * @tc.desc HiAppEvent write interface test. + */ + it('testHiAppEventApi01', Function|MediumTest|Level1, function () { + console.info('testHiAppEventApi01 start') + var result = false; + HiAppEvent.write("write", HiAppEvent.EventType.FAULT, "key_int", 100, "key_float", 1.1, "key_string", "demo", "key_bool", true, + "key_array_int", [1, 2, 3], "key_array_float", [1.1, 2.2, 3.3], "key_array_str", ["a", "b", "c"], "key_array_bool", [true, false], + "key_array_int2", [1, 2, 3], "key_array_float2", [1.1, 2.2, 3.3], "key_array_str2", ["a", "b", "c"], "key_array_bool2", [true, false], + (err, value) => { + console.log(`HiAppEvent into callback`); + if (err) { + console.error(`HiAppEvent json-callback-error code=${err.code}`); + result = false; + } else { + console.log(`HiAppEvent json-callback-success value=${value}`); + result = true; + } + console.log(`HiAppEvent result=${result}`); + expect(result).assertTrue(); + console.log(`HiAppEvent result123=${result}`); + + }); + }) + + /** + * @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_0200 + * @tc.name testHiAppEventApi02 + * @tc.desc HiAppEvent write json interface test. + */ + it('testHiAppEventApi02', Function|MediumTest|Level1, function () { + console.info('testHiAppEventApi02 start') + var result = false; + HiAppEvent.writeJson("writeJson", HiAppEvent.EventType.FAULT, {"key_int": 100, "key_string": "demo", "key_bool":true, "key_float":1.1 + ,"key_array_int": [1, 2, 3], "key_array_float": [1.1, 2.2, 3.3], "key_array_str": ["a", "b", "c"], "key_array_bool": [true, false] + ,"key_array_int2": [1, 2, 3], "key_arr_float2": [1.1, 2.2, 3.3], "key_arr_str2": ["a", "b", "c"], "key_array_bool2": [true, false] + }, + (err, value) => { + console.log(`HiAppEvent into json-callback`); + if (err) { + console.error(`HiAppEvent json-callback-error code=${err.code}`); + result = false; + } else { + console.log(`HiAppEvent json-callback-success value=${value}`); + result = true; + } + expect(result).assertTrue() + }); + }) + + /** + * @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_0300 + * @tc.name testHiAppEventApi03 + * @tc.desc HiAppEvent write EventType of STATISTIC. + */ + it('testHiAppEventApi03', Function|MediumTest|Level2, function () { + console.info('testHiAppEventApi03 start') + var result = false; + HiAppEvent.write("write", HiAppEvent.EventType.STATISTIC, "key_int", 100, "key_float", 1.1, "key_string", "demo", "key_bool", true, + "key_array_int", [1, 2, 3], "key_array_float", [1.1, 2.2, 3.3], "key_array_str", ["a", "b", "c"], "key_array_bool", [true, false], + "key_array_int2", [1, 2, 3], "key_array_float2", [1.1, 2.2, 3.3], "key_array_str2", ["a", "b", "c"], "key_array_bool2", [true, false], + (err, value) => { + console.log(`HiAppEvent into json-callback`); + if (err) { + console.error(`HiAppEvent json-callback-error code=${err.code}`); + result = false; + } else { + console.log(`HiAppEvent json-callback-success value=${value}`); + result = true; + } + expect(result).assertTrue(); + }); + console.info('testHiAppEventApi03 end') + }) + + /** + * @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_0400 + * @tc.name testHiAppEventApi04 + * @tc.desc HiAppEvent write EventType of SECURITY. + */ + it('testHiAppEventApi04', Function|MediumTest|Level2, function () { + console.info('testHiAppEventApi04 start') + var result = false; + HiAppEvent.write("write", HiAppEvent.EventType.SECURITY, "key_int", 100, "key_float", 1.1, "key_string", "demo", "key_bool", true, + "key_array_int", [1, 2, 3], "key_array_float", [1.1, 2.2, 3.3], "key_array_str", ["a", "b", "c"], "key_array_bool", [true, false], + "key_array_int2", [1, 2, 3], "key_array_float2", [1.1, 2.2, 3.3], "key_array_str2", ["a", "b", "c"], "key_array_bool2", [true, false], + (err, value) => { + console.log(`HiAppEvent into json-callback`); + if (err) { + console.error(`HiAppEvent json-callback-error code=${err.code}`); + result = false; + } else { + console.log(`HiAppEvent json-callback-success value=${value}`); + result = true; + } + expect(result).assertTrue(); + }); + console.info('testHiAppEventApi04 end') + }) + + /** + * @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_0500 + * @tc.name testHiAppEventApi05 + * @tc.desc HiAppEvent write EventType of BEHAVIOR. + */ + it('testHiAppEventApi05', Function|MediumTest|Level2, function () { + console.info('testHiAppEventApi05 start') + var result = false; + HiAppEvent.write("write", HiAppEvent.EventType.BEHAVIOR, "key_int", 100, "key_float", 1.1, "key_string", "demo", "key_bool", true, + "key_array_int", [1, 2, 3], "key_array_float", [1.1, 2.2, 3.3], "key_array_str", ["a", "b", "c"], "key_array_bool", [true, false], + "key_array_int2", [1, 2, 3], "key_array_float2", [1.1, 2.2, 3.3], "key_array_str2", ["a", "b", "c"], "key_array_bool2", [true, false], + (err, value) => { + console.log(`HiAppEvent into json-callback`); + if (err) { + console.error(`HiAppEvent json-callback-error code=${err.code}`); + result = false; + } else { + console.log(`HiAppEvent json-callback-success value=${value}`); + result = true; + } + expect(result).assertTrue(); + }); + console.info('testHiAppEventApi05 end') + }) + + + /** + * @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_0600 + * @tc.name testHiAppEventApi06 + * @tc.desc HiAppEvent write datatype of int. + */ + it('testHiAppEventApi06', Function|MediumTest|Level2, function () { + console.info('testHiAppEventApi06 start') + var result = false; + HiAppEvent.write("write", HiAppEvent.EventType.FAULT, "key_int", 100, + (err, value) => { + console.log(`HiAppEvent into json-callback`); + if (err) { + console.error(`HiAppEvent json-callback-error code=${err.code}`); + result = false; + } else { + console.log(`HiAppEvent json-callback-success value=${value}`); + result = true; + } + expect(result).assertTrue(); + }); + console.info('testHiAppEventApi06 end') + }) + + /** + * @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_0700 + * @tc.name testHiAppEventApi07 + * @tc.desc HiAppEvent write datatype of int array. + */ + it('testHiAppEventApi07', Function|MediumTest|Level2, function () { + console.info('testHiAppEventApi07 start') + var result = false; + HiAppEvent.write("write", HiAppEvent.EventType.FAULT, "key_int_array", [100, 200], + (err, value) => { + console.log(`HiAppEvent into json-callback`); + if (err) { + console.error(`HiAppEvent json-callback-error code=${err.code}`); + result = false; + } else { + console.log(`HiAppEvent json-callback-success value=${value}`); + result = true; + } + expect(result).assertTrue(); + }); + console.info('testHiAppEventApi07 end') + }) + + /** + * @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_0800 + * @tc.name testHiAppEventApi08 + * @tc.desc HiAppEvent write datatype of float. + */ + it('testHiAppEventApi08', Function|MediumTest|Level2, function () { + console.info('testHiAppEventApi08 start') + var result = false; + HiAppEvent.write("write", HiAppEvent.EventType.FAULT, "key_float", 1.1, + (err, value) => { + console.log(`HiAppEvent into json-callback`); + if (err) { + console.error(`HiAppEvent json-callback-error code=${err.code}`); + result = false; + } else { + console.log(`HiAppEvent json-callback-success value=${value}`); + result = true; + } + expect(result).assertTrue(); + }); + console.info('testHiAppEventApi08 end') + }) + + /** + * @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_0900 + * @tc.name testHiAppEventApi09 + * @tc.desc HiAppEvent write datatype of float array. + */ + it('testHiAppEventApi09', Function|MediumTest|Level3, function () { + console.info('testHiAppEventApi09 start') + var result = false; + HiAppEvent.write("write", HiAppEvent.EventType.FAULT, "key_float_array", [1.1, 1.2], + (err, value) => { + console.log(`HiAppEvent into json-callback`); + if (err) { + console.error(`HiAppEvent json-callback-error code=${err.code}`); + result = false; + } else { + console.log(`HiAppEvent json-callback-success value=${value}`); + result = true; + } + expect(result).assertTrue(); + }); + console.info('testHiAppEventApi09 end') + }) + + /** + * @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_1000 + * @tc.name testHiAppEventApi10 + * @tc.desc HiAppEvent write datatype of string. + */ + it('testHiAppEventApi10', Function|MediumTest|Level3, function () { + console.info('testHiAppEventApi10 start') + var result = false; + HiAppEvent.write("write", HiAppEvent.EventType.FAULT, "key_string", "hello world", + (err, value) => { + console.log(`HiAppEvent into json-callback`); + if (err) { + console.error(`HiAppEvent json-callback-error code=${err.code}`); + result = false; + } else { + console.log(`HiAppEvent json-callback-success value=${value}`); + result = true; + } + expect(result).assertTrue(); + }); + console.info('testHiAppEventApi10 end') + }) + + /** + * @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_1100 + * @tc.name testHiAppEventApi11 + * @tc.desc HiAppEvent write datatype of string array. + */ + it('testHiAppEventApi11', Function|MediumTest|Level3, function () { + console.info('testHiAppEventApi11 start') + var result = false; + HiAppEvent.write("write", HiAppEvent.EventType.FAULT, "key_string_array", ["hello world", "hello world2"], + (err, value) => { + console.log(`HiAppEvent into json-callback`); + if (err) { + console.error(`HiAppEvent json-callback-error code=${err.code}`); + result = false; + } else { + console.log(`HiAppEvent json-callback-success value=${value}`); + result = true; + } + expect(result).assertTrue(); + }); + console.info('testHiAppEventApi11 end') + }) + + /** + * @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_1200 + * @tc.name testHiAppEventApi12 + * @tc.desc HiAppEvent write datatype of bool with true. + */ + it('testHiAppEventApi12', Function|MediumTest|Level3, function () { + console.info('testHiAppEventApi12 start') + var result = false; + HiAppEvent.write("write", HiAppEvent.EventType.FAULT, "key_bool", true, + (err, value) => { + console.log(`HiAppEvent into json-callback`); + if (err) { + console.error(`HiAppEvent json-callback-error code=${err.code}`); + result = false; + } else { + console.log(`HiAppEvent json-callback-success value=${value}`); + result = true; + } + expect(result).assertTrue(); + }); + console.info('testHiAppEventApi12 end') + }) + + /** + * @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_1300 + * @tc.name testHiAppEventApi13 + * @tc.desc HiAppEvent write datatype of bool with false. + */ + it('testHiAppEventApi13', Function|MediumTest|Level3, function () { + console.info('testHiAppEventApi13 start') + var result = false; + HiAppEvent.write("write", HiAppEvent.EventType.FAULT, "key_bool", false, + (err, value) => { + console.log(`HiAppEvent into json-callback`); + if (err) { + console.error(`HiAppEvent json-callback-error code=${err.code}`); + result = false; + } else { + console.log(`HiAppEvent json-callback-success value=${value}`); + result = true; + } + expect(result).assertTrue(); + }); + console.info('testHiAppEventApi13 end') + }) + + /** + * @tc.number DFX_DFT_HiviewKit_HiAppEvent_JSNAPI_1400 + * @tc.name testHiAppEventApi14 + * @tc.desc HiAppEvent write datatype of bool array. + */ + it('testHiAppEventApi14', Function|MediumTest|Level3, function () { + console.info('testHiAppEventApi14 start') + var result = false; + HiAppEvent.write("write", HiAppEvent.EventType.FAULT, "key_bool_array", [false, true], + (err, value) => { + console.log(`HiAppEvent into json-callback`); + if (err) { + console.error(`HiAppEvent json-callback-error code=${err.code}`); + result = false; + } else { + console.log(`HiAppEvent json-callback-success value=${value}`); + result = true; + } + expect(result).assertTrue(); + }); + console.info('testHiAppEventApi14 end') + }) +}) diff --git a/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/test/List.test.js b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/test/List.test.js new file mode 100755 index 0000000000000000000000000000000000000000..c5a9b78240bf9cc566f4c0da0f85201c1545e8f6 --- /dev/null +++ b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/js/test/List.test.js @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2021 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. + */ +require('./HiAppEvent.test.js') diff --git a/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/resources/base/element/string.json b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..ab025e765292c86abf35e594e18f4e4549ed2f06 --- /dev/null +++ b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "test2demo" + }, + { + "name": "mainability_description", + "value": "hap sample empty page" + } + ] +} diff --git a/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/resources/base/media/icon.png b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/hiviewdfx/hiappeventtest/hiappeventjstest/project/entry/src/main/resources/base/media/icon.png differ diff --git a/hiviewdfx/hiappeventtest/hiappeventjstest/project/gradle.properties b/hiviewdfx/hiappeventtest/hiappeventjstest/project/gradle.properties new file mode 100755 index 0000000000000000000000000000000000000000..c555b4e6a519b939a3e954391a3f0772335ad7cf --- /dev/null +++ b/hiviewdfx/hiappeventtest/hiappeventjstest/project/gradle.properties @@ -0,0 +1,10 @@ +# Project-wide Gradle settings. +# IDE (e.g. DevEco Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# If the Chinese output is garbled, please configure the following parameter. +# org.gradle.jvmargs=-Dfile.encoding=GBK diff --git a/hiviewdfx/hiappeventtest/hiappeventjstest/project/settings.gradle b/hiviewdfx/hiappeventtest/hiappeventjstest/project/settings.gradle new file mode 100755 index 0000000000000000000000000000000000000000..28d595f2fba0d06b2025da200383d15f87c4e9f0 --- /dev/null +++ b/hiviewdfx/hiappeventtest/hiappeventjstest/project/settings.gradle @@ -0,0 +1 @@ +include ':entry' diff --git a/hiviewdfx/hilogtest/libhilogtest/BUILD.gn b/hiviewdfx/hilogtest/libhilogtest/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..f7225b97f2eec1479b024d7ca2e0f31aa5b93eda --- /dev/null +++ b/hiviewdfx/hilogtest/libhilogtest/BUILD.gn @@ -0,0 +1,20 @@ +# Copyright (C) 2021 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. + +group("libhilogtestacts") { + testonly = true + deps = [ + "libhilogCPPtest:LibhilogCPPtest", + "libhilogCtest:libhilogCtest", + ] +} diff --git a/hiviewdfx/hilogtest/libhilogtest/libhilogCPPtest/BUILD.gn b/hiviewdfx/hilogtest/libhilogtest/libhilogCPPtest/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..58764a68fcd3ea61ecf19af7e65cf538f525d935 --- /dev/null +++ b/hiviewdfx/hilogtest/libhilogtest/libhilogCPPtest/BUILD.gn @@ -0,0 +1,38 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") +module_output_path = "hits/LibhilogCPPtest" + +############################################################################### +config("hilogtest_config") { + visibility = [ ":*" ] + include_dirs = [ + "../../../utils/native", + "//utils/native/base/include/", + "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", + ] +} +ohos_moduletest_suite("LibhilogCPPtest") { + module_out_path = module_output_path + sources = [ "LibhilogCPPtest.cpp" ] + deps = [ + "../../../utils/native:utilskit", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//third_party/googletest:gtest_main", + "//utils/native/base:utils", + ] + + #external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + configs = [ ":hilogtest_config" ] +} diff --git a/hiviewdfx/hilogtest/libhilogtest/libhilogCPPtest/LibhilogCPPtest.cpp b/hiviewdfx/hilogtest/libhilogtest/libhilogCPPtest/LibhilogCPPtest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..74ba370fbb4d41a267ebb3d1f64ac7318f1786d2 --- /dev/null +++ b/hiviewdfx/hilogtest/libhilogtest/libhilogCPPtest/LibhilogCPPtest.cpp @@ -0,0 +1,963 @@ +/* + * Copyright (C) 2021 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. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include "hilog/log_c.h" +#include "hilog/log_cpp.h" +#include +#include "file_utils.h" +using namespace OHOS; +using namespace HiviewDFX; +using namespace testing::ext; +#define MAX_LINE ((1024) * (10)) +#define MAXBUFFSIZE 1024 +class LibhilogCPPtest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +private: +}; +void LibhilogCPPtest::SetUp() +{ + CleanCmd(); +} +void LibhilogCPPtest::TearDown() +{ +} +void LibhilogCPPtest::SetUpTestCase() +{ + std::vector cmdret; + string cmd = "setprop persist.sys.hilog.debug.on false"; + ExecCmdWithRet(cmd, cmdret); + cmd = "setprop hilog.debug.on false"; + ExecCmdWithRet(cmd, cmdret); +} +void LibhilogCPPtest::TearDownTestCase() +{ + std::cout << "TearDownTestCase" << std::endl; +} + +/** + * @tc.name Provides user-mode interfaces(CPP)INFO + * @tc.number DFX_DFT_HilogCPP_0100 + * @tc.desc Provides user-mode interfaces(CPP)INFO + */ +HWTEST_F(LibhilogCPPtest, HILOG_INFO_CPP, Function|MediumTest|Level2) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + int i = 1; + HiLog::Info(a, "123456789_1234567890_publicandprivatelogHWTEST_Fis:%{public}d," + "%{private}lf,%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a'); + std::string expected{"I 123456789_1234567890_publicandprivatelogHWTEST_Fis:1,,2.33,,"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $5, $7}'", cmdRunResult); + std::cout<<"cmdRunResult = " + cmdRunResult<,2.33,,"}; + CmdRun("hilog -L D -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $5, $7}'", cmdRunResult); + std::cout<<"cmdRunResult = " + cmdRunResult<,2.33,,"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $5, $7}'", cmdRunResult); + std::cout<<"cmdRunResult = " + cmdRunResult<,2.33,,"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $5, $7}'", cmdRunResult); + std::cout<<"cmdRunResult = " + cmdRunResult<,2.33,,"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $5, $7}'", cmdRunResult); + std::cout<<"cmdRunResult = " + cmdRunResult<,1,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log long integer format ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2100 + * @tc.desc libhilog-log long integer format ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_LONG_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "INTEGER_long:%{private}ld,%{public}ld,%ld;", 2147483647L, 2147483647L, 2147483647L); + std::string expected{"INTEGER_long:,2147483647,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log fixed-length integer format ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2110 + * @tc.desc libhilog-log fixed-length integer format ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_4_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "INTEGER_4:%{private}4d,%{public}4d,%4d;", 2000, 2000, 2000); + std::string expected{"INTEGER_4:,2000,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log short integer format ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2120 + * @tc.desc libhilog-log short integer format ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_SHORT_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "INTEGER_short:%{private}hd,%{public}hd,%hd;", (short)1024, (short)1024, (short)1024); + std::string expected{"INTEGER_short:,1024,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log unsigned integer format ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2130 + * @tc.desc libhilog-log unsigned integer format ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_UN_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "INTEGER_un:%{private}u,%{public}u,%u;", 2147483647u, 2147483647u, 2147483647u); + std::string expected{"INTEGER_un:,2147483647,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log unsigned long integer type identifier format ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2140 + * @tc.desc libhilog-log unsigned long integer type identifier format ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_LONG_UN_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "INTEGER_long_un:%{private}lu,%{public}lu,%lu;", 7483647ul, 2147483647ul, 2147483647ul); + std::string expected{"INTEGER_long_un:,2147483647,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log unsigned fixed-length integer format ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2150 + * @tc.desc libhilog-log unsigned fixed-length integer format ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_4_UN_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "INTEGER_4_un:%{private}4u,%{public}4u,%4u;", 4000, 4000, 4000); + std::string expected{"INTEGER_4_un:,4000,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log unsigned short integer type identifier format ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2160 + * @tc.desc libhilog-log unsigned short integer type identifier format ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_SHORT_UN_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "INTEGER_short_un:%{private}hu,%{public}hu,%hu;", (unsigned short)65535, + (unsigned short)65535, (unsigned short)65535); + std::string expected{"INTEGER_short_un:,65535,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log float type identifier format ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2170 + * @tc.desc libhilog-log float type identifier format ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_FLOAT_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "FLOAT:%{private}f,%{public}f,%f;", 1.01, 1.01, 1.01); + std::string expected{"FLOAT:,1.010000,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log long float type identifier format ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2180 + * @tc.desc libhilog-log long float type identifier format ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_FLOAT_LONG_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "FLOAT_long:%{private}lf,%{public}lf,%lf;", 2.147483647, 2.147483647, 2.147483647); + std::string expected{"FLOAT_long:,2.147484,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting of fixed-width floating-point identifiers in + * the decimal part of the log ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2190 + * @tc.desc libhilog-Formatting of fixed-width floating-point identifiers in + * the decimal part of the log ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_FLOAT_POINT2_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "FLOAT_.2:%{private}.2f,%{public}.2f,%.2f;", 2.147483647, 2.147483647, 2.147483647); + std::string expected{"FLOAT_.2:,2.15,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting of floating-point identifiers for + * the decimal part and integer part of the log ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2200 + * @tc.desc libhilog-Formatting of floating-point identifiers for + * the decimal part and integer part of the log ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_FLOAT_3POINT2_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "FLOAT_3.2:%{private}3.2f,%{public}4.1f,%2.6f;", 32.147483647, 321.147483647, 23.147483647); + std::string expected{"FLOAT_3.2:,321.1,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting log characters ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2210 + * @tc.desc libhilog-Formatting log characters ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_CHAR_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "CHAR:%{private}c,%{public}c,%c;", 'a', 'b', 'c'); + std::string expected{"CHAR:,b,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting log octal identifier ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2250 + * @tc.desc libhilog-Formatting log octal identifier ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_OCTAL_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "OCTAL:%{private}o,%{public}o,%o;", 15, 16, 17); + std::string expected{"OCTAL:,20,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting log long octal identifier ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2260 + * @tc.desc libhilog-Formatting log long octal identifier ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_OCTAL_LONG_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "OCTAL_long:%{private}lo,%{public}lo,%lo;", 18ul, 19ul, 20ul); + std::string expected{"OCTAL_long:,23,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting log hexadecimal identifiers ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2270 + * @tc.desc libhilog-Formatting log hexadecimal identifiers ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_HEX_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "HEX:%{private}x,%{public}x,%x;", 15, 16, 17); + std::string expected{"HEX:,10,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Logs with prefixes in hexadecimal format ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2280 + * @tc.desc libhilog-Logs with prefixes in hexadecimal format ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_HEX_UPPER_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "HEX_#:%{private}#x,%{public}#x,%#x;", 18, 19, 20); + std::string expected{"HEX_#:,0x13,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Logs are formatted with long hexadecimal identifiers + * ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2290 + * @tc.desc libhilog-Logs are formatted with long hexadecimal identifiers + * ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_HEX_LONG_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "HEX_long:%{private}lx,%{public}lx,%lx;", 21l, 22l, 23l); + std::string expected{"HEX_long:,16,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Logs are formatted with uppercase hexadecimal flags + * ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2300 + * @tc.desc libhilog-Logs are formatted with uppercase hexadecimal flags + * ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_HEX_X_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "HEX_X:%{private}X,%{public}X,%X;", 24u, 25u, 26u); + std::string expected{"HEX_X:,19,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Logs are formatted with uppercase and prefixes in hexadecimal format + * ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2310 + * @tc.desc libhilog-Logs are formatted with uppercase and prefixes in hexadecimal format + * ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_HEX_UPPER_X_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "HEX_#X:%{private}#X,%{public}#X,%#X;", 27, 28, 28); + std::string expected{"HEX_#X:,0X1C,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Logs are formatted with uppercase long hexadecimal identifiers + * ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2320 + * @tc.desc libhilog-Logs are formatted with uppercase long hexadecimal identifiers + * ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_HEX_LONG_UPPER_X_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "HEX_long_X:%{private}lX,%{public}lX,%lX;", 30ul, 31ul, 32ul); + std::string expected{"HEX_long_X:,1F,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting Log whith string identifiers ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2220 + * @tc.desc libhilog-Formatting Log whith string identifiers ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_STR_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "STRING:%{private}s,%{public}s,%s;", "STRING1", "STRING2", "STRING3"); + std::string expected{"STRING:,STRING2,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting Log whith empty string identifiers ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2240 + * @tc.desc libhilog-Formatting Log whith empty string identifiers ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_STR_EMPTY_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "STRING_empty:%{private}s,%{public}s,%s;", "", "", ""); + std::string expected{"STRING_empty:,,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting Log whith Chinese identifiers ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2230 + * @tc.desc libhilog-Formatting Log whith Chinese identifiers ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_STR_CHINESE_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "STRING_Chinese:%{private}s,%{public}s,%s;", "中文", "中文", "中文"); + std::string expected{"STRING_Chinese:,中文,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting Log whith scientific notation identifiers ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2330 + * @tc.desc libhilog-Formatting Log whith scientific notation identifiers ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_E_DOUBLE_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "DOUBLE_e:%{private}e,%{public}e,%e;", 1e-30, 2.231e10, 3.999e-13); + std::string expected{"DOUBLE_e:,2.231000e+10,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting Log whith scientific notation capitalized identifiers + * ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2340 + * @tc.desc libhilog-Formatting Log whith scientific notation capitalized identifiers + * ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_E_UPPER_DOUBLE_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "DOUBLE_E:%{private}E,%{public}E,%E;", 4.88E2, 5.676767e-2, 6.17E13); + std::string expected{"DOUBLE_E:,5.676767E-02,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting Log whith scientific notation(%g AUTO) identifiers + * ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2350 + * @tc.desc libhilog-Formatting Log whith scientific notation(%g AUTO) identifiers + * ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_E_AUTO_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "AUTO:%{private}g,%{public}g,%g;", 1e-30, 2.231e10, 3.999e-13); + std::string expected{"AUTO:,2.231e+10,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-libhilog-Formatting Log whith scientific notation(%g AUTO) capitalized + * identifiers ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogCPP_2360 + * @tc.desc libhilog-libhilog-Formatting Log whith scientific notation(%g AUTO) capitalized + * identifiers ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCPPtest, HILOG_E_UPPER_AUTO_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "AUTO_E:%{private}G,%{public}G,%G;", 4.88E2, 5.676767e-2, 6.17E13); + std::string expected{"AUTO_E:,0.0567677,;"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-The {private} flag parameter of mixed log formatting is hidden + * @tc.number DFX_DFT_HilogCPP_31 + * @tc.desc libhilog-The {private} flag parameter of mixed log formatting is hidden + */ +HWTEST_F(LibhilogCPPtest, HILOG_PRIVATE_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "private:%{private}d,%{private}lf,%{private}.2f,%{private}s,%{private}c", + 1, 1.00001, 2.333333, "sse", 'a'); + std::string expected{"private:,,,,"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-The parameters identified by {public} in mixed log formatting are displayed + * @tc.number DFX_DFT_HilogCPP_31 + * @tc.desc libhilog-The parameters identified by {public} in mixed log formatting are displayed + */ +HWTEST_F(LibhilogCPPtest, HILOG_PUBLIC_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "public:%{public}d,%{public}lf,%{public}.2f,%{public}s,%{public}c", + 1, 1.00001, 2.333333, "sse", 'a'); + std::string expected{"public:1,1.000010,2.33,sse,a"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Parameters without any privacy flag are not displayed in mixed log formatting + * @tc.number DFX_DFT_HilogCPP_31 + * @tc.desc libhilog-Parameters without any privacy flag are not displayed in mixed log formatting + */ +HWTEST_F(LibhilogCPPtest, HILOG_NO_SIGN_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "no_sign:%d,%lf,%.2f,%s,%c", 1, 1.00001, 2.333333, "sse", 'a'); + std::string expected{"no_sign:,,,,"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Log privacy flags are used together, and parameters are + * correctly displayed or hidden + * @tc.number DFX_DFT_HilogCPP_31 + * @tc.desc libhilog-Log privacy flags are used together, and parameters are + * correctly displayed or hidden + */ +HWTEST_F(LibhilogCPPtest, HILOG_MIX_CPP, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tag; + HiLog::Fatal(a, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a'); + std::string expected{"MIX:1,,2.33,,"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log are not truncated with normal length tag + * @tc.number DFX_DFT_HilogCPP_0280 + * @tc.desc libhilog-log are not truncated with normal length tag + */ +HWTEST_F(LibhilogCPPtest, TAG_CHECK_CPP, Function|MediumTest|Level2) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tagNormal = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tagNormal; + HiLog::Fatal(a, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a'); + std::string expected{"03200/HWTEST_Ftag0HWTEST_Ftag0HWTEST:"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $6}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log are truncated with too long tag + * @tc.number DFX_DFT_HilogCPP_0290 + * @tc.desc libhilog-log are truncated with too long tag + */ +HWTEST_F(LibhilogCPPtest, TAG_OVER_CHECK_CPP, Function|MediumTest|Level2) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd003200; + const char *tagToolong = "HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0" + "HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tagToolong; + HiLog::Fatal(a, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a'); + std::string expected{"03200/HWTEST_Ftag0HWTEST_Ftag0HWTEST_:"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST_/ | awk '{print $6}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log domain + * @tc.number DFX_DFT_HilogCPP_0270 + * @tc.desc libhilog-log domain + */ +HWTEST_F(LibhilogCPPtest, DOMAIN_CHECK_CPP, Function|MediumTest|Level1) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + const unsigned int domain = 0xd001111; + const char *tagNormal = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tagNormal; + HiLog::Fatal(a, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a'); + std::string expected{"01111/HWTEST_Ftag0HWTEST_Ftag0HWTEST:"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $6}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log LOG_APP type test + * @tc.number DFX_DFT_HilogCPP_0280 + * @tc.desc libhilog-log LOG_APP type test + */ +HWTEST_F(LibhilogCPPtest, TYPE_APP_CHECK_CPP, Function|MediumTest|Level2) +{ + std::string cmdRunResult; + LogType type = LOG_APP; + const unsigned int domain = 0xd003200; + const char *tagNormal = "HWTEST_Ftag0HWTEST_Ftag0HWTEST"; + HiLogLabel a; + a.type = type; + a.domain = domain; + a.tag = tagNormal; + HiLog::Fatal(a, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a'); + std::string expected{"03200/HWTEST_Ftag0HWTEST_Ftag0HWTEST:"}; + CmdRun("hilog -x -M ///HWTEST_Ftag0HWTEST_Ftag0HWTEST/ | awk '{print $6}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} diff --git a/hiviewdfx/hilogtest/libhilogtest/libhilogCPPtest/Test.json b/hiviewdfx/hilogtest/libhilogtest/libhilogCPPtest/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..ae9dea8149381abdd538d43b33c12b12537b1d8f --- /dev/null +++ b/hiviewdfx/hilogtest/libhilogtest/libhilogCPPtest/Test.json @@ -0,0 +1,21 @@ +{ + "kits": [ + { + "push": [ + "LibhilogCPPtest->/data/local/tmp/LibhilogCPPtest" + ], + "type": "PushKit", + "post-push": [ + "chmod -R 777 /data/local/tmp/*" + ] + } + ], + "driver": { + "native-test-timeout": "120000", + "type": "CppTest", + "module-name": "LibhilogCPPtest", + "runtime-hint": "1s", + "native-test-device-path": "/data/local/tmp" + }, + "description": "Configuration for LibhilogCPPtest Tests" +} \ No newline at end of file diff --git a/hiviewdfx/hilogtest/libhilogtest/libhilogCtest/BUILD.gn b/hiviewdfx/hilogtest/libhilogtest/libhilogCtest/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..3fd4a56acca22b508462d8326dabbd2a2456b836 --- /dev/null +++ b/hiviewdfx/hilogtest/libhilogtest/libhilogCtest/BUILD.gn @@ -0,0 +1,38 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") +module_output_path = "hits/libhilogCtest" + +############################################################################### +config("hilogtest_config") { + visibility = [ ":*" ] + include_dirs = [ + "../../../utils/native", + "//utils/native/base/include/", + "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", + ] +} +ohos_moduletest_suite("libhilogCtest") { + module_out_path = module_output_path + sources = [ "libhilogCtest.cpp" ] + deps = [ + "../../../utils/native:utilskit", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//third_party/googletest:gtest_main", + "//utils/native/base:utils", + ] + + #external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + configs = [ ":hilogtest_config" ] +} diff --git a/hiviewdfx/hilogtest/libhilogtest/libhilogCtest/Test.json b/hiviewdfx/hilogtest/libhilogtest/libhilogCtest/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..e265eeec1edde6bd1622c140db1e5cbca33651d1 --- /dev/null +++ b/hiviewdfx/hilogtest/libhilogtest/libhilogCtest/Test.json @@ -0,0 +1,21 @@ +{ + "kits": [ + { + "push": [ + "libhilogCtest->/data/local/tmp/libhilogCtest" + ], + "type": "PushKit", + "post-push": [ + "chmod -R 777 /data/local/tmp/*" + ] + } + ], + "driver": { + "native-test-timeout": "120000", + "type": "CppTest", + "module-name": "libhilogCtest", + "runtime-hint": "1s", + "native-test-device-path": "/data/local/tmp" + }, + "description": "Configuration for libhilogCtest Tests" +} \ No newline at end of file diff --git a/hiviewdfx/hilogtest/libhilogtest/libhilogCtest/libhilogCtest.cpp b/hiviewdfx/hilogtest/libhilogtest/libhilogCtest/libhilogCtest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..e8ea4561339f39450e129b91ece6739abea9e671 --- /dev/null +++ b/hiviewdfx/hilogtest/libhilogtest/libhilogCtest/libhilogCtest.cpp @@ -0,0 +1,714 @@ +/* + * Copyright (C) 2021 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. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include "hilog/log_c.h" +#include "hilog/log_cpp.h" +#include +#include "file_utils.h" + +#undef LOG_DOMAIN +#undef LOG_TAG +#define LOG_DOMAIN 0xD003E00 +#define LOG_TAG "testtag0testtag0testtag0testta" +using namespace std; +using namespace testing::ext; + +class LibhilogCtest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +private: +}; +void LibhilogCtest::SetUp() +{ + CleanCmd(); +} +void LibhilogCtest::TearDown() +{ +} +void LibhilogCtest::SetUpTestCase() +{ + std::vector cmdret; + string cmd = "setprop persist.sys.hilog.debug.on false"; + ExecCmdWithRet(cmd, cmdret); + cmd = "setprop hilog.debug.on false"; + ExecCmdWithRet(cmd, cmdret); +} +void LibhilogCtest::TearDownTestCase() +{ + std::cout << "TearDownTestCase" << std::endl; +} + +/** + * @tc.name Provides user-mode interfaces(C)INFO + * @tc.number DFX_DFT_HilogC_0180 + * @tc.desc Provides user-mode interfaces(C)INFO + */ +HWTEST_F(LibhilogCtest, HILOG_INFO, Function|MediumTest|Level2) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + int i = 1; + HILOG_INFO(type, "123456789_1234567890_publicandprivatelogtestis:%{public}d," + "%{private}lf,%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a'); + std::string expected{"I 123456789_1234567890_publicandprivatelogtestis:1,,2.33,,"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $5, $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.desc Provides user-mode interfaces(C)debug + * @tc.number DFX_DFT_HilogC_0170 + * @tc.desc Provides user-mode interfaces(C)debug + */ +HWTEST_F(LibhilogCtest, HILOG_DEBUG, Function|MediumTest|Level1) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + int i = 1; + HILOG_DEBUG(type, "123456789_1234567890_publicandprivatelogtestis:%{public}d,%{private}lf," + "%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a'); + std::string expected{"D 123456789_1234567890_publicandprivatelogtestis:1,,2.33,,"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $5, $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name Provides user-mode interfaces(C)warning + * @tc.number DFX_DFT_HilogC_0210 + * @tc.desc Provides user-mode interfaces(C)warning + */ +HWTEST_F(LibhilogCtest, HILOG_WARNING, Function|MediumTest|Level2) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + int i = 1; + HILOG_WARN(type, "123456789_1234567890_publicandprivatelogtestis:%{public}d," + "%{private}lf,%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a'); + std::string expected{"W 123456789_1234567890_publicandprivatelogtestis:1,,2.33,,"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $5, $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.desc Provides user-mode interfaces(C)error + * @tc.number DFX_DFT_HilogC_0190 + * @tc.desc Provides user-mode interfaces(C)error + */ +HWTEST_F(LibhilogCtest, HILOG_ERROR, Function|MediumTest|Level2) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + int i = 1; + HILOG_ERROR(type, "123456789_1234567890_publicandprivatelogtestis:%{public}d,%{private}lf," + "%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a'); + std::string expected{"E 123456789_1234567890_publicandprivatelogtestis:1,,2.33,,"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $5, $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name Provides user-mode interfaces(C)fatal + * @tc.number DFX_DFT_HilogC_0200 + * @tc.desc Provides user-mode interfaces(C)fatal + */ +HWTEST_F(LibhilogCtest, HILOG_FATAL, Function|MediumTest|Level2) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + int i = 1; + HILOG_FATAL(type, "123456789_1234567890_publicandprivatelogtestis:%{public}d,%{private}lf," + "%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a'); + std::string expected{"F 123456789_1234567890_publicandprivatelogtestis:1,,2.33,,"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $5, $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log integer format ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0360 + * @tc.desc libhilog-log integer format ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_INTEGER, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "INTEGER:%{private}d,%{public}d,%d;", 1, 1, 1); + std::string expected{"INTEGER:,1,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log long integer format ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0370 + * @tc.desc libhilog-log long integer format ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_INTEGER_LONG, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "INTEGER_long:%{private}ld,%{public}ld,%ld;", 2147483647L, 2147483647L, 2147483647L); + std::string expected{"INTEGER_long:,2147483647,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log fixed-length integer format ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0380 + * @tc.desc libhilog-log fixed-length integer format ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_INTEGER_4, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "INTEGER_4:%{private}4d,%{public}4d,%4d;", 2000, 2000, 2000); + std::string expected{"INTEGER_4:,2000,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log short integer format ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0390 + * @tc.desc libhilog-log short integer format ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_INTEGER_SHORT, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "INTEGER_short:%{private}hd,%{public}hd,%hd;", (short)1024, (short)1024, (short)1024); + std::string expected{"INTEGER_short:,1024,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log unsigned integer format ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0400 + * @tc.desc libhilog-log unsigned integer format ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_INTEGER_UN, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "INTEGER_un:%{private}u,%{public}u,%u;", 2147483647u, 2147483647u, 2147483647u); + std::string expected{"INTEGER_un:,2147483647,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log unsigned long integer type identifier format ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0410 + * @tc.desc libhilog-log unsigned long integer type identifier format ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_INTEGER_LONG_UN, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "INTEGER_long_un:%{private}lu,%{public}lu,%lu;", 7483647lu, 2147483647lu, 2147483647lu); + std::string expected{"INTEGER_long_un:,2147483647,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log unsigned fixed-length integer format ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0420 + * @tc.desc libhilog-log unsigned fixed-length integer format ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_INTEGER_4_UN, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "INTEGER_4_un:%{private}4u,%{public}4u,%4u;", 4000u, 4000u, 4000u); + std::string expected{"INTEGER_4_un:,4000,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log unsigned short integer type identifier format ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0430 + * @tc.desc libhilog-log unsigned short integer type identifier format ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_INTEGER_SHORT_UN, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "INTEGER_short_un:%{private}hu,%{public}hu,%hu;", + (unsigned short)65535, (unsigned short)65535, (unsigned short)65535); + std::string expected{"INTEGER_short_un:,65535,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log float type identifier format ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0440 + * @tc.desc libhilog-log float type identifier format ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_FLOAT, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "FLOAT:%{private}f,%{public}f,%f;", 1.01, 1.01, 1.01); + std::string expected{"FLOAT:,1.010000,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log long float type identifier format ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0450 + * @tc.desc libhilog-log long float type identifier format ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_FLOAT_LONG, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "FLOAT_long:%{private}lf,%{public}lf,%lf;", 2.147483647, 2.147483647, 2.147483647); + std::string expected{"FLOAT_long:,2.147484,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting of fixed-width floating-point identifiers in + * the decimal part of the log ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0460 + * @tc.desc libhilog-Formatting of fixed-width floating-point identifiers in + * the decimal part of the log ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_FLOAT_POINT2, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "FLOAT_.2:%{private}.2f,%{public}.2f,%.2f;", 2.147483647, 2.147483647, 2.147483647); + std::string expected{"FLOAT_.2:,2.15,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting of floating-point identifiers for + * the decimal part and integer part of the log ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0470 + * @tc.desc libhilog-Formatting of floating-point identifiers for + * the decimal part and integer part of the log ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_FLOAT_3POINT2, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "FLOAT_3.2:%{private}3.2f,%{public}4.1f,%2.6f;", 32.147483647, 321.147483647, 23.147483647); + std::string expected{"FLOAT_3.2:,321.1,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting log characters ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0480 + * @tc.desc libhilog-Formatting log characters ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_CHAR, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "CHAR:%{private}c,%{public}c,%c;", 'a', 'b', 'c'); + std::string expected{"CHAR:,b,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting log octal identifier ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0520 + * @tc.desc libhilog-Formatting log octal identifier ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_OCTAL, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "OCTAL:%{private}o,%{public}o,%o;", 15, 16, 17); + std::string expected{"OCTAL:,20,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting log long octal identifier ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0530 + * @tc.desc libhilog-Formatting log long octal identifier ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_OCTAL_LONG, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "OCTAL_long:%{private}lo,%{public}lo,%lo;", 022l, 023l, 024l); + std::string expected{"OCTAL_long:,23,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting log hexadecimal identifiers ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0540 + * @tc.desc libhilog-Formatting log hexadecimal identifiers ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_HEX, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "HEX:%{private}x,%{public}x,%x;", 0x0F, 0x10, 0x11); + std::string expected{"HEX:,10,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Logs with prefixes in hexadecimal format ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0550 + * @tc.desc libhilog-Logs with prefixes in hexadecimal format ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_HEX_UPPER, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "HEX_#:%{private}#x,%{public}#x,%#x;", 0x12, 0x13, 0x14); + std::string expected{"HEX_#:,0x13,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Logs are formatted with long hexadecimal identifiers + * ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0560 + * @tc.desc libhilog-Logs are formatted with long hexadecimal identifiers + * ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_HEX_LONG, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "HEX_long:%{private}lx,%{public}lx,%lx;", 0x15l, 0x16l, 0x17l); + std::string expected{"HEX_long:,16,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Logs are formatted with uppercase hexadecimal flags + * ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0570 + * @tc.desc libhilog-Logs are formatted with uppercase hexadecimal flags + * ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_HEX_X, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "HEX_X:%{private}X,%{public}X,%X;", 0x18, 0x19, 0x1A); + std::string expected{"HEX_X:,19,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Logs are formatted with uppercase and prefixes in hexadecimal format + * ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0580 + * @tc.desc libhilog-Logs are formatted with uppercase and prefixes in hexadecimal format + * ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_HEX_UPPER_X, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "HEX_#X:%{private}#X,%{public}#X,%#X;", 0x1B, 0x1C, 0x1C); + std::string expected{"HEX_#X:,0X1C,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Logs are formatted with uppercase long hexadecimal identifiers + * ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0590 + * @tc.desc libhilog-Logs are formatted with uppercase long hexadecimal identifiers + * ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_HEX_LONG_UPPER_X, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "HEX_long_X:%{private}lX,%{public}lX,%lX;", 0x1El, 0x1Fl, 0x20l); + std::string expected{"HEX_long_X:,1F,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting Log whith string identifiers ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0490 + * @tc.desc libhilog-Formatting Log whith string identifiers ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_STR, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "STRING:%{private}s,%{public}s,%s;", "STRING1", "STRING2", "STRING3"); + std::string expected{"STRING:,STRING2,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting Log whith empty string identifiers ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0510 + * @tc.desc libhilog-Formatting Log whith empty string identifiers ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_STR_EMPTY, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "STRING_empty:%{private}s,%{public}s,%s;", "", "", ""); + std::string expected{"STRING_empty:,,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting Log whith Chinese identifiers ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0500 + * @tc.desc libhilog-Formatting Log whith Chinese identifiers ({public}, {private}, no identifier) + */ + +HWTEST_F(LibhilogCtest, HILOG_STR_CHINESE, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "STRING_Chinese:%{private}s,%{public}s,%s;", "中文", "中文", "中文"); + std::string expected{"STRING_Chinese:,中文,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting Log whith scientific notation identifiers ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0600 + * @tc.desc libhilog-Formatting Log whith scientific notation identifiers ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_E_DOUBLE, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "DOUBLE_e:%{private}e,%{public}e,%e;", 1e-30, 2.231e10, 3.999e-13); + std::string expected{"DOUBLE_e:,2.231000e+10,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting Log whith scientific notation capitalized identifiers + * ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0610 + * @tc.desc libhilog-Formatting Log whith scientific notation capitalized identifiers + * ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_E_UPPER_DOUBLE, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "DOUBLE_E:%{private}E,%{public}E,%E;", 4.88E2, 5.676767e-2, 6.17E13); + std::string expected{"DOUBLE_E:,5.676767E-02,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Formatting Log whith scientific notation(%g AUTO) identifiers + * ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0620 + * @tc.desc libhilog-Formatting Log whith scientific notation(%g AUTO) identifiers + * ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_E_AUTO, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "AUTO:%{private}g,%{public}g,%g;", 1e-30, 2.231e10, 3.999e-13); + std::string expected{"AUTO:,2.231e+10,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-libhilog-Formatting Log whith scientific notation(%g AUTO) capitalized + * identifiers ({public}, {private}, no identifier) + * @tc.number DFX_DFT_HilogC_0630 + * @tc.desc libhilog-libhilog-Formatting Log whith scientific notation(%g AUTO) capitalized + * identifiers ({public}, {private}, no identifier) + */ +HWTEST_F(LibhilogCtest, HILOG_E_UPPER_AUTO, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "AUTO_E:%{private}G,%{public}G,%G;", 4.88E2, 5.676767e-2, 6.17E13); + std::string expected{"AUTO_E:,0.0567677,;"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-The {private} flag parameter of mixed log formatting is hidden + * @tc.number DFX_DFT_HilogC_3100 + * @tc.desc libhilog-The {private} flag parameter of mixed log formatting is hidden + */ +HWTEST_F(LibhilogCtest, HILOG_PRIVATE, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "private:%{private}d,%{private}lf,%{private}.2f," + "%{private}s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a'); + std::string expected{"private:,,,,"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-The parameters identified by {public} in mixed log formatting are displayed + * @tc.number DFX_DFT_HilogC_3200 + * @tc.desc libhilog-The parameters identified by {public} in mixed log formatting are displayed + */ +HWTEST_F(LibhilogCtest, HILOG_PUBLIC, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "public:%{public}d,%{public}lf,%{public}.2f,%{public}s,%{public}c", + 1, 1.00001, 2.333333, "sse", 'a'); + std::string expected{"public:1,1.000010,2.33,sse,a"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Parameters without any privacy flag are not displayed in mixed log formatting + * @tc.number DFX_DFT_HilogC_3300 + * @tc.desc libhilog-Parameters without any privacy flag are not displayed in mixed log formatting + */ +HWTEST_F(LibhilogCtest, HILOG_NO_SIGN, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "no_sign:%d,%lf,%.2f,%s,%c", 1, 1.00001, 2.333333, "sse", 'a'); + std::string expected{"no_sign:,,,,"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-Log privacy flags are used together, and parameters are + * correctly displayed or hidden + * @tc.number DFX_DFT_HilogC_3400 + * @tc.desc libhilog-Log privacy flags are used together, and parameters are + * correctly displayed or hidden + */ +HWTEST_F(LibhilogCtest, HILOG_MIX, Function|MediumTest|Level3) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a'); + std::string expected{"MIX:1,,2.33,,"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $7}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log are not truncated with normal length tag + * @tc.number DFX_DFT_HilogC_0280 + * @tc.desc libhilog-log are not truncated with normal length tag + */ +HWTEST_F(LibhilogCtest, TAG_CHECK, Function|MediumTest|Level2) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; + HILOG_FATAL(type, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a'); + std::string expected{"03e00/testtag0testtag0testtag0testta:"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $6}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log are not truncated with normal length tag + * @tc.number DFX_DFT_HilogC_0280 + * @tc.desc libhilog-log are not truncated with normal length tag + */ +HWTEST_F(LibhilogCtest, TYPE_APP_CHECK, Function|MediumTest|Level2) +{ + std::string cmdRunResult; + LogType type = LOG_APP; + HILOG_FATAL(type, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a'); + std::string expected{"03e00/testtag0testtag0testtag0testta:"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testta/ | awk '{print $6}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log are truncated with too long tag + * @tc.number DFX_DFT_HilogC_0290 + * @tc.desc libhilog-log are truncated with too long tag + */ +HWTEST_F(LibhilogCtest, TAG_OVER_CHECK, Function|MediumTest|Level2) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; +#undef LOG_TAG +#define LOG_TAG "testtag0testtag0testtag0testtag0testtag0testtag0testtag0testtag0testtag0testtag0testtag0testtag0" + HILOG_FATAL(type, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a'); + std::string expected{"03e00/testtag0testtag0testtag0testtag:"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testtag/ | awk '{print $6}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} + +/** + * @tc.name libhilog-log domain + * @tc.number DFX_DFT_HilogC_0270 + * @tc.desc libhilog-log domain + */ +HWTEST_F(LibhilogCtest, DOMAIN_CHECK, Function|MediumTest|Level1) +{ + std::string cmdRunResult; + LogType type = LOG_CORE; +#undef LOG_DOMAIN +#define LOG_DOMAIN 0xD001111 + HILOG_FATAL(type, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a'); + std::string expected{"01111/testtag0testtag0testtag0testtag:"}; + CmdRun("hilog -x -M ///testtag0testtag0testtag0testtag/ | awk '{print $6}'", cmdRunResult); + EXPECT_EQ(cmdRunResult, expected); +} \ No newline at end of file diff --git a/hiviewdfx/hisyseventtest/hisyseventcpptest/BUILD.gn b/hiviewdfx/hisyseventtest/hisyseventcpptest/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..1e931ccd083d8d69a23760b9848a8f13c22854b6 --- /dev/null +++ b/hiviewdfx/hisyseventtest/hisyseventcpptest/BUILD.gn @@ -0,0 +1,41 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +module_output_path = "hit/HiSysEventCPPTest" + +############################################################################### +config("hilogtest_config") { + visibility = [ ":*" ] + include_dirs = [ + "../../utils/native", + "//utils/native/base/include/", + "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", + "//base/hiviewdfx/hisysevent/interfaces/native/innerkits/include", + ] +} +ohos_moduletest_suite("HiSysEventCPPTest") { + module_out_path = module_output_path + sources = [ + "HiSysEventCPPTest.cpp", + ] + deps = [ + "../../utils/native:utilskit", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//base/hiviewdfx/hisysevent/interfaces/native/innerkits:libhisysevent", + "//third_party/googletest:gtest_main", + "//utils/native/base:utils", + ] + configs = [ ":hilogtest_config" ] +} diff --git a/hiviewdfx/hisyseventtest/hisyseventcpptest/HiSysEventCPPTest.cpp b/hiviewdfx/hisyseventtest/hisyseventcpptest/HiSysEventCPPTest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..7978a88b0115320ea5b5a425c979efb83ae313b2 --- /dev/null +++ b/hiviewdfx/hisyseventtest/hisyseventcpptest/HiSysEventCPPTest.cpp @@ -0,0 +1,606 @@ +/* + * Copyright (C) 2021 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. + */ +#include "hilog/log.h" +#include + +#include "file_utils.h" +#include "hisysevent.h" + +using namespace testing; +using namespace testing::ext; +using namespace std; +using namespace OHOS::HiviewDFX; +namespace { +string g_key = "key"; +string g_reDiRectTimeout = "5"; +string g_hiLogRedirect = "/data/local/tmp/hilogredirect.log"; +} +class HiSysEventCPPTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +private: +}; +void HiSysEventCPPTest::SetUp() +{ + std::cout << "SetUp" << std::endl; + std::vector cmdret; + string cmd = "hilog -r"; + ExecCmdWithRet(cmd, cmdret); + cmd = "setprop persist.sys.hilog.debug.on false"; + ExecCmdWithRet(cmd, cmdret); +} +void HiSysEventCPPTest::TearDown() +{ + std::cout << "TearDown" << std::endl; + std::vector cmdret; + string cmd = "rm " + g_hiLogRedirect; + ExecCmdWithRet(cmd, cmdret); +} +void HiSysEventCPPTest::SetUpTestCase() +{ + std::cout << "SetUpTestCase" << std::endl; + std::vector cmdret; + string cmd = "mkdir /data/local/tmp/"; + ExecCmdWithRet(cmd, cmdret); +} +void HiSysEventCPPTest::TearDownTestCase() +{ + std::cout << "TearDownTestCase" << std::endl; +} +/** +* @tc.name HiSysEvent Native Write Interface Test, Reported When the KeyValue Is of the +* boolean Type and the bool Value Is False +* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0100 +* @tc.desc The keyvalue is of the boolean type and the bool value is false. +*/ +HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0100, Function|MediumTest|Level3) +{ + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0100 start" << endl; + bool result = false; + bool param = false; + string domain = OHOS::HiviewDFX::HiSysEvent::Domain::AAFWK; + OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT; + OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param); + RedirecthiLog(g_hiLogRedirect, g_reDiRectTimeout); + string fileinfo; + fileinfo = ReadFile(g_hiLogRedirect); + std::vector para = {"AAFWK", "eventNameDemo", "\"event_type_\":1", "\"key\":0"}; + if (!fileinfo.empty()) { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0100 file error" << std::endl; + } + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0100 end" << endl; +} +/** +* @tc.name HiSysEvent Native Write Interface Test, Reported When the KeyValue Is of +* the boolean Type and the bool Value Is False +* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0200 +* @tc.desc The keyvalue is of the boolean type and the bool value is true. +*/ +HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0200, Function|MediumTest|Level3) +{ + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0200 start" << endl; + bool result = false; + bool param = true; + string domain = OHOS::HiviewDFX::HiSysEvent::Domain::APPEXECFWK; + OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT; + OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param); + RedirecthiLog(g_hiLogRedirect, g_reDiRectTimeout); + string fileinfo = ""; + fileinfo = ReadFile(g_hiLogRedirect); + std::vector para = {"APPEXECFWK", "eventNameDemo", "\"event_type_\":1", "\"key\":1"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0200 file error" << std::endl; + } + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0200 end" << endl; +} +/** +* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Keyvalue of the Boolean List Type +* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0300 +* @tc.desc The value of keyvalue is a boolean list. +*/ +HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0300, Function|MediumTest|Level3) +{ + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0300 start" << endl; + bool result = false; + bool param = false; + std::vector test; + test.push_back(param); + string domain = OHOS::HiviewDFX::HiSysEvent::Domain::ACCOUNT; + OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT; + OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test); + RedirecthiLog(g_hiLogRedirect, g_reDiRectTimeout); + string fileinfo = ""; + fileinfo = ReadFile(g_hiLogRedirect); + std::vector para = {"ACCOUNT", "eventNameDemo", "\"event_type_\":1", "\"key\":[0]"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0300 file error" << std::endl; + } + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0300 end" << endl; +} +/** +* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Key Value of the Char Type +* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0400 +* @tc.desc The keyvalue is of the char type. +*/ +HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0400, Function|MediumTest|Level3) +{ + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0400 start" << endl; + bool result = false; + char param = 'a'; + string domain = OHOS::HiviewDFX::HiSysEvent::Domain::OTHERS; + OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT; + OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param); + RedirecthiLog(g_hiLogRedirect, g_reDiRectTimeout); + string fileinfo = ""; + fileinfo = ReadFile(g_hiLogRedirect); + std::vector para = {"OTHERS", "eventNameDemo", "\"event_type_\":1", "\"key\":97"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0400 file error" << std::endl; + } + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0400 end" << endl; +} +/** +* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Keyvalue of the Char List Type +* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0500 +* @tc.desc keyvalue is of the char list type. +*/ +HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0500, Function|MediumTest|Level3) +{ + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0500 start" << endl; + bool result = false; + char param = 'a'; + std::vector test; + test.push_back(param); + string domain = OHOS::HiviewDFX::HiSysEvent::Domain::WEARABLE; + OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT; + OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test); + RedirecthiLog(g_hiLogRedirect, g_reDiRectTimeout); + string fileinfo = ""; + fileinfo = ReadFile(g_hiLogRedirect); + std::vector para = {"WEARABLE", "eventNameDemo", "\"event_type_\":1", "\"key\":[97]"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0500 file error" << std::endl; + } + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0500 end" << endl; +} +/** +* @tc.name HiSysEvent Natvie Write Interface Test, Reported When the KeyValue Is of the Double Type +* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0600 +* @tc.desc The keyvalue is of the double type. +*/ +HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0600, Function|MediumTest|Level2) +{ + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0600 start" << endl; + bool result = false; + double param = 30949.374; + string domain = OHOS::HiviewDFX::HiSysEvent::Domain::WEARABLE_HARDWARE; + OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT; + OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param); + RedirecthiLog(g_hiLogRedirect, g_reDiRectTimeout); + string fileinfo = ""; + fileinfo = ReadFile(g_hiLogRedirect); + std::vector para = {"WEARABLEHW", "eventNameDemo", "\"event_type_\":1", "\"key\":30949.4"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0600 file error" << std::endl; + } + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0600 end" << endl; +} +/** +* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Keyvalue of the Char List Type +* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0700 +* @tc.desc keyvalue is of the char list type. +*/ +HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0700, Function|MediumTest|Level3) +{ + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0700 start" << endl; + bool result = false; + double param = 30949.374; + std::vector test; + test.push_back(param); + string domain = OHOS::HiviewDFX::HiSysEvent::Domain::USB; + OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT; + OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test); + RedirecthiLog(g_hiLogRedirect, g_reDiRectTimeout); + string fileinfo = ""; + fileinfo = ReadFile(g_hiLogRedirect); + std::vector para = {"USB", "eventNameDemo", "\"event_type_\":1", "\"key\":[30949.4]"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0700 file error" << std::endl; + } + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0700 end" << endl; +} +/** +* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Key Value of the Floating Type +* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0800 +* @tc.desc The keyvalue is of the float type. +*/ +HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0800, Function|MediumTest|Level3) +{ + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0800 start" << endl; + bool result = false; + float param = 230.47; + string domain = OHOS::HiviewDFX::HiSysEvent::Domain::UPDATE; + OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT; + OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param); + RedirecthiLog(g_hiLogRedirect, g_reDiRectTimeout); + string fileinfo = ""; + fileinfo = ReadFile(g_hiLogRedirect); + std::vector para = {"UPDATE", "eventNameDemo", "\"event_type_\":1", "\"key\":230.47"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0800 file error" << std::endl; + } + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0800 end" << endl; +} +/** +* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Keyvalue of the Char List Type +* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0900 +* @tc.desc keyvalue is of the char list type. +*/ +HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0900, Function|MediumTest|Level3) +{ + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0900 start" << endl; + bool result = false; + float param = 230.47; + std::vector test; + test.push_back(param); + string domain = OHOS::HiviewDFX::HiSysEvent::Domain::TELEPHONY; + OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT; + OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test); + RedirecthiLog(g_hiLogRedirect, g_reDiRectTimeout); + string fileinfo = ""; + fileinfo = ReadFile(g_hiLogRedirect); + std::vector para = {"TELEPHONY", "eventNameDemo", "\"event_type_\":1", "\"key\":[230.47]"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0900 file error" << std::endl; + } + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0900 end" << endl; +} +/** +* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Keyvalue of the Int Type +* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1000 +* @tc.desc The keyvalue is of the int type. +*/ +HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1000, Function|MediumTest|Level3) +{ + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1000 start" << endl; + bool result = false; + int param = 100; + string domain = OHOS::HiviewDFX::HiSysEvent::Domain::STARTUP; + OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT; + OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param); + RedirecthiLog(g_hiLogRedirect, g_reDiRectTimeout); + string fileinfo = ""; + fileinfo = ReadFile(g_hiLogRedirect); + std::vector para = {"STARTUP", "eventNameDemo", "\"event_type_\":1", "\"key\":100"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1000 file error" << std::endl; + } + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1000 end" << endl; +} +/** +* @tc.name HiSysEvent Natvie Write Interface Test, Reporting of the int List of KeyValues +* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1100 +* @tc.desc keyvalue is of the int list type. +*/ +HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1100, Function|MediumTest|Level3) +{ + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1100 start" << endl; + bool result = false; + int param = 100; + std::vector test; + test.push_back(param); + string domain = OHOS::HiviewDFX::HiSysEvent::Domain::SOURCE_CODE_TRANSFORMER; + OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT; + OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test); + RedirecthiLog(g_hiLogRedirect, g_reDiRectTimeout); + string fileinfo = ""; + fileinfo = ReadFile(g_hiLogRedirect); + std::vector para = {"SRCTRANSFORMER", "eventNameDemo", "\"event_type_\":1", "\"key\":[100]"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1100 file error" << std::endl; + } + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1100 end" << endl; +} +/** +* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Key Value of the Long Type +* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1200 +* @tc.desc The keyvalue is of the long type. +*/ +HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1200, Function|MediumTest|Level3) +{ + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1200 start" << endl; + bool result = false; + long param = 1000000; + string domain = OHOS::HiviewDFX::HiSysEvent::Domain::SENSORS; + OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT; + OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param); + RedirecthiLog(g_hiLogRedirect, g_reDiRectTimeout); + string fileinfo = ""; + fileinfo = ReadFile(g_hiLogRedirect); + std::vector para = {"SENSORS", "eventNameDemo", "\"event_type_\":1", "\"key\":1000000"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1200 file error" << std::endl; + } + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1200 end" << endl; +} +/** +* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the List of the Long Key Value +* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1300 +* @tc.desc The keyvalue is of the long list type. +*/ +HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1300, Function|MediumTest|Level3) +{ + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1300 start" << endl; + bool result = false; + long param = 1000000; + std::vector test; + test.push_back(param); + string domain = OHOS::HiviewDFX::HiSysEvent::Domain::SECURITY; + OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT; + OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test); + RedirecthiLog(g_hiLogRedirect, g_reDiRectTimeout); + string fileinfo = ""; + fileinfo = ReadFile(g_hiLogRedirect); + std::vector para = {"SECURITY", "eventNameDemo", "\"event_type_\":1", "\"key\":[1000000]"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1300 file error" << std::endl; + } + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1300 end" << endl; +} +/** +* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Key Value of the Short Type +* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1400 +* @tc.desc The keyvalue is of the short type. +*/ +HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1400, Function|MediumTest|Level3) +{ + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0250 start" << endl; + bool result = false; + short param = 10; + string domain = OHOS::HiviewDFX::HiSysEvent::Domain::ROUTER; + OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT; + OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param); + RedirecthiLog(g_hiLogRedirect, g_reDiRectTimeout); + string fileinfo = ""; + fileinfo = ReadFile(g_hiLogRedirect); + std::vector para = {"ROUTER", "eventNameDemo", "\"event_type_\":1", "\"key\":10"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1400 file error" << std::endl; + } + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1400 end" << endl; +} +/** +* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the List of Short Key Values +* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1500 +* @tc.desc The keyvalue is of the short list type. +*/ +HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1500, Function|MediumTest|Level3) +{ + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1500 start" << endl; + bool result = false; + short param = 10; + std::vector test; + test.push_back(param); + string domain = OHOS::HiviewDFX::HiSysEvent::Domain::POWERMGR; + OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC; + OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test); + RedirecthiLog(g_hiLogRedirect, g_reDiRectTimeout); + string fileinfo = ""; + fileinfo = ReadFile(g_hiLogRedirect); + std::vector para = {"POWERMGR", "eventNameDemo", "\"event_type_\":2", "\"key\":[10]"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1500 file error" << std::endl; + } + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1500 end" << endl; +} +/** +* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Key Value of the String Type +* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1600 +* @tc.desc The keyvalue is of the string type. +*/ +HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1600, Function|MediumTest|Level2) +{ + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1600 start" << endl; + bool result = false; + string param = "abc"; + string domain = OHOS::HiviewDFX::HiSysEvent::Domain::NOTIFICATION; + OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC; + OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param); + RedirecthiLog(g_hiLogRedirect, g_reDiRectTimeout); + string fileinfo = ""; + fileinfo = ReadFile(g_hiLogRedirect); + std::vector para = {"NOTIFICATION", "eventNameDemo", "\"event_type_\":2", "\"key\":\"abc\""}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1600 file error" << std::endl; + } + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1600 end" << endl; +} +/** +* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the List of Short Key Values +* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1700 +* @tc.desc The keyvalue is of the short list type. +*/ +HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1700, Function|MediumTest|Level3) +{ + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1700 start" << endl; + bool result = false; + string param = "abc"; + std::vector test; + test.push_back(param); + string domain = OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT; + OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::SECURITY; + OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test); + RedirecthiLog(g_hiLogRedirect, g_reDiRectTimeout); + string fileinfo = ""; + fileinfo = ReadFile(g_hiLogRedirect); + std::vector para = {"MULTIMODALINPUT", "eventNameDemo", "\"event_type_\":3", "\"key\":[\"abc\"]"}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1700 file error" << std::endl; + } + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1700 end" << endl; +} +/** +* @tc.name HiSysEvent Natvie Write Interface Test, Reporting the List of 20 List Parameters When the Key Value Is String +* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1800 +* @tc.desc The keyvalue is reported as a string list. There are 20 list parameters. +*/ +HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1800, Function|MediumTest|Level4) +{ + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0290 start" << endl; + bool result = false; + string param = "abc"; + std::vector test; + for (int i = 0; i < 20; i++) { + test.push_back(param); + } + string str = "\"key\":["; + for (int i = 0; i < 19; i++) { + str = str + "\"abc\","; + } + str = str + "\"abc\"]"; + GTEST_LOG_(INFO) << str << endl; + string domain = OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MEDIA; + OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::SECURITY; + OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test); + RedirecthiLog(g_hiLogRedirect, g_reDiRectTimeout); + string fileinfo = ""; + fileinfo = ReadFile(g_hiLogRedirect); + std::vector para = {"MULTIMEDIA", "eventNameDemo", "\"event_type_\":3", str}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1800 file error" << std::endl; + } + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1800 end" << endl; +} +/** +* @tc.name In the HiSysEvent Natvie Write interface test, 32 parameters are reported for each type of keyvalue. +* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_2000 +* @tc.desc The keyvalue parameter has 32 parameters for each type. +*/ +HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_2000, Function|MediumTest|Level3) +{ + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_2000 start" << endl; + bool result = false; + string param = "abc"; + string str = ""; + for (int i=0; i < 31; i++){ + str = str + "\"key\":\"abc\","; + } + str += "\"key\":\"abc\""; + string domain = OHOS::HiviewDFX::HiSysEvent::Domain::MSDP; + OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR; + OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, + g_key, param, g_key, param, g_key, param, g_key, param, g_key, param, g_key, param, + g_key, param, g_key, param, g_key, param, g_key, param, g_key, param, g_key, param, + g_key, param, g_key, param, g_key, param, g_key, param, g_key, param, g_key, param, + g_key, param, g_key, param, g_key, param, g_key, param, g_key, param, g_key, param, + g_key, param, g_key, param, g_key, param, g_key, param, g_key, param, g_key, param, + g_key, param, g_key, param); + RedirecthiLog(g_hiLogRedirect, g_reDiRectTimeout); + string fileinfo = ""; + fileinfo = ReadFile(g_hiLogRedirect); + std::vector para = {"MSDP", "eventNameDemo", "\"event_type_\":4", str}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_2000 file error" << std::endl; + } + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_2000 end" << endl; +} +/** +* @tc.name In the test of the HiSysEvent Natvie Write interface, the key value is a string of 256 characters. +* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_2200 +* @tc.desc The keyvalue is a string of 256 characters. +*/ +HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_2200, Function|MediumTest|Level3) +{ + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_2200 start" << endl; + bool result = false; + string param = ""; + for (int i = 0; i < 256; i++) { + param += "a"; + } + string domain = OHOS::HiviewDFX::HiSysEvent::Domain::LOCATION; + OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR; + OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param); + RedirecthiLog(g_hiLogRedirect, g_reDiRectTimeout); + string fileinfo = ""; + fileinfo = ReadFile(g_hiLogRedirect); + std::vector para = {"LOCATION", "eventNameDemo", "\"event_type_\":4", g_key, param}; + if (fileinfo != "") { + result = CheckInfo(para, fileinfo); + } else { + std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_2200 file error" << std::endl; + } + ASSERT_TRUE(result); + GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_2200 end" << endl; +} diff --git a/hiviewdfx/hisyseventtest/hisyseventcpptest/Test.json b/hiviewdfx/hisyseventtest/hisyseventcpptest/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..4d088617bd50bbf25a86736ae2076d1d1781e2ce --- /dev/null +++ b/hiviewdfx/hisyseventtest/hisyseventcpptest/Test.json @@ -0,0 +1,21 @@ +{ + "kits": [ + { + "push": [ + "HiSysEventCPPTest->/data/local/tmp/HiSysEventCPPTest" + ], + "type": "PushKit", + "post-push": [ + "chmod -R 777 /data/local/tmp/*" + ] + } + ], + "driver": { + "native-test-timeout": "120000", + "type": "CppTest", + "module-name": "HiSysEventCPPTest", + "runtime-hint": "1s", + "native-test-device-path": "/data/local/tmp" + }, + "description": "Configuration for HiSysEventCPPTest Tests" +} \ No newline at end of file diff --git a/hiviewdfx/utils/native/BUILD.gn b/hiviewdfx/utils/native/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..e2d7697a5860c0ef91a517b85658a3b8f272fb0f --- /dev/null +++ b/hiviewdfx/utils/native/BUILD.gn @@ -0,0 +1,38 @@ +# Copyright (C) 2021 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("//build/ohos.gni") +import("//test/xts/tools/build/suite.gni") + +############################################################################### +config("utils_config") { + visibility = [ ":*" ] + include_dirs = [ + "//third_party/cJSON/", + "//third_party/zlib/", + "//utils/native/base/", + ] +} + +sources_common = [ "file_utils.cpp" ] +ohos_static_library("utilskit") { + sources = sources_common + configs = [ ":utils_config" ] + + #external_deps = [ "hilog:libhilog" ] + deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//base/hiviewdfx/hiview/base:hiviewbase", + "//utils/native/base:utils", + ] +} diff --git a/hiviewdfx/utils/native/file_utils.cpp b/hiviewdfx/utils/native/file_utils.cpp new file mode 100755 index 0000000000000000000000000000000000000000..4c7e10671b33192d5793dae14592e696f170f7de --- /dev/null +++ b/hiviewdfx/utils/native/file_utils.cpp @@ -0,0 +1,205 @@ +/* + * Copyright (C) 2021 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. + */ +#ifndef TEST_COMMON_H +#define TEST_COMMON_H +#include "file_utils.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "include/securec.h" +#include "string_util.h" + +using namespace OHOS::HiviewDFX; +int ExecCmdWithRet(std::string cmd, std::vector &resvec) +{ + if (cmd.size() == 0) { + return 0; + } + + std::cout<< "cmd is " + cmd < cmdret; + ExecCmdWithRet(cmd, cmdret); +} + +void CmdRun(std::string cmd, std::string &result) +{ + std::vector cmdret; + int resultlen; + int i = 0; + std::string rst; + resultlen = ExecCmdWithRet(cmd, cmdret); + while (i < resultlen) { + rst = rst + cmdret[i]; + i = i + 1; + } + result = rst; +} + +void CleanCmd() +{ + std::string cmdResult; + std::string cleanCmd = "hilog -r"; + CmdRun(cleanCmd, cmdResult); + std::cout << cmdResult; +} + +std::string ExecuteCmd(std::string cmd) +{ + std::vector cmdret; + int resultlen; + int i = 0; + std::string rst; + resultlen = ExecCmdWithRet(cmd, cmdret); + while (i < resultlen) { + rst = rst + cmdret[i] + "\n"; + i = i + 1; + } + return rst; +} +void SaveCmdOutput(std::string cmd, std::string saveFile) +{ + std::fstream fstr(saveFile, std::ios::out); + std::string cmdRet = ExecuteCmd(cmd); + fstr << cmdRet; + fstr.close(); +} +void RedirecthiLog(std::string &hilogredirect, std::string &timeout) +{ + unsigned long i; + std::vector cmdret; + unsigned long cmdretlen; + std::string cmd = "rm " + hilogredirect; + cmdretlen = ExecCmdWithRet(cmd, cmdret); + for (i = 0; i < cmdretlen; i++) { + std::cout<" + hilogredirect; + std::cout< ¶, std::string info) +{ + if (info.empty()) { + return false; + } + std::vector splitStr; + StringUtil::SplitStr(info, "\n", splitStr, false, false); + unsigned long matchcnt; + bool result = false; + std::string eventinfoline; + std::cout<::iterator iter = splitStr.begin(); iter != splitStr.end(); ++iter) { + eventinfoline = std::string (iter->c_str()); + for (unsigned long i = 0; i < para.size(); i++) { + std::cout<= 0) { + matchcnt++; + } + } + std::cout<<"Expect1:"<= 0) { + len--; + } + if (len >= 0 && x[len] > y[len]) { + return false; + } + return true; +} + +int GetTxtLine(std::string filename) +{ + FILE *fd = fopen(filename.c_str(), "r"); + int count = 0; + if (fd != nullptr) { + while (!feof(fd)) { + if (fgetc(fd) == '\n') { + count++; + } + } + } + std::cout << count << std::endl; + if (fd != nullptr) { + fclose(fd); + } + return count; +} + +std::string ReadFile(std::string filename) +{ + std::ifstream ifile(filename); + std::ostringstream buf; + char ch; + if (ifile.fail()) { + std::cout<<"open file fail!"< +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +bool CheckInfo(std::vector ¶, std::string eventinfo); +int ExecCmdWithRet(std::string cmd, std::vector &resvec); +std::string ReadFile(std::string filename); +void RedirecthiLog(std::string &hilogredirect, std::string &timeout); +void ExeCmd(std::string cmd); +void CmdRun(std::string cmd, std::string &result); +std::string ExecuteCmd(std::string cmd); +bool CompareString(const std::string& x, const std::string& y); +int GetTxtLine(std::string filename); +std::string ReadFile(std::string filename); +void CleanCmd(); +std::string ReadOneLine(std::string m_path, char* rBuf, int n); +void SaveCmdOutput(std::string cmd, std::string saveFile); +#endif diff --git a/miscservices/BUILD.gn b/miscservices/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..06ca24ea3dd731235cb10ad1847ef8dad1d88a5d --- /dev/null +++ b/miscservices/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (C) 2021 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("//build/ohos_var.gni") +group("miscservices") { + testonly = true + if (is_standard_system) { + deps = [ "TimeTest_js:time_js_test" ] + } else { + deps = [ + "DownloadTest:download_hap", + "InputMethodTest:InputMethodTest_hap", + "pasteboard:testpasteboard_hap", + "screenlock:ScreenLockTest_hap", + "timer:testtimer_hap", + "wallpaper:wallpaperTest_hap", + ] + } +} diff --git a/miscservices/TimeTest_js/BUILD.gn b/miscservices/TimeTest_js/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..fa77275bf527c0fb48f517f4b5c237a9b2d18757 --- /dev/null +++ b/miscservices/TimeTest_js/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("time_js_test") { + test_hap_name = "TimeJSApiTest" + hap_source_path = "hap/entry-debug-rich-signed.hap" +} diff --git a/miscservices/TimeTest_js/Test.json b/miscservices/TimeTest_js/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..906fff7003b2690eb43b8a6d7c4299aa44e6fa47 --- /dev/null +++ b/miscservices/TimeTest_js/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for time js api Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "21600000", + "package": "ohos.acts.miscservices.timer", + "shell-timeout": "21600000" + }, + "kits": [ + { + "test-file-name": [ + "TimeJSApiTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/miscservices/TimeTest_js/hap/entry-debug-rich-signed.hap b/miscservices/TimeTest_js/hap/entry-debug-rich-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..385f247828955dfa48b770cc15d950ff4309a1f5 Binary files /dev/null and b/miscservices/TimeTest_js/hap/entry-debug-rich-signed.hap differ diff --git a/miscservices/TimeTest_js/project/entry/package.json b/miscservices/TimeTest_js/project/entry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..69a88e3b65423624fe7ea8b0f8beefcc62cc3d5f --- /dev/null +++ b/miscservices/TimeTest_js/project/entry/package.json @@ -0,0 +1 @@ +{} diff --git a/miscservices/TimeTest_js/project/entry/src/main/config.json b/miscservices/TimeTest_js/project/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..461aee4d91a106a6796ae41741e58d5c634982bb --- /dev/null +++ b/miscservices/TimeTest_js/project/entry/src/main/config.json @@ -0,0 +1,59 @@ +{ + "app": { + "bundleName": "ohos.acts.miscservices.timer", + "vendor": "acts", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.miscservices.timer", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "ohos.acts.miscservices.timer.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} diff --git a/miscservices/TimeTest_js/project/entry/src/main/js/default/app.js b/miscservices/TimeTest_js/project/entry/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..ffc56f10680b6d4065e6af0f764850ea915d48e9 --- /dev/null +++ b/miscservices/TimeTest_js/project/entry/src/main/js/default/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 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 default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/miscservices/TimeTest_js/project/entry/src/main/js/default/i18n/en-US.json b/miscservices/TimeTest_js/project/entry/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/miscservices/TimeTest_js/project/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/miscservices/TimeTest_js/project/entry/src/main/js/default/i18n/zh-CN.json b/miscservices/TimeTest_js/project/entry/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/miscservices/TimeTest_js/project/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/miscservices/TimeTest_js/project/entry/src/main/js/default/pages/index/index.css b/miscservices/TimeTest_js/project/entry/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/miscservices/TimeTest_js/project/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/miscservices/TimeTest_js/project/entry/src/main/js/default/pages/index/index.hml b/miscservices/TimeTest_js/project/entry/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/miscservices/TimeTest_js/project/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/miscservices/TimeTest_js/project/entry/src/main/js/default/pages/index/index.js b/miscservices/TimeTest_js/project/entry/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..6367b2fd449b83b5baa752177423dfceeb494451 --- /dev/null +++ b/miscservices/TimeTest_js/project/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2021 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 file from '@system.file' +import app from '@system.app' + +//import {Core, ExpectExtend, ReportExtend, InstrumentLog} from 'deccjsunit/index' +import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + const reportExtend = new ReportExtend(file) + // const instrumentLog = new InstrumentLog({ + // 'id': 'report' + // }) + core.addService('expect', expectExtend) + core.addService('report', reportExtend) + // core.addService('report', instrumentLog) + core.init() + // core.subscribeEvent('spec', instrumentLog) + // core.subscribeEvent('suite', instrumentLog) + // core.subscribeEvent('task', instrumentLog) + + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} diff --git a/miscservices/TimeTest_js/project/entry/src/main/js/test/List.test.js b/miscservices/TimeTest_js/project/entry/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..f018c90a0fdd72bdfe9bd716689fc7708043e553 --- /dev/null +++ b/miscservices/TimeTest_js/project/entry/src/main/js/test/List.test.js @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2021 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. + */ + +require('./Time.test.js') \ No newline at end of file diff --git a/miscservices/TimeTest_js/project/entry/src/main/js/test/Time.test.js b/miscservices/TimeTest_js/project/entry/src/main/js/test/Time.test.js new file mode 100644 index 0000000000000000000000000000000000000000..625c8433c32649b78c70e94a0cedf9a775daf1bf --- /dev/null +++ b/miscservices/TimeTest_js/project/entry/src/main/js/test/Time.test.js @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2021 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. + */ + +// @ts-nocheck +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' +import systemTime from '@ohos.systemTime' + +describe('TimeTest', function() { + console.log('start################################start'); + /** + * @tc.number SUB_systemTime_setTime_JS_API_0100 + * @tc.name Test systemTime.setTime + * @tc.desc Test systemTime_setTime API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('systemTime_setTime_test1', 0, async function (done) { + console.log("SUB_systemTime_setTime_JS_API_0100 start") + expect(1).assertLarger(0) + systemTime.setTime(1526003846000) + .then(data =>{ + console.log("setTime ===data " + data) + }).catch(error => { + console.log("setTime ===error " + error) + console.log("setTime ===data " + data) + + }); + console.log('SUB_systemTime_setTime_JS_API_0100 end'); + done() + }) + + /** + * @tc.number SUB_systemTime_setTime_JS_API_0200 + * @tc.name Test systemTime.setTime Invalid value + * @tc.desc Test systemTime_setTime API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('systemTime_setTime_test2', 0, async function (done) { + console.log("SUB_systemTime_setTime_JS_API_0200 start") + expect(1).assertLarger(0) + systemTime.setTime(-1) + .then(data => { + console.log("setTime ===data " + data) + + }).catch(error => { + console.log("setTime ===error " + error) + + }); + console.log('SUB_systemTime_setTime_JS_API_0200 end'); + done() + }) + + /** + * @tc.number SUB_systemTime_setTime_JS_API_0300 + * @tc.name Test systemTime.setTime3 + * @tc.desc Test systemTime_setTime API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('systemTime_setTime_test3', 0, async function (done) { + console.log("SUB_systemTime_setTime_JS_API_0300 start") + expect(1).assertLarger(0) + systemTime.setTime(1597156246000, (error, data) => { + console.log("setTime ===data: " + data); + console.log("setTime ===error: " + error); + }); + console.log('SUB_systemTime_setTime_JS_API_0300 end'); + done() + }) + + /** + * @tc.number SUB_systemTime_setTime_JS_API_0400 + * @tc.name Test systemTime.setTime4 Invalid value + * @tc.desc Test systemTime_setTime API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('systemTime_setTime_test4', 0, async function (done) { + console.log("SUB_systemTime_setTime_JS_API_0400 start") + expect(1).assertLarger(0) + systemTime.setTime(-1, (error, data) => { + console.log("setTime ===data: " + data); + console.log("setTime ===error: " + error); + }); + console.log('SUB_systemTime_setTime_JS_API_0400 end'); + done() + }) +}) \ No newline at end of file diff --git a/miscservices/TimeTest_js/project/entry/src/main/resources/base/element/string.json b/miscservices/TimeTest_js/project/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ec03196184773273c7a5af69fc92d81cd0d3889b --- /dev/null +++ b/miscservices/TimeTest_js/project/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "JstimeTest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/miscservices/TimeTest_js/project/entry/src/main/resources/base/media/icon.png b/miscservices/TimeTest_js/project/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/miscservices/TimeTest_js/project/entry/src/main/resources/base/media/icon.png differ diff --git a/multimedia/BUILD.gn b/multimedia/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..a9292308f9553cbe1144c5ef2484e30b8d215518 --- /dev/null +++ b/multimedia/BUILD.gn @@ -0,0 +1,47 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +group("multimedia") { + testonly = true + if (is_standard_system) { + deps = [ "audio/audio_js_standard:audio_manager_js_test" ] + } else { + deps = [ + #"audio/audio_hap_test:MediaAudio_test_hap", + #"audio/audiotubecore_hap_test:Audiotubecore_test_hap", + #"camera/camera_hap_test:camera_test_hap", + #"image/AVScannerKit_hap:avscanner_test_hap", + #"media/media_hap_test:media_test_hap", + ] + } +} + +#car +group("multimedia_ivi") { + testonly = true + deps = [] +} + +#tv +group("multimedia_intellitv") { + testonly = true + deps = [] +} + +#watch +group("multimedia_wearable") { + testonly = true + deps = [] +} diff --git a/multimedia/audio/audio_js_standard/BUILD.gn b/multimedia/audio/audio_js_standard/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..63dce971b40d49a2fc33aaf5204f09dc13e6e5a6 --- /dev/null +++ b/multimedia/audio/audio_js_standard/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("audio_manager_js_test") { + test_hap_name = "AudioManagerJsTest" + hap_source_path = "hap/entry-debug-rich-signed.hap" +} diff --git a/multimedia/audio/audio_js_standard/Test.json b/multimedia/audio/audio_js_standard/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..5dff9d155ebf3f8503617accd47ce4ca451d7cdb --- /dev/null +++ b/multimedia/audio/audio_js_standard/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for audio manager Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "21600000", + "package": "ohos.acts.multimedia.audio.function", + "shell-timeout": "21600000" + }, + "kits": [ + { + "test-file-name": [ + "AudioManagerJsTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/multimedia/audio/audio_js_standard/hap/entry-debug-rich-signed.hap b/multimedia/audio/audio_js_standard/hap/entry-debug-rich-signed.hap new file mode 100755 index 0000000000000000000000000000000000000000..9f875f974f29fc7ad6da92d74e451a1dd7c33eb3 Binary files /dev/null and b/multimedia/audio/audio_js_standard/hap/entry-debug-rich-signed.hap differ diff --git a/multimedia/audio/audio_js_standard/project/entry/src/main/config.json b/multimedia/audio/audio_js_standard/project/entry/src/main/config.json new file mode 100755 index 0000000000000000000000000000000000000000..eba0ed436c4133ee365d9fd1ae7aa157993d918f --- /dev/null +++ b/multimedia/audio/audio_js_standard/project/entry/src/main/config.json @@ -0,0 +1,59 @@ +{ + "app": { + "bundleName": "ohos.acts.multimedia.audio.function", + "vendor": "acts", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 4 + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.multimedia.audio.function", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "ohos.acts.multimedia.audio.function.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} diff --git a/multimedia/audio/audio_js_standard/project/entry/src/main/js/default/app.js b/multimedia/audio/audio_js_standard/project/entry/src/main/js/default/app.js new file mode 100755 index 0000000000000000000000000000000000000000..1042ce48dcb55db5df48244110bf77278996003c --- /dev/null +++ b/multimedia/audio/audio_js_standard/project/entry/src/main/js/default/app.js @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2021 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 device from '@system.device'; + +export default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/multimedia/audio/audio_js_standard/project/entry/src/main/js/default/i18n/en-US.json b/multimedia/audio/audio_js_standard/project/entry/src/main/js/default/i18n/en-US.json new file mode 100755 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/multimedia/audio/audio_js_standard/project/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/multimedia/audio/audio_js_standard/project/entry/src/main/js/default/i18n/zh-CN.json b/multimedia/audio/audio_js_standard/project/entry/src/main/js/default/i18n/zh-CN.json new file mode 100755 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/multimedia/audio/audio_js_standard/project/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/multimedia/audio/audio_js_standard/project/entry/src/main/js/default/pages/index/index.css b/multimedia/audio/audio_js_standard/project/entry/src/main/js/default/pages/index/index.css new file mode 100755 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/multimedia/audio/audio_js_standard/project/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/multimedia/audio/audio_js_standard/project/entry/src/main/js/default/pages/index/index.hml b/multimedia/audio/audio_js_standard/project/entry/src/main/js/default/pages/index/index.hml new file mode 100755 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/multimedia/audio/audio_js_standard/project/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/multimedia/audio/audio_js_standard/project/entry/src/main/js/default/pages/index/index.js b/multimedia/audio/audio_js_standard/project/entry/src/main/js/default/pages/index/index.js new file mode 100755 index 0000000000000000000000000000000000000000..0ee24b27cd17b79470c04ca0609a842056b1a236 --- /dev/null +++ b/multimedia/audio/audio_js_standard/project/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2021 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 file from '@system.file' +import app from '@system.app' +import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + const reportExtend = new ReportExtend(file) + core.addService('expect', expectExtend) + core.addService('report', reportExtend) + core.init() + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} \ No newline at end of file diff --git a/multimedia/audio/audio_js_standard/project/entry/src/main/js/test/AudioManager.test.js b/multimedia/audio/audio_js_standard/project/entry/src/main/js/test/AudioManager.test.js new file mode 100755 index 0000000000000000000000000000000000000000..27e0fbbd718f0e6985f6c496fe6368a5474211c9 --- /dev/null +++ b/multimedia/audio/audio_js_standard/project/entry/src/main/js/test/AudioManager.test.js @@ -0,0 +1,450 @@ +/* + * Copyright (C) 2021 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 audio from '@ohos.multimedia.audio'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' +describe('AudioManager.test.js', function () { + const audioManager = audio.getAudioManager(); + var maxVolume = 1; + var minVolume = 0; + var deviceTypeValue = null; + var deviceRoleValue = null; + + beforeAll(function () { + console.info('beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.'); + + }) + + beforeEach(function () { + console.info('beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.'); + + }) + afterEach(function () { + console.info('afterEach: Test case-level clearance conditions, which are executed after each test case is executed.'); + + }) + afterAll(function () { + console.info('afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed'); + + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_MANAGER_SetVolume_001 + * @tc.name : Set Audiomanager with volume type media 01 + * @tc.desc : Audiomanager SetVolume media-success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_AUDIO_MANAGER_SetVolume_001', 0, function () { + audioManager.setVolume(1, 12).then(function (data) { + console.info('Media setVolume successful promise'); + audioManager.getVolume(1).then(function (data) { + console.info('Media getVolume promise ' + data); + expect(data).assertEqual(12); + console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_SetVolume_001 : PASS'); + }); + }); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_MANAGER_SetVolume_002 + * @tc.name : Set Audiomanager with volume type ringtone 02 + * @tc.desc : Audiomanager SetVolume media-success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_AUDIO_MANAGER_SetVolume_002', 0, function () { + audioManager.setVolume(2, 11).then(function (data) { + console.info('Media setVolume successful promise '); + audioManager.getVolume(2).then(function (data) { + console.info('Media getVolume promise ' + data); + expect(data).assertEqual(11); + console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_SetVolume_002 : PASS'); + }); + }); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_MANAGER_SetVolume_003 + * @tc.name : Set Audiomanager with volume type media and callback + * @tc.desc : Audiomanager SetVolume media-success + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_AUDIO_MANAGER_SetVolume_003', 0, function () { + audioManager.setVolume(1, 10, (err, value) => { + if (err) { + console.error(`failed to set volume ${err.message}`); + return; + } + console.log(`Media setVolume successful callback`); + audioManager.getVolume(1, (err, value) => { + if (err) { + console.error(`failed to get volume ${err.message}`); + return; + } + console.log(`Media getVolume ${value}`); + expect(value).assertEqual(10); + console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_SetVolume_003 : PASS'); + }); + }); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_MANAGER_SetVolume_004 + * @tc.name : Set Audiomanager with volume type ringtone and callback + * @tc.desc : Audiomanager should set the volume as per the API and return it from Get API + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_AUDIO_MANAGER_SetVolume_004', 0, function () { + audioManager.setVolume(2, 13, (err, value) => { + if (err) { + console.error(`failed to set volume ${err.message}`); + return; + } + console.log(`Media setVolume successful callback`); + audioManager.getVolume(1, (err, value) => { + if (err) { + console.error(`failed to get volume ${err.message}`); + return; + } + console.log(`Media getVolume ${value}`); + expect(value).assertEqual(13); + console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_SetVolume_004 : PASS'); + }); + }); + }) + + + /* * + * @tc.number : SUB_MEDIA_AUDIO_MANAGER_SetVolume_005 + * @tc.name : Set Audiomanager with volume level beyond maxvolume + * @tc.desc : Audiomanager should return an error for setting the volume + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_AUDIO_MANAGER_SetVolume_005', 0, function () { + audioManager.setVolume(2, 16, (err, value) => { + if (err) { + console.error(`failed to set volume ${err.message}`); + return; + } + audioManager.getVolume(2, (err, value) => { + if (err) { + console.error(`failed to get volume ${err.message}`); + return; + } + console.log(`Media getVolume ${value}`); + if (value != 16) { + expect(true).assertTrue(); + console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_SetVolume_005 : PASS'); + } + }); + }); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_001 + * @tc.name : Check Audiomanager get max volume for media + * @tc.desc : Audiomanager get max volume + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_001', 0, function () { + audioManager.getMaxVolume(1).then(function (data) { + console.info('Media getMaxVolume promise ' + data); + expect(data).assertEqual(maxVolume); + console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_001 : PASS'); + }); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_002 + * @tc.name : Check Audiomanager get max volume for ringtone + * @tc.desc : Audiomanager get max volume-ringtone + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_002', 0, function () { + + audioManager.getMaxVolume(2).then(function (data) { + console.info('Media getMaxVolume promise ' + data); + expect(data).assertEqual(maxVolume); + console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_002 : PASS'); + }); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_003 + * @tc.name : Check Audiomanager get max volume for media with callback + * @tc.desc : Audiomanager get max volume + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_003', 0, function () { + audioManager.getMaxVolume(1, (err, value) => { + if (err) { + console.error(`failed to get volume ${err.message}`); + return; + } + console.log(`Media getMaxVolume ${value}`); + expect(value).assertEqual(maxVolume); + console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_003 : PASS'); + }); + }); + + /* * + * @tc.number : SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_004 + * @tc.name : Check Audiomanager get max volume for ringtone with callback + * @tc.desc : Audiomanager get max volume - rigtone + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_004', 0, function () { + audioManager.getMaxVolume(2, (err, value) => { + if (err) { + console.error(`failed to get volume ${err.message}`); + return; + } + console.log(`Media getMaxVolume ${value}`); + expect(value).assertEqual(maxVolume); + console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_GetMaxVolume_004 : PASS'); + }); + }); + + /* * + * @tc.number : SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_001 + * @tc.name : Check Audiomanager get min volume for media + * @tc.desc : Audiomanager get min volume- media + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_001', 0, function () { + audioManager.getMinVolume(1).then(function (data) { + console.info('Media getMinVolume promise ' + data); + expect(data).assertEqual(minVolume); + console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_001 : PASS'); + }); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_002 + * @tc.name : Check Audiomanager get min volume for ringtone + * @tc.desc : Audiomanager get min volume-ringtone + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_002', 0, function () { + audioManager.getMinVolume(2).then(function (data) { + console.info('Media getMinVolume promise ' + data); + expect(data).assertEqual(minVolume); + console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_002 : PASS'); + }); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_003 + * @tc.name : Check Audiomanager get min volume for media with callback + * @tc.desc : Audiomanager get min volume- media + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_003', 0, function () { + audioManager.getMinVolume(1, (err, value) => { + if (err) { + console.error(`failed to get volume ${err.message}`); + return; + } + console.log(`Media getMinVolume ${value}`); + expect(value).assertEqual(minVolume); + console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_003 : PASS'); + }); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_004 + * @tc.name : Check Audiomanager get min volume for ringtone + * @tc.desc : Audiomanager get min volume-ringtone + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_004', 0, function () { + audioManager.getMinVolume(2, (err, value) => { + if (err) { + console.error(`failed to get volume ${err.message}`); + return; + } + console.log(`Media getMinVolume ${value}`); + expect(value).assertEqual(minVolume); + console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_GetMinVolume_004 : PASS'); + }); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_MANAGER_Get_Devices_001 + * @tc.name : Check Audiomanager get devices with DEVICES_FLAG 01 + * @tc.desc : Audiomanager get device-positive return value + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_AUDIO_MANAGER_Get_Devices_001', 0, function () { + deviceRoleValue = null; + deviceTypeValue = null; + audioManager.getDevices(1, (err, value) => { + if (err) { + console.error(`failed to get devices ${err.message}`); + return; + } + console.log('getDevices output devices'); + value.forEach(displayDeviceProp); + if (deviceTypeValue != null && deviceRoleValue != null) { + expect(true).assertTrue(); + console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_Get Devices_001 : PASS'); + } + }); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_MANAGER_Get_Devices_002 + * @tc.name : Check Audiomanager get devices with DEVICES_FLAG 02 + * @tc.desc : Audiomanager get device-positive return value + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_AUDIO_MANAGER_Get_Devices_002', 0, function () { + deviceRoleValue = null; + deviceTypeValue = null; + audioManager.getDevices(2, (err, value) => { + if (err) { + console.error(`failed to get devices ${err.message}`); + return; + } + console.log('getDevices output devices'); + value.forEach(displayDeviceProp); + if (deviceTypeValue != null && deviceRoleValue != null) { + expect(true).assertTrue(); + console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_Get Devices_002 : PASS'); + } + }); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_MANAGER_Get_Devices_003 + * @tc.name : Check Audiomanager get devices with DEVICES_FLAG 03 + * @tc.desc : Audiomanager get device-positive return value + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_AUDIO_MANAGER_Get_Devices_003', 0, function () { + deviceRoleValue = null; + deviceTypeValue = null; + audioManager.getDevices(3, (err, value) => { + if (err) { + console.error(`failed to get devices ${err.message}`); + return; + } + console.log('getDevices All devices'); + value.forEach(displayDeviceProp); + if (deviceTypeValue != null && deviceRoleValue != null) { + expect(true).assertTrue(); + console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_Get Devices_003 : PASS'); + } + }); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_MANAGER_GetDevice_004 + * @tc.name : Check Audiomanager get devices with deviceflag value as 1 + * @tc.desc : Audiomanager get getdevices without callback + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_AUDIO_MANAGER_Get_Devices_004', 0, function () { + deviceRoleValue = null; + deviceTypeValue = null; + audioManager.getDevices(1).then(function (value) { + value.forEach(displayDeviceProp); + if (deviceTypeValue != null && deviceRoleValue != null) { + expect(true).assertTrue(); + console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_Get Devices_004 : PASS'); + } + }); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_MANAGER_GetDevice_005 + * @tc.name : Check Audiomanager get devices with deviceflag values as 2 + * @tc.desc : Audiomanager get getdevices without callback + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_AUDIO_MANAGER_Get_Devices_005', 0, function () { + deviceRoleValue = null; + deviceTypeValue = null; + audioManager.getDevices(2).then(function (value) { + value.forEach(displayDeviceProp); + if (deviceTypeValue != null && deviceRoleValue != null) { + expect(true).assertTrue(); + console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_Get Devices_005 : PASS'); + } + }); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_MANAGER_GetDevice_006 + * @tc.name : Check Audiomanager get devices with deviceflag values as 3 + * @tc.desc : Audiomanager get getdevices without callback + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_AUDIO_MANAGER_Get_Devices_006', 0, function () { + deviceRoleValue = null; + deviceTypeValue = null; + audioManager.getDevices(3).then(function (value) { + value.forEach(displayDeviceProp); + if (deviceTypeValue != null && deviceRoleValue != null) { + expect(true).assertTrue(); + console.info('testCase_SUB_MEDIA_AUDIO_MANAGER_Get Devices_006 : PASS'); + } + }); + }) + + function displayDeviceProp(value, index, array) { + console.log(`device role: ${value.deviceRole}`); + deviceRoleValue = value.deviceRole; + console.log(`device type: ${value.deviceType}`); + deviceTypeValue = value.deviceType; + } +}) \ No newline at end of file diff --git a/multimedia/audio/audio_js_standard/project/entry/src/main/js/test/AudioPlayer.test.js b/multimedia/audio/audio_js_standard/project/entry/src/main/js/test/AudioPlayer.test.js new file mode 100755 index 0000000000000000000000000000000000000000..23c02d63a142826f6262f89e30e817a76b29b9f6 --- /dev/null +++ b/multimedia/audio/audio_js_standard/project/entry/src/main/js/test/AudioPlayer.test.js @@ -0,0 +1,719 @@ +/* + * Copyright (c) 2021 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 media from '@ohos.multimedia.media'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' +describe('AudioPlayer.test.js', function () { + var audiosourcemp3 = 'file///build/testAudio/ff-16b-2c-44100hz.mp3'; + var audiosourcewav = 'file///build/testAudio/ff-16b-2c-44100hz.wav'; + var audiosourceaac = 'file///build/testAudio/ff-16b-2c-44100hz.aac'; + var audiosourceac3 = 'file///build/testAudio/ff-16b-2c-44100hz.ac3'; + var audiosourceaiff = 'file///build/testAudio/ff-16b-2c-44100hz.aiff'; + var audiosourceflac = 'file///build/testAudio/ff-16b-2c-44100hz.flac'; + var audiosourcem4a = 'file///build/testAudio/ff-16b-2c-44100hz.m4a'; + var audiosourcemp4 = 'file///build/testAudio/ff-16b-2c-44100hz.mp4'; + var audiosourceogg = 'file///build/testAudio/ff-16b-2c-44100hz.ogg'; + var audiosourceopus = 'file///build/testAudio/ff-16b-2c-44100hz.opus'; + var audiosourcets = 'file///build/testAudio/ff-16b-2c-44100hz.ts'; + var audiosourcewma = 'file///build/testAudio/ff-16b-2c-44100hz.wma'; + var docsource = 'file///build/testAudio/asc.doc'; + var wrongsource = 'file///abd'; + var audioPlayer = media.createAudioPlayer(); + var audioState; + var waitTimer; + + beforeAll(function () { + console.info('beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.'); + }) + + beforeEach(function () { + console.info('beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.'); + }) + + afterEach(function () { + console.info('afterEach: Test case-level clearance conditions, which are executed after each test case is executed.'); + audioPlayer.release(); + }) + + afterAll(function () { + console.info('afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed'); + }) + + console.info('Setting Callback'); + player.on('play', (err, action) => { + if (err) { + console.log(`err returned in play() callback`); + return; + } + console.log(`Play() callback is called`); + console.info('Current Player Status: ' + player.state); + console.info('Current Song duration: ' + player.duration); + console.log(`In play callback current time: ${player.currentTime}`); + console.info('Pause aac'); + player.pause(); + }); + + player.on('pause', (err, action) => { + if (err) { + console.log(`err returned in pause() callback`); + return; + } + console.log(`Pause() callback is called`); + }); + + player.on('stop', (err, action) => { + if (err) { + console.log(`err returned in stop() callback`); + return; + } + console.log(`Stop() callback is called`); + }); + + player.on('dataLoad', (err, action) => { + if (err) { + console.log(`err returned in dataLoad() callback`); + return; + } + console.log(`dataLoad callback is called, cuurent time: ${player.currentTime}`); + console.log(`Duration of the source: ${player.duration}`); + }); + + player.on('finish', (err, action) => { + if (err) { + console.log(`err returned in finish() callback`); + return; + } + console.log(`Player finish callback is called`); + }); + + player.on('timeUpdate', (err, action) => { + if (err) { + console.log(`err returned in timeUpdate() callback`); + return; + } + console.log(`In timeupdate callback current time: ${player.currentTime}`); + }); + + player.on('durationchange', (err, action) => { + if (err) { + console.log(`err returned in durationchange callback`); + return; + } + console.log(`Durationchange callback is called`); + }); + + player.on('error', (err, action) => { + console.error(`player error: ${err.code}`); + }); + + /* * + * @tc.number : SUB_MEDIA_PLAYER_Play_001 + * @tc.name : Set Audio Play 01 + * @tc.desc : Audio Play-Positive return value + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_Play_001', 0, function () { + audioPlayer.src = audiosourcemp3; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('playing'); + console.info('testCase_SUB_MEDIA_PLAYER_001 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_Play_002 + * @tc.name : Audio play 02 + * @tc.desc : Audio play-Error return value + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_Play_002', 0, function () { + audioPlayer.src = docsource; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertNotEqual('playing'); + console.info('testCase_SUB_MEDIA_PLAYER_Play_002 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_Play_003 + * @tc.name : Audio play 03 + * @tc.desc : Audio Play-Positive return value - wav + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_Play_003', 0, function () { + audioPlayer.src = audiosourcewav; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('playing'); + console.info('SUB_MEDIA_PLAYER_Play_003 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_Play_004 + * @tc.name : Audio play 04 + * @tc.desc : Audio Play-Positive return value - acc + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_Play_004', 0, function () { + audioPlayer.src = audiosourceaac; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('playing'); + console.info('testCase_SUB_MEDIA_PLAYER_Play_004 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_Play_005 + * @tc.name : Audio play 05 + * @tc.desc : Audio Play-Positive return value - ac3 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_Play_005', 0, function () { + audioPlayer.src = audiosourceac3; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('playing'); + console.info('testCase_SUB_MEDIA_PLAYER_Play_005 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_Play_006 + * @tc.name : Audio play 06 + * @tc.desc : Audio Play-Positive return value - aiff + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_Play_006', 0, function () { + audioPlayer.src = audiosourceaiff; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('playing'); + console.info('testCase_SUB_MEDIA_PLAYER_Play_006 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_Play_007 + * @tc.name : Audio play 07 + * @tc.desc : Audio Play-Positive return value - m4a + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_Play_007', 0, function () { + audioPlayer.src = audiosourcem4a; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('playing'); + console.info('testCase_SUB_MEDIA_PLAYER_Play_007 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_Play_008 + * @tc.name : Audio play 08 + * @tc.desc : Audio Play-Positive return value - mp4 + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_Play_008', 0, function () { + audioPlayer.src = audiosourcemp4; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('playing'); + console.info('testCase_SUB_MEDIA_PLAYER_Play_008 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_Play_009 + * @tc.name : Audio play 09 + * @tc.desc : Audio Play-Positive return value - ogg + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_Play_009', 0, function () { + audioPlayer.src = audiosourceogg; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('playing'); + console.info('testCase_SUB_MEDIA_PLAYER_Play_009 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_Play_010 + * @tc.name : Audio play 10 + * @tc.desc : Audio Play-Positive return value - opus + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_Play_010', 0, function () { + audioPlayer.src = audiosourceopus; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('playing'); + console.info('testCase_SUB_MEDIA_PLAYER_Play_010 : PASS'); + + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_Play_011 + * @tc.name : Audio play 11 + * @tc.desc : Audio Play-Positive return value - ts + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_Play_011', 0, function () { + audioPlayer.src = audiosourcets; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('playing'); + console.info('testCase_SUB_MEDIA_PLAYER_Play_011 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_Play_012 + * @tc.name : Audio play 12 + * @tc.desc : Audio Play-Positive return value - wma + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_Play_012', 0, function () { + audioPlayer.src = audiosourcewma; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('playing'); + console.info('testCase_SUB_MEDIA_PLAYER_Play_012 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_Play_013 + * @tc.name : Audio play 13 + * @tc.desc : Audio Play-Positive return value - flac + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_Play_013', 0, function () { + audioPlayer.src = audiosourceflac; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('playing'); + console.info('testCase_SUB_MEDIA_PLAYER_Play_013 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_Pause_001 + * @tc.name : Audio Pause 01 + * @tc.desc : Audio Pause-Positive return value + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_Pause_001', 0, function () { + audioPlayer.src = audiosourcemp3; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('playing'); + audioPlayer.pause(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('paused'); + console.info('testCase_SUB_MEDIA_PLAYER_Pause_001 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_Pause_002 + * @tc.name : Audio Pause 02 + * @tc.desc : Audio Pause-Error return value + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_Pause_002', 0, function () { + audioPlayer.stop(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('stopped'); + audioPlayer.pause(); + audioState = audioPlayer.state; + expect(audioState).assertNotEqual('paused'); + console.info('testCase_SUB_MEDIA_PLAYER_Pause_002 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_Stop_001 + * @tc.name : Audio Stop 01 + * @tc.desc : Audio Stop-Positive return value + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_Stop_001', 0, function () { + audioPlayer.src = audiosourcemp3; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('playing'); + audioPlayer.stop(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('stopped'); + console.info('testCase_SUB_MEDIA_PLAYER_Stop_001 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_Stop_002 + * @tc.name : Audio Stop 02 + * @tc.desc : Audio Stop-Error return value + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_Stop_002', 0, function () { + audioPlayer.stop(); + audioState = audioPlayer.state; + expect(audioState).assertNotEqual('stopped'); + console.info('testCase_SUB_MEDIA_PLAYER_Stop_002 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_Seek_001 + * @tc.name : Audio Seek 01 + * @tc.desc : Audio Seek-Positive return value + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_Seek_001', 0, function () { + audioPlayer.src = audiosourcemp3; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('playing'); + var timeUs = 10; + audioPlayer.seek(timeUs); + var getCurrentTime = audioPlayer.currenTime; + if (getCurrentTime >= seekTime) { + console.info("current position after seek : " + getCurrentTime); + console.info('testCase_SUB_MEDIA_PLAYER_Seek_001 : PASS'); + } + else + console.info('Error'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_Seek_002 + * @tc.name : Audio Seek 02 + * @tc.desc : Audio Seek-error return value + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_Seek_002', 0, function () { + audioPlayer.stop(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('stopped'); + audioPlayer.seek(10); + var getCurrentTime = audioPlayer.currenTime; + expect(getCurrentTime).assertNotEqual(10); + console.info('testCase_SUB_MEDIA_PLAYER_Seek_002 : PASS'); + + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_Seek_003 + * @tc.name : Audio Seek 03 + * @tc.desc : Audio Seek-Negative return value + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_Seek_003', 0, function () { + audioPlayer.src = audiosourcemp3; + audioPlayer.play(); + audioState = audioPlayer.state; + setTimeout(waitTimer, 2); + expect(audioState).assertEqual('playing'); + audioPlayer.seek(-10); + var getCurrentTime = audioPlayer.currenTime; + expect(getCurrentTime).assertNotEqual(-10); + console.info('testCase_SUB_MEDIA_PLAYER_Seek_003 : PASS'); + + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_Seek_004 + * @tc.name : Audio Seek 04 + * @tc.desc : Audio Seek-out of range for the media its playing + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_Seek_004', 0, function () { + audioPlayer.src = audiosourcemp3; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('playing'); + audioPlayer.seek(16000); + var getCurrentTime = audioPlayer.currenTime; + expect(getCurrentTime).assertNotEqual(16000); + console.info('testCase_SUB_MEDIA_PLAYER_Seek_004 : PASS'); + + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_Playback_status_001 + * @tc.name : Audio Playback status 01 + * @tc.desc : Audio Playback status-positive return value + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_Playback_status_001', 0, function () { + audioPlayer.src = audiosourcemp3; + audioPlayer.play(); + audioState = audioPlayer.state; + setTimeout(waitTimer, 2); + expect(audioState).assertEqual('playing'); + console.info('testCase_SUB_MEDIA_PLAYER_Playback_status_001 : PASS'); + + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_EnableLooping_001 + * @tc.name : Audio EnableLooping 01 + * @tc.desc : Audio Enable Looping after play + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_EnableLooping_001', 0, function () { + audioPlayer.src = audiosourcemp3; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('playing'); + audioPlayer.loop = true; + expect(audioPlayer.loop).assertEqual(true); + console.info('testCase_SUB_MEDIA_PLAYER_EnableLooping_001 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_EnableLooping_002 + * @tc.name : Audio EnableLooping 02 + * @tc.desc : Audio EnableLooping- Enable Loop before play + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_EnableLooping_002', 0, function () { + audioPlayer.src = audiosourcemp3; + audioPlayer.loop = true; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('playing'); + expect(audioPlayer.loop).assertEqual(true); + console.info('testCase_SUB_MEDIA_PLAYER_EnableLooping_002 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_EnableLooping_003 + * @tc.name : Audio EnableLooping 03 + * @tc.desc : Audio EnableLooping-Disable Loop + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_EnableLooping_003', 0, function () { + audioPlayer.src = audiosourcemp3; + audioPlayer.loop = true; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('playing'); + audioPlayer.loop = false; + expect(audioPlayer.loop).assertEqual(false); + console.info('testCase_SUB_MEDIA_PLAYER_EnableLooping_003 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_SetVolume_001 + * @tc.name : Audio SetVolume 01 + * @tc.desc : Audio SetVolume-Positive return value + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_SetVolume_001', 0, function () { + audioPlayer.src = audiosourcemp3; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('playing'); + audioPlayer.volume = 0.5; + expect(audioPlayer.volume).assertEqual(0.5); + console.info('testCase_SUB_MEDIA_PLAYER_SetVolume_001 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_SetVolume_002 + * @tc.name : Audio SetVolume 02 + * @tc.desc : Audio SetVolume-Mute + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_SetVolume_002', 0, function () { + audioPlayer.src = audiosourcemp3; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('playing'); + audioPlayer.volume = 0; + expect(setVolume).assertEqual(audioPlayer.volume); + console.info('testCase_SUB_MEDIA_PLAYER_SetVolume_002 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_SetVolume_003 + * @tc.name : Audio SetVolume 03 + * @tc.desc : Audio SetVolume-Max + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_SetVolume_003', 0, function () { + audioPlayer.src = audiosourcemp3; + audioPlayer.play(); + audioState = audioPlayer.state; + setTimeout(waitTimer, 2); + expect(audioState).assertEqual('playing'); + audioPlayer.volume = 1; + expect(audioPlayer.volume).assertEqual(1); + console.info('testCase_SUB_MEDIA_PLAYER_SetVolume_003 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_SetVolume_004 + * @tc.name : Audio SetVolume 04 + * @tc.desc : Audio SetVolume-Out of range + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_SetVolume_004', 0, function () { + audioPlayer.src = audiosourcemp3; + audioPlayer.play(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('playing'); + audioPlayer.volume = 2; + expect(audioPlayer.volume).assertNotEqual(2); + console.info('testCase_SUB_MEDIA_PLAYER_SetVolume_004 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_SetVolume_005 + * @tc.name : Audio SetVolume 05 + * @tc.desc : Audio SetVolume-negative range + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_SetVolume_005', 0, function () { + audioPlayer.src = audiosourcemp3; + audioPlayer.play(); + audioState = audioPlayer.state; + audioPlayer.volume = -1; + expect(audioPlayer.volume).assertNotEqual(-1); + console.info('testCase_SUB_MEDIA_PLAYER_SetVolume_005 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_GetCurrentTime_001 + * @tc.name : Audio GetCurrentTime 01 + * @tc.desc : Audio GetCurrentTime-Play and get current time + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_GetCurrentTime_001', 0, function () { + audioPlayer.src = audiosourcemp3; + audioPlayer.play(); + audioState = audioPlayer.state; + setTimeout(waitTimer, 20); + expect(audioState).assertEqual('playing'); + var getCurrentTime = audioPlayer.currentTime; + expect(getCurrentTime).assertEqual(20); + console.info('testCase_SUB_MEDIA_PLAYER_GetCurrentTime_001 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_GetCurrentTime_002 + * @tc.name : Audio GetCurrentTime 02 + * @tc.desc : Audio GetCurrentTime- Error, get current time when nothing is playing. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_GetCurrentTime_002', 0, function () { + audioPlayer.stop(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('stopped'); + var getCurrentTime = audioPlayer.currentTime; + expect(getCurrentTime).assertNotEqual(0); + console.info('testCase_SUB_MEDIA_PLAYER_GetCurrentTime_002 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_GetDuration_001 + * @tc.name : Audio GetDuration 01 + * @tc.desc : Audio GetDuration-Play and get duration. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_GetDuration_001', 0, function () { + audioPlayer.src = audiosourcemp3; + audioPlayer.play(); + audioState = audioPlayer.state; + setTimeout(waitTimer, 2); + expect(audioState).assertEqual('playing'); + var getDuration = audioPlayer.duration; + expect(getDuration).assertEqual(200); + console.info('testCase_SUB_MEDIA_PLAYER_GetDuration_001 : PASS'); + }) + + /* * + * @tc.number : SUB_MEDIA_PLAYER_GetDuration_002 + * @tc.name : Audio GetDuration 02 + * @tc.desc : Audio GetDuration- Error, get duration time when nothing is playing. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_MEDIA_PLAYER_GetDuration_002', 0, function () { + audioPlayer.stop(); + audioState = audioPlayer.state; + expect(audioState).assertEqual('stopped'); + var getDuration = audioPlayer.duration; + expect(getDuration).assertNotEqual(0); + console.info('testCase_SUB_MEDIA_PLAYER_GetDuration_002 : PASS'); + }) +}) \ No newline at end of file diff --git a/multimedia/audio/audio_js_standard/project/entry/src/main/js/test/List.test.js b/multimedia/audio/audio_js_standard/project/entry/src/main/js/test/List.test.js new file mode 100755 index 0000000000000000000000000000000000000000..8f03c948b37228a207b1f46f90385fed429dcfe2 --- /dev/null +++ b/multimedia/audio/audio_js_standard/project/entry/src/main/js/test/List.test.js @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2021 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. + */ + +require('./AudioManager.test.js') \ No newline at end of file diff --git a/multimedia/audio/audio_js_standard/project/entry/src/main/resources/base/element/string.json b/multimedia/audio/audio_js_standard/project/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..d405647b90183b99fb4e15025a9fe12c85c495d4 --- /dev/null +++ b/multimedia/audio/audio_js_standard/project/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/multimedia/audio/audio_js_standard/project/entry/src/main/resources/base/media/icon.png b/multimedia/audio/audio_js_standard/project/entry/src/main/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/audio/audio_js_standard/project/entry/src/main/resources/base/media/icon.png differ diff --git a/powermgr/BUILD.gn b/powermgr/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..984d80d7306e6b9746c1ad62c7406d00ae0d0364 --- /dev/null +++ b/powermgr/BUILD.gn @@ -0,0 +1,20 @@ +# Copyright (C) 2021 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("//build/ohos_var.gni") +group("powermgr") { + testonly = true + + if (is_standard_system) { + deps = [ "powermgrbattery:powermgr_battery_test" ] + } +} diff --git a/powermgr/powermgrbattery/BUILD.gn b/powermgr/powermgrbattery/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..7e3ebee3c5790b6bcbeca2508cc61b204445efab --- /dev/null +++ b/powermgr/powermgrbattery/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("powermgr_battery_test") { + test_hap_name = "Powermgrbatterytest" + hap_source_path = "hap/entry-debug-rich-signed.hap" +} diff --git a/powermgr/powermgrbattery/Test.json b/powermgr/powermgrbattery/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..af388ea56a38a474e1133322646b07172df9e569 --- /dev/null +++ b/powermgr/powermgrbattery/Test.json @@ -0,0 +1,19 @@ +{ + "description": "Configuration for powermgr battery Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "21600000", + "package": "com.example.mybatteryapp", + "shell-timeout": "21600000" + }, + "kits": [ + { + "test-file-name": [ + "Powermgrbatterytest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} + diff --git a/powermgr/powermgrbattery/hap/entry-debug-rich-signed.hap b/powermgr/powermgrbattery/hap/entry-debug-rich-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..7856dec6a9f63129f7683075f24bcf8fe22f81d4 Binary files /dev/null and b/powermgr/powermgrbattery/hap/entry-debug-rich-signed.hap differ diff --git a/powermgr/powermgrbattery/project/.gitignore b/powermgr/powermgrbattery/project/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..ebdd23d29a08bffe35d1c4f0a21b058393fd9dba --- /dev/null +++ b/powermgr/powermgrbattery/project/.gitignore @@ -0,0 +1,14 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx diff --git a/powermgr/powermgrbattery/project/entry/.gitignore b/powermgr/powermgrbattery/project/entry/.gitignore new file mode 100755 index 0000000000000000000000000000000000000000..3543521e9fef8e7322940a87c2b45dd0061b0f45 --- /dev/null +++ b/powermgr/powermgrbattery/project/entry/.gitignore @@ -0,0 +1 @@ +/build diff --git a/powermgr/powermgrbattery/project/entry/package.json b/powermgr/powermgrbattery/project/entry/package.json new file mode 100755 index 0000000000000000000000000000000000000000..69a88e3b65423624fe7ea8b0f8beefcc62cc3d5f --- /dev/null +++ b/powermgr/powermgrbattery/project/entry/package.json @@ -0,0 +1 @@ +{} diff --git a/powermgr/powermgrbattery/project/entry/src/main/config.json b/powermgr/powermgrbattery/project/entry/src/main/config.json new file mode 100755 index 0000000000000000000000000000000000000000..4f9c4310070b6884dcc790d9acb39793ba046ca0 --- /dev/null +++ b/powermgr/powermgrbattery/project/entry/src/main/config.json @@ -0,0 +1,59 @@ +{ + "app": { + "bundleName": "com.example.mybatteryapp", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.mybatteryapp", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "com.example.mybatteryapp.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} diff --git a/powermgr/powermgrbattery/project/entry/src/main/js/default/app.js b/powermgr/powermgrbattery/project/entry/src/main/js/default/app.js new file mode 100755 index 0000000000000000000000000000000000000000..f796f6a0d8dde8b67d055b283776f27d4d06ac0f --- /dev/null +++ b/powermgr/powermgrbattery/project/entry/src/main/js/default/app.js @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2021 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 device from '@system.device'; + +export default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/powermgr/powermgrbattery/project/entry/src/main/js/default/i18n/en-US.json b/powermgr/powermgrbattery/project/entry/src/main/js/default/i18n/en-US.json new file mode 100755 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/powermgr/powermgrbattery/project/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/powermgr/powermgrbattery/project/entry/src/main/js/default/i18n/zh-CN.json b/powermgr/powermgrbattery/project/entry/src/main/js/default/i18n/zh-CN.json new file mode 100755 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/powermgr/powermgrbattery/project/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/powermgr/powermgrbattery/project/entry/src/main/js/default/pages/index/index.css b/powermgr/powermgrbattery/project/entry/src/main/js/default/pages/index/index.css new file mode 100755 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/powermgr/powermgrbattery/project/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/powermgr/powermgrbattery/project/entry/src/main/js/default/pages/index/index.hml b/powermgr/powermgrbattery/project/entry/src/main/js/default/pages/index/index.hml new file mode 100755 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/powermgr/powermgrbattery/project/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/powermgr/powermgrbattery/project/entry/src/main/js/default/pages/index/index.js b/powermgr/powermgrbattery/project/entry/src/main/js/default/pages/index/index.js new file mode 100755 index 0000000000000000000000000000000000000000..281c79d403db4376e0eca14346608521a28f69b8 --- /dev/null +++ b/powermgr/powermgrbattery/project/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2021 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 file from '@system.file' +import app from '@system.app' + +//import {Core, ExpectExtend, ReportExtend, InstrumentLog} from 'deccjsunit/index' +import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + const reportExtend = new ReportExtend(file) +// const instrumentLog = new InstrumentLog({ +// 'id': 'report' +// }) + core.addService('expect', expectExtend) + core.addService('report', reportExtend) +// core.addService('report', instrumentLog) + core.init() +// core.subscribeEvent('spec', instrumentLog) +// core.subscribeEvent('suite', instrumentLog) +// core.subscribeEvent('task', instrumentLog) + + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} \ No newline at end of file diff --git a/powermgr/powermgrbattery/project/entry/src/main/js/test/List.test.js b/powermgr/powermgrbattery/project/entry/src/main/js/test/List.test.js new file mode 100755 index 0000000000000000000000000000000000000000..57db8a3bcec40736ecce0e8117ed6447a7b04019 --- /dev/null +++ b/powermgr/powermgrbattery/project/entry/src/main/js/test/List.test.js @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2021 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. + */ +require('./battery_unit.test.js') \ No newline at end of file diff --git a/powermgr/powermgrbattery/project/entry/src/main/js/test/battery_unit.test.js b/powermgr/powermgrbattery/project/entry/src/main/js/test/battery_unit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..f313ea06cad6ef48fb35fefe2a6944b2d4f366c9 --- /dev/null +++ b/powermgr/powermgrbattery/project/entry/src/main/js/test/battery_unit.test.js @@ -0,0 +1,264 @@ +/* + * Copyright (C) 2021 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 app from '@system.app' +import Context from '@ohos.napi_context' +import batteryInfo from '@ohos.batteryInfo'; +import brightness from '@ohos.brightness'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('appInfoTest', function () { + console.log("*************Battery Unit Test Begin*************"); + /** + * @tc.number battery_manager_js_0100 + * @tc.name battery_soc_test + * @tc.desc Battery acquisition kit + */ + it('battery_soc_test', 0, function () { + var batterySoc = batteryInfo.batterySOC; + console.info('batterySoc = ' + batterySoc); + expect(batterySoc >= -1 && batterySoc <= 100).assertEqual('1') + }) + + /** + * @tc.number battery_manager_js_0200 + * @tc.name charging_status_test + * @tc.desc Battery charging kit + */ + it('charging_status_test', 0, function () { + var chargingStatus = batteryInfo.chargingStatus; + console.info('chargingStatus = ' + chargingStatus); + expect(chargingStatus >= 0 && chargingStatus <= 4).assertEqual('1') + }) + + /** + * @tc.number battery_manager_js_0300 + * @tc.name health_status_test + * @tc.desc Get Battery Health Get KIT + */ + it('health_status_test', 0, function () { + var healthStatus = batteryInfo.healthStatus; + console.info('healthStatus = ' + healthStatus); + expect(healthStatus >= 0 && healthStatus <= 6).assertEqual('1') + }) + + /** + * @tc.number battery_manager_js_0400 + * @tc.name plugged_type_test + * @tc.desc Obtaining the USB Connection Type KIT + */ + it('plugged_type_test', 0, function () { + var pluggedType = batteryInfo.pluggedType; + console.info('pluggedType = ' + pluggedType); + expect(pluggedType >= 0 && pluggedType <= 4).assertEqual('1') + }) + + /** + * @tc.number battery_manager_js_0500 + * @tc.name voltage_test + * @tc.desc Obtaining the Voltage Interface KIT + */ + it('voltage_test', 0, function () { + var voltage = batteryInfo.voltage; + console.info('voltage = ' + voltage); + expect(voltage >= -1).assertEqual('1') + }) + + /** + * @tc.number battery_manager_js_0600 + * @tc.name technology_test + * @tc.desc Obtaining the Battery Technology Interface KIT + */ + it('technology_test', 0, function () { + var technology = batteryInfo.technology; + console.info('technology = ' + technology); + expect(0).assertEqual('0') + }) + + /** + * @tc.number battery_manager_js_0700 + * @tc.name battery_temperature_test + * @tc.desc BatteryTemperature values Interface Test + */ + it('battery_temperature_test', 0, function () { + var batteryTemperature = batteryInfo.batteryTemperature; + console.info('batteryTemperature = ' + batteryTemperature); + expect(batteryTemperature <= 100).assertEqual('1') + }) + + /** + * @tc.number battery_manager_js_0800 + * @tc.name enum_health_state_test_unknown + * @tc.desc BatteryHealthState values Interface Test + */ + it('enum_health_state_test_unknown', 0, function () { + var batteryHealthState = batteryInfo.BatteryHealthState.UNKNOWN; + console.info('batteryHealthState = ' + batteryHealthState); + expect(batteryHealthState == 0).assertEqual('1') + }) + + /** + * @tc.number battery_manager_js_0900 + * @tc.name enum_health_state_test_good + * @tc.desc BatteryHealthState values Interface Test + */ + it('enum_health_state_test_good', 0, function () { + var batteryHealthState = batteryInfo.BatteryHealthState.GOOD; + console.info('batteryHealthState = ' + batteryHealthState); + expect(batteryHealthState == 1).assertEqual('1') + }) + + /** + * @tc.number battery_manager_js_1000 + * @tc.name enum_health_state_test_overheat + * @tc.desc BatteryHealthState values Interface Test + */ + it('enum_health_state_test_overheat', 0, function () { + var batteryHealthState = batteryInfo.BatteryHealthState.OVERHEAT; + console.info('batteryHealthState = ' + batteryHealthState); + expect(batteryHealthState == 2).assertEqual('1') + }) + + /** + * @tc.number battery_manager_js_1100 + * @tc.name enum_health_state_test_overvoltage + * @tc.desc BatteryHealthState values Interface Test + */ + it('enum_health_state_test_overvoltage', 0, function () { + var batteryHealthState = batteryInfo.BatteryHealthState.OVERVOLTAGE; + console.info('batteryHealthState = ' + batteryHealthState); + expect(batteryHealthState == 3).assertEqual('1') + }) + + /** + * @tc.number battery_manager_js_1200 + * @tc.name enum_health_state_test_cold + * @tc.desc BatteryHealthState values Interface Test + */ + it('enum_health_state_test_cold', 0, function () { + var batteryHealthState = batteryInfo.BatteryHealthState.COLD; + console.info('batteryHealthState = ' + batteryHealthState); + expect(batteryHealthState == 4).assertEqual('1') + }) + + /** + * @tc.number battery_manager_js_1300 + * @tc.name enum_health_state_test_dead + * @tc.desc BatteryHealthState values Interface Test + */ + it('enum_health_state_test_dead', 0, function () { + var batteryHealthState = batteryInfo.BatteryHealthState.DEAD; + console.info('batteryHealthState = ' + batteryHealthState); + expect(batteryHealthState == 5).assertEqual('1') + }) + + /** + * @tc.number battery_manager_js_1400 + * @tc.name enum_charge_state_test_none + * @tc.desc BatteryChargeState values Interface Test + */ + it('enum_charge_state_test_none', 0, function () { + var batteryChargeState = batteryInfo.BatteryChargeState.NONE; + console.info('batteryChargeState = ' + batteryChargeState); + expect(batteryChargeState == 0).assertEqual('1') + }) + + /** + * @tc.number battery_manager_js_1500 + * @tc.name enum_charge_state_test_enable + * @tc.desc BatteryChargeState values Interface Test + */ + it('enum_charge_state_test_enable', 0, function () { + var batteryChargeState = batteryInfo.BatteryChargeState.ENABLE; + console.info('batteryChargeState = ' + batteryChargeState); + expect(batteryChargeState == 1).assertEqual('1') + }) + + /** + * @tc.number battery_manager_js_1600 + * @tc.name enum_charge_state_test_disable + * @tc.desc BatteryChargeState values Interface Test + */ + it('enum_charge_state_test_disable', 0, function () { + var batteryChargeState = batteryInfo.BatteryChargeState.DISABLE; + console.info('batteryChargeState = ' + batteryChargeState); + expect(batteryChargeState == 2).assertEqual('1') + }) + + /** + * @tc.number battery_manager_js_1700 + * @tc.name enum_charge_state_test_full + * @tc.desc BatteryChargeState values Interface Test + */ + it('enum_charge_state_test_full', 0, function () { + var batteryChargeState = batteryInfo.BatteryChargeState.FULL; + console.info('batteryChargeState = ' + batteryChargeState); + expect(batteryChargeState == 3).assertEqual('1') + }) + + /** + * @tc.number battery_manager_js_1800 + * @tc.name enum_plugged_type_test_none + * @tc.desc BatteryPluggedType values Interface Test + */ + it('enum_plugged_type_test_none', 0, function () { + var batteryPluggedType = batteryInfo.BatteryPluggedType.NONE; + console.info('batteryPluggedType = ' + batteryPluggedType); + expect(batteryPluggedType == 0).assertEqual('1') + }) + + /** + * @tc.number battery_manager_js_1900 + * @tc.name enum_plugged_type_test_ac + * @tc.desc BatteryPluggedType values Interface Test + */ + it('enum_plugged_type_test_ac', 0, function () { + var batteryPluggedType = batteryInfo.BatteryPluggedType.AC; + console.info('batteryPluggedType = ' + batteryPluggedType); + expect(batteryPluggedType == 1).assertEqual('1') + }) + + /** + * @tc.number battery_manager_js_2000 + * @tc.name enum_plugged_type_test_usb + * @tc.desc BatteryPluggedType values Interface Test + */ + it('enum_plugged_type_test_usb', 0, function () { + var batteryPluggedType = batteryInfo.BatteryPluggedType.USB; + console.info('batteryPluggedType = ' + batteryPluggedType); + expect(batteryPluggedType == 2).assertEqual('1') + }) + + /** + * @tc.number battery_manager_js_2100 + * @tc.name enum_plugged_type_test_wireless + * @tc.desc BatteryPluggedType values Interface Test + */ + it('enum_plugged_type_test_wireless', 0, function () { + var batteryPluggedType = batteryInfo.BatteryPluggedType.WIRELESS; + console.info('batteryPluggedType = ' + batteryPluggedType); + expect(batteryPluggedType == 3).assertEqual('1') + }) + + /** + * @tc.number battery_manager_js_2200 + * @tc.name brightness_test + * @tc.desc Set Value Interface Test + */ + it('brightness_test', 0, function () { + brightness.setValue(10); + expect(0).assertEqual('0') + }) +}) diff --git a/powermgr/powermgrbattery/project/entry/src/main/resources/base/element/string.json b/powermgr/powermgrbattery/project/entry/src/main/resources/base/element/string.json new file mode 100755 index 0000000000000000000000000000000000000000..128f809780629b1f43c9bed19002fd9240021d84 --- /dev/null +++ b/powermgr/powermgrbattery/project/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyBatteryApp" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/powermgr/powermgrbattery/project/entry/src/main/resources/base/media/icon.png b/powermgr/powermgrbattery/project/entry/src/main/resources/base/media/icon.png new file mode 100755 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/powermgr/powermgrbattery/project/entry/src/main/resources/base/media/icon.png differ diff --git a/runtest.sh b/runtest.sh new file mode 100755 index 0000000000000000000000000000000000000000..969060e6de5ef18163969689c60da2993fedd3cd --- /dev/null +++ b/runtest.sh @@ -0,0 +1,187 @@ +#!/bin/bash + +# Copyright (C) 2021 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. + +set -e + +usage() +{ + echo + echo "USAGE" + echo " ./runtest.sh device=IP:PORT serial=[SERIAL_NUMBER] [module=MODULE_NAME] [test=TEST] [runonly=RUN_ONLY]" + echo " First, you must be execute stf/start.bat in the windows which connected a device." + echo " target_platform : TARGET_PLATFORM the target platform, such as phone or ivi; Default to phone" + echo " device : IP:PORT the host ip:port of the connected device." + echo " module : MODULE_NAME the module name to run. Run all modules by default." + echo " test : TEST_NAME the test name to run. Run all tests by default. This should be a FULL-QUALIFIED className or methodName." + echo " runonly : RUN_ONLY TRUE=not build, only runtest; FALSE=build and runtest. FALSE by default." + echo + exit 1 +} + +parse_cmdline() +{ + echo parse_cmdline:$@ + SCRIPT_DIR=$(cd $(dirname $0); pwd) + BUILD_SCRIPT=${SCRIPT_DIR}/build.sh + BASE_HOME=${SCRIPT_DIR}/../../.. + OUT_DIR=${SCRIPT_DIR}/../../../out + TARGET_ARCH=arm64 + TARGET_PLATFORM=all + BUILD_VARIANT=release + MODULE_NAME="" + DEVICE_SN="" + TEST_NAME="" + RUN_ONLY=FALSE + BUILD_PARAM="" + ACTS_HOME=$SCRIPT_DIR/../../../out/$BUILD_VARIANT/suites/acts + MODULE_INFO_FILE=$SCRIPT_DIR/../../../out/$BUILD_VARIANT/suites/acts/testcases/module_info.list + export PATH=${BASE_HOME}/prebuilts/python/linux-x86/3.8.5/bin:$PATH + BUILD_PARAM="$BUILD_PARAM target_arch=$TARGET_ARCH variant=$BUILD_VARIANT" + + while [ -n "$1" ] + do + var="$1" + OPTIONS=$(echo ${var%%=*}) + PARAM=$(echo ${var#*=}) + case "$OPTIONS" in + target_platform) TARGET_PLATFORM="$PARAM" + BUILD_PARAM="$BUILD_PARAM target_platform=$TARGET_PLATFORM" + ;; + module) MODULE_NAME="$PARAM" + BUILD_PARAM="$BUILD_PARAM suite=$MODULE_NAME" + ;; + test) TEST_NAME="$PARAM" + ;; + device) DEVICE_SN="$DEVICE_SN;$PARAM" + ;; + runonly) RUN_ONLY=$(echo $PARAM |tr [a-z] [A-Z]) + ;; + *) usage + break;; + esac + shift + done + if [ "$DEVICE_SN" == "" ];then + usage + fi +} + +do_make() +{ + cd $BASE_HOME + echo "================================" + echo "start to build" + echo "$BUILD_SCRIPT $BUILD_PARAM" + echo "================================" + + echo BUILD_PARAM= $BUILD_PARAM + $BUILD_SCRIPT $BUILD_PARAM + if [ "$?" != 0 ]; then + echo -e "\033[31mbuild error!\033[0m" + exit 1 + fi +} + +get_testmodule_name() +{ + BUILD_TARGET_NAME=$1 + # map from build_target name to actual testmodule name + test_module_name="" + OLD_IFS=$IFS + IFS=$'\n' + for line in $(cat $MODULE_INFO_FILE); do + VAR1=$(echo $line |awk -F ' ' '{print $1}') + VAR2=$(echo $line |awk -F ' ' '{print $2}') + if [ "$BUILD_TARGET_NAME" == "$VAR1" ] ; then + test_module_name=$VAR2 + break + fi + done + IFS=$OLD_IFS + echo $test_module_name +} + +run_test_with_xdevice() +{ + TC_PATH=$ACTS_HOME/testcases + RES_PATH=$ACTS_HOME/resource/ + REPORT_PATH=$ACTS_HOME/xdevice_reports/$(date "+%Y.%m.%d-%H.%M.%S") + python -m easy_install --quiet $ACTS_HOME/tools/xdevice-0.0.0.tar.gz + python -m easy_install --quiet $ACTS_HOME/tools/xdevice-extension-0.0.0.tar.gz + + run_arguments="run acts -tcpath $TC_PATH -respath $RES_PATH -rp $REPORT_PATH" + if [ ! -z "$MODULE_NAME" ]; then + run_arguments="$run_arguments -l $1" + fi + if [ ! -z "$TEST_NAME" ]; then + TEST_LIST_FILE=$ACTS_HOME/include_tests + echo "$TEST_NAME" > $TEST_LIST_FILE + run_arguments="$run_arguments -ta test-file-include-filter:$TEST_LIST_FILE" + fi + if [ ! -z "$DEVICE_SN" ]; then + run_arguments="$run_arguments $(echo $DEVICE_SN | sed 's/;/-sn /')" + fi + + echo $run_arguments + cd $ACTS_HOME + python -m xdevice "$run_arguments" + + return $? +} + +run_test() +{ + cd $BASE_HOME + + MAPPED_MODULE_NAME=$MODULE_NAME + # map from build_target name to actual testmodule name + if [ ! -z "$MODULE_NAME" ]; then + MAPPED_MODULE_NAME=$(get_testmodule_name $MODULE_NAME $ACTS_HOME) + if [ ! -z "$MAPPED_MODULE_NAME" ]; then + echo -e "\033[32mTest module name of build_target "$MODULE_NAME is" "$MAPPED_MODULE_NAME"\033[0m" + else + echo -e "\033[31mTest module "$MODULE_NAME" dose not exist!\033[0m" + exit 1 + fi + fi + + JSON_CONFIG_FILE=$ACTS_HOME/testcases/$MAPPED_MODULE_NAME.json + ret_code=0 + if [ -f "$JSON_CONFIG_FILE" ]; then + echo -e "\033[32mRun $MAPPED_MODULE_NAME with xdevice ...\033[0m" + run_test_with_xdevice $MAPPED_MODULE_NAME + ret_code=$? + elif [ -z "$MODULE_NAME" ]; then + echo -e "\033[32mRun all modules with xdevice ...\033[0m" + run_test_with_xdevice + ret_code=$? + else + echo -e "\033[31mNon-xdevice module in acts!\033[0m" + exit 1 + fi + + if [ "$ret_code" != "0" ]; then + echo -e "\033[31mFailed to run test, ret=$ret_code\033[0m" + exit 1 + fi +} + +parse_cmdline $@ +if [ "$RUN_ONLY" == FALSE ];then + do_make +fi +mkdir -p $OUT_DIR/$BUILD_VARIANT/suites/acts/resource/tools +run_test +exit 0 diff --git a/security/BUILD.gn b/security/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..13fbe5e1aa6601eea7d01e39e7440f7f2b8886d1 --- /dev/null +++ b/security/BUILD.gn @@ -0,0 +1,29 @@ +# Copyright (C) 2021 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("//build/ohos_var.gni") +import("//test/xts/tools/build/suite.gni") + +group("security") { + testonly = true + if (is_standard_system) { + deps = [ + "authentication_standard/deviceauth_p2p:DeviceauthP2PFunctionCPPTest", + "permission/permissionkitcpp:PermissionKitFunctionCPPTest", + "permission/permissionkitcpp:PermissionKitPerformanceCPPTest", + "permission/permissionkitcpp:PermissionKitReliabilityCPPTest", + ] + } else { + deps = + [ "permission/zpermissioninfoswitch:zpermissioninfoswitchFunctionTest" ] + } +} diff --git a/startup/BUILD.gn b/startup/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..19d2286ae281b3c5077fddab70b9314f5336807b --- /dev/null +++ b/startup/BUILD.gn @@ -0,0 +1,23 @@ +# Copyright (C) 2021 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("//build/ohos_var.gni") + +group("startup") { + testonly = true + if (is_standard_system) { + deps = [ + "startup_standard:startup_js_test", + ] + } +} diff --git a/startup/startup_standard/BUILD.gn b/startup/startup_standard/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..1b976d21ebbdba57e1ba04f83f46987883167b9c --- /dev/null +++ b/startup/startup_standard/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("startup_js_test") { + test_hap_name = "StartupJSApiTest" + hap_source_path = "hap/entry-debug-rich-signed.hap" +} diff --git a/startup/startup_standard/Test.json b/startup/startup_standard/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..89affa085b3ffbd25039357839dc52a85e5f2dc1 --- /dev/null +++ b/startup/startup_standard/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for startup js api Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "21600000", + "package": "ohos.acts.startup.js.function", + "shell-timeout": "21600000" + }, + "kits": [ + { + "test-file-name": [ + "StartupJSApiTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/startup/startup_standard/entry/package.json b/startup/startup_standard/entry/package.json new file mode 100755 index 0000000000000000000000000000000000000000..69a88e3b65423624fe7ea8b0f8beefcc62cc3d5f --- /dev/null +++ b/startup/startup_standard/entry/package.json @@ -0,0 +1 @@ +{} diff --git a/startup/startup_standard/entry/src/main/config.json b/startup/startup_standard/entry/src/main/config.json new file mode 100755 index 0000000000000000000000000000000000000000..515387c7f04325e792f1b75364c0962039a4638d --- /dev/null +++ b/startup/startup_standard/entry/src/main/config.json @@ -0,0 +1,59 @@ +{ + "app": { + "bundleName": "ohos.acts.startup.js.function", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.startup.js.function", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "ohos.acts.startup.js.function.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} diff --git a/startup/startup_standard/entry/src/main/js/default/app.js b/startup/startup_standard/entry/src/main/js/default/app.js new file mode 100755 index 0000000000000000000000000000000000000000..363f2555b1badec9fec342a93141db084083fcb8 --- /dev/null +++ b/startup/startup_standard/entry/src/main/js/default/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 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 default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/startup/startup_standard/entry/src/main/js/default/i18n/en-US.json b/startup/startup_standard/entry/src/main/js/default/i18n/en-US.json new file mode 100755 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/startup/startup_standard/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/startup/startup_standard/entry/src/main/js/default/i18n/zh-CN.json b/startup/startup_standard/entry/src/main/js/default/i18n/zh-CN.json new file mode 100755 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/startup/startup_standard/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/startup/startup_standard/entry/src/main/js/default/pages/index/index.js b/startup/startup_standard/entry/src/main/js/default/pages/index/index.js new file mode 100755 index 0000000000000000000000000000000000000000..6367b2fd449b83b5baa752177423dfceeb494451 --- /dev/null +++ b/startup/startup_standard/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2021 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 file from '@system.file' +import app from '@system.app' + +//import {Core, ExpectExtend, ReportExtend, InstrumentLog} from 'deccjsunit/index' +import {Core, ExpectExtend, ReportExtend} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + const reportExtend = new ReportExtend(file) + // const instrumentLog = new InstrumentLog({ + // 'id': 'report' + // }) + core.addService('expect', expectExtend) + core.addService('report', reportExtend) + // core.addService('report', instrumentLog) + core.init() + // core.subscribeEvent('spec', instrumentLog) + // core.subscribeEvent('suite', instrumentLog) + // core.subscribeEvent('task', instrumentLog) + + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} diff --git a/startup/startup_standard/entry/src/main/js/test/DeviceInfoJsUnit.test.js b/startup/startup_standard/entry/src/main/js/test/DeviceInfoJsUnit.test.js new file mode 100755 index 0000000000000000000000000000000000000000..f2adcbf50072912cfd56f60e0e3647572f06bcb1 --- /dev/null +++ b/startup/startup_standard/entry/src/main/js/test/DeviceInfoJsUnit.test.js @@ -0,0 +1,1315 @@ +/* + * Copyright (C) 2021 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. + */ + +// @ts-nocheck +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' +import deviceinfo from '@ohos.deviceInfo' + +describe('DeviceInfoTest', function () { + console.info('start################################start'); + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0100 + * @tc.name testGetDeviceType01 + * @tc.desc Get a string representing the device type. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_001', 0, function () { + console.info('device_info_test_001 start'); + var deviceTypeInfo = deviceinfo.deviceType; + var ret = false; + console.info('AceApplication onCreate startup para getDeviceType ' + deviceTypeInfo); + expect(deviceTypeInfo).assertEqual('default') + if (deviceTypeInfo !== null) { + ret = true; + } + expect(ret).assertTrue() + console.info('device_info_test_001 : PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0200 + * @tc.name testGetManufacture01 + * @tc.desc Get the manufacture name represented by a string. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_002', 0, function () { + console.info('device_info_test_002 start'); + var manufactureInfo = deviceinfo.manufacture; + var ret = false; + if (manufactureInfo !== null){ + ret = true; + } + console.info('the value of the deviceType is :' + manufactureInfo); + expect(ret).assertTrue(); + console.info('device_info_test_002 :PASS'); + }) + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0300 + * @tc.name testGetProductBrand01 + * @tc.desc Get the product brand represented by a string. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_003', 0, function () { + console.info('testGetProductBrand01 start'); + var brandInfo = deviceinfo.brand; + var ret = false; + if (brandInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo brand is :' + brandInfo); + expect(ret).assertTrue(); + console.info('testGetProductBrand01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0400 + * @tc.name testGetMarketName01 + * @tc.desc Get the external product family name represented by a string. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_004', 0, function () { + console.info('testGetMarketName01 start') + var marketNameInfo = deviceinfo.marketName; + var ret = false; + console.info('the value of the deviceinfo marketName is :' + marketNameInfo); + if(marketNameInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + console.info('testGetMarketName01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0500 + * @tc.name testGetProductSeries01 + * @tc.desc Get the product series represented by a string. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_005', 0, function () { + console.info('testGetProductSeries01 start'); + var productSeriesInfo = deviceinfo.productSeries; + var ret = false; + if(productSeriesInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo productSeries is :' + productSeriesInfo); + expect(ret).assertTrue(); + console.info('testGetProductSeries01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0600 + * @tc.name testGetProductModel01 + * @tc.desc Get the internal software sub-model represented by a string. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_006', 0, function () { + console.info('testGetProductModel01 start'); + var productModelInfo = deviceinfo.productModel; + var ret = false; + if(productModelInfo !== null){ + ret =true; + } + console.info('the value of the deviceinfo productModel is :' + productModelInfo); + expect(ret).assertTrue(); + console.info('testGetProductModel01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0700 + * @tc.name testGetSoftwareModel01 + * @tc.desc Get the internal software sub-model represented by a string. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_007', 0, function () { + console.info('testGetSoftwareModel01 start'); + var softwareModelInfo = deviceinfo.softwareModel; + var ret = false; + if(softwareModelInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo softwareModel is :' + softwareModelInfo); + expect(ret).assertTrue(); + console.info('testGetSoftwareModel01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0800 + * @tc.name testGetHardWareModel01 + * @tc.desc Get the hardware version represented by a string. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_008', 0, function () { + console.info('testGetHardWareModel01 start'); + var hardwareModelInfo = deviceinfo.hardwareModel; + var ret = false; + if(hardwareModelInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo hardwareModel is :' + hardwareModelInfo); + expect(ret).assertTrue(); + console.info('testGetHardWareModel01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0900 + * @tc.name testGetHardWareProfile01 + * @tc.desc Get the hardware profile represented by a string. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_009', 0, function () { + console.info('testGetHardWareProfile01 start'); + var hardwareProfileInfo = deviceinfo.hardwareProfile; + var ret = false; + if(hardwareProfileInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo hardwareProfile is :' + hardwareProfileInfo); + expect(ret).assertTrue(); + console.info('testGetHardWareProfile01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0110 + * @tc.name testGetSerial01 + * @tc.desc Get the device serial number represented by a string. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_010', 0, function () { + console.info('testGetSerial01 start'); + var serialInfo = deviceinfo.serial; + var ret = false; + if(serialInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo serial is :' + serialInfo); + expect(ret).assertTrue(); + console.info('testGetSerial01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0120 + * @tc.name testGetBootLoaderVersion01 + * @tc.desc Get the bootloader version number represented by a string. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_011', 0, function () { + console.info('testGetBootLoaderVersion01 start'); + var bootloaderVersionInfo = deviceinfo.bootloaderVersion; + var ret = false; + if(bootloaderVersionInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo bootloaderVersion is :' + bootloaderVersionInfo); + expect(ret).assertTrue(); + console.info('testGetBootLoaderVersion01 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0130 + * @tc.name testGetabiList01 + * @tc.desc Get the instruction set supported by the system. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_012', 0, function () { + console.info('testGetabiList01 start'); + var abiListInfo = deviceinfo.abiList; + var ret = false; + if(abiListInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo abiList is :' + abiListInfo); + expect(ret).assertTrue(); + console.info('testGetabiList01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0140 + * @tc.name testGetabiList01 + * @tc.desc Get the security patch level represented by a string. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_013', 0, function () { + console.info('testGetSecurityPatchTag01 start'); + var securityPatchTagInfo = deviceinfo.securityPatchTag; + var ret = false; + if(securityPatchTagInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo securityPatchTag is :' + securityPatchTagInfo); + expect(ret).assertTrue(); + console.info('testGetSecurityPatchTag01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0150 + * @tc.name testGetabiList01 + * @tc.desc Get the version number visible to users represented by a string. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_014', 0, function () { + console.info('testGetDisplayVersion01 start'); + var displayVersionInfo = deviceinfo.displayVersion; + var ret = false; + if(displayVersionInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo displayVersion is :' + displayVersionInfo); + expect(ret).assertTrue(); + console.info('testGetDisplayVersion01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0160 + * @tc.name testGetIncrementalVersion01 + * @tc.desc Get the difference version number represented by a string. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_015', 0, function () { + console.info('testGetIncrementalVersion01 start'); + var incrementalVersionInfo = deviceinfo.incrementalVersion; + var ret = false; + if(incrementalVersionInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo incrementalVersion is :' + incrementalVersionInfo); + expect(ret).assertTrue(); + console.info('testGetIncrementalVersion01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0170 + * @tc.name testGetOSReleaserType01 + * @tc.desc Get the OS release type. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_016', 0, function () { + console.info('testGetOSReleaserType01 start'); + var osReleaseTypeInfo = deviceinfo.osReleaseType; + var ret = false; + if(osReleaseTypeInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo osReleaseType is :' + osReleaseTypeInfo); + expect(ret).assertTrue(); + console.info('testGetOSReleaserType01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0180 + * @tc.name testGetOSFullName01 + * @tc.desc Get the operating system full name. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_017', 0, function () { + console.info('testGetOSFullName01 start'); + var osFullNameInfo = deviceinfo.osFullName; + var ret = false; + if(osFullNameInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo osFullName is :' + osFullNameInfo); + expect(ret).assertTrue(); + console.info('testGetOSFullName01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0190 + * @tc.name testGetMajorVersion01 + * @tc.desc Get the major (M) version number, which increases with any updates to the overall architecture. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_018', 0, function () { + console.info('testGetMajorVersion01 start'); + var majorVersionInfo = deviceinfo.majorVersion; + var ret = false; + if(majorVersionInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo majorVersion is :' + majorVersionInfo); + expect(ret).assertTrue(); + console.info('testGetMajorVersion01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0210 + * @tc.name testGetSeniorVersion01 + * @tc.desc Get the senior (S) version number, which increases with any updates to the partial. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_019', 0, function () { + console.info('testGetSeniorVersion01 start'); + var seniorVersionInfo = deviceinfo.seniorVersion; + var ret = false; + if(seniorVersionInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo seniorVersion is :' + seniorVersionInfo); + expect(ret).assertTrue(); + console.info('testGetSeniorVersion01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0220 + * @tc.name testGetFeatureVersion01 + * @tc.desc Get the feature (F) version number, which increases with any planned new features. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_020', 0, function () { + console.info('testGetFeatureVersion01 start'); + var featureVersionInfo = deviceinfo.featureVersion; + var ret = false; + if(featureVersionInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo featureVersion is :' + featureVersionInfo); + expect(ret).assertTrue(); + console.info('testGetFeatureVersion01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0230 + * @tc.name testGetBuildVersion01 + * @tc.desc Get the build (B) version number, which increases with each new development build. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_021', 0, function () { + console.info('testGetBuildVersion01 start'); + var buildVersionInfo = deviceinfo.buildVersion; + var ret = false; + if(buildVersionInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo buildVersion is :' + buildVersionInfo); + expect(ret).assertTrue(); + console.info('testGetBuildVersion01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0240 + * @tc.name testGetSdkApiVersion01 + * @tc.desc Get the API version number. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_022', 0, function () { + console.info('testGetSdkApiVersion01 start'); + var sdkApiVersionInfo = deviceinfo.sdkApiVersion; + var ret = false; + if(sdkApiVersionInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo sdkApiVersion is :' + sdkApiVersionInfo); + expect(ret).assertTrue(); + console.info('testGetSdkApiVersion01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0250 + * @tc.name testGetFirstApiVersion01 + * @tc.desc Get the first API version number. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_023', 0, function () { + console.info('testGetFirstApiVersion01 start') + var firstApiVersionInfo = deviceinfo.firstApiVersion; + var ret = true; + if(firstApiVersionInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo firstApiVersion is :' + firstApiVersionInfo); + expect(ret).assertTrue(); + console.info('testGetFirstApiVersion01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0260 + * @tc.name testGetVersionId01 + * @tc.desc Get the version ID number. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_024', 0, function () { + console.info('testGetVersionId01 start'); + var versionIdInfo = deviceinfo.versionId; + var ret = false; + if(versionIdInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo versionId is :' + versionIdInfo); + expect(ret).assertTrue(); + console.info('testGetVersionId01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0270 + * @tc.name testGetBuildType01 + * @tc.desc Get the different build types of the same baseline code. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_025', 0, function () { + console.info('testGetBuildType01 start'); + var buildTypeInfo = deviceinfo.buildType; + var ret = false; + if(buildTypeInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo buildType is :' + buildTypeInfo); + expect(ret).assertTrue(); + console.info('testGetBuildType01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0280 + * @tc.name testGetBuildUser01 + * @tc.desc Get the different build user of the same baseline code. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_026', 0, function () { + console.info('testGetBuildUser01 start'); + var buildUserInfo = deviceinfo.buildUser; + var ret = true; + if(buildUserInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo buildUser is :' + buildUserInfo); + expect(ret).assertTrue(); + console.info('testGetBuildUser01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0290 + * @tc.name testGetBuildHost01 + * @tc.desc Get the different build host of the same baseline code. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_027', 0, function () { + console.info('testGetBuildHost01 start'); + var buildHostInfo = deviceinfo.buildHost; + var ret = false; + if(buildHostInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo buildHost is :' + buildHostInfo); + expect(ret).assertTrue(); + console.info('testGetBuildHost01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0310 + * @tc.name testGetBuildTime01 + * @tc.desc Get the the build time. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_028', 0, function () { + console.info('testGetBuildTime01 start'); + var buildTimeInfo = deviceinfo.buildTime; + var ret = false; + if(buildTimeInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo buildTime is :' + buildTimeInfo); + expect(ret).assertTrue(); + console.info('testGetBuildTime01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0320 + * @tc.name testGetBuildRootHash01 + * @tc.desc Get the version hash. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_029', 0, function () { + console.info('testGetBuildRootHash01 start'); + var buildRootHashInfo = deviceinfo.buildRootHash; + var ret = false; + if(buildRootHashInfo !== null){ + ret = true; + } + console.info('the value of the deviceinfo buildRootHash is :' + buildRootHashInfo); + expect(ret).assertTrue(); + console.info('testGetBuildRootHash01 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0330 + * @tc.name testGetDeviceType02 + * @tc.desc Get a string representing the device type which has a maximum of 32 characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_030', 0, function () { + console.info('device_info_test_030 start'); + var deviceTypeInfo = deviceinfo.deviceType; + var ret = false; + if(deviceTypeInfo !== null){ + ret = true; + } + expect(deviceTypeInfo).assertEqual('default') + expect(ret).assertTrue(); + + let len = deviceTypeInfo.length + console.info('the value of the device type characters:' + len) + expect(len).assertLess(32) + console.info('device_info_test_030 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0340 + * @tc.name testGetManufacture02 + * @tc.desc Get a string representing the manufacture which has a maximum of 32 characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_031', 0, function () { + console.info('device_info_test_031 start'); + var manufactureInfo = deviceinfo.manufacture; + var ret = false; + if(manufactureInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = manufactureInfo.length + console.info('the value of the manufacture characters is :' + len) + expect(len).assertLess(32) + console.info('device_info_test_031 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0350 + * @tc.name testGetProductBrand02 + * @tc.desc Get a string representing the external product family name which has a maximum of 32 characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_032', 0, function () { + console.info('device_info_test_032 start'); + var brandInfo = deviceinfo.brand; + var ret = false; + if(brandInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = brandInfo.length + console.info('the value of the external product family name characters is :' + len) + expect(len).assertLess(32) + console.info('device_info_test_032 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0360 + * @tc.name testGetMarketName02 + * @tc.desc Get a string representing the product series which has a maximum of 32 characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_033', 0, function () { + console.info('device_info_test_033 start'); + var marketNameInfo = deviceinfo.marketName; + var ret = false; + if(marketNameInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = marketNameInfo.length + console.info('the value of the product series characters is :' + len) + expect(len).assertLess(32) + console.info('device_info_test_033 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0370 + * @tc.name testGetProductSeries02 + * @tc.desc Get a string representing the product series which has a maximum of 32 characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_034', 0, function () { + console.info('device_info_test_034 start'); + var productSeriesInfo = deviceinfo.productSeries; + var ret = false; + if(productSeriesInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = productSeriesInfo.length + console.info('the value of the product series characters is :' + len) + expect(len).assertLess(32) + console.info('device_info_test_034 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0380 + * @tc.name testGetProductModel02 + * @tc.desc Get a string representing the certified model which has a maximum of 32 characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_035', 0, function () { + console.info('device_info_test_035 start'); + var productModelInfo = deviceinfo.productModel; + var ret = false; + if(productModelInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = productModelInfo.length + console.info('the value of the certified model characters is :' + len) + expect(len).assertLess(32) + console.info('device_info_test_035 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0390 + * @tc.name testGetSoftwareModel02 + * @tc.desc Get a string representing the internal software sub-model which has a maximum of 32 characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_036', 0, function () { + console.info('device_info_test_036 start'); + var softwareModelInfo = deviceinfo.softwareModel; + var ret = false; + if(softwareModelInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = softwareModelInfo.length + console.info('the value of the internal software sub-model characters is :' + len) + expect(len).assertLess(32) + console.info('device_info_test_036 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0410 + * @tc.name testGetHardwareModel02 + * @tc.desc Get a string representing the hardware version which has a maximum of 32 characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_037', 0, function () { + console.info('device_info_test_037 start'); + var hardwareModelInfo = deviceinfo.hardwareModel; + var ret = false; + if(hardwareModelInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = hardwareModelInfo.length + console.info('the value of the hardware version characters is :' + len) + expect(len).assertLess(32) + console.info('device_info_test_037 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0420 + * @tc.name testGetHardwareProfile02 + * @tc.desc Get a string representing the hardware version which has a maximum of 32 characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_038', 0, function () { + console.info('device_info_test_038 start'); + var hardwareProfileInfo = deviceinfo.hardwareProfile; + var ret = false; + if(hardwareProfileInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = hardwareProfileInfo.length + console.info('the value of the hardware version characters is :' + len) + expect(len).assertLess(1000) + console.info('device_info_test_038 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0430 + * @tc.name testGetSerial02 + * @tc.desc Get a string representing the device serial number which has a maximum of 32 characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_039', 0, function () { + console.info('device_info_test_039 start'); + var serialInfo = deviceinfo.serial; + var ret = false; + if(serialInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = serialInfo.length + console.info('the value of the device serial number characters is :' + len) + expect(len).assertLess(64) + console.info('device_info_test_039 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0440 + * @tc.name testGetDisplayVersion02 + * @tc.desc Get a string representing the version number visible to users which has a maximum of 32 characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_040', 0, function () { + console.info('device_info_test_040 start'); + var displayVersionInfo = deviceinfo.displayVersion; + var ret = false; + if(displayVersionInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = displayVersionInfo.length + console.info('the value of the device serial number characters is :' + len) + expect(len).assertLess(64) + console.info('device_info_test_040 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0450 + * @tc.name testGetOsFullName02 + * @tc.desc Get a string representing the operating system full name which has a maximum of 32 characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_041', 0, function () { + console.info('device_info_test_041 start'); + var osFullNameInfo = deviceinfo.osFullName; + var ret = false; + if(osFullNameInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = osFullNameInfo.length + console.info('the value of the operating system full name characters is :' + len) + expect(len).assertLess(32) + console.info('device_info_test_041 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0460 + * @tc.name testGetVersionId02 + * @tc.desc Get a string representing the operating system full name which has a maximum of 32 characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_042', 0, function () { + console.info('device_info_test_042 start'); + var versionIdInfo = deviceinfo.versionId; + var ret = false; + if(versionIdInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = versionIdInfo.length + console.info('the value of the operating system full name characters is :' + len) + expect(len).assertLess(127) + console.info('device_info_test_042 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0470 + * @tc.name testGetBuildUser02 + * @tc.desc Get a string representing the different build user of the same baseline code which has a maximum of 32 characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_043', 0, function () { + console.info('device_info_test_043 start'); + var buildUserInfo = deviceinfo.buildUser; + var ret = false; + if(buildUserInfo !== null){ + ret = true; + } + console.info('the value of thebuildUser is :' + buildUserInfo); + expect(ret).assertTrue(); + console.info('the value of the different build user of the same baseline code characters is :' + buildUserInfo.length); + expect(buildUserInfo.length).assertLess(32) + console.info('device_info_test_043 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0480 + * @tc.name testGetBuildHost02 + * @tc.desc Get a string representing the different build host of the same baseline code which has a maximum of 32 characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_044', 0, function () { + console.info('device_info_test_044 start'); + var buildHostInfo = deviceinfo.buildHost; + var ret = false; + if(buildHostInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = buildHostInfo.length + console.info('the value of the different build host of the same baseline code characters is :' + len) + expect(len).assertLess(32) + console.info('device_info_test_044 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0490 + * @tc.name testGetDeviceType03 + * @tc.desc Get a string representing the device type which has at least one characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_045', 0, function () { + console.info('device_info_test_045 start'); + var deviceTypeInfo = deviceinfo.deviceType; + var ret = false; + if(deviceTypeInfo !== null){ + ret = true; + } + expect(deviceTypeInfo).assertEqual('default') + expect(ret).assertTrue(); + + let len = deviceTypeInfo.length + console.info('the value of the device type characters:' + len) + expect(len).assertLarger(0) + console.info('device_info_test_045 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0510 + * @tc.name testGetManufacture03 + * @tc.desc Get a string representing the manufacture which has at least one characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_046', 0, function () { + console.info('device_info_test_046 start'); + var manufactureInfo = deviceinfo.manufacture; + var ret = false; + if(manufactureInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = manufactureInfo.length + console.info('the value of the manufacture characters is :' + len) + expect(len).assertLarger(0) + console.info('device_info_test_046 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0520 + * @tc.name testGetProductBrand03 + * @tc.desc Get a string representing the external product family name which has at least one characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_047', 0, function () { + console.info('device_info_test_047 start'); + var brandInfo = deviceinfo.brand; + var ret = false; + if(brandInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = brandInfo.length + console.info('the value of the external product family name characters is :' + len) + expect(len).assertLarger(0) + console.info('device_info_test_047 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0530 + * @tc.name testGetMarketName03 + * @tc.desc Get a string representing the product series which has at least one characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_048', 0, function () { + console.info('device_info_test_048 start'); + var marketNameInfo = deviceinfo.marketName; + var ret = false; + if(marketNameInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = marketNameInfo.length + console.info('the value of the product series characters is :' + len) + expect(len).assertLarger(0) + console.info('device_info_test_048 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0540 + * @tc.name testGetProductSeries03 + * @tc.desc Get a string representing the product series which has at least one characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_049', 0, function () { + console.info('device_info_test_049 start'); + var productSeriesInfo = deviceinfo.productSeries; + var ret = false; + if(productSeriesInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = productSeriesInfo.length + console.info('the value of the product series characters is :' + len) + expect(len).assertLarger(0) + console.info('device_info_test_049 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0550 + * @tc.name testGetProductModel03 + * @tc.desc Get a string representing the certified model which has at least one characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_050', 0, function () { + console.info('device_info_test_050 start'); + var productModelInfo = deviceinfo.productModel; + var ret = false; + if(productModelInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = productModelInfo.length + console.info('the value of the certified model characters is :' + len) + expect(len).assertLarger(0) + console.info('device_info_test_050 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0560 + * @tc.name testGetSoftwareModel03 + * @tc.desc Get a string representing the internal software sub-model which has at least one characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_051', 0, function () { + console.info('device_info_test_036 start'); + var softwareModelInfo = deviceinfo.softwareModel; + var ret = false; + if(softwareModelInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = softwareModelInfo.length + console.info('the value of the internal software sub-model characters is :' + len) + expect(len).assertLarger(0) + console.info('device_info_test_036 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0570 + * @tc.name testGetHardwareModel03 + * @tc.desc Get a string representing the hardware version which has at least one characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_052', 0, function () { + console.info('device_info_test_052 start'); + var hardwareModelInfo = deviceinfo.hardwareModel; + var ret = false; + if(hardwareModelInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = hardwareModelInfo.length + console.info('the value of the hardware version characters is :' + len) + expect(len).assertLarger(0) + console.info('device_info_test_052 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0580 + * @tc.name testGetHardwareProfile03 + * @tc.desc Get a string representing the hardware version which has at least one characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_053', 0, function () { + console.info('device_info_test_053 start'); + var hardwareProfileInfo = deviceinfo.hardwareProfile; + var ret = false; + if(hardwareProfileInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = hardwareProfileInfo.length + console.info('the value of the hardware version characters is :' + len) + expect(len).assertLarger(0) + console.info('device_info_test_053 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0590 + * @tc.name testGetSerial03 + * @tc.desc Get a string representing the device serial number which has at least one characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_054', 0, function () { + console.info('device_info_test_054 start'); + var serialInfo = deviceinfo.serial; + var ret = false; + if(serialInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = serialInfo.length + console.info('the value of the device serial number characters is :' + len) + expect(len).assertLarger(0) + console.info('device_info_test_054 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0610 + * @tc.name testGetDisplayVersion03 + * @tc.desc Get a string representing the version number visible to users which has at least one characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_055', 0, function () { + console.info('device_info_test_055 start'); + var displayVersionInfo = deviceinfo.displayVersion; + var ret = false; + if(displayVersionInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = displayVersionInfo.length + console.info('the value of the device serial number characters is :' + len) + expect(len).assertLarger(0) + console.info('device_info_test_055 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0620 + * @tc.name testGetIncrementalVersionInfo02 + * @tc.desc Get a string representing the version number visible to users which has a maximum of 32 characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_056', 0, function () { + console.info('device_info_test_056 start'); + var incrementalVersionInfo = deviceinfo.incrementalVersion; + var ret = false; + if(incrementalVersionInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = incrementalVersionInfo.length + console.info('the value of the device serial number characters is :' + len) + expect(len).assertLess(32) + console.info('device_info_test_056 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0630 + * @tc.name testGetIncrementalVersionInfo03 + * @tc.desc Get a string representing the version number visible to users which has at least one characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_057', 0, function () { + console.info('device_info_test_057 start'); + var incrementalVersionInfo = deviceinfo.incrementalVersion; + var ret = false; + if(incrementalVersionInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = incrementalVersionInfo.length + console.info('the value of the device serial number characters is :' + len) + expect(len).assertLarger(0) + console.info('device_info_test_057 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0640 + * @tc.name testGetVersionId03 + * @tc.desc Get a string representing the operating system full name which has at least one characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_058', 0, function () { + console.info('device_info_test_058 start'); + var versionIdInfo = deviceinfo.versionId; + var ret = false; + if(versionIdInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = versionIdInfo.length + console.info('the value of the operating system full name characters is :' + len) + expect(len).assertLarger(0) + console.info('device_info_test_058 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0650 + * @tc.name testGetBuildUser03 + * @tc.desc Get a string representing the different build user of the same baseline code which has at least one characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_059', 0, function () { + console.info('device_info_test_043 start'); + var buildUserInfo = deviceinfo.buildUser; + var ret = false; + if(buildUserInfo !== null){ + ret = true; + } + console.info('the value of thebuildUser is :' + buildUserInfo); + expect(ret).assertTrue(); + console.info('the value of the different build user of the same baseline code characters is :' + buildUserInfo.length); + expect(buildUserInfo.length).assertLarger(0) + console.info('device_info_test_059 :PASS') + }) + + /** + * @tc.number SUB_STARTUP_JS_DEVCEINFO_0660 + * @tc.name testGetBuildHost03 + * @tc.desc Get a string representing the different build host of the same baseline code which has at least one characters. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('device_info_test_060', 0, function () { + console.info('device_info_test_060 start'); + var buildHostInfo = deviceinfo.buildHost; + var ret = false; + if(buildHostInfo !== null){ + ret = true; + } + expect(ret).assertTrue(); + + let len = buildHostInfo.length + console.info('the value of the different build host of the same baseline code characters is :' + len); + expect(len).assertLarger(0); + console.info('device_info_test_060 :PASS'); + }) +}) + diff --git a/startup/startup_standard/entry/src/main/js/test/List.test.js b/startup/startup_standard/entry/src/main/js/test/List.test.js new file mode 100755 index 0000000000000000000000000000000000000000..14b32309694f346415dd188961b77cc81fb9b3eb --- /dev/null +++ b/startup/startup_standard/entry/src/main/js/test/List.test.js @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2021 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. + */ + +require('./DeviceInfoJsUnit.test.js') +require('./ParametersJsUnit.test.js') +require('./UpdaterJsUnit.test.js') + + diff --git a/startup/startup_standard/entry/src/main/js/test/ParametersJsUnit.test.js b/startup/startup_standard/entry/src/main/js/test/ParametersJsUnit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..85b4836abe67bcfd81133ebdf8457decdd0ed879 --- /dev/null +++ b/startup/startup_standard/entry/src/main/js/test/ParametersJsUnit.test.js @@ -0,0 +1,396 @@ +/* + * Copyright (C) 2021 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. + */ + +// @ts-nocheck +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' +import systemparameter from '@ohos.systemParameter' + +describe('SystemParameterTest', function () { + console.info('SystemParameterTest start################################start'); + /** + * @tc.number SUB_STARTUP_JS_SYSTEM_PARAMETER_0100 + * @tc.name testSet01 + * @tc.desc Set the value for the given key with parameter callback. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('system_parameter_test_001', 0, function () { + console.info('system_parameter_test_001 start'); + var ret = false; + try { + systemparameter.set("hw_sc.build.os.version", "10.20.30.4", function (err, data) { + if (err == undefined) { + ret = true; + console.info("set callback hw_sc.build.os.version value success :" + data); + } else { + console.info("set callback hw_sc.build.os.version value err:" + err.code); + } + }); + }catch(e){ + console.info("set callback hw_sc.build.os.version unexpect err:" + e); + } + setTimeout("expect(ret).assertTrue()", "10"); + console.info('system_parameter_test_001 : PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_SYSTEM_PARAMETER_0200 + * @tc.name testSet02 + * @tc.desc Set the value for the given key. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('system_parameter_test_002', 0, function () { + console.info('system_parameter_test_002 start'); + var ret = false; + try { + systemparameter.set("ro.secure", "10.20.30.4", function (err, data) { + if (err == undefined) { + console.info("set callback ro.secure value success:" + data) + } else { + ret = true; + console.info("set callback ro.secure value err:" + err.code) + } + + }); + }catch(e){ + console.info("set callback ro.secure unexpect err:" + e) + } + setTimeout("expect(ret).assertTrue()", "10"); + console.info('system_parameter_test_002 : PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_SYSTEM_PARAMETER_0300 + * @tc.name testSet03 + * @tc.desc Set the value for the given key. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('system_parameter_test_003', 0, function () { + console.info('system_parameter_test_003 start'); + var parameterInfo = systemparameter.set("hw_sc.build.os.version", "1.5.3.6"); + var ret = false; + try { + parameterInfo.then(function (value) { + console.info("promise set hw_sc.build.os.version success: " + value); + }).catch(function (err) { + console.info("promise set hw_sc.build.os.version error: " + err.code); + }); + }catch(e){ + console.info("set callback hw_sc.build.os.version unexpect err:" + e) + } + if (parameterInfo !== null) { + ret = true; + } + expect(ret).assertTrue(); + console.info('system_parameter_test_003 : PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_SYSTEM_PARAMETER_0400 + * @tc.name testSet04 + * @tc.desc Set the value for the given key. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('system_parameter_test_004', 0, function () { + console.info('system_parameter_test_004 start'); + var parameterInfo = systemparameter.set("ro.secure", "10"); + var ret = false; + try { + parameterInfo.then(function (value) { + console.info("12333 promise set ro.secure success: " + value); + }).catch(function (err) { + console.info("12333 promise set ro.secure error: " + err.code); + }); + }catch(e){ + console.info("set callback ro.secure unexpect err:" + e) + } + if (parameterInfo !== null) { + ret = true; + } + expect(ret).assertTrue(); + console.info('system_parameter_test_004 :PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_SYSTEM_PARAMETER_0500 + * @tc.name testSetSync01 + * @tc.desc Set the value for the given key. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('system_parameter_test_005', 0, function () { + console.info('system_parameter_test_005 start'); + var ret = false; + try { + var parameterInfo = systemparameter.setSync("hw_sc.build.os.version", "2.5.3.7"); + console.info("promise setSync ro.secure success: " + parameterInfo); + ret = true; + }catch(e){ + console.info("promise setSync ro.secure error: " + e); + } + expect(ret).assertTrue(); + console.info('system_parameter_test_005 : PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_SYSTEM_PARAMETER_0600 + * @tc.name testSetSync02 + * @tc.desc Set the value for the given key. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('system_parameter_test_006', 0, function () { + console.info('system_parameter_test_006 start'); + var ret = false; + try { + var parameterInfo = systemparameter.setSync("hw_sc.build.os.version", 56789); + console.info("promise setSync ro.secure success: " + parameterInfo); + }catch(e){ + ret = true; + console.info("promise setSync ro.secure error: " + e); + } + expect(ret).assertTrue(); + console.info('system_parameter_test_006 : PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_SYSTEM_PARAMETER_0700 + * @tc.name testGet01 + * @tc.desc Set the value for the given key. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('system_parameter_test_007', 0, function () { + console.info('system_parameter_test_007 start'); + var ret = false; + try { + var parameterInfo = systemparameter.get("ro.secure", "1"); + parameterInfo.then(function (value) { + ret = true; + console.info("promise get ro.secure success: " + value); + }).catch(function (err) { + console.info("promise get ro.secure error: " + err.code); + }); + }catch(e){ + console.info("promise setSync ro.secure error: " + e); + } + setTimeout("expect(ret).assertTrue()", "10"); + console.info('system_parameter_test_007 : PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_SYSTEM_PARAMETER_0800 + * @tc.name testGet02 + * @tc.desc Set the value for the given key. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('system_parameter_test_008', 0, function () { + console.info('system_parameter_test_008 start'); + var ret = false; + try { + var parameterInfo = systemparameter.get("hw_sc.build.os.version"); + parameterInfo.then(function (value) { + ret = true; + console.info("promise get hw_sc.build.os.version success: " + value); + }).catch(function (err) { + console.info("promise get hw_sc.build.os.version error: " + err.code); + }); + }catch(e){ + console.info("promise setSync ro.secure error: " + e); + } + setTimeout("expect(ret).assertTrue()", "10"); + console.info('system_parameter_test_008 : PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_SYSTEM_PARAMETER_0900 + * @tc.name testGet03 + * @tc.desc Set the value for the given key. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('system_parameter_test_009', 0, function () { + console.info('system_parameter_test_009 start'); + var ret = false; + try { + var parameterInfo = systemparameter.get("hw_sc.build.os.version", 897); + parameterInfo.then(function (value) { + console.info("897 promise get hw_sc.build.os.version success: " + value); + }).catch(function (err) { + console.info("897 promise get hw_sc.build.os.version error: " + err.code); + }); + } catch (e) { + ret = true; + console.info("promise get input error: " + e); + } + expect(ret).assertTrue(); + console.info('system_parameter_test_009 : PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_SYSTEM_PARAMETER_0110 + * @tc.name testGet04 + * @tc.desc Set the value for the given key. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('system_parameter_test_010', 0, function () { + console.info('system_parameter_test_010 start'); + var ret = false; + try { + systemparameter.get("hw_sc.build.os.version", 567, function (err, data) { + if (err == undefined) { + console.info(" 567 callback get hw_sc.build.os.version value success:" + data) + } else { + console.info(" 567 callback get hw_sc.build.os.version value err:" + err.code) + } + + }); + } catch (e) { + ret = true; + console.info(" 567 callback get inputttt error:" + e) + } + expect(ret).assertTrue(); + console.info('system_parameter_test_010 : PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_SYSTEM_PARAMETER_0120 + * @tc.name testGet05 + * @tc.desc Set the value for the given key. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('system_parameter_test_011', 0, function () { + console.info('system_parameter_test_011 start'); + var ret = false; + try { + systemparameter.get("hw_sc.build.os.version", "10.20.30.4", function (err, data) { + if (err == undefined) { + ret = true; + console.info(" callback get hw_sc.build.os.version value success:" + data) + } else { + console.info(" callback get hw_sc.build.os.version value err:" + err.code) + } + + }); + } catch (e) { + ret = true; + console.info(" 567 callback get inputttt error:" + e) + } + setTimeout("expect(ret).assertTrue()", "10"); + console.info('system_parameter_test_011 : PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_SYSTEM_PARAMETER_0130 + * @tc.name testGet06 + * @tc.desc Set the value for the given key. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('system_parameter_test_012', 0, function () { + console.info('system_parameter_test_012 start'); + var ret = false; + try { + systemparameter.get("ro.secure", "zbc", function (err, data) { + if (err == undefined) { + ret = true; + console.info("callback get ro.secure value success:" + data) + } else { + console.info("callback get ro.secure value err:" + err.code) + } + + }); + } catch (e) { + ret = true; + console.info(" 567 callback get inputttt error:" + e) + } + setTimeout("expect(ret).assertTrue()", "10"); + console.info('system_parameter_test_012 : PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_SYSTEM_PARAMETER_0140 + * @tc.name testGet07 + * @tc.desc Gets the value of the attribute with the specified key. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('system_parameter_test_013', 0, function () { + console.info('system_parameter_test_013 start'); + var ret = false; + try { + systemparameter.get("ro.secure", function (err, data) { + if (err == undefined) { + ret = true; + console.info("callback get ro.secure value success:" + data) + } else { + console.info("callback get ro.secure value err:" + err.code) + } + + }); + } catch (e) { + ret = true; + console.info("callback get inputttt error:" + e) + } + setTimeout("expect(ret).assertTrue()", "10"); + console.info('system_parameter_test_013 : PASS'); + }) + + /** + * @tc.number SUB_STARTUP_JS_SYSTEM_PARAMETER_0150 + * @tc.name testGetSync01 + * @tc.desc Gets the value of the attribute with the specified key. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('system_parameter_test_014', 0, function () { + console.info('system_parameter_test_014 start'); + var ret = false; + try { + var parameterInfo = systemparameter.getSync("hw_sc.build.os.version", 496); + parameterInfo.then(function (value) { + console.info("496 promise get hw_sc.build.os.version success: " + value); + }).catch(function (err) { + console.info("496 promise get hw_sc.build.os.version error: " + err.code); + }); + } catch (e) { + ret = true; + console.info("promise get input error: " + e); + } + expect(ret).assertTrue(); + console.info('system_parameter_test_014 : PASS'); + }) + +}) \ No newline at end of file diff --git a/startup/startup_standard/entry/src/main/js/test/UpdaterJsUnit.test.js b/startup/startup_standard/entry/src/main/js/test/UpdaterJsUnit.test.js new file mode 100755 index 0000000000000000000000000000000000000000..9a8fbf23b1cc48a9b10268caa2c19b7542ebfcd5 --- /dev/null +++ b/startup/startup_standard/entry/src/main/js/test/UpdaterJsUnit.test.js @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2021 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. + */ + +// @ts-nocheck +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' +import updateTest from '@ohos.update' + +describe('UpdateTest', function () { + console.info('start################################start'); + /** + * @tc.number SUB_STARTUP_JS_UPDATE_0100 + * @tc.name testVerifyUpdatePackage01 + * @tc.desc Get Updater handler for the calling device. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('verify_update_packaget_est_001', 0, function () { + console.info('testVerifyUpdatePackage01 start'); + var ret = false; + var getVar = updateTest.getUpdater(); + try { + console.info('zpz AceApplication onCreate1'); + getVar.on("verifyProgress", function (aaa){ + console.info('zpz xxxxx ' + aaa.percent); + + console.info('zpz AceApplication onCreate2'); + getVar.verifyUpdatePackage(null, null); + getVar.off("verifyProgress", function (aaa){ + console.info('zpz xxxxx ' + aaa.percent); + }) + }); + } catch (e){ + console.info(" 567 callback get inputttt error:" + e); + ret = true; + } + setTimeout("expect(ret).assertTrue()", "10"); + console.info('testVerifyUpdatePackage01 : PASS'); + }) +}) + diff --git a/startup/startup_standard/hap/entry-debug-rich-signed.hap b/startup/startup_standard/hap/entry-debug-rich-signed.hap new file mode 100755 index 0000000000000000000000000000000000000000..39393f0451ac82c2ceea761bf92579ad13f0104d Binary files /dev/null and b/startup/startup_standard/hap/entry-debug-rich-signed.hap differ diff --git a/telephony/BUILD.gn b/telephony/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..98733dcfd27f6295b5693d876ccf40607894f386 --- /dev/null +++ b/telephony/BUILD.gn @@ -0,0 +1,24 @@ +# Copyright (C) 2021 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("//build/ohos_var.gni") +group("telephonyjstest") { + testonly = true + if (is_standard_system) { + deps = [ + # "network_search_test:network_search_test", + # "sms_mms:sms_mms_test", + # "call_manager:call_manager", + ] + } +} diff --git a/telephony/call_manager/BUILD.gn b/telephony/call_manager/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e78277dcba32e7c0176b6220664b77753f307f54 --- /dev/null +++ b/telephony/call_manager/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("call_manager") { + test_hap_name = "CallManagerTest" + hap_source_path = "hap/entry-debug-rich-unsigned.hap" +} diff --git a/telephony/call_manager/Test.json b/telephony/call_manager/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..2c9352c194d593e3fe5efba619787ca2acf22cec --- /dev/null +++ b/telephony/call_manager/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for callmanager Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "21600000", + "package": "ohos.acts.aafwk.ability", + "shell-timeout": "21600000" + }, + "kits": [ + { + "test-file-name": [ + "$module.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/telephony/call_manager/entry/src/main/config.json b/telephony/call_manager/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..0f8ea5444220fe94382ced56b86be93fdd3b27b8 --- /dev/null +++ b/telephony/call_manager/entry/src/main/config.json @@ -0,0 +1,48 @@ +{ + "app": { + "bundleName": "com.ohos.callmanagertest", + "vendor": "ohos", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.ohos.callmanagertest", + "name": "CallManagerTest", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "decc.testkit.runner.JsEntryAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + } + ] + } +} \ No newline at end of file diff --git a/telephony/call_manager/entry/src/main/js/default/app.js b/telephony/call_manager/entry/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..50cc70b0aab58a8ed825e6fb93d89b5539b2e6b3 --- /dev/null +++ b/telephony/call_manager/entry/src/main/js/default/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 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 default { + onCreate() { + console.info('TestApplication onCreate'); + }, + onDestroy() { + console.info('TestApplication onDestroy'); + } +}; diff --git a/telephony/call_manager/entry/src/main/js/default/i18n/en-US.json b/telephony/call_manager/entry/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..55561b83737c3c31d082fbfa11e5fc987a351104 --- /dev/null +++ b/telephony/call_manager/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/telephony/call_manager/entry/src/main/js/default/i18n/zh-CN.json b/telephony/call_manager/entry/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..cce1af06761a42add0cac1a0567aa3237eda8cb4 --- /dev/null +++ b/telephony/call_manager/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/telephony/call_manager/entry/src/main/js/default/pages/index/index.css b/telephony/call_manager/entry/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/telephony/call_manager/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/telephony/call_manager/entry/src/main/js/default/pages/index/index.hml b/telephony/call_manager/entry/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/telephony/call_manager/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/telephony/call_manager/entry/src/main/js/default/pages/index/index.js b/telephony/call_manager/entry/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..7b603361e647c09d4514146b678d084b41c41d76 --- /dev/null +++ b/telephony/call_manager/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2021 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 file from '@system.file' +import app from '@system.app' +import device from '@system.device' +import router from '@system.router' +import {Core, ExpectExtend} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish!') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + core.init() + + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} diff --git a/telephony/call_manager/entry/src/main/js/test/CallManager.test.js b/telephony/call_manager/entry/src/main/js/test/CallManager.test.js new file mode 100644 index 0000000000000000000000000000000000000000..a21c6a0038cc5bdb3431908f12f4b5a137e07bcb --- /dev/null +++ b/telephony/call_manager/entry/src/main/js/test/CallManager.test.js @@ -0,0 +1,455 @@ +/* + * Copyright (C) 2021 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 call from '@ohos.telephony_call' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('CallManagementTest', function () { + const TEST_PHONY_NUMBER = "13788888888"; + const TIMES_1000 = 1000; + const MSEC_500 = 500; + + /* + * @tc.number Telephony_CallManager_dial_Async_0100 + * @tc.name Call dial() by way of callback when the phone number is a normal number + * @tc.desc Function test + */ + it('Telephony_CallManager_dial_Async_0100', 0, async function (done) { + call.dial( TEST_PHONY_NUMBER, (err, value) => { + if (err) { + expect().assertFail(); + return; + } + expect(value).assertTrue(); + }) + done(); + }) + + /* + * @tc.number Telephony_CallManager_dial_Async_0200 + * @tc.name Call dial() by way of callback when the phone number is '' + * @tc.desc Function test + */ + it('Telephony_CallManager_dial_Async_0200', 0, async function (done) { + call.dial( '', (err, value) => { + if (err) { + expect().assertFail(); + return; + } + expect(value).assertFalse(); + }) + done(); + }) + + /* + * @tc.number Telephony_CallManager_dial_Async_0300 + * @tc.name Call dial() by way of callback when the phone number is '12345678901234567890012345678901' + * @tc.desc Function test + */ + it('Telephony_CallManager_dial_Async_0300', 0, async function (done) { + call.dial( '12345678901234567890012345678901', (err, value) => { + if (err) { + expect().assertFail(); + return; + } + expect(value).assertFalse(); + }) + done(); + }) + + /* + * @tc.number Telephony_CallManager_dial_Async_0400 + * @tc.name Call dial() by way of callback when the phone number is '13788888888,1234567890123456789123' + * @tc.desc Function test + */ + it('Telephony_CallManager_dial_Async_0400', 0, async function (done) { + call.dial( '13788888888,1234567890123456789123', (err, value) => { + if (err) { + expect().assertFail(); + return; + } + expect(value).assertTrue(); + }) + done(); + }) + + /* + * @tc.number Telephony_CallManager_dial_Async_0500 + * @tc.name Call dial() by way of callback when the phone number is 'abcde123456' + * @tc.desc Function test + */ + it('Telephony_CallManager_dial_Async_0500', 0, async function (done) { + call.dial( 'abcde123456', (err, value) => { + if (err) { + expect().assertFail(); + return; + } + expect(value).assertFalse(); + }) + done(); + }) + + /* + * @tc.number Telephony_CallManager_dial_Async_0600 + * @tc.name Call dial() by way of callback, phone number is 'abcde123456' + * @tc.desc Function test + */ + it('Telephony_CallManager_dial_Async_0600', 0, async function (done) { + for (let index = 0; index < TIMES_1000; index++) { + call.dial( 'abcde123456', (err, value) => { + if (err) { + expect().assertFail(); + return; + } + expect(value).assertFalse(); + }) + } + done(); + }) + + /* + * @tc.number Telephony_CallManager_dial_Async_0700 + * @tc.name Call dail() by way of callback 1000 times, phone number is 'abcde123456' + * @tc.desc Function test + */ + it('Telephony_CallManager_dial_Async_0700', 0, async function (done) { + const startTime = (new Date).getTime(); + for (let index = 0; index < TIMES_1000; index++) { + call.dial( 'abcde123456', (err, value) => { + if (err) { + expect().assertFail(); + return; + } + expect(value).assertFalse(); + }) + } + const endTime = (new Date).getTime(); + expect(endTime - startTime).assertLess(MSEC_500); + done(); + }) + + /* + * @tc.number Telephony_CallManager_dial_Async_0800 + * @tc.name Call dail() by way of callback, phoneNumber is a normal number, options is {extras: false} + * and the optional parameter options is {extras: false} + * @tc.desc Function test + */ + it('Telephony_CallManager_dial_Async_0800', 0, async function (done) { + call.dial( TEST_PHONY_NUMBER, {extras: false}, (err, value) => { + if (err) { + expect().assertFail(); + return; + } + expect(value.result).assertEqual(0); + }) + done(); + }) + + /* + * @tc.number Telephony_CallManager_dial_Async_0900 + * @tc.name Call dial() by way of callback, phoneNumber is a normal number, options is '' + * @tc.desc Function test + */ + it('Telephony_CallManager_dial_Async_0900', 0, async function (done) { + call.dial( '', {extras: false}, (err, value) => { + if (err) { + expect().assertFail(); + return; + } + expect(value.result).assertEqual(0); + }) + done(); + }) + + /* + * @tc.number Telephony_CallManager_dial_Async_1000 + * @tc.name Call dial() by way of callback, phoneNumber is 'abcde123456', options is {extras: false} + * parameter options is {extras: false} + * @tc.desc Function test + */ + it('Telephony_CallManager_dial_Async_1000', 0, async function (done) { + for (let index = 0; index < TIMES_1000; index++) { + call.dial( 'abcde123456', {extras: false}, (err, value) => { + if (err) { + expect().assertFail(); + return; + } + expect(value.result).assertEqual(call.CALL_MANAGER_PHONENUM_NULL); + }) + } + done(); + }) + + /* + * @tc.number Telephony_CallManager_dial_Async_1100 + * @tc.name Call dial() by way of callback check the time, phoneNumber is '~!@#$%^&*123', options is {extras: false} + * parameter options is empty + * @tc.desc Function test + */ + it('Telephony_CallManager_dial_Async_1100', 0, async function (done) { + const startTime = (new Date).getTime(); + for (let index = 0; index < TIMES_1000; index++) { + call.dial( '~!@#$%^&*123', {extras: false}, (err, value) => { + if (err) { + expect().assertFail(); + return; + } + expect(value).assertFalse(); + }) + } + const endTime = (new Date).getTime(); + expect(endTime - startTime).assertLess(MSEC_500); + done(); + }) + + /* + * @tc.number Telephony_CallManager_dial_Promise_0100 + * @tc.name Call dail(), phoneNumber is a normal number, options is {extras: false} + * @tc.desc Function test + */ + it('Telephony_CallManager_dial_Promise_0100', 0, async function (done) { + call.dial(TEST_PHONY_NUMBER, {extras: false}).then((data) => { + expect(data).assertTrue(); + }).catch((err) => { + expect().assertFail(); + }) + done(); + }) + + /* + * @tc.number Telephony_CallManager_dial_Promise_0200 + * @tc.name Call dail(), phoneNumber is '', options is {extras: false} + * @tc.desc Function test + */ + it('Telephony_CallManager_dial_Promise_0100', 0, async function (done) { + call.dial('', {extras: false}).then((data) => { + expect(data).assertFalse(); + }).catch((err) => { + expect().assertFail(); + }) + done(); + }) + + /* + * @tc.number Telephony_CallManager_dial_Promise_0300 + * @tc.name Call dail(), phoneNumber is 'abcde123456', options is {extras: false} + * @tc.desc Function test + */ + it('Telephony_CallManager_dial_Promise_0300', 0, async function (done) { + call.dial('abcde123456', {extras: false}).then((data) => { + expect(data).assertFalse(); + }).catch((err) => { + expect().assertFail(); + }) + done(); + }) + + /* + * @tc.number Telephony_CallManager_dial_Promise_0400 + * @tc.name Call dail() 1000 times, phoneNumber is 'abcde123456', options is {extras: false} + * @tc.desc Function test + */ + it('Telephony_CallManager_dial_Promise_0400', 0, async function (done) { + for (let index = 0; index < TIMES_1000; index++) { + call.dial('abcde123456', {extras: false}).then((data) => { + expect(data).assertNull(); + }).catch((err) => { + expect().assertFail(); + }) + } + done(); + }) + + /* + * @tc.number Telephony_CallManager_dial_Promise_0500 + * @tc.name Call dail() 1000 times check the time, phoneNumber is 'abcde123456', options is {extras: false} + * @tc.desc Function test + */ + it('Telephony_CallManager_dial_Promise_0400', 0, async function (done) { + const startTime = (new Date).getTime(); + for (let index = 0; index < TIMES_1000; index++) { + call.dial('abcde123456', {extras: false}).then((data) => { + expect(data).assertNull(); + }).catch((err) => { + expect().assertFail(); + }) + } + const endTime = (new Date).getTime(); + expect(endTime - startTime).assertLess(MSEC_500); + done(); + }) + + /* + * @tc.number Telephony_CallManager_dial_Promise_0600 + * @tc.name Call dail(), phoneNumber is a normal number + * @tc.desc Function test + */ + it('Telephony_CallManager_dial_Promise_0100', 0, async function (done) { + call.dial(TEST_PHONY_NUMBER).then((data) => { + expect(data).assertTrue(); + }).catch((err) => { + expect().assertFail(); + }) + done(); + }) + + /* + * @tc.number Telephony_CallManager_getCallState_Async_0100 + * @tc.name Call getCallState() by way of callback when idle + * @tc.desc Function test + */ + it('Telephony_CallManager_getCallState_Async_0100', 0, async function (done) { + call.getCallState((err, data) => { + if (err) { + expect().assertFail(); + return; + } + expect(value).assertEqual(call.CALL_STATE_IDLE); + }) + done(); + }) + + /* + * @tc.number Telephony_CallManager_getCallState_Async_0200 + * @tc.name Call getCallState() by way of callback when dialing + * @tc.desc Function test + */ + it('Telephony_CallManager_getCallState_Async_0100', 0, async function (done) { + call.dial(TEST_PHONY_NUMBER, (err, value) => { + if (err) { + expect().assertFail(); + return; + } + call.getCallState((err, value) => { + if (err) { + expect().assertFail(); + return; + } + expect(value).assertEqual(call.CALL_STATE_OFFHOOK); + }); + }); + done(); + }) + + /* + * @tc.number Telephony_CallManager_getCallState_Async_0300 + * @tc.name Call getCallState() 1000 times by way of callback when idle + * @tc.desc Function test + */ + it('Telephony_CallManager_getCallState_Async_0300', 0, async function (done) { + for (let index = 0; index < TIMES_1000; index++) { //Get call status 1000 calls in a loop + call.getCallState((err, data) => { + if (err) { + expect().assertFail(); + return; + } + expect(value).assertEqual(call.CALL_STATE_IDLE); + }) + } + done(); + }) + + /* + * @tc.number Telephony_CallManager_getCallState_Async_0400 + * @tc.name Call getCallState() 1000 times by way of callback when idle, to check the time + * less than 500000us + * @tc.desc Function test + */ + it('Telephony_CallManager_getCallState_Async_0400', 0, async function (done) { + const startTime = (new Date).getTime(); + for (let index = 0; index < TIMES_1000; index++) { + call.getCallState((err, value) => { + if (err) { + expect().assertFail(); + return; + } + expect(value).assertEqual(call.CALL_STATE_IDLE); + }) + } + const endTime = (new Date).getTime(); + expect(endTime - startTime).assertLess(MSEC_500); + done(); + }) + + /* + * @tc.number Telephony_CallManager_getCallState_Promise_0100 + * @tc.name Call getCallState() when idle + * @tc.desc Function test + */ + it('Telephony_CallManager_getCallState_Promise_0100', 0, async function (done) { + call.getCallState().then((data) => { + expect(data).assertEqual(call.CALL_STATE_IDLE); + }).catch((err) => { + expect().assertFail(); + }); + done(); + }) + + /* + * @tc.number Telephony_CallManager_getCallState_Promise_0200 + * @tc.name Call getCallState() when dialing + * @tc.desc Function test + */ + it('Telephony_CallManager_getCallState_Promise_0200', 0, async function (done) { + call.dial(TEST_PHONY_NUMBER, (err, value) => { + if (err) { + expect().assertFail(); + return; + } + call.getCallState().then((data) => { + expect(data).assertEqual(call.CALL_STATE_OFFHOOK); + }).catch((err) => { + expect().assertFail(); + }); + }); + done(); + }) + + /* + * @tc.number Telephony_CallManager_getCallState_Promise_0300' + * @tc.name Call getCallState() 1000 times when idle + * @tc.desc Function test + */ + it('Telephony_CallManager_getCallState_Promise_0300', 0, async function (done) { + for (let index = 0; index < TIMES_1000; index++) { + call.getCallState().then((data) => { + expect(data).assertEqual(call.CALL_STATE_IDLE); + }).catch((err) => { + expect().assertFail(); + }); + } + done(); + }) + + /* + * @tc.number Telephony_CallManager_getCallState_Promise_0400' + * @tc.name Call getCallState() 1000 times when idle, to check the time + * @tc.desc Function test + */ + it('Telephony_CallManager_getCallState_Promise_0400', 0, async function (done) { + const startTime = (new Date).getTime(); + for (let index = 0; index < TIMES_1000; index++) { + call.getCallState().then((data) => { + expect(data).assertEqual(call.CALL_STATE_IDLE); + }).catch((err) => { + expect().assertFail(); + return; + }); + } + const endTime = (new Date).getTime(); + expect(endTime - startTime).assertLess(MSEC_500); + done(); + }) +}) diff --git a/telephony/call_manager/entry/src/main/js/test/List.test.js b/telephony/call_manager/entry/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..ef47786db85e51d55c5ed7ae7c5c40f1777020c0 --- /dev/null +++ b/telephony/call_manager/entry/src/main/js/test/List.test.js @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2021 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. + */ + +require('./CallManager.test.js') \ No newline at end of file diff --git a/telephony/call_manager/entry/src/main/resources/base/element/string.json b/telephony/call_manager/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..004e845632dfcf674694d664f14e8d94d428304d --- /dev/null +++ b/telephony/call_manager/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "CallManagerTest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/telephony/call_manager/entry/src/main/resources/base/media/icon.png b/telephony/call_manager/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/telephony/call_manager/entry/src/main/resources/base/media/icon.png differ diff --git a/telephony/cellular_data/entry/.gitignore b/telephony/cellular_data/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..3543521e9fef8e7322940a87c2b45dd0061b0f45 --- /dev/null +++ b/telephony/cellular_data/entry/.gitignore @@ -0,0 +1 @@ +/build diff --git a/telephony/cellular_data/entry/src/main/config.json b/telephony/cellular_data/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..c717d684d8ac14f1290585024658977923bea371 --- /dev/null +++ b/telephony/cellular_data/entry/src/main/config.json @@ -0,0 +1,61 @@ +{ + "app": { + "bundleName": "com.example.cellulardatajstest", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 5, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.cellulardatajstest", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "com.example.cellulardatajstest.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard", + "isVisible": "true" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/telephony/cellular_data/entry/src/main/js/default/app.js b/telephony/cellular_data/entry/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..363f2555b1badec9fec342a93141db084083fcb8 --- /dev/null +++ b/telephony/cellular_data/entry/src/main/js/default/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 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 default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/telephony/cellular_data/entry/src/main/js/default/i18n/en-US.json b/telephony/cellular_data/entry/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/telephony/cellular_data/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/telephony/cellular_data/entry/src/main/js/default/i18n/zh-CN.json b/telephony/cellular_data/entry/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/telephony/cellular_data/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/telephony/cellular_data/entry/src/main/js/default/pages/index/index.css b/telephony/cellular_data/entry/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/telephony/cellular_data/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/telephony/cellular_data/entry/src/main/js/default/pages/index/index.hml b/telephony/cellular_data/entry/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/telephony/cellular_data/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/telephony/cellular_data/entry/src/main/js/default/pages/index/index.js b/telephony/cellular_data/entry/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..463271069e2a4d9f3c943424c72e1b10e0924b5b --- /dev/null +++ b/telephony/cellular_data/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2021 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{Core} from 'deccjsunit/lite' + +const core = Core.getInstance() + +core.init() + +require('../../../test/List.test.js') + +core.execyte() + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + } +} diff --git a/telephony/cellular_data/entry/src/main/js/test/List.test.js b/telephony/cellular_data/entry/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..cc381521d6f498ef1c1ec85934fc283c8acac33a --- /dev/null +++ b/telephony/cellular_data/entry/src/main/js/test/List.test.js @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2021 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. + */ + +require('./cellular_data_js_test.js') \ No newline at end of file diff --git a/telephony/cellular_data/entry/src/main/js/test/cellular_data_js_test.js b/telephony/cellular_data/entry/src/main/js/test/cellular_data_js_test.js new file mode 100644 index 0000000000000000000000000000000000000000..668026fa69f23c425d0fd102e00df415b8bfdfb2 --- /dev/null +++ b/telephony/cellular_data/entry/src/main/js/test/cellular_data_js_test.js @@ -0,0 +1,422 @@ +/* + * Copyright (C) 2021 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 cellular from '@ohos.telephony.data.d.ts' +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' + + +describe('Telephony_CellularData_isCellularDataEnabled_Async_0100', function () { + + const USEC_500 = 500 ; + const TTEST_RUN_TIME_1000 = 1000 ; + + /** + * @tc.number Telephony_CellularData_isCellularDataEnabled_Async_0100 + * @tc.name User data switch default state + * @tc.desc Function test + */ + it('Telephony_CellularData_isCellularDataEnabled_Async_0100', 0, function () { + cellular.isCellularDataEnabled((err, data) => { + if (err) { + expect(false == true).assertTrue(); + return; + } + expect(data).assertEqual(false); + }) + }) + + /** + * @tc.number Telephony_CellularData_isCellularDataEnabled_Promise_0200 + * @tc.name User data switch default state + * @tc.desc Function test + */ + it('Telephony_CellularData_isCellularDataEnabled_Promise_0200', 0, function () { + cellular.isCellularDataEnabled().then((data) => { + expect(data).assertEqual(false); + }).catch((err) => { + expect(false == true).assertTrue(); + return; + }); + }) + + + /** + * @tc.number Telephony_CellularData_getCellularDataState_Async_0300 + * @tc.name Verify cellular data status with data switch off + * @tc.desc Function test + */ + it('Telephony_CellularData_getCellularDataState_Async_0300', 0, function () { + cellular.getCellularDataState((err, data) => { + if (err) { + expect(false == true).assertTrue(); + return; + } + expect(data).assertEqual(cellular.DATA_STATE_DISCONNECTED); + }) + }) + + /** + * @tc.number Telephony_CellularData_getCellularDataState_Promise_0400 + * @tc.name Verify cellular data status with data switch off + * @tc.desc Function test + */ + it('Telephony_CellularData_getCellularDataState_Promise_0400', 0, function () { + cellular.getCellularDataState().then((data) => { + expect(data).assertEqual(cellular.DATA_STATE_DISCONNECTED); + }).catch((err) => { + expect(false == true).assertTrue(); + return; + }); + }) + + + /** + * @tc.number Telephony_CellularData_getCellularDataState_Async_0500 + * @tc.name Open the data switch and query the switch status and data status + * @tc.desc Function test + */ + it('Telephony_CellularData_getCellularDataState_Async_0500', 0, function () { + cellular.enableCellularData((err) => { + if (err) { + expect(false == true).assertTrue(); + return; + } + //Turn on the cellular data switch + }) + cellular.isCellularDataEnabled((err, data) => { + if (err) { + expect(false == true).assertTrue(); + return; + } + expect(data).assertEqual(true); + }) + cellular.getCellularDataState((err, data) => { + if (err) { + expect(false == true).assertTrue(); + return; + } + expect(data).assertEqual(cellular.DATA_STATE_CONNECTING); + }) + setTimeout(() => { + }, 1000); + cellular.getCellularDataState((err, data) => { + if (err) { + expect(false == true).assertTrue(); + return; + } + expect(data).assertEqual(cellular.DATA_STATE_CONNECTED); + }) + + }) + + /** + * @tc.number Telephony_CellularData_getCellularDataState_Async_0600 + * @tc.name Turn off the data switch and query the switch status and data status + * @tc.desc Function test + */ + it('Telephony_CellularData_getCellularDataState_Async_0600', 0, function () { + cellular.disableCellularData((err) => { + if (err) { + expect(false == true).assertTrue(); + return; + } + //Turn off the cellular data switch + }) + cellular.isCellularDataEnabled((err, data) => { + if (err) { + expect(false == true).assertTrue(); + return; + } + expect(data).assertEqual(false); + }) + cellular.getCellularDataState((err, data) => { + if (err) { + expect(false == true).assertTrue(); + return; + } + expect(data).assertEqual(cellular.DATA_STATE_DISCONNECTED); + }) + }) + + /** + * @tc.number Telephony_CellularData_getCellularDataState_Promise_0700 + * @tc.name Open the data switch and query the switch status and data status + * @tc.desc Function test + */ + it('Telephony_CellularData_getCellularDataState_Promise_0700', 0, function () { + cellular.enableCellularData().then(() => { + //Turn on the cellular data switch + }).catch((err) => { + expect(false == true).assertTrue(); + return; + }); + cellular.isCellularDataEnabled().then((data) => { + expect(data).assertEqual(true); + }).catch((err) => { + expect(false == true).assertTrue(); + return; + }); + cellular.getCellularDataState().then((data) => { + expect(data).assertEqual(cellular.DATA_STATE_CONNECTING); + }).catch((err) => { + expect(false == true).assertTrue(); + return; + }); + setTimeout(() => { + }, 1000); + cellular.getCellularDataState().then((data) => { + expect(data).assertEqual(cellular.DATA_STATE_CONNECTED); + }).catch((err) => { + expect(false == true).assertTrue(); + return; + }); + }) + + /** + * @tc.number Telephony_CellularData_getCellularDataState_Promise_0800 + * @tc.name Turn off the data switch and query the switch status and data status + * @tc.desc Function test + */ + it('Telephony_CellularData_getCellularDataState_Promise_0800', 0, function () { + cellular.disableCellularData().then(() => { + //Turn off the cellular data switch + }).catch((err) => { + expect(false == true).assertTrue(); + return; + }); + cellular.isCellularDataEnabled().then((data) => { + expect(data).assertEqual(false); + }).catch((err) => { + expect(false == true).assertTrue(); + return; + }); + cellular.getCellularDataState().then((data) => { + expect(data).assertEqual(cellular.DATA_STATE_DISCONNECTED); + }).catch((err) => { + expect(false == true).assertTrue(); + return; + }); + }) + + /** + * @tc.number Telephony_CellularData_getCellularDataState_Async_0900 + * @tc.name CellularData Open state 1000 queries + * @tc.desc Reliability test + */ + it('Telephony_CellularData_getCellularDataState_Async_0900', 0, function () { + for (let index = 0; index < TTEST_RUN_TIME_1000; index++) { + cellular.isCellularDataEnabled((err, data) => { + if (err) { + expect(false == true).assertTrue(); + return; + } + expect(data).assertEqual(false); + }) + } + }) + + /** + * @tc.number Telephony_CellularData_getCellularDataState_Async_1000 + * @tc.name CellularData Open state 1000 queries + * @tc.desc Reliability test + */ + it('Telephony_CellularData_getCellularDataState_Async_1000', 0, function () { + const startTime = (new Date).getTime(); + for (let index = 0; index < TTEST_RUN_TIME_1000; index++) { + cellular.isCellularDataEnabled((err, data) => { + if (err) { + expect(false == true).assertTrue(); + return; + } + }) + } + const endTime = (new Date).getTime(); + const bool = (endTime - startTime) < USEC_500; + expect(bool).assertEqual(true); + }) + + /** + * @tc.number Telephony_CellularData_isCellularDataEnabled_Promise_1100 + * @tc.name CellularData Open state 1000 queries + * @tc.desc Reliability test + */ + it('Telephony_CellularData_isCellularDataEnabled_Promise_1100', 0, function () { + for (let index = 0; index < TTEST_RUN_TIME_1000; index++) { + cellular.isCellularDataEnabled().then((data) => { + expect(data).assertEqual(false); + }).catch((err) => { + expect(false == true).assertTrue(); + return; + }); + } + }) + + /** + * @tc.number Telephony_CellularData_isCellularDataEnabled_Promise_1200 + * @tc.name IsCellularDataEnabled Perform an average of 20 performance tests + * @tc.desc Performance test + */ + it('Telephony_CellularData_isCellularDataEnabled_Promise_1200', 0, function () { + const startTime = (new Date).getTime(); + for (let index = 0; index < TTEST_RUN_TIME_1000; index++) { + cellular.isCellularDataEnabled().then((data) => { + }).catch((err) => { + expect(false == true).assertTrue(); + return; + }); + } + const endTime = (new Date).getTime(); + const bool = (endTime - startTime) < USEC_500; + expect(bool).assertEqual(true); + }) + + /** + * @tc.number Telephony_CellularData_getCellularDataState_Async_1300 + * @tc.name GetCellularDataState Perform an average of 20 performance tests + * @tc.desc Performance test + */ + it('Telephony_CellularData_getCellularDataState_Async_1300', 0, function () { + for (let index = 0; index < TTEST_RUN_TIME_1000; index++) { + cellular.getCellularDataState((err, data) => { + if (err) { + expect(false == true).assertTrue(); + return; + } + expect(data).assertEqual(cellular.DATA_STATE_DISCONNECTED); + }) + } + }) + + /** + * @tc.number Telephony_CellularData_getCellularDataState_Promise_1400 + * @tc.name GetCellularDataState Perform an average of 20 performance tests + * @tc.desc Performance test + */ + it('Telephony_CellularData_getCellularDataState_Promise_1400', 0, function () { + for (let index = 0; index < TTEST_RUN_TIME_1000; index++) { + cellular.getCellularDataState().then((data) => { + expect(data).assertEqual(cellular.DATA_STATE_DISCONNECTED); + }).catch((err) => { + expect(false == true).assertTrue(); + return; + }); + } + }) + + /** + * @tc.number Telephony_CellularData_getCellularDataState_Async_1500 + * @tc.name Access to cellular data has been linked 1000 times + * @tc.desc Reliability test + */ + it('Telephony_CellularData_getCellularDataState_Async_1500', 0, function () { + cellular.enableCellularData((err) => { + if (err) { + expect(false == true).assertTrue(); + return; + } + //Turn on the cellular data switch + }) + + cellular.isCellularDataEnabled((err, data) => { + if (err) { + expect(false == true).assertTrue(); + return; + } + expect(data).assertEqual(true); + }) + cellular.getCellularDataState((err, data) => { + if (err) { + expect(false == true).assertTrue(); + return; + } + expect(data).assertEqual(cellular.DATA_STATE_CONNECTING); + }) + setTimeout(() => { + }, 1000); + cellular.getCellularDataState((err, data) => { + if (err) { + expect(false == true).assertTrue(); + return; + } + expect(data).assertEqual(cellular.DATA_STATE_CONNECTED); + }) + for (let index = 0; index < TTEST_RUN_TIME_1000; index++) { + cellular.getCellularDataState((err, data) => { + if (err) { + expect(false == true).assertTrue(); + return; + } + expect(data).assertEqual(cellular.DATA_STATE_CONNECTED); + }) + } + }) + + /** + * @tc.number Telephony_CellularData_getCellularDataState_Async_1600 + * @tc.name getCellularDataState Perform an average of 1000 performance tests + * @tc.desc Performance test + */ + it('Telephony_CellularData_getCellularDataState_Async_1600', 0, function () { + const startTime = (new Date).getTime(); + for (let index = 0; index < TTEST_RUN_TIME_1000; index++) { + cellular.getCellularDataState((err, data) => { + if (err) { + expect(false == true).assertTrue(); + return; + } + expect(data).assertEqual(cellular.DATA_STATE_CONNECTED); + }) + } + const endTime = (new Date).getTime(); + const bool = (endTime - startTime) < USEC_500; + expect(bool).assertEqual(true); + }) + + /** + * @tc.number Telephony_CellularData_getCellularDataState_Promise_1700 + * @tc.name Access to cellular data has been linked 1000 times + * @tc.desc Reliability test + */ + it('Telephony_CellularData_getCellularDataState_Promise_1700', 0, function () { + for (let index = 0; index < TTEST_RUN_TIME_1000; index++) { + cellular.getCellularDataState().then((data) => { + expect(data).assertEqual(cellular.DATA_STATE_CONNECTED); + }).catch((err) => { + expect(false == true).assertTrue(); + return; + }); + } + }) + + /** + * @tc.number Telephony_CellularData_getCellularDataState_Promise_1800 + * @tc.name getCellularDataState Perform an average of 1000 performance tests + * @tc.desc Performance test + */ + it('Telephony_CellularData_getCellularDataState_Promise_1800', 0, function () { + const startTime = (new Date).getTime(); + for (let index = 0; index < TTEST_RUN_TIME_1000; index++) { + cellular.getCellularDataState((err, data) => { + expect(data).assertEqual(cellular.DATA_STATE_CONNECTED); + }).catch((err) => { + expect(false == true).assertTrue(); + return; + }); + } + const endTime = (new Date).getTime(); + const bool = (endTime - startTime) < USEC_500; + expect(bool).assertEqual(true); + }) +}) \ No newline at end of file diff --git a/telephony/cellular_data/entry/src/main/resources/base/element/string.json b/telephony/cellular_data/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3a754d288d4c4a561a53aa09fe2b4d84b9562964 --- /dev/null +++ b/telephony/cellular_data/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "CellularDataJSTest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/telephony/cellular_data/entry/src/main/resources/base/media/icon.png b/telephony/cellular_data/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/telephony/cellular_data/entry/src/main/resources/base/media/icon.png differ diff --git a/telephony/cellular_data/entry/src/ohosTest/config.json b/telephony/cellular_data/entry/src/ohosTest/config.json new file mode 100644 index 0000000000000000000000000000000000000000..d3ec714b8ac0d7635685ac02a18daad3fd5dbcf6 --- /dev/null +++ b/telephony/cellular_data/entry/src/ohosTest/config.json @@ -0,0 +1,53 @@ +{ + "app": { + "bundleName": "com.example.cellulardatajstest", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 5, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.cellulardatajstest", + "name": "testModule", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry_test", + "moduleType": "feature", + "installationFree": true + }, + "abilities": [ + { + "name": "decc.testkit.runner.JsEntryAbility", + "description": "Test Entry Ability", + "icon": "$media:icon", + "label": "$string:app_name", + "launchType": "standard", + "orientation": "landscape", + "visible": true, + "type": "page" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 750, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/telephony/cellular_data/entry/src/ohosTest/js/default/app.js b/telephony/cellular_data/entry/src/ohosTest/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..f6cc8926d94f6e4c3803ae8a7be2f5f08c0f78b5 --- /dev/null +++ b/telephony/cellular_data/entry/src/ohosTest/js/default/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 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 default { + onCreate() { + console.info('TestApplication onCreate'); + }, + onDestroy() { + console.info('TestApplication onDestroy'); + } +}; diff --git a/telephony/cellular_data/entry/src/ohosTest/js/default/i18n/en-US.json b/telephony/cellular_data/entry/src/ohosTest/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..55561b83737c3c31d082fbfa11e5fc987a351104 --- /dev/null +++ b/telephony/cellular_data/entry/src/ohosTest/js/default/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/telephony/cellular_data/entry/src/ohosTest/js/default/i18n/zh-CN.json b/telephony/cellular_data/entry/src/ohosTest/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..cce1af06761a42add0cac1a0567aa3237eda8cb4 --- /dev/null +++ b/telephony/cellular_data/entry/src/ohosTest/js/default/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/telephony/cellular_data/entry/src/ohosTest/js/default/pages/index/index.css b/telephony/cellular_data/entry/src/ohosTest/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/telephony/cellular_data/entry/src/ohosTest/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/telephony/cellular_data/entry/src/ohosTest/js/default/pages/index/index.hml b/telephony/cellular_data/entry/src/ohosTest/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/telephony/cellular_data/entry/src/ohosTest/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/telephony/cellular_data/entry/src/ohosTest/js/default/pages/index/index.js b/telephony/cellular_data/entry/src/ohosTest/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..9b041d7007852ac57c688654fb8f42c2c9ac9a51 --- /dev/null +++ b/telephony/cellular_data/entry/src/ohosTest/js/default/pages/index/index.js @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2021 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 file from '@system.file' +import app from '@system.app' +import device from '@system.device' +import router from '@system.router' +import {Core, ExpectExtend, ReportExtend, InstrumentLog} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + const reportExtend = new ReportExtend(file) + const instrumentLog = new InstrumentLog({ + 'id': 'report' + }) + core.addService('expect', expectExtend) + core.addService('report', reportExtend) + core.addService('report', instrumentLog) + core.init() + core.subscribeEvent('spec', instrumentLog) + core.subscribeEvent('suite', instrumentLog) + core.subscribeEvent('task', instrumentLog) + + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} \ No newline at end of file diff --git a/telephony/cellular_data/entry/src/ohosTest/js/test/ExampleJsunit.test.js b/telephony/cellular_data/entry/src/ohosTest/js/test/ExampleJsunit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..d043e7e9479ed2a8e2751397c67d43c2ee8f7a08 --- /dev/null +++ b/telephony/cellular_data/entry/src/ohosTest/js/test/ExampleJsunit.test.js @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2021 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 app from '@system.app' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('appInfoTest', function () { + it('app_info_test_001', 0, function () { + var info = app.getInfo() + expect(info.versionName).assertEqual('1.0') + expect(info.versionCode).assertEqual('3') + }) +}) \ No newline at end of file diff --git a/telephony/cellular_data/entry/src/ohosTest/js/test/List.test.js b/telephony/cellular_data/entry/src/ohosTest/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..d21d417581975daf4033529f6c2bfc7dca43c24a --- /dev/null +++ b/telephony/cellular_data/entry/src/ohosTest/js/test/List.test.js @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2021 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. + */ + +require('./ExampleJsunit.test.js') \ No newline at end of file diff --git a/telephony/cellular_data/entry/src/ohosTest/resources/base/element/string.json b/telephony/cellular_data/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..cfe6ace3398714d932e30fc2678af14053b99bd7 --- /dev/null +++ b/telephony/cellular_data/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "CellularDataJSTest" + }, + { + "name": "mainability_description", + "value": "hap sample empty page" + } + ] +} diff --git a/telephony/cellular_data/entry/src/ohosTest/resources/base/media/icon.png b/telephony/cellular_data/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/telephony/cellular_data/entry/src/ohosTest/resources/base/media/icon.png differ diff --git a/telephony/network_search_test/entry/src/main/config.json b/telephony/network_search_test/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..c60ca2b641506fe61babd8c0754ef16d22341145 --- /dev/null +++ b/telephony/network_search_test/entry/src/main/config.json @@ -0,0 +1,60 @@ +{ + "app": { + "bundleName": "com.ohos.networksearchtest", + "vendor": "ohos", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.ohos.networksearchtest", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "com.ohos.networksearchtest.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/telephony/network_search_test/entry/src/main/js/default/app.js b/telephony/network_search_test/entry/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..8a4398aa76a45cc5dbe221429448933ddd2e9b92 --- /dev/null +++ b/telephony/network_search_test/entry/src/main/js/default/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 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 default { + onCreate() { + console.info('AceApplication onCreate12622'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/telephony/network_search_test/entry/src/main/js/default/i18n/en-US.json b/telephony/network_search_test/entry/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/telephony/network_search_test/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/telephony/network_search_test/entry/src/main/js/default/i18n/zh-CN.json b/telephony/network_search_test/entry/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/telephony/network_search_test/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/telephony/network_search_test/entry/src/main/js/default/pages/index/index.css b/telephony/network_search_test/entry/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/telephony/network_search_test/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/telephony/network_search_test/entry/src/main/js/default/pages/index/index.hml b/telephony/network_search_test/entry/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/telephony/network_search_test/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/telephony/network_search_test/entry/src/main/js/default/pages/index/index.js b/telephony/network_search_test/entry/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..eb58b8cc37cd7e647b2249ec911a0418056127e9 --- /dev/null +++ b/telephony/network_search_test/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2021 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 file from '@system.file' +import app from '@system.app' +import device from '@system.device' +import router from '@system.router' +import {Core, ExpectExtend} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish!') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + core.init() + + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} \ No newline at end of file diff --git a/telephony/network_search_test/entry/src/main/js/test/List.test.js b/telephony/network_search_test/entry/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..8d0dd840962fb5b52945c664c50973eb9c5dcf0b --- /dev/null +++ b/telephony/network_search_test/entry/src/main/js/test/List.test.js @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2021 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. + */ + +require('./NetworkSearch.test.js') \ No newline at end of file diff --git a/telephony/network_search_test/entry/src/main/js/test/NetworkSearch.test.js b/telephony/network_search_test/entry/src/main/js/test/NetworkSearch.test.js new file mode 100644 index 0000000000000000000000000000000000000000..fbe9103147ccbd44b2ebd5fcf8dd0bc2b1045eb4 --- /dev/null +++ b/telephony/network_search_test/entry/src/main/js/test/NetworkSearch.test.js @@ -0,0 +1,539 @@ +/* + * Copyright (C) 2021 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 radio from '@ohos.telephony_radio' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('NetworkSearchTest', function () { + const STLO_1 = 1; + const TEST_RUN_TIME = 1000; + const MSEC_500 = 500; + const SIGNAL_STRENGTH_INVALID = 0; + const SIGNAL_STRENGTH_HIGHEST = 4; + + /* + * @tc.number Telephony_NetworkSearch_getNetworkState_Async_0100 + * @tc.name Test the getNetworkState() query function and return the default card 1 network registration status + * @tc.desc Function test + */ + it('Telephony_NetworkSearch_getNetworkState_Async_0100', 0, async function (done) { + radio.getNetworkState((err, data) => { + if (err) { + expect().assertFail(); + return; + } + expect(data != null && data != undefined).assertTrue(); + expect( data.longOperatorName != "" && + data.longOperatorName != null && + data.longOperatorName != undefined).assertTrue(); + expect( data.shortOperatorName != "" && + data.shortOperatorName != null && + data.shortOperatorName != undefined).assertTrue(); + expect( data.plmnNumeric != "" && + data.plmnNumeric != null && + data.plmnNumeric != undefined).assertTrue(); + }) + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getNetworkState_Async_0200 + * @tc.name The slotId parameter input is 1, test the getNetworkState() query function, + * and return the network registration status of card 1 + * @tc.desc Function test + */ + it('Telephony_NetworkSearch_getNetworkState_Async_0200', 0, async function (done) { + radio.getNetworkState(STLO_1, (err, data) => { + if (err) { + expect().assertFail(); + return; + } + expect(data != null && data != undefined).assertTrue(); + expect( data.longOperatorName != "" && + data.longOperatorName != null && + data.longOperatorName != undefined).assertTrue(); + expect( data.shortOperatorName != "" && + data.shortOperatorName != null && + data.shortOperatorName != undefined).assertTrue(); + expect( data.plmnNumeric != "" && + data.plmnNumeric != null && + data.plmnNumeric != undefined).assertTrue(); + }) + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getNetworkState_Async_0300 + * @tc.name Test getNetworkState() The query function is executed 1000 times, and the network registration status + * of the default card 1 can be successfully returned each time + * @tc.desc Reliability test + */ + it('Telephony_NetworkSearch_getNetworkState_Async_0300', 0, async function (done) { + for (let index = 0; index < TEST_RUN_TIME; index++) { + radio.getNetworkState((err, data) => { + if (err) { + expect().assertFail(); + return; + } + expect(data != null && data != undefined).assertTrue(); + expect( data.longOperatorName != "" && + data.longOperatorName != null && + data.longOperatorName != undefined).assertTrue(); + expect( data.shortOperatorName != "" && + data.shortOperatorName != null && + data.shortOperatorName != undefined).assertTrue(); + expect( data.plmnNumeric != "" && + data.plmnNumeric != null && + data.plmnNumeric != undefined).assertTrue(); + }) + } + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getNetworkState_Async_0400 + * @tc.name Test getNetworkState() query function is executed 1000 times, + * and the output delay is less than 500000us + * @tc.desc Performance test + */ + it('Telephony_NetworkSearch_getNetworkState_Async_0400', 0, async function (done) { + const startTime = (new Date).getTime(); + for (let index = 0; index < TEST_RUN_TIME; index++) { + radio.getNetworkState((err, data) => { + if (err) { + expect().assertFail(); + return; + } + }); + } + const endTime = (new Date).getTime(); + expect(endTime - startTime).assertLess(MSEC_500); + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getNetworkState_Async_0500 + * @tc.name The slotId parameter input is 1, the test getNetworkState() query function is executed 1000 times, + * and the network registration status can be returned every time + * @tc.desc Reliability test + */ + it('Telephony_NetworkSearch_getNetworkState_Async_0500', 0, async function (done) { + for (let index = 0; index < TEST_RUN_TIME; index++) { + radio.getNetworkState(STLO_1, (err, data) => { + if (err) { + expect().assertFail(); + return; + } + expect(data != null && data != undefined).assertTrue(); + }) + } + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getNetworkState_Async_0600 + * @tc.name The slotId parameter input is 1, the test getNetworkState() query function is executed 1000 times, + * and the output delay is less than 500000us + * @tc.desc Performance test + */ + it('Telephony_NetworkSearch_getNetworkState_Async_0600', 0, async function (done) { + const startTime = (new Date).getTime(); + for (let index = 0; index < TEST_RUN_TIME; index++) { + radio.getNetworkState(STLO_1, (err, data) => { + if (err) { + expect(data != null && data != undefined).assertTrue(); + expect().assertFail(); + return; + } + }) + } + const endTime = (new Date).getTime(); + expect(endTime - startTime).assertLess(MSEC_500); + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getRadioTech_Async_0100 + * @tc.name SlotId parameter input is 1, test getRadioTech() query function, return PS, CS network mode + * @tc.desc Function test + */ + it('Telephony_NetworkSearch_getRadioTech_Async_0100', 0, async function (done) { + radio.getRadioTech(STLO_1, (err, {psRadioTech, csRadioTech}) => { + if (err) { + expect().assertFail(); + return; + } + expect(psRadioTech != null && psRadioTech != undefined).assertTrue(); + expect(csRadioTech!= null && csRadioTech!= undefined).assertTrue(); + expect() + }) + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getRadioTech_Async_0200 + * @tc.name The slotId parameter input is 1, the test getRadioTech() query function is executed 1000 times, + * and the network mode of PS and CS is returned. + * @tc.desc Reliability test + */ + it('Telephony_NetworkSearch_getRadioTech_Async_0200', 0, async function (done) { + for (let index = 0; index < TEST_RUN_TIME; index++) { + radio.getRadioTech(STLO_1, (err, {psRadioTech, csRadioTech}) => { + if (err) { + expect().assertFail(); + return; + } + expect(psRadioTech != null && psRadioTech != undefined).assertTrue(); + expect(csRadioTech!= null && csRadioTech!= undefined).assertTrue(); + }) + } + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getRadioTech_Async_0300 + * @tc.name The slotId parameter input is 1, the test getRadioTech() query function is executed 1000 times, + * and the output delay is less than 500000us + * @tc.desc Performance test + */ + it('Telephony_NetworkSearch_getRadioTech_Async_0300', 0, async function (done) { + const startTime = (new Date).getTime(); + for (let index = 0; index < TEST_RUN_TIME; index++) { + radio.getRadioTech(STLO_1, (err, {psRadioTech, csRadioTech}) => { + if (err) { + expect(psRadioTech != null && psRadioTech != undefined).assertTrue(); + expect(csRadioTech!= null && csRadioTech!= undefined).assertTrue(); + expect().assertFail(); + return; + } + }) + } + const endTime = (new Date).getTime(); + expect(endTime - startTime).assertLess(MSEC_500); + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getSignalInformation_Async_0100 + * @tc.name SlotId parameter input is 1, test getSignalInformation() query function, + * return signal strength list information + * @tc.desc Function test + */ + it('Telephony_NetworkSearch_getSignalInformation_Async_0100', 0, async function (done) { + radio.getSignalInformation(STLO_1, (err, data) => { + if (err) { // 调用失败 + expect().assertFail(); + return; + } + expect(data != null && data != undefined).assertTrue(); + }) + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getSignalInformation_Async_0200 + * @tc.name The slotId parameter input is 1, the test getSignalInformation() query function is executed 1000 + * times, and the signal strength list information is returned each time + * @tc.desc Reliability test + */ + it('Telephony_NetworkSearch_getSignalInformation_Async_0200', 0, async function (done) { + for (let index = 0; index < TEST_RUN_TIME; index++) { + radio.getSignalInformation(STLO_1, (err, data) => { + if (err) { // 调用失败 + expect().assertFail(); + return; + } + expect(data != null && data != undefined).assertTrue(); + }) + } + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getSignalInformation_Async_0300 + * @tc.name The slotId parameter input is 1, the test getSignalInformation() query function is executed 1000 + * times, and the output delay is less than 500000us + * @tc.desc Performance test + */ + it('Telephony_NetworkSearch_getSignalInformation_Async_0300', 0, async function (done) { + const startTime = (new Date).getTime(); + for (let index = 0; index < TEST_RUN_TIME; index++) { + radio.getSignalInformation(STLO_1, (err, data) => { + if (err) { + expect(data != null && data != undefined).assertTrue(); + expect().assertFail(); + return; + } + }) + } + const endTime = (new Date).getTime(); + expect(endTime - startTime).assertLess(MSEC_500); + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getNetworkState_Promise_0100 + * @tc.name Test the getNetworkState() query function and return the default card 1 network registration status + * @tc.desc Function test + */ + it('Telephony_NetworkSearch_getNetworkState_Promise_0100', 0, async function (done) { + radio.getNetworkState().then((data) => { + expect(data != null && data != undefined).assertTrue(); + expect( data.longOperatorName != "" && + data.longOperatorName != null && + data.longOperatorName != undefined).assertTrue(); + expect( data.shortOperatorName != "" && + data.shortOperatorName != null && + data.shortOperatorName != undefined).assertTrue(); + expect( data.plmnNumeric != "" && + data.plmnNumeric != null && + data.plmnNumeric != undefined).assertTrue(); + }).catch((err) => { + console.log(err); + expect().assertFail(); + }) + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getNetworkState_Promise_0200 + * @tc.name The slotId parameter input is 1, test the getNetworkState() query function, + * and return the network registration status of card 1 + * @tc.desc Function test + */ + it('Telephony_NetworkSearch_getNetworkState_Promise_0200', 0, async function (done) { + radio.getNetworkState(STLO_1).then((data) => { + expect(data != null && data != undefined).assertTrue(); + expect( data.longOperatorName != "" && + data.longOperatorName != null && + data.longOperatorName != undefined).assertTrue(); + expect( data.shortOperatorName != "" && + data.shortOperatorName != null && + data.shortOperatorName != undefined).assertTrue(); + expect( data.plmnNumeric != "" && + data.plmnNumeric != null && + data.plmnNumeric != undefined).assertTrue(); + }).catch((err) => { + console.log(err); + expect().assertFail(); + }); + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getNetworkState_Promise_0300 + * @tc.name Test getNetworkState() The query function is executed 1000 times, and the network registration status + * of the default card 1 can be successfully returned each time + * @tc.desc Reliability test + */ + it('Telephony_NetworkSearch_getNetworkState_Promise_0300', 0, async function (done) { + for (let index = 0; index < TEST_RUN_TIME; index++) { + radio.getNetworkState().then((data) => { + expect(data != null && data != undefined).assertTrue(); + expect(data.longOperatorName).assertTrue(); + expect(data.shortOperatorName).assertTrue(); + expect(data.plmnNumeric).assertTrue(); + }).catch((err) => { + console.log(err); + expect().assertFail(); + }); + } + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getNetworkState_Promise_0400 + * @tc.name Test getNetworkState() query function is executed 1000 times, + * and the output delay is less than 500000us + * @tc.desc Performance test + */ + it('Telephony_NetworkSearch_getNetworkState_Promise_0400', 0, async function (done) { + const startTime = (new Date).getTime(); + for (let index = 0; index < TEST_RUN_TIME; index++) { + radio.getNetworkState().then((data) => { + //expect do nothing for performence test + }).catch((err) => { + console.log(err); + expect().assertFail(); + }); + } + const endTime = (new Date).getTime(); + expect(endTime - startTime).assertLess(MSEC_500); + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getNetworkState_Promise_0500 + * @tc.name The slotId parameter input is 1, the test getNetworkState() query function is executed 1000 times, + * and the network registration status can be returned every time + * @tc.desc Reliability test + */ + it('Telephony_NetworkSearch_getNetworkState_Promise_0500', 0, async function (done) { + for (let index = 0; index < TEST_RUN_TIME; index++) { + radio.getNetworkState(STLO_1).then((data) => { + expect(data != null && data != undefined).assertTrue(); + }).catch((err) => { + console.log(err); + expect().assertFail(); + return; + }); + } + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getNetworkState_Promise_0600 + * @tc.name The slotId parameter input is 1, the test getNetworkState() query function is executed 1000 times, + * and the output delay is less than 500000us + * @tc.desc Performance test + */ + it('Telephony_NetworkSearch_getNetworkState_Promise_0600', 0, async function (done) { + const startTime = (new Date).getTime(); + for (let index = 0; index < TEST_RUN_TIME; index++) { + radio.getNetworkState(STLO_1).then((data) => { + //expect do nothing for performence test + }).catch((err) => { + console.log(err); + expect().assertFail(); + return; + }); + } + const endTime = (new Date).getTime(); + expect(endTime - startTime).assertLess(MSEC_500); + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getRadioTech_Promise_0100 + * @tc.name SlotId parameter input is 1, test getRadioTech() query function, return PS, CS network mode + * @tc.desc Function test + */ + it('Telephony_NetworkSearch_getRadioTech_Promise_0100', 0, async function (done) { + radio.getRadioTech(STLO_1).then(({psRadioTech, csRadioTech}) => { + expect(psRadioTech != null && psRadioTech != undefined).assertTrue(); + expect(csRadioTech!= null && csRadioTech!= undefined).assertTrue(); + }).catch((err) => { + console.log(err); + expect().expect().assertFail(); + return; + }) + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getRadioTech_Promise_0200 + * @tc.name The slotId parameter input is 1, the test getRadioTech() query function is executed 1000 times, + * and the network mode of PS and CS is returned. + * @tc.desc Reliability test + */ + it('Telephony_NetworkSearch_getRadioTech_Promise_0200', 0, async function (done) { + for (let index = 0; index < TEST_RUN_TIME; index++) { + radio.getRadioTech(STLO_1).then(({psRadioTech, csRadioTech}) => { + expect(psRadioTech != null && psRadioTech != undefined).assertTrue(); + expect(csRadioTech!= null && csRadioTech!= undefined).assertTrue(); + }).catch((err) => { + console.log(err); + expect().expect().assertFail(); + return; + }) + } + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getRadioTech_Promise_0300 + * @tc.name The slotId parameter input is 1, the test getRadioTech() query function is executed 1000 times, + * and the output delay is less than 500000us + * @tc.desc Performance test + */ + it('Telephony_NetworkSearch_getRadioTech_Promise_0300', 0, async function (done) { + const startTime = (new Date).getTime(); + for (let index = 0; index < TEST_RUN_TIME; index++) { + radio.getRadioTech(STLO_1).then(({psRadioTech, csRadioTech}) => { + //expect do nothing for performance test + }).catch((err) => { + console.log(err); + expect().assertFail(); + return; + }) + } + const endTime = (new Date).getTime(); + expect(endTime - startTime).assertLess(MSEC_500); + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getSignalInformation_Promise_0100 + * @tc.name SlotId parameter input is 1, test getSignalInformation() query function, + * return signal strength list information + * @tc.desc Function test + */ + it('Telephony_NetworkSearch_getSignalInformation_Promise_0100', 0, async function (done) { + radio.getSignalInformation(STLO_1).then((data) => { + expect(data != null && data != undefined).assertTrue(); + data.forEach((item) => { + expect(item.signalLevel >= SIGNAL_STRENGTH_INVALID && + item.signalLevel <= SIGNAL_STRENGTH_HIGHEST).assertTrue(); + expect(item.signalType).assertTrue(); + }) + }).catch((err) => { + console.log(err); + expect().assertFail(); + return; + }) + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getSignalInformation_Promise_0200 + * @tc.name The slotId parameter input is 1, the test getSignalInformation() query function is executed 1000 + * times, and the signal strength list information is returned each time + * @tc.desc Reliability test + */ + it('Telephony_NetworkSearch_getSignalInformation_Promise_0200', 0, async function (done) { + for (let index = 0; index < TEST_RUN_TIME; index++) { + radio.getSignalInformation(STLO_1).then((data) => { + expect(data != null && data != undefined).assertTrue(); + }).catch((err) => { + console.log(err); + expect().assertFail(); + return; + }) + } + done() + }) + + /* + * @tc.number Telephony_NetworkSearch_getSignalInformation_Promise_0300 + * @tc.name The slotId parameter input is 1, the test getNetworkState() query function is executed 1000 times, + * and the output delay is less than 500000us + * @tc.desc Performance test + */ + it('Telephony_NetworkSearch_getSignalInformation_Promise_0300', 0, async function (done) { + const startTime = (new Date).getTime(); + for (let index = 0; index < TEST_RUN_TIME; index++) { + radio.getSignalInformation(STLO_1).then((data) => { + //expect do nothing for performance test + }).catch((err) => { + console.log(err); + expect().assertFail(); + return; + }) + } + const endTime = (new Date).getTime(); + expect(endTime - startTime).assertLess(MSEC_500); + done() + }) + }) \ No newline at end of file diff --git a/telephony/network_search_test/entry/src/main/resources/base/element/string.json b/telephony/network_search_test/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..32a2f0f03151a628adddea782adf964121c714b0 --- /dev/null +++ b/telephony/network_search_test/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "NetworkSearchTest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/telephony/network_search_test/entry/src/main/resources/base/media/icon.png b/telephony/network_search_test/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/telephony/network_search_test/entry/src/main/resources/base/media/icon.png differ diff --git a/telephony/sim/entry/src/main/config.json b/telephony/sim/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..92245a90cb192e1374581894d7adaf8268b69aa8 --- /dev/null +++ b/telephony/sim/entry/src/main/config.json @@ -0,0 +1,60 @@ +{ + "app": { + "bundleName": "com.ohos.simcard", + "vendor": "ohos", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.ohos.simcard", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "com.ohos.simcard.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/telephony/sim/entry/src/main/js/default/app.js b/telephony/sim/entry/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..f6cc8926d94f6e4c3803ae8a7be2f5f08c0f78b5 --- /dev/null +++ b/telephony/sim/entry/src/main/js/default/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 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 default { + onCreate() { + console.info('TestApplication onCreate'); + }, + onDestroy() { + console.info('TestApplication onDestroy'); + } +}; diff --git a/telephony/sim/entry/src/main/js/default/i18n/en-US.json b/telephony/sim/entry/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..55561b83737c3c31d082fbfa11e5fc987a351104 --- /dev/null +++ b/telephony/sim/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/telephony/sim/entry/src/main/js/default/i18n/zh-CN.json b/telephony/sim/entry/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..cce1af06761a42add0cac1a0567aa3237eda8cb4 --- /dev/null +++ b/telephony/sim/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/telephony/sim/entry/src/main/js/default/pages/index/index.css b/telephony/sim/entry/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/telephony/sim/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/telephony/sim/entry/src/main/js/default/pages/index/index.hml b/telephony/sim/entry/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/telephony/sim/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/telephony/sim/entry/src/main/js/default/pages/index/index.js b/telephony/sim/entry/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..9b041d7007852ac57c688654fb8f42c2c9ac9a51 --- /dev/null +++ b/telephony/sim/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2021 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 file from '@system.file' +import app from '@system.app' +import device from '@system.device' +import router from '@system.router' +import {Core, ExpectExtend, ReportExtend, InstrumentLog} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + const reportExtend = new ReportExtend(file) + const instrumentLog = new InstrumentLog({ + 'id': 'report' + }) + core.addService('expect', expectExtend) + core.addService('report', reportExtend) + core.addService('report', instrumentLog) + core.init() + core.subscribeEvent('spec', instrumentLog) + core.subscribeEvent('suite', instrumentLog) + core.subscribeEvent('task', instrumentLog) + + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} \ No newline at end of file diff --git a/telephony/sim/entry/src/main/js/test/ExampleJsunit.test.js b/telephony/sim/entry/src/main/js/test/ExampleJsunit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..84aaa51677f7ca4facf238d34f7e220a50b1a6e8 --- /dev/null +++ b/telephony/sim/entry/src/main/js/test/ExampleJsunit.test.js @@ -0,0 +1,599 @@ +/* + * Copyright (C) 2021 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 sim from '@ohos.telephony_sim' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('SimTest', function () { + const SOLTID_1 = 1; + const SOLTID_0 = 0; + const MSEC_500 = 500; + const TIMES_1000 = 1000; + + /* + * @tc.number Telephony_Sim_getISOCountryCodeForSim_Async_0100 + * @tc.name The SOLTID_1 parameter input is 1, test the getISOCountryCodeForSim() query function, + * and return the status of card 1 + * @tc.desc Function test + */ + it('Telephony_Sim_getISOCountryCodeForSim_Async_0100', 0, async function (done) { + sim.getISOCountryCodeForSim(SOLTID_1,(err, data) => { + if (err) { + expect().assertFail(); + return; + } + expect(data).assertTrue(); + }) + done(); + }) + + /*) + * @tc.number Telephony_Sim_getISOCountryCodeForSim_Async_0200 + * @tc.name The SOLTID_1 parameter input is 0, test the getISOCountryCodeForSim() query function, + * and return the status of card 1 + * @tc.desc Function test + */ + it('Telephony_Sim_getISOCountryCodeForSim_Async_0200', 0, async function (done) { + sim.getISOCountryCodeForSim(SOLTID_0,(err, data) => { + if (err) { + expect().assertFail(); + return; + } + expect(data).assertTrue(); + }) + done(); + }) + + /* + * @tc.number Telephony_Sim_getISOCountryCodeForSim_Async_0300 + * @tc.name Test getISOCountryCodeForSim() query function is executed 1000 TIMES_1000, + * and the output delay is less than 500ms + * @tc.desc Function test + */ + it('Telephony_Sim_getISOCountryCodeForSim_Async_0300', 0, async function (done) { + const startTime = (new Date).getTime(); + for (let index = 0; index < TIMES_1000; index++) { + sim.getISOCountryCodeForSim(SOLTID_1,(err, data) => { + expect().assertFail(); + return; + }) + } + const endTime = (new Date).getTime(); + const bool = (endTime - startTime) < MSEC_500; + expect(bool).assertTrue(); + done(); + }) + + /* + * @tc.number Telephony_Sim_getISOCountryCodeForSim_Async_0400 + * @tc.name The SOLTID_1 parameter input is 1, test getISOCountryCodeForSim() query function is executed 1000 TIMES_1000, + * and the status of card 1 can be returned every time + * @tc.desc Function test + */ + it('Telephony_Sim_getISOCountryCodeForSim_Async_0400', 0, async function (done) { + for (let index = 0; index < TIMES_1000; index++) { + sim.getISOCountryCodeForSim(SOLTID_1,(err, data) => { + if (err) { + expect().assertFail(); + return; + } + expect(data).assertTrue(); + }) + } + done(); + }) + + /* + * @tc.number Telephony_Sim_getISOCountryCodeForSim_Promise_0100 + * @tc.name The SOLTID_1 parameter input is 1, test the getISOCountryCodeForSim() query function, + * and return the status of card 1 + * @tc.desc Function test + */ + it('Telephony_Sim_getISOCountryCodeForSim_Promise_0100', 0, async function (done) { + sim.getISOCountryCodeForSim(SOLTID_1).then((data) => { + expect(data).assertTrue(); + }).catch((err) => { + expect().assertFail(); + return; + }) + done(); + }) + + /* + * @tc.number Telephony_Sim_getISOCountryCodeForSim_Async_0200 + * @tc.name The SOLTID_1 parameter input is 0, test the getISOCountryCodeForSim() query function, + * and return the status of card 1 + * @tc.desc Function test + */ + it('Telephony_Sim_getISOCountryCodeForSim_Promise_0200', 0, async function (done) { + sim.getISOCountryCodeForSim(SOLTID_0).then((data) => { + expect(data).assertTrue(); + }).catch((err) => { + expect().assertFail(); + return; + }) + done(); + }) + + /* + * @tc.number Telephony_Sim_getISOCountryCodeForSim_Async_0300 + * @tc.name Test getISOCountryCodeForSim() query function is executed 1000 TIMES_1000, + * and the output delay is less than 500ms + * @tc.desc Function test + */ + it('Telephony_Sim_getISOCountryCodeForSim_Promise_0300', 0, async function (done) { + const startTime = (new Date).getTime(); + for (let index = 0; index < TIMES_1000; index++) { + sim.getISOCountryCodeForSim(SOLTID_1).then((err, data) => { + }).catch((err) => { + expect().assertFail(); + return; + }) + const endTime = (new Date).getTime(); + const bool = (endTime - startTime) < MSEC_500; + expect(bool).assertTrue(); + } + done(); + }) + + /* + * @tc.number Telephony_Sim_getISOCountryCodeForSim_Async_0400 + * @tc.name The SOLTID_1 parameter input is 1, test getISOCountryCodeForSim() query function is executed 1000 TIMES_1000, + * and the status of card 1 can be returned every time + * @tc.desc Function test + */ + it('Telephony_Sim_getISOCountryCodeForSim_Promise_0400', 0, async function (done) { + for (let index = 0; index < TIMES_1000; index++) { + sim.getISOCountryCodeForSim(SOLTID_1).then((data) => { + }).catch((err) => { + expect().assertFail(); + return; + }) + } + done(); + }) + + /* + * @tc.number Telephony_Sim_getSimOperatorNumeric_Async_0100 + * @tc.name The SOLTID_1 parameter input is 1, test the getSimOperatorNumeric() query function, + * and return the status of card 1 + * @tc.desc Function test + */ + it('Telephony_Sim_getSimOperatorNumeric_Async_0100', 0, async function (done) { + sim.getSimOperatorNumeric(SOLTID_1,(err, data) => { + if (err) { + expect().assertFail(); + return; + } + expect(data).assertTrue(); + }) + done(); + }) + + /* + * @tc.number Telephony_Sim_getISOCountryCodeForSim_Async_0200 + * @tc.name The SOLTID_1 parameter input is 0, test the getSimOperatorNumeric() query function, + * and return the status of card 1 + * @tc.desc Function test + */ + it('Telephony_Sim_getSimOperatorNumeric_Async_0200', 0, async function (done) { + sim.getSimOperatorNumeric(SOLTID_0,(err, data) => { + if (err) { + expect().assertFail(); + return; + } + expect(data).assertTrue(); + }) + done(); + }) + + /* + * @tc.number Telephony_Sim_getISOCountryCodeForSim_Async_0300 + * @tc.name Test getSimOperatorNumeric() query function is executed 1000 TIMES_1000, + * and the output delay is less than 500ms + * @tc.desc Function test + */ + it('Telephony_Sim_getSimOperatorNumeric_Async_0300', 0, async function (done) { + const startTime = (new Date).getTime(); + for (let index = 0; index < TIMES_1000; index++) { + sim.getSimOperatorNumeric(SOLTID_1,(err, data) => { + expect().assertFail(); + return; + }) + } + const endTime = (new Date).getTime(); + const bool = (endTime - startTime) < MSEC_500; + expect(bool).assertTrue(); + done(); + }) + + /* + * @tc.number Telephony_Sim_getISOCountryCodeForSim_Async_0400 + * @tc.name The SOLTID_1 parameter input is 1, test getSimOperatorNumeric() query function is executed 1000 TIMES_1000, + * and the status of card 1 can be returned every time + * @tc.desc Function test + */ + it('Telephony_Sim_getSimOperatorNumeric_Async_0400', 0, async function (done) { + for (let index = 0; index < TIMES_1000; index++) { + sim.getSimOperatorNumeric(SOLTID_1,(err, data) => { + if (err) { + expect().assertFail(); + return; + } + expect(data).assertTrue(); + }) + } + done(); + }) + + /* + * @tc.number Telephony_Sim_getSimOperatorNumeric_Promise_0100 + * @tc.name The SOLTID_1 parameter input is 1, test the getSimOperatorNumeric() query function, + * and return the status of card 1 + * @tc.desc Function test + */ + it('Telephony_Sim_getSimOperatorNumeric_Promise_0100', 0, async function (done) { + sim.getSimOperatorNumeric(SOLTID_1).then((data) => { + expect(data).assertTrue(); + }).catch((err) => { + expect().assertFail(); + return; + }) + done(); + }) + + /* + * @tc.number Telephony_Sim_getISOCountryCodeForSim_Async_0400 + * @tc.name The SOLTID_1 parameter input is 0, test the getSimOperatorNumeric() query function, + * and return the status of card 1 + * @tc.desc Function test + */ + it('Telephony_Sim_getSimOperatorNumeric_Promise_0200', 0, async function (done) { + sim.getSimOperatorNumeric(SOLTID_0).then((data) => { + expect(data).assertTrue(); + }).catch((err) => { + expect().assertFail(); + return; + }) + done(); + }) + + /* + * @tc.number Telephony_Search_getState_0300 + * @tc.name Test getSimOperatorNumeric() query function is executed 1000 TIMES_1000, + * and the output delay is less than 500ms + * @tc.desc Function test + */ + it('Telephony_Sim_getSimOperatorNumeric_Promise_0300', 0, async function (done) { + const startTime = (new Date).getTime(); + for (let index = 0; index < TIMES_1000; index++) { + sim.getSimOperatorNumeric(SOLTID_1).then((err, data) => { + }).catch((err) => { + expect().assertFail(); + return; + }) + const endTime = (new Date).getTime(); + const bool = (endTime - startTime) < MSEC_500; + expect(bool).assertTrue(); + } + done(); + }) + + /* + * @tc.number Telephony_Sim_getSimOperatorNumeric_Promise_0400 + * @tc.name The SOLTID_1 parameter input is 1, test getSimOperatorNumeric() query function is executed 1000 TIMES_1000, + * and the status of card 1 can be returned every time + * @tc.desc Function test + */ + it('Telephony_Sim_getSimOperatorNumeric_Promise_0400', 0, async function (done) { + for (let index = 0; index < TIMES_1000; index++) { + sim.getSimOperatorNumeric().then((data) => { + expect(data).assertTrue(); + }).catch((err) => { + expect().assertFail(); + return; + }) + } + done(); + }) + + /* + * @tc.number Telephony_Sim_getSimSpn_Async_0100 + * @tc.name The SOLTID_1 parameter input is 1, test the getSimSpn() query function, + * and return the status of card 1 + * @tc.desc Function test + */ + it('Telephony_Sim_getSimSpn_Async_0100', 0, async function (done) { + sim.getSimSpn(SOLTID_1,(err, data) => { + if (err) { + expect().assertFail(); + return; + } + expect(data).assertTrue(); + }) + done(); + }) + + /* + * @tc.number Telephony_Sim_getISOCountryCodeForSim_Async_0200 + * @tc.name The SOLTID_1 parameter input is 0, test the getSimSpn() query function, + * and return the status of card 1 + * @tc.desc Function test + */ + it('Telephony_Sim_getSimSpn_Async_0200', 0, async function (done) { + sim.getSimSpn(SOLTID_0,(err, data) => { + if (err) { + expect().assertFail(); + return; + } + expect(data).assertTrue(); + }) + done(); + }) + + /* + * @tc.number Telephony_Sim_getISOCountryCodeForSim_Async_0300 + * @tc.name Test getSimSpn() query function is executed 1000 TIMES_1000, + * and the output delay is less than 500ms + * @tc.desc Function test + */ + it('Telephony_Sim_getSimSpn_Async_0300', 0, async function (done) { + const startTime = (new Date).getTime(); + for (let index = 0; index < TIMES_1000; index++) { + sim.getSimSpn(SOLTID_1,(err, data) => { + expect().assertFail(); + return; + }) + } + const endTime = (new Date).getTime(); + const bool = (endTime - startTime) < MSEC_500; + expect(bool).assertTrue(); + done(); + }) + + /* + * @tc.number Telephony_Sim_getSimSpn_Async_0400 + * @tc.name The SOLTID_1 parameter input is 1, test getSimSpn() query function is executed 1000 TIMES_1000, + * and the status of card 1 can be returned every time + * @tc.desc Function test + */ + it('Telephony_Sim_getSimSpn_Async_0400', 0, async function (done) { + for (let index = 0; index < TIMES_1000; index++) { + sim.getSimSpn(SOLTID_1,(err, data) => { + if (err) { + expect().assertFail(); + return; + } + expect(data).assertTrue(); + }) + } + done(); + }) + + /* + * @tc.number Telephony_Sim_getSimSpn_Promise_0100 + * @tc.name The SOLTID_1 parameter input is 1, test the getSimSpn() query function, + * and return the status of card 1 + * @tc.desc Function test + */ + it('Telephony_Sim_getSimSpn_Promise_0100', 0, async function (done) { + sim.getSimSpn(SOLTID_1).then((data) => { + expect(data).assertTrue(); + }).catch((err) => { + expect().assertFail(); + return; + }) + done(); + }) + + /* + * @tc.number Telephony_Sim_getSimSpn_Promise_0200 + * @tc.name The SOLTID_1 parameter input is 0, test the getSimSpn() query function, + * and return the status of card 1 + * @tc.desc Function test + */ + it('Telephony_Sim_getSimSpn_Promise_0200', 0, async function (done) { + sim.getSimSpn(SOLTID_0).then((data) => { + expect(data).assertTrue(); + }).catch((err) => { + expect().assertFail(); + return; + }) + done(); + }) + + /* + * @tc.number Telephony_Search_getState_0300 + * @tc.name Test getSimSpn() query function is executed 1000 TIMES_1000, + * and the output delay is less than 500ms + * @tc.desc Function test + */ + it('Telephony_Sim_getSimSpn_Promise_0300', 0, async function (done) { + const startTime = (new Date).getTime(); + for (let index = 0; index < TIMES_1000; index++) { + sim.getSimSpn(SOLTID_1).then((err, data) => { + const endTime = (new Date).getTime(); + const bool = (endTime - startTime) < MSEC_500; + expect(bool).assertTrue(); + }).catch((err) => { + expect().assertFail(); + return; + }) + } + done(); + }) + + /* + * @tc.number Telephony_Sim_getSimSpn_Promise_0400 + * @tc.name The SOLTID_1 parameter input is 1, test getSimSpn() query function is executed 1000 TIMES_1000, + * and the status of card 1 can be returned every time + * @tc.desc Function test + */ + it('Telephony_Sim_getSimSpn_Promise_0400', 0, async function (done) { + for (let index = 0; index < TIMES_1000; index++) { + sim.getSimSpn().then((data) => { + expect(data).assertTrue(); + }).catch((err) => { + expect().assertFail(); + return; + }) + } + done(); + }) + + /* + * @tc.number Telephony_Sim_getSimState_Async_0100 + * @tc.name The SOLTID_1 parameter input is 1, test the getSimState() query function, + * and return the status of card 1 + * @tc.desc Function test + */ + it('Telephony_Sim_getSimState_Async_0100', 0, async function (done) { + sim.getSimState(SOLTID_1,(err, data) => { + if (err) { + expect(data != sim.SIM_STATE_UNKNOWN).assertTrue(); + return; + } + expect(data).assertTrue(); + }) + done(); + }) + + /* + * @tc.number Telephony_Sim_getISOCountryCodeForSim_Async_0200 + * @tc.name The SOLTID_1 parameter input is 0, test the getSimState() query function, + * and return the status of card 1 + * @tc.desc Function test + */ + it('Telephony_Sim_getSimState_Async_0200', 0, async function (done) { + sim.getSimState(SOLTID_0,(err, data) => { + if (err) { + expect(data != sim.SIM_STATE_UNKNOWN).assertTrue(); + return; + } + expect(data).assertTrue(); + }) + done(); + }) + + /* + * @tc.number Telephony_Sim_getISOCountryCodeForSim_Async_0300 + * @tc.name Test getSimState() query function is executed 1000 TIMES_1000, + * and the output delay is less than 500ms + * @tc.desc Function test + */ + it('Telephony_Sim_getSimState_Async_0300', 0, async function (done) { + const startTime = (new Date).getTime(); + for (let index = 0; index < TIMES_1000; index++) { + sim.getSimState(SOLTID_1,(err, data) => { + expect(data != sim.SIM_STATE_UNKNOWN).assertTrue(); + return; + }) + } + const endTime = (new Date).getTime(); + const bool = (endTime - startTime) < MSEC_500; + expect(bool).assertTrue(); + done(); + }) + + /* + * @tc.number Telephony_Sim_getISOCountryCodeForSim_Async_0400 + * @tc.name The SOLTID_1 parameter input is 1, test getSimState() query function is executed 1000 TIMES_1000, + * and the status of card 1 can be returned every time + * @tc.desc Function test + */ + it('Telephony_Sim_getSimState_Async_0400', 0, async function (done) { + for (let index = 0; index < TIMES_1000; index++) { + sim.getSimState(SOLTID_1,(err, data) => { + if (err) { + expect(data != sim.SIM_STATE_UNKNOWN).assertTrue(); + return; + } + expect(data).assertTrue(); + }) + } + done(); + }) + + /* + * @tc.number Telephony_Sim_getSimState_Promise_0100 + * @tc.name The SOLTID_1 parameter input is 1, test the getSimState() query function, + * and return the status of card 1 + * @tc.desc Function test + */ + it('Telephony_Sim_getSimState_Promise_0100', 0, async function (done) { + sim.getSimState(SOLTID_1).then((data) => { + expect(data).assertTrue(); + }).catch((err) => { + expect().assertFail(); + return; + }) + done(); + }) + + /* + * @tc.number Telephony_Sim_getSimState_Promise_0200 + * @tc.name The SOLTID_1 parameter input is 0, test the getSimState() query function, + * and return the status of card 1 + * @tc.desc Function test + */ + it('Telephony_Sim_getSimState_Promise_0200', 0, async function (done) { + sim.getSimState(SOLTID_0).then((data) => { + expect(data).assertTrue(); + }).catch((err) => { + expect().assertFail(); + return; + }) + done(); + }) + + /* + * @tc.number Telephony_Search_getState_0300 + * @tc.name Test getSimState() query function is executed 1000 TIMES_1000, + * and the output delay is less than 500ms + * @tc.desc Function test + */ + it('Telephony_Sim_getSimState_Promise_0300', 0, async function (done) { + const startTime = (new Date).getTime(); + for (let index = 0; index < TIMES_1000; index++) { + sim.getSimState(SOLTID_1).then((err, data) => { + }).catch((err) => { + expect().assertFail(); + return; + }) + const endTime = (new Date).getTime(); + const bool = (endTime - startTime) < MSEC_500; + expect(bool).assertTrue(); + } + done(); + }) + + /* + * @tc.number Telephony_Sim_getSimState_Promise_0400 + * @tc.name The SOLTID_1 parameter input is 1, test getSimState() query function is executed 1000 TIMES_1000, + * and the status of card 1 can be returned every time + * @tc.desc Function test + */ + it('Telephony_Sim_getSimState_Promise_0400', 0, async function (done) { + for (let index = 0; index < TIMES_1000; index++) { + sim.getSimState().then((data) => { + expect(data).assertTrue(); + }).catch((err) => { + expect().assertFail(); + return; + }) + } + done(); + }) +}) \ No newline at end of file diff --git a/telephony/sim/entry/src/main/js/test/List.test.js b/telephony/sim/entry/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..d21d417581975daf4033529f6c2bfc7dca43c24a --- /dev/null +++ b/telephony/sim/entry/src/main/js/test/List.test.js @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2021 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. + */ + +require('./ExampleJsunit.test.js') \ No newline at end of file diff --git a/telephony/sim/entry/src/main/resources/base/element/string.json b/telephony/sim/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..076625946d65d77394e0e83d71394c2b29ed136c --- /dev/null +++ b/telephony/sim/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "SimCard" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/telephony/sim/entry/src/main/resources/base/media/icon.png b/telephony/sim/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/telephony/sim/entry/src/main/resources/base/media/icon.png differ diff --git a/telephony/sim/entry/src/ohosTest/config.json b/telephony/sim/entry/src/ohosTest/config.json new file mode 100644 index 0000000000000000000000000000000000000000..cef0e712d9234c1fcec2245d8dfe323f22f08438 --- /dev/null +++ b/telephony/sim/entry/src/ohosTest/config.json @@ -0,0 +1,53 @@ +{ + "app": { + "bundleName": "com.ohos.simcard", + "vendor": "ohos", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.ohos.simcard", + "name": "testModule", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry_test", + "moduleType": "feature", + "installationFree": true + }, + "abilities": [ + { + "name": "decc.testkit.runner.JsEntryAbility", + "description": "Test Entry Ability", + "icon": "$media:icon", + "label": "$string:app_name", + "launchType": "standard", + "orientation": "landscape", + "visible": true, + "type": "page" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 750, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/telephony/sim/entry/src/ohosTest/js/default/app.js b/telephony/sim/entry/src/ohosTest/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..f6cc8926d94f6e4c3803ae8a7be2f5f08c0f78b5 --- /dev/null +++ b/telephony/sim/entry/src/ohosTest/js/default/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 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 default { + onCreate() { + console.info('TestApplication onCreate'); + }, + onDestroy() { + console.info('TestApplication onDestroy'); + } +}; diff --git a/telephony/sim/entry/src/ohosTest/js/default/i18n/en-US.json b/telephony/sim/entry/src/ohosTest/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..55561b83737c3c31d082fbfa11e5fc987a351104 --- /dev/null +++ b/telephony/sim/entry/src/ohosTest/js/default/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/telephony/sim/entry/src/ohosTest/js/default/i18n/zh-CN.json b/telephony/sim/entry/src/ohosTest/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..cce1af06761a42add0cac1a0567aa3237eda8cb4 --- /dev/null +++ b/telephony/sim/entry/src/ohosTest/js/default/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/telephony/sim/entry/src/ohosTest/js/default/pages/index/index.css b/telephony/sim/entry/src/ohosTest/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/telephony/sim/entry/src/ohosTest/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/telephony/sim/entry/src/ohosTest/js/default/pages/index/index.hml b/telephony/sim/entry/src/ohosTest/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/telephony/sim/entry/src/ohosTest/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/telephony/sim/entry/src/ohosTest/js/default/pages/index/index.js b/telephony/sim/entry/src/ohosTest/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..9b041d7007852ac57c688654fb8f42c2c9ac9a51 --- /dev/null +++ b/telephony/sim/entry/src/ohosTest/js/default/pages/index/index.js @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2021 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 file from '@system.file' +import app from '@system.app' +import device from '@system.device' +import router from '@system.router' +import {Core, ExpectExtend, ReportExtend, InstrumentLog} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + const reportExtend = new ReportExtend(file) + const instrumentLog = new InstrumentLog({ + 'id': 'report' + }) + core.addService('expect', expectExtend) + core.addService('report', reportExtend) + core.addService('report', instrumentLog) + core.init() + core.subscribeEvent('spec', instrumentLog) + core.subscribeEvent('suite', instrumentLog) + core.subscribeEvent('task', instrumentLog) + + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} \ No newline at end of file diff --git a/telephony/sim/entry/src/ohosTest/js/test/ExampleJsunit.test.js b/telephony/sim/entry/src/ohosTest/js/test/ExampleJsunit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..d043e7e9479ed2a8e2751397c67d43c2ee8f7a08 --- /dev/null +++ b/telephony/sim/entry/src/ohosTest/js/test/ExampleJsunit.test.js @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2021 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 app from '@system.app' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('appInfoTest', function () { + it('app_info_test_001', 0, function () { + var info = app.getInfo() + expect(info.versionName).assertEqual('1.0') + expect(info.versionCode).assertEqual('3') + }) +}) \ No newline at end of file diff --git a/telephony/sim/entry/src/ohosTest/js/test/List.test.js b/telephony/sim/entry/src/ohosTest/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..d21d417581975daf4033529f6c2bfc7dca43c24a --- /dev/null +++ b/telephony/sim/entry/src/ohosTest/js/test/List.test.js @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2021 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. + */ + +require('./ExampleJsunit.test.js') \ No newline at end of file diff --git a/telephony/sim/entry/src/ohosTest/resources/base/element/string.json b/telephony/sim/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..40b70d0207e68e1ba674a72fc9f6cf62be016fa5 --- /dev/null +++ b/telephony/sim/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "SimCard" + }, + { + "name": "mainability_description", + "value": "hap sample empty page" + } + ] +} diff --git a/telephony/sim/entry/src/ohosTest/resources/base/media/icon.png b/telephony/sim/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/telephony/sim/entry/src/ohosTest/resources/base/media/icon.png differ diff --git a/telephony/sms_mms/BUILD.gn b/telephony/sms_mms/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..1fad8038bb5994b426f897420405789b1cdb00aa --- /dev/null +++ b/telephony/sms_mms/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("sms_mms") { + test_hap_name = "sms_mms" + hap_source_path = "hap/entry-debug-signed.hap" +} diff --git a/telephony/sms_mms/Test.json b/telephony/sms_mms/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..e9a825dcc6bdea6a429d42513f049a7b4626d98f --- /dev/null +++ b/telephony/sms_mms/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "21600000", + "package": "ohos.acts.aafwk.ability", + "shell-timeout": "21600000" + }, + "kits": [ + { + "test-file-name": [ + "$module.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/telephony/sms_mms/entry/src/main/config.json b/telephony/sms_mms/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..920c963891fbeeeab77948f444f6fe0ce18a5472 --- /dev/null +++ b/telephony/sms_mms/entry/src/main/config.json @@ -0,0 +1,60 @@ +{ + "app": { + "bundleName": "com.ohos.sms_mms", + "vendor": "ohos", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.ohos.sms_mms", + "name": "sms_mms", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "decc.testkit.runner.JsEntryAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/telephony/sms_mms/entry/src/main/js/default/app.js b/telephony/sms_mms/entry/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..363f2555b1badec9fec342a93141db084083fcb8 --- /dev/null +++ b/telephony/sms_mms/entry/src/main/js/default/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 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 default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/telephony/sms_mms/entry/src/main/js/default/i18n/en-US.json b/telephony/sms_mms/entry/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/telephony/sms_mms/entry/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/telephony/sms_mms/entry/src/main/js/default/i18n/zh-CN.json b/telephony/sms_mms/entry/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/telephony/sms_mms/entry/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/telephony/sms_mms/entry/src/main/js/default/pages/index/index.css b/telephony/sms_mms/entry/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/telephony/sms_mms/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/telephony/sms_mms/entry/src/main/js/default/pages/index/index.hml b/telephony/sms_mms/entry/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/telephony/sms_mms/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/telephony/sms_mms/entry/src/main/js/default/pages/index/index.js b/telephony/sms_mms/entry/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..eb58b8cc37cd7e647b2249ec911a0418056127e9 --- /dev/null +++ b/telephony/sms_mms/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2021 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 file from '@system.file' +import app from '@system.app' +import device from '@system.device' +import router from '@system.router' +import {Core, ExpectExtend} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish!') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + core.init() + + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} \ No newline at end of file diff --git a/telephony/sms_mms/entry/src/main/js/test/List.test.js b/telephony/sms_mms/entry/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..9bfa0d5b46ae80cf811bc41ef3769993ce096769 --- /dev/null +++ b/telephony/sms_mms/entry/src/main/js/test/List.test.js @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2021 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. + */ + +require('./SmsMms.test.js') \ No newline at end of file diff --git a/telephony/sms_mms/entry/src/main/js/test/SmsMms.test.js b/telephony/sms_mms/entry/src/main/js/test/SmsMms.test.js new file mode 100644 index 0000000000000000000000000000000000000000..032c2e844a5bd01c4e449b85f0e55e22985da181 --- /dev/null +++ b/telephony/sms_mms/entry/src/main/js/test/SmsMms.test.js @@ -0,0 +1,831 @@ +/* + * Copyright (C) 2021 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 sms from '@ohos.telephony_sms' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('SmsMmsTest', function () { + var sendCallback = (err, data) => { + }; + var deliveryCallback = (err, data) => { + }; + var rawArray = new Array( + 0x08, 0x91, 0x68, 0x31, 0x08, 0x20, 0x00, 0x75, 0xF4, 0x24, 0x0D, + 0x91, 0x68, 0x81, 0x29, 0x56, 0x29, 0x83, 0xF6, 0x00, 0x00, 0x12, + 0x40, 0x80, 0x01, 0x02, 0x14, 0x23, 0x02, 0xC1, 0x30); + var rawArrayNull = new Array(); + /* + * @tc.number Telephony_SmsMms_sendMessage_0100 + * @tc.name Call the interface sendMessage, set the card slot parameter "slotId" to 1, + * and send SMS successfully + * @tc.desc Function test + */ + it('Telephony_SmsMms_sendMessage_0100', 0, async function (done) { + sms.sendMessage({ + slotId: 1, + destinationHost: '18211305277', + content: 'hello', + sendCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + expect(value.result).assertEquals(sms.SEND_SMS_SUCCESS); + }, + deliveryCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("deliveryCallback success sendResult = " + value.pdu); + expect(value.pdu).assertTrue(); + } + }) + done() + }) + + /* + * @tc.number Telephony_SmsMms_sendMessage_0200 + * @tc.name Call the interface sendMessage, set the card slot parameter "slotId" to 0, + * SMS failed to send + * @tc.desc Function test + */ + it('Telephony_SmsMms_sendMessage_0200', 0, async function (done) { + sms.sendMessage({ + slotId: 0, + destinationHost: '18211305277', + content: 'hello', + sendCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("sendCallback success sendResult = " + value.result); + const bool = (value.result != sms.SEND_SMS_SUCCESS); + expect(bool).assertTrue(); + }, + deliveryCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("deliveryCallback success sendResult = " + value.pdu); + expect(value.pdu).assertTrue(); + } + }) + done() + }) + + /* + * @tc.number Telephony_SmsMms_sendMessage_0300 + * @tc.name Call interface sendMessage, + * set the destinationHost "destinationHost" is not empty, + * send SMS successfully + * @tc.desc Function test + */ + it('Telephony_SmsMms_sendMessage_0300', 0, async function (done) { + sms.sendMessage({ + slotId: 1, + destinationHost: '18211305277', + content: 'hello', + sendCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("sendCallback success sendResult = " + value.result); + expect(value.result).assertEquals(sms.SEND_SMS_SUCCESS); + }, + deliveryCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("deliveryCallback success sendResult = " + value.pdu); + expect(value.pdu).assertTrue(); + } + }) + done() + }) + + /* + * @tc.number Telephony_SmsMms_sendMessage_0400 + * @tc.name Call interface sendMessage, set destinationHost "destinationHost" to empty, + * send SMS failed + * @tc.desc Function test + */ + it('Telephony_SmsMms_sendMessage_0400', 0, async function (done) { + sms.sendMessage({ + slotId: 1, + destinationHost: '', + content: 'hello', + sendCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("sendCallback success sendResult = " + value.result); + const bool = (value.result != sms.SEND_SMS_SUCCESS); + expect(bool).assertTrue(); + }, + deliveryCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("deliveryCallback success sendResult = " + value.pdu); + expect(value.pdu).assertTrue(); + } + }) + done() + }) + + /* + * @tc.number Telephony_SmsMms_sendMessage_0500 + * @tc.name Call interface sendMessage, set the content "content" to empty, + * send a message failed + * @tc.desc Function test + */ + it('Telephony_SmsMms_sendMessage_0500', 0, async function (done) { + sms.sendMessage({ + slotId: 1, + destinationHost: '18211305277', + content: '', + sendCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("sendCallback success sendResult = " + value.result); + const bool = (value.result != sms.SEND_SMS_SUCCESS); + expect(bool).assertTrue(); + }, + deliveryCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("deliveryCallback success sendResult = " + value.pdu); + expect(value.pdu).assertTrue(); + } + }) + done() + }) + + /* + * @tc.number Telephony_SmsMms_sendMessage_0600 + * @tc.name Call the interface SendMessage, set the length of "content" to 159 bytes, + * and send a short message successfully + * @tc.desc Function test + */ + it('Telephony_SmsMms_sendMessage_0600', 0, async function (done) { + const count = 159; + let str = ''; + for (let index = 0; index < count; index++) { + str+='a'; + } + sms.sendMessage({ + slotId: 1, + destinationHost: '18211305277', + content: str, + sendCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("sendCallback success sendResult = " + value.result); + expect(value.result).assertEquals(sms.SEND_SMS_SUCCESS); + }, + deliveryCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("deliveryCallback success sendResult = " + value.pdu); + expect(value.pdu).assertTrue(); + } + }) + done() + }) + + /* + * @tc.number Telephony_SmsMms_sendMessage_0700 + * @tc.name Call the interface SendMessage, set the length of "content" to 160 bytes, + * and send a short message successfully + * @tc.desc Function test + */ + it('Telephony_SmsMms_sendMessage_0700', 0, async function (done) { + const count = 160; + let str = ''; + for (let index = 0; index < count; index++) { + str+='a'; + } + sms.sendMessage({ + slotId: 1, + destinationHost: '18211305277', + content: str, + sendCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("sendCallback success sendResult = " + value.result); + expect(value.result).assertEquals(sms.SEND_SMS_SUCCESS); + }, + deliveryCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("deliveryCallback success sendResult = " + value.pdu); + expect(value.pdu).assertTrue(); + } + }) + done() + }) + + /* + * @tc.number Telephony_SmsMms_sendMessage_0800 + * @tc.name Call the interface SendMessage, set the length of "content" to 161 bytes, + * and send a short message successfully + * @tc.desc Function test + */ + it('Telephony_SmsMms_sendMessage_0800', 0, async function (done) { + const count = 161; + let str = ''; + for (let index = 0; index < count; index++) { + str+='a'; + } + sms.sendMessage({ + slotId: 1, + destinationHost: '18211305277', + content: str, + sendCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("sendCallback success sendResult = " + value.result); + expect(value.result).assertEquals(sms.SEND_SMS_SUCCESS); + }, + deliveryCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("deliveryCallback success sendResult = " + value.pdu); + expect(value.pdu).assertTrue(); + } + }) + done() + }) + + /* + * @tc.number Telephony_SmsMms_sendMessage_0900 + * @tc.name Call the interface SendMessage, + * set the content "Content" as the content of Chinese character type, + * and send a short message successfully + * @tc.desc Function test + */ + it('Telephony_SmsMms_sendMessage_0900', 0, async function (done) { + sms.sendMessage({ + slotId: 1, + destinationHost: '18211305277', + content: '这是测试文本', + sendCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("sendCallback success sendResult = " + value.result); + expect(value.result).assertEquals(sms.SEND_SMS_SUCCESS); + }, + deliveryCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("deliveryCallback success sendResult = " + value.pdu); + expect(value.pdu).assertTrue(); + } + }) + done() + }) + + /* + * @tc.number Telephony_SmsMms_sendMessage_1000 + * @tc.name Call the interface sendMessage, + * set the content "content" to a single byte character (English alphabet or number) type of content, + * send a short message successfully + * @tc.desc Function test + */ + it('Telephony_SmsMms_sendMessage_1000', 0, async function (done) { + sms.sendMessage({ + slotId: 1, + destinationHost: '18211305277', + content: 'qwe123', + sendCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("sendCallback success sendResult = " + value.result); + expect(value.result).assertEquals(sms.SEND_SMS_SUCCESS); + }, + deliveryCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("deliveryCallback success sendResult = " + value.pdu); + expect(value.pdu).assertTrue(); + } + }) + done() + }) + + /* + * @tc.number Telephony_SmsMms_sendMessage_1100 + * @tc.name Call the interface sendMessage, + * set the content "content" to the content of special character type, + * and send the short message successfully + * @tc.desc Function test + */ + it('Telephony_SmsMms_sendMessage_1100', 0, async function (done) { + sms.sendMessage({ + slotId: 1, + destinationHost: '18211305277', + content: 'ㄅㄆ$£á ǎ㊊↑◎┴%@&*^#', + sendCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("sendCallback success sendResult = " + value.result); + expect(value.result).assertEquals(sms.SEND_SMS_SUCCESS); + }, + deliveryCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("deliveryCallback success sendResult = " + value.pdu); + expect(value.pdu).assertTrue(); + } + }) + done() + }) + + /* + * @tc.number Telephony_SmsMms_sendMessage_1200 + * @tc.name Call the interface SendMessage. + * If the "content" is of data type, set the destinationPort "DestinationPort" as 0x00, + * and SMS is sent successfully + * @tc.desc Function test + */ + it('Telephony_SmsMms_sendMessage_1200', 0, async function (done) { + sms.sendMessage({ + slotId: 1, + destinationHost: '18211305277', + content: new Uint8Array([54, 2, 3, 6, 3, 1, 1]), + destinationPort: 0x00, + sendCallback: (err, value) => { + if (err) { + console.log("rawdata msg sendCallback err"); + expect().assertFail(); + return; + } + console.log("rawdata msg sendCallback success sendResult = " + value.result); + expect(value.result).assertEquals(sms.SEND_SMS_SUCCESS); + }, + deliveryCallback: (err, value) => { + if (err) { + console.log("deliveryCallback err"); + expect().assertFail(); + return; + } + console.log("deliveryCallback success sendResult = " + value.pdu); + expect(value.pdu).assertTrue(); + } + }) + done() + }) + + /* + * @tc.number Telephony_SmsMms_sendMessage_1300 + * @tc.name Call the interface SendMessage. + * If the "content" is of data type, set the destinationPort "DestinationPort" as 0xffff, + * and SMS is sent successfully + * @tc.desc Function test + */ + it('Telephony_SmsMms_sendMessage_1300', 0, async function (done) { + sms.sendMessage({ + slotId: 1, + destinationHost: '18211305277', + content: new Uint8Array([54, 2, 3, 6, 3, 1, 1]), + destinationPort: 0xffff, + sendCallback: (err, value) => { + if (err) { + console.log("rawdata msg sendCallback err"); + expect().assertFail(); + return; + } + console.log("rawdata msg sendCallback success sendResult = " + value.result); + expect(value.result).assertEquals(sms.SEND_SMS_SUCCESS); + }, + deliveryCallback: (err, value) => { + if (err) { + console.log("deliveryCallback err"); + expect().assertFail(); + return; + } + console.log("deliveryCallback success sendResult = " + value.pdu); + expect(value.pdu).assertTrue(); + } + }) + done() + }) + + /* + * @tc.number Telephony_SmsMms_sendMessage_1400 + * @tc.name Call the interface SendMessage. + * If the "content" is of data type, set the destinationPort "DestinationPort" as 0xffff-1, + * and SMS is sent successfully + * @tc.desc Function test + */ + it('Telephony_SmsMms_sendMessage_1400', 0, async function (done) { + sms.sendMessage({ + slotId: 1, + destinationHost: '18211305277', + content: new Uint8Array([54, 2, 3, 6, 3, 1, 1]), + destinationPort: 0xffff-1, + sendCallback: (err, value) => { + if (err) { + console.log("rawdata msg sendCallback err"); + expect().assertFail(); + return; + } + console.log("rawdata msg sendCallback success sendResult = " + value.result); + expect(value.result).assertEquals(sms.SEND_SMS_SUCCESS); + }, + deliveryCallback: (err, value) => { + if (err) { + console.log("deliveryCallback err"); + expect().assertFail(); + return; + } + console.log("deliveryCallback success sendResult = " + value.pdu); + expect(value.pdu).assertTrue(); + } + }) + done() + }) + + /* + * @tc.number Telephony_SmsMms_sendMessage_1500 + * @tc.name Call the interface SendMessage. + * If the "content" is of data type, set the destinationPort "DestinationPort" as 0xffff-1, + * and SMS is sent successfully + * @tc.desc Function test + */ + it('Telephony_SmsMms_sendMessage_1500', 0, async function (done) { + sms.sendMessage({ + slotId: 1, + destinationHost: '18211305277', + content: new Uint8Array([54, 2, 3, 6, 3, 1, 1]), + destinationPort: 0xffff-1, + sendCallback: (err, value) => { + if (err) { + console.log("rawdata msg sendCallback err"); + expect().assertFail(); + return; + } + console.log("rawdata msg sendCallback success sendResult = " + value.result); + expect(value.result).assertEquals(sms.SEND_SMS_SUCCESS); + }, + deliveryCallback: (err, value) => { + if (err) { + console.log("deliveryCallback err"); + expect().assertFail(); + return; + } + console.log("deliveryCallback success sendResult = " + value.pdu); + expect(value.pdu).assertTrue(); + } + }) + done() + }) + + /* + * @tc.number Telephony_SmsMms_sendMessage_1600 + * @tc.name The loop calls the interface SendMessage1000 times, + * and the message is sent successfully each time + * @tc.desc Function test + */ + it('Telephony_SmsMms_sendMessage_1600', 0, async function (done) { + for(let index = 0; index < 1000; index++) + { + sms.sendMessage({ + slotId: 1, + destinationHost: '18211305277', + content: 'hello', + sendCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("sendCallback success sendResult = " + value.result); + expect(value.result).assertEquals(sms.SEND_SMS_SUCCESS); + }, + deliveryCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + console.log("deliveryCallback success sendResult = " + value.pdu); + expect(value.pdu).assertTrue(); + } + }) + } + done() + }) + + /* + * @tc.number Telephony_SmsMms_sendMessage_1700 + * @tc.name The loop calls the interface SendMessage1000 times, + * Delay < 500ms + * @tc.desc Function test + */ + it('Telephony_SmsMms_sendMessage_1700', 0, async function (done) { + const startTime = (new Date).getTime(); + for(let index = 0; index < 1000; index++) + { + sms.sendMessage({ + slotId: 1, + destinationHost: '18211305277', + content: 'hello', + sendCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + }, + deliveryCallback: (err, value) => { + if (err) { + expect().assertFail(); + return; + } + } + }) + } + const endTime = (new Date).getTime(); + const bool = (endTime - startTime) < 500; + expect(bool).assertTrue(); + done() + }) + + /* + * @tc.number Telephony_SmsMms_createMessage_Async_0100 + * @tc.name Call interface CreateMessage, + * pass in the PDU in line with the coding specification, the specification is 3GPP, + * shortMessage Don't empty + * @tc.desc Function test + */ + it('Telephony_SmsMms_createMessage_Async_0100', 0, async function (done) { + sms.createMessage(rawArray, "3gpp", (err, shortMessage) => { + if (err) { + expect().assertFail(); + return; + } + const bool = (shortMessage != null); + expect(bool).assertTrue(); + }) + done() + }) + + /* + * @tc.number Telephony_SmsMms_createMessage_Async_0200 + * @tc.name Call interface CreateMessage, + * pass in the PDU in line with the coding specification, the specification is 3GPP2, + * shortMessage Don't empty + * @tc.desc Function test + */ + it('Telephony_SmsMms_createMessage_Async_0200', 0, async function (done) { + sms.createMessage(rawArray, "3gpp2", (err, shortMessage) => { + if (err) { + expect().assertFail(); + return; + } + const bool = (shortMessage != null); + expect(bool).assertTrue(); + }) + done() + }) + + /* + * @tc.number Telephony_SmsMms_createMessage_Async_0300 + * @tc.name Call interface CreateMessage, + * The incoming PDU is empty, the specification is 3GPP, + * shortMessage isn't empty + * @tc.desc Function test + */ + it('Telephony_SmsMms_createMessage_Async_0300', 0, async function (done) { + sms.createMessage(rawArrayNull, "3gpp", (err, shortMessage) => { + if (err) { + expect().assertFail(); + return; + } + expect(shortMessage!= null && shortMessage!= undefined).assertTrue(); + }) + done() + }) + + /* + * @tc.number Telephony_SmsMms_createMessage_Async_0400 + * @tc.name Call interface CreateMessage, + * The incoming PDU is empty, the specification is 3GPP2, + * shortMessage isn't empty + * @tc.desc Function test + */ + it('Telephony_SmsMms_createMessage_Async_0400', 0, async function (done) { + sms.createMessage(rawArrayNull, "3gpp2", (err, shortMessage) => { + if (err) { + expect().assertFail(); + return; + } + expect(shortMessage!= null && shortMessage!= undefined).assertTrue(); + }) + done() + }) + + /* + * @tc.number Telephony_SmsMms_createMessage_Async_0500 + * @tc.name Loop through the createMessage1000 times + * @tc.desc Function test + */ + it('Telephony_SmsMms_createMessage_Async_0500', 0, async function (done) { + for(let index = 0; index < 1000; index++) + { + sms.createMessage(rawArray, "3gpp", (err, shortMessage) => { + if (err) { + expect().assertFail(); + return; + } + const bool = (shortMessage != null); + expect(bool).assertTrue(); + }) + } + done() + }) + + /* + * @tc.number Telephony_SmsMms_createMessage_Async_0600 + * @tc.name Loop through the createMessage1000 times, + * Time delay < 500ms + * @tc.desc Function test + */ + it('Telephony_SmsMms_createMessage_Async_0600', 0, async function (done) { + const startTime = (new Date).getTime(); + for(let index = 0; index < 1000; index++) + { + sms.createMessage(rawArray, "3gpp", (err, shortMessage) => { + if (err) { + expect().assertFail(); + return; + } + }) + } + const endTime = (new Date).getTime(); + const bool = (endTime - startTime) < 500; + expect(bool).assertTrue(); + done() + }) + + /* + * @tc.number Telephony_SmsMms_createMessage_Promise_0100 + * @tc.name Call interface CreateMessage, + * pass in the PDU in line with the coding specification, the specification is 3GPP, + * promise returns the result Don't empty + * @tc.desc Function test + */ + it('Telephony_SmsMms_createMessage_Promise_0100', 0, async function (done) { + var promise = sms.createMessage(rawArray, '3gpp'); + promise.then((shortMessage) => { + const bool = (shortMessage != null); + expect(bool).assertTrue(); + }).catch((err) => { + expect().assertFail(); + return; + }) + done() + }) + + /* + * @tc.number Telephony_SmsMms_createMessage_Promise_0200 + * @tc.name Call interface CreateMessage, + * pass in the PDU in line with the coding specification, the specification is 3GPP2, + * promise returns the result Don't empty + * @tc.desc Function test + */ + it('Telephony_SmsMms_createMessage_Promise_0200', 0, async function (done) { + var promise = sms.createMessage(rawArray, '3gpp2'); + promise.then((shortMessage) => { + const bool = (shortMessage != null); + expect(bool).assertTrue(); + }).catch((err) => { + expect().assertFail(); + return; + }) + }) + + /* + * @tc.number Telephony_SmsMms_createMessage_Promise_0300 + * @tc.name Call interface CreateMessage, + * The incoming PDU is empty, the specification is 3GPP, + * promise returns the result Don't empty + * @tc.desc Function test + */ + it('Telephony_SmsMms_createMessage_Promise_0300', 0, async function (done) { + var promise = sms.createMessage(rawArrayNull, '3gpp'); + promise.then((shortMessage) => { + expect(shortMessage!= null && shortMessage!= undefined).assertTrue(); + }).catch((err) => { + expect().assertFail(); + return; + }) + done() + }) + + /* + * @tc.number Telephony_SmsMms_createMessage_Async_0400 + * @tc.name Call interface CreateMessage, + * The incoming PDU is empty, the specification is 3GPP2, + * promise returns the result Don't empty + * @tc.desc Function test + */ + it('Telephony_SmsMms_createMessage_Async_0400', 0, async function (done) { + var promise = sms.createMessage(rawArrayNull, '3gpp2'); + promise.then((shortMessage) => { + expect(shortMessage!= null && shortMessage!= undefined).assertTrue(); + }).catch((err) => { + expect().assertFail(); + return; + }) + done() + }) + + /* + * @tc.number Telephony_SmsMms_createMessage_Async_0500 + * @tc.name Loop through the createMessage1000 times promise + * @tc.desc Function test + */ + it('Telephony_SmsMms_createMessage_Async_0500', 0, async function (done) { + for(let index = 0; index < 1000; index++) + { + var promise = sms.createMessage(rawArray, '3gpp'); + promise.then((shortMessage) => { + const bool = (shortMessage != null); + expect(bool).assertTrue(); + }).catch((err) => { + expect().assertFail(); + return; + }) + } + done() + }) + + /* + * @tc.number Telephony_SmsMms_createMessage_Async_0600 + * @tc.name Loop through the createMessage1000 times promise, + * Time delay < 500ms + * @tc.desc Function test + */ + it('Telephony_SmsMms_createMessage_Async_0600', 0, async function (done) { + const startTime = (new Date).getTime(); + for(let index = 0; index < 1000; index++) + { + var promise = sms.createMessage(rawArray, '3gpp'); + promise.then((shortMessage) => { + }).catch((err) => { + expect().assertFail(); + return; + }) + } + const endTime = (new Date).getTime(); + const bool = (endTime - startTime) < 500; + expect(bool).assertTrue(); + done() + }) +}) diff --git a/telephony/sms_mms/entry/src/main/resources/base/element/string.json b/telephony/sms_mms/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..a74fb5fc9747387b33ffbe689124232f16fb47bd --- /dev/null +++ b/telephony/sms_mms/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "sms_mms" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/telephony/sms_mms/entry/src/main/resources/base/media/icon.png b/telephony/sms_mms/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/telephony/sms_mms/entry/src/main/resources/base/media/icon.png differ diff --git a/test_packages.gni b/test_packages.gni new file mode 100755 index 0000000000000000000000000000000000000000..5b62f8671dc691c1b22b4406fc7ae1f6a6932525 --- /dev/null +++ b/test_packages.gni @@ -0,0 +1,105 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +_all_test_packages = [ + "${ACTS_ROOT}/global:global", + ## "${ACTS_ROOT}/security:security", + "${ACTS_ROOT}/multimedia:multimedia", + "${ACTS_ROOT}/hiviewdfx:hiviewdfxtestacts", + "${ACTS_ROOT}/barrierfree:barrierfree", + # "${ACTS_ROOT}/telephony:telephony", + "${ACTS_ROOT}/appexecfwk:appexecfwk", + "${ACTS_ROOT}/account:account", + # "${ACTS_ROOT}/communication:communication", + # "${ACTS_ROOT}/notification:notification", + # "${ACTS_ROOT}/aafwk:aafwk", + "${ACTS_ROOT}/location:location", + "${ACTS_ROOT}/miscservices:miscservices", + "${ACTS_ROOT}/powermgr:powermgr", + "${ACTS_ROOT}/startup:startup", + "${ACTS_ROOT}/sensors:sensors", + "${ACTS_ROOT}/distributeddatamgr:distributeddatamgr", + # "${ACTS_ROOT}/resourceschedule:resourceschedule", + # "${ACTS_ROOT}/multimodalinput:multimodalinput", + # "${ACTS_ROOT}/distributedschedule:distributedschedule", + "${ACTS_ROOT}/demo:demo", + "${ACTS_ROOT}/developtools:developtoolstestacts", + "${ACTS_ROOT}/updater:update", + "${ACTS_ROOT}/graphic:graphic", + "${ACTS_ROOT}/ace:ace", +] + +_all_test_packages_ivi = [ + # add acts for ivi here + # "${ACTS_ROOT}/multimedia:multimedia_ivi", +] + +_all_test_packages_intellitv = [ + # add acts for intellitv here + "${ACTS_ROOT}/multimedia:multimedia_intellitv", +] + +_all_test_packages_wearable = [ + # add acts for wearable here + "${ACTS_ROOT}/multimedia:multimedia_wearable", +] + +selected_packages_wearable = [] +selected_packages_intellitv = [] +selected_packages_ivi = [] +selected_packages = [] +assert(XTS_SUITENAME != "") +if (build_xts == true && XTS_SUITENAME == "acts") { + _select_script = "//test/xts/tools/build/test_package_select.py" + _subsystem_config_path = rebase_path( + "$root_build_dir/build_configs/subsystem_info/src_subsystem_info.json") + _select_args = [ _subsystem_config_path ] + _all_test_packages + _select_args_ivi = [ _subsystem_config_path ] + _all_test_packages_ivi + _select_args_intellitv = + [ _subsystem_config_path ] + _all_test_packages_intellitv + _select_args_wearable = + [ _subsystem_config_path ] + _all_test_packages_wearable + _target_subsystem = getenv("target_subsystem") + + if (_target_subsystem != "" && _target_subsystem != "all") { + print("Build acts, target_subsystem=" + _target_subsystem) + _select_args += [ "selected_subsystem=" + _target_subsystem ] + _select_args_ivi += [ "selected_subsystem=" + _target_subsystem ] + _select_args_intellitv += [ "selected_subsystem=" + _target_subsystem ] + _select_args_wearable += [ "selected_subsystem=" + _target_subsystem ] + } + + selected_packages = exec_script(_select_script, _select_args, "list lines") + + selected_packages_ivi = + exec_script(_select_script, _select_args_ivi, "list lines") + + selected_packages_intellitv = + exec_script(_select_script, _select_args_intellitv, "list lines") + + selected_packages_wearable = + exec_script(_select_script, _select_args_wearable, "list lines") + + print("Selected packages:") + print(selected_packages) + + # always include testtools + selected_packages += [ "testtools:deploy_testtools" ] + selected_packages_ivi += [ "testtools:deploy_testtools" ] + selected_packages_intellitv += [ "testtools:deploy_testtools" ] + selected_packages_wearable += [ "testtools:deploy_testtools" ] +} else { + print("ACTS build is not enabled") +} diff --git a/testtools/BUILD.gn b/testtools/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..37563874d1b7ef9389717347a639e159c65d16f5 --- /dev/null +++ b/testtools/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_deploy_xdevice("deploy_testtools") { + configs_dir = "./config" +} diff --git a/testtools/config/acts.json b/testtools/config/acts.json new file mode 100755 index 0000000000000000000000000000000000000000..733182d592c1d7c1ea5cfb28863e2f1fb5b9368a --- /dev/null +++ b/testtools/config/acts.json @@ -0,0 +1,33 @@ +{ + "description": "Common configurations for running acts modules", + "kits": [ + { + "type": "PropertyCheckKit", + "property-name": "ro.build.type", + "expected-value": "user", + "throw-error": "false" + }, + { + "type": "PropertyCheckKit", + "property-name": "ro.product.locale", + "expected-value": "en-US", + "throw-error": "false" + }, + { + "type": "ShellKit", + "run-command": [ + "remount", + "mkdir /data/data/resource", + "chmod -R 777 /data/data/resource", + "settings put global verifier_verify_hdc_installs 0", + "settings put secure hdc_install_need_confirm 0", + "setprop persist.sys.platformautotest 1", + "settings put secure smart_suggestion_enable 1" + ], + "teardown-command": [ + "remount", + "rm -rf /data/data/resource" + ] + } + ] +} diff --git a/testtools/config/user_config.xml b/testtools/config/user_config.xml new file mode 100755 index 0000000000000000000000000000000000000000..bab0f05edf2b62140b0c7df929cc48485bd64a2a --- /dev/null +++ b/testtools/config/user_config.xml @@ -0,0 +1,33 @@ + + + + + + true + + + + + + + + + + + + + + diff --git a/updater/BUILD.gn b/updater/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..714f0ce594a2c27c7e691e0635190ec0fb2434dd --- /dev/null +++ b/updater/BUILD.gn @@ -0,0 +1,23 @@ +# Copyright (C) 2021 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("//build/ohos_var.gni") + +group("update") { + testonly = true + if (is_standard_system) { + deps = [ + "update_test:update_js_test", + ] + } +} diff --git a/updater/update_test/BUILD.gn b/updater/update_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b75e9102ec7b73150931edbcbcb99ad13a83d44b --- /dev/null +++ b/updater/update_test/BUILD.gn @@ -0,0 +1,19 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("update_js_test") { + test_hap_name = "updatejstest" + hap_source_path = "hap/entry-debug-signed.hap" +} diff --git a/updater/update_test/Test.json b/updater/update_test/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..745a0e0b2e486b095739aafc4499b152d8c0f0dd --- /dev/null +++ b/updater/update_test/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for time js api Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "21600000", + "package": "ohos.acts.upgrade", + "shell-timeout": "21600000" + }, + "kits": [ + { + "test-file-name": [ + "updatejstest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/updater/update_test/gradle/entry/src/main/config.json b/updater/update_test/gradle/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..3e45182751ef5fc6d2a4ac0af3967e6ec5e4ffd0 --- /dev/null +++ b/updater/update_test/gradle/entry/src/main/config.json @@ -0,0 +1,60 @@ +{ + "app": { + "bundleName": "ohos.acts.upgrade", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.upgrade", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "ohos.acts.upgrade.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard", + "visible": true + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} diff --git a/updater/update_test/gradle/entry/src/main/js/default/app.js b/updater/update_test/gradle/entry/src/main/js/default/app.js new file mode 100755 index 0000000000000000000000000000000000000000..363f2555b1badec9fec342a93141db084083fcb8 --- /dev/null +++ b/updater/update_test/gradle/entry/src/main/js/default/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 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 default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/updater/update_test/gradle/entry/src/main/js/default/pages/index/index.css b/updater/update_test/gradle/entry/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/updater/update_test/gradle/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/updater/update_test/gradle/entry/src/main/js/default/pages/index/index.hml b/updater/update_test/gradle/entry/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/updater/update_test/gradle/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/updater/update_test/gradle/entry/src/main/js/default/pages/index/index.js b/updater/update_test/gradle/entry/src/main/js/default/pages/index/index.js new file mode 100755 index 0000000000000000000000000000000000000000..9ced109a502b895784f2b516c94c33ff799c671e --- /dev/null +++ b/updater/update_test/gradle/entry/src/main/js/default/pages/index/index.js @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2021 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 {Core} from 'deccjsunit/lite' +const core = Core.getInstance() +core.init() +require('../../../test/List.test.js') +core.execute() + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + } +} diff --git a/updater/update_test/gradle/entry/src/main/js/test/List.test.js b/updater/update_test/gradle/entry/src/main/js/test/List.test.js new file mode 100755 index 0000000000000000000000000000000000000000..e1fcb5f1bc18f45deaa0b6b9566b38253b06a0c6 --- /dev/null +++ b/updater/update_test/gradle/entry/src/main/js/test/List.test.js @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2021 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. + */ + +require('./update.test.js') \ No newline at end of file diff --git a/updater/update_test/gradle/entry/src/main/js/test/update.test.js b/updater/update_test/gradle/entry/src/main/js/test/update.test.js new file mode 100755 index 0000000000000000000000000000000000000000..90e8b8504864e21e559ce59de566a723ac102c14 --- /dev/null +++ b/updater/update_test/gradle/entry/src/main/js/test/update.test.js @@ -0,0 +1,1712 @@ +/* + * Copyright (C) 2021 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' +import client from '@ohos.update'; + +let updater; +var param_value1 = 444; +var param_value2 = 555; +var expect_value = 100; +var updateState = { + UPDATE_STATE_INIT : 0, + UPDATE_STATE_CHECK_VERSION_ON : 10, + UPDATE_STATE_CHECK_VERSION_FAIL : 11, + UPDATE_STATE_CHECK_VERSION_SUCCESS : 12, + UPDATE_STATE_DOWNLOAD_ON : 20, + UPDATE_STATE_DOWNLOAD_PAUSE : 21, + UPDATE_STATE_DOWNLOAD_CANCEL : 22, + UPDATE_STATE_DOWNLOAD_FAIL : 23, + UPDATE_STATE_DOWNLOAD_SUCCESS : 24, + UPDATE_STATE_VERIFY_ON : 30, + UPDATE_STATE_VERIFY_FAIL : 31, + UPDATE_STATE_VERIFY_SUCCESS : 32, + UPDATE_STATE_PACKAGE_TRANS_ON : 70, + UPDATE_STATE_PACKAGE_TRANS_FAIL : 71, + UPDATE_STATE_PACKAGE_TRANS_SUCCESS : 72, + UPDATE_STATE_INSTALL_ON : 80, + UPDATE_STATE_INSTALL_FAIL : 81, + UPDATE_STATE_INSTALL_SUCCESS : 82, + UPDATE_STATE_UPDATE_ON : 90, + UPDATE_STATE_UPDATE_FAIL : 91, + UPDATE_STATE_UPDATE_SUCCESS : 92 +}; + +describe('updateclient', function() { + beforeAll(function() { + if (updater == undefined) { + updater = client.getUpdater('OTA'); + } + }); + beforeEach(function() { + if (updater == undefined) { + updater = client.getUpdater('OTA'); + } + }); + afterEach(function() {}); + + /** + * @tc.number SUB_UPDATE_JS_API_0001 + * @tc.name testGetUpdate + * @tc.desc . + */ + it('testGetUpdate', 0, function() { + console.info('testGetUpdate START'); + try { + if (client == undefined) { + console.error("client not defined"); + return; + } + let tmpUpdater = client.getUpdater('/data/updater/updater.zip', 'OTA'); + expect(tmpUpdater != undefined); + if (tmpUpdater == undefined) { + console.error("Fail to get updater"); + return; + } + + } catch(e) { + console.error('[testGetUpdate] fail.' + e); + } + + console.info('[client.getUpdate] success.'); + console.info('testGetUpdate END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0002 + * @tc.name testGetUpdate2 + * @tc.desc Test incorrect parameters. + */ + it('testGetUpdate2', 0, function() { + console.info('testGetUpdate2 START'); + try { + if (client == undefined) { + console.error("client not defined"); + return; + } + let tmpUpdater = client.getUpdater('/data/updater/updater.zip', '44444'); + expect(tmpUpdater == undefined); + } catch(e) { + console.error('[testGetUpdate] fail.' + e); + } + + console.info('[client.getUpdate] success.'); + console.info('testGetUpdate2 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0003 + * @tc.name testGetUpdate3 + * @tc.desc Test incorrect parameters. + */ + it('testGetUpdate3', 0, function() { + console.info('testGetUpdate3 START'); + try { + if (client == undefined) { + console.error("client not defined"); + return; + } + let tmpUpdater = client.getUpdater('/data/updater/updater.zip', 'patch'); + expect(tmpUpdater != undefined); + if (tmpUpdater == undefined) { + console.error("Fail to get updater"); + return; + } + + } catch(e) { + console.error('[testGetUpdate] fail.' + e); + } + + console.info('[client.getUpdate] success.'); + console.info('testGetUpdate3 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0004 + * @tc.name testGetUpdate4 + * @tc.desc Test incorrect parameters. + */ + it('testGetUpdate4', 0, function() { + console.info('testGetUpdate4 START'); + try { + if (client == undefined) { + console.error("client not defined"); + return; + } + let tmpUpdater = client.getUpdater(function(){ + }); + expect(tmpUpdater == undefined); + } catch(e) { + console.error('[testGetUpdate4] fail.' + e); + } + + console.info('[client.getUpdate] success.'); + console.info('testGetUpdate4 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0005 + * @tc.name testGetUpdate5 + * @tc.desc Test incorrect parameters. + */ + it('testGetUpdate5', 0, function() { + console.info('testGetUpdate5 START'); + try { + if (client == undefined) { + console.error("client not defined"); + return; + } + let tmpUpdater = client.getUpdater(param_value1, param_value2); + expect(tmpUpdater == undefined); + } catch(e) { + console.error('[testGetUpdate] fail.' + e); + } + + console.info('[client.getUpdate] success.'); + console.info('testGetUpdate5 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0006 + * @tc.name testGetNewVersionInfo1 + * @tc.desc Get the current system version. + */ + it('testGetNewVersionInfo1', 0, function() { + console.info('testGetNewVersionInfo1 START'); + try { + let ret = updater.getNewVersionInfo(function(err, data){ + console.log("getNewVersionInfo success" + data); + expect(data.status).assertEqual(0); // Has new version. + }); + expect(ret != 0); + } catch(e) { + console.error('[testGetUpdate] fail.' + e); + } + console.info('[getNewVersionInfo] success.'); + console.info('testGetNewVersionInfo1 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0007 + * @tc.name testGetNewVersionInfo2 + * @tc.desc Test incorrect parameters. + */ + it('testGetNewVersionInfo2', 0, function() { + console.info('testGetNewVersionInfo2 START'); + try { + let ret = updater.getNewVersionInfo(); + expect(ret != 0); + console.info('[getNewVersionInfo] success.'); + console.info('testGetNewVersionInfo2 END'); + } catch(e) { + console.error('[testGetUpdate] fail.' + e); + } + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0008 + * @tc.name testGetNewVersionInfo3 + * @tc.desc Test incorrect parameters. + */ + it('testGetNewVersionInfo3', 0, function() { + console.info('testGetNewVersionInfo3 START'); + try { + let ret = updater.getNewVersionInfo("dddddd"); + expect(ret != 0); + console.info('[getNewVersionInfo] success.'); + console.info('testGetNewVersionInfo2 END'); + } catch(e) { + console.error('[testGetUpdate] fail.' + e); + } + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0009 + * @tc.name testGetNewVersionInfo4 + * @tc.desc Test incorrect parameters. + */ + it('testGetNewVersionInfo4', 0, function() { + console.info('testGetNewVersionInfo4 START'); + try { + let ret = updater.getNewVersionInfo(param_value1); + expect(ret != 0); + console.info('[getNewVersionInfo] success.'); + console.info('testGetNewVersionInfo5 END'); + } catch(e) { + console.error('[testGetUpdate] fail.' + e); + } + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0010 + * @tc.name testGetNewVersionInfo5 + * @tc.desc Test incorrect parameters. + */ + it('testGetNewVersionInfo5', 0, function() { + console.info('testGetNewVersionInfo5 START'); + try { + let ret = updater.getNewVersionInfo(param_value1, param_value2); + expect(ret != 0); + console.info('[getNewVersionInfo] success.'); + console.info('testGetNewVersionInfo5 END'); + } catch(e) { + console.error('[testGetUpdate] fail.' + e); + } + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0011 + * @tc.name testGetNewVersionInfoPromise + * @tc.desc Called by Promise to get the new version. + */ + it('testGetNewVersionInfoPromise', 0, function() { + console.info('testGetNewVersionInfoPromise START'); + try { + let ret = updater.getNewVersionInfo().then(data => { + console.log("getNewVersionInfo success " + data); + expect(data.status).assertEqual(0); // Has new version. + expect(data.checkResults.size > 0); + console.log(`info versionName = ` + data.checkResults[0].versionName); + console.log(`info versionCode = ` + data.checkResults[0].versionCode); + console.log(`info verifyInfo = ` + data.checkResults[0].verifyInfo); + console.log(`info descriptionId = ` + data.checkResults[0].descriptionId); + console.log(`info content = ` + data.descriptionInfo[0].content); + console.log(`info size = ` + data.checkResults[0].size); + }).catch(error => + console.error("getNewVersionInfo catch " + error) + ); + expect(ret != 0); + } catch(e) { + console.error("getNewVersionInfo catch " + e); + } + console.info('[getNewVersionInfo] success.'); + console.info('testGetNewVersionInfoPromise END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0012 + * @tc.name testGetNewVersionInfoPromise2 + * @tc.desc Test incorrect parameters. + */ + it('testGetNewVersionInfoPromise2', 0, function() { + console.info('testGetNewVersionInfoPromise2 START'); + try { + let ret = updater.getNewVersionInfo(param_value1).then(data => { + console.log("getNewVersionInfo success " + data); + }).catch(error => + console.error("getNewVersionInfo catch " + error) + ); + expect(ret != 0); + } catch(e) { + console.error("getNewVersionInfo catch " + e); + } + console.info('[getNewVersionInfo] success.'); + console.info('testGetNewVersionInfoPromise2 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0013 + * @tc.name testGetNewVersionInfoPromise3 + * @tc.desc Test incorrect parameters. + */ + it('testGetNewVersionInfoPromise3', 0, function() { + console.info('testGetNewVersionInfoPromise3 START'); + try { + let ret = updater.getNewVersionInfo(param_value1, param_value2).then(data => { + }).catch(error => + console.error("getNewVersionInfo catch " + error) + ); + expect(ret != 0); + } catch(e) { + console.error("getNewVersionInfo catch " + e); + } + console.info('[getNewVersionInfo] success.'); + console.info('testGetNewVersionInfoPromise3 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0014 + * @tc.name testGetNewVersionInfoPromise4 + * @tc.desc Test incorrect parameters. + */ + it('testGetNewVersionInfoPromise4', 0, function() { + console.info('testGetNewVersionInfoPromise4 START'); + try { + let ret = updater.getNewVersionInfo("44444444").then(data => { + }).catch(error => + console.error("getNewVersionInfo catch " + error) + ); + expect(ret != 0); + } catch(e) { + console.error("getNewVersionInfo catch " + e); + } + console.info('[getNewVersionInfo] success.'); + console.info('testGetNewVersionInfoPromise4 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0015 + * @tc.name testGetNewVersionInfoPromise5 + * @tc.desc Test incorrect parameters. + */ + it('testGetNewVersionInfoPromise5', 0, function() { + console.info('testGetNewVersionInfoPromise5 START'); + try { + let ret = updater.getNewVersionInfo("44444444", "5555555").then(data => { + }).catch(error => + console.error("getNewVersionInfo error " + error) + ); + expect(ret != 0); + } catch(e) { + console.error("getNewVersionInfo catch " + e); + } + console.info('[getNewVersionInfo] success.'); + console.info('testGetNewVersionInfoPromise5 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0016 + * @tc.name testCheckNewVersion1 + * @tc.desc Check the new version. + */ + it('testCheckNewVersion1', 0, function() { + console.info('testCheckNewVersion1 START'); + try { + let ret = updater.checkNewVersion(function(err, data){ + console.log("checkNewVersion success" + data); + expect(data.status).assertEqual(0); // Has new version. + expect(data.checkResults.size > 0); + console.log(`info versionName = ` + data.checkResults[0].versionName); + console.log(`info versionCode = ` + data.checkResults[0].versionCode); + console.log(`info verifyInfo = ` + data.checkResults[0].verifyInfo); + console.log(`info descriptionId = ` + data.checkResults[0].descriptionId); + console.log(`info content = ` + data.descriptionInfo[0].content); + console.log(`info size = ` + data.checkResults[0].size); + }, + error => { + console.log("checkNewVersion error" + error) + }); + expect(ret != 0); + } catch(e) { + console.error("checkNewVersion catch " + e); + } + console.info('[checkNewVersion] success.'); + console.info('testCheckNewVersion1 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0017 + * @tc.name testCheckNewVersion2 + * @tc.desc Test incorrect parameters. + */ + it('testCheckNewVersion2', 0, function() { + console.info('testCheckNewVersion2 START'); + try { + let ret = updater.checkNewVersion(); + expect(ret != 0); + console.info('[checkNewVersion] success.' + ret); + console.info('testCheckNewVersion2 END'); + } catch(e) { + console.error("checkNewVersion catch " + e); + } + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0018 + * @tc.name testCheckNewVersion3 + * @tc.desc Test incorrect parameters. + */ + it('testCheckNewVersion3', 0, function() { + console.info('testCheckNewVersion3 START'); + try { + let ret = updater.checkNewVersion("33333"); + expect(ret != 0); + console.info('[checkNewVersion] success.' + ret); + console.info('testCheckNewVersion3 END'); + } catch(e) { + console.error("checkNewVersion catch " + e); + } + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0019 + * @tc.name testCheckNewVersion4 + * @tc.desc Test incorrect parameters. + */ + it('testCheckNewVersion4', 0, function() { + console.info('testCheckNewVersion4 START'); + try { + let ret = updater.checkNewVersion(param_value1); + expect(ret != 0); + console.info('[checkNewVersion] success.' + ret); + console.info('testCheckNewVersion4 END'); + } catch(e) { + console.error("checkNewVersion catch " + e); + } + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0020 + * @tc.name testCheckNewVersion5 + * @tc.desc Test incorrect parameters. + */ + it('testCheckNewVersion5', 0, function() { + console.info('testCheckNewVersion4 START'); + try { + let ret = updater.checkNewVersion(param_value1, param_value2); + expect(ret != 0); + console.info('[checkNewVersion] success.' + ret); + console.info('testCheckNewVersion5 END'); + } catch(e) { + console.error("checkNewVersion catch " + e); + } + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0021 + * @tc.name testCheckNewVersionPromise + * @tc.desc Called by promise, the result is the new Promise version. + */ + it('testCheckNewVersionPromise', 0, function() { + console.info('testCheckNewVersionPromise START'); + try { + let ret = updater.checkNewVersion().then(data => { + console.log("checkNewVersion success" + data); + expect(data.status).assertEqual(0); + expect(data.checkResults.size > 0); + console.log(`info versionName = ` + data.checkResults[0].versionName); + console.log(`info versionCode = ` + data.checkResults[0].versionCode); + console.log(`info verifyInfo = ` + data.checkResults[0].verifyInfo); + console.log(`info descriptionId = ` + data.checkResults[0].descriptionId); + console.log(`info content = ` + data.descriptionInfo[0].content); + console.log(`info size = ` + data.checkResults[0].size); + }).catch(error => + console.error("checkNewVersion error " + error) + ); + expect(ret != 0); + } catch(e) { + console.error("checkNewVersion catch " + e) + } + console.info('[checkNewVersion] success.'); + console.info('testCheckNewVersionPromise END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0022 + * @tc.name testCheckNewVersionPromise2 + * @tc.desc Test incorrect parameters. + */ + it('testCheckNewVersionPromise2', 0, function() { + console.info('testCheckNewVersionPromise2 START'); + try{ + let ret = updater.checkNewVersion(2).then(data => { + }).catch(error => + console.error("checkNewVersion error " + error) + ); + expect(ret != 0); + } catch(e) { + console.error("checkNewVersion catch " + e); + } + console.info('[checkNewVersion] success.'); + console.info('testCheckNewVersionPromise2 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0023 + * @tc.name testCheckNewVersionPromise3 + * @tc.desc Test incorrect parameters. + */ + it('testCheckNewVersionPromise3', 0, function() { + console.info('testCheckNewVersionPromise3 START'); + try{ + let ret = updater.checkNewVersion(2, 4).then(data => { + }).catch(error => + console.error("checkNewVersion error " + error) + ); + expect(ret != 0); + } catch(e) { + console.error("checkNewVersion catch " + e); + } + console.info('[checkNewVersion] success.'); + console.info('testCheckNewVersionPromise3 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0024 + * @tc.name testCheckNewVersionPromise4 + * @tc.desc Test incorrect parameters. + */ + it('testCheckNewVersionPromise4', 0, function() { + console.info('testCheckNewVersionPromise4 START'); + try{ + let ret = updater.checkNewVersion("3333").then(data => { + }).catch(error => + console.error("checkNewVersion error " + error) + ); + expect(ret != 0); + } catch(e) { + console.error("checkNewVersion catch " + e); + } + console.info('[checkNewVersion] success.'); + console.info('testCheckNewVersionPromise4 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0025 + * @tc.name testCheckNewVersionPromise5 + * @tc.desc Test incorrect parameters. + */ + it('testCheckNewVersionPromise5', 0, function() { + console.info('testCheckNewVersionPromise5 START'); + try{ + let ret = updater.checkNewVersion("3333", "44444").then(data => { + }).catch(error => + console.error("checkNewVersion error " + error) + ); + expect(ret != 0); + } catch(e) { + console.error("checkNewVersion catch " + e); + } + console.info('[checkNewVersion] success.'); + console.info('testCheckNewVersionPromise5 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0026 + * @tc.name testSetUpdatePolicy001 + * @tc.desc Test and set the upgrade strategy, check whether the result is correct. + */ + it('testSetUpdatePolicy001', 0, function() { + console.info('testSetUpdatePolicy001 START' + updater); + // Set strategy. + let policy = { + autoDownload: false, + autoDownloadNet: true, + mode: 2, + autoUpgradeInterval: [ 2, 3 ], + autoUpgradeCondition: 2 + } + try { + let ret = updater.setUpdatePolicy(policy, function(err, data){ + console.log("setUpdatePolicy success" + data); + expect(data).assertEqual(0); + }); + expect(ret != 0); + } catch(e) { + console.error('[testSetUpdatePolicy001] fail.' + e); + } + console.info('[setUpdatePolicy] success.'); + console.info('testSetUpdatePolicy001 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0027 + * @tc.name testGetUpdatePolicy001 + * @tc.desc . + */ + it('testGetUpdatePolicy001', 0, function() { + console.info('testGetUpdatePolicy001 START'); + try { + let ret = updater.getUpdatePolicy(function(err, data){ + console.log("getUpdatePolicy success" + data); + expect(data.autoDownload).assertEqual(false); + expect(data.autoDownloadNet).assertEqual(true); + expect(data.mode).assertEqual(2); + expect(data.autoUpgradeInterval[0]).assertEqual(2); + expect(data.autoUpgradeInterval[1]).assertEqual(3); + + }); + expect(ret != 0); + } catch(e) { + console.error('[testGetUpdatePolicy001] fail.' + e); + } + console.info('[getUpdatePolicy] success.'); + console.info('testGetUpdatePolicy001 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0028 + * @tc.name testSetUpdatePolicy002 + * @tc.desc Modify the upgrade strategy and check whether the result is correct. + */ + it('testSetUpdatePolicy002', 0, function() { + console.info('testSetUpdatePolicy002 START' + updater); + let policy = { + autoDownload: true, + autoDownloadNet: true, + mode: 2, + autoUpgradeInterval: [ 2, 3 ], + autoUpgradeCondition: 2 + } + try { + let ret = updater.setUpdatePolicy(policy, function(err, data){ + console.log("setUpdatePolicy success" + data); + expect(data).assertEqual(0); + }); + expect(ret != 0); + } catch(e) { + console.error('[testSetUpdatePolicy002] fail.' + e); + } + + console.info('[setUpdatePolicy] success.'); + console.info('testSetUpdatePolicy002 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0029 + * @tc.name testGetUpdatePolicy002 + * @tc.desc Get the modified strategy. + */ + it('testGetUpdatePolicy002', 0, function() { + console.info('testGetUpdatePolicy002 START'); + try { + let ret = updater.getUpdatePolicy(function(err, data){ + console.log("getUpdatePolicy success" + data); + expect(data.autoDownload).assertEqual(true); + expect(data.autoDownloadNet).assertEqual(true); + expect(data.mode).assertEqual(2); + expect(data.autoUpgradeInterval[0]).assertEqual(2); + expect(data.autoUpgradeInterval[1]).assertEqual(3); + }); + expect(ret != 0); + } catch(e) { + console.error('[testGetUpdatePolicy002] fail.' + e); + } + + console.info('[getUpdatePolicy] success.'); + console.info('testGetUpdatePolicy002 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0030 + * @tc.name testSetUpdatePolicy003 + * @tc.desc Modify strategy mode. + */ + it('testSetUpdatePolicy003', 0, function() { + console.info('testSetUpdatePolicy003 START' + updater); + // Set strategy. + let policy = { + autoDownload: false, + autoDownloadNet: false, + mode: 2, + autoUpgradeInterval: [ 2, 3 ], + autoUpgradeCondition: 2 + } + try { + let ret = updater.setUpdatePolicy(policy, function(err, data){ + console.log("setUpdatePolicy success" + data); + expect(data).assertEqual(0); + }) + expect(ret != 0); + } catch(e) { + console.error('[testSetUpdatePolicy003] fail.' + e); + } + console.info('[setUpdatePolicy] success.'); + console.info('testSetUpdatePolicy003 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0031 + * @tc.name testGetUpdatePolicy003 + * @tc.desc Obtain strategy mode. + */ + it('testGetUpdatePolicy003', 0, function() { + console.info('testGetUpdatePolicy003 START ' + updater); + try { + let ret = updater.getUpdatePolicy(function(err, data){ + console.log("getUpdatePolicy success" + data); + expect(data.autoDownload).assertEqual(false); + expect(data.autoDownloadNet).assertEqual(false); + expect(data.mode).assertEqual(2); + expect(data.autoUpgradeInterval[0]).assertEqual(2); + expect(data.autoUpgradeInterval[1]).assertEqual(3); + }) + expect(ret != 0); + } catch(e) { + console.error('[testGetUpdatePolicy003] fail.' + e); + } + console.info('[getUpdatePolicy] success.'); + console.info('testGetUpdatePolicy003 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0032 + * @tc.name testSetUpdatePolicy004 + * @tc.desc Set policy upgrade interval. + */ + it('testSetUpdatePolicy004', 0, function() { + console.info('testSetUpdatePolicy004 START' + updater); + // Set strategy. + let policy = { + autoDownload: false, + autoDownloadNet: false, + mode: 1, + autoUpgradeInterval: [ 100, 100], + autoUpgradeCondition: 2 + } + try { + let ret = updater.setUpdatePolicy(policy, function(err, data){ + console.log("setUpdatePolicy success" + data); + expect(data).assertEqual(0); + }) + expect(ret != 0); + } catch(e) { + console.error('[testGetUpdatePolicy003] fail.' + e); + } + console.info('[setUpdatePolicy] success.'); + console.info('testSetUpdatePolicy004 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0033 + * @tc.name testGetUpdatePolicy004 + * @tc.desc Obtain policy upgrade interval. + */ + it('testGetUpdatePolicy004', 0, function() { + console.info('testGetUpdatePolicy004 START' + updater); + try { + let ret = updater.getUpdatePolicy(function(err, data){ + console.log("getUpdatePolicy success" + data); + expect(data.autoDownload).assertEqual(false); + expect(data.autoDownloadNet).assertEqual(false); + expect(data.mode).assertEqual(1); + expect(data.autoUpgradeInterval[0]).assertEqual(expect_value); + expect(data.autoUpgradeInterval[1]).assertEqual(expect_value); + }) + expect(ret != 0); + } catch(e) { + console.error('[testGetUpdatePolicy004] fail.' + e); + } + console.info('[getUpdatePolicy] success.'); + console.info('testGetUpdatePolicy004 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0034 + * @tc.name testSetUpdatePolicy005 + * @tc.desc Test incorrect parameters. + */ + it('testSetUpdatePolicy005', 0, function() { + console.info('testSetUpdatePolicy005 START' + updater); + try { + let ret = updater.setUpdatePolicy("", function(err, data){ + console.log("setUpdatePolicy success" + data); + expect(data).assertEqual(0); + }); + expect(ret != 0); + } catch(e) { + console.error('[testSetUpdatePolicy005] fail.' + e); + } + console.info('[setUpdatePolicy] success.'); + console.info('testSetUpdatePolicy005 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0035 + * @tc.name testGetUpdatePolicy005 + * @tc.desc Test incorrect parameters. + */ + it('testGetUpdatePolicy005', 0, function() { + console.info('testGetUpdatePolicy005 START' + updater); + try { + let ret = updater.getUpdatePolicy("", function(err, data){ + }) + expect(ret != 0); + } catch(e) { + console.error('[testSetUpdatePolicy005] fail.' + e); + } + console.info('[getUpdatePolicy] success.'); + console.info('testGetUpdatePolicy005 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0036 + * @tc.name testSetUpdatePolicyPromise + * @tc.desc Promise method call. + */ + it('testSetUpdatePolicyPromise', 0, function() { + console.info('testSetUpdatePolicyPromise START' + updater); + // Set strategy. + let policy = { + autoDownload: false, + autoDownloadNet: true, + mode: 2, + autoUpgradeInterval: [ 2, 3 ], + autoUpgradeCondition: 2 + } + try { + let ret = updater.setUpdatePolicy(policy).then(data => { + console.log("setUpdatePolicy success" + data); + expect(data).assertEqual(0); + }).catch(error => + console.error("setUpdatePolicy error " + error) + ); + expect(ret != 0); + } catch(e) { + console.error('[testSetUpdatePolicyPromise] fail.' + e); + } + console.info('[setUpdatePolicy] success.'); + console.info('testSetUpdatePolicyPromise END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0037 + * @tc.name testGetUpdatePolicyPromise + * @tc.desc Promise method call. + */ + it('testGetUpdatePolicyPromise', 0, function() { + console.info('testGetUpdatePolicyPromise START'); + try { + let ret = updater.getUpdatePolicy().then(data => { + console.log("getUpdatePolicy success" + data); + expect(data.autoDownload).assertEqual(false); + expect(data.autoDownload).assertEqual(true); + expect(data.mode).assertEqual(2); + expect(data.autoUpgradeInterval[0]).assertEqual(2); + expect(data.autoUpgradeInterval[1]).assertEqual(3); + expect(data.autoUpgradeCondition).assertEqual(2); + }).catch(error => + console.error("getUpdatePolicy catch " + error) + ); + expect(ret != 0); + } catch(e) { + console.error('[testGetUpdatePolicyPromise] fail.' + e); + } + console.info('[getUpdatePolicy] success.'); + console.info('testGetUpdatePolicyPromise END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0038 + * @tc.name testSetUpdatePolicyPromise002 + * @tc.desc Promise method call. + */ + it('testSetUpdatePolicyPromise002', 0, function() { + console.info('testSetUpdatePolicyPromise002 START' + updater); + let policy = { + autoDownload: true, + autoDownloadNet: true, + mode: 2, + autoUpgradeInterval: [ 2, 3 ], + autoUpgradeCondition: 2 + } + try { + let ret = updater.setUpdatePolicy(policy).then(data => { + console.log("setUpdatePolicy success" + data); + expect(data).assertEqual(0); + }).catch(error => + console.error("setUpdatePolicy error " + error) + ); + expect(ret != 0); + } catch(e) { + console.error('[setUpdatePolicy] fail.' + e); + } + console.info('[setUpdatePolicy] success.'); + console.info('testSetUpdatePolicyPromise002 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0039 + * @tc.name testGetUpdatePolicy002 + * @tc.desc Promise method call. + */ + it('testGetUpdatePolicyPromise002', 0, function() { + console.info('testGetUpdatePolicyPromise002 START'); + try { + let ret = updater.getUpdatePolicy().then(data => { + console.log("getUpdatePolicy success" + data); + expect(data.autoDownload).assertEqual(true); + expect(data.autoDownloadNet).assertEqual(true); + expect(data.mode).assertEqual(2); + expect(data.autoUpgradeInterval[0]).assertEqual(2); + expect(data.autoUpgradeInterval[1]).assertEqual(3); + }); + expect(ret != 0); + } catch(e) { + console.error('[testGetUpdatePolicyPromise002] fail.' + e); + } + console.info('[getUpdatePolicy] success.'); + console.info('testGetUpdatePolicyPromise002 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0040 + * @tc.name testSetUpdatePolicyPromise003 + * @tc.desc Promise method call. + */ + it('testSetUpdatePolicyPromise003', 0, function() { + console.info('testSetUpdatePolicyPromise003 START'); + // Set strategy. + let policy = { + autoDownload: false, + autoDownloadNet: false, + mode: 2, + autoUpgradeInterval: [ 2, 3 ], + autoUpgradeCondition: 2 + } + try { + let ret = updater.setUpdatePolicy(policy).then(data => { + console.log("setUpdatePolicy success" + data); + expect(data).assertEqual(0); + }).catch(error => { + console.info('[setUpdatePolicy] error ' + error) + }) + expect(ret != 0); + } catch(e) { + console.error('[testSetUpdatePolicyPromise003] fail.' + e); + } + console.info('[setUpdatePolicy] success.'); + console.info('testSetUpdatePolicyPromise003 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0041 + * @tc.name testGetUpdatePolicyPromise003 + * @tc.desc Promise method call. + */ + it('testGetUpdatePolicyPromise003', 0, function() { + console.info('testGetUpdatePolicyPromise003 START '); + try { + let ret = updater.getUpdatePolicy().then(data => { + console.log("getUpdatePolicy success" + data); + expect(data.autoDownload).assertEqual(false); + expect(data.autoDownloadNet).assertEqual(false); + expect(data.mode).assertEqual(2); + expect(data.autoUpgradeInterval[0]).assertEqual(2); + expect(data.autoUpgradeInterval[1]).assertEqual(3); + }).catch(error => { + console.info('[getUpdatePolicy] error ' + error) + }) + expect(ret != 0); + } catch(e) { + console.info('[getUpdatePolicy] catch ' + e) + } + console.info('[getUpdatePolicy] success.'); + console.info('testGetUpdatePolicyPromise003 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0042 + * @tc.name testSetUpdatePolicyPromise004 + * @tc.desc Promise method call. + */ + it('testSetUpdatePolicyPromise004', 0, function() { + console.info('testSetUpdatePolicyPromise004 START' + updater); + // Set strategy. + let policy = { + autoDownload: false, + autoDownloadNet: false, + mode: 1, + autoUpgradeInterval: [ 100, 100], + autoUpgradeCondition: 2 + } + try { + let ret = updater.setUpdatePolicy(policy).then(data => { + console.log("setUpdatePolicy success" + data); + expect(data).assertEqual(0); + }).catch(error => { + console.info('[setUpdatePolicy] error ' + error) + }) + expect(ret != 0); + } catch(e) { + console.info('[testSetUpdatePolicyPromise004] catch ' + e) + } + console.info('[setUpdatePolicy] success.'); + console.info('testSetUpdatePolicyPromise004 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0043 + * @tc.name testGetUpdatePolicyPromise004 + * @tc.desc Promise method call. + */ + it('testGetUpdatePolicyPromise004', 0, function() { + console.info('testGetUpdatePolicyPromise004 START' + updater); + try { + let ret = updater.getUpdatePolicy().then(data => { + console.log("getUpdatePolicy success" + data); + expect(data.autoDownload).assertEqual(false); + expect(data.autoDownloadNet).assertEqual(false); + expect(data.mode).assertEqual(1); + expect(data.autoUpgradeInterval[0]).assertEqual(expect_value); + expect(data.autoUpgradeInterval[1]).assertEqual(expect_value); + }).catch(error => { + console.info('[getUpdatePolicy] error ' + error) + }) + expect(ret != 0); + } catch(e) { + console.info('[testSetUpdatePolicyPromise004] catch ' + e) + } + console.info('[getUpdatePolicy] success.'); + console.info('testGetUpdatePolicyPromise004 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0044 + * @tc.name testSetUpdatePolicyPromise005 + * @tc.desc Test incorrect parameters. + */ + it('testSetUpdatePolicyPromise005', 0, function() { + console.info('testSetUpdatePolicyPromise005 START' + updater); + try { + let ret = updater.setUpdatePolicy("").then(data => { + console.log("setUpdatePolicy success" + data); + expect(data).assertEqual(0); + }); + expect(ret != 0); + } catch (e) { + console.info('[setUpdatePolicy] catch ' + e); + } + console.info('[setUpdatePolicy] success.'); + console.info('testSetUpdatePolicyPromise005 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0045 + * @tc.name testGetUpdatePolicyPromise005 + * @tc.desc Test incorrect parameters. + */ + it('testGetUpdatePolicyPromise005', 0, function() { + console.info('testGetUpdatePolicy005 START' + updater); + try{ + let ret = updater.getUpdatePolicy(param_value1).then(data => { + }) + expect(ret != 0); + } catch (e) { + console.info('[setUpdatePolicy] catch ' + e); + } + console.info('[getUpdatePolicy] success.'); + console.info('testGetUpdatePolicyPromise005 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0046 + * @tc.name testDownloadVersion + * @tc.desc Unsubscribe from monitoring. + */ + it('testDownloadVersion', 0, function() { + console.info('testDownloadVersion START'); + // Open download monitor. + try{ + updater.on('downloadProgress', progress => { + console.log("downloadProgress on" + progress); + console.log(`downloadProgress status: ` + progress.status); + console.log(`downloadProgress percent: ` + progress.percent); + console.log(`downloadProgress endReason: ` + progress.endReason); + if (progress.status == updateState.UPDATE_STATE_DOWNLOAD_SUCCESS || + progress.status == updateState.UPDATE_STATE_VERIFY_SUCCESS) { + expect(progress.percent).assertEqual(expect_value); + updater.off("downloadProgress"); + } + }) + let ret = updater.download(); + expect(ret != 0); + } catch (e) { + console.info('[testDownloadVersion] catch ' + e); + } + + console.info('[downloadVersion] success.'); + console.info('testDownloadVersion END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0047 + * @tc.name testDownloadVersion02 + * @tc.desc Unsubscribe out of monitoring. + */ + it('testDownloadVersion02', 0, function() { + console.info('testDownloadVersion02 START'); + // Open download monitor + try{ + updater.on('downloadProgress', progress => { + console.log("downloadProgress on" + progress); + console.log(`downloadProgress status: ` + progress.status); + console.log(`downloadProgress percent: ` + progress.percent); + console.log(`downloadProgress endReason: ` + progress.endReason); + if (progress.status == updateState.UPDATE_STATE_DOWNLOAD_SUCCESS || + progress.status == updateState.UPDATE_STATE_VERIFY_SUCCESS) { + expect(progress.percent).assertEqual(expect_value); + } + }) + let ret = updater.download(); + // Cancel subscription immediately, no callback will be received. + updater.off("downloadProgress"); + expect(ret != 0); + } catch (e) { + console.info('[testDownloadVersion02] catch ' + e); + } + console.info('[downloadVersion] success.'); + console.info('testDownloadVersion END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0048 + * @tc.name testDownloadVersion03 + * @tc.desc Test download parameter, callback is not supported. + */ + it('testDownloadVersion03', 0, function() { + console.info('testDownloadVersion03 START'); + try{ + let ret = updater.download(progress => { + console.log("downloadProgress on" + progress); + console.log(`downloadProgress status: ` + progress.status); + console.log(`downloadProgress percent: ` + progress.percent); + console.log(`downloadProgress endReason: ` + progress.endReason); + if (progress.status == updateState.UPDATE_STATE_DOWNLOAD_SUCCESS || + progress.status == updateState.UPDATE_STATE_VERIFY_SUCCESS) { + expect(progress.percent).assertEqual(expect_value); + } + }) + expect(ret != 0); + } catch (e) { + console.info('[testDownloadVersion03] catch ' + e); + } + console.info('[downloadVersion] success.'); + console.info('testDownloadVersion END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0049 + * @tc.name testDownloadVersion04 + * @tc.desc Test subscription without parameters, return error. + */ + it('testDownloadVersion04', 0, function() { + console.info('testDownloadVersion04 START'); + try{ + // Open download monitor. + let ret = updater.on('downloadProgress'); + expect(ret != 0); + let ret_download = updater.download(); + expect(ret_download != 0); + // Cancel subscription immediately, no callback will be received. + let ret_off = updater.off("downloadProgress"); + expect(ret_off != 0); + } catch (e) { + console.info('[testDownloadVersion04] catch ' + e); + } + console.info('[downloadVersion] success.'); + console.info('testDownloadVersion04 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0050 + * @tc.name testDownloadVersion05 + * @tc.desc Take function to subscribe. + */ + it('testDownloadVersion05', 0, function() { + function testFunction(progress) { + console.log("downloadProgress on" + progress); + console.log(`downloadProgress status: ` + progress.status); + console.log(`downloadProgress percent: ` + progress.percent); + console.log(`downloadProgress endReason: ` + progress.endReason); + } + console.info('testDownloadVersion05 START'); + try{ + // Open download monitor. + let ret = updater.on('downloadProgress', testFunction); + expect(ret == 0); + + let ret_download = updater.download(); + expect(ret_download != 0); + // Cancel subscription immediately, no callback will be received. + let ret_off = updater.off("downloadProgress", testFunction); + expect(ret_off != 0); + } catch (e) { + console.info('[testDownloadVersion05] catch ' + e); + } + console.info('[downloadVersion] success.'); + console.info('testDownloadVersion05 END'); + }); + + + /** + * @tc.number SUB_UPDATE_JS_API_0051 + * @tc.name testUpgradeVersion01 + * @tc.desc Unsubscribe from monitoring. + */ + it('testUpgradeVersion01', 0, function() { + console.info('testUpgradeVersion01 START'); + try{ + // Open download monitor. + updater.on('upgradeProgress', progress => { + console.log("upgradeProgress on" + progress); + console.log(`upgradeProgress status: ` + progress.status); + console.log(`upgradeProgress percent: ` + progress.percent); + console.log(`upgradeProgress endReason: ` + progress.endReason); + if (progress.status == updateState.UPDATE_STATE_DOWNLOAD_SUCCESS || + progress.status == updateState.UPDATE_STATE_VERIFY_SUCCESS) { + expect(progress.percent).assertEqual(expect_value); + updater.off("upgradeProgress"); + } + }) + let ret = updater.upgrade(); + expect(ret != 0); + } catch (e) { + console.info('[testUpgradeVersion01] catch ' + e); + } + console.info('[upgrade] success.'); + console.info('testUpgradeVersion01 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0052 + * @tc.name testUpgradeVersion02 + * @tc.desc Unsubscribe out of monitoring. + */ + it('testUpgradeVersion02', 0, function() { + console.info('testUpgradeVersion02 START'); + try{ + // Open download monitor. + let ret_on = updater.on('upgradeProgress', progress => { + console.log("upgradeProgress on" + progress); + console.log(`upgradeProgress status: ` + progress.status); + console.log(`upgradeProgress percent: ` + progress.percent); + console.log(`upgradeProgress endReason: ` + progress.endReason); + if (progress.status == updateState.UPDATE_STATE_DOWNLOAD_SUCCESS || + progress.status == updateState.UPDATE_STATE_VERIFY_SUCCESS) { + expect(progress.percent).assertEqual(expect_value); + } + }) + expect(ret_on != 0); + let ret = updater.upgrade(); + expect(ret != 0); + // Cancel subscription immediately, no callback will be received. + let ret_off = updater.off("upgradeProgress"); + expect(ret_off != 0); + } catch (e) { + console.info('[testUpgradeVersion02] catch ' + e); + } + console.info('[upgrade] success.'); + console.info('testUpgradeVersion02 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0053 + * @tc.name testUpgradeVersion03 + * @tc.desc Test download parameter, callback is not supported. + */ + it('testUpgradeVersion03', 0, function() { + console.info('testUpgradeVersion03 START'); + try{ + let ret = updater.upgrade(progress => { + console.log("upgradeProgress on" + progress); + console.log(`upgradeProgress status: ` + progress.status); + console.log(`upgradeProgress percent: ` + progress.percent); + console.log(`upgradeProgress endReason: ` + progress.endReason); + if (progress.status == updateState.UPDATE_STATE_DOWNLOAD_SUCCESS || + progress.status == updateState.UPDATE_STATE_VERIFY_SUCCESS) { + expect(progress.percent).assertEqual(expect_value); + } + }) + expect(ret != 0); + } catch (e) { + console.info('[testUpgradeVersion03] catch ' + e); + } + console.info('[upgrade] success.'); + console.info('testUpgradeVersion03 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0054 + * @tc.name testUpgradeVersion04 + * @tc.desc Test subscription without parameters, return error. + */ + it('testUpgradeVersion04', 0, function() { + console.info('testUpgradeVersion04 START'); + try{ + // Open download monitor. + let ret = updater.on('upgradeProgress'); + expect(ret != 0); + let ret_upgrade = updater.upgrade(); + expect(ret_upgrade != 0); + // Cancel subscription immediately, no callback will be received. + let ret_off = updater.off("upgradeProgress"); + expect(ret_off != 0); + } catch (e) { + console.info('[testUpgradeVersion04] catch ' + e); + } + console.info('[upgrade] success.'); + console.info('testUpgradeVersion04 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0055 + * @tc.name testUpgradeVersion05 + * @tc.desc Take function to subscribe. + */ + it('testUpgradeVersion05', 0, function() { + function testFunction(progress) { + console.log("upgradeProgress on" + progress); + console.log(`upgradeProgress status: ` + progress.status); + console.log(`upgradeProgress percent: ` + progress.percent); + console.log(`upgradeProgress endReason: ` + progress.endReason); + } + console.info('testUpgradeVersion05 START'); + try{ + let ret = updater.on('upgradeProgress', testFunction); + expect(ret == 0); + + let ret_upgrade = updater.upgrade(); + expect(ret_upgrade != 0); + + let ret_off = updater.off("upgradeProgress", testFunction); + expect(ret_off != 0); + } catch (e) { + console.info('[testUpgradeVersion05] catch ' + e); + } + console.info('[upgrade] success.'); + console.info('testUpgradeVersion05 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0056 + * @tc.name testOnDownload2 + * @tc.desc Test incorrect parameters. + */ + it('testOnDownload', 0, function() { + console.info('testOnDownload START'); + try{ + let ret = updater.on(function(){}); + expect(ret != 0); + } catch (e) { + console.info('[testOnDownload] catch ' + e); + } + console.info('[testOnDownload] success.'); + console.info('testOnDownload END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0057 + * @tc.name testOnDownload2 + * @tc.desc Test incorrect parameters. + */ + it('testOnDownload2', 0, function() { + console.info('testOnDownload2 START'); + try{ + let ret = updater.on(); + expect(ret != 0); + } catch (e) { + console.info('[testOnDownload2] catch ' + e); + } + console.info('[testOnDownload2] success.'); + console.info('testOnDownload2 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0058 + * @tc.name testOnDownload3 + * @tc.desc Test incorrect parameters. + */ + it('testOnDownload3', 0, function() { + console.info('testOnDownload3 START'); + try{ + let ret = updater.on("333333333"); + expect(ret != 0); + } catch (e) { + console.info('[testOnDownload3] catch ' + e); + } + console.info('[testOnDownload3] success.'); + console.info('testOnDownload3 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0059 + * @tc.name testOnDownload3 + * @tc.desc Test incorrect parameters. + */ + it('testOnDownload4', 0, function() { + console.info('testOnDownload3 START'); + try{ + let ret = updater.on(param_value2); + expect(ret != 0); + } catch (e) { + console.info('[testOnDownload4] catch ' + e); + } + console.info('[testOnDownload4] success.'); + console.info('testOnDownload4 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0060 + * @tc.name testOnDownload4 + * @tc.desc Test incorrect parameters. + */ + it('testOnDownload5', 0, function() { + console.info('testOnDownload5 START'); + try{ + let ret = updater.on(param_value2, "4444444444444"); + expect(ret != 0); + } catch (e) { + console.info('[testOnDownload5] catch ' + e); + } + console.info('[testOnDownload5] success.'); + console.info('testOnDownload5 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0061 + * @tc.name testOffDownload + * @tc.desc Test incorrect parameters. + */ + it('testOffDownload', 0, function() { + console.info('testOffDownload START'); + try{ + let ret = updater.off(); + expect(ret != 0); + } catch (e) { + console.info('[testOffDownload] catch ' + e); + } + console.info('[testOffDownload] success.'); + console.info('testOffDownload END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0062 + * @tc.name testOffDownload2 + * @tc.desc Test incorrect parameters. + */ + it('testOffDownload2', 0, function() { + console.info('testOffDownload2 START'); + try{ + let ret = updater.off("333333333"); + expect(ret != 0); + } catch (e) { + console.info('[testOffDownload2] catch ' + e); + } + console.info('[testOffDownload2] success.'); + console.info('testOffDownload2 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0063 + * @tc.name testOffDownload3 + * @tc.desc Test incorrect parameters. + */ + it('testOffDownload3', 0, function() { + console.info('testOffDownload3 START'); + try{ + let ret = updater.on(param_value2); + expect(ret != 0); + } catch (e) { + console.info('[testOffDownload3] catch ' + e); + } + console.info('[testOffDownload3] success.'); + console.info('testOffDownload3 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0064 + * @tc.name testOffDownload4 + * @tc.desc Test incorrect parameters. + */ + it('testOffDownload4', 0, function() { + console.info('testOffDownload4 START'); + try{ + let ret = updater.off(param_value2, "4444444444444"); + expect(ret != 0); + } catch (e) { + console.info('[testOffDownload4] catch ' + e); + } + console.info('[testOffDownload4] success.'); + console.info('testOffDownload4 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0065 + * @tc.name testOffDownload5 + * @tc.desc Test incorrect parameters. + */ + it('testOffDownload5', 0, function() { + console.info('testOffDownload5 START'); + try{ + let ret = updater.off(function(){}); + expect(ret != 0); + } catch (e) { + console.info('[testOffDownload5] catch ' + e); + } + console.info('[testOffDownload5] success.'); + console.info('testOffDownload5 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0066 + * @tc.name testOnUpgrade + * @tc.desc Test incorrect parameters. + */ + it('testOnUpgrade', 0, function() { + console.info('testOnUpgrade START'); + try{ + let ret = updater.on("upgradeProgress", function(){}); + expect(ret != 0); + } catch (e) { + console.info('[testOnUpgrade] catch ' + e); + } + console.info('[testOnUpgrade] success.'); + console.info('testOnUpgrade END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0067 + * @tc.name testOnUpgrade2 + * @tc.desc Test incorrect parameters. + */ + it('testOnUpgrade2', 0, function() { + console.info('testOnUpgrade2 START'); + try{ + let ret = updater.on("upgradeProgress"); + expect(ret != 0); + } catch (e) { + console.info('[testOnUpgrade2] catch ' + e); + } + console.info('[testOnUpgrade2] success.'); + console.info('testOnUpgrade2 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0068 + * @tc.name testOnUpgrade3 + * @tc.desc Test incorrect parameters. + */ + it('testOnUpgrade3', 0, function() { + console.info('testOnUpgrade3 START'); + try{ + let ret = updater.on("upgradeProgress", "333333333"); + expect(ret != 0); + } catch (e) { + console.info('[testOnUpgrade3] catch ' + e); + } + console.info('[testOnUpgrade3] success.'); + console.info('testOnUpgrade3 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0069 + * @tc.name testOnDownload3 + * @tc.desc Test incorrect parameters. + */ + it('testOnUpgrade4', 0, function() { + console.info('testOnUpgrade4 START'); + try{ + let ret = updater.on("upgradeProgress", param_value2); + expect(ret != 0); + } catch (e) { + console.info('[testOnUpgrade3] catch ' + e); + } + console.info('[testOnUpgrade4] success.'); + console.info('testOnUpgrade4 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0070 + * @tc.name testOnUpgrade5 + * @tc.desc Test incorrect parameters. + */ + it('testOnUpgrade5', 0, function() { + console.info('testOnUpgrade5 START'); + try{ + let ret = updater.on(param_value2, "4444444444444"); + expect(ret != 0); + } catch (e) { + console.info('[testOnUpgrade5] catch ' + e); + } + console.info('[testOnUpgrade5] success.'); + console.info('testOnUpgrade5 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0071 + * @tc.name testOffUpgrade + * @tc.desc Test incorrect parameters. + */ + it('testOffUpgrade', 0, function() { + console.info('testOffUpgrade START'); + try{ + let ret = updater.off("upgradeProgress"); + expect(ret != 0); + } catch (e) { + console.info('[testOffUpgrade] catch ' + e); + } + console.info('[testOffUpgrade] success.'); + console.info('testOffUpgrade END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0072 + * @tc.name testOffUpgrade2 + * @tc.desc Test incorrect parameters. + */ + it('testOffUpgrade2', 0, function() { + console.info('testOffUpgrade2 START'); + try{ + let ret = updater.off("upgradeProgress", "333333333"); + expect(ret != 0); + } catch (e) { + console.info('[testOffUpgrade] catch ' + e); + } + console.info('[testOffUpgrade2] success.'); + console.info('testOffUpgrade2 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0073 + * @tc.name testOffUpgrade3 + * @tc.desc Test incorrect parameters. + */ + it('testOffUpgrade3', 0, function() { + console.info('testOffDownload3 START'); + try{ + let ret = updater.on("upgradeProgress", param_value2); + expect(ret != 0); + } catch (e) { + console.info('[testOffUpgrade3] catch ' + e); + } + console.info('[testOffUpgrade3] success.'); + console.info('testOffUpgrade3 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0074 + * @tc.name testOffUpgrade4 + * @tc.desc Test incorrect parameters. + */ + it('testOffUpgrade4', 0, function() { + console.info('testOffUpgrade4 START'); + try{ + let ret = updater.off("upgradeProgress", param_value2, "4444444444444"); + expect(ret != 0); + } catch (e) { + console.info('[testOffUpgrade4] catch ' + e); + } + console.info('[testOffUpgrade4] success.'); + console.info('testOffUpgrade4 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0075 + * @tc.name testOffUpgrade5 + * @tc.desc Test incorrect parameters. + */ + it('testOffUpgrade5', 0, function() { + console.info('testOffUpgrade5 START'); + try{ + let ret = updater.off("upgradeProgress", "6"); + expect(ret != 0); + } catch (e) { + console.info('[testOffUpgrade5] catch ' + e); + } + console.info('[testOffUpgrade5] success.'); + console.info('testOffUpgrade5 END'); + }); +}); \ No newline at end of file diff --git a/updater/update_test/gradle/entry/src/main/resources/base/element/string.json b/updater/update_test/gradle/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..65d5b82bec27ec3f7f177fe78ff02f6a17536c0e --- /dev/null +++ b/updater/update_test/gradle/entry/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication0420" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/updater/update_test/gradle/entry/src/main/resources/base/media/icon.png b/updater/update_test/gradle/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/updater/update_test/gradle/entry/src/main/resources/base/media/icon.png differ diff --git a/updater/update_test/gradle/entry/src/ohosTest/config.json b/updater/update_test/gradle/entry/src/ohosTest/config.json new file mode 100644 index 0000000000000000000000000000000000000000..bfda4c2089daad05d93f790a660dffeb7031b6c2 --- /dev/null +++ b/updater/update_test/gradle/entry/src/ohosTest/config.json @@ -0,0 +1,52 @@ +{ + "app": { + "bundleName": "ohos.acts.upgrade", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.upgrade", + "name": "testModule", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry_test", + "moduleType": "feature", + "installationFree": true + }, + "abilities": [ + { + "name": "ohos.acts.upgrade.MainAbility", + "description": "Test Entry Ability", + "icon": "$media:icon", + "label": "$string:app_name", + "launchType": "standard", + "orientation": "landscape", + "visible": true, + "type": "page" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 750, + "autoDesignWidth": false + } + } + ] + } +} diff --git a/updater/update_test/gradle/entry/src/ohosTest/js/test/list.test.js b/updater/update_test/gradle/entry/src/ohosTest/js/test/list.test.js new file mode 100755 index 0000000000000000000000000000000000000000..0ec6c8dd15833fac2491bee5c299759c579d0795 --- /dev/null +++ b/updater/update_test/gradle/entry/src/ohosTest/js/test/list.test.js @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2021 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. + */ + +require('./update.test.js'); \ No newline at end of file diff --git a/updater/update_test/gradle/entry/src/ohosTest/js/test/update.test.js b/updater/update_test/gradle/entry/src/ohosTest/js/test/update.test.js new file mode 100755 index 0000000000000000000000000000000000000000..90e8b8504864e21e559ce59de566a723ac102c14 --- /dev/null +++ b/updater/update_test/gradle/entry/src/ohosTest/js/test/update.test.js @@ -0,0 +1,1712 @@ +/* + * Copyright (C) 2021 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' +import client from '@ohos.update'; + +let updater; +var param_value1 = 444; +var param_value2 = 555; +var expect_value = 100; +var updateState = { + UPDATE_STATE_INIT : 0, + UPDATE_STATE_CHECK_VERSION_ON : 10, + UPDATE_STATE_CHECK_VERSION_FAIL : 11, + UPDATE_STATE_CHECK_VERSION_SUCCESS : 12, + UPDATE_STATE_DOWNLOAD_ON : 20, + UPDATE_STATE_DOWNLOAD_PAUSE : 21, + UPDATE_STATE_DOWNLOAD_CANCEL : 22, + UPDATE_STATE_DOWNLOAD_FAIL : 23, + UPDATE_STATE_DOWNLOAD_SUCCESS : 24, + UPDATE_STATE_VERIFY_ON : 30, + UPDATE_STATE_VERIFY_FAIL : 31, + UPDATE_STATE_VERIFY_SUCCESS : 32, + UPDATE_STATE_PACKAGE_TRANS_ON : 70, + UPDATE_STATE_PACKAGE_TRANS_FAIL : 71, + UPDATE_STATE_PACKAGE_TRANS_SUCCESS : 72, + UPDATE_STATE_INSTALL_ON : 80, + UPDATE_STATE_INSTALL_FAIL : 81, + UPDATE_STATE_INSTALL_SUCCESS : 82, + UPDATE_STATE_UPDATE_ON : 90, + UPDATE_STATE_UPDATE_FAIL : 91, + UPDATE_STATE_UPDATE_SUCCESS : 92 +}; + +describe('updateclient', function() { + beforeAll(function() { + if (updater == undefined) { + updater = client.getUpdater('OTA'); + } + }); + beforeEach(function() { + if (updater == undefined) { + updater = client.getUpdater('OTA'); + } + }); + afterEach(function() {}); + + /** + * @tc.number SUB_UPDATE_JS_API_0001 + * @tc.name testGetUpdate + * @tc.desc . + */ + it('testGetUpdate', 0, function() { + console.info('testGetUpdate START'); + try { + if (client == undefined) { + console.error("client not defined"); + return; + } + let tmpUpdater = client.getUpdater('/data/updater/updater.zip', 'OTA'); + expect(tmpUpdater != undefined); + if (tmpUpdater == undefined) { + console.error("Fail to get updater"); + return; + } + + } catch(e) { + console.error('[testGetUpdate] fail.' + e); + } + + console.info('[client.getUpdate] success.'); + console.info('testGetUpdate END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0002 + * @tc.name testGetUpdate2 + * @tc.desc Test incorrect parameters. + */ + it('testGetUpdate2', 0, function() { + console.info('testGetUpdate2 START'); + try { + if (client == undefined) { + console.error("client not defined"); + return; + } + let tmpUpdater = client.getUpdater('/data/updater/updater.zip', '44444'); + expect(tmpUpdater == undefined); + } catch(e) { + console.error('[testGetUpdate] fail.' + e); + } + + console.info('[client.getUpdate] success.'); + console.info('testGetUpdate2 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0003 + * @tc.name testGetUpdate3 + * @tc.desc Test incorrect parameters. + */ + it('testGetUpdate3', 0, function() { + console.info('testGetUpdate3 START'); + try { + if (client == undefined) { + console.error("client not defined"); + return; + } + let tmpUpdater = client.getUpdater('/data/updater/updater.zip', 'patch'); + expect(tmpUpdater != undefined); + if (tmpUpdater == undefined) { + console.error("Fail to get updater"); + return; + } + + } catch(e) { + console.error('[testGetUpdate] fail.' + e); + } + + console.info('[client.getUpdate] success.'); + console.info('testGetUpdate3 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0004 + * @tc.name testGetUpdate4 + * @tc.desc Test incorrect parameters. + */ + it('testGetUpdate4', 0, function() { + console.info('testGetUpdate4 START'); + try { + if (client == undefined) { + console.error("client not defined"); + return; + } + let tmpUpdater = client.getUpdater(function(){ + }); + expect(tmpUpdater == undefined); + } catch(e) { + console.error('[testGetUpdate4] fail.' + e); + } + + console.info('[client.getUpdate] success.'); + console.info('testGetUpdate4 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0005 + * @tc.name testGetUpdate5 + * @tc.desc Test incorrect parameters. + */ + it('testGetUpdate5', 0, function() { + console.info('testGetUpdate5 START'); + try { + if (client == undefined) { + console.error("client not defined"); + return; + } + let tmpUpdater = client.getUpdater(param_value1, param_value2); + expect(tmpUpdater == undefined); + } catch(e) { + console.error('[testGetUpdate] fail.' + e); + } + + console.info('[client.getUpdate] success.'); + console.info('testGetUpdate5 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0006 + * @tc.name testGetNewVersionInfo1 + * @tc.desc Get the current system version. + */ + it('testGetNewVersionInfo1', 0, function() { + console.info('testGetNewVersionInfo1 START'); + try { + let ret = updater.getNewVersionInfo(function(err, data){ + console.log("getNewVersionInfo success" + data); + expect(data.status).assertEqual(0); // Has new version. + }); + expect(ret != 0); + } catch(e) { + console.error('[testGetUpdate] fail.' + e); + } + console.info('[getNewVersionInfo] success.'); + console.info('testGetNewVersionInfo1 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0007 + * @tc.name testGetNewVersionInfo2 + * @tc.desc Test incorrect parameters. + */ + it('testGetNewVersionInfo2', 0, function() { + console.info('testGetNewVersionInfo2 START'); + try { + let ret = updater.getNewVersionInfo(); + expect(ret != 0); + console.info('[getNewVersionInfo] success.'); + console.info('testGetNewVersionInfo2 END'); + } catch(e) { + console.error('[testGetUpdate] fail.' + e); + } + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0008 + * @tc.name testGetNewVersionInfo3 + * @tc.desc Test incorrect parameters. + */ + it('testGetNewVersionInfo3', 0, function() { + console.info('testGetNewVersionInfo3 START'); + try { + let ret = updater.getNewVersionInfo("dddddd"); + expect(ret != 0); + console.info('[getNewVersionInfo] success.'); + console.info('testGetNewVersionInfo2 END'); + } catch(e) { + console.error('[testGetUpdate] fail.' + e); + } + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0009 + * @tc.name testGetNewVersionInfo4 + * @tc.desc Test incorrect parameters. + */ + it('testGetNewVersionInfo4', 0, function() { + console.info('testGetNewVersionInfo4 START'); + try { + let ret = updater.getNewVersionInfo(param_value1); + expect(ret != 0); + console.info('[getNewVersionInfo] success.'); + console.info('testGetNewVersionInfo5 END'); + } catch(e) { + console.error('[testGetUpdate] fail.' + e); + } + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0010 + * @tc.name testGetNewVersionInfo5 + * @tc.desc Test incorrect parameters. + */ + it('testGetNewVersionInfo5', 0, function() { + console.info('testGetNewVersionInfo5 START'); + try { + let ret = updater.getNewVersionInfo(param_value1, param_value2); + expect(ret != 0); + console.info('[getNewVersionInfo] success.'); + console.info('testGetNewVersionInfo5 END'); + } catch(e) { + console.error('[testGetUpdate] fail.' + e); + } + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0011 + * @tc.name testGetNewVersionInfoPromise + * @tc.desc Called by Promise to get the new version. + */ + it('testGetNewVersionInfoPromise', 0, function() { + console.info('testGetNewVersionInfoPromise START'); + try { + let ret = updater.getNewVersionInfo().then(data => { + console.log("getNewVersionInfo success " + data); + expect(data.status).assertEqual(0); // Has new version. + expect(data.checkResults.size > 0); + console.log(`info versionName = ` + data.checkResults[0].versionName); + console.log(`info versionCode = ` + data.checkResults[0].versionCode); + console.log(`info verifyInfo = ` + data.checkResults[0].verifyInfo); + console.log(`info descriptionId = ` + data.checkResults[0].descriptionId); + console.log(`info content = ` + data.descriptionInfo[0].content); + console.log(`info size = ` + data.checkResults[0].size); + }).catch(error => + console.error("getNewVersionInfo catch " + error) + ); + expect(ret != 0); + } catch(e) { + console.error("getNewVersionInfo catch " + e); + } + console.info('[getNewVersionInfo] success.'); + console.info('testGetNewVersionInfoPromise END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0012 + * @tc.name testGetNewVersionInfoPromise2 + * @tc.desc Test incorrect parameters. + */ + it('testGetNewVersionInfoPromise2', 0, function() { + console.info('testGetNewVersionInfoPromise2 START'); + try { + let ret = updater.getNewVersionInfo(param_value1).then(data => { + console.log("getNewVersionInfo success " + data); + }).catch(error => + console.error("getNewVersionInfo catch " + error) + ); + expect(ret != 0); + } catch(e) { + console.error("getNewVersionInfo catch " + e); + } + console.info('[getNewVersionInfo] success.'); + console.info('testGetNewVersionInfoPromise2 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0013 + * @tc.name testGetNewVersionInfoPromise3 + * @tc.desc Test incorrect parameters. + */ + it('testGetNewVersionInfoPromise3', 0, function() { + console.info('testGetNewVersionInfoPromise3 START'); + try { + let ret = updater.getNewVersionInfo(param_value1, param_value2).then(data => { + }).catch(error => + console.error("getNewVersionInfo catch " + error) + ); + expect(ret != 0); + } catch(e) { + console.error("getNewVersionInfo catch " + e); + } + console.info('[getNewVersionInfo] success.'); + console.info('testGetNewVersionInfoPromise3 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0014 + * @tc.name testGetNewVersionInfoPromise4 + * @tc.desc Test incorrect parameters. + */ + it('testGetNewVersionInfoPromise4', 0, function() { + console.info('testGetNewVersionInfoPromise4 START'); + try { + let ret = updater.getNewVersionInfo("44444444").then(data => { + }).catch(error => + console.error("getNewVersionInfo catch " + error) + ); + expect(ret != 0); + } catch(e) { + console.error("getNewVersionInfo catch " + e); + } + console.info('[getNewVersionInfo] success.'); + console.info('testGetNewVersionInfoPromise4 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0015 + * @tc.name testGetNewVersionInfoPromise5 + * @tc.desc Test incorrect parameters. + */ + it('testGetNewVersionInfoPromise5', 0, function() { + console.info('testGetNewVersionInfoPromise5 START'); + try { + let ret = updater.getNewVersionInfo("44444444", "5555555").then(data => { + }).catch(error => + console.error("getNewVersionInfo error " + error) + ); + expect(ret != 0); + } catch(e) { + console.error("getNewVersionInfo catch " + e); + } + console.info('[getNewVersionInfo] success.'); + console.info('testGetNewVersionInfoPromise5 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0016 + * @tc.name testCheckNewVersion1 + * @tc.desc Check the new version. + */ + it('testCheckNewVersion1', 0, function() { + console.info('testCheckNewVersion1 START'); + try { + let ret = updater.checkNewVersion(function(err, data){ + console.log("checkNewVersion success" + data); + expect(data.status).assertEqual(0); // Has new version. + expect(data.checkResults.size > 0); + console.log(`info versionName = ` + data.checkResults[0].versionName); + console.log(`info versionCode = ` + data.checkResults[0].versionCode); + console.log(`info verifyInfo = ` + data.checkResults[0].verifyInfo); + console.log(`info descriptionId = ` + data.checkResults[0].descriptionId); + console.log(`info content = ` + data.descriptionInfo[0].content); + console.log(`info size = ` + data.checkResults[0].size); + }, + error => { + console.log("checkNewVersion error" + error) + }); + expect(ret != 0); + } catch(e) { + console.error("checkNewVersion catch " + e); + } + console.info('[checkNewVersion] success.'); + console.info('testCheckNewVersion1 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0017 + * @tc.name testCheckNewVersion2 + * @tc.desc Test incorrect parameters. + */ + it('testCheckNewVersion2', 0, function() { + console.info('testCheckNewVersion2 START'); + try { + let ret = updater.checkNewVersion(); + expect(ret != 0); + console.info('[checkNewVersion] success.' + ret); + console.info('testCheckNewVersion2 END'); + } catch(e) { + console.error("checkNewVersion catch " + e); + } + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0018 + * @tc.name testCheckNewVersion3 + * @tc.desc Test incorrect parameters. + */ + it('testCheckNewVersion3', 0, function() { + console.info('testCheckNewVersion3 START'); + try { + let ret = updater.checkNewVersion("33333"); + expect(ret != 0); + console.info('[checkNewVersion] success.' + ret); + console.info('testCheckNewVersion3 END'); + } catch(e) { + console.error("checkNewVersion catch " + e); + } + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0019 + * @tc.name testCheckNewVersion4 + * @tc.desc Test incorrect parameters. + */ + it('testCheckNewVersion4', 0, function() { + console.info('testCheckNewVersion4 START'); + try { + let ret = updater.checkNewVersion(param_value1); + expect(ret != 0); + console.info('[checkNewVersion] success.' + ret); + console.info('testCheckNewVersion4 END'); + } catch(e) { + console.error("checkNewVersion catch " + e); + } + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0020 + * @tc.name testCheckNewVersion5 + * @tc.desc Test incorrect parameters. + */ + it('testCheckNewVersion5', 0, function() { + console.info('testCheckNewVersion4 START'); + try { + let ret = updater.checkNewVersion(param_value1, param_value2); + expect(ret != 0); + console.info('[checkNewVersion] success.' + ret); + console.info('testCheckNewVersion5 END'); + } catch(e) { + console.error("checkNewVersion catch " + e); + } + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0021 + * @tc.name testCheckNewVersionPromise + * @tc.desc Called by promise, the result is the new Promise version. + */ + it('testCheckNewVersionPromise', 0, function() { + console.info('testCheckNewVersionPromise START'); + try { + let ret = updater.checkNewVersion().then(data => { + console.log("checkNewVersion success" + data); + expect(data.status).assertEqual(0); + expect(data.checkResults.size > 0); + console.log(`info versionName = ` + data.checkResults[0].versionName); + console.log(`info versionCode = ` + data.checkResults[0].versionCode); + console.log(`info verifyInfo = ` + data.checkResults[0].verifyInfo); + console.log(`info descriptionId = ` + data.checkResults[0].descriptionId); + console.log(`info content = ` + data.descriptionInfo[0].content); + console.log(`info size = ` + data.checkResults[0].size); + }).catch(error => + console.error("checkNewVersion error " + error) + ); + expect(ret != 0); + } catch(e) { + console.error("checkNewVersion catch " + e) + } + console.info('[checkNewVersion] success.'); + console.info('testCheckNewVersionPromise END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0022 + * @tc.name testCheckNewVersionPromise2 + * @tc.desc Test incorrect parameters. + */ + it('testCheckNewVersionPromise2', 0, function() { + console.info('testCheckNewVersionPromise2 START'); + try{ + let ret = updater.checkNewVersion(2).then(data => { + }).catch(error => + console.error("checkNewVersion error " + error) + ); + expect(ret != 0); + } catch(e) { + console.error("checkNewVersion catch " + e); + } + console.info('[checkNewVersion] success.'); + console.info('testCheckNewVersionPromise2 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0023 + * @tc.name testCheckNewVersionPromise3 + * @tc.desc Test incorrect parameters. + */ + it('testCheckNewVersionPromise3', 0, function() { + console.info('testCheckNewVersionPromise3 START'); + try{ + let ret = updater.checkNewVersion(2, 4).then(data => { + }).catch(error => + console.error("checkNewVersion error " + error) + ); + expect(ret != 0); + } catch(e) { + console.error("checkNewVersion catch " + e); + } + console.info('[checkNewVersion] success.'); + console.info('testCheckNewVersionPromise3 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0024 + * @tc.name testCheckNewVersionPromise4 + * @tc.desc Test incorrect parameters. + */ + it('testCheckNewVersionPromise4', 0, function() { + console.info('testCheckNewVersionPromise4 START'); + try{ + let ret = updater.checkNewVersion("3333").then(data => { + }).catch(error => + console.error("checkNewVersion error " + error) + ); + expect(ret != 0); + } catch(e) { + console.error("checkNewVersion catch " + e); + } + console.info('[checkNewVersion] success.'); + console.info('testCheckNewVersionPromise4 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0025 + * @tc.name testCheckNewVersionPromise5 + * @tc.desc Test incorrect parameters. + */ + it('testCheckNewVersionPromise5', 0, function() { + console.info('testCheckNewVersionPromise5 START'); + try{ + let ret = updater.checkNewVersion("3333", "44444").then(data => { + }).catch(error => + console.error("checkNewVersion error " + error) + ); + expect(ret != 0); + } catch(e) { + console.error("checkNewVersion catch " + e); + } + console.info('[checkNewVersion] success.'); + console.info('testCheckNewVersionPromise5 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0026 + * @tc.name testSetUpdatePolicy001 + * @tc.desc Test and set the upgrade strategy, check whether the result is correct. + */ + it('testSetUpdatePolicy001', 0, function() { + console.info('testSetUpdatePolicy001 START' + updater); + // Set strategy. + let policy = { + autoDownload: false, + autoDownloadNet: true, + mode: 2, + autoUpgradeInterval: [ 2, 3 ], + autoUpgradeCondition: 2 + } + try { + let ret = updater.setUpdatePolicy(policy, function(err, data){ + console.log("setUpdatePolicy success" + data); + expect(data).assertEqual(0); + }); + expect(ret != 0); + } catch(e) { + console.error('[testSetUpdatePolicy001] fail.' + e); + } + console.info('[setUpdatePolicy] success.'); + console.info('testSetUpdatePolicy001 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0027 + * @tc.name testGetUpdatePolicy001 + * @tc.desc . + */ + it('testGetUpdatePolicy001', 0, function() { + console.info('testGetUpdatePolicy001 START'); + try { + let ret = updater.getUpdatePolicy(function(err, data){ + console.log("getUpdatePolicy success" + data); + expect(data.autoDownload).assertEqual(false); + expect(data.autoDownloadNet).assertEqual(true); + expect(data.mode).assertEqual(2); + expect(data.autoUpgradeInterval[0]).assertEqual(2); + expect(data.autoUpgradeInterval[1]).assertEqual(3); + + }); + expect(ret != 0); + } catch(e) { + console.error('[testGetUpdatePolicy001] fail.' + e); + } + console.info('[getUpdatePolicy] success.'); + console.info('testGetUpdatePolicy001 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0028 + * @tc.name testSetUpdatePolicy002 + * @tc.desc Modify the upgrade strategy and check whether the result is correct. + */ + it('testSetUpdatePolicy002', 0, function() { + console.info('testSetUpdatePolicy002 START' + updater); + let policy = { + autoDownload: true, + autoDownloadNet: true, + mode: 2, + autoUpgradeInterval: [ 2, 3 ], + autoUpgradeCondition: 2 + } + try { + let ret = updater.setUpdatePolicy(policy, function(err, data){ + console.log("setUpdatePolicy success" + data); + expect(data).assertEqual(0); + }); + expect(ret != 0); + } catch(e) { + console.error('[testSetUpdatePolicy002] fail.' + e); + } + + console.info('[setUpdatePolicy] success.'); + console.info('testSetUpdatePolicy002 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0029 + * @tc.name testGetUpdatePolicy002 + * @tc.desc Get the modified strategy. + */ + it('testGetUpdatePolicy002', 0, function() { + console.info('testGetUpdatePolicy002 START'); + try { + let ret = updater.getUpdatePolicy(function(err, data){ + console.log("getUpdatePolicy success" + data); + expect(data.autoDownload).assertEqual(true); + expect(data.autoDownloadNet).assertEqual(true); + expect(data.mode).assertEqual(2); + expect(data.autoUpgradeInterval[0]).assertEqual(2); + expect(data.autoUpgradeInterval[1]).assertEqual(3); + }); + expect(ret != 0); + } catch(e) { + console.error('[testGetUpdatePolicy002] fail.' + e); + } + + console.info('[getUpdatePolicy] success.'); + console.info('testGetUpdatePolicy002 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0030 + * @tc.name testSetUpdatePolicy003 + * @tc.desc Modify strategy mode. + */ + it('testSetUpdatePolicy003', 0, function() { + console.info('testSetUpdatePolicy003 START' + updater); + // Set strategy. + let policy = { + autoDownload: false, + autoDownloadNet: false, + mode: 2, + autoUpgradeInterval: [ 2, 3 ], + autoUpgradeCondition: 2 + } + try { + let ret = updater.setUpdatePolicy(policy, function(err, data){ + console.log("setUpdatePolicy success" + data); + expect(data).assertEqual(0); + }) + expect(ret != 0); + } catch(e) { + console.error('[testSetUpdatePolicy003] fail.' + e); + } + console.info('[setUpdatePolicy] success.'); + console.info('testSetUpdatePolicy003 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0031 + * @tc.name testGetUpdatePolicy003 + * @tc.desc Obtain strategy mode. + */ + it('testGetUpdatePolicy003', 0, function() { + console.info('testGetUpdatePolicy003 START ' + updater); + try { + let ret = updater.getUpdatePolicy(function(err, data){ + console.log("getUpdatePolicy success" + data); + expect(data.autoDownload).assertEqual(false); + expect(data.autoDownloadNet).assertEqual(false); + expect(data.mode).assertEqual(2); + expect(data.autoUpgradeInterval[0]).assertEqual(2); + expect(data.autoUpgradeInterval[1]).assertEqual(3); + }) + expect(ret != 0); + } catch(e) { + console.error('[testGetUpdatePolicy003] fail.' + e); + } + console.info('[getUpdatePolicy] success.'); + console.info('testGetUpdatePolicy003 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0032 + * @tc.name testSetUpdatePolicy004 + * @tc.desc Set policy upgrade interval. + */ + it('testSetUpdatePolicy004', 0, function() { + console.info('testSetUpdatePolicy004 START' + updater); + // Set strategy. + let policy = { + autoDownload: false, + autoDownloadNet: false, + mode: 1, + autoUpgradeInterval: [ 100, 100], + autoUpgradeCondition: 2 + } + try { + let ret = updater.setUpdatePolicy(policy, function(err, data){ + console.log("setUpdatePolicy success" + data); + expect(data).assertEqual(0); + }) + expect(ret != 0); + } catch(e) { + console.error('[testGetUpdatePolicy003] fail.' + e); + } + console.info('[setUpdatePolicy] success.'); + console.info('testSetUpdatePolicy004 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0033 + * @tc.name testGetUpdatePolicy004 + * @tc.desc Obtain policy upgrade interval. + */ + it('testGetUpdatePolicy004', 0, function() { + console.info('testGetUpdatePolicy004 START' + updater); + try { + let ret = updater.getUpdatePolicy(function(err, data){ + console.log("getUpdatePolicy success" + data); + expect(data.autoDownload).assertEqual(false); + expect(data.autoDownloadNet).assertEqual(false); + expect(data.mode).assertEqual(1); + expect(data.autoUpgradeInterval[0]).assertEqual(expect_value); + expect(data.autoUpgradeInterval[1]).assertEqual(expect_value); + }) + expect(ret != 0); + } catch(e) { + console.error('[testGetUpdatePolicy004] fail.' + e); + } + console.info('[getUpdatePolicy] success.'); + console.info('testGetUpdatePolicy004 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0034 + * @tc.name testSetUpdatePolicy005 + * @tc.desc Test incorrect parameters. + */ + it('testSetUpdatePolicy005', 0, function() { + console.info('testSetUpdatePolicy005 START' + updater); + try { + let ret = updater.setUpdatePolicy("", function(err, data){ + console.log("setUpdatePolicy success" + data); + expect(data).assertEqual(0); + }); + expect(ret != 0); + } catch(e) { + console.error('[testSetUpdatePolicy005] fail.' + e); + } + console.info('[setUpdatePolicy] success.'); + console.info('testSetUpdatePolicy005 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0035 + * @tc.name testGetUpdatePolicy005 + * @tc.desc Test incorrect parameters. + */ + it('testGetUpdatePolicy005', 0, function() { + console.info('testGetUpdatePolicy005 START' + updater); + try { + let ret = updater.getUpdatePolicy("", function(err, data){ + }) + expect(ret != 0); + } catch(e) { + console.error('[testSetUpdatePolicy005] fail.' + e); + } + console.info('[getUpdatePolicy] success.'); + console.info('testGetUpdatePolicy005 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0036 + * @tc.name testSetUpdatePolicyPromise + * @tc.desc Promise method call. + */ + it('testSetUpdatePolicyPromise', 0, function() { + console.info('testSetUpdatePolicyPromise START' + updater); + // Set strategy. + let policy = { + autoDownload: false, + autoDownloadNet: true, + mode: 2, + autoUpgradeInterval: [ 2, 3 ], + autoUpgradeCondition: 2 + } + try { + let ret = updater.setUpdatePolicy(policy).then(data => { + console.log("setUpdatePolicy success" + data); + expect(data).assertEqual(0); + }).catch(error => + console.error("setUpdatePolicy error " + error) + ); + expect(ret != 0); + } catch(e) { + console.error('[testSetUpdatePolicyPromise] fail.' + e); + } + console.info('[setUpdatePolicy] success.'); + console.info('testSetUpdatePolicyPromise END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0037 + * @tc.name testGetUpdatePolicyPromise + * @tc.desc Promise method call. + */ + it('testGetUpdatePolicyPromise', 0, function() { + console.info('testGetUpdatePolicyPromise START'); + try { + let ret = updater.getUpdatePolicy().then(data => { + console.log("getUpdatePolicy success" + data); + expect(data.autoDownload).assertEqual(false); + expect(data.autoDownload).assertEqual(true); + expect(data.mode).assertEqual(2); + expect(data.autoUpgradeInterval[0]).assertEqual(2); + expect(data.autoUpgradeInterval[1]).assertEqual(3); + expect(data.autoUpgradeCondition).assertEqual(2); + }).catch(error => + console.error("getUpdatePolicy catch " + error) + ); + expect(ret != 0); + } catch(e) { + console.error('[testGetUpdatePolicyPromise] fail.' + e); + } + console.info('[getUpdatePolicy] success.'); + console.info('testGetUpdatePolicyPromise END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0038 + * @tc.name testSetUpdatePolicyPromise002 + * @tc.desc Promise method call. + */ + it('testSetUpdatePolicyPromise002', 0, function() { + console.info('testSetUpdatePolicyPromise002 START' + updater); + let policy = { + autoDownload: true, + autoDownloadNet: true, + mode: 2, + autoUpgradeInterval: [ 2, 3 ], + autoUpgradeCondition: 2 + } + try { + let ret = updater.setUpdatePolicy(policy).then(data => { + console.log("setUpdatePolicy success" + data); + expect(data).assertEqual(0); + }).catch(error => + console.error("setUpdatePolicy error " + error) + ); + expect(ret != 0); + } catch(e) { + console.error('[setUpdatePolicy] fail.' + e); + } + console.info('[setUpdatePolicy] success.'); + console.info('testSetUpdatePolicyPromise002 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0039 + * @tc.name testGetUpdatePolicy002 + * @tc.desc Promise method call. + */ + it('testGetUpdatePolicyPromise002', 0, function() { + console.info('testGetUpdatePolicyPromise002 START'); + try { + let ret = updater.getUpdatePolicy().then(data => { + console.log("getUpdatePolicy success" + data); + expect(data.autoDownload).assertEqual(true); + expect(data.autoDownloadNet).assertEqual(true); + expect(data.mode).assertEqual(2); + expect(data.autoUpgradeInterval[0]).assertEqual(2); + expect(data.autoUpgradeInterval[1]).assertEqual(3); + }); + expect(ret != 0); + } catch(e) { + console.error('[testGetUpdatePolicyPromise002] fail.' + e); + } + console.info('[getUpdatePolicy] success.'); + console.info('testGetUpdatePolicyPromise002 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0040 + * @tc.name testSetUpdatePolicyPromise003 + * @tc.desc Promise method call. + */ + it('testSetUpdatePolicyPromise003', 0, function() { + console.info('testSetUpdatePolicyPromise003 START'); + // Set strategy. + let policy = { + autoDownload: false, + autoDownloadNet: false, + mode: 2, + autoUpgradeInterval: [ 2, 3 ], + autoUpgradeCondition: 2 + } + try { + let ret = updater.setUpdatePolicy(policy).then(data => { + console.log("setUpdatePolicy success" + data); + expect(data).assertEqual(0); + }).catch(error => { + console.info('[setUpdatePolicy] error ' + error) + }) + expect(ret != 0); + } catch(e) { + console.error('[testSetUpdatePolicyPromise003] fail.' + e); + } + console.info('[setUpdatePolicy] success.'); + console.info('testSetUpdatePolicyPromise003 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0041 + * @tc.name testGetUpdatePolicyPromise003 + * @tc.desc Promise method call. + */ + it('testGetUpdatePolicyPromise003', 0, function() { + console.info('testGetUpdatePolicyPromise003 START '); + try { + let ret = updater.getUpdatePolicy().then(data => { + console.log("getUpdatePolicy success" + data); + expect(data.autoDownload).assertEqual(false); + expect(data.autoDownloadNet).assertEqual(false); + expect(data.mode).assertEqual(2); + expect(data.autoUpgradeInterval[0]).assertEqual(2); + expect(data.autoUpgradeInterval[1]).assertEqual(3); + }).catch(error => { + console.info('[getUpdatePolicy] error ' + error) + }) + expect(ret != 0); + } catch(e) { + console.info('[getUpdatePolicy] catch ' + e) + } + console.info('[getUpdatePolicy] success.'); + console.info('testGetUpdatePolicyPromise003 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0042 + * @tc.name testSetUpdatePolicyPromise004 + * @tc.desc Promise method call. + */ + it('testSetUpdatePolicyPromise004', 0, function() { + console.info('testSetUpdatePolicyPromise004 START' + updater); + // Set strategy. + let policy = { + autoDownload: false, + autoDownloadNet: false, + mode: 1, + autoUpgradeInterval: [ 100, 100], + autoUpgradeCondition: 2 + } + try { + let ret = updater.setUpdatePolicy(policy).then(data => { + console.log("setUpdatePolicy success" + data); + expect(data).assertEqual(0); + }).catch(error => { + console.info('[setUpdatePolicy] error ' + error) + }) + expect(ret != 0); + } catch(e) { + console.info('[testSetUpdatePolicyPromise004] catch ' + e) + } + console.info('[setUpdatePolicy] success.'); + console.info('testSetUpdatePolicyPromise004 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0043 + * @tc.name testGetUpdatePolicyPromise004 + * @tc.desc Promise method call. + */ + it('testGetUpdatePolicyPromise004', 0, function() { + console.info('testGetUpdatePolicyPromise004 START' + updater); + try { + let ret = updater.getUpdatePolicy().then(data => { + console.log("getUpdatePolicy success" + data); + expect(data.autoDownload).assertEqual(false); + expect(data.autoDownloadNet).assertEqual(false); + expect(data.mode).assertEqual(1); + expect(data.autoUpgradeInterval[0]).assertEqual(expect_value); + expect(data.autoUpgradeInterval[1]).assertEqual(expect_value); + }).catch(error => { + console.info('[getUpdatePolicy] error ' + error) + }) + expect(ret != 0); + } catch(e) { + console.info('[testSetUpdatePolicyPromise004] catch ' + e) + } + console.info('[getUpdatePolicy] success.'); + console.info('testGetUpdatePolicyPromise004 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0044 + * @tc.name testSetUpdatePolicyPromise005 + * @tc.desc Test incorrect parameters. + */ + it('testSetUpdatePolicyPromise005', 0, function() { + console.info('testSetUpdatePolicyPromise005 START' + updater); + try { + let ret = updater.setUpdatePolicy("").then(data => { + console.log("setUpdatePolicy success" + data); + expect(data).assertEqual(0); + }); + expect(ret != 0); + } catch (e) { + console.info('[setUpdatePolicy] catch ' + e); + } + console.info('[setUpdatePolicy] success.'); + console.info('testSetUpdatePolicyPromise005 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0045 + * @tc.name testGetUpdatePolicyPromise005 + * @tc.desc Test incorrect parameters. + */ + it('testGetUpdatePolicyPromise005', 0, function() { + console.info('testGetUpdatePolicy005 START' + updater); + try{ + let ret = updater.getUpdatePolicy(param_value1).then(data => { + }) + expect(ret != 0); + } catch (e) { + console.info('[setUpdatePolicy] catch ' + e); + } + console.info('[getUpdatePolicy] success.'); + console.info('testGetUpdatePolicyPromise005 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0046 + * @tc.name testDownloadVersion + * @tc.desc Unsubscribe from monitoring. + */ + it('testDownloadVersion', 0, function() { + console.info('testDownloadVersion START'); + // Open download monitor. + try{ + updater.on('downloadProgress', progress => { + console.log("downloadProgress on" + progress); + console.log(`downloadProgress status: ` + progress.status); + console.log(`downloadProgress percent: ` + progress.percent); + console.log(`downloadProgress endReason: ` + progress.endReason); + if (progress.status == updateState.UPDATE_STATE_DOWNLOAD_SUCCESS || + progress.status == updateState.UPDATE_STATE_VERIFY_SUCCESS) { + expect(progress.percent).assertEqual(expect_value); + updater.off("downloadProgress"); + } + }) + let ret = updater.download(); + expect(ret != 0); + } catch (e) { + console.info('[testDownloadVersion] catch ' + e); + } + + console.info('[downloadVersion] success.'); + console.info('testDownloadVersion END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0047 + * @tc.name testDownloadVersion02 + * @tc.desc Unsubscribe out of monitoring. + */ + it('testDownloadVersion02', 0, function() { + console.info('testDownloadVersion02 START'); + // Open download monitor + try{ + updater.on('downloadProgress', progress => { + console.log("downloadProgress on" + progress); + console.log(`downloadProgress status: ` + progress.status); + console.log(`downloadProgress percent: ` + progress.percent); + console.log(`downloadProgress endReason: ` + progress.endReason); + if (progress.status == updateState.UPDATE_STATE_DOWNLOAD_SUCCESS || + progress.status == updateState.UPDATE_STATE_VERIFY_SUCCESS) { + expect(progress.percent).assertEqual(expect_value); + } + }) + let ret = updater.download(); + // Cancel subscription immediately, no callback will be received. + updater.off("downloadProgress"); + expect(ret != 0); + } catch (e) { + console.info('[testDownloadVersion02] catch ' + e); + } + console.info('[downloadVersion] success.'); + console.info('testDownloadVersion END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0048 + * @tc.name testDownloadVersion03 + * @tc.desc Test download parameter, callback is not supported. + */ + it('testDownloadVersion03', 0, function() { + console.info('testDownloadVersion03 START'); + try{ + let ret = updater.download(progress => { + console.log("downloadProgress on" + progress); + console.log(`downloadProgress status: ` + progress.status); + console.log(`downloadProgress percent: ` + progress.percent); + console.log(`downloadProgress endReason: ` + progress.endReason); + if (progress.status == updateState.UPDATE_STATE_DOWNLOAD_SUCCESS || + progress.status == updateState.UPDATE_STATE_VERIFY_SUCCESS) { + expect(progress.percent).assertEqual(expect_value); + } + }) + expect(ret != 0); + } catch (e) { + console.info('[testDownloadVersion03] catch ' + e); + } + console.info('[downloadVersion] success.'); + console.info('testDownloadVersion END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0049 + * @tc.name testDownloadVersion04 + * @tc.desc Test subscription without parameters, return error. + */ + it('testDownloadVersion04', 0, function() { + console.info('testDownloadVersion04 START'); + try{ + // Open download monitor. + let ret = updater.on('downloadProgress'); + expect(ret != 0); + let ret_download = updater.download(); + expect(ret_download != 0); + // Cancel subscription immediately, no callback will be received. + let ret_off = updater.off("downloadProgress"); + expect(ret_off != 0); + } catch (e) { + console.info('[testDownloadVersion04] catch ' + e); + } + console.info('[downloadVersion] success.'); + console.info('testDownloadVersion04 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0050 + * @tc.name testDownloadVersion05 + * @tc.desc Take function to subscribe. + */ + it('testDownloadVersion05', 0, function() { + function testFunction(progress) { + console.log("downloadProgress on" + progress); + console.log(`downloadProgress status: ` + progress.status); + console.log(`downloadProgress percent: ` + progress.percent); + console.log(`downloadProgress endReason: ` + progress.endReason); + } + console.info('testDownloadVersion05 START'); + try{ + // Open download monitor. + let ret = updater.on('downloadProgress', testFunction); + expect(ret == 0); + + let ret_download = updater.download(); + expect(ret_download != 0); + // Cancel subscription immediately, no callback will be received. + let ret_off = updater.off("downloadProgress", testFunction); + expect(ret_off != 0); + } catch (e) { + console.info('[testDownloadVersion05] catch ' + e); + } + console.info('[downloadVersion] success.'); + console.info('testDownloadVersion05 END'); + }); + + + /** + * @tc.number SUB_UPDATE_JS_API_0051 + * @tc.name testUpgradeVersion01 + * @tc.desc Unsubscribe from monitoring. + */ + it('testUpgradeVersion01', 0, function() { + console.info('testUpgradeVersion01 START'); + try{ + // Open download monitor. + updater.on('upgradeProgress', progress => { + console.log("upgradeProgress on" + progress); + console.log(`upgradeProgress status: ` + progress.status); + console.log(`upgradeProgress percent: ` + progress.percent); + console.log(`upgradeProgress endReason: ` + progress.endReason); + if (progress.status == updateState.UPDATE_STATE_DOWNLOAD_SUCCESS || + progress.status == updateState.UPDATE_STATE_VERIFY_SUCCESS) { + expect(progress.percent).assertEqual(expect_value); + updater.off("upgradeProgress"); + } + }) + let ret = updater.upgrade(); + expect(ret != 0); + } catch (e) { + console.info('[testUpgradeVersion01] catch ' + e); + } + console.info('[upgrade] success.'); + console.info('testUpgradeVersion01 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0052 + * @tc.name testUpgradeVersion02 + * @tc.desc Unsubscribe out of monitoring. + */ + it('testUpgradeVersion02', 0, function() { + console.info('testUpgradeVersion02 START'); + try{ + // Open download monitor. + let ret_on = updater.on('upgradeProgress', progress => { + console.log("upgradeProgress on" + progress); + console.log(`upgradeProgress status: ` + progress.status); + console.log(`upgradeProgress percent: ` + progress.percent); + console.log(`upgradeProgress endReason: ` + progress.endReason); + if (progress.status == updateState.UPDATE_STATE_DOWNLOAD_SUCCESS || + progress.status == updateState.UPDATE_STATE_VERIFY_SUCCESS) { + expect(progress.percent).assertEqual(expect_value); + } + }) + expect(ret_on != 0); + let ret = updater.upgrade(); + expect(ret != 0); + // Cancel subscription immediately, no callback will be received. + let ret_off = updater.off("upgradeProgress"); + expect(ret_off != 0); + } catch (e) { + console.info('[testUpgradeVersion02] catch ' + e); + } + console.info('[upgrade] success.'); + console.info('testUpgradeVersion02 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0053 + * @tc.name testUpgradeVersion03 + * @tc.desc Test download parameter, callback is not supported. + */ + it('testUpgradeVersion03', 0, function() { + console.info('testUpgradeVersion03 START'); + try{ + let ret = updater.upgrade(progress => { + console.log("upgradeProgress on" + progress); + console.log(`upgradeProgress status: ` + progress.status); + console.log(`upgradeProgress percent: ` + progress.percent); + console.log(`upgradeProgress endReason: ` + progress.endReason); + if (progress.status == updateState.UPDATE_STATE_DOWNLOAD_SUCCESS || + progress.status == updateState.UPDATE_STATE_VERIFY_SUCCESS) { + expect(progress.percent).assertEqual(expect_value); + } + }) + expect(ret != 0); + } catch (e) { + console.info('[testUpgradeVersion03] catch ' + e); + } + console.info('[upgrade] success.'); + console.info('testUpgradeVersion03 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0054 + * @tc.name testUpgradeVersion04 + * @tc.desc Test subscription without parameters, return error. + */ + it('testUpgradeVersion04', 0, function() { + console.info('testUpgradeVersion04 START'); + try{ + // Open download monitor. + let ret = updater.on('upgradeProgress'); + expect(ret != 0); + let ret_upgrade = updater.upgrade(); + expect(ret_upgrade != 0); + // Cancel subscription immediately, no callback will be received. + let ret_off = updater.off("upgradeProgress"); + expect(ret_off != 0); + } catch (e) { + console.info('[testUpgradeVersion04] catch ' + e); + } + console.info('[upgrade] success.'); + console.info('testUpgradeVersion04 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0055 + * @tc.name testUpgradeVersion05 + * @tc.desc Take function to subscribe. + */ + it('testUpgradeVersion05', 0, function() { + function testFunction(progress) { + console.log("upgradeProgress on" + progress); + console.log(`upgradeProgress status: ` + progress.status); + console.log(`upgradeProgress percent: ` + progress.percent); + console.log(`upgradeProgress endReason: ` + progress.endReason); + } + console.info('testUpgradeVersion05 START'); + try{ + let ret = updater.on('upgradeProgress', testFunction); + expect(ret == 0); + + let ret_upgrade = updater.upgrade(); + expect(ret_upgrade != 0); + + let ret_off = updater.off("upgradeProgress", testFunction); + expect(ret_off != 0); + } catch (e) { + console.info('[testUpgradeVersion05] catch ' + e); + } + console.info('[upgrade] success.'); + console.info('testUpgradeVersion05 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0056 + * @tc.name testOnDownload2 + * @tc.desc Test incorrect parameters. + */ + it('testOnDownload', 0, function() { + console.info('testOnDownload START'); + try{ + let ret = updater.on(function(){}); + expect(ret != 0); + } catch (e) { + console.info('[testOnDownload] catch ' + e); + } + console.info('[testOnDownload] success.'); + console.info('testOnDownload END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0057 + * @tc.name testOnDownload2 + * @tc.desc Test incorrect parameters. + */ + it('testOnDownload2', 0, function() { + console.info('testOnDownload2 START'); + try{ + let ret = updater.on(); + expect(ret != 0); + } catch (e) { + console.info('[testOnDownload2] catch ' + e); + } + console.info('[testOnDownload2] success.'); + console.info('testOnDownload2 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0058 + * @tc.name testOnDownload3 + * @tc.desc Test incorrect parameters. + */ + it('testOnDownload3', 0, function() { + console.info('testOnDownload3 START'); + try{ + let ret = updater.on("333333333"); + expect(ret != 0); + } catch (e) { + console.info('[testOnDownload3] catch ' + e); + } + console.info('[testOnDownload3] success.'); + console.info('testOnDownload3 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0059 + * @tc.name testOnDownload3 + * @tc.desc Test incorrect parameters. + */ + it('testOnDownload4', 0, function() { + console.info('testOnDownload3 START'); + try{ + let ret = updater.on(param_value2); + expect(ret != 0); + } catch (e) { + console.info('[testOnDownload4] catch ' + e); + } + console.info('[testOnDownload4] success.'); + console.info('testOnDownload4 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0060 + * @tc.name testOnDownload4 + * @tc.desc Test incorrect parameters. + */ + it('testOnDownload5', 0, function() { + console.info('testOnDownload5 START'); + try{ + let ret = updater.on(param_value2, "4444444444444"); + expect(ret != 0); + } catch (e) { + console.info('[testOnDownload5] catch ' + e); + } + console.info('[testOnDownload5] success.'); + console.info('testOnDownload5 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0061 + * @tc.name testOffDownload + * @tc.desc Test incorrect parameters. + */ + it('testOffDownload', 0, function() { + console.info('testOffDownload START'); + try{ + let ret = updater.off(); + expect(ret != 0); + } catch (e) { + console.info('[testOffDownload] catch ' + e); + } + console.info('[testOffDownload] success.'); + console.info('testOffDownload END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0062 + * @tc.name testOffDownload2 + * @tc.desc Test incorrect parameters. + */ + it('testOffDownload2', 0, function() { + console.info('testOffDownload2 START'); + try{ + let ret = updater.off("333333333"); + expect(ret != 0); + } catch (e) { + console.info('[testOffDownload2] catch ' + e); + } + console.info('[testOffDownload2] success.'); + console.info('testOffDownload2 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0063 + * @tc.name testOffDownload3 + * @tc.desc Test incorrect parameters. + */ + it('testOffDownload3', 0, function() { + console.info('testOffDownload3 START'); + try{ + let ret = updater.on(param_value2); + expect(ret != 0); + } catch (e) { + console.info('[testOffDownload3] catch ' + e); + } + console.info('[testOffDownload3] success.'); + console.info('testOffDownload3 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0064 + * @tc.name testOffDownload4 + * @tc.desc Test incorrect parameters. + */ + it('testOffDownload4', 0, function() { + console.info('testOffDownload4 START'); + try{ + let ret = updater.off(param_value2, "4444444444444"); + expect(ret != 0); + } catch (e) { + console.info('[testOffDownload4] catch ' + e); + } + console.info('[testOffDownload4] success.'); + console.info('testOffDownload4 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0065 + * @tc.name testOffDownload5 + * @tc.desc Test incorrect parameters. + */ + it('testOffDownload5', 0, function() { + console.info('testOffDownload5 START'); + try{ + let ret = updater.off(function(){}); + expect(ret != 0); + } catch (e) { + console.info('[testOffDownload5] catch ' + e); + } + console.info('[testOffDownload5] success.'); + console.info('testOffDownload5 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0066 + * @tc.name testOnUpgrade + * @tc.desc Test incorrect parameters. + */ + it('testOnUpgrade', 0, function() { + console.info('testOnUpgrade START'); + try{ + let ret = updater.on("upgradeProgress", function(){}); + expect(ret != 0); + } catch (e) { + console.info('[testOnUpgrade] catch ' + e); + } + console.info('[testOnUpgrade] success.'); + console.info('testOnUpgrade END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0067 + * @tc.name testOnUpgrade2 + * @tc.desc Test incorrect parameters. + */ + it('testOnUpgrade2', 0, function() { + console.info('testOnUpgrade2 START'); + try{ + let ret = updater.on("upgradeProgress"); + expect(ret != 0); + } catch (e) { + console.info('[testOnUpgrade2] catch ' + e); + } + console.info('[testOnUpgrade2] success.'); + console.info('testOnUpgrade2 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0068 + * @tc.name testOnUpgrade3 + * @tc.desc Test incorrect parameters. + */ + it('testOnUpgrade3', 0, function() { + console.info('testOnUpgrade3 START'); + try{ + let ret = updater.on("upgradeProgress", "333333333"); + expect(ret != 0); + } catch (e) { + console.info('[testOnUpgrade3] catch ' + e); + } + console.info('[testOnUpgrade3] success.'); + console.info('testOnUpgrade3 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0069 + * @tc.name testOnDownload3 + * @tc.desc Test incorrect parameters. + */ + it('testOnUpgrade4', 0, function() { + console.info('testOnUpgrade4 START'); + try{ + let ret = updater.on("upgradeProgress", param_value2); + expect(ret != 0); + } catch (e) { + console.info('[testOnUpgrade3] catch ' + e); + } + console.info('[testOnUpgrade4] success.'); + console.info('testOnUpgrade4 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0070 + * @tc.name testOnUpgrade5 + * @tc.desc Test incorrect parameters. + */ + it('testOnUpgrade5', 0, function() { + console.info('testOnUpgrade5 START'); + try{ + let ret = updater.on(param_value2, "4444444444444"); + expect(ret != 0); + } catch (e) { + console.info('[testOnUpgrade5] catch ' + e); + } + console.info('[testOnUpgrade5] success.'); + console.info('testOnUpgrade5 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0071 + * @tc.name testOffUpgrade + * @tc.desc Test incorrect parameters. + */ + it('testOffUpgrade', 0, function() { + console.info('testOffUpgrade START'); + try{ + let ret = updater.off("upgradeProgress"); + expect(ret != 0); + } catch (e) { + console.info('[testOffUpgrade] catch ' + e); + } + console.info('[testOffUpgrade] success.'); + console.info('testOffUpgrade END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0072 + * @tc.name testOffUpgrade2 + * @tc.desc Test incorrect parameters. + */ + it('testOffUpgrade2', 0, function() { + console.info('testOffUpgrade2 START'); + try{ + let ret = updater.off("upgradeProgress", "333333333"); + expect(ret != 0); + } catch (e) { + console.info('[testOffUpgrade] catch ' + e); + } + console.info('[testOffUpgrade2] success.'); + console.info('testOffUpgrade2 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0073 + * @tc.name testOffUpgrade3 + * @tc.desc Test incorrect parameters. + */ + it('testOffUpgrade3', 0, function() { + console.info('testOffDownload3 START'); + try{ + let ret = updater.on("upgradeProgress", param_value2); + expect(ret != 0); + } catch (e) { + console.info('[testOffUpgrade3] catch ' + e); + } + console.info('[testOffUpgrade3] success.'); + console.info('testOffUpgrade3 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0074 + * @tc.name testOffUpgrade4 + * @tc.desc Test incorrect parameters. + */ + it('testOffUpgrade4', 0, function() { + console.info('testOffUpgrade4 START'); + try{ + let ret = updater.off("upgradeProgress", param_value2, "4444444444444"); + expect(ret != 0); + } catch (e) { + console.info('[testOffUpgrade4] catch ' + e); + } + console.info('[testOffUpgrade4] success.'); + console.info('testOffUpgrade4 END'); + }); + + /** + * @tc.number SUB_UPDATE_JS_API_0075 + * @tc.name testOffUpgrade5 + * @tc.desc Test incorrect parameters. + */ + it('testOffUpgrade5', 0, function() { + console.info('testOffUpgrade5 START'); + try{ + let ret = updater.off("upgradeProgress", "6"); + expect(ret != 0); + } catch (e) { + console.info('[testOffUpgrade5] catch ' + e); + } + console.info('[testOffUpgrade5] success.'); + console.info('testOffUpgrade5 END'); + }); +}); \ No newline at end of file diff --git a/updater/update_test/gradle/entry/src/ohosTest/resources/base/element/string.json b/updater/update_test/gradle/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f6a9508d8763dc699f2c5f0fcbc08bd4b5c6ba72 --- /dev/null +++ b/updater/update_test/gradle/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication0420" + }, + { + "name": "mainability_description", + "value": "hap sample empty page" + } + ] +} diff --git a/updater/update_test/gradle/entry/src/ohosTest/resources/base/media/icon.png b/updater/update_test/gradle/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/updater/update_test/gradle/entry/src/ohosTest/resources/base/media/icon.png differ diff --git a/updater/update_test/hap/entry-debug-signed.hap b/updater/update_test/hap/entry-debug-signed.hap new file mode 100755 index 0000000000000000000000000000000000000000..3d29f981e09746e640f8fb678b936e826eb08eb8 Binary files /dev/null and b/updater/update_test/hap/entry-debug-signed.hap differ