• 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 "disallowed_airplane_mode_plugin_test.h"
17 
18 #include "disallowed_airplane_mode_plugin.h"
19 #include "edm_constants.h"
20 #include "edm_ipc_interface_code.h"
21 #include "iplugin_manager.h"
22 #include "parameters.h"
23 #include "plugin_singleton.h"
24 #include "utils.h"
25 
26 using namespace testing::ext;
27 
28 namespace OHOS {
29 namespace EDM {
30 namespace TEST {
SetUpTestSuite(void)31 void DisallowedAirplaneModeTest::SetUpTestSuite(void)
32 {
33     Utils::SetEdmInitialEnv();
34 }
35 
TearDownTestSuite(void)36 void DisallowedAirplaneModeTest::TearDownTestSuite(void)
37 {
38     Utils::ResetTokenTypeAndUid();
39     ASSERT_TRUE(Utils::IsOriginalUTEnv());
40     std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
41 }
42 
43 /**
44  * @tc.name: TestDisallowedAirplaneModeSuccess_001
45  * @tc.desc: Test DisallowedAirplaneModePlugin::OnSetPolicy function sucess.
46  * @tc.type: FUNC
47  */
48 HWTEST_F(DisallowedAirplaneModeTest, TestDisallowedAirplaneModeSuccess_001, TestSize.Level1)
49 {
50     MessageParcel data;
51     MessageParcel reply;
52     data.WriteBool(false);
53     std::shared_ptr<IPlugin> plugin = DisallowedAirplaneModePlugin::GetPlugin();
54     HandlePolicyData handlePolicyData{"false", "", false};
55     std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET,
56         EdmInterfaceCode::DISALLOWED_AIRPLANE_MODE);
57     ErrCode ret = plugin->OnHandlePolicy(funcCode, data, reply, handlePolicyData, DEFAULT_USER_ID);
58     ASSERT_TRUE(ret == ERR_OK);
59 }
60 
61 /**
62  * @tc.name: TestDisallowedAirplaneModeSuccess_002
63  * @tc.desc: Test DisallowedAirplaneModePlugin::OnSetPolicy function sucess.
64  * @tc.type: FUNC
65  */
66 HWTEST_F(DisallowedAirplaneModeTest, TestDisallowedAirplaneModeSuccess_002, TestSize.Level1)
67 {
68     MessageParcel data;
69     MessageParcel reply;
70     data.WriteBool(true);
71     std::shared_ptr<IPlugin> plugin = DisallowedAirplaneModePlugin::GetPlugin();
72     HandlePolicyData handlePolicyData{"true", "", false};
73     std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET,
74         EdmInterfaceCode::DISALLOWED_AIRPLANE_MODE);
75     ErrCode ret = plugin->OnHandlePolicy(funcCode, data, reply, handlePolicyData, DEFAULT_USER_ID);
76     ASSERT_TRUE(ret == ERR_OK);
77 }
78 } // namespace TEST
79 } // namespace EDM
80 } // namespace OHOS