1 /*
2  * Copyright (c) 2020-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 
17 #ifndef _ACTS_PMS_TEST_H_
18 #define _ACTS_PMS_TEST_H_
19 
20 #include <cstdio>
21 #include <cstdlib>
22 #include <cstring>
23 #include <fcntl.h>
24 #include <securec.h>
25 #include <string>
26 #include <sys/stat.h>
27 #include <sys/types.h>
28 #include <sys/wait.h>
29 #include <unistd.h>
30 
31 #include "gtest/gtest.h"
32 #include "iunknown.h"
33 #include "perm_define.h"
34 #include "perm_operate.h"
35 #include "pms.h"
36 #include "pms_common.h"
37 #include "pms_inner.h"
38 #include "pms_interface.h"
39 #include "pms_types.h"
40 #include "samgr_lite.h"
41 #include "service.h"
42 #include "feature.h"
43 
44 
45 #define TEST_APP_ID "com.permission.test"
46 #define TEST_APP_ID2 "com.permission.test2"
47 #define SUBTEST_APP_ID "com.permission.subtest"
48 #define TEST_APP_SHORT "a"
49 #define TEST_APP_LONG "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
50 #define TEST_APP_PATH "/storage/app/etc/permissions/com.permission.test"
51 #define PERMISSION_UNDEFINED "ohos.permission.TEST"
52 #define PERMISSION_TOOLONG "ohos.permission.balabalabalabalabalabalabalabalabalabalabalabalabalabala"
53 #define PERMISSION_EMPTY ""
54 #define PERMISSION_UNSUPPORTED "!@#$%^&*()_+"
55 #define APP_PREFIX "/storage/app"
56 #define ETC_PREFIX "/storage/app/etc"
57 #define PERMISSION_PREFIX "/storage/app/etc/permissions"
58 
59 const int SLEEP_TIME = 5;
60 const int TEST_TASKID = 1000;
61 const int SUBTEST_TASKID = 1001;
62 const int ABNORMAL_TASKID = -1;
63 const int SYS_PERM_NUM = 9;
64 const int ABNORMAL_PERM_NUM = 3;
65 const int MAX_PERM_NUM = 1024;
66 const int RET_OK = 0;
67 const int RET_NOK = -1;
68 const int RELT_TEST_TIME = 1000;
69 const int MAX_PID = 0x7fffffff;
70 const int MIN_PID = 0;
71 const int ABNORMAL_PKG_NUM = 5;
72 const int DIR_MODE = 777;
73 
74 int IsUserGrant(const char *pname);
75 
76 int CheckPermData(const PermissionTrans *pt, const PermissionSaved *ps, const PermissionSaved *pre, int len, int plen);
77 
78 void CheckAppPermission(const char *identifier, int expRet, int expNum, const PermissionTrans *installPers,
79     const PermissionSaved *lastPers = nullptr, int lastLen = 0);
80 
81 void SubTestWithoutCheck(const char *identifier, int taskId);
82 
83 void CreateAppDir(void);
84 
85 #endif
86 
87