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 
17 #include "reboot_plugin_test.h"
18 #include "edm_ipc_interface_code.h"
19 #include "plugin_singleton.h"
20 #include "utils.h"
21 
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace EDM {
26 namespace TEST {
SetUpTestSuite(void)27 void RebootPluginTest::SetUpTestSuite(void)
28 {
29     Utils::SetEdmInitialEnv();
30 }
31 
TearDownTestSuite(void)32 void RebootPluginTest::TearDownTestSuite(void)
33 {
34     Utils::ResetTokenTypeAndUid();
35     ASSERT_TRUE(Utils::IsOriginalUTEnv());
36     std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
37 }
38 
39 /**
40  * @tc.name: TestShutdown
41  * @tc.desc: Test ShutdownPlugin::OnSetPolicy function fail.
42  * @tc.type: FUNC
43  */
44 HWTEST_F(RebootPluginTest, TestReboot, TestSize.Level1)
45 {
46     uint64_t selfTokenId = GetSelfTokenID();
47     SetSelfTokenID(0);
48     std::shared_ptr<IPlugin> plugin = RebootPlugin::GetPlugin();
49     uint32_t code = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::REBOOT);
50     HandlePolicyData handlePolicyData{"", false};
51     MessageParcel data;
52     MessageParcel reply;
53     ErrCode ret = plugin->OnHandlePolicy(code, data, reply, handlePolicyData, DEFAULT_USER_ID);
54     ASSERT_TRUE(ret == EdmReturnErrCode::SYSTEM_ABNORMALLY);
55     SetSelfTokenID(selfTokenId);
56 }
57 } // namespace TEST
58 } // namespace EDM
59 } // namespace OHOS
60