• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <gtest/gtest.h>
16 #include <thread>
17 #include <cstring>
18 #include <algorithm>
19 #include <sched.h>
20 #include <unistd.h>
21 #include "ffrt_inner.h"
22 #include "c/queue_ext.h"
23 #include "../common.h"
24 #include "util/white_list.h"
25 
26 using namespace std;
27 using namespace ffrt;
28 using namespace testing;
29 #ifdef HWTEST_TESTING_EXT_ENABLE
30 using namespace testing::ext;
31 #endif
32 
33 class WhiteListTest : public testing::Test {
34 protected:
SetUpTestCase()35     static void SetUpTestCase()
36     {
37     }
38 
TearDownTestCase()39     static void TearDownTestCase()
40     {
41     }
42 
SetUp()43     void SetUp() override
44     {
45     }
46 
TearDown()47     void TearDown() override
48     {
49     }
50 };
51 
52 /*
53  * 测试用例名称 : whiteList_enable
54  * 测试用例描述:进程在白名单内
55  * 操作步骤    :1、调用接口查看是否在白名单内
56  * 预期结果    :接口返回True
57  */
58 HWTEST_F(WhiteListTest, whiteList_enable, TestSize.Level1)
59 {
60     int x = 0;
61     if (WhiteList::GetInstance().IsEnabled("WhiteListTest", true)) {
62         x += 1;
63     }
64     EXPECT_EQ(x, 1);
65 }
66 
67 /*
68  * 测试用例名称 : whiteList_default
69  * 测试用例描述:在白名单内且在异常场景下,默认返回True
70  * 操作步骤    :1、调用接口查看是否在白名单内,或是否处于异常场景
71  * 预期结果    :接口返回True
72  */
73 HWTEST_F(WhiteListTest, whiteList_default, TestSize.Level1)
74 {
75     int x = 0;
76     if (WhiteList::GetInstance().IsEnabled("WhiteListTest", true)) {
77         x += 1;
78     }
79 
80     if (WhiteList::GetInstance().IsEnabled("WhiteListTest123", true)) {
81         x += 1;
82     }
83     EXPECT_EQ(x, 2);
84 }
85 
86 /*
87  * 测试用例名称 : whiteList_default_reverse
88  * 测试用例描述:异常情况下,在白名单内且默认皆返回false
89  * 操作步骤    :1、调用接口查看是否在白名单内,或是否处于异常场景
90  * 预期结果    :接口返回false
91  */
92 HWTEST_F(WhiteListTest, whiteList_default_reverse, TestSize.Level1)
93 {
94     int x = 0;
95     if (WhiteList::GetInstance().IsEnabled("WhiteListTest1", false)) {
96         x += 1;
97     }
98     EXPECT_EQ(x, 0);
99 }