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 "is_wifi_active_plugin.h"
18 #include "iplugin_manager.h"
19 #include "plugin_singleton.h"
20 #include "utils.h"
21 
22 using namespace testing::ext;
23 using namespace testing;
24 
25 namespace OHOS {
26 namespace EDM {
27 namespace TEST {
28 class IsWifiActivePluginTest : public testing::Test {
29 protected:
30     static void SetUpTestSuite(void);
31 
32     static void TearDownTestSuite(void);
33 };
34 
SetUpTestSuite(void)35 void IsWifiActivePluginTest::SetUpTestSuite(void)
36 {
37     Utils::SetEdmInitialEnv();
38 }
39 
TearDownTestSuite(void)40 void IsWifiActivePluginTest::TearDownTestSuite(void)
41 {
42     Utils::ResetTokenTypeAndUid();
43     ASSERT_TRUE(Utils::IsOriginalUTEnv());
44     std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
45 }
46 
47 /**
48  * @tc.name: TestIsWifiActiveFail
49  * @tc.desc: Test IsWifiActivePlugin fail function.
50  * @tc.type: FUNC
51  */
52 HWTEST_F(IsWifiActivePluginTest, TestIsWifiActiveFail, TestSize.Level1)
53 {
54     std::shared_ptr<IPlugin> plugin = IsWifiActivePlugin::GetPlugin();
55     std::string policyData{"TestIsWifiActive"};
56     MessageParcel data;
57     MessageParcel reply;
58     Utils::ResetTokenTypeAndUid();
59     ErrCode ret = plugin->OnGetPolicy(policyData, data, reply, DEFAULT_USER_ID);
60     ASSERT_TRUE(ret == EdmReturnErrCode::SYSTEM_ABNORMALLY);
61     Utils::SetEdmInitialEnv();
62 }
63 
64 /**
65  * @tc.name: TestIsWifiActiveSuc
66  * @tc.desc: Test IsWifiActivePlugin success function.
67  * @tc.type: FUNC
68  */
69 HWTEST_F(IsWifiActivePluginTest, TestIsWifiActiveSuc, TestSize.Level1)
70 {
71     std::shared_ptr<IPlugin> plugin = IsWifiActivePlugin::GetPlugin();
72     std::string policyData{"TestIsWifiActive"};
73     MessageParcel data;
74     MessageParcel reply;
75     ErrCode ret = plugin->OnGetPolicy(policyData, data, reply, DEFAULT_USER_ID);
76     ASSERT_TRUE(ret == ERR_OK);
77 }
78 } // namespace TEST
79 } // namespace EDM
80 } // namespace OHOS