diff --git a/bundle.json b/bundle.json index a432477445746ee4fe9fff8515c4f2197925dcb4..888e34ef7bf8f28bfefc31737dd1fbdbdc5a0b6e 100755 --- a/bundle.json +++ b/bundle.json @@ -27,7 +27,7 @@ "//developtools/syscap_codec:syscap_codec" ], "inner_kits": [], - "test": [] + "test": [ "//developtools/syscap_codec/test/unittest/common:unittest" ] } } } \ No newline at end of file diff --git a/test/unittest/common/BUILD.gn b/test/unittest/common/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..db64b61c9f2f434589d78781f2d5d6e384a82b58 --- /dev/null +++ b/test/unittest/common/BUILD.gn @@ -0,0 +1,90 @@ +# Copyright (c) 2022 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. + +if (defined(ohos_lite)) { + import("//build/lite/config/component/lite_component.gni") + import("//build/lite/config/test.gni") + test_output_root = "$root_out_dir/test/unittest/syscap_codec" + + executable("test_syscap_napi_unittest") { + output_extension = "bin" + output_dir = test_output_root + + include_dirs = [ + "//utils/native/base/include", + "//third_party/node/src", + "//third_party/googletest/include", + "//developtools/syscap_codec/src/", + "//developtools/syscap_codec/include/", + "//developtools/syscap_codec/interfaces/inner_api/", + "//developtools/syscap_codec/test/unittest/common/include/", + ] + + cflags = [ "-g3" ] + + sources = [ + "//developtools/syscap_codec/interfaces/inner_api/syscap_interface.c", + "//developtools/syscap_codec/src/create_pcid.c", + "syscap_codec_test.cpp", + ] + + defines = [ "NAPI_TEST" ] + + deps = [ + "//base//hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", + "//test/developertest/third_party/lib/cpp:gtest_main", + "//third_party/bounds_checking_function:libsec_static", + ] + + deps += [ "//build/lite/config/component/cJSON:cjson_static" ] + } + + group("unittest") { + deps = [ ":test_syscap_napi_unittest" ] + } +} else { + import("//build/lite/config/component/lite_component.gni") + import("//build/ohos.gni") + import("//build/test.gni") + + module_output_path = "developtools/syscap_codec" + + ohos_unittest("syscap_codec_test") { + module_out_path = module_output_path + + include_dirs = [ + "//developtools/syscap_codec/src/", + "//developtools/syscap_codec/include/", + "//developtools/syscap_codec/interfaces/inner_api/", + "//developtools/syscap_codec/test/unittest/common/include/", + ] + + sources = [ + "//developtools/syscap_codec/interfaces/inner_api/syscap_interface.c", + "//developtools/syscap_codec/src/create_pcid.c", + "syscap_codec_test.cpp", + ] + + deps = [ + "//third_party/bounds_checking_function:libsec_static", + "//third_party/googletest:gtest_main", + ] + + deps += [ "//third_party/cJSON:cjson_static" ] + } + + group("unittest") { + testonly = true + deps = [ ":syscap_codec_test" ] + } +} diff --git a/test/unittest/common/include/syscap_codec_test.h b/test/unittest/common/include/syscap_codec_test.h new file mode 100644 index 0000000000000000000000000000000000000000..61934ba8bff6259e0a814134dc74dd458df5c3aa --- /dev/null +++ b/test/unittest/common/include/syscap_codec_test.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2022 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 _SYSCAP_CODEC_TEST_H +#define _SYSCAP_CODEC_TEST_H + +#include +#include "syscap_interface.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +namespace Syscap { +int osSyscap[32] = {1, 3, 3}; +char priSyscap[] = "Device.syscap1GEDR,Device.syscap2WREGW,Vendor.syscap3RGD,Vendor.syscap4RWEG,Vendor.syscap5REWGWE,"; + +class SyscapCodecTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; +} // namespace Syscap + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _SYSCAP_CODEC_TEST_H */ \ No newline at end of file diff --git a/test/unittest/common/syscap_codec_test.cpp b/test/unittest/common/syscap_codec_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f761abbf96cbebf23d8bd13bd3a13b682e305972 --- /dev/null +++ b/test/unittest/common/syscap_codec_test.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2022 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"syscap_codec_test.h" + +using namespace testing::ext; +using namespace std; + +namespace Syscap { +void SyscapCodecTest::SetUpTestCase() {} + +void SyscapCodecTest::TearDownTestCase() {} + +void SyscapCodecTest::SetUp() {} + +void SyscapCodecTest::TearDown() {} + +/* + * @tc.name: EncodeOsSyscap + * @tc.desc: Check the OsSyscap Coding. + * @tc.type: FUNC + */ +HWTEST_F(SyscapCodecTest, EncodeOsSyscap, TestSize.Level1) +{ + int *intOsInput = NULL; + EXPECT_TRUE(EncodeOsSyscap(&intOsInput)); + free(intOsInput); +} + +/* + * @tc.name: EncodePrivateSyscap + * @tc.desc: Check the PrivateSyscap Coding. + * @tc.type: FUNC + */ +HWTEST_F(SyscapCodecTest, EncodePrivateSyscap, TestSize.Level1) +{ + char *charPriInput = NULL; + int priOutLen; + EXPECT_TRUE(EncodePrivateSyscap(&charPriInput, &priOutLen)); + free(charPriInput); +} + +/* + * @tc.name: DecodeOsSyscap + * @tc.desc: Check the OsSyscap Decoding. + * @tc.type: FUNC + */ +HWTEST_F(SyscapCodecTest, DecodeOsSyscap, TestSize.Level1) +{ + char (*osOutput)[128] = NULL; + int decodeOsCnt; + char expectOsOutput001[] = "SystemCapability.Account.AppAccount"; + char expectOsOutput002[] = "SystemCapability.Account.OsAccount"; + EXPECT_TRUE(DecodeOsSyscap(osSyscap, &osOutput, &decodeOsCnt)); + char (*tmpOsOutput)[128] = osOutput; + EXPECT_STREQ(*tmpOsOutput, expectOsOutput001); + EXPECT_STREQ(*(tmpOsOutput + 1), expectOsOutput002); + EXPECT_EQ(decodeOsCnt, 2); + free(osOutput); +} + +/* + * @tc.name: DecodePrivateSyscap + * @tc.desc: Check the PrivateSyscap Decoding. + * @tc.type: FUNC + */ +HWTEST_F(SyscapCodecTest, DecodePrivateSyscap, TestSize.Level1) +{ + char (*priOutput)[128] = NULL; + int decodePriCnt; + char expectPriOutput001[] = "SystemCapability.Device.syscap1GEDR"; + char expectPriOutput002[] = "SystemCapability.Device.syscap2WREGW"; + char expectPriOutput003[] = "SystemCapability.Vendor.syscap3RGD"; + char expectPriOutput004[] = "SystemCapability.Vendor.syscap4RWEG"; + char expectPriOutput005[] = "SystemCapability.Vendor.syscap5REWGWE"; + EXPECT_TRUE(DecodePrivateSyscap(priSyscap, &priOutput, &decodePriCnt)); + char (*tmpPtiOutput)[128] = priOutput; + EXPECT_STREQ(*tmpPtiOutput++, expectPriOutput001); + EXPECT_STREQ(*tmpPtiOutput++, expectPriOutput002); + EXPECT_STREQ(*tmpPtiOutput++, expectPriOutput003); + EXPECT_STREQ(*tmpPtiOutput++, expectPriOutput004); + EXPECT_STREQ(*tmpPtiOutput, expectPriOutput005); + EXPECT_EQ(decodePriCnt, 5); + free(priOutput); +} +} // namespace Syscap