!41 代码 codex 修改合入到 3.2Beta1 分支

Merge pull request !41 from chenyude/Beta1-cherrypick
This commit is contained in:
openharmony_ci
2022-05-20 04:05:36 +00:00
committed by Gitee
8 changed files with 135 additions and 81 deletions
-1
View File
@@ -34,7 +34,6 @@ ohos_executable("syscap_tool_bin") {
if (is_mingw) {
defines += [ "_POSIX_" ]
}
sources = [ "./src/main.c" ]
sources += sources_platform_common
+2 -2
View File
@@ -280,7 +280,7 @@ static SyscapWithNum arraySyscap[] = {
{"SystemCapability.Security.DeviceAuth", SECURITY_DEVICEAUTH},
{"SystemCapability.Security.DeviceSecurityLevel", SECURITY_DEVICESECURITYLEVEL},
{"SystemCapability.Security.Huks", SECURITY_HUKS},
{"SystemCapability.Sensors.Medical_sensor", SENSORS_MEDICAL_SENSOR},
{"SystemCapability.Sensors.Medical.Sensor", SENSORS_MEDICAL_SENSOR},
{"SystemCapability.Sensors.MiscDevice", SENSORS_MISCDEVICE},
{"SystemCapability.Sensors.Sensor", SENSORS_SENSOR},
{"SystemCapability.Sensors.Sensor.Lite", SENSORS_SENSOR_LITE},
@@ -305,4 +305,4 @@ static SyscapWithNum arraySyscap[] = {
{"SystemCapability.UserIAM.UserIdm", USERIAM_USERIDM}
};
#endif // _SYSCAP_DEFINE_H
#endif // _SYSCAP_DEFINE_H
+9 -9
View File
@@ -25,10 +25,10 @@
#include "syscap_interface.h"
#define PCID_OUT_BUFFER 32
#define MAX_SYSCAP_STR_LEN 128
#define OS_SYSCAP_BYTES 120
#define BITS_OF_BYTE 8
#define PCID_MAIN_LEN 128
#define PATH_MAX 4096
#define PRINT_ERR(...) \
do { \
@@ -36,19 +36,19 @@
printf(__VA_ARGS__); \
} while (0)
static char *inputFile = "/system/etc/PCID.sc";
static void FreeContextBuffer(char *contextBuffer)
{
(void)free(contextBuffer);
}
static uint32_t GetFileContext(char **contextBufPtr, uint32_t *bufferLen)
static int32_t GetFileContext(char **contextBufPtr, uint32_t *bufferLen)
{
uint32_t ret;
int32_t ret;
FILE *fp = NULL;
struct stat statBuf;
char *contextBuffer = NULL;
const char *inputFile = "/system/etc/PCID.sc";
ret = stat(inputFile, &statBuf);
if (ret != 0) {
PRINT_ERR("get file(%s) st_mode failed, errno = %d\n", inputFile, errno);
@@ -63,6 +63,7 @@ static uint32_t GetFileContext(char **contextBufPtr, uint32_t *bufferLen)
PRINT_ERR("malloc buffer failed, size = %d, errno = %d\n", (int32_t)statBuf.st_size + 1, errno);
return -1;
}
fp = fopen(inputFile, "rb");
if (fp == NULL) {
PRINT_ERR("open file(%s) failed, errno = %d\n", inputFile, errno);
@@ -84,7 +85,7 @@ static uint32_t GetFileContext(char **contextBufPtr, uint32_t *bufferLen)
return 0;
}
bool EncodeOsSyscap(char output[128])
bool EncodeOsSyscap(char output[MAX_SYSCAP_STR_LEN])
{
int32_t ret;
int32_t res;
@@ -130,7 +131,7 @@ bool EncodePrivateSyscap(char **output, int *outputLen)
}
(void)memset_s(outputStr, *outputLen, 0, *outputLen);
ret = strncpy_s(outputStr, *outputLen, contextBuffer + PCID_MAIN_LEN, *outputLen);
ret = strncpy_s(outputStr, *outputLen, contextBuffer + PCID_MAIN_LEN, *outputLen - 1);
if (ret != 0) {
PRINT_ERR("strcpy_s failed.");
FreeContextBuffer(contextBuffer);
@@ -197,8 +198,7 @@ bool DecodePrivateSyscap(char *input, char (**output)[128], int *outputCnt)
{
char (*outputArray)[MAX_SYSCAP_STR_LEN] = NULL;
char *inputPos = input;
uint16_t bufferLen;
int ret;
int bufferLen, ret;
int syscapCnt = 0;
while (*inputPos != '\0') {
+3 -1
View File
@@ -25,7 +25,9 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
bool EncodeOsSyscap(char output[128]);
#define MAX_SYSCAP_STR_LEN 128
bool EncodeOsSyscap(char output[MAX_SYSCAP_STR_LEN]);
bool DecodeOsSyscap(char input[128], char (**output)[128], int *outputCnt);
bool EncodePrivateSyscap(char **output, int *outputLen);
bool DecodePrivateSyscap(char *input, char (**output)[128], int *outputCnt);
+1 -1
View File
@@ -61,7 +61,7 @@ static char* getSystemCapability()
bool retBool;
int retError, priOutputLen, priCapArrayCnt, sumLen;
int i = 0;
char osOutput[128] = {};
char osOutput[SYSCAP_STR_MAX_LEN] = {};
errno_t err = EOK;
uint32_t *osCapU32 = nullptr;
char *priOutput = nullptr;
+50 -28
View File
@@ -47,20 +47,33 @@ static void FreeContextBuffer(char *contextBuffer)
(void)free(contextBuffer);
}
static uint32_t GetFileContext(char *inputFile, char **contextBufPtr, uint32_t *contextBufLen)
static int32_t GetFileContext(char *inputFile, char **contextBufPtr, uint32_t *contextBufLen)
{
uint32_t ret;
int32_t ret;
FILE *fp = NULL;
struct stat statBuf;
char *contextBuffer = NULL;
char path[PATH_MAX + 1] = {0x00};
ret = stat(inputFile, &statBuf);
#ifdef _POSIX_
if (strlen(inputFile) > PATH_MAX || strncpy_s(path, PATH_MAX, inputFile, strlen(inputFile)) != EOK) {
PRINT_ERR("get path(%s) failed\n", inputFile);
return -1;
}
#else
if (strlen(inputFile) > PATH_MAX || realpath(inputFile, path) == NULL) {
PRINT_ERR("get file(%s) real path failed\n", inputFile);
return -1;
}
#endif
ret = stat(path, &statBuf);
if (ret != 0) {
PRINT_ERR("get file(%s) st_mode failed, errno = %d\n", inputFile, errno);
PRINT_ERR("get file(%s) st_mode failed, errno = %d\n", path, errno);
return -1;
}
if (!(statBuf.st_mode & S_IRUSR)) {
PRINT_ERR("don't have permission to read the file(%s)\n", inputFile);
PRINT_ERR("don't have permission to read the file(%s)\n", path);
return -1;
}
contextBuffer = (char *)malloc(statBuf.st_size + 1);
@@ -68,15 +81,16 @@ static uint32_t GetFileContext(char *inputFile, char **contextBufPtr, uint32_t *
PRINT_ERR("malloc buffer failed, size = %d, errno = %d\n", (int32_t)statBuf.st_size + 1, errno);
return -1;
}
fp = fopen(inputFile, "rb");
fp = fopen(path, "rb");
if (fp == NULL) {
PRINT_ERR("open file(%s) failed, errno = %d\n", inputFile, errno);
PRINT_ERR("open file(%s) failed, errno = %d\n", path, errno);
FreeContextBuffer(contextBuffer);
return -1;
}
ret = fread(contextBuffer, statBuf.st_size, 1, fp);
if (ret != 1) {
PRINT_ERR("read file(%s) failed, errno = %d\n", inputFile, errno);
PRINT_ERR("read file(%s) failed, errno = %d\n", path, errno);
FreeContextBuffer(contextBuffer);
(void)fclose(fp);
return -1;
@@ -94,35 +108,44 @@ static int32_t ConvertedContextSaveAsFile(char *outDirPath, const char *filename
{
int32_t ret;
FILE *fp = NULL;
char fileFullPath[PATH_MAX] = {0};
int32_t pathLen = strlen(outDirPath);
char path[PATH_MAX + 1] = {0x00};
ret = strncpy_s(fileFullPath, PATH_MAX, outDirPath, pathLen + 1);
if (ret != 0) {
PRINT_ERR("strncpy_s failed, source string:%s, len = %d, errno = %d\n", outDirPath, pathLen + 1, errno);
#ifdef _POSIX_
if (strlen(outDirPath) > PATH_MAX || strncpy_s(path, PATH_MAX, outDirPath, strlen(outDirPath)) != EOK) {
PRINT_ERR("get path(%s) failed\n", outDirPath);
return -1;
}
#else
if (strlen(outDirPath) > PATH_MAX || realpath(outDirPath, path) == NULL) {
PRINT_ERR("get file(%s) real path failed\n", outDirPath);
return -1;
}
#endif
if (fileFullPath[pathLen - 1] != '/' && fileFullPath[pathLen - 1] != '\\') {
fileFullPath[pathLen] = '/';
if (path[pathLen - 1] != '/' && path[pathLen - 1] != '\\') {
path[pathLen] = '/';
}
ret = strncat_s(fileFullPath, PATH_MAX, filename, strlen(filename) + 1);
if (strlen(path) + strlen(filename) + 1 > PATH_MAX) {
PRINT_ERR("length of path too long.\n");
return -1;
}
ret = strncat_s(path, PATH_MAX, filename, strlen(filename) + 1);
if (ret != 0) {
PRINT_ERR("strncat_s failed, (%s, %d, %s, %d), errno = %d\n",
fileFullPath, PATH_MAX, filename, (int32_t)strlen(filename) + 1, errno);
path, PATH_MAX, filename, (int32_t)strlen(filename) + 1, errno);
return -1;
}
fp = fopen(fileFullPath, "wb");
fp = fopen(path, "wb");
if (fp == NULL) {
PRINT_ERR("can't create file(%s), errno = %d\n", fileFullPath, errno);
PRINT_ERR("can't create file(%s), errno = %d\n", path, errno);
return -1;
}
ret = fwrite(convertedBuffer, contextBufLen, 1, fp);
if (ret != 1) {
PRINT_ERR("can't write file(%s),errno = %d\n", fileFullPath, errno);
if (fwrite(convertedBuffer, contextBufLen, 1, fp) != 1) {
PRINT_ERR("can't write file(%s),errno = %d\n", path, errno);
(void)fclose(fp);
return -1;
}
@@ -144,9 +167,8 @@ static cJSON *CreateWholeSyscapJsonObj(void)
int32_t CreatePCID(char *inputFile, char *outDirPath)
{
uint8_t sectorOfBits, posOfBits;
int32_t ret, i;
uint32_t contextBufLen, osCapSize, privateCapSize;
int32_t ret, sectorOfBits, posOfBits;
uint32_t i, contextBufLen, privateCapSize, osCapSize;
errno_t nRet = 0;
char *contextBuffer = NULL;
char *systemType = NULL;
@@ -268,7 +290,7 @@ int32_t CreatePCID(char *inputFile, char *outDirPath)
jsonSyscapObj = cJSON_GetObjectItem(jsonRootObj, "system_type");
if (jsonSyscapObj == NULL || !cJSON_IsString(jsonSyscapObj)) {
PRINT_ERR("get \"system_type\" failed, jsonSyscapObj = %p\n", jsonSyscapObj);
PRINT_ERR("get \"system_type\" failed\n");
ret = -1;
goto FREE_PCID_BUFFER_OUT;
}
@@ -308,12 +330,12 @@ FREE_CONVERT_OUT:
int32_t DecodePCID(char *inputFile, char *outDirPath)
{
int32_t ret, i, j;
int32_t ret;
errno_t nRet = 0;
char *contextBuffer = NULL;
uint8_t osSyscap[BYTES_OF_OS_SYSCAP] = {0};
uint16_t indexOfSyscap[960] = {0};
uint32_t contextBufLen, countOfSyscap = 0;
uint16_t indexOfSyscap[BYTES_OF_OS_SYSCAP * BITS_OF_ONE_BYTE] = {0};
uint32_t i, j, contextBufLen, countOfSyscap = 0;
ret = GetFileContext(inputFile, &contextBuffer, &contextBufLen);
if (ret != 0) {
+65 -34
View File
@@ -54,20 +54,33 @@ static void FreeContextBuffer(char *contextBuffer)
(void)free(contextBuffer);
}
static uint32_t GetFileContext(char *inputFile, char **contextBufPtr, uint32_t *bufferLen)
static int32_t GetFileContext(char *inputFile, char **contextBufPtr, uint32_t *bufferLen)
{
uint32_t ret;
int32_t ret;
FILE *fp = NULL;
struct stat statBuf;
char *contextBuffer = NULL;
char path[PATH_MAX + 1] = {0x00};
ret = stat(inputFile, &statBuf);
#ifdef _POSIX_
if (strlen(inputFile) > PATH_MAX || strncpy_s(path, PATH_MAX, inputFile, strlen(inputFile)) != EOK) {
PRINT_ERR("get path(%s) failed\n", inputFile);
return -1;
}
#else
if (strlen(inputFile) > PATH_MAX || realpath(inputFile, path) == NULL) {
PRINT_ERR("get file(%s) real path failed\n", inputFile);
return -1;
}
#endif
ret = stat(path, &statBuf);
if (ret != 0) {
PRINT_ERR("get file(%s) st_mode failed, errno = %d\n", inputFile, errno);
PRINT_ERR("get file(%s) st_mode failed, errno = %d\n", path, errno);
return -1;
}
if (!(statBuf.st_mode & S_IRUSR)) {
PRINT_ERR("don't have permission to read the file(%s)\n", inputFile);
PRINT_ERR("don't have permission to read the file(%s)\n", path);
return -1;
}
contextBuffer = (char *)malloc(statBuf.st_size + 1);
@@ -75,15 +88,15 @@ static uint32_t GetFileContext(char *inputFile, char **contextBufPtr, uint32_t *
PRINT_ERR("malloc buffer failed, size = %d, errno = %d\n", (int32_t)statBuf.st_size + 1, errno);
return -1;
}
fp = fopen(inputFile, "rb");
fp = fopen(path, "rb");
if (fp == NULL) {
PRINT_ERR("open file(%s) failed, errno = %d\n", inputFile, errno);
PRINT_ERR("open file(%s) failed, errno = %d\n", path, errno);
FreeContextBuffer(contextBuffer);
return -1;
}
ret = fread(contextBuffer, statBuf.st_size, 1, fp);
if (ret != 1) {
PRINT_ERR("read file(%s) failed, errno = %d\n", inputFile, errno);
PRINT_ERR("read file(%s) failed, errno = %d\n", path, errno);
FreeContextBuffer(contextBuffer);
(void)fclose(fp);
return -1;
@@ -100,35 +113,45 @@ static int32_t ConvertedContextSaveAsFile(char *outDirPath, char *filename, char
{
int32_t ret;
FILE *fp = NULL;
char fileFullPath[PATH_MAX] = {0};
char path[PATH_MAX + 1] = {0x00};
int32_t pathLen = strlen(outDirPath);
ret = strncpy_s(fileFullPath, PATH_MAX, outDirPath, pathLen + 1);
if (ret != 0) {
PRINT_ERR("strncpy_s failed, source string:%s, len = %d, errno = %d\n", outDirPath, pathLen + 1, errno);
#ifdef _POSIX_
if (strlen(outDirPath) > PATH_MAX || strncpy_s(path, PATH_MAX, outDirPath, strlen(outDirPath)) != EOK) {
PRINT_ERR("get path(%s) failed\n", outDirPath);
return -1;
}
#else
if (strlen(outDirPath) > PATH_MAX || realpath(outDirPath, path) == NULL) {
PRINT_ERR("get file(%s) real path failed\n", outDirPath);
return -1;
}
#endif
if (fileFullPath[pathLen - 1] != '/' && fileFullPath[pathLen - 1] != '\\') {
fileFullPath[pathLen] = '/';
if (path[pathLen - 1] != '/' && path[pathLen - 1] != '\\') {
path[pathLen] = '/';
}
ret = strncat_s(fileFullPath, PATH_MAX, filename, strlen(filename) + 1);
if (strlen(filename) + 1 > PATH_MAX) {
PRINT_ERR("filename(%s) too long.\n", filename);
return -1;
}
ret = strncat_s(path, PATH_MAX, filename, strlen(filename));
if (ret != 0) {
PRINT_ERR("strncat_s failed, (%s, %d, %s, %d), errno = %d\n",
fileFullPath, PATH_MAX, filename, (int32_t)strlen(filename) + 1, errno);
path, PATH_MAX, filename, (int32_t)strlen(filename) + 1, errno);
return -1;
}
fp = fopen(fileFullPath, "wb");
fp = fopen(path, "wb");
if (fp == NULL) {
PRINT_ERR("can`t create file(%s), errno = %d\n", fileFullPath, errno);
PRINT_ERR("can`t create file(%s), errno = %d\n", path, errno);
return -1;
}
ret = fwrite(convertedBuffer, bufferLen, 1, fp);
if (ret != 1) {
PRINT_ERR("can`t write file(%s),errno = %d\n", fileFullPath, errno);
size_t retFwrite = fwrite(convertedBuffer, bufferLen, 1, fp);
if (retFwrite != 1) {
PRINT_ERR("can`t write file(%s),errno = %d\n", path, errno);
(void)fclose(fp);
return -1;
}
@@ -143,11 +166,10 @@ int32_t PCIDEncode(char *inputFile, char *outDirPath)
int32_t ret;
char productName[NAME_MAX] = {0};
char *contextBuffer = NULL;
uint32_t bufferLen;
uint32_t bufferLen, osCapSize, privateCapSize;
char *convertedBuffer = NULL;
uint32_t convertedBufLen = sizeof(PCIDHead);
char *systemType = NULL;
int32_t osCapSize, privateCapSize;
PCIDHead *headPtr = NULL;
char *fillTmpPtr = NULL;
cJSON *cjsonObjectRoot = NULL;
@@ -206,6 +228,11 @@ int32_t PCIDEncode(char *inputFile, char *outDirPath)
}
convertedBuffer = (char *)malloc(convertedBufLen);
if (convertedBuffer == NULL) {
PRINT_ERR("malloc failed.\n");
ret = -1;
goto FREE_CONTEXT_OUT;
}
(void)memset_s(convertedBuffer, convertedBufLen, 0, convertedBufLen);
@@ -221,7 +248,7 @@ int32_t PCIDEncode(char *inputFile, char *outDirPath)
cjsonObjectPtr = cJSON_GetObjectItem(cjsonObjectRoot, "system_type");
if (cjsonObjectPtr == NULL || !cJSON_IsString(cjsonObjectPtr)) {
PRINT_ERR("get \"system_type\" failed, cjsonObjectPtr = %p\n", cjsonObjectPtr);
PRINT_ERR("get \"system_type\" failed.\n");
ret = -1;
goto FREE_CONVERT_OUT;
}
@@ -250,7 +277,7 @@ int32_t PCIDEncode(char *inputFile, char *outDirPath)
// fill osCap Length
*(uint16_t *)fillTmpPtr = HtonsInter((uint16_t)(osCapSize * SINGLE_FEAT_LENGTH));
fillTmpPtr += sizeof(uint16_t);
for (int32_t i = 0; i < osCapSize; i++) {
for (uint32_t i = 0; i < osCapSize; i++) {
arrayItemPtr = cJSON_GetArrayItem(osCapPtr, i);
char *pointPos = strchr(arrayItemPtr->valuestring, '.');
if (pointPos == NULL) {
@@ -280,7 +307,7 @@ int32_t PCIDEncode(char *inputFile, char *outDirPath)
// fill privateCap Length
*(uint16_t *)fillTmpPtr = HtonsInter((uint16_t)(privateCapSize * SINGLE_FEAT_LENGTH));
fillTmpPtr += sizeof(uint16_t);
for (int32_t i = 0; i < privateCapSize; i++) {
for (uint32_t i = 0; i < privateCapSize; i++) {
arrayItemPtr = cJSON_GetArrayItem(privateCapPtr, i);
char *pointPos = strchr(arrayItemPtr->valuestring, '.');
if (pointPos == NULL) {
@@ -425,7 +452,7 @@ int32_t PCIDDecode(char *inputFile, char *outDirPath)
ret = -1;
goto FREE_SYSCAP_OUT;
}
for (int32_t i = 0; i < (sysCapLength / SINGLE_FEAT_LENGTH); i++) {
for (uint32_t i = 0; i < (sysCapLength / SINGLE_FEAT_LENGTH); i++) {
if (*(osCapArrayPtr + (i + 1) * SINGLE_FEAT_LENGTH - 1) != '\0') {
PRINT_ERR("prase file failed, format is invalid, input file : %s\n", inputFile);
ret = -1;
@@ -474,7 +501,7 @@ int32_t PCIDDecode(char *inputFile, char *outDirPath)
goto FREE_SYSCAP_OUT;
}
for (int32_t i = 0; i < (sysCapLength / SINGLE_FEAT_LENGTH); i++) {
for (uint32_t i = 0; i < (sysCapLength / SINGLE_FEAT_LENGTH); i++) {
if (*(privateCapArrayPtr + (i + 1) * SINGLE_FEAT_LENGTH - 1) != '\0') {
PRINT_ERR("prase file failed, format is invalid, input file : %s\n", inputFile);
ret = -1;
@@ -569,10 +596,9 @@ int32_t RPCIDEncode(char *inputFile, char *outDirPath)
{
int32_t ret;
char *contextBuffer = NULL;
uint32_t bufferLen;
uint32_t bufferLen, sysCapSize;
char *convertedBuffer = NULL;
uint32_t convertedBufLen = sizeof(RPCIDHead);
int32_t sysCapSize;
RPCIDHead *headPtr = NULL;
char *fillTmpPtr = NULL;
cJSON *cjsonObjectRoot = NULL;
@@ -595,7 +621,7 @@ int32_t RPCIDEncode(char *inputFile, char *outDirPath)
sysCapPtr = cJSON_GetObjectItem(cjsonObjectRoot, "syscap");
if (sysCapPtr == NULL || !cJSON_IsArray(sysCapPtr)) {
PRINT_ERR("get \"syscap\" object failed, sysCapPtr = %p\n", sysCapPtr);
PRINT_ERR("get \"syscap\" object failed.\n");
ret = -1;
goto FREE_CONTEXT_OUT;
}
@@ -610,6 +636,11 @@ int32_t RPCIDEncode(char *inputFile, char *outDirPath)
convertedBufLen += (2 * sizeof(uint16_t) + sysCapSize * SINGLE_FEAT_LENGTH);
convertedBuffer = (char *)malloc(convertedBufLen);
if (convertedBuffer == NULL) {
PRINT_ERR("malloc failed\n");
ret = -1;
goto FREE_CONTEXT_OUT;
}
(void)memset_s(convertedBuffer, convertedBufLen, 0, convertedBufLen);
headPtr = (RPCIDHead *)convertedBuffer;
@@ -629,7 +660,7 @@ int32_t RPCIDEncode(char *inputFile, char *outDirPath)
// fill osCap Length
*(uint16_t *)fillTmpPtr = HtonsInter((uint16_t)(sysCapSize * SINGLE_FEAT_LENGTH));
fillTmpPtr += sizeof(uint16_t);
for (int32_t i = 0; i < sysCapSize; i++) {
for (uint32_t i = 0; i < sysCapSize; i++) {
arrayItemPtr = cJSON_GetArrayItem(sysCapPtr, i);
char *pointPos = strchr(arrayItemPtr->valuestring, '.');
if (pointPos == NULL) {
@@ -668,7 +699,7 @@ FREE_CONTEXT_OUT:
int32_t RPCIDDecode(char *inputFile, char *outDirPath)
{
uint32_t ret;
int32_t ret;
char *contextBuffer = NULL;
char *contextBufferTail = NULL;
uint32_t bufferLen;
@@ -720,7 +751,7 @@ int32_t RPCIDDecode(char *inputFile, char *outDirPath)
ret = -1;
goto FREE_CONTEXT_OUT;
}
for (int32_t i = 0; i < (sysCapLength / SINGLE_FEAT_LENGTH); i++) {
for (uint32_t i = 0; i < (sysCapLength / SINGLE_FEAT_LENGTH); i++) {
if (*(sysCapArrayPtr + (i + 1) * SINGLE_FEAT_LENGTH - 1) != '\0') {
PRINT_ERR("prase file failed, format is invalid, input file : %s\n", inputFile);
ret = -1;
+5 -5
View File
@@ -34,7 +34,7 @@ void SyscapCodecTest::TearDown() {}
*/
HWTEST_F(SyscapCodecTest, EncodeOsSyscap, TestSize.Level1)
{
char OsInput[128] = {0};
char OsInput[MAX_SYSCAP_STR_LEN] = {0};
EXPECT_TRUE(EncodeOsSyscap(OsInput));
}
@@ -59,12 +59,12 @@ HWTEST_F(SyscapCodecTest, EncodePrivateSyscap, TestSize.Level1)
HWTEST_F(SyscapCodecTest, DecodeOsSyscap, TestSize.Level1)
{
int osSyscap[32] = {1, 3, 3};
char (*osOutput)[128] = NULL;
char (*osOutput)[MAX_SYSCAP_STR_LEN] = NULL;
int decodeOsCnt;
char expectOsOutput001[] = "SystemCapability.Account.AppAccount";
char expectOsOutput002[] = "SystemCapability.Account.OsAccount";
EXPECT_TRUE(DecodeOsSyscap((char *)osSyscap, &osOutput, &decodeOsCnt));
char (*tmpOsOutput)[128] = osOutput;
char (*tmpOsOutput)[MAX_SYSCAP_STR_LEN] = osOutput;
EXPECT_STREQ(*tmpOsOutput, expectOsOutput001);
EXPECT_STREQ(*(tmpOsOutput + 1), expectOsOutput002);
EXPECT_EQ(decodeOsCnt, 2);
@@ -78,7 +78,7 @@ HWTEST_F(SyscapCodecTest, DecodeOsSyscap, TestSize.Level1)
*/
HWTEST_F(SyscapCodecTest, DecodePrivateSyscap, TestSize.Level1)
{
char (*priOutput)[128] = NULL;
char (*priOutput)[MAX_SYSCAP_STR_LEN] = NULL;
char priSyscap[] = "Device.syscap1GEDR,Device.syscap2WREGW,Vendor.syscap3RGD,Vendor.syscap4RWEG,Vendor.syscap5REWGWE,";
int decodePriCnt;
char expectPriOutput001[] = "SystemCapability.Device.syscap1GEDR";
@@ -87,7 +87,7 @@ HWTEST_F(SyscapCodecTest, DecodePrivateSyscap, TestSize.Level1)
char expectPriOutput004[] = "SystemCapability.Vendor.syscap4RWEG";
char expectPriOutput005[] = "SystemCapability.Vendor.syscap5REWGWE";
EXPECT_TRUE(DecodePrivateSyscap(priSyscap, &priOutput, &decodePriCnt));
char (*tmpPtiOutput)[128] = priOutput;
char (*tmpPtiOutput)[MAX_SYSCAP_STR_LEN] = priOutput;
EXPECT_STREQ(*tmpPtiOutput++, expectPriOutput001);
EXPECT_STREQ(*tmpPtiOutput++, expectPriOutput002);
EXPECT_STREQ(*tmpPtiOutput++, expectPriOutput003);