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 "os_account_manager.h" 17 #include "lock_screen_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)27void LockScreenPluginTest::SetUpTestSuite(void) 28 { 29 Utils::SetEdmInitialEnv(); 30 } 31 TearDownTestSuite(void)32void LockScreenPluginTest::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: TestLockScreenFail 41 * @tc.desc: Test LockScreenPlugin::OnSetPolicy function fail. 42 * @tc.type: FUNC 43 */ 44 HWTEST_F(LockScreenPluginTest, TestLockScreenFail, TestSize.Level1) 45 { 46 LockScreenPlugin plugin; 47 int32_t userId = 0; 48 AccountSA::OsAccountManager::GetOsAccountLocalIdFromProcess(userId); 49 uint64_t selfTokenId = GetSelfTokenID(); 50 SetSelfTokenID(0); 51 ErrCode ret = plugin.OnSetPolicy(userId); 52 SetSelfTokenID(selfTokenId); 53 ASSERT_TRUE(ret == EdmReturnErrCode::SYSTEM_ABNORMALLY); 54 } 55 /** 56 * @tc.name: TestLockScreenSuccess 57 * @tc.desc: Test LockScreenPlugin::OnSetPolicy function success. 58 * @tc.type: FUNC 59 */ 60 HWTEST_F(LockScreenPluginTest, TestLockScreenSuccess, TestSize.Level1) 61 { 62 LockScreenPlugin plugin; 63 int32_t userId = 0; 64 AccountSA::OsAccountManager::GetOsAccountLocalIdFromProcess(userId); 65 ErrCode ret = plugin.OnSetPolicy(userId); 66 ASSERT_TRUE(ret == ERR_OK); 67 } 68 } // namespace TEST 69 } // namespace EDM 70 } // namespace OHOS 71