diff --git a/aafwk_lite/ability_posix/BUILD.gn b/aafwk_lite/ability_posix/BUILD.gn index 6b6ed2632652de9e2ffaedb0a0bf4bcd78fca13e..9f0d1c4e795db5d579463e32066aaac7e0e18d36 100755 --- a/aafwk_lite/ability_posix/BUILD.gn +++ b/aafwk_lite/ability_posix/BUILD.gn @@ -51,12 +51,9 @@ hcpptest_suite("ActsAbilityMgrTest") { "${appexecfwk_lite_path}/interfaces/innerkits/bundlemgr_lite/", "//foundation/distributedschedule/samgr_lite/interfaces/kits/registry", "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", - "//kernel/liteos_a/kernel/include", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//utils/native/lite/include", - "//kernel/liteos_a/lib/libsec/include", "${appexecfwk_lite_path}/interfaces/innerkits/bundlemgr_lite", "//foundation/graphic/ui/interfaces/kits", "//foundation/graphic/utils/interfaces/innerkits", diff --git a/appexecfwk_lite/appexecfwk_posix/BUILD.gn b/appexecfwk_lite/appexecfwk_posix/BUILD.gn index e7647c3c15e0e22694a7ccd4152753d04865f532..5066813bc7fd457882b0f61dbd7037e4ddc384ce 100755 --- a/appexecfwk_lite/appexecfwk_posix/BUILD.gn +++ b/appexecfwk_lite/appexecfwk_posix/BUILD.gn @@ -31,8 +31,6 @@ hcpptest_suite("ActsBundleMgrTest") { "//third_party/googletest/googletest/include", "//utils/native/lite/include", "${aafwk_lite_path}/interfaces/innerkits/intent_lite", - "//kernel/liteos_a/kernel/include", - "//kernel/liteos_a/kernel/common", "//third_party/cJSON", ] deps = [ diff --git a/communication_lite/softbus_posix/BUILD.gn b/communication_lite/softbus_posix/BUILD.gn index a47d12cda5179e84389881f65c60122e07da1e54..1c546b032d62b4c2eb93613ef89575a750df8b68 100755 --- a/communication_lite/softbus_posix/BUILD.gn +++ b/communication_lite/softbus_posix/BUILD.gn @@ -31,7 +31,6 @@ hcpptest_suite("ActsSoftBusTest") { "//third_party/cJSON", "//third_party/mbedtls/include", "//third_party/bounds_checking_function/include", - "//kernel/liteos_a/lib/libsec/include", "//base/startup/syspara_lite/interfaces/kits/include", "//base/security/deviceauth/interfaces/innerkits/deviceauth_lite", "//base/security/deviceauth/frameworks/deviceauth_lite/source/huks_adapter/", diff --git a/demo/hjsunit/Assertion/README_zh.md b/demo/hjsunit/Assertion/README_zh.md new file mode 100755 index 0000000000000000000000000000000000000000..e4bedae2772d019d51aa2992b81174927e31f275 --- /dev/null +++ b/demo/hjsunit/Assertion/README_zh.md @@ -0,0 +1,3 @@ +# Assertion + +- Assertion,HJSUnit测试框架提供的断言能力,通过expect(XXX).assertXX的断言方式检查结果。 \ No newline at end of file diff --git a/demo/hjsunit/Assertion/entry/src/main/js/default/app.js b/demo/hjsunit/Assertion/entry/src/main/js/default/app.js new file mode 100755 index 0000000000000000000000000000000000000000..4b241cccbaa71f0c5cbd9e7dc437a0feb224c7d5 --- /dev/null +++ b/demo/hjsunit/Assertion/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/demo/hjsunit/Assertion/entry/src/main/js/default/pages/index/index.css b/demo/hjsunit/Assertion/entry/src/main/js/default/pages/index/index.css new file mode 100755 index 0000000000000000000000000000000000000000..2b1965821483f4f8c8b97c86ef07fe87ea767d01 --- /dev/null +++ b/demo/hjsunit/Assertion/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,44 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 40px; + color: #000000; + opacity: 0.9; +} + +@media screen and (device-type: tablet) and (orientation: landscape) { + .title { + font-size: 100px; + } +} + +@media screen and (device-type: wearable) { + .title { + font-size: 28px; + color: #FFFFFF; + } +} + +@media screen and (device-type: tv) { + .container { + background-image: url("../../common/images/Wallpaper.png"); + background-size: cover; + background-repeat: no-repeat; + background-position: center; + } + + .title { + font-size: 100px; + color: #FFFFFF; + } +} + +@media screen and (device-type: phone) and (orientation: landscape) { + .title { + font-size: 60px; + } +} diff --git a/demo/hjsunit/Assertion/entry/src/main/js/default/pages/index/index.hml b/demo/hjsunit/Assertion/entry/src/main/js/default/pages/index/index.hml new file mode 100755 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/demo/hjsunit/Assertion/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/demo/hjsunit/Assertion/entry/src/main/js/default/pages/index/index.js b/demo/hjsunit/Assertion/entry/src/main/js/default/pages/index/index.js new file mode 100755 index 0000000000000000000000000000000000000000..49eb46a053db5a2da9542526b61eed164fa44d26 --- /dev/null +++ b/demo/hjsunit/Assertion/entry/src/main/js/default/pages/index/index.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 { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + } +} diff --git a/demo/hjsunit/Assertion/entry/src/ohosTest/js/default/app.js b/demo/hjsunit/Assertion/entry/src/ohosTest/js/default/app.js new file mode 100755 index 0000000000000000000000000000000000000000..044bffa75e29d7a5fe32644e19cc1bbbc5e9a7b1 --- /dev/null +++ b/demo/hjsunit/Assertion/entry/src/ohosTest/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/demo/hjsunit/Assertion/entry/src/ohosTest/js/default/pages/index/index.css b/demo/hjsunit/Assertion/entry/src/ohosTest/js/default/pages/index/index.css new file mode 100755 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/demo/hjsunit/Assertion/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/demo/hjsunit/Assertion/entry/src/ohosTest/js/default/pages/index/index.hml b/demo/hjsunit/Assertion/entry/src/ohosTest/js/default/pages/index/index.hml new file mode 100755 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/demo/hjsunit/Assertion/entry/src/ohosTest/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/demo/hjsunit/Assertion/entry/src/ohosTest/js/default/pages/index/index.js b/demo/hjsunit/Assertion/entry/src/ohosTest/js/default/pages/index/index.js new file mode 100755 index 0000000000000000000000000000000000000000..793667c97f947fdfc22f424847e85718bad72c49 --- /dev/null +++ b/demo/hjsunit/Assertion/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, Constant, 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', + 'version': '1.0.3' + }) + 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/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/ExampleJsunit.test.js b/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/ExampleJsunit.test.js new file mode 100755 index 0000000000000000000000000000000000000000..bdc0912bf7939add431943ded7146f3940144f13 --- /dev/null +++ b/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/ExampleJsunit.test.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 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/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertClose.test.js b/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertClose.test.js new file mode 100755 index 0000000000000000000000000000000000000000..c082d4bd454032b2ad394e3cc0b35fe82d28c579 --- /dev/null +++ b/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertClose.test.js @@ -0,0 +1,36 @@ +/* + * 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, it, expect} from 'deccjsunit/index' + +describe('assertClose', function () { + it('assertCloseSuccess001', 0, function () { + let a = 100; + let b = 0.1 + expect(a).assertClose(99, b) + }) + it('assertCloseFail002', 0, function () { + let a = 100; + let b = 0.1 + expect(a).assertClose(1, b) + }) + it('assertCloseFail003', 0, function () { + let a = 100; + let b = 0.1 + expect(a).assertClose(null, b) + }) + it('assertCloseFail004', 0, function () { + expect(null).assertClose(null, 0) + }) +}) \ No newline at end of file diff --git a/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertContain.test.js b/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertContain.test.js new file mode 100755 index 0000000000000000000000000000000000000000..9c5713a1e9a1858b9d8f1e0ee694b583988ec641 --- /dev/null +++ b/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertContain.test.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 {describe, it, expect} from 'deccjsunit/index' + +describe('assertContain', function () { + it('assertContainSuccessOnString', 0, function () { + let a = 'abc'; + let b = 'b' + expect(a).assertContain(b) + }) + it('assertContainSuccessOnArray', 0, function () { + let a = ['a', 'b', 'c']; + let b = 'b' + expect(a).assertContain(b) + }) + it('assertContainFailOnString', 0, function () { + let a = 'abc'; + let b = 'd' + expect(a).assertContain(b) + }) + it('assertContainFailOnArray', 0, function () { + let a = ['a', 'b', 'c']; + let b = 'd' + expect(a).assertContain(b) + }) +}) \ No newline at end of file diff --git a/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertFail.test.js b/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertFail.test.js new file mode 100755 index 0000000000000000000000000000000000000000..c09318bf0cf9b960925d7ca5329237a4c57db338 --- /dev/null +++ b/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertFail.test.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. + */ +import {describe, it, expect} from 'deccjsunit/index' + +describe('assertFail', function () { + it('assertFail', 0, function () { + let a = null + expect(a).assertFail() + }) +}) \ No newline at end of file diff --git a/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertFalse.test.js b/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertFalse.test.js new file mode 100755 index 0000000000000000000000000000000000000000..f5cb010066369d406d1510dbff106158df2cae2a --- /dev/null +++ b/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertFalse.test.js @@ -0,0 +1,26 @@ +/* + * 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, it, expect} from 'deccjsunit/index' + +describe('assertFalse', function () { + it('assertFalseSuccess', 0, function () { + let d = false + expect(d).assertFalse() + }) + it('assertFalseFail', 0, function () { + let d = true + expect(d).assertFalse() + }) +}) \ No newline at end of file diff --git a/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertInstantceOf.test.js b/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertInstantceOf.test.js new file mode 100755 index 0000000000000000000000000000000000000000..8c41cbecaf2c859dd4f3e5830dab4d3c10dc3beb --- /dev/null +++ b/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertInstantceOf.test.js @@ -0,0 +1,27 @@ +/* + * 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, it, expect} from 'deccjsunit/index' + +describe('assertInstanceOf', function () { + it('assertInstanceOfSuccessOnNumber', 0, function () { + let a = 12; + expect(a).assertInstanceOf('Number') + }) + it('assertInstanceOfFailOnNumber', 0, function () { + let a = "abc"; + expect(a).assertInstanceOf('String'); + expect(a).assertInstanceOf('Number'); + }) +}) diff --git a/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertLarger.test.js b/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertLarger.test.js new file mode 100755 index 0000000000000000000000000000000000000000..48de09018de0968fd39b7b2402042afc95fb3d63 --- /dev/null +++ b/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertLarger.test.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 {describe, it, expect} from 'deccjsunit/index' + +describe('assertLarger', function () { + it('assertLargerSuccess', 0, function () { + let a = 12; + let b = 10; + expect(a).assertLarger(b) + }) + it('assertLargerFail', 0, function () { + let a = 12; + let b = 13; + expect(a).assertLarger(b); + }) +}) \ No newline at end of file diff --git a/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertLess.test.js b/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertLess.test.js new file mode 100755 index 0000000000000000000000000000000000000000..5e404524cdc6b69d65a22a1884542757f4901ed8 --- /dev/null +++ b/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertLess.test.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 {describe, it, expect} from 'deccjsunit/index' + +describe('assertLess', function () { + it('assertLessSuccess', 0, function () { + let a = 12; + let b = 15; + expect(a).assertLess(b) + }) + it('assertLessFail', 0, function () { + let a = 12; + let b = 10; + expect(a).assertLess(b); + }) +}) \ No newline at end of file diff --git a/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertNull.test.js b/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertNull.test.js new file mode 100755 index 0000000000000000000000000000000000000000..0e774c6edbfe8a8c763bfbc2d6e9fa0f98f31ba7 --- /dev/null +++ b/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertNull.test.js @@ -0,0 +1,26 @@ +/* + * 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, it, expect} from 'deccjsunit/index' + +describe('assertNull', function () { + it('assertNullSuccess', 0, function () { + let d + expect(d).assertNull() + }) + it('assertNullFail', 0, function () { + let d = 100 + expect(d).assertNull() + }) +}) \ No newline at end of file diff --git a/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertThrowError.test.js b/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertThrowError.test.js new file mode 100755 index 0000000000000000000000000000000000000000..7aba149a470d80a8d340d8fc9f857008eff0bb4e --- /dev/null +++ b/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertThrowError.test.js @@ -0,0 +1,36 @@ +/* + * 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, it, expect} from 'deccjsunit/index' + +describe('assertThrowError', function () { + it('assertThrowErrorFail001', 0, function () { + let a = 12; + expect(a).assertThrowError() + }) + it('assertThrowErrorSuccess', 0, function () { + let a = test + function test() { + throw Error("exception") + } + expect(a).assertThrowError("exception"); + }) + it('assertThrowErrorFail002', 0, function () { + let a = test + function test() { + throw Error("exception") + } + expect(a).assertThrowError("test"); + }) +}) \ No newline at end of file diff --git a/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertUndefined.test.js b/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertUndefined.test.js new file mode 100755 index 0000000000000000000000000000000000000000..3c00a513c85eff8e8af56a366e1c2a8f86fa15c5 --- /dev/null +++ b/demo/hjsunit/Assertion/entry/src/ohosTest/js/test/assertUndefined.test.js @@ -0,0 +1,26 @@ +/* + * 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, it, expect} from 'deccjsunit/index' + +describe('assertUndefined', function () { + it('assertUndefinedSuccess', 0, function () { + let a = undefined + expect(a).assertUndefined() + }) + it('assertUndefinedFail', 0, function () { + let a = 100 + expect(a).assertUndefined() + }) +}) \ No newline at end of file diff --git a/demo/hjsunit/Async/README_zh.md b/demo/hjsunit/Async/README_zh.md new file mode 100755 index 0000000000000000000000000000000000000000..0bec3ed89f86af8a999afa357e3cc221971a064a --- /dev/null +++ b/demo/hjsunit/Async/README_zh.md @@ -0,0 +1,3 @@ +# Async + +- 异步,HJSUnit测试框架针对测试用例提供的异步能力。测试框架识别异步用例的关键字为async,用法如下:在回调函数function前加“async”关键字,调用异步接口时需加上“await”前缀;回调函数中添加“done”参数和用例结尾的加上“done()”,保证可以在执行该异步用例时强制获取到用例执行结果。 \ No newline at end of file diff --git a/demo/hjsunit/Async/entry/src/main/js/default/app.js b/demo/hjsunit/Async/entry/src/main/js/default/app.js new file mode 100755 index 0000000000000000000000000000000000000000..4b241cccbaa71f0c5cbd9e7dc437a0feb224c7d5 --- /dev/null +++ b/demo/hjsunit/Async/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/demo/hjsunit/Async/entry/src/main/js/default/pages/index/index.css b/demo/hjsunit/Async/entry/src/main/js/default/pages/index/index.css new file mode 100755 index 0000000000000000000000000000000000000000..2b1965821483f4f8c8b97c86ef07fe87ea767d01 --- /dev/null +++ b/demo/hjsunit/Async/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,44 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 40px; + color: #000000; + opacity: 0.9; +} + +@media screen and (device-type: tablet) and (orientation: landscape) { + .title { + font-size: 100px; + } +} + +@media screen and (device-type: wearable) { + .title { + font-size: 28px; + color: #FFFFFF; + } +} + +@media screen and (device-type: tv) { + .container { + background-image: url("../../common/images/Wallpaper.png"); + background-size: cover; + background-repeat: no-repeat; + background-position: center; + } + + .title { + font-size: 100px; + color: #FFFFFF; + } +} + +@media screen and (device-type: phone) and (orientation: landscape) { + .title { + font-size: 60px; + } +} diff --git a/demo/hjsunit/Async/entry/src/main/js/default/pages/index/index.hml b/demo/hjsunit/Async/entry/src/main/js/default/pages/index/index.hml new file mode 100755 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/demo/hjsunit/Async/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/demo/hjsunit/Async/entry/src/main/js/default/pages/index/index.js b/demo/hjsunit/Async/entry/src/main/js/default/pages/index/index.js new file mode 100755 index 0000000000000000000000000000000000000000..49eb46a053db5a2da9542526b61eed164fa44d26 --- /dev/null +++ b/demo/hjsunit/Async/entry/src/main/js/default/pages/index/index.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 { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + } +} diff --git a/demo/hjsunit/Async/entry/src/ohosTest/js/default/app.js b/demo/hjsunit/Async/entry/src/ohosTest/js/default/app.js new file mode 100755 index 0000000000000000000000000000000000000000..044bffa75e29d7a5fe32644e19cc1bbbc5e9a7b1 --- /dev/null +++ b/demo/hjsunit/Async/entry/src/ohosTest/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/demo/hjsunit/Async/entry/src/ohosTest/js/default/pages/index/index.css b/demo/hjsunit/Async/entry/src/ohosTest/js/default/pages/index/index.css new file mode 100755 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/demo/hjsunit/Async/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/demo/hjsunit/Async/entry/src/ohosTest/js/default/pages/index/index.hml b/demo/hjsunit/Async/entry/src/ohosTest/js/default/pages/index/index.hml new file mode 100755 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/demo/hjsunit/Async/entry/src/ohosTest/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/demo/hjsunit/Async/entry/src/ohosTest/js/default/pages/index/index.js b/demo/hjsunit/Async/entry/src/ohosTest/js/default/pages/index/index.js new file mode 100755 index 0000000000000000000000000000000000000000..793667c97f947fdfc22f424847e85718bad72c49 --- /dev/null +++ b/demo/hjsunit/Async/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, Constant, 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', + 'version': '1.0.3' + }) + 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/demo/hjsunit/Async/entry/src/ohosTest/js/test/Callback.test.js b/demo/hjsunit/Async/entry/src/ohosTest/js/test/Callback.test.js new file mode 100755 index 0000000000000000000000000000000000000000..6b95d985aa91a130b816932fb55ea7fbe8c9beed --- /dev/null +++ b/demo/hjsunit/Async/entry/src/ohosTest/js/test/Callback.test.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 {describe, it} from 'deccjsunit/index' + +describe('callback', function () { + it('callbackDemo', 0, async function (done) { + await a() + }) +}) + +function a(done){ + setTimeout(function(){ + console.log("run a after 1000ms") + },1000) + done() +} \ No newline at end of file diff --git a/demo/hjsunit/Async/entry/src/ohosTest/js/test/List.test.js b/demo/hjsunit/Async/entry/src/ohosTest/js/test/List.test.js new file mode 100755 index 0000000000000000000000000000000000000000..e397df520f9e3dac80fe8bf7498c68e6379de420 --- /dev/null +++ b/demo/hjsunit/Async/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('./Callback.test.js') +require('./Promise.test.js') \ No newline at end of file diff --git a/demo/hjsunit/Async/entry/src/ohosTest/js/test/Promise.test.js b/demo/hjsunit/Async/entry/src/ohosTest/js/test/Promise.test.js new file mode 100755 index 0000000000000000000000000000000000000000..785f3e87792b1fc7e40c90a41f3c90b4bbeb0739 --- /dev/null +++ b/demo/hjsunit/Async/entry/src/ohosTest/js/test/Promise.test.js @@ -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 {describe, it} from 'deccjsunit/index' + +describe('promise', function () { + it('promiseDemo', 0, async function (done) { + await new Promise( + function (resolve, reject) { + // 一段耗时的异步操作 + resolve('成功') // 数据处理完成 + // reject('失败') // 数据处理出错 + }).then( + (res) => {console.log(res)}, // 成功 + (err) => {console.log(err)} // 失败 + ) + done() + }) +}) \ No newline at end of file diff --git a/demo/hjsunit/DataDriver/README_zh.md b/demo/hjsunit/DataDriver/README_zh.md new file mode 100755 index 0000000000000000000000000000000000000000..0c3247bcde664ed2978666eca0f591f0b899b821 --- /dev/null +++ b/demo/hjsunit/DataDriver/README_zh.md @@ -0,0 +1,3 @@ +# DataDriver + +- DataDriver,HJSUnit测试框架提供的数据驱动能力。通过配置data.json文件,实现针对指定测试套、测试用例的参数传递,亦或是根据指定测试套、测试用例的执行次数做压力测试。 \ No newline at end of file diff --git a/demo/hjsunit/DataDriver/entry/src/main/js/default/app.js b/demo/hjsunit/DataDriver/entry/src/main/js/default/app.js new file mode 100755 index 0000000000000000000000000000000000000000..4b241cccbaa71f0c5cbd9e7dc437a0feb224c7d5 --- /dev/null +++ b/demo/hjsunit/DataDriver/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/demo/hjsunit/DataDriver/entry/src/main/js/default/pages/index/index.css b/demo/hjsunit/DataDriver/entry/src/main/js/default/pages/index/index.css new file mode 100755 index 0000000000000000000000000000000000000000..2b1965821483f4f8c8b97c86ef07fe87ea767d01 --- /dev/null +++ b/demo/hjsunit/DataDriver/entry/src/main/js/default/pages/index/index.css @@ -0,0 +1,44 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 40px; + color: #000000; + opacity: 0.9; +} + +@media screen and (device-type: tablet) and (orientation: landscape) { + .title { + font-size: 100px; + } +} + +@media screen and (device-type: wearable) { + .title { + font-size: 28px; + color: #FFFFFF; + } +} + +@media screen and (device-type: tv) { + .container { + background-image: url("../../common/images/Wallpaper.png"); + background-size: cover; + background-repeat: no-repeat; + background-position: center; + } + + .title { + font-size: 100px; + color: #FFFFFF; + } +} + +@media screen and (device-type: phone) and (orientation: landscape) { + .title { + font-size: 60px; + } +} diff --git a/demo/hjsunit/DataDriver/entry/src/main/js/default/pages/index/index.hml b/demo/hjsunit/DataDriver/entry/src/main/js/default/pages/index/index.hml new file mode 100755 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/demo/hjsunit/DataDriver/entry/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/demo/hjsunit/DataDriver/entry/src/main/js/default/pages/index/index.js b/demo/hjsunit/DataDriver/entry/src/main/js/default/pages/index/index.js new file mode 100755 index 0000000000000000000000000000000000000000..49eb46a053db5a2da9542526b61eed164fa44d26 --- /dev/null +++ b/demo/hjsunit/DataDriver/entry/src/main/js/default/pages/index/index.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 { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + } +} diff --git a/demo/hjsunit/DataDriver/entry/src/ohosTest/js/default/app.js b/demo/hjsunit/DataDriver/entry/src/ohosTest/js/default/app.js new file mode 100755 index 0000000000000000000000000000000000000000..044bffa75e29d7a5fe32644e19cc1bbbc5e9a7b1 --- /dev/null +++ b/demo/hjsunit/DataDriver/entry/src/ohosTest/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/demo/hjsunit/DataDriver/entry/src/ohosTest/js/default/pages/index/index.css b/demo/hjsunit/DataDriver/entry/src/ohosTest/js/default/pages/index/index.css new file mode 100755 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/demo/hjsunit/DataDriver/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/demo/hjsunit/DataDriver/entry/src/ohosTest/js/default/pages/index/index.hml b/demo/hjsunit/DataDriver/entry/src/ohosTest/js/default/pages/index/index.hml new file mode 100755 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/demo/hjsunit/DataDriver/entry/src/ohosTest/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/demo/hjsunit/DataDriver/entry/src/ohosTest/js/default/pages/index/index.js b/demo/hjsunit/DataDriver/entry/src/ohosTest/js/default/pages/index/index.js new file mode 100755 index 0000000000000000000000000000000000000000..4ada57fb31e4c492c605ec5a827878a01bc0cc10 --- /dev/null +++ b/demo/hjsunit/DataDriver/entry/src/ohosTest/js/default/pages/index/index.js @@ -0,0 +1,59 @@ +/* + * 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, Constant, DataDriver, ExpectExtend, ReportExtend, InstrumentLog} from 'deccjsunit/index' + +import data from '../../../test/data.json' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const dataDriver = new DataDriver({data:data}) + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + const reportExtend = new ReportExtend(file) + const instrumentLog = new InstrumentLog({ + 'id': 'report', + 'version': '1.0.3' + }) + core.addService('dataDriver',dataDriver) + 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/demo/hjsunit/DataDriver/entry/src/ohosTest/js/test/DataDriver.test.js b/demo/hjsunit/DataDriver/entry/src/ohosTest/js/test/DataDriver.test.js new file mode 100755 index 0000000000000000000000000000000000000000..a7c331fddc5bfc901302a63e93b7fc3ea1d4b67e --- /dev/null +++ b/demo/hjsunit/DataDriver/entry/src/ohosTest/js/test/DataDriver.test.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 {describe, it, expect} from 'deccjsunit/index' + +describe('testSuite01', function () { + it('testSpec01', function (data) { + console.info('testSpec01......' + JSON.stringify(data)) + }) + it('testSpec02', function (data) { + console.info('testSpec02......' + JSON.stringify(data)) + }) +}) \ No newline at end of file diff --git a/demo/hjsunit/DataDriver/entry/src/ohosTest/js/test/List.test.js b/demo/hjsunit/DataDriver/entry/src/ohosTest/js/test/List.test.js new file mode 100755 index 0000000000000000000000000000000000000000..ee629d2674217d3e6f2beb14661afe07ce140ce4 --- /dev/null +++ b/demo/hjsunit/DataDriver/entry/src/ohosTest/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('./DataDriver.test.js') \ No newline at end of file diff --git a/demo/hjsunit/DataDriver/entry/src/ohosTest/js/test/data.json b/demo/hjsunit/DataDriver/entry/src/ohosTest/js/test/data.json new file mode 100755 index 0000000000000000000000000000000000000000..ab74ea0df4d7110e83deccf744fd07bcaccbe350 --- /dev/null +++ b/demo/hjsunit/DataDriver/entry/src/ohosTest/js/test/data.json @@ -0,0 +1,26 @@ +{ + "suites": [{ + "describe":["testSuite01"], + "params":{ + "suiteParam01": "suiteParam" + } + },{ + "describe":["testSuite01","testSpec02"], + "params":{ + "suiteParam": "suiteParam" + } + },{ + "describe":"testSuite01", + "stress": 8, + "items":[{ + "it":"testSpec01", + "stress": 1, + "params":[{ + "name":"tom" + }] + },{ + "it":"testSpec02", + "stress": 2 + }] + }] +} \ No newline at end of file diff --git a/demo/hjsunit/README.md b/demo/hjsunit/README.md new file mode 100755 index 0000000000000000000000000000000000000000..0cde70f22bf5b9a2be51b524a963b16d05979f1e --- /dev/null +++ b/demo/hjsunit/README.md @@ -0,0 +1,19 @@ +# App Samples + +- [Introduction](#section_HJSUnit_001) +- [Usage](#section_HJSUnit_002) +- [Limitations](#section_HJSUnit_003) + +## Introduction + +We provide a series of app samples to help you quickly get familiar with the test capabilities and how to use of the HJSUnit. Each app sample is an independent project in DevEco Studio. You can import sample code from a project to a customized project to learn how to use APIs by browsing code, building the project, and installing and running the app. + +## Usage + +1. Development tool: Devco Studio 2.2.0.200 or later +2. Procedure: Create a blank JS template project in Devco Studio, import the sample code in the ohosTest directory of the sample project to the ohosTest directory of the user-defined project, and compile, build, run, and debug the project. +3. After HAP installation and execution, you can view the execution effect of the sample on the device and then conduct debugging. + +## Limitations + +Before installing and running the sample, check the **deviceType** field in the **config.json** file to obtain the device types supported by the sample. You can modify this field to enable the sample to run on your target device. \(The **config.json** file is generally stored in the **entry/src/main** directory, which may be different depending on the samples.\) \ No newline at end of file diff --git a/demo/hjsunit/README_zh.md b/demo/hjsunit/README_zh.md new file mode 100755 index 0000000000000000000000000000000000000000..0b1b7d7188babfd7728e4f456fc75a67e4aa44ff --- /dev/null +++ b/demo/hjsunit/README_zh.md @@ -0,0 +1,19 @@ +# 应用示例 + +- [概要简介](#section_HJSUnit_001) +- [使用说明](#section_HJSUnit_002) +- [约束与限制](#section_HJSUnit_003) + +## 概要简介 + +为帮助测试人员快速熟悉HJSUnit所提供的测试能力和如何使用,我们提供了一系列的应用示例,即Sample。每一个应用示例都是一个独立的DevEco Studio工程项目,测试人员可以将工程中的代码导入到自定义工程中,通过浏览代码、编译工程、安装和运行应用示例来了解应用示例中涉及测试能力的使用方法。 + +## 使用说明 + +1. 开发工具:2.2.0.200版本及以上的Deveco Studio +2. 使用步骤:①在Deveco Studio中新建空白JS模板项目,将示例工程ohosTest目录下的示例代码导入到自定义工程的ohosTest目录下,进行编译构建及运行调试。 +3. 安装运行后,即可在设备上查看应用示例运行效果,以及进行相关调试。 + +## 约束与限制 + +安装运行应用示例之前,请先通过config.json文件中的"deviceType"字段来确认该应用示例支持的设备类型,可尝试通过修改该字段使其可以在相应类型的设备上运行(config.json文件一般在代码的entry/src/main路径下,不同的Sample可能会有不同)。 \ No newline at end of file diff --git a/distributeddatamgr/distributedfilejstest/hap/entry-debug-rich-signed.hap b/distributeddatamgr/distributedfilejstest/hap/entry-debug-rich-signed.hap index 6b577198f7e4025425dfa6c7af34434a3956cda2..1e7e627b2611ff03c28822e681f9b715070f7a69 100644 Binary files a/distributeddatamgr/distributedfilejstest/hap/entry-debug-rich-signed.hap and b/distributeddatamgr/distributedfilejstest/hap/entry-debug-rich-signed.hap differ 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 index 81c6cd659a51b98db09edf521143d3f270d9b58e..13212a963a385b5897729d3f409ded96805f2b22 100755 --- a/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIO.test.js +++ b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIO.test.js @@ -561,7 +561,7 @@ describe('fileIOTest', function () { try { expect(fileio.chmodSync(fpath, 0o660)).assertNull() - expect(fileio.Stat.statSync(fpath).mode & 0o777).assertEqual(0o660) + expect(fileio.statSync(fpath).mode & 0o777).assertEqual(0o660) expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { console.log("fileio_test_chmod_sync_000 has failed for " + e) @@ -661,7 +661,7 @@ describe('fileIOTest', function () { try { expect(fileio.truncateSync(fpath)).assertNull() - expect(fileio.Stat.statSync(fpath).size).assertEqual(0) + expect(fileio.statSync(fpath).size).assertEqual(0) expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { console.log("fileio_test_truncate_sync_000 has failed for " + e) @@ -761,7 +761,7 @@ describe('fileIOTest', function () { try { let fd = fileio.openSync(fpath, 0o2) expect(fileio.fchmodSync(fd, 0o660)).assertNull() - expect(fileio.Stat.statSync(fpath).mode & 0o777).assertEqual(0o660) + expect(fileio.statSync(fpath).mode & 0o777).assertEqual(0o660) expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { console.log("fileio_test_fchmod_sync_000 has failed for " + e) @@ -794,7 +794,7 @@ describe('fileIOTest', function () { try { let fd = fileio.openSync(fpath, 0o2) expect(fileio.ftruncateSync(fd)).assertNull() - expect(fileio.Stat.statSync(fpath).size).assertEqual(0) + expect(fileio.statSync(fpath).size).assertEqual(0) expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { console.log("fileio_test_ftruncate_sync_000 has failed for " + e) 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 index 08b8079b6fd223a8fab7c8181b70c37d9cc98fd6..01bd141ddf068efa4532c2ccd3270dbb8ba9bbc9 100755 --- a/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIODir.test.js +++ b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIODir.test.js @@ -29,7 +29,7 @@ describe('fileIOTestDir', function () { try { expect(fileio.mkdirSync(dpath)).assertNull() - let dd = fileio.Dir.opendirSync(dpath) + let dd = fileio.opendirSync(dpath) expect(dd !== null).assertTrue() expect(dd.closeSync()).assertNull() expect(fileio.rmdirSync(dpath)).assertNull() @@ -46,7 +46,7 @@ describe('fileIOTestDir', function () { */ it('fileio_test_dir_open_close_sync_001', 0, function () { try { - fileio.Dir.opendirSync() + fileio.opendirSync() expect(null).assertFail() } catch (e) { } @@ -61,7 +61,7 @@ describe('fileIOTestDir', function () { let dpath = nextFileName('fileio_test_dir_read_sync_000') + 'd' try { - fileio.Dir.opendirSync(dpath) + fileio.opendirSync(dpath) expect(null).assertFail() } catch (e) { } @@ -79,7 +79,7 @@ describe('fileIOTestDir', function () { try { expect(fileio.mkdirSync(dpath)).assertNull() expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let dd = fileio.Dir.opendirSync(dpath) + let dd = fileio.opendirSync(dpath) expect(dd !== null).assertTrue() expect(dd.readSync() != null).assertTrue() expect(dd.closeSync()).assertNull() @@ -105,7 +105,7 @@ describe('fileIOTestDir', function () { try { expect(fileio.mkdirSync(dpath)).assertNull() expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - dd = fileio.Dir.opendirSync(dpath) + dd = fileio.opendirSync(dpath) expect(dd !== null).assertTrue() expect(dd.readSync(-1) != null).assertTrue() expect(null).assertFail() 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 index 349cce9e3c074241182c77aab98b2d796d8ecc8e..22b5a810a582b32b623f3e9688db736297eb8deb 100755 --- a/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIODirent.test.js +++ b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIODirent.test.js @@ -31,7 +31,7 @@ describe('fileIOTestDirent', function () { try { expect(fileio.mkdirSync(dpath)).assertNull() expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let dd = fileio.Dir.opendirSync(dpath) + let dd = fileio.opendirSync(dpath) expect(dd !== null).assertTrue() let dirent = dd.readSync() expect(dirent !== null).assertTrue() @@ -57,7 +57,7 @@ describe('fileIOTestDirent', function () { try { expect(fileio.mkdirSync(dpath)).assertNull() expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let dd = fileio.Dir.opendirSync(dpath) + let dd = fileio.opendirSync(dpath) expect(dd !== null).assertTrue() let dirent = dd.readSync() expect(dirent !== null).assertTrue() @@ -84,7 +84,7 @@ describe('fileIOTestDirent', function () { try { expect(fileio.mkdirSync(dpath)).assertNull() expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - dd = fileio.Dir.opendirSync(dpath) + dd = fileio.opendirSync(dpath) expect(dd !== null).assertTrue() let dirent = dd.readSync() expect(dirent !== null).assertTrue() @@ -109,7 +109,7 @@ describe('fileIOTestDirent', function () { try { expect(fileio.mkdirSync(dpath)).assertNull() expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let dd = fileio.Dir.opendirSync(dpath) + let dd = fileio.opendirSync(dpath) expect(dd !== null).assertTrue() let dirent = dd.readSync() expect(dirent !== null).assertTrue() @@ -136,7 +136,7 @@ describe('fileIOTestDirent', function () { try { expect(fileio.mkdirSync(dpath)).assertNull() expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - dd = fileio.Dir.opendirSync(dpath) + dd = fileio.opendirSync(dpath) expect(dd !== null).assertTrue() let dirent = dd.readSync() expect(dirent !== null).assertTrue() @@ -161,7 +161,7 @@ describe('fileIOTestDirent', function () { try { expect(fileio.mkdirSync(dpath)).assertNull() expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let dd = fileio.Dir.opendirSync(dpath) + let dd = fileio.opendirSync(dpath) expect(dd !== null).assertTrue() let dirent = dd.readSync() expect(dirent !== null).assertTrue() @@ -188,7 +188,7 @@ describe('fileIOTestDirent', function () { try { expect(fileio.mkdirSync(dpath)).assertNull() expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - dd = fileio.Dir.opendirSync(dpath) + dd = fileio.opendirSync(dpath) expect(dd !== null).assertTrue() let dirent = dd.readSync() expect(dirent !== null).assertTrue() @@ -213,7 +213,7 @@ describe('fileIOTestDirent', function () { try { expect(fileio.mkdirSync(dpath)).assertNull() expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let dd = fileio.Dir.opendirSync(dpath) + let dd = fileio.opendirSync(dpath) expect(dd !== null).assertTrue() let dirent = dd.readSync() expect(dirent !== null).assertTrue() @@ -240,7 +240,7 @@ describe('fileIOTestDirent', function () { try { expect(fileio.mkdirSync(dpath)).assertNull() expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - dd = fileio.Dir.opendirSync(dpath) + dd = fileio.opendirSync(dpath) expect(dd !== null).assertTrue() let dirent = dd.readSync() expect(dirent !== null).assertTrue() @@ -265,7 +265,7 @@ describe('fileIOTestDirent', function () { try { expect(fileio.mkdirSync(dpath)).assertNull() expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let dd = fileio.Dir.opendirSync(dpath) + let dd = fileio.opendirSync(dpath) expect(dd !== null).assertTrue() let dirent = dd.readSync() expect(dirent !== null).assertTrue() @@ -292,7 +292,7 @@ describe('fileIOTestDirent', function () { try { expect(fileio.mkdirSync(dpath)).assertNull() expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - dd = fileio.Dir.opendirSync(dpath) + dd = fileio.opendirSync(dpath) expect(dd !== null).assertTrue() let dirent = dd.readSync() expect(dirent !== null).assertTrue() @@ -317,7 +317,7 @@ describe('fileIOTestDirent', function () { try { expect(fileio.mkdirSync(dpath)).assertNull() expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let dd = fileio.Dir.opendirSync(dpath) + let dd = fileio.opendirSync(dpath) expect(dd !== null).assertTrue() let dirent = dd.readSync() expect(dirent !== null).assertTrue() @@ -344,7 +344,7 @@ describe('fileIOTestDirent', function () { try { expect(fileio.mkdirSync(dpath)).assertNull() expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - dd = fileio.Dir.opendirSync(dpath) + dd = fileio.opendirSync(dpath) expect(dd !== null).assertTrue() let dirent = dd.readSync() expect(dirent !== null).assertTrue() @@ -369,7 +369,7 @@ describe('fileIOTestDirent', function () { try { expect(fileio.mkdirSync(dpath)).assertNull() expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - let dd = fileio.Dir.opendirSync(dpath) + let dd = fileio.opendirSync(dpath) expect(dd !== null).assertTrue() let dirent = dd.readSync() expect(dirent !== null).assertTrue() @@ -396,7 +396,7 @@ describe('fileIOTestDirent', function () { try { expect(fileio.mkdirSync(dpath)).assertNull() expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() - dd = fileio.Dir.opendirSync(dpath) + dd = fileio.opendirSync(dpath) expect(dd !== null).assertTrue() let dirent = dd.readSync() expect(dirent !== null).assertTrue() 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 index 4dd67607d2e89ebacf9de96369e8c2528fb24c52..a4331db908369f9de8526c4c13218b9d6ec83cfd 100755 --- a/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIOStat.test.js +++ b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIOStat.test.js @@ -65,7 +65,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat !== null).assertTrue() expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -83,7 +83,7 @@ describe('fileIOTestStat', function () { let fpath = nextFileName('fileio_test_stat_stat_sync_001') try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(null).assertFail() } catch (e) { } @@ -99,7 +99,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.dev).assertInstanceOf('Number') expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -118,7 +118,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.ino).assertInstanceOf('Number') expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -137,7 +137,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.mode).assertInstanceOf('Number') expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -156,7 +156,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.nlink).assertInstanceOf('Number') expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -175,7 +175,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.uid).assertInstanceOf('Number') expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -194,7 +194,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.gid).assertInstanceOf('Number') expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -213,7 +213,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.rdev).assertInstanceOf('Number') expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -232,7 +232,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.size).assertInstanceOf('Number') expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -251,7 +251,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.blocks).assertInstanceOf('Number') expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -270,7 +270,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.atime).assertInstanceOf('Number') expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -289,7 +289,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.mtime).assertInstanceOf('Number') expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -308,7 +308,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.ctime).assertInstanceOf('Number') expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -327,7 +327,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.isBlockDevice()).assertInstanceOf('Boolean') expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -346,7 +346,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.isBlockDevice()).assertFalse() expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -365,7 +365,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.isBlockDevice(-1)).assertFalse() expect(null).assertFail() } catch (e) { @@ -383,7 +383,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.isCharacterDevice()).assertInstanceOf('Boolean') expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -402,7 +402,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.isCharacterDevice()).assertFalse() expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -421,7 +421,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.isCharacterDevice(-1)).assertFalse() expect(null).assertFail() } catch (e) { @@ -439,7 +439,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.isDirectory()).assertInstanceOf('Boolean') expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -458,7 +458,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.isDirectory()).assertFalse() expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -477,7 +477,7 @@ describe('fileIOTestStat', function () { try { expect(fileio.mkdirSync(dpath)).assertNull() - let stat = fileio.Stat.statSync(dpath) + let stat = fileio.statSync(dpath) expect(stat.isDirectory()).assertTrue() expect(fileio.rmdirSync(dpath)).assertNull() } catch (e) { @@ -496,7 +496,7 @@ describe('fileIOTestStat', function () { try { expect(fileio.mkdirSync(dpath)).assertNull() - let stat = fileio.Stat.statSync(dpath) + let stat = fileio.statSync(dpath) expect(stat.isDirectory(-1)).assertTrue() expect(null).assertFail() } catch (e) { @@ -514,7 +514,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.isFIFO()).assertInstanceOf('Boolean') expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -533,7 +533,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.isFIFO()).assertFalse() expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -552,7 +552,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.isFIFO(-1)).assertFalse() expect(null).assertFail() } catch (e) { @@ -570,7 +570,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertInstanceOf('Boolean') try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.isFile()).assertInstanceOf('Boolean') expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -589,7 +589,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertInstanceOf('Boolean') try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.isFile()).assertTrue() expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -608,7 +608,7 @@ describe('fileIOTestStat', function () { try { expect(fileio.mkdirSync(dpath)).assertNull() - let stat = fileio.Stat.statSync(dpath) + let stat = fileio.statSync(dpath) expect(stat.isFile()).assertFalse() expect(fileio.rmdirSync(dpath)).assertNull() } catch (e) { @@ -627,7 +627,7 @@ describe('fileIOTestStat', function () { try { expect(fileio.mkdirSync(dpath)).assertNull() - let stat = fileio.Stat.statSync(dpath) + let stat = fileio.statSync(dpath) expect(stat.isFile(-1)).assertFalse() expect(null).assertFail() } catch (e) { @@ -645,7 +645,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.isSocket()).assertInstanceOf('Boolean') expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -664,7 +664,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.isSocket()).assertFalse() expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -683,7 +683,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.isSocket(-1)).assertFalse() expect(null).assertFail() } catch (e) { @@ -701,7 +701,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.isSymbolicLink()).assertInstanceOf('Boolean') expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -720,7 +720,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.isSymbolicLink()).assertFalse() expect(fileio.unlinkSync(fpath)).assertNull() } catch (e) { @@ -739,7 +739,7 @@ describe('fileIOTestStat', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let stat = fileio.Stat.statSync(fpath) + let stat = fileio.statSync(fpath) expect(stat.isSymbolicLink(-1)).assertFalse() expect(null).assertFail() } catch (e) { 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 index 174614de1c3e4bb26eb6cb8063e9d06253f48e50..0c7f598e2a1dece71e28259f17cbf827242296ab 100755 --- a/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIOStream.test.js +++ b/distributeddatamgr/distributedfilejstest/project/entry/src/main/js/test/FileIOStream.test.js @@ -29,7 +29,7 @@ describe('fileIOTestStream', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - var ss = fileio.Stream.createStreamSync(fpath, "r+") + var ss = fileio.createStreamSync(fpath, "r+") expect(ss !== null).assertTrue() expect(ss.closeSync()).assertNull() expect(fileio.unlinkSync(fpath)).assertNull() @@ -48,7 +48,7 @@ describe('fileIOTestStream', function () { let fpath = nextFileName('fileio_test_stream_create_stream_sync_001') try { - fileio.Stream.createStreamSync(fpath, "r+") + fileio.createStreamSync(fpath, "r+") expect(null).assertFail() } catch (e) { } @@ -64,7 +64,7 @@ describe('fileIOTestStream', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - fileio.Stream.createStreamSync(fpath, "ohos") + fileio.createStreamSync(fpath, "ohos") expect(null).assertFail() } catch (e) { expect(fileio.unlinkSync(fpath)).assertNull() @@ -82,7 +82,7 @@ describe('fileIOTestStream', function () { try { var fd = fileio.openSync(fpath, 0o2) - let ss = fileio.Stream.fdopenStreamSync(fd, "r+") + let ss = fileio.fdopenStreamSync(fd, "r+") expect(ss !== null).assertTrue() expect(ss.closeSync()).assertNull() expect(fileio.unlinkSync(fpath)).assertNull() @@ -99,7 +99,7 @@ describe('fileIOTestStream', function () { */ it('fileio_test_stream_fdopen_stream_sync_001', 0, function () { try { - let ss = fileio.Stream.fdopenStreamSync(-1, "r+") + let ss = fileio.fdopenStreamSync(-1, "r+") expect(null).assertFail() } catch (e) { } @@ -115,7 +115,7 @@ describe('fileIOTestStream', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let ss = fileio.Stream.createStreamSync(fpath, "r+") + let ss = fileio.createStreamSync(fpath, "r+") expect(ss !== null).assertTrue() let len = ss.readSync(new ArrayBuffer(4096)) expect(len).assertEqual(FILE_CONTENT.length) @@ -137,7 +137,7 @@ describe('fileIOTestStream', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let ss = fileio.Stream.createStreamSync(fpath, "r+") + let ss = fileio.createStreamSync(fpath, "r+") expect(ss !== null).assertTrue() expect(ss.writeSync(FILE_CONTENT)).assertEqual(FILE_CONTENT.length) expect(ss.closeSync()).assertNull() @@ -158,7 +158,7 @@ describe('fileIOTestStream', function () { expect(prepareFile(fpath, FILE_CONTENT)).assertTrue() try { - let ss = fileio.Stream.createStreamSync(fpath, "r+") + let ss = fileio.createStreamSync(fpath, "r+") expect(ss !== null).assertTrue() expect(ss.writeSync(FILE_CONTENT)).assertEqual(FILE_CONTENT.length) expect(ss.flushSync()).assertNull() diff --git a/global_lite/i18n_lite/BUILD.gn b/global_lite/i18n_lite/BUILD.gn index bca233ceea109d54c8386823163f1f74318ff90c..6015fbfa646555920827ff56cdd8d96c4cea744a 100755 --- a/global_lite/i18n_lite/BUILD.gn +++ b/global_lite/i18n_lite/BUILD.gn @@ -17,5 +17,9 @@ group("ActsGlobalTest") { "//test/xts/acts/global_lite/i18n_lite/numberrecall_posix:ActsNumberRecallTest", "//test/xts/acts/global_lite/i18n_lite/datetime_posix:ActsGlobalDateTimeTest", "//test/xts/acts/global_lite/i18n_lite/datetimerecall_posix:ActsGlobalDateTimeRecallTest", + "//test/xts/acts/global_lite/i18n_lite/week_plural_number/src:WeekPluralNumbertest", + + # depend on the resources + #"//test/xts/acts/global_lite/i18n_lite/resource_parse_load/src:ResourceParseLoadtest", ] } diff --git a/global_lite/i18n_lite/resource_parse_load/src/BUILD.gn b/global_lite/i18n_lite/resource_parse_load/src/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..023207d6014b4d80b8979ba361d41316ce190458 --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/BUILD.gn @@ -0,0 +1,43 @@ +# 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/lite/build/suite_lite.gni") + +hcpptest_suite("ResourceParseLoadtest") { + suite_name = "acts" + sources = [ + "global_test.cpp", + "hap_manager_test.cpp", + "hap_parser_test.cpp", + "hap_resource_test.cpp", + "locale_info_test.cpp", + "res_config_impl_test.cpp", + "res_config_test.cpp", + "res_desc_test.cpp", + "resource_manager_performance_test.cpp", + "resource_manager_test.cpp", + "string_utils_test.cpp", + "test_common.cpp", + ] + + include_dirs = [ + "//base/global/i18n_lite/interfaces/kits/i18n/include", + "//base/global/resmgr_lite/frameworks/resmgr_lite/include", + "//base/global/resmgr_lite/interfaces/innerkits/include", + ] + + deps = [ + "//base/global/resmgr_lite/frameworks/resmgr_lite:global_resmgr", + #"//third_party/bounds_checking_function:libsec_shared", + ] +} diff --git a/global_lite/i18n_lite/resource_parse_load/src/Test.json b/global_lite/i18n_lite/resource_parse_load/src/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..3181ef0a455daed10f3ce8faba8c15d193215fd3 --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/Test.json @@ -0,0 +1,21 @@ +{ + "kits": [ + { + "push": [ + "ResourceParseLoadtest->/data/local/tmp/ResourceParseLoadtest" + ], + "type": "PushKit", + "post-push": [ + "chmod -R 777 /data/local/tmp/*" + ] + } + ], + "driver": { + "native-test-timeout": "120000", + "type": "CppTest", + "module-name": "ResourceParseLoadtest", + "runtime-hint": "1s", + "native-test-device-path": "/data/local/tmp" + }, + "description": "ResourceParseLoadtest Tests" +} \ No newline at end of file diff --git a/global_lite/i18n_lite/resource_parse_load/src/global_test.cpp b/global_lite/i18n_lite/resource_parse_load/src/global_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..4fd22a9554297abbd66ea1b5b3ea7405a2e75510 --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/global_test.cpp @@ -0,0 +1,158 @@ +/* + * 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 "global_test.h" + +#include + +#include "test_common.h" +#include "utils/errors.h" +#include "utils/string_utils.h" + +#define private public + +#include "global.h" + +using namespace OHOS::Global::Resource; +using namespace testing::ext; + +class GlobalTest : public testing::Test { +public: + static void SetUpTestCase(void); + + static void TearDownTestCase(void); + + void SetUp(); + + void TearDown(); +}; + +void GlobalTest::SetUpTestCase(void) +{ + // step 1: input testsuit setup step + g_logLevel = LOG_DEBUG; +} + +void GlobalTest::TearDownTestCase() +{ + // step 2: input testsuit teardown step +} + +void GlobalTest::SetUp() +{ + // step 3: input testcase setup step +} + +void GlobalTest::TearDown() +{ + // step 4: input testcase teardown step +} + +int GetResId(const std::string &name, ResType resType) +{ + auto rc = new ResConfigImpl; + rc->SetLocaleInfo("en", nullptr, "US"); + std::string resPath = FormatFullPath(g_resFilePath); + const char *path = resPath.c_str(); + + const HapResource *pResource = HapResource::LoadFromIndex(path, rc); + + int ret = pResource->GetIdByName(name.c_str(), resType); + delete pResource; + delete rc; + return ret; +} + +/* + * @tc.name: GlobalFuncTest001 + * @tc.desc: Test GLOBAL_ConfigLanguage function, file case. + * @tc.type: FUNC + */ +HWTEST_F(GlobalTest, GlobalFuncTest001, TestSize.Level1) +{ + char lan[10]; + char region[10]; + + GLOBAL_ConfigLanguage("en-Latn-US"); + int32_t ret = GLOBAL_GetLanguage(lan, 10); + ASSERT_EQ(OK, ret); + ASSERT_EQ(std::string("en"), lan); + ret = GLOBAL_GetRegion(region, 10); + ASSERT_EQ(OK, ret); + ASSERT_EQ(std::string("US"), region); + + GLOBAL_ConfigLanguage("en_Latn_US"); + ret = GLOBAL_GetLanguage(lan, 10); + ASSERT_EQ(OK, ret); + ASSERT_EQ(std::string("en"), lan); + ret = GLOBAL_GetRegion(region, 10); + ASSERT_EQ(OK, ret); + ASSERT_EQ(std::string("US"), region); + + GLOBAL_ConfigLanguage("en-US"); + ret = GLOBAL_GetLanguage(lan, 10); + ASSERT_EQ(OK, ret); + ASSERT_EQ(std::string("en"), lan); + ret = GLOBAL_GetRegion(region, 10); + ASSERT_EQ(OK, ret); + ASSERT_EQ(std::string("US"), region); + + GLOBAL_ConfigLanguage("en_US"); + ret = GLOBAL_GetLanguage(lan, 10); + ASSERT_EQ(OK, ret); + ASSERT_EQ(std::string("en"), lan); + ret = GLOBAL_GetRegion(region, 10); + ASSERT_EQ(OK, ret); + ASSERT_EQ(std::string("US"), region); + + GLOBAL_ConfigLanguage("en"); + ret = GLOBAL_GetLanguage(lan, 10); + ASSERT_EQ(OK, ret); + ASSERT_EQ(std::string("en"), lan); +} + +/* + * @tc.name: GlobalFuncTest002 + * @tc.desc: Test GLOBAL_GetValueByName function, file case. + * @tc.type: FUNC + */ +HWTEST_F(GlobalTest, GlobalFuncTest002, TestSize.Level1) +{ + GLOBAL_ConfigLanguage("en_Latn_US"); + char *values = nullptr; + int32_t ret = GLOBAL_GetValueByName("app_name", FormatFullPath(g_resFilePath).c_str(), &values); + // when ret != OK , values has been freed. + ASSERT_EQ(OK, ret); + EXPECT_EQ(std::string("App Name"), values); + free(values); +} + +/* + * @tc.name: GlobalFuncTest003 + * @tc.desc: Test GLOBAL_GetValueById function, file case. + * @tc.type: FUNC + */ +HWTEST_F(GlobalTest, GlobalFuncTest003, TestSize.Level1) +{ + GLOBAL_ConfigLanguage("en_Latn_US"); + char *values = nullptr; + int id = GetResId("app_name", ResType::STRING); + ASSERT_TRUE(id > 0); + int32_t ret = GLOBAL_GetValueById(static_cast(id), FormatFullPath(g_resFilePath).c_str(), &values); + // when ret != OK , values has been freed. + ASSERT_EQ(OK, ret); + EXPECT_EQ(std::string("App Name"), values); + free(values); +} diff --git a/global_lite/i18n_lite/resource_parse_load/src/global_test.h b/global_lite/i18n_lite/resource_parse_load/src/global_test.h new file mode 100755 index 0000000000000000000000000000000000000000..c5196fe30a555b64f2d9c4da756d7e2564a6f369 --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/global_test.h @@ -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. + */ + +#ifndef RESOURCE_MANAGER_GLOBAL_TEST_H +#define RESOURCE_MANAGER_GLOBAL_TEST_H + +int GlobalFuncTest001(); +int GlobalFuncTest002(); +int GlobalFuncTest003(); + +#endif diff --git a/global_lite/i18n_lite/resource_parse_load/src/hap_manager_test.cpp b/global_lite/i18n_lite/resource_parse_load/src/hap_manager_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..1dd131114d9733a46bc3dd9483218b568c27548b --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/hap_manager_test.cpp @@ -0,0 +1,154 @@ +/* + * 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 "hap_manager_test.h" + +#include + +#include "test_common.h" +#include "utils/string_utils.h" + +#define private public + +#include "hap_manager.h" + +using namespace OHOS::Global::Resource; +using namespace testing::ext; + +class HapManagerTest : public testing::Test { +public: + static void SetUpTestCase(void); + + static void TearDownTestCase(void); + + void SetUp(); + + void TearDown(); +}; + +void HapManagerTest::SetUpTestCase(void) +{ + // step 1: input testsuit setup step + g_logLevel = LOG_DEBUG; +} + +void HapManagerTest::TearDownTestCase() +{ + // step 2: input testsuit teardown step +} + +void HapManagerTest::SetUp() +{ + // step 3: input testcase setup step + HILOG_DEBUG("HapManagerTest setup"); +} + +void HapManagerTest::TearDown() +{ + // step 4: input testcase teardown step + HILOG_DEBUG("HapManagerTest teardown"); +} + +/* + * this test shows how to load a hap, then find value list by id + * @tc.name: HapManagerFuncTest001 + * @tc.desc: Test AddResourcePath & GetResourceList function, file case. + * @tc.type: FUNC + */ +HWTEST_F(HapManagerTest, HapManagerFuncTest001, TestSize.Level1) +{ + HapManager *hapManager = new HapManager(new ResConfigImpl); + bool ret = hapManager->AddResourcePath(FormatFullPath(g_resFilePath).c_str()); + + EXPECT_TRUE(ret); + + int id = 16777217; + const HapResource::IdValues *idValues = hapManager->GetResourceList(id); + if (idValues == nullptr) { + delete hapManager; + EXPECT_TRUE(false); + return; + } + + PrintIdValues(idValues); + delete hapManager; +} + +/* + * this test shows how to reload a hap + * @tc.name: HapManagerFuncTest002 + * @tc.desc: Test UpdateResConfig & AddResourcePath function, file case. + * @tc.type: FUNC + */ +HWTEST_F(HapManagerTest, HapManagerFuncTest002, TestSize.Level1) +{ + ResConfig *rc = CreateResConfig(); + if (rc == nullptr) { + EXPECT_TRUE(false); + return; + } + rc->SetLocaleInfo("en", nullptr, "US"); + std::string resPath = FormatFullPath(g_resFilePath); + const char *path = resPath.c_str(); + HapManager *hapManager = new HapManager(new ResConfigImpl); + if (hapManager == nullptr) { + delete (rc); + EXPECT_TRUE(false); + return; + } + hapManager->UpdateResConfig(*rc); + bool ret = hapManager->AddResourcePath(path); + + EXPECT_TRUE(ret); + + int id = 16777228; + const HapResource::IdValues *idValues = hapManager->GetResourceList(id); + if (idValues == nullptr) { + delete (hapManager); + delete (rc); + EXPECT_TRUE(false); + return; + } + + EXPECT_EQ(static_cast(1), idValues->GetLimitPathsConst().size()); + PrintIdValues(idValues); + + // reload + + ResConfig* rc2 = CreateResConfig(); + if (rc2 == nullptr) { + delete (hapManager); + delete (rc); + EXPECT_TRUE(false); + return; + } + + rc2->SetLocaleInfo("zh", nullptr, "CN"); + hapManager->UpdateResConfig(*rc2); + do { + idValues = hapManager->GetResourceList(id); + if (idValues == nullptr) { + EXPECT_TRUE(false); + break; + } + + EXPECT_EQ(static_cast(2), idValues->GetLimitPathsConst().size()); + + PrintIdValues(idValues); + } while (false); + delete (hapManager); + delete (rc2); + delete (rc); +} \ No newline at end of file diff --git a/global_lite/i18n_lite/resource_parse_load/src/hap_manager_test.h b/global_lite/i18n_lite/resource_parse_load/src/hap_manager_test.h new file mode 100755 index 0000000000000000000000000000000000000000..93b053760fb97a05080967ad338f81f3c9e1dad9 --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/hap_manager_test.h @@ -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. + */ + +#ifndef RESOURCE_MANAGER_HAP_MANAGER_TEST_H +#define RESOURCE_MANAGER_HAP_MANAGER_TEST_H + +int HapManagerFuncTest001(); +int HapManagerFuncTest002(); + +#endif diff --git a/global_lite/i18n_lite/resource_parse_load/src/hap_parser_test.cpp b/global_lite/i18n_lite/resource_parse_load/src/hap_parser_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..13decd68f7e1157c7e796a0dafabb203fb9b5329 --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/hap_parser_test.cpp @@ -0,0 +1,183 @@ +/* + * 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 "hap_parser_test.h" + +#include + +#include "test_common.h" +#include "utils/string_utils.h" + +#define private public + +#include "hap_parser.h" + +using namespace OHOS::Global::Resource; +using namespace testing::ext; + +class HapParserTest : public testing::Test { +public: + static void SetUpTestCase(void); + + static void TearDownTestCase(void); + + void SetUp(); + + void TearDown(); +}; + +void HapParserTest::SetUpTestCase(void) +{ + // step 1: input testsuit setup step + g_logLevel = LOG_DEBUG; +} + +void HapParserTest::TearDownTestCase() +{ + // step 2: input testsuit teardown step +} + +void HapParserTest::SetUp() +{ + // step 3: input testcase setup step +} + +void HapParserTest::TearDown() +{ + // step 4: input testcase teardown step +} + +/* + * @tc.name: HapParserFuncTest001 + * @tc.desc: Test CreateResConfigFromKeyParams + * @tc.type: FUNC + */ +HWTEST_F(HapParserTest, HapParserFuncTest001, TestSize.Level1) +{ + std::vector keyParams; + auto kp = new KeyParam(); + kp->type_ = LANGUAGES; + kp->value_ = 31336; + kp->InitStr(); + keyParams.push_back(kp); + kp = new KeyParam(); + kp->type_ = REGION; + kp->value_ = 17230; + kp->InitStr(); + keyParams.push_back(kp); + kp = new KeyParam(); + kp->type_ = SCREEN_DENSITY; + kp->value_ = SCREEN_DENSITY_SDPI; + kp->InitStr(); + keyParams.push_back(kp); + kp = new KeyParam(); + kp->type_ = DEVICETYPE; + kp->value_ = DEVICE_CAR; + kp->InitStr(); + keyParams.push_back(kp); + kp = new KeyParam(); + kp->type_ = DIRECTION; + kp->value_ = DIRECTION_VERTICAL; + kp->InitStr(); + keyParams.push_back(kp); + auto config = HapParser::CreateResConfigFromKeyParams(keyParams); + if (config != nullptr) { + EXPECT_EQ(std::string("zh"), config->GetLocaleInfo()->GetLanguage()); + EXPECT_EQ(std::string("CN"), config->GetLocaleInfo()->GetRegion()); + EXPECT_EQ(std::string("Hans"), config->GetLocaleInfo()->GetScript()); + EXPECT_EQ(DEVICE_CAR, config->GetDeviceType()); + EXPECT_EQ(DIRECTION_VERTICAL, config->GetDirection()); + EXPECT_EQ(SCREEN_DENSITY_SDPI, config->GetScreenDensity()); + } else { + EXPECT_TRUE(false); + } + + for (auto kp = keyParams.begin(); kp != keyParams.end(); kp++) { + delete *kp; + } + delete config; +} + +/* + * @tc.name: HapParserFuncTest002 + * @tc.desc: Test GetDeviceType + * @tc.type: FUNC + */ +HWTEST_F(HapParserTest, HapParserFuncTest002, TestSize.Level1) +{ + ASSERT_EQ(DEVICE_CAR, HapParser::GetDeviceType(DEVICE_CAR)); + ASSERT_EQ(DEVICE_PC, HapParser::GetDeviceType(DEVICE_PC)); + ASSERT_EQ(DEVICE_PHONE, HapParser::GetDeviceType(DEVICE_PHONE)); + ASSERT_EQ(DEVICE_TABLET, HapParser::GetDeviceType(DEVICE_TABLET)); + ASSERT_EQ(DEVICE_TV, HapParser::GetDeviceType(DEVICE_TV)); + ASSERT_EQ(DEVICE_WEARABLE, HapParser::GetDeviceType(DEVICE_WEARABLE)); + ASSERT_EQ(DEVICE_NOT_SET, HapParser::GetDeviceType(1000000)); +} + +/* + * @tc.name: HapParserFuncTest003 + * @tc.desc: Test GetScreenDensity + * @tc.type: FUNC + */ +HWTEST_F(HapParserTest, HapParserFuncTest003, TestSize.Level1) +{ + ASSERT_EQ(SCREEN_DENSITY_SDPI, HapParser::GetScreenDensity(SCREEN_DENSITY_SDPI)); + ASSERT_EQ(SCREEN_DENSITY_MDPI, HapParser::GetScreenDensity(SCREEN_DENSITY_MDPI)); + ASSERT_EQ(SCREEN_DENSITY_LDPI, HapParser::GetScreenDensity(SCREEN_DENSITY_LDPI)); + ASSERT_EQ(SCREEN_DENSITY_XLDPI, HapParser::GetScreenDensity(SCREEN_DENSITY_XLDPI)); + ASSERT_EQ(SCREEN_DENSITY_XXLDPI, HapParser::GetScreenDensity(SCREEN_DENSITY_XXLDPI)); + ASSERT_EQ(SCREEN_DENSITY_XXXLDPI, HapParser::GetScreenDensity(SCREEN_DENSITY_XXXLDPI)); + ASSERT_EQ(SCREEN_DENSITY_NOT_SET, HapParser::GetScreenDensity(10000000)); +} + +/* + * @tc.name: HapParserFuncTest004 + * @tc.desc: Test ToFolderPath + * @tc.type: FUNC + */ +HWTEST_F(HapParserTest, HapParserFuncTest004, TestSize.Level1) +{ + std::vector keyParams; + auto kp = new KeyParam(); + kp->type_ = LANGUAGES; + kp->value_ = 31336; + kp->InitStr(); + keyParams.push_back(kp); + kp = new KeyParam(); + kp->type_ = REGION; + kp->value_ = 17230; + kp->InitStr(); + keyParams.push_back(kp); + kp = new KeyParam(); + kp->type_ = SCREEN_DENSITY; + kp->value_ = SCREEN_DENSITY_SDPI; + kp->InitStr(); + keyParams.push_back(kp); + kp = new KeyParam(); + kp->type_ = DEVICETYPE; + kp->value_ = DEVICE_CAR; + kp->InitStr(); + keyParams.push_back(kp); + kp = new KeyParam(); + kp->type_ = DIRECTION; + kp->value_ = DIRECTION_VERTICAL; + kp->InitStr(); + keyParams.push_back(kp); + std::string folder = HapParser::ToFolderPath(keyParams); + ASSERT_EQ("zh_CN-vertical-car-sdpi", folder); + for (auto kp = keyParams.begin(); kp != keyParams.end(); kp++) { + delete *kp; + } +} \ No newline at end of file diff --git a/global_lite/i18n_lite/resource_parse_load/src/hap_parser_test.h b/global_lite/i18n_lite/resource_parse_load/src/hap_parser_test.h new file mode 100755 index 0000000000000000000000000000000000000000..7c5ef8d407c0902def1871732eb6ee376548ac65 --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/hap_parser_test.h @@ -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. + */ + +#ifndef RESOURCE_MANAGER_HAP_RESOURCE_TEST_H +#define RESOURCE_MANAGER_HAP_RESOURCE_TEST_H + +int HapParserFuncTest001(); +int HapParserFuncTest002(); +int HapParserFuncTest003(); +int HapParserFuncTest004(); + +#endif diff --git a/global_lite/i18n_lite/resource_parse_load/src/hap_resource_test.cpp b/global_lite/i18n_lite/resource_parse_load/src/hap_resource_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..872646f88c6e525baef00cec8bf2b5afee6f066b --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/hap_resource_test.cpp @@ -0,0 +1,304 @@ +/* + * 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 "hap_resource_test.h" + +#include +#include + +#include "hap_parser.h" +#include "hap_resource.h" +#include "test_common.h" +#include "utils/date_utils.h" +#include "utils/errors.h" +#include "utils/string_utils.h" + +#define private public + +using namespace OHOS::Global::Resource; +using namespace testing::ext; + +class HapResourceTest : public testing::Test { +public: + static void SetUpTestCase(void); + + static void TearDownTestCase(void); + + void SetUp(); + + void TearDown(); +}; + +void HapResourceTest::SetUpTestCase(void) +{ + // step 1: input testsuit setup step + g_logLevel = LOG_DEBUG; +} + +void HapResourceTest::TearDownTestCase(void) +{ + // step 2: input testsuit teardown step +} + +void HapResourceTest::SetUp() +{ + // step 3: input testcase setup step +} + +void HapResourceTest::TearDown() +{ + // step 4: input testcase teardown step +} + +/* + * this test shows how to load a hap, defaultConfig set to null + * @tc.name: HapResourceFuncTest001 + * @tc.desc: Test Load & GetIdValues & GetIdValuesByName function, file case. + * @tc.type: FUNC + */ +HWTEST_F(HapResourceTest, HapResourceFuncTest001, TestSize.Level1) +{ + auto start = CurrentTimeUsec(); + const HapResource *pResource = HapResource::LoadFromIndex(FormatFullPath(g_resFilePath).c_str(), nullptr); + auto cost = CurrentTimeUsec() - start; + HILOG_DEBUG("load cost: %ld us.", cost); + + if (pResource == nullptr) { + EXPECT_TRUE(false); + return; + } + EXPECT_EQ(static_cast(80), pResource->IdSize()); + + int id = pResource->GetIdByName("app_name", ResType::STRING); + start = CurrentTimeUsec(); + auto idValues = pResource->GetIdValues(id); + cost = CurrentTimeUsec() - start; + EXPECT_EQ(static_cast(3), idValues->GetLimitPathsConst().size()); + HILOG_DEBUG("GetIdValues by id cost: %ld us.", cost); + PrintIdValues(idValues); + { + auto limitPath = idValues->GetLimitPathsConst()[0]; + EXPECT_TRUE(limitPath->GetFolder() == "en_US"); + EXPECT_TRUE(limitPath->GetIdItem()->name_ == "app_name"); + EXPECT_TRUE(limitPath->GetIdItem()->value_ == "App Name"); + } + { + auto limitPath = idValues->GetLimitPathsConst()[1]; + EXPECT_TRUE(limitPath->GetFolder() == "zh_CN"); + EXPECT_TRUE(limitPath->GetIdItem()->name_ == "app_name"); + EXPECT_TRUE(limitPath->GetIdItem()->value_ == "应用名称"); + } + { + auto limitPath = idValues->GetLimitPathsConst()[2]; + EXPECT_TRUE(limitPath->GetFolder() == "default"); + EXPECT_TRUE(limitPath->GetIdItem()->name_ == "app_name"); + EXPECT_TRUE(limitPath->GetIdItem()->value_ == "About"); + } + + std::string name = std::string("app_name"); + start = CurrentTimeUsec(); + auto idValues2 = pResource->GetIdValuesByName(name, ResType::STRING); + cost = CurrentTimeUsec() - start; + EXPECT_EQ(static_cast(3), idValues2->GetLimitPathsConst().size()); + HILOG_DEBUG("GetIdValues by name cost: %ld us.", cost); + PrintIdValues(idValues); + { + auto limitPath = idValues->GetLimitPathsConst()[0]; + EXPECT_TRUE(limitPath->GetFolder() == "en_US"); + EXPECT_TRUE(limitPath->GetIdItem()->name_ == "app_name"); + EXPECT_TRUE(limitPath->GetIdItem()->value_ == "App Name"); + } + { + auto limitPath = idValues->GetLimitPathsConst()[1]; + EXPECT_TRUE(limitPath->GetFolder() == "zh_CN"); + EXPECT_TRUE(limitPath->GetIdItem()->name_ == "app_name"); + EXPECT_TRUE(limitPath->GetIdItem()->value_ == "应用名称"); + } + { + auto limitPath = idValues->GetLimitPathsConst()[2]; + EXPECT_TRUE(limitPath->GetFolder() == "default"); + EXPECT_TRUE(limitPath->GetIdItem()->name_ == "app_name"); + EXPECT_TRUE(limitPath->GetIdItem()->value_ == "About"); + } + + delete (pResource); +} + +/* + * load a hap, set config en_US + * @tc.name: HapResourceFuncTest002 + * @tc.desc: Test Load & GetIdValues & GetIdValuesByName function, file case. + * @tc.type: FUNC + */ +HWTEST_F(HapResourceTest, HapResourceFuncTest002, TestSize.Level1) +{ + ResConfigImpl *rc = new ResConfigImpl; + rc->SetLocaleInfo("en", nullptr, "US"); + std::string resPath = FormatFullPath(g_resFilePath); + const char *path = resPath.c_str(); + + auto start = CurrentTimeUsec(); + const HapResource *pResource = HapResource::LoadFromIndex(path, rc); + auto cost = CurrentTimeUsec() - start; + HILOG_DEBUG("load cost: %ld us.", cost); + + if (pResource == nullptr) { + delete rc; + EXPECT_TRUE(false); + return; + } + + EXPECT_EQ(static_cast(79), pResource->IdSize()); + + int id = pResource->GetIdByName("app_name", ResType::STRING); + start = CurrentTimeUsec(); + auto idValues = pResource->GetIdValues(id); + cost = CurrentTimeUsec() - start; + EXPECT_EQ(static_cast(2), idValues->GetLimitPathsConst().size()); + HILOG_DEBUG("GetIdValues by id cost: %ld us.", cost); + PrintIdValues(idValues); + + { + auto limitPath = idValues->GetLimitPathsConst()[0]; + EXPECT_TRUE(limitPath->GetFolder() == "en_US"); + EXPECT_TRUE(limitPath->GetIdItem()->name_ == "app_name"); + EXPECT_TRUE(limitPath->GetIdItem()->value_ == "App Name"); + } + + { + auto limitPath = idValues->GetLimitPathsConst()[1]; + EXPECT_TRUE(limitPath->GetFolder() == "default"); + EXPECT_TRUE(limitPath->GetIdItem()->name_ == "app_name"); + EXPECT_TRUE(limitPath->GetIdItem()->value_ == "About"); + } + + std::string name = std::string("app_name"); + start = CurrentTimeUsec(); + auto idValues2 = pResource->GetIdValuesByName(name, ResType::STRING); + cost = CurrentTimeUsec() - start; + EXPECT_EQ(static_cast(2), idValues2->GetLimitPathsConst().size()); + HILOG_DEBUG("GetIdValues by name cost: %ld us.", cost); + PrintIdValues(idValues); + + { + auto limitPath = idValues2->GetLimitPathsConst()[0]; + EXPECT_TRUE(limitPath->GetFolder() == "en_US"); + EXPECT_TRUE(limitPath->GetIdItem()->id_ == static_cast(id)); + EXPECT_TRUE(limitPath->GetIdItem()->value_ == "App Name"); + } + + { + auto limitPath = idValues->GetLimitPathsConst()[1]; + EXPECT_TRUE(limitPath->GetFolder() == "default"); + EXPECT_TRUE(limitPath->GetIdItem()->id_ == static_cast(id)); + EXPECT_TRUE(limitPath->GetIdItem()->value_ == "About"); + } + delete pResource; + delete rc; +} + +/* + * load a hap, get a value which is ref + * @tc.name: HapResourceFuncTest003 + * @tc.desc: Test GetIdValuesByName function, file case. + * @tc.type: FUNC + */ +HWTEST_F(HapResourceTest, HapResourceFuncTest003, TestSize.Level1) +{ + auto start = CurrentTimeUsec(); + const HapResource *pResource = HapResource::LoadFromIndex(FormatFullPath(g_resFilePath).c_str(), nullptr); + auto cost = CurrentTimeUsec() - start; + HILOG_DEBUG("load cost: %ld us.", cost); + + if (pResource == nullptr) { + EXPECT_TRUE(false); + return; + } + + auto idv = pResource->GetIdValuesByName(std::string("integer_ref"), ResType::INTEGER); + PrintIdValues(idv); + + idv = pResource->GetIdValuesByName(std::string("string_ref"), ResType::STRING); + PrintIdValues(idv); + + // ref propagation + idv = pResource->GetIdValuesByName(std::string("string_ref2"), ResType::STRING); + PrintIdValues(idv); + + idv = pResource->GetIdValuesByName(std::string("boolean_ref"), ResType::BOOLEAN); + PrintIdValues(idv); + + idv = pResource->GetIdValuesByName(std::string("color_ref"), ResType::COLOR); + PrintIdValues(idv); + + idv = pResource->GetIdValuesByName(std::string("float_ref"), ResType::FLOAT); + PrintIdValues(idv); + + // ref in array , + idv = pResource->GetIdValuesByName(std::string("intarray_1"), ResType::INTARRAY); + PrintIdValues(idv); + + // "parent": was ref too + idv = pResource->GetIdValuesByName(std::string("child"), ResType::PATTERN); + PrintIdValues(idv); +} + +ResDesc *LoadFromHap(const char *hapPath, const ResConfigImpl *defaultConfig) +{ + std::string errOut; + void *buf = nullptr; + size_t bufLen; + int32_t out = HapParser::ReadIndexFromFile(hapPath, + &buf, bufLen, errOut); + if (out != OK) { + HILOG_ERROR("ReadIndexFromFile failed! retcode:%d,err:%s", out, errOut.c_str()); + return nullptr; + } + HILOG_DEBUG("extract success, bufLen:%zu", bufLen); + + ResDesc *resDesc = new ResDesc(); + out = HapParser::ParseResHex((char *)buf, bufLen, *resDesc, defaultConfig); + if (out != OK) { + delete (resDesc); + free(buf); + HILOG_ERROR("ParseResHex failed! retcode:%d", out); + return nullptr; + } else { + HILOG_DEBUG("ParseResHex success:\n%s", resDesc->ToString().c_str()); + } + free(buf); + // construct hapresource + return resDesc; +} + +/* + * @tc.name: HapResourceFuncTest004 + * @tc.desc: Test HapParser::ReadIndexFromFile function, file case. + * @tc.type: FUNC + */ +HWTEST_F(HapResourceTest, HapResourceFuncTest004, TestSize.Level1) +{ + // 1. normal case + ResDesc *resDesc = LoadFromHap(FormatFullPath("all.hap").c_str(), nullptr); + ASSERT_TRUE(resDesc != nullptr); + + // 2. hap file exists, config.json does not exist + resDesc = LoadFromHap(FormatFullPath("err-config.json-1.hap").c_str(), nullptr); + ASSERT_TRUE(resDesc == nullptr); + + // 3. hap file exists, config.json error: missing "moduleName" + resDesc = LoadFromHap(FormatFullPath("err-config.json-2.hap").c_str(), nullptr); + ASSERT_TRUE(resDesc == nullptr); +} \ No newline at end of file diff --git a/global_lite/i18n_lite/resource_parse_load/src/hap_resource_test.h b/global_lite/i18n_lite/resource_parse_load/src/hap_resource_test.h new file mode 100755 index 0000000000000000000000000000000000000000..7ea1b99256d8ee8a9bd6a00c5a13921e1cc73179 --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/hap_resource_test.h @@ -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. + */ + +#ifndef RESOURCE_MANAGER_HAP_RESOURCE_TEST_H +#define RESOURCE_MANAGER_HAP_RESOURCE_TEST_H + +int HapResourceFuncTest001(); +int HapResourceFuncTest002(); +int HapResourceFuncTest003(); +int HapResourceFuncTest004(); + +#endif diff --git a/global_lite/i18n_lite/resource_parse_load/src/locale_info_test.cpp b/global_lite/i18n_lite/resource_parse_load/src/locale_info_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..eb0af69dd1fc56aed889b8a938c460d0bfefcd76 --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/locale_info_test.cpp @@ -0,0 +1,609 @@ +/* + * 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 "locale_info_test.h" + +#include +#include +#include +#include + +#include "hilog_wrapper.h" +#include "locale_info.h" +#include "test_common.h" + +using namespace OHOS::Global::Resource; +using namespace testing::ext; + +class LocaleInfoTest : public testing::Test { +public: + static void SetUpTestCase(void); + + static void TearDownTestCase(void); + + void SetUp(); + + void TearDown(); +}; + +void LocaleInfoTest::SetUpTestCase(void) +{ + // step 1: input testsuit setup step +} + +void LocaleInfoTest::TearDownTestCase(void) +{ + // step 2: input testsuit teardown step +} + +void LocaleInfoTest::SetUp() +{ +} + +void LocaleInfoTest::TearDown() +{ +} + +/* + * @tc.name: LocaleInfoFindAndSortTest001 + * @tc.desc: Test FindAndSort + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoFindAndSortTest001, TestSize.Level1) +{ + std::vector request; + std::vector outValue; + request.push_back("en"); + request.push_back("en-CN"); + request.push_back("en-US"); + request.push_back("en-GB"); + request.push_back(""); + std::string current = "en-US"; + FindAndSort(current, request, outValue); + EXPECT_TRUE(outValue.at(0) == "en-US"); + EXPECT_TRUE(outValue.at(1) == "en"); + EXPECT_TRUE(outValue.at(2) == ""); + EXPECT_TRUE(outValue.at(3) == "en-CN"); + EXPECT_TRUE(outValue.at(4) == "en-GB"); +} + +/* + * @tc.name: LocaleInfoFindAndSortTest002 + * @tc.desc: Test FindAndSort + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoFindAndSortTest002, TestSize.Level1) +{ + std::vector request; + std::vector outValue; + request.push_back("zh-CN"); + request.push_back("zh-TW"); + request.push_back("zh"); + request.push_back("zh-HK"); + request.push_back(""); + std::string current = "zh-CN"; + FindAndSort(current, request, outValue); + EXPECT_TRUE(outValue.at(0) == "zh-CN"); + EXPECT_TRUE(outValue.at(1) == "zh"); + EXPECT_TRUE(outValue.at(2) == ""); +} + +/* + * @tc.name: LocaleInfoFindAndSortTest003 + * @tc.desc: Test FindAndSort + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoFindAndSortTest003, TestSize.Level1) +{ + std::vector request; + std::vector outValue; + request.push_back("en"); + request.push_back("en-CA"); + request.push_back("en-GB"); + request.push_back(""); + std::string current = "en-CN"; + FindAndSort(current, request, outValue); + EXPECT_TRUE(outValue.at(0) == "en"); + EXPECT_TRUE(outValue.at(1) == "en-CA"); + EXPECT_TRUE(outValue.at(2) == ""); + EXPECT_TRUE(outValue.at(3) == "en-GB"); +} + +/* + * @tc.name: LocaleInfoFindAndSortTest004 + * @tc.desc: Test FindAndSort + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoFindAndSortTest004, TestSize.Level1) +{ + std::vector request; + std::vector outValue; + request.push_back("en"); + request.push_back("en-CA"); + request.push_back("en-GB"); + request.push_back(""); + std::string current = "en-Qaag"; + FindAndSort(current, request, outValue); + EXPECT_TRUE(outValue.at(0) == "en"); + EXPECT_TRUE(outValue.at(1) == "en-GB"); + EXPECT_TRUE(outValue.at(2) == "en-CA"); + EXPECT_TRUE(outValue.at(3) == ""); +} + +/* + * @tc.name: LocaleInfoFindAndSortTest005 + * @tc.desc: Test FindAndSort + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoFindAndSortTest005, TestSize.Level1) +{ + std::vector request; + std::vector outValue; + request.push_back("en"); + request.push_back("en-001"); + request.push_back("en-CA"); + request.push_back("en-GB"); + request.push_back(""); + std::string current = "en-AI"; + FindAndSort(current, request, outValue); + EXPECT_TRUE(outValue.at(0) == "en-001"); + EXPECT_TRUE(outValue.at(1) == "en"); + EXPECT_TRUE(outValue.at(2) == "en-GB"); + EXPECT_TRUE(outValue.at(3) == "en-CA"); + EXPECT_TRUE(outValue.at(4) == ""); +} + +/* + * @tc.name: LocaleInfoGetSysDefaultTest001 + * @tc.desc: Test GetSysDefault + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoGetSysDefaultTest001, TestSize.Level1) +{ + RState state = SUCCESS; + LocaleInfo* localeInfo = BuildFromString("zh-CN", '-', state); + if (localeInfo == nullptr) { + EXPECT_TRUE(false); + return; + } + UpdateSysDefault(*localeInfo, false); + const LocaleInfo* currentLocaleInfo = GetSysDefault(); + if (currentLocaleInfo == nullptr) { + EXPECT_TRUE(false); + delete localeInfo; + return; + } + EXPECT_TRUE(std::strcmp("zh", currentLocaleInfo->GetLanguage()) == 0); + EXPECT_TRUE(std::strcmp("CN", currentLocaleInfo->GetRegion()) == 0); + delete localeInfo; + localeInfo = nullptr; +} + +/* + * @tc.name: LocaleInfoUpdateSysDefaultTest001 + * @tc.desc: Test UpdateSysDefault + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoUpdateSysDefaultTest001, TestSize.Level1) +{ + RState state = SUCCESS; + LocaleInfo* localeInfo = BuildFromString("zh-CN", '-', state); + if (localeInfo == nullptr) { + EXPECT_TRUE(false); + return; + } + UpdateSysDefault(*localeInfo, false); + const LocaleInfo* currentLocaleInfo = GetSysDefault(); + if (currentLocaleInfo == nullptr) { + EXPECT_TRUE(false); + delete localeInfo; + return; + } + EXPECT_TRUE(std::strcmp("zh", currentLocaleInfo->GetLanguage()) == 0); + EXPECT_TRUE(std::strcmp("CN", currentLocaleInfo->GetRegion()) == 0); + delete localeInfo; + localeInfo = BuildFromString("en-US", '-', state); + UpdateSysDefault(*localeInfo, false); + currentLocaleInfo = GetSysDefault(); + if (currentLocaleInfo == nullptr) { + EXPECT_TRUE(false); + delete localeInfo; + return; + } + EXPECT_TRUE(std::strcmp("en", currentLocaleInfo->GetLanguage()) == 0); + EXPECT_TRUE(std::strcmp("US", currentLocaleInfo->GetRegion()) == 0); + delete localeInfo; + localeInfo = BuildFromString("en-Qaag-US", '-', state); + if (localeInfo == nullptr) { + EXPECT_TRUE(false); + return; + } + UpdateSysDefault(*localeInfo, false); + currentLocaleInfo = GetSysDefault(); + if (currentLocaleInfo == nullptr) { + EXPECT_TRUE(false); + delete localeInfo; + return; + } + EXPECT_TRUE(std::strcmp("en", currentLocaleInfo->GetLanguage()) == 0); + EXPECT_TRUE(std::strcmp("US", currentLocaleInfo->GetRegion()) == 0); + EXPECT_TRUE(std::strcmp("Qaag", currentLocaleInfo->GetScript()) == 0); + delete localeInfo; + localeInfo = nullptr; +} + +/* + * @tc.name: LocaleInfoGetLanguageTest001 + * @tc.desc: Test LocaleInfo GetLanguage + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoGetLanguageTest001, TestSize.Level1) +{ + RState state = SUCCESS; + LocaleInfo* localeInfo = BuildFromString("zh-CN", '-', state); + if (localeInfo == nullptr) { + EXPECT_TRUE(false); + return; + } + EXPECT_TRUE(std::strcmp("zh", localeInfo->GetLanguage()) == 0); + delete localeInfo; + localeInfo = nullptr; +} + +/* + * @tc.name: LocaleInfoGetRegionTest001 + * @tc.desc: Test LocaleInfo GetRegion + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoGetRegionTest001, TestSize.Level1) +{ + RState state = SUCCESS; + LocaleInfo* localeInfo = BuildFromString("zh-CN", '-', state); + if (localeInfo == nullptr) { + EXPECT_TRUE(false); + return; + } + EXPECT_TRUE(std::strcmp("CN", localeInfo->GetRegion()) == 0); + delete localeInfo; + localeInfo = nullptr; +} + +/* + * @tc.name: LocaleInfoGetScriptTest001 + * @tc.desc: Test LocaleInfo GetScript + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoGetScriptTest001, TestSize.Level1) +{ + RState state = SUCCESS; + LocaleInfo* localeInfo = BuildFromString("zh-Hant-CN", '-', state); + if (localeInfo == nullptr) { + EXPECT_TRUE(false); + return; + } + EXPECT_TRUE(std::strcmp("Hant", localeInfo->GetScript()) == 0); + delete localeInfo; + localeInfo = nullptr; +} + +/* + * @tc.name: LocaleInfoBuildFromPartsTest001 + * @tc.desc: Test BuildFromParts + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest001, TestSize.Level1) +{ + RState state = SUCCESS; + LocaleInfo* localeInfo = BuildFromParts("zh", "Hant", "CN", state); + if (localeInfo == nullptr) { + EXPECT_TRUE(false); + return; + } + EXPECT_TRUE(state == SUCCESS); + EXPECT_TRUE(std::strcmp("zh", localeInfo->GetLanguage()) == 0); + EXPECT_TRUE(std::strcmp("Hant", localeInfo->GetScript()) == 0); + EXPECT_TRUE(std::strcmp("CN", localeInfo->GetRegion()) == 0); + delete localeInfo; + localeInfo = nullptr; +} + +/* + * @tc.name: LocaleInfoBuildFromPartsTest002 + * @tc.desc: Test BuildFromParts + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest002, TestSize.Level1) +{ + RState state = SUCCESS; + LocaleInfo* localeInfo = BuildFromParts("zh1", "Hant", "CN", state); + EXPECT_TRUE(state == INVALID_BCP47_LANGUAGE_SUBTAG); + EXPECT_TRUE(localeInfo == nullptr); + delete localeInfo; + localeInfo = nullptr; +} + +/* + * @tc.name: LocaleInfoBuildFromPartsTest003 + * @tc.desc: Test BuildFromParts + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest003, TestSize.Level1) +{ + RState state = SUCCESS; + LocaleInfo* localeInfo = BuildFromParts("zh", "Hants", "CN", state); + EXPECT_TRUE(state == INVALID_BCP47_SCRIPT_SUBTAG); + EXPECT_TRUE(localeInfo == nullptr); + delete localeInfo; + localeInfo = nullptr; +} + +/* + * @tc.name: LocaleInfoBuildFromPartsTest004 + * @tc.desc: Test BuildFromParts + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest004, TestSize.Level1) +{ + RState state = SUCCESS; + LocaleInfo* localeInfo = BuildFromParts("zh", "Hant", "C", state); + EXPECT_TRUE(state == INVALID_BCP47_REGION_SUBTAG); + EXPECT_TRUE(localeInfo == nullptr); + delete localeInfo; + localeInfo = nullptr; +} + +/* + * @tc.name: LocaleInfoBuildFromPartsTest005 + * @tc.desc: Test BuildFromParts + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest005, TestSize.Level1) +{ + RState state = SUCCESS; + LocaleInfo* localeInfo = BuildFromParts(nullptr, "Hants", "CN", state); + EXPECT_TRUE(state == INVALID_BCP47_LANGUAGE_SUBTAG); + EXPECT_TRUE(localeInfo == nullptr); + delete localeInfo; + localeInfo = nullptr; +} + +/* + * @tc.name: LocaleInfoBuildFromPartsTest006 + * @tc.desc: Test BuildFromParts + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest006, TestSize.Level1) +{ + RState state = SUCCESS; + LocaleInfo* localeInfo = BuildFromParts("zh", nullptr, nullptr, state); + if (localeInfo == nullptr) { + EXPECT_TRUE(false); + return; + } + EXPECT_TRUE(state == SUCCESS); + EXPECT_TRUE(std::strcmp("zh", localeInfo->GetLanguage()) == 0); + EXPECT_TRUE(localeInfo->GetScript() == nullptr); + EXPECT_TRUE(localeInfo->GetRegion() == nullptr); + delete localeInfo; + localeInfo = nullptr; +} + +/* + * @tc.name: LocaleInfoBuildFromStringTest001 + * @tc.desc: Test BuildFromString + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest001, TestSize.Level1) +{ + RState state = SUCCESS; + LocaleInfo* localeInfo = BuildFromString("zh-Hant-CN", '-', state); + if (localeInfo == nullptr) { + EXPECT_TRUE(false); + return; + } + EXPECT_TRUE(state == SUCCESS); + EXPECT_TRUE(std::strcmp("zh", localeInfo->GetLanguage()) == 0); + EXPECT_TRUE(std::strcmp("Hant", localeInfo->GetScript()) == 0); + EXPECT_TRUE(std::strcmp("CN", localeInfo->GetRegion()) == 0); + delete localeInfo; + localeInfo = nullptr; +} + +/* + * @tc.name: LocaleInfoBuildFromStringTest002 + * @tc.desc: Test BuildFromString + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest002, TestSize.Level1) +{ + RState state = SUCCESS; + LocaleInfo* localeInfo = BuildFromString("zh1-Hant-CN", '-', state); + EXPECT_TRUE(state == INVALID_BCP47_LANGUAGE_SUBTAG); + EXPECT_TRUE(localeInfo == nullptr); + delete localeInfo; + localeInfo = nullptr; +} + +/* + * @tc.name: LocaleInfoBuildFromStringTest003 + * @tc.desc: Test BuildFromString + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest003, TestSize.Level1) +{ + RState state = SUCCESS; + LocaleInfo* localeInfo = BuildFromString("-Hant-CN", '-', state); + EXPECT_TRUE(state == INVALID_BCP47_LANGUAGE_SUBTAG); + EXPECT_TRUE(localeInfo == nullptr); + delete localeInfo; + localeInfo = nullptr; +} + +/* + * @tc.name: LocaleInfoBuildFromStringTest004 + * @tc.desc: Test BuildFromString + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest004, TestSize.Level1) +{ + RState state = SUCCESS; + LocaleInfo* localeInfo = BuildFromString("zh", '-', state); + if (localeInfo == nullptr) { + EXPECT_TRUE(false); + return; + } + EXPECT_TRUE(state == SUCCESS); + EXPECT_TRUE(std::strcmp("zh", localeInfo->GetLanguage()) == 0); + EXPECT_TRUE(localeInfo->GetScript() == nullptr); + EXPECT_TRUE(localeInfo->GetRegion() == nullptr); + delete localeInfo; + localeInfo = nullptr; +} + +/* + * @tc.name: LocaleInfoBuildFromStringTest005 + * @tc.desc: Test BuildFromString + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest005, TestSize.Level1) +{ + RState state = SUCCESS; + LocaleInfo* localeInfo = BuildFromString("en_US", '_', state); + if (localeInfo == nullptr) { + EXPECT_TRUE(false); + return; + } + EXPECT_TRUE(state == SUCCESS); + EXPECT_TRUE(std::strcmp("en", localeInfo->GetLanguage()) == 0); + EXPECT_TRUE(localeInfo->GetScript() == nullptr); + EXPECT_TRUE(std::strcmp("US", localeInfo->GetRegion()) == 0); + delete localeInfo; + localeInfo = nullptr; +} + +/* + * @tc.name: LocaleInfoBuildFromStringTest006 + * @tc.desc: Test BuildFromString + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest006, TestSize.Level1) +{ + RState state = SUCCESS; + LocaleInfo* localeInfo = BuildFromString("en_Latn_US", '&', state); + EXPECT_TRUE(state == NOT_SUPPORT_SEP); + EXPECT_TRUE(localeInfo == nullptr); + delete localeInfo; + localeInfo = nullptr; +} + +/* + * @tc.name: LocaleInfoBuildFromStringTest007 + * @tc.desc: Test BuildFromString + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest007, TestSize.Level1) +{ + RState state = SUCCESS; + LocaleInfo* localeInfo = BuildFromString("en_Latn_US", '_', state); + if (localeInfo == nullptr) { + EXPECT_TRUE(false); + return; + } + EXPECT_TRUE(state == SUCCESS); + EXPECT_TRUE(std::strcmp("en", localeInfo->GetLanguage()) == 0); + EXPECT_TRUE(std::strcmp("Latn", localeInfo->GetScript()) == 0); + EXPECT_TRUE(std::strcmp("US", localeInfo->GetRegion()) == 0); + delete localeInfo; + localeInfo = nullptr; +} + +/* + * @tc.name: LocaleInfoBuildFromStringTest008 + * @tc.desc: Test BuildFromString + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest008, TestSize.Level1) +{ + RState state = SUCCESS; + LocaleInfo* localeInfo = BuildFromString("zh-Hants-CN", '-', state); + EXPECT_TRUE(state == INVALID_BCP47_SCRIPT_SUBTAG); + EXPECT_TRUE(localeInfo == nullptr); + delete localeInfo; + localeInfo = nullptr; +} + +/* + * @tc.name: LocaleInfoBuildFromStringTest009 + * @tc.desc: Test BuildFromString + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest009, TestSize.Level1) +{ + RState state = SUCCESS; + LocaleInfo* localeInfo = BuildFromString("zh-Hant-C", '-', state); + EXPECT_TRUE(state == INVALID_BCP47_REGION_SUBTAG); + EXPECT_TRUE(localeInfo == nullptr); + delete localeInfo; + localeInfo = nullptr; +} + +/* + * @tc.name: LocaleInfoBuildFromStringTest0010 + * @tc.desc: Test BuildFromString + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest0010, TestSize.Level1) +{ + RState state = SUCCESS; + LocaleInfo* localeInfo = BuildFromString("zh-CN-xxxx", '-', state); + if (localeInfo == nullptr) { + EXPECT_TRUE(false); + return; + } + EXPECT_TRUE(state == SUCCESS); + EXPECT_TRUE(std::strcmp("zh", localeInfo->GetLanguage()) == 0); + EXPECT_TRUE(localeInfo->GetScript() == nullptr); + EXPECT_TRUE(std::strcmp("CN", localeInfo->GetRegion()) == 0); + delete localeInfo; + localeInfo = nullptr; +} + +/* + * @tc.name: LocaleInfoPerformanceFuncTest001 + * @tc.desc: Test FindAndSort Performance + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoPerformanceFuncTest001, TestSize.Level1) +{ + unsigned long long total = 0; + double average = 0; + std::vector outValue; + for (int k = 0; k < 1000; ++k) { + auto t1 = std::chrono::high_resolution_clock::now(); + std::vector request; + std::vector outValue; + request.push_back("en"); + request.push_back("en-CN"); + request.push_back("en-US"); + request.push_back("en-GB"); + request.push_back(""); + std::string current = "en-US"; + FindAndSort(current, request, outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + average = total / 1000.0; + HILOG_DEBUG("avg cost FindAndSort: %f us", average); + EXPECT_LT(average, 500); +}; \ No newline at end of file diff --git a/global_lite/i18n_lite/resource_parse_load/src/locale_info_test.h b/global_lite/i18n_lite/resource_parse_load/src/locale_info_test.h new file mode 100755 index 0000000000000000000000000000000000000000..6512ab3cb0f20178afe6aed75e4afa820c104cba --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/locale_info_test.h @@ -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. + */ + +#ifndef RESOURCE_MANAGER_LOCALE_INFO_TEST_H +#define RESOURCE_MANAGER_LOCALE_INFO_TEST_H + +int LocaleInfoFindAndSortTest001(); +int LocaleInfoFindAndSortTest002(); +int LocaleInfoFindAndSortTest003(); +int LocaleInfoFindAndSortTest004(); +int LocaleInfoFindAndSortTest005(); +int LocaleInfoUpdateSysDefaultTest001(); +int LocaleInfoGetSysDefaultTest001(); +int LocaleInfoGetLanguageTest001(); +int LocaleInfoGetRegionTest001(); +int LocaleInfoGetScriptTest001(); +int LocaleInfoBuildFromPartsTest001(); +int LocaleInfoBuildFromPartsTest002(); +int LocaleInfoBuildFromPartsTest003(); +int LocaleInfoBuildFromPartsTest004(); +int LocaleInfoBuildFromPartsTest005(); +int LocaleInfoBuildFromPartsTest006(); +int LocaleInfoBuildFromStringTest001(); +int LocaleInfoBuildFromStringTest002(); +int LocaleInfoBuildFromStringTest003(); +int LocaleInfoBuildFromStringTest004(); +int LocaleInfoBuildFromStringTest005(); +int LocaleInfoBuildFromStringTest006(); +int LocaleInfoBuildFromStringTest007(); +int LocaleInfoBuildFromStringTest008(); +int LocaleInfoBuildFromStringTest009(); +int LocaleInfoBuildFromStringTest0010(); +int LocaleInfoPerformanceFuncTest001(); + +#endif // RESOURCE_MANAGER_LOCALE_INFO_TEST_H diff --git a/global_lite/i18n_lite/resource_parse_load/src/res_config_impl_test.cpp b/global_lite/i18n_lite/resource_parse_load/src/res_config_impl_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..b58d3b84b3e54fbf4bcaddf202e8b19b12a8d52e --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/res_config_impl_test.cpp @@ -0,0 +1,1395 @@ +/* + * 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 "res_config_impl_test.h" + +#include +#include +#include + +#include "res_config_impl.h" +#include "test_common.h" + +using namespace OHOS::Global::Resource; +using namespace testing::ext; + +class ResConfigImplTest : public testing::Test { +public: + static void SetUpTestCase(void); + + static void TearDownTestCase(void); + + void SetUp(); + + void TearDown(); +}; + +void ResConfigImplTest::SetUpTestCase(void) +{ + // step 1: input testsuit setup step +} + +void ResConfigImplTest::TearDownTestCase(void) +{ + // step 2: input testsuit teardown step +} + +void ResConfigImplTest::SetUp() +{ +} + +void ResConfigImplTest::TearDown() +{ +} + +ResConfigImpl *CreateResConfigImpl(const char *language, const char *script, const char *region) +{ + ResConfigImpl *resConfigImpl = new ResConfigImpl; + resConfigImpl->SetLocaleInfo(language, script, region); + return resConfigImpl; +} + +/* + * @tc.name: ResConfigImplMatchTest001 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest001, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl(nullptr, nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("fr", nullptr, "CA"); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest002 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest002, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "CA"); + ResConfigImpl *current = CreateResConfigImpl("fr", nullptr, "CA"); + EXPECT_FALSE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest003 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest003, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("tl", nullptr, "PH"); + ResConfigImpl *current = CreateResConfigImpl("fil", nullptr, "PH"); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest004 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest004, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("qaa", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("qaa", nullptr, "CA"); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest005 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest005, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("qaa", nullptr, "CA"); + ResConfigImpl *current = CreateResConfigImpl("qaa", nullptr, "CA"); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest006 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest006, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("az", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("az", "Latn", nullptr); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest007 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest007, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("az", nullptr, "IR"); + ResConfigImpl *current = CreateResConfigImpl("az", "Arab", nullptr); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest008 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest008, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("ar", nullptr, "EG"); + ResConfigImpl *current = CreateResConfigImpl("ar", nullptr, "TN"); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest009 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest009, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("qaa", "Latn", "FR"); + ResConfigImpl *current = CreateResConfigImpl("qaa", nullptr, "CA"); + EXPECT_FALSE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest010 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest010, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("qaa", nullptr, "FR"); + ResConfigImpl *current = CreateResConfigImpl("qaa", "Latn", "CA"); + EXPECT_FALSE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest011 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest011, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("az", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("az", "Cyrl", nullptr); + EXPECT_FALSE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest012 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest012, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("az", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("az", nullptr, "IR"); + EXPECT_FALSE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest013 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest013, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("qaa", nullptr, "FR"); + ResConfigImpl *current = CreateResConfigImpl("qaa", nullptr, "CA"); + EXPECT_FALSE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest014 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest014, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("he", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("iw", nullptr, nullptr); + EXPECT_TRUE(current->Match(other)); + EXPECT_TRUE(other->Match(current)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest015 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest015, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("ji", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("yi", nullptr, nullptr); + EXPECT_TRUE(current->Match(other)); + EXPECT_TRUE(other->Match(current)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest016 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest016, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("jw", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("jv", nullptr, nullptr); + EXPECT_TRUE(current->Match(other)); + EXPECT_TRUE(other->Match(current)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest017 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest017, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("in", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("id", nullptr, nullptr); + EXPECT_TRUE(current->Match(other)); + EXPECT_TRUE(other->Match(current)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest018 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest018, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", "Latn", nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", "Qaag", nullptr); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest019 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest019, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + current->SetDeviceType(DeviceType::DEVICE_CAR); + other->SetDeviceType(DeviceType::DEVICE_CAR); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest020 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest020, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + current->SetDeviceType(DeviceType::DEVICE_CAR); + other->SetDeviceType(DeviceType::DEVICE_PC); + EXPECT_FALSE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest021 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest021, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + other->SetDeviceType(DeviceType::DEVICE_PC); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest022 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest022, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + current->SetDeviceType(DeviceType::DEVICE_PC); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest023 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest023, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + current->SetDirection(Direction::DIRECTION_HORIZONTAL); + other->SetDirection(Direction::DIRECTION_HORIZONTAL); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest024 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest024, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + current->SetDirection(Direction::DIRECTION_HORIZONTAL); + other->SetDirection(Direction::DIRECTION_VERTICAL); + EXPECT_FALSE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest025 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest025, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + other->SetDirection(Direction::DIRECTION_HORIZONTAL); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest026 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest026, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + current->SetDirection(Direction::DIRECTION_VERTICAL); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest027 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest027, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + current->SetDirection(Direction::DIRECTION_VERTICAL); + current->SetDeviceType(DeviceType::DEVICE_PHONE); + other->SetDirection(Direction::DIRECTION_VERTICAL); + other->SetDeviceType(DeviceType::DEVICE_PHONE); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest028 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest028, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + current->SetDirection(Direction::DIRECTION_VERTICAL); + current->SetDeviceType(DeviceType::DEVICE_PHONE); + other->SetDeviceType(DeviceType::DEVICE_PHONE); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest029 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest029, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + current->SetDirection(Direction::DIRECTION_VERTICAL); + current->SetDeviceType(DeviceType::DEVICE_PHONE); + other->SetDeviceType(DeviceType::DEVICE_PHONE); + other->SetDirection(Direction::DIRECTION_HORIZONTAL); + EXPECT_FALSE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest001 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest001, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl(nullptr, nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("fr", nullptr, "FR"); + ResConfigImpl *other = CreateResConfigImpl("fr", nullptr, "CA"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_TRUE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest002 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest002, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("fr", nullptr, "CA"); + ResConfigImpl *current = CreateResConfigImpl(nullptr, nullptr, nullptr); + ResConfigImpl *other = CreateResConfigImpl(nullptr, nullptr, nullptr); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_TRUE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest003 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest003, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("fr", nullptr, "CA"); + ResConfigImpl *current = CreateResConfigImpl("fr", nullptr, "FR"); + ResConfigImpl *other = CreateResConfigImpl(nullptr, nullptr, nullptr); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest004 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest004, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("fil", nullptr, "PH"); + ResConfigImpl *current = CreateResConfigImpl("tl", nullptr, "PH"); + ResConfigImpl *other = CreateResConfigImpl("fil", nullptr, "US"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest005 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest005, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("fil", nullptr, "PH"); + ResConfigImpl *current = CreateResConfigImpl("fil", nullptr, "PH"); + ResConfigImpl *other = CreateResConfigImpl("tl", nullptr, "PH"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest006 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest006, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); + ResConfigImpl *current = CreateResConfigImpl("es", nullptr, "419"); + ResConfigImpl *other = CreateResConfigImpl("es", nullptr, "419"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_TRUE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest007 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest007, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); + ResConfigImpl *current = CreateResConfigImpl("es", nullptr, "AR"); + ResConfigImpl *other = CreateResConfigImpl("es", nullptr, "419"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest008 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest008, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); + ResConfigImpl *current = CreateResConfigImpl("es", nullptr, "419"); + ResConfigImpl *other = CreateResConfigImpl("es", nullptr, nullptr); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest009 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest009, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); + ResConfigImpl *current = CreateResConfigImpl("es", nullptr, "419"); + ResConfigImpl *other = CreateResConfigImpl("es", nullptr, "ES"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest010 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest010, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); + ResConfigImpl *current = CreateResConfigImpl("es", nullptr, nullptr); + ResConfigImpl *other = CreateResConfigImpl("es", nullptr, "ES"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest011 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest011, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); + ResConfigImpl *current = CreateResConfigImpl("es", nullptr, "PE"); + ResConfigImpl *other = CreateResConfigImpl("es", nullptr, "ES"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest012 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest012, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); + ResConfigImpl *current = CreateResConfigImpl("es", nullptr, "AR"); + ResConfigImpl *other = CreateResConfigImpl("es", nullptr, nullptr); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest013 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest013, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); + ResConfigImpl *current = CreateResConfigImpl("es", nullptr, "US"); + ResConfigImpl *other = CreateResConfigImpl("es", nullptr, "BO"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest014 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest014, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "IC"); + ResConfigImpl *current = CreateResConfigImpl("es", nullptr, "ES"); + ResConfigImpl *other = CreateResConfigImpl("es", nullptr, "GQ"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest015 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest015, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "GQ"); + ResConfigImpl *current = CreateResConfigImpl("es", nullptr, "IC"); + ResConfigImpl *other = CreateResConfigImpl("es", nullptr, "419"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest016 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest016, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "GB"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "001"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest017 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest017, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "PR"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "001"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest018 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest018, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "DE"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "150"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "001"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest019 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest019, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "IN"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "AU"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest020 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest020, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "PR"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "001"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "GB"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest021 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest021, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "IN"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "GB"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "AU"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest022 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest022, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "IN"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "AU"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "CA"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest023 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest023, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("pt", nullptr, "MZ"); + ResConfigImpl *current = CreateResConfigImpl("pt", nullptr, "PT"); + ResConfigImpl *other = CreateResConfigImpl("pt", nullptr, nullptr); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest024 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest024, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("pt", nullptr, "MZ"); + ResConfigImpl *current = CreateResConfigImpl("pt", nullptr, "PT"); + ResConfigImpl *other = CreateResConfigImpl("pt", nullptr, "BR"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest025 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest025, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("zh", "Hant", "MO"); + ResConfigImpl *current = CreateResConfigImpl("zh", "Hant", "HK"); + ResConfigImpl *other = CreateResConfigImpl("zh", "Hant", "TW"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest026 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest026, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("zh", "Hant", "US"); + ResConfigImpl *current = CreateResConfigImpl("zh", "Hant", "TW"); + ResConfigImpl *other = CreateResConfigImpl("zh", "Hant", "HK"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest027 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest027, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("ar", nullptr, "DZ"); + ResConfigImpl *current = CreateResConfigImpl("ar", nullptr, "015"); + ResConfigImpl *other = CreateResConfigImpl("ar", nullptr, nullptr); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest028 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest028, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("ar", nullptr, "EG"); + ResConfigImpl *current = CreateResConfigImpl("ar", nullptr, nullptr); + ResConfigImpl *other = CreateResConfigImpl("ar", nullptr, "015"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest029 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest029, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("ar", nullptr, "QA"); + ResConfigImpl *current = CreateResConfigImpl("ar", nullptr, "EG"); + ResConfigImpl *other = CreateResConfigImpl("ar", nullptr, "BH"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest030 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest030, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("ar", nullptr, "QA"); + ResConfigImpl *current = CreateResConfigImpl("ar", nullptr, "SA"); + ResConfigImpl *other = CreateResConfigImpl("ar", nullptr, "015"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest031 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest031, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl(nullptr, nullptr, nullptr); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "001"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest032 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest032, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl(nullptr, nullptr, nullptr); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "GB"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest033 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest033, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "PR"); + ResConfigImpl *current = CreateResConfigImpl(nullptr, nullptr, nullptr); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "001"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest034 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest034, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *other = CreateResConfigImpl(nullptr, nullptr, nullptr); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest035 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest035, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "PR"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *other = CreateResConfigImpl(nullptr, nullptr, nullptr); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest036 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest036, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl(nullptr, nullptr, nullptr); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "PR"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest037 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest037, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "CN"); + ResConfigImpl *current = CreateResConfigImpl(nullptr, nullptr, nullptr); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "GB"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest038 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest038, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", "Qaag", nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "GB"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "CA"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest039 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest039, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", "Qaag", nullptr); + ResConfigImpl *current = CreateResConfigImpl(nullptr, nullptr, nullptr); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "CA"); + EXPECT_FALSE(current->IsMoreSuitable(other, request)); + EXPECT_TRUE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest040 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest040, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "CN"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "GB"); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest041 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest041, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + request->SetDirection(Direction::DIRECTION_HORIZONTAL); + current->SetDirection(Direction::DIRECTION_HORIZONTAL); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest042 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest042, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + request->SetDirection(Direction::DIRECTION_HORIZONTAL); + request->SetDeviceType(DeviceType::DEVICE_PHONE); + current->SetDirection(Direction::DIRECTION_HORIZONTAL); + current->SetDeviceType(DeviceType::DEVICE_PHONE); + other->SetDeviceType(DeviceType::DEVICE_PHONE); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest043 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest043, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + request->SetDirection(Direction::DIRECTION_HORIZONTAL); + request->SetDeviceType(DeviceType::DEVICE_PHONE); + request->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI); + current->SetDirection(Direction::DIRECTION_HORIZONTAL); + current->SetDeviceType(DeviceType::DEVICE_PHONE); + current->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI); + other->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI); + other->SetDeviceType(DeviceType::DEVICE_PHONE); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest044 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest044, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + request->SetDirection(Direction::DIRECTION_HORIZONTAL); + request->SetDeviceType(DeviceType::DEVICE_PHONE); + request->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI); + current->SetDeviceType(DeviceType::DEVICE_PHONE); + current->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI); + other->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest045 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest045, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + request->SetDirection(Direction::DIRECTION_HORIZONTAL); + request->SetDeviceType(DeviceType::DEVICE_PHONE); + request->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI); + current->SetDeviceType(DeviceType::DEVICE_PHONE); + current->SetDirection(Direction::DIRECTION_HORIZONTAL); + current->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_XLDPI); + other->SetDeviceType(DeviceType::DEVICE_PHONE); + other->SetDirection(Direction::DIRECTION_HORIZONTAL); + other->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_XXLDPI); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest046 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest046, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + request->SetDirection(Direction::DIRECTION_HORIZONTAL); + request->SetDeviceType(DeviceType::DEVICE_PHONE); + request->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI); + current->SetDeviceType(DeviceType::DEVICE_PHONE); + current->SetDirection(Direction::DIRECTION_HORIZONTAL); + current->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_MDPI); + other->SetDeviceType(DeviceType::DEVICE_PHONE); + other->SetDirection(Direction::DIRECTION_HORIZONTAL); + other->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_SDPI); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest047 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest047, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + request->SetDirection(Direction::DIRECTION_HORIZONTAL); + request->SetDeviceType(DeviceType::DEVICE_PHONE); + request->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI); + current->SetDeviceType(DeviceType::DEVICE_PHONE); + current->SetDirection(Direction::DIRECTION_HORIZONTAL); + current->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_XXXLDPI); + other->SetDeviceType(DeviceType::DEVICE_PHONE); + other->SetDirection(Direction::DIRECTION_HORIZONTAL); + other->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_SDPI); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest048 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest048, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + current->SetDeviceType(DeviceType::DEVICE_PHONE); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest049 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest049, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + current->SetDirection(Direction::DIRECTION_HORIZONTAL); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest050 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest050, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + current->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_SDPI); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} \ No newline at end of file diff --git a/global_lite/i18n_lite/resource_parse_load/src/res_config_impl_test.h b/global_lite/i18n_lite/resource_parse_load/src/res_config_impl_test.h new file mode 100755 index 0000000000000000000000000000000000000000..3a102ee5ea467446ee8a4a69f8aa857eed8f8379 --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/res_config_impl_test.h @@ -0,0 +1,99 @@ +/* + * 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 RESOURCE_MANAGER_RES_CONFIG_IMPL_TEST_H +#define RESOURCE_MANAGER_RES_CONFIG_IMPL_TEST_H + +int ResConfigImplMatchTest001(); +int ResConfigImplMatchTest002(); +int ResConfigImplMatchTest003(); +int ResConfigImplMatchTest004(); +int ResConfigImplMatchTest005(); +int ResConfigImplMatchTest006(); +int ResConfigImplMatchTest007(); +int ResConfigImplMatchTest008(); +int ResConfigImplMatchTest009(); +int ResConfigImplMatchTest010(); +int ResConfigImplMatchTest011(); +int ResConfigImplMatchTest012(); +int ResConfigImplMatchTest013(); +int ResConfigImplMatchTest014(); +int ResConfigImplMatchTest015(); +int ResConfigImplMatchTest016(); +int ResConfigImplMatchTest017(); +int ResConfigImplMatchTest018(); +int ResConfigImplMatchTest019(); +int ResConfigImplMatchTest020(); +int ResConfigImplMatchTest021(); +int ResConfigImplMatchTest022(); +int ResConfigImplMatchTest023(); +int ResConfigImplMatchTest024(); +int ResConfigImplMatchTest025(); +int ResConfigImplMatchTest026(); +int ResConfigImplMatchTest027(); +int ResConfigImplMatchTest028(); +int ResConfigImplMatchTest029(); +int ResConfigImplIsMoreSuitableTest001(); +int ResConfigImplIsMoreSuitableTest002(); +int ResConfigImplIsMoreSuitableTest003(); +int ResConfigImplIsMoreSuitableTest004(); +int ResConfigImplIsMoreSuitableTest005(); +int ResConfigImplIsMoreSuitableTest006(); +int ResConfigImplIsMoreSuitableTest007(); +int ResConfigImplIsMoreSuitableTest008(); +int ResConfigImplIsMoreSuitableTest009(); +int ResConfigImplIsMoreSuitableTest010(); +int ResConfigImplIsMoreSuitableTest011(); +int ResConfigImplIsMoreSuitableTest012(); +int ResConfigImplIsMoreSuitableTest013(); +int ResConfigImplIsMoreSuitableTest014(); +int ResConfigImplIsMoreSuitableTest015(); +int ResConfigImplIsMoreSuitableTest016(); +int ResConfigImplIsMoreSuitableTest017(); +int ResConfigImplIsMoreSuitableTest018(); +int ResConfigImplIsMoreSuitableTest019(); +int ResConfigImplIsMoreSuitableTest020(); +int ResConfigImplIsMoreSuitableTest021(); +int ResConfigImplIsMoreSuitableTest022(); +int ResConfigImplIsMoreSuitableTest023(); +int ResConfigImplIsMoreSuitableTest024(); +int ResConfigImplIsMoreSuitableTest025(); +int ResConfigImplIsMoreSuitableTest026(); +int ResConfigImplIsMoreSuitableTest027(); +int ResConfigImplIsMoreSuitableTest028(); +int ResConfigImplIsMoreSuitableTest029(); +int ResConfigImplIsMoreSuitableTest030(); +int ResConfigImplIsMoreSuitableTest031(); +int ResConfigImplIsMoreSuitableTest032(); +int ResConfigImplIsMoreSuitableTest033(); +int ResConfigImplIsMoreSuitableTest034(); +int ResConfigImplIsMoreSuitableTest035(); +int ResConfigImplIsMoreSuitableTest036(); +int ResConfigImplIsMoreSuitableTest037(); +int ResConfigImplIsMoreSuitableTest038(); +int ResConfigImplIsMoreSuitableTest039(); +int ResConfigImplIsMoreSuitableTest040(); +int ResConfigImplIsMoreSuitableTest041(); +int ResConfigImplIsMoreSuitableTest042(); +int ResConfigImplIsMoreSuitableTest043(); +int ResConfigImplIsMoreSuitableTest044(); +int ResConfigImplIsMoreSuitableTest045(); +int ResConfigImplIsMoreSuitableTest046(); +int ResConfigImplIsMoreSuitableTest047(); +int ResConfigImplIsMoreSuitableTest048(); +int ResConfigImplIsMoreSuitableTest049(); +int ResConfigImplIsMoreSuitableTest050(); + +#endif diff --git a/global_lite/i18n_lite/resource_parse_load/src/res_config_test.cpp b/global_lite/i18n_lite/resource_parse_load/src/res_config_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..2682b32ec6ef016bf557d0450102742f8b9e925c --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/res_config_test.cpp @@ -0,0 +1,77 @@ +/* + * 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 "res_config_test.h" + +#include +#include +#include + +#include "hap_resource.h" +#include "res_config.h" +#include "resource_manager_impl.h" +#include "test_common.h" + +using namespace OHOS::Global::Resource; +using namespace testing::ext; + +class ResConfigTest : public testing::Test { +public: + static void SetUpTestCase(void); + + static void TearDownTestCase(void); + + void SetUp(); + + void TearDown(); +}; + +void ResConfigTest::SetUpTestCase(void) +{ + // step 1: input testsuit setup step + g_logLevel = LOG_DEBUG; +} + +void ResConfigTest::TearDownTestCase(void) +{ + // step 2: input testsuit teardown step +} + +void ResConfigTest::SetUp() +{ +} + +void ResConfigTest::TearDown() +{ +} + +/* + * @tc.name: ResConfigFuncTest001 + * @tc.desc: Test Config function, non file case. + * @tc.type: FUNC + */ +HWTEST_F(ResConfigTest, ResConfigFuncTest001, TestSize.Level1) +{ + ResConfigImpl *rc = new ResConfigImpl; + rc->SetLocaleInfo("en", nullptr, "AU"); + ResConfigImpl *current = new ResConfigImpl; + current->SetLocaleInfo("en", nullptr, "GB"); + ResConfigImpl *target = new ResConfigImpl; + target->SetLocaleInfo("zh", nullptr, "CN"); + EXPECT_TRUE(rc->Match(current)); + EXPECT_TRUE(rc->Match(target) == false); + delete target; + delete current; + delete rc; +}; \ No newline at end of file diff --git a/global_lite/i18n_lite/resource_parse_load/src/res_config_test.h b/global_lite/i18n_lite/resource_parse_load/src/res_config_test.h new file mode 100755 index 0000000000000000000000000000000000000000..2b689eda164b35be5bfa6e7118fa939342980e22 --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/res_config_test.h @@ -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. + */ + +#ifndef RESOURCE_MANAGER_RES_CONFIG_TEST_H +#define RESOURCE_MANAGER_RES_CONFIG_TEST_H + +int ResConfigFuncTest001(); + +#endif diff --git a/global_lite/i18n_lite/resource_parse_load/src/res_desc_test.cpp b/global_lite/i18n_lite/resource_parse_load/src/res_desc_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..7b19f0b7eb5e9c1ba5655a8eb8292fe592a73b9c --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/res_desc_test.cpp @@ -0,0 +1,156 @@ +/* + * 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 "res_desc_test.h" + +#include + +#include "res_desc.h" +#include "test_common.h" +#include "utils/string_utils.h" + +using namespace OHOS::Global::Resource; +using namespace testing::ext; + +class ResDescTest : public testing::Test { +public: + static void SetUpTestCase(void); + + static void TearDownTestCase(void); + + void SetUp(); + + void TearDown(); +}; + +void ResDescTest::SetUpTestCase(void) +{ + // step 1: input testsuit setup step + g_logLevel = LOG_DEBUG; +} + +void ResDescTest::TearDownTestCase(void) +{ + // step 2: input testsuit teardown step +} + +void ResDescTest::SetUp() +{ + // step 3: input testcase setup step + HILOG_DEBUG("ResDescTest setup"); +} + +void ResDescTest::TearDown() +{ + // step 4: input testcase teardown step + HILOG_DEBUG("ResDescTest teardown"); +} + +/* + * @tc.name: ResDescFuncTest001 + * @tc.desc: Test IsRef function, non file case. + * @tc.type: FUNC + */ +HWTEST_F(ResDescTest, ResDescFuncTest001, TestSize.Level1) +{ + std::string str; + int id; + ResType resType; + str.assign("abc"); + EXPECT_TRUE(!IdItem::IsRef(str, resType, id)); + + str.assign("$abc"); + EXPECT_TRUE(!IdItem::IsRef(str, resType, id)); + + str.assign("$abc:"); + EXPECT_TRUE(!IdItem::IsRef(str, resType, id)); + + str.assign("$abc:abc"); + EXPECT_TRUE(!IdItem::IsRef(str, resType, id)); + + str.assign("$abc:123456"); + EXPECT_TRUE(!IdItem::IsRef(str, resType, id)); + + str.assign("$string:123456"); + EXPECT_TRUE(IdItem::IsRef(str, resType, id)); + EXPECT_EQ(ResType::STRING, resType); + EXPECT_EQ(123456, id); + str.assign("$boolean:100001"); + EXPECT_TRUE(IdItem::IsRef(str, resType, id)); + EXPECT_EQ(ResType::BOOLEAN, resType); + EXPECT_EQ(100001, id); + str.assign("$color:66666"); + EXPECT_TRUE(IdItem::IsRef(str, resType, id)); + EXPECT_EQ(ResType::COLOR, resType); + EXPECT_EQ(66666, id); + str.assign("$float:100002"); + EXPECT_TRUE(IdItem::IsRef(str, resType, id)); + EXPECT_EQ(ResType::FLOAT, resType); + EXPECT_EQ(100002, id); + str.assign("$integer:2008168"); + EXPECT_TRUE(IdItem::IsRef(str, resType, id)); + EXPECT_EQ(ResType::INTEGER, resType); + EXPECT_EQ(2008168, id); + str.assign("$pattern:654321"); + EXPECT_TRUE(IdItem::IsRef(str, resType, id)); + EXPECT_EQ(ResType::PATTERN, resType); + EXPECT_EQ(654321, id); + str.assign("$theme:99999"); + EXPECT_TRUE(IdItem::IsRef(str, resType, id)); + EXPECT_EQ(ResType::THEME, resType); + EXPECT_EQ(99999, id); +} + +void TestKeyParam(KeyType keyType, int value, std::string expectStr) +{ + KeyParam keyParam; + keyParam.type_ = keyType; + keyParam.value_ = value; + keyParam.InitStr(); + EXPECT_EQ(expectStr, keyParam.str_); +} + +/* + * @tc.name: ResDescFuncTest002 + * @tc.desc: Test IsRef function, non file case. + * @tc.type: FUNC + */ +HWTEST_F(ResDescTest, ResDescFuncTest002, TestSize.Level1) +{ + TestKeyParam(KeyType::LANGUAGES, 25966, "en"); + TestKeyParam(KeyType::LANGUAGES, 31336, "zh"); + + TestKeyParam(KeyType::REGION, 21843, "US"); + TestKeyParam(KeyType::REGION, 17230, "CN"); + + TestKeyParam(KeyType::DIRECTION, 0, VERTICAL); + TestKeyParam(KeyType::DIRECTION, 1, HORIZONTAL); + + TestKeyParam(KeyType::DEVICETYPE, DeviceType::DEVICE_PHONE, PHONE_STR); + TestKeyParam(KeyType::DEVICETYPE, DeviceType::DEVICE_TABLET, TABLET_STR); + TestKeyParam(KeyType::DEVICETYPE, DeviceType::DEVICE_CAR, CAR_STR); + TestKeyParam(KeyType::DEVICETYPE, DeviceType::DEVICE_PC, PC_STR); + TestKeyParam(KeyType::DEVICETYPE, DeviceType::DEVICE_TV, TV_STR); + TestKeyParam(KeyType::DEVICETYPE, DeviceType::DEVICE_WEARABLE, WEARABLE_STR); + TestKeyParam(KeyType::DEVICETYPE, DeviceType::DEVICE_NOT_SET, "not_device_type"); + + TestKeyParam(KeyType::SCREEN_DENSITY, ScreenDensity::SCREEN_DENSITY_SDPI, RE_120_STR); + TestKeyParam(KeyType::SCREEN_DENSITY, ScreenDensity::SCREEN_DENSITY_MDPI, RE_160_STR); + TestKeyParam(KeyType::SCREEN_DENSITY, ScreenDensity::SCREEN_DENSITY_LDPI, RE_240_STR); + TestKeyParam(KeyType::SCREEN_DENSITY, ScreenDensity::SCREEN_DENSITY_XLDPI, RE_320_STR); + TestKeyParam(KeyType::SCREEN_DENSITY, ScreenDensity::SCREEN_DENSITY_XXLDPI, RE_480_STR); + TestKeyParam(KeyType::SCREEN_DENSITY, ScreenDensity::SCREEN_DENSITY_XXXLDPI, RE_640_STR); + TestKeyParam(KeyType::SCREEN_DENSITY, ScreenDensity::SCREEN_DENSITY_NOT_SET, "not_screen_density"); +} \ No newline at end of file diff --git a/global_lite/i18n_lite/resource_parse_load/src/res_desc_test.h b/global_lite/i18n_lite/resource_parse_load/src/res_desc_test.h new file mode 100755 index 0000000000000000000000000000000000000000..416f3486ebafe64a9147e58fa5db62249525da51 --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/res_desc_test.h @@ -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. + */ + +#ifndef RESOURCE_MANAGER_RES_DESC_TEST_H +#define RESOURCE_MANAGER_RES_DESC_TEST_H + +int ResDescFuncTest001(); +int ResDescFuncTest002(); + +#endif diff --git a/global_lite/i18n_lite/resource_parse_load/src/resource_manager_performance_test.cpp b/global_lite/i18n_lite/resource_parse_load/src/resource_manager_performance_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..0e028d4c763583fd7debfb41c1ed6df72169a926 --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/resource_manager_performance_test.cpp @@ -0,0 +1,1055 @@ +/* + * 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 "resource_manager_performance_test.h" + +#include +#include +#include +#include +#include + +#define private public + +#include "resource_manager.h" +#include "resource_manager_impl.h" +#include "test_common.h" +#include "utils/errors.h" + +using namespace OHOS::Global::Resource; +using namespace testing::ext; +using namespace std; + +class ResourceManagerPerformanceTest : public testing::Test { +public: + static void SetUpTestCase(void); + + static void TearDownTestCase(void); + + void SetUp(); + + void TearDown(); + + ResourceManagerPerformanceTest() : rm(nullptr) + {} + + ~ResourceManagerPerformanceTest() + {} + +public: + ResourceManager *rm; + + int GetResId(std::string name, ResType resType) const; +}; + +int ResourceManagerPerformanceTest::GetResId(std::string name, ResType resType) const +{ + auto idv = ((ResourceManagerImpl *)rm)->hapManager_->GetResourceListByName(name.c_str(), resType); + if (idv == nullptr) { + return -1; + } + + if (idv->GetLimitPathsConst().size() > 0) { + return idv->GetLimitPathsConst()[0]->GetIdItem()->id_; + } + return OBJ_NOT_FOUND; +} + +void ResourceManagerPerformanceTest::SetUpTestCase(void) +{ + // step 1: input testsuit setup step +} + +void ResourceManagerPerformanceTest::TearDownTestCase(void) +{ + // step 2: input testsuit teardown step +} + +void ResourceManagerPerformanceTest::SetUp(void) +{ + // PerformanceTest need higher log level + g_logLevel = LOG_INFO; + this->rm = CreateResourceManager(); + if (rm == nullptr) { + return; + } + auto rc = CreateResConfig(); + if (rc == nullptr) { + return; + } + rc->SetLocaleInfo("zh", nullptr, nullptr); + rm->UpdateResConfig(*rc); + delete rc; + bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str()); + if (!ret) { + HILOG_ERROR("AddResource failed. test would fail."); + } +} + +void ResourceManagerPerformanceTest::TearDown(void) +{ + if (this->rm != nullptr) { + delete this->rm; + this->rm = nullptr; + } +} + +/* + * @tc.name: ResourceManagerPerformanceFuncTest001 + * @tc.desc: Test AddResource + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest001, TestSize.Level1) +{ + unsigned long long total = 0; + double average = 0; + for (int k = 0; k < 1000; ++k) { + auto tmpRm = CreateResourceManager(); + if (tmpRm == nullptr) { + EXPECT_TRUE(false); + return; + } + auto t1 = std::chrono::high_resolution_clock::now(); + tmpRm->AddResource(FormatFullPath(g_resFilePath).c_str()); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + delete tmpRm; + } + average = total / 1000.0; + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 001: %f us", average); + EXPECT_LT(average, 9000); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest002 + * @tc.desc: Test UpdateResConfig + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest002, TestSize.Level1) +{ + unsigned long long total = 0; + double average = 0; + auto tmpRm = CreateResourceManager(); + if (tmpRm == nullptr) { + EXPECT_TRUE(false); + return; + } + ResConfig *rc = CreateResConfig(); + if (rc == nullptr) { + EXPECT_TRUE(false); + delete tmpRm; + return; + } + rc->SetLocaleInfo("en", nullptr, "US"); + rc->SetDeviceType(DeviceType::DEVICE_CAR); + for (int k = 0; k < 1000; ++k) { + auto t1 = std::chrono::high_resolution_clock::now(); + tmpRm->UpdateResConfig(*rc); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + delete tmpRm; + delete rc; + average = total / 1000.0; + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 002: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest003 + * @tc.desc: Test GetResConfig + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest003, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + ResConfig *rc = CreateResConfig(); + if (rc == nullptr) { + EXPECT_TRUE(false); + return; + } + rc->SetLocaleInfo("en", nullptr, "US"); + rc->SetDeviceType(DeviceType::DEVICE_CAR); + ResConfigImpl rci; + for (int k = 0; k < 1000; ++k) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetResConfig(rci); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + delete rc; + average = total / 1000.0; + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 003: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest004 + * @tc.desc: Test GetStringByID + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest004, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + string name[] = {"app_name", "title"}; + vector ids; + int count = 2; + for (int i = 0; i < count; ++i) { + int id = GetResId(name[i], ResType::STRING); + ASSERT_TRUE(id > 0); + ids.push_back(static_cast(id)); + } + + std::string outValue; + for (int k = 0; k < 1000; ++k) { + for (int i = 0; i < count; ++i) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetStringById(ids[i], outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + } + average = total / (1000.0 * count); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 004: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest005 + * @tc.desc: Test GetStringByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest005, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + string name[] = {"app_name", "title"}; + int count = 2; + std::string outValue; + for (int k = 0; k < 1000; ++k) { + for (int i = 0; i < count; ++i) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetStringByName(name[i].c_str(), outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + } + average = total / (1000.0 * count); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 005: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest006 + * @tc.desc: Test GetStringByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest006, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + string name[] = {"string_ref", "string_ref2"}; + int count = 2; + std::string outValue; + for (int k = 0; k < 1000; ++k) { + for (int i = 0; i < count; ++i) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetStringByName(name[i].c_str(), outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + } + average = total / (1000.0 * count); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 006: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest007 + * @tc.desc: Test GetStringFormatById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest007, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + string name[] = {"app_name", "title"}; + vector ids; + int count = 2; + for (int i = 0; i < count; ++i) { + int id = GetResId(name[i], ResType::STRING); + ASSERT_TRUE(id > 0); + ids.push_back(static_cast(id)); + } + + std::string outValue; + for (int k = 0; k < 1000; ++k) { + for (int i = 0; i < count; ++i) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetStringFormatById(outValue, ids[i], 12); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + } + average = total / (1000.0 * count); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 007: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest008 + * @tc.desc: Test GetStringFormatByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest008, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + string name[] = {"app_name", "title"}; + int count = 2; + std::string outValue; + for (int k = 0; k < 1000; ++k) { + for (int i = 0; i < count; ++i) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetStringFormatByName(outValue, name[i].c_str(), 123); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + } + average = total / (1000.0 * count); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 008: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest009 + * @tc.desc: Test GetStringArrayById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest009, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + int id = GetResId("size", ResType::STRINGARRAY); + ASSERT_TRUE(id > 0); + + std::vector outValue; + for (int k = 0; k < 1000; ++k) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetStringArrayById(id, outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + average = total / 1000.0; + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 009: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest010 + * @tc.desc: Test GetStringArrayByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest010, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + std::vector outValue; + for (int k = 0; k < 1000; ++k) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetStringArrayByName("size", outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + average = total / 1000.0; + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 010: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest011 + * @tc.desc: Test GetPatternById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest011, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + string name[] = {"base", "child"}; + vector ids; + int count = 2; + for (int i = 0; i < count; ++i) { + int id = GetResId(name[i], ResType::PATTERN); + ASSERT_TRUE(id > 0); + ids.push_back(static_cast(id)); + } + std::map outValue; + for (int k = 0; k < 1000; ++k) { + for (int i = 0; i < count; ++i) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetPatternById(ids[i], outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + } + average = total / (1000.0 * count); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 011: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest012 + * @tc.desc: Test GetPatternByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest012, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + string name[] = {"base", "child"}; + int count = 2; + std::map outValue; + for (int k = 0; k < 1000; ++k) { + for (int i = 0; i < count; ++i) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetPatternByName(name[i].c_str(), outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + } + average = total / (1000.0 * count); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 012: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest013 + * @tc.desc: Test GetPluralStringById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest013, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + int quantity[] = {1, 100}; + int count = 2; + int id = GetResId("eat_apple", ResType::PLURALS); + ASSERT_TRUE(id > 0); + + string outValue; + for (int k = 0; k < 1000; ++k) { + for (int i = 0; i < count; ++i) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetPluralStringById(id, quantity[i], outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + } + average = total / (1000.0 * count); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 013: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest014 + * @tc.desc: Test GetPluralStringByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest014, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + int quantity[] = {1, 100}; + int count = 2; + string outValue; + for (int k = 0; k < 1000; ++k) { + for (int i = 0; i < count; ++i) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetPluralStringByName("eat_apple", quantity[i], outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + } + average = total / (1000.0 * count); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 014: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest015 + * @tc.desc: Test GetPluralStringByIdFormat + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest015, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + int quantity[] = {1, 100}; + int count = 2; + int id = GetResId("eat_apple", ResType::PLURALS); + ASSERT_TRUE(id > 0); + + string outValue; + for (int k = 0; k < 1000; ++k) { + for (int i = 0; i < count; ++i) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetPluralStringByIdFormat(outValue, id, quantity[i], quantity[i]); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + } + average = total / (1000.0 * count); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 015: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest016 + * @tc.desc: Test GetPluralStringByNameFormat + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest016, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + int quantity[] = {1, 100}; + int count = 2; + string outValue; + for (int k = 0; k < 1000; ++k) { + for (int i = 0; i < count; ++i) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetPluralStringByNameFormat(outValue, "eat_apple", quantity[i], quantity[i]); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + } + average = total / (1000.0 * count); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 016: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest017 + * @tc.desc: Test GetThemeById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest017, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + int id = GetResId("app_theme", ResType::THEME); + ASSERT_TRUE(id > 0); + + std::map outValue; + for (int k = 0; k < 1000; ++k) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetThemeById(id, outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + average = total / 1000.0; + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 017: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest018 + * @tc.desc: Test GetThemeByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest018, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + std::map outValue; + for (int k = 0; k < 1000; ++k) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetThemeByName("app_theme", outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + average = total / 1000.0; + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 018: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest019 + * @tc.desc: Test GetBooleanById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest019, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + int id = GetResId("boolean_1", ResType::BOOLEAN); + ASSERT_TRUE(id > 0); + + bool outValue = true; + for (int k = 0; k < 1000; ++k) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetBooleanById(id, outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + average = total / 1000.0; + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 019: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest020 + * @tc.desc: Test GetBooleanByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest020, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + bool outValue = true; + for (int k = 0; k < 1000; ++k) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetBooleanByName("boolean_1", outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + average = total / 1000.0; + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 020: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest021 + * @tc.desc: Test GetIntegerById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest021, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + int id = GetResId("integer_1", ResType::INTEGER); + ASSERT_TRUE(id > 0); + + int outValue = 0; + for (int k = 0; k < 1000; ++k) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetIntegerById(id, outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + average = total / 1000.0; + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 021: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest022 + * @tc.desc: Test GetIntegerByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest022, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + int outValue = 0; + for (int k = 0; k < 1000; ++k) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetIntegerByName("integer_ref", outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + average = total / 1000.0; + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 022: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest023 + * @tc.desc: Test GetFloatById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest023, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + int id = GetResId("width_appBar_backButton_touchTarget", ResType::FLOAT); + ASSERT_TRUE(id > 0); + + float outValue = 0.0; + for (int k = 0; k < 1000; ++k) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetFloatById(id, outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + average = total / 1000.0; + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 023: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest024 + * @tc.desc: Test GetFloatByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest024, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + float outValue = 0; + for (int k = 0; k < 1000; ++k) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetFloatByName("width_appBar_backButton_touchTarget", outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + average = total / 1000.0; + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 024: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest025 + * @tc.desc: Test GetIntArrayById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest025, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + int id = GetResId("intarray_1", ResType::INTARRAY); + ASSERT_TRUE(id > 0); + + std::vector outValue; + for (int k = 0; k < 1000; ++k) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetIntArrayById(id, outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + average = total / 1000.0; + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 025: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest026 + * @tc.desc: Test GetIntArrayByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest026, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + std::vector outValue; + for (int k = 0; k < 1000; ++k) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetIntArrayByName("intarray_1", outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + average = total / 1000.0; + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 026: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest027 + * @tc.desc: Test GetColorById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest027, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + int id = GetResId("divider_color", ResType::COLOR); + ASSERT_TRUE(id > 0); + + uint32_t outValue; + for (int k = 0; k < 1000; ++k) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetColorById(id, outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + average = total / 1000.0; + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 027: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest028 + * @tc.desc: Test GetColorByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest028, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + uint32_t outValue; + for (int k = 0; k < 1000; ++k) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetColorByName("divider_color", outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + average = total / 1000.0; + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 028: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest029 + * @tc.desc: Test GetProfileById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest029, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + int id = GetResId("test_common", ResType::PROF); + ASSERT_TRUE(id > 0); + + string outValue; + for (int k = 0; k < 1000; ++k) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetProfileById(id, outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + average = total / 1000.0; + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 029: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest030 + * @tc.desc: Test GetProfileByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest030, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + string outValue; + for (int k = 0; k < 1000; ++k) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetProfileByName("test_common", outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + average = total / 1000.0; + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 030: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest031 + * @tc.desc: Test GetMediaById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest031, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + int id = GetResId("icon", ResType::MEDIA); + ASSERT_TRUE(id > 0); + + string outValue; + for (int k = 0; k < 1000; ++k) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetMediaById(id, outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + average = total / 1000.0; + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 031: %f us", average); + EXPECT_LT(average, 500); +}; + +/* + * @tc.name: ResourceManagerPerformanceFuncTest032 + * @tc.desc: Test GetMediaByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest032, TestSize.Level1) +{ + if (rm == nullptr) { + EXPECT_TRUE(false); + return; + } + unsigned long long total = 0; + double average = 0; + string outValue; + for (int k = 0; k < 1000; ++k) { + auto t1 = std::chrono::high_resolution_clock::now(); + rm->GetMediaByName("icon", outValue); + auto t2 = std::chrono::high_resolution_clock::now(); + total += std::chrono::duration_cast(t2 - t1).count(); + } + average = total / 1000.0; + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 032: %f us", average); + EXPECT_LT(average, 500); +}; diff --git a/global_lite/i18n_lite/resource_parse_load/src/resource_manager_performance_test.h b/global_lite/i18n_lite/resource_parse_load/src/resource_manager_performance_test.h new file mode 100755 index 0000000000000000000000000000000000000000..7269ed78ad136a794094e58cdfc7b3ab32e94d8e --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/resource_manager_performance_test.h @@ -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. + */ + +#ifndef RESOURCE_MANAGER_RESOURCE_MANANGER_PERF_TEST_H +#define RESOURCE_MANAGER_RESOURCE_MANANGER_PERF_TEST_H + +int ResourceManagerPerformanceFuncTest001(); +int ResourceManagerPerformanceFuncTest002(); +int ResourceManagerPerformanceFuncTest003(); +int ResourceManagerPerformanceFuncTest004(); +int ResourceManagerPerformanceFuncTest005(); +int ResourceManagerPerformanceFuncTest006(); +int ResourceManagerPerformanceFuncTest007(); +int ResourceManagerPerformanceFuncTest008(); +int ResourceManagerPerformanceFuncTest009(); +int ResourceManagerPerformanceFuncTest010(); +int ResourceManagerPerformanceFuncTest011(); +int ResourceManagerPerformanceFuncTest012(); +int ResourceManagerPerformanceFuncTest013(); +int ResourceManagerPerformanceFuncTest014(); +int ResourceManagerPerformanceFuncTest015(); +int ResourceManagerPerformanceFuncTest016(); +int ResourceManagerPerformanceFuncTest017(); +int ResourceManagerPerformanceFuncTest018(); +int ResourceManagerPerformanceFuncTest019(); +int ResourceManagerPerformanceFuncTest020(); +int ResourceManagerPerformanceFuncTest021(); +int ResourceManagerPerformanceFuncTest022(); +int ResourceManagerPerformanceFuncTest023(); +int ResourceManagerPerformanceFuncTest024(); +int ResourceManagerPerformanceFuncTest025(); +int ResourceManagerPerformanceFuncTest026(); +int ResourceManagerPerformanceFuncTest027(); +int ResourceManagerPerformanceFuncTest028(); +int ResourceManagerPerformanceFuncTest029(); +int ResourceManagerPerformanceFuncTest030(); +int ResourceManagerPerformanceFuncTest031(); +int ResourceManagerPerformanceFuncTest032(); + +#endif diff --git a/global_lite/i18n_lite/resource_parse_load/src/resource_manager_test.cpp b/global_lite/i18n_lite/resource_parse_load/src/resource_manager_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..78896733b748ddbc80bbe9476b667016a8fbec9f --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/resource_manager_test.cpp @@ -0,0 +1,1703 @@ +/* + * 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 "resource_manager_test.h" + +#include +#include +#include +#define private public + +#include "res_config.h" +#include "resource_manager.h" +#include "resource_manager_impl.h" +#include "test_common.h" +#include "utils/errors.h" +#include "utils/string_utils.h" + +using namespace OHOS::Global::Resource; +using namespace testing::ext; + +static const int NON_EXIST_ID = 1111; + +static const char *g_nonExistName = "non_existent_name"; +class ResourceManagerTest : public testing::Test { +public: + static void SetUpTestCase(void); + + static void TearDownTestCase(void); + + void SetUp(); + + void TearDown(); + + ResourceManagerTest() : rm(nullptr) + {} + + ~ResourceManagerTest() + {} + +public: + ResourceManager *rm; + + int GetResId(std::string name, ResType resType) const; + + void TestStringByName(const char *name, const char *cmp) const; + + void TestStringById(const char *name, const char *cmp) const; + + void TestPluralStringById(int quantity, const char *cmp, bool format = false) const; + + void TestPluralStringByName(int quantity, const char *cmp, bool format = false) const; + + void AddResource(const char *language, const char *script, const char *region); +}; + +int ResourceManagerTest::GetResId(std::string name, ResType resType) const +{ + auto idv = ((ResourceManagerImpl *)rm)->hapManager_->GetResourceListByName(name.c_str(), resType); + if (idv == nullptr) { + return -1; + } + + PrintIdValues(idv); + if (idv->GetLimitPathsConst().size() > 0) { + return idv->GetLimitPathsConst()[0]->GetIdItem()->id_; + } + return OBJ_NOT_FOUND; +} + +void ResourceManagerTest::TestStringByName(const char *name, const char *cmp) const +{ + RState rState; + std::string outValue; + rState = rm->GetStringByName(name, outValue); + ASSERT_EQ(SUCCESS, rState); + HILOG_DEBUG("%s : %s", name, outValue.c_str()); + ASSERT_EQ(std::string(cmp), outValue); +} + +void ResourceManagerTest::TestStringById(const char *name, const char *cmp) const +{ + RState rState; + std::string outValue; + int id = GetResId(name, ResType::STRING); + ASSERT_TRUE(id > 0); + rState = rm->GetStringById(id, outValue); + ASSERT_EQ(SUCCESS, rState); + ASSERT_EQ(std::string(cmp), outValue); +} + +void ResourceManagerTest::AddResource(const char *language, const char *script, const char *region) +{ + if (language != nullptr || region != nullptr) { + auto rc = CreateResConfig(); + if (rc == nullptr) { + EXPECT_TRUE(false); + return; + } + rc->SetLocaleInfo(language, script, region); + rm->UpdateResConfig(*rc); + delete rc; + } + bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str()); + ASSERT_TRUE(ret); +} + +void ResourceManagerTest::TestPluralStringById(int quantity, const char *cmp, bool format) const +{ + RState ret; + std::string outValue; + int id = GetResId("eat_apple", ResType::PLURALS); + if (format) { + ret = rm->GetPluralStringByIdFormat(outValue, id, quantity, quantity); + } else { + ret = rm->GetPluralStringById(id, quantity, outValue); + } + + ASSERT_EQ(SUCCESS, ret); + ASSERT_EQ(std::string(cmp), outValue); +} + +void ResourceManagerTest::TestPluralStringByName(int quantity, const char *cmp, bool format) const +{ + RState ret; + std::string outValue; + const char *name = "eat_apple"; + if (format) { + ret = rm->GetPluralStringByNameFormat(outValue, name, quantity, quantity); + } else { + ret = rm->GetPluralStringByName(name, quantity, outValue); + } + + ASSERT_EQ(SUCCESS, ret); + ASSERT_EQ(std::string(cmp), outValue); +} + +void ResourceManagerTest::SetUpTestCase(void) +{ + // step 1: input testsuit setup step + g_logLevel = LOG_DEBUG; +} + +void ResourceManagerTest::TearDownTestCase(void) +{ + // step 2: input testsuit teardown step +} + +void ResourceManagerTest::SetUp(void) +{ + this->rm = CreateResourceManager(); +} + +void ResourceManagerTest::TearDown(void) +{ + delete this->rm; +} + +/* + * @tc.name: ResourceManagerAddResourceTest001 + * @tc.desc: Test AddResource function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerAddResourceTest001, TestSize.Level1) +{ + // success cases + bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str()); + ASSERT_TRUE(ret); +}; + +/* + * @tc.name: ResourceManagerAddResourceTest002 + * @tc.desc: Test AddResource function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerAddResourceTest002, TestSize.Level1) +{ + // error cases + // file not exist + bool ret = rm->AddResource("/data/test/do_not_exist.resources"); + ASSERT_TRUE(!ret); +} + +/* + * @tc.name: ResourceManagerAddResourceTest003 + * @tc.desc: Test AddResource function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerAddResourceTest003, TestSize.Level1) +{ + // error cases + // reload the same path + bool ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str()); + ASSERT_TRUE(ret); + ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str()); + ASSERT_TRUE(!ret); +} + +/* + * @tc.name: ResourceManagerUpdateResConfigTest001 + * @tc.desc: Test UpdateResConfig function + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerUpdateResConfigTest001, TestSize.Level1) +{ + // success cases + RState state; + ResConfig *rc = CreateResConfig(); + if (rc == nullptr) { + EXPECT_TRUE(false); + return; + } + rc->SetLocaleInfo("en", nullptr, "US"); + rc->SetDeviceType(DeviceType::DEVICE_CAR); + state = rm->UpdateResConfig(*rc); + delete rc; + EXPECT_EQ(SUCCESS, state); +} + +/* + * @tc.name: ResourceManagerUpdateResConfigTest002 + * @tc.desc: Test UpdateResConfig function + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerUpdateResConfigTest002, TestSize.Level1) +{ + // error cases + RState state; + ResConfig *rc = CreateResConfig(); + if (rc == nullptr) { + EXPECT_TRUE(false); + return; + } + state = rm->UpdateResConfig(*rc); + delete rc; + EXPECT_EQ(LOCALEINFO_IS_NULL, state); +} + +/* + * @tc.name: ResourceManagerUpdateResConfigTest003 + * @tc.desc: Test UpdateResConfig function + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerUpdateResConfigTest003, TestSize.Level1) +{ + // error cases + RState state; + ResConfig *rc = CreateResConfig(); + if (rc == nullptr) { + EXPECT_TRUE(false); + return; + } + rc->SetLocaleInfo(nullptr, nullptr, "US"); + state = rm->UpdateResConfig(*rc); + delete rc; + EXPECT_EQ(LOCALEINFO_IS_NULL, state); +} + +/* + * load a hap, defaultConfig set to en, then switch to zh + * @tc.name: ResourceManagerUpdateResConfigTest004 + * @tc.desc: Test UpdateResConfig function + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerUpdateResConfigTest004, TestSize.Level1) +{ + // success case + bool ret = true; + RState state; + ResConfig *rc = CreateResConfig(); + if (rc == nullptr) { + EXPECT_TRUE(false); + return; + } + rc->SetLocaleInfo("en", nullptr, nullptr); + state = rm->UpdateResConfig(*rc); + EXPECT_EQ(SUCCESS, state); + ret = rm->AddResource(FormatFullPath(g_resFilePath).c_str()); + if (!ret) { + EXPECT_TRUE(false); + delete rc; + return; + } + // update to another language, will trigger reload + // before reload: + TestStringByName("app_name", "App Name"); + + rc->SetLocaleInfo("zh", nullptr, nullptr); + state = rm->UpdateResConfig(*rc); + delete rc; + EXPECT_EQ(SUCCESS, state); + // after reload: + TestStringByName("app_name", "应用名称"); +} + +/* + * @tc.name: ResourceManagerUpdateResConfigTest005 + * @tc.desc: Test UpdateResConfig function + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerUpdateResConfigTest005, TestSize.Level1) +{ + // error case + AddResource("zh", nullptr, nullptr); + + // make a fake hapResource, then reload will fail + HapResource *hapResource = new HapResource("/data/test/non_exist", 0, nullptr, nullptr); + ((ResourceManagerImpl *)rm)->hapManager_->hapResources_.push_back(hapResource); + RState state; + ResConfig *rc = CreateResConfig(); + if (rc == nullptr) { + EXPECT_TRUE(false); + return; + } + rc->SetLocaleInfo("en", nullptr, "US"); + state = rm->UpdateResConfig(*rc); + delete rc; + EXPECT_EQ(HAP_INIT_FAILED, state); +} + +/* + * @tc.name: ResourceManagerGetResConfigTest001 + * @tc.desc: Test GetResConfig function + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetResConfigTest001, TestSize.Level1) +{ + // success cases + ResConfigImpl rc; + rm->GetResConfig(rc); + EXPECT_EQ(nullptr, rc.GetLocaleInfo()); + EXPECT_EQ(DIRECTION_NOT_SET, rc.GetDirection()); + EXPECT_EQ(SCREEN_DENSITY_NOT_SET, rc.GetScreenDensity()); + EXPECT_EQ(DEVICE_NOT_SET, rc.GetDeviceType()); +} + +/* + * @tc.name: ResourceManagerGetResConfigTest002 + * @tc.desc: Test GetResConfig function + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetResConfigTest002, TestSize.Level1) +{ + // success cases + RState state; + { + ResConfig *rc = CreateResConfig(); + if (rc == nullptr) { + EXPECT_TRUE(false); + return; + } + rc->SetLocaleInfo("en", nullptr, "US"); + rc->SetDeviceType(DeviceType::DEVICE_CAR); + state = rm->UpdateResConfig(*rc); + delete rc; + EXPECT_EQ(SUCCESS, state); + } + + ResConfigImpl rc; + rm->GetResConfig(rc); + EXPECT_EQ("en", std::string(rc.GetLocaleInfo()->GetLanguage())); + EXPECT_EQ(DEVICE_CAR, rc.GetDeviceType()); +} + +/* + * @tc.name: ResourceManagerGetStringByIdTest001 + * @tc.desc: Test GetStringById function + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetStringByIdTest001, TestSize.Level1) +{ + AddResource("en", nullptr, nullptr); + + TestStringById("app_name", "App Name"); + + TestStringById("copyright_text", "XXXXXX All rights reserved. ©2011-2019"); + + TestStringById("string_ref", "XXXXXX All rights reserved. ©2011-2019"); + + TestStringById("string_ref2", "XXXXXX All rights reserved. ©2011-2019"); +} + +/* + * @tc.name: ResourceManagerGetStringByIdTest002 + * @tc.desc: Test GetStringById function + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetStringByIdTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, nullptr); + + TestStringById("app_name", "应用名称"); + + TestStringById("copyright_text", "版权所有 ©2011-2019 XXXX有限公司保留一切权利"); + + TestStringById("string_ref", "$aaaaa"); + + TestStringById("string_ref2", "$aaaaa"); +} + +/* + * @tc.name: ResourceManagerGetStringByIdTest003 + * @tc.desc: Test GetStringById function + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetStringByIdTest003, TestSize.Level1) +{ + AddResource("zh", nullptr, nullptr); + + std::string outValue; + RState state = rm->GetStringById(NON_EXIST_ID, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetStringByNameTest001 + * @tc.desc: Test GetStringByName function + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetStringByNameTest001, TestSize.Level1) +{ + AddResource("en", nullptr, nullptr); + + TestStringByName("app_name", "App Name"); + + TestStringByName("copyright_text", "XXXXXX All rights reserved. ©2011-2019"); + + TestStringByName("string_ref", "XXXXXX All rights reserved. ©2011-2019"); + + TestStringByName("string_ref2", "XXXXXX All rights reserved. ©2011-2019"); +} + +/* + * @tc.name: ResourceManagerGetStringByNameTest002 + * @tc.desc: Test GetStringByName function + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetStringByNameTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, nullptr); + + TestStringByName("app_name", "应用名称"); + + TestStringByName("copyright_text", "版权所有 ©2011-2019 XXXX有限公司保留一切权利"); + + TestStringByName("string_ref", "$aaaaa"); + + TestStringByName("string_ref2", "$aaaaa"); +} + +/* + * @tc.name: ResourceManagerGetStringByNameTest003 + * @tc.desc: Test GetStringByName function + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetStringByNameTest003, TestSize.Level1) +{ + AddResource("zh", nullptr, nullptr); + + std::string outValue; + RState state = rm->GetStringByName(g_nonExistName, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetStringFormatByIdTest001 + * @tc.desc: Test GetStringFormatById function + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetStringFormatByIdTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, nullptr); + + const char *name = "app_name"; + int id = GetResId(name, ResType::STRING); + ASSERT_TRUE(id > 0); + std::string outValue; + RState state = rm->GetStringFormatById(outValue, id, 101); + ASSERT_EQ(SUCCESS, state); + ASSERT_EQ("应用名称", outValue); +} + +/* + * @tc.name: ResourceManagerGetStringFormatByIdTest002 + * @tc.desc: Test GetStringFormatById function + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetStringFormatByIdTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, nullptr); + + std::string outValue; + RState state = rm->GetStringFormatById(outValue, NON_EXIST_ID, 101); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetStringFormatByNameTest001 + * @tc.desc: Test GetStringFormatByName function + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetStringFormatByNameTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, nullptr); + + const char *name = "app_name"; + std::string outValue; + RState state = rm->GetStringFormatByName(outValue, name, 101); + ASSERT_EQ(SUCCESS, state); + ASSERT_EQ("应用名称", outValue); +} + +/* + * @tc.name: ResourceManagerGetStringFormatByNameTest002 + * @tc.desc: Test GetStringFormatByName function + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetStringFormatByNameTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, nullptr); + + std::string outValue; + RState state = rm->GetStringFormatByName(outValue, g_nonExistName, 101); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetStringArrayByIdTest001 + * @tc.desc: Test GetStringArrayById function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetStringArrayByIdTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, nullptr); + + int id; + std::vector outValue; + RState state; + + id = GetResId("size", ResType::STRINGARRAY); + state = rm->GetStringArrayById(id, outValue); + ASSERT_EQ(SUCCESS, state); + ASSERT_EQ(static_cast(4), outValue.size()); + PrintVectorString(outValue); + + // by name + state = rm->GetStringArrayByName("size", outValue); + ASSERT_EQ(SUCCESS, state); + ASSERT_EQ(static_cast(4), outValue.size()); + PrintVectorString(outValue); +} + +/* + * @tc.name: ResourceManagerGetStringArrayByIdTest002 + * @tc.desc: Test GetStringArrayById function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetStringArrayByIdTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, nullptr); + + RState state; + // error case + // not found case + std::vector outValue; + state = rm->GetStringArrayById(NON_EXIST_ID, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetStringArrayByNameTest001 + * @tc.desc: Test GetStringArrayByName function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetStringArrayByNameTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, nullptr); + + std::vector outValue; + RState state; + + // by name + state = rm->GetStringArrayByName("size", outValue); + ASSERT_EQ(SUCCESS, state); + ASSERT_EQ(static_cast(4), outValue.size()); + PrintVectorString(outValue); +} + +/* + * @tc.name: ResourceManagerGetStringArrayByNameTest002 + * @tc.desc: Test GetStringArrayByName function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetStringArrayByNameTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, nullptr); + + RState state; + // error case + // not found case + std::vector outValue; + state = rm->GetStringArrayByName(g_nonExistName, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetPatternByIdTest001 + * @tc.desc: Test GetPatternById function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetPatternByIdTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, nullptr); + + int id; + std::map outValue; + RState state; + + id = GetResId("base", ResType::PATTERN); + state = rm->GetPatternById(id, outValue); + ASSERT_EQ(SUCCESS, state); + ASSERT_EQ(static_cast(3), outValue.size()); + PrintMapString(outValue); +} + +/* + * @tc.name: ResourceManagerGetPatternByIdTest002 + * @tc.desc: Test GetPatternById function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetPatternByIdTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, nullptr); + + int id; + std::map outValue; + RState state; + + id = GetResId("child", ResType::PATTERN); + state = rm->GetPatternById(id, outValue); + ASSERT_EQ(SUCCESS, state); + ASSERT_EQ(static_cast(4), outValue.size()); + PrintMapString(outValue); +} + +/* + * @tc.name: ResourceManagerGetPatternByIdTest003 + * @tc.desc: Test GetPatternById function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetPatternByIdTest003, TestSize.Level1) +{ + AddResource("zh", nullptr, nullptr); + + int id; + std::map outValue; + RState state; + + id = GetResId("ccchild", ResType::PATTERN); + state = rm->GetPatternById(id, outValue); + ASSERT_EQ(SUCCESS, state); + ASSERT_EQ(static_cast(5), outValue.size()); + PrintMapString(outValue); +} + +/* + * @tc.name: ResourceManagerGetPatternByIdTest004 + * @tc.desc: Test GetPatternById function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetPatternByIdTest004, TestSize.Level1) +{ + AddResource("zh", nullptr, nullptr); + + std::map outValue; + RState state; + + // not found case + state = rm->GetPatternById(NON_EXIST_ID, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetPatternByNameTest001 + * @tc.desc: Test GetPatternByName function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetPatternByNameTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, nullptr); + + std::map outValue; + RState state; + + state = rm->GetPatternByName("base", outValue); + ASSERT_EQ(SUCCESS, state); + ASSERT_EQ(static_cast(3), outValue.size()); + PrintMapString(outValue); +} + +/* + * @tc.name: ResourceManagerGetPatternByNameTest002 + * @tc.desc: Test GetPatternByName function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetPatternByNameTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, nullptr); + + std::map outValue; + RState state; + + state = rm->GetPatternByName("child", outValue); + ASSERT_EQ(SUCCESS, state); + ASSERT_EQ(static_cast(4), outValue.size()); + PrintMapString(outValue); +} + +/* + * @tc.name: ResourceManagerGetPatternByNameTest003 + * @tc.desc: Test GetPatternByName function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetPatternByNameTest003, TestSize.Level1) +{ + AddResource("zh", nullptr, nullptr); + + std::map outValue; + RState state; + + state = rm->GetPatternByName("ccchild", outValue); + ASSERT_EQ(SUCCESS, state); + ASSERT_EQ(static_cast(5), outValue.size()); + PrintMapString(outValue); +} + +/* + * @tc.name: ResourceManagerGetPatternByNameTest004 + * @tc.desc: Test GetPatternByName function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetPatternByNameTest004, TestSize.Level1) +{ + AddResource("zh", nullptr, nullptr); + + std::map outValue; + RState state; + + // not found case + state = rm->GetPatternByName(g_nonExistName, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetPluralStringByIdTest001 + * @tc.desc: Test GetPluralStringById function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetPluralStringByIdTest001, TestSize.Level1) +{ + AddResource("en", nullptr, "US"); + + int quantity = 1; + TestPluralStringById(quantity, "%d apple", false); + + quantity = 101; + TestPluralStringById(quantity, "%d apples", false); +} + +/* + * @tc.name: ResourceManagerGetPluralStringByIdTest002 + * @tc.desc: Test GetPluralStringById function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetPluralStringByIdTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + int quantity = 1; + TestPluralStringById(quantity, "%d apples", false); + + quantity = 101; + TestPluralStringById(quantity, "%d apples", false); +} + +/* + * @tc.name: ResourceManagerGetPluralStringByIdTest003 + * @tc.desc: Test GetPluralStringById function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetPluralStringByIdTest003, TestSize.Level1) +{ + AddResource("pl", nullptr, "PL"); + + int quantity = 1; + TestPluralStringById(quantity, "1 jabłko"); + + quantity = 2; + TestPluralStringById(quantity, "%d jabłka"); + + quantity = 23; + TestPluralStringById(quantity, "%d jabłka"); + + quantity = 12; + TestPluralStringById(quantity, "%d jabłek"); +} + +/* + * @tc.name: ResourceManagerGetPluralStringByIdTest004 + * @tc.desc: Test GetPluralStringById function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetPluralStringByIdTest004, TestSize.Level1) +{ + AddResource("ar", nullptr, "SA"); + + int quantity = 0; + TestPluralStringById(quantity, "zero-0"); + quantity = 1; + TestPluralStringById(quantity, "one-1"); + quantity = 2; + TestPluralStringById(quantity, "two-2"); + quantity = 5; + TestPluralStringById(quantity, "few-%d"); + quantity = 12; + TestPluralStringById(quantity, "many-%d"); + quantity = 500; + TestPluralStringById(quantity, "other-%d"); +} + +/* + * @tc.name: ResourceManagerGetPluralStringByIdTest005 + * @tc.desc: Test GetPluralStringById function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetPluralStringByIdTest005, TestSize.Level1) +{ + AddResource("ar", nullptr, "SA"); + + RState state; + std::string outValue; + state = rm->GetPluralStringById(NON_EXIST_ID, 1, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetPluralStringByNameTest001 + * @tc.desc: Test GetPluralStringByName function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetPluralStringByNameTest001, TestSize.Level1) +{ + AddResource("en", nullptr, "US"); + + int quantity = 1; + TestPluralStringByName(quantity, "%d apple", false); + + quantity = 101; + TestPluralStringByName(quantity, "%d apples", false); +} + +/* + * @tc.name: ResourceManagerGetPluralStringByNameTest002 + * @tc.desc: Test GetPluralStringByName function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetPluralStringByNameTest002, TestSize.Level1) +{ + AddResource("ar", nullptr, "SA"); + + RState state; + std::string outValue; + state = rm->GetPluralStringByName(g_nonExistName, 1, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetPluralStringByIdFormatTest001 + * @tc.desc: Test GetPluralStringByIdFormat function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetPluralStringByIdFormatTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + int quantity = 1; + TestPluralStringById(quantity, "1 apples", true); + + quantity = 101; + TestPluralStringById(quantity, "101 apples", true); +} + +/* + * @tc.name: ResourceManagerGetPluralStringByIdFormatTest002 + * @tc.desc: Test GetPluralStringByIdFormat function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetPluralStringByIdFormatTest002, TestSize.Level1) +{ + AddResource("ar", nullptr, "SA"); + + RState state; + std::string outValue; + state = rm->GetPluralStringByIdFormat(outValue, NON_EXIST_ID, 1, 1); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetPluralStringByNameFormatTest001 + * @tc.desc: Test GetPluralStringByNameFormat function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetPluralStringByNameFormatTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + int quantity = 1; + TestPluralStringByName(quantity, "1 apples", true); + + quantity = 101; + TestPluralStringByName(quantity, "101 apples", true); +} + +/* + * @tc.name: ResourceManagerGetPluralStringByNameFormatTest002 + * @tc.desc: Test GetPluralStringByNameFormat function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetPluralStringByNameFormatTest002, TestSize.Level1) +{ + AddResource("ar", nullptr, "SA"); + + RState state; + std::string outValue; + state = rm->GetPluralStringByNameFormat(outValue, g_nonExistName, 1, 1); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetThemeByIdTest001 + * @tc.desc: Test GetThemeById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetThemeByIdTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + std::map outValue; + RState state; + int id = GetResId("app_theme", ResType::THEME); + ASSERT_TRUE(id > 0); + state = rm->GetThemeById(id, outValue); + ASSERT_EQ(SUCCESS, state); + PrintMapString(outValue); +} + +/* + * @tc.name: ResourceManagerGetThemeByIdTest002 + * @tc.desc: Test GetThemeById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetThemeByIdTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + std::map outValue; + RState state; + state = rm->GetThemeById(NON_EXIST_ID, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetThemeByNameTest001 + * @tc.desc: Test GetThemeByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetThemeByNameTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + std::map outValue; + RState state; + state = rm->GetThemeByName("app_theme", outValue); + ASSERT_EQ(SUCCESS, state); + PrintMapString(outValue); + + state = rm->GetThemeByName("activity_theme", outValue); + ASSERT_EQ(SUCCESS, state); + PrintMapString(outValue); +} + +/* + * @tc.name: ResourceManagerGetThemeByNameTest002 + * @tc.desc: Test GetThemeByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetThemeByNameTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + std::map outValue; + RState state; + state = rm->GetThemeByName(g_nonExistName, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetBooleanByIdTest001 + * @tc.desc: Test GetBooleanById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetBooleanByIdTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + bool outValue = true; + RState state; + int id = GetResId("boolean_1", ResType::BOOLEAN); + ASSERT_TRUE(id > 0); + state = rm->GetBooleanById(id, outValue); + ASSERT_EQ(SUCCESS, state); + EXPECT_TRUE(outValue); + + id = GetResId("boolean_ref", ResType::BOOLEAN); + ASSERT_TRUE(id > 0); + state = rm->GetBooleanById(id, outValue); + ASSERT_EQ(SUCCESS, state); + EXPECT_TRUE(outValue); +} + +/* + * @tc.name: ResourceManagerGetBooleanByIdTest002 + * @tc.desc: Test GetBooleanById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetBooleanByIdTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + bool outValue = true; + RState state; + state = rm->GetBooleanById(NON_EXIST_ID, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetBooleanByNameTest001 + * @tc.desc: Test GetBooleanByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetBooleanByNameTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + bool outValue = true; + RState state; + state = rm->GetBooleanByName("boolean_1", outValue); + ASSERT_EQ(SUCCESS, state); + EXPECT_TRUE(outValue); + + state = rm->GetBooleanByName("boolean_ref", outValue); + ASSERT_EQ(SUCCESS, state); + EXPECT_TRUE(outValue); +} + +/* + * @tc.name: ResourceManagerGetBooleanByNameTest002 + * @tc.desc: Test GetBooleanByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetBooleanByNameTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + bool outValue = true; + RState state; + state = rm->GetBooleanByName(g_nonExistName, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetIntegerByIdTest001 + * @tc.desc: Test GetIntegerById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetIntegerByIdTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + int outValue; + RState state; + int id = GetResId("integer_1", ResType::INTEGER); + ASSERT_TRUE(id > 0); + state = rm->GetIntegerById(id, outValue); + ASSERT_EQ(SUCCESS, state); + EXPECT_EQ(101, outValue); + + id = GetResId("integer_ref", ResType::INTEGER); + ASSERT_TRUE(id > 0); + state = rm->GetIntegerById(id, outValue); + ASSERT_EQ(SUCCESS, state); + EXPECT_EQ(101, outValue); +} + +/* + * @tc.name: ResourceManagerGetIntegerByIdTest002 + * @tc.desc: Test GetIntegerById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetIntegerByIdTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + int outValue; + RState state; + state = rm->GetIntegerById(NON_EXIST_ID, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetIntegerByNameTest001 + * @tc.desc: Test GetIntegerByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetIntegerByNameTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + int outValue; + RState state; + state = rm->GetIntegerByName("integer_1", outValue); + ASSERT_EQ(SUCCESS, state); + EXPECT_EQ(101, outValue); + + state = rm->GetIntegerByName("integer_ref", outValue); + ASSERT_EQ(SUCCESS, state); + EXPECT_EQ(101, outValue); +} + +/* + * @tc.name: ResourceManagerGetIntegerByNameTest002 + * @tc.desc: Test GetIntegerByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetIntegerByNameTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + int outValue; + RState state; + state = rm->GetIntegerByName(g_nonExistName, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetFloatByIdTest001 + * @tc.desc: Test GetFloatById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetFloatByIdTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + float outValue; + RState state; + int id = GetResId("width_appBar_backButton_touchTarget", ResType::FLOAT); + ASSERT_TRUE(id > 0); + state = rm->GetFloatById(id, outValue); + ASSERT_EQ(SUCCESS, state); + EXPECT_EQ(48, outValue); // 50vp + + id = GetResId("float_ref", ResType::FLOAT); + ASSERT_TRUE(id > 0); + state = rm->GetFloatById(id, outValue); + ASSERT_EQ(SUCCESS, state); + EXPECT_EQ(707, outValue); // 48vp +} + +/* + * @tc.name: ResourceManagerGetFloatByIdTest002 + * @tc.desc: Test GetFloatById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetFloatByIdTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + float outValue; + RState state; + state = rm->GetFloatById(NON_EXIST_ID, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetFloatByNameTest001 + * @tc.desc: Test GetFloatByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetFloatByNameTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + float outValue; + RState state; + state = rm->GetFloatByName("width_appBar_backButton_touchTarget", outValue); + ASSERT_EQ(SUCCESS, state); + EXPECT_EQ(48, outValue); // 50vp + + state = rm->GetFloatByName("float_ref", outValue); + ASSERT_EQ(SUCCESS, state); + EXPECT_EQ(707, outValue); // 48vp +} + +/* + * @tc.name: ResourceManagerGetFloatByNameTest002 + * @tc.desc: Test GetFloatByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetFloatByNameTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + float outValue; + RState state; + state = rm->GetFloatByName(g_nonExistName, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetIntArrayByIdTest001 + * @tc.desc: Test GetIntArrayById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetIntArrayByIdTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + std::vector outValue; + RState state; + int id = GetResId("intarray_1", ResType::INTARRAY); + EXPECT_TRUE(id > 0); + state = rm->GetIntArrayById(id, outValue); + EXPECT_TRUE(state == SUCCESS); + EXPECT_EQ(static_cast(3), outValue.size()); + EXPECT_EQ(100, outValue[0]); + EXPECT_EQ(200, outValue[1]); + EXPECT_EQ(101, outValue[2]); +} + +/* + * @tc.name: ResourceManagerGetIntArrayByIdTest002 + * @tc.desc: Test GetIntArrayById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetIntArrayByIdTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + std::vector outValue; + RState state; + state = rm->GetIntArrayById(NON_EXIST_ID, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetIntArrayByNameTest001 + * @tc.desc: Test GetIntArrayByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetIntArrayByNameTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + std::vector outValue; + RState state; + state = rm->GetIntArrayByName("intarray_1", outValue); + EXPECT_TRUE(state == SUCCESS); + EXPECT_EQ(static_cast(3), outValue.size()); + EXPECT_EQ(100, outValue[0]); + EXPECT_EQ(200, outValue[1]); + EXPECT_EQ(101, outValue[2]); +} + +/* + * @tc.name: ResourceManagerGetIntArrayByNameTest002 + * @tc.desc: Test GetIntArrayByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetIntArrayByNameTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + std::vector outValue; + RState state; + state = rm->GetIntArrayByName(g_nonExistName, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetColorByIdTest001 + * @tc.desc: Test GetColorById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetColorByIdTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + uint32_t outValue; + RState state; + int id = GetResId("divider_color", ResType::COLOR); + EXPECT_TRUE(id > 0); + state = rm->GetColorById(id, outValue); + EXPECT_TRUE(state == SUCCESS); + EXPECT_EQ(static_cast(268435456), outValue); // #10000000 + + id = GetResId("color_aboutPage_title_primary", ResType::COLOR); + EXPECT_TRUE(id > 0); + state = rm->GetColorById(id, outValue); + EXPECT_TRUE(state == SUCCESS); + EXPECT_EQ(4279834905, outValue); // #191919 +} + +/* + * @tc.name: ResourceManagerGetColorByIdTest002 + * @tc.desc: Test GetColorById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetColorByIdTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + uint32_t outValue; + RState state; + state = rm->GetColorById(NON_EXIST_ID, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetColorByNameTest001 + * @tc.desc: Test GetColorByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetColorByNameTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + uint32_t outValue; + RState state; + state = rm->GetColorByName("divider_color", outValue); + EXPECT_TRUE(state == SUCCESS); + EXPECT_EQ(static_cast(268435456), outValue); // #10000000 + + state = rm->GetColorByName("color_aboutPage_title_primary", outValue); + EXPECT_TRUE(state == SUCCESS); + EXPECT_EQ(4279834905, outValue); // #191919 +} + +/* + * @tc.name: ResourceManagerGetColorByNameTest002 + * @tc.desc: Test GetColorByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetColorByNameTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + uint32_t outValue; + RState state; + state = rm->GetColorByName(g_nonExistName, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetProfileByIdTest001 + * @tc.desc: Test GetProfileById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetProfileByIdTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr, nullptr); + tmp->Init(); + std::string res = tmp->GetResourcePath(); + res.append("entry/resources/base/profile/test_common.h"); + + std::string outValue; + RState state; + int id = GetResId("test_common", ResType::PROF); + EXPECT_TRUE(id > 0); + state = rm->GetProfileById(id, outValue); + EXPECT_TRUE(state == SUCCESS); + EXPECT_EQ(res, outValue); + delete tmp; +} + +/* + * @tc.name: ResourceManagerGetProfileByIdTest002 + * @tc.desc: Test GetProfileById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetProfileByIdTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + std::string outValue; + RState state; + state = rm->GetProfileById(NON_EXIST_ID, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetProfileByNameTest001 + * @tc.desc: Test GetProfileByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetProfileByNameTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr, nullptr); + tmp->Init(); + std::string res = tmp->GetResourcePath(); + res.append("entry/resources/base/profile/test_common.h"); + + std::string outValue; + RState state; + state = rm->GetProfileByName("test_common", outValue); + EXPECT_TRUE(state == SUCCESS); + EXPECT_EQ(res, outValue); + delete tmp; +} + +/* + * @tc.name: ResourceManagerGetProfileByNameTest002 + * @tc.desc: Test GetProfileByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetProfileByNameTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + std::string outValue; + RState state; + state = rm->GetProfileByName(g_nonExistName, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetMediaByIdTest001 + * @tc.desc: Test GetMediaById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetMediaByIdTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr, nullptr); + tmp->Init(); + std::string res = tmp->GetResourcePath(); + res.append("entry/resources/base/media/icon.png"); + + std::string outValue; + RState state; + int id = GetResId("icon", ResType::MEDIA); + EXPECT_TRUE(id > 0); + state = rm->GetMediaById(id, outValue); + EXPECT_TRUE(state == SUCCESS); + EXPECT_EQ(res, outValue); + delete tmp; +} + +/* + * @tc.name: ResourceManagerGetMediaByIdTest002 + * @tc.desc: Test GetMediaById + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetMediaByIdTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + std::string outValue; + RState state; + state = rm->GetMediaById(NON_EXIST_ID, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerGetMediaByNameTest001 + * @tc.desc: Test GetMediaByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetMediaByNameTest001, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + HapResource *tmp = new HapResource(FormatFullPath(g_resFilePath).c_str(), 0, nullptr, nullptr); + tmp->Init(); + std::string res = tmp->GetResourcePath(); + res.append("entry/resources/base/media/icon.png"); + + std::string outValue; + RState state; + state = rm->GetMediaByName("icon", outValue); + EXPECT_TRUE(state == SUCCESS); + EXPECT_EQ(res, outValue); + delete tmp; +} + +/* + * @tc.name: ResourceManagerGetMediaByNameTest002 + * @tc.desc: Test GetMediaByName + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerGetMediaByNameTest002, TestSize.Level1) +{ + AddResource("zh", nullptr, "CN"); + + std::string outValue; + RState state; + state = rm->GetMediaByName(g_nonExistName, outValue); + ASSERT_EQ(NOT_FOUND, state); +} + +/* + * @tc.name: ResourceManagerResolveReferenceTest001 + * @tc.desc: Test ResolveReference function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerResolveReferenceTest001, TestSize.Level1) +{ + ResConfig *rc = CreateResConfig(); + if (rc == nullptr) { + EXPECT_TRUE(false); + return; + } + rc->SetLocaleInfo("en", nullptr, "US"); + rm->UpdateResConfig(*rc); + + rm->AddResource(FormatFullPath(g_resFilePath).c_str()); + + int id = GetResId("integer_1", ResType::INTEGER); + std::string value(FormatString("$integer:%d", id)); + std::string outValue; + RState ret = ((ResourceManagerImpl *)rm)->ResolveReference(value, outValue); + EXPECT_EQ(SUCCESS, ret); + EXPECT_EQ(std::string("101"), outValue); + + std::string copyright("XXXXXX All rights reserved. ©2011-2019"); + id = GetResId("copyright_text", ResType::STRING); + value.assign(FormatString("$string:%d", id)); + ret = ((ResourceManagerImpl *)rm)->ResolveReference(value, outValue); + EXPECT_EQ(SUCCESS, ret); + EXPECT_EQ(copyright, outValue); + + id = GetResId("string_ref", ResType::STRING); + value.assign(FormatString("$string:%d", id)); + ret = ((ResourceManagerImpl *)rm)->ResolveReference(value, outValue); + EXPECT_EQ(SUCCESS, ret); + EXPECT_EQ(copyright, outValue); + + id = GetResId("boolean_1", ResType::BOOLEAN); + value.assign(FormatString("$boolean:%d", id)); + ret = ((ResourceManagerImpl *)rm)->ResolveReference(value, outValue); + EXPECT_EQ(SUCCESS, ret); + EXPECT_EQ(std::string("true"), outValue); + + id = GetResId("grey_background", ResType::COLOR); + value.assign(FormatString("$color:%d", id)); + ret = ((ResourceManagerImpl *)rm)->ResolveReference(value, outValue); + EXPECT_EQ(SUCCESS, ret); + EXPECT_EQ(std::string("#F5F5F5"), outValue); + + id = GetResId("aboutPage_minHeight", ResType::FLOAT); + value.assign(FormatString("$float:%d", id)); + ret = ((ResourceManagerImpl *)rm)->ResolveReference(value, outValue); + EXPECT_EQ(SUCCESS, ret); + EXPECT_EQ(std::string("707vp"), outValue); + + id = GetResId("base", ResType::PATTERN); + value.assign(FormatString("$pattern:%d", id)); + ret = ((ResourceManagerImpl *)rm)->ResolveReference(value, outValue); + EXPECT_EQ(ERROR, ret); + + // reload + rc->SetLocaleInfo("zh", nullptr, "CN"); + rm->UpdateResConfig(*rc); + delete rc; + + id = GetResId("copyright_text", ResType::STRING); + value.assign(FormatString("$string:%d", id)); + ret = ((ResourceManagerImpl *)rm)->ResolveReference(value, outValue); + ASSERT_EQ(SUCCESS, ret); + ASSERT_EQ(std::string("版权所有 ©2011-2019 XXXX有限公司保留一切权利"), outValue.c_str()); + + id = GetResId("string_ref", ResType::STRING); + value.assign(FormatString("$string:%d", id)); + ret = ((ResourceManagerImpl *)rm)->ResolveReference(value, outValue); + ASSERT_EQ(SUCCESS, ret); + ASSERT_EQ(std::string("$aaaaa"), outValue.c_str()); + + // error case + // wrong id + value.assign(FormatString("$boolean:%d", NON_EXIST_ID)); + ret = ((ResourceManagerImpl *)rm)->ResolveReference(value, outValue); + ASSERT_EQ(ERROR, ret); + // wrong type + id = GetResId("copyright_text", ResType::STRING); + value.assign(FormatString("$boolean:%d", id)); + ret = ((ResourceManagerImpl *)rm)->ResolveReference(value, outValue); + ASSERT_EQ(ERROR, ret); +} + +/* + * @tc.name: ResourceManagerResolveParentReferenceTest001 + * @tc.desc: Test ResolveParentReference function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerResolveParentReferenceTest001, TestSize.Level1) +{ + rm->AddResource(FormatFullPath(g_resFilePath).c_str()); + int id; + std::map outValue; + const IdItem *idItem; + RState ret; + + id = GetResId("base", ResType::PATTERN); + idItem = ((ResourceManagerImpl *)rm)->hapManager_->FindResourceById(id); + ASSERT_TRUE(idItem != nullptr); + ret = ((ResourceManagerImpl *)rm)->ResolveParentReference(idItem, outValue); + ASSERT_EQ(SUCCESS, ret); + PrintMapString(outValue); + + HILOG_DEBUG("====="); + id = GetResId("child", ResType::PATTERN); + idItem = ((ResourceManagerImpl *)rm)->hapManager_->FindResourceById(id); + ASSERT_TRUE(idItem != nullptr); + ret = ((ResourceManagerImpl *)rm)->ResolveParentReference(idItem, outValue); + ASSERT_EQ(SUCCESS, ret); + PrintMapString(outValue); + + HILOG_DEBUG("====="); + id = GetResId("ccchild", ResType::PATTERN); + idItem = ((ResourceManagerImpl *)rm)->hapManager_->FindResourceById(id); + ASSERT_TRUE(idItem != nullptr); + ret = ((ResourceManagerImpl *)rm)->ResolveParentReference(idItem, outValue); + ASSERT_EQ(SUCCESS, ret); + PrintMapString(outValue); + + // error case + ret = ((ResourceManagerImpl *)rm)->ResolveParentReference(nullptr, outValue); + ASSERT_EQ(ERROR, ret); + // wrong resType + IdItem *item = new IdItem; + for (int i = 0; i < ResType::MAX_RES_TYPE; ++i) { + if (i == ResType::THEME || i == ResType::PATTERN) { + continue; + } + item->resType_ = (ResType) i; + ret = ((ResourceManagerImpl *)rm)->ResolveParentReference(item, outValue); + EXPECT_EQ(ERROR, ret); + } + delete item; +} + +/* + * test res with same name in different resType + * @tc.name: ResourceManagerSameNameTest001 + * @tc.desc: Test GetStringByName & GetBooleanByName & GetIntegerByName function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerTest, ResourceManagerSameNameTest001, TestSize.Level1) +{ + rm->AddResource(FormatFullPath(g_resFilePath).c_str()); + std::string outValue; + std::string name; + RState state; + + state = rm->GetStringByName("same_name", outValue); + EXPECT_TRUE(state == SUCCESS); + EXPECT_EQ(std::string("StringSameName"), outValue); + + bool outValueB = true; + state = rm->GetBooleanByName("same_name", outValueB); + EXPECT_TRUE(state == SUCCESS); + EXPECT_EQ(false, outValueB); + + int outValueI; + state = rm->GetIntegerByName("same_name", outValueI); + EXPECT_TRUE(state == SUCCESS); + EXPECT_EQ(999, outValueI); +} diff --git a/global_lite/i18n_lite/resource_parse_load/src/resource_manager_test.h b/global_lite/i18n_lite/resource_parse_load/src/resource_manager_test.h new file mode 100755 index 0000000000000000000000000000000000000000..c637d048f6a07ae2b11bf5980c2e4aedbdec0c5c --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/resource_manager_test.h @@ -0,0 +1,98 @@ +/* + * 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 RESOURCE_MANAGER_RESOURCE_MANANGER_TEST_H +#define RESOURCE_MANAGER_RESOURCE_MANANGER_TEST_H + +int ResourceManagerAddResourceTest001(); +int ResourceManagerAddResourceTest002(); +int ResourceManagerAddResourceTest003(); +int ResourceManagerUpdateResConfigTest001(); +int ResourceManagerUpdateResConfigTest002(); +int ResourceManagerUpdateResConfigTest003(); +int ResourceManagerUpdateResConfigTest004(); +int ResourceManagerUpdateResConfigTest005(); +int ResourceManagerGetResConfigTest001(); +int ResourceManagerGetResConfigTest002(); +int ResourceManagerGetStringByIdTest001(); +int ResourceManagerGetStringByIdTest002(); +int ResourceManagerGetStringByIdTest003(); +int ResourceManagerGetStringByNameTest001(); +int ResourceManagerGetStringByNameTest002(); +int ResourceManagerGetStringByNameTest003(); +int ResourceManagerGetStringFormatByIdTest001(); +int ResourceManagerGetStringFormatByIdTest002(); +int ResourceManagerGetStringFormatByNameTest001(); +int ResourceManagerGetStringFormatByNameTest002(); +int ResourceManagerGetStringArrayByIdTest001(); +int ResourceManagerGetStringArrayByIdTest002(); +int ResourceManagerGetStringArrayByNameTest001(); +int ResourceManagerGetStringArrayByNameTest002(); +int ResourceManagerGetPatternByIdTest001(); +int ResourceManagerGetPatternByIdTest002(); +int ResourceManagerGetPatternByIdTest003(); +int ResourceManagerGetPatternByIdTest004(); +int ResourceManagerGetPatternByNameTest001(); +int ResourceManagerGetPatternByNameTest002(); +int ResourceManagerGetPatternByNameTest003(); +int ResourceManagerGetPatternByNameTest004(); +int ResourceManagerGetPluralStringByIdTest001(); +int ResourceManagerGetPluralStringByIdTest002(); +int ResourceManagerGetPluralStringByIdTest003(); +int ResourceManagerGetPluralStringByIdTest004(); +int ResourceManagerGetPluralStringByIdTest005(); +int ResourceManagerGetPluralStringByNameTest001(); +int ResourceManagerGetPluralStringByNameTest002(); +int ResourceManagerGetPluralStringByIdFormatTest001(); +int ResourceManagerGetPluralStringByIdFormatTest002(); +int ResourceManagerGetPluralStringByNameFormatTest001(); +int ResourceManagerGetPluralStringByNameFormatTest002(); +int ResourceManagerGetThemeByIdTest001(); +int ResourceManagerGetThemeByIdTest002(); +int ResourceManagerGetThemeByNameTest001(); +int ResourceManagerGetThemeByNameTest002(); +int ResourceManagerGetBooleanByIdTest001(); +int ResourceManagerGetBooleanByIdTest002(); +int ResourceManagerGetBooleanByNameTest001(); +int ResourceManagerGetBooleanByNameTest002(); +int ResourceManagerGetIntegerByIdTest001(); +int ResourceManagerGetIntegerByIdTest002(); +int ResourceManagerGetIntegerByNameTest001(); +int ResourceManagerGetIntegerByNameTest002(); +int ResourceManagerGetFloatByIdTest001(); +int ResourceManagerGetFloatByIdTest002(); +int ResourceManagerGetFloatByNameTest001(); +int ResourceManagerGetFloatByNameTest002(); +int ResourceManagerGetIntArrayByIdTest001(); +int ResourceManagerGetIntArrayByIdTest002(); +int ResourceManagerGetIntArrayByNameTest001(); +int ResourceManagerGetIntArrayByNameTest002(); +int ResourceManagerGetColorByIdTest001(); +int ResourceManagerGetColorByIdTest002(); +int ResourceManagerGetColorByNameTest001(); +int ResourceManagerGetColorByNameTest002(); +int ResourceManagerGetProfileByIdTest001(); +int ResourceManagerGetProfileByIdTest002(); +int ResourceManagerGetProfileByNameTest001(); +int ResourceManagerGetProfileByNameTest002(); +int ResourceManagerGetMediaByIdTest001(); +int ResourceManagerGetMediaByIdTest002(); +int ResourceManagerGetMediaByNameTest001(); +int ResourceManagerGetMediaByNameTest002(); +int ResourceManagerResolveReferenceTest001(); +int ResourceManagerResolveParentReferenceTest001(); +int ResourceManagerSameNameTest001(); + +#endif diff --git a/global_lite/i18n_lite/resource_parse_load/src/string_utils_test.cpp b/global_lite/i18n_lite/resource_parse_load/src/string_utils_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..cfe24af2f381d071ceb24c352fefe02cf269b8fb --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/string_utils_test.cpp @@ -0,0 +1,73 @@ +/* + * 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 "string_utils_test.h" + +#include +#include +#include + +#include "test_common.h" +#include "utils/string_utils.h" + +using namespace OHOS::Global::Resource; +using namespace testing::ext; +using namespace OHOS::I18N; + +class StringUtilsTest : public testing::Test { +public: + static void SetUpTestCase(void); + + static void TearDownTestCase(void); + + void SetUp(); + + void TearDown(); +}; + +void StringUtilsTest::SetUpTestCase(void) +{ + // step 1: input testsuit setup step + g_logLevel = LOG_DEBUG; +} + +void StringUtilsTest::TearDownTestCase(void) +{ + // step 2: input testsuit teardown step +} + +void StringUtilsTest::SetUp() +{ + // step 3: input testcase setup step +} + +void StringUtilsTest::TearDown() +{ + // step 4: input testcase teardown step +} + +/* + * @tc.name: StringUtilsFuncTest001 + * @tc.desc: Test FormatString, none file case. + * @tc.type: FUNC + */ +HWTEST_F(StringUtilsTest, StringUtilsFuncTest001, TestSize.Level1) +{ + std::string result = FormatString("%d", 10001); + EXPECT_EQ("10001", result); + + result = FormatString("I'm %s, I'm %d", "cici", 5); + EXPECT_EQ("I'm cici, I'm 5", result); +} \ No newline at end of file diff --git a/global_lite/i18n_lite/resource_parse_load/src/string_utils_test.h b/global_lite/i18n_lite/resource_parse_load/src/string_utils_test.h new file mode 100755 index 0000000000000000000000000000000000000000..0e5642f43b5f4d780365cce5128821c6417cdca7 --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/string_utils_test.h @@ -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. + */ + +#ifndef RESOURCE_MANAGER_STRING_UTILS_TEST_H +#define RESOURCE_MANAGER_STRING_UTILS_TEST_H + +int StringUtilsFuncTest001(); + +#endif diff --git a/global_lite/i18n_lite/resource_parse_load/src/test_common.cpp b/global_lite/i18n_lite/resource_parse_load/src/test_common.cpp new file mode 100755 index 0000000000000000000000000000000000000000..a8d261dfe074c6c9aef10c23c3230126ad560694 --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/test_common.cpp @@ -0,0 +1,81 @@ +/* + * 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 "test_common.h" + +#include +#include +#include +#include + +#include "hilog_wrapper.h" +#include "utils/errors.h" + +#if defined(__linux__) +#include +#endif + +namespace OHOS { +namespace Global { +namespace Resource { +std::string FormatFullPath(const char *fileRelativePath) +{ + const char *value = "/user/data"; + std::string result(value); + result.append("/"); + result.append(fileRelativePath); + return result; +} + +void PrintIdValues(const HapResource::IdValues *idValues) +{ + HILOG_DEBUG("idvalues size: %u", idValues->GetLimitPathsConst().size()); + for (size_t i = 0; i < idValues->GetLimitPathsConst().size(); ++i) { + auto limitPath = idValues->GetLimitPathsConst()[i]; + HILOG_DEBUG("%zu: folder is: %s, value: %s", i, limitPath->GetFolder().c_str(), + limitPath->GetIdItem()->ToString().c_str()); + } +} + +void PrintMapString(const std::map &value) +{ + auto iter = value.begin(); + for (; iter != value.end(); ++iter) { + std::string key = iter->first; + std::string val = iter->second; + HILOG_DEBUG("%s : %s", key.c_str(), val.c_str()); + } +} + +void PrintVectorString(const std::vector &value) +{ + for (size_t i = 0; i < value.size(); ++i) { + std::string val = value[i]; + HILOG_DEBUG("%zu : %s", i, val.c_str()); + } +} + +ResConfig *CreateResConfig(const char *language, const char *script, const char *region) +{ + ResConfig *resConfig = CreateResConfig(); + if (resConfig == nullptr) { + return nullptr; + } + resConfig->SetLocaleInfo(language, script, region); + return resConfig; +} +} // namespace Resource +} // namespace Global +} // namespace OHOS diff --git a/global_lite/i18n_lite/resource_parse_load/src/test_common.h b/global_lite/i18n_lite/resource_parse_load/src/test_common.h new file mode 100755 index 0000000000000000000000000000000000000000..53dd723c6ba31e2686657e584d6fb04e3fb513aa --- /dev/null +++ b/global_lite/i18n_lite/resource_parse_load/src/test_common.h @@ -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. + */ + +#ifndef RESOURCE_MANAGER_TEST_COMMON_H +#define RESOURCE_MANAGER_TEST_COMMON_H + +#include "hap_resource.h" +#include "hilog_wrapper.h" + +#include +#include +#include + +// this is relative path +static const char *g_resFilePath = "all/assets/entry/resources.index"; + +namespace OHOS { +namespace Global { +namespace Resource { +std::string FormatFullPath(const char *fileRelativePath); + +void PrintIdValues(const HapResource::IdValues *idValues); + +void PrintMapString(const std::map &value); + +void PrintVectorString(const std::vector &value); + +ResConfig *CreateResConfig(const char *language, const char *script, const char *region); +} // namespace Resource +} // namespace Global +} // namespace OHOS +#endif diff --git a/global_lite/i18n_lite/week_plural_number/src/BUILD.gn b/global_lite/i18n_lite/week_plural_number/src/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..d6fa95bfb284a9197d1fa438157c4a33076a01d8 --- /dev/null +++ b/global_lite/i18n_lite/week_plural_number/src/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/lite/build/suite_lite.gni") + +hcpptest_suite("WeekPluralNumbertest") { + suite_name = "acts" + sources = [ "week_plural_number_test.cpp" ] + + include_dirs = [ + "//base/global/i18n_lite/interfaces/kits/i18n/include", + "//third_party/bounds_checking_function/include", + + ] + + deps = [ + "//base/global/i18n_lite/frameworks/i18n:global_i18n", + #"//third_party/bounds_checking_function:libsec_shared", + ] +} diff --git a/global_lite/i18n_lite/week_plural_number/src/Test.json b/global_lite/i18n_lite/week_plural_number/src/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..9816262b53bdef1403dc99ce5ac329f85dd2df5e --- /dev/null +++ b/global_lite/i18n_lite/week_plural_number/src/Test.json @@ -0,0 +1,21 @@ +{ + "kits": [ + { + "push": [ + "WeekPluralNumbertest->/data/local/tmp/WeekPluralNumbertest" + ], + "type": "PushKit", + "post-push": [ + "chmod -R 777 /data/local/tmp/*" + ] + } + ], + "driver": { + "native-test-timeout": "120000", + "type": "CppTest", + "module-name": "WeekPluralNumbertest", + "runtime-hint": "1s", + "native-test-device-path": "/data/local/tmp" + }, + "description": "WeekPluralNumbertest Tests" +} \ No newline at end of file diff --git a/global_lite/i18n_lite/week_plural_number/src/week_plural_number_test.cpp b/global_lite/i18n_lite/week_plural_number/src/week_plural_number_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..e9b4b49b9288302ce7c219d53b693870be5ef42d --- /dev/null +++ b/global_lite/i18n_lite/week_plural_number/src/week_plural_number_test.cpp @@ -0,0 +1,360 @@ +/* + * 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 "week_plural_number_test.h" +#include +#include "date_time_format.h" +#include "iostream" +#include "locale_info.h" +#include "number_format.h" +#include "plural_format.h" +#include "types.h" +#include "week_info.h" + +namespace OHOS { +using namespace std; +using namespace testing::ext; +using namespace OHOS::I18N; + +class WeekPluralNumberTest : public testing::Test { +public: + void SetUp(); + void TearDown(); +}; + +void WeekPluralNumberTest::SetUp() +{ +} + +void WeekPluralNumberTest::TearDown() +{ +} + +/** + * @tc.number: WeekPluralNumberTest0100 + * @tc.name: Test PluralFormat GetPluralRuleIndex function with zh locale + */ +HWTEST_F(WeekPluralNumberTest, WeekPluralNumberTest0100, Function | MediumTest | Level3) +{ + LocaleInfo locale("zh", "", ""); + I18nStatus status = I18nStatus::ISUCCESS; + PluralFormat formatter(locale, status); + double number = 2.1; + int out = formatter.GetPluralRuleIndex(number, status); + int expect = PluralRuleType::OTHER; + EXPECT_TRUE(expect == out); + number = 10.10; + out = formatter.GetPluralRuleIndex(number, status); + EXPECT_TRUE(expect == out); + number = 100.1234567; + out = formatter.GetPluralRuleIndex(number, status); + EXPECT_TRUE(expect == out); +} + +/** + * @tc.number: WeekPluralNumberTest0200 + * @tc.name: Test PluralFormat GetPluralRuleIndex function with uk locale + */ +HWTEST_F(WeekPluralNumberTest, WeekPluralNumberTest0200, Function | MediumTest | Level3) +{ + LocaleInfo locale("uk", "", ""); + I18nStatus status = I18nStatus::ISUCCESS; + PluralFormat formatter(locale, status); + double number = 3.3; + int out = formatter.GetPluralRuleIndex(number, status); + int expect = PluralRuleType::OTHER; + EXPECT_TRUE(expect == out); + number = 10.10; + out = formatter.GetPluralRuleIndex(number, status); + EXPECT_TRUE(expect == out); + number = 1.7654321; + out = formatter.GetPluralRuleIndex(number, status); + EXPECT_TRUE(expect == out); +} + +/** + * @tc.number: WeekPluralNumberTest0300 + * @tc.name: Test PluralFormat GetPluralRuleIndex function with sr locale + */ +HWTEST_F(WeekPluralNumberTest, WeekPluralNumberTest0300, Function | MediumTest | Level3) +{ + LocaleInfo locale("sr", "", ""); + I18nStatus status = I18nStatus::ISUCCESS; + PluralFormat formatter(locale, status); + double number = 1.10; + int out = formatter.GetPluralRuleIndex(number, status); + int expect = PluralRuleType::ONE; + EXPECT_TRUE(expect == out); + number = 1.1210; + out = formatter.GetPluralRuleIndex(number, status); + EXPECT_TRUE(expect == out); + number = 1.2; + out = formatter.GetPluralRuleIndex(number, status); + expect = PluralRuleType::FEW; + EXPECT_TRUE(expect == out); + number = 1.20; + out = formatter.GetPluralRuleIndex(number, status); + EXPECT_TRUE(expect == out); + number = 1.3; + out = formatter.GetPluralRuleIndex(number, status); + EXPECT_TRUE(expect == out); + number = 1.40; + out = formatter.GetPluralRuleIndex(number, status); + EXPECT_TRUE(expect == out); + number = 1.22; + out = formatter.GetPluralRuleIndex(number, status); + EXPECT_TRUE(expect == out); + number = 1.340; + out = formatter.GetPluralRuleIndex(number, status); + EXPECT_TRUE(expect == out); + number = 1.11; + out = formatter.GetPluralRuleIndex(number, status); + expect = PluralRuleType::OTHER; + EXPECT_TRUE(expect == out); + number = 1.120; + out = formatter.GetPluralRuleIndex(number, status); + EXPECT_TRUE(expect == out); + number = 1.13; + out = formatter.GetPluralRuleIndex(number, status); + EXPECT_TRUE(expect == out); + number = 1.140; + out = formatter.GetPluralRuleIndex(number, status); + EXPECT_TRUE(expect == out); +} + +/** + * @tc.number: WeekPluralNumberTest0400 + * @tc.name: Test PluralFormat GetPluralRuleIndex function with lv locale + */ +HWTEST_F(WeekPluralNumberTest, WeekPluralNumberTest0400, Function | MediumTest | Level3) +{ + LocaleInfo locale("lv", "", ""); + I18nStatus status = I18nStatus::ISUCCESS; + PluralFormat formatter(locale, status); + double number = 1.140; + int out = formatter.GetPluralRuleIndex(number, status); + int expect = PluralRuleType::ZERO; + EXPECT_TRUE(expect == out); + number = 11.0; + out = formatter.GetPluralRuleIndex(number, status); + EXPECT_TRUE(expect == out); +} + +/** + * @tc.number: WeekPluralNumberTest0500 + * @tc.name: Test PluralFormat GetPluralRuleIndex function with ar locale + */ +HWTEST_F(WeekPluralNumberTest, WeekPluralNumberTest0500, Function | MediumTest | Level3) +{ + LocaleInfo locale("ar", "", ""); + I18nStatus status = I18nStatus::ISUCCESS; + PluralFormat formatter(locale, status); + double number = 2.0; + int out = formatter.GetPluralRuleIndex(number, status); + int expect = PluralRuleType::TWO; + EXPECT_TRUE(expect == out); + number = 2.0; + out = formatter.GetPluralRuleIndex(number, status); + EXPECT_TRUE(expect == out); + number = 2.00; + out = formatter.GetPluralRuleIndex(number, status); + EXPECT_TRUE(expect == out); + number = 2.000; + out = formatter.GetPluralRuleIndex(number, status); + EXPECT_TRUE(expect == out); + expect = PluralRuleType::MANY; + number = 1011.0; + out = formatter.GetPluralRuleIndex(number, status); + EXPECT_TRUE(expect == out); +} + +/** + * @tc.number: WeekPluralNumberTest0600 + * @tc.name: Test LocaleInfo ForLanguageTag with zh locale + */ +HWTEST_F(WeekPluralNumberTest, WeekPluralNumberTest0600, Function | MediumTest | Level3) +{ + I18nStatus status = I18nStatus::ISUCCESS; + LocaleInfo locale = LocaleInfo::ForLanguageTag("zh-Hant-CN-u-nu-arab", status); + EXPECT_TRUE(status == I18nStatus::ISUCCESS); +} + +/** + * @tc.number: WeekPluralNumberTest0700 + * @tc.name: Test LocaleInfo ForLanguageTag with ko locale + */ +HWTEST_F(WeekPluralNumberTest, WeekPluralNumberTest0700, Function | MediumTest | Level3) +{ + I18nStatus status = I18nStatus::ISUCCESS; + LocaleInfo locale = LocaleInfo::ForLanguageTag("ko-Hani-KR-u-nu-arab", status); + EXPECT_TRUE(status == I18nStatus::ISUCCESS); +} + +/** + * @tc.number: WeekPluralNumberTest0800 + * @tc.name: Test LocaleInfo GetExtension with zh locale + */ +HWTEST_F(WeekPluralNumberTest, WeekPluralNumberTest0800, Function | MediumTest | Level3) +{ + I18nStatus status = I18nStatus::ISUCCESS; + LocaleInfo locale = LocaleInfo::ForLanguageTag("zh-Hant-CN-u-nu-arab", status); + EXPECT_TRUE(status == I18nStatus::ISUCCESS); + const char *numberDigits = locale.GetExtension("nu"); + EXPECT_TRUE(numberDigits != nullptr); + EXPECT_TRUE(strcmp("arab", numberDigits) == 0); + int status_v2 = 0; + NumberFormat formatter(locale, status_v2); + int intNum1 = 1234567; + std::string out = formatter.Format(intNum1, status_v2); + std::cout << "out: " << out << std::endl; + EXPECT_TRUE(out == "١,٢٣٤,٥٦٧"); +} + +/** + * @tc.number: WeekPluralNumberTest0900 + * @tc.name: Test LocaleInfo GetExtension with ko locale + */ +HWTEST_F(WeekPluralNumberTest, WeekPluralNumberTest0900, Function | MediumTest | Level3) +{ + I18nStatus status = I18nStatus::ISUCCESS; + LocaleInfo locale = LocaleInfo::ForLanguageTag("ko-Hani-KR-u-nu-arab", status); + EXPECT_TRUE(status == I18nStatus::ISUCCESS); + const char *numberDigits = locale.GetExtension("nu"); + EXPECT_TRUE(numberDigits != nullptr); + EXPECT_TRUE(strcmp("arab", numberDigits) == 0); + int status_v2 = 0; + NumberFormat formatter(locale, status_v2); + int intNum1 = 1234567; + std::string out = formatter.Format(intNum1, status_v2); + std::cout << "out: " << out << std::endl; + EXPECT_TRUE(out == "١,٢٣٤,٥٦٧"); +} + +/** + * @tc.number: WeekPluralNumberTest1000 + * @tc.name: Test WeekInfo constructor with zh language + */ +HWTEST_F(WeekPluralNumberTest, WeekPluralNumberTest1000, Function | MediumTest | Level3) +{ + I18nStatus status = I18nStatus::ISUCCESS; + LocaleInfo locale("zh", "CN"); + WeekInfo weekInfo(locale, status); + EXPECT_TRUE(status == I18nStatus::ISUCCESS); +} + +/** + * @tc.number: WeekPluralNumberTest1100 + * @tc.name: Test WeekInfo GetFirstDayOfWeek with zh locale + */ +HWTEST_F(WeekPluralNumberTest, WeekPluralNumberTest1100, Function | MediumTest | Level3) +{ + I18nStatus status = I18nStatus::ISUCCESS; + LocaleInfo locale("zh", "CN"); + WeekInfo weekInfo(locale, status); + uint8_t ret = weekInfo.GetFirstDayOfWeek(); + EXPECT_TRUE(ret == 1); +} + +/** + * @tc.number: WeekPluralNumberTest1200 + * @tc.name: Test WeekInfo GetFirstDayOfWeek with en locale + */ +HWTEST_F(WeekPluralNumberTest, WeekPluralNumberTest1200, Function | MediumTest | Level3) +{ + I18nStatus status = I18nStatus::ISUCCESS; + LocaleInfo locale("en", "US"); + WeekInfo weekInfo(locale, status); + uint8_t ret = weekInfo.GetFirstDayOfWeek(); + EXPECT_TRUE(ret == 1); +} + +/** + * @tc.number: WeekPluralNumberTest1300 + * @tc.name: Test WeekInfo GetMinimalDaysInFirstWeek with zh locale + */ +HWTEST_F(WeekPluralNumberTest, WeekPluralNumberTest1300, Function | MediumTest | Level3) +{ + I18nStatus status = I18nStatus::ISUCCESS; + LocaleInfo locale("zh", "CN"); + WeekInfo weekInfo(locale, status); + uint8_t ret = weekInfo.GetMinimalDaysInFirstWeek(); + EXPECT_TRUE(ret == 1); +} + +/** + * @tc.number: WeekPluralNumberTest1400 + * @tc.name: Test WeekInfo GetMinimalDaysInFirstWeek with zh locale + */ +HWTEST_F(WeekPluralNumberTest, WeekPluralNumberTest1400, Function | MediumTest | Level3) +{ + I18nStatus status = I18nStatus::ISUCCESS; + LocaleInfo locale("en", "US"); + WeekInfo weekInfo(locale, status); + uint8_t ret = weekInfo.GetMinimalDaysInFirstWeek(); + EXPECT_TRUE(ret == 1); +} + +/** + * @tc.number: WeekPluralNumberTest1500 + * @tc.name: Test WeekInfo GetFirstDayOfWeekend with zh locale + */ +HWTEST_F(WeekPluralNumberTest, WeekPluralNumberTest1500, Function | MediumTest | Level3) +{ + I18nStatus status = I18nStatus::ISUCCESS; + LocaleInfo locale("zh", "CN"); + WeekInfo weekInfo(locale, status); + uint8_t ret = weekInfo.GetFirstDayOfWeekend(); + EXPECT_TRUE(ret == 7); +} + +/** + * @tc.number: WeekPluralNumberTest1600 + * @tc.name: Test WeekInfo GetFirstDayOfWeekend with en locale + */ +HWTEST_F(WeekPluralNumberTest, WeekPluralNumberTest1600, Function | MediumTest | Level3) +{ + I18nStatus status = I18nStatus::ISUCCESS; + LocaleInfo locale("en", "US"); + WeekInfo weekInfo(locale, status); + uint8_t ret = weekInfo.GetFirstDayOfWeekend(); + EXPECT_TRUE(ret == 7); +} + +/** + * @tc.number: WeekPluralNumberTest1700 + * @tc.name: Test WeekInfo GetLastDayOfWeekend with zh locale + */ +HWTEST_F(WeekPluralNumberTest, WeekPluralNumberTest1700, Function | MediumTest | Level3) +{ + I18nStatus status = I18nStatus::ISUCCESS; + LocaleInfo locale("zh", "CN"); + WeekInfo weekInfo(locale, status); + uint8_t ret = weekInfo.GetLastDayOfWeekend(); + EXPECT_TRUE(ret == 1); +} + +/** + * @tc.number: WeekPluralNumberTest1800 + * @tc.name: Test WeekInfo GetLastDayOfWeekend with en locale + */ +HWTEST_F(WeekPluralNumberTest, WeekPluralNumberTest1800, Function | MediumTest | Level3) +{ + I18nStatus status = I18nStatus::ISUCCESS; + LocaleInfo locale("en", "US"); + WeekInfo weekInfo(locale, status); + uint8_t ret = weekInfo.GetLastDayOfWeekend(); + EXPECT_TRUE(ret == 1); +} +} \ No newline at end of file diff --git a/global_lite/i18n_lite/week_plural_number/src/week_plural_number_test.h b/global_lite/i18n_lite/week_plural_number/src/week_plural_number_test.h new file mode 100755 index 0000000000000000000000000000000000000000..b157925e8baa606a3304e249d218062db96390a6 --- /dev/null +++ b/global_lite/i18n_lite/week_plural_number/src/week_plural_number_test.h @@ -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. + */ + +#ifndef OHOS_GLOBAL_I18N_WEEK_PLURAL_NUMBER_TEST_H +#define OHOS_GLOBAL_I18N_WEEK_PLURAL_NUMBER_TEST_H + +int WeekPluralNumberTest0100(); +int WeekPluralNumberTest0200(); +int WeekPluralNumberTest0300(); +int WeekPluralNumberTest0400(); +int WeekPluralNumberTest0500(); +int WeekPluralNumberTest0600(); +int WeekPluralNumberTest0700(); +int WeekPluralNumberTest0800(); +int WeekPluralNumberTest0900(); +int WeekPluralNumberTest1000(); +int WeekPluralNumberTest1100(); +int WeekPluralNumberTest1200(); +int WeekPluralNumberTest1300(); +int WeekPluralNumberTest1400(); +int WeekPluralNumberTest1500(); +int WeekPluralNumberTest1600(); +int WeekPluralNumberTest1700(); +int WeekPluralNumberTest1800(); + +#endif diff --git a/graphic_lite/graphic_utils/a/BUILD.gn b/graphic_lite/graphic_utils/a/BUILD.gn index 6efbe1981f1942ce908ca10ea2bb0c217ad60787..f6a4d83e8e206c69939f49748fd7d0062def3ae0 100755 --- a/graphic_lite/graphic_utils/a/BUILD.gn +++ b/graphic_lite/graphic_utils/a/BUILD.gn @@ -27,8 +27,6 @@ hcpptest_suite("ActsUiInterface1Test") { } include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/graphic_utils/color_posix/BUILD.gn b/graphic_lite/graphic_utils/color_posix/BUILD.gn index 28c86485030ed0aedac9cb063f0a8cc5749c654c..fde8d65c5c923637843ca24fa53cf93f4e5a92da 100755 --- a/graphic_lite/graphic_utils/color_posix/BUILD.gn +++ b/graphic_lite/graphic_utils/color_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsColorTest") { sources = [ "src/color_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/graphic_utils/geometry2d_posix/BUILD.gn b/graphic_lite/graphic_utils/geometry2d_posix/BUILD.gn index a455c130e40066e44ae19dca5c9cfd7e6e7f8f31..9c5344d9cc3912110bb4f226aeba9015caf713b3 100755 --- a/graphic_lite/graphic_utils/geometry2d_posix/BUILD.gn +++ b/graphic_lite/graphic_utils/geometry2d_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsGeometyr2dTest") { sources = [ "src/geometry2d_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/graphic_utils/graphic_math_posix/BUILD.gn b/graphic_lite/graphic_utils/graphic_math_posix/BUILD.gn index 3fc371b8f9f8b55481295bd4fac272944439a927..039da721fbf9d742752ff2ba9ad13749354dae70 100755 --- a/graphic_lite/graphic_utils/graphic_math_posix/BUILD.gn +++ b/graphic_lite/graphic_utils/graphic_math_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsGraphicMathTest") { sources = [ "src/graphic_math_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/graphic_utils/graphic_math_posix/src/graphic_math_test.cpp b/graphic_lite/graphic_utils/graphic_math_posix/src/graphic_math_test.cpp index 157b0389523d40199c527dca905aa1789f61d377..703b9fdf2d84ebce360ad7ddd688d696eecf1ebf 100755 --- a/graphic_lite/graphic_utils/graphic_math_posix/src/graphic_math_test.cpp +++ b/graphic_lite/graphic_utils/graphic_math_posix/src/graphic_math_test.cpp @@ -37,448 +37,16 @@ void MathTest::TearDownTestCase() return; } -/** - * @tc.number SUB_GRAPHIC_MATH_SIN_0100 - * @tc.name test math sin api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Math_Test_Sin_0100, Function | MediumTest | Level0) -{ - EXPECT_EQ(Sin(0), 0); - EXPECT_EQ(Sin(90), 1); - EXPECT_EQ(Sin(180), 0); -} - /** * @tc.number SUB_GRAPHIC_MATH_FASTATAN2_0200 * @tc.name test math fast-atan2 api * @tc.desc [C- SOFTWARE -0200] */ -HWTEST_F(MathTest, Graphic_Math_Test_FastAtan2_0200, Function | MediumTest | Level0) +HWTEST_F(MathTest, Graphic_Math_Test_FastAtan2_0100, Function | MediumTest | Level0) { EXPECT_EQ(FastAtan2(0, 1), 0); EXPECT_EQ(FastAtan2(1, 0), 90); EXPECT_EQ(FastAtan2(0, -1), 180); EXPECT_EQ(FastAtan2(-1, 0), 270); } - - -/** - * @tc.number SUB_GRAPHIC_MATH_FLOATTOINT64_0300 - * @tc.name test math float-to-int64 api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Math_Test_FloatToInt64_0300, Function | MediumTest | Level0) -{ - EXPECT_EQ(FloatToInt64(1), 256); -} - -/** - * @tc.number SUB_GRAPHIC_MATH_SQRT_0400 - * @tc.name test math sqrt api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Math_Test_Sqrt_0400, Function | MediumTest | Level0) -{ - const float testInteger = 2.0; - const float testIntegerSquared = testInteger * testInteger; - const float testFloat = 2.121320; // 2.121320: 4.5 squaring results - const float testFloatSquared = 4.5; - const float accuracy = 0.000001; - - EXPECT_EQ(Sqrt(0), 0); - float ret = Sqrt(testIntegerSquared); - if (ret > testInteger - accuracy && ret < testInteger + accuracy) { - EXPECT_EQ(0, 0); - } else { - EXPECT_NE(0, 0); - } - - ret = Sqrt(testFloatSquared); - if (ret > testFloat - accuracy && ret < testFloat + accuracy) { - EXPECT_EQ(0, 0); - } else { - EXPECT_NE(0, 0); - } -} - -/** - * @tc.number SUB_GRAPHIC_MATH_VECTOR2_DOT_0500 - * @tc.name test math vector2-dot api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Vector2_Test_Dot_0500, Function | MediumTest | Level0) -{ - Vector2* vector1 = new Vector2(5, 4); - Vector2* vector2 = new Vector2(3, 2); - - EXPECT_EQ(vector1->Dot(*vector2), 23); - - delete vector1; - delete vector2; -} - -/** - * @tc.number SUB_GRAPHIC_MATH_VECTOR2_CROSS_0600 - * @tc.name test math vector2-cross api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Vector2_Test_Cross_0600, Function | MediumTest | Level0) -{ - Vector2* vector1 = new Vector2(5, 4); - Vector2* vector2 = new Vector2(3, 5); - - EXPECT_EQ(vector1->Cross(*vector2), 13); - - delete vector1; - delete vector2; -} - -/** - * @tc.number SUB_GRAPHIC_MATH_VECTOR2_OPERATOR_0700 - * @tc.name test math vector2-operator-minus api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Vector2_Test_operator_Minus_0700, Function | MediumTest | Level0) -{ - Vector2* vector1 = new Vector2(5, 4); - Vector2 vector2 = vector1->operator-(); - - EXPECT_EQ(vector2.x_, 65531); - EXPECT_EQ(vector2.y_, 65532); - - delete vector1; - - Vector2* vector3 = new Vector2(5, 7); - Vector2* vector4 = new Vector2(3, 5); - Vector2 vector5 = vector3->operator-(*vector4); - - EXPECT_EQ(vector5.x_, 2); - EXPECT_EQ(vector5.y_, 2); - - delete vector3; - delete vector4; -} - -/** - * @tc.number SUB_GRAPHIC_MATH_VECTOR2_OPERATOR_0800 - * @tc.name test math vector2-operator-plus api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Vector2_Test_operator_Plus_0800, Function | MediumTest | Level0) -{ - Vector2* vector1 = new Vector2(5, 7); - Vector2* vector2 = new Vector2(3, 5); - Vector2 vector3 = vector1->operator+(*vector2); - - EXPECT_EQ(vector3.x_, 8); - EXPECT_EQ(vector3.y_, 12); - - delete vector1; - delete vector2; -} - -/** - * @tc.number SUB_GRAPHIC_MATH_VECTOR2_OPERATOR_0900 - * @tc.name test math vector2-operator-star api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Vector2_Test_operator_Star_0900, Function | MediumTest | Level0) -{ - Vector2* vector1 = new Vector2(5, 7); - Vector2 vector2 = vector1->operator*(2); - - EXPECT_EQ(vector2.x_, 10); - EXPECT_EQ(vector2.y_, 14); - - delete vector1; -} - -/** - * @tc.number SUB_GRAPHIC_MATH_VECTOR2_OPERATOR_1000 - * @tc.name test math vector2-operator-duo-equal api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Vector2_Test_operator_DuoEqual_1000, Function | MediumTest | Level0) -{ - Vector2* vector1 = new Vector2(5, 7); - Vector2* vector2 = new Vector2(5, 7); - Vector2* vector3 = new Vector2(5, 8); - - EXPECT_EQ(vector1->operator==(*vector2), true); - EXPECT_EQ(vector1->operator==(*vector3), false); - - delete vector1; - delete vector2; - delete vector3; -} - -/** - * @tc.number SUB_GRAPHIC_MATH_VECTOR2_OPERATOR_1100 - * @tc.name test math vector2-operator-equal api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Vector2_Test_operator_Equal_1100, Function | MediumTest | Level0) -{ - Vector2* vector1 = new Vector2(5, 7); - Vector2* vector2 = new Vector2(1, 2); - vector1->operator=(*vector2); - EXPECT_EQ(vector1->x_, 1); - EXPECT_EQ(vector1->y_, 2); - - delete vector1; - delete vector2; -} - -/** - * @tc.number SUB_GRAPHIC_MATH_VECTOR2_OPERATOR_1200 - * @tc.name test math vector2-operator-plus-equal api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Vector2_Test_operator_PlusEqual_1200, Function | MediumTest | Level0) -{ - Vector2* vector1 = new Vector2(5, 7); - Vector2* vector2 = new Vector2(1, 2); - vector1->operator+=(*vector2); - EXPECT_EQ(vector1->x_, 6); - EXPECT_EQ(vector1->y_, 9); - - delete vector1; - delete vector2; -} - -/** - * @tc.number SUB_GRAPHIC_MATH_VECTOR2_OPERATOR_1300 - * @tc.name test math vector2-operator-minus-equal api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Vector2_Test_operator_MinusEqual_1300, Function | MediumTest | Level0) -{ - Vector2* vector1 = new Vector2(5, 7); - Vector2* vector2 = new Vector2(1, 2); - vector1->operator-=(*vector2); - EXPECT_EQ(vector1->x_, 4); - EXPECT_EQ(vector1->y_, 5); - - delete vector1; - delete vector2; -} - -/** - * @tc.number SUB_GRAPHIC_MATH_VECTOR3_OPERATOR_1400 - * @tc.name test math vector3-operator-brackets api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Vector3_Test_operator_Brackets_1400, Function | MediumTest | Level0) -{ - Vector3* vector1 = new Vector3(3, 5, 7); - EXPECT_EQ(vector1->operator[](0), 3); - EXPECT_EQ(vector1->operator[](1), 5); - EXPECT_EQ(vector1->operator[](2), 7); - - delete vector1; -} - -/** - * @tc.number SUB_GRAPHIC_MATH_VECTOR3_OPERATOR_1500 - * @tc.name test math vector3-operator-duo-equal api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Vector3_Test_operator_DuoEqual_1500, Function | MediumTest | Level0) -{ - Vector3* vector1 = new Vector3(3, 5, 7); - Vector3* vector2 = new Vector3(3, 5, 7); - Vector3* vector3 = new Vector3(3, 5, 9); - - EXPECT_EQ(vector1->operator==(*vector2), true); - EXPECT_EQ(vector1->operator==(*vector3), false); - - delete vector1; - delete vector2; - delete vector3; -} - -/** - * @tc.number SUB_GRAPHIC_MATH_MATRIX3_GETDATA_1600 - * @tc.name test math matrix3-getdata api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Matrix3_Test_GetData_1600, Function | MediumTest | Level0) -{ - Matrix3* matrix = new Matrix3(1, 1, 1, 1, 1, 1, 1, 1, 1); - - EXPECT_EQ(matrix->GetData()[0], 1); - EXPECT_EQ(matrix->GetData()[5], 1); - - delete matrix; -} - -/** - * @tc.number SUB_GRAPHIC_MATH_MATRIX3_OPERATOR_1700 - * @tc.name test math matrix3-operator-star api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Matrix3_Test_operator_Star_1700, Function | MediumTest | Level0) -{ - Matrix3 matrix1(1, 1, 1, 1, 1, 1, 1, 1, 1); - Matrix3 matrix2(1, 2, 3, 4, 5, 6, 7, 8, 9); - Matrix3 matrix3 = matrix1 * matrix2; - - EXPECT_EQ(matrix3.GetData()[0], 6); - EXPECT_EQ(matrix3.GetData()[1], 6); - EXPECT_EQ(matrix3.GetData()[2], 6); - EXPECT_EQ(matrix3.GetData()[3], 15); - EXPECT_EQ(matrix3.GetData()[4], 15); - EXPECT_EQ(matrix3.GetData()[5], 15); - EXPECT_EQ(matrix3.GetData()[6], 24); - EXPECT_EQ(matrix3.GetData()[7], 24); - EXPECT_EQ(matrix3.GetData()[8], 24); - - Vector3 vector1(1, 2, 3); - Vector3 vector2 = matrix1 * vector1; - - EXPECT_EQ(vector2.x_, 6); - EXPECT_EQ(vector2.y_, 6); - EXPECT_EQ(vector2.z_, 6); -} - -/** - * @tc.number SUB_GRAPHIC_MATH_MATRIX3_OPERATOR_1800 - * @tc.name test math matrix3-operator-brackets api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Matrix3_Test_operator_Brackets_1800, Function | MediumTest | Level0) -{ - Matrix3* matrix = new Matrix3(1, 2, 3, 4, 5, 6, 7, 8, 9); - - EXPECT_EQ(*matrix->operator[](0), 1); - EXPECT_EQ(*matrix->operator[](1), 4); - EXPECT_EQ(*matrix->operator[](2), 7); - - delete matrix; -} - -/** - * @tc.number SUB_GRAPHIC_MATH_MATRIX3_OPERATOR_1900 - * @tc.name test math matrix3-operator-equal api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Matrix3_Test_operator_Equal_1900, Function | MediumTest | Level0) -{ - Matrix3* matrix1 = new Matrix3(1, 2, 3, 4, 5, 6, 7, 8, 9); - Matrix3* matrix2 = new Matrix3(1, 1, 1, 1, 1, 1, 1, 1, 1); - matrix1->operator=(*matrix2); - EXPECT_EQ(matrix1->GetData()[0], 1); - EXPECT_EQ(matrix1->GetData()[1], 1); - EXPECT_EQ(matrix1->GetData()[2], 1); - EXPECT_EQ(matrix1->GetData()[3], 1); - EXPECT_EQ(matrix1->GetData()[4], 1); - EXPECT_EQ(matrix1->GetData()[5], 1); - EXPECT_EQ(matrix1->GetData()[6], 1); - EXPECT_EQ(matrix1->GetData()[7], 1); - EXPECT_EQ(matrix1->GetData()[8], 1); - - delete matrix1; - delete matrix2; -} - -/** - * @tc.number SUB_GRAPHIC_MATH_MATRIX3_DETERMINANT_2000 - * @tc.name test math matrix3-determinant api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Matrix3_Test_Determinant_2000, Function | MediumTest | Level0) -{ - Matrix3* matrix1 = new Matrix3(1, 2, 2, 2, 1, 2, 2, 2, 1); - EXPECT_EQ(matrix1->Determinant(), 5); - - delete matrix1; -} - -/** - * @tc.number SUB_GRAPHIC_MATH_MATRIX3_INVERSE_2100 - * @tc.name test math matrix3-inverse api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Matrix3_Test_Inverse_2100, Function | MediumTest | Level0) -{ - Matrix3* matrix1 = new Matrix3(1, 1, 1, 1, 1, 1, 1, 1, 1); - Matrix3 matrix2 = matrix1->Inverse(); - EXPECT_EQ(matrix2.GetData()[0], 1); - EXPECT_EQ(matrix2.GetData()[1], 1); - EXPECT_EQ(matrix2.GetData()[2], 1); - EXPECT_EQ(matrix2.GetData()[3], 1); - EXPECT_EQ(matrix2.GetData()[4], 1); - EXPECT_EQ(matrix2.GetData()[5], 1); - EXPECT_EQ(matrix2.GetData()[6], 1); - EXPECT_EQ(matrix2.GetData()[7], 1); - EXPECT_EQ(matrix2.GetData()[8], 1); - delete matrix1; -} - -/** - * @tc.number SUB_GRAPHIC_MATH_MATRIX3_OPERATOR_2200 - * @tc.name test math matrix3-operator-duo-equal api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Matrix3_Test_operator_DuoEqual_2200, Function | MediumTest | Level0) -{ - Matrix3* matrix1 = new Matrix3(1, 1, 1, 1, 1, 1, 1, 1, 1); - Matrix3* matrix2 = new Matrix3(1, 1, 1, 1, 1, 1, 1, 1, 1); - Matrix3* matrix3 = new Matrix3(1, 1, 1, 1, 1, 1, 8, 1, 1); - EXPECT_EQ(matrix1->operator==(*matrix2), true); - EXPECT_EQ(matrix1->operator==(*matrix3), false); - - delete matrix1; - delete matrix2; - delete matrix3; -} - -/** - * @tc.number SUB_GRAPHIC_MATH_MATRIX3_ROTATE_2300 - * @tc.name test math matrix3-rotate api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Matrix3_Test_Rotate_2300, Function | MediumTest | Level0) -{ - Matrix3 rotate = Matrix3::Rotate(0, Vector2(0, 0)); - EXPECT_EQ(rotate.GetData()[0], 1); - EXPECT_EQ(rotate.GetData()[1], 0); - EXPECT_EQ(rotate.GetData()[3], 0); - EXPECT_EQ(rotate.GetData()[4], 1); -} - -/** - * @tc.number SUB_GRAPHIC_MATH_MATRIX3_SCALE_2400 - * @tc.name test math matrix3-scale api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Matrix3_Test_Scale_2400, Function | MediumTest | Level0) -{ - Matrix3 scale = Matrix3::Scale(Vector2(256, 256), Vector2(0, 0)); - EXPECT_EQ(scale.GetData()[0], 256); - EXPECT_EQ(scale.GetData()[4], 256); - EXPECT_EQ(scale.GetData()[6], 0); - EXPECT_EQ(scale.GetData()[7], 0); - EXPECT_EQ(scale.GetData()[8], 1); -} - -/** - * @tc.number SUB_GRAPHIC_MATH_MATRIX3_TRANSLATE_2500 - * @tc.name test math matrix3-translate api - * @tc.desc [C- SOFTWARE -0200] - */ -HWTEST_F(MathTest, Graphic_Matrix3_Test_Translate_2500, Function | MediumTest | Level0) -{ - Matrix3 translate = Matrix3::Translate(Vector2(0, 0)); - EXPECT_EQ(translate.GetData()[0], 1); - EXPECT_EQ(translate.GetData()[1], 0); - EXPECT_EQ(translate.GetData()[2], 0); - EXPECT_EQ(translate.GetData()[3], 0); - EXPECT_EQ(translate.GetData()[4], 1); - EXPECT_EQ(translate.GetData()[5], 0); - EXPECT_EQ(translate.GetData()[6], 0); - EXPECT_EQ(translate.GetData()[7], 0); - EXPECT_EQ(translate.GetData()[8], 1); -} -} // namespace OHOS \ No newline at end of file +} \ No newline at end of file diff --git a/graphic_lite/graphic_utils/heap_base_posix/BUILD.gn b/graphic_lite/graphic_utils/heap_base_posix/BUILD.gn index 4801635232f4e533f4c4e770975a7fc342557fc8..aebfc0508fd6a9a48cbfcb2cd51bafd7092dbb94 100755 --- a/graphic_lite/graphic_utils/heap_base_posix/BUILD.gn +++ b/graphic_lite/graphic_utils/heap_base_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsHeapBaseTest") { sources = [ "src/heap_base_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/graphic_utils/list_posix/BUILD.gn b/graphic_lite/graphic_utils/list_posix/BUILD.gn index fbc4887598467e0e0bd430eb4454510119bdd64b..b9e85390f39a95cac779fa7d030b8aabd3cac90a 100755 --- a/graphic_lite/graphic_utils/list_posix/BUILD.gn +++ b/graphic_lite/graphic_utils/list_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsListTest") { sources = [ "src/list_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/graphic_utils/mem_api_posix/BUILD.gn b/graphic_lite/graphic_utils/mem_api_posix/BUILD.gn index 9627edc04dfa4322041c74f29bf8683fa452ae5e..9c1d31f9fd3e46a2f317ab36aece2f3d2aac328d 100755 --- a/graphic_lite/graphic_utils/mem_api_posix/BUILD.gn +++ b/graphic_lite/graphic_utils/mem_api_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsGraphMemApiTest") { sources = [ "src/mem_api_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/graphic_utils/rect_posix/BUILD.gn b/graphic_lite/graphic_utils/rect_posix/BUILD.gn index 8fcef3bcc807d5306f9d9b8702d29e7072b4e4fc..a2fc00d6f29ded556061205b24652bbb3f8f26b8 100755 --- a/graphic_lite/graphic_utils/rect_posix/BUILD.gn +++ b/graphic_lite/graphic_utils/rect_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsRectTest") { sources = [ "src/rect_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/graphic_utils/sys_info_posix/BUILD.gn b/graphic_lite/graphic_utils/sys_info_posix/BUILD.gn index 340641fc7ec2a4fad60f235effc97a9e626fe500..9cbf70ba5956bbee3f07738f914d60e10f05e34b 100755 --- a/graphic_lite/graphic_utils/sys_info_posix/BUILD.gn +++ b/graphic_lite/graphic_utils/sys_info_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsSysInfoTest") { sources = [ "src/sys_info_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/graphic_utils/transform_posix/BUILD.gn b/graphic_lite/graphic_utils/transform_posix/BUILD.gn index ec291ecf95e7aa8fcbedb20eb6ede86f0399315e..f0858fe22fcb6ee664781389caeb324616842e47 100755 --- a/graphic_lite/graphic_utils/transform_posix/BUILD.gn +++ b/graphic_lite/graphic_utils/transform_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsTransformTest") { sources = [ "src/transform_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/graphic_utils/version_posix/BUILD.gn b/graphic_lite/graphic_utils/version_posix/BUILD.gn index d9032520a4548f871e2f555814bc25899b79eb4b..be39c42170df4ab92c285b4783eb059025b4c662 100755 --- a/graphic_lite/graphic_utils/version_posix/BUILD.gn +++ b/graphic_lite/graphic_utils/version_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsGraphVersionTest") { sources = [ "src/version_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/surface/surface_posix/BUILD.gn b/graphic_lite/surface/surface_posix/BUILD.gn index 5d17aa9c8b8afff2c9a3ba9cb8d1d505e22df632..d5aacb3e6f4277a5f6d4952ba68ece7163cd3a8d 100755 --- a/graphic_lite/surface/surface_posix/BUILD.gn +++ b/graphic_lite/surface/surface_posix/BUILD.gn @@ -21,8 +21,6 @@ hcpptest_suite("ActsSurfaceTest") { ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/a/BUILD.gn b/graphic_lite/ui/a/BUILD.gn index adb59ea254dcc36bcf233d25305ed42bbcd5495d..bee6356f611dbe13623a4a05e1816904746703f8 100755 --- a/graphic_lite/ui/a/BUILD.gn +++ b/graphic_lite/ui/a/BUILD.gn @@ -28,8 +28,6 @@ hcpptest_suite("ActsUiInterfaceTest") { } include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/animator_posix/BUILD.gn b/graphic_lite/ui/animator_posix/BUILD.gn index 95b8f1141724f6d867e1aef0d75f566df67ad4cc..4fe8c00d2ef04a100522796d1566cfe32e9c470e 100755 --- a/graphic_lite/ui/animator_posix/BUILD.gn +++ b/graphic_lite/ui/animator_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsAnimatorTest") { sources = [ "src/animator_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/easing_equation_posix/BUILD.gn b/graphic_lite/ui/easing_equation_posix/BUILD.gn index 00ade17f46015081970b68d43940ab80a26f6fb8..2988a3a1259f0693c85a83ef3f002b3d37d5bd14 100755 --- a/graphic_lite/ui/easing_equation_posix/BUILD.gn +++ b/graphic_lite/ui/easing_equation_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsEasingEquationTest") { sources = [ "src/test_easing_equation.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/events_posix/BUILD.gn b/graphic_lite/ui/events_posix/BUILD.gn index 406a25b44394e03b092b340c1d06cb03810d7810..00f2ba3b564da9ce17fa4e1def7469d3e57713ae 100755 --- a/graphic_lite/ui/events_posix/BUILD.gn +++ b/graphic_lite/ui/events_posix/BUILD.gn @@ -28,8 +28,6 @@ hcpptest_suite("ActsEventsTest") { ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/flexlayout_posix/BUILD.gn b/graphic_lite/ui/flexlayout_posix/BUILD.gn index 256896b023c54ead4b3d3fd39480cb9b7a642b40..a9698b9a5535f3c0a25f23012f72f346f08ba545 100755 --- a/graphic_lite/ui/flexlayout_posix/BUILD.gn +++ b/graphic_lite/ui/flexlayout_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsFlexlaoutTest") { sources = [ "src/test_flex_layout.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/gridlayout_posix/BUILD.gn b/graphic_lite/ui/gridlayout_posix/BUILD.gn index 580b61fa073be2a61cf8eb640a3fbe7b826b5caf..42e9ebeb51b467b7daf35df409cc246fd9077482 100755 --- a/graphic_lite/ui/gridlayout_posix/BUILD.gn +++ b/graphic_lite/ui/gridlayout_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsGridLayoutTest") { sources = [ "src/test_grid_layout.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/image_posix/BUILD.gn b/graphic_lite/ui/image_posix/BUILD.gn index e843423fb0816d336902e050f41d8e1c83f695f9..ae530849ae0d39d6cb3d01be8eda929a29e2005a 100755 --- a/graphic_lite/ui/image_posix/BUILD.gn +++ b/graphic_lite/ui/image_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsImageTest") { sources = [ "src/image_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/interpolation_posix/BUILD.gn b/graphic_lite/ui/interpolation_posix/BUILD.gn index 504d958d58645ca52c821cd1efc16ee8e739d359..2ba18c3ba411e470cb9348a5a7f09111c63ff54b 100755 --- a/graphic_lite/ui/interpolation_posix/BUILD.gn +++ b/graphic_lite/ui/interpolation_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsInterpoliationTest") { sources = [ "src/interpolation_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/layout_posix/BUILD.gn b/graphic_lite/ui/layout_posix/BUILD.gn index e3f1da1420db30e03a85f807b100c140902e6b9c..af2b887e0a3dd1ef6f926cda14cc9aa3afb4cd00 100755 --- a/graphic_lite/ui/layout_posix/BUILD.gn +++ b/graphic_lite/ui/layout_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsLayoutTest") { sources = [ "src/test_layout.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/listlayout_posix/BUILD.gn b/graphic_lite/ui/listlayout_posix/BUILD.gn index 075630e96991b9a81586c75f961da6e89ccc5ad8..0762d7d52d36bba28eba83fe34870b96fcd30711 100755 --- a/graphic_lite/ui/listlayout_posix/BUILD.gn +++ b/graphic_lite/ui/listlayout_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsListlayoutTest") { sources = [ "src/list_layout_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/screen_posix/BUILD.gn b/graphic_lite/ui/screen_posix/BUILD.gn index ac0d3e24534d051ca5a2d022d8564331bdf5d8d3..8dfa19520ec651ebb17163d5030e73b91ad5231f 100755 --- a/graphic_lite/ui/screen_posix/BUILD.gn +++ b/graphic_lite/ui/screen_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsScreenTest") { sources = [ "src/screen_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/style_posix/BUILD.gn b/graphic_lite/ui/style_posix/BUILD.gn index 7765af26c9611bbce057b5e1e60fb130681026eb..9186e380d60724169381a622e5752c73546b1308 100755 --- a/graphic_lite/ui/style_posix/BUILD.gn +++ b/graphic_lite/ui/style_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsStyleTest") { sources = [ "src/style_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/theme_posix/BUILD.gn b/graphic_lite/ui/theme_posix/BUILD.gn index 5aa12f7ac73a231a551acf943078721284b74425..b1b6d034c8254e98d26102da3282b71232ffa004 100755 --- a/graphic_lite/ui/theme_posix/BUILD.gn +++ b/graphic_lite/ui/theme_posix/BUILD.gn @@ -21,8 +21,6 @@ hcpptest_suite("ActsThemeTest") { ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_abstract_progress_posix/BUILD.gn b/graphic_lite/ui/ui_abstract_progress_posix/BUILD.gn index 85eaa1be7d4a7acefbb8added61d46d55953d8ed..bc5dc42b3e429a4514822f52b4434cdb376c92a5 100755 --- a/graphic_lite/ui/ui_abstract_progress_posix/BUILD.gn +++ b/graphic_lite/ui/ui_abstract_progress_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUIAbstractProgressTest") { sources = [ "src/ui_abstract_progress_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_analog_clock_posix/BUILD.gn b/graphic_lite/ui/ui_analog_clock_posix/BUILD.gn index 0d8a48098a96267f70780d28a6ecf74ad9abaf87..248fb72e90b733533c32d10a777d2dc9a3e057ae 100755 --- a/graphic_lite/ui/ui_analog_clock_posix/BUILD.gn +++ b/graphic_lite/ui/ui_analog_clock_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUIAnalogClockTest") { sources = [ "src/ui_analog_clock_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_arc_lable_posix/BUILD.gn b/graphic_lite/ui/ui_arc_lable_posix/BUILD.gn index f9322d142b8707d93bf81b198078681ab0579565..b6b80698d16b4f95a9c0ffe39edbf569aff2e1f6 100755 --- a/graphic_lite/ui/ui_arc_lable_posix/BUILD.gn +++ b/graphic_lite/ui/ui_arc_lable_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUIArcLabelTest") { sources = [ "src/ui_arc_label_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_axis_posix/BUILD.gn b/graphic_lite/ui/ui_axis_posix/BUILD.gn index 2849d22b544fb7e8fe5f3380fc572ce883406ad8..60e9a2c3991c3e3b12b21b5dcb48b47a855e4ab3 100755 --- a/graphic_lite/ui/ui_axis_posix/BUILD.gn +++ b/graphic_lite/ui/ui_axis_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUIAxisTest") { sources = [ "src/ui_axis_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_box_porgress_posix/BUILD.gn b/graphic_lite/ui/ui_box_porgress_posix/BUILD.gn index 45e1b889f0027672ac14fce01d17f3a6203b52d7..f0e9f103da078a05ec84341d24001a473091e405 100755 --- a/graphic_lite/ui/ui_box_porgress_posix/BUILD.gn +++ b/graphic_lite/ui/ui_box_porgress_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUIBoxProgressTest") { sources = [ "src/ui_box_progress_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_button_posix/BUILD.gn b/graphic_lite/ui/ui_button_posix/BUILD.gn index b7fce2fc97160979f6f59e67de9d392250a6bcb3..9b70e099b4c1ba4298c5969e5ce5850efdd3d182 100755 --- a/graphic_lite/ui/ui_button_posix/BUILD.gn +++ b/graphic_lite/ui/ui_button_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUIButtonTest") { sources = [ "src/ui_button_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_canvas_posix/BUILD.gn b/graphic_lite/ui/ui_canvas_posix/BUILD.gn index 3d6bc017f468c553be5f68781b4bd7637df69c4d..53a4e2387501ba6d7642c6787eb03985ea92eb48 100755 --- a/graphic_lite/ui/ui_canvas_posix/BUILD.gn +++ b/graphic_lite/ui/ui_canvas_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUICanvasTest") { sources = [ "src/ui_canvas_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_chart_posix/BUILD.gn b/graphic_lite/ui/ui_chart_posix/BUILD.gn index b73af2a6d90e94ba6dfefe95c0320393b81a9d7a..668f883ca2afe5ce951385ffd4b88d2936184a21 100755 --- a/graphic_lite/ui/ui_chart_posix/BUILD.gn +++ b/graphic_lite/ui/ui_chart_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUIChartTest") { sources = [ "src/ui_chart_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_checbox_posix/BUILD.gn b/graphic_lite/ui/ui_checbox_posix/BUILD.gn index 02a5e9f0a077af45a6ce0977e7e27fad0293a559..7e2280b9cc89d46164986c91b0988f4fb4484827 100755 --- a/graphic_lite/ui/ui_checbox_posix/BUILD.gn +++ b/graphic_lite/ui/ui_checbox_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUICheckboxTest") { sources = [ "src/ui_checkbox_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_circle_progress_posix/BUILD.gn b/graphic_lite/ui/ui_circle_progress_posix/BUILD.gn index 0439b24f48467b552e93d829fed013f83d21610e..8a970523a91c72fafe1099b1c964d44706d269d6 100755 --- a/graphic_lite/ui/ui_circle_progress_posix/BUILD.gn +++ b/graphic_lite/ui/ui_circle_progress_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUICircleProgressTest") { sources = [ "src/ui_circle_progress_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_digital_clock_posix/BUILD.gn b/graphic_lite/ui/ui_digital_clock_posix/BUILD.gn index 02c1e33ce59ea4cd24b1280546eea3428783b465..57fb0140e3d5d23c2fe73abd39841ea04ad271de 100755 --- a/graphic_lite/ui/ui_digital_clock_posix/BUILD.gn +++ b/graphic_lite/ui/ui_digital_clock_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUIDigitalClockTest") { sources = [ "src/ui_digital_clock_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_image_animator_posix/BUILD.gn b/graphic_lite/ui/ui_image_animator_posix/BUILD.gn index dfffa0c4e5692efca1c11e9bf3142ef89d71b7dc..719e859a202176b3b66bd0570f018c8721a32069 100755 --- a/graphic_lite/ui/ui_image_animator_posix/BUILD.gn +++ b/graphic_lite/ui/ui_image_animator_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUIImageAnimatorTest") { sources = [ "src/ui_image_animator_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_image_posix/BUILD.gn b/graphic_lite/ui/ui_image_posix/BUILD.gn index a11e3173103d722102a5ffb8cd90c3df4085ec5a..c93f817ea8f609f769ed5ef01aaae2d7ab5ef566 100755 --- a/graphic_lite/ui/ui_image_posix/BUILD.gn +++ b/graphic_lite/ui/ui_image_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUIImageTest") { sources = [ "src/ui_image_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_label_button_posix/BUILD.gn b/graphic_lite/ui/ui_label_button_posix/BUILD.gn index ef1e317bf381540a0111c52b49910ae4c008c600..ddf49f09bbc5b5296459369c09c893872b3125e3 100755 --- a/graphic_lite/ui/ui_label_button_posix/BUILD.gn +++ b/graphic_lite/ui/ui_label_button_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUILabelButtonTest") { sources = [ "src/ui_label_button_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_label_posix/BUILD.gn b/graphic_lite/ui/ui_label_posix/BUILD.gn index eeae7e01b4ac03f81d052b818ad7d33cf05577d2..a6a74807a21619916133f72ee1693744c8101dc8 100755 --- a/graphic_lite/ui/ui_label_posix/BUILD.gn +++ b/graphic_lite/ui/ui_label_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUILabelTest") { sources = [ "src/ui_label_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_list_posix/BUILD.gn b/graphic_lite/ui/ui_list_posix/BUILD.gn index 616d68e62610746f7450236b1fb02832f064ecc0..81a2a0f4f7909220461c638bd05b0080539a907e 100755 --- a/graphic_lite/ui/ui_list_posix/BUILD.gn +++ b/graphic_lite/ui/ui_list_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUIListTest") { sources = [ "src/ui_list_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_picker_posix/BUILD.gn b/graphic_lite/ui/ui_picker_posix/BUILD.gn index 4ed3187cf0d265b8db669a733dab37b999bf67c9..266202db6e27cb79b0139e6d09b3151b322aec30 100755 --- a/graphic_lite/ui/ui_picker_posix/BUILD.gn +++ b/graphic_lite/ui/ui_picker_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUIPickerTest") { sources = [ "src/ui_picker_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_radio_button_posix/BUILD.gn b/graphic_lite/ui/ui_radio_button_posix/BUILD.gn index 111b1305c76ad79252b78bdf7d42bd1dcab54353..e543c237ea2621a5bf292e13247effad9f97deba 100755 --- a/graphic_lite/ui/ui_radio_button_posix/BUILD.gn +++ b/graphic_lite/ui/ui_radio_button_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUIRadioButtonTest") { sources = [ "src/ui_radio_button_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_repeat_button_posix/BUILD.gn b/graphic_lite/ui/ui_repeat_button_posix/BUILD.gn index 0a6de8b2c1b97105edeb79af232fa50cbe3e0082..95b0435a84ff9e3d7f26ccde6a6e60558bb915cc 100755 --- a/graphic_lite/ui/ui_repeat_button_posix/BUILD.gn +++ b/graphic_lite/ui/ui_repeat_button_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUIRepeatButtonTest") { sources = [ "src/ui_repeat_button_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_screenshot_posix/BUILD.gn b/graphic_lite/ui/ui_screenshot_posix/BUILD.gn index a7f21b4374f6b5e4b79e9ef81eea0b66520c2f91..c2427d4a54282490b6dc5a3b6b93c2f30458c987 100755 --- a/graphic_lite/ui/ui_screenshot_posix/BUILD.gn +++ b/graphic_lite/ui/ui_screenshot_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUIScreenshotTest") { sources = [ "src/ui_screenshot_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_scroll_view_posix/BUILD.gn b/graphic_lite/ui/ui_scroll_view_posix/BUILD.gn index 80b52adc2705cc7f7ea11685827c149e87bee70f..f7f449d51822586562b0ecb0c0b9b36fb55b413d 100755 --- a/graphic_lite/ui/ui_scroll_view_posix/BUILD.gn +++ b/graphic_lite/ui/ui_scroll_view_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUIScrollViewTest") { sources = [ "src/ui_scroll_view_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_slider_posix/BUILD.gn b/graphic_lite/ui/ui_slider_posix/BUILD.gn index 6c2446017ccc0f001036f5186815874ce51e7578..bbee1efb31575d892f12d31f66d7ab4e29a8bb0f 100755 --- a/graphic_lite/ui/ui_slider_posix/BUILD.gn +++ b/graphic_lite/ui/ui_slider_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUISliderTest") { sources = [ "src/ui_slider_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_surface_view_posix/BUILD.gn b/graphic_lite/ui/ui_surface_view_posix/BUILD.gn index 88596348255a9c84ce0c877d9675ba7376f0376d..6076a71cc0f94ecaf15cd015ac58482d35e38600 100755 --- a/graphic_lite/ui/ui_surface_view_posix/BUILD.gn +++ b/graphic_lite/ui/ui_surface_view_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUISurfaceViewTest") { sources = [ "src/ui_surface_view_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_swipe_view_posix/BUILD.gn b/graphic_lite/ui/ui_swipe_view_posix/BUILD.gn index a8e2d03e84ee673b523fa7385b84750e8811504b..20a2cf1ba7e95978aa91880a16a540eec8f004c3 100755 --- a/graphic_lite/ui/ui_swipe_view_posix/BUILD.gn +++ b/graphic_lite/ui/ui_swipe_view_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUISwipeViewTest") { sources = [ "src/ui_swipe_view_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_text_posix/BUILD.gn b/graphic_lite/ui/ui_text_posix/BUILD.gn index 46b8c78cb2a9c8645f269a14a5bf6f9d866cb17a..e5ee22d2a60fde23b2bf0c6398a7032ee3d65347 100755 --- a/graphic_lite/ui/ui_text_posix/BUILD.gn +++ b/graphic_lite/ui/ui_text_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUITextTest") { sources = [ "src/ui_text_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_texture_mapper_posix/BUILD.gn b/graphic_lite/ui/ui_texture_mapper_posix/BUILD.gn index e625b28764fb72a2c9d7a9f3951ef8e21d0c2623..e9b37a85394c1f2b415bfc92c44b6dff2431a83c 100755 --- a/graphic_lite/ui/ui_texture_mapper_posix/BUILD.gn +++ b/graphic_lite/ui/ui_texture_mapper_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUITextureMapperTest") { sources = [ "src/ui_texture_mapper_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_time_picker_posix/BUILD.gn b/graphic_lite/ui/ui_time_picker_posix/BUILD.gn index c6140bf0e1ee0ef3904fe22e812715074a0a881c..c4aec9bafb9e63c296a5afdb26c0cf8dd71b0f7a 100755 --- a/graphic_lite/ui/ui_time_picker_posix/BUILD.gn +++ b/graphic_lite/ui/ui_time_picker_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUITimePickerTest") { sources = [ "src/ui_time_picker_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_toggle_button_posix/BUILD.gn b/graphic_lite/ui/ui_toggle_button_posix/BUILD.gn index 3ab94fe1e2409cb2ebfa933d1fcabb277980e3e8..de43827b6f20de1ef87f29fcbeb0faf7937c3f27 100755 --- a/graphic_lite/ui/ui_toggle_button_posix/BUILD.gn +++ b/graphic_lite/ui/ui_toggle_button_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUIToggleButtonTest") { sources = [ "src/ui_toggle_button_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_view_group_posix/BUILD.gn b/graphic_lite/ui/ui_view_group_posix/BUILD.gn index 04c7e86ac8723183ca725a25191aaad4c2b5ac52..5f687b70c01a552536e8de20d6532d9f8a68b61f 100755 --- a/graphic_lite/ui/ui_view_group_posix/BUILD.gn +++ b/graphic_lite/ui/ui_view_group_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUIViewGroupTest") { sources = [ "src/ui_view_group_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/ui_view_posix/BUILD.gn b/graphic_lite/ui/ui_view_posix/BUILD.gn index 660055bb501e481b72c9a3ce3e899014b07b6066..e0cd78b361fd4874dfc24366bc8151689b667a6c 100755 --- a/graphic_lite/ui/ui_view_posix/BUILD.gn +++ b/graphic_lite/ui/ui_view_posix/BUILD.gn @@ -21,8 +21,6 @@ hcpptest_suite("ActsUIViewTest") { ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/uianimator_posix/BUILD.gn b/graphic_lite/ui/uianimator_posix/BUILD.gn index 005bb3b418f216b646da8bf2c9b73a616fb75356..00b9839dcbeb66b6dfcb08511e585030ae93893e 100755 --- a/graphic_lite/ui/uianimator_posix/BUILD.gn +++ b/graphic_lite/ui/uianimator_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUIAnimatorTest") { sources = [ "src/easing_equation_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/uidfx_posix/BUILD.gn b/graphic_lite/ui/uidfx_posix/BUILD.gn index b1126b81784eb53bb7f74d11c525586ef8068c86..1a40d3f38c2254c4a49b3a50960be9deddc3b21a 100755 --- a/graphic_lite/ui/uidfx_posix/BUILD.gn +++ b/graphic_lite/ui/uidfx_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUIDfxTest") { sources = [ "src/dump_dom_tree_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/graphic_lite/ui/uifont_posix/BUILD.gn b/graphic_lite/ui/uifont_posix/BUILD.gn index 2fa2d347f342b6e502d32a00d6d7729cb6fa4f70..e7349dc035a6a7b83edc3ce90b5650c4235f629f 100755 --- a/graphic_lite/ui/uifont_posix/BUILD.gn +++ b/graphic_lite/ui/uifont_posix/BUILD.gn @@ -18,8 +18,6 @@ hcpptest_suite("ActsUIFontTest") { sources = [ "src/font_test.cpp" ] include_dirs = [ - "//kernel/liteos_a/kernel/include/", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include", "//third_party/cJSON", "//third_party/libpng", diff --git a/hiviewdfx/hilogtest/libhilogtest/BUILD.gn b/hiviewdfx/hilogtest/libhilogtest/BUILD.gn index f7225b97f2eec1479b024d7ca2e0f31aa5b93eda..b8fa07e06d5e994fbbd20e1d8ccabed4fecb3425 100755 --- a/hiviewdfx/hilogtest/libhilogtest/BUILD.gn +++ b/hiviewdfx/hilogtest/libhilogtest/BUILD.gn @@ -16,5 +16,6 @@ group("libhilogtestacts") { deps = [ "libhilogCPPtest:LibhilogCPPtest", "libhilogCtest:libhilogCtest", + "hilogtest:hilogtest", ] } diff --git a/hiviewdfx/hilogtest/libhilogtest/hilogtest/BUILD.gn b/hiviewdfx/hilogtest/libhilogtest/hilogtest/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..3c49f4b2f0875bb884232bd9e662d946317d88af --- /dev/null +++ b/hiviewdfx/hilogtest/libhilogtest/hilogtest/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/hilogtest" + +############################################################################### +config("hilogtest_config") { + visibility = [ ":*" ] + include_dirs = [ + "../../../utils/native", + "//utils/native/base/include/", + "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", + ] +} +ohos_moduletest_suite("hilogtest") { + module_out_path = module_output_path + sources = [ "hilogtest.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/hilogtest/Test.json b/hiviewdfx/hilogtest/libhilogtest/hilogtest/Test.json new file mode 100755 index 0000000000000000000000000000000000000000..5c034405b2750a10bce8275dc9e865846836dcd7 --- /dev/null +++ b/hiviewdfx/hilogtest/libhilogtest/hilogtest/Test.json @@ -0,0 +1,21 @@ +{ + "kits": [ + { + "push": [ + "hilogtest->/data/local/tmp/hilogtest" + ], + "type": "PushKit", + "post-push": [ + "chmod -R 777 /data/local/tmp/*" + ] + } + ], + "driver": { + "native-test-timeout": "120000", + "type": "CppTest", + "module-name": "hilogtest", + "runtime-hint": "1s", + "native-test-device-path": "/data/local/tmp" + }, + "description": "Configuration for hilogtest Tests" +} \ No newline at end of file diff --git a/hiviewdfx/hilogtest/libhilogtest/hilogtest/hilogtest.cpp b/hiviewdfx/hilogtest/libhilogtest/hilogtest/hilogtest.cpp new file mode 100755 index 0000000000000000000000000000000000000000..adc42b524a06dad1f64878a1f68cc210b734e9d9 --- /dev/null +++ b/hiviewdfx/hilogtest/libhilogtest/hilogtest/hilogtest.cpp @@ -0,0 +1,738 @@ +/* + * 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 "file_utils.h" +#include "hilog/log_c.h" +#include "hilog/log_cpp.h" + +#undef LOG_DOMAIN +#undef LOG_TAG +#define LOG_DOMAIN 0xD003200 +#define LOG_TAG "HILOGTOOLTEST" +#define MAX_LINE 1024*10 +using namespace OHOS; +using namespace HiviewDFX; +using namespace testing::ext; +using namespace std; + +class hilogtest : public testing::Test { +public: + string input = ""; + string result = ""; + string expect = ""; + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + string gHilogtoolExecutable = "hilog "; + string g_logContent = "123456789_1234567890_public and private log test is:\ + %{public}d, %{private}lf, %{public}.2f, %s, %{private}c\n"; + string g_commonContent = "03200/HILOGTOOLTEST: 123456789_1234567890_public and private log test is:"; +private: +}; +void hilogtest::SetUp() +{ +} +void hilogtest::TearDown() +{ +} +void hilogtest::SetUpTestCase() +{ + ExeCmd("hilog -p on"); + ExeCmd("hilog -Q domainoff"); + ExeCmd("hilog -Q pidoff"); + ExeCmd("hilog -b debug"); + ExeCmd("hilog -b debug -D 218116608"); + ExeCmd("hilog -b debug -T HILOGTOOLTEST"); + ExeCmd("hilog -r -t all"); + ExeCmd("hilog -G 1m -t all"); + ExeCmd("hilog -S -t all"); + ExeCmd("hilog -S -D 218116608"); +} +void hilogtest::TearDownTestCase() +{ + ExeCmd("hilog -p on"); + ExeCmd("hilog -Q domainoff"); + ExeCmd("hilog -Q pidoff"); + ExeCmd("hilog -b debug"); + ExeCmd("hilog -b debug -D 218116608"); + ExeCmd("hilog -b debug -T HILOGTOOLTEST"); + ExeCmd("hilog -r -t all"); + ExeCmd("hilog -G 1m -t all"); + ExeCmd("hilog -S -t all"); + ExeCmd("hilog -S -D 218116608"); + std::cout << "TearDownTestCase" << std::endl; +} + + +/* + * @tc.name one-time read + * @tc.number DFX_DFT_HilogCPP_0840 + * @tc.desc one-time read +*/ +HWTEST_F(hilogtest, Hilogtool_exit, Function|MediumTest|Level3) +{ + CleanCmd(); + std::string saveFile= "test_data_31.txt"; + std::string cmd1 = gHilogtoolExecutable + " -r"; + std::string cmdResult; + CmdRun(cmd1, cmdResult); + LogType type = LOG_APP; + int i = 0; + while (i++ <= 5) { + usleep(1000); + HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a'); + } + std::string cmd2 = gHilogtoolExecutable + "-T HILOGTOOLTEST -x"; + SaveCmdOutput(cmd2, saveFile); + string hilogInfo = ReadFile(saveFile); + bool result = false; + std::vector para = {g_commonContent}; + if (hilogInfo != "") { + result = CheckInfo(para, hilogInfo); + } else { + std::cout << "Hilogtool_exit error" << std::endl; + } + ASSERT_TRUE(true == result); +} + +/* + * @tc.name The log tool can read app log types at a time. + * @tc.number DFX_DFT_HilogCPP_0860 + * @tc.desc The log tool can read app log types at a time. +*/ +HWTEST_F(hilogtest, Hilogtool_type_app, Function|MediumTest|Level3) +{ + CleanCmd(); + std::string saveFile= "test_data_33_1.txt"; + LogType type = LOG_APP; + int i = 0; + while (i++ <= 5) { + usleep(1000); + HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a'); + } + std::string cmd = gHilogtoolExecutable + " -t app -x "; + SaveCmdOutput(cmd, saveFile); + string hilogInfo = ReadFile(saveFile); + bool result = false; + std::vector para = {g_commonContent}; + if (hilogInfo != " ") { + result = CheckInfo(para, hilogInfo); + } else { + std::cout << "Hilogtool_type_app error"; + } + ASSERT_TRUE(true == result); +} + + +/* + * @tc.name The log tool can read core log types at a time. + * @tc.number DFX_DFT_HilogCPP_0870 + * @tc.desc The log tool can read core log types at a time +*/ +HWTEST_F(hilogtest, Hilogtool_type_core, Function|MediumTest|Level3) +{ + CleanCmd(); + std::string saveFile= "test_data_33_2.txt"; + LogType type = LOG_CORE; + int i = 0; + while (i++ <= 5) { + usleep(1000); + HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a'); + } + std::string cmd = gHilogtoolExecutable + " -t core -x "; + SaveCmdOutput(cmd, saveFile); + string hilogInfo = ReadFile(saveFile); + bool result = false; + std::vector para = {g_commonContent}; + if (hilogInfo != "") { + result = CheckInfo(para, hilogInfo); + } else { + std::cout << "Hilogtool_type_app error"< para = {g_commonContent}; + if (hilogInfo != "") { + result = CheckInfo(para, hilogInfo); + } else { + std::cout << "Hilogtool_type_init error"; + } + ASSERT_TRUE(true == result); +} + +/* + * @tc.name The log tool can read Hilogtool_type_multiple log types at a time. + * @tc.number DFX_DFT_HilogCPP_0890 + * @tc.desc The log tool can read Hilogtool_type_multiple log types at a time. +*/ +HWTEST_F(hilogtest, Hilogtool_type_multiple, Function|MediumTest|Level2) +{ + CleanCmd(); + std::string saveFile= "test_data_33_4.txt"; + LogType type = LOG_INIT; + int i = 0; + while (i++ <= 3) { + usleep(1000); + HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a'); + type = LOG_INIT; + HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a'); + type = LOG_APP; + HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a'); + } + std::string cmd = gHilogtoolExecutable + "-D 0xd003200 -t app core init -x "; + SaveCmdOutput(cmd, saveFile); + string hilogInfo = ReadFile(saveFile); + bool result = false; + std::vector para = {g_commonContent}; + if (hilogInfo != "") { + result = CheckInfo(para, hilogInfo); + } else { + std::cout << "Hilogtool_type_multiple error"; + } + ASSERT_TRUE(true == result); +} + +/* + * @tc.name show local time + * @tc.number DFX_DFT_HilogCPP_0950 + * @tc.desc show local time +*/ +HWTEST_F(hilogtest, Hilogtool_time, Function|MediumTest|Level3) +{ + std::string cmd = gHilogtoolExecutable + " -a 1 -v time "; + std::string saveFile= "test_data_35_1.txt"; + SaveCmdOutput(cmd, saveFile); + string hilogInfo = ReadFile(saveFile); + bool result = false; + std::regex pattern( + "(0\\d{1}|1[0-2])-(0\\d{1}|[12]\\d{1}|3[01])\\s(0\\d{1}|1\\d{1}|2[0-3]):[0-5]\\d{1}:([0-5]\\d{1})(\\.(\\d){0,3})?$"); + std::cout << hilogInfo.substr(0, 18); + string timeBuffer = hilogInfo.substr(0, 18); + std::smatch match; + bool ismatch = regex_match(timeBuffer, match, pattern); + if (ismatch) { + std::cout<<"match successed"< para = {g_commonContent}; + if (hilogInfo != " ") { + result = CheckInfo(para, hilogInfo); + } else { + std::cout << "Hilogtool_regex_null error"; + } + ASSERT_TRUE(true == result); +} + +/* + * @tc.name Filtering by regular expression + * @tc.number DFX_DFT_HilogCPP_1880 + * @tc.desc Filtering by regular expression +*/ +HWTEST_F(hilogtest, Hilogtool_regex, Function|MediumTest|Level3) +{ + CleanCmd(); + std::string cmd1 = gHilogtoolExecutable + " -x -e \"^(123)\""; + + char saveFile462[] = "test_data_46_2.txt"; + SaveCmdOutput(cmd1, saveFile462); + string hilogInfo = ReadFile(saveFile462); + bool result = false; + std::vector para = {"03200/HILOGTOOLTEST"}; + if (hilogInfo != "") { + result = CheckInfo(para, hilogInfo); + } else { + std::cout << "Hilogtool_regex error"; + } + ASSERT_TRUE(true == result); + CleanCmd(); + std::string cmd2 = gHilogtoolExecutable + " -x -e \"^(www)\""; + char saveFile463[] = "test_data_46_3.txt"; + SaveCmdOutput(cmd2, saveFile463); + hilogInfo = ReadFile(saveFile463); + if (hilogInfo != " ") { + result = CheckInfo(para, hilogInfo); + } else { + std::cout << "Hilogtool_regex error"; + } + ASSERT_TRUE(false == result); +} + +/* + * @tc.name show the first 1 row + * @tc.number DFX_DFT_HilogCPP_1890 + * @tc.desc show the first 1 row +*/ + +HWTEST_F(hilogtest, Hilogtool_head_1, Function|MediumTest|Level3) +{ + CleanCmd(); + LogType type = LOG_INIT; + int cnt =20; + int i = 0; + while (i++ <= cnt) { + usleep(1); + HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a'); + } + std::string cmd = gHilogtoolExecutable + " -a 1 -x "; + std::string saveFile = "test_data_47_1.txt"; + SaveCmdOutput(cmd, saveFile); + string hilogInfo = ReadFile(saveFile); + bool result = false; + std::vector para = {g_commonContent}; + if (hilogInfo != " ") { + result = CheckInfo(para, hilogInfo); + } else { + std::cout << "Hilogtool_n error"; + } + ASSERT_TRUE(true == result); +} + +/* + * @tc.name show first 20 rows + * @tc.number DFX_DFT_HilogCPP_1900 + * @tc.desc show first 20 rows +*/ +HWTEST_F(hilogtest, Hilogtool_head_20, Function|MediumTest|Level4) +{ + CleanCmd(); + LogType type = LOG_INIT; + int cnt =20; + int i = 0; + while (i++ <= cnt) { + usleep(1); + HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a'); + } + std::string saveFile= "test_data_47_2.txt"; + std::string cmd = gHilogtoolExecutable + " -a 20 -x "; + SaveCmdOutput(cmd, saveFile); + int n = GetTxtLine(saveFile); + ASSERT_TRUE(n == 20); +} + +/* + * @tc.name show the last 1 row + * @tc.number DFX_DFT_HilogCPP_1910 + * @tc.desc show the last 1 row +*/ +HWTEST_F(hilogtest, Hilogtool_tail_1, Function|MediumTest|Level4) +{ + CleanCmd(); + LogType type = LOG_INIT; + int cnt =20; + int i = 0; + while (i++ <= cnt) { + usleep(1); + HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a'); + } + std::string saveFile= "test_data_47_3.txt"; + std::string cmd = gHilogtoolExecutable + "-t init -z 1"; + SaveCmdOutput(cmd, saveFile); + sleep(2); + string hilogInfo = ReadFile(saveFile); + bool result = false; + std::vector para = {g_commonContent}; + if (hilogInfo != " ") { + result = CheckInfo(para, hilogInfo); + } else { + std::cout << "Hilogtool_n error"; + } + ASSERT_TRUE(true == result); +} + +/* + * @tc.name show last 20 rows + * @tc.number DFX_DFT_HilogCPP_1920 + * @tc.desc show last 20 rows +*/ +HWTEST_F(hilogtest, Hilogtool_tail_20, Function|MediumTest|Level4) +{ + CleanCmd(); + LogType type = LOG_INIT; + int cnt =20; + int i = 0; + while (i++ <= cnt) { + usleep(1); + HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a'); + } + std::string saveFile= "test_data_47_4.txt"; + std::string cmd = gHilogtoolExecutable + "-t init -z 20"; + SaveCmdOutput(cmd, saveFile); + int n = GetTxtLine(saveFile); + ASSERT_TRUE(n == 20); +} + +/* + * @tc.name The filtering parameter is empty. + * @tc.number DFX_DFT_HilogCPP_1930 + * @tc.desc The filtering parameter is empty. +*/ +HWTEST_F(hilogtest, Hilogtool_filter_null, Function|MediumTest|Level4) +{ + CleanCmd(); + LogType type = LOG_INIT; + + int cnt =20; + int i = 0; + while (i++ <= cnt) { + usleep(1000); + HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a'); + } + std::string saveFile= "test_data_48_1.txt"; + std::string cmd = gHilogtoolExecutable + " -t init -x"; + SaveCmdOutput(cmd, saveFile); + string hilogInfo = ReadFile(saveFile); + bool result = false; + std::vector para = {g_commonContent}; + if (hilogInfo != "") { + result = CheckInfo(para, hilogInfo); + } else { + std::cout << "Hilogtool_filter error"; + } + ASSERT_TRUE(true == result); +} + +/* + * @tc.name Filter level only. + * @tc.number DFX_DFT_HilogCPP_1960 + * @tc.desc Filter level only. +*/ + +HWTEST_F(hilogtest, Hilogtool_filter_level, Function|MediumTest|Level4) +{ + CleanCmd(); + LogType type = LOG_INIT; + int cnt =20; + int i = 0; + while (i++ <= cnt) { + usleep(1); + HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a'); + } + std::string saveFile= "test_data_48_4.txt"; + std::string cmd = gHilogtoolExecutable + " -t init -L D -x"; + SaveCmdOutput(cmd, saveFile); + string hilogInfo = ReadFile(saveFile); + bool result = false; + std::vector para = {g_commonContent}; + if (hilogInfo != "") { + result = CheckInfo(para, hilogInfo); + } else { + std::cout << "Hilogtool_filter error"; + } + ASSERT_TRUE(true == result); +} + +/* + * @tc.name Filter domain only. + * @tc.number DFX_DFT_HilogCPP_1970 + * @tc.desc Filter domain only. +*/ + +HWTEST_F(hilogtest, Hilogtool_filter_domain, Function|MediumTest|Level3) +{ + CleanCmd(); + LogType type = LOG_INIT; + + int cnt =20; + int i = 0; + while (i++ <= cnt) { + usleep(1); + HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a'); + } + std::string saveFile= "test_data_48_3.txt"; + std::string cmd = gHilogtoolExecutable + " -t init -D 0xd003200 -x"; + SaveCmdOutput(cmd, saveFile); + string hilogInfo = ReadFile(saveFile); + bool result = false; + std::vector para = {g_commonContent}; + if (hilogInfo != "") { + result = CheckInfo(para, hilogInfo); + } else { + std::cout << "Hilogtool_filter error"; + } + ASSERT_TRUE(true == result); +} + +/* + * @tc.name Filter tag only. + * @tc.number DFX_DFT_HilogCPP_1980 + * @tc.desc Filter tag only. +*/ +HWTEST_F(hilogtest, Hilogtool_filter_tag, Function|MediumTest|Level4) +{ + CleanCmd(); + LogType type = LOG_INIT; + int cnt = 20; + int i = 0; + while (i++ <= cnt) { + usleep(1); + HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a'); + } + std::string saveFile= "test_data_48_5.txt"; + std::string cmd = gHilogtoolExecutable + " -T HILOGTOOLTEST -x"; + SaveCmdOutput(cmd, saveFile); + string hilogInfo = ReadFile(saveFile); + bool result = false; + std::vector para = {g_commonContent}; + if (hilogInfo != " ") { + result = CheckInfo(para, hilogInfo); + } else { + std::cout << "Hilogtool_filter error"; + } + ASSERT_TRUE(true == result); +} + +/* + * @tc.name Filter Multi-parameter + * @tc.number DFX_DFT_HilogCPP_1990 + * @tc.desc Filter Multi-parameter +*/ + +HWTEST_F(hilogtest, Hilogtool_filter_multiple, Function|MediumTest|Level2) +{ + CleanCmd(); + LogType type = LOG_INIT; + int i = 0; + int cnt = 20; + while (i++ <= cnt) { + usleep(1); + HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a'); + } + std::string saveFile= "test_data_48_6.txt"; + std::string cmd = gHilogtoolExecutable + \ + " -T HILOGTOOLTEST -L D -x"; + SaveCmdOutput(cmd, saveFile); + string hilogInfo = ReadFile(saveFile); + bool result = false; + std::vector para = {g_commonContent}; + if (hilogInfo != " ") { + result = CheckInfo(para, hilogInfo); + } else { + std::cout << "Hilogtool_filter error"; + } + ASSERT_TRUE(true == result); +} diff --git a/hiviewdfx_lite/hilog_posix/BUILD.gn b/hiviewdfx_lite/hilog_posix/BUILD.gn index d6d863a75230270e15a3d906b385256b24dfe54b..556689eac29bc7ceacbcad8e20b3bda728738ba1 100755 --- a/hiviewdfx_lite/hilog_posix/BUILD.gn +++ b/hiviewdfx_lite/hilog_posix/BUILD.gn @@ -21,7 +21,6 @@ hcpptest_suite("ActsHilogTest") { "src", "//test/xts/tools/hctest/include", "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits/", - "//kernel/liteos_a/include/config/base/core", ] deps = [ "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared" ] diff --git a/kernel_lite/process_posix/src/UidGidTest.cpp b/kernel_lite/process_posix/src/UidGidTest.cpp index cde44231371673ac2c52011b983bfc303b2a7f5b..00b916d165e620575bb268490c04d95099667d4d 100755 --- a/kernel_lite/process_posix/src/UidGidTest.cpp +++ b/kernel_lite/process_posix/src/UidGidTest.cpp @@ -640,11 +640,15 @@ HWTEST_F(UidGidTest, testGetgroups, Function | MediumTest | Level1) const int testSize = 10; gid_t gidList[testSize] = {0}; int n = getgroups(0, gidList); - ASSERT_EQ(n, 1); - ASSERT_EQ(gidList[0], 0); + ASSERT_EQ(n, 2); + int rt = getgroups(n, gidList); + ASSERT_EQ(gidList[0], SHELL_GID); + ASSERT_EQ(gidList[1], 0); + ASSERT_EQ(rt, n); n = getgroups(testSize, gidList); - ASSERT_EQ(n, 1); + ASSERT_EQ(n, 2); ASSERT_EQ(gidList[0], SHELL_GID); + ASSERT_EQ(gidList[1], 0); } /** @@ -705,12 +709,15 @@ HWTEST_F(UidGidTest, testSetgroups2, Function | MediumTest | Level1) gid_t gidListOut[4] = {0}; LOG("Init: make sure groups not changed by other test."); - int n = getgroups(1, gidListOut); - EXPECT_EQ(n, 1); + int n = getgroups(0, gidListOut); + EXPECT_EQ(n, 2); + int rt = getgroups(n, gidListOut); EXPECT_EQ(gidListOut[0], SHELL_GID); + EXPECT_EQ(gidListOut[1], 0); + EXPECT_EQ(rt, n); LOG("add 2 groups"); - int rt = setgroups(2, gidListIn); + rt = setgroups(2, gidListIn); EXPECT_EQ(rt, 0); n = getgroups(4, gidListOut); EXPECT_EQ(n, 3); @@ -721,8 +728,10 @@ HWTEST_F(UidGidTest, testSetgroups2, Function | MediumTest | Level1) LOG("clear groups"); rt = setgroups(0, NULL); EXPECT_EQ(rt, 0); - n = getgroups(2, gidListOut); + n = getgroups(0, gidListOut); EXPECT_EQ(n, 1); + rt = getgroups(n, gidListOut); + EXPECT_EQ(rt, n); EXPECT_EQ(gidListOut[0], SHELL_GID); } diff --git a/kernel_lite/process_posix/src/UidGidTest.h b/kernel_lite/process_posix/src/UidGidTest.h index fc3a1131322bc4814e583a39ee7dc4952f294c32..57f9d9a18e40d5ecd3f47fa944f89082594383ae 100755 --- a/kernel_lite/process_posix/src/UidGidTest.h +++ b/kernel_lite/process_posix/src/UidGidTest.h @@ -23,6 +23,9 @@ // max test number of uid/gid, not actual max number const int MAX_UGID = 100000; +static int groupNum = -1; +const int ARRAY_SIZE = 10; +static gid_t groupsArray[ARRAY_SIZE] = {0}; // Assert all uid == expectUid #define AssertAllUid(expectUid) do { \ @@ -54,14 +57,30 @@ public: return id; } protected: + static void SetUpTestCase() + { + for (int i = 0; i < ARRAY_SIZE; i++) { + groupsArray[i] = -1; + } + groupNum = getgroups(0, groupsArray); + EXPECT_NE(groupNum, -1); + int rt = getgroups(groupNum, groupsArray); + EXPECT_EQ(rt, groupNum); + } void TearDown() { LOG("TearDown: reset uid and gid"); + gid_t groupIds[groupNum]; + LOG("TearDown: reset uid and gid %d", sizeof(groupIds) / sizeof(gid_t)); + for (int i = 0; i < groupNum; i++) { + groupIds[i] = groupsArray[i]; + } setuid(SHELL_UID); setgid(SHELL_GID); AssertAllUid(SHELL_UID); AssertAllGid(SHELL_GID); - int rt = setgroups(0, NULL); + int rt = setgroups(groupNum, groupIds); + EXPECT_EQ(rt, 0); } }; diff --git a/security_lite/permission_posix/dac/src/ActsDacPreTest.cpp b/security_lite/permission_posix/dac/src/ActsDacPreTest.cpp index 5990c1df148a00067f1fae4f74f2175f425bd628..54b53e5053b56702497d3a121c802f0ded3f408e 100755 --- a/security_lite/permission_posix/dac/src/ActsDacPreTest.cpp +++ b/security_lite/permission_posix/dac/src/ActsDacPreTest.cpp @@ -29,8 +29,10 @@ using namespace testing::ext; static int TestSetUid() { // Test the 'setuid' interface - int ret; - uid_t ruid, euid, suid; + int ret = 0; + uid_t ruid = 0; + uid_t euid = 0; + uid_t suid = 0; // Step 1: Verify that UID is set to 0 ret = setuid(UID0); if (ret != 0) { @@ -85,8 +87,10 @@ static int TestSetUid() static int TestSetREUid() { // Test the 'setreuid' interface - int ret; - uid_t ruid, euid, suid; + int ret = 0; + uid_t ruid = 0; + uid_t euid = 0; + uid_t suid = 0; // Step 1: Verify that UID is set to 0 ret = setreuid(UID0, UID0); if (ret != 0) { @@ -141,8 +145,10 @@ static int TestSetREUid() static int TestSetRESUid() { // Test the 'setresuid' interface - int ret; - uid_t ruid, euid, suid; + int ret = 0; + uid_t ruid = 0; + uid_t euid = 0; + uid_t suid = 0; // Step 1: Verify that UID is set to 0 ret = setresuid(UID0, UID0, UID0); if (ret != 0) { @@ -197,8 +203,13 @@ static int TestSetRESUid() static int TestSetUidAbnormal() { // Enter the exception parameter when invoke the 'setuid','setreuid','setresuid' interface - int ret; - uid_t newruid, neweuid, newsuid, ruid, euid, suid; + int ret = 0; + uid_t newruid = 0; + uid_t neweuid = 0; + uid_t newsuid = 0; + uid_t ruid = 0; + uid_t euid = 0; + uid_t suid = 0; // Obtain the ruid, euid, suid of the current process getresuid(&ruid, &euid, &suid); // Step 1: Verify that UID is set to -100 with the 'setuid' interface @@ -243,8 +254,10 @@ static int TestSetUidAbnormal() static int TestSetGid() { // Test the 'setgid' interface - int ret; - gid_t rgid, egid, sgid; + int ret = 0; + gid_t rgid = 0; + gid_t egid = 0; + gid_t sgid = 0; // Step 1: Verify that GID is set to 0 ret = setgid(GID0); if (ret != 0) { @@ -299,8 +312,10 @@ static int TestSetGid() static int TestSetREGid() { // Test the 'setregid' interface - int ret; - gid_t rgid, egid, sgid; + int ret = 0; + gid_t rgid = 0; + gid_t egid = 0; + gid_t sgid = 0; // Step 1: Verify that GID is set to 0 ret = setregid(GID0, GID0); if (ret != 0) { @@ -355,8 +370,10 @@ static int TestSetREGid() static int TestSetRESGid() { // Test the 'setresgid' interface - int ret; - gid_t rgid, egid, sgid; + int ret = 0; + gid_t rgid = 0; + gid_t egid = 0; + gid_t sgid = 0; // Step 1: Verify that GID is set to 0 ret = setresgid(GID0, GID0, GID0); if (ret != 0) { @@ -411,8 +428,13 @@ static int TestSetRESGid() static int TestSetGidAbnormal() { // Enter the exception parameter when invoke the 'setgid','setregid','setresgid' interface - int ret; - gid_t newrgid, newegid, newsgid, rgid, egid, sgid; + int ret = 0; + gid_t newrgid = 0; + gid_t newegid = 0; + gid_t newsgid = 0; + gid_t rgid = 0; + gid_t egid = 0; + gid_t sgid = 0; // Obtain the rgid, egid, sgid of the current process getresgid(&rgid, &egid, &sgid); // Step 1: Verify that GID is set to -100 with the 'setgid' interface @@ -546,8 +568,13 @@ static int ChangeSensitiveInformation() */ HWTEST_F(DacTestSuite, DACTest0010, Function | MediumTest | Level1) { - int ret; - uid_t ruid, euid, suid, newruid, neweuid, newsuid; + int ret = 0; + uid_t ruid = 0; + uid_t euid = 0; + uid_t suid = 0; + uid_t newruid = 0; + uid_t neweuid = 0; + uid_t newsuid = 0; // Preset action: Obtain the ruid, euid, suid of the current process getresuid(&ruid, &euid, &suid); // Step 1: Test the 'setuid' interface @@ -578,8 +605,13 @@ HWTEST_F(DacTestSuite, DACTest0010, Function | MediumTest | Level1) */ HWTEST_F(DacTestSuite, DACTest0020, Function | MediumTest | Level1) { - int ret; - gid_t rgid, egid, sgid, newrgid, newegid, newsgid; + int ret = 0; + gid_t rgid = 0; + gid_t egid = 0; + gid_t sgid = 0; + gid_t newrgid = 0; + gid_t newegid = 0; + gid_t newsgid = 0; // Preset action: Obtain the rgid, egid, sgid of the current process getresgid(&rgid, &egid, &sgid); // Step 1: Test the 'setgid' interface @@ -613,7 +645,7 @@ HWTEST_F(DacTestSuite, DACTest0030, Function | MediumTest | Level1) int ret; gid_t grouplist[SIZE255]; // Preset action: Obtain the groups of the current process - int groupsize = getgroups(0, grouplist); + size_t groupsize = getgroups(0, grouplist); if (groupsize >= 0) { getgroups(groupsize, grouplist); } else { @@ -648,7 +680,7 @@ HWTEST_F(DacTestSuite, DACTest0040, Function | MediumTest | Level2) int ret; gid_t grouplist[SIZE255]; // Preset action: Obtain the groups of the current process - int groupsize = getgroups(0, grouplist); + size_t groupsize = getgroups(0, grouplist); if (groupsize >= 0) { getgroups(groupsize, grouplist); } else { @@ -683,7 +715,7 @@ HWTEST_F(DacTestSuite, DACTest0050, Function | MediumTest | Level3) int ret; gid_t grouplist[SIZE255]; // Preset action: Obtain the groups of the current process - int groupsize = getgroups(0, grouplist); + size_t groupsize = getgroups(0, grouplist); if (groupsize >= 0) { getgroups(groupsize, grouplist); } else { @@ -718,7 +750,7 @@ HWTEST_F(DacTestSuite, DACTest0060, Function | MediumTest | Level3) int ret; gid_t grouplist[SIZE255]; // Preset action: Obtain the groups of the current process - int groupsize = getgroups(0, grouplist); + size_t groupsize = getgroups(0, grouplist); if (groupsize >= 0) { getgroups(groupsize, grouplist); } else { @@ -818,8 +850,11 @@ HWTEST_F(DacTestSuite, DACTest0070, Security | MediumTest | Level2) HWTEST_F(DacTestSuite, DACTest0080, Function | MediumTest | Level2) { int ret; - uid_t ruid, euid, suid, newruid, neweuid, newsuid; - gid_t rgid, egid, sgid, newrgid, newegid, newsgid, grouplist[SIZE255]; + uid_t ruid = 0; uid_t euid = 0; uid_t suid = 0; + uid_t newruid = 0; uid_t neweuid = 0; uid_t newsuid = 0; + gid_t rgid = 0; gid_t egid = 0; gid_t sgid = 0; + gid_t newrgid = 0; gid_t newegid = 0; gid_t newsgid = 0; + gid_t grouplist[SIZE255]; // Preset action: Obtain the ruid, euid, suid of the current process getresuid(&ruid, &euid, &suid); // Preset action: Obtain the rgid, egid, sgid of the current process @@ -947,4 +982,4 @@ HWTEST_F(DacTestSuite, DACTest0130, Performance | MediumTest | Level2) SetUidGid(UID0, GID0); setgroups(0, nullptr); } -#endif \ No newline at end of file +#endif diff --git a/startup_lite/bootstrap_hal/src/samgr_api_test.h b/startup_lite/bootstrap_hal/src/samgr_api_test.h index aac0a83026eacd52c6c20403780ffab77c481a19..78abe285d3e5f3561ab254ad50dfc0cd4fc0e020 100644 --- a/startup_lite/bootstrap_hal/src/samgr_api_test.h +++ b/startup_lite/bootstrap_hal/src/samgr_api_test.h @@ -25,13 +25,13 @@ const int SAMGR_API_CALL_NUM = 0; enum TagSamgrApiGroup { CORE_INIT_E = 0, - SYS_SERVICE_INIT_E = 0, - SYS_FEATURE_INIT_E = 0, - APP_SERVICE_INIT_E = 0, - SYSEX_SERVICE_INIT_E = 0, - APP_FEATURE_INIT_E = 0, - SYSEX_FEATURE_INIT = 0, - SYS_RUN_E = 0, + SYS_SERVICE_INIT_E, + SYS_FEATURE_INIT_E, + APP_SERVICE_INIT_E, + SYSEX_SERVICE_INIT_E, + APP_FEATURE_INIT_E, + SYSEX_FEATURE_INIT, + SYS_RUN_E, }; enum TagSamgrApiPri { diff --git a/startup_lite/bootstrap_posix/BUILD.gn b/startup_lite/bootstrap_posix/BUILD.gn index da9897cf74c2538152a8241f12c0700c782b555c..fcb1073738c51fbdbb7f4e3cbf0a9c0cb4c5614d 100755 --- a/startup_lite/bootstrap_posix/BUILD.gn +++ b/startup_lite/bootstrap_posix/BUILD.gn @@ -23,7 +23,6 @@ hcpptest_suite("ActsBootstrapTest") { include_dirs = [ "src", "//utils/native/native_lite/include", - "//kernel/liteos_a/kernel/common", "//third_party/bounds_checking_function/include/", "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", ]