• 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 "permission_grant_event_test.h"
17 
18 #define private public
19 #include "permission_grant_event.h"
20 #undef private
21 
22 using namespace testing::ext;
23 using namespace OHOS::Security::AccessToken;
24 
SetUpTestCase()25 void PermissionGrantEventTest::SetUpTestCase()
26 {}
27 
TearDownTestCase()28 void PermissionGrantEventTest::TearDownTestCase()
29 {
30     sleep(3); // delay 3 minutes
31 }
32 
SetUp()33 void PermissionGrantEventTest::SetUp()
34 {}
35 
TearDown()36 void PermissionGrantEventTest::TearDown()
37 {}
38 
39 /**
40  * @tc.name: NotifyPermGrantStoreResult001
41  * @tc.desc: test notify permssion grant event success
42  * @tc.type: FUNC
43  * @tc.require:issueI5OOPG
44  */
45 HWTEST_F(PermissionGrantEventTest, NotifyPermGrantStoreResult001, TestSize.Level0)
46 {
47     LOGI(ATM_DOMAIN, ATM_TAG, "NotifyPermGrantStoreResult001!");
48     AccessTokenID tokenID = 0x100000;
49     std::string permissionName = "testpremission";
50     uint64_t time;
51 
52     PermissionGrantEvent eventHandler;
53     eventHandler.AddEvent(tokenID, permissionName, time);
54 
55     // larger than grant timestamp
56     eventHandler.NotifyPermGrantStoreResult(true, time + 1);
57 
58     ASSERT_EQ(eventHandler.permGrantEventList_.size(), static_cast<uint32_t>(0));
59 }
60 
61 /**
62  * @tc.name: NotifyPermGrantStoreResult002
63  * @tc.desc: test notify permssion grant event failed
64  * @tc.type: FUNC
65  * @tc.require:issueI5OOPG
66  */
67 HWTEST_F(PermissionGrantEventTest, NotifyPermGrantStoreResult002, TestSize.Level0)
68 {
69     LOGI(ATM_DOMAIN, ATM_TAG, "NotifyPermGrantStoreResult002!");
70     AccessTokenID tokenID = 0x100000;
71     std::string permissionName = "testpremission";
72     uint64_t time;
73 
74     PermissionGrantEvent eventHandler;
75     eventHandler.AddEvent(tokenID, permissionName, time);
76 
77     // larger than grant timestamp
78     eventHandler.NotifyPermGrantStoreResult(false, time + 1);
79 
80     ASSERT_EQ(eventHandler.permGrantEventList_.size(), static_cast<uint32_t>(0));
81 }
82 
83 /**
84  * @tc.name: NotifyPermGrantStoreResult003
85  * @tc.desc: test notify permssion grant event success, but timestamp is less than add timestamp
86  * @tc.type: FUNC
87  * @tc.require:issueI5OOPG
88  */
89 HWTEST_F(PermissionGrantEventTest, NotifyPermGrantStoreResult003, TestSize.Level0)
90 {
91     LOGI(ATM_DOMAIN, ATM_TAG, "NotifyPermGrantStoreResult003!");
92     AccessTokenID tokenID = 0x100000;
93     std::string permissionName = "testpremission";
94     uint64_t time;
95 
96     PermissionGrantEvent eventHandler;
97     eventHandler.AddEvent(tokenID, permissionName, time);
98 
99     // less than grant timestamp
100     eventHandler.NotifyPermGrantStoreResult(true, time - 1);
101 
102     ASSERT_EQ(eventHandler.permGrantEventList_.size(), static_cast<uint32_t>(1));
103 }
104