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 }
57 
58 /**
59  * @tc.name: DlpParcelTest002
60  * @tc.desc: DlpPolicyParcel test
61  * @tc.type: FUNC
62  * @tc.require:
63  */
64 HWTEST_F(DlpParcelTest, DlpParcelTest002, TestSize.Level1)
65 {
66     DlpPolicyParcel info;
67     info.policyParams_.ownerAccount_ = "abc";
68     info.policyParams_.ownerAccountId_ = "abc";
69     Parcel out;
70 
71     EXPECT_EQ(true, info.Marshalling(out));
72     auto result = DlpPolicyParcel::Unmarshalling(out);
73     EXPECT_EQ(result, nullptr);
74 }
75 
76 /**
77  * @tc.name: DlpParcelTest003
78  * @tc.desc: DlpSandboxCallbackInfoParcel test
79  * @tc.type: FUNC
80  * @tc.require:
81  */
82 HWTEST_F(DlpParcelTest, DlpParcelTest003, TestSize.Level1)
83 {
84     DlpSandboxCallbackInfoParcel info;
85     info.changeInfo.appIndex = 0;
86     Parcel out;
87 
88     EXPECT_EQ(true, info.Marshalling(out));
89     auto result = DlpSandboxCallbackInfoParcel::Unmarshalling(out);
90     ASSERT_NE(result, nullptr);
91     EXPECT_EQ(0, result->changeInfo.appIndex);
92 }
93 
94 /**
95  * @tc.name: DlpParcelTest004
96  * @tc.desc: OpenDlpFileCallbackInfoParcel test
97  * @tc.type: FUNC
98  * @tc.require:
99  */
100 HWTEST_F(DlpParcelTest, DlpParcelTest004, TestSize.Level1)
101 {
102     OpenDlpFileCallbackInfoParcel info;
103     info.fileInfo.uri = "test";
104     info.fileInfo.timeStamp = 1;
105     Parcel out;
106 
107     EXPECT_EQ(true, info.Marshalling(out));
108     auto result = OpenDlpFileCallbackInfoParcel::Unmarshalling(out);
109     ASSERT_NE(result, nullptr);
110     EXPECT_EQ("test", result->fileInfo.uri);
111     EXPECT_EQ(1, result->fileInfo.timeStamp);
112 }
113 
114 /**
115  * @tc.name: RetentionSandBoxInfo001
116  * @tc.desc: RetentionSandBoxInfo test
117  * @tc.type: FUNC
118  * @tc.require:
119  */
120 HWTEST_F(DlpParcelTest, RetentionSandBoxInfo001, TestSize.Level1)
121 {
122     DLP_LOG_INFO(LABEL, "RetentionSandBoxInfo001");
123     RetentionSandBoxInfo info;
124     info.bundleName_ = "abc";
125     info.appIndex_ = 1;
126     Parcel out;
127 
128     EXPECT_EQ(true, info.Marshalling(out));
129     auto result = RetentionSandBoxInfo::Unmarshalling(out);
130     ASSERT_NE(result, nullptr);
131     EXPECT_EQ(0, result->bundleName_.compare("abc"));
132 }
133 
134 /**
135  * @tc.name: VisitedDLPFileInfo001
136  * @tc.desc: VisitedDLPFileInfo test
137  * @tc.type: FUNC
138  * @tc.require:
139  */
140 HWTEST_F(DlpParcelTest, VisitedDLPFileInfo001, TestSize.Level1)
141 {
142     DLP_LOG_INFO(LABEL, "VisitedDLPFileInfo001");
143     VisitedDLPFileInfo info;
144     info.docUri = "abc";
145     Parcel out;
146 
147     EXPECT_EQ(true, info.Marshalling(out));
148     auto result = VisitedDLPFileInfo::Unmarshalling(out);
149     ASSERT_NE(result, nullptr);
150     EXPECT_EQ(0, result->docUri.compare("abc"));
151 }
152 }  // namespace DlpPermission
153 }  // namespace Security
154 }  // namespace OHOS