• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 
16 #include <gtest/gtest.h>
17 
18 #include "disallowed_nearlink_protocols_plugin.h"
19 
20 #include "edm_constants.h"
21 #include "edm_data_ability_utils_mock.h"
22 #include "edm_ipc_interface_code.h"
23 #include "iplugin_manager.h"
24 #include "utils.h"
25 
26 using namespace testing::ext;
27 using namespace testing;
28 
29 namespace OHOS {
30 namespace EDM {
31 namespace TEST {
32 class DisallowedNearlinkProtocolsPluginTest : public testing::Test {
33 protected:
34     static void SetUpTestSuite(void);
35 
36     static void TearDownTestSuite(void);
37 };
38 
SetUpTestSuite(void)39 void DisallowedNearlinkProtocolsPluginTest::SetUpTestSuite(void)
40 {
41     Utils::SetEdmServiceEnable();
42     Utils::SetEdmInitialEnv();
43 }
TearDownTestSuite(void)44 void DisallowedNearlinkProtocolsPluginTest::TearDownTestSuite(void)
45 {
46     Utils::SetEdmServiceDisable();
47     Utils::ResetTokenTypeAndUid();
48     ASSERT_TRUE(Utils::IsOriginalUTEnv());
49     std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
50 }
51 
52 /**
53  * @tc.name: TestSetDisallowedNearlinkProtocolsEmpty
54  * @tc.desc: Test set disallowed nearlink protocols function.
55  * @tc.type: FUNC
56  */
57 HWTEST_F(DisallowedNearlinkProtocolsPluginTest, TestSetDisallowedNearlinkProtocolsEmpty, TestSize.Level1)
58 {
59     Utils::SetBluetoothEnable();
60     DisallowedNearlinkProtocolsPlugin plugin;
61     std::vector<std::int32_t> policyData;
62     std::vector<std::int32_t> currentData;
63     std::vector<std::int32_t> mergeData;
64     ErrCode ret = plugin.OnSetPolicy(policyData, currentData, mergeData, DEFAULT_USER_ID);
65     ASSERT_TRUE(ret == EdmReturnErrCode::PARAMETER_VERIFICATION_FAILED);
66 }
67 
68 /**
69  * @tc.name: TestSetDisallowedNearlinkProtocolsParameterIsTooLong
70  * @tc.desc: Test DisallowedNearlinkProtocolsPluginTest::OnSetPolicy function.
71  * @tc.type: FUNC
72  */
73 HWTEST_F(DisallowedNearlinkProtocolsPluginTest, TestSetDisallowedNearlinkProtocolsParameterIsTooLong, TestSize.Level1)
74 {
75     DisallowedNearlinkProtocolsPlugin plugin;
76     std::vector<std::int32_t> policyData = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
77     std::vector<std::int32_t> currentData;
78     std::vector<std::int32_t> mergeData;
79     ErrCode ret = plugin.OnSetPolicy(policyData, currentData, mergeData, DEFAULT_USER_ID);
80     ASSERT_TRUE(ret == EdmReturnErrCode::PARAMETER_VERIFICATION_FAILED);
81 }
82 
83 /**
84  * @tc.name: TestSetDisallowedNearlinkProtocolsWithDataAndCurrentData
85  * @tc.desc: Test DisallowedNearlinkProtocolsPluginTest::OnSetPolicy function.
86  * @tc.type: FUNC
87  */
88 HWTEST_F(DisallowedNearlinkProtocolsPluginTest, TestSetDisallowedNearlinkProtocolsWithDataAndCurrentData,
89 TestSize.Level1)
90 {
91     Utils::SetBluetoothEnable();
92     DisallowedNearlinkProtocolsPlugin plugin;
93     std::vector<std::int32_t> policyData = { 0, 1};
94     std::vector<std::int32_t> currentData;
95     std::vector<std::int32_t> mergeData;
96     ErrCode ret = plugin.OnSetPolicy(policyData, currentData, mergeData, DEFAULT_USER_ID);
97     plugin.OnChangedPolicyDone(true);
98     ASSERT_TRUE(ret == ERR_OK);
99 }
100 
101 /**
102  * @tc.name: TestRemoveDisallowedNearlinkProtocolsEmpty
103  * @tc.desc: Test DisallowedNearlinkProtocolsPluginTest::OnRemovePolicy function.
104  * @tc.type: FUNC
105  */
106 HWTEST_F(DisallowedNearlinkProtocolsPluginTest, TestRemoveDisallowedNearlinkProtocolsEmpty, TestSize.Level1)
107 {
108     DisallowedNearlinkProtocolsPlugin plugin;
109     std::vector<std::int32_t> policyData;
110     std::vector<std::int32_t> currentData;
111     std::vector<std::int32_t> mergeData;
112     ErrCode ret = plugin.OnRemovePolicy(policyData, currentData, mergeData, DEFAULT_USER_ID);
113     ASSERT_TRUE(ret == EdmReturnErrCode::PARAMETER_VERIFICATION_FAILED);
114 }
115 
116 /**
117  * @tc.name: TestRemoveDisallowedNearlinkProtocolsParameterIsTooLong
118  * @tc.desc: Test DisallowedNearlinkProtocolsPluginTest::OnRemovePolicy function.
119  * @tc.type: FUNC
120  */
121 HWTEST_F(DisallowedNearlinkProtocolsPluginTest, TestRemoveDisallowedNearlinkProtocolsParameterIsTooLong,
122     TestSize.Level1)
123 {
124     DisallowedNearlinkProtocolsPlugin plugin;
125     std::vector<std::int32_t> policyData = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
126     std::vector<std::int32_t> currentData;
127     std::vector<std::int32_t> mergeData;
128     ErrCode ret = plugin.OnRemovePolicy(policyData, currentData, mergeData, DEFAULT_USER_ID);
129     ASSERT_TRUE(ret == EdmReturnErrCode::PARAMETER_VERIFICATION_FAILED);
130 }
131 
132 /**
133  * @tc.name: TestRemoveDisallowedNearlinkProtocolsWithDataAndCurrentData
134  * @tc.desc: Test DisallowedNearlinkProtocolsPluginTest::OnRemovePolicy function.
135  * @tc.type: FUNC
136  */
137 HWTEST_F(DisallowedNearlinkProtocolsPluginTest, TestRemoveDisallowedNearlinkProtocolsWithDataAndCurrentData,
138     TestSize.Level1)
139 {
140     DisallowedNearlinkProtocolsPlugin plugin;
141     std::vector<std::int32_t> policyData = { 0, 1 };
142     std::vector<std::int32_t> currentData;
143     std::vector<std::int32_t> mergeData;
144     ErrCode ret = plugin.OnRemovePolicy(policyData, currentData, mergeData, DEFAULT_USER_ID);
145     plugin.OnChangedPolicyDone(false);
146     ASSERT_TRUE(ret == ERR_OK);
147 }
148 
149 /**
150  * @tc.name: TestAdminRemoveDisallowedNearlinkProtocolsEmpty
151  * @tc.desc: Test DisallowedNearlinkProtocolsPluginTest::OnAdminRemovePolicy function.
152  * @tc.type: FUNC
153  */
154 HWTEST_F(DisallowedNearlinkProtocolsPluginTest, TestAdminRemoveDisallowedNearlinkProtocolsEmpty, TestSize.Level1)
155 {
156     DisallowedNearlinkProtocolsPlugin plugin;
157     std::string adminName{"testAdminName"};
158     std::vector<std::int32_t> policyData;
159     std::vector<std::int32_t> mergeData;
160     ErrCode ret = plugin.OnAdminRemove(adminName, policyData, mergeData, DEFAULT_USER_ID);
161     ASSERT_TRUE(ret == ERR_OK);
162 }
163 
164 /**
165  * @tc.name: TestGetPolicyDisallowedNearlinkProtocolsEmpty
166  * @tc.desc: Test DisallowedNearlinkProtocolsPluginTest::OnGetPolicy function.
167  * @tc.type: FUNC
168  */
169 HWTEST_F(DisallowedNearlinkProtocolsPluginTest, TestGetPolicyDisallowedNearlinkProtocolsEmpty, TestSize.Level1)
170 {
171     DisallowedNearlinkProtocolsPlugin plugin;
172     std::string policyData;
173     MessageParcel data;
174     MessageParcel reply;
175     ErrCode ret = plugin.OnGetPolicy(policyData, data, reply, DEFAULT_USER_ID);
176     ASSERT_TRUE(ret == ERR_OK);
177 }
178 }
179 }
180 }