• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "token_sync_kit_test.h"
17 
18 #include "i_token_sync_manager.h"
19 #define private public
20 #include "token_sync_load_callback.h"
21 #undef private
22 
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Security {
27 namespace AccessToken {
SetUpTestCase()28 void TokenSyncKitTest::SetUpTestCase()
29 {}
30 
TearDownTestCase()31 void TokenSyncKitTest::TearDownTestCase()
32 {
33 }
34 
SetUp()35 void TokenSyncKitTest::SetUp()
36 {
37 }
38 
TearDown()39 void TokenSyncKitTest::TearDown()
40 {}
41 
42 /**
43  * @tc.name: OnLoadSystemAbilitySuccess001
44  * @tc.desc: TokenSyncLoadCallback::OnLoadSystemAbilitySuccess function test
45  * @tc.type: FUNC
46  * @tc.require:
47  */
48 HWTEST_F(TokenSyncKitTest, OnLoadSystemAbilitySuccess001, TestSize.Level1)
49 {
50     int32_t systemAbilityId = 0;
51 
52     bool ready = TokenSyncManagerClient::GetInstance().ready_; // backup
53     TokenSyncManagerClient::GetInstance().ready_ = true;
54 
55     sptr<TokenSyncLoadCallback> callback = new (std::nothrow) TokenSyncLoadCallback();
56     ASSERT_NE(nullptr, callback);
57 
58     callback->OnLoadSystemAbilitySuccess(systemAbilityId, nullptr); // start aystemabilityId is not TokenSync
59     ASSERT_EQ(true, TokenSyncManagerClient::GetInstance().ready_);
60 
61     TokenSyncManagerClient::GetInstance().ready_ = false;
62     callback->OnLoadSystemAbilityFail(0); // start aystemabilityId is not TokenSync
63     ASSERT_EQ(false, TokenSyncManagerClient::GetInstance().ready_);
64 
65     systemAbilityId = ITokenSyncManager::SA_ID_TOKENSYNC_MANAGER_SERVICE;
66     TokenSyncManagerClient::GetInstance().ready_ = true;
67     callback->OnLoadSystemAbilitySuccess(systemAbilityId, nullptr); // remoteObject is null
68     ASSERT_EQ(true, TokenSyncManagerClient::GetInstance().ready_);
69 
70     TokenSyncManagerClient::GetInstance().ready_ = false;
71     callback->OnLoadSystemAbilityFail(systemAbilityId); // systemAbilityId = 3504
72     ASSERT_EQ(true, TokenSyncManagerClient::GetInstance().ready_);
73 
74     TokenSyncManagerClient::GetInstance().ready_ = ready; // recovery
75 }
76 
77 /**
78  * @tc.name: UpdateRemoteHapTokenInfo001
79  * @tc.desc: TokenSyncManagerProxy::UpdateRemoteHapTokenInfo function test
80  * @tc.type: FUNC
81  * @tc.require:
82  */
83 HWTEST_F(TokenSyncKitTest, UpdateRemoteHapTokenInfo001, TestSize.Level1)
84 {
85     HapTokenInfoForSync tokenInfo;
86 
87     ASSERT_EQ(0, TokenSyncManagerClient::GetInstance().UpdateRemoteHapTokenInfo(tokenInfo));
88 }
89 } // namespace AccessToken
90 } // namespace Security
91 } // namespace OHOS
92