From 3c454b560889b8a7c26e67404a416cd443a3011c Mon Sep 17 00:00:00 2001 From: zhouyan Date: Mon, 19 Sep 2022 12:01:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0libperm=5Factive=5Fresponse?= =?UTF-8?q?=5Fparcel=5Ftest=E6=B5=8B=E8=AF=95=E5=A5=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhouyan Change-Id: I1407df636ec33656cf55212ebb07df52bf3ecdbd --- BUILD.gn | 1 + frameworks/privacy/test/BUILD.gn | 49 +++++++++++++ .../src/perm_active_response_parcel_test.cpp | 73 +++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 frameworks/privacy/test/BUILD.gn create mode 100644 frameworks/privacy/test/unittest/src/perm_active_response_parcel_test.cpp diff --git a/BUILD.gn b/BUILD.gn index 9bb4e5844..9e318da81 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -20,6 +20,7 @@ group("accesstoken_build_module_test") { if (is_standard_system) { deps += [ "//base/security/access_token/frameworks/accesstoken/test:unittest", + "//base/security/access_token/frameworks/privacy/test:unittest", "//base/security/access_token/interfaces/innerkits/accesstoken/test:unittest", "//base/security/access_token/interfaces/innerkits/nativetoken/test:unittest", "//base/security/access_token/interfaces/innerkits/privacy/test:unittest", diff --git a/frameworks/privacy/test/BUILD.gn b/frameworks/privacy/test/BUILD.gn new file mode 100644 index 000000000..ad953fe35 --- /dev/null +++ b/frameworks/privacy/test/BUILD.gn @@ -0,0 +1,49 @@ +# 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. + +import("//base/security/access_token/access_token.gni") +import("//build/test.gni") + +config("accesstoken_test_config") { + include_dirs = [ + "//third_party/googletest/include", + "//base/security/access_token/frameworks/privacy/include", + "//base/security/access_token/interfaces/innerkits/accesstoken/include", + "//base/security/access_token/interfaces/innerkits/privacy/include", + ] +} + +ohos_unittest("libperm_active_response_parcel_test") { + subsystem_name = "security" + part_name = "access_token" + module_out_path = part_name + "/" + part_name + + sources = [ "unittest/src/perm_active_response_parcel_test.cpp" ] + + configs = [ + ":accesstoken_test_config", + "//base/security/access_token/config:coverage_flags", + ] + + deps = [ "//base/security/access_token/frameworks/privacy:privacy_communication_adapter_cxx" ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_single", + ] +} + +group("unittest") { + testonly = true + deps = [ ":libperm_active_response_parcel_test" ] +} diff --git a/frameworks/privacy/test/unittest/src/perm_active_response_parcel_test.cpp b/frameworks/privacy/test/unittest/src/perm_active_response_parcel_test.cpp new file mode 100644 index 000000000..5638e8c37 --- /dev/null +++ b/frameworks/privacy/test/unittest/src/perm_active_response_parcel_test.cpp @@ -0,0 +1,73 @@ +/* + * 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 +#include +#include +#include "perm_active_response_parcel.h" +#include "parcel.h" + +using namespace testing::ext; + +namespace OHOS { +namespace Security { +namespace AccessToken { +namespace { + +} +class ActiveChangeResponseParcelTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void ActiveChangeResponseParcelTest::SetUpTestCase(void) {} +void ActiveChangeResponseParcelTest::TearDownTestCase(void) {} +void ActiveChangeResponseParcelTest::SetUp(void) {} +void ActiveChangeResponseParcelTest::TearDown(void) {} + +/** + * @tc.name: ActiveChangeResponseParcel001 + * @tc.desc: Verify ActiveChangeResponseParcel Marshalling and Unmarshalling function. + * @tc.type: FUNC + * @tc.require: issueI5RRLJ + */ +HWTEST_F(ActiveChangeResponseParcelTest, ActiveChangeResponseParcel001, TestSize.Level1) +{ + ActiveChangeResponseParcel activeChangeResponseParcel; + + activeChangeResponseParcel.changeResponse = { + .tokenID = 100, + .permissionName = "ohos.permission.CAMERA", + .deviceId = "you guess", + .type = PERM_INACTIVE, + }; + + Parcel parcel; + EXPECT_EQ(true, activeChangeResponseParcel.Marshalling(parcel)); + + std::shared_ptr readedData(ActiveChangeResponseParcel::Unmarshalling(parcel)); + EXPECT_EQ(true, readedData != nullptr); + + EXPECT_EQ(activeChangeResponseParcel.changeResponse.tokenID, readedData->changeResponse.tokenID); + EXPECT_EQ(activeChangeResponseParcel.changeResponse.permissionName, readedData->changeResponse.permissionName); + EXPECT_EQ(activeChangeResponseParcel.changeResponse.deviceId, readedData->changeResponse.deviceId); + EXPECT_EQ(activeChangeResponseParcel.changeResponse.type, readedData->changeResponse.type); +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS -- Gitee