1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "dlp_parcel_test.h"
16 #include <string>
17 #include "dlp_permission_log.h"
18
19 namespace OHOS {
20 namespace Security {
21 namespace DlpPermission {
22 using namespace testing::ext;
23 using namespace OHOS;
24 using namespace OHOS::Security::DlpPermission;
25
26 namespace {
27 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
28 LOG_CORE, SECURITY_DOMAIN_DLP_PERMISSION, "DlpParcelTest"};
29 }
30
SetUpTestCase()31 void DlpParcelTest::SetUpTestCase() {}
32
TearDownTestCase()33 void DlpParcelTest::TearDownTestCase() {}
34
SetUp()35 void DlpParcelTest::SetUp() {}
36
TearDown()37 void DlpParcelTest::TearDown() {}
38
39 /**
40 * @tc.name: DlpParcelTest001
41 * @tc.desc: AuthUserInfoParcel test
42 * @tc.type: FUNC
43 * @tc.require:
44 */
45 HWTEST_F(DlpParcelTest, AuthUserInfoParcel001, TestSize.Level1)
46 {
47 DLP_LOG_INFO(LABEL, "AuthUserInfoParcel001");
48 AuthUserInfoParcel info;
49 info.authUserInfo_.authAccount = "abc";
50 Parcel out;
51
52 EXPECT_EQ(true, info.Marshalling(out));
53 auto result = AuthUserInfoParcel::Unmarshalling(out);
54 ASSERT_NE(result, nullptr);
55 EXPECT_EQ(0, result->authUserInfo_.authAccount.compare("abc"));
56 delete result;
57 result = nullptr;
58 }
59
60 /**
61 * @tc.name: DlpParcelTest002
62 * @tc.desc: DlpPolicyParcel test
63 * @tc.type: FUNC
64 * @tc.require:
65 */
66 HWTEST_F(DlpParcelTest, DlpParcelTest002, TestSize.Level1)
67 {
68 DlpPolicyParcel info;
69 info.policyParams_.ownerAccount_ = "abc";
70 info.policyParams_.ownerAccountId_ = "abc";
71 Parcel out;
72
73 EXPECT_EQ(false, info.Marshalling(out));
74 auto result = DlpPolicyParcel::Unmarshalling(out);
75 EXPECT_EQ(result, nullptr);
76 }
77
78 /**
79 * @tc.name: DlpParcelTest003
80 * @tc.desc: DlpSandboxCallbackInfoParcel test
81 * @tc.type: FUNC
82 * @tc.require:
83 */
84 HWTEST_F(DlpParcelTest, DlpParcelTest003, TestSize.Level1)
85 {
86 DlpSandboxCallbackInfoParcel info;
87 info.changeInfo.appIndex = 0;
88 Parcel out;
89
90 EXPECT_EQ(true, info.Marshalling(out));
91 auto result = DlpSandboxCallbackInfoParcel::Unmarshalling(out);
92 ASSERT_NE(result, nullptr);
93 EXPECT_EQ(0, result->changeInfo.appIndex);
94 delete result;
95 result = nullptr;
96 }
97
98 /**
99 * @tc.name: DlpParcelTest004
100 * @tc.desc: OpenDlpFileCallbackInfoParcel test
101 * @tc.type: FUNC
102 * @tc.require:
103 */
104 HWTEST_F(DlpParcelTest, DlpParcelTest004, TestSize.Level1)
105 {
106 OpenDlpFileCallbackInfoParcel info;
107 info.fileInfo.uri = "test";
108 info.fileInfo.timeStamp = 1;
109 Parcel out;
110
111 EXPECT_EQ(true, info.Marshalling(out));
112 auto result = OpenDlpFileCallbackInfoParcel::Unmarshalling(out);
113 ASSERT_NE(result, nullptr);
114 EXPECT_EQ("test", result->fileInfo.uri);
115 EXPECT_EQ(1, result->fileInfo.timeStamp);
116 delete result;
117 result = nullptr;
118 }
119
120 /**
121 * @tc.name: RetentionSandBoxInfo001
122 * @tc.desc: RetentionSandBoxInfo test
123 * @tc.type: FUNC
124 * @tc.require:
125 */
126 HWTEST_F(DlpParcelTest, RetentionSandBoxInfo001, TestSize.Level1)
127 {
128 DLP_LOG_INFO(LABEL, "RetentionSandBoxInfo001");
129 RetentionSandBoxInfo info;
130 info.bundleName_ = "abc";
131 info.appIndex_ = 1;
132 Parcel out;
133
134 EXPECT_EQ(true, info.Marshalling(out));
135 auto result = RetentionSandBoxInfo::Unmarshalling(out);
136 ASSERT_NE(result, nullptr);
137 EXPECT_EQ(0, result->bundleName_.compare("abc"));
138 delete result;
139 result = nullptr;
140 }
141
142 /**
143 * @tc.name: VisitedDLPFileInfo001
144 * @tc.desc: VisitedDLPFileInfo test
145 * @tc.type: FUNC
146 * @tc.require:
147 */
148 HWTEST_F(DlpParcelTest, VisitedDLPFileInfo001, TestSize.Level1)
149 {
150 DLP_LOG_INFO(LABEL, "VisitedDLPFileInfo001");
151 VisitedDLPFileInfo info;
152 info.docUri = "abc";
153 Parcel out;
154
155 EXPECT_EQ(true, info.Marshalling(out));
156 auto result = VisitedDLPFileInfo::Unmarshalling(out);
157 ASSERT_NE(result, nullptr);
158 EXPECT_EQ(0, result->docUri.compare("abc"));
159 delete result;
160 result = nullptr;
161 }
162 } // namespace DlpPermission
163 } // namespace Security
164 } // namespace OHOS