1 /*
2  * Copyright (c) 2021-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 #ifndef ACCESSTOKEN_KIT_TEST_H
17 #define ACCESSTOKEN_KIT_TEST_H
18 
19 #include <gtest/gtest.h>
20 
21 #include "access_token.h"
22 #include "accesstoken_kit.h"
23 #include "permission_def.h"
24 #include "permission_state_full.h"
25 
26 namespace OHOS {
27 namespace Security {
28 namespace AccessToken {
29 static const std::string TEST_BUNDLE_NAME = "ohos";
30 static const std::string TEST_PERMISSION_NAME_ALPHA = "ohos.permission.ALPHA";
31 static const std::string TEST_PERMISSION_NAME_BETA = "ohos.permission.BETA";
32 static const std::string TEST_PERMISSION_NAME_GAMMA = "ohos.permission.GAMMA";
33 static const std::string TEST_PKG_NAME = "com.softbus.test";
34 static const int TEST_USER_ID = 0;
35 static const int TEST_USER_ID_INVALID = -1;
36 static const unsigned int TEST_TOKENID_INVALID = 0;
37 static const int INVALID_BUNDLENAME_LEN = 260;
38 static const int INVALID_APPIDDESC_LEN = 10244;
39 static const int INVALID_LABEL_LEN = 260;
40 static const int INVALID_DESCRIPTION_LEN = 260;
41 static const int INVALID_PERMNAME_LEN = 260;
42 static const int CYCLE_TIMES = 100;
43 static const int THREAD_NUM = 3;
44 static const int INVALID_DCAP_LEN = 1025;
45 static const int INVALID_DLP_TYPE = 4;
46 class AccessTokenKitTest : public testing::Test {
47 public:
48     static void SetUpTestCase();
49 
50     static void TearDownTestCase();
51 
52     void SetUp();
53 
54     void TearDown();
55     unsigned int GetAccessTokenID(int userID, std::string bundleName, int instIndex);
56     void DeleteTestToken() const;
57     AccessTokenID AllocTestToken(const HapInfoParams& hapInfo, const HapPolicyParams& hapPolicy) const;
58     void GetDlpFlagTest(HapInfoParams info, HapPolicyParams policy, int flag);
59 
60     uint64_t selfTokenId_;
61 };
62 } // namespace AccessToken
63 } // namespace Security
64 } // namespace OHOS
65 #endif // ACCESSTOKEN_KIT_TEST_H
66