mirror of
https://github.com/openharmony/developtools_syscap_codec.git
synced 2026-08-27 02:11:19 -04:00
add test case for inner api.
Signed-off-by: yudechen <chenyude@huawei.com> Change-Id: Ie420cd3c297e45108ed66fdab649508b5cd8a2a8
This commit is contained in:
@@ -25,7 +25,7 @@ typedef struct SystemCapabilityWithNum {
|
||||
uint16_t num;
|
||||
} SyscapWithNum;
|
||||
|
||||
/* sort by alphabet */
|
||||
/* add last */
|
||||
typedef enum SystemCapabilityNum {
|
||||
ACCOUNT_APPACCOUNT,
|
||||
ACCOUNT_OSACCOUNT,
|
||||
@@ -179,7 +179,7 @@ typedef enum SystemCapabilityNum {
|
||||
} SyscapNum;
|
||||
|
||||
/* sort by enum */
|
||||
static SyscapWithNum arraySyscap[] = {
|
||||
const static SyscapWithNum arraySyscap[] = {
|
||||
{"SystemCapability.Account.AppAccount", ACCOUNT_APPACCOUNT},
|
||||
{"SystemCapability.Account.OsAccount", ACCOUNT_OSACCOUNT},
|
||||
{"SystemCapability.Ace.UiAppearance", ACE_UI_APPEARANCE},
|
||||
|
||||
@@ -161,8 +161,12 @@ bool EncodePrivateSyscap(char **output, int *outputLen)
|
||||
PRINT_ERR("GetFileContext failed, input file : /system/etc/PCID.sc\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
*outputLen = bufferLen - PCID_MAIN_BYTES - 1;
|
||||
if (*outputLen == 0) {
|
||||
*output = outputStr;
|
||||
return true;
|
||||
}
|
||||
outputStr = (char *)malloc(*outputLen);
|
||||
if (outputStr == NULL) {
|
||||
PRINT_ERR("malloc buffer failed, size = %d, errno = %d\n", *outputLen, errno);
|
||||
@@ -185,7 +189,7 @@ bool EncodePrivateSyscap(char **output, int *outputLen)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DecodeOsSyscap(char input[PCID_MAIN_BYTES], char (**output)[SINGLE_SYSCAP_LEN], int *outputCnt)
|
||||
bool DecodeOsSyscap(const char input[PCID_MAIN_BYTES], char (**output)[SINGLE_SYSCAP_LEN], int *outputCnt)
|
||||
{
|
||||
errno_t nRet = 0;
|
||||
uint16_t indexOfSyscap[CHAR_BIT * OS_SYSCAP_BYTES] = {0};
|
||||
@@ -241,6 +245,12 @@ bool DecodePrivateSyscap(char *input, char (**output)[SINGLE_SYSCAP_LEN], int *o
|
||||
int bufferLen, ret;
|
||||
int syscapCnt = 0;
|
||||
|
||||
if (input == NULL) {
|
||||
*output = outputArray;
|
||||
*outputCnt = syscapCnt;
|
||||
return false;
|
||||
}
|
||||
|
||||
while (*inputPos != '\0') {
|
||||
if (*inputPos == ',') {
|
||||
syscapCnt++;
|
||||
@@ -368,7 +378,7 @@ FREE_SYSCAP_OUT:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t CheckRpcidFormat(char *inputFile, char **Buffer, uint32_t *Len)
|
||||
static int32_t CheckRpcidFormat(const char *inputFile, char **Buffer, uint32_t *Len)
|
||||
{
|
||||
uint32_t bufferLen;
|
||||
uint16_t sysCaptype, sysCapLength;
|
||||
@@ -404,7 +414,7 @@ static int32_t CheckRpcidFormat(char *inputFile, char **Buffer, uint32_t *Len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *DecodeRpcidToStringFormat(char *inputFile)
|
||||
char *DecodeRpcidToStringFormat(const char *inputFile)
|
||||
{
|
||||
int32_t ret = 0;
|
||||
int32_t sysCapArraySize;
|
||||
@@ -580,7 +590,6 @@ int32_t ComparePcidString(char *pcidString, char *rpcidString, CompareError *res
|
||||
FreeCompareError(result);
|
||||
return -1;
|
||||
}
|
||||
result->missSyscapNum++;
|
||||
ret = strcpy_s(temp, sizeof(char) * SINGLE_SYSCAP_LEN,
|
||||
arraySyscap[(i - 2) * INT_BIT + k].syscapStr); // 2, header of pcid & rpcid
|
||||
if (ret != EOK) {
|
||||
@@ -609,7 +618,6 @@ int32_t ComparePcidString(char *pcidString, char *rpcidString, CompareError *res
|
||||
FreeCompareError(result);
|
||||
return -1;
|
||||
}
|
||||
result->missSyscapNum++;
|
||||
ret = strcpy_s(temp, sizeof(char) * SINGLE_SYSCAP_LEN,
|
||||
rpcidPriSyscap + SINGLE_SYSCAP_LEN * i);
|
||||
if (ret != EOK) {
|
||||
@@ -628,8 +636,9 @@ int32_t ComparePcidString(char *pcidString, char *rpcidString, CompareError *res
|
||||
}
|
||||
if (ossyscapFlag || prisyscapFlag) {
|
||||
ret |= 0x1 << 1;
|
||||
result->missSyscapNum = ossyscapFlag + prisyscapFlag;
|
||||
}
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t FreeCompareError(CompareError *result)
|
||||
@@ -639,6 +648,9 @@ int32_t FreeCompareError(CompareError *result)
|
||||
}
|
||||
for (int i = 0; i < result->missSyscapNum; i++) {
|
||||
free(result->syscap[i]);
|
||||
result->syscap[i] = NULL;
|
||||
}
|
||||
result->missSyscapNum = 0;
|
||||
result->targetApiVersion = 0;
|
||||
return 0;
|
||||
}
|
||||
@@ -26,6 +26,7 @@
|
||||
#define PCID_MAIN_BYTES 128
|
||||
#define PCID_MAIN_INTS 32
|
||||
|
||||
#define E_EORROR (-1)
|
||||
#define E_OK 0
|
||||
#define E_APIVERSION 1
|
||||
#define E_SYSCAP 2
|
||||
@@ -43,10 +44,29 @@ typedef struct CompareErrorMessage {
|
||||
} CompareError;
|
||||
|
||||
bool EncodeOsSyscap(char *output, int len);
|
||||
bool DecodeOsSyscap(char input[PCID_MAIN_BYTES], char (**output)[SINGLE_SYSCAP_LEN], int *outputCnt);
|
||||
bool DecodeOsSyscap(const char input[PCID_MAIN_BYTES], char (**output)[SINGLE_SYSCAP_LEN], int *outputCnt);
|
||||
bool EncodePrivateSyscap(char **output, int *outputLen);
|
||||
bool DecodePrivateSyscap(char *input, char (**output)[SINGLE_SYSCAP_LEN], int *outputCnt);
|
||||
char *DecodeRpcidToStringFormat(char *inputFile);
|
||||
char *DecodeRpcidToStringFormat(const char *inputFile);
|
||||
/*
|
||||
* params:
|
||||
* pcidString, input string format pcid.
|
||||
* rpcidString, input string format rpcid.
|
||||
* result, output comparison results.
|
||||
* retval:
|
||||
* E_EORROR, compare failed.
|
||||
* E_OK, compare successful and meet the requirements.
|
||||
* E_APIVERSION, compare successful but api version too low.
|
||||
* E_SYSCAP, compare successful but missing some syscaps.
|
||||
* E_APIVERSION | E_SYSCAP, none of api version and syscap
|
||||
* meet the requirements.
|
||||
* notes:
|
||||
* when return E_APIVERSION, the value of result.targetApiVersion
|
||||
* is the require api version.
|
||||
* when return E_SYSCAP, the value of result.missSyscapNum is the missing syscaps's numbers.
|
||||
* result.syscap[] is the array of points to syscap strings.
|
||||
* free variable result by function FreeCompareError.
|
||||
*/
|
||||
int32_t ComparePcidString(char *pcidString, char *rpcidString, CompareError *result);
|
||||
int32_t FreeCompareError(CompareError *result);
|
||||
|
||||
|
||||
@@ -97,6 +97,28 @@ HWTEST_F(SyscapCodecTest, DecodePrivateSyscap, TestSize.Level1)
|
||||
free(priOutput);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: DecodePrivateSyscap1
|
||||
* @tc.desc: Check the PrivateSyscap Decoding.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SyscapCodecTest, DecodePrivateSyscap1, TestSize.Level1)
|
||||
{
|
||||
char *charPriInput = NULL;
|
||||
char (*priOutput)[SINGLE_SYSCAP_LEN] = NULL;
|
||||
int priOutLen;
|
||||
int decodePriCnt;
|
||||
|
||||
EXPECT_TRUE(EncodePrivateSyscap(&charPriInput, &priOutLen));
|
||||
if (priOutLen == 0) {
|
||||
EXPECT_TRUE(DecodePrivateSyscap(charPriInput, &priOutput, &decodePriCnt));
|
||||
EXPECT_EQ((void *)priOutput, (void *)NULL);
|
||||
EXPECT_EQ(decodePriCnt, 0);
|
||||
free(priOutput);
|
||||
}
|
||||
free(charPriInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: ComparePcidString
|
||||
* @tc.desc: Check the DecodeRpcidToStringFormat Decoding.
|
||||
@@ -105,13 +127,13 @@ HWTEST_F(SyscapCodecTest, DecodePrivateSyscap, TestSize.Level1)
|
||||
HWTEST_F(SyscapCodecTest, ComparePcidString, TestSize.Level1)
|
||||
{
|
||||
CompareError result = {{0}, 0, 0};
|
||||
char pcidString[] = "263168,0,3473408,0,0,0,1634,0,0,0,0,0,0,0,0,0,0,\
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,SystemCapability.vendor.xxxxx3,\
|
||||
SystemCapability.device.xxxxx4";
|
||||
char rpcidString[] = "33588992,1766370052,65536,276824064,0,0,0,0,0,0,\
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
|
||||
SystemCapability.vendor.xxxxx1,SystemCapability.device.xxxxx2";
|
||||
char expect[][256] = {"SystemCapability.HiviewDFX.HiLog", "SystemCapability.HiviewDFX.Hiview",
|
||||
char pcidString[] = "263168,0,3473408,0,0,0,1634,0,0,0,0,0,0,0,0,0,0,"\
|
||||
"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,SystemCapability.vendor.xxxxx3,"\
|
||||
"SystemCapability.device.xxxxx4";
|
||||
char rpcidString[] = "33588992,1766370052,65536,276824064,0,0,0,0,0,0,"\
|
||||
"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"\
|
||||
"SystemCapability.vendor.xxxxx1,SystemCapability.device.xxxxx2";
|
||||
char expect[][256] = {"SystemCapability.HiviewDFX.HiDumper", "SystemCapability.HiviewDFX.HiSysEvent",
|
||||
"SystemCapability.vendor.xxxxx1", "SystemCapability.device.xxxxx2"};
|
||||
int32_t ret = ComparePcidString(pcidString, rpcidString, &result);
|
||||
EXPECT_EQ(ret, 3);
|
||||
@@ -121,5 +143,10 @@ HWTEST_F(SyscapCodecTest, ComparePcidString, TestSize.Level1)
|
||||
EXPECT_STREQ(result.syscap[i], expect[i]);
|
||||
}
|
||||
(void)FreeCompareError(&result);
|
||||
EXPECT_EQ(result.targetApiVersion, 0);
|
||||
EXPECT_EQ(result.missSyscapNum, 0);
|
||||
for (int i = 0; i < MAX_MISS_SYSCAP; i++) {
|
||||
EXPECT_EQ((void *)result.syscap[i], (void *)NULL);
|
||||
}
|
||||
}
|
||||
} // namespace Syscap
|
||||
|
||||
Reference in New Issue
Block a user