• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "ability_info.h"
18 #include "want.h"
19 #include "application_info.h"
20 #include "ability_record.h"
21 #include "dlp_state_item.h"
22 
23 using namespace testing::ext;
24 namespace OHOS {
25 namespace AAFwk {
26 
27 class DlpStateItemTest : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31     void SetUp();
32     void TearDown();
33 };
34 
SetUpTestCase()35 void DlpStateItemTest::SetUpTestCase()
36 {}
37 
TearDownTestCase()38 void DlpStateItemTest::TearDownTestCase()
39 {}
40 
SetUp()41 void DlpStateItemTest::SetUp()
42 {}
43 
TearDown()44 void DlpStateItemTest::TearDown()
45 {}
46 
47 /*
48  * Feature: DLP State Item
49  * Function: AddDlpConnectionState AddDlpConnectionState
50  * SubFunction: HandleDlpConnectionState
51  * FunctionPoints:DLP State Item HandleDlpConnectionState
52  * EnvConditions: NA
53  * CaseDescription: Verify andleDlpConnectionState
54  */
55 HWTEST_F(DlpStateItemTest, dlp_state_item_test_handle_001, TestSize.Level1)
56 {
57     auto item = std::make_shared<DlpStateItem>(1, 2);
58     AppExecFwk::AbilityInfo abilityInfo;
59     abilityInfo.launchMode = AppExecFwk::LaunchMode::STANDARD;
60     Want want;
61     AppExecFwk::ApplicationInfo applicationInfo;
62     std::shared_ptr<AbilityRecord> abilityRecord = std::make_shared<AbilityRecord>(want, abilityInfo, applicationInfo);
63     abilityRecord->Init();
64     abilityRecord->SetAppIndex(1);
65     AbilityRuntime::DlpStateData data;
66     EXPECT_FALSE(item->RemoveDlpConnectionState(abilityRecord, data));
67     EXPECT_TRUE(item->AddDlpConnectionState(abilityRecord, data));
68     EXPECT_FALSE(item->AddDlpConnectionState(abilityRecord, data));
69     EXPECT_TRUE(item->RemoveDlpConnectionState(abilityRecord, data));
70     EXPECT_FALSE(item->RemoveDlpConnectionState(abilityRecord, data));
71 }
72 
73 /*
74  * Feature: DLP State Item
75  * Function: GetOpenedAbilitySize
76  * SubFunction: NA
77  * FunctionPoints:DLP State Item GetOpenedAbilitySize
78  * EnvConditions: NA
79  * CaseDescription: Verify GetOpenedAbilitySize
80  */
81 HWTEST_F(DlpStateItemTest, dlp_state_item_test_get_size_002, TestSize.Level1)
82 {
83     auto item = std::make_shared<DlpStateItem>(1, 2);
84     AppExecFwk::AbilityInfo abilityInfo;
85     abilityInfo.launchMode = AppExecFwk::LaunchMode::STANDARD;
86     Want want;
87     AppExecFwk::ApplicationInfo applicationInfo;
88     std::shared_ptr<AbilityRecord> abilityRecord = std::make_shared<AbilityRecord>(want, abilityInfo, applicationInfo);
89     abilityRecord->Init();
90     AbilityRuntime::DlpStateData data;
91     abilityRecord->SetAppIndex(0);
92     EXPECT_FALSE(item->AddDlpConnectionState(abilityRecord, data));
93     abilityRecord->SetAppIndex(1);
94     EXPECT_TRUE(item->AddDlpConnectionState(abilityRecord, data));
95     auto item2 = std::make_shared<DlpStateItem>(0, 0);
96     EXPECT_FALSE(item2->AddDlpConnectionState(abilityRecord, data));
97 }
98 
99 /*
100  * Feature: DLP State Item
101  * Function: GetDlpUid
102  * SubFunction: H
103  * FunctionPoints:DLP State ItemGetDlpUid
104  * EnvConditions: NA
105  * CaseDescription: Verify GetDlpUid
106  */
107 HWTEST_F(DlpStateItemTest, dlp_state_item_test_get_uid_001, TestSize.Level1)
108 {
109     auto item = std::make_shared<DlpStateItem>(10, 2);
110     EXPECT_EQ(10, item->GetDlpUid());
111 }
112 
113 /*
114  * Feature: DLP State Item
115  * Function: GetOpenedAbilitySize
116  * SubFunction: GenerateDlpStateData
117  * FunctionPoints:DLP State Item GetOpenedAbilitySize
118  * EnvConditions: NA
119  * CaseDescription: Verify GetOpenedAbilitySize
120  */
121 HWTEST_F(DlpStateItemTest, dlp_state_item_test_get_size_001, TestSize.Level1)
122 {
123     auto item = std::make_shared<DlpStateItem>(1, 2);
124     AppExecFwk::AbilityInfo abilityInfo;
125     abilityInfo.launchMode = AppExecFwk::LaunchMode::STANDARD;
126     Want want;
127     AppExecFwk::ApplicationInfo applicationInfo;
128     std::shared_ptr<AbilityRecord> abilityRecord = std::make_shared<AbilityRecord>(want, abilityInfo, applicationInfo);
129     abilityRecord->Init();
130     abilityRecord->SetAppIndex(1);
131     AbilityRuntime::DlpStateData data;
132     EXPECT_EQ(0, item->GetOpenedAbilitySize());
133     EXPECT_TRUE(item->AddDlpConnectionState(abilityRecord, data));
134     EXPECT_LT(0, item->GetOpenedAbilitySize());
135     EXPECT_TRUE(item->RemoveDlpConnectionState(abilityRecord, data));
136     EXPECT_EQ(0, item->GetOpenedAbilitySize());
137 }
138 }  // namespace AppExecFwk
139 }  // namespace OHOS
140