• 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 #include <vector>
18 
19 #include "disallowed_telephony_call_plugin.h"
20 #include "edm_ipc_interface_code.h"
21 #include "utils.h"
22 #include "parameters.h"
23 
24 using namespace testing::ext;
25 using namespace testing;
26 
27 namespace OHOS {
28 namespace EDM {
29 namespace TEST {
30 const std::string PARAM_DISALLOWED_TELEPHONY_CALL = "persist.edm.telephony_call_disable";
31 
32 class DisallowedTelephonyCallPluginTest
33     : public testing::TestWithParam<std::pair<std::shared_ptr<IPlugin>, EdmInterfaceCode>> {
34 protected:
35     static void SetUpTestSuite(void);
36 
37     static void TearDownTestSuite(void);
38 };
39 
SetUpTestSuite(void)40 void DisallowedTelephonyCallPluginTest::SetUpTestSuite(void)
41 {
42     Utils::SetEdmInitialEnv();
43 }
44 
TearDownTestSuite(void)45 void DisallowedTelephonyCallPluginTest::TearDownTestSuite(void)
46 {
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 INSTANTIATE_TEST_SUITE_P(TestOnSetPolicy, DisallowedTelephonyCallPluginTest,
53     testing::ValuesIn(std::vector<std::pair<std::shared_ptr<IPlugin>, EdmInterfaceCode>>({
54         {DisallowedTelephonyCallPlugin::GetPlugin(), EdmInterfaceCode::DISALLOWED_TELEPHONY_CALL},
55     })));
56 
57 /**
58  * @tc.name: TestOnSetPolicy
59  * @tc.desc: Test DisallowedTelephonyCallPluginTest::OnSetPolicy function.
60  * @tc.type: FUNC
61  */
62 HWTEST_P(DisallowedTelephonyCallPluginTest, TestOnSetPolicy, TestSize.Level1)
63 {
64     auto param = GetParam();
65     bool currentval = system::GetBoolParameter(PARAM_DISALLOWED_TELEPHONY_CALL, false);
66     std::string setData = currentval? "true" : "false";
67     std::string afterData = currentval? "false" : "true";
68     MessageParcel data;
69     MessageParcel reply;
70     data.WriteBool(!currentval);
71     std::shared_ptr<IPlugin> plugin = param.first;
72     HandlePolicyData handlePolicyData{"false", "", false};
73     if (currentval) {
74         handlePolicyData.policyData = "true";
75     }
76     std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, param.second);
77     ErrCode ret = plugin->OnHandlePolicy(funcCode, data, reply, handlePolicyData, DEFAULT_USER_ID);
78     ASSERT_TRUE(ret == ERR_OK);
79     ASSERT_TRUE(handlePolicyData.policyData == afterData);
80     ASSERT_TRUE(handlePolicyData.isChanged);
81     system::SetParameter(PARAM_DISALLOWED_TELEPHONY_CALL, setData);
82 }
83 } // namespace TEST
84 } // namespace EDM
85 } // namespace OHOS
86