• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include <gtest/gtest.h>
17 #include "set_wifi_disabled_plugin.h"
18 
19 #include "edm_ipc_interface_code.h"
20 #include "iplugin_manager.h"
21 #include "parameters.h"
22 #include "utils.h"
23 
24 using namespace testing::ext;
25 using namespace testing;
26 
27 namespace OHOS {
28 namespace EDM {
29 namespace TEST {
30 class SetWifiDisabledPluginTest : public testing::Test {
31 protected:
32     static void SetUpTestSuite(void);
33 
34     static void TearDownTestSuite(void);
35 };
36 
SetUpTestSuite(void)37 void SetWifiDisabledPluginTest::SetUpTestSuite(void)
38 {
39     Utils::SetEdmServiceEnable();
40     Utils::SetEdmInitialEnv();
41 }
42 
TearDownTestSuite(void)43 void SetWifiDisabledPluginTest::TearDownTestSuite(void)
44 {
45     Utils::SetEdmServiceDisable();
46     Utils::ResetTokenTypeAndUid();
47     ASSERT_TRUE(Utils::IsOriginalUTEnv());
48     std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
49 }
50 
51 /**
52  * @tc.name: TestSetWifiDisabledPluginTestSetTrue
53  * @tc.desc: Test SetWifiDisabledPluginTest::OnSetPolicy function.
54  * @tc.type: FUNC
55  */
56 HWTEST_F(SetWifiDisabledPluginTest, TestSetWifiDisabledPluginTestSetTrue, TestSize.Level1)
57 {
58     MessageParcel data;
59     MessageParcel reply;
60     data.WriteBool(true);
61     std::shared_ptr<IPlugin> plugin = SetWifiDisabledPlugin::GetPlugin();
62     HandlePolicyData handlePolicyData{"false", "", false};
63     std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::DISABLE_WIFI);
64     ErrCode ret = plugin->OnHandlePolicy(funcCode, data, reply, handlePolicyData, DEFAULT_USER_ID);
65     ASSERT_TRUE(ret == ERR_OK);
66     ASSERT_TRUE(handlePolicyData.isChanged);
67 }
68 
69 /**
70  * @tc.name: TestSetWifiDisabledPluginTestSetFalse
71  * @tc.desc: Test SetWifiDisabledPluginTest::OnSetPolicy function.
72  * @tc.type: FUNC
73  */
74 HWTEST_F(SetWifiDisabledPluginTest, TestSetWifiDisabledPluginTestSetFalse, TestSize.Level1)
75 {
76     MessageParcel data;
77     MessageParcel reply;
78     data.WriteBool(false);
79     std::shared_ptr<IPlugin> plugin = SetWifiDisabledPlugin::GetPlugin();
80     HandlePolicyData handlePolicyData{"false", "", false};
81     std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::DISABLE_WIFI);
82     ErrCode ret = plugin->OnHandlePolicy(funcCode, data, reply, handlePolicyData, DEFAULT_USER_ID);
83     ASSERT_TRUE(ret == ERR_OK);
84     ASSERT_TRUE(handlePolicyData.isChanged);
85 }
86 } // namespace TEST
87 } // namespace EDM
88 } // namespace OHOS